mirror of
https://github.com/facebook/lexical.git
synced 2025-08-26 10:40:47 +08:00
flow exact objects by default (#1249)
This commit is contained in:

committed by
acywatson

parent
2020bbadd5
commit
bf6bf30504
@ -14,6 +14,7 @@ untyped-type-import=error
|
||||
|
||||
[options]
|
||||
server.max_workers=4
|
||||
exact_by_default=true
|
||||
|
||||
module.name_mapper='^lexical$' -> '<PROJECT_ROOT>/packages/lexical/src/index.js'
|
||||
|
||||
|
@ -42,7 +42,7 @@ function readTextFileFromSystem(callback: (text: string) => void) {
|
||||
|
||||
export function exportFile(
|
||||
editor: LexicalEditor,
|
||||
config?: $ReadOnly<{source?: string, fileName?: string}> = {},
|
||||
config?: $ReadOnly<{source?: string, fileName?: string}> = Object.freeze({}),
|
||||
) {
|
||||
const now = new Date();
|
||||
const editorState = editor.getEditorState();
|
||||
|
@ -18,7 +18,10 @@ type SettingsContextShape = {
|
||||
setOption: (name: SettingName, value: boolean) => void,
|
||||
};
|
||||
|
||||
const Context: React$Context<SettingsContextShape> = createContext({});
|
||||
const Context: React$Context<SettingsContextShape> = createContext({
|
||||
settings: {},
|
||||
setOption: (_, __) => {},
|
||||
});
|
||||
|
||||
export const SettingsContext = ({
|
||||
children,
|
||||
|
@ -17,7 +17,9 @@ type ContextShape = {
|
||||
historyState?: HistoryState,
|
||||
};
|
||||
|
||||
const Context: React$Context<ContextShape> = createContext({});
|
||||
const Context: React$Context<ContextShape> = createContext({
|
||||
historyState: {current: null, redoStack: [], undoStack: []},
|
||||
});
|
||||
|
||||
export const SharedHistoryContext = ({
|
||||
children,
|
||||
|
@ -117,13 +117,7 @@ export class ExcalidrawNode extends DecoratorNode {
|
||||
}
|
||||
|
||||
decorate(editor: LexicalEditor): React$Node {
|
||||
return (
|
||||
<ExcalidrawComponent
|
||||
nodeKey={this.getKey()}
|
||||
state={this.__state}
|
||||
elements={[]}
|
||||
/>
|
||||
);
|
||||
return <ExcalidrawComponent nodeKey={this.getKey()} state={this.__state} />;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -434,7 +434,7 @@ function ImageComponent({
|
||||
<CollaborationPlugin
|
||||
id={decoratorEditor.id}
|
||||
providerFactory={createWebsocketProvider}
|
||||
initEditorState={false}
|
||||
skipInit={false}
|
||||
/>
|
||||
) : (
|
||||
<HistoryPlugin externalHistoryState={historyState} />
|
||||
|
@ -282,7 +282,7 @@ function StickyComponent({
|
||||
<CollaborationPlugin
|
||||
id={decoratorEditor.id}
|
||||
providerFactory={createWebsocketProvider}
|
||||
initEditorState={false}
|
||||
skipInit={false}
|
||||
/>
|
||||
) : (
|
||||
<HistoryPlugin externalHistoryState={historyState} />
|
||||
|
@ -35,7 +35,14 @@ export default function useLexical<EditorContext>(editorConfig?: {
|
||||
const onError =
|
||||
(editorConfig !== undefined && editorConfig.onError) ||
|
||||
defaultOnErrorHandler;
|
||||
const editor = useMemo(() => createEditor(editorConfig), [editorConfig]);
|
||||
const editor = useMemo(() => {
|
||||
if (editorConfig !== undefined) {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const {onError: _onError, ...config} = editorConfig;
|
||||
return createEditor(config);
|
||||
}
|
||||
return createEditor(editorConfig);
|
||||
}, [editorConfig]);
|
||||
const [rootElementRef, showPlaceholder] = useLexicalEditor(editor, onError);
|
||||
|
||||
return [editor, rootElementRef, showPlaceholder];
|
||||
|
@ -37,7 +37,7 @@ type OptionalProps = {
|
||||
export function useCharacterLimit(
|
||||
editor: LexicalEditor,
|
||||
maxCharacters: number,
|
||||
optional: OptionalProps = {},
|
||||
optional: OptionalProps = Object.freeze({}),
|
||||
): void {
|
||||
const {
|
||||
strlen = (input) => input.length, // UTF-16
|
||||
|
@ -47,6 +47,7 @@ export type CursorSelection = {
|
||||
key: NodeKey,
|
||||
offset: number,
|
||||
},
|
||||
name: HTMLSpanElement,
|
||||
};
|
||||
|
||||
export type Cursor = {
|
||||
|
@ -149,6 +149,7 @@ export type RootListener = (
|
||||
prevRootElement: null | HTMLElement,
|
||||
) => void;
|
||||
export type TextContentListener = (text: string) => void;
|
||||
export type TextMutationListener = (text: Text) => void;
|
||||
export type CommandListener = (
|
||||
type: string,
|
||||
payload: CommandPayload,
|
||||
@ -178,6 +179,7 @@ type Listeners = {
|
||||
root: Set<RootListener>,
|
||||
update: Set<UpdateListener>,
|
||||
command: Array<Set<CommandListener>>,
|
||||
textmutation: Set<TextMutationListener>,
|
||||
};
|
||||
|
||||
export type ListenerType =
|
||||
@ -186,6 +188,7 @@ export type ListenerType =
|
||||
| 'root'
|
||||
| 'decorator'
|
||||
| 'textcontent'
|
||||
| 'textmutation'
|
||||
| 'command';
|
||||
|
||||
export type TransformerType = 'text' | 'decorator' | 'element' | 'root';
|
||||
@ -353,6 +356,7 @@ class BaseLexicalEditor {
|
||||
decorator: new Set(),
|
||||
error: new Set(),
|
||||
textcontent: new Set(),
|
||||
textmutation: new Set(),
|
||||
root: new Set(),
|
||||
update: new Set(),
|
||||
command: [new Set(), new Set(), new Set(), new Set(), new Set()],
|
||||
|
@ -56,14 +56,19 @@ type RootElementEvents = Array<
|
||||
[string, {} | ((event: Event, editor: LexicalEditor) => void)],
|
||||
>;
|
||||
|
||||
const PASS_THROUGH_COMMAND = {};
|
||||
const PASS_THROUGH_COMMAND = Object.freeze({});
|
||||
|
||||
const rootElementEvents: RootElementEvents = [
|
||||
['selectionchange', onSelectionChange],
|
||||
// $FlowIgnore bad event inheritance
|
||||
['keydown', onKeyDown],
|
||||
// $FlowIgnore bad event inheritance
|
||||
['compositionstart', onCompositionStart],
|
||||
// $FlowIgnore bad event inheritance
|
||||
['compositionend', onCompositionEnd],
|
||||
// $FlowIgnore bad event inheritance
|
||||
['input', onInput],
|
||||
// $FlowIgnore bad event inheritance
|
||||
['click', onClick],
|
||||
['cut', PASS_THROUGH_COMMAND],
|
||||
['copy', PASS_THROUGH_COMMAND],
|
||||
@ -74,6 +79,7 @@ const rootElementEvents: RootElementEvents = [
|
||||
];
|
||||
|
||||
if (CAN_USE_BEFORE_INPUT) {
|
||||
// $FlowIgnore bad event inheritance
|
||||
rootElementEvents.push(['beforeinput', onBeforeInput]);
|
||||
} else {
|
||||
rootElementEvents.push(['drop', PASS_THROUGH_COMMAND]);
|
||||
|
@ -138,7 +138,7 @@ export function internalCreateNodeFromParse(
|
||||
parsedNodeMap: ParsedNodeMap,
|
||||
editor: LexicalEditor,
|
||||
parentKey: null | NodeKey,
|
||||
state: NodeParserState = {},
|
||||
state: NodeParserState = {originalSelection: null},
|
||||
): LexicalNode {
|
||||
const nodeType = parsedNode.__type;
|
||||
const registeredNode = editor._registeredNodes.get(nodeType);
|
||||
|
Reference in New Issue
Block a user