@tapestry-ui/board 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +111 -2
- package/dist/board.d.ts +106 -0
- package/dist/board.js +192 -0
- package/package.json +55 -4
- package/styles.css +84 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Brandon Minton
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,112 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tapestry-ui/board
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A WCAG 2.1 AA kanban board for Preact. **Headless: you render the card, it moves it.**
|
|
4
|
+
|
|
5
|
+
Pointer drag between columns from a grip (so a finger can still scroll the
|
|
6
|
+
page), a keyboard path that is not a second-class citizen, announcements for
|
|
7
|
+
every move, and lanes for grouping cards inside a column.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i @tapestry-ui/board
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## What it is and is not
|
|
14
|
+
|
|
15
|
+
It owns the board's **shape and behaviour**: which card is in which column,
|
|
16
|
+
moving one, dragging one, the keyboard route, what gets said out loud, and
|
|
17
|
+
drawing grouped cards together.
|
|
18
|
+
|
|
19
|
+
It does not know what a card **means**. Priorities, owners, due dates, whether a
|
|
20
|
+
card is allowed in a column at all — all yours. The seam is `canMove`.
|
|
21
|
+
|
|
22
|
+
## Use
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { useBoard } from '@tapestry-ui/board';
|
|
26
|
+
import '@tapestry-ui/board/styles.css'; // optional
|
|
27
|
+
|
|
28
|
+
const board = useBoard({
|
|
29
|
+
columns, // [{ id, name }]
|
|
30
|
+
cards: stories,
|
|
31
|
+
columnOf: story => story.columnId,
|
|
32
|
+
labelOf: story => story.title, // for announcements, not rendering
|
|
33
|
+
onMove: (id, toColumnId) => save(id, toColumnId),
|
|
34
|
+
canMove: (story, to) =>
|
|
35
|
+
to === BACKLOG || story.priority ? true : 'it needs a priority first',
|
|
36
|
+
strings: UK_BOARD,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
<div class="tui-board">
|
|
40
|
+
<p {...board.liveProps}>{board.announcement}</p>
|
|
41
|
+
{columns.map(column => (
|
|
42
|
+
<div key={column.id} {...board.columnProps(column.id)}>
|
|
43
|
+
<h3>{column.name} <span>{board.cardsIn(column.id).length}</span></h3>
|
|
44
|
+
{board.blocksIn(column.id).map(block => (
|
|
45
|
+
<Lane key={block.group?.id ?? block.cards[0].id} name={block.group?.name}>
|
|
46
|
+
{block.cards.map(card => (
|
|
47
|
+
<article key={card.id} {...board.cardProps(card)}>
|
|
48
|
+
<button {...board.gripProps(card)} aria-label={board.moveLabel(card)}>⠿</button>
|
|
49
|
+
<YourCard card={card} />
|
|
50
|
+
</article>
|
|
51
|
+
))}
|
|
52
|
+
</Lane>
|
|
53
|
+
))}
|
|
54
|
+
</div>
|
|
55
|
+
))}
|
|
56
|
+
</div>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`moveTo(card, columnId)` is the keyboard path — wire it to a `<select>` or a
|
|
60
|
+
menu. Drag is the enhancement on top; it is never the only way.
|
|
61
|
+
|
|
62
|
+
## `canMove` is the whole domain seam
|
|
63
|
+
|
|
64
|
+
Return `true` to allow the move, or **a string**, which refuses it and *is the
|
|
65
|
+
reason*. The reason is announced in your own words and language:
|
|
66
|
+
|
|
67
|
+
> *Roof was not moved: it needs a priority first*
|
|
68
|
+
|
|
69
|
+
A card that silently fails to move tells a sighted reader nothing and a
|
|
70
|
+
screen-reader reader less than that.
|
|
71
|
+
|
|
72
|
+
## No copy lives in here
|
|
73
|
+
|
|
74
|
+
Every sentence this produces is assembled from a card name and a column name, so
|
|
75
|
+
`strings` is an object of **functions** — a format string cannot pluralise and
|
|
76
|
+
cannot make articles agree. `EN_BOARD` is the English default and exists so a
|
|
77
|
+
demo runs.
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const UK_BOARD: BoardStrings = {
|
|
81
|
+
moveLabel: card => `Перенести «${card}» до…`,
|
|
82
|
+
moved: (card, column) => `«${card}» перенесено до «${column}».`,
|
|
83
|
+
refused: (card, why) => `«${card}» не перенесено: ${why}`,
|
|
84
|
+
grabbed: card => `«${card}» взято. Перетягни або натисни Escape.`,
|
|
85
|
+
abandoned: card => `«${card}» повернуто.`,
|
|
86
|
+
};
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Behaviour worth knowing
|
|
90
|
+
|
|
91
|
+
- **A tap is not a drag.** Under 6px of travel nothing moves, because on a phone
|
|
92
|
+
the same gesture opens a card.
|
|
93
|
+
- **Escape always abandons** a drag, including one the pointer never returned
|
|
94
|
+
from, and says so.
|
|
95
|
+
- **A second finger cannot hijack** a drag in flight.
|
|
96
|
+
- **A right-click never starts one** — a context menu mid-drag leaves a drag
|
|
97
|
+
with no way out.
|
|
98
|
+
- **An empty-string column id is a real column.** The drop target is read from
|
|
99
|
+
the element, never from the truthiness of its id.
|
|
100
|
+
- **An unknown lane keeps its cards** and loses only its name, so a ledger older
|
|
101
|
+
than its code degrades rather than breaks.
|
|
102
|
+
|
|
103
|
+
## Styling
|
|
104
|
+
|
|
105
|
+
Skin it with custom properties and the `[data-part]` hooks (`column`, `card`,
|
|
106
|
+
`grip`, `live`); `[data-dragging]` and `[data-over]` reflect live state. **Never
|
|
107
|
+
fork the package to restyle it** — if a property is missing, add one.
|
|
108
|
+
|
|
109
|
+
It never owns scrolling and never constrains its container. You pick the scroll
|
|
110
|
+
region.
|
|
111
|
+
|
|
112
|
+
MIT.
|
package/dist/board.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/** The least a card can be. Everything else about it is the consumer's. */
|
|
2
|
+
export interface BoardItem {
|
|
3
|
+
id: string;
|
|
4
|
+
}
|
|
5
|
+
export interface BoardColumn {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A lane within a column -- eig's epics, drawn as a tinted box.
|
|
11
|
+
*
|
|
12
|
+
* Generic on purpose: the package knows a group has an id and a name and that
|
|
13
|
+
* its cards are drawn together. It does not know what a group IS.
|
|
14
|
+
*/
|
|
15
|
+
export interface BoardGroup {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
}
|
|
19
|
+
/** A drag in flight. `overColumnId` is null when the pointer is off any column. */
|
|
20
|
+
export interface BoardDrag {
|
|
21
|
+
cardId: string;
|
|
22
|
+
fromColumnId: string;
|
|
23
|
+
pointerId: number;
|
|
24
|
+
startX: number;
|
|
25
|
+
startY: number;
|
|
26
|
+
dx: number;
|
|
27
|
+
dy: number;
|
|
28
|
+
overColumnId: string | null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Everything this component says out loud.
|
|
32
|
+
*
|
|
33
|
+
* FUNCTIONS, not format strings, because a format string cannot pluralise and
|
|
34
|
+
* cannot agree with gender -- and these are read aloud by a screen reader,
|
|
35
|
+
* where a wrong plural is not a cosmetic bug.
|
|
36
|
+
*/
|
|
37
|
+
export interface BoardStrings {
|
|
38
|
+
/** The move control's accessible name. */
|
|
39
|
+
moveLabel: (card: string) => string;
|
|
40
|
+
/** A card has landed. The single most important thing this says. */
|
|
41
|
+
moved: (card: string, column: string) => string;
|
|
42
|
+
/** The consumer refused the move and gave a reason in its own words. */
|
|
43
|
+
refused: (card: string, reason: string) => string;
|
|
44
|
+
/** A drag has begun, for a reader who cannot see it lift. */
|
|
45
|
+
grabbed: (card: string) => string;
|
|
46
|
+
/** Escape, or a pointer that never came back. */
|
|
47
|
+
abandoned: (card: string) => string;
|
|
48
|
+
}
|
|
49
|
+
export declare const EN_BOARD: BoardStrings;
|
|
50
|
+
export interface BoardOptions<C extends BoardItem> {
|
|
51
|
+
columns: readonly BoardColumn[];
|
|
52
|
+
cards: readonly C[];
|
|
53
|
+
/** Which column a card is in right now. */
|
|
54
|
+
columnOf: (card: C) => string;
|
|
55
|
+
/** What to call a card when announcing it. Not a render -- a sentence. */
|
|
56
|
+
labelOf: (card: C) => string;
|
|
57
|
+
/** Commit the move. Called only after canMove has allowed it. */
|
|
58
|
+
onMove: (cardId: string, toColumnId: string) => void;
|
|
59
|
+
/**
|
|
60
|
+
* May this card go there?
|
|
61
|
+
*
|
|
62
|
+
* `true` allows it; a STRING refuses it and is the reason, in the consumer's
|
|
63
|
+
* own words and language. This is the entire domain seam -- eig answers "it
|
|
64
|
+
* needs a priority and a start date", babyland always allows.
|
|
65
|
+
*/
|
|
66
|
+
canMove?: (card: C, toColumnId: string) => true | string;
|
|
67
|
+
/** Which lane a card belongs to, if any. */
|
|
68
|
+
groupOf?: (card: C) => string | null;
|
|
69
|
+
groups?: readonly BoardGroup[];
|
|
70
|
+
/** Reading, not editing: no drag, no move control. */
|
|
71
|
+
disabled?: boolean;
|
|
72
|
+
strings?: BoardStrings;
|
|
73
|
+
}
|
|
74
|
+
type Spreadable = Record<string, unknown>;
|
|
75
|
+
/** One lane's worth of cards, or the ungrouped ones when `group` is null. */
|
|
76
|
+
export interface GroupBlock<C> {
|
|
77
|
+
group: BoardGroup | null;
|
|
78
|
+
cards: C[];
|
|
79
|
+
}
|
|
80
|
+
export interface Board<C extends BoardItem> {
|
|
81
|
+
/** Cards in a column, in the order they were given. */
|
|
82
|
+
cardsIn: (columnId: string) => C[];
|
|
83
|
+
/** A column's cards, with each lane's drawn together. Ungrouped cards keep
|
|
84
|
+
* their position; a lane appears where its FIRST card sits. */
|
|
85
|
+
blocksIn: (columnId: string) => GroupBlock<C>[];
|
|
86
|
+
/** Goes on the element that IS the column. Carries the drop target. */
|
|
87
|
+
columnProps: (columnId: string) => Spreadable;
|
|
88
|
+
cardProps: (card: C) => Spreadable;
|
|
89
|
+
/** The handle a drag starts from. A GRIP, not the whole card: on a phone the
|
|
90
|
+
* card must stay scrollable, which is the lesson @tapestry-ui/sortable
|
|
91
|
+
* learned the hard way. */
|
|
92
|
+
gripProps: (card: C) => Spreadable;
|
|
93
|
+
/** One option of a move control. `onPick` is yours to wire to a select or a menu. */
|
|
94
|
+
moveTo: (card: C, toColumnId: string) => void;
|
|
95
|
+
moveLabel: (card: C) => string;
|
|
96
|
+
/** Live region. Put it somewhere that stays mounted. */
|
|
97
|
+
liveProps: Spreadable;
|
|
98
|
+
announcement: string;
|
|
99
|
+
drag: BoardDrag | null;
|
|
100
|
+
/** True while this card is the one in flight -- for a lifted look. */
|
|
101
|
+
isDragging: (card: C) => boolean;
|
|
102
|
+
/** True while the pointer is over this column and would drop here. */
|
|
103
|
+
isOver: (columnId: string) => boolean;
|
|
104
|
+
}
|
|
105
|
+
export declare function useBoard<C extends BoardItem>(options: BoardOptions<C>): Board<C>;
|
|
106
|
+
export {};
|
package/dist/board.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// A KANBAN BOARD, HEADLESS.
|
|
2
|
+
//
|
|
3
|
+
// Citizen #11, extracted from eig's war room on 2026-11-23 after it had been
|
|
4
|
+
// the only board in the monorepo for two months and babyland wanted one too.
|
|
5
|
+
//
|
|
6
|
+
// WHAT IS HERE AND WHAT IS NOT is the whole design, and the line is NOT
|
|
7
|
+
// "complicated things go in the package". It is:
|
|
8
|
+
//
|
|
9
|
+
// HERE the SHAPE and the BEHAVIOUR -- columns, which card is in which,
|
|
10
|
+
// moving one, dragging one, the keyboard path, the announcements,
|
|
11
|
+
// the grouping of cards into named lanes.
|
|
12
|
+
// NOT HERE what a card MEANS. eig's P0-P4 priorities, its epics and their
|
|
13
|
+
// tints, its rule that a story may only sit in a column once it has
|
|
14
|
+
// a priority AND a scheduled start -- all of that is eig's, and a
|
|
15
|
+
// package that knew about any of it would be eig's board with a
|
|
16
|
+
// different import path.
|
|
17
|
+
//
|
|
18
|
+
// The seam between them is `canMove`: the consumer answers "may this card go
|
|
19
|
+
// there", in its own words, and this file does everything else.
|
|
20
|
+
//
|
|
21
|
+
// NO COPY LIVES HERE (Brandon's ruling, 2026-10-08). Every sentence this
|
|
22
|
+
// produces is assembled -- a card name, a column name, a count -- and a format
|
|
23
|
+
// string cannot pluralise, so `strings` is an object of FUNCTIONS. EN_BOARD is
|
|
24
|
+
// the English default and the only reason it exists is that a demo should run.
|
|
25
|
+
import { useEffect, useRef, useState } from "preact/hooks";
|
|
26
|
+
/** Pixels a pointer must travel before a press becomes a drag. Below this a
|
|
27
|
+
* tap is a tap -- on a phone, a card is also a thing you want to open. */
|
|
28
|
+
const DRAG_THRESHOLD_PX = 6;
|
|
29
|
+
/** Mouse button that drags. Right and middle must not, or a context menu
|
|
30
|
+
* becomes a half-finished drag the pointer never returns from. */
|
|
31
|
+
const PRIMARY_BUTTON = 0;
|
|
32
|
+
export const EN_BOARD = {
|
|
33
|
+
moveLabel: card => `Move ${card} to…`,
|
|
34
|
+
moved: (card, column) => `${card} moved to ${column}.`,
|
|
35
|
+
refused: (card, reason) => `${card} was not moved: ${reason}`,
|
|
36
|
+
grabbed: card => `${card} grabbed. Drag to a column, or press Escape.`,
|
|
37
|
+
abandoned: card => `${card} put back.`,
|
|
38
|
+
};
|
|
39
|
+
/** The column under a point, read from the DOM rather than from geometry we
|
|
40
|
+
* tracked: elementFromPoint is what the finger is actually over, and a layout
|
|
41
|
+
* that moved mid-drag cannot make it lie. */
|
|
42
|
+
function columnIdAtPoint(clientX, clientY) {
|
|
43
|
+
const under = document.elementFromPoint(clientX, clientY)?.closest("[data-board-column]");
|
|
44
|
+
// a column id may legitimately be "" (eig's backlog), so test the ELEMENT,
|
|
45
|
+
// never the truthiness of what it holds
|
|
46
|
+
return under ? under.dataset.boardColumn ?? null : null;
|
|
47
|
+
}
|
|
48
|
+
const startsADrag = (event) => event.pointerType !== "mouse" || event.button === PRIMARY_BUTTON;
|
|
49
|
+
export function useBoard(options) {
|
|
50
|
+
const { columns, cards, columnOf, labelOf, onMove, canMove, groupOf, groups = [], disabled = false, strings = EN_BOARD, } = options;
|
|
51
|
+
// A REF AS WELL AS STATE, and this is not belt-and-braces. A pointer handler
|
|
52
|
+
// closes over the render it was created in; without the ref, a move event
|
|
53
|
+
// arriving before the re-render reads a stale null and the drop is lost.
|
|
54
|
+
// @tapestry-ui/sortable found this; it is the same bug in a second shape.
|
|
55
|
+
const dragRef = useRef(null);
|
|
56
|
+
const [drag, setDragState] = useState(null);
|
|
57
|
+
const setDrag = (next) => { dragRef.current = next; setDragState(next); };
|
|
58
|
+
const [announcement, setAnnouncement] = useState("");
|
|
59
|
+
const nameOfColumn = new Map(columns.map(column => [column.id, column.name]));
|
|
60
|
+
const labelById = new Map(cards.map(card => [card.id, labelOf(card)]));
|
|
61
|
+
// A drag can be left in mid-air if the pointer never comes back -- a phone
|
|
62
|
+
// call, a dropped finger, a browser that swallowed the up event. Escape
|
|
63
|
+
// always abandons it, and the listener is registered ONCE so there is no
|
|
64
|
+
// window where a drag has begun and nothing is listening.
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
const abandonOnEscape = (event) => {
|
|
67
|
+
const current = dragRef.current;
|
|
68
|
+
if (event.key !== "Escape" || !current)
|
|
69
|
+
return;
|
|
70
|
+
setDrag(null);
|
|
71
|
+
setAnnouncement(strings.abandoned(labelById.get(current.cardId) ?? current.cardId));
|
|
72
|
+
};
|
|
73
|
+
window.addEventListener("keydown", abandonOnEscape);
|
|
74
|
+
return () => window.removeEventListener("keydown", abandonOnEscape);
|
|
75
|
+
// labelById is rebuilt every render; the listener only reads it on Escape,
|
|
76
|
+
// so re-registering per render would be churn for nothing
|
|
77
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
|
+
}, []);
|
|
79
|
+
const cardsIn = (columnId) => cards.filter(card => columnOf(card) === columnId);
|
|
80
|
+
function blocksIn(columnId) {
|
|
81
|
+
const inColumn = cardsIn(columnId);
|
|
82
|
+
if (!groupOf)
|
|
83
|
+
return inColumn.map(card => ({ group: null, cards: [card] }));
|
|
84
|
+
const blocks = [];
|
|
85
|
+
const byGroup = new Map();
|
|
86
|
+
for (const card of inColumn) {
|
|
87
|
+
const groupId = groupOf(card);
|
|
88
|
+
if (groupId === null) {
|
|
89
|
+
blocks.push({ group: null, cards: [card] });
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const existing = byGroup.get(groupId);
|
|
93
|
+
if (existing) {
|
|
94
|
+
existing.cards.push(card);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
// a lane appears where its FIRST card sits, so the column does not
|
|
98
|
+
// reshuffle when somebody tags a card half way down
|
|
99
|
+
const block = { group: groups.find(one => one.id === groupId) ?? { id: groupId, name: groupId }, cards: [card] };
|
|
100
|
+
byGroup.set(groupId, block);
|
|
101
|
+
blocks.push(block);
|
|
102
|
+
}
|
|
103
|
+
return blocks;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The one way a card changes column, whether by drag or by menu.
|
|
107
|
+
*
|
|
108
|
+
* A REFUSAL IS ANNOUNCED, not swallowed. A card that simply does not move
|
|
109
|
+
* tells a sighted reader nothing and a screen-reader reader less than that.
|
|
110
|
+
*/
|
|
111
|
+
function moveTo(card, toColumnId) {
|
|
112
|
+
if (disabled)
|
|
113
|
+
return;
|
|
114
|
+
const verdict = canMove ? canMove(card, toColumnId) : true;
|
|
115
|
+
if (verdict !== true) {
|
|
116
|
+
setAnnouncement(strings.refused(labelOf(card), verdict));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
onMove(card.id, toColumnId);
|
|
120
|
+
setAnnouncement(strings.moved(labelOf(card), nameOfColumn.get(toColumnId) ?? toColumnId));
|
|
121
|
+
}
|
|
122
|
+
const startDrag = (event, card) => {
|
|
123
|
+
if (disabled || dragRef.current || !startsADrag(event))
|
|
124
|
+
return;
|
|
125
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
126
|
+
// no text selection under a mouse, no page scroll under a finger
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
const fromColumnId = columnOf(card);
|
|
129
|
+
setDrag({
|
|
130
|
+
cardId: card.id, fromColumnId, pointerId: event.pointerId,
|
|
131
|
+
startX: event.clientX, startY: event.clientY, dx: 0, dy: 0, overColumnId: fromColumnId,
|
|
132
|
+
});
|
|
133
|
+
setAnnouncement(strings.grabbed(labelOf(card)));
|
|
134
|
+
};
|
|
135
|
+
const trackDrag = (event) => {
|
|
136
|
+
const current = dragRef.current;
|
|
137
|
+
if (!current || current.pointerId !== event.pointerId)
|
|
138
|
+
return;
|
|
139
|
+
setDrag({
|
|
140
|
+
...current,
|
|
141
|
+
dx: event.clientX - current.startX,
|
|
142
|
+
dy: event.clientY - current.startY,
|
|
143
|
+
overColumnId: columnIdAtPoint(event.clientX, event.clientY),
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
const endDrag = (event, card) => {
|
|
147
|
+
const current = dragRef.current;
|
|
148
|
+
if (!current || current.pointerId !== event.pointerId)
|
|
149
|
+
return;
|
|
150
|
+
const droppedOn = current.overColumnId;
|
|
151
|
+
const travelled = Math.abs(current.dx) + Math.abs(current.dy);
|
|
152
|
+
setDrag(null);
|
|
153
|
+
// a press that never travelled is a TAP, and a tap must not move anything:
|
|
154
|
+
// on a phone the same gesture opens the card
|
|
155
|
+
if (travelled < DRAG_THRESHOLD_PX)
|
|
156
|
+
return;
|
|
157
|
+
if (droppedOn !== null && droppedOn !== current.fromColumnId)
|
|
158
|
+
moveTo(card, droppedOn);
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
cardsIn,
|
|
162
|
+
blocksIn,
|
|
163
|
+
columnProps: columnId => ({
|
|
164
|
+
// the drop target, read by elementFromPoint. An empty id is legal.
|
|
165
|
+
"data-board-column": columnId,
|
|
166
|
+
"data-part": "column",
|
|
167
|
+
"data-over": drag?.overColumnId === columnId ? "" : undefined,
|
|
168
|
+
class: "tui-board__column",
|
|
169
|
+
}),
|
|
170
|
+
cardProps: card => ({
|
|
171
|
+
"data-board-card": card.id,
|
|
172
|
+
"data-part": "card",
|
|
173
|
+
"data-dragging": drag?.cardId === card.id ? "" : undefined,
|
|
174
|
+
class: "tui-board__card",
|
|
175
|
+
}),
|
|
176
|
+
gripProps: card => (disabled ? { "data-part": "grip", class: "tui-board__grip" } : {
|
|
177
|
+
"data-part": "grip",
|
|
178
|
+
class: "tui-board__grip",
|
|
179
|
+
onPointerDown: (event) => startDrag(event, card),
|
|
180
|
+
onPointerMove: trackDrag,
|
|
181
|
+
onPointerUp: (event) => endDrag(event, card),
|
|
182
|
+
onPointerCancel: (event) => endDrag(event, card),
|
|
183
|
+
}),
|
|
184
|
+
moveTo,
|
|
185
|
+
moveLabel: card => strings.moveLabel(labelOf(card)),
|
|
186
|
+
liveProps: { role: "status", "aria-live": "polite", "data-part": "live", class: "tui-board__live" },
|
|
187
|
+
announcement,
|
|
188
|
+
drag,
|
|
189
|
+
isDragging: card => drag?.cardId === card.id,
|
|
190
|
+
isOver: columnId => drag !== null && drag.overColumnId === columnId,
|
|
191
|
+
};
|
|
192
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tapestry-ui/board",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A WCAG 2.1 AA kanban board for Preact — pointer drag between columns, a keyboard move menu, announcements, grouped lanes. Headless: you render the card, it moves it.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Brandon Minton",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": [
|
|
9
|
+
"*.css"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/board.d.ts",
|
|
14
|
+
"default": "./dist/board.js"
|
|
15
|
+
},
|
|
16
|
+
"./styles.css": "./styles.css"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"styles.css",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc -p tsconfig.build.json",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"prepublishOnly": "npm run test && npm run build"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"preact": ">=10.24.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"jsdom": "^25.0.1",
|
|
36
|
+
"preact": "^10.29.4",
|
|
37
|
+
"typescript": "^6.0.3",
|
|
38
|
+
"vitest": "^4.1.10"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/ryurage/brandonminton.git",
|
|
43
|
+
"directory": "packages/tapestry-ui/board"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"preact",
|
|
47
|
+
"kanban",
|
|
48
|
+
"board",
|
|
49
|
+
"drag-and-drop",
|
|
50
|
+
"dnd",
|
|
51
|
+
"touch",
|
|
52
|
+
"a11y",
|
|
53
|
+
"wcag",
|
|
54
|
+
"headless",
|
|
55
|
+
"tapestry-ui"
|
|
56
|
+
]
|
|
57
|
+
}
|
package/styles.css
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/* @tapestry-ui/board — the optional skin.
|
|
2
|
+
*
|
|
3
|
+
* OPTIONAL is the point. The hook renders nothing; these are the few rules a
|
|
4
|
+
* board cannot do without, written so a consumer can take them and then dress
|
|
5
|
+
* everything through custom properties rather than forking the package.
|
|
6
|
+
*
|
|
7
|
+
* THE CONTAINER CONTRACT (the house rule): this never owns scrolling and never
|
|
8
|
+
* constrains its container. The columns lay out in whatever width they are
|
|
9
|
+
* given, and the consumer picks the scroll region. A package that decided to be
|
|
10
|
+
* 100vh tall would be unusable in a panel, which is exactly where eig puts it. */
|
|
11
|
+
|
|
12
|
+
.tui-board {
|
|
13
|
+
--tui-board-gap: 12px;
|
|
14
|
+
--tui-board-column-min: 0;
|
|
15
|
+
--tui-board-card-bg: transparent;
|
|
16
|
+
--tui-board-card-radius: 10px;
|
|
17
|
+
--tui-board-card-pad: 10px;
|
|
18
|
+
--tui-board-over-outline: 2px dashed currentColor;
|
|
19
|
+
--tui-board-lift-shadow: 0 6px 16px rgb(0 0 0 / 0.25);
|
|
20
|
+
|
|
21
|
+
display: grid;
|
|
22
|
+
/* auto-fit rather than a fixed count: the consumer decides the breakpoint by
|
|
23
|
+
* setting --tui-board-column-min, and one column on a phone is the default */
|
|
24
|
+
grid-template-columns: repeat(auto-fit, minmax(var(--tui-board-column-min), 1fr));
|
|
25
|
+
gap: var(--tui-board-gap);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.tui-board__column {
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
gap: var(--tui-board-gap);
|
|
32
|
+
/* a column must be a drop target even when it holds nothing, or the only way
|
|
33
|
+
* to empty a column is to never need to */
|
|
34
|
+
min-height: 2rem;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* reflects the live drag; [data-over] is behaviour, the class is the hook */
|
|
38
|
+
.tui-board__column[data-over] {
|
|
39
|
+
outline: var(--tui-board-over-outline);
|
|
40
|
+
outline-offset: 2px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.tui-board__card {
|
|
44
|
+
background: var(--tui-board-card-bg);
|
|
45
|
+
border-radius: var(--tui-board-card-radius);
|
|
46
|
+
padding: var(--tui-board-card-pad);
|
|
47
|
+
/* a lifted card must not swallow the pointer test underneath it, or
|
|
48
|
+
* elementFromPoint returns the card being dragged instead of the column */
|
|
49
|
+
position: relative;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.tui-board__card[data-dragging] {
|
|
53
|
+
box-shadow: var(--tui-board-lift-shadow);
|
|
54
|
+
opacity: 0.9;
|
|
55
|
+
pointer-events: none;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.tui-board__grip {
|
|
59
|
+
/* the drag starts HERE, not on the card, so a finger can still scroll the
|
|
60
|
+
* page by dragging the card body — @tapestry-ui/sortable's hard-won rule */
|
|
61
|
+
touch-action: none;
|
|
62
|
+
cursor: grab;
|
|
63
|
+
background: none;
|
|
64
|
+
border: 0;
|
|
65
|
+
padding: 4px;
|
|
66
|
+
font: inherit;
|
|
67
|
+
color: inherit;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.tui-board__grip:active { cursor: grabbing; }
|
|
71
|
+
|
|
72
|
+
/* Announcements are for screen readers and must not take space. Not
|
|
73
|
+
* `display: none`, which removes them from the accessibility tree too. */
|
|
74
|
+
.tui-board__live {
|
|
75
|
+
position: absolute;
|
|
76
|
+
width: 1px;
|
|
77
|
+
height: 1px;
|
|
78
|
+
padding: 0;
|
|
79
|
+
margin: -1px;
|
|
80
|
+
overflow: hidden;
|
|
81
|
+
clip-path: inset(50%);
|
|
82
|
+
white-space: nowrap;
|
|
83
|
+
border: 0;
|
|
84
|
+
}
|