@jcsoftdev/ui 0.7.0 → 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 +51 -0
- package/README.md +9 -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 +48 -0
- package/dist/i18n/strings.js +24 -0
- package/dist/shell/bottom-nav/bottom-nav.d.ts +5 -1
- package/dist/shell/bottom-nav/bottom-nav.js +52 -9
- 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 +48 -0
- package/src/shell/bottom-nav/bottom-nav.tsx +78 -8
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "../../utils/cn.js";
|
|
3
|
+
import { glyphLayout, UNIT } from "./layout.js";
|
|
4
|
+
const sizeClasses = {
|
|
5
|
+
sm: "h-control w-auto",
|
|
6
|
+
md: "h-control-lg w-auto",
|
|
7
|
+
lg: "h-[calc(var(--control-height-lg)*1.5)] w-auto",
|
|
8
|
+
fill: "size-full"
|
|
9
|
+
};
|
|
10
|
+
const patternClasses = {
|
|
11
|
+
dashed: "fill-transparent",
|
|
12
|
+
solid: "fill-surface",
|
|
13
|
+
soft: "fill-current/10",
|
|
14
|
+
strong: "fill-current/35"
|
|
15
|
+
};
|
|
16
|
+
const defaultBox = {
|
|
17
|
+
round: [1, 1],
|
|
18
|
+
square: [1, 1],
|
|
19
|
+
rect: [2, 1],
|
|
20
|
+
bar: [3, 1]
|
|
21
|
+
};
|
|
22
|
+
const STROKE = 1.5;
|
|
23
|
+
function TableGlyph({
|
|
24
|
+
shape,
|
|
25
|
+
seats,
|
|
26
|
+
occupied = 0,
|
|
27
|
+
size = "md",
|
|
28
|
+
width,
|
|
29
|
+
height,
|
|
30
|
+
pattern = "solid",
|
|
31
|
+
className,
|
|
32
|
+
classNames,
|
|
33
|
+
"aria-label": ariaLabel,
|
|
34
|
+
...props
|
|
35
|
+
}) {
|
|
36
|
+
const [defaultW, defaultH] = defaultBox[shape];
|
|
37
|
+
const w = (width ?? defaultW) * UNIT;
|
|
38
|
+
const h = (height ?? defaultH) * UNIT;
|
|
39
|
+
const layout = glyphLayout(shape, seats, w, h);
|
|
40
|
+
const filled = Math.max(0, Math.min(Math.floor(occupied), layout.chairs.length));
|
|
41
|
+
const { body } = layout;
|
|
42
|
+
const labelled = ariaLabel !== void 0;
|
|
43
|
+
return /* @__PURE__ */ jsxs(
|
|
44
|
+
"svg",
|
|
45
|
+
{
|
|
46
|
+
viewBox: `0 0 ${w} ${h}`,
|
|
47
|
+
role: labelled ? "img" : void 0,
|
|
48
|
+
"aria-label": ariaLabel,
|
|
49
|
+
"aria-hidden": labelled ? void 0 : true,
|
|
50
|
+
focusable: "false",
|
|
51
|
+
"data-shape": shape,
|
|
52
|
+
"data-seats": layout.chairs.length,
|
|
53
|
+
"data-occupied": filled,
|
|
54
|
+
"data-pattern": pattern,
|
|
55
|
+
preserveAspectRatio: "xMidYMid meet",
|
|
56
|
+
className: cn("shrink-0 text-ink-2", sizeClasses[size], classNames?.root, className),
|
|
57
|
+
...props,
|
|
58
|
+
children: [
|
|
59
|
+
body.round ? /* @__PURE__ */ jsx(
|
|
60
|
+
"circle",
|
|
61
|
+
{
|
|
62
|
+
cx: body.x + body.width / 2,
|
|
63
|
+
cy: body.y + body.height / 2,
|
|
64
|
+
r: body.width / 2,
|
|
65
|
+
"data-part": "body",
|
|
66
|
+
className: cn("stroke-current", patternClasses[pattern], classNames?.body),
|
|
67
|
+
strokeWidth: STROKE,
|
|
68
|
+
strokeDasharray: pattern === "dashed" ? "5 4" : void 0,
|
|
69
|
+
vectorEffect: "non-scaling-stroke"
|
|
70
|
+
}
|
|
71
|
+
) : /* @__PURE__ */ jsx(
|
|
72
|
+
"rect",
|
|
73
|
+
{
|
|
74
|
+
x: body.x,
|
|
75
|
+
y: body.y,
|
|
76
|
+
width: body.width,
|
|
77
|
+
height: body.height,
|
|
78
|
+
rx: 6,
|
|
79
|
+
"data-part": "body",
|
|
80
|
+
className: cn("stroke-current", patternClasses[pattern], classNames?.body),
|
|
81
|
+
strokeWidth: STROKE,
|
|
82
|
+
strokeDasharray: pattern === "dashed" ? "5 4" : void 0,
|
|
83
|
+
vectorEffect: "non-scaling-stroke"
|
|
84
|
+
}
|
|
85
|
+
),
|
|
86
|
+
layout.chairs.map((chair, index) => {
|
|
87
|
+
const taken = index < filled;
|
|
88
|
+
const chairClass = cn(
|
|
89
|
+
"stroke-current",
|
|
90
|
+
taken ? "fill-current" : "fill-surface",
|
|
91
|
+
classNames?.chair
|
|
92
|
+
);
|
|
93
|
+
const key = `${chair.cx.toFixed(2)}-${chair.cy.toFixed(2)}`;
|
|
94
|
+
return chair.circle ? /* @__PURE__ */ jsx(
|
|
95
|
+
"circle",
|
|
96
|
+
{
|
|
97
|
+
cx: chair.cx,
|
|
98
|
+
cy: chair.cy,
|
|
99
|
+
r: chair.width / 2,
|
|
100
|
+
"data-part": "chair",
|
|
101
|
+
"data-occupied": taken ? "" : void 0,
|
|
102
|
+
className: chairClass,
|
|
103
|
+
strokeWidth: STROKE,
|
|
104
|
+
vectorEffect: "non-scaling-stroke"
|
|
105
|
+
},
|
|
106
|
+
key
|
|
107
|
+
) : /* @__PURE__ */ jsx(
|
|
108
|
+
"rect",
|
|
109
|
+
{
|
|
110
|
+
x: chair.cx - chair.width / 2,
|
|
111
|
+
y: chair.cy - chair.height / 2,
|
|
112
|
+
width: chair.width,
|
|
113
|
+
height: chair.height,
|
|
114
|
+
rx: 5,
|
|
115
|
+
transform: `rotate(${chair.rotate.toFixed(2)} ${chair.cx.toFixed(2)} ${chair.cy.toFixed(2)})`,
|
|
116
|
+
"data-part": "chair",
|
|
117
|
+
"data-occupied": taken ? "" : void 0,
|
|
118
|
+
className: chairClass,
|
|
119
|
+
strokeWidth: STROKE,
|
|
120
|
+
vectorEffect: "non-scaling-stroke"
|
|
121
|
+
},
|
|
122
|
+
key
|
|
123
|
+
);
|
|
124
|
+
})
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
export {
|
|
130
|
+
TableGlyph
|
|
131
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Box } from "./model.js";
|
|
2
|
+
export type ResizeHandle = "n" | "s" | "e" | "w" | "ne" | "nw" | "se" | "sw";
|
|
3
|
+
export interface EditBounds {
|
|
4
|
+
/** Canvas size in grid units. */
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
/** Grid step positions and sizes snap to. */
|
|
8
|
+
snap: number;
|
|
9
|
+
/** Smallest width or height. */
|
|
10
|
+
minSize: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function snapTo(value: number, step: number): number;
|
|
13
|
+
/** Moves a box by a delta in grid units, snapped to the grid and kept inside the canvas. */
|
|
14
|
+
export declare function moveBox(box: Box, dx: number, dy: number, bounds: EditBounds): Box;
|
|
15
|
+
/** Resizes a box from one handle by a delta in grid units; the opposite edges stay put. */
|
|
16
|
+
export declare function resizeBox(box: Box, handle: ResizeHandle, dx: number, dy: number, bounds: EditBounds): Box;
|
|
17
|
+
/** Turns a box a quarter by swapping its width and height around its centre, snapped and kept inside the canvas. */
|
|
18
|
+
export declare function rotateBox(box: Box, bounds: EditBounds): Box;
|
|
19
|
+
export type EditKeyResult = {
|
|
20
|
+
box: Box;
|
|
21
|
+
} | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Keyboard edit of a box: Alt with an arrow nudges by one grid step, Alt and Shift with an arrow
|
|
24
|
+
* grows or shrinks the bottom-right corner, `r` turns it a quarter. Anything else is not an edit.
|
|
25
|
+
*/
|
|
26
|
+
export declare function editKey(box: Box, event: {
|
|
27
|
+
key: string;
|
|
28
|
+
altKey: boolean;
|
|
29
|
+
shiftKey: boolean;
|
|
30
|
+
ctrlKey?: boolean;
|
|
31
|
+
metaKey?: boolean;
|
|
32
|
+
}, bounds: EditBounds): EditKeyResult;
|
|
33
|
+
export declare function sameBox(a: Box, b: Box): boolean;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
function snapTo(value, step) {
|
|
2
|
+
if (step <= 0) return value;
|
|
3
|
+
return Math.round(value / step) * step;
|
|
4
|
+
}
|
|
5
|
+
const clean = (value) => Math.round(value * 1e6) / 1e6;
|
|
6
|
+
function contain(box, bounds) {
|
|
7
|
+
const width = Math.min(Math.max(box.width, bounds.minSize), bounds.width);
|
|
8
|
+
const height = Math.min(Math.max(box.height, bounds.minSize), bounds.height);
|
|
9
|
+
return {
|
|
10
|
+
x: clean(Math.min(Math.max(box.x, 0), bounds.width - width)),
|
|
11
|
+
y: clean(Math.min(Math.max(box.y, 0), bounds.height - height)),
|
|
12
|
+
width: clean(width),
|
|
13
|
+
height: clean(height)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function moveBox(box, dx, dy, bounds) {
|
|
17
|
+
return contain(
|
|
18
|
+
{ ...box, x: snapTo(box.x + dx, bounds.snap), y: snapTo(box.y + dy, bounds.snap) },
|
|
19
|
+
bounds
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
function resizeBox(box, handle, dx, dy, bounds) {
|
|
23
|
+
let left = box.x;
|
|
24
|
+
let top = box.y;
|
|
25
|
+
let right = box.x + box.width;
|
|
26
|
+
let bottom = box.y + box.height;
|
|
27
|
+
const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
28
|
+
if (handle.includes("w")) left = clamp(snapTo(left + dx, bounds.snap), 0, right - bounds.minSize);
|
|
29
|
+
if (handle.includes("e")) {
|
|
30
|
+
right = clamp(snapTo(right + dx, bounds.snap), left + bounds.minSize, bounds.width);
|
|
31
|
+
}
|
|
32
|
+
if (handle.includes("n")) top = clamp(snapTo(top + dy, bounds.snap), 0, bottom - bounds.minSize);
|
|
33
|
+
if (handle.includes("s")) {
|
|
34
|
+
bottom = clamp(snapTo(bottom + dy, bounds.snap), top + bounds.minSize, bounds.height);
|
|
35
|
+
}
|
|
36
|
+
return contain({ x: left, y: top, width: right - left, height: bottom - top }, bounds);
|
|
37
|
+
}
|
|
38
|
+
function rotateBox(box, bounds) {
|
|
39
|
+
const centerX = box.x + box.width / 2;
|
|
40
|
+
const centerY = box.y + box.height / 2;
|
|
41
|
+
return moveBox(
|
|
42
|
+
{
|
|
43
|
+
x: centerX - box.height / 2,
|
|
44
|
+
y: centerY - box.width / 2,
|
|
45
|
+
width: box.height,
|
|
46
|
+
height: box.width
|
|
47
|
+
},
|
|
48
|
+
0,
|
|
49
|
+
0,
|
|
50
|
+
bounds
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
const ARROWS = {
|
|
54
|
+
ArrowLeft: [-1, 0],
|
|
55
|
+
ArrowRight: [1, 0],
|
|
56
|
+
ArrowUp: [0, -1],
|
|
57
|
+
ArrowDown: [0, 1]
|
|
58
|
+
};
|
|
59
|
+
function editKey(box, event, bounds) {
|
|
60
|
+
if (event.ctrlKey || event.metaKey) return void 0;
|
|
61
|
+
if (!event.altKey && !event.shiftKey && event.key.toLowerCase() === "r") {
|
|
62
|
+
return { box: rotateBox(box, bounds) };
|
|
63
|
+
}
|
|
64
|
+
const arrow = ARROWS[event.key];
|
|
65
|
+
if (!arrow || !event.altKey) return void 0;
|
|
66
|
+
const dx = arrow[0] * bounds.snap;
|
|
67
|
+
const dy = arrow[1] * bounds.snap;
|
|
68
|
+
return {
|
|
69
|
+
box: event.shiftKey ? resizeBox(box, "se", dx, dy, bounds) : moveBox(box, dx, dy, bounds)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function sameBox(a, b) {
|
|
73
|
+
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
editKey,
|
|
77
|
+
moveBox,
|
|
78
|
+
resizeBox,
|
|
79
|
+
rotateBox,
|
|
80
|
+
sameBox,
|
|
81
|
+
snapTo
|
|
82
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { TableShape } from "../../atoms/table-glyph/layout.js";
|
|
3
|
+
import { type TableGlyphPattern } from "../../atoms/table-glyph/table-glyph.js";
|
|
4
|
+
import type { ClassNames } from "../../utils/class-names.js";
|
|
5
|
+
export type FloorPlanBuiltinTone = "neutral" | "accent" | "success" | "warning" | "danger" | "info";
|
|
6
|
+
/** A built-in tone, or the name of a tone declared in `tonePalettes`. */
|
|
7
|
+
export type FloorPlanTone = FloorPlanBuiltinTone | (string & {});
|
|
8
|
+
export type FloorPlanRing = "none" | "late" | "selected";
|
|
9
|
+
export interface FloorPlanItem {
|
|
10
|
+
id: string;
|
|
11
|
+
/** Position and size in grid units. */
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
shape: TableShape;
|
|
17
|
+
seats: number;
|
|
18
|
+
/** Chairs drawn as taken. */
|
|
19
|
+
occupied?: number | undefined;
|
|
20
|
+
/** Table name; always visible, inside the table or under it on small shapes. */
|
|
21
|
+
label: string;
|
|
22
|
+
/** Text of the state. Pair it with `statusIcon`: the state is never carried by colour alone. */
|
|
23
|
+
statusLabel?: string | undefined;
|
|
24
|
+
/** Decorative glyph shown before `statusLabel`. */
|
|
25
|
+
statusIcon?: ReactNode;
|
|
26
|
+
/** Colour of the table and the status glyph. Defaults to `neutral`. */
|
|
27
|
+
tone?: FloorPlanTone | undefined;
|
|
28
|
+
/** Table surface; see `TableGlyph`. Defaults to `solid`. */
|
|
29
|
+
pattern?: TableGlyphPattern | undefined;
|
|
30
|
+
/** A uniform ring around the whole item: `late` (danger) or `selected` (accent). `selectedId` wins over it. */
|
|
31
|
+
ring?: FloorPlanRing | undefined;
|
|
32
|
+
/** Items sharing a `groupId` (merged tables) get one outline around the group. */
|
|
33
|
+
groupId?: string | undefined;
|
|
34
|
+
}
|
|
35
|
+
export interface FloorPlanLandmark {
|
|
36
|
+
id: string;
|
|
37
|
+
/** What it is (`wall`, `door`, `bar`, `stairs`, `restroom`...); exposed as `data-kind`. */
|
|
38
|
+
kind: string;
|
|
39
|
+
label: string;
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
}
|
|
45
|
+
export type FloorPlanPart = "root" | "canvas" | "item" | "glyph" | "label" | "status" | "landmark" | "group" | "handle" | "rotate";
|
|
46
|
+
export interface FloorPlanProps {
|
|
47
|
+
/** Canvas size in grid units. The canvas fills its container and keeps this aspect ratio. */
|
|
48
|
+
width: number;
|
|
49
|
+
height: number;
|
|
50
|
+
items: readonly FloorPlanItem[];
|
|
51
|
+
landmarks?: readonly FloorPlanLandmark[];
|
|
52
|
+
/** Controlled selection; the item gets the selected ring and `aria-pressed`. */
|
|
53
|
+
selectedId?: string | null;
|
|
54
|
+
/** Called with the id of the item or landmark that was picked, by click, keyboard or the start of a drag. */
|
|
55
|
+
onSelect?: (id: string) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Lets people rearrange the plan: drag an item or landmark to move it, drag a corner handle of
|
|
58
|
+
* the selected one to resize, press the rotate button or `r` to turn it a quarter, Alt with an
|
|
59
|
+
* arrow to nudge and Alt and Shift with an arrow to resize. Edits snap to `snap`, stay inside the
|
|
60
|
+
* canvas and are reported through `onChange`; the plan stays controlled by `items` and `landmarks`.
|
|
61
|
+
* Edited boxes are not checked against each other, so overlaps are possible.
|
|
62
|
+
*/
|
|
63
|
+
editable?: boolean;
|
|
64
|
+
/** Receives the full lists with the edited box applied; called once per drop and once per key press. */
|
|
65
|
+
onChange?: (items: FloorPlanItem[], landmarks: FloorPlanLandmark[]) => void;
|
|
66
|
+
/** Grid step in units that positions and sizes snap to while editing. Defaults to 1. */
|
|
67
|
+
snap?: number;
|
|
68
|
+
/** Smallest width or height in units while editing. Defaults to 1. */
|
|
69
|
+
minSize?: number;
|
|
70
|
+
/** Accessible name of the plan. Defaults to the localized "Floor plan". */
|
|
71
|
+
"aria-label"?: string;
|
|
72
|
+
className?: string;
|
|
73
|
+
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root and is merged last. */
|
|
74
|
+
classNames?: ClassNames<FloorPlanPart>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A salon plan on a logical-unit canvas, read-only unless `editable`. The canvas fills its container and keeps the
|
|
78
|
+
* `width` x `height` aspect ratio, and every item is placed in percentages of it, so hit areas
|
|
79
|
+
* always match what is drawn. Items are buttons in array order with roving arrow-key focus. A
|
|
80
|
+
* state shows as an icon plus text (never colour alone), `late` and `selected` as one ring around
|
|
81
|
+
* the whole item, and the label moves under the shape when the table is too small to hold it.
|
|
82
|
+
*/
|
|
83
|
+
export declare function FloorPlan({ width, height, items, landmarks, selectedId, onSelect, editable, onChange, snap, minSize, "aria-label": ariaLabel, className, classNames, }: FloorPlanProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId, useRef } from "react";
|
|
4
|
+
import { TableGlyph } from "../../atoms/table-glyph/table-glyph.js";
|
|
5
|
+
import { useUiStrings } from "../../i18n/index.js";
|
|
6
|
+
import { RotateCcw } from "../../icons/index.js";
|
|
7
|
+
import { cn } from "../../utils/cn.js";
|
|
8
|
+
import { useComposedRefs } from "../../utils/compose.js";
|
|
9
|
+
import { useRovingFocus } from "../../utils/roving-focus.js";
|
|
10
|
+
import { customToneStyle, isCustomTone } from "../../utils/tone.js";
|
|
11
|
+
import { useContainerWidth } from "../../utils/use-container-width.js";
|
|
12
|
+
import { DEFAULT_PX_PER_UNIT, groupOutlines, labelPlacement, percentBox } from "./model.js";
|
|
13
|
+
import { useFloorPlanEdit } from "./use-floor-plan-edit.js";
|
|
14
|
+
const toneClasses = {
|
|
15
|
+
neutral: "text-ink-2",
|
|
16
|
+
accent: "text-accent",
|
|
17
|
+
success: "text-success",
|
|
18
|
+
warning: "text-warning",
|
|
19
|
+
danger: "text-danger",
|
|
20
|
+
info: "text-info"
|
|
21
|
+
};
|
|
22
|
+
const builtinTones = new Set(Object.keys(toneClasses));
|
|
23
|
+
const ringClasses = {
|
|
24
|
+
none: "",
|
|
25
|
+
late: "ring-2 ring-danger",
|
|
26
|
+
selected: "ring-2 ring-accent"
|
|
27
|
+
};
|
|
28
|
+
const HANDLES = ["nw", "ne", "sw", "se"];
|
|
29
|
+
const handleClasses = {
|
|
30
|
+
nw: "-top-1.5 -left-1.5 cursor-nwse-resize",
|
|
31
|
+
ne: "-top-1.5 -right-1.5 cursor-nesw-resize",
|
|
32
|
+
sw: "-bottom-1.5 -left-1.5 cursor-nesw-resize",
|
|
33
|
+
se: "-right-1.5 -bottom-1.5 cursor-nwse-resize"
|
|
34
|
+
};
|
|
35
|
+
const hatch = "bg-[repeating-linear-gradient(135deg,var(--line-strong)_0_1px,transparent_1px_7px)] border border-line-strong";
|
|
36
|
+
function format(template, count) {
|
|
37
|
+
return template.replace("{count}", String(count));
|
|
38
|
+
}
|
|
39
|
+
function FloorPlan({
|
|
40
|
+
width,
|
|
41
|
+
height,
|
|
42
|
+
items,
|
|
43
|
+
landmarks = [],
|
|
44
|
+
selectedId,
|
|
45
|
+
onSelect,
|
|
46
|
+
editable = false,
|
|
47
|
+
onChange,
|
|
48
|
+
snap = 1,
|
|
49
|
+
minSize = 1,
|
|
50
|
+
"aria-label": ariaLabel,
|
|
51
|
+
className,
|
|
52
|
+
classNames
|
|
53
|
+
}) {
|
|
54
|
+
const strings = useUiStrings();
|
|
55
|
+
const canvasRef = useRef(null);
|
|
56
|
+
const measured = useContainerWidth(canvasRef);
|
|
57
|
+
const pxPerUnit = measured === null ? DEFAULT_PX_PER_UNIT : measured / width;
|
|
58
|
+
const { rootProps, getItemProps } = useRovingFocus({ activeId: selectedId ?? null });
|
|
59
|
+
const rootRef = useComposedRefs(canvasRef, rootProps.ref);
|
|
60
|
+
const selectable = onSelect !== void 0 || selectedId !== void 0;
|
|
61
|
+
const hintId = useId();
|
|
62
|
+
const edit = useFloorPlanEdit({
|
|
63
|
+
enabled: editable,
|
|
64
|
+
items,
|
|
65
|
+
landmarks,
|
|
66
|
+
bounds: { width, height, snap, minSize },
|
|
67
|
+
canvasRef,
|
|
68
|
+
onChange,
|
|
69
|
+
onSelect
|
|
70
|
+
});
|
|
71
|
+
const shownItems = items.map(edit.view);
|
|
72
|
+
const shownLandmarks = landmarks.map(edit.view);
|
|
73
|
+
const outlines = groupOutlines(shownItems);
|
|
74
|
+
const selectedBox = editable ? [...shownItems, ...shownLandmarks].find((entry) => entry.id === selectedId) : void 0;
|
|
75
|
+
const selectedSource = selectedBox ? [...items, ...landmarks].find((entry) => entry.id === selectedBox.id) : void 0;
|
|
76
|
+
return /* @__PURE__ */ jsx("div", { className: cn("@container/floor w-full", classNames?.root, className), children: /* @__PURE__ */ jsxs(
|
|
77
|
+
"div",
|
|
78
|
+
{
|
|
79
|
+
...rootProps,
|
|
80
|
+
ref: rootRef,
|
|
81
|
+
role: "group",
|
|
82
|
+
"aria-label": ariaLabel ?? strings.floorPlan,
|
|
83
|
+
style: {
|
|
84
|
+
aspectRatio: `${width} / ${height}`,
|
|
85
|
+
...editable ? {
|
|
86
|
+
backgroundImage: "radial-gradient(circle, var(--line-strong) 1px, transparent 1px)",
|
|
87
|
+
backgroundSize: `${100 / width}% ${100 / height}%`
|
|
88
|
+
} : null
|
|
89
|
+
},
|
|
90
|
+
"data-editable": editable ? "" : void 0,
|
|
91
|
+
className: cn(
|
|
92
|
+
"relative w-full rounded-card border border-line bg-surface-sunken focus-visible:focus-ring",
|
|
93
|
+
classNames?.canvas
|
|
94
|
+
),
|
|
95
|
+
children: [
|
|
96
|
+
editable ? /* @__PURE__ */ jsx("p", { id: hintId, className: "sr-only", children: strings.floorPlanEditHint }) : null,
|
|
97
|
+
shownLandmarks.map((landmark) => {
|
|
98
|
+
const common = {
|
|
99
|
+
"data-kind": landmark.kind,
|
|
100
|
+
style: percentBox(landmark, width, height),
|
|
101
|
+
className: cn(
|
|
102
|
+
"absolute flex items-center justify-center overflow-hidden rounded-control p-0.5 text-center text-ink-2 text-meta",
|
|
103
|
+
hatch,
|
|
104
|
+
classNames?.landmark
|
|
105
|
+
)
|
|
106
|
+
};
|
|
107
|
+
const label = /* @__PURE__ */ jsx("span", { className: "max-w-full truncate rounded-chip bg-surface px-1", children: landmark.label });
|
|
108
|
+
if (!editable) {
|
|
109
|
+
return /* @__PURE__ */ jsx("div", { ...common, children: label }, landmark.id);
|
|
110
|
+
}
|
|
111
|
+
const selected = selectedId === landmark.id;
|
|
112
|
+
return /* @__PURE__ */ jsxs(
|
|
113
|
+
"button",
|
|
114
|
+
{
|
|
115
|
+
type: "button",
|
|
116
|
+
"data-landmark": landmark.id,
|
|
117
|
+
"aria-pressed": selectable ? selected : void 0,
|
|
118
|
+
"aria-describedby": hintId,
|
|
119
|
+
...common,
|
|
120
|
+
className: cn(
|
|
121
|
+
common.className,
|
|
122
|
+
"cursor-grab touch-none focus-visible:focus-ring active:cursor-grabbing",
|
|
123
|
+
selected && "ring-2 ring-accent"
|
|
124
|
+
),
|
|
125
|
+
...getItemProps(landmark.id, { onKeyDown: edit.onKeyDown(landmark) }),
|
|
126
|
+
...edit.dragProps(landmark, "move"),
|
|
127
|
+
onClick: () => onSelect?.(landmark.id),
|
|
128
|
+
children: [
|
|
129
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: landmark.label }),
|
|
130
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "contents", children: label })
|
|
131
|
+
]
|
|
132
|
+
},
|
|
133
|
+
landmark.id
|
|
134
|
+
);
|
|
135
|
+
}),
|
|
136
|
+
outlines.map((outline) => /* @__PURE__ */ jsx(
|
|
137
|
+
"div",
|
|
138
|
+
{
|
|
139
|
+
"aria-hidden": "true",
|
|
140
|
+
"data-group": outline.groupId,
|
|
141
|
+
style: percentBox(outline, width, height),
|
|
142
|
+
className: cn(
|
|
143
|
+
"pointer-events-none absolute rounded-card border border-ink-3 border-dashed",
|
|
144
|
+
classNames?.group
|
|
145
|
+
)
|
|
146
|
+
},
|
|
147
|
+
outline.groupId
|
|
148
|
+
)),
|
|
149
|
+
shownItems.map((item) => {
|
|
150
|
+
const selected = selectedId === item.id || item.ring === "selected";
|
|
151
|
+
const ring = selected ? "selected" : item.ring ?? "none";
|
|
152
|
+
const tone = item.tone ?? "neutral";
|
|
153
|
+
const placement = labelPlacement(item, pxPerUnit);
|
|
154
|
+
const hasStatus = item.statusLabel !== void 0 || item.statusIcon !== void 0;
|
|
155
|
+
const style = customToneStyle(
|
|
156
|
+
tone,
|
|
157
|
+
builtinTones,
|
|
158
|
+
percentBox(item, width, height)
|
|
159
|
+
);
|
|
160
|
+
return /* @__PURE__ */ jsxs(
|
|
161
|
+
"button",
|
|
162
|
+
{
|
|
163
|
+
type: "button",
|
|
164
|
+
"data-item": item.id,
|
|
165
|
+
"data-shape": item.shape,
|
|
166
|
+
"data-tone": tone === "neutral" ? void 0 : tone,
|
|
167
|
+
"data-ring": ring === "none" ? void 0 : ring,
|
|
168
|
+
"data-label": placement,
|
|
169
|
+
"data-selected": selected ? "" : void 0,
|
|
170
|
+
"aria-pressed": selectable ? selected : void 0,
|
|
171
|
+
style,
|
|
172
|
+
"aria-describedby": editable ? hintId : void 0,
|
|
173
|
+
...getItemProps(item.id, { onKeyDown: edit.onKeyDown(item) }),
|
|
174
|
+
...editable ? edit.dragProps(item, "move") : null,
|
|
175
|
+
onClick: () => onSelect?.(item.id),
|
|
176
|
+
className: cn(
|
|
177
|
+
"absolute block rounded-control p-0 text-ink focus-visible:focus-ring",
|
|
178
|
+
editable && "cursor-grab touch-none active:cursor-grabbing",
|
|
179
|
+
isCustomTone(tone, builtinTones) ? "text-(--tone-c)" : toneClasses[tone] ?? toneClasses.neutral,
|
|
180
|
+
ringClasses[ring],
|
|
181
|
+
classNames?.item
|
|
182
|
+
),
|
|
183
|
+
children: [
|
|
184
|
+
/* @__PURE__ */ jsx(
|
|
185
|
+
TableGlyph,
|
|
186
|
+
{
|
|
187
|
+
shape: item.shape,
|
|
188
|
+
seats: item.seats,
|
|
189
|
+
occupied: item.occupied ?? 0,
|
|
190
|
+
width: item.width,
|
|
191
|
+
height: item.height,
|
|
192
|
+
pattern: item.pattern,
|
|
193
|
+
size: "fill",
|
|
194
|
+
className: cn(
|
|
195
|
+
"pointer-events-none absolute inset-0 text-current",
|
|
196
|
+
classNames?.glyph
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
),
|
|
200
|
+
/* @__PURE__ */ jsxs(
|
|
201
|
+
"span",
|
|
202
|
+
{
|
|
203
|
+
className: cn(
|
|
204
|
+
"pointer-events-none flex flex-col items-center text-center",
|
|
205
|
+
placement === "inside" ? "absolute inset-0 justify-center" : "absolute inset-x-0 top-full pt-0.5",
|
|
206
|
+
classNames?.label
|
|
207
|
+
),
|
|
208
|
+
children: [
|
|
209
|
+
/* @__PURE__ */ jsx("span", { className: "whitespace-nowrap font-bold text-ink text-meta", children: item.label }),
|
|
210
|
+
hasStatus ? /* @__PURE__ */ jsxs(
|
|
211
|
+
"span",
|
|
212
|
+
{
|
|
213
|
+
className: cn(
|
|
214
|
+
"inline-flex items-center gap-0.5 whitespace-nowrap text-ink-2 text-count",
|
|
215
|
+
classNames?.status
|
|
216
|
+
),
|
|
217
|
+
children: [
|
|
218
|
+
item.statusIcon ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "inline-flex shrink-0 text-current", children: item.statusIcon }) : null,
|
|
219
|
+
item.statusLabel
|
|
220
|
+
]
|
|
221
|
+
}
|
|
222
|
+
) : null
|
|
223
|
+
]
|
|
224
|
+
}
|
|
225
|
+
),
|
|
226
|
+
/* @__PURE__ */ jsxs("span", { className: "sr-only", children: [
|
|
227
|
+
format(item.seats === 1 ? strings.seatsOne : strings.seats, item.seats),
|
|
228
|
+
item.ring === "late" ? `, ${strings.late}` : ""
|
|
229
|
+
] })
|
|
230
|
+
]
|
|
231
|
+
},
|
|
232
|
+
item.id
|
|
233
|
+
);
|
|
234
|
+
}),
|
|
235
|
+
selectedBox && selectedSource ? /* @__PURE__ */ jsxs(
|
|
236
|
+
"div",
|
|
237
|
+
{
|
|
238
|
+
"data-edit-overlay": selectedBox.id,
|
|
239
|
+
style: percentBox(selectedBox, width, height),
|
|
240
|
+
className: "pointer-events-none absolute",
|
|
241
|
+
children: [
|
|
242
|
+
HANDLES.map((handle) => /* @__PURE__ */ jsx(
|
|
243
|
+
"span",
|
|
244
|
+
{
|
|
245
|
+
"aria-hidden": "true",
|
|
246
|
+
"data-handle": handle,
|
|
247
|
+
...edit.dragProps(selectedSource, handle),
|
|
248
|
+
className: cn(
|
|
249
|
+
"pointer-events-auto absolute size-2.5 touch-none rounded-chip border border-accent bg-surface before:absolute before:-inset-1.5 before:content-['']",
|
|
250
|
+
handleClasses[handle],
|
|
251
|
+
classNames?.handle
|
|
252
|
+
)
|
|
253
|
+
},
|
|
254
|
+
handle
|
|
255
|
+
)),
|
|
256
|
+
/* @__PURE__ */ jsx(
|
|
257
|
+
"button",
|
|
258
|
+
{
|
|
259
|
+
type: "button",
|
|
260
|
+
"aria-label": strings.rotate,
|
|
261
|
+
onClick: () => edit.rotate(selectedSource),
|
|
262
|
+
className: cn(
|
|
263
|
+
"pointer-events-auto absolute right-0 bottom-full mb-1 inline-flex size-control-sm items-center justify-center rounded-control border border-line bg-surface text-ink-2 hover:bg-surface-2 focus-visible:focus-ring [&_svg]:size-4",
|
|
264
|
+
classNames?.rotate
|
|
265
|
+
),
|
|
266
|
+
children: /* @__PURE__ */ jsx(RotateCcw, { "aria-hidden": "true" })
|
|
267
|
+
}
|
|
268
|
+
)
|
|
269
|
+
]
|
|
270
|
+
}
|
|
271
|
+
) : null
|
|
272
|
+
]
|
|
273
|
+
}
|
|
274
|
+
) });
|
|
275
|
+
}
|
|
276
|
+
export {
|
|
277
|
+
FloorPlan
|
|
278
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { type EditBounds, editKey, moveBox, type ResizeHandle, resizeBox, rotateBox, snapTo, } from "./edit-model.js";
|
|
2
|
+
export { FloorPlan, type FloorPlanBuiltinTone, type FloorPlanItem, type FloorPlanLandmark, type FloorPlanPart, type FloorPlanProps, type FloorPlanRing, type FloorPlanTone, } from "./floor-plan.js";
|
|
3
|
+
export { type GroupOutline, groupOutlines, type LabelPlacement, labelPlacement } from "./model.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
editKey,
|
|
3
|
+
moveBox,
|
|
4
|
+
resizeBox,
|
|
5
|
+
rotateBox,
|
|
6
|
+
snapTo
|
|
7
|
+
} from "./edit-model.js";
|
|
8
|
+
import {
|
|
9
|
+
FloorPlan
|
|
10
|
+
} from "./floor-plan.js";
|
|
11
|
+
import { groupOutlines, labelPlacement } from "./model.js";
|
|
12
|
+
export {
|
|
13
|
+
FloorPlan,
|
|
14
|
+
editKey,
|
|
15
|
+
groupOutlines,
|
|
16
|
+
labelPlacement,
|
|
17
|
+
moveBox,
|
|
18
|
+
resizeBox,
|
|
19
|
+
rotateBox,
|
|
20
|
+
snapTo
|
|
21
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { TableShape } from "../../atoms/table-glyph/layout.js";
|
|
2
|
+
export interface Box {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
export interface FloorPlanBox extends Box {
|
|
9
|
+
id: string;
|
|
10
|
+
}
|
|
11
|
+
export type LabelPlacement = "inside" | "below";
|
|
12
|
+
export declare const DEFAULT_PX_PER_UNIT = 32;
|
|
13
|
+
/**
|
|
14
|
+
* Whether an item's label fits inside the table body. The usable area is the box minus the chair
|
|
15
|
+
* band (and a round body only offers its inscribed square), measured in pixels from the canvas
|
|
16
|
+
* scale; anything smaller puts the label under the shape.
|
|
17
|
+
*/
|
|
18
|
+
export declare function labelPlacement(item: {
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
shape: TableShape;
|
|
22
|
+
}, pxPerUnit?: number): LabelPlacement;
|
|
23
|
+
export declare function percentBox(box: Box, width: number, height: number): {
|
|
24
|
+
left: string;
|
|
25
|
+
top: string;
|
|
26
|
+
width: string;
|
|
27
|
+
height: string;
|
|
28
|
+
};
|
|
29
|
+
export interface GroupOutline extends Box {
|
|
30
|
+
groupId: string;
|
|
31
|
+
}
|
|
32
|
+
export declare const GROUP_PADDING = 0.2;
|
|
33
|
+
/** One outline per `groupId` shared by at least two items: their union box plus a small padding. */
|
|
34
|
+
export declare function groupOutlines(items: ReadonlyArray<Box & {
|
|
35
|
+
groupId?: string | undefined;
|
|
36
|
+
}>): GroupOutline[];
|