@sanity/color-input 4.0.7 → 5.0.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.
@@ -1,337 +0,0 @@
1
- "use strict";
2
- var jsxRuntime = require("react/jsx-runtime"), react = require("react"), reactColor = require("react-color"), common = require("react-color/lib/components/common"), sanity = require("sanity"), styledComponents = require("styled-components"), useEffectEvent = require("use-effect-event"), icons = require("@sanity/icons"), ui = require("@sanity/ui"), tinycolor = require("tinycolor2"), color = require("react-color/lib/helpers/color");
3
- function _interopDefaultCompat(e) {
4
- return e && typeof e == "object" && "default" in e ? e : { default: e };
5
- }
6
- var tinycolor__default = /* @__PURE__ */ _interopDefaultCompat(tinycolor);
7
- const ColorListWrap = styledComponents.styled(ui.Flex)`
8
- gap: 0.25em;
9
- `, ColorBoxContainer = styledComponents.styled.div`
10
- width: 2.1em;
11
- height: 2.1em;
12
- cursor: pointer;
13
- position: relative;
14
- overflow: hidden;
15
- border-radius: 3px;
16
- background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAADFJREFUOE9jZGBgEGHAD97gk2YcNYBhmIQBgWSAP52AwoAQwJvQRg1gACckQoC2gQgAIF8IscwEtKYAAAAASUVORK5CYII=')
17
- left center #fff;
18
- `, ColorBox$1 = styledComponents.styled.div`
19
- border-radius: inherit;
20
- box-shadow: inset 0 0 0 1px var(--card-shadow-outline-color);
21
- content: '';
22
- position: absolute;
23
- inset: 0;
24
- z-index: 1;
25
- `, validateColors = (colors) => colors.reduce((cls, c) => {
26
- const color2 = c.hex ? tinycolor__default.default(c.hex) : tinycolor__default.default(c);
27
- return color2.isValid() && cls.push({
28
- color: c,
29
- backgroundColor: color2.toRgbString()
30
- }), cls;
31
- }, []), ColorList = react.memo(function({ colors, onChange }) {
32
- return colors ? /* @__PURE__ */ jsxRuntime.jsx(ColorListWrap, { wrap: "wrap", children: validateColors(colors).map(({ color: color2, backgroundColor }, idx) => /* @__PURE__ */ jsxRuntime.jsx(
33
- ColorBoxContainer,
34
- {
35
- onClick: () => {
36
- onChange(color2);
37
- },
38
- children: /* @__PURE__ */ jsxRuntime.jsx(ColorBox$1, { style: { background: backgroundColor } })
39
- },
40
- `${backgroundColor}-${idx}`
41
- )) }) : null;
42
- }), ColorPickerFields = ({
43
- onChange,
44
- rgb,
45
- hsl,
46
- hex,
47
- disableAlpha
48
- }) => {
49
- const { sanity: sanity2 } = ui.useTheme(), inputStyles = react.useMemo(
50
- () => ({
51
- input: {
52
- width: "80%",
53
- padding: "4px 10% 3px",
54
- border: "none",
55
- boxShadow: `inset 0 0 0 1px ${sanity2.color.input.default.enabled.border}`,
56
- color: sanity2.color.input.default.enabled.fg,
57
- backgroundColor: sanity2.color.input.default.enabled.bg,
58
- fontSize: sanity2.fonts.text.sizes[0]?.fontSize,
59
- textAlign: "center"
60
- },
61
- label: {
62
- display: "block",
63
- textAlign: "center",
64
- fontSize: sanity2.fonts.label.sizes[0]?.fontSize,
65
- color: sanity2.color.base.fg,
66
- paddingTop: "3px",
67
- paddingBottom: "4px",
68
- textTransform: "capitalize"
69
- }
70
- }),
71
- [sanity2]
72
- ), handleChange = react.useCallback(
73
- (data) => {
74
- if ("hex" in data && data.hex && color.isValidHex(data.hex))
75
- onChange({
76
- hex: data.hex,
77
- source: "hex"
78
- });
79
- else if (rgb && ("r" in data && data.r || "g" in data && data.g || "b" in data && data.b))
80
- onChange({
81
- r: Number(data.r) || rgb.r,
82
- g: Number(data.g) || rgb.g,
83
- b: Number(data.b) || rgb.b,
84
- a: rgb.a,
85
- source: "rgb"
86
- });
87
- else if (hsl && "a" in data && data.a) {
88
- let alpha = Number(data.a);
89
- alpha < 0 ? alpha = 0 : alpha > 100 && (alpha = 100), alpha /= 100, onChange({
90
- h: hsl.h,
91
- s: hsl.s,
92
- l: hsl.l,
93
- a: alpha,
94
- source: "hsl"
95
- });
96
- }
97
- },
98
- [onChange, hsl, rgb]
99
- );
100
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { children: [
101
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 2, marginRight: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
102
- common.EditableInput,
103
- {
104
- style: inputStyles,
105
- label: "hex",
106
- value: hex?.replace("#", ""),
107
- onChange: handleChange
108
- }
109
- ) }),
110
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
111
- common.EditableInput,
112
- {
113
- style: inputStyles,
114
- label: "r",
115
- value: rgb?.r,
116
- onChange: handleChange,
117
- dragLabel: !0,
118
- dragMax: 255
119
- }
120
- ) }),
121
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
122
- common.EditableInput,
123
- {
124
- style: inputStyles,
125
- label: "g",
126
- value: rgb?.g,
127
- onChange: handleChange,
128
- dragLabel: !0,
129
- dragMax: 255
130
- }
131
- ) }),
132
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
133
- common.EditableInput,
134
- {
135
- style: inputStyles,
136
- label: "b",
137
- value: rgb?.b,
138
- onChange: handleChange,
139
- dragLabel: !0,
140
- dragMax: 255
141
- }
142
- ) }),
143
- !disableAlpha && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
144
- common.EditableInput,
145
- {
146
- style: inputStyles,
147
- label: "a",
148
- value: Math.round((rgb?.a ?? 1) * 100),
149
- onChange: handleChange,
150
- dragLabel: !0,
151
- dragMax: 100
152
- }
153
- ) })
154
- ] });
155
- }, ColorBox = styledComponents.styled(ui.Box)`
156
- position: absolute;
157
- top: 0;
158
- left: 0;
159
- width: 100%;
160
- height: 100%;
161
- `, ReadOnlyContainer = styledComponents.styled(ui.Flex)`
162
- margin-top: 6rem;
163
- background-color: var(--card-bg-color);
164
- position: relative;
165
- width: 100%;
166
- `, ColorPickerInner = (props) => {
167
- const {
168
- width,
169
- color: { rgb, hex, hsv, hsl },
170
- onChange,
171
- onUnset,
172
- disableAlpha,
173
- colorList,
174
- readOnly
175
- } = props;
176
- return !hsl || !hsv ? null : /* @__PURE__ */ jsxRuntime.jsx("div", { style: { width }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { padding: 1, border: !0, radius: 1, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 2, children: [
177
- !readOnly && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
178
- /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { overflow: "hidden", style: { position: "relative", height: "5em" }, children: /* @__PURE__ */ jsxRuntime.jsx(common.Saturation, { onChange, hsl, hsv }) }),
179
- /* @__PURE__ */ jsxRuntime.jsx(
180
- ui.Card,
181
- {
182
- shadow: 1,
183
- radius: 3,
184
- overflow: "hidden",
185
- style: { position: "relative", height: "10px" },
186
- children: /* @__PURE__ */ jsxRuntime.jsx(common.Hue, { hsl, onChange: !readOnly && onChange })
187
- }
188
- ),
189
- !disableAlpha && /* @__PURE__ */ jsxRuntime.jsx(
190
- ui.Card,
191
- {
192
- shadow: 1,
193
- radius: 3,
194
- overflow: "hidden",
195
- style: { position: "relative", height: "10px", background: "#fff" },
196
- children: /* @__PURE__ */ jsxRuntime.jsx(common.Alpha, { rgb, hsl, onChange })
197
- }
198
- )
199
- ] }),
200
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { children: [
201
- /* @__PURE__ */ jsxRuntime.jsxs(
202
- ui.Card,
203
- {
204
- flex: 1,
205
- radius: 2,
206
- overflow: "hidden",
207
- style: { position: "relative", minWidth: "4em", background: "#fff" },
208
- children: [
209
- /* @__PURE__ */ jsxRuntime.jsx(
210
- common.Checkboard,
211
- {
212
- size: 8,
213
- white: "transparent",
214
- grey: "rgba(0,0,0,.08)",
215
- renderers: {}
216
- }
217
- ),
218
- /* @__PURE__ */ jsxRuntime.jsx(
219
- ColorBox,
220
- {
221
- style: {
222
- backgroundColor: `rgba(${rgb?.r},${rgb?.g},${rgb?.b},${rgb?.a})`
223
- }
224
- }
225
- ),
226
- readOnly && /* @__PURE__ */ jsxRuntime.jsx(
227
- ReadOnlyContainer,
228
- {
229
- padding: 2,
230
- paddingBottom: 1,
231
- sizing: "border",
232
- justify: "space-between",
233
- children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 3, marginTop: 1, children: [
234
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 3, weight: "bold", children: hex }),
235
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Inline, { space: 3, children: [
236
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, children: [
237
- /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "RGB: " }),
238
- rgb?.r,
239
- " ",
240
- rgb?.g,
241
- " ",
242
- rgb?.b
243
- ] }),
244
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, children: [
245
- /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "HSL: " }),
246
- " ",
247
- Math.round(hsl?.h ?? 0),
248
- " ",
249
- Math.round((hsl?.s ?? 0) * 100),
250
- "% ",
251
- Math.round((hsl?.l ?? 0) * 100),
252
- "%"
253
- ] })
254
- ] })
255
- ] })
256
- }
257
- )
258
- ]
259
- }
260
- ),
261
- !readOnly && /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "flex-start", marginLeft: 2, children: [
262
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { style: { width: 200 }, children: /* @__PURE__ */ jsxRuntime.jsx(
263
- ColorPickerFields,
264
- {
265
- rgb,
266
- hsl,
267
- hex,
268
- onChange,
269
- disableAlpha
270
- }
271
- ) }),
272
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginLeft: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: onUnset, title: "Delete color", icon: icons.TrashIcon, tone: "critical" }) })
273
- ] })
274
- ] }),
275
- colorList && /* @__PURE__ */ jsxRuntime.jsx(ColorList, { colors: colorList, onChange })
276
- ] }) }) });
277
- }, ColorPicker = reactColor.CustomPicker(ColorPickerInner), DEFAULT_COLOR = {
278
- hex: "#24a3e3",
279
- hsl: { h: 200, s: 0.7732, l: 0.5156, a: 1 },
280
- hsv: { h: 200, s: 0.8414, v: 0.8901, a: 1 },
281
- rgb: { r: 46, g: 163, b: 227, a: 1 },
282
- source: "hex"
283
- };
284
- function ColorInput(props) {
285
- const { onChange, readOnly } = props, value = props.value, type = props.schemaType, focusRef = react.useRef(null), [color2, setColor] = react.useState(value);
286
- react.useEffect(() => react.startTransition(() => setColor(value)), [value]);
287
- const [emitColor, setEmitColor] = react.useState(void 0), debouncedColor = react.useDeferredValue(emitColor), handleChange = useEffectEvent.useEffectEvent((nextColor) => {
288
- const fieldPatches = type.fields.filter((field) => field.name in nextColor).map((field) => {
289
- const nextFieldValue = nextColor[field.name], isObject = field.type.jsonType === "object";
290
- return sanity.set(
291
- isObject ? Object.assign({ _type: field.type.name }, nextFieldValue) : nextFieldValue,
292
- [field.name]
293
- );
294
- });
295
- onChange([
296
- sanity.setIfMissing({ _type: type.name }),
297
- sanity.set(type.name, ["_type"]),
298
- sanity.set(nextColor.rgb?.a, ["alpha"]),
299
- ...fieldPatches
300
- ]);
301
- });
302
- react.useEffect(() => {
303
- if (!debouncedColor) return;
304
- const raf = requestAnimationFrame(() => handleChange(debouncedColor));
305
- return () => cancelAnimationFrame(raf);
306
- }, [debouncedColor]);
307
- const handleCreateColor = react.useCallback(() => {
308
- setColor(DEFAULT_COLOR), setEmitColor(DEFAULT_COLOR);
309
- }, []), handleColorChange = react.useCallback((nextColor) => {
310
- setColor(nextColor), setEmitColor(nextColor);
311
- }, []), handleUnset = react.useCallback(() => {
312
- setColor(void 0), onChange(sanity.unset());
313
- }, [onChange]);
314
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: value && value.hex ? /* @__PURE__ */ jsxRuntime.jsx(
315
- ColorPicker,
316
- {
317
- color: color2,
318
- onChange: handleColorChange,
319
- readOnly: readOnly || typeof type.readOnly == "boolean" && type.readOnly,
320
- disableAlpha: !!type.options?.disableAlpha,
321
- colorList: type.options?.colorList,
322
- onUnset: handleUnset
323
- }
324
- ) : /* @__PURE__ */ jsxRuntime.jsx(
325
- ui.Button,
326
- {
327
- icon: icons.AddIcon,
328
- mode: "ghost",
329
- text: "Create color",
330
- ref: focusRef,
331
- disabled: !!readOnly,
332
- onClick: handleCreateColor
333
- }
334
- ) });
335
- }
336
- exports.default = ColorInput;
337
- //# sourceMappingURL=ColorInput.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ColorInput.cjs","sources":["../../src/ColorList.tsx","../../src/ColorPickerFields.tsx","../../src/ColorInput.tsx"],"sourcesContent":["import type {Color, ColorChangeHandler} from 'react-color'\n\nimport {memo} from 'react'\nimport {styled} from 'styled-components'\nimport tinycolor from 'tinycolor2'\n\nimport {Flex} from '@sanity/ui'\n\nconst ColorListWrap = styled(Flex)`\n gap: 0.25em;\n`\n\nconst ColorBoxContainer = styled.div`\n width: 2.1em;\n height: 2.1em;\n cursor: pointer;\n position: relative;\n overflow: hidden;\n border-radius: 3px;\n background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAADFJREFUOE9jZGBgEGHAD97gk2YcNYBhmIQBgWSAP52AwoAQwJvQRg1gACckQoC2gQgAIF8IscwEtKYAAAAASUVORK5CYII=')\n left center #fff;\n`\n\nconst ColorBox = styled.div`\n border-radius: inherit;\n box-shadow: inset 0 0 0 1px var(--card-shadow-outline-color);\n content: '';\n position: absolute;\n inset: 0;\n z-index: 1;\n`\n\ninterface ValidatedColor {\n color: Color\n backgroundColor: string\n}\n\ninterface ColorListProps {\n colors?: Array<Color>\n onChange: ColorChangeHandler<Color>\n}\n\nconst validateColors = (colors: Array<Color>) =>\n colors.reduce((cls: Array<ValidatedColor>, c) => {\n // @ts-expect-error fix types later\n const color = c.hex ? tinycolor(c.hex) : tinycolor(c)\n if (color.isValid()) {\n cls.push({\n color: c,\n backgroundColor: color.toRgbString(),\n })\n }\n return cls\n }, [])\n\nexport const ColorList = memo(function ColorList({colors, onChange}: ColorListProps) {\n if (!colors) return null\n return (\n <ColorListWrap wrap=\"wrap\">\n {validateColors(colors).map(({color, backgroundColor}, idx) => (\n <ColorBoxContainer\n key={`${backgroundColor}-${idx}`}\n onClick={() => {\n onChange(color)\n }}\n >\n <ColorBox style={{background: backgroundColor}} />\n </ColorBoxContainer>\n ))}\n </ColorListWrap>\n )\n})\n","import type {Color, ColorChangeHandler, HSLColor, RGBColor} from 'react-color'\nimport type {EditableInputStyles} from 'react-color/lib/components/common/EditableInput'\n\nimport {useCallback, useMemo} from 'react'\nimport {EditableInput} from 'react-color/lib/components/common'\n// @ts-expect-error missing export\nimport {isValidHex} from 'react-color/lib/helpers/color'\n\nimport {Box, Flex, useTheme} from '@sanity/ui'\n\ninterface ColorPickerFieldsProps {\n rgb?: RGBColor\n hsl?: HSLColor\n hex?: string\n disableAlpha: boolean\n onChange: ColorChangeHandler<Color>\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 type {CustomPickerInjectedProps} from 'react-color/lib/components/common/ColorWrap'\n\nimport {startTransition, useCallback, useDeferredValue, useEffect, useRef, useState} from 'react'\nimport {type Color, CustomPicker} from 'react-color'\nimport {Alpha, Checkboard, Hue, Saturation} from 'react-color/lib/components/common'\nimport {type ObjectInputProps, set, setIfMissing, unset} from 'sanity'\nimport {styled} from 'styled-components'\nimport {useEffectEvent} from 'use-effect-event'\n\nimport {AddIcon} from '@sanity/icons'\nimport {TrashIcon} from '@sanity/icons'\nimport {Box, Button, Card, Flex, Inline, Stack, Text} from '@sanity/ui'\n\nimport type {ColorSchemaType, ColorValue} from './types'\n\nimport {ColorList} from './ColorList'\nimport {ColorPickerFields} from './ColorPickerFields'\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\ninterface ColorPickerProps extends CustomPickerInjectedProps<Color> {\n width?: string\n disableAlpha: boolean\n colorList?: Array<Color> | undefined\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 colorList,\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', background: '#fff'}}\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', background: '#fff'}}\n >\n <Checkboard\n size={8}\n white=\"transparent\"\n grey=\"rgba(0,0,0,.08)\"\n renderers={{} as {canvas: unknown}}\n />\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)}{' '}\n {Math.round((hsl?.s ?? 0) * 100)}% {Math.round((hsl?.l ?? 0) * 100)}%\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 {colorList && <ColorList colors={colorList} onChange={onChange} />}\n </Stack>\n </Card>\n </div>\n )\n}\n\nconst ColorPicker = CustomPicker(ColorPickerInner)\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 default 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 // Marking the `setColor` in a transition allows React to interrupt render should the user start dragging the input before React is finished rendering\n useEffect(() => startTransition(() => setColor(value)), [value])\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 // and massively improve render performance and avoid jank\n const [emitColor, setEmitColor] = useState<typeof value>(undefined)\n const debouncedColor = useDeferredValue(emitColor)\n const handleChange = useEffectEvent((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 useEffect(() => {\n if (!debouncedColor) return undefined\n const raf = requestAnimationFrame(() => handleChange(debouncedColor))\n return () => cancelAnimationFrame(raf)\n }, [debouncedColor])\n\n const handleCreateColor = useCallback(() => {\n setColor(DEFAULT_COLOR)\n setEmitColor(DEFAULT_COLOR)\n }, [])\n\n const handleColorChange = useCallback((nextColor: ColorValue) => {\n setColor(nextColor)\n setEmitColor(nextColor)\n }, [])\n\n const handleUnset = useCallback(() => {\n setColor(undefined)\n onChange(unset())\n }, [onChange])\n\n return (\n <>\n {value && value.hex ? (\n <ColorPicker\n color={color!}\n onChange={handleColorChange}\n readOnly={readOnly || (typeof type.readOnly === 'boolean' && type.readOnly)}\n disableAlpha={!!type.options?.disableAlpha}\n colorList={type.options?.colorList}\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"],"names":["styled","Flex","ColorBox","color","tinycolor","memo","jsx","sanity","useTheme","useMemo","useCallback","isValidHex","Box","EditableInput","Card","jsxs","Stack","Fragment","Saturation","Hue","Alpha","Checkboard","Text","Inline","Button","TrashIcon","CustomPicker","useRef","useState","useEffect","startTransition","useDeferredValue","useEffectEvent","set","setIfMissing","unset","AddIcon"],"mappings":";;;;;;AAQA,MAAM,gBAAgBA,iBAAAA,OAAOC,OAAI;AAAA;AAAA,GAI3B,oBAAoBD,iBAAAA,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAW3BE,aAAWF,iBAAAA,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAmBlB,iBAAiB,CAAC,WACtB,OAAO,OAAO,CAAC,KAA4B,MAAM;AAE/C,QAAMG,SAAQ,EAAE,MAAMC,mBAAAA,QAAU,EAAE,GAAG,IAAIA,mBAAAA,QAAU,CAAC;AACpD,SAAID,OAAM,aACR,IAAI,KAAK;AAAA,IACP,OAAO;AAAA,IACP,iBAAiBA,OAAM,YAAA;AAAA,EAAY,CACpC,GAEI;AACT,GAAG,EAAE,GAEM,YAAYE,MAAAA,KAAK,SAAmB,EAAC,QAAQ,YAA2B;AACnF,SAAK,SAEHC,2BAAAA,IAAC,eAAA,EAAc,MAAK,QACjB,UAAA,eAAe,MAAM,EAAE,IAAI,CAAC,EAAC,OAAAH,QAAO,gBAAA,GAAkB,QACrDG,2BAAAA;AAAAA,IAAC;AAAA,IAAA;AAAA,MAEC,SAAS,MAAM;AACb,iBAASH,MAAK;AAAA,MAChB;AAAA,MAEA,yCAACD,YAAA,EAAS,OAAO,EAAC,YAAY,kBAAe,CAAG;AAAA,IAAA;AAAA,IAL3C,GAAG,eAAe,IAAI,GAAG;AAAA,EAAA,CAOjC,GACH,IAbkB;AAetB,CAAC,GCrDY,oBAAoB,CAAC;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AAAA,MACL,KAAK;AAAA,MACL,UAAU,CAAA,CAAQ;AAAA,MAClB,SAAS;AAAA,IAAA;AAAA,EAAA,GAGf;AAEJ;;"}
package/dist/index.cjs DELETED
@@ -1,114 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var sanity = require("sanity"), jsxRuntime = require("react/jsx-runtime"), react = require("react");
4
- const ColorInput = react.lazy(() => Promise.resolve().then(function() {
5
- return require("./_chunks-cjs/ColorInput.cjs");
6
- })), round = (val = 1) => Math.round(val * 100), colorTypeName = "color", color = sanity.defineType({
7
- name: colorTypeName,
8
- type: "object",
9
- title: "Color",
10
- components: { input: ColorInput },
11
- fields: [
12
- {
13
- title: "Hex",
14
- name: "hex",
15
- type: "string"
16
- },
17
- {
18
- title: "Alpha",
19
- name: "alpha",
20
- type: "number"
21
- },
22
- {
23
- title: "Hue Saturation Lightness",
24
- name: "hsl",
25
- type: "hslaColor"
26
- },
27
- {
28
- title: "Hue Saturation Value",
29
- name: "hsv",
30
- type: "hsvaColor"
31
- },
32
- {
33
- title: "Red Green Blue (rgb)",
34
- name: "rgb",
35
- type: "rgbaColor"
36
- }
37
- ],
38
- preview: {
39
- select: {
40
- title: "hex",
41
- alpha: "alpha",
42
- hex: "hex",
43
- hsl: "hsl"
44
- },
45
- prepare({
46
- title,
47
- hex,
48
- hsl,
49
- alpha
50
- }) {
51
- let subtitle = hex || "No color set";
52
- return hsl && (subtitle = `H:${round(hsl.h)} S:${round(hsl.s)} L:${round(hsl.l)} A:${round(alpha)}`), {
53
- title,
54
- subtitle,
55
- media: () => /* @__PURE__ */ jsxRuntime.jsx(
56
- "div",
57
- {
58
- style: {
59
- backgroundColor: hex ?? "#000",
60
- opacity: alpha ?? 1,
61
- position: "absolute",
62
- height: "100%",
63
- width: "100%",
64
- top: "0",
65
- left: "0"
66
- }
67
- }
68
- )
69
- };
70
- }
71
- }
72
- }), hslaColor = sanity.defineType({
73
- title: "Hue Saturation Lightness",
74
- name: "hslaColor",
75
- type: "object",
76
- fields: [
77
- { name: "h", type: "number", title: "Hue" },
78
- { name: "s", type: "number", title: "Saturation" },
79
- { name: "l", type: "number", title: "Lightness" },
80
- { name: "a", type: "number", title: "Alpha" }
81
- ]
82
- }), hsvaColor = sanity.defineType({
83
- title: "Hue Saturation Value",
84
- name: "hsvaColor",
85
- type: "object",
86
- fields: [
87
- { name: "h", type: "number", title: "Hue" },
88
- { name: "s", type: "number", title: "Saturation" },
89
- { name: "v", type: "number", title: "Value" },
90
- { name: "a", type: "number", title: "Alpha" }
91
- ]
92
- }), rgbaColor = sanity.defineType({
93
- title: "Red Green Blue (rgb)",
94
- name: "rgbaColor",
95
- type: "object",
96
- fields: [
97
- { name: "r", type: "number", title: "Red" },
98
- { name: "g", type: "number", title: "Green" },
99
- { name: "b", type: "number", title: "Blue" },
100
- { name: "a", type: "number", title: "Alpha" }
101
- ]
102
- }), colorInput = sanity.definePlugin({
103
- name: "@sanity/color-input",
104
- schema: {
105
- types: [hslaColor, hsvaColor, rgbaColor, color]
106
- }
107
- });
108
- exports.ColorInput = ColorInput;
109
- exports.color = color;
110
- exports.colorInput = colorInput;
111
- exports.hslaColor = hslaColor;
112
- exports.hsvaColor = hsvaColor;
113
- exports.rgbaColor = rgbaColor;
114
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/LazyColorInput.tsx","../src/schemas/color.tsx","../src/schemas/hslaColor.ts","../src/schemas/hsvaColor.ts","../src/schemas/rgbaColor.ts","../src/index.ts"],"sourcesContent":["import {lazy} from 'react'\n\nexport const ColorInput = lazy(() => import('./ColorInput'))\n","import {defineType, type ObjectDefinition} from 'sanity'\n\nimport {ColorInput} from '../LazyColorInput'\nimport {type ColorOptions} from '../types'\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' {\n // makes type: 'color' narrow correctly when using defineType/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 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 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 {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 {definePlugin} from 'sanity'\n\nimport {color, type ColorDefinition} from './schemas/color'\nimport {hslaColor} from './schemas/hslaColor'\nimport {hsvaColor} from './schemas/hsvaColor'\nimport {rgbaColor} from './schemas/rgbaColor'\n\nexport const colorInput = definePlugin({\n name: '@sanity/color-input',\n schema: {\n types: [hslaColor, hsvaColor, rgbaColor, color],\n },\n})\n\nexport {color, hslaColor, hsvaColor, rgbaColor}\nexport {ColorInput} from './LazyColorInput'\nexport type {ColorDefinition}\nexport type {ColorInputProps, ColorOptions, ColorSchemaType, ColorValue} from './types'\n"],"names":["lazy","defineType","jsx","definePlugin"],"mappings":";;;AAEO,MAAM,aAAaA,MAAAA,KAAK,MAAM,QAAA,QAAA,EAAA,KAAA,WAAA;AAAA,SAAA,QAAO,8BAAc;AAAA,CAAA,CAAC,GCGrD,QAAQ,CAAC,MAAc,MAAM,KAAK,MAAM,MAAM,GAAG,GAEjD,gBAAgB,SAiBT,QAAQC,OAAAA,WAAW;AAAA,EAC9B,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,YAAY,EAAC,OAAO,WAAA;AAAA,EACpB,QAAQ;AAAA,IACN;AAAA,MACE,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,IAAA;AAAA,IAER;AAAA,MACE,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,IAAA;AAAA,IAER;AAAA,MACE,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA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ACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,QAAQ;AAAA,IACN,EAAC,MAAM,KAAK,MAAM,UAAU,OAAO,MAAA;AAAA,IACnC,EAAC,MAAM,KAAK,MAAM,UAAU,OAAO,aAAA;AAAA,IACnC,EAAC,MAAM,KAAK,MAAM,UAAU,OAAO,QAAA;AAAA,IACnC,EAAC,MAAM,KAAK,MAAM,UAAU,OAAO,QAAA;AAAA,EAAO;AAE9C,CAAC,GCVY,YAAYA,OAAAA,WAAW;AAAA,EAClC,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,QAAQ;AAAA,IACN,EAAC,MAAM,KAAK,MAAM,UAAU,OAAO,MAAA;AAAA,IACnC,EAAC,MAAM,KAAK,MAAM,UAAU,OAAO,QAAA;AAAA,IACnC,EAAC,MAAM,KAAK,MAAM,UAAU,OAAO,OAAA;AAAA,IACnC,EAAC,MAAM,KAAK,MAAM,UAAU,OAAO,QAAA;AAAA,EAAO;AAE9C,CAAC,GCLY,aAAaE,OAAAA,aAAa;AAAA,EACrC,MAAM;AAAA,EACN,QAAQ;AAAA,IACN,OAAO,CAAC,WAAW,WAAW,WAAW,KAAK;AAAA,EAAA;AAElD,CAAC;;;;;;;"}
package/dist/index.d.cts DELETED
@@ -1,64 +0,0 @@
1
- import * as sanity8 from "sanity";
2
- import { ObjectDefinition, ObjectInputProps, ObjectOptions, ObjectSchemaType } from "sanity";
3
- import { Color, HSLColor, HSVColor, RGBColor } from "react-color";
4
- import * as react2 from "react";
5
- interface ColorValue {
6
- hex: string;
7
- hsl: HSLColor;
8
- hsv: HSVColor;
9
- rgb: RGBColor;
10
- }
11
- interface ColorOptions extends Omit<ObjectOptions, 'columns'> {
12
- disableAlpha?: boolean;
13
- colorList?: Array<Color>;
14
- }
15
- type ColorSchemaType = Omit<ObjectSchemaType, 'options'> & {
16
- options?: ColorOptions;
17
- };
18
- type ColorInputProps = ObjectInputProps<ColorValue, ColorSchemaType>;
19
- declare const colorTypeName: "color";
20
- /**
21
- * @public
22
- */
23
- interface ColorDefinition extends Omit<ObjectDefinition, 'type' | 'fields' | 'options'> {
24
- type: typeof colorTypeName;
25
- options?: ColorOptions;
26
- }
27
- declare module 'sanity' {
28
- interface IntrinsicDefinitions {
29
- color: ColorDefinition;
30
- }
31
- }
32
- declare const color: {
33
- type: "object";
34
- name: "color";
35
- } & Omit<ObjectDefinition, "preview"> & {
36
- preview?: sanity8.PreviewConfig<{
37
- title: string;
38
- alpha: string;
39
- hex: string;
40
- hsl: string;
41
- }, Record<"alpha" | "hex" | "hsl" | "title", any>>;
42
- };
43
- declare const hslaColor: {
44
- type: "object";
45
- name: "hslaColor";
46
- } & Omit<sanity8.ObjectDefinition, "preview"> & {
47
- preview?: sanity8.PreviewConfig<Record<string, string>, Record<never, any>>;
48
- };
49
- declare const hsvaColor: {
50
- type: "object";
51
- name: "hsvaColor";
52
- } & Omit<sanity8.ObjectDefinition, "preview"> & {
53
- preview?: sanity8.PreviewConfig<Record<string, string>, Record<never, any>>;
54
- };
55
- declare const rgbaColor: {
56
- type: "object";
57
- name: "rgbaColor";
58
- } & Omit<sanity8.ObjectDefinition, "preview"> & {
59
- preview?: sanity8.PreviewConfig<Record<string, string>, Record<never, any>>;
60
- };
61
- declare function ColorInput$1(props: ObjectInputProps): react2.JSX.Element;
62
- declare const ColorInput: react2.LazyExoticComponent<typeof ColorInput$1>;
63
- declare const colorInput: sanity8.Plugin<void>;
64
- export { type ColorDefinition, ColorInput, type ColorInputProps, type ColorOptions, type ColorSchemaType, type ColorValue, color, colorInput, hslaColor, hsvaColor, rgbaColor };