@svar-ui/svelte-kanban 2.6.0 → 2.7.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/dist/components/Card.svelte +15 -72
- package/dist/components/CardList.svelte +8 -341
- package/dist/components/CardList.svelte.d.ts +14 -12
- package/dist/components/CardMenuButton.svelte +47 -0
- package/dist/components/CardMenuButton.svelte.d.ts +10 -0
- package/dist/components/CardWrapper.svelte +2 -5
- package/dist/components/Column.svelte +85 -53
- package/dist/components/Column.svelte.d.ts +4 -0
- package/dist/components/DragGhost.svelte +4 -0
- package/dist/components/Kanban.svelte +19 -20
- package/dist/components/Kanban.svelte.d.ts +117 -12
- package/dist/components/Layout.svelte +103 -51
- package/dist/components/Layout.svelte.d.ts +5 -1
- package/dist/components/Stack.svelte +383 -0
- package/dist/components/Stack.svelte.d.ts +26 -0
- package/dist/components/StackCardList.svelte +434 -0
- package/dist/components/StackCardList.svelte.d.ts +28 -0
- package/dist/components/useDrag.svelte.d.ts +7 -5
- package/dist/components/useDrag.svelte.js +6 -0
- package/dist/context.d.ts +6 -0
- package/dist/context.js +1 -0
- package/dist/directives/dblclick.d.ts +2 -1
- package/dist/directives/dblclick.js +5 -4
- package/dist/directives/drag.d.ts +2 -0
- package/dist/directives/drag.js +99 -43
- package/dist/index.d.ts +10 -4
- package/dist/index.js +9 -3
- package/dist/layout/stack.d.ts +19 -0
- package/dist/layout/stack.js +37 -0
- package/dist/layout/target.d.ts +18 -0
- package/dist/layout/target.js +74 -0
- package/dist/menus/CardActionMenu.svelte +20 -0
- package/dist/menus/CardActionMenu.svelte.d.ts +7 -0
- package/dist/menus/CardContextMenu.svelte +20 -0
- package/dist/menus/CardContextMenu.svelte.d.ts +7 -0
- package/dist/menus/ColumnActionMenu.svelte +20 -0
- package/dist/menus/ColumnActionMenu.svelte.d.ts +7 -0
- package/dist/menus/ColumnContextMenu.svelte +20 -0
- package/dist/menus/ColumnContextMenu.svelte.d.ts +7 -0
- package/dist/menus/KanbanMenu.svelte +65 -0
- package/dist/menus/KanbanMenu.svelte.d.ts +37 -0
- package/dist/menus/helpers.d.ts +23 -0
- package/dist/menus/helpers.js +80 -0
- package/dist/themes/Print.svelte +1 -8
- package/dist/themes/PrintBW.svelte +1 -8
- package/dist/themes/Willow.svelte +1 -1
- package/dist/themes/WillowDark.svelte +1 -1
- package/dist/types.d.ts +71 -9
- package/package.json +25 -11
- package/readme.md +16 -8
- package/dist/components/ContextMenu.svelte +0 -111
- package/dist/components/ContextMenu.svelte.d.ts +0 -18
- package/dist/components/ExportLayout.svelte +0 -52
- package/dist/components/ExportLayout.svelte.d.ts +0 -15
- package/dist/export/Card.svelte +0 -5
- package/dist/export/Card.svelte.d.ts +0 -11
- package/dist/export/Kanban.svelte +0 -30
- package/dist/export/Kanban.svelte.d.ts +0 -16
- package/dist/export.d.ts +0 -3
- package/dist/export.js +0 -15
package/dist/directives/drag.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { cellDestinations, dropCell, resolveDropTarget, sameTarget, } from "../layout/target.js";
|
|
1
2
|
import { getID } from "@svar-ui/lib-dom";
|
|
2
3
|
const DRAG_THRESHOLD_PX = 4;
|
|
3
4
|
export function cardDrag(node, initial) {
|
|
@@ -7,8 +8,68 @@ export function cardDrag(node, initial) {
|
|
|
7
8
|
let pending = false;
|
|
8
9
|
let started = false;
|
|
9
10
|
let active = null;
|
|
11
|
+
let scrollFrame = 0;
|
|
12
|
+
let hovered = null;
|
|
13
|
+
// Retarget a still pointer only when the hovered cell itself scrolled, moved or
|
|
14
|
+
// rewrapped. A cell that arrives under the pointer because a placeholder resized
|
|
15
|
+
// a lane waits for the next move; retargeting it would bounce the placeholder
|
|
16
|
+
// between lanes every frame.
|
|
17
|
+
const inert = () => !!(params.readonly || params.disabled);
|
|
18
|
+
function refreshStationary(a, force, hit = document.elementFromPoint(a.dnd.pointer.x, a.dnd.pointer.y)) {
|
|
19
|
+
const cell = hit?.closest("[data-kanban-column-cards]");
|
|
20
|
+
const key = cell ? cellKey(cell) : "";
|
|
21
|
+
const changed = !!cell &&
|
|
22
|
+
hovered !== null &&
|
|
23
|
+
hovered.cell === cell &&
|
|
24
|
+
hovered.key !== key;
|
|
25
|
+
hovered = cell ? { cell, key } : null;
|
|
26
|
+
if (force || changed)
|
|
27
|
+
updateTarget(a.dnd.pointer.x, a.dnd.pointer.y, a, hit);
|
|
28
|
+
}
|
|
29
|
+
function autoScroll() {
|
|
30
|
+
if (!started || !active)
|
|
31
|
+
return;
|
|
32
|
+
const { x, y } = active.dnd.pointer;
|
|
33
|
+
let scrolled = false;
|
|
34
|
+
const scroll = node.querySelector(".wx-scroll");
|
|
35
|
+
if (scroll) {
|
|
36
|
+
const rect = scroll.getBoundingClientRect();
|
|
37
|
+
const inset = node.querySelector(".wx-lane-columns")?.offsetHeight ?? 0;
|
|
38
|
+
const speed = (position, start, end) => position < start + 36 ? -12 : position > end - 36 ? 12 : 0;
|
|
39
|
+
if (x >= rect.left &&
|
|
40
|
+
x <= rect.right &&
|
|
41
|
+
y >= rect.top &&
|
|
42
|
+
y <= rect.bottom) {
|
|
43
|
+
const previousLeft = scroll.scrollLeft;
|
|
44
|
+
const previousTop = scroll.scrollTop;
|
|
45
|
+
const speedX = speed(x, rect.left, rect.right);
|
|
46
|
+
const speedY = node.classList.contains("wx-scroll-board")
|
|
47
|
+
? speed(y, rect.top + inset, rect.bottom)
|
|
48
|
+
: 0;
|
|
49
|
+
if (speedX)
|
|
50
|
+
scroll.scrollLeft += speedX;
|
|
51
|
+
if (speedY)
|
|
52
|
+
scroll.scrollTop += speedY;
|
|
53
|
+
scrolled =
|
|
54
|
+
scroll.scrollLeft !== previousLeft ||
|
|
55
|
+
scroll.scrollTop !== previousTop;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const hit = document.elementFromPoint(x, y);
|
|
59
|
+
const cell = hit?.closest("[data-kanban-column-cards]");
|
|
60
|
+
if (cell && !node.classList.contains("wx-scroll-board")) {
|
|
61
|
+
const rect = cell.getBoundingClientRect();
|
|
62
|
+
if (y < rect.top + 36)
|
|
63
|
+
cell.scrollTop -= 12;
|
|
64
|
+
else if (y > rect.bottom - 36)
|
|
65
|
+
cell.scrollTop += 12;
|
|
66
|
+
}
|
|
67
|
+
// Pointer moves retarget in onPointerMove; between moves only on changes.
|
|
68
|
+
refreshStationary(active, scrolled, hit);
|
|
69
|
+
scrollFrame = requestAnimationFrame(autoScroll);
|
|
70
|
+
}
|
|
10
71
|
function onPointerDown(e) {
|
|
11
|
-
if (e.button !== 0 ||
|
|
72
|
+
if (e.button !== 0 || inert() || !params.dnd || !params.store)
|
|
12
73
|
return;
|
|
13
74
|
const target = e.target;
|
|
14
75
|
const cardEl = target
|
|
@@ -33,7 +94,9 @@ export function cardDrag(node, initial) {
|
|
|
33
94
|
store: params.store,
|
|
34
95
|
id: cardRec.id,
|
|
35
96
|
column: column.id,
|
|
97
|
+
swimlane: getID(columnEl, "data-kanban-swimlane") ?? undefined,
|
|
36
98
|
cardEl,
|
|
99
|
+
root: node,
|
|
37
100
|
};
|
|
38
101
|
pending = true;
|
|
39
102
|
started = false;
|
|
@@ -46,7 +109,7 @@ export function cardDrag(node, initial) {
|
|
|
46
109
|
function onPointerMove(e) {
|
|
47
110
|
if (!pending || !active)
|
|
48
111
|
return;
|
|
49
|
-
if (
|
|
112
|
+
if (inert()) {
|
|
50
113
|
cancelActiveDrag();
|
|
51
114
|
return;
|
|
52
115
|
}
|
|
@@ -63,6 +126,8 @@ export function cardDrag(node, initial) {
|
|
|
63
126
|
function onPointerUp() {
|
|
64
127
|
teardownListeners();
|
|
65
128
|
if (started && active) {
|
|
129
|
+
// Catch changes made after the last frame, e.g. a rewrap just before release.
|
|
130
|
+
refreshStationary(active, false);
|
|
66
131
|
commitDrop(active);
|
|
67
132
|
active.dnd.reset();
|
|
68
133
|
document.body.style.userSelect = "";
|
|
@@ -85,12 +150,15 @@ export function cardDrag(node, initial) {
|
|
|
85
150
|
a.dnd.pointer = { x: e.clientX, y: e.clientY };
|
|
86
151
|
a.dnd.cardId = a.id;
|
|
87
152
|
a.dnd.sourceColumn = a.column;
|
|
88
|
-
a.dnd.target = { column: a.column,
|
|
153
|
+
a.dnd.target = { column: a.column, swimlane: a.swimlane, before: null };
|
|
89
154
|
a.dnd.active = true;
|
|
90
155
|
document.body.style.userSelect = "none";
|
|
91
156
|
started = true;
|
|
157
|
+
hovered = null;
|
|
158
|
+
scrollFrame = requestAnimationFrame(autoScroll);
|
|
92
159
|
}
|
|
93
160
|
function teardownListeners() {
|
|
161
|
+
cancelAnimationFrame(scrollFrame);
|
|
94
162
|
window.removeEventListener("pointermove", onPointerMove);
|
|
95
163
|
window.removeEventListener("pointerup", onPointerUp);
|
|
96
164
|
window.removeEventListener("keydown", onKeyDown);
|
|
@@ -109,7 +177,7 @@ export function cardDrag(node, initial) {
|
|
|
109
177
|
return {
|
|
110
178
|
update(next) {
|
|
111
179
|
params = next;
|
|
112
|
-
if (
|
|
180
|
+
if (inert() && (pending || started))
|
|
113
181
|
cancelActiveDrag();
|
|
114
182
|
},
|
|
115
183
|
destroy() {
|
|
@@ -118,56 +186,44 @@ export function cardDrag(node, initial) {
|
|
|
118
186
|
},
|
|
119
187
|
};
|
|
120
188
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
const columnId = getID(columnEl, "data-kanban-column-cards");
|
|
132
|
-
if (columnId == null)
|
|
133
|
-
return;
|
|
134
|
-
const viewData = a.store.getState().viewData;
|
|
135
|
-
const column = viewData.columns.find((c) => c.id === columnId);
|
|
136
|
-
if (!column)
|
|
137
|
-
return;
|
|
138
|
-
const cardEls = Array.from(columnEl.querySelectorAll("[data-kanban-card-id]")).filter(n => getID(n, "data-kanban-card-id") !== a.id);
|
|
139
|
-
let beforeId = null;
|
|
140
|
-
for (const cardEl of cardEls) {
|
|
141
|
-
const rect = cardEl.getBoundingClientRect();
|
|
142
|
-
if (y < rect.top + rect.height / 2) {
|
|
143
|
-
beforeId = resolveRenderedCardId(column, getID(cardEl, "data-kanban-card-id"));
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (beforeId == null) {
|
|
148
|
-
beforeId = resolveRenderedCardId(column, getID(columnEl, "data-kanban-after-rendered-before-id"));
|
|
149
|
-
}
|
|
150
|
-
const next = { column: column.id, beforeId };
|
|
189
|
+
/** Hovered-cell state that invalidates a target under a still pointer. */
|
|
190
|
+
function cellKey(cell) {
|
|
191
|
+
const rect = cell.getBoundingClientRect();
|
|
192
|
+
const layout = cellDestinations.get(cell)?.layout() ?? "";
|
|
193
|
+
return `${layout}|${rect.top}|${rect.left}|${cell.scrollTop}|${cell.scrollLeft}`;
|
|
194
|
+
}
|
|
195
|
+
function updateTarget(x, y, a, hit = document.elementFromPoint(x, y)) {
|
|
196
|
+
const model = a.store.getState().viewData;
|
|
197
|
+
const next = resolveDropTarget(a.root, model, x, y, a.id, hit);
|
|
151
198
|
const prev = a.dnd.target;
|
|
152
|
-
|
|
199
|
+
// Interaction policy: a stack target survives gutters and headers, while
|
|
200
|
+
// invalid cells and stale flow boundaries are dropped.
|
|
201
|
+
if (!next &&
|
|
202
|
+
!dropCell(a.root, hit) &&
|
|
203
|
+
!model.columns.some(column => column.id === prev?.column && column.cardWidth !== undefined))
|
|
204
|
+
return;
|
|
205
|
+
if (!sameTarget(prev, next))
|
|
153
206
|
a.dnd.target = next;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
function resolveRenderedCardId(column, id) {
|
|
157
|
-
if (id == null)
|
|
158
|
-
return null;
|
|
159
|
-
return column.cards.find(card => card.id === id)?.id ?? null;
|
|
160
207
|
}
|
|
161
208
|
function commitDrop(a) {
|
|
162
209
|
const target = a.dnd.target;
|
|
163
210
|
if (!target)
|
|
164
211
|
return;
|
|
212
|
+
const model = a.store.getState().viewData;
|
|
213
|
+
if (model.columns.find(column => column.id === target.column)?.collapsed !==
|
|
214
|
+
false)
|
|
215
|
+
return;
|
|
216
|
+
if (model.swimlanes.length > 0 &&
|
|
217
|
+
model.swimlanes.find(lane => lane.id === target.swimlane)?.collapsed !==
|
|
218
|
+
false)
|
|
219
|
+
return;
|
|
165
220
|
const payload = {
|
|
166
221
|
id: a.id,
|
|
167
222
|
column: target.column,
|
|
223
|
+
swimlane: target.swimlane,
|
|
168
224
|
};
|
|
169
|
-
if (target.
|
|
170
|
-
payload.before = target.
|
|
225
|
+
if (target.before != null)
|
|
226
|
+
payload.before = target.before;
|
|
171
227
|
void a.store.exec("move-card", payload);
|
|
172
228
|
}
|
|
173
229
|
function suppressNextClick() {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
declare const version: string;
|
|
2
2
|
import Kanban from "./components/Kanban.svelte";
|
|
3
3
|
import Editor from "./components/Editor.svelte";
|
|
4
|
-
import
|
|
4
|
+
import CardActionMenu from "./menus/CardActionMenu.svelte";
|
|
5
|
+
import CardMenuButton from "./components/CardMenuButton.svelte";
|
|
6
|
+
import CardContextMenu from "./menus/CardContextMenu.svelte";
|
|
7
|
+
import ColumnActionMenu from "./menus/ColumnActionMenu.svelte";
|
|
8
|
+
import ColumnContextMenu from "./menus/ColumnContextMenu.svelte";
|
|
5
9
|
import Toolbar from "./components/Toolbar.svelte";
|
|
6
10
|
import Willow from "./themes/Willow.svelte";
|
|
7
11
|
import WillowDark from "./themes/WillowDark.svelte";
|
|
8
12
|
import Print from "./themes/Print.svelte";
|
|
9
13
|
import PrintBW from "./themes/PrintBW.svelte";
|
|
10
|
-
export { Kanban, Editor,
|
|
14
|
+
export { Kanban, Editor, CardActionMenu, CardMenuButton, CardContextMenu, ColumnActionMenu, ColumnContextMenu,
|
|
15
|
+
/** @deprecated use `CardContextMenu` */
|
|
16
|
+
CardContextMenu as ContextMenu, Toolbar, Willow, WillowDark, Print, PrintBW, version, };
|
|
11
17
|
export { RestDataProvider } from "@svar-ui/kanban-provider";
|
|
12
|
-
export type { KanbanInstanceApi, KanbanCard, RenderConfig, CardID, ColumnID, CardShape, CardShapeItem, CardShapeUserItem, CardPriorityShape, CardTagsShape, CardUsersShape,
|
|
18
|
+
export type { KanbanInstanceApi, KanbanEventHandlers, KanbanCard, RenderConfig, CardID, ColumnID, CardShape, CardShapeItem, CardShapeUserItem, CardPriorityShape, CardTagsShape, CardUsersShape, ColumnMenuContext, KanbanMenuProps, CardCssFn, CardListSlotProps, ColumnCssFn, CardProjection, CardProjectionTarget, } from "./types.js";
|
|
13
19
|
export { getCardShape, getEditorItems, getPriorityOptions, } from "./defaults.js";
|
|
14
|
-
export { getMenuOptions, getToolbarItems, type ToolbarButtonConfig, type StoreActions, type ColumnConfig, } from "@svar-ui/kanban-store";
|
|
20
|
+
export { getMenuOptions, getColumnMenuOptions, getToolbarItems, type ToolbarButtonConfig, type StoreActions, type ColumnConfig, type ColumnSummaryConfig, type ColumnSummaryResult, type SwimlaneID, type SwimlaneAccessor, type SwimlaneConfig, type SwimlaneView, type SwimlaneCellView, } from "@svar-ui/kanban-store";
|
|
15
21
|
export { registerEditorItem } from "@svar-ui/svelte-editor";
|
package/dist/index.js
CHANGED
|
@@ -2,14 +2,20 @@ import pkg from "../package.json" with { type: "json" };
|
|
|
2
2
|
const version = pkg.version;
|
|
3
3
|
import Kanban from "./components/Kanban.svelte";
|
|
4
4
|
import Editor from "./components/Editor.svelte";
|
|
5
|
-
import
|
|
5
|
+
import CardActionMenu from "./menus/CardActionMenu.svelte";
|
|
6
|
+
import CardMenuButton from "./components/CardMenuButton.svelte";
|
|
7
|
+
import CardContextMenu from "./menus/CardContextMenu.svelte";
|
|
8
|
+
import ColumnActionMenu from "./menus/ColumnActionMenu.svelte";
|
|
9
|
+
import ColumnContextMenu from "./menus/ColumnContextMenu.svelte";
|
|
6
10
|
import Toolbar from "./components/Toolbar.svelte";
|
|
7
11
|
import Willow from "./themes/Willow.svelte";
|
|
8
12
|
import WillowDark from "./themes/WillowDark.svelte";
|
|
9
13
|
import Print from "./themes/Print.svelte";
|
|
10
14
|
import PrintBW from "./themes/PrintBW.svelte";
|
|
11
|
-
export { Kanban, Editor,
|
|
15
|
+
export { Kanban, Editor, CardActionMenu, CardMenuButton, CardContextMenu, ColumnActionMenu, ColumnContextMenu,
|
|
16
|
+
/** @deprecated use `CardContextMenu` */
|
|
17
|
+
CardContextMenu as ContextMenu, Toolbar, Willow, WillowDark, Print, PrintBW, version, };
|
|
12
18
|
export { RestDataProvider } from "@svar-ui/kanban-provider";
|
|
13
19
|
export { getCardShape, getEditorItems, getPriorityOptions, } from "./defaults.js";
|
|
14
|
-
export { getMenuOptions, getToolbarItems, } from "@svar-ui/kanban-store";
|
|
20
|
+
export { getMenuOptions, getColumnMenuOptions, getToolbarItems, } from "@svar-ui/kanban-store";
|
|
15
21
|
export { registerEditorItem } from "@svar-ui/svelte-editor";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ColumnView, KanbanCard, KanbanModel, SwimlaneView } from "@svar-ui/kanban-store";
|
|
2
|
+
export type StackGroup = {
|
|
3
|
+
/** Stable across re-projection; distinguishes numeric from string IDs. */
|
|
4
|
+
key: string;
|
|
5
|
+
/** The aggregate column, for styling hooks and whole-column summaries. */
|
|
6
|
+
column: ColumnView;
|
|
7
|
+
/** Present only when lanes are enabled. */
|
|
8
|
+
swimlane?: SwimlaneView;
|
|
9
|
+
/** Shared with `viewData`, never copied or reordered. */
|
|
10
|
+
cards: KanbanCard[];
|
|
11
|
+
collapsed: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** JSON keeps `1` and `"1"` apart, and never collides on separators. */
|
|
14
|
+
export declare function stackGroupKey(column: ColumnView["id"], lane?: SwimlaneView["id"]): string;
|
|
15
|
+
/**
|
|
16
|
+
* Column-major group list for the stack layout. Empty groups are omitted, even
|
|
17
|
+
* when collapsed; a group is collapsed when its column or its lane is.
|
|
18
|
+
*/
|
|
19
|
+
export declare function stackGroups(model: KanbanModel): StackGroup[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** JSON keeps `1` and `"1"` apart, and never collides on separators. */
|
|
2
|
+
export function stackGroupKey(column, lane) {
|
|
3
|
+
return JSON.stringify(lane === undefined ? [column] : [column, lane]);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Column-major group list for the stack layout. Empty groups are omitted, even
|
|
7
|
+
* when collapsed; a group is collapsed when its column or its lane is.
|
|
8
|
+
*/
|
|
9
|
+
export function stackGroups(model) {
|
|
10
|
+
const groups = [];
|
|
11
|
+
const lanes = model.swimlanes;
|
|
12
|
+
model.columns.forEach((column, index) => {
|
|
13
|
+
if (!lanes.length) {
|
|
14
|
+
if (column.cards.length)
|
|
15
|
+
groups.push({
|
|
16
|
+
key: stackGroupKey(column.id),
|
|
17
|
+
column,
|
|
18
|
+
cards: column.cards,
|
|
19
|
+
collapsed: column.collapsed,
|
|
20
|
+
});
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
for (const lane of lanes) {
|
|
24
|
+
const cell = lane.cells[index];
|
|
25
|
+
if (!cell.cards.length)
|
|
26
|
+
continue;
|
|
27
|
+
groups.push({
|
|
28
|
+
key: stackGroupKey(column.id, lane.id),
|
|
29
|
+
column,
|
|
30
|
+
swimlane: lane,
|
|
31
|
+
cards: cell.cards,
|
|
32
|
+
collapsed: column.collapsed || lane.collapsed,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return groups;
|
|
37
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CardID, KanbanModel } from "@svar-ui/kanban-store";
|
|
2
|
+
import type { CardProjectionTarget } from "../types.js";
|
|
3
|
+
/** Drop resolution for a cell that lays cards out itself (e.g. a card grid). */
|
|
4
|
+
export type CellDestination = {
|
|
5
|
+
before: (x: number, y: number, source: CardID | null) => CardID | null;
|
|
6
|
+
/** Changes when the cell's layout changes (rewrap or new card size). */
|
|
7
|
+
layout: () => string;
|
|
8
|
+
};
|
|
9
|
+
export declare const cellDestinations: WeakMap<HTMLElement, CellDestination>;
|
|
10
|
+
/** Card cell of this board under the hit element; cells of other boards are ignored. */
|
|
11
|
+
export declare function dropCell(root: HTMLElement, hit: Element | null): HTMLElement | null;
|
|
12
|
+
/**
|
|
13
|
+
* Destination under a viewport point, shared by internal moves and external
|
|
14
|
+
* projections. Pure: returns null outside an expanded, rendered cell and never
|
|
15
|
+
* keeps a previous result. `exclude` is the internally dragged card, if any.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveDropTarget(root: HTMLElement, model: Pick<KanbanModel, "columns" | "swimlanes">, x: number, y: number, exclude: CardID | null, hit?: Element | null): CardProjectionTarget | null;
|
|
18
|
+
export declare function sameTarget(a: CardProjectionTarget | null | undefined, b: CardProjectionTarget | null | undefined): boolean;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { getID } from "@svar-ui/lib-dom";
|
|
2
|
+
// Retained cell shells provide current geometry and O(1) indexed ID resolution.
|
|
3
|
+
export const cellDestinations = new WeakMap();
|
|
4
|
+
/** Card cell of this board under the hit element; cells of other boards are ignored. */
|
|
5
|
+
export function dropCell(root, hit) {
|
|
6
|
+
const cell = hit?.closest("[data-kanban-column-cards]") ?? null;
|
|
7
|
+
return cell && root.contains(cell) ? cell : null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Destination under a viewport point, shared by internal moves and external
|
|
11
|
+
* projections. Pure: returns null outside an expanded, rendered cell and never
|
|
12
|
+
* keeps a previous result. `exclude` is the internally dragged card, if any.
|
|
13
|
+
*/
|
|
14
|
+
export function resolveDropTarget(root, model, x, y, exclude, hit = document.elementFromPoint(x, y)) {
|
|
15
|
+
const cell = dropCell(root, hit);
|
|
16
|
+
if (!cell)
|
|
17
|
+
return null;
|
|
18
|
+
const columnId = getID(cell, "data-kanban-column-cards");
|
|
19
|
+
if (columnId == null)
|
|
20
|
+
return null;
|
|
21
|
+
const column = model.columns.find(c => c.id === columnId);
|
|
22
|
+
if (!column || column.collapsed)
|
|
23
|
+
return null;
|
|
24
|
+
const laneId = getID(cell, "data-kanban-swimlane");
|
|
25
|
+
const lane = model.swimlanes.find(l => l.id === laneId);
|
|
26
|
+
if (model.swimlanes.length > 0 && (!lane || lane.collapsed))
|
|
27
|
+
return null;
|
|
28
|
+
const swimlane = lane?.id;
|
|
29
|
+
const cards = lane
|
|
30
|
+
? (lane.cells.find(c => c.column === column.id)?.cards ?? [])
|
|
31
|
+
: column.cards;
|
|
32
|
+
// Slots refer to the full area, even when no cards are currently rendered.
|
|
33
|
+
if (hit?.closest(".wx-card-list-start"))
|
|
34
|
+
return {
|
|
35
|
+
column: column.id,
|
|
36
|
+
swimlane,
|
|
37
|
+
before: cards.find(c => c.id !== exclude)?.id ?? null,
|
|
38
|
+
};
|
|
39
|
+
if (hit?.closest(".wx-card-list-end"))
|
|
40
|
+
return { column: column.id, swimlane, before: null };
|
|
41
|
+
const custom = cellDestinations.get(cell);
|
|
42
|
+
if (custom)
|
|
43
|
+
return {
|
|
44
|
+
column: column.id,
|
|
45
|
+
swimlane,
|
|
46
|
+
before: custom.before(x, y, exclude),
|
|
47
|
+
};
|
|
48
|
+
// Stack: insert before the first rendered card whose midpoint is below y.
|
|
49
|
+
for (const cardEl of Array.from(cell.querySelectorAll("[data-kanban-card-id]"))) {
|
|
50
|
+
const id = getID(cardEl, "data-kanban-card-id");
|
|
51
|
+
if (id === exclude)
|
|
52
|
+
continue;
|
|
53
|
+
const rect = cardEl.getBoundingClientRect();
|
|
54
|
+
if (y < rect.top + rect.height / 2) {
|
|
55
|
+
const before = renderedCardId(cards, id);
|
|
56
|
+
if (before != null)
|
|
57
|
+
return { column: column.id, swimlane, before };
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Below the rendered slice of a virtual list: before the next unrendered card.
|
|
62
|
+
const before = renderedCardId(cards, getID(cell, "data-kanban-after-rendered-before-id"));
|
|
63
|
+
return { column: column.id, swimlane, before };
|
|
64
|
+
}
|
|
65
|
+
export function sameTarget(a, b) {
|
|
66
|
+
if (!a || !b)
|
|
67
|
+
return !a && !b;
|
|
68
|
+
return (a.column === b.column && a.swimlane === b.swimlane && a.before === b.before);
|
|
69
|
+
}
|
|
70
|
+
function renderedCardId(cards, id) {
|
|
71
|
+
if (id == null)
|
|
72
|
+
return null;
|
|
73
|
+
return cards.find(card => card.id === id)?.id ?? null;
|
|
74
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!-- @component Opens on a click of the card ⋯ button (card.menu: true). -->
|
|
2
|
+
<script lang="ts">import { getMenuOptions } from "@svar-ui/kanban-store";
|
|
3
|
+
import KanbanMenu from "./KanbanMenu.svelte";
|
|
4
|
+
import { execCardMenuAction, resolveCard } from "./helpers.js";
|
|
5
|
+
let { api = null, ...rest } = $props();
|
|
6
|
+
let menu = $state();
|
|
7
|
+
export function show(ev, obj) {
|
|
8
|
+
menu?.show(ev, obj);
|
|
9
|
+
}
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<KanbanMenu
|
|
13
|
+
{...rest}
|
|
14
|
+
trigger="click"
|
|
15
|
+
dataKey="cardMenu"
|
|
16
|
+
resolve={id => resolveCard(api, id)}
|
|
17
|
+
defaults={getMenuOptions}
|
|
18
|
+
builtin={(action, card) => execCardMenuAction(api, action, card)}
|
|
19
|
+
bind:this={menu}
|
|
20
|
+
/>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { KanbanCard, KanbanMenuProps } from "../types.js";
|
|
2
|
+
/** Opens on a click of the card ⋯ button (card.menu: true). */
|
|
3
|
+
declare const CardActionMenu: import("svelte").Component<KanbanMenuProps<KanbanCard>, {
|
|
4
|
+
show: (ev: any, obj?: any) => void;
|
|
5
|
+
}, "">;
|
|
6
|
+
type CardActionMenu = ReturnType<typeof CardActionMenu>;
|
|
7
|
+
export default CardActionMenu;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!-- @component Opens on a right click anywhere on a card. -->
|
|
2
|
+
<script lang="ts">import { getMenuOptions } from "@svar-ui/kanban-store";
|
|
3
|
+
import KanbanMenu from "./KanbanMenu.svelte";
|
|
4
|
+
import { execCardMenuAction, resolveCard } from "./helpers.js";
|
|
5
|
+
let { api = null, ...rest } = $props();
|
|
6
|
+
let menu = $state();
|
|
7
|
+
export function show(ev, obj) {
|
|
8
|
+
menu?.show(ev, obj);
|
|
9
|
+
}
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<KanbanMenu
|
|
13
|
+
{...rest}
|
|
14
|
+
trigger="contextmenu"
|
|
15
|
+
dataKey="id"
|
|
16
|
+
resolve={id => resolveCard(api, id)}
|
|
17
|
+
defaults={getMenuOptions}
|
|
18
|
+
builtin={(action, card) => execCardMenuAction(api, action, card)}
|
|
19
|
+
bind:this={menu}
|
|
20
|
+
/>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { KanbanCard, KanbanMenuProps } from "../types.js";
|
|
2
|
+
/** Opens on a right click anywhere on a card. */
|
|
3
|
+
declare const CardContextMenu: import("svelte").Component<KanbanMenuProps<KanbanCard>, {
|
|
4
|
+
show: (ev: any, obj?: any) => void;
|
|
5
|
+
}, "">;
|
|
6
|
+
type CardContextMenu = ReturnType<typeof CardContextMenu>;
|
|
7
|
+
export default CardContextMenu;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!-- @component Opens on a click of the column header ⋯ button (column.menu: true). -->
|
|
2
|
+
<script lang="ts">import { getColumnMenuOptions } from "@svar-ui/kanban-store";
|
|
3
|
+
import KanbanMenu from "./KanbanMenu.svelte";
|
|
4
|
+
import { defaultColumnOptions, execColumnMenuAction, locateLane, resolveColumn } from "./helpers.js";
|
|
5
|
+
let { api = null, ...rest } = $props();
|
|
6
|
+
let menu = $state();
|
|
7
|
+
export function show(ev, obj) {
|
|
8
|
+
menu?.show(ev, obj);
|
|
9
|
+
}
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<KanbanMenu
|
|
13
|
+
{...rest}
|
|
14
|
+
trigger="click"
|
|
15
|
+
dataKey="columnMenu"
|
|
16
|
+
resolve={(id, ev) => resolveColumn(api, id, locateLane(ev.target as Element))}
|
|
17
|
+
defaults={ctx => defaultColumnOptions(getColumnMenuOptions(), ctx)}
|
|
18
|
+
builtin={(action, ctx) => execColumnMenuAction(api, action, ctx)}
|
|
19
|
+
bind:this={menu}
|
|
20
|
+
/>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ColumnMenuContext, KanbanMenuProps } from "../types.js";
|
|
2
|
+
/** Opens on a click of the column header ⋯ button (column.menu: true). */
|
|
3
|
+
declare const ColumnActionMenu: import("svelte").Component<KanbanMenuProps<ColumnMenuContext>, {
|
|
4
|
+
show: (ev: any, obj?: any) => void;
|
|
5
|
+
}, "">;
|
|
6
|
+
type ColumnActionMenu = ReturnType<typeof ColumnActionMenu>;
|
|
7
|
+
export default ColumnActionMenu;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!-- @component Opens on a right click anywhere on a column header. -->
|
|
2
|
+
<script lang="ts">import { getColumnMenuOptions } from "@svar-ui/kanban-store";
|
|
3
|
+
import KanbanMenu from "./KanbanMenu.svelte";
|
|
4
|
+
import { defaultColumnOptions, execColumnMenuAction, locateLane, resolveColumn } from "./helpers.js";
|
|
5
|
+
let { api = null, ...rest } = $props();
|
|
6
|
+
let menu = $state();
|
|
7
|
+
export function show(ev, obj) {
|
|
8
|
+
menu?.show(ev, obj);
|
|
9
|
+
}
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<KanbanMenu
|
|
13
|
+
{...rest}
|
|
14
|
+
trigger="contextmenu"
|
|
15
|
+
dataKey="columnId"
|
|
16
|
+
resolve={(id, ev) => resolveColumn(api, id, locateLane(ev.target as Element))}
|
|
17
|
+
defaults={ctx => defaultColumnOptions(getColumnMenuOptions(), ctx)}
|
|
18
|
+
builtin={(action, ctx) => execColumnMenuAction(api, action, ctx)}
|
|
19
|
+
bind:this={menu}
|
|
20
|
+
/>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ColumnMenuContext, KanbanMenuProps } from "../types.js";
|
|
2
|
+
/** Opens on a right click anywhere on a column header. */
|
|
3
|
+
declare const ColumnContextMenu: import("svelte").Component<KanbanMenuProps<ColumnMenuContext>, {
|
|
4
|
+
show: (ev: any, obj?: any) => void;
|
|
5
|
+
}, "">;
|
|
6
|
+
type ColumnContextMenu = ReturnType<typeof ColumnContextMenu>;
|
|
7
|
+
export default ColumnContextMenu;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<script lang="ts" generics="T">import { getContext } from "svelte";
|
|
2
|
+
import { ActionMenu, ContextMenu } from "@svar-ui/svelte-menu";
|
|
3
|
+
import { locale } from "@svar-ui/lib-dom";
|
|
4
|
+
import { en } from "@svar-ui/kanban-locales";
|
|
5
|
+
import { en as coreEn } from "@svar-ui/core-locales";
|
|
6
|
+
import { localizeOptions } from "./helpers.js";
|
|
7
|
+
let { options, resolver = null, filter = null, onclick, at = "point", css = "", children, trigger, dataKey, resolve, defaults, builtin } = $props();
|
|
8
|
+
// the menu wraps <Kanban> from the outside, so the kanban locale is not in
|
|
9
|
+
// context unless the host provides one
|
|
10
|
+
const _ = (getContext("wx-i18n") ?? locale({
|
|
11
|
+
...en,
|
|
12
|
+
...coreEn
|
|
13
|
+
})).getGroup("kanban");
|
|
14
|
+
// Items are resolved when the menu opens: the inner menu calls the resolver
|
|
15
|
+
// before it renders, so they can follow the target's current state.
|
|
16
|
+
let current = $state([]);
|
|
17
|
+
let active = null;
|
|
18
|
+
function itemResolver(id, ev) {
|
|
19
|
+
const ctx = resolve(id, ev);
|
|
20
|
+
if (!ctx) return null;
|
|
21
|
+
if (resolver && !resolver(ctx, ev)) return null;
|
|
22
|
+
const base = typeof options === "function" ? options(ctx) : options ?? defaults(ctx);
|
|
23
|
+
if (!base || !base.length) return null;
|
|
24
|
+
current = localizeOptions(base, _);
|
|
25
|
+
active = ctx;
|
|
26
|
+
return ctx;
|
|
27
|
+
}
|
|
28
|
+
function menuAction(ev) {
|
|
29
|
+
// closing without a choice (outside click, Escape) comes with no action
|
|
30
|
+
if (!ev?.action || !active) return;
|
|
31
|
+
builtin(ev.action, active);
|
|
32
|
+
onclick?.(ev);
|
|
33
|
+
}
|
|
34
|
+
function filterMenu(item, ctx) {
|
|
35
|
+
return filter ? filter(item, ctx) : true;
|
|
36
|
+
}
|
|
37
|
+
let menu = $state();
|
|
38
|
+
export function show(ev, obj) {
|
|
39
|
+
menu?.show(ev, obj);
|
|
40
|
+
}
|
|
41
|
+
const Menu = $derived(trigger === "click" ? ActionMenu : ContextMenu);
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<Menu
|
|
45
|
+
options={current}
|
|
46
|
+
resolver={itemResolver}
|
|
47
|
+
filter={filterMenu}
|
|
48
|
+
onclick={menuAction}
|
|
49
|
+
{dataKey}
|
|
50
|
+
{at}
|
|
51
|
+
{css}
|
|
52
|
+
bind:this={menu}
|
|
53
|
+
>
|
|
54
|
+
{@render children?.()}
|
|
55
|
+
</Menu>
|
|
56
|
+
|
|
57
|
+
<style>
|
|
58
|
+
:global(.wx-menu .wx-option.wx-disabled) {
|
|
59
|
+
pointer-events: none;
|
|
60
|
+
}
|
|
61
|
+
:global(.wx-menu .wx-option.wx-disabled .wx-value),
|
|
62
|
+
:global(.wx-menu .wx-option.wx-disabled .wx-icon) {
|
|
63
|
+
color: var(--wx-color-font-disabled);
|
|
64
|
+
}
|
|
65
|
+
</style>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { KanbanMenuProps } from "../types.js";
|
|
2
|
+
declare function $$render<T>(): {
|
|
3
|
+
props: Omit<KanbanMenuProps<T>, "api"> & {
|
|
4
|
+
/** `click` - ActionMenu, `contextmenu` - ContextMenu. */
|
|
5
|
+
trigger: "click" | "contextmenu";
|
|
6
|
+
/** Attribute (camelCase) carrying the target id, e.g. `columnMenu`. */
|
|
7
|
+
dataKey: string;
|
|
8
|
+
resolve: (id: any, ev: MouseEvent) => T | null;
|
|
9
|
+
defaults: (ctx: T) => any[];
|
|
10
|
+
builtin: (action: any, ctx: T) => void;
|
|
11
|
+
};
|
|
12
|
+
exports: {
|
|
13
|
+
show: (ev: any, obj?: any) => void;
|
|
14
|
+
};
|
|
15
|
+
bindings: "";
|
|
16
|
+
slots: {};
|
|
17
|
+
events: {};
|
|
18
|
+
};
|
|
19
|
+
declare class __sveltets_Render<T> {
|
|
20
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
21
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
22
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
23
|
+
bindings(): "";
|
|
24
|
+
exports(): {
|
|
25
|
+
show: (ev: any, obj?: any) => void;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
interface $$IsomorphicComponent {
|
|
29
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
30
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
31
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
32
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
33
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
34
|
+
}
|
|
35
|
+
declare const KanbanMenu: $$IsomorphicComponent;
|
|
36
|
+
type KanbanMenu<T> = InstanceType<typeof KanbanMenu<T>>;
|
|
37
|
+
export default KanbanMenu;
|