@madebywild/sanity-icon-field 0.2.3 → 0.2.5

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.cjs CHANGED
@@ -1,46 +1,54 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var jsxRuntime = require("react/jsx-runtime"), sanity = require("sanity"), asyncAutocomplete = require("@madebywild/sanity-utils/async-autocomplete"), ui = require("@sanity/ui");
4
- function IconInput({
5
- pluginConfig,
6
- ...props
7
- }) {
3
+ var jsxRuntime = require("react/jsx-runtime"), sanity = require("sanity"), compilerRuntime = require("react/compiler-runtime"), asyncAutocomplete = require("@madebywild/sanity-utils/async-autocomplete"), ui = require("@sanity/ui");
4
+ function IconInput(t0) {
5
+ const $ = compilerRuntime.c(15);
6
+ let pluginConfig, props;
7
+ $[0] !== t0 ? ({
8
+ pluginConfig,
9
+ ...props
10
+ } = t0, $[0] = t0, $[1] = pluginConfig, $[2] = props) : (pluginConfig = $[1], props = $[2]);
8
11
  const options = props.schemaType.options, iconList = options?.iconList ?? pluginConfig.iconList, renderOption = options?.renderOption ?? pluginConfig.renderOption, renderSelected = options?.renderSelected ?? pluginConfig.renderSelected;
9
- return /* @__PURE__ */ jsxRuntime.jsx(
10
- asyncAutocomplete.AsyncAutocomplete,
11
- {
12
- placeholder: "Select icon",
13
- noOptionsPlaceholder: "No icons found",
14
- listItems: iconList,
15
- value: props.value,
16
- renderValue: (value, opt) => opt?.label ?? value,
17
- onChange: (value) => {
18
- const next = value ? sanity.set(value) : sanity.unset();
19
- return props.onChange(next);
20
- },
21
- renderSelected: (value) => renderSelected ? renderSelected(value) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 2, children: value }),
22
- renderOption: ({ label, value }) => renderOption ? renderOption({ label, value }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { as: "button", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", padding: 2, children: [
23
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u{1F9FF}" }),
24
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 2, children: label }) })
25
- ] }) })
26
- }
27
- );
12
+ let t1;
13
+ $[3] !== props ? (t1 = (value_0) => {
14
+ const next = value_0 ? sanity.set(value_0) : sanity.unset();
15
+ return props.onChange(next);
16
+ }, $[3] = props, $[4] = t1) : t1 = $[4];
17
+ let t2;
18
+ $[5] !== renderSelected ? (t2 = (value_1) => renderSelected ? renderSelected(value_1) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 2, children: value_1 }), $[5] = renderSelected, $[6] = t2) : t2 = $[6];
19
+ let t3;
20
+ $[7] !== renderOption ? (t3 = (t42) => {
21
+ const {
22
+ label,
23
+ value: value_2
24
+ } = t42;
25
+ return renderOption ? renderOption({
26
+ label,
27
+ value: value_2
28
+ }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { as: "button", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", padding: 2, children: [
29
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u{1F9FF}" }),
30
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 2, children: label }) })
31
+ ] }) });
32
+ }, $[7] = renderOption, $[8] = t3) : t3 = $[8];
33
+ let t4;
34
+ return $[9] !== iconList || $[10] !== props.value || $[11] !== t1 || $[12] !== t2 || $[13] !== t3 ? (t4 = /* @__PURE__ */ jsxRuntime.jsx(asyncAutocomplete.AsyncAutocomplete, { placeholder: "Select icon", noOptionsPlaceholder: "No icons found", listItems: iconList, value: props.value, renderValue: _temp, onChange: t1, renderSelected: t2, renderOption: t3 }), $[9] = iconList, $[10] = props.value, $[11] = t1, $[12] = t2, $[13] = t3, $[14] = t4) : t4 = $[14], t4;
35
+ }
36
+ function _temp(value, opt) {
37
+ return opt?.label ?? value;
28
38
  }
29
39
  const typeName = "wild.icon", wildSanityIconFieldPlugin = sanity.definePlugin((config) => ({
30
40
  name: "@madebywild/sanity-icon-field",
31
41
  schema: {
32
- types: [
33
- sanity.defineType({
34
- name: typeName,
35
- type: "string",
36
- title: "Icon",
37
- description: "Select an icon.",
38
- icon: () => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u{1F9FF}" }),
39
- components: {
40
- input: (props) => /* @__PURE__ */ jsxRuntime.jsx(IconInput, { pluginConfig: config, ...props })
41
- }
42
- })
43
- ]
42
+ types: [sanity.defineType({
43
+ name: typeName,
44
+ type: "string",
45
+ title: "Icon",
46
+ description: "Select an icon.",
47
+ icon: () => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u{1F9FF}" }),
48
+ components: {
49
+ input: (props) => /* @__PURE__ */ jsxRuntime.jsx(IconInput, { pluginConfig: config, ...props })
50
+ }
51
+ })]
44
52
  }
45
53
  }));
46
54
  exports.typeName = typeName;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/input.tsx","../src/types.tsx","../src/index.tsx"],"sourcesContent":["import { AsyncAutocomplete } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport { Box, Card, Flex, Text } from \"@sanity/ui\";\nimport { type StringInputProps, set, unset } from \"sanity\";\nimport type { FieldOptions, PluginConfig } from \"./types\";\n\nfunction IconInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig: PluginConfig;\n}) {\n const options = props.schemaType.options as FieldOptions | undefined;\n const iconList = options?.iconList ?? pluginConfig.iconList;\n const renderOption = options?.renderOption ?? pluginConfig.renderOption;\n const renderSelected = options?.renderSelected ?? pluginConfig.renderSelected;\n\n return (\n <AsyncAutocomplete\n placeholder=\"Select icon\"\n noOptionsPlaceholder=\"No icons found\"\n listItems={iconList}\n value={props.value}\n renderValue={(value, opt) => opt?.label ?? value}\n onChange={(value) => {\n const next = value ? set(value) : unset();\n return props.onChange(next);\n }}\n renderSelected={(value) => {\n if (renderSelected) return renderSelected(value);\n return <Text size={2}>{value}</Text>;\n }}\n renderOption={({ label, value }) => {\n if (renderOption) return renderOption({ label, value });\n return (\n <Card as=\"button\">\n <Flex align=\"center\" padding={2}>\n <span>🧿</span>\n <Box flex={1} padding={2}>\n <Text size={2}>{label}</Text>\n </Box>\n </Flex>\n </Card>\n );\n }}\n />\n );\n}\n\nexport { IconInput };\n","import type { ListItems } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport type { StringDefinition, StringOptions } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.icon\" as const;\n\n/** @public */\nexport type PluginConfig = {\n iconList: ListItems;\n renderSelected?: (value: string) => React.JSX.Element;\n renderOption?: (item: { label?: string; value: string }) => React.JSX.Element;\n};\n\n/** @public */\nexport type FieldOptions = StringOptions & {\n iconList?: ListItems;\n renderSelected?: (value: string) => React.JSX.Element;\n renderOption?: (item: { label?: string; value: string }) => React.JSX.Element;\n};\n\n// Add the custom field definition to Sanity's intrinsic definitions\n// so that type checking works correctly when using this field type.\ndeclare module \"sanity\" {\n export interface IntrinsicDefinitions {\n [typeName]: Omit<StringDefinition, \"type\" | \"fields\" | \"options\"> & {\n type: typeof typeName;\n options?: FieldOptions;\n };\n }\n}\n","import { definePlugin, defineType } from \"sanity\";\nimport { IconInput } from \"./input\";\nimport { type FieldOptions, type PluginConfig, typeName } from \"./types\";\n\n/** @public */\nconst wildSanityIconFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-icon-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"string\",\n title: \"Icon\",\n description: \"Select an icon.\",\n icon: () => <>🧿</>,\n components: {\n input: (props) => <IconInput pluginConfig={config} {...props} />,\n },\n }),\n ],\n },\n };\n});\n\nexport { wildSanityIconFieldPlugin, typeName, type PluginConfig, type FieldOptions };\n"],"names":["jsx","A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AA,IACN,OAAO;AAAA,MACLC,kBAAW;AAAA,QACT,MAAM;AAAA,QACN,MAAM;AAAA,QACN,OAAO;AAAA,QACP,aAAa;AAAA,QACb,MAAM,MAAMT,2BAAAA,IAAAU,WAAAA,UAAA,EAAE,UAAA,YAAA,CAAE;AAAA,QAChB,YAAY;AAAA,UACV,OAAO,CAAC,UAAUV,+BAAC,aAAU,cAAc,QAAS,GAAG,MAAA,CAAO;AAAA,QAAA;AAAA,MAChE,CACD;AAAA,IAAA;AAAA,EACH;AAEJ,EACD;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/input.tsx","../src/types.tsx","../src/index.tsx"],"sourcesContent":["import { AsyncAutocomplete } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport { Box, Card, Flex, Text } from \"@sanity/ui\";\nimport { type StringInputProps, set, unset } from \"sanity\";\nimport type { FieldOptions, PluginConfig } from \"./types\";\n\nfunction IconInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig: PluginConfig;\n}) {\n const options = props.schemaType.options as FieldOptions | undefined;\n const iconList = options?.iconList ?? pluginConfig.iconList;\n const renderOption = options?.renderOption ?? pluginConfig.renderOption;\n const renderSelected = options?.renderSelected ?? pluginConfig.renderSelected;\n\n return (\n <AsyncAutocomplete\n placeholder=\"Select icon\"\n noOptionsPlaceholder=\"No icons found\"\n listItems={iconList}\n value={props.value}\n renderValue={(value, opt) => opt?.label ?? value}\n onChange={(value) => {\n const next = value ? set(value) : unset();\n return props.onChange(next);\n }}\n renderSelected={(value) => {\n if (renderSelected) return renderSelected(value);\n return <Text size={2}>{value}</Text>;\n }}\n renderOption={({ label, value }) => {\n if (renderOption) return renderOption({ label, value });\n return (\n <Card as=\"button\">\n <Flex align=\"center\" padding={2}>\n <span>🧿</span>\n <Box flex={1} padding={2}>\n <Text size={2}>{label}</Text>\n </Box>\n </Flex>\n </Card>\n );\n }}\n />\n );\n}\n\nexport { IconInput };\n","import type { ListItems } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport type { StringDefinition, StringOptions } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.icon\" as const;\n\n/** @public */\nexport type PluginConfig = {\n iconList: ListItems;\n renderSelected?: (value: string) => React.JSX.Element;\n renderOption?: (item: { label?: string; value: string }) => React.JSX.Element;\n};\n\n/** @public */\nexport type FieldOptions = StringOptions & {\n iconList?: ListItems;\n renderSelected?: (value: string) => React.JSX.Element;\n renderOption?: (item: { label?: string; value: string }) => React.JSX.Element;\n};\n\n// Add the custom field definition to Sanity's intrinsic definitions\n// so that type checking works correctly when using this field type.\ndeclare module \"sanity\" {\n export interface IntrinsicDefinitions {\n [typeName]: Omit<StringDefinition, \"type\" | \"fields\" | \"options\"> & {\n type: typeof typeName;\n options?: FieldOptions;\n };\n }\n}\n","import { definePlugin, defineType } from \"sanity\";\nimport { IconInput } from \"./input\";\nimport { type FieldOptions, type PluginConfig, typeName } from \"./types\";\n\n/** @public */\nconst wildSanityIconFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-icon-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"string\",\n title: \"Icon\",\n description: \"Select an icon.\",\n icon: () => <>🧿</>,\n components: {\n input: (props) => <IconInput pluginConfig={config} {...props} />,\n },\n }),\n ],\n },\n };\n});\n\nexport { wildSanityIconFieldPlugin, typeName, type PluginConfig, type FieldOptions };\n"],"names":["IconInput","t0","$","_c","pluginConfig","props","options","schemaType","iconList","renderOption","renderSelected","t1","value_0","next","value","set","unset","onChange","t2","value_1","jsx","Text","t3","t4","label","value_2","Card","jsxs","Flex","Box","AsyncAutocomplete","_temp","opt","typeName","wildSanityIconFieldPlugin","definePlugin","config","name","schema","types","defineType","type","title","description","icon","Fragment","components","input"],"mappings":";;;AAKA,SAAAA,UAAAC,IAAA;AAAA,QAAAC,IAAAC,gBAAAA,EAAA,EAAA;AAAA,MAAAC,cAAAC;AAAAH,WAAAD,MAAmB;AAAA,IAAAG;AAAAA,IAA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U,EAAA,CACxB;AAAA,IAAA,EAAA,CACF,EAAA,CACF;AAAA,EAAO,GAEVnB,OAAAO,cAAAP,OAAAoB,MAAAA,KAAApB,EAAA,CAAA;AAAA,MAAAqB;AAAA,SAAArB,SAAAM,YAAAN,EAAA,EAAA,MAAAG,MAAAS,SAAAZ,EAAA,EAAA,MAAAS,MAAAT,EAAA,EAAA,MAAAgB,MAAAhB,UAAAoB,MA1BHC,oCAACO,kBAAAA,mBAAA,EACa,aAAA,eACS,sBAAA,kBACVtB,qBACJ,OAAAH,MAAKS,OACC,aAAAiB,OACH,UAAApB,IAIM,gBAAAO,IAIF,cAAAI,GAAAA,CAYb,GACDpB,OAAAM,UAAAN,EAAA,EAAA,IAAAG,MAAAS,OAAAZ,QAAAS,IAAAT,QAAAgB,IAAAhB,QAAAoB,IAAApB,QAAAqB,MAAAA,KAAArB,EAAA,EAAA,GA3BFqB;AA2BE;AAvCN,SAAAQ,MAAAjB,OAAAkB,KAAA;AAAA,SAiBmCA,KAAGR,SAAHV;AAAmB;AClB/C,MAAMmB,WAAW,aCClBC,4BAA4BC,OAAAA,aAA4BC,CAAAA,YACrD;AAAA,EACLC,MAAM;AAAA,EACNC,QAAQ;AAAA,IACNC,OAAO,CACLC,OAAAA,WAAW;AAAA,MACTH,MAAMJ;AAAAA,MACNQ,MAAM;AAAA,MACNC,OAAO;AAAA,MACPC,aAAa;AAAA,MACbC,MAAMA,MAAMxB,2BAAAA,IAAAyB,WAAAA,UAAA,EAAE,UAAA,YAAA,CAAE;AAAA,MAChBC,YAAY;AAAA,QACVC,OAAQ1C,CAAAA,UAAUe,+BAAC,aAAU,cAAcgB,QAAQ,GAAI/B,MAAAA,CAAM;AAAA,MAAA;AAAA,IAC/D,CACD,CAAC;AAAA,EAAA;AAGR,EACD;;;"}
package/dist/index.js CHANGED
@@ -1,47 +1,56 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import { set, unset, definePlugin, defineType } from "sanity";
3
+ import { c } from "react/compiler-runtime";
3
4
  import { AsyncAutocomplete } from "@madebywild/sanity-utils/async-autocomplete";
4
- import { Card, Flex, Box, Text } from "@sanity/ui";
5
- function IconInput({
6
- pluginConfig,
7
- ...props
8
- }) {
5
+ import { Text, Card, Flex, Box } from "@sanity/ui";
6
+ function IconInput(t0) {
7
+ const $ = c(15);
8
+ let pluginConfig, props;
9
+ $[0] !== t0 ? ({
10
+ pluginConfig,
11
+ ...props
12
+ } = t0, $[0] = t0, $[1] = pluginConfig, $[2] = props) : (pluginConfig = $[1], props = $[2]);
9
13
  const options = props.schemaType.options, iconList = options?.iconList ?? pluginConfig.iconList, renderOption = options?.renderOption ?? pluginConfig.renderOption, renderSelected = options?.renderSelected ?? pluginConfig.renderSelected;
10
- return /* @__PURE__ */ jsx(
11
- AsyncAutocomplete,
12
- {
13
- placeholder: "Select icon",
14
- noOptionsPlaceholder: "No icons found",
15
- listItems: iconList,
16
- value: props.value,
17
- renderValue: (value, opt) => opt?.label ?? value,
18
- onChange: (value) => {
19
- const next = value ? set(value) : unset();
20
- return props.onChange(next);
21
- },
22
- renderSelected: (value) => renderSelected ? renderSelected(value) : /* @__PURE__ */ jsx(Text, { size: 2, children: value }),
23
- renderOption: ({ label, value }) => renderOption ? renderOption({ label, value }) : /* @__PURE__ */ jsx(Card, { as: "button", children: /* @__PURE__ */ jsxs(Flex, { align: "center", padding: 2, children: [
24
- /* @__PURE__ */ jsx("span", { children: "\u{1F9FF}" }),
25
- /* @__PURE__ */ jsx(Box, { flex: 1, padding: 2, children: /* @__PURE__ */ jsx(Text, { size: 2, children: label }) })
26
- ] }) })
27
- }
28
- );
14
+ let t1;
15
+ $[3] !== props ? (t1 = (value_0) => {
16
+ const next = value_0 ? set(value_0) : unset();
17
+ return props.onChange(next);
18
+ }, $[3] = props, $[4] = t1) : t1 = $[4];
19
+ let t2;
20
+ $[5] !== renderSelected ? (t2 = (value_1) => renderSelected ? renderSelected(value_1) : /* @__PURE__ */ jsx(Text, { size: 2, children: value_1 }), $[5] = renderSelected, $[6] = t2) : t2 = $[6];
21
+ let t3;
22
+ $[7] !== renderOption ? (t3 = (t42) => {
23
+ const {
24
+ label,
25
+ value: value_2
26
+ } = t42;
27
+ return renderOption ? renderOption({
28
+ label,
29
+ value: value_2
30
+ }) : /* @__PURE__ */ jsx(Card, { as: "button", children: /* @__PURE__ */ jsxs(Flex, { align: "center", padding: 2, children: [
31
+ /* @__PURE__ */ jsx("span", { children: "\u{1F9FF}" }),
32
+ /* @__PURE__ */ jsx(Box, { flex: 1, padding: 2, children: /* @__PURE__ */ jsx(Text, { size: 2, children: label }) })
33
+ ] }) });
34
+ }, $[7] = renderOption, $[8] = t3) : t3 = $[8];
35
+ let t4;
36
+ return $[9] !== iconList || $[10] !== props.value || $[11] !== t1 || $[12] !== t2 || $[13] !== t3 ? (t4 = /* @__PURE__ */ jsx(AsyncAutocomplete, { placeholder: "Select icon", noOptionsPlaceholder: "No icons found", listItems: iconList, value: props.value, renderValue: _temp, onChange: t1, renderSelected: t2, renderOption: t3 }), $[9] = iconList, $[10] = props.value, $[11] = t1, $[12] = t2, $[13] = t3, $[14] = t4) : t4 = $[14], t4;
37
+ }
38
+ function _temp(value, opt) {
39
+ return opt?.label ?? value;
29
40
  }
30
41
  const typeName = "wild.icon", wildSanityIconFieldPlugin = definePlugin((config) => ({
31
42
  name: "@madebywild/sanity-icon-field",
32
43
  schema: {
33
- types: [
34
- defineType({
35
- name: typeName,
36
- type: "string",
37
- title: "Icon",
38
- description: "Select an icon.",
39
- icon: () => /* @__PURE__ */ jsx(Fragment, { children: "\u{1F9FF}" }),
40
- components: {
41
- input: (props) => /* @__PURE__ */ jsx(IconInput, { pluginConfig: config, ...props })
42
- }
43
- })
44
- ]
44
+ types: [defineType({
45
+ name: typeName,
46
+ type: "string",
47
+ title: "Icon",
48
+ description: "Select an icon.",
49
+ icon: () => /* @__PURE__ */ jsx(Fragment, { children: "\u{1F9FF}" }),
50
+ components: {
51
+ input: (props) => /* @__PURE__ */ jsx(IconInput, { pluginConfig: config, ...props })
52
+ }
53
+ })]
45
54
  }
46
55
  }));
47
56
  export {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/input.tsx","../src/types.tsx","../src/index.tsx"],"sourcesContent":["import { AsyncAutocomplete } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport { Box, Card, Flex, Text } from \"@sanity/ui\";\nimport { type StringInputProps, set, unset } from \"sanity\";\nimport type { FieldOptions, PluginConfig } from \"./types\";\n\nfunction IconInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig: PluginConfig;\n}) {\n const options = props.schemaType.options as FieldOptions | undefined;\n const iconList = options?.iconList ?? pluginConfig.iconList;\n const renderOption = options?.renderOption ?? pluginConfig.renderOption;\n const renderSelected = options?.renderSelected ?? pluginConfig.renderSelected;\n\n return (\n <AsyncAutocomplete\n placeholder=\"Select icon\"\n noOptionsPlaceholder=\"No icons found\"\n listItems={iconList}\n value={props.value}\n renderValue={(value, opt) => opt?.label ?? value}\n onChange={(value) => {\n const next = value ? set(value) : unset();\n return props.onChange(next);\n }}\n renderSelected={(value) => {\n if (renderSelected) return renderSelected(value);\n return <Text size={2}>{value}</Text>;\n }}\n renderOption={({ label, value }) => {\n if (renderOption) return renderOption({ label, value });\n return (\n <Card as=\"button\">\n <Flex align=\"center\" padding={2}>\n <span>🧿</span>\n <Box flex={1} padding={2}>\n <Text size={2}>{label}</Text>\n </Box>\n </Flex>\n </Card>\n );\n }}\n />\n );\n}\n\nexport { IconInput };\n","import type { ListItems } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport type { StringDefinition, StringOptions } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.icon\" as const;\n\n/** @public */\nexport type PluginConfig = {\n iconList: ListItems;\n renderSelected?: (value: string) => React.JSX.Element;\n renderOption?: (item: { label?: string; value: string }) => React.JSX.Element;\n};\n\n/** @public */\nexport type FieldOptions = StringOptions & {\n iconList?: ListItems;\n renderSelected?: (value: string) => React.JSX.Element;\n renderOption?: (item: { label?: string; value: string }) => React.JSX.Element;\n};\n\n// Add the custom field definition to Sanity's intrinsic definitions\n// so that type checking works correctly when using this field type.\ndeclare module \"sanity\" {\n export interface IntrinsicDefinitions {\n [typeName]: Omit<StringDefinition, \"type\" | \"fields\" | \"options\"> & {\n type: typeof typeName;\n options?: FieldOptions;\n };\n }\n}\n","import { definePlugin, defineType } from \"sanity\";\nimport { IconInput } from \"./input\";\nimport { type FieldOptions, type PluginConfig, typeName } from \"./types\";\n\n/** @public */\nconst wildSanityIconFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-icon-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"string\",\n title: \"Icon\",\n description: \"Select an icon.\",\n icon: () => <>🧿</>,\n components: {\n input: (props) => <IconInput pluginConfig={config} {...props} />,\n },\n }),\n ],\n },\n };\n});\n\nexport { wildSanityIconFieldPlugin, typeName, type PluginConfig, type FieldOptions };\n"],"names":[],"mappings":";;;;AAKA,SAAS,UAAU;AAAA,EACjB;AAAA,EACA,GAAG;AACL,GAEG;AACD,QAAM,UAAU,MAAM,WAAW,SAC3B,WAAW,SAAS,YAAY,aAAa,UAC7C,eAAe,SAAS,gBAAgB,aAAa,cACrD,iBAAiB,SAAS,kBAAkB,aAAa;AAE/D,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,aAAY;AAAA,MACZ,sBAAqB;AAAA,MACrB,WAAW;AAAA,MACX,OAAO,MAAM;AAAA,MACb,aAAa,CAAC,OAAO,QAAQ,KAAK,SAAS;AAAA,MAC3C,UAAU,CAAC,UAAU;AACnB,cAAM,OAAO,QAAQ,IAAI,KAAK,IAAI,MAAA;AAClC,eAAO,MAAM,SAAS,IAAI;AAAA,MAC5B;AAAA,MACA,gBAAgB,CAAC,UACX,iBAAuB,eAAe,KAAK,IACxC,oBAAC,MAAA,EAAK,MAAM,GAAI,UAAA,MAAA,CAAM;AAAA,MAE/B,cAAc,CAAC,EAAE,OAAO,YAClB,eAAqB,aAAa,EAAE,OAAO,MAAA,CAAO,IAEpD,oBAAC,QAAK,IAAG,UACP,+BAAC,MAAA,EAAK,OAAM,UAAS,SAAS,GAC5B,UAAA;AAAA,QAAA,oBAAC,UAAK,UAAA,YAAA,CAAE;AAAA,QACR,oBAAC,KAAA,EAAI,MAAM,GAAG,SAAS,GACrB,UAAA,oBAAC,MAAA,EAAK,MAAM,GAAI,UAAA,MAAA,CAAM,EAAA,CACxB;AAAA,MAAA,EAAA,CACF,EAAA,CACF;AAAA,IAAA;AAAA,EAAA;AAKV;AC1CO,MAAM,WAAW,aCClB,4BAA4B,aAA2B,CAAC,YACrD;AAAA,EACL,MAAM;AAAA,EACN,QAAQ;AAAA,IACN,OAAO;AAAA,MACL,WAAW;AAAA,QACT,MAAM;AAAA,QACN,MAAM;AAAA,QACN,OAAO;AAAA,QACP,aAAa;AAAA,QACb,MAAM,MAAM,oBAAA,UAAA,EAAE,UAAA,YAAA,CAAE;AAAA,QAChB,YAAY;AAAA,UACV,OAAO,CAAC,UAAU,oBAAC,aAAU,cAAc,QAAS,GAAG,MAAA,CAAO;AAAA,QAAA;AAAA,MAChE,CACD;AAAA,IAAA;AAAA,EACH;AAEJ,EACD;"}
1
+ {"version":3,"file":"index.js","sources":["../src/input.tsx","../src/types.tsx","../src/index.tsx"],"sourcesContent":["import { AsyncAutocomplete } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport { Box, Card, Flex, Text } from \"@sanity/ui\";\nimport { type StringInputProps, set, unset } from \"sanity\";\nimport type { FieldOptions, PluginConfig } from \"./types\";\n\nfunction IconInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig: PluginConfig;\n}) {\n const options = props.schemaType.options as FieldOptions | undefined;\n const iconList = options?.iconList ?? pluginConfig.iconList;\n const renderOption = options?.renderOption ?? pluginConfig.renderOption;\n const renderSelected = options?.renderSelected ?? pluginConfig.renderSelected;\n\n return (\n <AsyncAutocomplete\n placeholder=\"Select icon\"\n noOptionsPlaceholder=\"No icons found\"\n listItems={iconList}\n value={props.value}\n renderValue={(value, opt) => opt?.label ?? value}\n onChange={(value) => {\n const next = value ? set(value) : unset();\n return props.onChange(next);\n }}\n renderSelected={(value) => {\n if (renderSelected) return renderSelected(value);\n return <Text size={2}>{value}</Text>;\n }}\n renderOption={({ label, value }) => {\n if (renderOption) return renderOption({ label, value });\n return (\n <Card as=\"button\">\n <Flex align=\"center\" padding={2}>\n <span>🧿</span>\n <Box flex={1} padding={2}>\n <Text size={2}>{label}</Text>\n </Box>\n </Flex>\n </Card>\n );\n }}\n />\n );\n}\n\nexport { IconInput };\n","import type { ListItems } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport type { StringDefinition, StringOptions } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.icon\" as const;\n\n/** @public */\nexport type PluginConfig = {\n iconList: ListItems;\n renderSelected?: (value: string) => React.JSX.Element;\n renderOption?: (item: { label?: string; value: string }) => React.JSX.Element;\n};\n\n/** @public */\nexport type FieldOptions = StringOptions & {\n iconList?: ListItems;\n renderSelected?: (value: string) => React.JSX.Element;\n renderOption?: (item: { label?: string; value: string }) => React.JSX.Element;\n};\n\n// Add the custom field definition to Sanity's intrinsic definitions\n// so that type checking works correctly when using this field type.\ndeclare module \"sanity\" {\n export interface IntrinsicDefinitions {\n [typeName]: Omit<StringDefinition, \"type\" | \"fields\" | \"options\"> & {\n type: typeof typeName;\n options?: FieldOptions;\n };\n }\n}\n","import { definePlugin, defineType } from \"sanity\";\nimport { IconInput } from \"./input\";\nimport { type FieldOptions, type PluginConfig, typeName } from \"./types\";\n\n/** @public */\nconst wildSanityIconFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-icon-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"string\",\n title: \"Icon\",\n description: \"Select an icon.\",\n icon: () => <>🧿</>,\n components: {\n input: (props) => <IconInput pluginConfig={config} {...props} />,\n },\n }),\n ],\n },\n };\n});\n\nexport { wildSanityIconFieldPlugin, typeName, type PluginConfig, type FieldOptions };\n"],"names":["IconInput","t0","$","_c","pluginConfig","props","options","schemaType","iconList","renderOption","renderSelected","t1","value_0","next","value","set","unset","onChange","t2","value_1","t3","t4","label","value_2","_temp","opt","typeName","wildSanityIconFieldPlugin","definePlugin","config","name","schema","types","defineType","type","title","description","icon","components","input"],"mappings":";;;;;AAKA,SAAAA,UAAAC,IAAA;AAAA,QAAAC,IAAAC,EAAA,EAAA;AAAA,MAAAC,cAAAC;AAAAH,WAAAD,MAAmB;AAAA,IAAAG;AAAAA,IAAA,GAAAC;AAAAA,EAAAA,IAAAJ,IAKlBC,OAAAD,IAAAC,OAAAE,cAAAF,OAAAG,UAAAD,eAAAF,EAAA,CAAA,GAAAG,QAAAH,EAAA,CAAA;AACC,QAAAI,UAAgBD,MAAKE,WAAWD,SAChCE,WAAiBF,SAAOE,YAAcJ,aAAYI,UAClDC,eAAqBH,SAAOG,gBAAkBL,aAAYK,cAC1DC,iBAAuBJ,SAAOI,kBAAoBN,aAAYM;AAAgB,MAAAC;AAAAT,WAAAG,SAShEM,KAAAC,CAAAA,YAAA;AACR,UAAAC,OAAaC,UAAQC,IAAID,OAAe,IAANE,MAAAA;AAAQ,WACnCX,MAAKY,SAAUJ,IAAI;AAAA,EAAC,GAC5BX,OAAAG,OAAAH,OAAAS,MAAAA,KAAAT,EAAA,CAAA;AAAA,MAAAgB;AAAAhB,WAAAQ,kBACeQ,KAAAC,CAAAA,YACVT,iBAAuBA,eAAeI,OAAK,IACxC,oBAAC,MAAA,EAAW,MAAA,GAAIA,UAAAA,QAAAA,CAAM,GAC9BZ,OAAAQ,gBAAAR,OAAAgB,MAAAA,KAAAhB,EAAA,CAAA;AAAA,MAAAkB;AAAAlB,WAAAO,gBACaW,KAAAC,CAAAA,QAAA;AAAC,UAAA;AAAA,MAAAC;AAAAA,MAAAR,OAAAS;AAAAA,IAAAA,IAAAF;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,QACVC,OAAQlC,CAAAA,UAAU,oBAAC,aAAU,cAAcwB,QAAQ,GAAIxB,MAAAA,CAAM;AAAA,MAAA;AAAA,IAC/D,CACD,CAAC;AAAA,EAAA;AAGR,EACD;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madebywild/sanity-icon-field",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "UNLICENSED",
@@ -21,22 +21,23 @@
21
21
  "access": "restricted"
22
22
  },
23
23
  "dependencies": {
24
- "@madebywild/sanity-utils": "0.2.3"
24
+ "@madebywild/sanity-utils": "0.2.5"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@sanity/ui": "^3.1",
28
- "sanity": "^4.17",
29
28
  "react": "^19",
30
- "react-dom": "^19"
29
+ "react-dom": "^19",
30
+ "sanity": "^4.17"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@sanity/pkg-utils": "^9.2",
34
- "sanity": "^4.17",
34
+ "@types/react": "^19",
35
+ "@types/react-dom": "^19",
36
+ "babel-plugin-react-compiler": "1.0.0",
35
37
  "react": "^19",
36
38
  "react-dom": "^19",
37
- "typescript": "^5",
38
- "@types/react": "^19",
39
- "@types/react-dom": "^19"
39
+ "sanity": "^4.17",
40
+ "typescript": "^5"
40
41
  },
41
42
  "scripts": {
42
43
  "build": "pkg-utils build --strict",