Skip to content

refactor: code cleanup pass#27

Merged
u8array merged 8 commits into
mainfrom
refactor/cleanup
May 7, 2026
Merged

refactor: code cleanup pass#27
u8array merged 8 commits into
mainfrom
refactor/cleanup

Conversation

@u8array
Copy link
Copy Markdown
Owner

@u8array u8array commented May 7, 2026

No description provided.

u8array added 4 commits May 7, 2026 23:27
text.tsx and serial.tsx were the last two registries duplicating the
rotation-select markup inline (label + select with 4 hardcoded options).
Every other rotation-using registry already routes through the shared
RotationSelect component, which centralises the t.registry.text.rotation*
locale-key reuse so the cross-block access lives in one well-named place
instead of being spread across two more files.
Adds a non-reactive sibling to useCurrentObjects so event handlers and
callbacks no longer have to spell out
`currentObjects(useLabelStore.getState())` every time. Replaces the
verbose form in useGlobalShortcuts, useCanvasLasso,
useKonvaTransformer, and the one-shot site in LabelCanvas. The
remaining LabelCanvas call sites that share a state snapshot across
multiple reads keep using `currentObjects(state)` directly, which
preserves the snapshot-consistency intent.
…number

ObjectTypeDefinition's P generic already defaults to `object`, so the
Record value type can simply be `ObjectTypeDefinition` without any
explicit `any` and the eslint-disable comment that came with it.

The bare `< 10` guard in useKonvaTransformer.boundBoxFunc becomes
MIN_RESIZE_BOX_PX with a comment explaining why we ignore newer boxes
that small (the user flicked past the object — keep the previous box
rather than collapsing it).
text.tsx and serial.tsx had identical label+number-input markup for
their fontHeight/fontWidth pairs. Extracts a NumberInput component into
components/Properties/ that wraps the labelCls/inputCls layout and
applies clampMin when a min is set, so registry panels stop hand-rolling
the same boilerplate. Other registries can migrate their bare
`<input type="number">` usages to this primitive incrementally — out
of scope for this commit, which only consolidates the duplicated pair.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a getCurrentObjects helper for non-reactive state access and refactors several components to use it. It also centralizes property inputs by creating a new NumberInput component and utilizing RotationSelect in the serial and text registries. A critical bug was identified in LabelCanvas.tsx where the removal of a variable used in subsequent logic would cause a ReferenceError.

Comment thread src/components/Canvas/LabelCanvas.tsx Outdated
u8array added 3 commits May 7, 2026 23:42
CI surfaced two issues from the cleanup pass that local `tsc --noEmit`
missed because it ran against the looser root config:

1) Dropping the explicit `<any>` from ObjectTypeDefinition triggers
   function-parameter contravariance under tsconfig.app.json strict —
   ObjectTypeDefinition<EllipseProps>.toZPL is not assignable to one
   that takes `object`. Restore the `<any>` with a comment explaining
   why the eslint-disable is necessary.

2) The handleStageDragMove cleanup that switched to
   getCurrentObjects().find(...) accidentally dropped the `objs`
   binding still used a few lines later. Re-introduce the local.
Sweeps the bare `<input type="number">` patterns in barcode1d, code128,
code39, ean13, qrcode, datamatrix, aztec, pdf417, micropdf417, codablock
to the shared NumberInput component. Each migration removes the
hand-rolled label+input wrapper and the duplicate
`Number(e.target.value)` plumbing, picking up clampMin sanitisation
where a `min` is set.
…erial extras

Sweeps the remaining number inputs onto the shared NumberInput
primitive: box/ellipse/circle/line shape registries (which were already
on clampMin inline) plus gs1databar moduleWidth, text blockWidth/
blockLines/blockLineSpacing, and serial increment. Image widthDots
keeps its custom step={8} handler; gs1databar segments keeps its even-
snapping logic. The simple 1D barcodes (ean8, upca, upce, code93, etc.)
already route through barcode1d so they pick up the change for free.
@u8array
Copy link
Copy Markdown
Owner Author

u8array commented May 7, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new NumberInput component to centralize number input logic, including clamping and sanitization, and refactors various registry components to use it. It also adds a non-reactive getCurrentObjects helper to the label store and a MIN_RESIZE_BOX_PX constant to the Konva transformer hook. Feedback was provided regarding the NumberInput component, specifically that its onChange handler should enforce the max constraint and guard against NaN values to prevent invalid state updates.

Comment thread src/components/Properties/NumberInput.tsx
Gemini surfaced two corner cases in the NumberInput change handler:
`max` was only an HTML hint, so the state could exceed it via paste/
keyboard, and a non-numeric paste with no `min` set would push NaN
into the model. Tightens the handler so neither leaks into the store.
@u8array u8array merged commit 3bdf433 into main May 7, 2026
2 checks passed
@u8array u8array deleted the refactor/cleanup branch May 7, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant