@madebywild/sanity-icon-field 0.2.7 → 0.3.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.cjs CHANGED
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
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
4
  function IconInput(t0) {
5
- const $ = compilerRuntime.c(15);
5
+ const $ = compilerRuntime.c(17);
6
6
  let pluginConfig, props;
7
7
  $[0] !== t0 ? ({
8
8
  pluginConfig,
9
9
  ...props
10
10
  } = t0, $[0] = t0, $[1] = pluginConfig, $[2] = props) : (pluginConfig = $[1], props = $[2]);
11
- const options = props.schemaType.options, iconList = options?.iconList ?? pluginConfig.iconList, renderOption = options?.renderOption ?? pluginConfig.renderOption, renderSelected = options?.renderSelected ?? pluginConfig.renderSelected;
11
+ const options = props.schemaType.options, iconList = pluginConfig.iconList, renderOption = options?.renderOption ?? pluginConfig.renderOption, renderSelected = options?.renderSelected ?? pluginConfig.renderSelected, whitelist = options?.whitelist, blacklist = options?.blacklist;
12
12
  let t1;
13
13
  $[3] !== props ? (t1 = (value_0) => {
14
14
  const next = value_0 ? sanity.set(value_0) : sanity.unset();
@@ -31,7 +31,7 @@ function IconInput(t0) {
31
31
  ] }) });
32
32
  }, $[7] = renderOption, $[8] = t3) : t3 = $[8];
33
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;
34
+ return $[9] !== blacklist || $[10] !== iconList || $[11] !== props.value || $[12] !== t1 || $[13] !== t2 || $[14] !== t3 || $[15] !== whitelist ? (t4 = /* @__PURE__ */ jsxRuntime.jsx(asyncAutocomplete.AsyncAutocomplete, { placeholder: "Select icon", noOptionsPlaceholder: "No icons found", listItems: iconList, whitelist, blacklist, value: props.value, renderValue: _temp, onChange: t1, renderSelected: t2, renderOption: t3 }), $[9] = blacklist, $[10] = iconList, $[11] = props.value, $[12] = t1, $[13] = t2, $[14] = t3, $[15] = whitelist, $[16] = t4) : t4 = $[16], t4;
35
35
  }
36
36
  function _temp(value, opt) {
37
37
  return opt?.label ?? value;
@@ -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":["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,UAAA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{"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 = pluginConfig.iconList;\n const renderOption = options?.renderOption ?? pluginConfig.renderOption;\n const renderSelected = options?.renderSelected ?? pluginConfig.renderSelected;\n\n const whitelist = options?.whitelist;\n const blacklist = options?.blacklist;\n\n return (\n <AsyncAutocomplete\n placeholder=\"Select icon\"\n noOptionsPlaceholder=\"No icons found\"\n listItems={iconList}\n whitelist={whitelist}\n blacklist={blacklist}\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 whitelist?: string[];\n blacklist?: string[];\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","whitelist","blacklist","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,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,WAAiBJ,aAAYI,UAC7BC,eAAqBH,SAAOG,gBAAkBL,aAAYK,cAC1DC,iBAAuBJ,SAAOI,kBAA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AAAW,SAAAd,EAAA,EAAA,MAAAW,MAAAX,EAAA,EAAA,MAAAkB,MAAAlB,EAAA,EAAA,MAAAsB,MAAAtB,EAAA,EAAA,MAAAS,aA5BHc,KAAAH,2BAAAA,IAACU,kBAAAA,mBAAA,EACa,aAAA,eACS,sBAAA,kBACVxB,qBACAG,WACAC,WACJ,OAAAP,MAAKW,OACC,aAAAiB,OACH,UAAApB,IAIM,gBAAAO,IAIF,cAAAI,GAAAA,CAYb,GACDtB,OAAAU,WAAAV,QAAAM,UAAAN,EAAA,EAAA,IAAAG,MAAAW,OAAAd,QAAAW,IAAAX,QAAAkB,IAAAlB,QAAAsB,IAAAtB,QAAAS,WAAAT,QAAAuB,MAAAA,KAAAvB,EAAA,EAAA,GA7BFuB;AA6BE;AA5CN,SAAAQ,MAAAjB,OAAAkB,KAAA;AAAA,SAsBmCA,KAAGR,SAAHV;AAAmB;ACvB/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,OAAQ5C,CAAAA,UAAUiB,+BAAC,aAAU,cAAcgB,QAAQ,GAAIjC,MAAAA,CAAM;AAAA,MAAA;AAAA,IAC/D,CACD,CAAC;AAAA,EAAA;AAGR,EACD;;;"}
package/dist/index.d.cts CHANGED
@@ -21,7 +21,8 @@ type PluginConfig = {
21
21
  };
22
22
  /** @public */
23
23
  type FieldOptions = StringOptions & {
24
- iconList?: ListItems;
24
+ whitelist?: string[];
25
+ blacklist?: string[];
25
26
  renderSelected?: (value: string) => React.JSX.Element;
26
27
  renderOption?: (item: {
27
28
  label?: string;
package/dist/index.d.ts CHANGED
@@ -21,7 +21,8 @@ type PluginConfig = {
21
21
  };
22
22
  /** @public */
23
23
  type FieldOptions = StringOptions & {
24
- iconList?: ListItems;
24
+ whitelist?: string[];
25
+ blacklist?: string[];
25
26
  renderSelected?: (value: string) => React.JSX.Element;
26
27
  renderOption?: (item: {
27
28
  label?: string;
package/dist/index.js CHANGED
@@ -4,13 +4,13 @@ import { c } from "react/compiler-runtime";
4
4
  import { AsyncAutocomplete } from "@madebywild/sanity-utils/async-autocomplete";
5
5
  import { Text, Card, Flex, Box } from "@sanity/ui";
6
6
  function IconInput(t0) {
7
- const $ = c(15);
7
+ const $ = c(17);
8
8
  let pluginConfig, props;
9
9
  $[0] !== t0 ? ({
10
10
  pluginConfig,
11
11
  ...props
12
12
  } = t0, $[0] = t0, $[1] = pluginConfig, $[2] = props) : (pluginConfig = $[1], props = $[2]);
13
- const options = props.schemaType.options, iconList = options?.iconList ?? pluginConfig.iconList, renderOption = options?.renderOption ?? pluginConfig.renderOption, renderSelected = options?.renderSelected ?? pluginConfig.renderSelected;
13
+ const options = props.schemaType.options, iconList = pluginConfig.iconList, renderOption = options?.renderOption ?? pluginConfig.renderOption, renderSelected = options?.renderSelected ?? pluginConfig.renderSelected, whitelist = options?.whitelist, blacklist = options?.blacklist;
14
14
  let t1;
15
15
  $[3] !== props ? (t1 = (value_0) => {
16
16
  const next = value_0 ? set(value_0) : unset();
@@ -33,7 +33,7 @@ function IconInput(t0) {
33
33
  ] }) });
34
34
  }, $[7] = renderOption, $[8] = t3) : t3 = $[8];
35
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;
36
+ return $[9] !== blacklist || $[10] !== iconList || $[11] !== props.value || $[12] !== t1 || $[13] !== t2 || $[14] !== t3 || $[15] !== whitelist ? (t4 = /* @__PURE__ */ jsx(AsyncAutocomplete, { placeholder: "Select icon", noOptionsPlaceholder: "No icons found", listItems: iconList, whitelist, blacklist, value: props.value, renderValue: _temp, onChange: t1, renderSelected: t2, renderOption: t3 }), $[9] = blacklist, $[10] = iconList, $[11] = props.value, $[12] = t1, $[13] = t2, $[14] = t3, $[15] = whitelist, $[16] = t4) : t4 = $[16], t4;
37
37
  }
38
38
  function _temp(value, opt) {
39
39
  return opt?.label ?? value;
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":["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,MA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CACF,EAAA,CACF;AAAA,EAAO,GAEVZ,OAAAO,cAAAP,OAAAkB,MAAAA,KAAAlB,EAAA,CAAA;AAAA,MAAAmB;AAAA,SAAAnB,SAAAM,YAAAN,EAAA,EAAA,MAAAG,MAAAS,SAAAZ,EAAA,EAAA,MAAAS,MAAAT,EAAA,EAAA,MAAAgB,MAAAhB,UAAAkB,MA1BHC,yBAAC,mBAAA,EACa,aAAA,eACS,sBAAA,kBACVb,qBACJ,OAAAH,MAAKS,OACC,aAAAU,OACH,UAAAb,IAIM,gBAAAO,IAIF,cAAAE,GAAAA,CAYb,GACDlB,OAAAM,UAAAN,EAAA,EAAA,IAAAG,MAAAS,OAAAZ,QAAAS,IAAAT,QAAAgB,IAAAhB,QAAAkB,IAAAlB,QAAAmB,MAAAA,KAAAnB,EAAA,EAAA,GA3BFmB;AA2BE;AAvCN,SAAAG,MAAAV,OAAAW,KAAA;AAAA,SAiBmCA,KAAGH,SAAHR;AAAmB;AClB/C,MAAMY,WAAW,aCClBC,4BAA4BC,aAA4BC,CAAAA,YACrD;AAAA,EACLC,MAAM;AAAA,EACNC,QAAQ;AAAA,IACNC,OAAO,CACLC,WAAW;AAAA,MACTH,MAAMJ;AAAAA,MACNQ,MAAM;AAAA,MACNC,OAAO;AAAA,MACPC,aAAa;AAAA,MACbC,MAAMA,MAAM,oBAAA,UAAA,EAAE,UAAA,YAAA,CAAE;AAAA,MAChBC,YAAY;AAAA,QACVC,OAAQlC,CAAAA,UAAU,oBAAC,aAAU,cAAcwB,QAAQ,GAAIxB,MAAAA,CAAM;AAAA,MAAA;AAAA,IAC/D,CACD,CAAC;AAAA,EAAA;AAGR,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 = pluginConfig.iconList;\n const renderOption = options?.renderOption ?? pluginConfig.renderOption;\n const renderSelected = options?.renderSelected ?? pluginConfig.renderSelected;\n\n const whitelist = options?.whitelist;\n const blacklist = options?.blacklist;\n\n return (\n <AsyncAutocomplete\n placeholder=\"Select icon\"\n noOptionsPlaceholder=\"No icons found\"\n listItems={iconList}\n whitelist={whitelist}\n blacklist={blacklist}\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 whitelist?: string[];\n blacklist?: string[];\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","whitelist","blacklist","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,WAAiBJ,aAAYI,UAC7BC,eAAqBH,SAAOG,gBAAkBL,aAAYK,cAC1DC,iBAAuBJ,SAAOI,kBAAoBN,aAAYM,gBAE9DC,YAAkBL,SAAOK,WACzBC,YAAkBN,SAAOM;AAAY,MAAAC;AAAAX,WAAAG,SAWvBQ,KAAAC,CAAAA,YAAA;AACR,UAAAC,OAAaC,UAAQC,IAAID,OAAe,IAANE,MAAAA;AAAQ,WACnCb,MAAKc,SAAUJ,IAAI;AAAA,EAAC,GAC5Bb,OAAAG,OAAAH,OAAAW,MA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AAX,QAAAkB,IAAAlB,QAAAoB,IAAApB,QAAAS,WAAAT,QAAAqB,MAAAA,KAAArB,EAAA,EAAA,GA7BFqB;AA6BE;AA5CN,SAAAG,MAAAV,OAAAW,KAAA;AAAA,SAsBmCA,KAAGH,SAAHR;AAAmB;ACvB/C,MAAMY,WAAW,aCClBC,4BAA4BC,aAA4BC,CAAAA,YACrD;AAAA,EACLC,MAAM;AAAA,EACNC,QAAQ;AAAA,IACNC,OAAO,CACLC,WAAW;AAAA,MACTH,MAAMJ;AAAAA,MACNQ,MAAM;AAAA,MACNC,OAAO;AAAA,MACPC,aAAa;AAAA,MACbC,MAAMA,MAAM,oBAAA,UAAA,EAAE,UAAA,YAAA,CAAE;AAAA,MAChBC,YAAY;AAAA,QACVC,OAAQpC,CAAAA,UAAU,oBAAC,aAAU,cAAc0B,QAAQ,GAAI1B,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.7",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "UNLICENSED",
@@ -21,7 +21,7 @@
21
21
  "access": "restricted"
22
22
  },
23
23
  "dependencies": {
24
- "@madebywild/sanity-utils": "0.2.7"
24
+ "@madebywild/sanity-utils": "0.3.0"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@sanity/ui": "^3.1",
package/src/input.tsx CHANGED
@@ -10,15 +10,20 @@ function IconInput({
10
10
  pluginConfig: PluginConfig;
11
11
  }) {
12
12
  const options = props.schemaType.options as FieldOptions | undefined;
13
- const iconList = options?.iconList ?? pluginConfig.iconList;
13
+ const iconList = pluginConfig.iconList;
14
14
  const renderOption = options?.renderOption ?? pluginConfig.renderOption;
15
15
  const renderSelected = options?.renderSelected ?? pluginConfig.renderSelected;
16
16
 
17
+ const whitelist = options?.whitelist;
18
+ const blacklist = options?.blacklist;
19
+
17
20
  return (
18
21
  <AsyncAutocomplete
19
22
  placeholder="Select icon"
20
23
  noOptionsPlaceholder="No icons found"
21
24
  listItems={iconList}
25
+ whitelist={whitelist}
26
+ blacklist={blacklist}
22
27
  value={props.value}
23
28
  renderValue={(value, opt) => opt?.label ?? value}
24
29
  onChange={(value) => {
package/src/types.tsx CHANGED
@@ -13,7 +13,8 @@ export type PluginConfig = {
13
13
 
14
14
  /** @public */
15
15
  export type FieldOptions = StringOptions & {
16
- iconList?: ListItems;
16
+ whitelist?: string[];
17
+ blacklist?: string[];
17
18
  renderSelected?: (value: string) => React.JSX.Element;
18
19
  renderOption?: (item: { label?: string; value: string }) => React.JSX.Element;
19
20
  };