@sanity/color-input 6.0.11 → 6.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ColorInput.js +967 -0
- package/dist/ColorInput.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +143 -132
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
- package/dist/_chunks-es/ColorInput.js +0 -790
- package/dist/_chunks-es/ColorInput.js.map +0 -1
|
@@ -0,0 +1,967 @@
|
|
|
1
|
+
import { set, setIfMissing, unset } from "sanity";
|
|
2
|
+
import { Component, PureComponent, startTransition, useOptimistic, useRef } from "react";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { c } from "react/compiler-runtime";
|
|
5
|
+
import { AddIcon } from "@sanity/icons/Add";
|
|
6
|
+
import { TrashIcon } from "@sanity/icons/Trash";
|
|
7
|
+
import { Box, Button, Card, Flex, Inline, Stack, Text, useTheme } from "@sanity/ui";
|
|
8
|
+
import { styled } from "styled-components";
|
|
9
|
+
import tinycolor from "tinycolor2";
|
|
10
|
+
import throttle from "lodash-es/throttle.js";
|
|
11
|
+
const ColorListWrap = styled(Flex).withConfig({
|
|
12
|
+
displayName: "ColorListWrap",
|
|
13
|
+
componentId: "sc-fcjsbz-0"
|
|
14
|
+
})`gap:0.25em;`, ColorBoxContainer = styled.div.withConfig({
|
|
15
|
+
displayName: "ColorBoxContainer",
|
|
16
|
+
componentId: "sc-fcjsbz-1"
|
|
17
|
+
})`width:2.1em;height:2.1em;cursor:pointer;position:relative;overflow:hidden;border-radius:3px;background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAADFJREFUOE9jZGBgEGHAD97gk2YcNYBhmIQBgWSAP52AwoAQwJvQRg1gACckQoC2gQgAIF8IscwEtKYAAAAASUVORK5CYII=') left center #fff;`, ColorBox$1 = styled.div.withConfig({
|
|
18
|
+
displayName: "ColorBox",
|
|
19
|
+
componentId: "sc-fcjsbz-2"
|
|
20
|
+
})`border-radius:inherit;box-shadow:inset 0 0 0 1px var(--card-shadow-outline-color);content:'';position:absolute;inset:0;z-index:1;`, validateColors = (colors) => {
|
|
21
|
+
let seen = /* @__PURE__ */ new Set();
|
|
22
|
+
return colors.reduce((cls, c) => {
|
|
23
|
+
let color = c.hex ? tinycolor(c.hex) : tinycolor(c);
|
|
24
|
+
if (color.isValid()) {
|
|
25
|
+
let backgroundColor = color.toRgbString(), key = JSON.stringify({
|
|
26
|
+
color: c,
|
|
27
|
+
backgroundColor
|
|
28
|
+
});
|
|
29
|
+
seen.has(key) || (seen.add(key), cls.push({
|
|
30
|
+
key,
|
|
31
|
+
color: c,
|
|
32
|
+
backgroundColor
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
return cls;
|
|
36
|
+
}, []);
|
|
37
|
+
};
|
|
38
|
+
function ColorList(t0) {
|
|
39
|
+
let $ = c(7), { colors, onChange } = t0;
|
|
40
|
+
if (!colors) return null;
|
|
41
|
+
let t1;
|
|
42
|
+
if ($[0] !== colors || $[1] !== onChange) {
|
|
43
|
+
let t2;
|
|
44
|
+
$[3] === onChange ? t2 = $[4] : (t2 = (t3) => {
|
|
45
|
+
let { key, color, backgroundColor } = t3;
|
|
46
|
+
return /* @__PURE__ */ jsx(ColorBoxContainer, {
|
|
47
|
+
onClick: () => {
|
|
48
|
+
onChange(color);
|
|
49
|
+
},
|
|
50
|
+
children: /* @__PURE__ */ jsx(ColorBox$1, { style: { background: backgroundColor } })
|
|
51
|
+
}, key);
|
|
52
|
+
}, $[3] = onChange, $[4] = t2), t1 = validateColors(colors).map(t2), $[0] = colors, $[1] = onChange, $[2] = t1;
|
|
53
|
+
} else t1 = $[2];
|
|
54
|
+
let t2;
|
|
55
|
+
return $[5] === t1 ? t2 = $[6] : (t2 = /* @__PURE__ */ jsx(ColorListWrap, {
|
|
56
|
+
wrap: "wrap",
|
|
57
|
+
children: t1
|
|
58
|
+
}), $[5] = t1, $[6] = t2), t2;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Renders a checkerboard pattern as a data URL, used as the transparency backdrop.
|
|
62
|
+
*
|
|
63
|
+
* Forked from
|
|
64
|
+
* {@link https://github.com/casesandberg/react-color/blob/v2.19.3/src/helpers/checkboard.js | react-color's checkboard helper}
|
|
65
|
+
* (MIT, Copyright (c) 2015 Case Sandberg). See the plugin LICENSE.
|
|
66
|
+
*/
|
|
67
|
+
const checkboardCache = {};
|
|
68
|
+
function render(c1, c2, size, serverCanvas) {
|
|
69
|
+
if (typeof document > "u" && !serverCanvas) return null;
|
|
70
|
+
let canvas = serverCanvas ? new serverCanvas() : document.createElement("canvas");
|
|
71
|
+
canvas.width = size * 2, canvas.height = size * 2;
|
|
72
|
+
let ctx = canvas.getContext("2d");
|
|
73
|
+
return ctx ? (ctx.fillStyle = c1, ctx.fillRect(0, 0, canvas.width, canvas.height), ctx.fillStyle = c2, ctx.fillRect(0, 0, size, size), ctx.translate(size, size), ctx.fillRect(0, 0, size, size), canvas.toDataURL()) : null;
|
|
74
|
+
}
|
|
75
|
+
function get(c1, c2, size, serverCanvas) {
|
|
76
|
+
let key = `${c1}-${c2}-${size}${serverCanvas ? "-server" : ""}`, cached = checkboardCache[key];
|
|
77
|
+
if (cached) return cached;
|
|
78
|
+
let checkboard = render(c1, c2, size, serverCanvas);
|
|
79
|
+
return checkboardCache[key] = checkboard, checkboard;
|
|
80
|
+
}
|
|
81
|
+
const EMPTY_RENDERERS = {};
|
|
82
|
+
function Checkboard(t0) {
|
|
83
|
+
let $ = c(9), { white: t1, grey: t2, size: t3, renderers: t4, borderRadius, boxShadow } = t0, white = t1 === void 0 ? "transparent" : t1, grey = t2 === void 0 ? "rgba(0,0,0,.08)" : t2, size = t3 === void 0 ? 8 : t3, renderers = t4 === void 0 ? EMPTY_RENDERERS : t4, t5;
|
|
84
|
+
$[0] !== grey || $[1] !== renderers.canvas || $[2] !== size || $[3] !== white ? (t5 = get(white, grey, size, renderers.canvas), $[0] = grey, $[1] = renderers.canvas, $[2] = size, $[3] = white, $[4] = t5) : t5 = $[4];
|
|
85
|
+
let background = t5, t6 = background ? `url(${background}) center left` : void 0, t7;
|
|
86
|
+
return $[5] !== borderRadius || $[6] !== boxShadow || $[7] !== t6 ? (t7 = /* @__PURE__ */ jsx("div", { style: {
|
|
87
|
+
borderRadius,
|
|
88
|
+
boxShadow,
|
|
89
|
+
position: "absolute",
|
|
90
|
+
inset: 0,
|
|
91
|
+
background: t6
|
|
92
|
+
} }), $[5] = borderRadius, $[6] = boxShadow, $[7] = t6, $[8] = t7) : t7 = $[8], t7;
|
|
93
|
+
}
|
|
94
|
+
function calculateChange$2(e, hsl, direction, initialA, container) {
|
|
95
|
+
let containerWidth = container.clientWidth, containerHeight = container.clientHeight, x = "touches" in e ? e.touches[0]?.pageX ?? 0 : e.pageX, y = "touches" in e ? e.touches[0]?.pageY ?? 0 : e.pageY, left = x - (container.getBoundingClientRect().left + window.scrollX), top = y - (container.getBoundingClientRect().top + window.scrollY);
|
|
96
|
+
if (direction === "vertical") {
|
|
97
|
+
let a;
|
|
98
|
+
return a = top < 0 ? 0 : top > containerHeight ? 1 : Math.round(top * 100 / containerHeight) / 100, hsl.a === a ? null : {
|
|
99
|
+
h: hsl.h,
|
|
100
|
+
s: hsl.s,
|
|
101
|
+
l: hsl.l,
|
|
102
|
+
a,
|
|
103
|
+
source: "rgb"
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
let a;
|
|
107
|
+
return a = left < 0 ? 0 : left > containerWidth ? 1 : Math.round(left * 100 / containerWidth) / 100, initialA === a ? null : {
|
|
108
|
+
h: hsl.h,
|
|
109
|
+
s: hsl.s,
|
|
110
|
+
l: hsl.l,
|
|
111
|
+
a,
|
|
112
|
+
source: "rgb"
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Alpha (transparency) slider.
|
|
117
|
+
*
|
|
118
|
+
* Forked from
|
|
119
|
+
* {@link https://github.com/casesandberg/react-color/blob/v2.19.3/src/components/common/Alpha.js | react-color's Alpha}
|
|
120
|
+
* (MIT, Copyright (c) 2015 Case Sandberg). See the plugin LICENSE.
|
|
121
|
+
*
|
|
122
|
+
* @remarks
|
|
123
|
+
* Kept as a class component for this round (function-component conversion is a
|
|
124
|
+
* follow-up PR). `reactcss` has been removed in favor of plain inline styles,
|
|
125
|
+
* and the unused custom `pointer` slot dropped.
|
|
126
|
+
*/
|
|
127
|
+
var Alpha = class extends Component {
|
|
128
|
+
container = null;
|
|
129
|
+
componentWillUnmount() {
|
|
130
|
+
this.unbindEventListeners();
|
|
131
|
+
}
|
|
132
|
+
setContainerRef = (node) => {
|
|
133
|
+
this.container = node;
|
|
134
|
+
};
|
|
135
|
+
handleChange = (event) => {
|
|
136
|
+
if (!this.container) return;
|
|
137
|
+
let change = calculateChange$2(event, this.props.hsl, this.props.direction, this.props.a, this.container);
|
|
138
|
+
change && typeof this.props.onChange == "function" && this.props.onChange(change);
|
|
139
|
+
};
|
|
140
|
+
handleMouseDown = (event) => {
|
|
141
|
+
this.handleChange(event.nativeEvent), window.addEventListener("mousemove", this.handleChange), window.addEventListener("mouseup", this.handleMouseUp);
|
|
142
|
+
};
|
|
143
|
+
handleMouseUp = () => {
|
|
144
|
+
this.unbindEventListeners();
|
|
145
|
+
};
|
|
146
|
+
unbindEventListeners = () => {
|
|
147
|
+
window.removeEventListener("mousemove", this.handleChange), window.removeEventListener("mouseup", this.handleMouseUp);
|
|
148
|
+
};
|
|
149
|
+
render() {
|
|
150
|
+
let { rgb, direction, radius, shadow, renderers } = this.props, alphaValue = rgb.a ?? 1, gradient = direction === "vertical" ? `linear-gradient(to bottom, rgba(${rgb.r},${rgb.g},${rgb.b}, 0) 0%, rgba(${rgb.r},${rgb.g},${rgb.b}, 1) 100%)` : `linear-gradient(to right, rgba(${rgb.r},${rgb.g},${rgb.b}, 0) 0%, rgba(${rgb.r},${rgb.g},${rgb.b}, 1) 100%)`, pointerStyle = direction === "vertical" ? {
|
|
151
|
+
position: "absolute",
|
|
152
|
+
left: 0,
|
|
153
|
+
top: `${alphaValue * 100}%`
|
|
154
|
+
} : {
|
|
155
|
+
position: "absolute",
|
|
156
|
+
left: `${alphaValue * 100}%`
|
|
157
|
+
};
|
|
158
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
159
|
+
style: {
|
|
160
|
+
position: "absolute",
|
|
161
|
+
inset: 0,
|
|
162
|
+
borderRadius: radius
|
|
163
|
+
},
|
|
164
|
+
children: [
|
|
165
|
+
/* @__PURE__ */ jsx("div", {
|
|
166
|
+
style: {
|
|
167
|
+
position: "absolute",
|
|
168
|
+
inset: 0,
|
|
169
|
+
overflow: "hidden",
|
|
170
|
+
borderRadius: radius
|
|
171
|
+
},
|
|
172
|
+
children: /* @__PURE__ */ jsx(Checkboard, { renderers })
|
|
173
|
+
}),
|
|
174
|
+
/* @__PURE__ */ jsx("div", { style: {
|
|
175
|
+
position: "absolute",
|
|
176
|
+
inset: 0,
|
|
177
|
+
background: gradient,
|
|
178
|
+
boxShadow: shadow,
|
|
179
|
+
borderRadius: radius
|
|
180
|
+
} }),
|
|
181
|
+
/* @__PURE__ */ jsx("div", {
|
|
182
|
+
style: {
|
|
183
|
+
position: "relative",
|
|
184
|
+
height: "100%",
|
|
185
|
+
margin: "0 3px"
|
|
186
|
+
},
|
|
187
|
+
ref: this.setContainerRef,
|
|
188
|
+
onMouseDown: this.handleMouseDown,
|
|
189
|
+
onTouchMove: this.handleChange,
|
|
190
|
+
onTouchStart: this.handleChange,
|
|
191
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
192
|
+
style: pointerStyle,
|
|
193
|
+
children: /* @__PURE__ */ jsx("div", { style: {
|
|
194
|
+
width: "4px",
|
|
195
|
+
borderRadius: "1px",
|
|
196
|
+
height: "8px",
|
|
197
|
+
boxShadow: "0 0 2px rgba(0, 0, 0, .6)",
|
|
198
|
+
background: "#fff",
|
|
199
|
+
marginTop: "1px",
|
|
200
|
+
transform: "translateX(-2px)"
|
|
201
|
+
} })
|
|
202
|
+
})
|
|
203
|
+
})
|
|
204
|
+
]
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Color conversion and validation helpers built on `tinycolor2`.
|
|
210
|
+
*
|
|
211
|
+
* Forked from
|
|
212
|
+
* {@link https://github.com/casesandberg/react-color/blob/v2.19.3/src/helpers/color.js | react-color's color helpers}
|
|
213
|
+
* (MIT, Copyright (c) 2015 Case Sandberg). See the plugin LICENSE.
|
|
214
|
+
*/
|
|
215
|
+
const VALIDATION_KEYS = /* @__PURE__ */ new Set([
|
|
216
|
+
"r",
|
|
217
|
+
"g",
|
|
218
|
+
"b",
|
|
219
|
+
"a",
|
|
220
|
+
"h",
|
|
221
|
+
"s",
|
|
222
|
+
"l",
|
|
223
|
+
"v"
|
|
224
|
+
]), PERCENT_PATTERN = /^\d+%$/;
|
|
225
|
+
function simpleCheckForValidColor(data) {
|
|
226
|
+
if (typeof data == "string") return data;
|
|
227
|
+
let checked = 0, passed = 0;
|
|
228
|
+
for (let [key, value] of Object.entries(data)) !VALIDATION_KEYS.has(key) || !value || (checked += 1, Number.isNaN(Number(value)) || (passed += 1), (key === "s" || key === "l") && PERCENT_PATTERN.test(String(value)) && (passed += 1));
|
|
229
|
+
return checked === passed ? data : !1;
|
|
230
|
+
}
|
|
231
|
+
function toState(data, oldHue) {
|
|
232
|
+
let instance = typeof data == "string" ? tinycolor(data) : "hex" in data ? tinycolor(data.hex) : tinycolor(data), hsl = instance.toHsl(), hsv = instance.toHsv(), rgb = instance.toRgb(), hex = instance.toHex();
|
|
233
|
+
hsl.s === 0 && (hsl.h = oldHue ?? 0, hsv.h = oldHue ?? 0);
|
|
234
|
+
let transparent = hex === "000000" && rgb.a === 0, incomingHue = typeof data == "string" ? void 0 : "h" in data ? data.h : void 0, source = typeof data == "string" ? void 0 : data.source;
|
|
235
|
+
return {
|
|
236
|
+
hsl,
|
|
237
|
+
hex: transparent ? "transparent" : `#${hex}`,
|
|
238
|
+
rgb,
|
|
239
|
+
hsv,
|
|
240
|
+
oldHue: incomingHue || oldHue || hsl.h,
|
|
241
|
+
source: source ?? ""
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function isValidHex(hex) {
|
|
245
|
+
if (hex === "transparent") return !0;
|
|
246
|
+
let lh = +(hex.charAt(0) === "#");
|
|
247
|
+
return hex.length !== 4 + lh && hex.length < 7 + lh && tinycolor(hex).isValid();
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* `CustomPicker` higher-order component: manages color state and injects the
|
|
251
|
+
* normalized color (`hsl`/`hsv`/`rgb`/`hex`) plus an `onChange` handler into the
|
|
252
|
+
* wrapped picker.
|
|
253
|
+
*
|
|
254
|
+
* Forked from
|
|
255
|
+
* {@link https://github.com/casesandberg/react-color/blob/v2.19.3/src/components/common/ColorWrap.js | react-color's ColorWrap}
|
|
256
|
+
* (MIT, Copyright (c) 2015 Case Sandberg). See the plugin LICENSE.
|
|
257
|
+
*
|
|
258
|
+
* @remarks
|
|
259
|
+
* Kept as a class component for this round (function-component conversion is a
|
|
260
|
+
* follow-up PR). `prop-types` and the unused `lodash` `debounce` of
|
|
261
|
+
* `onChangeComplete` have been removed.
|
|
262
|
+
*/
|
|
263
|
+
const DEFAULT_COLOR$1 = {
|
|
264
|
+
h: 250,
|
|
265
|
+
s: .5,
|
|
266
|
+
l: .2,
|
|
267
|
+
a: 1
|
|
268
|
+
};
|
|
269
|
+
function CustomPicker(Picker) {
|
|
270
|
+
class ColorPicker extends PureComponent {
|
|
271
|
+
static getDerivedStateFromProps(nextProps, state) {
|
|
272
|
+
return { ...toState(nextProps.color ?? DEFAULT_COLOR$1, state.oldHue) };
|
|
273
|
+
}
|
|
274
|
+
constructor(props) {
|
|
275
|
+
super(props), this.state = { ...toState(props.color ?? DEFAULT_COLOR$1, 0) };
|
|
276
|
+
}
|
|
277
|
+
handleChange = (data) => {
|
|
278
|
+
if (!simpleCheckForValidColor(data)) return;
|
|
279
|
+
let colors = toState(data, (typeof data == "string" ? void 0 : "h" in data ? data.h : void 0) || this.state.oldHue);
|
|
280
|
+
this.setState(colors), this.props.onChange?.(colors);
|
|
281
|
+
};
|
|
282
|
+
render() {
|
|
283
|
+
let injected = {
|
|
284
|
+
hsl: this.state.hsl,
|
|
285
|
+
hsv: this.state.hsv,
|
|
286
|
+
rgb: this.state.rgb,
|
|
287
|
+
hex: this.state.hex,
|
|
288
|
+
oldHue: this.state.oldHue,
|
|
289
|
+
source: this.state.source,
|
|
290
|
+
onChange: this.handleChange
|
|
291
|
+
};
|
|
292
|
+
return /* @__PURE__ */ jsx(Picker, {
|
|
293
|
+
...this.props,
|
|
294
|
+
...injected
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return ColorPicker;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Labeled text input with arrow-key stepping and drag-to-change support.
|
|
302
|
+
*
|
|
303
|
+
* Forked from
|
|
304
|
+
* {@link https://github.com/casesandberg/react-color/blob/v2.19.3/src/components/common/EditableInput.js | react-color's EditableInput}
|
|
305
|
+
* (MIT, Copyright (c) 2015 Case Sandberg). See the plugin LICENSE.
|
|
306
|
+
*
|
|
307
|
+
* @remarks
|
|
308
|
+
* Kept as a class component for this round; converting to a function component
|
|
309
|
+
* (with `useId`, `useRef`, etc.) is deferred to a follow-up PR. `reactcss` and
|
|
310
|
+
* `prop-types` have been removed, and deprecated `keyCode` checks replaced with
|
|
311
|
+
* `event.key`.
|
|
312
|
+
*/
|
|
313
|
+
const getNumberValue = (value) => Number(String(value).replace(/%/g, ""));
|
|
314
|
+
let idCounter = 1;
|
|
315
|
+
var EditableInput = class extends Component {
|
|
316
|
+
inputId;
|
|
317
|
+
input = null;
|
|
318
|
+
constructor(props) {
|
|
319
|
+
super(props);
|
|
320
|
+
let initialValue = String(props.value ?? "").toUpperCase();
|
|
321
|
+
this.state = {
|
|
322
|
+
value: initialValue,
|
|
323
|
+
blurValue: initialValue
|
|
324
|
+
}, this.inputId = `rc-editable-input-${idCounter++}`;
|
|
325
|
+
}
|
|
326
|
+
componentDidUpdate(prevProps, prevState) {
|
|
327
|
+
if (this.props.value !== this.state.value && (prevProps.value !== this.props.value || prevState.value !== this.state.value)) {
|
|
328
|
+
let nextValue = String(this.props.value ?? "").toUpperCase(), isFocused = this.input === document.activeElement;
|
|
329
|
+
this.setState(isFocused ? { blurValue: nextValue } : {
|
|
330
|
+
value: nextValue,
|
|
331
|
+
blurValue: this.state.blurValue ? "" : nextValue
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
componentWillUnmount() {
|
|
336
|
+
this.unbindEventListeners();
|
|
337
|
+
}
|
|
338
|
+
setInputRef = (input) => {
|
|
339
|
+
this.input = input;
|
|
340
|
+
};
|
|
341
|
+
getValueObjectWithLabel = (value) => ({ [this.props.label]: String(value) });
|
|
342
|
+
getArrowOffset = () => this.props.arrowOffset ?? 1;
|
|
343
|
+
setUpdatedValue = (value, event) => {
|
|
344
|
+
this.props.onChange?.(this.getValueObjectWithLabel(value), event), this.setState({ value: String(value) });
|
|
345
|
+
};
|
|
346
|
+
handleBlur = () => {
|
|
347
|
+
this.state.blurValue && this.setState({
|
|
348
|
+
value: this.state.blurValue,
|
|
349
|
+
blurValue: ""
|
|
350
|
+
});
|
|
351
|
+
};
|
|
352
|
+
handleChange = (event) => {
|
|
353
|
+
this.setUpdatedValue(event.target.value, event);
|
|
354
|
+
};
|
|
355
|
+
handleKeyDown = (event) => {
|
|
356
|
+
let value = getNumberValue(event.currentTarget.value), isUp = event.key === "ArrowUp", isDown = event.key === "ArrowDown";
|
|
357
|
+
if (!Number.isNaN(value) && (isUp || isDown)) {
|
|
358
|
+
let offset = this.getArrowOffset(), updatedValue = isUp ? value + offset : value - offset;
|
|
359
|
+
this.setUpdatedValue(updatedValue, event);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
handleDrag = (event) => {
|
|
363
|
+
if (!this.props.dragLabel) return;
|
|
364
|
+
let { dragMax, value } = this.props, numericValue = typeof value == "number" ? value : Number(value), newValue = Math.round(numericValue + event.movementX);
|
|
365
|
+
dragMax !== void 0 && newValue >= 0 && newValue <= dragMax && this.props.onChange?.(this.getValueObjectWithLabel(newValue), event);
|
|
366
|
+
};
|
|
367
|
+
handleMouseDown = (event) => {
|
|
368
|
+
this.props.dragLabel && (event.preventDefault(), this.handleDrag(event.nativeEvent), window.addEventListener("mousemove", this.handleDrag), window.addEventListener("mouseup", this.handleMouseUp));
|
|
369
|
+
};
|
|
370
|
+
handleMouseUp = () => {
|
|
371
|
+
this.unbindEventListeners();
|
|
372
|
+
};
|
|
373
|
+
unbindEventListeners = () => {
|
|
374
|
+
window.removeEventListener("mousemove", this.handleDrag), window.removeEventListener("mouseup", this.handleMouseUp);
|
|
375
|
+
};
|
|
376
|
+
render() {
|
|
377
|
+
let style = this.props.style ?? {}, wrapStyle = {
|
|
378
|
+
position: "relative",
|
|
379
|
+
...style.wrap
|
|
380
|
+
}, inputStyle = { ...style.input }, labelStyle = {
|
|
381
|
+
...style.label,
|
|
382
|
+
...this.props.dragLabel ? { cursor: "ew-resize" } : null
|
|
383
|
+
};
|
|
384
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
385
|
+
style: wrapStyle,
|
|
386
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
387
|
+
id: this.inputId,
|
|
388
|
+
style: inputStyle,
|
|
389
|
+
ref: this.setInputRef,
|
|
390
|
+
value: this.state.value,
|
|
391
|
+
onKeyDown: this.handleKeyDown,
|
|
392
|
+
onChange: this.handleChange,
|
|
393
|
+
onBlur: this.handleBlur,
|
|
394
|
+
placeholder: this.props.placeholder,
|
|
395
|
+
spellCheck: "false"
|
|
396
|
+
}), this.props.label && !this.props.hideLabel ? /* @__PURE__ */ jsx("label", {
|
|
397
|
+
htmlFor: this.inputId,
|
|
398
|
+
style: labelStyle,
|
|
399
|
+
onMouseDown: this.handleMouseDown,
|
|
400
|
+
children: this.props.label
|
|
401
|
+
}) : null]
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
function calculateChange$1(e, direction, hsl, container) {
|
|
406
|
+
let containerWidth = container.clientWidth, containerHeight = container.clientHeight, x = "touches" in e ? e.touches[0]?.pageX ?? 0 : e.pageX, y = "touches" in e ? e.touches[0]?.pageY ?? 0 : e.pageY, left = x - (container.getBoundingClientRect().left + window.scrollX), top = y - (container.getBoundingClientRect().top + window.scrollY);
|
|
407
|
+
if (direction === "vertical") {
|
|
408
|
+
let h;
|
|
409
|
+
return h = top < 0 ? 359 : top > containerHeight ? 0 : 360 * (-(top * 100 / containerHeight) + 100) / 100, hsl.h === h ? null : {
|
|
410
|
+
h,
|
|
411
|
+
s: hsl.s,
|
|
412
|
+
l: hsl.l,
|
|
413
|
+
a: hsl.a ?? 1,
|
|
414
|
+
source: "hsl"
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
let h;
|
|
418
|
+
return h = left < 0 ? 0 : left > containerWidth ? 359 : 360 * (left * 100 / containerWidth) / 100, hsl.h === h ? null : {
|
|
419
|
+
h,
|
|
420
|
+
s: hsl.s,
|
|
421
|
+
l: hsl.l,
|
|
422
|
+
a: hsl.a ?? 1,
|
|
423
|
+
source: "hsl"
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Hue slider.
|
|
428
|
+
*
|
|
429
|
+
* Forked from
|
|
430
|
+
* {@link https://github.com/casesandberg/react-color/blob/v2.19.3/src/components/common/Hue.js | react-color's Hue}
|
|
431
|
+
* (MIT, Copyright (c) 2015 Case Sandberg). See the plugin LICENSE.
|
|
432
|
+
*
|
|
433
|
+
* @remarks
|
|
434
|
+
* Kept as a class component for this round (function-component conversion is a
|
|
435
|
+
* follow-up PR). The upstream raw `<style>` tag holding the static hue gradient
|
|
436
|
+
* has been replaced with a `styled-components` element, and `reactcss` removed.
|
|
437
|
+
*/
|
|
438
|
+
const HueGradient = styled.div.withConfig({
|
|
439
|
+
displayName: "HueGradient",
|
|
440
|
+
componentId: "sc-kldwsm-0"
|
|
441
|
+
})`background:${({ $direction }) => $direction === "vertical" ? "linear-gradient(to top, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%)" : "linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%)"};`;
|
|
442
|
+
var Hue = class extends Component {
|
|
443
|
+
container = null;
|
|
444
|
+
componentWillUnmount() {
|
|
445
|
+
this.unbindEventListeners();
|
|
446
|
+
}
|
|
447
|
+
setContainerRef = (node) => {
|
|
448
|
+
this.container = node;
|
|
449
|
+
};
|
|
450
|
+
handleChange = (event) => {
|
|
451
|
+
if (!this.container) return;
|
|
452
|
+
let change = calculateChange$1(event, this.props.direction, this.props.hsl, this.container);
|
|
453
|
+
change && typeof this.props.onChange == "function" && this.props.onChange(change);
|
|
454
|
+
};
|
|
455
|
+
handleMouseDown = (event) => {
|
|
456
|
+
this.handleChange(event.nativeEvent), window.addEventListener("mousemove", this.handleChange), window.addEventListener("mouseup", this.handleMouseUp);
|
|
457
|
+
};
|
|
458
|
+
handleMouseUp = () => {
|
|
459
|
+
this.unbindEventListeners();
|
|
460
|
+
};
|
|
461
|
+
unbindEventListeners = () => {
|
|
462
|
+
window.removeEventListener("mousemove", this.handleChange), window.removeEventListener("mouseup", this.handleMouseUp);
|
|
463
|
+
};
|
|
464
|
+
render() {
|
|
465
|
+
let { hsl, direction = "horizontal", radius, shadow } = this.props, pointerStyle = direction === "vertical" ? {
|
|
466
|
+
position: "absolute",
|
|
467
|
+
left: "0px",
|
|
468
|
+
top: `${-(hsl.h * 100 / 360) + 100}%`
|
|
469
|
+
} : {
|
|
470
|
+
position: "absolute",
|
|
471
|
+
left: `${hsl.h * 100 / 360}%`
|
|
472
|
+
};
|
|
473
|
+
return /* @__PURE__ */ jsx("div", {
|
|
474
|
+
style: {
|
|
475
|
+
position: "absolute",
|
|
476
|
+
inset: 0,
|
|
477
|
+
borderRadius: radius,
|
|
478
|
+
boxShadow: shadow
|
|
479
|
+
},
|
|
480
|
+
children: /* @__PURE__ */ jsx(HueGradient, {
|
|
481
|
+
$direction: direction,
|
|
482
|
+
style: {
|
|
483
|
+
padding: "0 2px",
|
|
484
|
+
position: "relative",
|
|
485
|
+
height: "100%",
|
|
486
|
+
borderRadius: radius
|
|
487
|
+
},
|
|
488
|
+
ref: this.setContainerRef,
|
|
489
|
+
onMouseDown: this.handleMouseDown,
|
|
490
|
+
onTouchMove: this.handleChange,
|
|
491
|
+
onTouchStart: this.handleChange,
|
|
492
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
493
|
+
style: pointerStyle,
|
|
494
|
+
children: /* @__PURE__ */ jsx("div", { style: {
|
|
495
|
+
marginTop: "1px",
|
|
496
|
+
width: "4px",
|
|
497
|
+
borderRadius: "1px",
|
|
498
|
+
height: "8px",
|
|
499
|
+
boxShadow: "0 0 2px rgba(0, 0, 0, .6)",
|
|
500
|
+
background: "#fff",
|
|
501
|
+
transform: "translateX(-2px)"
|
|
502
|
+
} })
|
|
503
|
+
})
|
|
504
|
+
})
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
function calculateChange(e, hsl, container) {
|
|
509
|
+
let { width: containerWidth, height: containerHeight } = container.getBoundingClientRect(), x = "touches" in e ? e.touches[0]?.pageX ?? 0 : e.pageX, y = "touches" in e ? e.touches[0]?.pageY ?? 0 : e.pageY, left = x - (container.getBoundingClientRect().left + window.scrollX), top = y - (container.getBoundingClientRect().top + window.scrollY);
|
|
510
|
+
left < 0 ? left = 0 : left > containerWidth && (left = containerWidth), top < 0 ? top = 0 : top > containerHeight && (top = containerHeight);
|
|
511
|
+
let saturation = left / containerWidth, bright = 1 - top / containerHeight;
|
|
512
|
+
return {
|
|
513
|
+
h: hsl.h,
|
|
514
|
+
s: saturation,
|
|
515
|
+
v: bright,
|
|
516
|
+
a: hsl.a ?? 1,
|
|
517
|
+
source: "hsv"
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Saturation / value box.
|
|
522
|
+
*
|
|
523
|
+
* Forked from
|
|
524
|
+
* {@link https://github.com/casesandberg/react-color/blob/v2.19.3/src/components/common/Saturation.js | react-color's Saturation}
|
|
525
|
+
* (MIT, Copyright (c) 2015 Case Sandberg). See the plugin LICENSE.
|
|
526
|
+
*
|
|
527
|
+
* @remarks
|
|
528
|
+
* Kept as a class component for this round (function-component conversion is a
|
|
529
|
+
* follow-up PR). The upstream raw `<style>` tag holding the static white/black
|
|
530
|
+
* gradients has been replaced with `styled-components` elements, `reactcss`
|
|
531
|
+
* removed, and `lodash` swapped for `lodash-es`.
|
|
532
|
+
*/
|
|
533
|
+
const SaturationWhite = styled.div.withConfig({
|
|
534
|
+
displayName: "SaturationWhite",
|
|
535
|
+
componentId: "sc-0wl7vo-0"
|
|
536
|
+
})`background:linear-gradient(to right,#fff,rgba(255,255,255,0));`, SaturationBlack = styled.div.withConfig({
|
|
537
|
+
displayName: "SaturationBlack",
|
|
538
|
+
componentId: "sc-0wl7vo-1"
|
|
539
|
+
})`background:linear-gradient(to top,#000,rgba(0,0,0,0));`;
|
|
540
|
+
var Saturation = class extends Component {
|
|
541
|
+
container = null;
|
|
542
|
+
throttle = throttle((handler, data) => {
|
|
543
|
+
handler(data);
|
|
544
|
+
}, 50);
|
|
545
|
+
componentWillUnmount() {
|
|
546
|
+
this.throttle.cancel(), this.unbindEventListeners();
|
|
547
|
+
}
|
|
548
|
+
setContainerRef = (node) => {
|
|
549
|
+
this.container = node;
|
|
550
|
+
};
|
|
551
|
+
getContainerRenderWindow() {
|
|
552
|
+
let { container } = this, renderWindow = window;
|
|
553
|
+
for (; !renderWindow.document.contains(container) && renderWindow.parent !== renderWindow;) renderWindow = renderWindow.parent;
|
|
554
|
+
return renderWindow;
|
|
555
|
+
}
|
|
556
|
+
handleChange = (event) => {
|
|
557
|
+
!this.container || typeof this.props.onChange != "function" || this.throttle(this.props.onChange, calculateChange(event, this.props.hsl, this.container));
|
|
558
|
+
};
|
|
559
|
+
handleMouseDown = (event) => {
|
|
560
|
+
this.handleChange(event.nativeEvent);
|
|
561
|
+
let renderWindow = this.getContainerRenderWindow();
|
|
562
|
+
renderWindow.addEventListener("mousemove", this.handleChange), renderWindow.addEventListener("mouseup", this.handleMouseUp);
|
|
563
|
+
};
|
|
564
|
+
handleMouseUp = () => {
|
|
565
|
+
this.unbindEventListeners();
|
|
566
|
+
};
|
|
567
|
+
unbindEventListeners = () => {
|
|
568
|
+
let renderWindow = this.getContainerRenderWindow();
|
|
569
|
+
renderWindow.removeEventListener("mousemove", this.handleChange), renderWindow.removeEventListener("mouseup", this.handleMouseUp);
|
|
570
|
+
};
|
|
571
|
+
render() {
|
|
572
|
+
let { hsl, hsv, radius, shadow } = this.props, pointerStyle = {
|
|
573
|
+
position: "absolute",
|
|
574
|
+
top: `${-(hsv.v * 100) + 100}%`,
|
|
575
|
+
left: `${hsv.s * 100}%`,
|
|
576
|
+
cursor: "default"
|
|
577
|
+
};
|
|
578
|
+
return /* @__PURE__ */ jsx("div", {
|
|
579
|
+
style: {
|
|
580
|
+
position: "absolute",
|
|
581
|
+
inset: 0,
|
|
582
|
+
background: `hsl(${hsl.h},100%, 50%)`,
|
|
583
|
+
borderRadius: radius
|
|
584
|
+
},
|
|
585
|
+
ref: this.setContainerRef,
|
|
586
|
+
onMouseDown: this.handleMouseDown,
|
|
587
|
+
onTouchMove: this.handleChange,
|
|
588
|
+
onTouchStart: this.handleChange,
|
|
589
|
+
children: /* @__PURE__ */ jsxs(SaturationWhite, {
|
|
590
|
+
style: {
|
|
591
|
+
position: "absolute",
|
|
592
|
+
inset: 0,
|
|
593
|
+
borderRadius: radius
|
|
594
|
+
},
|
|
595
|
+
children: [/* @__PURE__ */ jsx(SaturationBlack, { style: {
|
|
596
|
+
position: "absolute",
|
|
597
|
+
inset: 0,
|
|
598
|
+
boxShadow: shadow,
|
|
599
|
+
borderRadius: radius
|
|
600
|
+
} }), /* @__PURE__ */ jsx("div", {
|
|
601
|
+
style: pointerStyle,
|
|
602
|
+
children: /* @__PURE__ */ jsx("div", { style: {
|
|
603
|
+
width: "4px",
|
|
604
|
+
height: "4px",
|
|
605
|
+
boxShadow: "0 0 0 1.5px #fff, inset 0 0 1px 1px rgba(0,0,0,.3), 0 0 1px 2px rgba(0,0,0,.4)",
|
|
606
|
+
borderRadius: "50%",
|
|
607
|
+
cursor: "pointer",
|
|
608
|
+
transform: "translate(-2px, -2px)"
|
|
609
|
+
} })
|
|
610
|
+
})]
|
|
611
|
+
})
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
const ColorPickerFields = (t0) => {
|
|
616
|
+
let $ = c(44), { onChange, rgb, hsl, hex, disableAlpha } = t0, { sanity } = useTheme(), t1 = `inset 0 0 0 1px ${sanity.color.input.default.enabled.border}`, t2 = sanity.fonts.text.sizes[0]?.fontSize, t3;
|
|
617
|
+
$[0] !== sanity.color.input.default.enabled.bg || $[1] !== sanity.color.input.default.enabled.fg || $[2] !== t1 || $[3] !== t2 ? (t3 = {
|
|
618
|
+
width: "80%",
|
|
619
|
+
padding: "4px 10% 3px",
|
|
620
|
+
border: "none",
|
|
621
|
+
boxShadow: t1,
|
|
622
|
+
color: sanity.color.input.default.enabled.fg,
|
|
623
|
+
backgroundColor: sanity.color.input.default.enabled.bg,
|
|
624
|
+
fontSize: t2,
|
|
625
|
+
textAlign: "center"
|
|
626
|
+
}, $[0] = sanity.color.input.default.enabled.bg, $[1] = sanity.color.input.default.enabled.fg, $[2] = t1, $[3] = t2, $[4] = t3) : t3 = $[4];
|
|
627
|
+
let t4 = sanity.fonts.label.sizes[0]?.fontSize, t5;
|
|
628
|
+
$[5] !== sanity.color.base.fg || $[6] !== t4 ? (t5 = {
|
|
629
|
+
display: "block",
|
|
630
|
+
textAlign: "center",
|
|
631
|
+
fontSize: t4,
|
|
632
|
+
color: sanity.color.base.fg,
|
|
633
|
+
paddingTop: "3px",
|
|
634
|
+
paddingBottom: "4px",
|
|
635
|
+
textTransform: "capitalize"
|
|
636
|
+
}, $[5] = sanity.color.base.fg, $[6] = t4, $[7] = t5) : t5 = $[7];
|
|
637
|
+
let t6;
|
|
638
|
+
$[8] !== t3 || $[9] !== t5 ? (t6 = {
|
|
639
|
+
input: t3,
|
|
640
|
+
label: t5
|
|
641
|
+
}, $[8] = t3, $[9] = t5, $[10] = t6) : t6 = $[10];
|
|
642
|
+
let inputStyles = t6, t7;
|
|
643
|
+
$[11] !== hsl || $[12] !== onChange || $[13] !== rgb ? (t7 = (data) => {
|
|
644
|
+
if ("hex" in data && data.hex && isValidHex(data.hex)) onChange({
|
|
645
|
+
hex: data.hex,
|
|
646
|
+
source: "hex"
|
|
647
|
+
});
|
|
648
|
+
else if (rgb && ("r" in data && data.r || "g" in data && data.g || "b" in data && data.b)) onChange({
|
|
649
|
+
r: Number(data.r) || rgb.r,
|
|
650
|
+
g: Number(data.g) || rgb.g,
|
|
651
|
+
b: Number(data.b) || rgb.b,
|
|
652
|
+
a: rgb.a,
|
|
653
|
+
source: "rgb"
|
|
654
|
+
});
|
|
655
|
+
else if (hsl && "a" in data && data.a) {
|
|
656
|
+
let alpha = Number(data.a);
|
|
657
|
+
alpha < 0 ? alpha = 0 : alpha > 100 && (alpha = 100), alpha /= 100, onChange({
|
|
658
|
+
h: hsl.h,
|
|
659
|
+
s: hsl.s,
|
|
660
|
+
l: hsl.l,
|
|
661
|
+
a: alpha,
|
|
662
|
+
source: "hsl"
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
}, $[11] = hsl, $[12] = onChange, $[13] = rgb, $[14] = t7) : t7 = $[14];
|
|
666
|
+
let handleChange = t7, t8;
|
|
667
|
+
$[15] === hex ? t8 = $[16] : (t8 = hex?.replace("#", ""), $[15] = hex, $[16] = t8);
|
|
668
|
+
let t9;
|
|
669
|
+
$[17] !== handleChange || $[18] !== inputStyles || $[19] !== t8 ? (t9 = /* @__PURE__ */ jsx(Box, {
|
|
670
|
+
flex: 2,
|
|
671
|
+
marginRight: 1,
|
|
672
|
+
children: /* @__PURE__ */ jsx(EditableInput, {
|
|
673
|
+
style: inputStyles,
|
|
674
|
+
label: "hex",
|
|
675
|
+
value: t8,
|
|
676
|
+
onChange: handleChange
|
|
677
|
+
})
|
|
678
|
+
}), $[17] = handleChange, $[18] = inputStyles, $[19] = t8, $[20] = t9) : t9 = $[20];
|
|
679
|
+
let t10 = rgb?.r, t11;
|
|
680
|
+
$[21] !== handleChange || $[22] !== inputStyles || $[23] !== t10 ? (t11 = /* @__PURE__ */ jsx(Box, {
|
|
681
|
+
flex: 1,
|
|
682
|
+
marginRight: 1,
|
|
683
|
+
children: /* @__PURE__ */ jsx(EditableInput, {
|
|
684
|
+
style: inputStyles,
|
|
685
|
+
label: "r",
|
|
686
|
+
value: t10,
|
|
687
|
+
onChange: handleChange,
|
|
688
|
+
dragLabel: !0,
|
|
689
|
+
dragMax: 255
|
|
690
|
+
})
|
|
691
|
+
}), $[21] = handleChange, $[22] = inputStyles, $[23] = t10, $[24] = t11) : t11 = $[24];
|
|
692
|
+
let t12 = rgb?.g, t13;
|
|
693
|
+
$[25] !== handleChange || $[26] !== inputStyles || $[27] !== t12 ? (t13 = /* @__PURE__ */ jsx(Box, {
|
|
694
|
+
flex: 1,
|
|
695
|
+
marginRight: 1,
|
|
696
|
+
children: /* @__PURE__ */ jsx(EditableInput, {
|
|
697
|
+
style: inputStyles,
|
|
698
|
+
label: "g",
|
|
699
|
+
value: t12,
|
|
700
|
+
onChange: handleChange,
|
|
701
|
+
dragLabel: !0,
|
|
702
|
+
dragMax: 255
|
|
703
|
+
})
|
|
704
|
+
}), $[25] = handleChange, $[26] = inputStyles, $[27] = t12, $[28] = t13) : t13 = $[28];
|
|
705
|
+
let t14 = rgb?.b, t15;
|
|
706
|
+
$[29] !== handleChange || $[30] !== inputStyles || $[31] !== t14 ? (t15 = /* @__PURE__ */ jsx(Box, {
|
|
707
|
+
flex: 1,
|
|
708
|
+
marginRight: 1,
|
|
709
|
+
children: /* @__PURE__ */ jsx(EditableInput, {
|
|
710
|
+
style: inputStyles,
|
|
711
|
+
label: "b",
|
|
712
|
+
value: t14,
|
|
713
|
+
onChange: handleChange,
|
|
714
|
+
dragLabel: !0,
|
|
715
|
+
dragMax: 255
|
|
716
|
+
})
|
|
717
|
+
}), $[29] = handleChange, $[30] = inputStyles, $[31] = t14, $[32] = t15) : t15 = $[32];
|
|
718
|
+
let t16;
|
|
719
|
+
$[33] !== disableAlpha || $[34] !== handleChange || $[35] !== inputStyles || $[36] !== rgb?.a ? (t16 = !disableAlpha && /* @__PURE__ */ jsx(Box, {
|
|
720
|
+
flex: 1,
|
|
721
|
+
children: /* @__PURE__ */ jsx(EditableInput, {
|
|
722
|
+
style: inputStyles,
|
|
723
|
+
label: "a",
|
|
724
|
+
value: Math.round((rgb?.a ?? 1) * 100),
|
|
725
|
+
onChange: handleChange,
|
|
726
|
+
dragLabel: !0,
|
|
727
|
+
dragMax: 100
|
|
728
|
+
})
|
|
729
|
+
}), $[33] = disableAlpha, $[34] = handleChange, $[35] = inputStyles, $[36] = rgb?.a, $[37] = t16) : t16 = $[37];
|
|
730
|
+
let t17;
|
|
731
|
+
return $[38] !== t11 || $[39] !== t13 || $[40] !== t15 || $[41] !== t16 || $[42] !== t9 ? (t17 = /* @__PURE__ */ jsxs(Flex, { children: [
|
|
732
|
+
t9,
|
|
733
|
+
t11,
|
|
734
|
+
t13,
|
|
735
|
+
t15,
|
|
736
|
+
t16
|
|
737
|
+
] }), $[38] = t11, $[39] = t13, $[40] = t15, $[41] = t16, $[42] = t9, $[43] = t17) : t17 = $[43], t17;
|
|
738
|
+
}, ColorBox = styled(Box).withConfig({
|
|
739
|
+
displayName: "ColorBox",
|
|
740
|
+
componentId: "sc-pfhngk-0"
|
|
741
|
+
})`position:absolute;top:0;left:0;width:100%;height:100%;`, ReadOnlyContainer = styled(Flex).withConfig({
|
|
742
|
+
displayName: "ReadOnlyContainer",
|
|
743
|
+
componentId: "sc-pfhngk-1"
|
|
744
|
+
})`margin-top:6rem;background-color:var(--card-bg-color);position:relative;width:100%;`, ColorPicker = CustomPicker((props) => {
|
|
745
|
+
let $ = c(46), { width, color: t0, onChange, onUnset, disableAlpha, colorList, readOnly } = props, { rgb, hex, hsv, hsl } = t0;
|
|
746
|
+
if (!hsl || !hsv) return null;
|
|
747
|
+
let t1;
|
|
748
|
+
$[0] === width ? t1 = $[1] : (t1 = { width }, $[0] = width, $[1] = t1);
|
|
749
|
+
let t2;
|
|
750
|
+
$[2] !== disableAlpha || $[3] !== hsl || $[4] !== hsv || $[5] !== onChange || $[6] !== readOnly || $[7] !== rgb ? (t2 = !readOnly && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
751
|
+
/* @__PURE__ */ jsx(Card, {
|
|
752
|
+
overflow: "hidden",
|
|
753
|
+
style: {
|
|
754
|
+
position: "relative",
|
|
755
|
+
height: "5em"
|
|
756
|
+
},
|
|
757
|
+
children: /* @__PURE__ */ jsx(Saturation, {
|
|
758
|
+
onChange,
|
|
759
|
+
hsl,
|
|
760
|
+
hsv
|
|
761
|
+
})
|
|
762
|
+
}),
|
|
763
|
+
/* @__PURE__ */ jsx(Card, {
|
|
764
|
+
shadow: 1,
|
|
765
|
+
radius: 3,
|
|
766
|
+
overflow: "hidden",
|
|
767
|
+
style: {
|
|
768
|
+
position: "relative",
|
|
769
|
+
height: "10px"
|
|
770
|
+
},
|
|
771
|
+
children: /* @__PURE__ */ jsx(Hue, {
|
|
772
|
+
hsl,
|
|
773
|
+
onChange: !readOnly && onChange
|
|
774
|
+
})
|
|
775
|
+
}),
|
|
776
|
+
!disableAlpha && /* @__PURE__ */ jsx(Card, {
|
|
777
|
+
shadow: 1,
|
|
778
|
+
radius: 3,
|
|
779
|
+
overflow: "hidden",
|
|
780
|
+
style: {
|
|
781
|
+
position: "relative",
|
|
782
|
+
height: "10px",
|
|
783
|
+
background: "#fff"
|
|
784
|
+
},
|
|
785
|
+
children: /* @__PURE__ */ jsx(Alpha, {
|
|
786
|
+
rgb,
|
|
787
|
+
hsl,
|
|
788
|
+
onChange
|
|
789
|
+
})
|
|
790
|
+
})
|
|
791
|
+
] }), $[2] = disableAlpha, $[3] = hsl, $[4] = hsv, $[5] = onChange, $[6] = readOnly, $[7] = rgb, $[8] = t2) : t2 = $[8];
|
|
792
|
+
let t3, t4;
|
|
793
|
+
$[9] === Symbol.for("react.memo_cache_sentinel") ? (t3 = {
|
|
794
|
+
position: "relative",
|
|
795
|
+
minWidth: "4em",
|
|
796
|
+
background: "#fff"
|
|
797
|
+
}, t4 = /* @__PURE__ */ jsx(Checkboard, {
|
|
798
|
+
size: 8,
|
|
799
|
+
white: "transparent",
|
|
800
|
+
grey: "rgba(0,0,0,.08)"
|
|
801
|
+
}), $[9] = t3, $[10] = t4) : (t3 = $[9], t4 = $[10]);
|
|
802
|
+
let t5 = `rgba(${rgb?.r},${rgb?.g},${rgb?.b},${rgb?.a})`, t6;
|
|
803
|
+
$[11] === t5 ? t6 = $[12] : (t6 = /* @__PURE__ */ jsx(ColorBox, { style: { backgroundColor: t5 } }), $[11] = t5, $[12] = t6);
|
|
804
|
+
let t7;
|
|
805
|
+
$[13] !== hex || $[14] !== hsl?.h || $[15] !== hsl?.l || $[16] !== hsl?.s || $[17] !== readOnly || $[18] !== rgb?.b || $[19] !== rgb?.g || $[20] !== rgb?.r ? (t7 = readOnly && /* @__PURE__ */ jsx(ReadOnlyContainer, {
|
|
806
|
+
padding: 2,
|
|
807
|
+
paddingBottom: 1,
|
|
808
|
+
sizing: "border",
|
|
809
|
+
justify: "space-between",
|
|
810
|
+
children: /* @__PURE__ */ jsxs(Stack, {
|
|
811
|
+
gap: 3,
|
|
812
|
+
marginTop: 1,
|
|
813
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
814
|
+
size: 3,
|
|
815
|
+
weight: "bold",
|
|
816
|
+
children: hex
|
|
817
|
+
}), /* @__PURE__ */ jsxs(Inline, {
|
|
818
|
+
gap: 3,
|
|
819
|
+
children: [/* @__PURE__ */ jsxs(Text, {
|
|
820
|
+
size: 1,
|
|
821
|
+
children: [
|
|
822
|
+
/* @__PURE__ */ jsx("strong", { children: "RGB: " }),
|
|
823
|
+
rgb?.r,
|
|
824
|
+
" ",
|
|
825
|
+
rgb?.g,
|
|
826
|
+
" ",
|
|
827
|
+
rgb?.b
|
|
828
|
+
]
|
|
829
|
+
}), /* @__PURE__ */ jsxs(Text, {
|
|
830
|
+
size: 1,
|
|
831
|
+
children: [
|
|
832
|
+
/* @__PURE__ */ jsx("strong", { children: "HSL: " }),
|
|
833
|
+
" ",
|
|
834
|
+
Math.round(hsl?.h ?? 0),
|
|
835
|
+
" ",
|
|
836
|
+
Math.round((hsl?.s ?? 0) * 100),
|
|
837
|
+
"% ",
|
|
838
|
+
Math.round((hsl?.l ?? 0) * 100),
|
|
839
|
+
"%"
|
|
840
|
+
]
|
|
841
|
+
})]
|
|
842
|
+
})]
|
|
843
|
+
})
|
|
844
|
+
}), $[13] = hex, $[14] = hsl?.h, $[15] = hsl?.l, $[16] = hsl?.s, $[17] = readOnly, $[18] = rgb?.b, $[19] = rgb?.g, $[20] = rgb?.r, $[21] = t7) : t7 = $[21];
|
|
845
|
+
let t8;
|
|
846
|
+
$[22] !== t6 || $[23] !== t7 ? (t8 = /* @__PURE__ */ jsxs(Card, {
|
|
847
|
+
flex: 1,
|
|
848
|
+
radius: 2,
|
|
849
|
+
overflow: "hidden",
|
|
850
|
+
style: t3,
|
|
851
|
+
children: [
|
|
852
|
+
t4,
|
|
853
|
+
t6,
|
|
854
|
+
t7
|
|
855
|
+
]
|
|
856
|
+
}), $[22] = t6, $[23] = t7, $[24] = t8) : t8 = $[24];
|
|
857
|
+
let t9;
|
|
858
|
+
$[25] !== disableAlpha || $[26] !== hex || $[27] !== hsl || $[28] !== onChange || $[29] !== onUnset || $[30] !== readOnly || $[31] !== rgb ? (t9 = !readOnly && /* @__PURE__ */ jsxs(Flex, {
|
|
859
|
+
align: "flex-start",
|
|
860
|
+
marginLeft: 2,
|
|
861
|
+
children: [/* @__PURE__ */ jsx(Box, {
|
|
862
|
+
style: { width: 200 },
|
|
863
|
+
children: /* @__PURE__ */ jsx(ColorPickerFields, {
|
|
864
|
+
rgb,
|
|
865
|
+
hsl,
|
|
866
|
+
hex,
|
|
867
|
+
onChange,
|
|
868
|
+
disableAlpha
|
|
869
|
+
})
|
|
870
|
+
}), /* @__PURE__ */ jsx(Box, {
|
|
871
|
+
marginLeft: 2,
|
|
872
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
873
|
+
onClick: onUnset,
|
|
874
|
+
title: "Delete color",
|
|
875
|
+
icon: TrashIcon,
|
|
876
|
+
tone: "critical"
|
|
877
|
+
})
|
|
878
|
+
})]
|
|
879
|
+
}), $[25] = disableAlpha, $[26] = hex, $[27] = hsl, $[28] = onChange, $[29] = onUnset, $[30] = readOnly, $[31] = rgb, $[32] = t9) : t9 = $[32];
|
|
880
|
+
let t10;
|
|
881
|
+
$[33] !== t8 || $[34] !== t9 ? (t10 = /* @__PURE__ */ jsxs(Flex, { children: [t8, t9] }), $[33] = t8, $[34] = t9, $[35] = t10) : t10 = $[35];
|
|
882
|
+
let t11;
|
|
883
|
+
$[36] !== colorList || $[37] !== onChange ? (t11 = colorList && /* @__PURE__ */ jsx(ColorList, {
|
|
884
|
+
colors: colorList,
|
|
885
|
+
onChange
|
|
886
|
+
}), $[36] = colorList, $[37] = onChange, $[38] = t11) : t11 = $[38];
|
|
887
|
+
let t12;
|
|
888
|
+
$[39] !== t10 || $[40] !== t11 || $[41] !== t2 ? (t12 = /* @__PURE__ */ jsx(Card, {
|
|
889
|
+
padding: 1,
|
|
890
|
+
border: !0,
|
|
891
|
+
radius: 1,
|
|
892
|
+
children: /* @__PURE__ */ jsxs(Stack, {
|
|
893
|
+
gap: 2,
|
|
894
|
+
children: [
|
|
895
|
+
t2,
|
|
896
|
+
t10,
|
|
897
|
+
t11
|
|
898
|
+
]
|
|
899
|
+
})
|
|
900
|
+
}), $[39] = t10, $[40] = t11, $[41] = t2, $[42] = t12) : t12 = $[42];
|
|
901
|
+
let t13;
|
|
902
|
+
return $[43] !== t1 || $[44] !== t12 ? (t13 = /* @__PURE__ */ jsx("div", {
|
|
903
|
+
style: t1,
|
|
904
|
+
children: t12
|
|
905
|
+
}), $[43] = t1, $[44] = t12, $[45] = t13) : t13 = $[45], t13;
|
|
906
|
+
}), DEFAULT_COLOR = {
|
|
907
|
+
hex: "#24a3e3",
|
|
908
|
+
hsl: {
|
|
909
|
+
h: 200,
|
|
910
|
+
s: .7732,
|
|
911
|
+
l: .5156,
|
|
912
|
+
a: 1
|
|
913
|
+
},
|
|
914
|
+
hsv: {
|
|
915
|
+
h: 200,
|
|
916
|
+
s: .8414,
|
|
917
|
+
v: .8901,
|
|
918
|
+
a: 1
|
|
919
|
+
},
|
|
920
|
+
rgb: {
|
|
921
|
+
r: 46,
|
|
922
|
+
g: 163,
|
|
923
|
+
b: 227,
|
|
924
|
+
a: 1
|
|
925
|
+
},
|
|
926
|
+
source: "hex"
|
|
927
|
+
};
|
|
928
|
+
function ColorInput(props) {
|
|
929
|
+
let $ = c(10), { onChange, readOnly } = props, _value = props.value, [value, setColorOptimistic] = useOptimistic(_value), type = props.schemaType, focusRef = useRef(null), t0;
|
|
930
|
+
$[0] !== onChange || $[1] !== type ? (t0 = function(nextColor) {
|
|
931
|
+
let fieldPatches = type.fields.filter((field) => field.name in nextColor).map((field_0) => {
|
|
932
|
+
let nextFieldValue = nextColor[field_0.name];
|
|
933
|
+
return set(field_0.type.jsonType === "object" ? Object.assign({ _type: field_0.type.name }, nextFieldValue) : nextFieldValue, [field_0.name]);
|
|
934
|
+
});
|
|
935
|
+
onChange([
|
|
936
|
+
setIfMissing({ _type: type.name }),
|
|
937
|
+
set(type.name, ["_type"]),
|
|
938
|
+
set(nextColor.rgb?.a, ["alpha"]),
|
|
939
|
+
...fieldPatches
|
|
940
|
+
]);
|
|
941
|
+
}, $[0] = onChange, $[1] = type, $[2] = t0) : t0 = $[2];
|
|
942
|
+
let handleChange = t0, t1;
|
|
943
|
+
return $[3] !== handleChange || $[4] !== onChange || $[5] !== readOnly || $[6] !== setColorOptimistic || $[7] !== type || $[8] !== value ? (t1 = /* @__PURE__ */ jsx(Fragment, { children: value && value.hex ? /* @__PURE__ */ jsx(ColorPicker, {
|
|
944
|
+
color: value,
|
|
945
|
+
onChange: (nextColor_0) => startTransition(() => {
|
|
946
|
+
setColorOptimistic(nextColor_0), handleChange(nextColor_0);
|
|
947
|
+
}),
|
|
948
|
+
readOnly: readOnly || typeof type.readOnly == "boolean" && type.readOnly,
|
|
949
|
+
disableAlpha: !!type.options?.disableAlpha,
|
|
950
|
+
colorList: type.options?.colorList,
|
|
951
|
+
onUnset: () => startTransition(() => {
|
|
952
|
+
setColorOptimistic(void 0), onChange(unset());
|
|
953
|
+
})
|
|
954
|
+
}) : /* @__PURE__ */ jsx(Button, {
|
|
955
|
+
icon: AddIcon,
|
|
956
|
+
mode: "ghost",
|
|
957
|
+
text: "Create color",
|
|
958
|
+
ref: focusRef,
|
|
959
|
+
disabled: !!readOnly,
|
|
960
|
+
onClick: () => startTransition(() => {
|
|
961
|
+
setColorOptimistic(DEFAULT_COLOR), handleChange(DEFAULT_COLOR);
|
|
962
|
+
})
|
|
963
|
+
}) }), $[3] = handleChange, $[4] = onChange, $[5] = readOnly, $[6] = setColorOptimistic, $[7] = type, $[8] = value, $[9] = t1) : t1 = $[9], t1;
|
|
964
|
+
}
|
|
965
|
+
export { ColorInput as default };
|
|
966
|
+
|
|
967
|
+
//# sourceMappingURL=ColorInput.js.map
|