Skip to content

Commit 9ec8637

Browse files
[lexical][lexical-clipboard][lexical-playground][lexical-react][lexical-selection][lexical-table][lexical-utils] Add Shadow DOM support
1 parent 92ddb41 commit 9ec8637

File tree

27 files changed

+2273
-93
lines changed

27 files changed

+2273
-93
lines changed

package-lock.json

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
"@rollup/plugin-terser": "^0.4.4",
136136
"@types/child-process-promise": "^2.2.6",
137137
"@types/jest": "^29.5.12",
138-
"@types/jsdom": "^21.1.6",
138+
"@types/jsdom": "^27.0.0",
139139
"@types/katex": "^0.16.7",
140140
"@types/node": "^17.0.31",
141141
"@types/prettier": "^2.7.3",

packages/lexical-clipboard/src/clipboard.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import {
2525
BaseSelection,
2626
COMMAND_PRIORITY_CRITICAL,
2727
COPY_COMMAND,
28-
getDOMSelection,
28+
getDOMSelectionForEditor,
29+
getWindow,
2930
isSelectionWithinEditor,
3031
LexicalEditor,
3132
LexicalNode,
@@ -448,9 +449,9 @@ export async function copyToClipboard(
448449
}
449450

450451
const rootElement = editor.getRootElement();
451-
const editorWindow = editor._window || window;
452+
const editorWindow = getWindow(editor);
452453
const windowDocument = editorWindow.document;
453-
const domSelection = getDOMSelection(editorWindow);
454+
const domSelection = getDOMSelectionForEditor(editor);
454455
if (rootElement === null || domSelection === null) {
455456
return false;
456457
}
@@ -499,13 +500,12 @@ function $copyToClipboardEvent(
499500
data?: LexicalClipboardData,
500501
): boolean {
501502
if (data === undefined) {
502-
const domSelection = getDOMSelection(editor._window);
503+
const domSelection = getDOMSelectionForEditor(editor);
503504
const selection = $getSelection();
504505

505506
if (!selection || selection.isCollapsed()) {
506507
return false;
507508
}
508-
509509
if (!domSelection) {
510510
return false;
511511
}

packages/lexical-playground/src/Editor.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import TwitterPlugin from './plugins/TwitterPlugin';
8383
import {VersionsPlugin} from './plugins/VersionsPlugin';
8484
import YouTubePlugin from './plugins/YouTubePlugin';
8585
import ContentEditable from './ui/ContentEditable';
86+
import ShadowDOMWrapper from './ui/ShadowDOMWrapper';
8687

8788
const COLLAB_DOC_ID = 'main';
8889

@@ -104,6 +105,7 @@ export default function Editor(): JSX.Element {
104105
hasLinkAttributes,
105106
isCharLimitUtf8,
106107
isRichText,
108+
isShadowDOM,
107109
showTreeView,
108110
showTableOfContents,
109111
shouldUseLexicalContextMenu,
@@ -169,7 +171,9 @@ export default function Editor(): JSX.Element {
169171
setIsLinkEditMode={setIsLinkEditMode}
170172
/>
171173
)}
172-
<div
174+
<ShadowDOMWrapper
175+
key={`shadow-${isShadowDOM}`}
176+
enabled={isShadowDOM}
173177
className={`editor-container ${showTreeView ? 'tree-view' : ''} ${
174178
!isRichText ? 'plain-text' : ''
175179
}`}>
@@ -302,7 +306,7 @@ export default function Editor(): JSX.Element {
302306
shouldPreserveNewLinesInMarkdown={shouldPreserveNewLinesInMarkdown}
303307
useCollabV2={useCollabV2}
304308
/>
305-
</div>
309+
</ShadowDOMWrapper>
306310
{showTreeView && <TreeViewPlugin />}
307311
</>
308312
);

packages/lexical-playground/src/Settings.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default function Settings(): JSX.Element {
2828
isCharLimit,
2929
isCharLimitUtf8,
3030
isAutocomplete,
31+
isShadowDOM,
3132
showTreeView,
3233
showNestedEditorTreeView,
3334
// disableBeforeInput,
@@ -139,6 +140,11 @@ export default function Settings(): JSX.Element {
139140
checked={isAutocomplete}
140141
text="Autocomplete"
141142
/>
143+
<Switch
144+
onClick={() => setOption('isShadowDOM', !isShadowDOM)}
145+
checked={isShadowDOM}
146+
text="Shadow DOM"
147+
/>
142148
{/* <Switch
143149
onClick={() => {
144150
setOption('disableBeforeInput', !disableBeforeInput);

packages/lexical-playground/src/appSettings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const DEFAULT_SETTINGS = {
2323
isCollab: false,
2424
isMaxLength: false,
2525
isRichText: true,
26+
isShadowDOM: false,
2627
listStrictIndent: false,
2728
measureTypingPerf: false,
2829
selectionAlwaysOnDisplay: false,

packages/lexical-playground/src/plugins/CommentPlugin/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import {
5050
COMMAND_PRIORITY_EDITOR,
5151
COMMAND_PRIORITY_NORMAL,
5252
createCommand,
53-
getDOMSelection,
53+
getDOMSelectionForEditor,
5454
KEY_ESCAPE_COMMAND,
5555
} from 'lexical';
5656
import {
@@ -933,7 +933,7 @@ export default function CommentPlugin({
933933
editor.registerCommand(
934934
INSERT_INLINE_COMMAND,
935935
() => {
936-
const domSelection = getDOMSelection(editor._window);
936+
const domSelection = getDOMSelectionForEditor(editor);
937937
if (domSelection !== null) {
938938
domSelection.removeAllRanges();
939939
}

packages/lexical-playground/src/plugins/FloatingLinkEditorPlugin/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
COMMAND_PRIORITY_CRITICAL,
2828
COMMAND_PRIORITY_HIGH,
2929
COMMAND_PRIORITY_LOW,
30-
getDOMSelection,
30+
getDOMSelectionForEditor,
3131
KEY_ESCAPE_COMMAND,
3232
LexicalEditor,
3333
SELECTION_CHANGE_COMMAND,
@@ -104,7 +104,7 @@ function FloatingLinkEditor({
104104
}
105105

106106
const editorElem = editorRef.current;
107-
const nativeSelection = getDOMSelection(editor._window);
107+
const nativeSelection = getDOMSelectionForEditor(editor);
108108
const activeElement = document.activeElement;
109109

110110
if (editorElem === null) {

packages/lexical-playground/src/plugins/FloatingTextFormatToolbarPlugin/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
$isTextNode,
2222
COMMAND_PRIORITY_LOW,
2323
FORMAT_TEXT_COMMAND,
24-
getDOMSelection,
24+
getDOMSelectionForEditor,
2525
LexicalEditor,
2626
SELECTION_CHANGE_COMMAND,
2727
} from 'lexical';
@@ -122,7 +122,7 @@ function TextFormatFloatingToolbar({
122122
const selection = $getSelection();
123123

124124
const popupCharStylesEditorElem = popupCharStylesEditorRef.current;
125-
const nativeSelection = getDOMSelection(editor._window);
125+
const nativeSelection = getDOMSelectionForEditor(editor);
126126

127127
if (popupCharStylesEditorElem === null) {
128128
return;
@@ -342,7 +342,7 @@ function useFloatingTextFormatToolbar(
342342
return;
343343
}
344344
const selection = $getSelection();
345-
const nativeSelection = getDOMSelection(editor._window);
345+
const nativeSelection = getDOMSelectionForEditor(editor);
346346
const rootElement = editor.getRootElement();
347347

348348
if (

packages/lexical-playground/src/plugins/TableActionMenuPlugin/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
$isTextNode,
4242
$setSelection,
4343
COMMAND_PRIORITY_CRITICAL,
44-
getDOMSelection,
44+
getDOMSelectionForEditor,
4545
isDOMNode,
4646
SELECTION_CHANGE_COMMAND,
4747
} from 'lexical';
@@ -729,7 +729,7 @@ function TableCellActionMenuContainer({
729729
const $moveMenu = useCallback(() => {
730730
const menu = menuButtonRef.current;
731731
const selection = $getSelection();
732-
const nativeSelection = getDOMSelection(editor._window);
732+
const nativeSelection = getDOMSelectionForEditor(editor);
733733
const activeElement = document.activeElement;
734734
function disable() {
735735
if (menu) {

0 commit comments

Comments
 (0)