@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/feitio.js
CHANGED
|
@@ -145,6 +145,613 @@ function wireForms(window, root) {
|
|
|
145
145
|
function forms(window, root = window.document) {
|
|
146
146
|
wireForms(window, root);
|
|
147
147
|
}
|
|
148
|
+
// src/kanban/calculations/kanban-rules.ts
|
|
149
|
+
function targetsOf(attribute) {
|
|
150
|
+
return (attribute ?? "").split(/\s+/).filter(Boolean);
|
|
151
|
+
}
|
|
152
|
+
function canMove(targets, from, to) {
|
|
153
|
+
return to !== from && targets.includes(to);
|
|
154
|
+
}
|
|
155
|
+
function minimapScale(mapWidth, scrollWidth) {
|
|
156
|
+
return scrollWidth > 0 ? mapWidth / scrollWidth : 0;
|
|
157
|
+
}
|
|
158
|
+
function minimapScroll(x, scale, clientWidth) {
|
|
159
|
+
return scale > 0 ? Math.max(0, x / scale - clientWidth / 2) : 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/kanban/calculations/kanban-motion.ts
|
|
163
|
+
var FLY = { stiffness: 170, damping: 14 };
|
|
164
|
+
var SETTLE = { stiffness: 230, damping: 24 };
|
|
165
|
+
var HOP = { stiffness: 320, damping: 11 };
|
|
166
|
+
function springCurve(spring, maxFrames = 240) {
|
|
167
|
+
let x = 0;
|
|
168
|
+
let v = 0;
|
|
169
|
+
const out = [0];
|
|
170
|
+
const dt = 1 / 60;
|
|
171
|
+
for (let i = 0;i < maxFrames; i++) {
|
|
172
|
+
v += (-spring.stiffness * (x - 1) - spring.damping * v) * dt;
|
|
173
|
+
x += v * dt;
|
|
174
|
+
out.push(x);
|
|
175
|
+
if (Math.abs(x - 1) < 0.002 && Math.abs(v) < 0.01)
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
out[out.length - 1] = 1;
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
function curveDuration(curve) {
|
|
182
|
+
return curve.length * 1000 / 60;
|
|
183
|
+
}
|
|
184
|
+
function followStep(state, targetX, targetY) {
|
|
185
|
+
const vx = (state.vx + (targetX - state.x) * 0.3) * 0.62;
|
|
186
|
+
const vy = (state.vy + (targetY - state.y) * 0.3) * 0.62;
|
|
187
|
+
const lean = Math.max(-14, Math.min(14, vx * 1.2));
|
|
188
|
+
return {
|
|
189
|
+
x: state.x + vx,
|
|
190
|
+
y: state.y + vy,
|
|
191
|
+
vx,
|
|
192
|
+
vy,
|
|
193
|
+
tilt: state.tilt + (lean - state.tilt) * 0.18
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function flightTilt(dx) {
|
|
197
|
+
return Math.max(-9, Math.min(9, dx / 35));
|
|
198
|
+
}
|
|
199
|
+
function edgesVisible(scrollLeft, clientWidth, scrollWidth) {
|
|
200
|
+
return { start: scrollLeft > 8, end: scrollLeft + clientWidth < scrollWidth - 8 };
|
|
201
|
+
}
|
|
202
|
+
function autoScrollSpeed(pointerX, left, right, zone = 90, max = 16) {
|
|
203
|
+
if (pointerX < left + zone)
|
|
204
|
+
return -((left + zone - pointerX) / zone) * max;
|
|
205
|
+
if (pointerX > right - zone)
|
|
206
|
+
return (pointerX - (right - zone)) / zone * max;
|
|
207
|
+
return 0;
|
|
208
|
+
}
|
|
209
|
+
function insertionIndex(middles, y) {
|
|
210
|
+
const i = middles.findIndex((m) => y < m);
|
|
211
|
+
return i === -1 ? middles.length : i;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/kanban/actions/kanban-flip.ts
|
|
215
|
+
function keyOf(el) {
|
|
216
|
+
if (el.classList.contains("feitio-kanban-card"))
|
|
217
|
+
return el.dataset.id ? `card:${el.dataset.id}` : undefined;
|
|
218
|
+
const col = el.closest(".col");
|
|
219
|
+
return col ? `add:${col.dataset.col}` : undefined;
|
|
220
|
+
}
|
|
221
|
+
function pieces(board) {
|
|
222
|
+
return [
|
|
223
|
+
...board.querySelectorAll(".col > .feitio-kanban-card:not(.draft), .col > .add")
|
|
224
|
+
];
|
|
225
|
+
}
|
|
226
|
+
function snapshot(board, moving) {
|
|
227
|
+
const rects = new Map;
|
|
228
|
+
const clones = new Map;
|
|
229
|
+
for (const el of pieces(board)) {
|
|
230
|
+
const key = keyOf(el);
|
|
231
|
+
const r = el.getBoundingClientRect();
|
|
232
|
+
if (key && r.width)
|
|
233
|
+
rects.set(key, { left: r.left, top: r.top, width: r.width });
|
|
234
|
+
if (key && moving && key === `card:${moving}`)
|
|
235
|
+
clones.set(key, el.cloneNode(true));
|
|
236
|
+
}
|
|
237
|
+
const widths = new Map;
|
|
238
|
+
for (const col of board.querySelectorAll(".col")) {
|
|
239
|
+
const w = col.getBoundingClientRect().width;
|
|
240
|
+
if (w)
|
|
241
|
+
widths.set(col.dataset.col ?? "", w);
|
|
242
|
+
}
|
|
243
|
+
return { rects, widths, clones };
|
|
244
|
+
}
|
|
245
|
+
function play(el, spring, frame) {
|
|
246
|
+
if (typeof el.animate !== "function")
|
|
247
|
+
return;
|
|
248
|
+
const curve = springCurve(spring);
|
|
249
|
+
return el.animate(curve.map(frame), { duration: curveDuration(curve), easing: "linear" });
|
|
250
|
+
}
|
|
251
|
+
function reduced(window) {
|
|
252
|
+
return window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
|
|
253
|
+
}
|
|
254
|
+
function animateFrom(window, board, before, motion) {
|
|
255
|
+
if (reduced(window))
|
|
256
|
+
return;
|
|
257
|
+
const after = new Map;
|
|
258
|
+
for (const el of pieces(board)) {
|
|
259
|
+
const key = keyOf(el);
|
|
260
|
+
const r = el.getBoundingClientRect();
|
|
261
|
+
if (key && r.width)
|
|
262
|
+
after.set(key, [el, r]);
|
|
263
|
+
}
|
|
264
|
+
for (const col of board.querySelectorAll(".col")) {
|
|
265
|
+
const w0 = before.widths.get(col.dataset.col ?? "");
|
|
266
|
+
const w1 = col.getBoundingClientRect().width;
|
|
267
|
+
if (!w0 || !w1 || Math.abs(w0 - w1) < 1)
|
|
268
|
+
continue;
|
|
269
|
+
play(col, SETTLE, (p) => ({
|
|
270
|
+
flexBasis: `${w0 + (w1 - w0) * p}px`,
|
|
271
|
+
flexGrow: 0,
|
|
272
|
+
flexShrink: 0
|
|
273
|
+
}));
|
|
274
|
+
}
|
|
275
|
+
const mover = motion.id ? `card:${motion.id}` : undefined;
|
|
276
|
+
for (const [key, [el, r1]] of after) {
|
|
277
|
+
const isMover = key === mover;
|
|
278
|
+
let r0 = before.rects.get(key);
|
|
279
|
+
if (isMover && motion.from)
|
|
280
|
+
r0 = { left: motion.from.x, top: motion.from.y };
|
|
281
|
+
if (!r0) {
|
|
282
|
+
if (isMover)
|
|
283
|
+
play(el, FLY, (p) => ({
|
|
284
|
+
transform: `translateY(${-24 * (1 - p)}px) scale(${1 + 0.08 * (1 - p)})`,
|
|
285
|
+
opacity: Math.min(1, p * 2)
|
|
286
|
+
}));
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
const dx = r0.left - r1.left;
|
|
290
|
+
const dy = r0.top - r1.top;
|
|
291
|
+
if (Math.abs(dx) < 1 && Math.abs(dy) < 1)
|
|
292
|
+
continue;
|
|
293
|
+
if (!isMover) {
|
|
294
|
+
play(el, SETTLE, (p) => ({ transform: `translate(${dx * (1 - p)}px, ${dy * (1 - p)}px)` }));
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
const tilt = motion.from ? motion.from.tilt : flightTilt(dx);
|
|
298
|
+
const lift = motion.from ? 0.04 : 0.06;
|
|
299
|
+
el.style.zIndex = "5";
|
|
300
|
+
const run = play(el, FLY, (p) => ({
|
|
301
|
+
transform: `translate(${dx * (1 - p)}px, ${dy * (1 - p)}px) rotate(${tilt * (1 - p)}deg) scale(${1 + lift * Math.max(0, 1 - p)})`
|
|
302
|
+
}));
|
|
303
|
+
if (run)
|
|
304
|
+
run.onfinish = () => el.style.removeProperty("z-index");
|
|
305
|
+
}
|
|
306
|
+
if (!mover)
|
|
307
|
+
return;
|
|
308
|
+
const landed = after.get(mover);
|
|
309
|
+
const cols = board.querySelector(".cols");
|
|
310
|
+
if (landed && !motion.from && cols) {
|
|
311
|
+
const r = landed[1];
|
|
312
|
+
const box = cols.getBoundingClientRect();
|
|
313
|
+
if (r.right > box.right - 72)
|
|
314
|
+
cols.scrollBy({ left: r.right - box.right + 72, behavior: "smooth" });
|
|
315
|
+
else if (r.left < box.left + 72)
|
|
316
|
+
cols.scrollBy({ left: r.left - box.left - 72, behavior: "smooth" });
|
|
317
|
+
}
|
|
318
|
+
const r0 = before.rects.get(mover);
|
|
319
|
+
const clone = before.clones.get(mover);
|
|
320
|
+
const tab = board.querySelector(`.tabs [data-col="${motion.to}"]`);
|
|
321
|
+
if (landed || !r0 || !clone || !tab || typeof tab.animate !== "function")
|
|
322
|
+
return;
|
|
323
|
+
const tr = tab.getBoundingClientRect();
|
|
324
|
+
const ghost = window.document.createElement("div");
|
|
325
|
+
ghost.className = "feitio-kanban-ghost";
|
|
326
|
+
ghost.setAttribute("aria-hidden", "true");
|
|
327
|
+
Object.assign(ghost.style, { left: `${r0.left}px`, top: `${r0.top}px`, width: `${r0.width}px` });
|
|
328
|
+
clone.removeAttribute("id");
|
|
329
|
+
ghost.append(clone);
|
|
330
|
+
window.document.body.append(ghost);
|
|
331
|
+
const dx = tr.left + tr.width / 2 - (r0.left + r0.width / 2);
|
|
332
|
+
const dy = tr.top + tr.height / 2 - (r0.top + clone.getBoundingClientRect().height / 2);
|
|
333
|
+
const flight = ghost.animate([
|
|
334
|
+
{ transform: "translate(0, 0) scale(1) rotate(0deg)", opacity: 1 },
|
|
335
|
+
{
|
|
336
|
+
transform: `translate(${dx * 0.35}px, ${dy * 0.35 - 30}px) scale(0.7) rotate(-5deg)`,
|
|
337
|
+
opacity: 1,
|
|
338
|
+
offset: 0.45
|
|
339
|
+
},
|
|
340
|
+
{ transform: `translate(${dx}px, ${dy}px) scale(0.08) rotate(-14deg)`, opacity: 0.2 }
|
|
341
|
+
], { duration: 560, easing: "cubic-bezier(0.45, 0, 0.8, 0.4)" });
|
|
342
|
+
flight.onfinish = () => {
|
|
343
|
+
ghost.remove();
|
|
344
|
+
play(tab, HOP, (p) => ({ transform: `scale(${1 + 0.4 * (1 - p)})` }));
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// src/kanban/actions/sync-kanban.ts
|
|
349
|
+
function setText(el, text) {
|
|
350
|
+
if (el && el.textContent !== text)
|
|
351
|
+
el.textContent = text;
|
|
352
|
+
}
|
|
353
|
+
function syncKanban(board) {
|
|
354
|
+
for (const col of board.querySelectorAll(".col")) {
|
|
355
|
+
const n = col.querySelectorAll(":scope > .feitio-kanban-card:not(.draft)").length;
|
|
356
|
+
const id = col.dataset.col ?? "";
|
|
357
|
+
if (col.hasAttribute("data-empty") !== (n === 0))
|
|
358
|
+
col.toggleAttribute("data-empty", n === 0);
|
|
359
|
+
setText(col.querySelector(".col-head .n"), String(n));
|
|
360
|
+
const empty = col.querySelector(":scope > .empty");
|
|
361
|
+
if (empty && empty.hidden !== n > 0)
|
|
362
|
+
empty.hidden = n > 0;
|
|
363
|
+
const tab = board.querySelector(`.tabs [data-col="${id}"]`);
|
|
364
|
+
if (!tab)
|
|
365
|
+
continue;
|
|
366
|
+
if (tab.hasAttribute("data-has") !== n > 0)
|
|
367
|
+
tab.toggleAttribute("data-has", n > 0);
|
|
368
|
+
setText(tab.querySelector(".n"), String(n));
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
function chooseStage(board, id) {
|
|
372
|
+
for (const col of board.querySelectorAll(".col")) {
|
|
373
|
+
const on = col.dataset.col === id;
|
|
374
|
+
if (col.hasAttribute("data-current") !== on)
|
|
375
|
+
col.toggleAttribute("data-current", on);
|
|
376
|
+
}
|
|
377
|
+
for (const tab of board.querySelectorAll(".tabs [data-col]")) {
|
|
378
|
+
tab.setAttribute("aria-pressed", String(tab.dataset.col === id));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// src/kanban/actions/move-card.ts
|
|
383
|
+
function moveCard(window, board, card, to, index, before, from) {
|
|
384
|
+
const fromCol = card.closest(".col")?.dataset.col ?? "";
|
|
385
|
+
const id = card.dataset.id ?? "";
|
|
386
|
+
const target = board.querySelector(`.col[data-col="${to}"]`);
|
|
387
|
+
if (!target || !canMove(targetsOf(card.dataset.to), fromCol, to))
|
|
388
|
+
return false;
|
|
389
|
+
const cards = [
|
|
390
|
+
...target.querySelectorAll(":scope > .feitio-kanban-card:not(.draft)")
|
|
391
|
+
];
|
|
392
|
+
const place = index === undefined ? cards.length : Math.min(index, cards.length);
|
|
393
|
+
const picture = before ?? snapshot(board, id);
|
|
394
|
+
if (!picture.clones.size) {
|
|
395
|
+
const own = snapshot(board, id).clones;
|
|
396
|
+
for (const [k, v] of own)
|
|
397
|
+
picture.clones.set(k, v);
|
|
398
|
+
}
|
|
399
|
+
const detail = { card, id, from: fromCol, to, index: place };
|
|
400
|
+
const event = new CustomEvent("feitio-kanban-move", {
|
|
401
|
+
bubbles: true,
|
|
402
|
+
cancelable: true,
|
|
403
|
+
detail
|
|
404
|
+
});
|
|
405
|
+
const done = () => {
|
|
406
|
+
syncKanban(board);
|
|
407
|
+
animateFrom(window, board, picture, { id, to, from });
|
|
408
|
+
};
|
|
409
|
+
if (board.dispatchEvent(event)) {
|
|
410
|
+
const ref = cards[place] ?? target.querySelector(":scope > .add");
|
|
411
|
+
target.insertBefore(card, ref);
|
|
412
|
+
syncKanban(board);
|
|
413
|
+
window.requestAnimationFrame(done);
|
|
414
|
+
} else {
|
|
415
|
+
window.requestAnimationFrame(() => window.requestAnimationFrame(done));
|
|
416
|
+
}
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// src/kanban/actions/wire-create.ts
|
|
421
|
+
var drafts = 0;
|
|
422
|
+
function wireCreate(window, board) {
|
|
423
|
+
const doc = window.document;
|
|
424
|
+
board.addEventListener("click", (event) => {
|
|
425
|
+
const add = event.target.closest(".col > .add");
|
|
426
|
+
if (!add || !board.contains(add))
|
|
427
|
+
return;
|
|
428
|
+
const col = add.parentElement;
|
|
429
|
+
const id = `${board.id || "kanban"}-new-${++drafts}`;
|
|
430
|
+
const form = doc.createElement("form");
|
|
431
|
+
form.className = "feitio-kanban-card draft feitio-place";
|
|
432
|
+
const label = doc.createElement("label");
|
|
433
|
+
label.htmlFor = id;
|
|
434
|
+
label.textContent = add.dataset.field ?? "";
|
|
435
|
+
const field = doc.createElement("textarea");
|
|
436
|
+
field.className = "feitio-textarea";
|
|
437
|
+
field.id = id;
|
|
438
|
+
field.required = true;
|
|
439
|
+
field.rows = 2;
|
|
440
|
+
const actions = doc.createElement("div");
|
|
441
|
+
actions.className = "actions";
|
|
442
|
+
const save = doc.createElement("button");
|
|
443
|
+
save.type = "submit";
|
|
444
|
+
save.className = "feitio-button";
|
|
445
|
+
save.dataset.variant = "primary";
|
|
446
|
+
save.dataset.size = "small";
|
|
447
|
+
save.textContent = add.dataset.save ?? "Save";
|
|
448
|
+
const cancel = doc.createElement("button");
|
|
449
|
+
cancel.type = "button";
|
|
450
|
+
cancel.className = "feitio-button";
|
|
451
|
+
cancel.dataset.size = "small";
|
|
452
|
+
cancel.textContent = add.dataset.cancel ?? "Cancel";
|
|
453
|
+
actions.append(save, cancel);
|
|
454
|
+
form.append(label, field, actions);
|
|
455
|
+
add.hidden = true;
|
|
456
|
+
col.insertBefore(form, add);
|
|
457
|
+
field.focus();
|
|
458
|
+
const close = () => {
|
|
459
|
+
form.remove();
|
|
460
|
+
add.hidden = false;
|
|
461
|
+
add.focus();
|
|
462
|
+
};
|
|
463
|
+
cancel.addEventListener("click", close);
|
|
464
|
+
form.addEventListener("keydown", (e) => {
|
|
465
|
+
if (e.key === "Escape")
|
|
466
|
+
close();
|
|
467
|
+
});
|
|
468
|
+
form.addEventListener("submit", (e) => {
|
|
469
|
+
e.preventDefault();
|
|
470
|
+
const text = field.value.trim();
|
|
471
|
+
if (!text)
|
|
472
|
+
return field.focus();
|
|
473
|
+
const before = snapshot(board);
|
|
474
|
+
const known = new Set([...col.querySelectorAll(":scope > .feitio-kanban-card")].map((c) => c.dataset.id));
|
|
475
|
+
const detail = { column: col.dataset.col ?? "", element: col, text };
|
|
476
|
+
board.dispatchEvent(new CustomEvent("feitio-kanban-create", { bubbles: true, detail }));
|
|
477
|
+
close();
|
|
478
|
+
window.requestAnimationFrame(() => {
|
|
479
|
+
syncKanban(board);
|
|
480
|
+
const fresh = [
|
|
481
|
+
...col.querySelectorAll(":scope > .feitio-kanban-card:not(.draft)")
|
|
482
|
+
].find((c) => !known.has(c.dataset.id));
|
|
483
|
+
animateFrom(window, board, before, { id: fresh?.dataset.id });
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// src/kanban/actions/wire-drag.ts
|
|
490
|
+
function wireDrag(window, board) {
|
|
491
|
+
const doc = window.document;
|
|
492
|
+
const cols = () => board.querySelector(".cols");
|
|
493
|
+
board.addEventListener("pointerdown", (event) => {
|
|
494
|
+
const card = event.target.closest(".col > .feitio-kanban-card");
|
|
495
|
+
if (!card || !board.contains(card) || card.classList.contains("draft"))
|
|
496
|
+
return;
|
|
497
|
+
if (event.button !== 0 || event.pointerType === "touch")
|
|
498
|
+
return;
|
|
499
|
+
if (event.target.closest("button, a, input, textarea, select, label"))
|
|
500
|
+
return;
|
|
501
|
+
if (!targetsOf(card.dataset.to).length)
|
|
502
|
+
return;
|
|
503
|
+
const row = cols();
|
|
504
|
+
if (!row || window.getComputedStyle(row).display !== "flex")
|
|
505
|
+
return;
|
|
506
|
+
event.preventDefault();
|
|
507
|
+
const sx = event.clientX;
|
|
508
|
+
const sy = event.clientY;
|
|
509
|
+
let held;
|
|
510
|
+
const stop = () => {
|
|
511
|
+
window.removeEventListener("pointermove", onMove);
|
|
512
|
+
window.removeEventListener("pointerup", onUp);
|
|
513
|
+
window.removeEventListener("keydown", onKey);
|
|
514
|
+
};
|
|
515
|
+
const onMove = (e) => {
|
|
516
|
+
if (!held) {
|
|
517
|
+
if (Math.hypot(e.clientX - sx, e.clientY - sy) < 5)
|
|
518
|
+
return;
|
|
519
|
+
held = lift(e, card);
|
|
520
|
+
}
|
|
521
|
+
held.px = e.clientX;
|
|
522
|
+
held.py = e.clientY;
|
|
523
|
+
hover(held);
|
|
524
|
+
};
|
|
525
|
+
const onUp = () => {
|
|
526
|
+
stop();
|
|
527
|
+
if (held)
|
|
528
|
+
letGo(held, false);
|
|
529
|
+
};
|
|
530
|
+
const onKey = (e) => {
|
|
531
|
+
if (e.key !== "Escape" || !held)
|
|
532
|
+
return;
|
|
533
|
+
stop();
|
|
534
|
+
letGo(held, true);
|
|
535
|
+
};
|
|
536
|
+
window.addEventListener("pointermove", onMove);
|
|
537
|
+
window.addEventListener("pointerup", onUp);
|
|
538
|
+
window.addEventListener("keydown", onKey);
|
|
539
|
+
});
|
|
540
|
+
function lift(event, card) {
|
|
541
|
+
const r = card.getBoundingClientRect();
|
|
542
|
+
const ghost = doc.createElement("div");
|
|
543
|
+
ghost.className = "feitio-kanban-ghost";
|
|
544
|
+
ghost.dataset.motion = "direct";
|
|
545
|
+
ghost.setAttribute("aria-hidden", "true");
|
|
546
|
+
ghost.style.width = `${r.width}px`;
|
|
547
|
+
const copy = card.cloneNode(true);
|
|
548
|
+
copy.removeAttribute("id");
|
|
549
|
+
ghost.append(copy);
|
|
550
|
+
doc.body.append(ghost);
|
|
551
|
+
const slot = doc.createElement("div");
|
|
552
|
+
slot.className = "slot";
|
|
553
|
+
slot.style.blockSize = `${r.height}px`;
|
|
554
|
+
const home = card.closest(".col");
|
|
555
|
+
const homeNext = card.nextSibling;
|
|
556
|
+
card.replaceWith(slot);
|
|
557
|
+
doc.documentElement.setAttribute("data-kanban-dragging", "");
|
|
558
|
+
board.setAttribute("data-dragging", "");
|
|
559
|
+
const targets = targetsOf(card.dataset.to);
|
|
560
|
+
for (const col of board.querySelectorAll(".col")) {
|
|
561
|
+
if (col !== home && !targets.includes(col.dataset.col ?? ""))
|
|
562
|
+
col.setAttribute("data-blocked", "");
|
|
563
|
+
}
|
|
564
|
+
const held = {
|
|
565
|
+
card,
|
|
566
|
+
ghost,
|
|
567
|
+
slot,
|
|
568
|
+
home,
|
|
569
|
+
homeNext,
|
|
570
|
+
offX: event.clientX - r.left,
|
|
571
|
+
offY: event.clientY - r.top,
|
|
572
|
+
x: r.left,
|
|
573
|
+
y: r.top,
|
|
574
|
+
vx: 0,
|
|
575
|
+
vy: 0,
|
|
576
|
+
tilt: 0,
|
|
577
|
+
px: event.clientX,
|
|
578
|
+
py: event.clientY,
|
|
579
|
+
running: true
|
|
580
|
+
};
|
|
581
|
+
follow(held);
|
|
582
|
+
return held;
|
|
583
|
+
}
|
|
584
|
+
function follow(held) {
|
|
585
|
+
if (!held.running)
|
|
586
|
+
return;
|
|
587
|
+
const tx = held.px - held.offX;
|
|
588
|
+
const ty = held.py - held.offY;
|
|
589
|
+
if (reduced(window))
|
|
590
|
+
Object.assign(held, { x: tx, y: ty, vx: 0, vy: 0, tilt: 0 });
|
|
591
|
+
else
|
|
592
|
+
Object.assign(held, followStep(held, tx, ty));
|
|
593
|
+
held.ghost.style.transform = `translate(${held.x}px, ${held.y}px) rotate(${held.tilt}deg) scale(1.04)`;
|
|
594
|
+
const row = cols();
|
|
595
|
+
if (row) {
|
|
596
|
+
const r = row.getBoundingClientRect();
|
|
597
|
+
const v = autoScrollSpeed(held.px, r.left, r.right);
|
|
598
|
+
if (v) {
|
|
599
|
+
row.scrollLeft += v;
|
|
600
|
+
hover(held);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
window.requestAnimationFrame(() => follow(held));
|
|
604
|
+
}
|
|
605
|
+
function hover(held) {
|
|
606
|
+
const under = doc.elementFromPoint(held.px, held.py)?.closest(".col");
|
|
607
|
+
const ok = Boolean(under && board.contains(under) && under !== held.home && !under.hasAttribute("data-blocked"));
|
|
608
|
+
const dest = ok && under ? under : held.home;
|
|
609
|
+
let before;
|
|
610
|
+
if (ok) {
|
|
611
|
+
const cards = [
|
|
612
|
+
...dest.querySelectorAll(":scope > .feitio-kanban-card:not(.draft)")
|
|
613
|
+
];
|
|
614
|
+
const i = insertionIndex(cards.map((c) => {
|
|
615
|
+
const r = c.getBoundingClientRect();
|
|
616
|
+
return r.top + r.height / 2;
|
|
617
|
+
}), held.py);
|
|
618
|
+
before = cards[i] ?? dest.querySelector(":scope > .add");
|
|
619
|
+
} else {
|
|
620
|
+
before = held.homeNext && held.homeNext.parentNode === held.home ? held.homeNext : held.home.querySelector(":scope > .add");
|
|
621
|
+
}
|
|
622
|
+
for (const col of board.querySelectorAll(".col"))
|
|
623
|
+
col.toggleAttribute("data-over", ok && col === under);
|
|
624
|
+
if (held.slot.parentNode === dest && held.slot.nextSibling === before)
|
|
625
|
+
return;
|
|
626
|
+
const moving = [
|
|
627
|
+
...board.querySelectorAll(".col > .feitio-kanban-card, .col > .add")
|
|
628
|
+
];
|
|
629
|
+
const first = new Map(moving.map((m) => [m, m.getBoundingClientRect()]));
|
|
630
|
+
const widths = new Map([...board.querySelectorAll(".col")].map((c) => [
|
|
631
|
+
c,
|
|
632
|
+
c.getBoundingClientRect().width
|
|
633
|
+
]));
|
|
634
|
+
if (held.opened && held.opened !== dest) {
|
|
635
|
+
held.opened.setAttribute("data-empty", "");
|
|
636
|
+
held.opened = undefined;
|
|
637
|
+
}
|
|
638
|
+
if (dest !== held.home && dest.hasAttribute("data-empty")) {
|
|
639
|
+
dest.removeAttribute("data-empty");
|
|
640
|
+
held.opened = dest;
|
|
641
|
+
}
|
|
642
|
+
dest.insertBefore(held.slot, before);
|
|
643
|
+
if (reduced(window))
|
|
644
|
+
return;
|
|
645
|
+
for (const [col, w0] of widths) {
|
|
646
|
+
const w1 = col.getBoundingClientRect().width;
|
|
647
|
+
if (Math.abs(w1 - w0) > 1)
|
|
648
|
+
play(col, SETTLE, (p) => ({
|
|
649
|
+
flexBasis: `${w0 + (w1 - w0) * p}px`,
|
|
650
|
+
flexGrow: 0,
|
|
651
|
+
flexShrink: 0
|
|
652
|
+
}));
|
|
653
|
+
}
|
|
654
|
+
for (const m of moving) {
|
|
655
|
+
const a = first.get(m);
|
|
656
|
+
const b = m.getBoundingClientRect();
|
|
657
|
+
const dx = a.left - b.left;
|
|
658
|
+
const dy = a.top - b.top;
|
|
659
|
+
if (Math.abs(dx) > 0.5 || Math.abs(dy) > 0.5)
|
|
660
|
+
play(m, SETTLE, (p) => ({ transform: `translate(${dx * (1 - p)}px, ${dy * (1 - p)}px)` }));
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
function letGo(held, cancel) {
|
|
664
|
+
held.running = false;
|
|
665
|
+
doc.documentElement.removeAttribute("data-kanban-dragging");
|
|
666
|
+
board.removeAttribute("data-dragging");
|
|
667
|
+
for (const col of board.querySelectorAll(".col")) {
|
|
668
|
+
col.removeAttribute("data-blocked");
|
|
669
|
+
col.removeAttribute("data-over");
|
|
670
|
+
}
|
|
671
|
+
const dest = held.slot.closest(".col");
|
|
672
|
+
const index = [
|
|
673
|
+
...dest.querySelectorAll(":scope > .feitio-kanban-card:not(.draft), :scope > .slot")
|
|
674
|
+
].indexOf(held.slot);
|
|
675
|
+
const id = held.card.dataset.id ?? "";
|
|
676
|
+
const before = snapshot(board);
|
|
677
|
+
const from = { x: held.x, y: held.y, tilt: held.tilt };
|
|
678
|
+
held.ghost.remove();
|
|
679
|
+
held.home.insertBefore(held.card, held.homeNext && held.homeNext.parentNode === held.home ? held.homeNext : null);
|
|
680
|
+
held.slot.remove();
|
|
681
|
+
if (held.opened)
|
|
682
|
+
held.opened.setAttribute("data-empty", "");
|
|
683
|
+
if (!cancel && dest !== held.home && moveCard(window, board, held.card, dest.dataset.col ?? "", index, before, from))
|
|
684
|
+
return;
|
|
685
|
+
window.requestAnimationFrame(() => animateFrom(window, board, before, { id, from }));
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// src/kanban/actions/wire-minimap.ts
|
|
690
|
+
var WIDTH = 176;
|
|
691
|
+
function wireMinimap(window, board) {
|
|
692
|
+
const map = board.querySelector(":scope > .minimap");
|
|
693
|
+
const cols = board.querySelector(".cols");
|
|
694
|
+
if (!map || !cols)
|
|
695
|
+
return () => {};
|
|
696
|
+
let scale = 0;
|
|
697
|
+
const pad = 4;
|
|
698
|
+
const place = () => {
|
|
699
|
+
const view = map.querySelector(".view");
|
|
700
|
+
if (!view)
|
|
701
|
+
return;
|
|
702
|
+
view.style.insetInlineStart = `${pad + cols.scrollLeft * scale}px`;
|
|
703
|
+
view.style.inlineSize = `${cols.clientWidth * scale}px`;
|
|
704
|
+
};
|
|
705
|
+
const build = () => {
|
|
706
|
+
const wide = window.getComputedStyle(cols).display === "flex";
|
|
707
|
+
const over = wide && cols.scrollWidth > cols.clientWidth + 8;
|
|
708
|
+
map.hidden = !over;
|
|
709
|
+
if (!over)
|
|
710
|
+
return;
|
|
711
|
+
scale = minimapScale(WIDTH, cols.scrollWidth);
|
|
712
|
+
map.replaceChildren();
|
|
713
|
+
for (const col of cols.querySelectorAll(".col")) {
|
|
714
|
+
const m = window.document.createElement("div");
|
|
715
|
+
m.className = "m-col";
|
|
716
|
+
m.style.inlineSize = `${Math.max(6, col.offsetWidth * scale)}px`;
|
|
717
|
+
if (col.hasAttribute("data-empty"))
|
|
718
|
+
m.dataset.empty = "";
|
|
719
|
+
for (const _ of col.querySelectorAll(":scope > .feitio-kanban-card:not(.draft)")) {
|
|
720
|
+
const c = window.document.createElement("i");
|
|
721
|
+
c.className = "m-card";
|
|
722
|
+
m.append(c);
|
|
723
|
+
}
|
|
724
|
+
map.append(m);
|
|
725
|
+
}
|
|
726
|
+
const view = window.document.createElement("span");
|
|
727
|
+
view.className = "view";
|
|
728
|
+
map.append(view);
|
|
729
|
+
place();
|
|
730
|
+
};
|
|
731
|
+
const go = (event) => {
|
|
732
|
+
const r = map.getBoundingClientRect();
|
|
733
|
+
cols.scrollLeft = minimapScroll(event.clientX - r.left - pad, scale, cols.clientWidth);
|
|
734
|
+
};
|
|
735
|
+
let dragging = false;
|
|
736
|
+
map.addEventListener("pointerdown", (event) => {
|
|
737
|
+
dragging = true;
|
|
738
|
+
map.setPointerCapture?.(event.pointerId);
|
|
739
|
+
go(event);
|
|
740
|
+
});
|
|
741
|
+
map.addEventListener("pointermove", (event) => {
|
|
742
|
+
if (dragging)
|
|
743
|
+
go(event);
|
|
744
|
+
});
|
|
745
|
+
map.addEventListener("pointerup", () => {
|
|
746
|
+
dragging = false;
|
|
747
|
+
});
|
|
748
|
+
cols.addEventListener("scroll", place, { passive: true });
|
|
749
|
+
if (typeof ResizeObserver === "function")
|
|
750
|
+
new ResizeObserver(build).observe(cols);
|
|
751
|
+
build();
|
|
752
|
+
return build;
|
|
753
|
+
}
|
|
754
|
+
|
|
148
755
|
// src/menu/calculations/menu-focus.ts
|
|
149
756
|
function nextMenuIndex(key, current, count) {
|
|
150
757
|
if (count === 0)
|
|
@@ -170,14 +777,166 @@ function menuPosition(button, menu, viewport, gap) {
|
|
|
170
777
|
return { left, top };
|
|
171
778
|
}
|
|
172
779
|
|
|
173
|
-
// src/
|
|
780
|
+
// src/kanban/actions/wire-move-menu.ts
|
|
781
|
+
function wireMoveMenu(window, board) {
|
|
782
|
+
const doc = window.document;
|
|
783
|
+
let list;
|
|
784
|
+
let opener;
|
|
785
|
+
const make = () => {
|
|
786
|
+
const ul = doc.createElement("ul");
|
|
787
|
+
ul.className = "feitio-menu-list feitio-kanban-menu";
|
|
788
|
+
ul.id = `${board.id || "kanban"}-move`;
|
|
789
|
+
ul.setAttribute("popover", "auto");
|
|
790
|
+
doc.body.append(ul);
|
|
791
|
+
ul.addEventListener("toggle", (event) => {
|
|
792
|
+
if (event.newState === "closed")
|
|
793
|
+
opener?.setAttribute("aria-expanded", "false");
|
|
794
|
+
});
|
|
795
|
+
ul.addEventListener("keydown", (event) => {
|
|
796
|
+
const all = items();
|
|
797
|
+
const next = nextMenuIndex(event.key, all.indexOf(doc.activeElement), all.length);
|
|
798
|
+
if (next === undefined)
|
|
799
|
+
return;
|
|
800
|
+
event.preventDefault();
|
|
801
|
+
all[next]?.focus();
|
|
802
|
+
});
|
|
803
|
+
return ul;
|
|
804
|
+
};
|
|
805
|
+
const items = () => [...list?.querySelectorAll("button") ?? []];
|
|
806
|
+
board.addEventListener("click", (event) => {
|
|
807
|
+
const button = event.target.closest(".feitio-kanban-card > .move");
|
|
808
|
+
if (!button || !board.contains(button))
|
|
809
|
+
return;
|
|
810
|
+
const card = button.parentElement;
|
|
811
|
+
opener = button;
|
|
812
|
+
list ??= make();
|
|
813
|
+
const menu = list;
|
|
814
|
+
menu.replaceChildren();
|
|
815
|
+
const head = doc.createElement("li");
|
|
816
|
+
head.className = "head";
|
|
817
|
+
head.setAttribute("role", "presentation");
|
|
818
|
+
head.textContent = board.dataset.moveLabel ?? "Move to";
|
|
819
|
+
menu.append(head);
|
|
820
|
+
for (const to of targetsOf(card.dataset.to)) {
|
|
821
|
+
const title = board.querySelector(`.col[data-col="${to}"] .col-head h3`)?.textContent?.trim();
|
|
822
|
+
if (!title)
|
|
823
|
+
continue;
|
|
824
|
+
const li = doc.createElement("li");
|
|
825
|
+
const choice = doc.createElement("button");
|
|
826
|
+
choice.type = "button";
|
|
827
|
+
choice.textContent = title;
|
|
828
|
+
choice.addEventListener("click", () => {
|
|
829
|
+
menu.hidePopover?.();
|
|
830
|
+
if (moveCard(window, board, card, to))
|
|
831
|
+
window.requestAnimationFrame(() => card.querySelector(":scope > .move")?.focus({ preventScroll: true }));
|
|
832
|
+
});
|
|
833
|
+
li.append(choice);
|
|
834
|
+
menu.append(li);
|
|
835
|
+
}
|
|
836
|
+
menu.showPopover?.();
|
|
837
|
+
button.setAttribute("aria-expanded", "true");
|
|
838
|
+
const place = menuPosition(button.getBoundingClientRect(), menu.getBoundingClientRect(), { width: window.innerWidth, height: window.innerHeight }, 8);
|
|
839
|
+
menu.style.left = `${place.left}px`;
|
|
840
|
+
menu.style.top = `${place.top}px`;
|
|
841
|
+
items()[0]?.focus();
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
// src/kanban/actions/wire-scroll-row.ts
|
|
846
|
+
function wireScrollRow(box) {
|
|
847
|
+
const row = box.querySelector(":scope > .tabs, :scope > .cols");
|
|
848
|
+
const start = box.querySelector(":scope > .edge.start");
|
|
849
|
+
const end = box.querySelector(":scope > .edge.end");
|
|
850
|
+
if (!row)
|
|
851
|
+
return;
|
|
852
|
+
const sync = () => {
|
|
853
|
+
const seen = edgesVisible(row.scrollLeft, row.clientWidth, row.scrollWidth);
|
|
854
|
+
start?.toggleAttribute("data-visible", seen.start);
|
|
855
|
+
end?.toggleAttribute("data-visible", seen.end);
|
|
856
|
+
};
|
|
857
|
+
row.addEventListener("scroll", sync, { passive: true });
|
|
858
|
+
if (typeof ResizeObserver === "function")
|
|
859
|
+
new ResizeObserver(sync).observe(row);
|
|
860
|
+
sync();
|
|
861
|
+
if (!row.classList.contains("tabs"))
|
|
862
|
+
return;
|
|
863
|
+
row.addEventListener("wheel", (event) => {
|
|
864
|
+
if (row.scrollWidth <= row.clientWidth || Math.abs(event.deltaX) > Math.abs(event.deltaY))
|
|
865
|
+
return;
|
|
866
|
+
event.preventDefault();
|
|
867
|
+
row.scrollLeft += event.deltaY;
|
|
868
|
+
}, { passive: false });
|
|
869
|
+
let down;
|
|
870
|
+
row.addEventListener("pointerdown", (event) => {
|
|
871
|
+
if (event.pointerType === "mouse")
|
|
872
|
+
down = { x: event.clientX, scroll: row.scrollLeft, moved: false, id: event.pointerId };
|
|
873
|
+
});
|
|
874
|
+
row.addEventListener("pointermove", (event) => {
|
|
875
|
+
if (!down)
|
|
876
|
+
return;
|
|
877
|
+
const d = event.clientX - down.x;
|
|
878
|
+
if (!down.moved && Math.abs(d) > 4) {
|
|
879
|
+
down.moved = true;
|
|
880
|
+
row.setPointerCapture?.(down.id);
|
|
881
|
+
}
|
|
882
|
+
if (down.moved)
|
|
883
|
+
row.scrollLeft = down.scroll - d;
|
|
884
|
+
});
|
|
885
|
+
row.addEventListener("pointerup", () => {
|
|
886
|
+
if (down?.moved)
|
|
887
|
+
row.addEventListener("click", (e) => {
|
|
888
|
+
e.stopPropagation();
|
|
889
|
+
e.preventDefault();
|
|
890
|
+
}, { capture: true, once: true });
|
|
891
|
+
down = undefined;
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// src/kanban/actions/wire-kanbans.ts
|
|
174
896
|
var wired = new WeakSet;
|
|
897
|
+
function wireKanbans(window, root) {
|
|
898
|
+
const self = root.matches?.(".feitio-kanban") ? [root] : [];
|
|
899
|
+
const boards = [...self, ...root.querySelectorAll(".feitio-kanban")];
|
|
900
|
+
for (const board of boards) {
|
|
901
|
+
if (wired.has(board))
|
|
902
|
+
continue;
|
|
903
|
+
wired.add(board);
|
|
904
|
+
board.querySelector(".tabs")?.addEventListener("click", (event) => {
|
|
905
|
+
const tab = event.target.closest("[data-col]");
|
|
906
|
+
if (tab?.dataset.col)
|
|
907
|
+
chooseStage(board, tab.dataset.col);
|
|
908
|
+
});
|
|
909
|
+
for (const box of board.querySelectorAll(":scope > .feitio-kanban-scroll"))
|
|
910
|
+
wireScrollRow(box);
|
|
911
|
+
const rebuild = wireMinimap(window, board);
|
|
912
|
+
wireMoveMenu(window, board);
|
|
913
|
+
wireDrag(window, board);
|
|
914
|
+
wireCreate(window, board);
|
|
915
|
+
board.addEventListener("feitio-kanban-move", () => window.requestAnimationFrame(rebuild));
|
|
916
|
+
board.addEventListener("feitio-kanban-create", () => window.requestAnimationFrame(rebuild));
|
|
917
|
+
syncKanban(board);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// src/kanban/index.ts
|
|
922
|
+
function kanbans(window, root = window.document) {
|
|
923
|
+
wireKanbans(window, root);
|
|
924
|
+
return {
|
|
925
|
+
move: (card, to, index) => {
|
|
926
|
+
const board = card.closest(".feitio-kanban");
|
|
927
|
+
return board ? moveCard(window, board, card, to, index) : false;
|
|
928
|
+
},
|
|
929
|
+
sync: syncKanban
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
// src/menu/actions/wire-menus.ts
|
|
933
|
+
var wired2 = new WeakSet;
|
|
175
934
|
function wireMenus(window, root) {
|
|
176
935
|
for (const list of root.querySelectorAll(".feitio-menu-list[popover]")) {
|
|
177
936
|
const button = root.querySelector(`[popovertarget="${list.id}"]`);
|
|
178
|
-
if (!button ||
|
|
937
|
+
if (!button || wired2.has(list))
|
|
179
938
|
continue;
|
|
180
|
-
|
|
939
|
+
wired2.add(list);
|
|
181
940
|
const items = () => [...list.querySelectorAll("a, button")];
|
|
182
941
|
list.addEventListener("toggle", (event) => {
|
|
183
942
|
const open = event.newState === "open";
|
|
@@ -303,7 +1062,7 @@ function showNotice(host, notice) {
|
|
|
303
1062
|
}
|
|
304
1063
|
|
|
305
1064
|
// src/notice/actions/wire-notices.ts
|
|
306
|
-
var
|
|
1065
|
+
var wired3 = new WeakSet;
|
|
307
1066
|
function wireNotices(host, root) {
|
|
308
1067
|
const own = "matches" in root && root.matches(".feitio-notice");
|
|
309
1068
|
const notices = [
|
|
@@ -320,9 +1079,9 @@ function wireNotices(host, root) {
|
|
|
320
1079
|
}
|
|
321
1080
|
}, { threshold: 0.9 }) : undefined;
|
|
322
1081
|
for (const notice of notices) {
|
|
323
|
-
if (
|
|
1082
|
+
if (wired3.has(notice))
|
|
324
1083
|
continue;
|
|
325
|
-
|
|
1084
|
+
wired3.add(notice);
|
|
326
1085
|
notice.querySelector(".close")?.addEventListener("click", () => closeNotice(host, notice));
|
|
327
1086
|
if (!notice.dataset.timeout || notice.hidden)
|
|
328
1087
|
continue;
|
|
@@ -409,6 +1168,7 @@ function setStatus(host, state, label = "") {
|
|
|
409
1168
|
export {
|
|
410
1169
|
dialogs,
|
|
411
1170
|
forms,
|
|
1171
|
+
kanbans,
|
|
412
1172
|
menus,
|
|
413
1173
|
notices,
|
|
414
1174
|
scrolls,
|