-
Notifications
You must be signed in to change notification settings - Fork 621
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lexical-editor): normalize input value and improve onChange execu…
…tion
- Loading branch information
Showing
3 changed files
with
34 additions
and
14 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
17 changes: 17 additions & 0 deletions
17
packages/lexical-editor/src/components/Editor/normalizeInputValue.ts
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,17 @@ | ||
import { LexicalValue, NormalizedInputValue } from "~/types"; | ||
|
||
const isValueEmpty = (value: any) => { | ||
return [undefined, null, "", '""', "null"].includes(value); | ||
}; | ||
|
||
/** | ||
* Value passed to the `RichTextEditor` component can be anything. This function normalizes some of the more common shapes | ||
* of input into a value that is either a `null` or a `LexicalValue`. | ||
*/ | ||
export function normalizeInputValue(value: LexicalValue | null | undefined) { | ||
if (isValueEmpty(value)) { | ||
return null; | ||
} | ||
|
||
return value as NormalizedInputValue; | ||
} |
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