-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from retejs/fix/no-drag-for-radix-ui
fix: pointerdown propagation
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export function copyEvent<T extends Event & Record<string, any>>(e: T) { | ||
const newEvent = new (e.constructor as { new(type: string): T })(e.type) | ||
let current = newEvent | ||
|
||
while ((current = Object.getPrototypeOf(current))) { | ||
const keys = Object.getOwnPropertyNames(current) | ||
|
||
for (const k of keys) { | ||
const item = newEvent[k] | ||
|
||
if (typeof item === 'function') continue | ||
|
||
Object.defineProperty(newEvent, k, { value: e[k] }) | ||
} | ||
} | ||
|
||
return newEvent | ||
} | ||
|
||
const rootPrefix = '__reactContainer$' | ||
|
||
type Keys = `${typeof rootPrefix}${string}` | '_reactRootContainer' | ||
type ReactNode = { [key in Keys]?: unknown } & HTMLElement | ||
|
||
export function findReactRoot(element: HTMLElement) { | ||
let current: ReactNode | null = element as ReactNode | ||
|
||
while (current) { | ||
if (current._reactRootContainer || Object.keys(current).some(key => key.startsWith(rootPrefix))) return current | ||
current = current.parentElement as ReactNode | ||
} | ||
} |