sanity-plugin-iconify 1.1.1 → 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 +14 -6
- package/dist/index.cjs +278 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +222 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.js +216 -399
- package/dist/index.js.map +1 -1
- package/package.json +53 -56
- package/src/combobox/iconify-combobox.styles.tsx +3 -3
- package/src/combobox/iconify-combobox.tsx +5 -4
- package/src/combobox/search-input.tsx +7 -4
- package/src/combobox/search-result.tsx +7 -7
- package/src/combobox/unset-button.tsx +1 -1
- package/src/iconify-input.tsx +12 -10
- package/src/iconify-plugin.tsx +3 -2
- package/src/iconify-preview.tsx +4 -3
- package/src/lib/api.ts +2 -2
- package/src/lib/query-client.tsx +1 -1
- package/src/lib/types.ts +1 -1
- package/src/lib/use-pretty-icon-name.ts +2 -1
- package/dist/index.esm.js +0 -459
- package/dist/index.esm.js.map +0 -1
- package/src/lib/{generate-types.ts → generate-types.js} +1 -1
package/dist/index.js
CHANGED
|
@@ -1,100 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var react$2 = require('@iconify/react');
|
|
16
|
-
var icons = require('@sanity/icons');
|
|
17
|
-
var utils = require('@iconify/utils');
|
|
18
|
-
var changeCase = require('change-case');
|
|
19
|
-
function _interopDefaultCompat(e) {
|
|
20
|
-
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
21
|
-
default: e
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
var styled__default = /*#__PURE__*/_interopDefaultCompat(styled);
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { unset, set, definePlugin } from "sanity";
|
|
3
|
+
import { Grid, Box, Card, Text, TextInput, Button, useToast, Popover, ThemeProvider, Stack, Flex } from "@sanity/ui";
|
|
4
|
+
import { buildTheme } from "@sanity/ui/theme";
|
|
5
|
+
import { useState, useCallback, forwardRef, useId, useRef, useEffect, useMemo } from "react";
|
|
6
|
+
import { ComboboxInput, ComboboxOptions, ComboboxOption, Combobox } from "@headlessui/react";
|
|
7
|
+
import { match } from "ts-pattern";
|
|
8
|
+
import { useQueryClient, useQuery, keepPreviousData, QueryClient, QueryClientProvider as QueryClientProvider$1 } from "@tanstack/react-query";
|
|
9
|
+
import { useDebounce } from "use-debounce";
|
|
10
|
+
import styled from "styled-components";
|
|
11
|
+
import { Icon } from "@iconify/react";
|
|
12
|
+
import { TrashIcon } from "@sanity/icons";
|
|
13
|
+
import { stringToIcon } from "@iconify/utils";
|
|
14
|
+
import { sentenceCase } from "change-case";
|
|
25
15
|
const BASE_API_URL = "https://api.iconify.design";
|
|
26
|
-
function fetchJson(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} = _ref;
|
|
31
|
-
return fetch(url, {
|
|
32
|
-
signal
|
|
33
|
-
}).then(response => {
|
|
34
|
-
if (!response.ok) {
|
|
35
|
-
throw new Error("Network error: status ".concat(response.status));
|
|
36
|
-
}
|
|
16
|
+
function fetchJson({ url, signal }) {
|
|
17
|
+
return fetch(url, { signal }).then((response) => {
|
|
18
|
+
if (!response.ok)
|
|
19
|
+
throw new Error(`Network error: status ${response.status}`);
|
|
37
20
|
return response.json();
|
|
38
|
-
}).then(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
console.error("Unknown error: ".concat(error));
|
|
43
|
-
throw new Error("Something went wrong");
|
|
21
|
+
}).then(
|
|
22
|
+
(result) => result,
|
|
23
|
+
(error) => {
|
|
24
|
+
throw error instanceof Error ? error : (console.error(`Unknown error: ${error}`), new Error("Something went wrong"));
|
|
44
25
|
}
|
|
45
|
-
|
|
26
|
+
);
|
|
46
27
|
}
|
|
47
|
-
function useSearch(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const updateTerm = react.useCallback(function (newTerm) {
|
|
55
|
-
let updateImmediately = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
56
|
-
setTerm(newTerm);
|
|
57
|
-
if (updateImmediately) {
|
|
58
|
-
setDebouncedTerm(newTerm);
|
|
59
|
-
}
|
|
60
|
-
}, [setDebouncedTerm]);
|
|
61
|
-
const {
|
|
62
|
-
isLoading,
|
|
63
|
-
isError,
|
|
64
|
-
error,
|
|
65
|
-
data,
|
|
66
|
-
isPlaceholderData
|
|
67
|
-
} = reactQuery.useQuery({
|
|
28
|
+
function useSearch({ collections }) {
|
|
29
|
+
const queryClient2 = useQueryClient(), [term, setTerm] = useState(""), [debouncedTerm, setDebouncedTerm] = useDebounce(term, 500), updateTerm = useCallback(
|
|
30
|
+
(newTerm, updateImmediately = !1) => {
|
|
31
|
+
setTerm(newTerm), updateImmediately && setDebouncedTerm(newTerm);
|
|
32
|
+
},
|
|
33
|
+
[setDebouncedTerm]
|
|
34
|
+
), { isLoading, isError, error, data, isPlaceholderData } = useQuery({
|
|
68
35
|
queryKey: ["search", collections, debouncedTerm],
|
|
69
|
-
queryFn: async
|
|
70
|
-
let {
|
|
71
|
-
signal
|
|
72
|
-
} = _ref3;
|
|
36
|
+
queryFn: async ({ signal }) => {
|
|
73
37
|
var _a;
|
|
74
38
|
const url = new URL("/search", BASE_API_URL);
|
|
75
|
-
url.searchParams.append("query", debouncedTerm);
|
|
76
|
-
url
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
const result = debouncedTerm ? await fetchJson({
|
|
81
|
-
url,
|
|
82
|
-
signal
|
|
83
|
-
}) : null;
|
|
84
|
-
if (result) {
|
|
85
|
-
Object.entries(result.collections).forEach(_ref4 => {
|
|
86
|
-
let [prefix, info] = _ref4;
|
|
87
|
-
queryClient.setQueryData(["iconSetInfo", prefix], info);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
return (_a = result == null ? void 0 : result.icons) != null ? _a : [];
|
|
39
|
+
url.searchParams.append("query", debouncedTerm), url.searchParams.append("limit", "60"), collections && url.searchParams.append("prefixes", collections.join(","));
|
|
40
|
+
const result = debouncedTerm ? await fetchJson({ url, signal }) : null;
|
|
41
|
+
return result && Object.entries(result.collections).forEach(([prefix, info]) => {
|
|
42
|
+
queryClient2.setQueryData(["iconSetInfo", prefix], info);
|
|
43
|
+
}), (_a = result == null ? void 0 : result.icons) != null ? _a : [];
|
|
91
44
|
},
|
|
92
45
|
enabled: debouncedTerm.length > 0,
|
|
93
|
-
placeholderData:
|
|
46
|
+
placeholderData: keepPreviousData,
|
|
94
47
|
staleTime: 5 * 60 * 1e3
|
|
95
48
|
// 5 minutes
|
|
96
49
|
});
|
|
97
|
-
|
|
98
50
|
return {
|
|
99
51
|
term,
|
|
100
52
|
setTerm: updateTerm,
|
|
@@ -106,365 +58,230 @@ function useSearch(_ref2) {
|
|
|
106
58
|
isPreviousData: isPlaceholderData
|
|
107
59
|
};
|
|
108
60
|
}
|
|
109
|
-
function useIconSetInfo(
|
|
110
|
-
|
|
111
|
-
prefix
|
|
112
|
-
} = _ref5;
|
|
113
|
-
return reactQuery.useQuery({
|
|
61
|
+
function useIconSetInfo({ prefix }) {
|
|
62
|
+
return useQuery({
|
|
114
63
|
queryKey: ["iconSetInfo", prefix],
|
|
115
|
-
queryFn: async
|
|
116
|
-
let {
|
|
117
|
-
signal
|
|
118
|
-
} = _ref6;
|
|
64
|
+
queryFn: async ({ signal }) => {
|
|
119
65
|
var _a;
|
|
120
66
|
if (!prefix) return null;
|
|
121
67
|
const url = new URL("/collection", BASE_API_URL);
|
|
122
|
-
url.searchParams.append("prefix", prefix);
|
|
123
|
-
url
|
|
124
|
-
const result = await fetchJson({
|
|
125
|
-
url,
|
|
126
|
-
signal
|
|
127
|
-
});
|
|
68
|
+
url.searchParams.append("prefix", prefix), url.searchParams.append("info", "true");
|
|
69
|
+
const result = await fetchJson({ url, signal });
|
|
128
70
|
return (_a = result == null ? void 0 : result.info) != null ? _a : null;
|
|
129
71
|
},
|
|
130
|
-
staleTime:
|
|
72
|
+
staleTime: 1 / 0
|
|
131
73
|
});
|
|
132
74
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
75
|
+
const ComboboxWrapper = styled(Grid)`
|
|
76
|
+
grid-template-columns: 1fr min-content;
|
|
77
|
+
position: relative;
|
|
78
|
+
`, OptionsWrapper = styled(Box)`
|
|
79
|
+
box-sizing: border-box;
|
|
80
|
+
padding: 0.5rem;
|
|
81
|
+
|
|
82
|
+
& [role='listbox'] {
|
|
83
|
+
display: grid;
|
|
84
|
+
grid-template-columns: repeat(auto-fill, minmax(min(100%, 2.5rem), 1fr));
|
|
85
|
+
gap: 0.5rem;
|
|
86
|
+
margin: 0;
|
|
87
|
+
padding: 0;
|
|
88
|
+
list-style: none;
|
|
89
|
+
|
|
90
|
+
@media (min-width: 650px) {
|
|
91
|
+
grid-template-columns: repeat(10, minmax(min(100%, 2.5rem), 1fr));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
& [role='option'] {
|
|
96
|
+
display: grid;
|
|
97
|
+
place-items: center;
|
|
98
|
+
|
|
99
|
+
& button {
|
|
100
|
+
cursor: pointer;
|
|
101
|
+
aspect-ratio: 1;
|
|
102
|
+
width: 100%;
|
|
103
|
+
|
|
104
|
+
& > [data-ui='Box'] {
|
|
105
|
+
display: flex;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
`;
|
|
110
|
+
function MessageWrapper({ children }) {
|
|
111
|
+
return /* @__PURE__ */ jsx(Card, { padding: 4, children: /* @__PURE__ */ jsx(Text, { align: "center", muted: !0, children }) });
|
|
153
112
|
}
|
|
154
|
-
const SearchInput =
|
|
155
|
-
const {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
placeholder: selectedIcon ? "Search and replace selected icon..." : "Search for an icon..."
|
|
170
|
-
});
|
|
113
|
+
const SearchInput = forwardRef((props, ref) => {
|
|
114
|
+
const { term, selectedIcon, onChange, suffix } = props;
|
|
115
|
+
return /* @__PURE__ */ jsx(
|
|
116
|
+
ComboboxInput,
|
|
117
|
+
{
|
|
118
|
+
as: TextInput,
|
|
119
|
+
ref,
|
|
120
|
+
inputMode: "search",
|
|
121
|
+
value: term,
|
|
122
|
+
onChange,
|
|
123
|
+
icon: selectedIcon ? /* @__PURE__ */ jsx(Icon, { icon: selectedIcon }) : null,
|
|
124
|
+
placeholder: selectedIcon ? "Search and replace selected icon..." : "Search for an icon...",
|
|
125
|
+
suffix
|
|
126
|
+
}
|
|
127
|
+
);
|
|
171
128
|
});
|
|
172
129
|
SearchInput.displayName = "SearchInput";
|
|
173
130
|
function SearchResults(props) {
|
|
174
|
-
const {
|
|
175
|
-
|
|
176
|
-
data
|
|
177
|
-
} = props;
|
|
178
|
-
if (state === "initial") {
|
|
179
|
-
return /* @__PURE__ */jsxRuntime.jsx(MessageWrapper, {
|
|
180
|
-
children: "Search for icons"
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
if (state === "loading") {
|
|
184
|
-
return /* @__PURE__ */jsxRuntime.jsx(MessageWrapper, {
|
|
185
|
-
children: "Searching..."
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
if (state === "error") {
|
|
189
|
-
return /* @__PURE__ */jsxRuntime.jsx(MessageWrapper, {
|
|
190
|
-
children: "Something went wrong..."
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
if (state === "empty") {
|
|
194
|
-
return /* @__PURE__ */jsxRuntime.jsx(MessageWrapper, {
|
|
195
|
-
children: "No icons found"
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
return /* @__PURE__ */jsxRuntime.jsx(react$1.Combobox.Options, {
|
|
199
|
-
style: {
|
|
200
|
-
opacity: state === "stale" ? 0.5 : 1
|
|
201
|
-
},
|
|
202
|
-
children: data.map(icon => /* @__PURE__ */jsxRuntime.jsx(react$1.Combobox.Option, {
|
|
203
|
-
value: icon,
|
|
204
|
-
children: _ref8 => {
|
|
205
|
-
let {
|
|
206
|
-
active
|
|
207
|
-
} = _ref8;
|
|
208
|
-
return /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
209
|
-
padding: 3,
|
|
210
|
-
mode: "bleed",
|
|
211
|
-
selected: active,
|
|
212
|
-
children: /* @__PURE__ */jsxRuntime.jsx(react$2.Icon, {
|
|
213
|
-
icon,
|
|
214
|
-
width: "100%",
|
|
215
|
-
height: "100%"
|
|
216
|
-
})
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
}, icon))
|
|
220
|
-
});
|
|
131
|
+
const { state, data } = props;
|
|
132
|
+
return state === "initial" ? /* @__PURE__ */ jsx(MessageWrapper, { children: "Search for icons" }) : state === "loading" ? /* @__PURE__ */ jsx(MessageWrapper, { children: "Searching..." }) : state === "error" ? /* @__PURE__ */ jsx(MessageWrapper, { children: "Something went wrong..." }) : state === "empty" ? /* @__PURE__ */ jsx(MessageWrapper, { children: "No icons found" }) : /* @__PURE__ */ jsx(ComboboxOptions, { style: { opacity: state === "stale" ? 0.5 : 1 }, children: data.map((icon) => /* @__PURE__ */ jsx(ComboboxOption, { value: icon, children: ({ focus }) => /* @__PURE__ */ jsx(Button, { padding: 3, mode: "bleed", selected: focus, children: /* @__PURE__ */ jsx(Icon, { icon, width: "100%", height: "100%" }) }) }, icon)) });
|
|
221
133
|
}
|
|
222
134
|
function UnsetButton(props) {
|
|
223
|
-
const {
|
|
224
|
-
|
|
225
|
-
} = props;
|
|
226
|
-
return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
227
|
-
border: true,
|
|
228
|
-
borderLeft: false,
|
|
229
|
-
padding: 1,
|
|
230
|
-
display: "flex",
|
|
231
|
-
children: /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
232
|
-
icon: /* @__PURE__ */jsxRuntime.jsx(icons.TrashIcon, {}),
|
|
233
|
-
onClick: onUnset,
|
|
234
|
-
mode: "bleed",
|
|
235
|
-
fontSize: 1,
|
|
236
|
-
padding: 2
|
|
237
|
-
})
|
|
238
|
-
});
|
|
135
|
+
const { onUnset } = props;
|
|
136
|
+
return /* @__PURE__ */ jsx(Card, { border: !0, borderLeft: !1, padding: 1, display: "flex", radius: 2, children: /* @__PURE__ */ jsx(Button, { icon: /* @__PURE__ */ jsx(TrashIcon, {}), onClick: onUnset, mode: "bleed", fontSize: 1, padding: 2 }) });
|
|
239
137
|
}
|
|
240
138
|
function IconifyCombobox(props) {
|
|
241
|
-
const {
|
|
242
|
-
selectedIcon,
|
|
243
|
-
onSelect: pushSelection,
|
|
139
|
+
const { selectedIcon, onSelect: pushSelection, collections } = props, id = useId(), toast = useToast(), inputRef = useRef(null), { term, setTerm, debouncedTerm, isLoading, isError, error, data, isPreviousData } = useSearch({
|
|
244
140
|
collections
|
|
245
|
-
} =
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
error,
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
toast.push({
|
|
271
|
-
id,
|
|
272
|
-
status: "error",
|
|
273
|
-
title: "Iconify input error",
|
|
274
|
-
description: error == null ? void 0 : error.message
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
}, [error, id, isError, toast]);
|
|
278
|
-
return /* @__PURE__ */jsxRuntime.jsxs(ComboboxWrapper, {
|
|
279
|
-
children: [/* @__PURE__ */jsxRuntime.jsx(react$1.Combobox, {
|
|
280
|
-
onChange: handleSelect,
|
|
281
|
-
children: _ref9 => {
|
|
282
|
-
let {
|
|
283
|
-
open
|
|
284
|
-
} = _ref9;
|
|
285
|
-
return /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
286
|
-
children: [/* @__PURE__ */jsxRuntime.jsx(SearchInput, {
|
|
287
|
-
ref: inputRef,
|
|
288
|
-
term,
|
|
289
|
-
selectedIcon,
|
|
290
|
-
onChange: handleTermChange
|
|
291
|
-
}), /* @__PURE__ */jsxRuntime.jsx(ui.Popover, {
|
|
292
|
-
open,
|
|
293
|
-
placement: "bottom",
|
|
294
|
-
arrow: false,
|
|
295
|
-
matchReferenceWidth: true,
|
|
296
|
-
portal: true,
|
|
297
|
-
constrainSize: true,
|
|
298
|
-
referenceElement: inputRef.current,
|
|
299
|
-
content: /* @__PURE__ */jsxRuntime.jsx(OptionsWrapper, {
|
|
300
|
-
children: /* @__PURE__ */jsxRuntime.jsx(SearchResults, {
|
|
301
|
-
state: tsPattern.match(true).returnType().with(isLoading, () => "loading").with(!debouncedTerm, () => "initial").with(isError, () => "error").with(!data || data.length === 0, () => "empty").with(isPreviousData, () => "stale").otherwise(() => "data"),
|
|
302
|
-
data
|
|
303
|
-
})
|
|
304
|
-
})
|
|
305
|
-
})]
|
|
306
|
-
});
|
|
141
|
+
}), handleTermChange = useCallback(
|
|
142
|
+
(event) => setTerm(event.target.value),
|
|
143
|
+
[setTerm]
|
|
144
|
+
), handleSelect = useCallback(
|
|
145
|
+
(icon) => {
|
|
146
|
+
pushSelection(icon), setTerm("", !0);
|
|
147
|
+
},
|
|
148
|
+
[pushSelection, setTerm]
|
|
149
|
+
), handleUnset = useCallback(() => handleSelect(""), [handleSelect]);
|
|
150
|
+
return useEffect(() => {
|
|
151
|
+
isError && (console.error("Iconify input error:", error), toast.push({
|
|
152
|
+
id,
|
|
153
|
+
status: "error",
|
|
154
|
+
title: "Iconify input error",
|
|
155
|
+
description: error == null ? void 0 : error.message
|
|
156
|
+
}));
|
|
157
|
+
}, [error, id, isError, toast]), /* @__PURE__ */ jsx(ComboboxWrapper, { children: /* @__PURE__ */ jsx(Combobox, { onChange: handleSelect, children: ({ open }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
158
|
+
/* @__PURE__ */ jsx(
|
|
159
|
+
SearchInput,
|
|
160
|
+
{
|
|
161
|
+
ref: inputRef,
|
|
162
|
+
term,
|
|
163
|
+
selectedIcon,
|
|
164
|
+
onChange: handleTermChange,
|
|
165
|
+
suffix: selectedIcon ? /* @__PURE__ */ jsx(UnsetButton, { onUnset: handleUnset }) : null
|
|
307
166
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
167
|
+
),
|
|
168
|
+
/* @__PURE__ */ jsx(
|
|
169
|
+
Popover,
|
|
170
|
+
{
|
|
171
|
+
open,
|
|
172
|
+
placement: "bottom",
|
|
173
|
+
arrow: !1,
|
|
174
|
+
matchReferenceWidth: !0,
|
|
175
|
+
portal: !0,
|
|
176
|
+
constrainSize: !0,
|
|
177
|
+
referenceElement: inputRef.current,
|
|
178
|
+
content: /* @__PURE__ */ jsx(OptionsWrapper, { children: /* @__PURE__ */ jsx(
|
|
179
|
+
SearchResults,
|
|
180
|
+
{
|
|
181
|
+
state: match(!0).returnType().with(isLoading, () => "loading").with(!debouncedTerm, () => "initial").with(isError, () => "error").with(!data || data.length === 0, () => "empty").with(isPreviousData, () => "stale").otherwise(() => "data"),
|
|
182
|
+
data
|
|
183
|
+
}
|
|
184
|
+
) })
|
|
185
|
+
}
|
|
186
|
+
)
|
|
187
|
+
] }) }) });
|
|
312
188
|
}
|
|
313
|
-
const queryClient = new
|
|
189
|
+
const queryClient = new QueryClient();
|
|
314
190
|
function QueryClientProvider(props) {
|
|
315
|
-
return /* @__PURE__ */
|
|
316
|
-
client: queryClient,
|
|
317
|
-
children: props.children
|
|
318
|
-
});
|
|
191
|
+
return /* @__PURE__ */ jsx(QueryClientProvider$1, { client: queryClient, children: props.children });
|
|
319
192
|
}
|
|
320
193
|
function usePrettyIconName(props) {
|
|
321
194
|
var _a, _b;
|
|
322
|
-
const {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
195
|
+
const { name } = props, iconMeta = useMemo(
|
|
196
|
+
() => {
|
|
197
|
+
var _a2;
|
|
198
|
+
return (_a2 = props.iconMeta) != null ? _a2 : name ? stringToIcon(name) : null;
|
|
199
|
+
},
|
|
200
|
+
[name, props.iconMeta]
|
|
201
|
+
), iconSetInfo = useIconSetInfo({ prefix: (_a = iconMeta == null ? void 0 : iconMeta.prefix) != null ? _a : null });
|
|
202
|
+
return useMemo(
|
|
203
|
+
() => {
|
|
204
|
+
var _a2, _b2;
|
|
205
|
+
return iconMeta ? {
|
|
206
|
+
name: sentenceCase(iconMeta.name),
|
|
207
|
+
collection: (_b2 = (_a2 = iconSetInfo.data) == null ? void 0 : _a2.name) != null ? _b2 : iconMeta.prefix
|
|
208
|
+
} : null;
|
|
209
|
+
},
|
|
210
|
+
[iconMeta, (_b = iconSetInfo.data) == null ? void 0 : _b.name]
|
|
211
|
+
);
|
|
339
212
|
}
|
|
340
213
|
function IconifyInput(props) {
|
|
341
214
|
var _a, _b, _c, _d, _e;
|
|
342
|
-
const {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}, [pushChange]);
|
|
360
|
-
return /* @__PURE__ */jsxRuntime.jsx(QueryClientProvider, {
|
|
361
|
-
children: /* @__PURE__ */jsxRuntime.jsx(ui.ThemeProvider, {
|
|
362
|
-
theme,
|
|
363
|
-
children: /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
|
|
364
|
-
space: 2,
|
|
365
|
-
children: [/* @__PURE__ */jsxRuntime.jsx(IconifyCombobox, {
|
|
366
|
-
selectedIcon,
|
|
367
|
-
onSelect: handleSelect,
|
|
368
|
-
collections
|
|
369
|
-
}), showName && selectedIcon ? /* @__PURE__ */jsxRuntime.jsx(IconifyNameDisplay, {
|
|
370
|
-
name: selectedIcon
|
|
371
|
-
}) : null]
|
|
372
|
-
})
|
|
373
|
-
})
|
|
374
|
-
});
|
|
215
|
+
const { config, value, onChange: pushChange, schemaType } = props, selectedIcon = (_a = value == null ? void 0 : value.name) != null ? _a : null, options = schemaType.options, collections = !!((_b = options == null ? void 0 : options.collections) != null && _b.length) && options.collections || !!((_c = config == null ? void 0 : config.collections) != null && _c.length) && config.collections || null, showName = (_e = (_d = options == null ? void 0 : options.showName) != null ? _d : config == null ? void 0 : config.showName) != null ? _e : !1, handleSelect = useCallback(
|
|
216
|
+
(icon) => {
|
|
217
|
+
pushChange(icon === "" ? unset() : set(icon, ["name"]));
|
|
218
|
+
},
|
|
219
|
+
[pushChange]
|
|
220
|
+
);
|
|
221
|
+
return /* @__PURE__ */ jsx(QueryClientProvider, { children: /* @__PURE__ */ jsx(ThemeProvider, { theme: buildTheme(), children: /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
222
|
+
/* @__PURE__ */ jsx(
|
|
223
|
+
IconifyCombobox,
|
|
224
|
+
{
|
|
225
|
+
selectedIcon,
|
|
226
|
+
onSelect: handleSelect,
|
|
227
|
+
collections
|
|
228
|
+
}
|
|
229
|
+
),
|
|
230
|
+
showName && selectedIcon ? /* @__PURE__ */ jsx(IconifyNameDisplay, { name: selectedIcon }) : null
|
|
231
|
+
] }) }) });
|
|
375
232
|
}
|
|
376
233
|
function IconifyNameDisplay(props) {
|
|
377
234
|
var _a;
|
|
378
|
-
const {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
size: 1,
|
|
388
|
-
muted: true,
|
|
389
|
-
children: "Selected:"
|
|
390
|
-
}), /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
|
|
391
|
-
size: 1,
|
|
392
|
-
weight: "semibold",
|
|
393
|
-
children: (_a = prettyName == null ? void 0 : prettyName.name) != null ? _a : name
|
|
394
|
-
}), (prettyName == null ? void 0 : prettyName.collection) && /* @__PURE__ */jsxRuntime.jsxs(ui.Text, {
|
|
395
|
-
size: 1,
|
|
396
|
-
muted: true,
|
|
397
|
-
style: {
|
|
398
|
-
fontStyle: "italic"
|
|
399
|
-
},
|
|
400
|
-
children: ["by ", prettyName == null ? void 0 : prettyName.collection]
|
|
401
|
-
})]
|
|
402
|
-
});
|
|
235
|
+
const { name } = props, prettyName = usePrettyIconName({ name });
|
|
236
|
+
return /* @__PURE__ */ jsxs(Flex, { gap: 1, children: [
|
|
237
|
+
/* @__PURE__ */ jsx(Text, { size: 1, muted: !0, children: "Selected:" }),
|
|
238
|
+
/* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: (_a = prettyName == null ? void 0 : prettyName.name) != null ? _a : name }),
|
|
239
|
+
(prettyName == null ? void 0 : prettyName.collection) && /* @__PURE__ */ jsxs(Text, { size: 1, muted: !0, style: { fontStyle: "italic" }, children: [
|
|
240
|
+
"by ",
|
|
241
|
+
prettyName == null ? void 0 : prettyName.collection
|
|
242
|
+
] })
|
|
243
|
+
] });
|
|
403
244
|
}
|
|
404
245
|
function IconifyPreview(props) {
|
|
405
|
-
const {
|
|
406
|
-
|
|
407
|
-
} = props;
|
|
408
|
-
const iconName = typeof props.title === "string" ? utils.stringToIcon(props.title) : null;
|
|
409
|
-
if (typeof title === "string" && iconName) {
|
|
410
|
-
return /* @__PURE__ */jsxRuntime.jsx(QueryClientProvider, {
|
|
411
|
-
children: /* @__PURE__ */jsxRuntime.jsx(IconifyPreviewInner, {
|
|
412
|
-
...props,
|
|
413
|
-
iconName: title,
|
|
414
|
-
iconMeta: iconName
|
|
415
|
-
})
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
return props.renderDefault(props);
|
|
246
|
+
const { title } = props, iconName = typeof props.title == "string" ? stringToIcon(props.title) : null;
|
|
247
|
+
return typeof title == "string" && iconName ? /* @__PURE__ */ jsx(QueryClientProvider, { children: /* @__PURE__ */ jsx(IconifyPreviewInner, { ...props, iconName: title, iconMeta: iconName }) }) : props.renderDefault(props);
|
|
419
248
|
}
|
|
420
249
|
function IconifyPreviewInner(props) {
|
|
421
250
|
var _a;
|
|
422
|
-
const {
|
|
423
|
-
iconMeta,
|
|
424
|
-
iconName,
|
|
425
|
-
...previewProps
|
|
426
|
-
} = props;
|
|
427
|
-
const prettyName = usePrettyIconName({
|
|
428
|
-
iconMeta
|
|
429
|
-
});
|
|
251
|
+
const { iconMeta, iconName, ...previewProps } = props, prettyName = usePrettyIconName({ iconMeta });
|
|
430
252
|
return props.renderDefault({
|
|
431
253
|
...previewProps,
|
|
432
|
-
media: /* @__PURE__ */
|
|
433
|
-
icon: iconName
|
|
434
|
-
}),
|
|
254
|
+
media: /* @__PURE__ */ jsx(Icon, { icon: iconName }),
|
|
435
255
|
title: (_a = prettyName == null ? void 0 : prettyName.name) != null ? _a : iconName,
|
|
436
256
|
subtitle: prettyName == null ? void 0 : prettyName.collection
|
|
437
257
|
});
|
|
438
258
|
}
|
|
439
|
-
const iconify =
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
types: [{
|
|
259
|
+
const iconify = definePlugin((config = {}) => ({
|
|
260
|
+
name: "sanity-plugin-iconify",
|
|
261
|
+
schema: {
|
|
262
|
+
types: [
|
|
263
|
+
{
|
|
445
264
|
name: "icon",
|
|
446
265
|
title: "Icon",
|
|
447
266
|
type: "object",
|
|
448
|
-
fields: [
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
267
|
+
fields: [
|
|
268
|
+
{
|
|
269
|
+
name: "name",
|
|
270
|
+
title: "Name",
|
|
271
|
+
type: "string"
|
|
272
|
+
}
|
|
273
|
+
],
|
|
453
274
|
components: {
|
|
454
|
-
input: props => /* @__PURE__ */
|
|
455
|
-
...props,
|
|
456
|
-
config
|
|
457
|
-
}),
|
|
275
|
+
input: (props) => /* @__PURE__ */ jsx(IconifyInput, { ...props, config }),
|
|
458
276
|
preview: IconifyPreview,
|
|
459
277
|
// This makes sure the input component is not indented
|
|
460
|
-
field: props => props.renderDefault({
|
|
461
|
-
...props,
|
|
462
|
-
level: 0
|
|
463
|
-
})
|
|
278
|
+
field: (props) => props.renderDefault({ ...props, level: 0 })
|
|
464
279
|
}
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
|
|
280
|
+
}
|
|
281
|
+
]
|
|
282
|
+
}
|
|
283
|
+
}));
|
|
284
|
+
export {
|
|
285
|
+
iconify
|
|
286
|
+
};
|
|
470
287
|
//# sourceMappingURL=index.js.map
|