sanity-plugin-utils 1.7.0 → 2.0.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/LICENSE +1 -1
- package/README.md +10 -42
- package/dist/index.d.ts +95 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +343 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -74
- package/lib/index.cjs +0 -652
- package/lib/index.cjs.map +0 -1
- package/lib/index.d.cts +0 -132
- package/lib/index.d.ts +0 -132
- package/lib/index.js +0 -658
- package/lib/index.js.map +0 -1
- package/sanity.json +0 -8
- package/src/components/Feedback.tsx +0 -48
- package/src/components/Table.tsx +0 -83
- package/src/components/UserSelectMenu/index.tsx +0 -162
- package/src/hooks/useImageUrlBuilder.tsx +0 -13
- package/src/hooks/useImageUrlBuilderImage.tsx +0 -18
- package/src/hooks/useListeningQuery.tsx +0 -98
- package/src/hooks/useOpenInNewPane.tsx +0 -27
- package/src/hooks/useProjectUsers.tsx +0 -99
- package/src/index.ts +0 -9
- package/v2-incompatible.js +0 -11
package/lib/index.js
DELETED
|
@@ -1,658 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Card, Flex, Box, Stack, Text, Menu, MenuItem, TextInput, Badge } from "@sanity/ui";
|
|
3
|
-
import { styled, css } from "styled-components";
|
|
4
|
-
import { RemoveCircleIcon, AddCircleIcon, RestoreIcon } from "@sanity/icons";
|
|
5
|
-
import { useState, useRef, useMemo, useEffect, useContext, useCallback } from "react";
|
|
6
|
-
import { UserAvatar, useClient, useDocumentStore, useWorkspace } from "sanity";
|
|
7
|
-
import isEqual from "react-fast-compare";
|
|
8
|
-
import { distinctUntilChanged, catchError } from "rxjs/operators";
|
|
9
|
-
import { RouterContext } from "sanity/router";
|
|
10
|
-
import { usePaneRouter } from "sanity/structure";
|
|
11
|
-
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
|
-
] }) });
|
|
31
|
-
}
|
|
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 }));
|
|
63
|
-
}
|
|
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;
|
|
70
|
-
}
|
|
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;
|
|
97
|
-
};
|
|
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"
|
|
107
|
-
};
|
|
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
|
|
136
|
-
}
|
|
137
|
-
) : /* @__PURE__ */ jsx(
|
|
138
|
-
MenuItem,
|
|
139
|
-
{
|
|
140
|
-
tone: "positive",
|
|
141
|
-
onClick: handleAssignMyself,
|
|
142
|
-
icon: AddCircleIcon,
|
|
143
|
-
text: labels.addMe
|
|
144
|
-
}
|
|
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
|
|
154
|
-
}
|
|
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
|
|
163
|
-
}
|
|
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
|
-
] });
|
|
180
|
-
}
|
|
181
|
-
function getDefaultExportFromCjs(x) {
|
|
182
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x.default : x;
|
|
183
|
-
}
|
|
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;
|
|
199
|
-
}
|
|
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);
|
|
258
|
-
}
|
|
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 = {
|
|
272
|
-
left: 0,
|
|
273
|
-
top: 0,
|
|
274
|
-
bottom: 0,
|
|
275
|
-
right: 0
|
|
276
|
-
}), result.hotspot || (result.hotspot = {
|
|
277
|
-
x: 0.5,
|
|
278
|
-
y: 0.5,
|
|
279
|
-
height: 1,
|
|
280
|
-
width: 1
|
|
281
|
-
}), result;
|
|
282
|
-
}
|
|
283
|
-
return parseSource;
|
|
284
|
-
}
|
|
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 };
|
|
298
|
-
};
|
|
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 }));
|
|
340
|
-
}
|
|
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));
|
|
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("&"));
|
|
354
|
-
}
|
|
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 };
|
|
366
|
-
}
|
|
367
|
-
return {
|
|
368
|
-
width: imgWidth,
|
|
369
|
-
height: imgHeight,
|
|
370
|
-
rect: cropRect
|
|
371
|
-
};
|
|
372
|
-
}
|
|
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]);
|
|
384
|
-
}
|
|
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;
|
|
410
|
-
}
|
|
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;
|
|
416
|
-
}
|
|
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
|
-
});
|
|
427
|
-
}
|
|
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
|
-
});
|
|
436
|
-
}
|
|
437
|
-
return new ImageUrlBuilder(null, options);
|
|
438
|
-
}
|
|
439
|
-
builder.default = urlBuilder;
|
|
440
|
-
var ImageUrlBuilder = (
|
|
441
|
-
/** @class */
|
|
442
|
-
function() {
|
|
443
|
-
function ImageUrlBuilder2(parent, options) {
|
|
444
|
-
this.options = parent ? __assign(__assign({}, parent.options || {}), options || {}) : __assign({}, options || {});
|
|
445
|
-
}
|
|
446
|
-
return ImageUrlBuilder2.prototype.withOptions = function(options) {
|
|
447
|
-
var baseUrl = options.baseUrl || this.options.baseUrl, newOptions = { baseUrl };
|
|
448
|
-
for (var key in options)
|
|
449
|
-
if (options.hasOwnProperty(key)) {
|
|
450
|
-
var specKey = rewriteSpecName(key);
|
|
451
|
-
newOptions[specKey] = options[key];
|
|
452
|
-
}
|
|
453
|
-
return new ImageUrlBuilder2(this, __assign({ baseUrl }, newOptions));
|
|
454
|
-
}, ImageUrlBuilder2.prototype.image = function(source) {
|
|
455
|
-
return this.withOptions({ source });
|
|
456
|
-
}, ImageUrlBuilder2.prototype.dataset = function(dataset) {
|
|
457
|
-
return this.withOptions({ dataset });
|
|
458
|
-
}, ImageUrlBuilder2.prototype.projectId = function(projectId) {
|
|
459
|
-
return this.withOptions({ projectId });
|
|
460
|
-
}, ImageUrlBuilder2.prototype.bg = function(bg) {
|
|
461
|
-
return this.withOptions({ bg });
|
|
462
|
-
}, ImageUrlBuilder2.prototype.dpr = function(dpr) {
|
|
463
|
-
return this.withOptions(dpr && dpr !== 1 ? { dpr } : {});
|
|
464
|
-
}, ImageUrlBuilder2.prototype.width = function(width) {
|
|
465
|
-
return this.withOptions({ width });
|
|
466
|
-
}, ImageUrlBuilder2.prototype.height = function(height) {
|
|
467
|
-
return this.withOptions({ height });
|
|
468
|
-
}, ImageUrlBuilder2.prototype.focalPoint = function(x, y) {
|
|
469
|
-
return this.withOptions({ focalPoint: { x, y } });
|
|
470
|
-
}, ImageUrlBuilder2.prototype.maxWidth = function(maxWidth) {
|
|
471
|
-
return this.withOptions({ maxWidth });
|
|
472
|
-
}, ImageUrlBuilder2.prototype.minWidth = function(minWidth) {
|
|
473
|
-
return this.withOptions({ minWidth });
|
|
474
|
-
}, ImageUrlBuilder2.prototype.maxHeight = function(maxHeight) {
|
|
475
|
-
return this.withOptions({ maxHeight });
|
|
476
|
-
}, ImageUrlBuilder2.prototype.minHeight = function(minHeight) {
|
|
477
|
-
return this.withOptions({ minHeight });
|
|
478
|
-
}, ImageUrlBuilder2.prototype.size = function(width, height) {
|
|
479
|
-
return this.withOptions({ width, height });
|
|
480
|
-
}, ImageUrlBuilder2.prototype.blur = function(blur) {
|
|
481
|
-
return this.withOptions({ blur });
|
|
482
|
-
}, ImageUrlBuilder2.prototype.sharpen = function(sharpen) {
|
|
483
|
-
return this.withOptions({ sharpen });
|
|
484
|
-
}, ImageUrlBuilder2.prototype.rect = function(left, top, width, height) {
|
|
485
|
-
return this.withOptions({ rect: { left, top, width, height } });
|
|
486
|
-
}, ImageUrlBuilder2.prototype.format = function(format) {
|
|
487
|
-
return this.withOptions({ format });
|
|
488
|
-
}, ImageUrlBuilder2.prototype.invert = function(invert) {
|
|
489
|
-
return this.withOptions({ invert });
|
|
490
|
-
}, ImageUrlBuilder2.prototype.orientation = function(orientation) {
|
|
491
|
-
return this.withOptions({ orientation });
|
|
492
|
-
}, ImageUrlBuilder2.prototype.quality = function(quality) {
|
|
493
|
-
return this.withOptions({ quality });
|
|
494
|
-
}, ImageUrlBuilder2.prototype.forceDownload = function(download) {
|
|
495
|
-
return this.withOptions({ download });
|
|
496
|
-
}, ImageUrlBuilder2.prototype.flipHorizontal = function() {
|
|
497
|
-
return this.withOptions({ flipHorizontal: !0 });
|
|
498
|
-
}, ImageUrlBuilder2.prototype.flipVertical = function() {
|
|
499
|
-
return this.withOptions({ flipVertical: !0 });
|
|
500
|
-
}, ImageUrlBuilder2.prototype.ignoreImageParams = function() {
|
|
501
|
-
return this.withOptions({ ignoreImageParams: !0 });
|
|
502
|
-
}, ImageUrlBuilder2.prototype.fit = function(value) {
|
|
503
|
-
if (validFits.indexOf(value) === -1)
|
|
504
|
-
throw new Error('Invalid fit mode "'.concat(value, '"'));
|
|
505
|
-
return this.withOptions({ fit: value });
|
|
506
|
-
}, ImageUrlBuilder2.prototype.crop = function(value) {
|
|
507
|
-
if (validCrops.indexOf(value) === -1)
|
|
508
|
-
throw new Error('Invalid crop mode "'.concat(value, '"'));
|
|
509
|
-
return this.withOptions({ crop: value });
|
|
510
|
-
}, ImageUrlBuilder2.prototype.saturation = function(saturation) {
|
|
511
|
-
return this.withOptions({ saturation });
|
|
512
|
-
}, ImageUrlBuilder2.prototype.auto = function(value) {
|
|
513
|
-
if (validAutoModes.indexOf(value) === -1)
|
|
514
|
-
throw new Error('Invalid auto mode "'.concat(value, '"'));
|
|
515
|
-
return this.withOptions({ auto: value });
|
|
516
|
-
}, ImageUrlBuilder2.prototype.pad = function(pad) {
|
|
517
|
-
return this.withOptions({ pad });
|
|
518
|
-
}, ImageUrlBuilder2.prototype.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;
|
|
526
|
-
}
|
|
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;
|
|
535
|
-
}
|
|
536
|
-
var nodeExports = /* @__PURE__ */ requireNode(), createImageUrlBuilder = /* @__PURE__ */ getDefaultExportFromCjs(nodeExports);
|
|
537
|
-
function useImageUrlBuilder(clientOptions) {
|
|
538
|
-
const client = useClient(clientOptions);
|
|
539
|
-
return useMemo(() => createImageUrlBuilder(client), [client]);
|
|
540
|
-
}
|
|
541
|
-
function useImageUrlBuilderImage(source, clientOptions) {
|
|
542
|
-
const builder2 = useImageUrlBuilder(clientOptions);
|
|
543
|
-
return useMemo(
|
|
544
|
-
() => source && builder2 ? builder2.image(source) : null,
|
|
545
|
-
[builder2, source]
|
|
546
|
-
);
|
|
547
|
-
}
|
|
548
|
-
const DEFAULT_PARAMS = {}, DEFAULT_OPTIONS = { apiVersion: "v2023-05-01" }, DEFAULT_INITIAL_VALUE = null;
|
|
549
|
-
function useParams(params) {
|
|
550
|
-
const stringifiedParams = useMemo(
|
|
551
|
-
() => JSON.stringify(params || {}),
|
|
552
|
-
[params]
|
|
553
|
-
);
|
|
554
|
-
return useMemo(() => JSON.parse(stringifiedParams), [stringifiedParams]);
|
|
555
|
-
}
|
|
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)
|
|
564
|
-
try {
|
|
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);
|
|
572
|
-
});
|
|
573
|
-
} catch (err) {
|
|
574
|
-
console.error(err), setLoading(!1), setError(err);
|
|
575
|
-
}
|
|
576
|
-
return error && subscription.current && subscription.current.unsubscribe(), () => {
|
|
577
|
-
var _a;
|
|
578
|
-
subscription.current && ((_a = subscription == null ? void 0 : subscription.current) == null || _a.unsubscribe(), subscription.current = null);
|
|
579
|
-
};
|
|
580
|
-
}, [query, error, memoParams, memoOptions, documentStore]), { data, loading, error };
|
|
581
|
-
}
|
|
582
|
-
function useOpenInNewPane(id, type) {
|
|
583
|
-
const routerContext = useContext(RouterContext), { routerPanesState, groupIndex } = usePaneRouter();
|
|
584
|
-
return useCallback(() => {
|
|
585
|
-
if (!routerContext || !id || !type)
|
|
586
|
-
return;
|
|
587
|
-
const panes = [...routerPanesState];
|
|
588
|
-
panes.splice(groupIndex + 1, 0, [
|
|
589
|
-
{
|
|
590
|
-
id,
|
|
591
|
-
params: { type }
|
|
592
|
-
}
|
|
593
|
-
]);
|
|
594
|
-
const href = routerContext.resolvePathFromState({ panes });
|
|
595
|
-
routerContext.navigateUrl({ path: href });
|
|
596
|
-
}, [id, type, routerContext, routerPanesState, groupIndex]);
|
|
597
|
-
}
|
|
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;
|
|
611
|
-
}
|
|
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;
|
|
645
|
-
}
|
|
646
|
-
export {
|
|
647
|
-
Cell,
|
|
648
|
-
Feedback,
|
|
649
|
-
Row,
|
|
650
|
-
Table,
|
|
651
|
-
UserSelectMenu,
|
|
652
|
-
useImageUrlBuilder,
|
|
653
|
-
useImageUrlBuilderImage,
|
|
654
|
-
useListeningQuery,
|
|
655
|
-
useOpenInNewPane,
|
|
656
|
-
useProjectUsers
|
|
657
|
-
};
|
|
658
|
-
//# sourceMappingURL=index.js.map
|