@jcsoftdev/ui 0.7.1 → 0.9.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +4 -0
  3. package/dist/atoms/elapsed-time/elapsed-time.d.ts +29 -0
  4. package/dist/atoms/elapsed-time/elapsed-time.js +65 -0
  5. package/dist/atoms/elapsed-time/index.d.ts +2 -0
  6. package/dist/atoms/elapsed-time/index.js +9 -0
  7. package/dist/atoms/elapsed-time/model.d.ts +17 -0
  8. package/dist/atoms/elapsed-time/model.js +37 -0
  9. package/dist/atoms/elapsed-time/ticker.d.ts +5 -0
  10. package/dist/atoms/elapsed-time/ticker.js +37 -0
  11. package/dist/atoms/index.d.ts +2 -0
  12. package/dist/atoms/index.js +2 -0
  13. package/dist/atoms/table-glyph/index.d.ts +2 -0
  14. package/dist/atoms/table-glyph/index.js +14 -0
  15. package/dist/atoms/table-glyph/layout.d.ts +38 -0
  16. package/dist/atoms/table-glyph/layout.js +152 -0
  17. package/dist/atoms/table-glyph/table-glyph.d.ts +32 -0
  18. package/dist/atoms/table-glyph/table-glyph.js +131 -0
  19. package/dist/containers/floor-plan/edit-model.d.ts +33 -0
  20. package/dist/containers/floor-plan/edit-model.js +82 -0
  21. package/dist/containers/floor-plan/floor-plan.d.ts +83 -0
  22. package/dist/containers/floor-plan/floor-plan.js +278 -0
  23. package/dist/containers/floor-plan/index.d.ts +3 -0
  24. package/dist/containers/floor-plan/index.js +21 -0
  25. package/dist/containers/floor-plan/model.d.ts +36 -0
  26. package/dist/containers/floor-plan/model.js +52 -0
  27. package/dist/containers/floor-plan/use-floor-plan-edit.d.ts +26 -0
  28. package/dist/containers/floor-plan/use-floor-plan-edit.js +97 -0
  29. package/dist/containers/index.d.ts +2 -0
  30. package/dist/containers/index.js +2 -0
  31. package/dist/containers/order-ticket/index.d.ts +2 -0
  32. package/dist/containers/order-ticket/index.js +16 -0
  33. package/dist/containers/order-ticket/model.d.ts +18 -0
  34. package/dist/containers/order-ticket/model.js +36 -0
  35. package/dist/containers/order-ticket/order-ticket.d.ts +34 -0
  36. package/dist/containers/order-ticket/order-ticket.js +390 -0
  37. package/dist/glass/crystal-map.d.ts +3 -1
  38. package/dist/glass/crystal-map.js +13 -2
  39. package/dist/i18n/strings.d.ts +104 -0
  40. package/dist/i18n/strings.js +62 -0
  41. package/dist/icons/alarm-clock.d.ts +2 -0
  42. package/dist/icons/alarm-clock.js +15 -0
  43. package/dist/icons/hourglass.d.ts +2 -0
  44. package/dist/icons/hourglass.js +13 -0
  45. package/dist/icons/index.d.ts +2 -0
  46. package/dist/icons/index.js +4 -0
  47. package/icons/svg/alarm-clock.svg +8 -0
  48. package/icons/svg/hourglass.svg +6 -0
  49. package/package.json +2 -2
  50. package/src/atoms/elapsed-time/elapsed-time.tsx +101 -0
  51. package/src/atoms/elapsed-time/index.ts +6 -0
  52. package/src/atoms/elapsed-time/model.ts +54 -0
  53. package/src/atoms/elapsed-time/ticker.ts +39 -0
  54. package/src/atoms/index.ts +2 -0
  55. package/src/atoms/table-glyph/index.ts +14 -0
  56. package/src/atoms/table-glyph/layout.ts +187 -0
  57. package/src/atoms/table-glyph/table-glyph.tsx +161 -0
  58. package/src/containers/floor-plan/edit-model.ts +115 -0
  59. package/src/containers/floor-plan/floor-plan.tsx +393 -0
  60. package/src/containers/floor-plan/index.ts +20 -0
  61. package/src/containers/floor-plan/model.ts +81 -0
  62. package/src/containers/floor-plan/use-floor-plan-edit.ts +135 -0
  63. package/src/containers/index.ts +2 -0
  64. package/src/containers/order-ticket/index.ts +15 -0
  65. package/src/containers/order-ticket/model.ts +55 -0
  66. package/src/containers/order-ticket/order-ticket.tsx +463 -0
  67. package/src/glass/crystal-map.ts +21 -3
  68. package/src/i18n/strings.ts +104 -0
  69. package/src/icons/alarm-clock.tsx +16 -0
  70. package/src/icons/hourglass.tsx +14 -0
  71. package/src/icons/index.ts +2 -0
@@ -0,0 +1,52 @@
1
+ const DEFAULT_PX_PER_UNIT = 32;
2
+ const CHAIR_BAND = 0.24;
3
+ const MIN_INSIDE_WIDTH = 44;
4
+ const MIN_INSIDE_HEIGHT = 30;
5
+ function labelPlacement(item, pxPerUnit = DEFAULT_PX_PER_UNIT) {
6
+ if (item.shape === "bar") return "below";
7
+ const usable = (units) => units * pxPerUnit * (1 - 2 * CHAIR_BAND);
8
+ const round = item.shape === "round" ? Math.SQRT1_2 : 1;
9
+ const fits = usable(item.width) * round >= MIN_INSIDE_WIDTH && usable(item.height) * round >= MIN_INSIDE_HEIGHT;
10
+ return fits ? "inside" : "below";
11
+ }
12
+ function percentBox(box, width, height) {
13
+ return {
14
+ left: `${box.x / width * 100}%`,
15
+ top: `${box.y / height * 100}%`,
16
+ width: `${box.width / width * 100}%`,
17
+ height: `${box.height / height * 100}%`
18
+ };
19
+ }
20
+ const GROUP_PADDING = 0.2;
21
+ function groupOutlines(items) {
22
+ const groups = /* @__PURE__ */ new Map();
23
+ for (const item of items) {
24
+ if (item.groupId === void 0) continue;
25
+ const list = groups.get(item.groupId) ?? [];
26
+ list.push(item);
27
+ groups.set(item.groupId, list);
28
+ }
29
+ const outlines = [];
30
+ for (const [groupId, members] of groups) {
31
+ if (members.length < 2) continue;
32
+ const left = Math.min(...members.map((m) => m.x));
33
+ const top = Math.min(...members.map((m) => m.y));
34
+ const right = Math.max(...members.map((m) => m.x + m.width));
35
+ const bottom = Math.max(...members.map((m) => m.y + m.height));
36
+ outlines.push({
37
+ groupId,
38
+ x: left - GROUP_PADDING,
39
+ y: top - GROUP_PADDING,
40
+ width: right - left + 2 * GROUP_PADDING,
41
+ height: bottom - top + 2 * GROUP_PADDING
42
+ });
43
+ }
44
+ return outlines;
45
+ }
46
+ export {
47
+ DEFAULT_PX_PER_UNIT,
48
+ GROUP_PADDING,
49
+ groupOutlines,
50
+ labelPlacement,
51
+ percentBox
52
+ };
@@ -0,0 +1,26 @@
1
+ import { type PointerEvent, type RefObject } from "react";
2
+ import { type EditBounds, type ResizeHandle } from "./edit-model.js";
3
+ import type { FloorPlanBox } from "./model.js";
4
+ type DragMode = "move" | ResizeHandle;
5
+ interface Options<I extends FloorPlanBox, L extends FloorPlanBox> {
6
+ enabled: boolean;
7
+ items: readonly I[];
8
+ landmarks: readonly L[];
9
+ bounds: EditBounds;
10
+ canvasRef: RefObject<HTMLElement | null>;
11
+ onChange?: ((items: I[], landmarks: L[]) => void) | undefined;
12
+ onSelect?: ((id: string) => void) | undefined;
13
+ }
14
+ /** Drag, resize, rotate and keyboard edits of floor plan boxes; commits only on release, never mid-drag. */
15
+ export declare function useFloorPlanEdit<I extends FloorPlanBox, L extends FloorPlanBox>({ enabled, items, landmarks, bounds, canvasRef, onChange, onSelect, }: Options<I, L>): {
16
+ view: <T extends FloorPlanBox>(entry: T) => T;
17
+ dragProps: (entry: FloorPlanBox, mode: DragMode) => {
18
+ onPointerDown: (event: PointerEvent<HTMLElement>) => void;
19
+ onPointerMove: (event: PointerEvent<HTMLElement>) => void;
20
+ onPointerUp: (event: PointerEvent<HTMLElement>) => void;
21
+ onPointerCancel: () => void;
22
+ };
23
+ onKeyDown: (entry: FloorPlanBox) => (event: React.KeyboardEvent<HTMLElement>) => void;
24
+ rotate: (entry: FloorPlanBox) => void;
25
+ };
26
+ export {};
@@ -0,0 +1,97 @@
1
+ import { useRef, useState } from "react";
2
+ import {
3
+ editKey,
4
+ moveBox,
5
+ resizeBox,
6
+ sameBox
7
+ } from "./edit-model.js";
8
+ const DRAG_THRESHOLD_PX = 3;
9
+ function capturePointer(element, pointerId) {
10
+ try {
11
+ element.setPointerCapture(pointerId);
12
+ return true;
13
+ } catch {
14
+ return false;
15
+ }
16
+ }
17
+ const pick = ({ x, y, width, height }) => ({ x, y, width, height });
18
+ function useFloorPlanEdit({
19
+ enabled,
20
+ items,
21
+ landmarks,
22
+ bounds,
23
+ canvasRef,
24
+ onChange,
25
+ onSelect
26
+ }) {
27
+ const [draft, setDraft] = useState(null);
28
+ const drag = useRef(null);
29
+ const view = (entry) => draft?.id === entry.id ? { ...entry, ...draft.box } : entry;
30
+ const commit = (id, box) => {
31
+ const current = [...items, ...landmarks].find((entry) => entry.id === id);
32
+ if (!current || sameBox(pick(current), box)) return;
33
+ const apply = (list) => list.map((entry) => entry.id === id ? { ...entry, ...box } : entry);
34
+ onChange?.(apply(items), apply(landmarks));
35
+ };
36
+ const dragProps = (entry, mode) => ({
37
+ onPointerDown: (event) => {
38
+ if (!enabled || event.button !== 0) return;
39
+ const canvas = canvasRef.current;
40
+ if (!canvas) return;
41
+ event.stopPropagation();
42
+ capturePointer(event.currentTarget, event.pointerId);
43
+ drag.current = {
44
+ id: entry.id,
45
+ mode,
46
+ startX: event.clientX,
47
+ startY: event.clientY,
48
+ origin: pick(entry),
49
+ unit: canvas.getBoundingClientRect().width / bounds.width,
50
+ moved: false
51
+ };
52
+ onSelect?.(entry.id);
53
+ },
54
+ onPointerMove: (event) => {
55
+ const current = drag.current;
56
+ if (!current || current.id !== entry.id) return;
57
+ const px = Math.hypot(event.clientX - current.startX, event.clientY - current.startY);
58
+ if (!current.moved && px < DRAG_THRESHOLD_PX) return;
59
+ current.moved = true;
60
+ const dx = (event.clientX - current.startX) / current.unit;
61
+ const dy = (event.clientY - current.startY) / current.unit;
62
+ const box = current.mode === "move" ? moveBox(current.origin, dx, dy, bounds) : resizeBox(current.origin, current.mode, dx, dy, bounds);
63
+ setDraft(
64
+ (previous) => previous && sameBox(previous.box, box) ? previous : { id: entry.id, box }
65
+ );
66
+ },
67
+ onPointerUp: (event) => {
68
+ const current = drag.current;
69
+ if (!current || current.id !== entry.id) return;
70
+ drag.current = null;
71
+ if (event.currentTarget.hasPointerCapture?.(event.pointerId)) {
72
+ event.currentTarget.releasePointerCapture(event.pointerId);
73
+ }
74
+ if (current.moved && draft) commit(entry.id, draft.box);
75
+ setDraft(null);
76
+ },
77
+ onPointerCancel: () => {
78
+ drag.current = null;
79
+ setDraft(null);
80
+ }
81
+ });
82
+ const onKeyDown = (entry) => (event) => {
83
+ if (!enabled) return;
84
+ const result = editKey(pick(entry), event, bounds);
85
+ if (!result) return;
86
+ event.preventDefault();
87
+ commit(entry.id, result.box);
88
+ };
89
+ const rotate = (entry) => {
90
+ const result = editKey(pick(entry), { key: "r", altKey: false, shiftKey: false }, bounds);
91
+ if (result) commit(entry.id, result.box);
92
+ };
93
+ return { view, dragProps, onKeyDown, rotate };
94
+ }
95
+ export {
96
+ useFloorPlanEdit
97
+ };
@@ -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";
@@ -27,6 +28,7 @@ export * from "./kpi/index.js";
27
28
  export * from "./kpi-group/index.js";
28
29
  export * from "./list-detail/index.js";
29
30
  export * from "./note/index.js";
31
+ export * from "./order-ticket/index.js";
30
32
  export * from "./page/index.js";
31
33
  export * from "./page-header/index.js";
32
34
  export * from "./pagination/index.js";
@@ -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";
@@ -27,6 +28,7 @@ export * from "./kpi/index.js";
27
28
  export * from "./kpi-group/index.js";
28
29
  export * from "./list-detail/index.js";
29
30
  export * from "./note/index.js";
31
+ export * from "./order-ticket/index.js";
30
32
  export * from "./page/index.js";
31
33
  export * from "./page-header/index.js";
32
34
  export * from "./pagination/index.js";
@@ -0,0 +1,2 @@
1
+ export { type OrderTicketLine, type OrderTicketLineStatus, type OrderTicketState, orderTicketState, splitTicketLines, ticketLineCost, warnLeadSeconds, } from "./model.js";
2
+ export { OrderTicket, type OrderTicketChannel, type OrderTicketPart, type OrderTicketProps, } from "./order-ticket.js";
@@ -0,0 +1,16 @@
1
+ import {
2
+ orderTicketState,
3
+ splitTicketLines,
4
+ ticketLineCost,
5
+ warnLeadSeconds
6
+ } from "./model.js";
7
+ import {
8
+ OrderTicket
9
+ } from "./order-ticket.js";
10
+ export {
11
+ OrderTicket,
12
+ orderTicketState,
13
+ splitTicketLines,
14
+ ticketLineCost,
15
+ warnLeadSeconds
16
+ };
@@ -0,0 +1,18 @@
1
+ export type OrderTicketState = "ok" | "warn" | "late";
2
+ export type OrderTicketLineStatus = "pending" | "in-progress" | "done";
3
+ export interface OrderTicketLine {
4
+ id: string;
5
+ qty: number;
6
+ name: string;
7
+ modifiers?: readonly string[] | undefined;
8
+ note?: string | undefined;
9
+ allergy?: string | undefined;
10
+ status?: OrderTicketLineStatus | undefined;
11
+ onToggle?: (() => void) | undefined;
12
+ }
13
+ export declare function warnLeadSeconds(targetMinutes: number): number;
14
+ export declare function orderTicketState(elapsedSeconds: number, targetMinutes: number): OrderTicketState;
15
+ type LineShape = Pick<OrderTicketLine, "modifiers" | "note" | "allergy">;
16
+ export declare function ticketLineCost(line: LineShape): number;
17
+ export declare function splitTicketLines<Line extends LineShape>(lines: readonly Line[], budget: number, cost?: (line: Line) => number): Line[][];
18
+ export {};
@@ -0,0 +1,36 @@
1
+ const MIN_WARN_LEAD_SECONDS = 120;
2
+ const WARN_LEAD_SHARE = 0.25;
3
+ function warnLeadSeconds(targetMinutes) {
4
+ return Math.max(MIN_WARN_LEAD_SECONDS, targetMinutes * 60 * WARN_LEAD_SHARE);
5
+ }
6
+ function orderTicketState(elapsedSeconds, targetMinutes) {
7
+ const target = targetMinutes * 60;
8
+ if (elapsedSeconds > target) return "late";
9
+ if (elapsedSeconds >= target - warnLeadSeconds(targetMinutes)) return "warn";
10
+ return "ok";
11
+ }
12
+ function ticketLineCost(line) {
13
+ return 1 + (line.modifiers?.length ? 0.6 : 0) + (line.note ? 0.9 : 0) + (line.allergy ? 0.9 : 0);
14
+ }
15
+ function splitTicketLines(lines, budget, cost = ticketLineCost) {
16
+ const parts = [];
17
+ let used = 0;
18
+ for (const line of lines) {
19
+ const weight = cost(line);
20
+ const current = parts.at(-1);
21
+ if (current && used + weight <= budget) {
22
+ current.push(line);
23
+ used += weight;
24
+ } else {
25
+ parts.push([line]);
26
+ used = weight;
27
+ }
28
+ }
29
+ return parts;
30
+ }
31
+ export {
32
+ orderTicketState,
33
+ splitTicketLines,
34
+ ticketLineCost,
35
+ warnLeadSeconds
36
+ };
@@ -0,0 +1,34 @@
1
+ import { type ComponentPropsWithoutRef, type ReactNode } from "react";
2
+ import type { ClassNames } from "../../utils/class-names.js";
3
+ import { type OrderTicketLine, type OrderTicketState } from "./model.js";
4
+ export type OrderTicketPart = "root" | "paper" | "band" | "title" | "meta" | "timer" | "progress" | "lines" | "line" | "footer";
5
+ export interface OrderTicketChannel {
6
+ label: string;
7
+ icon?: ReactNode;
8
+ }
9
+ export interface OrderTicketProps extends Omit<ComponentPropsWithoutRef<"article">, "title" | "children"> {
10
+ table?: string | undefined;
11
+ number?: string | number | undefined;
12
+ channel?: OrderTicketChannel | undefined;
13
+ guests?: number | undefined;
14
+ server?: string | undefined;
15
+ customer?: string | undefined;
16
+ since: Date | string;
17
+ targetMinutes: number;
18
+ serverOffsetMs?: number | undefined;
19
+ state?: OrderTicketState | undefined;
20
+ lines: readonly OrderTicketLine[];
21
+ partIndex?: number | undefined;
22
+ partCount?: number | undefined;
23
+ recovered?: boolean | undefined;
24
+ chip?: ReactNode;
25
+ readOnly?: boolean | undefined;
26
+ onStartAll?: ((lines: readonly OrderTicketLine[]) => void) | undefined;
27
+ onReadyAll?: ((lines: readonly OrderTicketLine[]) => void) | undefined;
28
+ actions?: ReactNode;
29
+ hanging?: boolean | undefined;
30
+ headingLevel?: 2 | 3 | 4 | undefined;
31
+ viewTransitionName?: string | undefined;
32
+ classNames?: ClassNames<OrderTicketPart> | undefined;
33
+ }
34
+ export declare function OrderTicket({ table, number, channel, guests, server, customer, since, targetMinutes, serverOffsetMs, state: stateProp, lines, partIndex, partCount, recovered, chip, readOnly, onStartAll, onReadyAll, actions, hanging, headingLevel, viewTransitionName, classNames, className, style, ...props }: OrderTicketProps): import("react").JSX.Element;