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