sanity-plugin-iconify 1.1.1 → 1.1.2

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