Mayo commited on
Commit
3cd559b
·
unverified ·
1 Parent(s): d61e0c7

fix: black color not apply

Browse files
ui/components/panels/RenderControlsPanel.tsx CHANGED
@@ -126,6 +126,8 @@ const predictionColor = (prediction?: FontPrediction | null): number[] | undefin
126
  const effectiveColorOf = (style?: TextStyle | null, prediction?: FontPrediction | null): number[] =>
127
  style?.color ?? predictionColor(prediction) ?? DEFAULT_COLOR
128
 
 
 
129
  export function RenderControlsPanel() {
130
  const { t } = useTranslation()
131
  const page = useCurrentPage()
@@ -239,6 +241,12 @@ export function RenderControlsPanel() {
239
  applyStyleToNodes(textNodes, updates, 'Bulk style update')
240
  }
241
 
 
 
 
 
 
 
242
  const applyStrokeSetting = (nextStroke: TextStrokeStyle) => {
243
  if (applyStyleToSelected({ stroke: normalizeStroke(nextStroke) })) return
244
  setRenderStroke({
@@ -336,6 +344,9 @@ export function RenderControlsPanel() {
336
  swatchTestId='render-color-swatch'
337
  inputTestId='render-color-input'
338
  pickButtonTestId='render-color-pick'
 
 
 
339
  onChange={(hex) => {
340
  const nextColor = hexToColor(hex, currentColor[3] ?? 255)
341
  if (applyStyleToSelected({ color: nextColor })) return
 
126
  const effectiveColorOf = (style?: TextStyle | null, prediction?: FontPrediction | null): number[] =>
127
  style?.color ?? predictionColor(prediction) ?? DEFAULT_COLOR
128
 
129
+ const hasExplicitColor = (node: TextNodeEntry) => Array.isArray(node.data.style?.color)
130
+
131
  export function RenderControlsPanel() {
132
  const { t } = useTranslation()
133
  const page = useCurrentPage()
 
241
  applyStyleToNodes(textNodes, updates, 'Bulk style update')
242
  }
243
 
244
+ const commitCurrentFontColorIfImplicit = () => {
245
+ const targets = selectedNodes.length > 0 ? selectedNodes : textNodes
246
+ if (targets.every(hasExplicitColor)) return
247
+ applyStyleToNodes(targets, { color: currentColor }, 'Explicit font color update')
248
+ }
249
+
250
  const applyStrokeSetting = (nextStroke: TextStrokeStyle) => {
251
  if (applyStyleToSelected({ stroke: normalizeStroke(nextStroke) })) return
252
  setRenderStroke({
 
344
  swatchTestId='render-color-swatch'
345
  inputTestId='render-color-input'
346
  pickButtonTestId='render-color-pick'
347
+ onOpenChange={(open) => {
348
+ if (open) commitCurrentFontColorIfImplicit()
349
+ }}
350
  onChange={(hex) => {
351
  const nextColor = hexToColor(hex, currentColor[3] ?? 255)
352
  if (applyStyleToSelected({ color: nextColor })) return
ui/components/ui/color-picker.tsx CHANGED
@@ -10,6 +10,7 @@ import { cn } from '@/lib/utils'
10
  type ColorPickerProps = {
11
  value: string
12
  onChange: (color: string) => void
 
13
  disabled?: boolean
14
  className?: string
15
  triggerTestId?: string
@@ -35,6 +36,7 @@ const normalizeHex = (value: string) => {
35
  export function ColorPicker({
36
  value,
37
  onChange,
 
38
  disabled,
39
  className,
40
  triggerTestId,
@@ -81,7 +83,7 @@ export function ColorPicker({
81
  }
82
 
83
  return (
84
- <Popover>
85
  <PopoverTrigger asChild>
86
  <button
87
  data-testid={triggerTestId}
 
10
  type ColorPickerProps = {
11
  value: string
12
  onChange: (color: string) => void
13
+ onOpenChange?: (open: boolean) => void
14
  disabled?: boolean
15
  className?: string
16
  triggerTestId?: string
 
36
  export function ColorPicker({
37
  value,
38
  onChange,
39
+ onOpenChange,
40
  disabled,
41
  className,
42
  triggerTestId,
 
83
  }
84
 
85
  return (
86
+ <Popover onOpenChange={onOpenChange}>
87
  <PopoverTrigger asChild>
88
  <button
89
  data-testid={triggerTestId}
ui/tests/components/RenderControlsPanel.test.tsx CHANGED
@@ -169,4 +169,34 @@ describe('RenderControlsPanel Font Assignment', () => {
169
  await waitFor(() => expect(input.value).toBe(''))
170
  expect(input).toHaveAttribute('placeholder', 'auto')
171
  })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  })
 
169
  await waitFor(() => expect(input.value).toBe(''))
170
  expect(input).toHaveAttribute('placeholder', 'auto')
171
  })
172
+
173
+ it('opening the font color picker commits effective black as an explicit color', async () => {
174
+ server.use(
175
+ http.get('/api/v1/scene.json', () =>
176
+ HttpResponse.json(
177
+ sceneWithTextNodes([
178
+ {
179
+ id: 't1',
180
+ kind: {
181
+ text: {
182
+ fontPrediction: { fontSizePx: 66, strokeWidthPx: 0, textColor: [0, 0, 0] },
183
+ },
184
+ },
185
+ },
186
+ ]),
187
+ ),
188
+ ),
189
+ )
190
+
191
+ renderWithQuery(<RenderControlsPanel />)
192
+ useSelectionStore.getState().select('t1', false)
193
+
194
+ const trigger = await screen.findByTestId('render-color-trigger')
195
+ await userEvent.click(trigger)
196
+
197
+ await waitFor(() => expect(sceneActions.applyOp).toHaveBeenCalled())
198
+ const op = (sceneActions.applyOp as any).mock.calls[0][0]
199
+ expect(op.updateNode.id).toBe('t1')
200
+ expect(op.updateNode.patch.data.text.style.color).toEqual([0, 0, 0, 255])
201
+ })
202
  })