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/dist/index.js CHANGED
@@ -1,100 +1,52 @@
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, 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(_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
- }
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(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");
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(_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({
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 _ref3 => {
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.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 : [];
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: reactQuery.keepPreviousData,
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(_ref5) {
110
- let {
111
- prefix
112
- } = _ref5;
113
- return reactQuery.useQuery({
61
+ function useIconSetInfo({ prefix }) {
62
+ return useQuery({
114
63
  queryKey: ["iconSetInfo", prefix],
115
- queryFn: async _ref6 => {
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.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
+ 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 = 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, 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
- 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
- });
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
- 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
- });
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
- } = 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({
259
- 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
- });
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
- }), selectedIcon ? /* @__PURE__ */jsxRuntime.jsx(UnsetButton, {
309
- onUnset: handleUnset
310
- }) : null]
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 reactQuery.QueryClient();
189
+ const queryClient = new QueryClient();
314
190
  function QueryClientProvider(props) {
315
- return /* @__PURE__ */jsxRuntime.jsx(reactQuery.QueryClientProvider, {
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
- 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]);
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
- 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
- });
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
- 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
- });
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
- 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);
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__ */jsxRuntime.jsx(react$2.Icon, {
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 = 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: [{
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
- name: "name",
450
- title: "Name",
451
- type: "string"
452
- }],
267
+ fields: [
268
+ {
269
+ name: "name",
270
+ title: "Name",
271
+ type: "string"
272
+ }
273
+ ],
453
274
  components: {
454
- input: props => /* @__PURE__ */jsxRuntime.jsx(IconifyInput, {
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
- exports.iconify = iconify;
280
+ }
281
+ ]
282
+ }
283
+ }));
284
+ export {
285
+ iconify
286
+ };
470
287
  //# sourceMappingURL=index.js.map