@sanity/color-input 3.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/schemas/hslaColor.ts","../src/schemas/rgbaColor.ts","../src/ColorPickerFields.tsx","../src/ColorPicker.tsx","../src/ColorInput.tsx","../src/schemas/color.tsx","../src/schemas/hsvaColor.ts","../src/index.ts"],"sourcesContent":["import {defineType} from 'sanity'\n\nexport const hslaColor = defineType({\n title: 'Hue Saturation Lightness',\n name: 'hslaColor',\n type: 'object',\n fields: [\n {name: 'h', type: 'number', title: 'Hue'},\n {name: 's', type: 'number', title: 'Saturation'},\n {name: 'l', type: 'number', title: 'Lightness'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n})\n","import {defineType} from 'sanity'\n\nexport const rgbaColor = defineType({\n title: 'Red Green Blue (rgb)',\n name: 'rgbaColor',\n type: 'object',\n fields: [\n {name: 'r', type: 'number', title: 'Red'},\n {name: 'g', type: 'number', title: 'Green'},\n {name: 'b', type: 'number', title: 'Blue'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n})\n","import React, {useCallback, useMemo} from 'react'\n// @ts-expect-error missing export\nimport {isValidHex} from 'react-color/lib/helpers/color'\nimport {EditableInput} from 'react-color/lib/components/common'\nimport {Box, Flex, useTheme} from '@sanity/ui'\nimport {ColorChangeHandler, HEXColor, HSLColor, HSVColor, RGBColor} from 'react-color'\nimport {EditableInputStyles} from 'react-color/lib/components/common/EditableInput'\n\ninterface ColorPickerFieldsProps {\n rgb?: RGBColor\n hsl?: HSLColor\n hex?: string\n disableAlpha: boolean\n onChange: ColorChangeHandler<HSLColor | HSVColor | RGBColor | HEXColor>\n}\n\nexport const ColorPickerFields = ({\n onChange,\n rgb,\n hsl,\n hex,\n disableAlpha,\n}: ColorPickerFieldsProps) => {\n const {sanity} = useTheme()\n\n const inputStyles: EditableInputStyles = useMemo(\n () => ({\n input: {\n width: '80%',\n padding: '4px 10% 3px',\n border: 'none',\n boxShadow: `inset 0 0 0 1px ${sanity.color.input.default.enabled.border}`,\n color: sanity.color.input.default.enabled.fg,\n backgroundColor: sanity.color.input.default.enabled.bg,\n fontSize: sanity.fonts.text.sizes[0].fontSize,\n textAlign: 'center',\n },\n label: {\n display: 'block',\n textAlign: 'center',\n fontSize: sanity.fonts.label.sizes[0].fontSize,\n color: sanity.color.base.fg,\n paddingTop: '3px',\n paddingBottom: '4px',\n textTransform: 'capitalize',\n },\n }),\n [sanity]\n )\n\n const handleChange: ColorChangeHandler<Record<string, string>> = useCallback(\n (data) => {\n if ('hex' in data && data.hex && isValidHex(data.hex)) {\n onChange({\n hex: data.hex,\n source: 'hex',\n })\n } else if (\n rgb &&\n (('r' in data && data.r) || ('g' in data && data.g) || ('b' in data && data.b))\n ) {\n onChange({\n r: Number(data.r) || rgb.r,\n g: Number(data.g) || rgb.g,\n b: Number(data.b) || rgb.b,\n a: rgb.a,\n source: 'rgb',\n })\n } else if (hsl && 'a' in data && data.a) {\n let alpha = Number(data.a)\n if (alpha < 0) {\n alpha = 0\n } else if (alpha > 100) {\n alpha = 100\n }\n alpha /= 100\n\n onChange({\n h: hsl.h,\n s: hsl.s,\n l: hsl.l,\n a: alpha,\n source: 'hsl',\n })\n }\n },\n [onChange, hsl, rgb]\n )\n\n return (\n <Flex>\n <Box flex={2} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"hex\"\n value={hex?.replace('#', '')}\n onChange={handleChange}\n />\n </Box>\n <Box flex={1} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"r\"\n value={rgb?.r}\n onChange={handleChange}\n dragLabel\n dragMax={255}\n />\n </Box>\n <Box flex={1} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"g\"\n value={rgb?.g}\n onChange={handleChange}\n dragLabel\n dragMax={255}\n />\n </Box>\n <Box flex={1} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"b\"\n value={rgb?.b}\n onChange={handleChange}\n dragLabel\n dragMax={255}\n />\n </Box>\n {!disableAlpha && (\n <Box flex={1}>\n <EditableInput\n style={inputStyles}\n label=\"a\"\n value={Math.round((rgb?.a ?? 1) * 100)}\n onChange={handleChange}\n dragLabel\n dragMax={100}\n />\n </Box>\n )}\n </Flex>\n )\n}\n","import React from 'react'\nimport {Alpha, Checkboard, Hue, Saturation} from 'react-color/lib/components/common'\nimport {CustomPicker, HEXColor, HSLColor, HSVColor, RGBColor} from 'react-color'\nimport {Box, Button, Card, Flex, Inline, Stack, Text} from '@sanity/ui'\nimport {TrashIcon} from '@sanity/icons'\nimport styled from 'styled-components'\nimport {ColorPickerFields} from './ColorPickerFields'\nimport {CustomPickerInjectedProps} from 'react-color/lib/components/common/ColorWrap'\nimport {ColorValue} from './ColorInput'\n\nconst ColorBox = styled(Box)`\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n`\n\nconst ReadOnlyContainer = styled(Flex)`\n margin-top: 6rem;\n background-color: var(--card-bg-color);\n position: relative;\n width: 100%;\n`\n\nexport interface ColorPickerProps\n extends CustomPickerInjectedProps<HSLColor | HSVColor | RGBColor | HEXColor> {\n width?: string\n disableAlpha: boolean\n readOnly?: boolean\n onUnset: () => void\n color: ColorValue\n}\n\nconst ColorPickerInner = (props: ColorPickerProps) => {\n const {\n width,\n color: {rgb, hex, hsv, hsl},\n onChange,\n onUnset,\n disableAlpha,\n readOnly,\n } = props\n\n if (!hsl || !hsv) {\n return null\n }\n\n return (\n <div style={{width}}>\n <Card padding={1} border radius={1}>\n <Stack space={2}>\n {!readOnly && (\n <>\n <Card overflow=\"hidden\" style={{position: 'relative', height: '5em'}}>\n <Saturation onChange={onChange} hsl={hsl} hsv={hsv} />\n </Card>\n\n <Card\n shadow={1}\n radius={3}\n overflow=\"hidden\"\n style={{position: 'relative', height: '10px'}}\n >\n <Hue hsl={hsl} onChange={!readOnly && onChange} />\n </Card>\n\n {!disableAlpha && (\n <Card\n shadow={1}\n radius={3}\n overflow=\"hidden\"\n style={{position: 'relative', height: '10px'}}\n >\n <Alpha rgb={rgb} hsl={hsl} onChange={onChange} />\n </Card>\n )}\n </>\n )}\n <Flex>\n <Card\n flex={1}\n radius={2}\n overflow=\"hidden\"\n style={{position: 'relative', minWidth: '4em'}}\n >\n <Checkboard />\n <ColorBox\n style={{\n backgroundColor: `rgba(${rgb?.r},${rgb?.g},${rgb?.b},${rgb?.a})`,\n }}\n />\n\n {readOnly && (\n <ReadOnlyContainer\n padding={2}\n paddingBottom={1}\n sizing=\"border\"\n justify=\"space-between\"\n >\n <Stack space={3} marginTop={1}>\n <Text size={3} weight=\"bold\">\n {hex}\n </Text>\n\n <Inline space={3}>\n <Text size={1}>\n <strong>RGB: </strong>\n {rgb?.r} {rgb?.g} {rgb?.b}\n </Text>\n <Text size={1}>\n <strong>HSL: </strong> {Math.round(hsl?.h ?? 0)} {Math.round(hsl?.s ?? 0)}%{' '}\n {Math.round(hsl?.l ?? 0)}\n </Text>\n </Inline>\n </Stack>\n </ReadOnlyContainer>\n )}\n </Card>\n\n {!readOnly && (\n <Flex align=\"flex-start\" marginLeft={2}>\n <Box style={{width: 200}}>\n <ColorPickerFields\n rgb={rgb}\n hsl={hsl}\n hex={hex}\n onChange={onChange}\n disableAlpha={disableAlpha}\n />\n </Box>\n <Box marginLeft={2}>\n <Button onClick={onUnset} title=\"Delete color\" icon={TrashIcon} tone=\"critical\" />\n </Box>\n </Flex>\n )}\n </Flex>\n </Stack>\n </Card>\n </div>\n )\n}\n\nexport const ColorPicker = CustomPicker(ColorPickerInner)\n","import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'\nimport {ObjectOptions, set, setIfMissing, unset} from 'sanity'\nimport {debounce} from 'lodash'\nimport {Button} from '@sanity/ui'\nimport {AddIcon} from '@sanity/icons'\nimport {ColorPicker} from './ColorPicker'\nimport {ObjectInputProps} from 'sanity'\nimport {HSLColor, HSVColor, RGBColor} from 'react-color'\nimport {ObjectSchemaType} from 'sanity'\n\nconst DEFAULT_COLOR: ColorValue & {source: string} = {\n hex: '#24a3e3',\n hsl: {h: 200, s: 0.7732, l: 0.5156, a: 1},\n hsv: {h: 200, s: 0.8414, v: 0.8901, a: 1},\n rgb: {r: 46, g: 163, b: 227, a: 1},\n source: 'hex',\n}\n\nexport interface ColorValue {\n hex: string\n hsl: HSLColor\n hsv: HSVColor\n rgb: RGBColor\n}\n\nexport interface ColorOptions extends Omit<ObjectOptions, 'columns'> {\n disableAlpha?: boolean\n}\n\nexport type ColorSchemaType = Omit<ObjectSchemaType, 'options'> & {\n options?: ColorOptions\n}\nexport type ColorInputProps = ObjectInputProps<ColorValue, ColorSchemaType>\n\nexport function ColorInput(props: ColorInputProps) {\n const {onChange, schemaType: type, readOnly, value} = props\n const focusRef = useRef<HTMLButtonElement>(null)\n\n // use local state so we can have instant ui updates while debouncing patch emits\n const [color, setColor] = useState(value)\n useEffect(() => setColor(value), [value])\n\n const emitSetColor = useCallback(\n (nextColor: ColorValue) => {\n const fieldPatches = type.fields\n .filter((field) => field.name in nextColor)\n .map((field) => {\n const nextFieldValue = nextColor[field.name as keyof ColorValue]\n const isObject = field.type.jsonType === 'object'\n return set(\n isObject ? Object.assign({_type: field.type.name}, nextFieldValue) : nextFieldValue,\n [field.name]\n )\n })\n\n onChange([\n setIfMissing({_type: type.name}),\n set(type.name, ['_type']),\n set(nextColor.rgb?.a, ['alpha']),\n ...fieldPatches,\n ])\n },\n [onChange, type]\n )\n\n // The color picker emits onChange events continuously while the user is sliding the\n // hue/saturation/alpha selectors. This debounces the event to avoid excessive patches\n const debouncedColorChange = useMemo(() => debounce(emitSetColor, 100), [emitSetColor])\n const handleColorChange = useCallback(\n (nextColor: ColorValue) => {\n setColor(nextColor)\n debouncedColorChange(nextColor)\n },\n [debouncedColorChange, setColor]\n )\n\n const handleCreateColor = useCallback(() => {\n setColor(DEFAULT_COLOR)\n emitSetColor(DEFAULT_COLOR)\n }, [emitSetColor])\n\n const handleUnset = useCallback(() => {\n setColor(undefined)\n onChange(unset())\n }, [onChange])\n\n return (\n <>\n {value ? (\n <ColorPicker\n /* ref={this.focusRef}*/\n color={color}\n onChange={handleColorChange}\n readOnly={readOnly || (typeof type.readOnly === 'boolean' && type.readOnly)}\n disableAlpha={!!type.options?.disableAlpha}\n onUnset={handleUnset}\n />\n ) : (\n <Button\n icon={AddIcon}\n mode=\"ghost\"\n text=\"Create color\"\n ref={focusRef}\n disabled={Boolean(readOnly)}\n onClick={handleCreateColor}\n />\n )}\n </>\n )\n}\n","import React from 'react'\nimport {ColorInput, ColorOptions} from '../ColorInput'\nimport {defineType, ObjectDefinition} from 'sanity'\n\nconst round = (val: number = 1) => Math.round(val * 100)\n\nconst colorTypeName = 'color' as const\n\n/**\n * @public\n */\nexport interface ColorDefinition extends Omit<ObjectDefinition, 'type' | 'fields' | 'options'> {\n type: typeof colorTypeName\n options?: ColorOptions\n}\n\ndeclare module '@sanity/types' {\n // makes type: 'color' narrow correctly when using defineTyp/defineField/defineArrayMember\n export interface IntrinsicDefinitions {\n color: ColorDefinition\n }\n}\n\nexport const color = defineType({\n name: colorTypeName,\n type: 'object',\n title: 'Color',\n ...({components: {input: ColorInput}} as {}), //TODO revert this change when sanity 3.0.0-rc.1 is released\n fields: [\n {\n title: 'Hex',\n name: 'hex',\n type: 'string',\n },\n {\n title: 'Alpha',\n name: 'alpha',\n type: 'number',\n },\n {\n title: 'Hue Saturation Lightness',\n name: 'hsl',\n type: 'hslaColor',\n },\n {\n title: 'Hue Saturation Value',\n name: 'hsv',\n type: 'hsvaColor',\n },\n {\n title: 'Red Green Blue (rgb)',\n name: 'rgb',\n type: 'rgbaColor',\n },\n ],\n preview: {\n select: {\n title: 'hex',\n alpha: 'alpha',\n hex: 'hex',\n hsl: 'hsl',\n },\n prepare({\n title,\n hex,\n hsl,\n alpha,\n }: {\n title?: string\n alpha?: number\n hex?: string\n hsl?: {h: number; s: number; l: number}\n }) {\n let subtitle = hex || 'No color set'\n if (hsl) {\n subtitle = `H:${round(hsl.h)} S:${round(hsl.s)} L:${round(hsl.l)} A:${round(alpha)}`\n }\n return {\n title: title,\n subtitle: subtitle,\n media: () => (\n <div\n style={{\n backgroundColor: hex ?? '#000',\n opacity: alpha ?? 1,\n position: 'absolute',\n height: '100%',\n width: '100%',\n top: '0',\n left: '0',\n }}\n />\n ),\n }\n },\n },\n})\n","import {defineType} from 'sanity'\n\nexport const hsvaColor = defineType({\n title: 'Hue Saturation Value',\n name: 'hsvaColor',\n type: 'object',\n fields: [\n {name: 'h', type: 'number', title: 'Hue'},\n {name: 's', type: 'number', title: 'Saturation'},\n {name: 'v', type: 'number', title: 'Value'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n})\n","import {definePlugin} from 'sanity'\nimport {hslaColor} from './schemas/hslaColor'\nimport {rgbaColor} from './schemas/rgbaColor'\nimport {color, ColorDefinition} from './schemas/color'\nimport {hsvaColor} from './schemas/hsvaColor'\n\nexport const colorInput = definePlugin({\n name: '@sanity/color-input',\n schema: {\n types: [hslaColor, hsvaColor, rgbaColor, color],\n },\n})\n\nexport {hslaColor, rgbaColor, color, hsvaColor}\nexport {ColorInput} from './ColorInput'\nexport type {ColorDefinition}\nexport type {ColorValue, ColorInputProps, ColorOptions, ColorSchemaType} from './ColorInput'\n"],"names":["hslaColor","defineType","title","name","type","fields","rgbaColor","ColorPickerFields","_ref","onChange","rgb","hsl","hex","disableAlpha","_a","sanity","useTheme","inputStyles","useMemo","input","width","padding","border","boxShadow","color","default","enabled","fg","backgroundColor","bg","fontSize","fonts","text","sizes","textAlign","label","display","base","paddingTop","paddingBottom","textTransform","handleChange","useCallback","data","isValidHex","source","r","g","b","Number","a","alpha","h","s","l","jsxs","Flex","children","jsx","Box","flex","marginRight","EditableInput","style","value","replace","dragLabel","dragMax","Math","round","ColorBox","styled","_templateObject","_taggedTemplateLiteral","ReadOnlyContainer","_templateObject2","ColorPicker","CustomPicker","props","_b","_c","hsv","onUnset","readOnly","Card","radius","Stack","space","Fragment","overflow","position","height","Saturation","shadow","Hue","Alpha","minWidth","Checkboard","concat","sizing","justify","marginTop","Text","size","weight","Inline","align","marginLeft","Button","onClick","icon","TrashIcon","tone","DEFAULT_COLOR","v","ColorInput","schemaType","focusRef","useRef","setColor","useState","useEffect","emitSetColor","nextColor","fieldPatches","filter","field","map","nextFieldValue","isObject","jsonType","set","Object","assign","_type","setIfMissing","debouncedColorChange","debounce","handleColorChange","handleCreateColor","handleUnset","unset","options","AddIcon","mode","ref","disabled","Boolean","val","_objectSpread","components","preview","select","prepare","_ref2","subtitle","media","opacity","top","left","hsvaColor","colorInput","definePlugin","schema","types"],"mappings":"6+CAEO,MAAMA,EAAYC,EAAW,CAClCC,MAAO,2BACPC,KAAM,YACNC,KAAM,SACNC,OAAQ,CACN,CAACF,KAAM,IAAKC,KAAM,SAAUF,MAAO,OACnC,CAACC,KAAM,IAAKC,KAAM,SAAUF,MAAO,cACnC,CAACC,KAAM,IAAKC,KAAM,SAAUF,MAAO,aACnC,CAACC,KAAM,IAAKC,KAAM,SAAUF,MAAO,YCR1BI,EAAYL,EAAW,CAClCC,MAAO,uBACPC,KAAM,YACNC,KAAM,SACNC,OAAQ,CACN,CAACF,KAAM,IAAKC,KAAM,SAAUF,MAAO,OACnC,CAACC,KAAM,IAAKC,KAAM,SAAUF,MAAO,SACnC,CAACC,KAAM,IAAKC,KAAM,SAAUF,MAAO,QACnC,CAACC,KAAM,IAAKC,KAAM,SAAUF,MAAO,YCM1BK,EAAoBC,IAMH,IANIC,SAChCA,EAAAC,IACAA,EAAAC,IACAA,EAAAC,IACAA,EAAAC,aACAA,GAC4BL,EAtB9B,IAAAM,EAuBQ,MAAAC,OAACA,GAAUC,IAEXC,EAAmCC,GACvC,KAAO,CACLC,MAAO,CACLC,MAAO,MACPC,QAAS,cACTC,OAAQ,OACRC,UAA8BR,mBAAAA,OAAAA,EAAOS,MAAML,MAAMM,QAAQC,QAAQJ,QACjEE,MAAOT,EAAOS,MAAML,MA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J,KAAM,sBACNgK,OAAQ,CACNC,MAAO,CAACpK,EAAWgK,EAAW1J,EAAWkB"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/schemas/hslaColor.ts","../src/schemas/rgbaColor.ts","../src/ColorPickerFields.tsx","../src/ColorPicker.tsx","../src/ColorInput.tsx","../src/schemas/color.tsx","../src/schemas/hsvaColor.ts","../src/index.ts"],"sourcesContent":["import {defineType} from 'sanity'\n\nexport const hslaColor = defineType({\n title: 'Hue Saturation Lightness',\n name: 'hslaColor',\n type: 'object',\n fields: [\n {name: 'h', type: 'number', title: 'Hue'},\n {name: 's', type: 'number', title: 'Saturation'},\n {name: 'l', type: 'number', title: 'Lightness'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n})\n","import {defineType} from 'sanity'\n\nexport const rgbaColor = defineType({\n title: 'Red Green Blue (rgb)',\n name: 'rgbaColor',\n type: 'object',\n fields: [\n {name: 'r', type: 'number', title: 'Red'},\n {name: 'g', type: 'number', title: 'Green'},\n {name: 'b', type: 'number', title: 'Blue'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n})\n","import React, {useCallback, useMemo} from 'react'\n// @ts-expect-error missing export\nimport {isValidHex} from 'react-color/lib/helpers/color'\nimport {EditableInput} from 'react-color/lib/components/common'\nimport {Box, Flex, useTheme} from '@sanity/ui'\nimport {ColorChangeHandler, HEXColor, HSLColor, HSVColor, RGBColor} from 'react-color'\nimport {EditableInputStyles} from 'react-color/lib/components/common/EditableInput'\n\ninterface ColorPickerFieldsProps {\n rgb?: RGBColor\n hsl?: HSLColor\n hex?: string\n disableAlpha: boolean\n onChange: ColorChangeHandler<HSLColor | HSVColor | RGBColor | HEXColor>\n}\n\nexport const ColorPickerFields = ({\n onChange,\n rgb,\n hsl,\n hex,\n disableAlpha,\n}: ColorPickerFieldsProps) => {\n const {sanity} = useTheme()\n\n const inputStyles: EditableInputStyles = useMemo(\n () => ({\n input: {\n width: '80%',\n padding: '4px 10% 3px',\n border: 'none',\n boxShadow: `inset 0 0 0 1px ${sanity.color.input.default.enabled.border}`,\n color: sanity.color.input.default.enabled.fg,\n backgroundColor: sanity.color.input.default.enabled.bg,\n fontSize: sanity.fonts.text.sizes[0].fontSize,\n textAlign: 'center',\n },\n label: {\n display: 'block',\n textAlign: 'center',\n fontSize: sanity.fonts.label.sizes[0].fontSize,\n color: sanity.color.base.fg,\n paddingTop: '3px',\n paddingBottom: '4px',\n textTransform: 'capitalize',\n },\n }),\n [sanity]\n )\n\n const handleChange: ColorChangeHandler<Record<string, string>> = useCallback(\n (data) => {\n if ('hex' in data && data.hex && isValidHex(data.hex)) {\n onChange({\n hex: data.hex,\n source: 'hex',\n })\n } else if (\n rgb &&\n (('r' in data && data.r) || ('g' in data && data.g) || ('b' in data && data.b))\n ) {\n onChange({\n r: Number(data.r) || rgb.r,\n g: Number(data.g) || rgb.g,\n b: Number(data.b) || rgb.b,\n a: rgb.a,\n source: 'rgb',\n })\n } else if (hsl && 'a' in data && data.a) {\n let alpha = Number(data.a)\n if (alpha < 0) {\n alpha = 0\n } else if (alpha > 100) {\n alpha = 100\n }\n alpha /= 100\n\n onChange({\n h: hsl.h,\n s: hsl.s,\n l: hsl.l,\n a: alpha,\n source: 'hsl',\n })\n }\n },\n [onChange, hsl, rgb]\n )\n\n return (\n <Flex>\n <Box flex={2} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"hex\"\n value={hex?.replace('#', '')}\n onChange={handleChange}\n />\n </Box>\n <Box flex={1} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"r\"\n value={rgb?.r}\n onChange={handleChange}\n dragLabel\n dragMax={255}\n />\n </Box>\n <Box flex={1} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"g\"\n value={rgb?.g}\n onChange={handleChange}\n dragLabel\n dragMax={255}\n />\n </Box>\n <Box flex={1} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"b\"\n value={rgb?.b}\n onChange={handleChange}\n dragLabel\n dragMax={255}\n />\n </Box>\n {!disableAlpha && (\n <Box flex={1}>\n <EditableInput\n style={inputStyles}\n label=\"a\"\n value={Math.round((rgb?.a ?? 1) * 100)}\n onChange={handleChange}\n dragLabel\n dragMax={100}\n />\n </Box>\n )}\n </Flex>\n )\n}\n","import React from 'react'\nimport {Alpha, Checkboard, Hue, Saturation} from 'react-color/lib/components/common'\nimport {CustomPicker, HEXColor, HSLColor, HSVColor, RGBColor} from 'react-color'\nimport {Box, Button, Card, Flex, Inline, Stack, Text} from '@sanity/ui'\nimport {TrashIcon} from '@sanity/icons'\nimport styled from 'styled-components'\nimport {ColorPickerFields} from './ColorPickerFields'\nimport {CustomPickerInjectedProps} from 'react-color/lib/components/common/ColorWrap'\nimport {ColorValue} from './ColorInput'\n\nconst ColorBox = styled(Box)`\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n`\n\nconst ReadOnlyContainer = styled(Flex)`\n margin-top: 6rem;\n background-color: var(--card-bg-color);\n position: relative;\n width: 100%;\n`\n\nexport interface ColorPickerProps\n extends CustomPickerInjectedProps<HSLColor | HSVColor | RGBColor | HEXColor> {\n width?: string\n disableAlpha: boolean\n readOnly?: boolean\n onUnset: () => void\n color: ColorValue\n}\n\nconst ColorPickerInner = (props: ColorPickerProps) => {\n const {\n width,\n color: {rgb, hex, hsv, hsl},\n onChange,\n onUnset,\n disableAlpha,\n readOnly,\n } = props\n\n if (!hsl || !hsv) {\n return null\n }\n\n return (\n <div style={{width}}>\n <Card padding={1} border radius={1}>\n <Stack space={2}>\n {!readOnly && (\n <>\n <Card overflow=\"hidden\" style={{position: 'relative', height: '5em'}}>\n <Saturation onChange={onChange} hsl={hsl} hsv={hsv} />\n </Card>\n\n <Card\n shadow={1}\n radius={3}\n overflow=\"hidden\"\n style={{position: 'relative', height: '10px'}}\n >\n <Hue hsl={hsl} onChange={!readOnly && onChange} />\n </Card>\n\n {!disableAlpha && (\n <Card\n shadow={1}\n radius={3}\n overflow=\"hidden\"\n style={{position: 'relative', height: '10px'}}\n >\n <Alpha rgb={rgb} hsl={hsl} onChange={onChange} />\n </Card>\n )}\n </>\n )}\n <Flex>\n <Card\n flex={1}\n radius={2}\n overflow=\"hidden\"\n style={{position: 'relative', minWidth: '4em'}}\n >\n <Checkboard />\n <ColorBox\n style={{\n backgroundColor: `rgba(${rgb?.r},${rgb?.g},${rgb?.b},${rgb?.a})`,\n }}\n />\n\n {readOnly && (\n <ReadOnlyContainer\n padding={2}\n paddingBottom={1}\n sizing=\"border\"\n justify=\"space-between\"\n >\n <Stack space={3} marginTop={1}>\n <Text size={3} weight=\"bold\">\n {hex}\n </Text>\n\n <Inline space={3}>\n <Text size={1}>\n <strong>RGB: </strong>\n {rgb?.r} {rgb?.g} {rgb?.b}\n </Text>\n <Text size={1}>\n <strong>HSL: </strong> {Math.round(hsl?.h ?? 0)} {Math.round(hsl?.s ?? 0)}%{' '}\n {Math.round(hsl?.l ?? 0)}\n </Text>\n </Inline>\n </Stack>\n </ReadOnlyContainer>\n )}\n </Card>\n\n {!readOnly && (\n <Flex align=\"flex-start\" marginLeft={2}>\n <Box style={{width: 200}}>\n <ColorPickerFields\n rgb={rgb}\n hsl={hsl}\n hex={hex}\n onChange={onChange}\n disableAlpha={disableAlpha}\n />\n </Box>\n <Box marginLeft={2}>\n <Button onClick={onUnset} title=\"Delete color\" icon={TrashIcon} tone=\"critical\" />\n </Box>\n </Flex>\n )}\n </Flex>\n </Stack>\n </Card>\n </div>\n )\n}\n\nexport const ColorPicker = CustomPicker(ColorPickerInner)\n","import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'\nimport {ObjectOptions, set, setIfMissing, unset} from 'sanity'\nimport {debounce} from 'lodash'\nimport {Button} from '@sanity/ui'\nimport {AddIcon} from '@sanity/icons'\nimport {ColorPicker} from './ColorPicker'\nimport {ObjectInputProps} from 'sanity'\nimport {HSLColor, HSVColor, RGBColor} from 'react-color'\nimport {ObjectSchemaType} from 'sanity'\n\nconst DEFAULT_COLOR: ColorValue & {source: string} = {\n hex: '#24a3e3',\n hsl: {h: 200, s: 0.7732, l: 0.5156, a: 1},\n hsv: {h: 200, s: 0.8414, v: 0.8901, a: 1},\n rgb: {r: 46, g: 163, b: 227, a: 1},\n source: 'hex',\n}\n\nexport interface ColorValue {\n hex: string\n hsl: HSLColor\n hsv: HSVColor\n rgb: RGBColor\n}\n\nexport interface ColorOptions extends Omit<ObjectOptions, 'columns'> {\n disableAlpha?: boolean\n}\n\nexport type ColorSchemaType = Omit<ObjectSchemaType, 'options'> & {\n options?: ColorOptions\n}\nexport type ColorInputProps = ObjectInputProps<ColorValue, ColorSchemaType>\n\nexport function ColorInput(props: ObjectInputProps) {\n const {onChange, readOnly} = props\n const value = props.value as ColorValue | undefined\n const type = props.schemaType as ColorSchemaType\n const focusRef = useRef<HTMLButtonElement>(null)\n\n // use local state so we can have instant ui updates while debouncing patch emits\n const [color, setColor] = useState(value)\n useEffect(() => setColor(value), [value])\n\n const emitSetColor = useCallback(\n (nextColor: ColorValue) => {\n const fieldPatches = type.fields\n .filter((field) => field.name in nextColor)\n .map((field) => {\n const nextFieldValue = nextColor[field.name as keyof ColorValue]\n const isObject = field.type.jsonType === 'object'\n return set(\n isObject ? Object.assign({_type: field.type.name}, nextFieldValue) : nextFieldValue,\n [field.name]\n )\n })\n\n onChange([\n setIfMissing({_type: type.name}),\n set(type.name, ['_type']),\n set(nextColor.rgb?.a, ['alpha']),\n ...fieldPatches,\n ])\n },\n [onChange, type]\n )\n\n // The color picker emits onChange events continuously while the user is sliding the\n // hue/saturation/alpha selectors. This debounces the event to avoid excessive patches\n const debouncedColorChange = useMemo(() => debounce(emitSetColor, 100), [emitSetColor])\n const handleColorChange = useCallback(\n (nextColor: ColorValue) => {\n setColor(nextColor)\n debouncedColorChange(nextColor)\n },\n [debouncedColorChange, setColor]\n )\n\n const handleCreateColor = useCallback(() => {\n setColor(DEFAULT_COLOR)\n emitSetColor(DEFAULT_COLOR)\n }, [emitSetColor])\n\n const handleUnset = useCallback(() => {\n setColor(undefined)\n onChange(unset())\n }, [onChange])\n\n return (\n <>\n {value && value.hex ? (\n <ColorPicker\n /* ref={this.focusRef}*/\n color={color}\n onChange={handleColorChange}\n readOnly={readOnly || (typeof type.readOnly === 'boolean' && type.readOnly)}\n disableAlpha={!!type.options?.disableAlpha}\n onUnset={handleUnset}\n />\n ) : (\n <Button\n icon={AddIcon}\n mode=\"ghost\"\n text=\"Create color\"\n ref={focusRef}\n disabled={Boolean(readOnly)}\n onClick={handleCreateColor}\n />\n )}\n </>\n )\n}\n","import React from 'react'\nimport {ColorInput, ColorOptions} from '../ColorInput'\nimport {defineType, ObjectDefinition} from 'sanity'\n\nconst round = (val: number = 1) => Math.round(val * 100)\n\nconst colorTypeName = 'color' as const\n\n/**\n * @public\n */\nexport interface ColorDefinition extends Omit<ObjectDefinition, 'type' | 'fields' | 'options'> {\n type: typeof colorTypeName\n options?: ColorOptions\n}\n\ndeclare module '@sanity/types' {\n // makes type: 'color' narrow correctly when using defineTyp/defineField/defineArrayMember\n export interface IntrinsicDefinitions {\n color: ColorDefinition\n }\n}\n\nexport const color = defineType({\n name: colorTypeName,\n type: 'object',\n title: 'Color',\n components: {input: ColorInput},\n fields: [\n {\n title: 'Hex',\n name: 'hex',\n type: 'string',\n },\n {\n title: 'Alpha',\n name: 'alpha',\n type: 'number',\n },\n {\n title: 'Hue Saturation Lightness',\n name: 'hsl',\n type: 'hslaColor',\n },\n {\n title: 'Hue Saturation Value',\n name: 'hsv',\n type: 'hsvaColor',\n },\n {\n title: 'Red Green Blue (rgb)',\n name: 'rgb',\n type: 'rgbaColor',\n },\n ],\n preview: {\n select: {\n title: 'hex',\n alpha: 'alpha',\n hex: 'hex',\n hsl: 'hsl',\n },\n prepare({\n title,\n hex,\n hsl,\n alpha,\n }: {\n title?: string\n alpha?: number\n hex?: string\n hsl?: {h: number; s: number; l: number}\n }) {\n let subtitle = hex || 'No color set'\n if (hsl) {\n subtitle = `H:${round(hsl.h)} S:${round(hsl.s)} L:${round(hsl.l)} A:${round(alpha)}`\n }\n return {\n title: title,\n subtitle: subtitle,\n media: () => (\n <div\n style={{\n backgroundColor: hex ?? '#000',\n opacity: alpha ?? 1,\n position: 'absolute',\n height: '100%',\n width: '100%',\n top: '0',\n left: '0',\n }}\n />\n ),\n }\n },\n },\n})\n","import {defineType} from 'sanity'\n\nexport const hsvaColor = defineType({\n title: 'Hue Saturation Value',\n name: 'hsvaColor',\n type: 'object',\n fields: [\n {name: 'h', type: 'number', title: 'Hue'},\n {name: 's', type: 'number', title: 'Saturation'},\n {name: 'v', type: 'number', title: 'Value'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n})\n","import {definePlugin} from 'sanity'\nimport {hslaColor} from './schemas/hslaColor'\nimport {rgbaColor} from './schemas/rgbaColor'\nimport {color, ColorDefinition} from './schemas/color'\nimport {hsvaColor} from './schemas/hsvaColor'\n\nexport const colorInput = definePlugin({\n name: '@sanity/color-input',\n schema: {\n types: [hslaColor, hsvaColor, rgbaColor, color],\n },\n})\n\nexport {hslaColor, rgbaColor, color, hsvaColor}\nexport {ColorInput} from './ColorInput'\nexport type {ColorDefinition}\nexport type {ColorValue, ColorInputProps, ColorOptions, ColorSchemaType} from './ColorInput'\n"],"names":["hslaColor","defineType","title","name","type","fields","rgbaColor","ColorPickerFields","onChange","rgb","hsl","hex","disableAlpha","_a","sanity","useTheme","inputStyles","useMemo","input","width","padding","border","boxShadow","color","default","enabled","fg","backgroundColor","bg","fontSize","fonts","text","sizes","textAlign","label","display","base","paddingTop","paddingBottom","textTransform","handleChange","useCallback","data","isValidHex","source","r","g","b","Number","a","alpha","h","s","l","jsxs","Flex","children","jsx","Box","flex","marginRight","EditableInput","style","value","replace","dragLabel","dragMax","Math","round","ColorBox","styled","ReadOnlyContainer","ColorPickerInner","props","_b","_c","hsv","onUnset","readOnly","Card","radius","Stack","space","Fragment","overflow","position","height","Saturation","shadow","Hue","Alpha","minWidth","Checkboard","sizing","justify","marginTop","Text","size","weight","Inline","align","marginLeft","Button","onClick","icon","TrashIcon","tone","ColorPicker","CustomPicker","DEFAULT_COLOR","v","ColorInput","schemaType","focusRef","useRef","setColor","useState","useEffect","emitSetColor","nextColor","fieldPatches","filter","field","map","nextFieldValue","isObject","jsonType","set","Object","assign","_type","setIfMissing","debouncedColorChange","debounce","handleColorChange","handleCreateColor","handleUnset","unset","options","AddIcon","mode","ref","disabled","Boolean","val","colorTypeName","components","preview","select","prepare","subtitle","media","opacity","top","left","hsvaColor","colorInput","definePlugin","schema","types"],"mappings":";;;;;;;;;;;;AAEO,MAAMA,YAAYC,UAAW,CAAA;EAClCC,KAAO,EAAA,0BAAA;EACPC,IAAM,EAAA,WAAA;EACNC,IAAM,EAAA,QAAA;EACNC,MAAQ,EAAA,CACN;IAACF,IAAM,EAAA,GAAA;IAAKC,IAAM,EAAA,QAAA;IAAUF,OAAO;EAAK,CAAA,EACxC;IAACC,IAAM,EAAA,GAAA;IAAKC,IAAM,EAAA,QAAA;IAAUF,OAAO;EAAY,CAAA,EAC/C;IAACC,IAAM,EAAA,GAAA;IAAKC,IAAM,EAAA,QAAA;IAAUF,OAAO;EAAW,CAAA,EAC9C;IAACC,IAAM,EAAA,GAAA;IAAKC,IAAM,EAAA,QAAA;IAAUF,OAAO;EAAO,CAAA;AAE9C,CAAC,CAAA;ACVM,MAAMI,YAAYL,UAAW,CAAA;EAClCC,KAAO,EAAA,sBAAA;EACPC,IAAM,EAAA,WAAA;EACNC,IAAM,EAAA,QAAA;EACNC,MAAQ,EAAA,CACN;IAACF,IAAM,EAAA,GAAA;IAAKC,IAAM,EAAA,QAAA;IAAUF,OAAO;EAAK,CAAA,EACxC;IAACC,IAAM,EAAA,GAAA;IAAKC,IAAM,EAAA,QAAA;IAAUF,OAAO;EAAO,CAAA,EAC1C;IAACC,IAAM,EAAA,GAAA;IAAKC,IAAM,EAAA,QAAA;IAAUF,OAAO;EAAM,CAAA,EACzC;IAACC,IAAM,EAAA,GAAA;IAAKC,IAAM,EAAA,QAAA;IAA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;QACAC,KAAA,EAAO,MAAA,eACJ9F,GAAA,CAAA,KAAA,EAAA;UACCK,KAAO,EAAA;YACLnC,iBAAiBhB,GAAO,IAAA,IAAA,GAAAA,GAAA,GAAA,MAAA;YACxB6I,SAAStG,KAAS,IAAA,IAAA,GAAAA,KAAA,GAAA,CAAA;YAClBmC,QAAU,EAAA,UAAA;YACVC,MAAQ,EAAA,MAAA;YACRnE,KAAO,EAAA,MAAA;YACPsI,GAAK,EAAA,GAAA;YACLC,IAAM,EAAA;UACR;QAAA,CACF;MAAA,CAEJ;IACF;EACF;AACF,CAAC,CAAA;AC9FM,MAAMC,YAAY1J,UAAW,CAAA;EAClCC,KAAO,EAAA,sBAAA;EACPC,IAAM,EAAA,WAAA;EACNC,IAAM,EAAA,QAAA;EACNC,MAAQ,EAAA,CACN;IAACF,IAAM,EAAA,GAAA;IAAKC,IAAM,EAAA,QAAA;IAAUF,OAAO;EAAK,CAAA,EACxC;IAACC,IAAM,EAAA,GAAA;IAAKC,IAAM,EAAA,QAAA;IAAUF,OAAO;EAAY,CAAA,EAC/C;IAACC,IAAM,EAAA,GAAA;IAAKC,IAAM,EAAA,QAAA;IAAUF,OAAO;EAAO,CAAA,EAC1C;IAACC,IAAM,EAAA,GAAA;IAAKC,IAAM,EAAA,QAAA;IAAUF,OAAO;EAAO,CAAA;AAE9C,CAAC,CAAA;ACNM,MAAM0J,aAAaC,YAAa,CAAA;EACrC1J,IAAM,EAAA,qBAAA;EACN2J,MAAQ,EAAA;IACNC,KAAO,EAAA,CAAC/J,SAAW,EAAA2J,SAAA,EAAWrJ,WAAWiB,KAAK;EAChD;AACF,CAAC,CAAA;"}
package/lib/index.js CHANGED
@@ -1,2 +1,506 @@
1
- "use strict";var e,t;function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);t&&(l=l.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,l)}return n}function l(e){for(var t=1;t<arguments.length;t++){var l=null!=arguments[t]?arguments[t]:{};t%2?n(Object(l),!0).forEach((function(t){r(e,t,l[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(l)):n(Object(l)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(l,t))}))}return e}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}Object.defineProperty(exports,"__esModule",{value:!0});var o=require("sanity"),i=require("react/jsx-runtime"),s=require("react"),u=require("lodash"),c=require("@sanity/ui"),d=require("@sanity/icons"),h=require("react-color/lib/components/common"),p=require("react-color"),b=require("styled-components"),x=require("react-color/lib/helpers/color");function g(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var m=g(b);const f=o.defineType({title:"Hue Saturation Lightness",name:"hslaColor",type:"object",fields:[{name:"h",type:"number",title:"Hue"},{name:"s",type:"number",title:"Saturation"},{name:"l",type:"number",title:"Lightness"},{name:"a",type:"number",title:"Alpha"}]}),y=o.defineType({title:"Red Green Blue (rgb)",name:"rgbaColor",type:"object",fields:[{name:"r",type:"number",title:"Red"},{name:"g",type:"number",title:"Green"},{name:"b",type:"number",title:"Blue"},{name:"a",type:"number",title:"Alpha"}]}),j=e=>{let{onChange:t,rgb:n,hsl:l,hex:r,disableAlpha:a}=e;var o;const{sanity:u}=c.useTheme(),d=s.useMemo((()=>({input:{width:"80%",padding:"4px 10% 3px",border:"none",boxShadow:"inset 0 0 0 1px ".concat(u.color.input.default.enabled.border),color:u.color.input.default.enabled.fg,backgroundColor:u.color.input.default.enabled.bg,fontSize:u.fonts.text.sizes[0].fontSize,textAlign:"center"},label:{display:"block",textAlign:"center",fontSize:u.fonts.label.sizes[0].fontSize,color:u.color.base.fg,paddingTop:"3px",paddingBottom:"4px",textTransform:"capitalize"}})),[u]),p=s.useCallback((e=>{if("hex"in e&&e.hex&&x.isValidHex(e.hex))t({hex:e.hex,source:"hex"});else if(n&&("r"in e&&e.r||"g"in e&&e.g||"b"in e&&e.b))t({r:Number(e.r)||n.r,g:Number(e.g)||n.g,b:Number(e.b)||n.b,a:n.a,source:"rgb"});else if(l&&"a"in e&&e.a){let n=Number(e.a);n<0?n=0:n>100&&(n=100),n/=100,t({h:l.h,s:l.s,l:l.l,a:n,source:"hsl"})}}),[t,l,n]);return i.jsxs(c.Flex,{children:[i.jsx(c.Box,{flex:2,marginRight:1,children:i.jsx(h.EditableInput,{style:d,label:"hex",value:null==r?void 0:r.replace("#",""),onChange:p})}),i.jsx(c.Box,{flex:1,marginRight:1,children:i.jsx(h.EditableInput,{style:d,label:"r",value:null==n?void 0:n.r,onChange:p,dragLabel:!0,dragMax:255})}),i.jsx(c.Box,{flex:1,marginRight:1,children:i.jsx(h.EditableInput,{style:d,label:"g",value:null==n?void 0:n.g,onChange:p,dragLabel:!0,dragMax:255})}),i.jsx(c.Box,{flex:1,marginRight:1,children:i.jsx(h.EditableInput,{style:d,label:"b",value:null==n?void 0:n.b,onChange:p,dragLabel:!0,dragMax:255})}),!a&&i.jsx(c.Box,{flex:1,children:i.jsx(h.EditableInput,{style:d,label:"a",value:Math.round(100*(null!=(o=null==n?void 0:n.a)?o:1)),onChange:p,dragLabel:!0,dragMax:100})})]})},v=m.default(c.Box)(e||(e=a(["\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n"]))),C=m.default(c.Flex)(t||(t=a(["\n margin-top: 6rem;\n background-color: var(--card-bg-color);\n position: relative;\n width: 100%;\n"]))),O=p.CustomPicker((e=>{var t,n,l;const{width:r,color:{rgb:a,hex:o,hsv:s,hsl:u},onChange:p,onUnset:b,disableAlpha:x,readOnly:g}=e;return u&&s?i.jsx("div",{style:{width:r},children:i.jsx(c.Card,{padding:1,border:!0,radius:1,children:i.jsxs(c.Stack,{space:2,children:[!g&&i.jsxs(i.Fragment,{children:[i.jsx(c.Card,{overflow:"hidden",style:{position:"relative",height:"5em"},children:i.jsx(h.Saturation,{onChange:p,hsl:u,hsv:s})}),i.jsx(c.Card,{shadow:1,radius:3,overflow:"hidden",style:{position:"relative",height:"10px"},children:i.jsx(h.Hue,{hsl:u,onChange:!g&&p})}),!x&&i.jsx(c.Card,{shadow:1,radius:3,overflow:"hidden",style:{position:"relative",height:"10px"},children:i.jsx(h.Alpha,{rgb:a,hsl:u,onChange:p})})]}),i.jsxs(c.Flex,{children:[i.jsxs(c.Card,{flex:1,radius:2,overflow:"hidden",style:{position:"relative",minWidth:"4em"},children:[i.jsx(h.Checkboard,{}),i.jsx(v,{style:{backgroundColor:"rgba(".concat(null==a?void 0:a.r,",").concat(null==a?void 0:a.g,",").concat(null==a?void 0:a.b,",").concat(null==a?void 0:a.a,")")}}),g&&i.jsx(C,{padding:2,paddingBottom:1,sizing:"border",justify:"space-between",children:i.jsxs(c.Stack,{space:3,marginTop:1,children:[i.jsx(c.Text,{size:3,weight:"bold",children:o}),i.jsxs(c.Inline,{space:3,children:[i.jsxs(c.Text,{size:1,children:[i.jsx("strong",{children:"RGB: "}),null==a?void 0:a.r," ",null==a?void 0:a.g," ",null==a?void 0:a.b]}),i.jsxs(c.Text,{size:1,children:[i.jsx("strong",{children:"HSL: "})," ",Math.round(null!=(t=null==u?void 0:u.h)?t:0)," ",Math.round(null!=(n=null==u?void 0:u.s)?n:0),"%"," ",Math.round(null!=(l=null==u?void 0:u.l)?l:0)]})]})]})})]}),!g&&i.jsxs(c.Flex,{align:"flex-start",marginLeft:2,children:[i.jsx(c.Box,{style:{width:200},children:i.jsx(j,{rgb:a,hsl:u,hex:o,onChange:p,disableAlpha:x})}),i.jsx(c.Box,{marginLeft:2,children:i.jsx(c.Button,{onClick:b,title:"Delete color",icon:d.TrashIcon,tone:"critical"})})]})]})]})})}):null})),w={hex:"#24a3e3",hsl:{h:200,s:.7732,l:.5156,a:1},hsv:{h:200,s:.8414,v:.8901,a:1},rgb:{r:46,g:163,b:227,a:1},source:"hex"};function S(e){var t;const{onChange:n,schemaType:l,readOnly:r,value:a}=e,h=s.useRef(null),[p,b]=s.useState(a);s.useEffect((()=>b(a)),[a]);const x=s.useCallback((e=>{var t;const r=l.fields.filter((t=>t.name in e)).map((t=>{const n=e[t.name],l="object"===t.type.jsonType;return o.set(l?Object.assign({_type:t.type.name},n):n,[t.name])}));n([o.setIfMissing({_type:l.name}),o.set(l.name,["_type"]),o.set(null==(t=e.rgb)?void 0:t.a,["alpha"]),...r])}),[n,l]),g=s.useMemo((()=>u.debounce(x,100)),[x]),m=s.useCallback((e=>{b(e),g(e)}),[g,b]),f=s.useCallback((()=>{b(w),x(w)}),[x]),y=s.useCallback((()=>{b(void 0),n(o.unset())}),[n]);return i.jsx(i.Fragment,{children:a?i.jsx(O,{color:p,onChange:m,readOnly:r||"boolean"==typeof l.readOnly&&l.readOnly,disableAlpha:!!(null==(t=l.options)?void 0:t.disableAlpha),onUnset:y}):i.jsx(c.Button,{icon:d.AddIcon,mode:"ghost",text:"Create color",ref:h,disabled:Boolean(r),onClick:f})})}const k=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return Math.round(100*e)},B=o.defineType(l(l({name:"color",type:"object",title:"Color"},{components:{input:S}}),{},{fields:[{title:"Hex",name:"hex",type:"string"},{title:"Alpha",name:"alpha",type:"number"},{title:"Hue Saturation Lightness",name:"hsl",type:"hslaColor"},{title:"Hue Saturation Value",name:"hsv",type:"hsvaColor"},{title:"Red Green Blue (rgb)",name:"rgb",type:"rgbaColor"}],preview:{select:{title:"hex",alpha:"alpha",hex:"hex",hsl:"hsl"},prepare(e){let{title:t,hex:n,hsl:l,alpha:r}=e,a=n||"No color set";return l&&(a="H:".concat(k(l.h)," S:").concat(k(l.s)," L:").concat(k(l.l)," A:").concat(k(r))),{title:t,subtitle:a,media:()=>i.jsx("div",{style:{backgroundColor:null!=n?n:"#000",opacity:null!=r?r:1,position:"absolute",height:"100%",width:"100%",top:"0",left:"0"}})}}}})),A=o.defineType({title:"Hue Saturation Value",name:"hsvaColor",type:"object",fields:[{name:"h",type:"number",title:"Hue"},{name:"s",type:"number",title:"Saturation"},{name:"v",type:"number",title:"Value"},{name:"a",type:"number",title:"Alpha"}]}),T=o.definePlugin({name:"@sanity/color-input",schema:{types:[f,A,y,B]}});exports.ColorInput=S,exports.color=B,exports.colorInput=T,exports.hslaColor=f,exports.hsvaColor=A,exports.rgbaColor=y;
1
+ 'use strict';
2
+
3
+ var _templateObject, _templateObject2;
4
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
5
+ Object.defineProperty(exports, '__esModule', {
6
+ value: true
7
+ });
8
+ var sanity = require('sanity');
9
+ var jsxRuntime = require('react/jsx-runtime');
10
+ var react = require('react');
11
+ var lodash = require('lodash');
12
+ var ui = require('@sanity/ui');
13
+ var icons = require('@sanity/icons');
14
+ var common = require('react-color/lib/components/common');
15
+ var reactColor = require('react-color');
16
+ var styled = require('styled-components');
17
+ var color$1 = require('react-color/lib/helpers/color');
18
+ function _interopDefaultCompat(e) {
19
+ return e && typeof e === 'object' && 'default' in e ? e : {
20
+ default: e
21
+ };
22
+ }
23
+ var styled__default = /*#__PURE__*/_interopDefaultCompat(styled);
24
+ const hslaColor = sanity.defineType({
25
+ title: "Hue Saturation Lightness",
26
+ name: "hslaColor",
27
+ type: "object",
28
+ fields: [{
29
+ name: "h",
30
+ type: "number",
31
+ title: "Hue"
32
+ }, {
33
+ name: "s",
34
+ type: "number",
35
+ title: "Saturation"
36
+ }, {
37
+ name: "l",
38
+ type: "number",
39
+ title: "Lightness"
40
+ }, {
41
+ name: "a",
42
+ type: "number",
43
+ title: "Alpha"
44
+ }]
45
+ });
46
+ const rgbaColor = sanity.defineType({
47
+ title: "Red Green Blue (rgb)",
48
+ name: "rgbaColor",
49
+ type: "object",
50
+ fields: [{
51
+ name: "r",
52
+ type: "number",
53
+ title: "Red"
54
+ }, {
55
+ name: "g",
56
+ type: "number",
57
+ title: "Green"
58
+ }, {
59
+ name: "b",
60
+ type: "number",
61
+ title: "Blue"
62
+ }, {
63
+ name: "a",
64
+ type: "number",
65
+ title: "Alpha"
66
+ }]
67
+ });
68
+ const ColorPickerFields = _ref => {
69
+ let {
70
+ onChange,
71
+ rgb,
72
+ hsl,
73
+ hex,
74
+ disableAlpha
75
+ } = _ref;
76
+ var _a;
77
+ const {
78
+ sanity
79
+ } = ui.useTheme();
80
+ const inputStyles = react.useMemo(() => ({
81
+ input: {
82
+ width: "80%",
83
+ padding: "4px 10% 3px",
84
+ border: "none",
85
+ boxShadow: "inset 0 0 0 1px ".concat(sanity.color.input.default.enabled.border),
86
+ color: sanity.color.input.default.enabled.fg,
87
+ backgroundColor: sanity.color.input.default.enabled.bg,
88
+ fontSize: sanity.fonts.text.sizes[0].fontSize,
89
+ textAlign: "center"
90
+ },
91
+ label: {
92
+ display: "block",
93
+ textAlign: "center",
94
+ fontSize: sanity.fonts.label.sizes[0].fontSize,
95
+ color: sanity.color.base.fg,
96
+ paddingTop: "3px",
97
+ paddingBottom: "4px",
98
+ textTransform: "capitalize"
99
+ }
100
+ }), [sanity]);
101
+ const handleChange = react.useCallback(data => {
102
+ if ("hex" in data && data.hex && color$1.isValidHex(data.hex)) {
103
+ onChange({
104
+ hex: data.hex,
105
+ source: "hex"
106
+ });
107
+ } else if (rgb && ("r" in data && data.r || "g" in data && data.g || "b" in data && data.b)) {
108
+ onChange({
109
+ r: Number(data.r) || rgb.r,
110
+ g: Number(data.g) || rgb.g,
111
+ b: Number(data.b) || rgb.b,
112
+ a: rgb.a,
113
+ source: "rgb"
114
+ });
115
+ } else if (hsl && "a" in data && data.a) {
116
+ let alpha = Number(data.a);
117
+ if (alpha < 0) {
118
+ alpha = 0;
119
+ } else if (alpha > 100) {
120
+ alpha = 100;
121
+ }
122
+ alpha /= 100;
123
+ onChange({
124
+ h: hsl.h,
125
+ s: hsl.s,
126
+ l: hsl.l,
127
+ a: alpha,
128
+ source: "hsl"
129
+ });
130
+ }
131
+ }, [onChange, hsl, rgb]);
132
+ return /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
133
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
134
+ flex: 2,
135
+ marginRight: 1,
136
+ children: /* @__PURE__ */jsxRuntime.jsx(common.EditableInput, {
137
+ style: inputStyles,
138
+ label: "hex",
139
+ value: hex == null ? void 0 : hex.replace("#", ""),
140
+ onChange: handleChange
141
+ })
142
+ }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
143
+ flex: 1,
144
+ marginRight: 1,
145
+ children: /* @__PURE__ */jsxRuntime.jsx(common.EditableInput, {
146
+ style: inputStyles,
147
+ label: "r",
148
+ value: rgb == null ? void 0 : rgb.r,
149
+ onChange: handleChange,
150
+ dragLabel: true,
151
+ dragMax: 255
152
+ })
153
+ }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
154
+ flex: 1,
155
+ marginRight: 1,
156
+ children: /* @__PURE__ */jsxRuntime.jsx(common.EditableInput, {
157
+ style: inputStyles,
158
+ label: "g",
159
+ value: rgb == null ? void 0 : rgb.g,
160
+ onChange: handleChange,
161
+ dragLabel: true,
162
+ dragMax: 255
163
+ })
164
+ }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
165
+ flex: 1,
166
+ marginRight: 1,
167
+ children: /* @__PURE__ */jsxRuntime.jsx(common.EditableInput, {
168
+ style: inputStyles,
169
+ label: "b",
170
+ value: rgb == null ? void 0 : rgb.b,
171
+ onChange: handleChange,
172
+ dragLabel: true,
173
+ dragMax: 255
174
+ })
175
+ }), !disableAlpha && /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
176
+ flex: 1,
177
+ children: /* @__PURE__ */jsxRuntime.jsx(common.EditableInput, {
178
+ style: inputStyles,
179
+ label: "a",
180
+ value: Math.round(((_a = rgb == null ? void 0 : rgb.a) != null ? _a : 1) * 100),
181
+ onChange: handleChange,
182
+ dragLabel: true,
183
+ dragMax: 100
184
+ })
185
+ })]
186
+ });
187
+ };
188
+ const ColorBox = styled__default.default(ui.Box)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n"])));
189
+ const ReadOnlyContainer = styled__default.default(ui.Flex)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n margin-top: 6rem;\n background-color: var(--card-bg-color);\n position: relative;\n width: 100%;\n"])));
190
+ const ColorPickerInner = props => {
191
+ var _a, _b, _c;
192
+ const {
193
+ width,
194
+ color: {
195
+ rgb,
196
+ hex,
197
+ hsv,
198
+ hsl
199
+ },
200
+ onChange,
201
+ onUnset,
202
+ disableAlpha,
203
+ readOnly
204
+ } = props;
205
+ if (!hsl || !hsv) {
206
+ return null;
207
+ }
208
+ return /* @__PURE__ */jsxRuntime.jsx("div", {
209
+ style: {
210
+ width
211
+ },
212
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
213
+ padding: 1,
214
+ border: true,
215
+ radius: 1,
216
+ children: /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
217
+ space: 2,
218
+ children: [!readOnly && /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
219
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Card, {
220
+ overflow: "hidden",
221
+ style: {
222
+ position: "relative",
223
+ height: "5em"
224
+ },
225
+ children: /* @__PURE__ */jsxRuntime.jsx(common.Saturation, {
226
+ onChange,
227
+ hsl,
228
+ hsv
229
+ })
230
+ }), /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
231
+ shadow: 1,
232
+ radius: 3,
233
+ overflow: "hidden",
234
+ style: {
235
+ position: "relative",
236
+ height: "10px"
237
+ },
238
+ children: /* @__PURE__ */jsxRuntime.jsx(common.Hue, {
239
+ hsl,
240
+ onChange: !readOnly && onChange
241
+ })
242
+ }), !disableAlpha && /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
243
+ shadow: 1,
244
+ radius: 3,
245
+ overflow: "hidden",
246
+ style: {
247
+ position: "relative",
248
+ height: "10px"
249
+ },
250
+ children: /* @__PURE__ */jsxRuntime.jsx(common.Alpha, {
251
+ rgb,
252
+ hsl,
253
+ onChange
254
+ })
255
+ })]
256
+ }), /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
257
+ children: [/* @__PURE__ */jsxRuntime.jsxs(ui.Card, {
258
+ flex: 1,
259
+ radius: 2,
260
+ overflow: "hidden",
261
+ style: {
262
+ position: "relative",
263
+ minWidth: "4em"
264
+ },
265
+ children: [/* @__PURE__ */jsxRuntime.jsx(common.Checkboard, {}), /* @__PURE__ */jsxRuntime.jsx(ColorBox, {
266
+ style: {
267
+ backgroundColor: "rgba(".concat(rgb == null ? void 0 : rgb.r, ",").concat(rgb == null ? void 0 : rgb.g, ",").concat(rgb == null ? void 0 : rgb.b, ",").concat(rgb == null ? void 0 : rgb.a, ")")
268
+ }
269
+ }), readOnly && /* @__PURE__ */jsxRuntime.jsx(ReadOnlyContainer, {
270
+ padding: 2,
271
+ paddingBottom: 1,
272
+ sizing: "border",
273
+ justify: "space-between",
274
+ children: /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
275
+ space: 3,
276
+ marginTop: 1,
277
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Text, {
278
+ size: 3,
279
+ weight: "bold",
280
+ children: hex
281
+ }), /* @__PURE__ */jsxRuntime.jsxs(ui.Inline, {
282
+ space: 3,
283
+ children: [/* @__PURE__ */jsxRuntime.jsxs(ui.Text, {
284
+ size: 1,
285
+ children: [/* @__PURE__ */jsxRuntime.jsx("strong", {
286
+ children: "RGB: "
287
+ }), rgb == null ? void 0 : rgb.r, " ", rgb == null ? void 0 : rgb.g, " ", rgb == null ? void 0 : rgb.b]
288
+ }), /* @__PURE__ */jsxRuntime.jsxs(ui.Text, {
289
+ size: 1,
290
+ children: [/* @__PURE__ */jsxRuntime.jsx("strong", {
291
+ children: "HSL: "
292
+ }), " ", Math.round((_a = hsl == null ? void 0 : hsl.h) != null ? _a : 0), " ", Math.round((_b = hsl == null ? void 0 : hsl.s) != null ? _b : 0), "%", " ", Math.round((_c = hsl == null ? void 0 : hsl.l) != null ? _c : 0)]
293
+ })]
294
+ })]
295
+ })
296
+ })]
297
+ }), !readOnly && /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
298
+ align: "flex-start",
299
+ marginLeft: 2,
300
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
301
+ style: {
302
+ width: 200
303
+ },
304
+ children: /* @__PURE__ */jsxRuntime.jsx(ColorPickerFields, {
305
+ rgb,
306
+ hsl,
307
+ hex,
308
+ onChange,
309
+ disableAlpha
310
+ })
311
+ }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
312
+ marginLeft: 2,
313
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
314
+ onClick: onUnset,
315
+ title: "Delete color",
316
+ icon: icons.TrashIcon,
317
+ tone: "critical"
318
+ })
319
+ })]
320
+ })]
321
+ })]
322
+ })
323
+ })
324
+ });
325
+ };
326
+ const ColorPicker = reactColor.CustomPicker(ColorPickerInner);
327
+ const DEFAULT_COLOR = {
328
+ hex: "#24a3e3",
329
+ hsl: {
330
+ h: 200,
331
+ s: 0.7732,
332
+ l: 0.5156,
333
+ a: 1
334
+ },
335
+ hsv: {
336
+ h: 200,
337
+ s: 0.8414,
338
+ v: 0.8901,
339
+ a: 1
340
+ },
341
+ rgb: {
342
+ r: 46,
343
+ g: 163,
344
+ b: 227,
345
+ a: 1
346
+ },
347
+ source: "hex"
348
+ };
349
+ function ColorInput(props) {
350
+ var _a;
351
+ const {
352
+ onChange,
353
+ readOnly
354
+ } = props;
355
+ const value = props.value;
356
+ const type = props.schemaType;
357
+ const focusRef = react.useRef(null);
358
+ const [color, setColor] = react.useState(value);
359
+ react.useEffect(() => setColor(value), [value]);
360
+ const emitSetColor = react.useCallback(nextColor => {
361
+ var _a2;
362
+ const fieldPatches = type.fields.filter(field => field.name in nextColor).map(field => {
363
+ const nextFieldValue = nextColor[field.name];
364
+ const isObject = field.type.jsonType === "object";
365
+ return sanity.set(isObject ? Object.assign({
366
+ _type: field.type.name
367
+ }, nextFieldValue) : nextFieldValue, [field.name]);
368
+ });
369
+ onChange([sanity.setIfMissing({
370
+ _type: type.name
371
+ }), sanity.set(type.name, ["_type"]), sanity.set((_a2 = nextColor.rgb) == null ? void 0 : _a2.a, ["alpha"]), ...fieldPatches]);
372
+ }, [onChange, type]);
373
+ const debouncedColorChange = react.useMemo(() => lodash.debounce(emitSetColor, 100), [emitSetColor]);
374
+ const handleColorChange = react.useCallback(nextColor => {
375
+ setColor(nextColor);
376
+ debouncedColorChange(nextColor);
377
+ }, [debouncedColorChange, setColor]);
378
+ const handleCreateColor = react.useCallback(() => {
379
+ setColor(DEFAULT_COLOR);
380
+ emitSetColor(DEFAULT_COLOR);
381
+ }, [emitSetColor]);
382
+ const handleUnset = react.useCallback(() => {
383
+ setColor(void 0);
384
+ onChange(sanity.unset());
385
+ }, [onChange]);
386
+ return /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {
387
+ children: value && value.hex ? /* @__PURE__ */jsxRuntime.jsx(ColorPicker, {
388
+ color,
389
+ onChange: handleColorChange,
390
+ readOnly: readOnly || typeof type.readOnly === "boolean" && type.readOnly,
391
+ disableAlpha: !!((_a = type.options) == null ? void 0 : _a.disableAlpha),
392
+ onUnset: handleUnset
393
+ }) : /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
394
+ icon: icons.AddIcon,
395
+ mode: "ghost",
396
+ text: "Create color",
397
+ ref: focusRef,
398
+ disabled: Boolean(readOnly),
399
+ onClick: handleCreateColor
400
+ })
401
+ });
402
+ }
403
+ const round = function () {
404
+ let val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
405
+ return Math.round(val * 100);
406
+ };
407
+ const colorTypeName = "color";
408
+ const color = sanity.defineType({
409
+ name: colorTypeName,
410
+ type: "object",
411
+ title: "Color",
412
+ components: {
413
+ input: ColorInput
414
+ },
415
+ fields: [{
416
+ title: "Hex",
417
+ name: "hex",
418
+ type: "string"
419
+ }, {
420
+ title: "Alpha",
421
+ name: "alpha",
422
+ type: "number"
423
+ }, {
424
+ title: "Hue Saturation Lightness",
425
+ name: "hsl",
426
+ type: "hslaColor"
427
+ }, {
428
+ title: "Hue Saturation Value",
429
+ name: "hsv",
430
+ type: "hsvaColor"
431
+ }, {
432
+ title: "Red Green Blue (rgb)",
433
+ name: "rgb",
434
+ type: "rgbaColor"
435
+ }],
436
+ preview: {
437
+ select: {
438
+ title: "hex",
439
+ alpha: "alpha",
440
+ hex: "hex",
441
+ hsl: "hsl"
442
+ },
443
+ prepare(_ref2) {
444
+ let {
445
+ title,
446
+ hex,
447
+ hsl,
448
+ alpha
449
+ } = _ref2;
450
+ let subtitle = hex || "No color set";
451
+ if (hsl) {
452
+ subtitle = "H:".concat(round(hsl.h), " S:").concat(round(hsl.s), " L:").concat(round(hsl.l), " A:").concat(round(alpha));
453
+ }
454
+ return {
455
+ title,
456
+ subtitle,
457
+ media: () => /* @__PURE__ */jsxRuntime.jsx("div", {
458
+ style: {
459
+ backgroundColor: hex != null ? hex : "#000",
460
+ opacity: alpha != null ? alpha : 1,
461
+ position: "absolute",
462
+ height: "100%",
463
+ width: "100%",
464
+ top: "0",
465
+ left: "0"
466
+ }
467
+ })
468
+ };
469
+ }
470
+ }
471
+ });
472
+ const hsvaColor = sanity.defineType({
473
+ title: "Hue Saturation Value",
474
+ name: "hsvaColor",
475
+ type: "object",
476
+ fields: [{
477
+ name: "h",
478
+ type: "number",
479
+ title: "Hue"
480
+ }, {
481
+ name: "s",
482
+ type: "number",
483
+ title: "Saturation"
484
+ }, {
485
+ name: "v",
486
+ type: "number",
487
+ title: "Value"
488
+ }, {
489
+ name: "a",
490
+ type: "number",
491
+ title: "Alpha"
492
+ }]
493
+ });
494
+ const colorInput = sanity.definePlugin({
495
+ name: "@sanity/color-input",
496
+ schema: {
497
+ types: [hslaColor, hsvaColor, rgbaColor, color]
498
+ }
499
+ });
500
+ exports.ColorInput = ColorInput;
501
+ exports.color = color;
502
+ exports.colorInput = colorInput;
503
+ exports.hslaColor = hslaColor;
504
+ exports.hsvaColor = hsvaColor;
505
+ exports.rgbaColor = rgbaColor;
2
506
  //# sourceMappingURL=index.js.map