Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172// Drive Dock's pointer lifecycle: tree tests cannot see which rendered edge// wins or whether a preview can be released onto its advertised target.import assert from 'node:assert/strict';import test from 'node:test';import { loadDock, tree } from './tiles-fixture.mjs';
const { Dock } = await loadDock();const { canvas, leaf, split, tabs, windows } = tree;
const rect = (left, top, width, height) => ({ left, top, width, height, right: left + width, bottom: top + height,});
function dockOn(t, layout, boxes) { const listeners = new Map(); t.mock.timers.enable({ apis: ['setTimeout'] }); const undo = (key, value) => { const prior = globalThis[key]; globalThis[key] = value; t.after(() => { if (prior === undefined) delete globalThis[key]; else globalThis[key] = prior; }); }; undo('addEventListener', (type, fn) => listeners.set(type, fn)); undo('removeEventListener', (type) => listeners.delete(type)); undo('CSS', { escape: (id) => id }); undo('document', { elementsFromPoint: () => [] }); const landed = []; const board = { id: 'board', root: layout, windows: Object.fromEntries(windows(layout).map((id) => [id, { id }])), placeOf: () => 'tile', lift: () => assert.fail('a direct column must not lift'), unlift: () => {}, squeeze: () => null, move: (id, target, side) => landed.push(['window', id, target, side]), moveTile: (id, target, side) => landed.push(['tile', id, target, side]), }; const dock = new Dock( () => board, () => ({ getBoundingClientRect: () => rect(0, 0, 680, 440), querySelector: (selector) => { if (selector === ':scope > .layout') return { clientWidth: 680 }; const id = selector.match(/="([^"]+)"/)?.[1]; const box = boxes.get(id); return ( box && { isConnected: true, getBoundingClientRect: () => box, querySelector: () => null, } ); }, }), );
const at = (clientX, clientY, shiftKey = false) => ({ button: 0, buttons: 1, pointerId: 1, clientX, clientY, shiftKey, preventDefault() {}, stopPropagation() {}, }); return { dock, landed, press: (tile, x, y) => { const window = tile.kind === 'leaf'; const grip = window ? 'dockWindow' : 'dockTile'; const selector = window ? '[data-dock-window]' : '[data-dock-tile]'; dock.press({ ...at(x, y), target: { closest: (query) => query === selector ? { dataset: { [grip]: tile.window ?? tile.id } } : null, }, }); }, move: (x, y, shift) => listeners.get('pointermove')(at(x, y, shift)), up: (x, y) => { listeners.get('pointerup')(at(x, y)); t.mock.timers.runAll(); }, };}
test('returning over an empty canvas carried as a column never previews or commits a move', (t) => { const own = canvas(); const other = leaf('other'); const root = split('row', [own, other]); const drag = dockOn( t, root, new Map([ [root.id, rect(0, 0, 606, 440)], [own.id, rect(0, 0, 300, 440)], [other.id, rect(306, 0, 300, 440)], ]), ); drag.press(own, 130, 20); drag.move(430, 200); assert.equal(drag.dock.carry.drop?.target, other.id); drag.move(130, 200); assert.equal(drag.dock.carry.drop, null); drag.up(130, 200); assert.deepEqual(drag.landed, []);});
test('a tab-frame drop falls back in the reserved edge and can land beside the surviving ancestor', (t) => { const frame = tabs([canvas(), leaf('hidden')]); const bottom = leaf('bottom'); const stack = split('column', [frame, bottom]); const own = leaf('moving'); const root = split('row', [stack, own]); const drag = dockOn( t, root, new Map([ [root.id, rect(0, 0, 670, 440)], [stack.id, rect(0, 0, 320, 440)], [frame.id, rect(0, 0, 320, 270)], [bottom.id, rect(0, 276, 320, 164)], [own.id, rect(326, 0, 344, 440)], ]), ); drag.press(own, 510, 25); // Shift skips the scrolling insertion band, which must fall back to the frame. drag.move(4, 220, true); assert.equal(drag.dock.carry.drop?.target, frame.id); assert.equal(drag.dock.carry.drop?.where, 'left'); // Past the insertion band is the ancestor strip. The original row will vanish. drag.move(13, 220); assert.equal(drag.dock.carry.drop?.target, stack.id); assert.equal(drag.dock.carry.drop?.where, 'left'); drag.up(13, 220); assert.deepEqual(drag.landed, [['window', own.window, stack.id, 'left']]);});
test('a whole tabs column can merge even though its original wrapper disappears', (t) => { const moving = tabs([leaf('moving tab'), canvas()]); const target = tabs([leaf('first tab'), leaf('second tab')]); const root = split('row', [moving, target]); const drag = dockOn( t, root, new Map([ [root.id, rect(0, 0, 606, 440)], [moving.id, rect(0, 0, 300, 440)], [target.id, rect(306, 0, 300, 440)], ]), ); drag.press(moving, 135, 25); drag.move(450, 220); assert.equal(drag.dock.carry.drop?.target, target.id); assert.equal(drag.dock.carry.drop?.where, 'tab'); drag.up(450, 220); assert.deepEqual(drag.landed, [['tile', moving.id, target.id, 'tab']]);});