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/LICENSE +1 -1
- package/dist/index.cjs +283 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +218 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +222 -401
- package/dist/index.js.map +1 -1
- package/package.json +50 -47
- package/src/combobox/iconify-combobox.tsx +1 -0
- package/src/combobox/search-result.tsx +1 -0
- package/src/iconify-input.tsx +3 -2
- package/src/iconify-plugin.tsx +2 -1
- package/src/iconify-preview.tsx +3 -2
- package/src/lib/api.ts +1 -0
- package/src/lib/{generate-types.ts → generate-types.js} +2 -1
- package/src/lib/use-pretty-icon-name.ts +1 -0
- package/dist/index.esm.js +0 -459
- package/dist/index.esm.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,100 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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(
|
|
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
|
-
}
|
|
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(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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(
|
|
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({
|
|
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
|
|
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
|
|
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 : [];
|
|
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:
|
|
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(
|
|
110
|
-
|
|
111
|
-
prefix
|
|
112
|
-
} = _ref5;
|
|
113
|
-
return reactQuery.useQuery({
|
|
60
|
+
function useIconSetInfo({ prefix }) {
|
|
61
|
+
return useQuery({
|
|
114
62
|
queryKey: ["iconSetInfo", prefix],
|
|
115
|
-
queryFn: async
|
|
116
|
-
let {
|
|
117
|
-
signal
|
|
118
|
-
} = _ref6;
|
|
63
|
+
queryFn: async ({ signal }) => {
|
|
119
64
|
var _a;
|
|
120
|
-
if (!prefix)
|
|
65
|
+
if (!prefix)
|
|
66
|
+
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
|
-
padding:
|
|
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
|
+
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 =
|
|
155
|
-
const {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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
|
|
190
|
+
const queryClient = new QueryClient();
|
|
314
191
|
function QueryClientProvider(props) {
|
|
315
|
-
return /* @__PURE__ */
|
|
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
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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
|
-
|
|
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
|
-
});
|
|
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
|
-
|
|
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__ */
|
|
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 =
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
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
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
271
|
+
fields: [
|
|
272
|
+
{
|
|
273
|
+
name: "name",
|
|
274
|
+
title: "Name",
|
|
275
|
+
type: "string"
|
|
276
|
+
}
|
|
277
|
+
],
|
|
453
278
|
components: {
|
|
454
|
-
input: props => /* @__PURE__ */
|
|
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
|
-
|
|
284
|
+
}
|
|
285
|
+
]
|
|
286
|
+
}
|
|
287
|
+
}));
|
|
288
|
+
export {
|
|
289
|
+
iconify
|
|
290
|
+
};
|
|
470
291
|
//# sourceMappingURL=index.js.map
|