Skip to content

Commit

Permalink
feat: correct types and utilize IS_IOS from lexical
Browse files Browse the repository at this point in the history
  • Loading branch information
2wheeh committed Apr 17, 2024
1 parent b971b06 commit f9e8b76
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
21 changes: 1 addition & 20 deletions ui/src/editor/plugins/fix-ios-korean-issue/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This plugin is a workaround for utilizing default backspace behavior on iOS Korean keyboards.
// https://github.com/facebook/lexical/pull/4814#issuecomment-2037716048
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
import { $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
import { $getNearestBlockElementAncestorOrThrow, IS_IOS } from '@lexical/utils';
import {
$getNearestNodeFromDOMNode,
$getSelection,
Expand All @@ -14,7 +14,6 @@ import {
} from 'lexical';
import { useEffect } from 'react';

// TODO: remove eslint-disables after https://github.com/facebook/lexical/pull/5833 is released
export function FixIOSKoreanIssuePlugin() {
const [editor] = useLexicalComposerContext();

Expand All @@ -32,12 +31,9 @@ export function FixIOSKoreanIssuePlugin() {
}

const { anchor } = selection;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const anchorNode = anchor.getNode();

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
if (selection.isCollapsed() && anchor.offset === 0 && !$isRootNode(anchorNode)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const element = $getNearestBlockElementAncestorOrThrow(anchorNode);
if (element.getIndent() > 0) {
event.preventDefault();
Expand Down Expand Up @@ -65,18 +61,3 @@ function $isTargetWithinDecorator(target: HTMLElement): boolean {
const node = $getNearestNodeFromDOMNode(target);
return $isDecoratorNode(node);
}

// TODO: remove below after https://github.com/facebook/lexical/pull/5831 is released
declare global {
interface Window {
MSStream?: unknown;
}
}

const CAN_USE_DOM: boolean =
typeof window !== 'undefined' &&
typeof window.document !== 'undefined' &&
typeof window.document.createElement !== 'undefined';

const IS_IOS: boolean =
CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
8 changes: 3 additions & 5 deletions ui/src/editor/plugins/list-max-indent-level/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import { useEffect } from 'react';

function getElementNodesInSelection(selection: RangeSelection): Set<ElementNode> {
const nodesInSelection = selection.getNodes();
// TODO: Remove this type assertion once the lexical types are updated. facebook#5710
const anchor = selection.anchor.getNode() as ElementNode;
const focus = selection.focus.getNode() as ElementNode;
const anchor = selection.anchor.getNode();
const focus = selection.focus.getNode();

if (nodesInSelection.length === 0) {
return new Set<ElementNode>([anchor.getParentOrThrow(), focus.getParentOrThrow()]);
Expand All @@ -41,8 +40,7 @@ function shouldPreventIndent(maxDepth: number) {
if ($isListNode(elementNode)) {
listNode = elementNode;
} else if ($isListItemNode(elementNode)) {
// TODO: Remove this type assertion once the lexical types are updated.
const parent = elementNode.getParent() as ElementNode;
const parent = elementNode.getParent();

if (!$isListNode(parent)) {
throw new Error(
Expand Down

0 comments on commit f9e8b76

Please sign in to comment.