-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix share dialog and make it into ShadowRoot
- Loading branch information
1 parent
834a01e
commit 3f56792
Showing
9 changed files
with
88 additions
and
40 deletions.
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
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
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
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,57 @@ | ||
import { livingShadowRoots } from './ConstructableStyleSheetsRenderer' | ||
|
||
const div = document.createElement('div') | ||
document.body.appendChild(div) | ||
export const PortalShadowRoot = (div.attachShadow({ mode: 'closed' }) as unknown) as any | ||
livingShadowRoots.add(PortalShadowRoot as any) | ||
|
||
Object.defineProperty(ShadowRoot.prototype, 'nodeType', { | ||
get() { | ||
if (this === PortalShadowRoot) return 1 | ||
else return Object.getOwnPropertyDescriptor(Node.prototype, 'nodeType')!.get!.call(this) | ||
}, | ||
}) | ||
Object.defineProperty(ShadowRoot.prototype, 'tagName', { | ||
get() { | ||
if (this === PortalShadowRoot) return 'div' | ||
else return undefined | ||
}, | ||
}) | ||
Object.defineProperty(ShadowRoot.prototype, 'style', { | ||
get() { | ||
if (this === PortalShadowRoot) return div.style | ||
else return undefined | ||
}, | ||
}) | ||
|
||
{ | ||
// ? Hack for React, let event go through ShadowDom | ||
const hackingEvents = new WeakMap<Event, EventTarget[]>() | ||
function hack(eventName: string, shadowRoot: ShadowRoot) { | ||
shadowRoot.addEventListener(eventName, (e: Event) => { | ||
if (hackingEvents.has(e)) return | ||
const path = e.composedPath() | ||
// @ts-ignore | ||
const e2 = new e.constructor(e.type, e) | ||
hackingEvents.set(e2, path) | ||
shadowRoot.dispatchEvent(e2) | ||
e.stopPropagation() | ||
e.stopImmediatePropagation() | ||
}) | ||
} | ||
// ? If react listen to some event, we also hack it. | ||
document.addEventListener = new Proxy(document.addEventListener, { | ||
apply(target, thisArg, args) { | ||
const [eventName, listener, options] = args | ||
hack(eventName, PortalShadowRoot) | ||
return target.apply(thisArg, args) | ||
}, | ||
}) | ||
const nativeTarget = Object.getOwnPropertyDescriptor(Event.prototype, 'target')!.get! | ||
Object.defineProperty(Event.prototype, 'target', { | ||
get() { | ||
if (hackingEvents.has(this)) return hackingEvents.get(this)![0] | ||
return nativeTarget.call(this) | ||
}, | ||
}) | ||
} |
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