@madebywild/sanity-color-field 0.0.4 → 0.0.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 +46 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +47 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/dist/_chunks-cjs/index.cjs +0 -18378
- package/dist/_chunks-cjs/index.cjs.map +0 -1
- package/dist/_chunks-cjs/refractor.cjs +0 -4643
- package/dist/_chunks-cjs/refractor.cjs.map +0 -1
- package/dist/_chunks-es/index.js +0 -18367
- package/dist/_chunks-es/index.js.map +0 -1
- package/dist/_chunks-es/refractor.js +0 -4646
- package/dist/_chunks-es/refractor.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
require("react/jsx-runtime");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
var jsxRuntime = require("react/jsx-runtime"), sanity = require("sanity"), sanityUtils = require("@madebywild/sanity-utils"), ui = require("@sanity/ui");
|
|
4
|
+
function ColorInput({
|
|
5
|
+
config,
|
|
6
|
+
schemaType,
|
|
7
|
+
onChange,
|
|
8
|
+
value
|
|
9
|
+
}) {
|
|
10
|
+
const options = schemaType.options, colorList = options?.colorList ?? config.colorList, renderOption = options?.renderOption ?? config.renderOption, renderSelected = options?.renderSelected ?? config.renderSelected;
|
|
11
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12
|
+
sanityUtils.AsyncAutocomplete,
|
|
13
|
+
{
|
|
14
|
+
defaultValue: value,
|
|
15
|
+
placeholder: "Select color",
|
|
16
|
+
listItems: colorList,
|
|
17
|
+
renderValue: (value2, opt) => opt?.label ?? value2,
|
|
18
|
+
onChange: (value2) => {
|
|
19
|
+
const next = value2 ? sanity.set(value2) : sanity.unset();
|
|
20
|
+
return onChange(next);
|
|
21
|
+
},
|
|
22
|
+
renderSelected: (value2) => renderSelected ? renderSelected(value2) : /* @__PURE__ */ jsxRuntime.jsx(ui.Avatar, { style: { backgroundColor: value2 } }),
|
|
23
|
+
renderOption: ({ label, value: value2 }) => renderOption ? renderOption({ label, value: value2 }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { as: "button", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", padding: 2, children: [
|
|
24
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Avatar, { size: 1, style: { backgroundColor: value2 } }),
|
|
25
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 2, children: label }) })
|
|
26
|
+
] }) })
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
const typeName = "wild.color", wildSanityColorFieldPlugin = sanity.definePlugin((config) => ({
|
|
31
|
+
name: "@madebywild/sanity-color-field",
|
|
32
|
+
schema: {
|
|
33
|
+
types: [
|
|
34
|
+
sanity.defineType({
|
|
35
|
+
name: typeName,
|
|
36
|
+
type: "string",
|
|
37
|
+
title: "Color",
|
|
38
|
+
description: "Select a color.",
|
|
39
|
+
icon: () => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u{1F3A8}" }),
|
|
40
|
+
components: {
|
|
41
|
+
input: (props) => /* @__PURE__ */ jsxRuntime.jsx(ColorInput, { config, ...props })
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
exports.typeName = typeName;
|
|
48
|
+
exports.wildSanityColorFieldPlugin = wildSanityColorFieldPlugin;
|
|
8
49
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/input.tsx","../src/types.ts","../src/index.tsx"],"sourcesContent":["import { AsyncAutocomplete } from \"@madebywild/sanity-utils\";\nimport { Avatar, Box, Card, Flex, Text } from \"@sanity/ui\";\nimport { type StringInputProps, set, unset } from \"sanity\";\nimport type { FieldOptions, PluginConfig } from \"./types\";\n\nfunction ColorInput({\n config,\n schemaType,\n onChange,\n value,\n}: StringInputProps & {\n config: PluginConfig;\n}) {\n const options = schemaType.options as FieldOptions | undefined;\n const colorList = options?.colorList ?? config.colorList;\n const renderOption = options?.renderOption ?? config.renderOption;\n const renderSelected = options?.renderSelected ?? config.renderSelected;\n\n return (\n <AsyncAutocomplete\n defaultValue={value}\n placeholder=\"Select color\"\n listItems={colorList}\n renderValue={(value, opt) => opt?.label ?? value}\n onChange={(value) => {\n const next = value ? set(value) : unset();\n return onChange(next);\n }}\n renderSelected={(value) => {\n if (renderSelected) return renderSelected(value);\n return <Avatar style={{ backgroundColor: value }} />;\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 <Avatar size={1} style={{ backgroundColor: value }} />\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 { ColorInput };\n","import type { ListItemsGetter } from \"@madebywild/sanity-utils\";\nimport type { StringDefinition, StringOptions } from \"sanity\";\n\n/** @public */\nexport type PluginConfig = {\n colorList: ListItemsGetter;\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 colorList?: ListItemsGetter;\n renderSelected?: (value: string) => React.JSX.Element;\n renderOption?: (item: { label?: string; value: string }) => React.JSX.Element;\n};\n\n/** @public */\nexport const typeName = \"wild.color\" as const;\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\"> & {\n type: typeof typeName;\n options?: FieldOptions;\n };\n }\n}\n","import { definePlugin, defineType } from \"sanity\";\nimport { ColorInput } from \"./input\";\nimport { type FieldOptions, type PluginConfig, typeName } from \"./types\";\n\n/** @public */\nconst wildSanityColorFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-color-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"string\",\n title: \"Color\",\n description: \"Select a color.\",\n icon: () => <>🎨</>,\n components: {\n input: (props) => <ColorInput config={config} {...props} />,\n },\n }),\n ],\n },\n };\n});\n\nexport { wildSanityColorFieldPlugin, type PluginConfig, type FieldOptions, typeName };\n"],"names":["jsx","AsyncAutocomplete","value","set","unset","Avatar","Card","Flex","Box","Text","definePlugin","defineType","Fragment"],"mappings":";;;AAKA,SAAS,WAAW;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAEG;AACD,QAAM,UAAU,WAAW,SACrB,YAAY,SAAS,aAAa,OAAO,WACzC,eAAe,SAAS,gBAAgB,OAAO,cAC/C,iBAAiB,SAAS,kBAAkB,OAAO;AAEzD,SACEA,2BAAAA;AAAAA,IAACC,YAAAA;AAAAA,IAAA;AAAA,MACC,cAAc;AAAA,MACd,aAAY;AAAA,MACZ,WAAW;AAAA,MACX,aAAa,CAACC,QAAO,QAAQ,KAAK,SAASA;AAAAA,MAC3C,UAAU,CAACA,WAAU;AACnB,cAAM,OAAOA,SAAQC,OAAAA,IAAID,MAAK,IAAIE,OAAAA,MAAA;AAClC,eAAO,SAAS,IAAI;AAAA,MACtB;AAAA,MACA,gBAAgB,CAACF,WACX,iBAAuB,eAAeA,MAAK,IACxCF,+BAACK,GAAAA,QAAA,EAAO,OAAO,EAAE,iBAAiBH,SAAM,CAAG;AAAA,MAEpD,cAAc,CAAC,EAAE,OAAO,OAAAA,aAClB,eAAqB,aAAa,EAAE,OAAO,OAAAA,QAAO,IAEpDF,+BAACM,GAAAA,MAAA,EAAK,IAAG,UACP,0CAACC,SAAA,EAAK,OAAM,UAAS,SAAS,GAC5B,UAAA;AAAA,QAAAP,+BAACK,GAAAA,UAAO,MAAM,GAAG,OAAO,EAAE,iBAAiBH,UAAS;AAAA,QACpDF,2BAAAA,IAACQ,GAAAA,KAAA,EAAI,MAAM,GAAG,SAAS,GACrB,UAAAR,2BAAAA,IAACS,GAAAA,MAAA,EAAK,MAAM,GAAI,UAAA,MAAA,CAAM,EAAA,CACxB;AAAA,MAAA,EAAA,CACF,EAAA,CACF;AAAA,IAAA;AAAA,EAAA;AAKV;AC7BO,MAAM,WAAW,cCblB,6BAA6BC,OAAAA,aAA2B,CAAC,YACtD;AAAA,EACL,MAAM;AAAA,EACN,QAAQ;AAAA,IACN,OAAO;AAAA,MACLC,kBAAW;AAAA,QACT,MAAM;AAAA,QACN,MAAM;AAAA,QACN,OAAO;AAAA,QACP,aAAa;AAAA,QACb,MAAM,MAAMX,2BAAAA,IAAAY,WAAAA,UAAA,EAAE,UAAA,YAAA,CAAE;AAAA,QAChB,YAAY;AAAA,UACV,OAAO,CAAC,yCAAW,YAAA,EAAW,QAAiB,GAAG,MAAA,CAAO;AAAA,QAAA;AAAA,MAC3D,CACD;AAAA,IAAA;AAAA,EACH;AAEJ,EACD;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
|
-
import "react/jsx-runtime";
|
|
2
|
-
import "sanity";
|
|
3
|
-
import {
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { set, unset, definePlugin, defineType } from "sanity";
|
|
3
|
+
import { AsyncAutocomplete } from "@madebywild/sanity-utils";
|
|
4
|
+
import { Card, Flex, Avatar, Box, Text } from "@sanity/ui";
|
|
5
|
+
function ColorInput({
|
|
6
|
+
config,
|
|
7
|
+
schemaType,
|
|
8
|
+
onChange,
|
|
9
|
+
value
|
|
10
|
+
}) {
|
|
11
|
+
const options = schemaType.options, colorList = options?.colorList ?? config.colorList, renderOption = options?.renderOption ?? config.renderOption, renderSelected = options?.renderSelected ?? config.renderSelected;
|
|
12
|
+
return /* @__PURE__ */ jsx(
|
|
13
|
+
AsyncAutocomplete,
|
|
14
|
+
{
|
|
15
|
+
defaultValue: value,
|
|
16
|
+
placeholder: "Select color",
|
|
17
|
+
listItems: colorList,
|
|
18
|
+
renderValue: (value2, opt) => opt?.label ?? value2,
|
|
19
|
+
onChange: (value2) => {
|
|
20
|
+
const next = value2 ? set(value2) : unset();
|
|
21
|
+
return onChange(next);
|
|
22
|
+
},
|
|
23
|
+
renderSelected: (value2) => renderSelected ? renderSelected(value2) : /* @__PURE__ */ jsx(Avatar, { style: { backgroundColor: value2 } }),
|
|
24
|
+
renderOption: ({ label, value: value2 }) => renderOption ? renderOption({ label, value: value2 }) : /* @__PURE__ */ jsx(Card, { as: "button", children: /* @__PURE__ */ jsxs(Flex, { align: "center", padding: 2, children: [
|
|
25
|
+
/* @__PURE__ */ jsx(Avatar, { size: 1, style: { backgroundColor: value2 } }),
|
|
26
|
+
/* @__PURE__ */ jsx(Box, { flex: 1, padding: 2, children: /* @__PURE__ */ jsx(Text, { size: 2, children: label }) })
|
|
27
|
+
] }) })
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
const typeName = "wild.color", wildSanityColorFieldPlugin = definePlugin((config) => ({
|
|
32
|
+
name: "@madebywild/sanity-color-field",
|
|
33
|
+
schema: {
|
|
34
|
+
types: [
|
|
35
|
+
defineType({
|
|
36
|
+
name: typeName,
|
|
37
|
+
type: "string",
|
|
38
|
+
title: "Color",
|
|
39
|
+
description: "Select a color.",
|
|
40
|
+
icon: () => /* @__PURE__ */ jsx(Fragment, { children: "\u{1F3A8}" }),
|
|
41
|
+
components: {
|
|
42
|
+
input: (props) => /* @__PURE__ */ jsx(ColorInput, { config, ...props })
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
4
48
|
export {
|
|
5
49
|
typeName,
|
|
6
50
|
wildSanityColorFieldPlugin
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/input.tsx","../src/types.ts","../src/index.tsx"],"sourcesContent":["import { AsyncAutocomplete } from \"@madebywild/sanity-utils\";\nimport { Avatar, Box, Card, Flex, Text } from \"@sanity/ui\";\nimport { type StringInputProps, set, unset } from \"sanity\";\nimport type { FieldOptions, PluginConfig } from \"./types\";\n\nfunction ColorInput({\n config,\n schemaType,\n onChange,\n value,\n}: StringInputProps & {\n config: PluginConfig;\n}) {\n const options = schemaType.options as FieldOptions | undefined;\n const colorList = options?.colorList ?? config.colorList;\n const renderOption = options?.renderOption ?? config.renderOption;\n const renderSelected = options?.renderSelected ?? config.renderSelected;\n\n return (\n <AsyncAutocomplete\n defaultValue={value}\n placeholder=\"Select color\"\n listItems={colorList}\n renderValue={(value, opt) => opt?.label ?? value}\n onChange={(value) => {\n const next = value ? set(value) : unset();\n return onChange(next);\n }}\n renderSelected={(value) => {\n if (renderSelected) return renderSelected(value);\n return <Avatar style={{ backgroundColor: value }} />;\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 <Avatar size={1} style={{ backgroundColor: value }} />\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 { ColorInput };\n","import type { ListItemsGetter } from \"@madebywild/sanity-utils\";\nimport type { StringDefinition, StringOptions } from \"sanity\";\n\n/** @public */\nexport type PluginConfig = {\n colorList: ListItemsGetter;\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 colorList?: ListItemsGetter;\n renderSelected?: (value: string) => React.JSX.Element;\n renderOption?: (item: { label?: string; value: string }) => React.JSX.Element;\n};\n\n/** @public */\nexport const typeName = \"wild.color\" as const;\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\"> & {\n type: typeof typeName;\n options?: FieldOptions;\n };\n }\n}\n","import { definePlugin, defineType } from \"sanity\";\nimport { ColorInput } from \"./input\";\nimport { type FieldOptions, type PluginConfig, typeName } from \"./types\";\n\n/** @public */\nconst wildSanityColorFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-color-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"string\",\n title: \"Color\",\n description: \"Select a color.\",\n icon: () => <>🎨</>,\n components: {\n input: (props) => <ColorInput config={config} {...props} />,\n },\n }),\n ],\n },\n };\n});\n\nexport { wildSanityColorFieldPlugin, type PluginConfig, type FieldOptions, typeName };\n"],"names":["value"],"mappings":";;;;AAKA,SAAS,WAAW;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAEG;AACD,QAAM,UAAU,WAAW,SACrB,YAAY,SAAS,aAAa,OAAO,WACzC,eAAe,SAAS,gBAAgB,OAAO,cAC/C,iBAAiB,SAAS,kBAAkB,OAAO;AAEzD,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,cAAc;AAAA,MACd,aAAY;AAAA,MACZ,WAAW;AAAA,MACX,aAAa,CAACA,QAAO,QAAQ,KAAK,SAASA;AAAAA,MAC3C,UAAU,CAACA,WAAU;AACnB,cAAM,OAAOA,SAAQ,IAAIA,MAAK,IAAI,MAAA;AAClC,eAAO,SAAS,IAAI;AAAA,MACtB;AAAA,MACA,gBAAgB,CAACA,WACX,iBAAuB,eAAeA,MAAK,IACxC,oBAAC,QAAA,EAAO,OAAO,EAAE,iBAAiBA,SAAM,CAAG;AAAA,MAEpD,cAAc,CAAC,EAAE,OAAO,OAAAA,aAClB,eAAqB,aAAa,EAAE,OAAO,OAAAA,QAAO,IAEpD,oBAAC,MAAA,EAAK,IAAG,UACP,+BAAC,MAAA,EAAK,OAAM,UAAS,SAAS,GAC5B,UAAA;AAAA,QAAA,oBAAC,UAAO,MAAM,GAAG,OAAO,EAAE,iBAAiBA,UAAS;AAAA,QACpD,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;AC7BO,MAAM,WAAW,cCblB,6BAA6B,aAA2B,CAAC,YACtD;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,8BAAW,YAAA,EAAW,QAAiB,GAAG,MAAA,CAAO;AAAA,QAAA;AAAA,MAC3D,CACD;AAAA,IAAA;AAAA,EACH;AAEJ,EACD;"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"browserslist": "extends @sanity/browserslist-config",
|
|
7
|
-
"version": "0.0.
|
|
7
|
+
"version": "0.0.5",
|
|
8
8
|
"exports": {
|
|
9
9
|
"./package.json": "./package.json",
|
|
10
10
|
".": {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@madebywild/sanity-utils": "*"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
+
"@sanity/ui": "^3.1.11",
|
|
33
34
|
"sanity": "^4.17",
|
|
34
35
|
"react": "^19",
|
|
35
36
|
"react-dom": "^19"
|