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