@sanity/color-input 4.0.1-canary.0 → 4.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.
package/lib/index.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
1
+ {"version":3,"file":"index.mjs","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/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 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":[],"mappings":";;;AAEO,MAAM,aAAa,KAAK,MAAM,OAAO,6BAAc,CAAC,GCGrD,QAAQ,CAAC,MAAc,MAAM,KAAK,MAAM,MAAM,GAAG,GAEjD,gBAAgB,SAiBT,QAAQ,WAAW;AAAA,EAC9B,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,YAAY,EAAC,OAAO,WAAU;AAAA,EAC9B,QAAQ;AAAA,IACN;AAAA,MACE,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,IACA;AAAA,MACE,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,IACA;AAAA,MACE,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,IACA;AAAA,MACE,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,IACA;AAAA,MACE,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,IAAA;AAAA,EAEV;AAAA,EACA,SAAS;AAAA,IACP,QAAQ;AAAA,MACN,OAAO;AAAA,MACP,OAAO;AAAA,MACP,KAAK;AAAA,MACL,KAAK;AAAA,IACP;AAAA,IACA,QAAQ;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,GAMC;AACD,UAAI,WAAW,OAAO;AAClB,aAAA,QACF,WAAW,KAAK,MAAM,IAAI,CAAC,CAAC,MAAM,MAAM,IAAI,CAAC,CAAC,MAAM,MAAM,IAAI,CAAC,CAAC,MAAM,MAAM,KAAK,CAAC,KAE7E;AAAA,QACL;AAAA,QACA;AAAA,QACA,OAAO,MACL;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO;AAAA,cACL,iBAAiB,OAAO,OAAA,MAAA;AAAA,cACxB,SAAS,SAAS,OAAA,QAAA;AAAA,cAClB,UAAU;AAAA,cAC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AAK;AAAA,EAAA;AAElD,CAAC;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/color-input",
3
- "version": "4.0.1-canary.0",
3
+ "version": "4.0.2",
4
4
  "description": "Color input",
5
5
  "keywords": [
6
6
  "sanity",
@@ -53,9 +53,9 @@
53
53
  "browserslist": "extends @sanity/browserslist-config",
54
54
  "prettier": "@sanity/prettier-config",
55
55
  "dependencies": {
56
- "@sanity/icons": "^3.4.0",
57
- "@sanity/incompatible-plugin": "^1.0.4",
58
- "@sanity/ui": "^2.8.9",
56
+ "@sanity/icons": "^3.5.3",
57
+ "@sanity/incompatible-plugin": "^1.0.5",
58
+ "@sanity/ui": "^2.10.10",
59
59
  "react-color": "^2.19.3",
60
60
  "use-effect-event": "^1.0.2"
61
61
  },
@@ -83,13 +83,13 @@
83
83
  "prettier": "^3.3.3",
84
84
  "react": "^18.3.1",
85
85
  "react-dom": "^18.3.1",
86
- "sanity": "^3.57.3",
86
+ "sanity": "^3.67.1",
87
87
  "semantic-release": "^24.1.1",
88
88
  "styled-components": "^6.1",
89
89
  "typescript": "^5.6.2"
90
90
  },
91
91
  "peerDependencies": {
92
- "react": "^18.3",
92
+ "react": "^18.3 || ^19",
93
93
  "sanity": "^3.23.0",
94
94
  "styled-components": "^6.1"
95
95
  },
@@ -1,25 +1,11 @@
1
1
  import {AddIcon} from '@sanity/icons'
2
2
  import {Button} from '@sanity/ui'
3
3
  import {startTransition, useCallback, useDeferredValue, useEffect, useRef, useState} from 'react'
4
- import type {Color, HSLColor, HSVColor, RGBColor} from 'react-color'
5
- import {
6
- type ObjectInputProps,
7
- type ObjectOptions,
8
- type ObjectSchemaType,
9
- set,
10
- setIfMissing,
11
- unset,
12
- } from 'sanity'
4
+ import {type ObjectInputProps, set, setIfMissing, unset} from 'sanity'
13
5
  import {useEffectEvent} from 'use-effect-event'
14
6
 
15
7
  import {ColorPicker} from './ColorPicker'
16
-
17
- export interface ColorValue {
18
- hex: string
19
- hsl: HSLColor
20
- hsv: HSVColor
21
- rgb: RGBColor
22
- }
8
+ import type {ColorSchemaType, ColorValue} from './types'
23
9
 
24
10
  const DEFAULT_COLOR: ColorValue & {source: string} = {
25
11
  hex: '#24a3e3',
@@ -29,16 +15,6 @@ const DEFAULT_COLOR: ColorValue & {source: string} = {
29
15
  source: 'hex',
30
16
  }
31
17
 
32
- export interface ColorOptions extends Omit<ObjectOptions, 'columns'> {
33
- disableAlpha?: boolean
34
- colorList?: Array<Color>
35
- }
36
-
37
- export type ColorSchemaType = Omit<ObjectSchemaType, 'options'> & {
38
- options?: ColorOptions
39
- }
40
- export type ColorInputProps = ObjectInputProps<ColorValue, ColorSchemaType>
41
-
42
18
  export default function ColorInput(props: ObjectInputProps) {
43
19
  const {onChange, readOnly} = props
44
20
  const value = props.value as ColorValue | undefined
@@ -5,9 +5,9 @@ import {Alpha, Checkboard, Hue, Saturation} from 'react-color/lib/components/com
5
5
  import type {CustomPickerInjectedProps} from 'react-color/lib/components/common/ColorWrap'
6
6
  import {styled} from 'styled-components'
7
7
 
8
- import type {ColorValue} from './ColorInput'
9
8
  import {ColorList} from './ColorList'
10
9
  import {ColorPickerFields} from './ColorPickerFields'
10
+ import type {ColorValue} from './types'
11
11
 
12
12
  const ColorBox = styled(Box)`
13
13
  position: absolute;
package/src/index.ts CHANGED
@@ -15,4 +15,4 @@ export const colorInput = definePlugin({
15
15
  export {color, hslaColor, hsvaColor, rgbaColor}
16
16
  export {ColorInput} from './LazyColorInput'
17
17
  export type {ColorDefinition}
18
- export type {ColorInputProps, ColorOptions, ColorSchemaType, ColorValue} from './ColorInput'
18
+ export type {ColorInputProps, ColorOptions, ColorSchemaType, ColorValue} from './types'
@@ -1,7 +1,7 @@
1
1
  import {defineType, type ObjectDefinition} from 'sanity'
2
2
 
3
- import {type ColorOptions} from '../ColorInput'
4
3
  import {ColorInput} from '../LazyColorInput'
4
+ import {type ColorOptions} from '../types'
5
5
 
6
6
  const round = (val: number = 1) => Math.round(val * 100)
7
7
 
package/src/types.ts ADDED
@@ -0,0 +1,19 @@
1
+ import type {Color, HSLColor, HSVColor, RGBColor} from 'react-color'
2
+ import type {ObjectInputProps, ObjectOptions, ObjectSchemaType} from 'sanity'
3
+
4
+ export interface ColorValue {
5
+ hex: string
6
+ hsl: HSLColor
7
+ hsv: HSVColor
8
+ rgb: RGBColor
9
+ }
10
+
11
+ export interface ColorOptions extends Omit<ObjectOptions, 'columns'> {
12
+ disableAlpha?: boolean
13
+ colorList?: Array<Color>
14
+ }
15
+
16
+ export type ColorSchemaType = Omit<ObjectSchemaType, 'options'> & {
17
+ options?: ColorOptions
18
+ }
19
+ export type ColorInputProps = ObjectInputProps<ColorValue, ColorSchemaType>