Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions src/components/Canvas/BarcodeObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { Image as KImage, Group, Rect, Text } from "react-konva";
import type Konva from "konva";
import { BARCODE_1D_TYPES, ObjectRegistry } from "../../registry";
import { dotsToPx, pxToDots } from "../../lib/coordinates";
import type { KonvaObjectProps } from "./konvaObjectProps";
import { useColorScheme } from "../../lib/useColorScheme";
import { selectionHandlers, type KonvaObjectProps } from "./konvaObjectProps";
import {
buildBwipOptions,
getDisplaySize,
Expand Down Expand Up @@ -36,6 +37,7 @@ export function BarcodeObject({
}: KonvaObjectProps) {
const groupRef = useRef<Konva.Group>(null);
const textRef = useRef<Konva.Text>(null);
const colors = useColorScheme();

// Exclude the HRI text from the parent Group's getClientRect. This anchors
// the resize at the bar top (logmars: was anchoring at text top above bars)
Expand Down Expand Up @@ -415,10 +417,7 @@ export function BarcodeObject({
clipWidth={Math.max(w, 1) + clipLeft + clipRight}
clipHeight={Math.max(h, 1) + textFontSize + textGap}
draggable
onClick={(e) =>
onSelect(e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey)
}
onTap={() => onSelect(false)}
{...selectionHandlers(onSelect)}
onDragMove={(e) =>
e.target.position(snapPos(e.target.x(), e.target.y()))
}
Expand All @@ -432,7 +431,7 @@ export function BarcodeObject({
width={bw}
height={bh}
imageSmoothingEnabled={false}
stroke={isSelected ? "#6366f1" : undefined}
stroke={isSelected ? colors.selection : undefined}
strokeWidth={isSelected ? 2 : 0}
strokeScaleEnabled={false}
/>
Expand Down Expand Up @@ -508,10 +507,7 @@ export function BarcodeObject({
x={x}
y={y}
draggable
onClick={(e) =>
onSelect(e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey)
}
onTap={() => onSelect(false)}
{...selectionHandlers(onSelect)}
onDragMove={(e) =>
e.target.position(snapPos(e.target.x(), e.target.y()))
}
Expand Down Expand Up @@ -540,7 +536,7 @@ export function BarcodeObject({
width={bw}
height={bh}
imageSmoothingEnabled={false}
stroke={isSelected ? "#6366f1" : undefined}
stroke={isSelected ? colors.selection : undefined}
strokeWidth={isSelected ? 2 : 0}
strokeScaleEnabled={false}
/>
Expand Down Expand Up @@ -685,8 +681,7 @@ export function BarcodeObject({
return (
<Group
id={obj.id} x={x} y={y} draggable
onClick={(e) => onSelect(e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey)}
onTap={() => onSelect(false)}
{...selectionHandlers(onSelect)}
onDragMove={(e) => e.target.position(snapPos(e.target.x(), e.target.y()))}
onDragEnd={handleDragEnd}
>
Expand All @@ -702,7 +697,7 @@ export function BarcodeObject({
<KImage x={btX} y={btY} image={barcodeCanvas} crop={bitmapCrop}
width={bw} height={bh}
imageSmoothingEnabled={false}
stroke={isSelected ? "#6366f1" : undefined}
stroke={isSelected ? colors.selection : undefined}
strokeWidth={isSelected ? 2 : 0}
strokeScaleEnabled={false}
/>
Expand All @@ -722,10 +717,7 @@ export function BarcodeObject({
x={x}
y={y}
draggable
onClick={(e) =>
onSelect(e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey)
}
onTap={() => onSelect(false)}
{...selectionHandlers(onSelect)}
onDragMove={handleDragMove}
onDragEnd={handleDragEnd}
>
Expand All @@ -745,7 +737,7 @@ export function BarcodeObject({
width={bw}
height={bh}
imageSmoothingEnabled={false}
stroke={isSelected ? "#6366f1" : undefined}
stroke={isSelected ? colors.selection : undefined}
strokeWidth={isSelected ? 2 : 0}
strokeScaleEnabled={false}
/>
Expand All @@ -762,18 +754,15 @@ export function BarcodeObject({
x={x}
y={y}
draggable
onClick={(e) =>
onSelect(e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey)
}
onTap={() => onSelect(false)}
{...selectionHandlers(onSelect)}
onDragMove={handleDragMove}
onDragEnd={handleDragEnd}
>
<Rect
width={fbW}
height={fbH}
fill="#f9fafb"
stroke={isSelected ? "#6366f1" : "#9ca3af"}
stroke={isSelected ? colors.selection : "#9ca3af"}
strokeWidth={isSelected ? 2 : 1}
dash={isSelected ? undefined : [4, 2]}
/>
Expand Down
18 changes: 7 additions & 11 deletions src/components/Canvas/ImageObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type Konva from "konva";
import type { LabelObject } from "../../registry";
import { dotsToPx, pxToDots } from "../../lib/coordinates";
import { getImage } from "../../lib/imageCache";
import type { KonvaObjectProps } from "./konvaObjectProps";
import { useColorScheme } from "../../lib/useColorScheme";
import { selectionHandlers, type KonvaObjectProps } from "./konvaObjectProps";

type ImageLabelObject = Extract<LabelObject, { type: "image" }>;
type Props = Omit<KonvaObjectProps, "obj"> & { obj: ImageLabelObject };
Expand All @@ -25,6 +26,7 @@ export function ImageObject({
snap,
}: Props) {
const p = obj.props;
const colors = useColorScheme();
const cached = getImage(p.imageId);
const w = dotsToPx(p.widthDots, scale, dpmm);
// Guard against a 0-width cached image: the imageCache pipeline
Expand Down Expand Up @@ -90,13 +92,10 @@ export function ImageObject({
image={htmlImg}
width={w}
height={h}
stroke={isSelected ? "#6366f1" : undefined}
stroke={isSelected ? colors.selection : undefined}
strokeWidth={isSelected ? 2 : 0}
draggable
onClick={(e) =>
onSelect(e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey)
}
onTap={() => onSelect(false)}
{...selectionHandlers(onSelect)}
onDragMove={handleDragMove}
onDragEnd={handleDragEnd}
/>
Expand All @@ -109,18 +108,15 @@ export function ImageObject({
x={x}
y={y}
draggable
onClick={(e) =>
onSelect(e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey)
}
onTap={() => onSelect(false)}
{...selectionHandlers(onSelect)}
onDragMove={handleDragMove}
onDragEnd={handleDragEnd}
>
<Rect
width={w}
height={h}
fill="#f9fafb"
stroke={isSelected ? "#6366f1" : "#9ca3af"}
stroke={isSelected ? colors.selection : "#9ca3af"}
strokeWidth={isSelected ? 2 : 1}
dash={[4, 2]}
/>
Expand Down
Loading