From 816d1db4c6639ea74a572f070a897000818915f0 Mon Sep 17 00:00:00 2001 From: xdan Date: Sun, 14 Aug 2022 13:14:38 +0300 Subject: [PATCH] Dialogs don't work inside Shadow DOM #866 Issue: https://github.com/xdan/jodit/issues/866 --- src/core/event-emitter/event-emitter.ts | 9 +++++++++ src/core/ui/popup/popup.ts | 8 ++------ src/jodit.ts | 1 + src/plugins/fullsize/fullsize.ts | 6 +++++- src/plugins/link/link.ts | 1 - 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/core/event-emitter/event-emitter.ts b/src/core/event-emitter/event-emitter.ts index 78d4fdae6..5894c9130 100644 --- a/src/core/event-emitter/event-emitter.ts +++ b/src/core/event-emitter/event-emitter.ts @@ -103,6 +103,15 @@ export class EventEmitter implements IEventEmitter { return; } + // for Shadow Dom + if (e.composed && isFunction(e.composedPath) && e.composedPath()[0]) { + Object.defineProperty(e, 'target', { + value: e.composedPath()[0], + configurable: true, + enumerable: true + }); + } + if ( event.type.match(/^touch/) && (event as TouchEvent).changedTouches && diff --git a/src/core/ui/popup/popup.ts b/src/core/ui/popup/popup.ts index 4054623ad..fdd312890 100644 --- a/src/core/ui/popup/popup.ts +++ b/src/core/ui/popup/popup.ts @@ -28,7 +28,6 @@ import { assert, attr, css, - isFunction, isString, kebabCase, markOwner, @@ -383,14 +382,11 @@ export class Popup extends UIElement implements IPopup { } isOwnClick(e: MouseEvent): boolean { - const target = - (isFunction(e.composedPath) && e.composedPath()[0]) || e.target; - - if (!target) { + if (!e.target) { return false; } - const box = UIElement.closestElement(target as Node, Popup); + const box = UIElement.closestElement(e.target as Node, Popup); return Boolean(box && (this === box || box.closest(this))); } diff --git a/src/jodit.ts b/src/jodit.ts index c20a74730..c6f9e0395 100644 --- a/src/jodit.ts +++ b/src/jodit.ts @@ -348,6 +348,7 @@ export class Jodit extends Panel implements IJodit { language: jodit.o.language, license: jodit.o.license, theme: jodit.o.theme, + shadowRoot: jodit.o.shadowRoot, defaultCallback(data: IFileBrowserCallBackData): void { if (data.files && data.files.length) { data.files.forEach((file, i) => { diff --git a/src/plugins/fullsize/fullsize.ts b/src/plugins/fullsize/fullsize.ts index a73e1197d..10a579d5f 100644 --- a/src/plugins/fullsize/fullsize.ts +++ b/src/plugins/fullsize/fullsize.ts @@ -87,7 +87,11 @@ export function fullsize(editor: IViewWithToolbar): void { if (editor.o.globalFullSize) { let node = container.parentNode as HTMLElement; - while (node && node.nodeType !== Node.DOCUMENT_NODE) { + while ( + node && + node.nodeType !== Node.DOCUMENT_NODE && + node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE + ) { node.classList.toggle('jodit_fullsize-box_true', enable); node = node.parentNode as HTMLElement; } diff --git a/src/plugins/link/link.ts b/src/plugins/link/link.ts index 6b821be3a..db73f065b 100644 --- a/src/plugins/link/link.ts +++ b/src/plugins/link/link.ts @@ -23,7 +23,6 @@ import { } from 'jodit/core/helpers'; import { Plugin } from 'jodit/core/plugin'; import { autobind } from 'jodit/core/decorators'; -import { Dialog } from 'jodit/modules/dialog'; import { pluginSystem } from 'jodit/core/global'; import './config';