@jcsoftdev/ui 0.7.1 → 0.8.0
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/CHANGELOG.md +32 -0
- package/README.md +3 -0
- package/dist/atoms/elapsed-time/elapsed-time.d.ts +29 -0
- package/dist/atoms/elapsed-time/elapsed-time.js +65 -0
- package/dist/atoms/elapsed-time/index.d.ts +2 -0
- package/dist/atoms/elapsed-time/index.js +9 -0
- package/dist/atoms/elapsed-time/model.d.ts +17 -0
- package/dist/atoms/elapsed-time/model.js +37 -0
- package/dist/atoms/elapsed-time/ticker.d.ts +5 -0
- package/dist/atoms/elapsed-time/ticker.js +37 -0
- package/dist/atoms/index.d.ts +2 -0
- package/dist/atoms/index.js +2 -0
- package/dist/atoms/table-glyph/index.d.ts +2 -0
- package/dist/atoms/table-glyph/index.js +14 -0
- package/dist/atoms/table-glyph/layout.d.ts +38 -0
- package/dist/atoms/table-glyph/layout.js +152 -0
- package/dist/atoms/table-glyph/table-glyph.d.ts +32 -0
- package/dist/atoms/table-glyph/table-glyph.js +131 -0
- package/dist/containers/floor-plan/edit-model.d.ts +33 -0
- package/dist/containers/floor-plan/edit-model.js +82 -0
- package/dist/containers/floor-plan/floor-plan.d.ts +83 -0
- package/dist/containers/floor-plan/floor-plan.js +278 -0
- package/dist/containers/floor-plan/index.d.ts +3 -0
- package/dist/containers/floor-plan/index.js +21 -0
- package/dist/containers/floor-plan/model.d.ts +36 -0
- package/dist/containers/floor-plan/model.js +52 -0
- package/dist/containers/floor-plan/use-floor-plan-edit.d.ts +26 -0
- package/dist/containers/floor-plan/use-floor-plan-edit.js +97 -0
- package/dist/containers/index.d.ts +1 -0
- package/dist/containers/index.js +1 -0
- package/dist/i18n/strings.d.ts +44 -0
- package/dist/i18n/strings.js +22 -0
- package/package.json +2 -2
- package/src/atoms/elapsed-time/elapsed-time.tsx +101 -0
- package/src/atoms/elapsed-time/index.ts +6 -0
- package/src/atoms/elapsed-time/model.ts +54 -0
- package/src/atoms/elapsed-time/ticker.ts +39 -0
- package/src/atoms/index.ts +2 -0
- package/src/atoms/table-glyph/index.ts +14 -0
- package/src/atoms/table-glyph/layout.ts +187 -0
- package/src/atoms/table-glyph/table-glyph.tsx +161 -0
- package/src/containers/floor-plan/edit-model.ts +115 -0
- package/src/containers/floor-plan/floor-plan.tsx +393 -0
- package/src/containers/floor-plan/index.ts +20 -0
- package/src/containers/floor-plan/model.ts +81 -0
- package/src/containers/floor-plan/use-floor-plan-edit.ts +135 -0
- package/src/containers/index.ts +1 -0
- package/src/i18n/strings.ts +44 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { TableShape } from "../../atoms/table-glyph/layout.js";
|
|
2
|
+
|
|
3
|
+
export interface Box {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface FloorPlanBox extends Box {
|
|
11
|
+
id: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type LabelPlacement = "inside" | "below";
|
|
15
|
+
|
|
16
|
+
export const DEFAULT_PX_PER_UNIT = 32;
|
|
17
|
+
const CHAIR_BAND = 0.24;
|
|
18
|
+
const MIN_INSIDE_WIDTH = 44;
|
|
19
|
+
const MIN_INSIDE_HEIGHT = 30;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Whether an item's label fits inside the table body. The usable area is the box minus the chair
|
|
23
|
+
* band (and a round body only offers its inscribed square), measured in pixels from the canvas
|
|
24
|
+
* scale; anything smaller puts the label under the shape.
|
|
25
|
+
*/
|
|
26
|
+
export function labelPlacement(
|
|
27
|
+
item: { width: number; height: number; shape: TableShape },
|
|
28
|
+
pxPerUnit: number = DEFAULT_PX_PER_UNIT,
|
|
29
|
+
): LabelPlacement {
|
|
30
|
+
if (item.shape === "bar") return "below";
|
|
31
|
+
const usable = (units: number) => units * pxPerUnit * (1 - 2 * CHAIR_BAND);
|
|
32
|
+
const round = item.shape === "round" ? Math.SQRT1_2 : 1;
|
|
33
|
+
const fits =
|
|
34
|
+
usable(item.width) * round >= MIN_INSIDE_WIDTH &&
|
|
35
|
+
usable(item.height) * round >= MIN_INSIDE_HEIGHT;
|
|
36
|
+
return fits ? "inside" : "below";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function percentBox(box: Box, width: number, height: number) {
|
|
40
|
+
return {
|
|
41
|
+
left: `${(box.x / width) * 100}%`,
|
|
42
|
+
top: `${(box.y / height) * 100}%`,
|
|
43
|
+
width: `${(box.width / width) * 100}%`,
|
|
44
|
+
height: `${(box.height / height) * 100}%`,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface GroupOutline extends Box {
|
|
49
|
+
groupId: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const GROUP_PADDING = 0.2;
|
|
53
|
+
|
|
54
|
+
/** One outline per `groupId` shared by at least two items: their union box plus a small padding. */
|
|
55
|
+
export function groupOutlines(
|
|
56
|
+
items: ReadonlyArray<Box & { groupId?: string | undefined }>,
|
|
57
|
+
): GroupOutline[] {
|
|
58
|
+
const groups = new Map<string, Box[]>();
|
|
59
|
+
for (const item of items) {
|
|
60
|
+
if (item.groupId === undefined) continue;
|
|
61
|
+
const list = groups.get(item.groupId) ?? [];
|
|
62
|
+
list.push(item);
|
|
63
|
+
groups.set(item.groupId, list);
|
|
64
|
+
}
|
|
65
|
+
const outlines: GroupOutline[] = [];
|
|
66
|
+
for (const [groupId, members] of groups) {
|
|
67
|
+
if (members.length < 2) continue;
|
|
68
|
+
const left = Math.min(...members.map((m) => m.x));
|
|
69
|
+
const top = Math.min(...members.map((m) => m.y));
|
|
70
|
+
const right = Math.max(...members.map((m) => m.x + m.width));
|
|
71
|
+
const bottom = Math.max(...members.map((m) => m.y + m.height));
|
|
72
|
+
outlines.push({
|
|
73
|
+
groupId,
|
|
74
|
+
x: left - GROUP_PADDING,
|
|
75
|
+
y: top - GROUP_PADDING,
|
|
76
|
+
width: right - left + 2 * GROUP_PADDING,
|
|
77
|
+
height: bottom - top + 2 * GROUP_PADDING,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return outlines;
|
|
81
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { type PointerEvent, type RefObject, useRef, useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
type EditBounds,
|
|
4
|
+
editKey,
|
|
5
|
+
moveBox,
|
|
6
|
+
type ResizeHandle,
|
|
7
|
+
resizeBox,
|
|
8
|
+
sameBox,
|
|
9
|
+
} from "./edit-model.js";
|
|
10
|
+
import type { Box, FloorPlanBox } from "./model.js";
|
|
11
|
+
|
|
12
|
+
type DragMode = "move" | ResizeHandle;
|
|
13
|
+
|
|
14
|
+
interface Drag {
|
|
15
|
+
id: string;
|
|
16
|
+
mode: DragMode;
|
|
17
|
+
startX: number;
|
|
18
|
+
startY: number;
|
|
19
|
+
origin: Box;
|
|
20
|
+
unit: number;
|
|
21
|
+
moved: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const DRAG_THRESHOLD_PX = 3;
|
|
25
|
+
|
|
26
|
+
function capturePointer(element: HTMLElement, pointerId: number): boolean {
|
|
27
|
+
try {
|
|
28
|
+
element.setPointerCapture(pointerId);
|
|
29
|
+
return true;
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const pick = ({ x, y, width, height }: Box): Box => ({ x, y, width, height });
|
|
36
|
+
|
|
37
|
+
interface Options<I extends FloorPlanBox, L extends FloorPlanBox> {
|
|
38
|
+
enabled: boolean;
|
|
39
|
+
items: readonly I[];
|
|
40
|
+
landmarks: readonly L[];
|
|
41
|
+
bounds: EditBounds;
|
|
42
|
+
canvasRef: RefObject<HTMLElement | null>;
|
|
43
|
+
onChange?: ((items: I[], landmarks: L[]) => void) | undefined;
|
|
44
|
+
onSelect?: ((id: string) => void) | undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Drag, resize, rotate and keyboard edits of floor plan boxes; commits only on release, never mid-drag. */
|
|
48
|
+
export function useFloorPlanEdit<I extends FloorPlanBox, L extends FloorPlanBox>({
|
|
49
|
+
enabled,
|
|
50
|
+
items,
|
|
51
|
+
landmarks,
|
|
52
|
+
bounds,
|
|
53
|
+
canvasRef,
|
|
54
|
+
onChange,
|
|
55
|
+
onSelect,
|
|
56
|
+
}: Options<I, L>) {
|
|
57
|
+
const [draft, setDraft] = useState<{ id: string; box: Box } | null>(null);
|
|
58
|
+
const drag = useRef<Drag | null>(null);
|
|
59
|
+
|
|
60
|
+
const view = <T extends FloorPlanBox>(entry: T): T =>
|
|
61
|
+
draft?.id === entry.id ? { ...entry, ...draft.box } : entry;
|
|
62
|
+
|
|
63
|
+
const commit = (id: string, box: Box) => {
|
|
64
|
+
const current = [...items, ...landmarks].find((entry) => entry.id === id);
|
|
65
|
+
if (!current || sameBox(pick(current), box)) return;
|
|
66
|
+
const apply = <T extends FloorPlanBox>(list: readonly T[]): T[] =>
|
|
67
|
+
list.map((entry) => (entry.id === id ? { ...entry, ...box } : entry));
|
|
68
|
+
onChange?.(apply(items), apply(landmarks));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const dragProps = (entry: FloorPlanBox, mode: DragMode) => ({
|
|
72
|
+
onPointerDown: (event: PointerEvent<HTMLElement>) => {
|
|
73
|
+
if (!enabled || event.button !== 0) return;
|
|
74
|
+
const canvas = canvasRef.current;
|
|
75
|
+
if (!canvas) return;
|
|
76
|
+
event.stopPropagation();
|
|
77
|
+
capturePointer(event.currentTarget, event.pointerId);
|
|
78
|
+
drag.current = {
|
|
79
|
+
id: entry.id,
|
|
80
|
+
mode,
|
|
81
|
+
startX: event.clientX,
|
|
82
|
+
startY: event.clientY,
|
|
83
|
+
origin: pick(entry),
|
|
84
|
+
unit: canvas.getBoundingClientRect().width / bounds.width,
|
|
85
|
+
moved: false,
|
|
86
|
+
};
|
|
87
|
+
onSelect?.(entry.id);
|
|
88
|
+
},
|
|
89
|
+
onPointerMove: (event: PointerEvent<HTMLElement>) => {
|
|
90
|
+
const current = drag.current;
|
|
91
|
+
if (!current || current.id !== entry.id) return;
|
|
92
|
+
const px = Math.hypot(event.clientX - current.startX, event.clientY - current.startY);
|
|
93
|
+
if (!current.moved && px < DRAG_THRESHOLD_PX) return;
|
|
94
|
+
current.moved = true;
|
|
95
|
+
const dx = (event.clientX - current.startX) / current.unit;
|
|
96
|
+
const dy = (event.clientY - current.startY) / current.unit;
|
|
97
|
+
const box =
|
|
98
|
+
current.mode === "move"
|
|
99
|
+
? moveBox(current.origin, dx, dy, bounds)
|
|
100
|
+
: resizeBox(current.origin, current.mode, dx, dy, bounds);
|
|
101
|
+
setDraft((previous) =>
|
|
102
|
+
previous && sameBox(previous.box, box) ? previous : { id: entry.id, box },
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
onPointerUp: (event: PointerEvent<HTMLElement>) => {
|
|
106
|
+
const current = drag.current;
|
|
107
|
+
if (!current || current.id !== entry.id) return;
|
|
108
|
+
drag.current = null;
|
|
109
|
+
if (event.currentTarget.hasPointerCapture?.(event.pointerId)) {
|
|
110
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
111
|
+
}
|
|
112
|
+
if (current.moved && draft) commit(entry.id, draft.box);
|
|
113
|
+
setDraft(null);
|
|
114
|
+
},
|
|
115
|
+
onPointerCancel: () => {
|
|
116
|
+
drag.current = null;
|
|
117
|
+
setDraft(null);
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const onKeyDown = (entry: FloorPlanBox) => (event: React.KeyboardEvent<HTMLElement>) => {
|
|
122
|
+
if (!enabled) return;
|
|
123
|
+
const result = editKey(pick(entry), event, bounds);
|
|
124
|
+
if (!result) return;
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
commit(entry.id, result.box);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const rotate = (entry: FloorPlanBox) => {
|
|
130
|
+
const result = editKey(pick(entry), { key: "r", altKey: false, shiftKey: false }, bounds);
|
|
131
|
+
if (result) commit(entry.id, result.box);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return { view, dragProps, onKeyDown, rotate };
|
|
135
|
+
}
|
package/src/containers/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * from "./facts/index.js";
|
|
|
17
17
|
export * from "./feed/index.js";
|
|
18
18
|
export * from "./file-tree/index.js";
|
|
19
19
|
export * from "./filter-bar/index.js";
|
|
20
|
+
export * from "./floor-plan/index.js";
|
|
20
21
|
export * from "./generic-row/index.js";
|
|
21
22
|
export * from "./grid/index.js";
|
|
22
23
|
export * from "./hbars/index.js";
|
package/src/i18n/strings.ts
CHANGED
|
@@ -22,6 +22,28 @@ export interface UiStrings {
|
|
|
22
22
|
more: string;
|
|
23
23
|
/** Accessible total on the bottom bar "More" button; `{count}` is replaced. */
|
|
24
24
|
morePending: string;
|
|
25
|
+
/** Accessible text of an `ElapsedTime` at exactly one minute; `{count}` is replaced. */
|
|
26
|
+
elapsedMinutesOne: string;
|
|
27
|
+
/** Accessible text of an `ElapsedTime`; `{count}` is replaced. */
|
|
28
|
+
elapsedMinutes: string;
|
|
29
|
+
/** Visible text of an `ElapsedTime` with `format="minutes"`; `{count}` is replaced. */
|
|
30
|
+
minutesShort: string;
|
|
31
|
+
/** Accessible text of a countdown `ElapsedTime`; `{time}` is the remaining time. */
|
|
32
|
+
countdownLeft: string;
|
|
33
|
+
/** Accessible text of a countdown `ElapsedTime` past its target; `{time}` is the overrun. */
|
|
34
|
+
countdownOver: string;
|
|
35
|
+
/** Seat count of a floor plan table; `{count}` is replaced. */
|
|
36
|
+
seats: string;
|
|
37
|
+
/** Seat count of a one-seat floor plan table; `{count}` is replaced. */
|
|
38
|
+
seatsOne: string;
|
|
39
|
+
/** Screen-reader state of a floor plan item ringed as late. */
|
|
40
|
+
late: string;
|
|
41
|
+
/** Default accessible name of a `FloorPlan`. */
|
|
42
|
+
floorPlan: string;
|
|
43
|
+
/** Accessible name of the rotate button of an editable `FloorPlan` item. */
|
|
44
|
+
rotate: string;
|
|
45
|
+
/** Keyboard help of an editable `FloorPlan`. */
|
|
46
|
+
floorPlanEditHint: string;
|
|
25
47
|
remove: string;
|
|
26
48
|
noResults: string;
|
|
27
49
|
clear: string;
|
|
@@ -162,6 +184,17 @@ export const uiStrings = {
|
|
|
162
184
|
copied: "Copied",
|
|
163
185
|
more: "More",
|
|
164
186
|
morePending: "{count} pending",
|
|
187
|
+
elapsedMinutesOne: "{count} minute",
|
|
188
|
+
elapsedMinutes: "{count} minutes",
|
|
189
|
+
minutesShort: "{count} min",
|
|
190
|
+
countdownLeft: "{time} left",
|
|
191
|
+
countdownOver: "{time} over",
|
|
192
|
+
seats: "{count} seats",
|
|
193
|
+
seatsOne: "{count} seat",
|
|
194
|
+
late: "Late",
|
|
195
|
+
floorPlan: "Floor plan",
|
|
196
|
+
rotate: "Rotate 90°",
|
|
197
|
+
floorPlanEditHint: "Alt with arrows moves, Alt and Shift with arrows resizes, R rotates.",
|
|
165
198
|
remove: "Remove",
|
|
166
199
|
noResults: "No results",
|
|
167
200
|
clear: "Clear",
|
|
@@ -252,6 +285,17 @@ export const uiStrings = {
|
|
|
252
285
|
copied: "Copiado",
|
|
253
286
|
more: "Más",
|
|
254
287
|
morePending: "{count} pendientes",
|
|
288
|
+
elapsedMinutesOne: "{count} minuto",
|
|
289
|
+
elapsedMinutes: "{count} minutos",
|
|
290
|
+
minutesShort: "{count} min",
|
|
291
|
+
countdownLeft: "faltan {time}",
|
|
292
|
+
countdownOver: "{time} de retraso",
|
|
293
|
+
seats: "{count} asientos",
|
|
294
|
+
seatsOne: "{count} asiento",
|
|
295
|
+
late: "Con retraso",
|
|
296
|
+
floorPlan: "Plano de sala",
|
|
297
|
+
rotate: "Girar 90°",
|
|
298
|
+
floorPlanEditHint: "Alt con flechas mueve, Alt y Mayús con flechas cambia el tamaño, R gira.",
|
|
255
299
|
remove: "Quitar",
|
|
256
300
|
noResults: "Sin resultados",
|
|
257
301
|
clear: "Limpiar",
|