sanity-plugin-utils 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -6
- package/lib/index.cjs +76 -78
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +2 -4
- package/lib/index.d.ts +2 -4
- package/lib/index.js +75 -78
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/hooks/useImageUrlBuilder.tsx +1 -1
- package/src/hooks/useImageUrlBuilderImage.tsx +1 -1
package/README.md
CHANGED
package/lib/index.cjs
CHANGED
|
@@ -4,19 +4,15 @@ var jsxRuntime = require("react/jsx-runtime"), ui = require("@sanity/ui"), style
|
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
7
|
-
var isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual)
|
|
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
|
-
};
|
|
7
|
+
var isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual);
|
|
15
8
|
const DEFAULT_PROPS = {
|
|
16
9
|
tone: "primary"
|
|
17
10
|
};
|
|
18
11
|
function Feedback(props) {
|
|
19
|
-
const { title, description, icon, tone, children } =
|
|
12
|
+
const { title, description, icon, tone, children } = {
|
|
13
|
+
...DEFAULT_PROPS,
|
|
14
|
+
...props
|
|
15
|
+
};
|
|
20
16
|
return /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { tone, padding: 4, radius: 3, border: !0, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { children: [
|
|
21
17
|
icon ? "display icon" : null,
|
|
22
18
|
children || /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 4, children: [
|
|
@@ -25,23 +21,7 @@ function Feedback(props) {
|
|
|
25
21
|
] }) })
|
|
26
22
|
] }) });
|
|
27
23
|
}
|
|
28
|
-
|
|
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)(
|
|
24
|
+
const TableWrapper = (props = {}) => /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { as: "table", ...props }), StyledTable = styledComponents.styled(TableWrapper)(
|
|
45
25
|
() => styledComponents.css`
|
|
46
26
|
display: table;
|
|
47
27
|
width: 100%;
|
|
@@ -54,10 +34,10 @@ const TableWrapper = (props = {}) => /* @__PURE__ */ jsxRuntime.jsx(ui.Card, __s
|
|
|
54
34
|
`
|
|
55
35
|
);
|
|
56
36
|
function Table(props) {
|
|
57
|
-
const
|
|
58
|
-
return /* @__PURE__ */ jsxRuntime.jsx(StyledTable,
|
|
37
|
+
const { children, ...rest } = props;
|
|
38
|
+
return /* @__PURE__ */ jsxRuntime.jsx(StyledTable, { ...rest, children });
|
|
59
39
|
}
|
|
60
|
-
const RowWrapper = (props = {}) => /* @__PURE__ */ jsxRuntime.jsx(ui.Card,
|
|
40
|
+
const RowWrapper = (props = {}) => /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { as: "tr", ...props }), StyledRow = styledComponents.styled(RowWrapper)(
|
|
61
41
|
() => styledComponents.css`
|
|
62
42
|
display: table-row;
|
|
63
43
|
|
|
@@ -67,10 +47,10 @@ const RowWrapper = (props = {}) => /* @__PURE__ */ jsxRuntime.jsx(ui.Card, __spr
|
|
|
67
47
|
`
|
|
68
48
|
);
|
|
69
49
|
function Row(props) {
|
|
70
|
-
const
|
|
71
|
-
return /* @__PURE__ */ jsxRuntime.jsx(StyledRow,
|
|
50
|
+
const { children, ...rest } = props;
|
|
51
|
+
return /* @__PURE__ */ jsxRuntime.jsx(StyledRow, { ...rest, children });
|
|
72
52
|
}
|
|
73
|
-
const CellWrapper = (props = {}) => /* @__PURE__ */ jsxRuntime.jsx(ui.Card,
|
|
53
|
+
const CellWrapper = (props = {}) => /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { as: "td", ...props }), StyledCell = styledComponents.styled(CellWrapper)(
|
|
74
54
|
() => styledComponents.css`
|
|
75
55
|
display: table-cell;
|
|
76
56
|
|
|
@@ -80,17 +60,9 @@ const CellWrapper = (props = {}) => /* @__PURE__ */ jsxRuntime.jsx(ui.Card, __sp
|
|
|
80
60
|
`
|
|
81
61
|
);
|
|
82
62
|
function Cell(props) {
|
|
83
|
-
const
|
|
84
|
-
return /* @__PURE__ */ jsxRuntime.jsx(StyledCell,
|
|
63
|
+
const { children, ...rest } = props;
|
|
64
|
+
return /* @__PURE__ */ jsxRuntime.jsx(StyledCell, { ...rest, children });
|
|
85
65
|
}
|
|
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;
|
|
93
|
-
};
|
|
94
66
|
function searchUsers(users, searchString) {
|
|
95
67
|
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
68
|
}
|
|
@@ -109,7 +81,7 @@ function UserSelectMenu(props) {
|
|
|
109
81
|
onRemove,
|
|
110
82
|
onClear,
|
|
111
83
|
style = {}
|
|
112
|
-
} = props, labels = props
|
|
84
|
+
} = props, labels = props?.labels ? { ...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
85
|
setSearchString(event.target.value);
|
|
114
86
|
}, handleSelect = (isChecked, user) => {
|
|
115
87
|
isChecked ? onRemove && onRemove(user.id) : onAdd && onAdd(user.id);
|
|
@@ -158,7 +130,7 @@ function UserSelectMenu(props) {
|
|
|
158
130
|
value: searchString
|
|
159
131
|
}
|
|
160
132
|
) }),
|
|
161
|
-
searchString &&
|
|
133
|
+
searchString && searchResults?.length === 0 && /* @__PURE__ */ jsxRuntime.jsx(ui.MenuItem, { disabled: !0, text: labels.notFound }),
|
|
162
134
|
searchResults && searchResults.map((user) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
163
135
|
ui.MenuItem,
|
|
164
136
|
{
|
|
@@ -206,7 +178,7 @@ function requireParseSource() {
|
|
|
206
178
|
return t;
|
|
207
179
|
}, __assign.apply(this, arguments);
|
|
208
180
|
};
|
|
209
|
-
Object.defineProperty(parseSource, "__esModule", { value: !0 });
|
|
181
|
+
Object.defineProperty(parseSource, "__esModule", { value: !0 }), parseSource.isInProgressUpload = void 0;
|
|
210
182
|
var isRef = function(src) {
|
|
211
183
|
var source = src;
|
|
212
184
|
return source ? typeof source._ref == "string" : !1;
|
|
@@ -216,7 +188,14 @@ function requireParseSource() {
|
|
|
216
188
|
}, isAssetStub = function(src) {
|
|
217
189
|
var source = src;
|
|
218
190
|
return source && source.asset ? typeof source.asset.url == "string" : !1;
|
|
191
|
+
}, isInProgressUpload = function(src) {
|
|
192
|
+
if (typeof src == "object" && src !== null) {
|
|
193
|
+
var obj = src;
|
|
194
|
+
return obj._upload && (!obj.asset || !obj.asset._ref);
|
|
195
|
+
}
|
|
196
|
+
return !1;
|
|
219
197
|
};
|
|
198
|
+
parseSource.isInProgressUpload = isInProgressUpload;
|
|
220
199
|
function parseSource$1(source) {
|
|
221
200
|
if (!source)
|
|
222
201
|
return null;
|
|
@@ -280,7 +259,7 @@ function requireParseSource() {
|
|
|
280
259
|
}
|
|
281
260
|
var hasRequiredUrlForImage;
|
|
282
261
|
function requireUrlForImage() {
|
|
283
|
-
return hasRequiredUrlForImage || (hasRequiredUrlForImage = 1, function(
|
|
262
|
+
return hasRequiredUrlForImage || (hasRequiredUrlForImage = 1, function(exports$1) {
|
|
284
263
|
var __assign = urlForImage && urlForImage.__assign || function() {
|
|
285
264
|
return __assign = Object.assign || function(t) {
|
|
286
265
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -289,12 +268,29 @@ function requireUrlForImage() {
|
|
|
289
268
|
}
|
|
290
269
|
return t;
|
|
291
270
|
}, __assign.apply(this, arguments);
|
|
271
|
+
}, __createBinding = urlForImage && urlForImage.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
272
|
+
k2 === void 0 && (k2 = k);
|
|
273
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
274
|
+
(!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) && (desc = { enumerable: !0, get: function() {
|
|
275
|
+
return m[k];
|
|
276
|
+
} }), Object.defineProperty(o, k2, desc);
|
|
277
|
+
} : function(o, m, k, k2) {
|
|
278
|
+
k2 === void 0 && (k2 = k), o[k2] = m[k];
|
|
279
|
+
}), __setModuleDefault = urlForImage && urlForImage.__setModuleDefault || (Object.create ? function(o, v) {
|
|
280
|
+
Object.defineProperty(o, "default", { enumerable: !0, value: v });
|
|
281
|
+
} : function(o, v) {
|
|
282
|
+
o.default = v;
|
|
283
|
+
}), __importStar = urlForImage && urlForImage.__importStar || function(mod) {
|
|
284
|
+
if (mod && mod.__esModule) return mod;
|
|
285
|
+
var result = {};
|
|
286
|
+
if (mod != null) for (var k in mod) k !== "default" && Object.prototype.hasOwnProperty.call(mod, k) && __createBinding(result, mod, k);
|
|
287
|
+
return __setModuleDefault(result, mod), result;
|
|
292
288
|
}, __importDefault = urlForImage && urlForImage.__importDefault || function(mod) {
|
|
293
289
|
return mod && mod.__esModule ? mod : { default: mod };
|
|
294
290
|
};
|
|
295
|
-
Object.defineProperty(
|
|
296
|
-
var parseAssetId_1 = __importDefault(requireParseAssetId()), parseSource_1 =
|
|
297
|
-
|
|
291
|
+
Object.defineProperty(exports$1, "__esModule", { value: !0 }), exports$1.parseSource = exports$1.SPEC_NAME_TO_URL_NAME_MAPPINGS = void 0;
|
|
292
|
+
var parseAssetId_1 = __importDefault(requireParseAssetId()), parseSource_1 = __importStar(requireParseSource());
|
|
293
|
+
exports$1.parseSource = parseSource_1.default, exports$1.SPEC_NAME_TO_URL_NAME_MAPPINGS = [
|
|
298
294
|
["width", "w"],
|
|
299
295
|
["height", "h"],
|
|
300
296
|
["format", "fm"],
|
|
@@ -313,14 +309,18 @@ function requireUrlForImage() {
|
|
|
313
309
|
["saturation", "sat"],
|
|
314
310
|
["auto", "auto"],
|
|
315
311
|
["dpr", "dpr"],
|
|
316
|
-
["pad", "pad"]
|
|
312
|
+
["pad", "pad"],
|
|
313
|
+
["frame", "frame"]
|
|
317
314
|
];
|
|
318
315
|
function urlForImage$1(options) {
|
|
319
316
|
var spec = __assign({}, options || {}), source = spec.source;
|
|
320
317
|
delete spec.source;
|
|
321
318
|
var image = (0, parseSource_1.default)(source);
|
|
322
|
-
if (!image)
|
|
319
|
+
if (!image) {
|
|
320
|
+
if (source && (0, parseSource_1.isInProgressUpload)(source))
|
|
321
|
+
return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8HwQACfsD/QNViZkAAAAASUVORK5CYII=";
|
|
323
322
|
throw new Error("Unable to resolve image URL from source (".concat(JSON.stringify(source), ")"));
|
|
323
|
+
}
|
|
324
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
325
|
left: cropLeft,
|
|
326
326
|
top: cropTop,
|
|
@@ -334,16 +334,16 @@ function requireUrlForImage() {
|
|
|
334
334
|
};
|
|
335
335
|
return spec.rect || spec.focalPoint || spec.ignoreImageParams || spec.crop || (spec = __assign(__assign({}, spec), fit({ crop, hotspot }, spec))), specToImageUrl(__assign(__assign({}, spec), { asset }));
|
|
336
336
|
}
|
|
337
|
-
|
|
337
|
+
exports$1.default = urlForImage$1;
|
|
338
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 = [];
|
|
339
|
+
var cdnUrl = (spec.baseUrl || "https://cdn.sanity.io").replace(/\/+$/, ""), vanityStub = spec.vanityName ? "/".concat(spec.vanityName) : "", filename = "".concat(spec.asset.id, "-").concat(spec.asset.width, "x").concat(spec.asset.height, ".").concat(spec.asset.format).concat(vanityStub), baseUrl = "".concat(cdnUrl, "/images/").concat(spec.projectId, "/").concat(spec.dataset, "/").concat(filename), params = [];
|
|
340
340
|
if (spec.rect) {
|
|
341
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
342
|
isEffectiveCrop && params.push("rect=".concat(left, ",").concat(top_1, ",").concat(width, ",").concat(height));
|
|
343
343
|
}
|
|
344
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
345
|
var flip = [spec.flipHorizontal && "h", spec.flipVertical && "v"].filter(Boolean).join("");
|
|
346
|
-
return flip && params.push("flip=".concat(flip)),
|
|
346
|
+
return flip && params.push("flip=".concat(flip)), exports$1.SPEC_NAME_TO_URL_NAME_MAPPINGS.forEach(function(mapping) {
|
|
347
347
|
var specName = mapping[0], param = mapping[1];
|
|
348
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
349
|
}), params.length === 0 ? baseUrl : "".concat(baseUrl, "?").concat(params.join("&"));
|
|
@@ -381,9 +381,11 @@ function requireBuilder() {
|
|
|
381
381
|
return t;
|
|
382
382
|
}, __assign.apply(this, arguments);
|
|
383
383
|
}, __createBinding = builder && builder.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
384
|
-
k2 === void 0 && (k2 = k)
|
|
384
|
+
k2 === void 0 && (k2 = k);
|
|
385
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
386
|
+
(!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) && (desc = { enumerable: !0, get: function() {
|
|
385
387
|
return m[k];
|
|
386
|
-
} });
|
|
388
|
+
} }), Object.defineProperty(o, k2, desc);
|
|
387
389
|
} : function(o, m, k, k2) {
|
|
388
390
|
k2 === void 0 && (k2 = k), o[k2] = m[k];
|
|
389
391
|
}), __setModuleDefault = builder && builder.__setModuleDefault || (Object.create ? function(o, v) {
|
|
@@ -421,16 +423,15 @@ function requireBuilder() {
|
|
|
421
423
|
dataset
|
|
422
424
|
});
|
|
423
425
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
var _b = client.clientConfig, apiUrl = _b.apiHost, projectId = _b.projectId, dataset = _b.dataset, apiHost = apiUrl || "https://api.sanity.io";
|
|
426
|
+
if (isSanityClientLike(options)) {
|
|
427
|
+
var _b = options.clientConfig, apiUrl = _b.apiHost, projectId = _b.projectId, dataset = _b.dataset, apiHost = apiUrl || "https://api.sanity.io";
|
|
427
428
|
return new ImageUrlBuilder(null, {
|
|
428
429
|
baseUrl: apiHost.replace(/^https:\/\/api\./, "https://cdn."),
|
|
429
430
|
projectId,
|
|
430
431
|
dataset
|
|
431
432
|
});
|
|
432
433
|
}
|
|
433
|
-
return new ImageUrlBuilder(null, options);
|
|
434
|
+
return new ImageUrlBuilder(null, options || {});
|
|
434
435
|
}
|
|
435
436
|
builder.default = urlBuilder;
|
|
436
437
|
var ImageUrlBuilder = (
|
|
@@ -511,6 +512,12 @@ function requireBuilder() {
|
|
|
511
512
|
return this.withOptions({ auto: value });
|
|
512
513
|
}, ImageUrlBuilder2.prototype.pad = function(pad) {
|
|
513
514
|
return this.withOptions({ pad });
|
|
515
|
+
}, ImageUrlBuilder2.prototype.vanityName = function(value) {
|
|
516
|
+
return this.withOptions({ vanityName: value });
|
|
517
|
+
}, ImageUrlBuilder2.prototype.frame = function(frame) {
|
|
518
|
+
if (frame !== 1)
|
|
519
|
+
throw new Error('Invalid frame value "'.concat(frame, '"'));
|
|
520
|
+
return this.withOptions({ frame });
|
|
514
521
|
}, ImageUrlBuilder2.prototype.url = function() {
|
|
515
522
|
return (0, urlForImage_1.default)(this.options);
|
|
516
523
|
}, ImageUrlBuilder2.prototype.toString = function() {
|
|
@@ -570,8 +577,7 @@ function useListeningQuery(query, {
|
|
|
570
577
|
console.error(err), setLoading(!1), setError(err);
|
|
571
578
|
}
|
|
572
579
|
return error && subscription.current && subscription.current.unsubscribe(), () => {
|
|
573
|
-
|
|
574
|
-
subscription.current && ((_a = subscription == null ? void 0 : subscription.current) == null || _a.unsubscribe(), subscription.current = null);
|
|
580
|
+
subscription.current && (subscription?.current?.unsubscribe(), subscription.current = null);
|
|
575
581
|
};
|
|
576
582
|
}, [query, error, memoParams, memoOptions, documentStore]), { data, loading, error };
|
|
577
583
|
}
|
|
@@ -591,14 +597,6 @@ function useOpenInNewPane(id, type) {
|
|
|
591
597
|
routerContext.navigateUrl({ path: href });
|
|
592
598
|
}, [id, type, routerContext, routerPanesState, groupIndex]);
|
|
593
599
|
}
|
|
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));
|
|
602
600
|
function chunkArray(array, size) {
|
|
603
601
|
const chunks = [];
|
|
604
602
|
for (let i = 0; i < array.length; i += size)
|
|
@@ -606,7 +604,7 @@ function chunkArray(array, size) {
|
|
|
606
604
|
return chunks;
|
|
607
605
|
}
|
|
608
606
|
function useProjectUsers({ apiVersion }) {
|
|
609
|
-
const { currentUser } = sanity.useWorkspace(), client = sanity.useClient({ apiVersion: apiVersion
|
|
607
|
+
const { currentUser } = sanity.useWorkspace(), client = sanity.useClient({ apiVersion: apiVersion ?? "2023-01-01" }), [users, setUsers] = react.useState([]);
|
|
610
608
|
return react.useEffect(() => {
|
|
611
609
|
const { projectId } = client.config();
|
|
612
610
|
async function getUsersWithRoles() {
|
|
@@ -622,14 +620,14 @@ function useProjectUsers({ apiVersion }) {
|
|
|
622
620
|
usersData = [...usersData, ...response];
|
|
623
621
|
}
|
|
624
622
|
const usersWithRoles = usersData.map((user) => {
|
|
625
|
-
|
|
626
|
-
const userRoles = ((_a = aclData.find(
|
|
623
|
+
const userRoles = aclData.find(
|
|
627
624
|
(aclUser) => aclUser.projectUserId === user.id
|
|
628
|
-
)
|
|
629
|
-
return
|
|
630
|
-
|
|
625
|
+
)?.roles || [];
|
|
626
|
+
return {
|
|
627
|
+
...user,
|
|
628
|
+
isCurrentUser: user.id === currentUser?.id,
|
|
631
629
|
roles: userRoles
|
|
632
|
-
}
|
|
630
|
+
};
|
|
633
631
|
});
|
|
634
632
|
setUsers(usersWithRoles);
|
|
635
633
|
} catch (err) {
|
|
@@ -637,7 +635,7 @@ function useProjectUsers({ apiVersion }) {
|
|
|
637
635
|
}
|
|
638
636
|
}
|
|
639
637
|
users.length || getUsersWithRoles();
|
|
640
|
-
}, [client, currentUser
|
|
638
|
+
}, [client, currentUser?.id, users.length]), users;
|
|
641
639
|
}
|
|
642
640
|
exports.Cell = Cell;
|
|
643
641
|
exports.Feedback = Feedback;
|