@ordinatio/ui 1.8.0 → 1.10.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 ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ Entries start at 1.9.0 (older history is in git).
4
+
5
+ ## 1.10.0
6
+
7
+ - New pipeline board components: `PipelineBoard`, `BoardColumn`, `DealCard`, `AddCardBox`, `MoveMenu`, `LostStep`, `ReopenStep`, the pure `nearestColumnIndex`, and the types (`BoardCard`, `BoardColumnData`, `BoardTexts`, `BoardClassNames`, `MoveRequest`, `DropRule`, `BoardDnd`, and more). A Trello-style row of columns with cards. Contract: the app injects ALL words (`texts`, no English defaults) and, optionally, `classNames` (replace the default look; the sideways-scroll structure is always kept inline). The board holds no rules: `legalTargets`, `reopenFor`, `lost` (`validateReason`, `humanize`, suggestions) and every callback come from the app. A move into a lost column asks for a reason first; a move shows "moving" in the new column and snaps back with the sentence on a refusal; a closed card can be reopened (stage picker or plain).
8
+ - New entry `@ordinatio/ui/board-dnd` (`boardDnd`, `resolveDrop`, `columnShift`, `buildAnnouncements`): drag and drop as an optional layer over the same move callback. `@dnd-kit/core` 6.3.1 and `@dnd-kit/utilities` 3.2.2 are OPTIONAL exact peer dependencies: apps that never import `board-dnd` do not need them.
9
+ - Drag guards: no drag starts inside the card's own controls; keyboard drag only from the focused card; the board refuses Lost columns when no `lost` step is given; focus returns to the moved card.
10
+ - Additive: no existing export changes.
11
+
12
+ ## 1.9.0
13
+
14
+ - New `Pager` component (and the `PagerProps`, `PagerClassNames`, `PagerLabels`, `PagerLinkProps` types): the "Showing X to Y of Z" line with Previous and Next links. Contract: the caller passes a `page` already inside [1, last page] and builds `hrefs: { previous, next }` from that same number; Pager decides which links show and never renders a link for a page out of range. If `page` was not in range (NaN, 0, negative, fractional, past the end) Pager shows the text for the nearest real page and NO links. No prop is a function except `LinkComponent`, which across a server-to-client boundary must be a client component or client reference (`next/link` works). Also `classNames`, `labels` (strings only; `showing` is a `{start}`/`{end}`/`{total}` template, for example an en dash form `'Showing {start}–{end} of {total}'`) and `hideWhenSinglePage` (default true: renders nothing when everything fits on one page; false shows the "Showing" line whenever the list is not empty). Tolerates NaN, Infinity, negative and fractional numbers.
15
+ - Additive: no existing export changes.
package/README.md CHANGED
@@ -258,6 +258,26 @@ Presentation for a soft-delete flow. None of them knows a route, a router or a d
258
258
  - `TrashedBanner`: amber "In the Trash since DATE by NAME." strip with a `restore` slot. `since` null reads "earlier". Dates use `formatTrashedDate(date, locale = 'en-US', timeZone?)` or your `formatDate`. `labels` `{ intro, since, by, earlier }`.
259
259
  - Styling: plain elements with inline defaults; `classNames.<part>` REPLACES that part's look. Parts: RestoreButton `root, button, error`; UndoNotice `root, message, link, undo, dismiss, error`; TrashedBanner `root, text, action`.
260
260
 
261
+ ### `Pager` (1.9.0)
262
+
263
+ The "Showing X to Y of Z" line with Previous and Next links under a paged list. No hooks, state or router: the app owns the page number and passes the two link targets in `hrefs`.
264
+
265
+ ```tsx
266
+ // Clamp FIRST, then build the hrefs from that same number.
267
+ const { page } = pageWindow({ total, page: requestedPage, pageSize: 50 }); // or your own clamp into [1, lastPage]
268
+ <Pager total={total} page={page} pageSize={50} hrefs={{ previous: `?page=${page - 1}`, next: `?page=${page + 1}` }} LinkComponent={Link} />
269
+ // An en dash instead of "to":
270
+ <Pager ... labels={{ showing: 'Showing {start}–{end} of {total}' }} />
271
+ ```
272
+
273
+ - Props: `total`, `page` (1-based), `pageSize`, `hrefs` `{ previous, next }`, `LinkComponent` (default a plain `<a>`; gets `href`, `className`, `children`), `classNames` `{ root, summary, links, link }`, `labels` `{ previous, next, showing }` (strings only; `showing` is a template with `{start}`, `{end}` and `{total}`; defaults "← Previous", "Next →", "Showing {start} to {end} of {total}"), `hideWhenSinglePage` (default true). The en dash form above is what Cranberry's old hand-written Tasks and Inbox bars used.
274
+ - Contract: you MUST pass a `page` already inside `[1, last page]` (for example from `@ordinatio/core/paging` `pageWindow().page`) and build `hrefs` from that same number (`previous` = page - 1, `next` = page + 1). Pager decides which links show (no Previous on page 1, no Next on the last page) and never renders a link for a page out of range.
275
+ - Last-resort guard: if `page` is NOT already a whole number inside `[1, last page]` (NaN, 0, negative, fractional, past the end), Pager shows the "Showing" text for the nearest real page and renders NO links, because it cannot vouch for where your `hrefs` point.
276
+ - Single page: by default it renders nothing when `total <= pageSize`. With `hideWhenSinglePage={false}` it shows the "Showing" line (no links) whenever `total > 0`. An empty list (`total` 0) always renders nothing.
277
+ - Bad numbers (NaN, Infinity, negative, fractional `total`, `page` or `pageSize`) never print NaN or make an empty link: `total` and `page` are floored, `pageSize` is at least 1.
278
+ - Server-safe: the only function prop is `LinkComponent` (a component reference). Across a server-to-client boundary it must be a client component or a client reference (`next/link` works; a plain function component defined in a server file does not). Every other prop is a string, number, boolean or plain object, so a server page (Tasks, Inbox, Trash) can render it.
279
+ - Styling: `classNames.<part>` REPLACES that part's look (the root and links wrapper have small inline defaults, the summary and links have none).
280
+
261
281
  ### `ShowOnceSecret` and `useCopyToClipboard`
262
282
 
263
283
  A box for something that is readable only right now (an API key, a signing secret, an invite link).
@@ -270,6 +290,40 @@ A box for something that is readable only right now (an API key, a signing secre
270
290
  - `labels`: `warning, copy, done, copied, failed, secret`. `classNames`: `root, title, warning, secret, actions, copy, done, note`.
271
291
  - `useCopyToClipboard({ copiedNote, failedNote, resetAfterMs })` returns `{ copy, note, status, reset }`. `copy(text)` resolves true or false and never throws (a refused or missing clipboard gives the failed note). The last of overlapping copies decides the note; `resetAfterMs` fades it; nothing is set after unmount.
272
292
 
293
+ ### PipelineBoard
294
+
295
+ A Trello-style board: columns of cards, a "+ Add a card" box at the bottom of each OPEN column, sideways scroll with snap on a phone. The board is rule-free and word-free: the app passes everything.
296
+
297
+ ```tsx
298
+ import { PipelineBoard } from '@ordinatio/ui';
299
+ import { boardDnd } from '@ordinatio/ui/board-dnd'; // optional; needs @dnd-kit/core 6.3.1 + @dnd-kit/utilities 3.2.2
300
+
301
+ <PipelineBoard
302
+ columns={columns} // BoardColumnData[]: id, name, kind 'open'|'won'|'lost', count, totals[], cards[]
303
+ texts={texts} // every word the board shows (BoardTexts); no English defaults
304
+ legalTargets={(card) => targets} // the app's rule: which stages a card may move to
305
+ onMove={async ({ dealId, toStageId, expectedVersion, reason }) => ({ error })} // return { error } to refuse
306
+ lost={{ suggestions, used, validateReason, humanize }} // asks for a reason on a move into a lost column
307
+ reopenFor={(card) => ({ needsStage, stages })} onReopen={...}
308
+ onAddCard={async (stageId, { title, amount, currency }) => ({ error })}
309
+ classNames={{ card: '...' }} // replaces the default look of a part; structure is kept
310
+ dnd={boardDnd({ canDrop, texts: dragTexts })} // optional drag and drop over the same onMove
311
+ />
312
+ ```
313
+
314
+ **Things the app must know:**
315
+
316
+ - `onMove` success: the card stays in its new column only until the app re-reads. The app MUST re-read (or update) `columns` after a successful `onMove`, `onReopen` or `onAddCard`; until then the card data (version, badge, totals) is stale.
317
+ - `card.overdue` must be `false` for closed (won or lost) deals; the board shows whatever it is given.
318
+ - `lost` is `{ suggestions: {code, label?}[], used: {code, label?}[], validateReason(text) => code | null, humanize(code) => string }`. Without `lost`, Lost columns are not offered in the menu and a drop on one is refused (the board will not send a lost move with no reason).
319
+ - Drag texts, `BoardDndTexts`: `{ instructions, roleDescription, pickedUp(title), over(title, column), dropped(title, column), cancelled(title), sameColumnNote, cannotDrop }`.
320
+ - `canDrop(card, fromStageId, toStageId, columns) => boolean` (the `DropRule`). A refused drop is announced with `cannotDrop`, not "dropped"; the visible note clears on the next pointer or key action.
321
+ - Drag guards: a drag never starts inside an input, textarea, select, button, link, `[contenteditable]` or `[data-no-drag]`; a keyboard drag starts with Space only when focus is on the card itself (Space inside the card's controls works normally).
322
+ - After a move settles, focus goes to the moved card; after "add", focus returns to the title field.
323
+ - NOT proven in jsdom (needs the browser pass): arrow-key moves between columns, real drops, touch long-press, focus return after a drop, auto-scroll at the row edge.
324
+
325
+ Injection contract: pure rules (reason validation, which move is legal) belong in the engine package and are passed in as `validateReason`, `humanize`, `legalTargets` and `canDrop`; this package never imports them.
326
+
273
327
  ## Hooks
274
328
 
275
329
  ### Form and screen hooks (1.7.0, 1.8.0)
@@ -0,0 +1,111 @@
1
+ import { ReactNode } from 'react';
2
+ import { b as BoardColumnData, c as BoardCard, D as DropRule, e as BoardDnd } from './board-types-D8JR0lN4.mjs';
3
+
4
+ /** How a drag starts. A mouse needs a small move; a finger needs a long press (so scrolling the row still works) with a small allowed wobble. The keyboard uses Space to pick up and drop and Escape to cancel. */
5
+ declare const BOARD_DND_SENSORS: {
6
+ readonly mouse: {
7
+ readonly distance: 6;
8
+ };
9
+ readonly touch: {
10
+ readonly delay: 250;
11
+ readonly tolerance: 8;
12
+ };
13
+ readonly keyboard: {
14
+ readonly start: readonly ["Space"];
15
+ readonly end: readonly ["Space"];
16
+ readonly cancel: readonly ["Escape"];
17
+ };
18
+ };
19
+ type DropOutcome = {
20
+ kind: 'move';
21
+ cardId: string;
22
+ toStageId: string;
23
+ }
24
+ /** Dropped on the column it came from: a plain note, nothing is sent (cards stay newest first). */
25
+ | {
26
+ kind: 'same-column';
27
+ }
28
+ /** The app's rule refuses that column. */
29
+ | {
30
+ kind: 'illegal';
31
+ }
32
+ /** Dropped on nothing, or on something that is not a column of this board. */
33
+ | {
34
+ kind: 'none';
35
+ };
36
+ declare function findCard(columns: ReadonlyArray<BoardColumnData>, cardId: string): {
37
+ card: BoardCard;
38
+ column: BoardColumnData;
39
+ } | null;
40
+ /** What a drop of `activeId` on `overId` means. Never throws. */
41
+ declare function resolveDrop(activeId: string, overId: string | null, columns: ReadonlyArray<BoardColumnData>, canDrop: DropRule): DropOutcome;
42
+ interface ColumnRect {
43
+ id: string;
44
+ left: number;
45
+ width: number;
46
+ }
47
+ /**
48
+ * How far to shift a dragged card sideways for an arrow key so it lands in the next column: the distance between the left edges of the current column and its neighbour, or null when there is no neighbour
49
+ * (or the key is not a sideways arrow). `currentLeft` is the left edge of the dragged card's box.
50
+ */
51
+ declare function columnShift(key: string, currentLeft: number, columns: ReadonlyArray<ColumnRect>): number | null;
52
+ interface BoardDndTexts {
53
+ /** Read to a screen-reader user when focus lands on a card that can be dragged. */
54
+ instructions: string;
55
+ /** Spoken as the role of a draggable card, for example "draggable card". */
56
+ roleDescription: string;
57
+ pickedUp: (cardTitle: string) => string;
58
+ over: (cardTitle: string, columnName: string) => string;
59
+ dropped: (cardTitle: string, columnName: string) => string;
60
+ cancelled: (cardTitle: string) => string;
61
+ /** The note shown (and spoken) when a card is dropped on its own column. */
62
+ sameColumnNote: string;
63
+ /** The note shown when the app's rule refuses the column. */
64
+ cannotDrop: string;
65
+ }
66
+ interface AnnouncementLookup {
67
+ cardTitle: (cardId: string) => string | null;
68
+ columnName: (columnId: string | null) => string | null;
69
+ /** Whether a drop of this card on this column would send a move. Required, so a caller cannot forget it. */
70
+ canLand: (cardId: string, columnId: string) => boolean;
71
+ }
72
+ /** The spoken steps of a drag, in the app's words. A step about a card or column that is not on the board says nothing. */
73
+ declare function buildAnnouncements(texts: BoardDndTexts, lookup: AnnouncementLookup): {
74
+ onDragStart: ({ active }: {
75
+ active: {
76
+ id: unknown;
77
+ };
78
+ }) => string | undefined;
79
+ onDragOver: ({ active, over }: {
80
+ active: {
81
+ id: unknown;
82
+ };
83
+ over: {
84
+ id: unknown;
85
+ } | null;
86
+ }) => string | undefined;
87
+ onDragEnd: ({ active, over }: {
88
+ active: {
89
+ id: unknown;
90
+ };
91
+ over: {
92
+ id: unknown;
93
+ } | null;
94
+ }) => string | undefined;
95
+ onDragCancel: ({ active }: {
96
+ active: {
97
+ id: unknown;
98
+ };
99
+ }) => string | undefined;
100
+ };
101
+
102
+ interface BoardDndConfig {
103
+ canDrop: DropRule;
104
+ texts: BoardDndTexts;
105
+ /** What follows the pointer while dragging. Default: the card's title in a plain box. */
106
+ renderPreview?: (card: BoardCard) => ReactNode;
107
+ }
108
+ /** The descriptor for `<PipelineBoard dnd={...} />`. Call it once per render with the app's drop rule and texts. */
109
+ declare function boardDnd(config: BoardDndConfig): BoardDnd;
110
+
111
+ export { type AnnouncementLookup, BOARD_DND_SENSORS, type BoardDndConfig, type BoardDndTexts, type ColumnRect, type DropOutcome, boardDnd, buildAnnouncements, columnShift, findCard, resolveDrop };
@@ -0,0 +1,208 @@
1
+ 'use client';
2
+
3
+ // src/board-dnd/board-dnd.tsx
4
+ import {
5
+ DndContext,
6
+ DragOverlay,
7
+ KeyboardSensor,
8
+ MouseSensor,
9
+ TouchSensor,
10
+ useDraggable,
11
+ useDroppable,
12
+ useSensor,
13
+ useSensors
14
+ } from "@dnd-kit/core";
15
+ import { createContext, useContext, useEffect, useMemo, useState } from "react";
16
+
17
+ // src/board-dnd/drop.ts
18
+ var BOARD_DND_SENSORS = {
19
+ mouse: { distance: 6 },
20
+ touch: { delay: 250, tolerance: 8 },
21
+ keyboard: { start: ["Space"], end: ["Space"], cancel: ["Escape"] }
22
+ };
23
+ var NO_DRAG_SELECTOR = "input, textarea, select, button, a, [contenteditable], [data-no-drag]";
24
+ function isInsideControl(target) {
25
+ const el = target;
26
+ return !!el && typeof el.closest === "function" && el.closest(NO_DRAG_SELECTOR) !== null;
27
+ }
28
+ function keyStartsDrag(target, currentTarget) {
29
+ return target !== null && target !== void 0 && target === currentTarget;
30
+ }
31
+ function findCard(columns, cardId) {
32
+ for (const column of columns) {
33
+ for (const card of column.cards) if (card.id === cardId) return { card, column };
34
+ }
35
+ return null;
36
+ }
37
+ function resolveDrop(activeId, overId, columns, canDrop) {
38
+ if (overId === null) return { kind: "none" };
39
+ const found = findCard(columns, activeId);
40
+ const target = columns.find((c) => c.id === overId);
41
+ if (!found || !target) return { kind: "none" };
42
+ if (found.column.id === target.id) return { kind: "same-column" };
43
+ if (!canDrop(found.card, found.column.id, target.id, columns)) return { kind: "illegal" };
44
+ return { kind: "move", cardId: activeId, toStageId: target.id };
45
+ }
46
+ function columnShift(key, currentLeft, columns) {
47
+ if (key !== "ArrowRight" && key !== "ArrowLeft") return null;
48
+ const sorted = [...columns].sort((a, b) => a.left - b.left);
49
+ if (sorted.length < 2) return null;
50
+ let current = 0;
51
+ for (let i = 0; i < sorted.length; i++) {
52
+ const column = sorted[i];
53
+ if (column && currentLeft >= column.left - 1) current = i;
54
+ }
55
+ const next = sorted[current + (key === "ArrowRight" ? 1 : -1)];
56
+ const here = sorted[current];
57
+ if (!next || !here) return null;
58
+ return next.left - here.left;
59
+ }
60
+ function buildAnnouncements(texts, lookup) {
61
+ const idOf = (value) => String(value);
62
+ return {
63
+ onDragStart: ({ active }) => {
64
+ const title = lookup.cardTitle(idOf(active.id));
65
+ return title === null ? void 0 : texts.pickedUp(title);
66
+ },
67
+ onDragOver: ({ active, over }) => {
68
+ const title = lookup.cardTitle(idOf(active.id));
69
+ const column = over ? lookup.columnName(idOf(over.id)) : null;
70
+ return title === null || column === null ? void 0 : texts.over(title, column);
71
+ },
72
+ onDragEnd: ({ active, over }) => {
73
+ const title = lookup.cardTitle(idOf(active.id));
74
+ const column = over ? lookup.columnName(idOf(over.id)) : null;
75
+ if (title === null) return void 0;
76
+ if (column !== null && over && !lookup.canLand(idOf(active.id), idOf(over.id))) return texts.cannotDrop;
77
+ return column === null ? texts.cancelled(title) : texts.dropped(title, column);
78
+ },
79
+ onDragCancel: ({ active }) => {
80
+ const title = lookup.cardTitle(idOf(active.id));
81
+ return title === null ? void 0 : texts.cancelled(title);
82
+ }
83
+ };
84
+ }
85
+
86
+ // src/board-dnd/board-dnd.tsx
87
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
88
+ var GuardedMouseSensor = class extends MouseSensor {
89
+ static activators = [{
90
+ eventName: "onMouseDown",
91
+ handler: ({ nativeEvent }, { onActivation }) => {
92
+ if (nativeEvent.button === 2 || isInsideControl(nativeEvent.target)) return false;
93
+ onActivation?.({ event: nativeEvent });
94
+ return true;
95
+ }
96
+ }];
97
+ };
98
+ var GuardedTouchSensor = class extends TouchSensor {
99
+ static activators = [{
100
+ eventName: "onTouchStart",
101
+ handler: ({ nativeEvent }, { onActivation }) => {
102
+ if (nativeEvent.touches.length > 1 || isInsideControl(nativeEvent.target)) return false;
103
+ onActivation?.({ event: nativeEvent });
104
+ return true;
105
+ }
106
+ }];
107
+ };
108
+ var GuardedKeyboardSensor = class extends KeyboardSensor {
109
+ static activators = [{
110
+ eventName: "onKeyDown",
111
+ handler: (event, { keyboardCodes, onActivation }) => {
112
+ const start = keyboardCodes?.start ?? ["Space", "Enter"];
113
+ if (!start.includes(event.nativeEvent.code) || !keyStartsDrag(event.target, event.currentTarget)) return false;
114
+ event.preventDefault();
115
+ onActivation?.({ event: event.nativeEvent });
116
+ return true;
117
+ }
118
+ }];
119
+ };
120
+ var ConfigContext = createContext(null);
121
+ var columnJump = (event, { currentCoordinates, context }) => {
122
+ const rects = Array.from(context.droppableRects.entries()).map(([id, rect]) => ({ id: String(id), left: rect.left, width: rect.width }));
123
+ const shift = columnShift(event.code === "ArrowRight" || event.code === "ArrowLeft" ? event.code : "", context.collisionRect?.left ?? currentCoordinates.x, rects);
124
+ if (shift === null) return void 0;
125
+ return { x: currentCoordinates.x + shift, y: currentCoordinates.y };
126
+ };
127
+ function usePrefersReducedMotion() {
128
+ const [reduced, setReduced] = useState(false);
129
+ useEffect(() => {
130
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") return;
131
+ const query = window.matchMedia("(prefers-reduced-motion: reduce)");
132
+ setReduced(query.matches);
133
+ const onChange = (event) => setReduced(event.matches);
134
+ query.addEventListener?.("change", onChange);
135
+ return () => query.removeEventListener?.("change", onChange);
136
+ }, []);
137
+ return reduced;
138
+ }
139
+ function BoardDndProvider({ columns, onDrop, allow, config, children }) {
140
+ const appRule = config.canDrop;
141
+ const cfg = useMemo(() => ({ ...config, canDrop: (card, from, to, cols) => (allow ? allow(card.id, to) : true) && appRule(card, from, to, cols) }), [config, allow, appRule]);
142
+ const sensors = useSensors(
143
+ useSensor(GuardedMouseSensor, { activationConstraint: BOARD_DND_SENSORS.mouse }),
144
+ useSensor(GuardedTouchSensor, { activationConstraint: BOARD_DND_SENSORS.touch }),
145
+ useSensor(GuardedKeyboardSensor, { coordinateGetter: columnJump, keyboardCodes: { start: [...BOARD_DND_SENSORS.keyboard.start], end: [...BOARD_DND_SENSORS.keyboard.end], cancel: [...BOARD_DND_SENSORS.keyboard.cancel] } })
146
+ );
147
+ const [activeId, setActiveId] = useState(null);
148
+ const [note, setNote] = useState(null);
149
+ const reduced = usePrefersReducedMotion();
150
+ const announcements = useMemo(
151
+ () => buildAnnouncements(cfg.texts, {
152
+ cardTitle: (id) => findCard(columns, id)?.card.title ?? null,
153
+ columnName: (id) => id === null ? null : columns.find((c) => c.id === id)?.name ?? null,
154
+ canLand: (cardId, columnId) => resolveDrop(cardId, columnId, columns, cfg.canDrop).kind === "move"
155
+ }),
156
+ [cfg.texts, cfg.canDrop, columns]
157
+ );
158
+ const active = activeId ? findCard(columns, activeId) : null;
159
+ const onDragStart = (event) => {
160
+ setNote(null);
161
+ setActiveId(String(event.active.id));
162
+ };
163
+ const onDragEnd = (event) => {
164
+ setActiveId(null);
165
+ const outcome = resolveDrop(String(event.active.id), event.over ? String(event.over.id) : null, columns, cfg.canDrop);
166
+ if (outcome.kind === "move") onDrop(outcome.cardId, outcome.toStageId);
167
+ else if (outcome.kind === "same-column") setNote(cfg.texts.sameColumnNote);
168
+ else if (outcome.kind === "illegal") setNote(cfg.texts.cannotDrop);
169
+ };
170
+ return /* @__PURE__ */ jsx(ConfigContext.Provider, { value: cfg, children: /* @__PURE__ */ jsxs(
171
+ DndContext,
172
+ {
173
+ sensors,
174
+ accessibility: { announcements, screenReaderInstructions: { draggable: cfg.texts.instructions } },
175
+ autoScroll: { threshold: { x: 0.15, y: 0 } },
176
+ onDragStart,
177
+ onDragEnd,
178
+ onDragCancel: () => setActiveId(null),
179
+ children: [
180
+ /* @__PURE__ */ jsx("div", { style: { display: "contents" }, onPointerDownCapture: () => note && setNote(null), onKeyDownCapture: () => note && setNote(null), children }),
181
+ /* @__PURE__ */ jsx(DragOverlay, { dropAnimation: reduced ? null : void 0, children: active ? cfg.renderPreview ? cfg.renderPreview(active.card) : /* @__PURE__ */ jsx("div", { style: { padding: "12px", borderRadius: "8px", background: "#ffffff", boxShadow: "0 4px 12px rgba(0,0,0,0.3)", fontSize: "16px" }, children: active.card.title }) : null }),
182
+ note ? /* @__PURE__ */ jsx("p", { role: "status", style: { margin: "8px 0 0", fontSize: "16px" }, children: note }) : null
183
+ ]
184
+ }
185
+ ) });
186
+ }
187
+ function DragColumn({ column, children }) {
188
+ const { setNodeRef, isOver } = useDroppable({ id: column.id });
189
+ const shell = { ref: setNodeRef };
190
+ return /* @__PURE__ */ jsx(Fragment, { children: children(isOver ? { ...shell, "data-drop-over": "true" } : shell, isOver) });
191
+ }
192
+ function DragCard({ card, children }) {
193
+ const cfg = useContext(ConfigContext);
194
+ const { attributes, listeners, setNodeRef, isDragging } = useDraggable({ id: card.id, attributes: { role: "listitem", roleDescription: cfg?.texts.roleDescription ?? "" } });
195
+ const shell = { ref: setNodeRef, ...attributes, ...listeners ?? {} };
196
+ return /* @__PURE__ */ jsx(Fragment, { children: children(shell, isDragging) });
197
+ }
198
+ function boardDnd(config) {
199
+ return { Provider: BoardDndProvider, Column: DragColumn, Card: DragCard, config };
200
+ }
201
+ export {
202
+ BOARD_DND_SENSORS,
203
+ boardDnd,
204
+ buildAnnouncements,
205
+ columnShift,
206
+ findCard,
207
+ resolveDrop
208
+ };
@@ -0,0 +1,182 @@
1
+ import { ComponentType, ReactNode, HTMLAttributes, Ref } from 'react';
2
+
3
+ /** One card on the board. Display text is built by the caller (money, dates and names are formatted outside this package). */
4
+ interface BoardCard {
5
+ id: string;
6
+ title: string;
7
+ /** The version the card was read at: it goes back out with a move so a stale move is refused. */
8
+ version: number;
9
+ stageId: string;
10
+ /** For example "$1,200.00". Null or missing: no amount line. */
11
+ amountLine?: string | null;
12
+ /** For example "Close 2026-12-31". */
13
+ closeDateLine?: string | null;
14
+ overdue?: boolean;
15
+ ownerInitials?: string | null;
16
+ /** At most two are drawn. */
17
+ tags?: ReadonlyArray<{
18
+ id: string;
19
+ label: string;
20
+ }>;
21
+ /** A closed card shows its badge. */
22
+ badge?: 'won' | 'lost' | null;
23
+ }
24
+ /** open: new cards can be added here. won and lost: a stage that ends a deal. */
25
+ type BoardColumnKind = 'open' | 'won' | 'lost';
26
+ interface BoardColumnData {
27
+ id: string;
28
+ name: string;
29
+ kind: BoardColumnKind;
30
+ /** The number the header shows (may be larger than the cards drawn). */
31
+ count: number;
32
+ /** One ready-made line per currency, for example "$4,000.00". Never summed across currencies. */
33
+ totals: ReadonlyArray<string>;
34
+ cards: ReadonlyArray<BoardCard>;
35
+ /** More cards exist in this stage than are drawn. */
36
+ hasMore?: boolean;
37
+ }
38
+ /** What a move sends. `reason` is present only for a move into a lost stage. */
39
+ interface MoveRequest {
40
+ dealId: string;
41
+ toStageId: string;
42
+ expectedVersion: number;
43
+ reason?: string;
44
+ }
45
+ /** What a callback returns: nothing or an object without `error` is success; `{ error }` is a refusal a person can read. */
46
+ type BoardResult = {
47
+ error?: string;
48
+ [extra: string]: unknown;
49
+ } | void;
50
+ interface AddCardInput {
51
+ title: string;
52
+ /** The amount exactly as typed; empty means no amount. */
53
+ amount: string;
54
+ /** Empty when no currency applies. */
55
+ currency: string;
56
+ }
57
+ type MoveHandler = (request: MoveRequest) => Promise<BoardResult>;
58
+ type AddCardHandler = (stageId: string, input: AddCardInput) => Promise<BoardResult>;
59
+ /** Whether a card may be dropped on a stage. Pure; the caller supplies the app's rule (for example the one in @ordinatio/pipelines/board). */
60
+ type DropRule = (card: BoardCard, fromStageId: string, toStageId: string, columns: ReadonlyArray<BoardColumnData>) => boolean;
61
+ interface MoveTarget {
62
+ stageId: string;
63
+ label: string;
64
+ }
65
+ /** Every text arrives from outside (no English default lives in this package), so an app in any language shows only its own words. */
66
+ interface BoardTexts {
67
+ /** Accessible name of the scrolling row. */
68
+ boardLabel: string;
69
+ /** For example (2, 6) gives "Stage 2 of 6". */
70
+ stagePosition: (position: number, total: number) => string;
71
+ emptyBoard: string;
72
+ emptyColumn: string;
73
+ /** For example (4) gives "4 cards". */
74
+ columnCount: (count: number) => string;
75
+ showMore: string;
76
+ moving: string;
77
+ overdue: string;
78
+ won: string;
79
+ lost: string;
80
+ /** Spoken before the initials, for example "Owner". */
81
+ owner: string;
82
+ addCard: string;
83
+ addTitleLabel: string;
84
+ addAmountLabel: string;
85
+ addCurrencyLabel: string;
86
+ addSubmit: string;
87
+ addCancel: string;
88
+ /** Shown when the title is empty. */
89
+ addTitleRequired: string;
90
+ addPending: string;
91
+ moveLabel: string;
92
+ moveChoose: string;
93
+ moveSubmit: string;
94
+ movePending: string;
95
+ lostTitle: string;
96
+ lostSuggested: string;
97
+ lostUsed: string;
98
+ lostOwnLabel: string;
99
+ lostConfirm: string;
100
+ lostCancel: string;
101
+ /** Shown when no reason, or a reason of invalid shape, is chosen. */
102
+ lostRequired: string;
103
+ /** The button on a closed card that opens the reopen step. */
104
+ reopen: string;
105
+ reopenTitle: string;
106
+ reopenStageLabel: string;
107
+ reopenConfirm: string;
108
+ reopenCancel: string;
109
+ /** Shown when an action throws instead of returning a refusal. */
110
+ unexpectedError: string;
111
+ }
112
+ /** The parts of the board that can take a class name. Any part left out keeps a plain default look. */
113
+ interface BoardClassNames {
114
+ root?: string;
115
+ row?: string;
116
+ position?: string;
117
+ column?: string;
118
+ columnDropOver?: string;
119
+ columnHeader?: string;
120
+ columnName?: string;
121
+ columnCount?: string;
122
+ columnTotals?: string;
123
+ cardList?: string;
124
+ empty?: string;
125
+ card?: string;
126
+ cardPending?: string;
127
+ cardDragging?: string;
128
+ cardTitle?: string;
129
+ cardMeta?: string;
130
+ overdue?: string;
131
+ ownerMark?: string;
132
+ tagChip?: string;
133
+ badgeWon?: string;
134
+ badgeLost?: string;
135
+ cardError?: string;
136
+ showMore?: string;
137
+ addButton?: string;
138
+ addForm?: string;
139
+ input?: string;
140
+ select?: string;
141
+ primaryButton?: string;
142
+ secondaryButton?: string;
143
+ error?: string;
144
+ panel?: string;
145
+ panelTitle?: string;
146
+ choice?: string;
147
+ choiceActive?: string;
148
+ note?: string;
149
+ }
150
+ /** Wraps a card title, for example in the app's router link. Receives the title text as `children`. */
151
+ type RenderCardTitle = (card: BoardCard, children: ReactNode) => ReactNode;
152
+ /** What the drag layer (`@ordinatio/ui/board-dnd`) hands to the plain board. The plain board needs none of it: with no `dnd` it is complete (a menu moves cards). */
153
+ type CardShellProps = HTMLAttributes<HTMLLIElement> & {
154
+ ref?: Ref<HTMLLIElement>;
155
+ };
156
+ type ColumnShellProps = HTMLAttributes<HTMLElement> & {
157
+ ref?: Ref<HTMLElement>;
158
+ };
159
+ interface BoardDnd {
160
+ /** Wraps the whole board (the drag context, the drag preview and the plain-words announcements). */
161
+ Provider: ComponentType<{
162
+ columns: ReadonlyArray<BoardColumnData>;
163
+ onDrop: (cardId: string, toStageId: string) => void; /** The board's own veto (for example a Lost column with no lost-reason step): checked before the app's `canDrop`. */
164
+ allow?: (cardId: string, toStageId: string) => boolean;
165
+ config: unknown;
166
+ children: ReactNode;
167
+ }>;
168
+ /** Makes a column a drop target; calls its child with the attributes to spread on the column and whether a card is over it. */
169
+ Column: ComponentType<{
170
+ column: BoardColumnData;
171
+ children: (props: ColumnShellProps, over: boolean) => ReactNode;
172
+ }>;
173
+ /** Makes a card draggable; calls its child with the attributes to spread on the card and whether it is being dragged. */
174
+ Card: ComponentType<{
175
+ card: BoardCard;
176
+ children: (props: CardShellProps, dragging: boolean) => ReactNode;
177
+ }>;
178
+ /** Passed back to `Provider` as-is (the app's drop rule and the drag texts). */
179
+ config: unknown;
180
+ }
181
+
182
+ export type { AddCardHandler as A, BoardTexts as B, CardShellProps as C, DropRule as D, MoveHandler as M, RenderCardTitle as R, BoardClassNames as a, BoardColumnData as b, BoardCard as c, MoveTarget as d, BoardDnd as e, AddCardInput as f, BoardResult as g, BoardColumnKind as h, ColumnShellProps as i, MoveRequest as j };