@reactloom/dnd 0.0.0-stage → 1.0.1
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/README.md +30 -2
- package/dist/LICENSE +21 -0
- package/dist/_internal/hooks/use-controllable-state.js +24 -0
- package/dist/_internal/hooks/use-controllable-state.js.map +1 -0
- package/dist/_internal/hooks/use-isomorphic-layout-effect.js +7 -0
- package/dist/_internal/hooks/use-isomorphic-layout-effect.js.map +1 -0
- package/dist/dnd.module.js +30 -0
- package/dist/dnd.module.js.map +1 -0
- package/dist/drag.d.ts +26 -0
- package/dist/drag.d.ts.map +1 -0
- package/dist/drag.js +72 -0
- package/dist/drag.js.map +1 -0
- package/dist/flow-canvas.d.ts +33 -0
- package/dist/flow-canvas.d.ts.map +1 -0
- package/dist/flow-canvas.js +201 -0
- package/dist/flow-canvas.js.map +1 -0
- package/dist/flow-canvas.module.js +34 -0
- package/dist/flow-canvas.module.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/kanban-board.d.ts +29 -0
- package/dist/kanban-board.d.ts.map +1 -0
- package/dist/kanban-board.js +185 -0
- package/dist/kanban-board.js.map +1 -0
- package/dist/kanban.module.js +32 -0
- package/dist/kanban.module.js.map +1 -0
- package/dist/sortable.d.ts +25 -0
- package/dist/sortable.d.ts.map +1 -0
- package/dist/sortable.js +133 -0
- package/dist/sortable.js.map +1 -0
- package/dist/styles.css +3 -0
- package/dist/transfer.d.ts +21 -0
- package/dist/transfer.d.ts.map +1 -0
- package/dist/transfer.js +144 -0
- package/dist/transfer.js.map +1 -0
- package/package.json +95 -3
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useIsomorphicLayoutEffect } from "./_internal/hooks/use-isomorphic-layout-effect.js";
|
|
3
|
+
import { DragHandle, restoreMoveFocus, useDragScope, useItemDrop } from "./drag.js";
|
|
4
|
+
import kanban_module_default from "./kanban.module.js";
|
|
5
|
+
import { useRef, useState } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// src/kanban-board.tsx
|
|
8
|
+
var defaults = {
|
|
9
|
+
drag: (card) => `Drag ${card}`,
|
|
10
|
+
move: (card) => `Move ${card} to column`,
|
|
11
|
+
earlier: (card) => `Move ${card} earlier`,
|
|
12
|
+
later: (card) => `Move ${card} later`,
|
|
13
|
+
moved: (card, column, position) => `${card} moved to ${column}, position ${position}.`,
|
|
14
|
+
empty: "No cards"
|
|
15
|
+
};
|
|
16
|
+
function CardRow({ card, previous, next, nextAfter, columns, scopeRef, messages, disabled, renderCard, move, register }) {
|
|
17
|
+
const { ref, dropProps, isDropTarget } = useItemDrop(scopeRef, (id) => id !== card.id, (id, handle) => move(id, card.columnId, card.id, handle), disabled);
|
|
18
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
19
|
+
...dropProps,
|
|
20
|
+
ref,
|
|
21
|
+
tabIndex: -1,
|
|
22
|
+
"aria-label": card.label,
|
|
23
|
+
className: kanban_module_default.card,
|
|
24
|
+
"data-drop-target": isDropTarget || void 0,
|
|
25
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
26
|
+
className: kanban_module_default.cardTop,
|
|
27
|
+
children: [/* @__PURE__ */ jsx(DragHandle, {
|
|
28
|
+
scopeRef,
|
|
29
|
+
item: card,
|
|
30
|
+
label: messages.drag(card.label),
|
|
31
|
+
disabled
|
|
32
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
33
|
+
className: kanban_module_default.cardContent,
|
|
34
|
+
children: renderCard ? renderCard(card) : card.label
|
|
35
|
+
})]
|
|
36
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
37
|
+
className: kanban_module_default.controls,
|
|
38
|
+
children: [
|
|
39
|
+
/* @__PURE__ */ jsx("select", {
|
|
40
|
+
className: kanban_module_default.destination,
|
|
41
|
+
"aria-label": messages.move(card.label),
|
|
42
|
+
value: card.columnId,
|
|
43
|
+
disabled,
|
|
44
|
+
ref: (control) => register(card.id, control),
|
|
45
|
+
onChange: (event) => move(card.id, event.target.value, void 0, "column"),
|
|
46
|
+
children: columns.map(({ id, label }) => /* @__PURE__ */ jsx("option", {
|
|
47
|
+
value: id,
|
|
48
|
+
children: label
|
|
49
|
+
}, id))
|
|
50
|
+
}),
|
|
51
|
+
/* @__PURE__ */ jsx("button", {
|
|
52
|
+
type: "button",
|
|
53
|
+
className: kanban_module_default.reorder,
|
|
54
|
+
"aria-label": messages.earlier(card.label),
|
|
55
|
+
disabled,
|
|
56
|
+
"aria-disabled": !previous || void 0,
|
|
57
|
+
onClick: (event) => {
|
|
58
|
+
if (previous) move(card.id, card.columnId, previous.id, event.currentTarget);
|
|
59
|
+
},
|
|
60
|
+
children: "↑"
|
|
61
|
+
}),
|
|
62
|
+
/* @__PURE__ */ jsx("button", {
|
|
63
|
+
type: "button",
|
|
64
|
+
className: kanban_module_default.reorder,
|
|
65
|
+
"aria-label": messages.later(card.label),
|
|
66
|
+
disabled,
|
|
67
|
+
"aria-disabled": !next || void 0,
|
|
68
|
+
onClick: (event) => {
|
|
69
|
+
if (next) move(card.id, card.columnId, nextAfter?.id, event.currentTarget);
|
|
70
|
+
},
|
|
71
|
+
children: "↓"
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
})]
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function Lane({ column, cards, ...actions }) {
|
|
78
|
+
const { scopeRef, disabled, move, messages } = actions;
|
|
79
|
+
const { ref, dropProps, isDropTarget } = useItemDrop(scopeRef, () => true, (id, handle) => move(id, column.id, void 0, handle), disabled);
|
|
80
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
81
|
+
...dropProps,
|
|
82
|
+
ref,
|
|
83
|
+
tabIndex: -1,
|
|
84
|
+
"aria-label": column.label,
|
|
85
|
+
className: kanban_module_default.lane,
|
|
86
|
+
"data-drop-target": isDropTarget || void 0,
|
|
87
|
+
children: [/* @__PURE__ */ jsx("strong", {
|
|
88
|
+
className: kanban_module_default.laneLabel,
|
|
89
|
+
children: column.label
|
|
90
|
+
}), cards.length === 0 ? /* @__PURE__ */ jsx("p", {
|
|
91
|
+
className: kanban_module_default.empty,
|
|
92
|
+
children: messages.empty
|
|
93
|
+
}) : /* @__PURE__ */ jsx("ol", {
|
|
94
|
+
role: "list",
|
|
95
|
+
className: kanban_module_default.cards,
|
|
96
|
+
children: cards.map((card, i) => /* @__PURE__ */ jsx(CardRow, {
|
|
97
|
+
card,
|
|
98
|
+
previous: cards[i - 1],
|
|
99
|
+
next: cards[i + 1],
|
|
100
|
+
nextAfter: cards[i + 2],
|
|
101
|
+
...actions
|
|
102
|
+
}, card.id))
|
|
103
|
+
})]
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function KanbanBoard({ label, columns, cards, onChange, renderCard, disabled = false, messages: overrides, className }) {
|
|
107
|
+
const scopeRef = useDragScope();
|
|
108
|
+
const controls = useRef(/* @__PURE__ */ new Map());
|
|
109
|
+
const pending = useRef(null);
|
|
110
|
+
const [status, setStatus] = useState("");
|
|
111
|
+
const messages = {
|
|
112
|
+
...defaults,
|
|
113
|
+
...overrides
|
|
114
|
+
};
|
|
115
|
+
const announce = overrides?.moved ?? defaults.moved;
|
|
116
|
+
useIsomorphicLayoutEffect(() => {
|
|
117
|
+
const change = pending.current;
|
|
118
|
+
if (!change) return;
|
|
119
|
+
const card = cards.filter(({ columnId }) => columnId === change.columnId)[change.position];
|
|
120
|
+
const column = columns.find(({ id }) => id === change.columnId);
|
|
121
|
+
if (card?.id !== change.id || !column) return;
|
|
122
|
+
pending.current = null;
|
|
123
|
+
const control = controls.current.get(change.id);
|
|
124
|
+
const focus = change.focus === "column" ? control : change.focus?.isConnected ? change.focus : control;
|
|
125
|
+
restoreMoveFocus(change.previous, focus);
|
|
126
|
+
setStatus(announce(card.label, column.label, change.position + 1));
|
|
127
|
+
}, [
|
|
128
|
+
cards,
|
|
129
|
+
columns,
|
|
130
|
+
announce
|
|
131
|
+
]);
|
|
132
|
+
function register(id, control) {
|
|
133
|
+
if (control) controls.current.set(id, control);
|
|
134
|
+
else controls.current.delete(id);
|
|
135
|
+
}
|
|
136
|
+
function move(id, columnId, before, focus) {
|
|
137
|
+
const card = cards.find((item) => item.id === id);
|
|
138
|
+
if (disabled || !card || before === id || !columns.some((column) => column.id === columnId)) return;
|
|
139
|
+
const ordered = cards.filter((item) => item !== card);
|
|
140
|
+
const target = before === void 0 ? -1 : ordered.findIndex((item) => item.id === before && item.columnId === columnId);
|
|
141
|
+
const index = target < 0 ? ordered.length : target;
|
|
142
|
+
const position = ordered.slice(0, index).filter((item) => item.columnId === columnId).length;
|
|
143
|
+
const prior = cards.filter((item) => item.columnId === card.columnId).indexOf(card);
|
|
144
|
+
if (card.columnId === columnId && position === prior) return;
|
|
145
|
+
ordered.splice(index, 0, {
|
|
146
|
+
...card,
|
|
147
|
+
columnId
|
|
148
|
+
});
|
|
149
|
+
pending.current = {
|
|
150
|
+
id,
|
|
151
|
+
columnId,
|
|
152
|
+
position,
|
|
153
|
+
focus,
|
|
154
|
+
previous: controls.current.get(id)?.ownerDocument.activeElement ?? null
|
|
155
|
+
};
|
|
156
|
+
onChange(ordered);
|
|
157
|
+
}
|
|
158
|
+
const classNames = className ? `${kanban_module_default.board} ${className}` : kanban_module_default.board;
|
|
159
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
160
|
+
role: "group",
|
|
161
|
+
"aria-label": label,
|
|
162
|
+
className: classNames,
|
|
163
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
164
|
+
className: kanban_module_default.lanes,
|
|
165
|
+
children: columns.map((column) => /* @__PURE__ */ jsx(Lane, {
|
|
166
|
+
column,
|
|
167
|
+
cards: cards.filter(({ columnId }) => columnId === column.id),
|
|
168
|
+
columns,
|
|
169
|
+
scopeRef,
|
|
170
|
+
messages,
|
|
171
|
+
disabled,
|
|
172
|
+
renderCard,
|
|
173
|
+
move,
|
|
174
|
+
register
|
|
175
|
+
}, column.id))
|
|
176
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
177
|
+
role: "status",
|
|
178
|
+
className: kanban_module_default.announcement,
|
|
179
|
+
children: status
|
|
180
|
+
})]
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
export { KanbanBoard };
|
|
184
|
+
|
|
185
|
+
//# sourceMappingURL=kanban-board.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kanban-board.js","names":["styles"],"sources":["../src/kanban-board.tsx"],"sourcesContent":["'use client';\n\nimport { useRef, useState, type ReactNode } from 'react';\nimport { useIsomorphicLayoutEffect } from '@reactloom/hooks';\nimport { DragHandle, restoreMoveFocus, useDragScope, useItemDrop, type DragItem } from './drag.js';\nimport styles from './kanban.module.css';\n\nexport interface KanbanColumn { id: string; label: string }\nexport interface KanbanCard extends DragItem { columnId: string }\n\nexport interface KanbanBoardProps<T extends KanbanCard> {\n label: string;\n columns: readonly KanbanColumn[];\n cards: readonly T[];\n onChange: (cards: T[]) => void;\n renderCard?: (card: T) => ReactNode;\n disabled?: boolean;\n messages?: Partial<KanbanMessages>;\n className?: string;\n}\n\nexport interface KanbanMessages {\n drag: (card: string) => string;\n move: (card: string) => string;\n earlier: (card: string) => string;\n later: (card: string) => string;\n moved: (card: string, column: string, position: number) => string;\n empty: string;\n}\n\nconst defaults: KanbanMessages = {\n drag: (card) => `Drag ${card}`,\n move: (card) => `Move ${card} to column`,\n earlier: (card) => `Move ${card} earlier`,\n later: (card) => `Move ${card} later`,\n moved: (card, column, position) => `${card} moved to ${column}, position ${position}.`,\n empty: 'No cards',\n};\n\ninterface LaneActions<T extends KanbanCard> {\n columns: readonly KanbanColumn[];\n scopeRef: ReturnType<typeof useDragScope>;\n messages: KanbanMessages;\n disabled: boolean;\n renderCard?: (card: T) => ReactNode;\n move: (id: string, columnId: string, before: string | undefined, focus?: 'column' | HTMLButtonElement) => void;\n register: (id: string, control: HTMLSelectElement | null) => void;\n}\n\nfunction CardRow<T extends KanbanCard>({ card, previous, next, nextAfter, columns, scopeRef, messages, disabled, renderCard, move, register }: LaneActions<T> & {\n card: T;\n previous?: T;\n next?: T;\n nextAfter?: T;\n}) {\n const { ref, dropProps, isDropTarget } = useItemDrop<HTMLLIElement>(scopeRef, (id) => id !== card.id,\n (id, handle) => move(id, card.columnId, card.id, handle), disabled);\n return (\n <li {...dropProps} ref={ref} tabIndex={-1} aria-label={card.label}\n className={styles.card} data-drop-target={isDropTarget || undefined}>\n <div className={styles.cardTop}>\n <DragHandle scopeRef={scopeRef} item={card} label={messages.drag(card.label)} disabled={disabled} />\n <div className={styles.cardContent}>{renderCard ? renderCard(card) : card.label}</div>\n </div>\n <div className={styles.controls}>\n <select className={styles.destination} aria-label={messages.move(card.label)} value={card.columnId}\n disabled={disabled} ref={(control) => register(card.id, control)}\n onChange={(event) => move(card.id, event.target.value, undefined, 'column')}>\n {columns.map(({ id, label }) => <option value={id} key={id}>{label}</option>)}\n </select>\n <button type=\"button\" className={styles.reorder} aria-label={messages.earlier(card.label)}\n disabled={disabled} aria-disabled={!previous || undefined}\n onClick={(event) => { if (previous) move(card.id, card.columnId, previous.id, event.currentTarget); }}>↑</button>\n <button type=\"button\" className={styles.reorder} aria-label={messages.later(card.label)}\n disabled={disabled} aria-disabled={!next || undefined}\n onClick={(event) => { if (next) move(card.id, card.columnId, nextAfter?.id, event.currentTarget); }}>↓</button>\n </div>\n </li>\n );\n}\n\nfunction Lane<T extends KanbanCard>({ column, cards, ...actions }: LaneActions<T> & { column: KanbanColumn; cards: readonly T[] }) {\n const { scopeRef, disabled, move, messages } = actions;\n const { ref, dropProps, isDropTarget } = useItemDrop<HTMLElement>(scopeRef, () => true,\n (id, handle) => move(id, column.id, undefined, handle), disabled);\n return (\n <section {...dropProps} ref={ref} tabIndex={-1} aria-label={column.label} className={styles.lane}\n data-drop-target={isDropTarget || undefined}>\n <strong className={styles.laneLabel}>{column.label}</strong>\n {cards.length === 0 ? <p className={styles.empty}>{messages.empty}</p> : (\n // eslint-disable-next-line jsx-a11y/no-redundant-roles -- Keep Safari list semantics with custom styles.\n <ol role=\"list\" className={styles.cards}>\n {cards.map((card, i) => <CardRow key={card.id} card={card} previous={cards[i - 1]} next={cards[i + 1]} nextAfter={cards[i + 2]} {...actions} />)}\n </ol>\n )}\n </section>\n );\n}\n\nexport function KanbanBoard<T extends KanbanCard>({\n label, columns, cards, onChange, renderCard, disabled = false, messages: overrides, className,\n}: KanbanBoardProps<T>) {\n const scopeRef = useDragScope();\n const controls = useRef(new Map<string, HTMLSelectElement>());\n const pending = useRef<{ id: string; columnId: string; position: number; previous: Element | null; focus?: 'column' | HTMLButtonElement } | null>(null);\n const [status, setStatus] = useState('');\n const messages = { ...defaults, ...overrides };\n const announce = overrides?.moved ?? defaults.moved;\n\n useIsomorphicLayoutEffect(() => {\n const change = pending.current;\n if (!change) return;\n const lane = cards.filter(({ columnId }) => columnId === change.columnId);\n const card = lane[change.position];\n const column = columns.find(({ id }) => id === change.columnId);\n if (card?.id !== change.id || !column) return;\n pending.current = null;\n const control = controls.current.get(change.id);\n const focus = change.focus === 'column' ? control : change.focus?.isConnected ? change.focus : control;\n restoreMoveFocus(change.previous, focus);\n setStatus(announce(card.label, column.label, change.position + 1));\n }, [cards, columns, announce]);\n\n function register(id: string, control: HTMLSelectElement | null) {\n if (control) controls.current.set(id, control);\n else controls.current.delete(id);\n }\n\n function move(id: string, columnId: string, before: string | undefined, focus?: 'column' | HTMLButtonElement) {\n const card = cards.find((item) => item.id === id);\n if (disabled || !card || before === id || !columns.some((column) => column.id === columnId)) return;\n const ordered = cards.filter((item) => item !== card);\n const target = before === undefined ? -1 : ordered.findIndex((item) => item.id === before && item.columnId === columnId);\n const index = target < 0 ? ordered.length : target;\n const position = ordered.slice(0, index).filter((item) => item.columnId === columnId).length;\n const prior = cards.filter((item) => item.columnId === card.columnId).indexOf(card);\n if (card.columnId === columnId && position === prior) return;\n ordered.splice(index, 0, { ...card, columnId });\n pending.current = { id, columnId, position, focus, previous: controls.current.get(id)?.ownerDocument.activeElement ?? null };\n onChange(ordered);\n }\n\n const classNames = className ? `${styles.board} ${className}` : styles.board;\n return (\n <div role=\"group\" aria-label={label} className={classNames}>\n <div className={styles.lanes}>\n {columns.map((column) => <Lane key={column.id} column={column} cards={cards.filter(({ columnId }) => columnId === column.id)}\n columns={columns} scopeRef={scopeRef} messages={messages} disabled={disabled} renderCard={renderCard} move={move} register={register} />)}\n </div>\n <div role=\"status\" className={styles.announcement}>{status}</div>\n </div>\n );\n}\n"],"mappings":";;;;;;;AA8BA,IAAM,WAA2B;CAC/B,OAAO,SAAS,QAAQ;CACxB,OAAO,SAAS,QAAQ,KAAK;CAC7B,UAAU,SAAS,QAAQ,KAAK;CAChC,QAAQ,SAAS,QAAQ,KAAK;CAC9B,QAAQ,MAAM,QAAQ,aAAa,GAAG,KAAK,YAAY,OAAO,aAAa,SAAS;CACpF,OAAO;AACT;AAYA,SAAS,QAA8B,EAAE,MAAM,UAAU,MAAM,WAAW,SAAS,UAAU,UAAU,UAAU,YAAY,MAAM,YAKhI;CACD,MAAM,EAAE,KAAK,WAAW,iBAAiB,YAA2B,WAAW,OAAO,OAAO,KAAK,KAC/F,IAAI,WAAW,KAAK,IAAI,KAAK,UAAU,KAAK,IAAI,MAAM,GAAG,QAAQ;CACpE,OACE,qBAAC,MAAD;EAAI,GAAI;EAAgB;EAAK,UAAU;EAAI,cAAY,KAAK;EAC1D,WAAWA,sBAAO;EAAM,oBAAkB,gBAAgB,KAAA;EAD5D,UAAA,CAEE,qBAAC,OAAD;GAAK,WAAWA,sBAAO;GAAvB,UAAA,CACE,oBAAC,YAAD;IAAsB;IAAU,MAAM;IAAM,OAAO,SAAS,KAAK,KAAK,KAAK;IAAa;GAAW,CAAA,GACnG,oBAAC,OAAD;IAAK,WAAWA,sBAAO;IAAc,UAAA,aAAa,WAAW,IAAI,IAAI,KAAK;GAAW,CAAA,CAClF;EACL,CAAA,GAAA,qBAAC,O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,oBAAC,MAAD;IAA8B;IAAQ,OAAO,MAAM,QAAQ,EAAE,eAAe,aAAa,OAAO,EAAE;IAChH;IAAmB;IAAoB;IAAoB;IAAsB;IAAkB;IAAgB;GAAW,GADrG,OAAO,EAC8F,CAAC;EACvI,CAAA,GACL,oBAAC,OAAD;GAAK,MAAK;GAAS,WAAWA,sBAAO;GAAe,UAAA;EAAY,CAAA,CAC7D;;AAET"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/kanban.module.css
|
|
2
|
+
var board = "pl-kanban-board-wg5uGC";
|
|
3
|
+
var lanes = "pl-kanban-lanes-wg5uGC";
|
|
4
|
+
var lane = "pl-kanban-lane-wg5uGC";
|
|
5
|
+
var laneLabel = "pl-kanban-lane-label-wg5uGC";
|
|
6
|
+
var cards = "pl-kanban-cards-wg5uGC";
|
|
7
|
+
var card = "pl-kanban-card-wg5uGC";
|
|
8
|
+
var cardTop = "pl-kanban-card-top-wg5uGC";
|
|
9
|
+
var controls = "pl-kanban-controls-wg5uGC";
|
|
10
|
+
var cardContent = "pl-kanban-card-content-wg5uGC";
|
|
11
|
+
var destination = "pl-kanban-destination-wg5uGC";
|
|
12
|
+
var reorder = "pl-kanban-reorder-wg5uGC";
|
|
13
|
+
var empty = "pl-kanban-empty-wg5uGC";
|
|
14
|
+
var announcement = "pl-kanban-announcement-wg5uGC";
|
|
15
|
+
var kanban_module_default = {
|
|
16
|
+
board,
|
|
17
|
+
lanes,
|
|
18
|
+
lane,
|
|
19
|
+
laneLabel,
|
|
20
|
+
cards,
|
|
21
|
+
card,
|
|
22
|
+
cardTop,
|
|
23
|
+
controls,
|
|
24
|
+
cardContent,
|
|
25
|
+
destination,
|
|
26
|
+
reorder,
|
|
27
|
+
empty,
|
|
28
|
+
announcement
|
|
29
|
+
};
|
|
30
|
+
export { announcement, board, card, cardContent, cardTop, cards, controls, kanban_module_default as default, destination, empty, lane, laneLabel, lanes, reorder };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=kanban.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kanban.module.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type DragItem } from './drag.js';
|
|
3
|
+
export interface SortableMessages {
|
|
4
|
+
drag: (item: string) => string;
|
|
5
|
+
drop: (item: string, position: number) => string;
|
|
6
|
+
earlier: (item: string) => string;
|
|
7
|
+
later: (item: string) => string;
|
|
8
|
+
moved: (item: string, position: number, total: number) => string;
|
|
9
|
+
}
|
|
10
|
+
export interface SortableListProps<T extends DragItem> {
|
|
11
|
+
label: string;
|
|
12
|
+
items: readonly T[];
|
|
13
|
+
onChange: (items: T[]) => void;
|
|
14
|
+
renderItem?: (item: T) => ReactNode;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
messages?: Partial<SortableMessages>;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface SortableGridProps<T extends DragItem> extends SortableListProps<T> {
|
|
20
|
+
/** Maximum columns. The layout uses fewer columns in narrower containers. */
|
|
21
|
+
columns?: number;
|
|
22
|
+
}
|
|
23
|
+
export declare function SortableList<T extends DragItem>(props: SortableListProps<T>): import("react").JSX.Element;
|
|
24
|
+
export declare function SortableGrid<T extends DragItem>({ columns, ...props }: SortableGridProps<T>): import("react").JSX.Element;
|
|
25
|
+
//# sourceMappingURL=sortable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortable.d.ts","sourceRoot":"","sources":["../src/sortable.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAwC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE7E,OAAO,EAA2D,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGnG,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAC/B,IAAI,EAAE,CA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Focus, useDragScope, useItemDrop } from "./drag.js";
|
|
4
|
+
import dnd_module_default from "./dnd.module.js";
|
|
5
|
+
import { useRef, useState } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// src/sortable.tsx
|
|
8
|
+
var defaults = {
|
|
9
|
+
drag: (item) => `Drag ${item}`,
|
|
10
|
+
drop: (item, position) => `Position ${position}: ${item}`,
|
|
11
|
+
earlier: (item) => `Move ${item} earlier`,
|
|
12
|
+
later: (item) => `Move ${item} later`,
|
|
13
|
+
moved: (item, position, total) => `${item} moved to position ${position} of ${total}.`
|
|
14
|
+
};
|
|
15
|
+
function SortableRow({ item, index, total, scopeRef, disabled, messages, children, onMove }) {
|
|
16
|
+
const { ref, dropProps, isDropTarget } = useItemDrop(scopeRef, (id) => id !== item.id, (id, handle) => onMove(id, index, handle), disabled);
|
|
17
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
18
|
+
...dropProps,
|
|
19
|
+
ref,
|
|
20
|
+
tabIndex: -1,
|
|
21
|
+
"aria-label": messages.drop(item.label, index + 1),
|
|
22
|
+
className: dnd_module_default.item,
|
|
23
|
+
"data-drop-target": isDropTarget || void 0,
|
|
24
|
+
children: [
|
|
25
|
+
/* @__PURE__ */ jsx(DragHandle, {
|
|
26
|
+
scopeRef,
|
|
27
|
+
item,
|
|
28
|
+
label: messages.drag(item.label),
|
|
29
|
+
disabled
|
|
30
|
+
}),
|
|
31
|
+
/* @__PURE__ */ jsx("div", {
|
|
32
|
+
className: dnd_module_default.content,
|
|
33
|
+
children
|
|
34
|
+
}),
|
|
35
|
+
/* @__PURE__ */ jsxs("div", {
|
|
36
|
+
className: dnd_module_default.actions,
|
|
37
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
38
|
+
type: "button",
|
|
39
|
+
className: dnd_module_default.button,
|
|
40
|
+
"aria-label": messages.earlier(item.label),
|
|
41
|
+
disabled,
|
|
42
|
+
"aria-disabled": index === 0,
|
|
43
|
+
onClick: (event) => onMove(item.id, index - 1, event.currentTarget),
|
|
44
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
45
|
+
"aria-hidden": "true",
|
|
46
|
+
children: "↑"
|
|
47
|
+
})
|
|
48
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
49
|
+
type: "button",
|
|
50
|
+
className: dnd_module_default.button,
|
|
51
|
+
"aria-label": messages.later(item.label),
|
|
52
|
+
disabled,
|
|
53
|
+
"aria-disabled": index === total - 1,
|
|
54
|
+
onClick: (event) => onMove(item.id, index + 1, event.currentTarget),
|
|
55
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
56
|
+
"aria-hidden": "true",
|
|
57
|
+
children: "↓"
|
|
58
|
+
})
|
|
59
|
+
})]
|
|
60
|
+
})
|
|
61
|
+
]
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function Sortable({ label, items, onChange, renderItem, disabled = false, messages: overrides, className, columns }) {
|
|
65
|
+
const scopeRef = useDragScope();
|
|
66
|
+
const [status, setStatus] = useState("");
|
|
67
|
+
const pending = useRef(null);
|
|
68
|
+
const messages = {
|
|
69
|
+
...defaults,
|
|
70
|
+
...overrides
|
|
71
|
+
};
|
|
72
|
+
const announceMove = overrides?.moved ?? defaults.moved;
|
|
73
|
+
useIsomorphicLayoutEffect(() => {
|
|
74
|
+
const move = pending.current;
|
|
75
|
+
const item = move && items[move.position];
|
|
76
|
+
if (move && item?.id === move.id) {
|
|
77
|
+
pending.current = null;
|
|
78
|
+
restoreMoveFocus(move.focused, move.button);
|
|
79
|
+
setStatus(announceMove(item.label, move.position + 1, items.length));
|
|
80
|
+
}
|
|
81
|
+
}, [items, announceMove]);
|
|
82
|
+
function move(id, index, button) {
|
|
83
|
+
const from = items.findIndex((item) => item.id === id);
|
|
84
|
+
const item = items[from];
|
|
85
|
+
if (disabled || !item || from === index || index < 0 || index >= items.length) return;
|
|
86
|
+
const next = [...items];
|
|
87
|
+
next.splice(from, 1);
|
|
88
|
+
next.splice(index, 0, item);
|
|
89
|
+
pending.current = {
|
|
90
|
+
id,
|
|
91
|
+
position: index,
|
|
92
|
+
button,
|
|
93
|
+
focused: button?.ownerDocument.activeElement ?? null
|
|
94
|
+
};
|
|
95
|
+
onChange(next);
|
|
96
|
+
}
|
|
97
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
98
|
+
className,
|
|
99
|
+
children: [/* @__PURE__ */ jsx("ol", {
|
|
100
|
+
role: "list",
|
|
101
|
+
"aria-label": label,
|
|
102
|
+
className: columns === void 0 ? dnd_module_default.list : dnd_module_default.grid,
|
|
103
|
+
style: columns === void 0 ? void 0 : { "--pl-sortable-columns": columns },
|
|
104
|
+
children: items.map((item, index) => /* @__PURE__ */ jsx(SortableRow, {
|
|
105
|
+
item,
|
|
106
|
+
index,
|
|
107
|
+
total: items.length,
|
|
108
|
+
scopeRef,
|
|
109
|
+
disabled: disabled || items.length < 2,
|
|
110
|
+
messages,
|
|
111
|
+
onMove: move,
|
|
112
|
+
children: renderItem ? renderItem(item) : item.label
|
|
113
|
+
}, item.id))
|
|
114
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
115
|
+
role: "status",
|
|
116
|
+
className: dnd_module_default.status,
|
|
117
|
+
children: status
|
|
118
|
+
})]
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function SortableList(props) {
|
|
122
|
+
return /* @__PURE__ */ jsx(Sortable, { ...props });
|
|
123
|
+
}
|
|
124
|
+
function SortableGrid({ columns = 3, ...props }) {
|
|
125
|
+
const count = Number.isFinite(columns) ? Math.max(1, Math.floor(columns)) : 3;
|
|
126
|
+
return /* @__PURE__ */ jsx(Sortable, {
|
|
127
|
+
...props,
|
|
128
|
+
columns: count
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
export { SortableGrid, SortableList };
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=sortable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortable.js","names":["styles"],"sources":["../src/sortable.tsx"],"sourcesContent":["'use client';\n\nimport { useRef, useState, type CSSProperties, type ReactNode } from 'react';\nimport { useIsomorphicLayoutEffect } from '@reactloom/hooks';\nimport { DragHandle, restoreMoveFocus, useDragScope, useItemDrop, type DragItem } from './drag.js';\nimport styles from './dnd.module.css';\n\nexport interface SortableMessages {\n drag: (item: string) => string;\n drop: (item: string, position: number) => string;\n earlier: (item: string) => string;\n later: (item: string) => string;\n moved: (item: string, position: number, total: number) => string;\n}\n\nconst defaults: SortableMessages = {\n drag: (item) => `Drag ${item}`,\n drop: (item, position) => `Position ${position}: ${item}`,\n earlier: (item) => `Move ${item} earlier`,\n later: (item) => `Move ${item} later`,\n moved: (item, position, total) => `${item} moved to position ${position} of ${total}.`,\n};\n\nexport interface SortableListProps<T extends DragItem> {\n label: string;\n items: readonly T[];\n onChange: (items: T[]) => void;\n renderItem?: (item: T) => ReactNode;\n disabled?: boolean;\n messages?: Partial<SortableMessages>;\n className?: string;\n}\n\nexport interface SortableGridProps<T extends DragItem> extends SortableListProps<T> {\n /** Maximum columns. The layout uses fewer columns in narrower containers. */\n columns?: number;\n}\n\nfunction SortableRow<T extends DragItem>({ item, index, total, scopeRef, disabled, messages, children, onMove }: {\n item: T;\n index: number;\n total: number;\n scopeRef: ReturnType<typeof useDragScope>;\n disabled: boolean;\n messages: SortableMessages;\n children: ReactNode;\n onMove: (id: string, index: number, button?: HTMLButtonElement) => void;\n}) {\n const { ref, dropProps, isDropTarget } = useItemDrop<HTMLLIElement>(\n scopeRef, (id) => id !== item.id, (id, handle) => onMove(id, index, handle), disabled,\n );\n return (\n <li {...dropProps} ref={ref} tabIndex={-1} aria-label={messages.drop(item.label, index + 1)}\n className={styles.item} data-drop-target={isDropTarget || undefined}>\n <DragHandle scopeRef={scopeRef} item={item} label={messages.drag(item.label)} disabled={disabled} />\n <div className={styles.content}>{children}</div>\n <div className={styles.actions}>\n <button type=\"button\" className={styles.button} aria-label={messages.earlier(item.label)}\n disabled={disabled} aria-disabled={index === 0}\n onClick={(event) => onMove(item.id, index - 1, event.currentTarget)}>\n <span aria-hidden=\"true\">↑</span>\n </button>\n <button type=\"button\" className={styles.button} aria-label={messages.later(item.label)}\n disabled={disabled} aria-disabled={index === total - 1}\n onClick={(event) => onMove(item.id, index + 1, event.currentTarget)}>\n <span aria-hidden=\"true\">↓</span>\n </button>\n </div>\n </li>\n );\n}\n\nfunction Sortable<T extends DragItem>({\n label, items, onChange, renderItem, disabled = false, messages: overrides, className, columns,\n}: SortableListProps<T> & { columns?: number }) {\n const scopeRef = useDragScope();\n const [status, setStatus] = useState('');\n const pending = useRef<{ id: string; position: number; button?: HTMLButtonElement; focused: Element | null } | null>(null);\n const messages = { ...defaults, ...overrides };\n\n const announceMove = overrides?.moved ?? defaults.moved;\n\n useIsomorphicLayoutEffect(() => {\n const move = pending.current;\n const item = move && items[move.position];\n if (move && item?.id === move.id) {\n pending.current = null;\n restoreMoveFocus(move.focused, move.button);\n setStatus(announceMove(item.label, move.position + 1, items.length));\n }\n }, [items, announceMove]);\n\n function move(id: string, index: number, button?: HTMLButtonElement) {\n const from = items.findIndex((item) => item.id === id);\n const item = items[from];\n if (disabled || !item || from === index || index < 0 || index >= items.length) return;\n const next = [...items];\n next.splice(from, 1);\n next.splice(index, 0, item);\n pending.current = { id, position: index, button, focused: button?.ownerDocument.activeElement ?? null };\n onChange(next);\n }\n\n return (\n <div className={className}>\n {/* eslint-disable-next-line jsx-a11y/no-redundant-roles -- Safari removes list semantics with list-style: none. */}\n <ol role=\"list\" aria-label={label} className={columns === undefined ? styles.list : styles.grid}\n style={columns === undefined ? undefined : { '--pl-sortable-columns': columns } as CSSProperties}>\n {items.map((item, index) => (\n <SortableRow key={item.id} item={item} index={index} total={items.length} scopeRef={scopeRef}\n disabled={disabled || items.length < 2} messages={messages} onMove={move}>\n {renderItem ? renderItem(item) : item.label}\n </SortableRow>\n ))}\n </ol>\n <div role=\"status\" className={styles.status}>{status}</div>\n </div>\n );\n}\n\nexport function SortableList<T extends DragItem>(props: SortableListProps<T>) {\n return <Sortable {...props} />;\n}\n\nexport function SortableGrid<T extends DragItem>({ columns = 3, ...props }: SortableGridProps<T>) {\n const count = Number.isFinite(columns) ? Math.max(1, Math.floor(columns)) : 3;\n return <Sortable {...props} columns={count} />;\n}\n"],"mappings":";;;;;;;AAeA,IAAM,WAA6B;CACjC,OAAO,SAAS,QAAQ;CACxB,OAAO,MAAM,aAAa,YAAY,SAAS,IAAI;CACnD,UAAU,SAAS,QAAQ,KAAK;CAChC,QAAQ,SAAS,QAAQ,KAAK;CAC9B,QAAQ,MAAM,UAAU,UAAU,GAAG,KAAK,qBAAqB,SAAS,MAAM,MAAM;AACtF;AAiBA,SAAS,YAAgC,EAAE,MAAM,OAAO,OAAO,UAAU,UAAU,UAAU,UAAU,UASpG;CACD,MAAM,EAAE,KAAK,WAAW,iBAAiB,YACvC,WAAW,OAAO,OAAO,KAAK,KAAK,IAAI,WAAW,OAAO,IAAI,OAAO,MAAM,GAAG,QAC/E;CACA,OACE,qBAAC,MAAD;EAAI,GAAI;EAAgB;EAAK,UAAU;EAAI,cAAY,SAAS,KAAK,KAAK,OAAO,QAAQ,CAAC;EACxF,WAAWA,mBAAO;EAAM,oBAAkB,gBAAgB,KAAA;EAD5D,UAAA;GAEE,oBAAC,YAAD;IAAsB;IAAgB;IAAM,OAAO,SAAS,KAAK,KAAK,KAAK;IAAa;GAAW,CAAA;GACnG,oBAAC,OAAD;IAAK,WAAWA,mBAAO;IAAU;GAAc,CAAA;GAC/C,qBAAC,OAAD;IAAK,WAAWA,mBAAO;IAAvB,UAAA,CACE,oBAAC,UAAD;KAAQ,MAAK;KAAS,WAAWA,mBAAO;KAAQ,cAAY,SAAS,QAAQ,KAAK,KAAK;KAC3E;KAAU,iBAAe,UAAU;KAC7C,UAAU,UAAU,OAAO,KAAK,IAAI,QAAQ,GAAG,MAAM,aAAa;KAClE,UAAA,oBAAC,QAAD;MAAM,eAAY;MAAO,UAAA;KAAO,CAAA;IAC1B,CAAA,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CACf;CAEA,OACE,qBAAC,OAAD;EAAgB;EAAhB,UAAA,CAEE,oBAAC,MAAD;GAAI,MAAK;GAAO,cAAY;GAAO,WAAW,YAAY,KAAA,IAAYA,mBAAO,OAAOA,mBAAO;GACzF,OAAO,YAAY,KAAA,IAAY,KAAA,IAAY,EAAE,yBAAyB,QAAQ;GAC7E,UAAA,MAAM,KAAK,MAAM,UAChB,oBAAC,aAAD;IAAiC;IAAa;IAAO,OAAO,MAAM;IAAkB;IAClF,UAAU,YAAY,MAAM,SAAS;IAAa;IAAU,QAAQ;IACnE,UAAA,aAAa,WAAW,IAAI,IAAI,KAAK;GAC3B,GAHK,KAAK,EAGV,CACd;EACC,CAAA,GACJ,oBAAC,OAAD;GAAK,MAAK;GAAS,WAAWA,mBAAO;GAAS,UAAA;EAAY,CAAA,CACvD;;AAET;AAEA,SAAgB,aAAiC,OAA6B;CAC5E,OAAO,oBAAC,UAAD,EAAU,GAAI,MAAQ,CAAA;AAC/B;AAEA,SAAgB,aAAiC,EAAE,UAAU,GAAG,GAAG,SAA+B;CAChG,MAAM,QAAQ,OAAO,SAAS,OAAO,IAAI,KAAK,IAAI,GAAG,KAAK,MAAM,OAAO,CAAC,IAAI;CAC5E,OAAO,oBAAC,UAAD;EAAU,GAAI;EAAO,SAAS;CAAQ,CAAA;AAC/C"}
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
@layer pl.theme, pl.components;
|
|
2
|
+
@layer pl.components{.pl-dnd-list-3C7zgf,.pl-dnd-grid-3C7zgf{gap:var(--pl-space-2);margin:0;padding:0;list-style:none;display:grid}.pl-dnd-grid-3C7zgf{grid-template-columns:repeat(auto-fit, minmax(min(100%, max(var(--pl-sortable-min,12rem), calc((100% - (var(--pl-sortable-columns) - 1) * var(--pl-space-2)) / var(--pl-sortable-columns)))), 1fr))}.pl-dnd-item-3C7zgf{background:var(--pl-color-bg-surface);border:1px solid var(--pl-color-border-default);border-radius:var(--pl-radius-md);color:var(--pl-color-fg-default);align-items:center;gap:var(--pl-space-2);padding:var(--pl-space-2);display:flex}.pl-dnd-content-3C7zgf{overflow-wrap:anywhere;flex:1;min-inline-size:0}.pl-dnd-actions-3C7zgf{gap:var(--pl-space-1);flex-shrink:0;display:flex}.pl-dnd-handle-3C7zgf,.pl-dnd-button-3C7zgf{background:var(--pl-color-bg-surface);border:1px solid var(--pl-color-border-default);border-radius:var(--pl-radius-sm);color:var(--pl-color-fg-default);font:inherit;justify-content:center;align-items:center;min-block-size:2rem;min-inline-size:2rem;padding:0;font-weight:600;display:inline-flex}.pl-dnd-handle-3C7zgf{cursor:grab}.pl-dnd-handle-3C7zgf[data-dragging]{cursor:grabbing}.pl-dnd-button-3C7zgf{cursor:pointer}.pl-dnd-button-3C7zgf:disabled,.pl-dnd-button-3C7zgf[aria-disabled=true],.pl-dnd-handle-3C7zgf:disabled{cursor:default;opacity:.5}.pl-dnd-handle-3C7zgf:focus-visible,.pl-dnd-button-3C7zgf:focus-visible,.pl-dnd-item-3C7zgf:focus-visible,.pl-dnd-side-3C7zgf:focus-visible,[data-drop-target].pl-dnd-item-3C7zgf,[data-drop-target].pl-dnd-side-3C7zgf{outline:2px solid var(--pl-focus-ring-color);outline-offset:2px}.pl-dnd-transfer-3C7zgf{gap:var(--pl-space-3);grid-template-columns:repeat(auto-fit,minmax(min(100%,13rem),1fr));display:grid}.pl-dnd-side-3C7zgf{border:1px solid var(--pl-color-border-default);border-radius:var(--pl-radius-md);color:var(--pl-color-fg-default);padding:var(--pl-space-3)}.pl-dnd-side-label-3C7zgf{margin-block-end:var(--pl-space-2);font-weight:600}.pl-dnd-empty-3C7zgf{color:var(--pl-color-fg-muted);margin:0}.pl-dnd-status-3C7zgf{clip-path:inset(50%);white-space:nowrap;block-size:1px;inline-size:1px;position:absolute;overflow:hidden}@media (pointer:coarse){.pl-dnd-handle-3C7zgf,.pl-dnd-button-3C7zgf{min-block-size:2.75rem;min-inline-size:2.75rem}}.pl-kanban-board-wg5uGC{min-inline-size:0;color:var(--pl-color-fg-default)}.pl-kanban-lanes-wg5uGC{gap:var(--pl-space-3);grid-template-columns:repeat(auto-fit,minmax(min(100%,15rem),1fr));display:grid}.pl-kanban-lane-wg5uGC{background:var(--pl-color-bg-subtle);border:1px solid var(--pl-color-border-default);border-radius:var(--pl-radius-lg);padding:var(--pl-space-3);min-inline-size:0}.pl-kanban-lane-label-wg5uGC{margin-block-end:var(--pl-space-2);display:block}.pl-kanban-cards-wg5uGC{gap:var(--pl-space-2);margin:0;padding:0;list-style:none;display:grid}.pl-kanban-card-wg5uGC{background:var(--pl-color-bg-surface);border:1px solid var(--pl-color-border-default);border-radius:var(--pl-radius-md);min-inline-size:0;padding:var(--pl-space-2)}.pl-kanban-card-top-wg5uGC,.pl-kanban-controls-wg5uGC{align-items:center;gap:var(--pl-space-2);display:flex}.pl-kanban-card-content-wg5uGC{overflow-wrap:anywhere;min-inline-size:0}.pl-kanban-controls-wg5uGC{margin-block-start:var(--pl-space-2)}.pl-kanban-destination-wg5uGC,.pl-kanban-reorder-wg5uGC{border:1px solid var(--pl-color-border-default);border-radius:var(--pl-radius-sm);background:var(--pl-color-bg-surface);min-block-size:2rem;min-inline-size:2rem;color:inherit;font:inherit}.pl-kanban-destination-wg5uGC{flex:1 1 0;min-inline-size:0}.pl-kanban-reorder-wg5uGC[aria-disabled],.pl-kanban-reorder-wg5uGC:disabled{opacity:.55}.pl-kanban-lane-wg5uGC:focus-visible,.pl-kanban-card-wg5uGC:focus-visible,.pl-kanban-destination-wg5uGC:focus-visible,.pl-kanban-reorder-wg5uGC:focus-visible,.pl-kanban-lane-wg5uGC[data-drop-target],.pl-kanban-card-wg5uGC[data-drop-target]{outline:var(--pl-focus-ring-width) solid var(--pl-focus-ring-color);outline-offset:2px}.pl-kanban-empty-wg5uGC{color:var(--pl-color-fg-muted);margin:0}.pl-kanban-announcement-wg5uGC{clip-path:inset(50%);white-space:nowrap;block-size:1px;inline-size:1px;position:absolute;overflow:hidden}.pl-flow-canvas-root-EFgZ7R{border:var(--pl-border-width-hairline) solid var(--pl-color-border-default);border-radius:var(--pl-radius-md);background:var(--pl-color-bg-surface);color:var(--pl-color-fg-default);flex-direction:column;display:flex;overflow:hidden}.pl-flow-canvas-toolbar-EFgZ7R{justify-content:space-between;align-items:center;gap:var(--pl-space-2);padding:var(--pl-space-2) var(--pl-space-3);border-block-end:var(--pl-border-width-hairline) solid var(--pl-color-border-default);background:var(--pl-color-bg-subtle);display:flex}.pl-flow-canvas-title-EFgZ7R{font-size:var(--pl-font-size-sm);font-weight:var(--pl-font-weight-semibold)}.pl-flow-canvas-controls-EFgZ7R{align-items:center;gap:var(--pl-space-1-5);display:inline-flex}.pl-flow-canvas-toolBtn-EFgZ7R{appearance:none;padding:var(--pl-space-1) var(--pl-space-2);border:var(--pl-border-width-hairline) solid var(--pl-color-border-default);border-radius:var(--pl-radius-sm);background:var(--pl-color-bg-surface);color:inherit;font:inherit;font-size:var(--pl-font-size-xs);cursor:pointer}.pl-flow-canvas-toolBtn-EFgZ7R:focus-visible{outline:var(--pl-focus-ring-width) solid var(--pl-focus-ring-color);outline-offset:1px}.pl-flow-canvas-zoomLabel-EFgZ7R{min-inline-size:2.75rem;font-size:var(--pl-font-size-xs);font-variant-numeric:tabular-nums;text-align:center;color:var(--pl-color-fg-muted)}.pl-flow-canvas-viewport-EFgZ7R{background-image:radial-gradient(color-mix(in srgb, var(--pl-color-border-strong) 55%, transparent) 1px, transparent 1px);background-size:16px 16px;position:relative;overflow:auto}.pl-flow-canvas-stage-EFgZ7R{min-block-size:100%;min-inline-size:720px;position:relative}.pl-flow-canvas-edges-EFgZ7R{pointer-events:none;width:100%;height:100%;position:absolute;inset:0;overflow:visible}.pl-flow-canvas-edgePath-EFgZ7R{fill:none;stroke:var(--pl-color-border-strong);stroke-width:2px}.pl-flow-canvas-edgeLabel-EFgZ7R{fill:var(--pl-color-fg-muted);font-size:11px;font-weight:500}.pl-flow-canvas-node-EFgZ7R{box-sizing:border-box;padding:var(--pl-space-2) var(--pl-space-3);border:var(--pl-border-width-hairline) solid var(--pl-color-border-strong);border-radius:var(--pl-radius-md);background:var(--pl-color-bg-surface-raised);box-shadow:var(--pl-shadow-sm);cursor:grab;-webkit-user-select:none;user-select:none;flex-direction:column;justify-content:center;gap:2px;display:flex;position:absolute;inset-block-start:0;inset-inline-start:0}.pl-flow-canvas-node-EFgZ7R:active{cursor:grabbing}.pl-flow-canvas-node-EFgZ7R[data-tone=accent]{border-inline-start:3px solid var(--pl-color-accent-solid)}.pl-flow-canvas-node-EFgZ7R[data-tone=success]{border-inline-start:3px solid var(--pl-color-success-solid)}.pl-flow-canvas-node-EFgZ7R[data-tone=warning]{border-inline-start:3px solid var(--pl-color-warning-solid)}.pl-flow-canvas-node-EFgZ7R[data-selected]{border-color:var(--pl-color-accent-solid);box-shadow:0 0 0 2px color-mix(in srgb, var(--pl-color-accent-solid) 25%, transparent)}.pl-flow-canvas-node-EFgZ7R:focus-visible{outline:var(--pl-focus-ring-width) solid var(--pl-focus-ring-color);outline-offset:2px}.pl-flow-canvas-nodeTitle-EFgZ7R{font-size:var(--pl-font-size-sm);font-weight:var(--pl-font-weight-semibold)}.pl-flow-canvas-nodeDesc-EFgZ7R{font-size:var(--pl-font-size-xs);color:var(--pl-color-fg-muted)}}
|
|
3
|
+
/*$vite$:1*/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type DragItem } from './drag.js';
|
|
2
|
+
export interface TransferMessages {
|
|
3
|
+
drag: (item: string) => string;
|
|
4
|
+
move: (item: string, destination: string) => string;
|
|
5
|
+
moved: (item: string, destination: string) => string;
|
|
6
|
+
empty: string;
|
|
7
|
+
}
|
|
8
|
+
export interface TransferListProps<T extends DragItem> {
|
|
9
|
+
/** All items, in the order they should appear within each list. */
|
|
10
|
+
items: readonly T[];
|
|
11
|
+
/** IDs of items in the destination list. */
|
|
12
|
+
value: readonly string[];
|
|
13
|
+
onChange: (value: string[]) => void;
|
|
14
|
+
sourceLabel: string;
|
|
15
|
+
destinationLabel: string;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
messages?: Partial<TransferMessages>;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function TransferList<T extends DragItem>({ items, value, onChange, sourceLabel, destinationLabel, disabled, messages: overrides, className, }: TransferListProps<T>): import("react").JSX.Element;
|
|
21
|
+
//# sourceMappingURL=transfer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../src/transfer.tsx"],"names":[],"mappings":"AAIA,OAAO,EAA2D,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGnG,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAC/B,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,MAAM,CAAC;IACpD,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,MAAM,CAAC;IACrD,KAAK,EAAE,MAAM,CAAC;CACf;AASD,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,QAAQ;IACnD,mEAAmE;IACnE,KAAK,EAAE,SAAS,CAAC,EAAE,CAAC;IACpB,4CAA4C;IAC5C,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAyCD,wBAAgB,YAAY,CAAC,CAAC,SAAS,QAAQ,EAAE,EAC/C,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,gBAAgB,EAAE,QAAgB,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,GACxG,EAAE,iBAAiB,CAAC,CAAC,CAAC,+BAmDtB"}
|
package/dist/transfer.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useIsomorphicLayoutEffect } from "./_internal/hooks/use-isomorphic-layout-effect.js";
|
|
3
|
+
import { DragHandle, restoreMoveFocus, useDragScope, useItemDrop } from "./drag.js";
|
|
4
|
+
import dnd_module_default from "./dnd.module.js";
|
|
5
|
+
import { useRef, useState } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// src/transfer.tsx
|
|
8
|
+
var defaults = {
|
|
9
|
+
drag: (item) => `Drag ${item}`,
|
|
10
|
+
move: (item, destination) => `Move ${item} to ${destination}`,
|
|
11
|
+
moved: (item, destination) => `${item} moved to ${destination}.`,
|
|
12
|
+
empty: "No items"
|
|
13
|
+
};
|
|
14
|
+
function TransferSide({ items, label, otherLabel, disabled, selected, scopeRef, messages, transfer, registerButton, canMove }) {
|
|
15
|
+
const { ref, dropProps, isDropTarget } = useItemDrop(scopeRef, (id) => canMove(id, selected), (id) => transfer(id, selected), disabled);
|
|
16
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
17
|
+
...dropProps,
|
|
18
|
+
ref,
|
|
19
|
+
tabIndex: -1,
|
|
20
|
+
role: "group",
|
|
21
|
+
"aria-label": label,
|
|
22
|
+
className: dnd_module_default.side,
|
|
23
|
+
"data-drop-target": isDropTarget || void 0,
|
|
24
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
25
|
+
className: dnd_module_default.sideLabel,
|
|
26
|
+
"aria-hidden": "true",
|
|
27
|
+
children: label
|
|
28
|
+
}), items.length === 0 ? /* @__PURE__ */ jsx("p", {
|
|
29
|
+
className: dnd_module_default.empty,
|
|
30
|
+
children: messages.empty
|
|
31
|
+
}) : /* @__PURE__ */ jsx("ul", {
|
|
32
|
+
role: "list",
|
|
33
|
+
className: dnd_module_default.list,
|
|
34
|
+
children: items.map((item) => /* @__PURE__ */ jsxs("li", {
|
|
35
|
+
className: dnd_module_default.item,
|
|
36
|
+
children: [
|
|
37
|
+
/* @__PURE__ */ jsx(DragHandle, {
|
|
38
|
+
scopeRef,
|
|
39
|
+
item,
|
|
40
|
+
label: messages.drag(item.label),
|
|
41
|
+
disabled
|
|
42
|
+
}),
|
|
43
|
+
/* @__PURE__ */ jsx("span", {
|
|
44
|
+
className: dnd_module_default.content,
|
|
45
|
+
children: item.label
|
|
46
|
+
}),
|
|
47
|
+
/* @__PURE__ */ jsx("button", {
|
|
48
|
+
type: "button",
|
|
49
|
+
className: dnd_module_default.button,
|
|
50
|
+
"aria-label": messages.move(item.label, otherLabel),
|
|
51
|
+
ref: (button) => registerButton(item.id, button),
|
|
52
|
+
disabled,
|
|
53
|
+
onClick: () => transfer(item.id, !selected),
|
|
54
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
55
|
+
"aria-hidden": "true",
|
|
56
|
+
children: selected ? "−" : "+"
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
]
|
|
60
|
+
}, item.id))
|
|
61
|
+
})]
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function TransferList({ items, value, onChange, sourceLabel, destinationLabel, disabled = false, messages: overrides, className }) {
|
|
65
|
+
const scopeRef = useDragScope();
|
|
66
|
+
const buttonsRef = useRef(/* @__PURE__ */ new Map());
|
|
67
|
+
const pending = useRef(null);
|
|
68
|
+
const [status, setStatus] = useState("");
|
|
69
|
+
const messages = {
|
|
70
|
+
...defaults,
|
|
71
|
+
...overrides
|
|
72
|
+
};
|
|
73
|
+
const announceMove = overrides?.moved ?? defaults.moved;
|
|
74
|
+
useIsomorphicLayoutEffect(() => {
|
|
75
|
+
const move = pending.current;
|
|
76
|
+
if (!move || value.includes(move.id) !== move.selected) return;
|
|
77
|
+
pending.current = null;
|
|
78
|
+
const item = items.find((entry) => entry.id === move.id);
|
|
79
|
+
if (item) {
|
|
80
|
+
restoreMoveFocus(move.focused, buttonsRef.current.get(move.id));
|
|
81
|
+
setStatus(announceMove(item.label, move.selected ? destinationLabel : sourceLabel));
|
|
82
|
+
}
|
|
83
|
+
}, [
|
|
84
|
+
items,
|
|
85
|
+
value,
|
|
86
|
+
destinationLabel,
|
|
87
|
+
sourceLabel,
|
|
88
|
+
announceMove
|
|
89
|
+
]);
|
|
90
|
+
function canMove(id, selected) {
|
|
91
|
+
return !disabled && value.includes(id) !== selected && items.some((item) => item.id === id);
|
|
92
|
+
}
|
|
93
|
+
function transfer(id, selected) {
|
|
94
|
+
if (!canMove(id, selected)) return;
|
|
95
|
+
pending.current = {
|
|
96
|
+
id,
|
|
97
|
+
selected,
|
|
98
|
+
focused: buttonsRef.current.get(id)?.ownerDocument.activeElement ?? null
|
|
99
|
+
};
|
|
100
|
+
onChange(selected ? [...value, id] : value.filter((key) => key !== id));
|
|
101
|
+
}
|
|
102
|
+
const selectedIds = new Set(value);
|
|
103
|
+
const source = [];
|
|
104
|
+
const destination = [];
|
|
105
|
+
for (const item of items) (selectedIds.has(item.id) ? destination : source).push(item);
|
|
106
|
+
function registerButton(id, button) {
|
|
107
|
+
if (button) buttonsRef.current.set(id, button);
|
|
108
|
+
else buttonsRef.current.delete(id);
|
|
109
|
+
}
|
|
110
|
+
const shared = {
|
|
111
|
+
scopeRef,
|
|
112
|
+
messages,
|
|
113
|
+
registerButton,
|
|
114
|
+
transfer,
|
|
115
|
+
canMove,
|
|
116
|
+
disabled
|
|
117
|
+
};
|
|
118
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
119
|
+
className,
|
|
120
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
121
|
+
className: dnd_module_default.transfer,
|
|
122
|
+
children: [/* @__PURE__ */ jsx(TransferSide, {
|
|
123
|
+
...shared,
|
|
124
|
+
items: source,
|
|
125
|
+
label: sourceLabel,
|
|
126
|
+
otherLabel: destinationLabel,
|
|
127
|
+
selected: false
|
|
128
|
+
}), /* @__PURE__ */ jsx(TransferSide, {
|
|
129
|
+
...shared,
|
|
130
|
+
items: destination,
|
|
131
|
+
label: destinationLabel,
|
|
132
|
+
otherLabel: sourceLabel,
|
|
133
|
+
selected: true
|
|
134
|
+
})]
|
|
135
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
136
|
+
role: "status",
|
|
137
|
+
className: dnd_module_default.status,
|
|
138
|
+
children: status
|
|
139
|
+
})]
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
export { TransferList };
|
|
143
|
+
|
|
144
|
+
//# sourceMappingURL=transfer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer.js","names":["styles"],"sources":["../src/transfer.tsx"],"sourcesContent":["'use client';\n\nimport { useRef, useState } from 'react';\nimport { useIsomorphicLayoutEffect } from '@reactloom/hooks';\nimport { DragHandle, restoreMoveFocus, useDragScope, useItemDrop, type DragItem } from './drag.js';\nimport styles from './dnd.module.css';\n\nexport interface TransferMessages {\n drag: (item: string) => string;\n move: (item: string, destination: string) => string;\n moved: (item: string, destination: string) => string;\n empty: string;\n}\n\nconst defaults: TransferMessages = {\n drag: (item) => `Drag ${item}`,\n move: (item, destination) => `Move ${item} to ${destination}`,\n moved: (item, destination) => `${item} moved to ${destination}.`,\n empty: 'No items',\n};\n\nexport interface TransferListProps<T extends DragItem> {\n /** All items, in the order they should appear within each list. */\n items: readonly T[];\n /** IDs of items in the destination list. */\n value: readonly string[];\n onChange: (value: string[]) => void;\n sourceLabel: string;\n destinationLabel: string;\n disabled?: boolean;\n messages?: Partial<TransferMessages>;\n className?: string;\n}\n\nfunction TransferSide<T extends DragItem>({ items, label, otherLabel, disabled, selected, scopeRef, messages, transfer, registerButton, canMove }: {\n items: readonly T[];\n label: string;\n otherLabel: string;\n disabled: boolean;\n selected: boolean;\n scopeRef: ReturnType<typeof useDragScope>;\n messages: TransferMessages;\n transfer: (id: string, selected: boolean) => void;\n registerButton: (id: string, button: HTMLButtonElement | null) => void;\n canMove: (id: string, selected: boolean) => boolean;\n}) {\n const { ref, dropProps, isDropTarget } = useItemDrop<HTMLDivElement>(\n scopeRef, (id) => canMove(id, selected), (id) => transfer(id, selected), disabled,\n );\n return (\n <div {...dropProps} ref={ref} tabIndex={-1} role=\"group\" aria-label={label}\n className={styles.side} data-drop-target={isDropTarget || undefined}>\n <div className={styles.sideLabel} aria-hidden=\"true\">{label}</div>\n {items.length === 0 ? <p className={styles.empty}>{messages.empty}</p> : (\n // eslint-disable-next-line jsx-a11y/no-redundant-roles -- Safari removes list semantics with list-style: none.\n <ul role=\"list\" className={styles.list}>\n {items.map((item) => (\n <li key={item.id} className={styles.item}>\n <DragHandle scopeRef={scopeRef} item={item} label={messages.drag(item.label)} disabled={disabled} />\n <span className={styles.content}>{item.label}</span>\n <button type=\"button\" className={styles.button} aria-label={messages.move(item.label, otherLabel)}\n ref={(button) => registerButton(item.id, button)}\n disabled={disabled} onClick={() => transfer(item.id, !selected)}>\n <span aria-hidden=\"true\">{selected ? '−' : '+'}</span>\n </button>\n </li>\n ))}\n </ul>\n )}\n </div>\n );\n}\n\nexport function TransferList<T extends DragItem>({\n items, value, onChange, sourceLabel, destinationLabel, disabled = false, messages: overrides, className,\n}: TransferListProps<T>) {\n const scopeRef = useDragScope();\n const buttonsRef = useRef(new Map<string, HTMLButtonElement>());\n const pending = useRef<{ id: string; selected: boolean; focused: Element | null } | null>(null);\n const [status, setStatus] = useState('');\n const messages = { ...defaults, ...overrides };\n\n const announceMove = overrides?.moved ?? defaults.moved;\n\n useIsomorphicLayoutEffect(() => {\n const move = pending.current;\n if (!move || value.includes(move.id) !== move.selected) return;\n pending.current = null;\n const item = items.find((entry) => entry.id === move.id);\n if (item) {\n restoreMoveFocus(move.focused, buttonsRef.current.get(move.id));\n setStatus(announceMove(item.label, move.selected ? destinationLabel : sourceLabel));\n }\n }, [items, value, destinationLabel, sourceLabel, announceMove]);\n\n function canMove(id: string, selected: boolean) {\n return !disabled && value.includes(id) !== selected && items.some((item) => item.id === id);\n }\n\n function transfer(id: string, selected: boolean) {\n if (!canMove(id, selected)) return;\n pending.current = { id, selected, focused: buttonsRef.current.get(id)?.ownerDocument.activeElement ?? null };\n onChange(selected ? [...value, id] : value.filter((key) => key !== id));\n }\n\n const selectedIds = new Set(value);\n const source: T[] = [];\n const destination: T[] = [];\n for (const item of items) {\n (selectedIds.has(item.id) ? destination : source).push(item);\n }\n function registerButton(id: string, button: HTMLButtonElement | null) {\n if (button) buttonsRef.current.set(id, button);\n else buttonsRef.current.delete(id);\n }\n const shared = { scopeRef, messages, registerButton, transfer, canMove, disabled };\n\n return (\n <div className={className}>\n <div className={styles.transfer}>\n <TransferSide {...shared} items={source} label={sourceLabel} otherLabel={destinationLabel} selected={false} />\n <TransferSide {...shared} items={destination} label={destinationLabel} otherLabel={sourceLabel} selected />\n </div>\n <div role=\"status\" className={styles.status}>{status}</div>\n </div>\n );\n}\n"],"mappings":";;;;;;;AAcA,IAAM,WAA6B;CACjC,OAAO,SAAS,QAAQ;CACxB,OAAO,MAAM,gBAAgB,QAAQ,KAAK,MAAM;CAChD,QAAQ,MAAM,gBAAgB,GAAG,KAAK,YAAY,YAAY;CAC9D,OAAO;AACT;AAeA,SAAS,aAAiC,EAAE,OAAO,OAAO,YAAY,UAAU,UAAU,UAAU,UAAU,UAAU,gBAAgB,WAWrI;CACD,MAAM,EAAE,KAAK,WAAW,iBAAiB,YACvC,WAAW,OAAO,QAAQ,IAAI,QAAQ,IAAI,OAAO,SAAS,IAAI,QAAQ,GAAG,QAC3E;CACA,OACE,qBAAC,OAAD;EAAK,GAAI;EAAgB;EAAK,UAAU;EAAI,MAAK;EAAQ,cAAY;EACnE,WAAWA,mBAAO;EAAM,oBAAkB,gBAAgB,KAAA;EAD5D,UAAA,CAEE,oBAAC,OAAD;GAAK,WAAWA,mBAAO;GAAW,eAAY;GAAQ,UAAA;EAAW,CAAA,GAChE,M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