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