@feitio/vanilla 0.2.1 → 0.3.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/README.md +3 -2
- package/dist/feitio.js +766 -6
- package/dist/kanban.js +789 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/kanban/actions/kanban-flip.d.ts +33 -0
- package/dist/types/kanban/actions/move-card.d.ts +19 -0
- package/dist/types/kanban/actions/sync-kanban.d.ts +4 -0
- package/dist/types/kanban/actions/wire-create.d.ts +12 -0
- package/dist/types/kanban/actions/wire-drag.d.ts +8 -0
- package/dist/types/kanban/actions/wire-kanbans.d.ts +6 -0
- package/dist/types/kanban/actions/wire-minimap.d.ts +6 -0
- package/dist/types/kanban/actions/wire-move-menu.d.ts +5 -0
- package/dist/types/kanban/actions/wire-scroll-row.d.ts +5 -0
- package/dist/types/kanban/calculations/kanban-motion.d.ts +45 -0
- package/dist/types/kanban/calculations/kanban-rules.d.ts +8 -0
- package/dist/types/kanban/index.d.ts +11 -0
- package/package.json +11 -6
- package/src/index.ts +1 -0
- package/src/kanban/actions/kanban-flip.ts +172 -0
- package/src/kanban/actions/move-card.ts +61 -0
- package/src/kanban/actions/sync-kanban.ts +31 -0
- package/src/kanban/actions/wire-create.ts +84 -0
- package/src/kanban/actions/wire-drag.ts +240 -0
- package/src/kanban/actions/wire-kanbans.ts +36 -0
- package/src/kanban/actions/wire-minimap.ts +66 -0
- package/src/kanban/actions/wire-move-menu.ts +80 -0
- package/src/kanban/actions/wire-scroll-row.ts +58 -0
- package/src/kanban/calculations/kanban-motion.ts +98 -0
- package/src/kanban/calculations/kanban-rules.ts +19 -0
- package/src/kanban/index.ts +28 -0
package/dist/kanban.js
ADDED
|
@@ -0,0 +1,789 @@
|
|
|
1
|
+
// src/kanban/calculations/kanban-rules.ts
|
|
2
|
+
function targetsOf(attribute) {
|
|
3
|
+
return (attribute ?? "").split(/\s+/).filter(Boolean);
|
|
4
|
+
}
|
|
5
|
+
function canMove(targets, from, to) {
|
|
6
|
+
return to !== from && targets.includes(to);
|
|
7
|
+
}
|
|
8
|
+
function minimapScale(mapWidth, scrollWidth) {
|
|
9
|
+
return scrollWidth > 0 ? mapWidth / scrollWidth : 0;
|
|
10
|
+
}
|
|
11
|
+
function minimapScroll(x, scale, clientWidth) {
|
|
12
|
+
return scale > 0 ? Math.max(0, x / scale - clientWidth / 2) : 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/kanban/calculations/kanban-motion.ts
|
|
16
|
+
var FLY = { stiffness: 170, damping: 14 };
|
|
17
|
+
var SETTLE = { stiffness: 230, damping: 24 };
|
|
18
|
+
var HOP = { stiffness: 320, damping: 11 };
|
|
19
|
+
function springCurve(spring, maxFrames = 240) {
|
|
20
|
+
let x = 0;
|
|
21
|
+
let v = 0;
|
|
22
|
+
const out = [0];
|
|
23
|
+
const dt = 1 / 60;
|
|
24
|
+
for (let i = 0;i < maxFrames; i++) {
|
|
25
|
+
v += (-spring.stiffness * (x - 1) - spring.damping * v) * dt;
|
|
26
|
+
x += v * dt;
|
|
27
|
+
out.push(x);
|
|
28
|
+
if (Math.abs(x - 1) < 0.002 && Math.abs(v) < 0.01)
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
out[out.length - 1] = 1;
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
function curveDuration(curve) {
|
|
35
|
+
return curve.length * 1000 / 60;
|
|
36
|
+
}
|
|
37
|
+
function followStep(state, targetX, targetY) {
|
|
38
|
+
const vx = (state.vx + (targetX - state.x) * 0.3) * 0.62;
|
|
39
|
+
const vy = (state.vy + (targetY - state.y) * 0.3) * 0.62;
|
|
40
|
+
const lean = Math.max(-14, Math.min(14, vx * 1.2));
|
|
41
|
+
return {
|
|
42
|
+
x: state.x + vx,
|
|
43
|
+
y: state.y + vy,
|
|
44
|
+
vx,
|
|
45
|
+
vy,
|
|
46
|
+
tilt: state.tilt + (lean - state.tilt) * 0.18
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function flightTilt(dx) {
|
|
50
|
+
return Math.max(-9, Math.min(9, dx / 35));
|
|
51
|
+
}
|
|
52
|
+
function edgesVisible(scrollLeft, clientWidth, scrollWidth) {
|
|
53
|
+
return { start: scrollLeft > 8, end: scrollLeft + clientWidth < scrollWidth - 8 };
|
|
54
|
+
}
|
|
55
|
+
function autoScrollSpeed(pointerX, left, right, zone = 90, max = 16) {
|
|
56
|
+
if (pointerX < left + zone)
|
|
57
|
+
return -((left + zone - pointerX) / zone) * max;
|
|
58
|
+
if (pointerX > right - zone)
|
|
59
|
+
return (pointerX - (right - zone)) / zone * max;
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
function insertionIndex(middles, y) {
|
|
63
|
+
const i = middles.findIndex((m) => y < m);
|
|
64
|
+
return i === -1 ? middles.length : i;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/kanban/actions/kanban-flip.ts
|
|
68
|
+
function keyOf(el) {
|
|
69
|
+
if (el.classList.contains("feitio-kanban-card"))
|
|
70
|
+
return el.dataset.id ? `card:${el.dataset.id}` : undefined;
|
|
71
|
+
const col = el.closest(".col");
|
|
72
|
+
return col ? `add:${col.dataset.col}` : undefined;
|
|
73
|
+
}
|
|
74
|
+
function pieces(board) {
|
|
75
|
+
return [
|
|
76
|
+
...board.querySelectorAll(".col > .feitio-kanban-card:not(.draft), .col > .add")
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
function snapshot(board, moving) {
|
|
80
|
+
const rects = new Map;
|
|
81
|
+
const clones = new Map;
|
|
82
|
+
for (const el of pieces(board)) {
|
|
83
|
+
const key = keyOf(el);
|
|
84
|
+
const r = el.getBoundingClientRect();
|
|
85
|
+
if (key && r.width)
|
|
86
|
+
rects.set(key, { left: r.left, top: r.top, width: r.width });
|
|
87
|
+
if (key && moving && key === `card:${moving}`)
|
|
88
|
+
clones.set(key, el.cloneNode(true));
|
|
89
|
+
}
|
|
90
|
+
const widths = new Map;
|
|
91
|
+
for (const col of board.querySelectorAll(".col")) {
|
|
92
|
+
const w = col.getBoundingClientRect().width;
|
|
93
|
+
if (w)
|
|
94
|
+
widths.set(col.dataset.col ?? "", w);
|
|
95
|
+
}
|
|
96
|
+
return { rects, widths, clones };
|
|
97
|
+
}
|
|
98
|
+
function play(el, spring, frame) {
|
|
99
|
+
if (typeof el.animate !== "function")
|
|
100
|
+
return;
|
|
101
|
+
const curve = springCurve(spring);
|
|
102
|
+
return el.animate(curve.map(frame), { duration: curveDuration(curve), easing: "linear" });
|
|
103
|
+
}
|
|
104
|
+
function reduced(window) {
|
|
105
|
+
return window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
|
|
106
|
+
}
|
|
107
|
+
function animateFrom(window, board, before, motion) {
|
|
108
|
+
if (reduced(window))
|
|
109
|
+
return;
|
|
110
|
+
const after = new Map;
|
|
111
|
+
for (const el of pieces(board)) {
|
|
112
|
+
const key = keyOf(el);
|
|
113
|
+
const r = el.getBoundingClientRect();
|
|
114
|
+
if (key && r.width)
|
|
115
|
+
after.set(key, [el, r]);
|
|
116
|
+
}
|
|
117
|
+
for (const col of board.querySelectorAll(".col")) {
|
|
118
|
+
const w0 = before.widths.get(col.dataset.col ?? "");
|
|
119
|
+
const w1 = col.getBoundingClientRect().width;
|
|
120
|
+
if (!w0 || !w1 || Math.abs(w0 - w1) < 1)
|
|
121
|
+
continue;
|
|
122
|
+
play(col, SETTLE, (p) => ({
|
|
123
|
+
flexBasis: `${w0 + (w1 - w0) * p}px`,
|
|
124
|
+
flexGrow: 0,
|
|
125
|
+
flexShrink: 0
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
const mover = motion.id ? `card:${motion.id}` : undefined;
|
|
129
|
+
for (const [key, [el, r1]] of after) {
|
|
130
|
+
const isMover = key === mover;
|
|
131
|
+
let r0 = before.rects.get(key);
|
|
132
|
+
if (isMover && motion.from)
|
|
133
|
+
r0 = { left: motion.from.x, top: motion.from.y };
|
|
134
|
+
if (!r0) {
|
|
135
|
+
if (isMover)
|
|
136
|
+
play(el, FLY, (p) => ({
|
|
137
|
+
transform: `translateY(${-24 * (1 - p)}px) scale(${1 + 0.08 * (1 - p)})`,
|
|
138
|
+
opacity: Math.min(1, p * 2)
|
|
139
|
+
}));
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const dx = r0.left - r1.left;
|
|
143
|
+
const dy = r0.top - r1.top;
|
|
144
|
+
if (Math.abs(dx) < 1 && Math.abs(dy) < 1)
|
|
145
|
+
continue;
|
|
146
|
+
if (!isMover) {
|
|
147
|
+
play(el, SETTLE, (p) => ({ transform: `translate(${dx * (1 - p)}px, ${dy * (1 - p)}px)` }));
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const tilt = motion.from ? motion.from.tilt : flightTilt(dx);
|
|
151
|
+
const lift = motion.from ? 0.04 : 0.06;
|
|
152
|
+
el.style.zIndex = "5";
|
|
153
|
+
const run = play(el, FLY, (p) => ({
|
|
154
|
+
transform: `translate(${dx * (1 - p)}px, ${dy * (1 - p)}px) rotate(${tilt * (1 - p)}deg) scale(${1 + lift * Math.max(0, 1 - p)})`
|
|
155
|
+
}));
|
|
156
|
+
if (run)
|
|
157
|
+
run.onfinish = () => el.style.removeProperty("z-index");
|
|
158
|
+
}
|
|
159
|
+
if (!mover)
|
|
160
|
+
return;
|
|
161
|
+
const landed = after.get(mover);
|
|
162
|
+
const cols = board.querySelector(".cols");
|
|
163
|
+
if (landed && !motion.from && cols) {
|
|
164
|
+
const r = landed[1];
|
|
165
|
+
const box = cols.getBoundingClientRect();
|
|
166
|
+
if (r.right > box.right - 72)
|
|
167
|
+
cols.scrollBy({ left: r.right - box.right + 72, behavior: "smooth" });
|
|
168
|
+
else if (r.left < box.left + 72)
|
|
169
|
+
cols.scrollBy({ left: r.left - box.left - 72, behavior: "smooth" });
|
|
170
|
+
}
|
|
171
|
+
const r0 = before.rects.get(mover);
|
|
172
|
+
const clone = before.clones.get(mover);
|
|
173
|
+
const tab = board.querySelector(`.tabs [data-col="${motion.to}"]`);
|
|
174
|
+
if (landed || !r0 || !clone || !tab || typeof tab.animate !== "function")
|
|
175
|
+
return;
|
|
176
|
+
const tr = tab.getBoundingClientRect();
|
|
177
|
+
const ghost = window.document.createElement("div");
|
|
178
|
+
ghost.className = "feitio-kanban-ghost";
|
|
179
|
+
ghost.setAttribute("aria-hidden", "true");
|
|
180
|
+
Object.assign(ghost.style, { left: `${r0.left}px`, top: `${r0.top}px`, width: `${r0.width}px` });
|
|
181
|
+
clone.removeAttribute("id");
|
|
182
|
+
ghost.append(clone);
|
|
183
|
+
window.document.body.append(ghost);
|
|
184
|
+
const dx = tr.left + tr.width / 2 - (r0.left + r0.width / 2);
|
|
185
|
+
const dy = tr.top + tr.height / 2 - (r0.top + clone.getBoundingClientRect().height / 2);
|
|
186
|
+
const flight = ghost.animate([
|
|
187
|
+
{ transform: "translate(0, 0) scale(1) rotate(0deg)", opacity: 1 },
|
|
188
|
+
{
|
|
189
|
+
transform: `translate(${dx * 0.35}px, ${dy * 0.35 - 30}px) scale(0.7) rotate(-5deg)`,
|
|
190
|
+
opacity: 1,
|
|
191
|
+
offset: 0.45
|
|
192
|
+
},
|
|
193
|
+
{ transform: `translate(${dx}px, ${dy}px) scale(0.08) rotate(-14deg)`, opacity: 0.2 }
|
|
194
|
+
], { duration: 560, easing: "cubic-bezier(0.45, 0, 0.8, 0.4)" });
|
|
195
|
+
flight.onfinish = () => {
|
|
196
|
+
ghost.remove();
|
|
197
|
+
play(tab, HOP, (p) => ({ transform: `scale(${1 + 0.4 * (1 - p)})` }));
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// src/kanban/actions/sync-kanban.ts
|
|
202
|
+
function setText(el, text) {
|
|
203
|
+
if (el && el.textContent !== text)
|
|
204
|
+
el.textContent = text;
|
|
205
|
+
}
|
|
206
|
+
function syncKanban(board) {
|
|
207
|
+
for (const col of board.querySelectorAll(".col")) {
|
|
208
|
+
const n = col.querySelectorAll(":scope > .feitio-kanban-card:not(.draft)").length;
|
|
209
|
+
const id = col.dataset.col ?? "";
|
|
210
|
+
if (col.hasAttribute("data-empty") !== (n === 0))
|
|
211
|
+
col.toggleAttribute("data-empty", n === 0);
|
|
212
|
+
setText(col.querySelector(".col-head .n"), String(n));
|
|
213
|
+
const empty = col.querySelector(":scope > .empty");
|
|
214
|
+
if (empty && empty.hidden !== n > 0)
|
|
215
|
+
empty.hidden = n > 0;
|
|
216
|
+
const tab = board.querySelector(`.tabs [data-col="${id}"]`);
|
|
217
|
+
if (!tab)
|
|
218
|
+
continue;
|
|
219
|
+
if (tab.hasAttribute("data-has") !== n > 0)
|
|
220
|
+
tab.toggleAttribute("data-has", n > 0);
|
|
221
|
+
setText(tab.querySelector(".n"), String(n));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function chooseStage(board, id) {
|
|
225
|
+
for (const col of board.querySelectorAll(".col")) {
|
|
226
|
+
const on = col.dataset.col === id;
|
|
227
|
+
if (col.hasAttribute("data-current") !== on)
|
|
228
|
+
col.toggleAttribute("data-current", on);
|
|
229
|
+
}
|
|
230
|
+
for (const tab of board.querySelectorAll(".tabs [data-col]")) {
|
|
231
|
+
tab.setAttribute("aria-pressed", String(tab.dataset.col === id));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/kanban/actions/move-card.ts
|
|
236
|
+
function moveCard(window, board, card, to, index, before, from) {
|
|
237
|
+
const fromCol = card.closest(".col")?.dataset.col ?? "";
|
|
238
|
+
const id = card.dataset.id ?? "";
|
|
239
|
+
const target = board.querySelector(`.col[data-col="${to}"]`);
|
|
240
|
+
if (!target || !canMove(targetsOf(card.dataset.to), fromCol, to))
|
|
241
|
+
return false;
|
|
242
|
+
const cards = [
|
|
243
|
+
...target.querySelectorAll(":scope > .feitio-kanban-card:not(.draft)")
|
|
244
|
+
];
|
|
245
|
+
const place = index === undefined ? cards.length : Math.min(index, cards.length);
|
|
246
|
+
const picture = before ?? snapshot(board, id);
|
|
247
|
+
if (!picture.clones.size) {
|
|
248
|
+
const own = snapshot(board, id).clones;
|
|
249
|
+
for (const [k, v] of own)
|
|
250
|
+
picture.clones.set(k, v);
|
|
251
|
+
}
|
|
252
|
+
const detail = { card, id, from: fromCol, to, index: place };
|
|
253
|
+
const event = new CustomEvent("feitio-kanban-move", {
|
|
254
|
+
bubbles: true,
|
|
255
|
+
cancelable: true,
|
|
256
|
+
detail
|
|
257
|
+
});
|
|
258
|
+
const done = () => {
|
|
259
|
+
syncKanban(board);
|
|
260
|
+
animateFrom(window, board, picture, { id, to, from });
|
|
261
|
+
};
|
|
262
|
+
if (board.dispatchEvent(event)) {
|
|
263
|
+
const ref = cards[place] ?? target.querySelector(":scope > .add");
|
|
264
|
+
target.insertBefore(card, ref);
|
|
265
|
+
syncKanban(board);
|
|
266
|
+
window.requestAnimationFrame(done);
|
|
267
|
+
} else {
|
|
268
|
+
window.requestAnimationFrame(() => window.requestAnimationFrame(done));
|
|
269
|
+
}
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// src/kanban/actions/wire-create.ts
|
|
274
|
+
var drafts = 0;
|
|
275
|
+
function wireCreate(window, board) {
|
|
276
|
+
const doc = window.document;
|
|
277
|
+
board.addEventListener("click", (event) => {
|
|
278
|
+
const add = event.target.closest(".col > .add");
|
|
279
|
+
if (!add || !board.contains(add))
|
|
280
|
+
return;
|
|
281
|
+
const col = add.parentElement;
|
|
282
|
+
const id = `${board.id || "kanban"}-new-${++drafts}`;
|
|
283
|
+
const form = doc.createElement("form");
|
|
284
|
+
form.className = "feitio-kanban-card draft feitio-place";
|
|
285
|
+
const label = doc.createElement("label");
|
|
286
|
+
label.htmlFor = id;
|
|
287
|
+
label.textContent = add.dataset.field ?? "";
|
|
288
|
+
const field = doc.createElement("textarea");
|
|
289
|
+
field.className = "feitio-textarea";
|
|
290
|
+
field.id = id;
|
|
291
|
+
field.required = true;
|
|
292
|
+
field.rows = 2;
|
|
293
|
+
const actions = doc.createElement("div");
|
|
294
|
+
actions.className = "actions";
|
|
295
|
+
const save = doc.createElement("button");
|
|
296
|
+
save.type = "submit";
|
|
297
|
+
save.className = "feitio-button";
|
|
298
|
+
save.dataset.variant = "primary";
|
|
299
|
+
save.dataset.size = "small";
|
|
300
|
+
save.textContent = add.dataset.save ?? "Save";
|
|
301
|
+
const cancel = doc.createElement("button");
|
|
302
|
+
cancel.type = "button";
|
|
303
|
+
cancel.className = "feitio-button";
|
|
304
|
+
cancel.dataset.size = "small";
|
|
305
|
+
cancel.textContent = add.dataset.cancel ?? "Cancel";
|
|
306
|
+
actions.append(save, cancel);
|
|
307
|
+
form.append(label, field, actions);
|
|
308
|
+
add.hidden = true;
|
|
309
|
+
col.insertBefore(form, add);
|
|
310
|
+
field.focus();
|
|
311
|
+
const close = () => {
|
|
312
|
+
form.remove();
|
|
313
|
+
add.hidden = false;
|
|
314
|
+
add.focus();
|
|
315
|
+
};
|
|
316
|
+
cancel.addEventListener("click", close);
|
|
317
|
+
form.addEventListener("keydown", (e) => {
|
|
318
|
+
if (e.key === "Escape")
|
|
319
|
+
close();
|
|
320
|
+
});
|
|
321
|
+
form.addEventListener("submit", (e) => {
|
|
322
|
+
e.preventDefault();
|
|
323
|
+
const text = field.value.trim();
|
|
324
|
+
if (!text)
|
|
325
|
+
return field.focus();
|
|
326
|
+
const before = snapshot(board);
|
|
327
|
+
const known = new Set([...col.querySelectorAll(":scope > .feitio-kanban-card")].map((c) => c.dataset.id));
|
|
328
|
+
const detail = { column: col.dataset.col ?? "", element: col, text };
|
|
329
|
+
board.dispatchEvent(new CustomEvent("feitio-kanban-create", { bubbles: true, detail }));
|
|
330
|
+
close();
|
|
331
|
+
window.requestAnimationFrame(() => {
|
|
332
|
+
syncKanban(board);
|
|
333
|
+
const fresh = [
|
|
334
|
+
...col.querySelectorAll(":scope > .feitio-kanban-card:not(.draft)")
|
|
335
|
+
].find((c) => !known.has(c.dataset.id));
|
|
336
|
+
animateFrom(window, board, before, { id: fresh?.dataset.id });
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/kanban/actions/wire-drag.ts
|
|
343
|
+
function wireDrag(window, board) {
|
|
344
|
+
const doc = window.document;
|
|
345
|
+
const cols = () => board.querySelector(".cols");
|
|
346
|
+
board.addEventListener("pointerdown", (event) => {
|
|
347
|
+
const card = event.target.closest(".col > .feitio-kanban-card");
|
|
348
|
+
if (!card || !board.contains(card) || card.classList.contains("draft"))
|
|
349
|
+
return;
|
|
350
|
+
if (event.button !== 0 || event.pointerType === "touch")
|
|
351
|
+
return;
|
|
352
|
+
if (event.target.closest("button, a, input, textarea, select, label"))
|
|
353
|
+
return;
|
|
354
|
+
if (!targetsOf(card.dataset.to).length)
|
|
355
|
+
return;
|
|
356
|
+
const row = cols();
|
|
357
|
+
if (!row || window.getComputedStyle(row).display !== "flex")
|
|
358
|
+
return;
|
|
359
|
+
event.preventDefault();
|
|
360
|
+
const sx = event.clientX;
|
|
361
|
+
const sy = event.clientY;
|
|
362
|
+
let held;
|
|
363
|
+
const stop = () => {
|
|
364
|
+
window.removeEventListener("pointermove", onMove);
|
|
365
|
+
window.removeEventListener("pointerup", onUp);
|
|
366
|
+
window.removeEventListener("keydown", onKey);
|
|
367
|
+
};
|
|
368
|
+
const onMove = (e) => {
|
|
369
|
+
if (!held) {
|
|
370
|
+
if (Math.hypot(e.clientX - sx, e.clientY - sy) < 5)
|
|
371
|
+
return;
|
|
372
|
+
held = lift(e, card);
|
|
373
|
+
}
|
|
374
|
+
held.px = e.clientX;
|
|
375
|
+
held.py = e.clientY;
|
|
376
|
+
hover(held);
|
|
377
|
+
};
|
|
378
|
+
const onUp = () => {
|
|
379
|
+
stop();
|
|
380
|
+
if (held)
|
|
381
|
+
letGo(held, false);
|
|
382
|
+
};
|
|
383
|
+
const onKey = (e) => {
|
|
384
|
+
if (e.key !== "Escape" || !held)
|
|
385
|
+
return;
|
|
386
|
+
stop();
|
|
387
|
+
letGo(held, true);
|
|
388
|
+
};
|
|
389
|
+
window.addEventListener("pointermove", onMove);
|
|
390
|
+
window.addEventListener("pointerup", onUp);
|
|
391
|
+
window.addEventListener("keydown", onKey);
|
|
392
|
+
});
|
|
393
|
+
function lift(event, card) {
|
|
394
|
+
const r = card.getBoundingClientRect();
|
|
395
|
+
const ghost = doc.createElement("div");
|
|
396
|
+
ghost.className = "feitio-kanban-ghost";
|
|
397
|
+
ghost.dataset.motion = "direct";
|
|
398
|
+
ghost.setAttribute("aria-hidden", "true");
|
|
399
|
+
ghost.style.width = `${r.width}px`;
|
|
400
|
+
const copy = card.cloneNode(true);
|
|
401
|
+
copy.removeAttribute("id");
|
|
402
|
+
ghost.append(copy);
|
|
403
|
+
doc.body.append(ghost);
|
|
404
|
+
const slot = doc.createElement("div");
|
|
405
|
+
slot.className = "slot";
|
|
406
|
+
slot.style.blockSize = `${r.height}px`;
|
|
407
|
+
const home = card.closest(".col");
|
|
408
|
+
const homeNext = card.nextSibling;
|
|
409
|
+
card.replaceWith(slot);
|
|
410
|
+
doc.documentElement.setAttribute("data-kanban-dragging", "");
|
|
411
|
+
board.setAttribute("data-dragging", "");
|
|
412
|
+
const targets = targetsOf(card.dataset.to);
|
|
413
|
+
for (const col of board.querySelectorAll(".col")) {
|
|
414
|
+
if (col !== home && !targets.includes(col.dataset.col ?? ""))
|
|
415
|
+
col.setAttribute("data-blocked", "");
|
|
416
|
+
}
|
|
417
|
+
const held = {
|
|
418
|
+
card,
|
|
419
|
+
ghost,
|
|
420
|
+
slot,
|
|
421
|
+
home,
|
|
422
|
+
homeNext,
|
|
423
|
+
offX: event.clientX - r.left,
|
|
424
|
+
offY: event.clientY - r.top,
|
|
425
|
+
x: r.left,
|
|
426
|
+
y: r.top,
|
|
427
|
+
vx: 0,
|
|
428
|
+
vy: 0,
|
|
429
|
+
tilt: 0,
|
|
430
|
+
px: event.clientX,
|
|
431
|
+
py: event.clientY,
|
|
432
|
+
running: true
|
|
433
|
+
};
|
|
434
|
+
follow(held);
|
|
435
|
+
return held;
|
|
436
|
+
}
|
|
437
|
+
function follow(held) {
|
|
438
|
+
if (!held.running)
|
|
439
|
+
return;
|
|
440
|
+
const tx = held.px - held.offX;
|
|
441
|
+
const ty = held.py - held.offY;
|
|
442
|
+
if (reduced(window))
|
|
443
|
+
Object.assign(held, { x: tx, y: ty, vx: 0, vy: 0, tilt: 0 });
|
|
444
|
+
else
|
|
445
|
+
Object.assign(held, followStep(held, tx, ty));
|
|
446
|
+
held.ghost.style.transform = `translate(${held.x}px, ${held.y}px) rotate(${held.tilt}deg) scale(1.04)`;
|
|
447
|
+
const row = cols();
|
|
448
|
+
if (row) {
|
|
449
|
+
const r = row.getBoundingClientRect();
|
|
450
|
+
const v = autoScrollSpeed(held.px, r.left, r.right);
|
|
451
|
+
if (v) {
|
|
452
|
+
row.scrollLeft += v;
|
|
453
|
+
hover(held);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
window.requestAnimationFrame(() => follow(held));
|
|
457
|
+
}
|
|
458
|
+
function hover(held) {
|
|
459
|
+
const under = doc.elementFromPoint(held.px, held.py)?.closest(".col");
|
|
460
|
+
const ok = Boolean(under && board.contains(under) && under !== held.home && !under.hasAttribute("data-blocked"));
|
|
461
|
+
const dest = ok && under ? under : held.home;
|
|
462
|
+
let before;
|
|
463
|
+
if (ok) {
|
|
464
|
+
const cards = [
|
|
465
|
+
...dest.querySelectorAll(":scope > .feitio-kanban-card:not(.draft)")
|
|
466
|
+
];
|
|
467
|
+
const i = insertionIndex(cards.map((c) => {
|
|
468
|
+
const r = c.getBoundingClientRect();
|
|
469
|
+
return r.top + r.height / 2;
|
|
470
|
+
}), held.py);
|
|
471
|
+
before = cards[i] ?? dest.querySelector(":scope > .add");
|
|
472
|
+
} else {
|
|
473
|
+
before = held.homeNext && held.homeNext.parentNode === held.home ? held.homeNext : held.home.querySelector(":scope > .add");
|
|
474
|
+
}
|
|
475
|
+
for (const col of board.querySelectorAll(".col"))
|
|
476
|
+
col.toggleAttribute("data-over", ok && col === under);
|
|
477
|
+
if (held.slot.parentNode === dest && held.slot.nextSibling === before)
|
|
478
|
+
return;
|
|
479
|
+
const moving = [
|
|
480
|
+
...board.querySelectorAll(".col > .feitio-kanban-card, .col > .add")
|
|
481
|
+
];
|
|
482
|
+
const first = new Map(moving.map((m) => [m, m.getBoundingClientRect()]));
|
|
483
|
+
const widths = new Map([...board.querySelectorAll(".col")].map((c) => [
|
|
484
|
+
c,
|
|
485
|
+
c.getBoundingClientRect().width
|
|
486
|
+
]));
|
|
487
|
+
if (held.opened && held.opened !== dest) {
|
|
488
|
+
held.opened.setAttribute("data-empty", "");
|
|
489
|
+
held.opened = undefined;
|
|
490
|
+
}
|
|
491
|
+
if (dest !== held.home && dest.hasAttribute("data-empty")) {
|
|
492
|
+
dest.removeAttribute("data-empty");
|
|
493
|
+
held.opened = dest;
|
|
494
|
+
}
|
|
495
|
+
dest.insertBefore(held.slot, before);
|
|
496
|
+
if (reduced(window))
|
|
497
|
+
return;
|
|
498
|
+
for (const [col, w0] of widths) {
|
|
499
|
+
const w1 = col.getBoundingClientRect().width;
|
|
500
|
+
if (Math.abs(w1 - w0) > 1)
|
|
501
|
+
play(col, SETTLE, (p) => ({
|
|
502
|
+
flexBasis: `${w0 + (w1 - w0) * p}px`,
|
|
503
|
+
flexGrow: 0,
|
|
504
|
+
flexShrink: 0
|
|
505
|
+
}));
|
|
506
|
+
}
|
|
507
|
+
for (const m of moving) {
|
|
508
|
+
const a = first.get(m);
|
|
509
|
+
const b = m.getBoundingClientRect();
|
|
510
|
+
const dx = a.left - b.left;
|
|
511
|
+
const dy = a.top - b.top;
|
|
512
|
+
if (Math.abs(dx) > 0.5 || Math.abs(dy) > 0.5)
|
|
513
|
+
play(m, SETTLE, (p) => ({ transform: `translate(${dx * (1 - p)}px, ${dy * (1 - p)}px)` }));
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
function letGo(held, cancel) {
|
|
517
|
+
held.running = false;
|
|
518
|
+
doc.documentElement.removeAttribute("data-kanban-dragging");
|
|
519
|
+
board.removeAttribute("data-dragging");
|
|
520
|
+
for (const col of board.querySelectorAll(".col")) {
|
|
521
|
+
col.removeAttribute("data-blocked");
|
|
522
|
+
col.removeAttribute("data-over");
|
|
523
|
+
}
|
|
524
|
+
const dest = held.slot.closest(".col");
|
|
525
|
+
const index = [
|
|
526
|
+
...dest.querySelectorAll(":scope > .feitio-kanban-card:not(.draft), :scope > .slot")
|
|
527
|
+
].indexOf(held.slot);
|
|
528
|
+
const id = held.card.dataset.id ?? "";
|
|
529
|
+
const before = snapshot(board);
|
|
530
|
+
const from = { x: held.x, y: held.y, tilt: held.tilt };
|
|
531
|
+
held.ghost.remove();
|
|
532
|
+
held.home.insertBefore(held.card, held.homeNext && held.homeNext.parentNode === held.home ? held.homeNext : null);
|
|
533
|
+
held.slot.remove();
|
|
534
|
+
if (held.opened)
|
|
535
|
+
held.opened.setAttribute("data-empty", "");
|
|
536
|
+
if (!cancel && dest !== held.home && moveCard(window, board, held.card, dest.dataset.col ?? "", index, before, from))
|
|
537
|
+
return;
|
|
538
|
+
window.requestAnimationFrame(() => animateFrom(window, board, before, { id, from }));
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/kanban/actions/wire-minimap.ts
|
|
543
|
+
var WIDTH = 176;
|
|
544
|
+
function wireMinimap(window, board) {
|
|
545
|
+
const map = board.querySelector(":scope > .minimap");
|
|
546
|
+
const cols = board.querySelector(".cols");
|
|
547
|
+
if (!map || !cols)
|
|
548
|
+
return () => {};
|
|
549
|
+
let scale = 0;
|
|
550
|
+
const pad = 4;
|
|
551
|
+
const place = () => {
|
|
552
|
+
const view = map.querySelector(".view");
|
|
553
|
+
if (!view)
|
|
554
|
+
return;
|
|
555
|
+
view.style.insetInlineStart = `${pad + cols.scrollLeft * scale}px`;
|
|
556
|
+
view.style.inlineSize = `${cols.clientWidth * scale}px`;
|
|
557
|
+
};
|
|
558
|
+
const build = () => {
|
|
559
|
+
const wide = window.getComputedStyle(cols).display === "flex";
|
|
560
|
+
const over = wide && cols.scrollWidth > cols.clientWidth + 8;
|
|
561
|
+
map.hidden = !over;
|
|
562
|
+
if (!over)
|
|
563
|
+
return;
|
|
564
|
+
scale = minimapScale(WIDTH, cols.scrollWidth);
|
|
565
|
+
map.replaceChildren();
|
|
566
|
+
for (const col of cols.querySelectorAll(".col")) {
|
|
567
|
+
const m = window.document.createElement("div");
|
|
568
|
+
m.className = "m-col";
|
|
569
|
+
m.style.inlineSize = `${Math.max(6, col.offsetWidth * scale)}px`;
|
|
570
|
+
if (col.hasAttribute("data-empty"))
|
|
571
|
+
m.dataset.empty = "";
|
|
572
|
+
for (const _ of col.querySelectorAll(":scope > .feitio-kanban-card:not(.draft)")) {
|
|
573
|
+
const c = window.document.createElement("i");
|
|
574
|
+
c.className = "m-card";
|
|
575
|
+
m.append(c);
|
|
576
|
+
}
|
|
577
|
+
map.append(m);
|
|
578
|
+
}
|
|
579
|
+
const view = window.document.createElement("span");
|
|
580
|
+
view.className = "view";
|
|
581
|
+
map.append(view);
|
|
582
|
+
place();
|
|
583
|
+
};
|
|
584
|
+
const go = (event) => {
|
|
585
|
+
const r = map.getBoundingClientRect();
|
|
586
|
+
cols.scrollLeft = minimapScroll(event.clientX - r.left - pad, scale, cols.clientWidth);
|
|
587
|
+
};
|
|
588
|
+
let dragging = false;
|
|
589
|
+
map.addEventListener("pointerdown", (event) => {
|
|
590
|
+
dragging = true;
|
|
591
|
+
map.setPointerCapture?.(event.pointerId);
|
|
592
|
+
go(event);
|
|
593
|
+
});
|
|
594
|
+
map.addEventListener("pointermove", (event) => {
|
|
595
|
+
if (dragging)
|
|
596
|
+
go(event);
|
|
597
|
+
});
|
|
598
|
+
map.addEventListener("pointerup", () => {
|
|
599
|
+
dragging = false;
|
|
600
|
+
});
|
|
601
|
+
cols.addEventListener("scroll", place, { passive: true });
|
|
602
|
+
if (typeof ResizeObserver === "function")
|
|
603
|
+
new ResizeObserver(build).observe(cols);
|
|
604
|
+
build();
|
|
605
|
+
return build;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// src/menu/calculations/menu-focus.ts
|
|
609
|
+
function nextMenuIndex(key, current, count) {
|
|
610
|
+
if (count === 0)
|
|
611
|
+
return;
|
|
612
|
+
switch (key) {
|
|
613
|
+
case "ArrowDown":
|
|
614
|
+
return current < 0 ? 0 : (current + 1) % count;
|
|
615
|
+
case "ArrowUp":
|
|
616
|
+
return current <= 0 ? count - 1 : current - 1;
|
|
617
|
+
case "Home":
|
|
618
|
+
return 0;
|
|
619
|
+
case "End":
|
|
620
|
+
return count - 1;
|
|
621
|
+
default:
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
function menuPosition(button, menu, viewport, gap) {
|
|
626
|
+
const fitsRight = button.left + menu.width <= viewport.width - gap;
|
|
627
|
+
const left = Math.max(gap, fitsRight ? button.left : button.right - menu.width);
|
|
628
|
+
const fitsBelow = button.bottom + gap + menu.height <= viewport.height - gap;
|
|
629
|
+
const top = fitsBelow ? button.bottom + gap : Math.max(gap, button.top - gap - menu.height);
|
|
630
|
+
return { left, top };
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// src/kanban/actions/wire-move-menu.ts
|
|
634
|
+
function wireMoveMenu(window, board) {
|
|
635
|
+
const doc = window.document;
|
|
636
|
+
let list;
|
|
637
|
+
let opener;
|
|
638
|
+
const make = () => {
|
|
639
|
+
const ul = doc.createElement("ul");
|
|
640
|
+
ul.className = "feitio-menu-list feitio-kanban-menu";
|
|
641
|
+
ul.id = `${board.id || "kanban"}-move`;
|
|
642
|
+
ul.setAttribute("popover", "auto");
|
|
643
|
+
doc.body.append(ul);
|
|
644
|
+
ul.addEventListener("toggle", (event) => {
|
|
645
|
+
if (event.newState === "closed")
|
|
646
|
+
opener?.setAttribute("aria-expanded", "false");
|
|
647
|
+
});
|
|
648
|
+
ul.addEventListener("keydown", (event) => {
|
|
649
|
+
const all = items();
|
|
650
|
+
const next = nextMenuIndex(event.key, all.indexOf(doc.activeElement), all.length);
|
|
651
|
+
if (next === undefined)
|
|
652
|
+
return;
|
|
653
|
+
event.preventDefault();
|
|
654
|
+
all[next]?.focus();
|
|
655
|
+
});
|
|
656
|
+
return ul;
|
|
657
|
+
};
|
|
658
|
+
const items = () => [...list?.querySelectorAll("button") ?? []];
|
|
659
|
+
board.addEventListener("click", (event) => {
|
|
660
|
+
const button = event.target.closest(".feitio-kanban-card > .move");
|
|
661
|
+
if (!button || !board.contains(button))
|
|
662
|
+
return;
|
|
663
|
+
const card = button.parentElement;
|
|
664
|
+
opener = button;
|
|
665
|
+
list ??= make();
|
|
666
|
+
const menu = list;
|
|
667
|
+
menu.replaceChildren();
|
|
668
|
+
const head = doc.createElement("li");
|
|
669
|
+
head.className = "head";
|
|
670
|
+
head.setAttribute("role", "presentation");
|
|
671
|
+
head.textContent = board.dataset.moveLabel ?? "Move to";
|
|
672
|
+
menu.append(head);
|
|
673
|
+
for (const to of targetsOf(card.dataset.to)) {
|
|
674
|
+
const title = board.querySelector(`.col[data-col="${to}"] .col-head h3`)?.textContent?.trim();
|
|
675
|
+
if (!title)
|
|
676
|
+
continue;
|
|
677
|
+
const li = doc.createElement("li");
|
|
678
|
+
const choice = doc.createElement("button");
|
|
679
|
+
choice.type = "button";
|
|
680
|
+
choice.textContent = title;
|
|
681
|
+
choice.addEventListener("click", () => {
|
|
682
|
+
menu.hidePopover?.();
|
|
683
|
+
if (moveCard(window, board, card, to))
|
|
684
|
+
window.requestAnimationFrame(() => card.querySelector(":scope > .move")?.focus({ preventScroll: true }));
|
|
685
|
+
});
|
|
686
|
+
li.append(choice);
|
|
687
|
+
menu.append(li);
|
|
688
|
+
}
|
|
689
|
+
menu.showPopover?.();
|
|
690
|
+
button.setAttribute("aria-expanded", "true");
|
|
691
|
+
const place = menuPosition(button.getBoundingClientRect(), menu.getBoundingClientRect(), { width: window.innerWidth, height: window.innerHeight }, 8);
|
|
692
|
+
menu.style.left = `${place.left}px`;
|
|
693
|
+
menu.style.top = `${place.top}px`;
|
|
694
|
+
items()[0]?.focus();
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// src/kanban/actions/wire-scroll-row.ts
|
|
699
|
+
function wireScrollRow(box) {
|
|
700
|
+
const row = box.querySelector(":scope > .tabs, :scope > .cols");
|
|
701
|
+
const start = box.querySelector(":scope > .edge.start");
|
|
702
|
+
const end = box.querySelector(":scope > .edge.end");
|
|
703
|
+
if (!row)
|
|
704
|
+
return;
|
|
705
|
+
const sync = () => {
|
|
706
|
+
const seen = edgesVisible(row.scrollLeft, row.clientWidth, row.scrollWidth);
|
|
707
|
+
start?.toggleAttribute("data-visible", seen.start);
|
|
708
|
+
end?.toggleAttribute("data-visible", seen.end);
|
|
709
|
+
};
|
|
710
|
+
row.addEventListener("scroll", sync, { passive: true });
|
|
711
|
+
if (typeof ResizeObserver === "function")
|
|
712
|
+
new ResizeObserver(sync).observe(row);
|
|
713
|
+
sync();
|
|
714
|
+
if (!row.classList.contains("tabs"))
|
|
715
|
+
return;
|
|
716
|
+
row.addEventListener("wheel", (event) => {
|
|
717
|
+
if (row.scrollWidth <= row.clientWidth || Math.abs(event.deltaX) > Math.abs(event.deltaY))
|
|
718
|
+
return;
|
|
719
|
+
event.preventDefault();
|
|
720
|
+
row.scrollLeft += event.deltaY;
|
|
721
|
+
}, { passive: false });
|
|
722
|
+
let down;
|
|
723
|
+
row.addEventListener("pointerdown", (event) => {
|
|
724
|
+
if (event.pointerType === "mouse")
|
|
725
|
+
down = { x: event.clientX, scroll: row.scrollLeft, moved: false, id: event.pointerId };
|
|
726
|
+
});
|
|
727
|
+
row.addEventListener("pointermove", (event) => {
|
|
728
|
+
if (!down)
|
|
729
|
+
return;
|
|
730
|
+
const d = event.clientX - down.x;
|
|
731
|
+
if (!down.moved && Math.abs(d) > 4) {
|
|
732
|
+
down.moved = true;
|
|
733
|
+
row.setPointerCapture?.(down.id);
|
|
734
|
+
}
|
|
735
|
+
if (down.moved)
|
|
736
|
+
row.scrollLeft = down.scroll - d;
|
|
737
|
+
});
|
|
738
|
+
row.addEventListener("pointerup", () => {
|
|
739
|
+
if (down?.moved)
|
|
740
|
+
row.addEventListener("click", (e) => {
|
|
741
|
+
e.stopPropagation();
|
|
742
|
+
e.preventDefault();
|
|
743
|
+
}, { capture: true, once: true });
|
|
744
|
+
down = undefined;
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// src/kanban/actions/wire-kanbans.ts
|
|
749
|
+
var wired = new WeakSet;
|
|
750
|
+
function wireKanbans(window, root) {
|
|
751
|
+
const self = root.matches?.(".feitio-kanban") ? [root] : [];
|
|
752
|
+
const boards = [...self, ...root.querySelectorAll(".feitio-kanban")];
|
|
753
|
+
for (const board of boards) {
|
|
754
|
+
if (wired.has(board))
|
|
755
|
+
continue;
|
|
756
|
+
wired.add(board);
|
|
757
|
+
board.querySelector(".tabs")?.addEventListener("click", (event) => {
|
|
758
|
+
const tab = event.target.closest("[data-col]");
|
|
759
|
+
if (tab?.dataset.col)
|
|
760
|
+
chooseStage(board, tab.dataset.col);
|
|
761
|
+
});
|
|
762
|
+
for (const box of board.querySelectorAll(":scope > .feitio-kanban-scroll"))
|
|
763
|
+
wireScrollRow(box);
|
|
764
|
+
const rebuild = wireMinimap(window, board);
|
|
765
|
+
wireMoveMenu(window, board);
|
|
766
|
+
wireDrag(window, board);
|
|
767
|
+
wireCreate(window, board);
|
|
768
|
+
board.addEventListener("feitio-kanban-move", () => window.requestAnimationFrame(rebuild));
|
|
769
|
+
board.addEventListener("feitio-kanban-create", () => window.requestAnimationFrame(rebuild));
|
|
770
|
+
syncKanban(board);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// src/kanban/index.ts
|
|
775
|
+
function kanbans(window, root = window.document) {
|
|
776
|
+
wireKanbans(window, root);
|
|
777
|
+
return {
|
|
778
|
+
move: (card, to, index) => {
|
|
779
|
+
const board = card.closest(".feitio-kanban");
|
|
780
|
+
return board ? moveCard(window, board, card, to, index) : false;
|
|
781
|
+
},
|
|
782
|
+
sync: syncKanban
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
export {
|
|
786
|
+
canMove,
|
|
787
|
+
kanbans,
|
|
788
|
+
targetsOf
|
|
789
|
+
};
|