sanity-plugin-utils 1.6.5 → 1.6.7

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 CHANGED
@@ -1,997 +1,658 @@
1
- import React, { useMemo, useState, useRef, useEffect } from 'react';
2
- import { useClient, useDocumentStore, useWorkspace, UserAvatar } from 'sanity';
3
- import isEqual from 'react-fast-compare';
4
- import { distinctUntilChanged, catchError } from 'rxjs/operators';
5
- import { usePaneRouter } from 'sanity/structure';
6
- import { RouterContext } from 'sanity/router';
7
- import { jsx, jsxs } from 'react/jsx-runtime';
8
- import { Card, Flex, Box, Stack, Text, Menu, MenuItem, TextInput, Badge } from '@sanity/ui';
9
- import styled, { css } from 'styled-components';
10
- import { RemoveCircleIcon, AddCircleIcon, RestoreIcon } from '@sanity/icons';
11
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
12
- function getDefaultExportFromCjs(x) {
13
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
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
+ var __defProp$3 = Object.defineProperty, __getOwnPropSymbols$3 = Object.getOwnPropertySymbols, __hasOwnProp$3 = Object.prototype.hasOwnProperty, __propIsEnum$3 = Object.prototype.propertyIsEnumerable, __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$3 = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ __hasOwnProp$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols$3)
15
+ for (var prop of __getOwnPropSymbols$3(b))
16
+ __propIsEnum$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
17
+ return a;
18
+ };
19
+ const DEFAULT_PROPS = {
20
+ tone: "primary"
21
+ };
22
+ function Feedback(props) {
23
+ const { title, description, icon, tone, children } = __spreadValues$3(__spreadValues$3({}, DEFAULT_PROPS), props);
24
+ return /* @__PURE__ */ jsx(Card, { tone, padding: 4, radius: 3, border: !0, children: /* @__PURE__ */ jsxs(Flex, { children: [
25
+ icon ? "display icon" : null,
26
+ children || /* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
27
+ title ? /* @__PURE__ */ jsx(Text, { weight: "semibold", children: title }) : null,
28
+ description ? /* @__PURE__ */ jsx(Text, { size: 2, children: description }) : null
29
+ ] }) })
30
+ ] }) });
14
31
  }
15
- var builder = {};
16
- var urlForImage = {};
17
- var parseAssetId$1 = {};
18
- Object.defineProperty(parseAssetId$1, "__esModule", {
19
- value: true
20
- });
21
- var example = 'image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg';
22
- function parseAssetId(ref) {
23
- var _a = ref.split('-'),
24
- id = _a[1],
25
- dimensionString = _a[2],
26
- format = _a[3];
27
- if (!id || !dimensionString || !format) {
28
- throw new Error("Malformed asset _ref '".concat(ref, "'. Expected an id like \"").concat(example, "\"."));
29
- }
30
- var _b = dimensionString.split('x'),
31
- imgWidthStr = _b[0],
32
- imgHeightStr = _b[1];
33
- var width = +imgWidthStr;
34
- var height = +imgHeightStr;
35
- var isValidAssetId = isFinite(width) && isFinite(height);
36
- if (!isValidAssetId) {
37
- throw new Error("Malformed asset _ref '".concat(ref, "'. Expected an id like \"").concat(example, "\"."));
38
- }
39
- return {
40
- id: id,
41
- width: width,
42
- height: height,
43
- format: format
44
- };
32
+ var __defProp$2 = Object.defineProperty, __defProps$1 = Object.defineProperties, __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$2 = Object.getOwnPropertySymbols, __hasOwnProp$2 = Object.prototype.hasOwnProperty, __propIsEnum$2 = Object.prototype.propertyIsEnumerable, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$2 = (a, b) => {
33
+ for (var prop in b || (b = {}))
34
+ __hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
35
+ if (__getOwnPropSymbols$2)
36
+ for (var prop of __getOwnPropSymbols$2(b))
37
+ __propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
38
+ return a;
39
+ }, __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b)), __objRest = (source, exclude) => {
40
+ var target = {};
41
+ for (var prop in source)
42
+ __hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
43
+ if (source != null && __getOwnPropSymbols$2)
44
+ for (var prop of __getOwnPropSymbols$2(source))
45
+ exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop) && (target[prop] = source[prop]);
46
+ return target;
47
+ };
48
+ const TableWrapper = (props = {}) => /* @__PURE__ */ jsx(Card, __spreadValues$2({ as: "table" }, props)), StyledTable = styled(TableWrapper)(
49
+ () => css`
50
+ display: table;
51
+ width: 100%;
52
+ border-collapse: collapse;
53
+
54
+ &:not([hidden]) {
55
+ display: table;
56
+ border-collapse: collapse;
57
+ }
58
+ `
59
+ );
60
+ function Table(props) {
61
+ const _a = props, { children } = _a, rest = __objRest(_a, ["children"]);
62
+ return /* @__PURE__ */ jsx(StyledTable, __spreadProps$1(__spreadValues$2({}, rest), { children }));
45
63
  }
46
- parseAssetId$1.default = parseAssetId;
47
- var parseSource$1 = {};
48
- var __assign$1 = commonjsGlobal && commonjsGlobal.__assign || function () {
49
- __assign$1 = Object.assign || function (t) {
50
- for (var s, i = 1, n = arguments.length; i < n; i++) {
51
- s = arguments[i];
52
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
64
+ const RowWrapper = (props = {}) => /* @__PURE__ */ jsx(Card, __spreadValues$2({ as: "tr" }, props)), StyledRow = styled(RowWrapper)(
65
+ () => css`
66
+ display: table-row;
67
+
68
+ &:not([hidden]) {
69
+ display: table-row;
53
70
  }
54
- return t;
55
- };
56
- return __assign$1.apply(this, arguments);
57
- };
58
- Object.defineProperty(parseSource$1, "__esModule", {
59
- value: true
60
- });
61
- var isRef = function (src) {
62
- var source = src;
63
- return source ? typeof source._ref === 'string' : false;
64
- };
65
- var isAsset = function (src) {
66
- var source = src;
67
- return source ? typeof source._id === 'string' : false;
71
+ `
72
+ );
73
+ function Row(props) {
74
+ const _a = props, { children } = _a, rest = __objRest(_a, ["children"]);
75
+ return /* @__PURE__ */ jsx(StyledRow, __spreadProps$1(__spreadValues$2({}, rest), { children }));
76
+ }
77
+ const CellWrapper = (props = {}) => /* @__PURE__ */ jsx(Card, __spreadValues$2({ as: "td" }, props)), StyledCell = styled(CellWrapper)(
78
+ () => css`
79
+ display: table-cell;
80
+
81
+ &:not([hidden]) {
82
+ display: table-cell;
83
+ }
84
+ `
85
+ );
86
+ function Cell(props) {
87
+ const _a = props, { children } = _a, rest = __objRest(_a, ["children"]);
88
+ return /* @__PURE__ */ jsx(StyledCell, __spreadProps$1(__spreadValues$2({}, rest), { children }));
89
+ }
90
+ var __defProp$1 = Object.defineProperty, __getOwnPropSymbols$1 = Object.getOwnPropertySymbols, __hasOwnProp$1 = Object.prototype.hasOwnProperty, __propIsEnum$1 = Object.prototype.propertyIsEnumerable, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$1 = (a, b) => {
91
+ for (var prop in b || (b = {}))
92
+ __hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
93
+ if (__getOwnPropSymbols$1)
94
+ for (var prop of __getOwnPropSymbols$1(b))
95
+ __propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
96
+ return a;
68
97
  };
69
- var isAssetStub = function (src) {
70
- var source = src;
71
- return source && source.asset ? typeof source.asset.url === 'string' : false;
98
+ function searchUsers(users, searchString) {
99
+ return users.filter((user) => !!((user.displayName || "").toLowerCase().startsWith(searchString) || (user.givenName || "").toLowerCase().startsWith(searchString) || (user.middleName || "").toLowerCase().startsWith(searchString) || (user.familyName || "").toLowerCase().startsWith(searchString)));
100
+ }
101
+ const LABELS = {
102
+ addMe: "Assign myself",
103
+ removeMe: "Unassign myself",
104
+ clear: "Clear assignees",
105
+ searchPlaceholder: "Search users",
106
+ notFound: "No users found"
72
107
  };
73
- // Convert an asset-id, asset or image to an image record suitable for processing
74
- // eslint-disable-next-line complexity
75
- function parseSource(source) {
76
- if (!source) {
77
- return null;
78
- }
79
- var image;
80
- if (typeof source === 'string' && isUrl(source)) {
81
- // Someone passed an existing image url?
82
- image = {
83
- asset: {
84
- _ref: urlToId(source)
108
+ function UserSelectMenu(props) {
109
+ const {
110
+ value = [],
111
+ userList = [],
112
+ onAdd,
113
+ onRemove,
114
+ onClear,
115
+ style = {}
116
+ } = props, labels = props != null && props.labels ? __spreadValues$1(__spreadValues$1({}, 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) => {
117
+ setSearchString(event.target.value);
118
+ }, handleSelect = (isChecked, user) => {
119
+ isChecked ? onRemove && onRemove(user.id) : onAdd && onAdd(user.id);
120
+ }, handleAssignMyself = () => {
121
+ me && onAdd && onAdd(me.id);
122
+ }, handleUnassignMyself = () => {
123
+ me && onRemove && onRemove(me.id);
124
+ }, handleClearAssigneesClick = () => {
125
+ onClear && onClear();
126
+ };
127
+ return /* @__PURE__ */ jsxs(Menu, { style, children: [
128
+ meAssigned ? /* @__PURE__ */ jsx(
129
+ MenuItem,
130
+ {
131
+ tone: "caution",
132
+ disabled: !me,
133
+ onClick: handleUnassignMyself,
134
+ icon: RemoveCircleIcon,
135
+ text: labels.removeMe
85
136
  }
86
- };
87
- } else if (typeof source === 'string') {
88
- // Just an asset id
89
- image = {
90
- asset: {
91
- _ref: source
137
+ ) : /* @__PURE__ */ jsx(
138
+ MenuItem,
139
+ {
140
+ tone: "positive",
141
+ onClick: handleAssignMyself,
142
+ icon: AddCircleIcon,
143
+ text: labels.addMe
92
144
  }
93
- };
94
- } else if (isRef(source)) {
95
- // We just got passed an asset directly
96
- image = {
97
- asset: source
98
- };
99
- } else if (isAsset(source)) {
100
- // If we were passed an image asset document
101
- image = {
102
- asset: {
103
- _ref: source._id || ''
145
+ ),
146
+ /* @__PURE__ */ jsx(
147
+ MenuItem,
148
+ {
149
+ tone: "critical",
150
+ disabled: value.length === 0,
151
+ onClick: handleClearAssigneesClick,
152
+ icon: RestoreIcon,
153
+ text: labels.clear
104
154
  }
105
- };
106
- } else if (isAssetStub(source)) {
107
- // If we were passed a partial asset (`url`, but no `_id`)
108
- image = {
109
- asset: {
110
- _ref: urlToId(source.asset.url)
155
+ ),
156
+ /* @__PURE__ */ jsx(Box, { padding: 1, children: /* @__PURE__ */ jsx(
157
+ TextInput,
158
+ {
159
+ ref: input,
160
+ onChange: handleSearchChange,
161
+ placeholder: labels.searchPlaceholder,
162
+ value: searchString
111
163
  }
112
- };
113
- } else if (typeof source.asset === 'object') {
114
- // Probably an actual image with materialized asset
115
- image = __assign$1({}, source);
116
- } else {
117
- // We got something that does not look like an image, or it is an image
118
- // that currently isn't sporting an asset.
119
- return null;
120
- }
121
- var img = source;
122
- if (img.crop) {
123
- image.crop = img.crop;
124
- }
125
- if (img.hotspot) {
126
- image.hotspot = img.hotspot;
127
- }
128
- return applyDefaults(image);
164
+ ) }),
165
+ searchString && (searchResults == null ? void 0 : searchResults.length) === 0 && /* @__PURE__ */ jsx(MenuItem, { disabled: !0, text: labels.notFound }),
166
+ searchResults && searchResults.map((user) => /* @__PURE__ */ jsx(
167
+ MenuItem,
168
+ {
169
+ pressed: value.includes(user.id),
170
+ onClick: () => handleSelect(value.indexOf(user.id) > -1, user),
171
+ children: /* @__PURE__ */ jsxs(Flex, { align: "center", children: [
172
+ /* @__PURE__ */ jsx(UserAvatar, { user, size: 1 }),
173
+ /* @__PURE__ */ jsx(Box, { paddingX: 2, flex: 1, children: /* @__PURE__ */ jsx(Text, { children: user.displayName }) }),
174
+ user.isCurrentUser && /* @__PURE__ */ jsx(Badge, { fontSize: 1, tone: "positive", mode: "outline", children: "Me" })
175
+ ] })
176
+ },
177
+ user.id
178
+ ))
179
+ ] });
129
180
  }
130
- parseSource$1.default = parseSource;
131
- function isUrl(url) {
132
- return /^https?:\/\//.test("".concat(url));
181
+ function getDefaultExportFromCjs(x) {
182
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x.default : x;
133
183
  }
134
- function urlToId(url) {
135
- var parts = url.split('/').slice(-1);
136
- return "image-".concat(parts[0]).replace(/\.([a-z]+)$/, '-$1');
184
+ var builder = {}, urlForImage = {}, parseAssetId = {}, hasRequiredParseAssetId;
185
+ function requireParseAssetId() {
186
+ if (hasRequiredParseAssetId) return parseAssetId;
187
+ hasRequiredParseAssetId = 1, Object.defineProperty(parseAssetId, "__esModule", { value: !0 });
188
+ var example = "image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg";
189
+ function parseAssetId$1(ref) {
190
+ var _a = ref.split("-"), id = _a[1], dimensionString = _a[2], format = _a[3];
191
+ if (!id || !dimensionString || !format)
192
+ throw new Error("Malformed asset _ref '".concat(ref, `'. Expected an id like "`).concat(example, '".'));
193
+ var _b = dimensionString.split("x"), imgWidthStr = _b[0], imgHeightStr = _b[1], width = +imgWidthStr, height = +imgHeightStr, isValidAssetId = isFinite(width) && isFinite(height);
194
+ if (!isValidAssetId)
195
+ throw new Error("Malformed asset _ref '".concat(ref, `'. Expected an id like "`).concat(example, '".'));
196
+ return { id, width, height, format };
197
+ }
198
+ return parseAssetId.default = parseAssetId$1, parseAssetId;
137
199
  }
138
- // Mock crop and hotspot if image lacks it
139
- function applyDefaults(image) {
140
- if (image.crop && image.hotspot) {
141
- return image;
200
+ var parseSource = {}, hasRequiredParseSource;
201
+ function requireParseSource() {
202
+ if (hasRequiredParseSource) return parseSource;
203
+ hasRequiredParseSource = 1;
204
+ var __assign = parseSource && parseSource.__assign || function() {
205
+ return __assign = Object.assign || function(t) {
206
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
207
+ s = arguments[i];
208
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
209
+ }
210
+ return t;
211
+ }, __assign.apply(this, arguments);
212
+ };
213
+ Object.defineProperty(parseSource, "__esModule", { value: !0 });
214
+ var isRef = function(src) {
215
+ var source = src;
216
+ return source ? typeof source._ref == "string" : !1;
217
+ }, isAsset = function(src) {
218
+ var source = src;
219
+ return source ? typeof source._id == "string" : !1;
220
+ }, isAssetStub = function(src) {
221
+ var source = src;
222
+ return source && source.asset ? typeof source.asset.url == "string" : !1;
223
+ };
224
+ function parseSource$1(source) {
225
+ if (!source)
226
+ return null;
227
+ var image;
228
+ if (typeof source == "string" && isUrl(source))
229
+ image = {
230
+ asset: { _ref: urlToId(source) }
231
+ };
232
+ else if (typeof source == "string")
233
+ image = {
234
+ asset: { _ref: source }
235
+ };
236
+ else if (isRef(source))
237
+ image = {
238
+ asset: source
239
+ };
240
+ else if (isAsset(source))
241
+ image = {
242
+ asset: {
243
+ _ref: source._id || ""
244
+ }
245
+ };
246
+ else if (isAssetStub(source))
247
+ image = {
248
+ asset: {
249
+ _ref: urlToId(source.asset.url)
250
+ }
251
+ };
252
+ else if (typeof source.asset == "object")
253
+ image = __assign({}, source);
254
+ else
255
+ return null;
256
+ var img = source;
257
+ return img.crop && (image.crop = img.crop), img.hotspot && (image.hotspot = img.hotspot), applyDefaults(image);
142
258
  }
143
- // We need to pad in default values for crop or hotspot
144
- var result = __assign$1({}, image);
145
- if (!result.crop) {
146
- result.crop = {
259
+ parseSource.default = parseSource$1;
260
+ function isUrl(url) {
261
+ return /^https?:\/\//.test("".concat(url));
262
+ }
263
+ function urlToId(url) {
264
+ var parts = url.split("/").slice(-1);
265
+ return "image-".concat(parts[0]).replace(/\.([a-z]+)$/, "-$1");
266
+ }
267
+ function applyDefaults(image) {
268
+ if (image.crop && image.hotspot)
269
+ return image;
270
+ var result = __assign({}, image);
271
+ return result.crop || (result.crop = {
147
272
  left: 0,
148
273
  top: 0,
149
274
  bottom: 0,
150
275
  right: 0
151
- };
152
- }
153
- if (!result.hotspot) {
154
- result.hotspot = {
276
+ }), result.hotspot || (result.hotspot = {
155
277
  x: 0.5,
156
278
  y: 0.5,
157
- height: 1.0,
158
- width: 1.0
159
- };
279
+ height: 1,
280
+ width: 1
281
+ }), result;
160
282
  }
161
- return result;
283
+ return parseSource;
162
284
  }
163
- (function (exports) {
164
- var __assign = commonjsGlobal && commonjsGlobal.__assign || function () {
165
- __assign = Object.assign || function (t) {
166
- for (var s, i = 1, n = arguments.length; i < n; i++) {
167
- s = arguments[i];
168
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
169
- }
170
- return t;
171
- };
172
- return __assign.apply(this, arguments);
173
- };
174
- var __importDefault = commonjsGlobal && commonjsGlobal.__importDefault || function (mod) {
175
- return mod && mod.__esModule ? mod : {
176
- "default": mod
177
- };
178
- };
179
- Object.defineProperty(exports, "__esModule", {
180
- value: true
181
- });
182
- exports.parseSource = exports.SPEC_NAME_TO_URL_NAME_MAPPINGS = void 0;
183
- var parseAssetId_1 = __importDefault(parseAssetId$1);
184
- var parseSource_1 = __importDefault(parseSource$1);
185
- exports.parseSource = parseSource_1.default;
186
- 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']];
187
- function urlForImage(options) {
188
- var spec = __assign({}, options || {});
189
- var source = spec.source;
190
- delete spec.source;
191
- var image = (0, parseSource_1.default)(source);
192
- if (!image) {
193
- throw new Error("Unable to resolve image URL from source (".concat(JSON.stringify(source), ")"));
194
- }
195
- var id = image.asset._ref || image.asset._id || '';
196
- var asset = (0, parseAssetId_1.default)(id);
197
- // Compute crop rect in terms of pixel coordinates in the raw source image
198
- var cropLeft = Math.round(image.crop.left * asset.width);
199
- var cropTop = Math.round(image.crop.top * asset.height);
200
- var crop = {
201
- left: cropLeft,
202
- top: cropTop,
203
- width: Math.round(asset.width - image.crop.right * asset.width - cropLeft),
204
- height: Math.round(asset.height - image.crop.bottom * asset.height - cropTop)
285
+ var hasRequiredUrlForImage;
286
+ function requireUrlForImage() {
287
+ return hasRequiredUrlForImage || (hasRequiredUrlForImage = 1, function(exports) {
288
+ var __assign = urlForImage && urlForImage.__assign || function() {
289
+ return __assign = Object.assign || function(t) {
290
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
291
+ s = arguments[i];
292
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
293
+ }
294
+ return t;
295
+ }, __assign.apply(this, arguments);
296
+ }, __importDefault = urlForImage && urlForImage.__importDefault || function(mod) {
297
+ return mod && mod.__esModule ? mod : { default: mod };
205
298
  };
206
- // Compute hot spot rect in terms of pixel coordinates
207
- var hotSpotVerticalRadius = image.hotspot.height * asset.height / 2;
208
- var hotSpotHorizontalRadius = image.hotspot.width * asset.width / 2;
209
- var hotSpotCenterX = image.hotspot.x * asset.width;
210
- var hotSpotCenterY = image.hotspot.y * asset.height;
211
- var hotspot = {
212
- left: hotSpotCenterX - hotSpotHorizontalRadius,
213
- top: hotSpotCenterY - hotSpotVerticalRadius,
214
- right: hotSpotCenterX + hotSpotHorizontalRadius,
215
- bottom: hotSpotCenterY + hotSpotVerticalRadius
216
- };
217
- // If irrelevant, or if we are requested to: don't perform crop/fit based on
218
- // the crop/hotspot.
219
- if (!(spec.rect || spec.focalPoint || spec.ignoreImageParams || spec.crop)) {
220
- spec = __assign(__assign({}, spec), fit({
221
- crop: crop,
222
- hotspot: hotspot
223
- }, spec));
299
+ Object.defineProperty(exports, "__esModule", { value: !0 }), exports.parseSource = exports.SPEC_NAME_TO_URL_NAME_MAPPINGS = void 0;
300
+ var parseAssetId_1 = __importDefault(requireParseAssetId()), parseSource_1 = __importDefault(requireParseSource());
301
+ exports.parseSource = parseSource_1.default, exports.SPEC_NAME_TO_URL_NAME_MAPPINGS = [
302
+ ["width", "w"],
303
+ ["height", "h"],
304
+ ["format", "fm"],
305
+ ["download", "dl"],
306
+ ["blur", "blur"],
307
+ ["sharpen", "sharp"],
308
+ ["invert", "invert"],
309
+ ["orientation", "or"],
310
+ ["minHeight", "min-h"],
311
+ ["maxHeight", "max-h"],
312
+ ["minWidth", "min-w"],
313
+ ["maxWidth", "max-w"],
314
+ ["quality", "q"],
315
+ ["fit", "fit"],
316
+ ["crop", "crop"],
317
+ ["saturation", "sat"],
318
+ ["auto", "auto"],
319
+ ["dpr", "dpr"],
320
+ ["pad", "pad"]
321
+ ];
322
+ function urlForImage$1(options) {
323
+ var spec = __assign({}, options || {}), source = spec.source;
324
+ delete spec.source;
325
+ var image = (0, parseSource_1.default)(source);
326
+ if (!image)
327
+ throw new Error("Unable to resolve image URL from source (".concat(JSON.stringify(source), ")"));
328
+ 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 = {
329
+ left: cropLeft,
330
+ top: cropTop,
331
+ width: Math.round(asset.width - image.crop.right * asset.width - cropLeft),
332
+ height: Math.round(asset.height - image.crop.bottom * asset.height - cropTop)
333
+ }, 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 = {
334
+ left: hotSpotCenterX - hotSpotHorizontalRadius,
335
+ top: hotSpotCenterY - hotSpotVerticalRadius,
336
+ right: hotSpotCenterX + hotSpotHorizontalRadius,
337
+ bottom: hotSpotCenterY + hotSpotVerticalRadius
338
+ };
339
+ return spec.rect || spec.focalPoint || spec.ignoreImageParams || spec.crop || (spec = __assign(__assign({}, spec), fit({ crop, hotspot }, spec))), specToImageUrl(__assign(__assign({}, spec), { asset }));
224
340
  }
225
- return specToImageUrl(__assign(__assign({}, spec), {
226
- asset: asset
227
- }));
228
- }
229
- exports.default = urlForImage;
230
- // eslint-disable-next-line complexity
231
- function specToImageUrl(spec) {
232
- var cdnUrl = (spec.baseUrl || 'https://cdn.sanity.io').replace(/\/+$/, '');
233
- var filename = "".concat(spec.asset.id, "-").concat(spec.asset.width, "x").concat(spec.asset.height, ".").concat(spec.asset.format);
234
- var baseUrl = "".concat(cdnUrl, "/images/").concat(spec.projectId, "/").concat(spec.dataset, "/").concat(filename);
235
- var params = [];
236
- if (spec.rect) {
237
- // Only bother url with a crop if it actually crops anything
238
- var _a = spec.rect,
239
- left = _a.left,
240
- top_1 = _a.top,
241
- width = _a.width,
242
- height = _a.height;
243
- var isEffectiveCrop = left !== 0 || top_1 !== 0 || height !== spec.asset.height || width !== spec.asset.width;
244
- if (isEffectiveCrop) {
245
- params.push("rect=".concat(left, ",").concat(top_1, ",").concat(width, ",").concat(height));
341
+ exports.default = urlForImage$1;
342
+ function specToImageUrl(spec) {
343
+ var cdnUrl = (spec.baseUrl || "https://cdn.sanity.io").replace(/\/+$/, ""), filename = "".concat(spec.asset.id, "-").concat(spec.asset.width, "x").concat(spec.asset.height, ".").concat(spec.asset.format), baseUrl = "".concat(cdnUrl, "/images/").concat(spec.projectId, "/").concat(spec.dataset, "/").concat(filename), params = [];
344
+ if (spec.rect) {
345
+ 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;
346
+ isEffectiveCrop && params.push("rect=".concat(left, ",").concat(top_1, ",").concat(width, ",").concat(height));
246
347
  }
348
+ 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)));
349
+ var flip = [spec.flipHorizontal && "h", spec.flipVertical && "v"].filter(Boolean).join("");
350
+ return flip && params.push("flip=".concat(flip)), exports.SPEC_NAME_TO_URL_NAME_MAPPINGS.forEach(function(mapping) {
351
+ var specName = mapping[0], param = mapping[1];
352
+ typeof spec[specName] < "u" ? params.push("".concat(param, "=").concat(encodeURIComponent(spec[specName]))) : typeof spec[param] < "u" && params.push("".concat(param, "=").concat(encodeURIComponent(spec[param])));
353
+ }), params.length === 0 ? baseUrl : "".concat(baseUrl, "?").concat(params.join("&"));
247
354
  }
248
- if (spec.bg) {
249
- params.push("bg=".concat(spec.bg));
250
- }
251
- if (spec.focalPoint) {
252
- params.push("fp-x=".concat(spec.focalPoint.x));
253
- params.push("fp-y=".concat(spec.focalPoint.y));
254
- }
255
- var flip = [spec.flipHorizontal && 'h', spec.flipVertical && 'v'].filter(Boolean).join('');
256
- if (flip) {
257
- params.push("flip=".concat(flip));
258
- }
259
- // Map from spec name to url param name, and allow using the actual param name as an alternative
260
- exports.SPEC_NAME_TO_URL_NAME_MAPPINGS.forEach(function (mapping) {
261
- var specName = mapping[0],
262
- param = mapping[1];
263
- if (typeof spec[specName] !== 'undefined') {
264
- params.push("".concat(param, "=").concat(encodeURIComponent(spec[specName])));
265
- } else if (typeof spec[param] !== 'undefined') {
266
- params.push("".concat(param, "=").concat(encodeURIComponent(spec[param])));
355
+ function fit(source, spec) {
356
+ var cropRect, imgWidth = spec.width, imgHeight = spec.height;
357
+ if (!(imgWidth && imgHeight))
358
+ return { width: imgWidth, height: imgHeight, rect: source.crop };
359
+ var crop = source.crop, hotspot = source.hotspot, desiredAspectRatio = imgWidth / imgHeight, cropAspectRatio = crop.width / crop.height;
360
+ if (cropAspectRatio > desiredAspectRatio) {
361
+ 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));
362
+ 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 };
363
+ } else {
364
+ 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));
365
+ 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 };
267
366
  }
268
- });
269
- if (params.length === 0) {
270
- return baseUrl;
271
- }
272
- return "".concat(baseUrl, "?").concat(params.join('&'));
273
- }
274
- function fit(source, spec) {
275
- var cropRect;
276
- var imgWidth = spec.width;
277
- var imgHeight = spec.height;
278
- // If we are not constraining the aspect ratio, we'll just use the whole crop
279
- if (!(imgWidth && imgHeight)) {
280
367
  return {
281
368
  width: imgWidth,
282
369
  height: imgHeight,
283
- rect: source.crop
370
+ rect: cropRect
284
371
  };
285
372
  }
286
- var crop = source.crop;
287
- var hotspot = source.hotspot;
288
- // If we are here, that means aspect ratio is locked and fitting will be a bit harder
289
- var desiredAspectRatio = imgWidth / imgHeight;
290
- var cropAspectRatio = crop.width / crop.height;
291
- if (cropAspectRatio > desiredAspectRatio) {
292
- // The crop is wider than the desired aspect ratio. That means we are cutting from the sides
293
- var height = Math.round(crop.height);
294
- var width = Math.round(height * desiredAspectRatio);
295
- var top_2 = Math.max(0, Math.round(crop.top));
296
- // Center output horizontally over hotspot
297
- var hotspotXCenter = Math.round((hotspot.right - hotspot.left) / 2 + hotspot.left);
298
- var left = Math.max(0, Math.round(hotspotXCenter - width / 2));
299
- // Keep output within crop
300
- if (left < crop.left) {
301
- left = crop.left;
302
- } else if (left + width > crop.left + crop.width) {
303
- left = crop.left + crop.width - width;
304
- }
305
- cropRect = {
306
- left: left,
307
- top: top_2,
308
- width: width,
309
- height: height
310
- };
311
- } else {
312
- // The crop is taller than the desired ratio, we are cutting from top and bottom
313
- var width = crop.width;
314
- var height = Math.round(width / desiredAspectRatio);
315
- var left = Math.max(0, Math.round(crop.left));
316
- // Center output vertically over hotspot
317
- var hotspotYCenter = Math.round((hotspot.bottom - hotspot.top) / 2 + hotspot.top);
318
- var top_3 = Math.max(0, Math.round(hotspotYCenter - height / 2));
319
- // Keep output rect within crop
320
- if (top_3 < crop.top) {
321
- top_3 = crop.top;
322
- } else if (top_3 + height > crop.top + crop.height) {
323
- top_3 = crop.top + crop.height - height;
373
+ }(urlForImage)), urlForImage;
374
+ }
375
+ var hasRequiredBuilder;
376
+ function requireBuilder() {
377
+ if (hasRequiredBuilder) return builder;
378
+ hasRequiredBuilder = 1;
379
+ var __assign = builder && builder.__assign || function() {
380
+ return __assign = Object.assign || function(t) {
381
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
382
+ s = arguments[i];
383
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
324
384
  }
325
- cropRect = {
326
- left: left,
327
- top: top_3,
328
- width: width,
329
- height: height
330
- };
331
- }
332
- return {
333
- width: imgWidth,
334
- height: imgHeight,
335
- rect: cropRect
336
- };
385
+ return t;
386
+ }, __assign.apply(this, arguments);
387
+ }, __createBinding = builder && builder.__createBinding || (Object.create ? function(o, m, k, k2) {
388
+ k2 === void 0 && (k2 = k), Object.defineProperty(o, k2, { enumerable: !0, get: function() {
389
+ return m[k];
390
+ } });
391
+ } : function(o, m, k, k2) {
392
+ k2 === void 0 && (k2 = k), o[k2] = m[k];
393
+ }), __setModuleDefault = builder && builder.__setModuleDefault || (Object.create ? function(o, v) {
394
+ Object.defineProperty(o, "default", { enumerable: !0, value: v });
395
+ } : function(o, v) {
396
+ o.default = v;
397
+ }), __importStar = builder && builder.__importStar || function(mod) {
398
+ if (mod && mod.__esModule) return mod;
399
+ var result = {};
400
+ if (mod != null) for (var k in mod) k !== "default" && Object.prototype.hasOwnProperty.call(mod, k) && __createBinding(result, mod, k);
401
+ return __setModuleDefault(result, mod), result;
402
+ };
403
+ Object.defineProperty(builder, "__esModule", { value: !0 }), builder.ImageUrlBuilder = void 0;
404
+ var urlForImage_1 = __importStar(requireUrlForImage()), validFits = ["clip", "crop", "fill", "fillmax", "max", "scale", "min"], validCrops = ["top", "bottom", "left", "right", "center", "focalpoint", "entropy"], validAutoModes = ["format"];
405
+ function isSanityModernClientLike(client) {
406
+ return client && "config" in client ? typeof client.config == "function" : !1;
407
+ }
408
+ function isSanityClientLike(client) {
409
+ return client && "clientConfig" in client ? typeof client.clientConfig == "object" : !1;
337
410
  }
338
- })(urlForImage);
339
- var __assign = commonjsGlobal && commonjsGlobal.__assign || function () {
340
- __assign = Object.assign || function (t) {
341
- for (var s, i = 1, n = arguments.length; i < n; i++) {
342
- s = arguments[i];
343
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
411
+ function rewriteSpecName(key) {
412
+ for (var specs = urlForImage_1.SPEC_NAME_TO_URL_NAME_MAPPINGS, _i = 0, specs_1 = specs; _i < specs_1.length; _i++) {
413
+ var entry = specs_1[_i], specName = entry[0], param = entry[1];
414
+ if (key === specName || key === param)
415
+ return specName;
344
416
  }
345
- return t;
346
- };
347
- return __assign.apply(this, arguments);
348
- };
349
- var __createBinding = commonjsGlobal && commonjsGlobal.__createBinding || (Object.create ? function (o, m, k, k2) {
350
- if (k2 === undefined) k2 = k;
351
- Object.defineProperty(o, k2, {
352
- enumerable: true,
353
- get: function () {
354
- return m[k];
417
+ return key;
418
+ }
419
+ function urlBuilder(options) {
420
+ if (isSanityModernClientLike(options)) {
421
+ var _a = options.config(), apiUrl = _a.apiHost, projectId = _a.projectId, dataset = _a.dataset, apiHost = apiUrl || "https://api.sanity.io";
422
+ return new ImageUrlBuilder(null, {
423
+ baseUrl: apiHost.replace(/^https:\/\/api\./, "https://cdn."),
424
+ projectId,
425
+ dataset
426
+ });
355
427
  }
356
- });
357
- } : function (o, m, k, k2) {
358
- if (k2 === undefined) k2 = k;
359
- o[k2] = m[k];
360
- });
361
- var __setModuleDefault = commonjsGlobal && commonjsGlobal.__setModuleDefault || (Object.create ? function (o, v) {
362
- Object.defineProperty(o, "default", {
363
- enumerable: true,
364
- value: v
365
- });
366
- } : function (o, v) {
367
- o["default"] = v;
368
- });
369
- var __importStar = commonjsGlobal && commonjsGlobal.__importStar || function (mod) {
370
- if (mod && mod.__esModule) return mod;
371
- var result = {};
372
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
373
- __setModuleDefault(result, mod);
374
- return result;
375
- };
376
- Object.defineProperty(builder, "__esModule", {
377
- value: true
378
- });
379
- builder.ImageUrlBuilder = void 0;
380
- var urlForImage_1 = __importStar(urlForImage);
381
- var validFits = ['clip', 'crop', 'fill', 'fillmax', 'max', 'scale', 'min'];
382
- var validCrops = ['top', 'bottom', 'left', 'right', 'center', 'focalpoint', 'entropy'];
383
- var validAutoModes = ['format'];
384
- function isSanityModernClientLike(client) {
385
- return client && 'config' in client ? typeof client.config === 'function' : false;
386
- }
387
- function isSanityClientLike(client) {
388
- return client && 'clientConfig' in client ? typeof client.clientConfig === 'object' : false;
389
- }
390
- function rewriteSpecName(key) {
391
- var specs = urlForImage_1.SPEC_NAME_TO_URL_NAME_MAPPINGS;
392
- for (var _i = 0, specs_1 = specs; _i < specs_1.length; _i++) {
393
- var entry = specs_1[_i];
394
- var specName = entry[0],
395
- param = entry[1];
396
- if (key === specName || key === param) {
397
- return specName;
428
+ var client = options;
429
+ if (isSanityClientLike(client)) {
430
+ var _b = client.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
+ });
398
436
  }
437
+ return new ImageUrlBuilder(null, options);
399
438
  }
400
- return key;
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.url = function() {
519
+ return (0, urlForImage_1.default)(this.options);
520
+ }, ImageUrlBuilder2.prototype.toString = function() {
521
+ return this.url();
522
+ }, ImageUrlBuilder2;
523
+ }()
524
+ );
525
+ return builder.ImageUrlBuilder = ImageUrlBuilder, builder;
401
526
  }
402
- function urlBuilder(options) {
403
- // Did we get a modernish client?
404
- if (isSanityModernClientLike(options)) {
405
- // Inherit config from client
406
- var _a = options.config(),
407
- apiUrl = _a.apiHost,
408
- projectId = _a.projectId,
409
- dataset = _a.dataset;
410
- var apiHost = apiUrl || 'https://api.sanity.io';
411
- return new ImageUrlBuilder(null, {
412
- baseUrl: apiHost.replace(/^https:\/\/api\./, 'https://cdn.'),
413
- projectId: projectId,
414
- dataset: dataset
415
- });
416
- }
417
- // Did we get a SanityClient?
418
- var client = options;
419
- if (isSanityClientLike(client)) {
420
- // Inherit config from client
421
- var _b = client.clientConfig,
422
- apiUrl = _b.apiHost,
423
- projectId = _b.projectId,
424
- dataset = _b.dataset;
425
- var apiHost = apiUrl || 'https://api.sanity.io';
426
- return new ImageUrlBuilder(null, {
427
- baseUrl: apiHost.replace(/^https:\/\/api\./, 'https://cdn.'),
428
- projectId: projectId,
429
- dataset: dataset
430
- });
431
- }
432
- // Or just accept the options as given
433
- return new ImageUrlBuilder(null, options);
527
+ var node, hasRequiredNode;
528
+ function requireNode() {
529
+ if (hasRequiredNode) return node;
530
+ hasRequiredNode = 1;
531
+ var __importDefault = node && node.__importDefault || function(mod) {
532
+ return mod && mod.__esModule ? mod : { default: mod };
533
+ }, builder_1 = __importDefault(requireBuilder());
534
+ return node = builder_1.default, node;
434
535
  }
435
- builder.default = urlBuilder;
436
- var ImageUrlBuilder = /** @class */function () {
437
- function ImageUrlBuilder(parent, options) {
438
- this.options = parent ? __assign(__assign({}, parent.options || {}), options || {}) : __assign({}, options || {}); // Copy options
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 = /*@__PURE__*/getDefaultExportFromCjs(node);
536
+ var nodeExports = /* @__PURE__ */ requireNode(), createImageUrlBuilder = /* @__PURE__ */ getDefaultExportFromCjs(nodeExports);
660
537
  function useImageUrlBuilder(clientOptions) {
661
538
  const client = useClient(clientOptions);
662
- const builder = useMemo(() => createImageUrlBuilder(client), [client]);
663
- return builder;
539
+ return useMemo(() => createImageUrlBuilder(client), [client]);
664
540
  }
665
541
  function useImageUrlBuilderImage(source, clientOptions) {
666
- const builder = useImageUrlBuilder(clientOptions);
667
- const image = useMemo(() => source && builder ? builder.image(source) : null, [builder, source]);
668
- return image;
542
+ const builder2 = useImageUrlBuilder(clientOptions);
543
+ return useMemo(
544
+ () => source && builder2 ? builder2.image(source) : null,
545
+ [builder2, source]
546
+ );
669
547
  }
670
- const DEFAULT_PARAMS = {};
671
- const DEFAULT_OPTIONS = {
672
- apiVersion: "v2023-05-01"
673
- };
674
- const DEFAULT_INITIAL_VALUE = null;
548
+ const DEFAULT_PARAMS = {}, DEFAULT_OPTIONS = { apiVersion: "v2023-05-01" }, DEFAULT_INITIAL_VALUE = null;
675
549
  function useParams(params) {
676
- const stringifiedParams = useMemo(() => JSON.stringify(params || {}), [params]);
550
+ const stringifiedParams = useMemo(
551
+ () => JSON.stringify(params || {}),
552
+ [params]
553
+ );
677
554
  return useMemo(() => JSON.parse(stringifiedParams), [stringifiedParams]);
678
555
  }
679
- function useListeningQuery(query, _ref) {
680
- let {
681
- params = DEFAULT_PARAMS,
682
- options = DEFAULT_OPTIONS,
683
- initialValue = DEFAULT_INITIAL_VALUE
684
- } = _ref;
685
- const [loading, setLoading] = useState(true);
686
- const [error, setError] = useState(false);
687
- const [data, setData] = useState(initialValue);
688
- const memoParams = useParams(params);
689
- const memoOptions = useParams(options);
690
- const subscription = useRef(null);
691
- const documentStore = useDocumentStore();
692
- useEffect(() => {
693
- if (query && !error && !subscription.current) {
556
+ function useListeningQuery(query, {
557
+ params = DEFAULT_PARAMS,
558
+ options = DEFAULT_OPTIONS,
559
+ initialValue = DEFAULT_INITIAL_VALUE
560
+ }) {
561
+ const [loading, setLoading] = useState(!0), [error, setError] = useState(!1), [data, setData] = useState(initialValue), memoParams = useParams(params), memoOptions = useParams(options), subscription = useRef(null), documentStore = useDocumentStore();
562
+ return useEffect(() => {
563
+ if (query && !error && !subscription.current)
694
564
  try {
695
- subscription.current = documentStore.listenQuery(query, memoParams, memoOptions).pipe(distinctUntilChanged(isEqual), catchError(err => {
696
- console.error(err);
697
- setError(err);
698
- setLoading(false);
699
- setData(null);
700
- return err;
701
- })).subscribe(documents => {
702
- setData(current => isEqual(current, documents) ? current : documents);
703
- setLoading(false);
704
- setError(false);
565
+ subscription.current = documentStore.listenQuery(query, memoParams, memoOptions).pipe(
566
+ distinctUntilChanged(isEqual),
567
+ catchError((err) => (console.error(err), setError(err), setLoading(!1), setData(null), err))
568
+ ).subscribe((documents) => {
569
+ setData(
570
+ (current) => isEqual(current, documents) ? current : documents
571
+ ), setLoading(!1), setError(!1);
705
572
  });
706
573
  } catch (err) {
707
- console.error(err);
708
- setLoading(false);
709
- setError(err);
574
+ console.error(err), setLoading(!1), setError(err);
710
575
  }
711
- }
712
- if (error && subscription.current) {
713
- subscription.current.unsubscribe();
714
- }
715
- return () => {
576
+ return error && subscription.current && subscription.current.unsubscribe(), () => {
716
577
  var _a;
717
- if (subscription.current) {
718
- (_a = subscription == null ? void 0 : subscription.current) == null ? void 0 : _a.unsubscribe();
719
- subscription.current = null;
720
- }
578
+ subscription.current && ((_a = subscription == null ? void 0 : subscription.current) == null || _a.unsubscribe(), subscription.current = null);
721
579
  };
722
- }, [query, error, memoParams, memoOptions, documentStore]);
723
- return {
724
- data,
725
- loading,
726
- error
727
- };
728
- }
729
- function useProjectUsers(_ref2) {
730
- let {
731
- apiVersion
732
- } = _ref2;
733
- const {
734
- currentUser
735
- } = useWorkspace();
736
- const client = useClient({
737
- apiVersion: apiVersion != null ? apiVersion : "2023-01-01"
738
- });
739
- const [users, setUsers] = useState([]);
740
- useEffect(() => {
741
- const {
742
- projectId
743
- } = client.config();
744
- async function getUser(id) {
745
- const userDetails = await client.request({
746
- url: "/projects/".concat(projectId, "/users/").concat(id)
747
- });
748
- return userDetails;
749
- }
750
- async function getUsersWithRoles() {
751
- const userRoles = await client.request({
752
- url: "/projects/".concat(projectId, "/acl")
753
- }).then(async res => Promise.all(res.map(async user => ({
754
- isCurrentUser: user.projectUserId === (currentUser == null ? void 0 : currentUser.id),
755
- ...(await getUser(user.projectUserId))
756
- })))).catch(err => err);
757
- setUsers(userRoles);
758
- }
759
- if (!users.length) {
760
- getUsersWithRoles();
761
- }
762
- }, [client, currentUser == null ? void 0 : currentUser.id, users.length]);
763
- return users;
580
+ }, [query, error, memoParams, memoOptions, documentStore]), { data, loading, error };
764
581
  }
765
582
  function useOpenInNewPane(id, type) {
766
- const routerContext = React.useContext(RouterContext);
767
- const {
768
- routerPanesState,
769
- groupIndex
770
- } = usePaneRouter();
771
- const openInNewPane = React.useCallback(() => {
772
- if (!routerContext || !id || !type) {
583
+ const routerContext = useContext(RouterContext), { routerPanesState, groupIndex } = usePaneRouter();
584
+ return useCallback(() => {
585
+ if (!routerContext || !id || !type)
773
586
  return;
774
- }
775
587
  const panes = [...routerPanesState];
776
- panes.splice(groupIndex + 1, 0, [{
777
- id,
778
- params: {
779
- type
588
+ panes.splice(groupIndex + 1, 0, [
589
+ {
590
+ id,
591
+ params: { type }
780
592
  }
781
- }]);
782
- const href = routerContext.resolvePathFromState({
783
- panes
784
- });
785
- routerContext.navigateUrl({
786
- path: href
787
- });
593
+ ]);
594
+ const href = routerContext.resolvePathFromState({ panes });
595
+ routerContext.navigateUrl({ path: href });
788
596
  }, [id, type, routerContext, routerPanesState, groupIndex]);
789
- return openInNewPane;
790
- }
791
- const DEFAULT_PROPS = {
792
- tone: "primary"
793
- };
794
- function Feedback(props) {
795
- const {
796
- title,
797
- description,
798
- icon,
799
- tone,
800
- children
801
- } = {
802
- ...DEFAULT_PROPS,
803
- ...props
804
- };
805
- return /* @__PURE__ */jsx(Card, {
806
- tone,
807
- padding: 4,
808
- radius: 3,
809
- border: true,
810
- children: /* @__PURE__ */jsxs(Flex, {
811
- children: [icon ? "display icon" : null, children ? children : /* @__PURE__ */jsx(Box, {
812
- flex: 1,
813
- children: /* @__PURE__ */jsxs(Stack, {
814
- space: 4,
815
- children: [title ? /* @__PURE__ */jsx(Text, {
816
- weight: "semibold",
817
- children: title
818
- }) : null, description ? /* @__PURE__ */jsx(Text, {
819
- size: 2,
820
- children: description
821
- }) : null]
822
- })
823
- })]
824
- })
825
- });
826
597
  }
827
- var __freeze = Object.freeze;
828
- var __defProp = Object.defineProperty;
829
- var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", {
830
- value: __freeze(cooked.slice())
831
- }));
832
- var _a, _b, _c;
833
- const TableWrapper = function () {
834
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
835
- return /* @__PURE__ */jsx(Card, {
836
- as: "table",
837
- ...props
838
- });
839
- };
840
- const StyledTable = styled(TableWrapper)(() => css(_a || (_a = __template(["\n display: table;\n width: 100%;\n border-collapse: collapse;\n\n &:not([hidden]) {\n display: table;\n border-collapse: collapse;\n }\n "]))));
841
- function Table(props) {
842
- const {
843
- children,
844
- ...rest
845
- } = props;
846
- return /* @__PURE__ */jsx(StyledTable, {
847
- ...rest,
848
- children
849
- });
598
+ var __defProp = Object.defineProperty, __defProps = Object.defineProperties, __getOwnPropDescs = Object.getOwnPropertyDescriptors, __getOwnPropSymbols = Object.getOwnPropertySymbols, __hasOwnProp = Object.prototype.hasOwnProperty, __propIsEnum = Object.prototype.propertyIsEnumerable, __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues = (a, b) => {
599
+ for (var prop in b || (b = {}))
600
+ __hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
601
+ if (__getOwnPropSymbols)
602
+ for (var prop of __getOwnPropSymbols(b))
603
+ __propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
604
+ return a;
605
+ }, __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
606
+ function chunkArray(array, size) {
607
+ const chunks = [];
608
+ for (let i = 0; i < array.length; i += size)
609
+ chunks.push(array.slice(i, i + size));
610
+ return chunks;
850
611
  }
851
- const RowWrapper = function () {
852
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
853
- return /* @__PURE__ */jsx(Card, {
854
- as: "tr",
855
- ...props
856
- });
857
- };
858
- const StyledRow = styled(RowWrapper)(() => css(_b || (_b = __template(["\n display: table-row;\n\n &:not([hidden]) {\n display: table-row;\n }\n "]))));
859
- function Row(props) {
860
- const {
861
- children,
862
- ...rest
863
- } = props;
864
- return /* @__PURE__ */jsx(StyledRow, {
865
- ...rest,
866
- children
867
- });
868
- }
869
- const CellWrapper = function () {
870
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
871
- return /* @__PURE__ */jsx(Card, {
872
- as: "td",
873
- ...props
874
- });
875
- };
876
- const StyledCell = styled(CellWrapper)(() => css(_c || (_c = __template(["\n display: table-cell;\n\n &:not([hidden]) {\n display: table-cell;\n }\n "]))));
877
- function Cell(props) {
878
- const {
879
- children,
880
- ...rest
881
- } = props;
882
- return /* @__PURE__ */jsx(StyledCell, {
883
- ...rest,
884
- children
885
- });
886
- }
887
- function searchUsers(users, searchString) {
888
- return users.filter(user => {
889
- const displayName = (user.displayName || "").toLowerCase();
890
- if (displayName.startsWith(searchString)) return true;
891
- const givenName = (user.givenName || "").toLowerCase();
892
- if (givenName.startsWith(searchString)) return true;
893
- const middleName = (user.middleName || "").toLowerCase();
894
- if (middleName.startsWith(searchString)) return true;
895
- const familyName = (user.familyName || "").toLowerCase();
896
- if (familyName.startsWith(searchString)) return true;
897
- return false;
898
- });
612
+ function useProjectUsers({ apiVersion }) {
613
+ const { currentUser } = useWorkspace(), client = useClient({ apiVersion: apiVersion != null ? apiVersion : "2023-01-01" }), [users, setUsers] = useState([]);
614
+ return useEffect(() => {
615
+ const { projectId } = client.config();
616
+ async function getUsersWithRoles() {
617
+ try {
618
+ const aclData = await client.request({
619
+ url: `/projects/${projectId}/acl`
620
+ }), userIds = aclData.map((user) => user.projectUserId), userIdChunks = chunkArray(userIds, 200);
621
+ let usersData = [];
622
+ for (const chunk of userIdChunks) {
623
+ const chunkedUserIds = chunk.join(","), response = await client.request({
624
+ url: `/projects/${projectId}/users/${chunkedUserIds}`
625
+ });
626
+ usersData = [...usersData, ...response];
627
+ }
628
+ const usersWithRoles = usersData.map((user) => {
629
+ var _a;
630
+ const userRoles = ((_a = aclData.find(
631
+ (aclUser) => aclUser.projectUserId === user.id
632
+ )) == null ? void 0 : _a.roles) || [];
633
+ return __spreadProps(__spreadValues({}, user), {
634
+ isCurrentUser: user.id === (currentUser == null ? void 0 : currentUser.id),
635
+ roles: userRoles
636
+ });
637
+ });
638
+ setUsers(usersWithRoles);
639
+ } catch (err) {
640
+ console.error("Failed to fetch users:", err);
641
+ }
642
+ }
643
+ users.length || getUsersWithRoles();
644
+ }, [client, currentUser == null ? void 0 : currentUser.id, users.length]), users;
899
645
  }
900
- const LABELS = {
901
- addMe: "Assign myself",
902
- removeMe: "Unassign myself",
903
- clear: "Clear assignees",
904
- searchPlaceholder: "Search users",
905
- notFound: "No users found"
646
+ export {
647
+ Cell,
648
+ Feedback,
649
+ Row,
650
+ Table,
651
+ UserSelectMenu,
652
+ useImageUrlBuilder,
653
+ useImageUrlBuilderImage,
654
+ useListeningQuery,
655
+ useOpenInNewPane,
656
+ useProjectUsers
906
657
  };
907
- function UserSelectMenu(props) {
908
- const {
909
- value = [],
910
- userList = [],
911
- onAdd,
912
- onRemove,
913
- onClear,
914
- style = {}
915
- } = props;
916
- const labels = (props == null ? void 0 : props.labels) ? {
917
- ...LABELS,
918
- ...props.labels
919
- } : LABELS;
920
- const [searchString, setSearchString] = React.useState("");
921
- const searchResults = searchUsers(userList || [], searchString);
922
- const me = userList.find(u => u.isCurrentUser);
923
- const meAssigned = me && value.includes(me.id);
924
- const input = useRef(null);
925
- const handleSearchChange = event => {
926
- setSearchString(event.target.value);
927
- };
928
- const handleSelect = (isChecked, user) => {
929
- if (!isChecked) {
930
- if (onAdd) onAdd(user.id);
931
- } else if (onRemove) onRemove(user.id);
932
- };
933
- const handleAssignMyself = () => {
934
- if (me && onAdd) onAdd(me.id);
935
- };
936
- const handleUnassignMyself = () => {
937
- if (me && onRemove) onRemove(me.id);
938
- };
939
- const handleClearAssigneesClick = () => {
940
- if (onClear) onClear();
941
- };
942
- return /* @__PURE__ */jsxs(Menu, {
943
- style,
944
- children: [meAssigned ? /* @__PURE__ */jsx(MenuItem, {
945
- tone: "caution",
946
- disabled: !me,
947
- onClick: handleUnassignMyself,
948
- icon: RemoveCircleIcon,
949
- text: labels.removeMe
950
- }) : /* @__PURE__ */jsx(MenuItem, {
951
- tone: "positive",
952
- onClick: handleAssignMyself,
953
- icon: AddCircleIcon,
954
- text: labels.addMe
955
- }), /* @__PURE__ */jsx(MenuItem, {
956
- tone: "critical",
957
- disabled: value.length === 0,
958
- onClick: handleClearAssigneesClick,
959
- icon: RestoreIcon,
960
- text: labels.clear
961
- }), /* @__PURE__ */jsx(Box, {
962
- padding: 1,
963
- children: /* @__PURE__ */jsx(TextInput, {
964
- ref: input,
965
- onChange: handleSearchChange,
966
- placeholder: labels.searchPlaceholder,
967
- value: searchString
968
- })
969
- }), searchString && (searchResults == null ? void 0 : searchResults.length) === 0 && /* @__PURE__ */jsx(MenuItem, {
970
- disabled: true,
971
- text: labels.notFound
972
- }), searchResults && searchResults.map(user => /* @__PURE__ */jsx(MenuItem, {
973
- pressed: value.includes(user.id),
974
- onClick: () => handleSelect(value.indexOf(user.id) > -1, user),
975
- children: /* @__PURE__ */jsxs(Flex, {
976
- align: "center",
977
- children: [/* @__PURE__ */jsx(UserAvatar, {
978
- user,
979
- size: 1
980
- }), /* @__PURE__ */jsx(Box, {
981
- paddingX: 2,
982
- flex: 1,
983
- children: /* @__PURE__ */jsx(Text, {
984
- children: user.displayName
985
- })
986
- }), user.isCurrentUser && /* @__PURE__ */jsx(Badge, {
987
- fontSize: 1,
988
- tone: "positive",
989
- mode: "outline",
990
- children: "Me"
991
- })]
992
- })
993
- }, user.id))]
994
- });
995
- }
996
- export { Cell, Feedback, Row, Table, UserSelectMenu, useImageUrlBuilder, useImageUrlBuilderImage, useListeningQuery, useOpenInNewPane, useProjectUsers };
997
658
  //# sourceMappingURL=index.js.map