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