chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import { act } from '@testing-library/react'
|
||||
import { vi } from 'vite-plus/test'
|
||||
|
||||
/** Emit visibility changes for currently observed elements; restore globals after each test. */
|
||||
export function mockIntersectionObserver() {
|
||||
const observers = new Set<Observer>()
|
||||
class Observer implements IntersectionObserver {
|
||||
readonly root: Element | Document | null
|
||||
readonly rootMargin: string
|
||||
readonly thresholds: number[]
|
||||
readonly scrollMargin = '0px'
|
||||
readonly delay = 0
|
||||
readonly trackVisibility = false
|
||||
readonly targets = new Set<Element>()
|
||||
readonly callback: IntersectionObserverCallback
|
||||
constructor(callback: IntersectionObserverCallback, options: IntersectionObserverInit = {}) {
|
||||
this.callback = callback
|
||||
this.root = options.root ?? null
|
||||
this.rootMargin = options.rootMargin ?? '0px'
|
||||
this.thresholds = [options.threshold ?? 0].flat()
|
||||
}
|
||||
observe(target: Element) {
|
||||
this.targets.add(target)
|
||||
observers.add(this)
|
||||
}
|
||||
unobserve(target: Element) {
|
||||
this.targets.delete(target)
|
||||
if (!this.targets.size) observers.delete(this)
|
||||
}
|
||||
disconnect() {
|
||||
this.targets.clear()
|
||||
observers.delete(this)
|
||||
}
|
||||
takeRecords(): IntersectionObserverEntry[] {
|
||||
return []
|
||||
}
|
||||
}
|
||||
vi.stubGlobal('IntersectionObserver', Observer)
|
||||
return (isIntersecting = true, options: { target?: Element; intersectionRatio?: number } = {}) =>
|
||||
act(() => {
|
||||
for (const observer of [...observers]) {
|
||||
const targets = [...observer.targets].filter(
|
||||
(target) => !options.target || target === options.target,
|
||||
)
|
||||
if (!targets.length) continue
|
||||
observer.callback(
|
||||
targets.map((target) => ({
|
||||
target,
|
||||
time: 0,
|
||||
isIntersecting,
|
||||
intersectionRatio: options.intersectionRatio ?? (isIntersecting ? 1 : 0),
|
||||
rootBounds: null,
|
||||
boundingClientRect: target.getBoundingClientRect(),
|
||||
intersectionRect: new DOMRect(),
|
||||
})),
|
||||
observer,
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user