Skip to content

Commit

Permalink
rename to onwarn
Browse files Browse the repository at this point in the history
  • Loading branch information
zurfyx committed May 4, 2024
1 parent 54d7282 commit 3f96a80
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
2 changes: 2 additions & 0 deletions packages/lexical-playground/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import YouTubePlugin from './plugins/YouTubePlugin';
import ContentEditable from './ui/ContentEditable';
import Placeholder from './ui/Placeholder';
import onError from './utils/onError';
import onWarn from './utils/onWarn';

const skipCollaborationInit =
// @ts-expect-error
Expand Down Expand Up @@ -157,6 +158,7 @@ export default function Editor(): JSX.Element {
<LexicalBlockNodeNormalizerPlugin__EXPERIMENTAL
blockNodes={BLOCK_NODES}
onError={onError}
onWarn={onWarn}
/>
{isRichText ? (
<>
Expand Down
11 changes: 11 additions & 0 deletions packages/lexical-playground/src/utils/onWarn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

export default function onWarn(message: string) {
console.warn(message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export type BlockNodeKlass<T> = Class<BlockNode<T>>;

declare export function LexicalBlockNodeNormalizerPlugin__EXPERIMENTAL(props: {
onError?: (message: string) => void;
onInfo?: (message: string) => void;
onWarn?: (message: string) => void;
blockNodes: Array<Class<React.Node>>;
}): React$Node;

declare export function registerBlockNodeNormalizerPlugin__EXPERIMENTAL<T>(
editor: LexicalEditor,
nodes: Array<Class<T>>, {
onError?: (message: string) => void;
onInfo?: (message: string) => void;
onWarn?: (message: string) => void;
},
): () => void;
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*
*/



import type {
DecoratorNode,
ElementNode,
Expand Down Expand Up @@ -44,25 +42,25 @@ const emptyFunction = () => {};
*
* @param blockNodes array of blockNode (aka elementNode.isInline() === false)
* @param onError won't be fixed
* @param onInfo
* @param onWarn
*/
export function LexicalBlockNodeNormalizerPlugin__EXPERIMENTAL({
blockNodes,
onError,
onInfo,
onWarn,
}: {
onError?: (message: string) => void;
onInfo?: (message: string) => void;
onWarn?: (message: string) => void;
blockNodes: Array<BlockNodeKlass<JSX.Element>>;
}): null {
const [editor] = useLexicalComposerContext();

useEffect(() => {
return registerBlockNodeNormalizerPlugin__EXPERIMENTAL(editor, blockNodes, {
onError,
onInfo,
onWarn,
});
}, [editor, blockNodes, onError, onInfo]);
}, [editor, blockNodes, onError, onWarn]);

return null;
}
Expand All @@ -72,10 +70,10 @@ export function registerBlockNodeNormalizerPlugin__EXPERIMENTAL<T>(
nodes: Array<BlockNodeKlass<T>>,
optional: {
onError?: (message: string) => void;
onInfo?: (message: string) => void;
onWarn?: (message: string) => void;
} = {},
): () => void {
const {onError = emptyFunction, onInfo = emptyFunction} = optional;
const {onError = emptyFunction, onWarn = emptyFunction} = optional;
let lastPasteCommand = 0;

const nodeTransform = (node: BlockNode<T>) => {
Expand Down Expand Up @@ -106,7 +104,7 @@ export function registerBlockNodeNormalizerPlugin__EXPERIMENTAL<T>(
// Log structural issues only once, and then separate events if it's
// related to copy-pasting
const isPasting = lastPasteCommand + 250 > Date.now();
onInfo(
onWarn(
`Found top level node ${node.getKey()} ${
node.constructor.name
} inside ${parent.getKey()} ${parent.constructor.name}${
Expand Down

0 comments on commit 3f96a80

Please sign in to comment.