This lands the clue collection line on top of origin/dev (v0.32.1, DSH 0.2.2-rc.2). The 14 commits that carried it are squashed into this one because every one of them overlapped upstream's own changes (version, 19 dictionaries, CHANGELOG), and each intermediate commit would have failed to compile against rc.2's menu API. The pre-integration head is kept at backup/clues-uiux-refresh-pre-rebase. What the feature is: - a Clues tab that reads local files, Feishu tasks/docs and GitHub issues/pulls through one source registry, with a scope row, shared search, filters, paging and stable [[dsh-clue:...]] references; - one window host for detail, pack management, source configuration, new pack and sharing (preview and edit are separate paths: a read is never saved over); - .cluepack export/import with per-row resolvability previews; - a source runtime that owns dependency installs and connection authorization (gh, lark-cli device code) and only probes on an explicit read; - the public betterSidebarClues service and the windows capability (features gains clues / windowHost). Merged with upstream rather than over it: - the settings section keeps upstream's start-page takeover group and this branch's clue sources group; navigation is now six groups; - the dictionaries keep both sides' new keys (1211 each, verified equal across all 19), the external-plugin guide and CHANGELOG keep both histories, and service features list both capability sets. Adapted to 0.2.2-rc.2: - menu call sites use anchorPoint instead of getAnchorRect; - the shared SelectMenu mounts the host menu only while open, because rc.2's Menu reads the DOM during render and broke server-rendered settings surfaces; - the submenu flip workaround stays deleted (the host positions submenus now), pinned by an updated layout-css assertion. Version 0.33.0 (three synced spots) with a new 未发布 / Unreleased changelog section; package.json regains the ./clues export, lib/clues.js and the uqr dependency that upstream never had. Gates: typecheck, lint, 5410 unit tests, build, check:consumer-types and the full mount lane (35 passed) against dsh 0.2.2-rc.2 in Chromium.
142 lines
6.8 KiB
TypeScript
142 lines
6.8 KiB
TypeScript
/**
|
||
* The Tasks page's motion contract, pinned where a refactor would break it
|
||
* silently:
|
||
*
|
||
* - the CANVAS must not run a FLIP library. Its card layer carries the fit's
|
||
* `transform: scale(k)`, and `@formkit/auto-animate` pins a leaving card with
|
||
* absolute `left/top` from `getBoundingClientRect()` (a box a scaled layer
|
||
* cannot express — the card jumps) and translates movers in unscaled units
|
||
* (k× the true distance). Attached there, it was reported as "折叠展开的动效
|
||
* 都特别怪"; the canvas uses the CSS entrance on `.node` instead.
|
||
* - the FLOW surfaces (tree rows, jobs rows) are where FLIP belongs, and they
|
||
* keep it.
|
||
*/
|
||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||
import { tasksFlowAnimation } from '../src/client/use-auto-animate.ts'
|
||
import { readFileSync } from 'node:fs'
|
||
import { resolve } from 'node:path'
|
||
|
||
const ROOT = resolve(import.meta.dirname, '..')
|
||
|
||
/** One source file of the client half. */
|
||
function source(relative: string): string {
|
||
return readFileSync(resolve(ROOT, relative), 'utf8')
|
||
}
|
||
|
||
/**
|
||
* A source file with its comments removed. The NEGATIVE assertions below are
|
||
* about what the code does, and these files deliberately DOCUMENT the library
|
||
* they avoid ("measures `getBoundingClientRect()`…"), so matching raw text
|
||
* would fail on the very explanation we want to keep.
|
||
*/
|
||
function code(relative: string): string {
|
||
return source(relative)
|
||
.replace(/\/\*[\s\S]*?\*\//g, '')
|
||
.replace(/^\s*\/\/.*$/gm, '')
|
||
}
|
||
|
||
afterEach(() => { vi.unstubAllGlobals() })
|
||
|
||
describe('Tasks page motion', () => {
|
||
it('keeps the FLIP library off the scaled canvas, and on the flow surfaces', () => {
|
||
expect(code('src/client/TasksGraph.tsx')).not.toContain('use-auto-animate')
|
||
expect(source('src/client/TasksTree.tsx')).toContain('useAutoAnimateRef')
|
||
expect(source('src/client/JobsDrawer.tsx')).toContain('useAutoAnimateRef')
|
||
})
|
||
|
||
it('keeps graph control menu items square while clipping the rounded cluster', () => {
|
||
const styles = source('src/client/tasks-graph.module.css')
|
||
const controls = /\.controls \{([\s\S]*?)\n\}/.exec(styles)?.[1]
|
||
const button = /\.controlBtn \{([\s\S]*?)\n\}/.exec(styles)?.[1]
|
||
const textButton = /\.controlText \{([\s\S]*?)\n\}/.exec(styles)?.[1]
|
||
if (controls === undefined || button === undefined || textButton === undefined) {
|
||
throw new Error('graph control rules must exist')
|
||
}
|
||
expect(controls).toContain('overflow: hidden')
|
||
expect(button).toContain('border-radius: 0')
|
||
expect(textButton).toContain('border-radius: 0')
|
||
})
|
||
|
||
it('gives canvas cards a mount-only CSS entrance that respects reduced motion', () => {
|
||
const styles = source('src/client/tasks-graph.module.css')
|
||
const node = /\.node \{([\s\S]*?)\n\}/.exec(styles)?.[1]
|
||
if (node === undefined) throw new Error('the .node rule must exist')
|
||
expect(node).toContain('animation: dsh-card-in')
|
||
const frames = /@keyframes dsh-card-in \{([\s\S]*?)\n\}/.exec(styles)?.[1]
|
||
if (frames === undefined) throw new Error('the card entrance keyframes must exist')
|
||
expect(frames).toContain('opacity: 0')
|
||
// Card entrances must switch off when reduced motion is requested.
|
||
const reduced = [...styles.matchAll(/@media \(prefers-reduced-motion: reduce\) \{([\s\S]*?)\n\}/g)]
|
||
.map(match => match[1])
|
||
.join('\n')
|
||
expect(reduced).toContain('.node')
|
||
})
|
||
|
||
it('animates the canvas in LAYOUT coordinates, never with screen-space transforms', () => {
|
||
// The canvas tween translates cards in canvas units, so the fit's scale
|
||
// applies to the tween exactly as it applies to the final positions — and
|
||
// the connectors (pure functions of the boxes) travel with the cards.
|
||
expect(source('src/client/TasksGraph.tsx')).toContain('useTweenedLayout')
|
||
const tween = code('src/client/tasks-layout-tween.ts')
|
||
expect(tween).toContain('requestAnimationFrame')
|
||
// No rect measuring in the CODE: that is exactly what makes a scaled layer
|
||
// unrepresentable for a FLIP library.
|
||
expect(tween).not.toContain('getBoundingClientRect')
|
||
// The card entrance is staggered, so a revealed group cascades.
|
||
expect(source('src/client/TasksGraph.tsx')).toContain('animationDelay')
|
||
})
|
||
|
||
it('keeps the frame auto-fitted across a fold, by GLIDING rather than jumping', () => {
|
||
const graph = code('src/client/TasksGraph.tsx')
|
||
// Folding must not claim the view: while the reader has not taken over, a
|
||
// layout change glides the frame to the new fit, so an expanded group stays
|
||
// centred and inside the panel without yanking the view.
|
||
expect(graph).not.toContain('markTouched')
|
||
// The untouched-view path GLIDES to the new framing; a fresh session snaps
|
||
// (the content changes wholesale), and the reader's own gestures cancel a
|
||
// glide in flight.
|
||
expect(graph).toContain('if (!touchedRef.current) fitRef.current(true)')
|
||
expect(graph).toContain('fitRef.current(false)')
|
||
expect(graph).toContain('stopGlide()')
|
||
})
|
||
|
||
it('gives every NESTED tree level its own FLIP host', () => {
|
||
// The library watches a container's direct children only: one host on the
|
||
// scroll container would animate the top level and let every nested fold
|
||
// blink. TreeLevel exists to own one per level.
|
||
const tree = code('src/client/TasksTree.tsx')
|
||
expect(tree).toContain('function TreeLevel')
|
||
expect(tree).toContain('useAutoAnimateRef')
|
||
expect(tree).toContain('<TreeLevel')
|
||
})
|
||
|
||
it('parks the motion host behind a WAAPI guard so tests and old hosts stay inert', () => {
|
||
const hook = source('src/client/use-auto-animate.ts')
|
||
expect(hook).toContain("typeof Element.prototype.animate !== 'function'")
|
||
expect(hook).toContain("typeof KeyframeEffect === 'undefined'")
|
||
expect(hook).toContain("typeof Animation === 'undefined'")
|
||
})
|
||
|
||
it('uses only opacity and transforms for flow-list motion within 300ms', () => {
|
||
const effects: Array<{ frames: Keyframe[]; timing: KeyframeEffectOptions }> = []
|
||
vi.stubGlobal('KeyframeEffect', class {
|
||
constructor(_element: Element, frames: Keyframe[], timing: KeyframeEffectOptions) {
|
||
effects.push({ frames, timing })
|
||
}
|
||
})
|
||
const element = {} as Element
|
||
tasksFlowAnimation(element, 'add', { left: 20, top: 20, width: 100, height: 30 })
|
||
tasksFlowAnimation(element, 'remove', { left: 20, top: 20, width: 100, height: 30 })
|
||
tasksFlowAnimation(element, 'remain',
|
||
{ left: 32, top: 16, width: 100, height: 30 },
|
||
{ left: 20, top: 20, width: 140, height: 60 })
|
||
expect(effects).toHaveLength(3)
|
||
for (const effect of effects) {
|
||
expect(effect.timing.duration).toBeLessThanOrEqual(300)
|
||
for (const frame of effect.frames) expect(Object.keys(frame).every(key => ['opacity', 'transform'].includes(key))).toBe(true)
|
||
}
|
||
expect(effects[2]?.frames).toEqual([{ transform: 'translate(12px, -4px)' }, { transform: 'translate(0, 0)' }])
|
||
})
|
||
|
||
})
|