Skip to content

Commit

Permalink
Update lexical and lexical-react module
Browse files Browse the repository at this point in the history
  • Loading branch information
aquarius-wing committed May 13, 2024
1 parent db9f260 commit 369937f
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 69 deletions.
3 changes: 2 additions & 1 deletion packages/lexical-react/dist/LexicalComposer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
*/
import { EditorState, EditorThemeClasses, HTMLConfig, Klass, LexicalEditor, LexicalNode, LexicalNodeReplacement } from 'lexical';
import { EditorState, EditorThemeClasses, HTMLConfig, Klass, LexicalEditor, LexicalNode, LexicalNodeReplacement, type PointType } from 'lexical';
import * as React from 'react';
export type InitialEditorStateType = null | string | EditorState | ((editor: LexicalEditor) => void);
export type InitialConfigType = Readonly<{
Expand All @@ -17,6 +17,7 @@ export type InitialConfigType = Readonly<{
theme?: EditorThemeClasses;
editorState?: InitialEditorStateType;
html?: HTMLConfig;
customGetAdjacentNode?: (focus: PointType, isBackward: boolean) => null | LexicalNode;
}>;
type Props = React.PropsWithChildren<{
initialConfig: InitialConfigType;
Expand Down
3 changes: 2 additions & 1 deletion packages/lexical-react/npm/LexicalComposer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
*/
import { EditorState, EditorThemeClasses, HTMLConfig, Klass, LexicalEditor, LexicalNode, LexicalNodeReplacement } from 'lexical';
import { EditorState, EditorThemeClasses, HTMLConfig, Klass, LexicalEditor, LexicalNode, LexicalNodeReplacement, type PointType } from 'lexical';
import * as React from 'react';
export type InitialEditorStateType = null | string | EditorState | ((editor: LexicalEditor) => void);
export type InitialConfigType = Readonly<{
Expand All @@ -17,6 +17,7 @@ export type InitialConfigType = Readonly<{
theme?: EditorThemeClasses;
editorState?: InitialEditorStateType;
html?: HTMLConfig;
customGetAdjacentNode?: (focus: PointType, isBackward: boolean) => null | LexicalNode;
}>;
type Props = React.PropsWithChildren<{
initialConfig: InitialConfigType;
Expand Down
1 change: 1 addition & 0 deletions packages/lexical-react/npm/LexicalComposer.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function LexicalComposer({
let editor = initialEditor || null;
if (editor === null) {
const newEditor = lexical.createEditor({
customGetAdjacentNode: initialConfig.customGetAdjacentNode,
editable: initialConfig.editable,
html,
namespace,
Expand Down
1 change: 1 addition & 0 deletions packages/lexical-react/npm/LexicalComposer.dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function LexicalComposer({
let editor = initialEditor || null;
if (editor === null) {
const newEditor = createEditor({
customGetAdjacentNode: initialConfig.customGetAdjacentNode,
editable: initialConfig.editable,
html,
namespace,
Expand Down
4 changes: 2 additions & 2 deletions packages/lexical-react/npm/LexicalComposer.prod.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/lexical-react/npm/LexicalComposer.prod.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import{createLexicalComposerContext as e,LexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{createEditor as o,$getRoot as n,$createParagraphNode as i,$getSelection as r}from"lexical";import*as a from"react";import{useLayoutEffect as l,useEffect as c,useMemo as s}from"react";const d="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;var m=d?l:c;const u={tag:"history-merge"};function f({initialConfig:l,children:c}){const f=s((()=>{const{theme:t,namespace:a,editor__DEPRECATED:c,nodes:s,onError:m,editorState:f,html:p}=l,E=e(null,t);let v=c||null;if(null===v){const e=o({editable:l.editable,html:p,namespace:a,nodes:s,onError:t=>m(t,e),theme:t});!function(e,t){if(null===t)return;if(void 0===t)e.update((()=>{const t=n();if(t.isEmpty()){const o=i();t.append(o);const n=d?document.activeElement:null;(null!==r()||null!==n&&n===e.getRootElement())&&o.select()}}),u);else if(null!==t)switch(typeof t){case"string":{const o=e.parseEditorState(t);e.setEditorState(o,u);break}case"object":e.setEditorState(t,u);break;case"function":e.update((()=>{n().isEmpty()&&t(e)}),u)}}(e,f),v=e}return[v,E]}),[]);return m((()=>{const e=l.editable,[t]=f;t.setEditable(void 0===e||e)}),[]),a.createElement(t.Provider,{value:f},c)}export{f as LexicalComposer};
import{createLexicalComposerContext as e,LexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{createEditor as o,$getRoot as n,$createParagraphNode as i,$getSelection as r}from"lexical";import*as a from"react";import{useLayoutEffect as c,useEffect as l,useMemo as s}from"react";const d="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;var m=d?c:l;const u={tag:"history-merge"};function f({initialConfig:c,children:l}){const f=s((()=>{const{theme:t,namespace:a,editor__DEPRECATED:l,nodes:s,onError:m,editorState:f,html:p}=c,E=e(null,t);let v=l||null;if(null===v){const e=o({customGetAdjacentNode:c.customGetAdjacentNode,editable:c.editable,html:p,namespace:a,nodes:s,onError:t=>m(t,e),theme:t});!function(e,t){if(null===t)return;if(void 0===t)e.update((()=>{const t=n();if(t.isEmpty()){const o=i();t.append(o);const n=d?document.activeElement:null;(null!==r()||null!==n&&n===e.getRootElement())&&o.select()}}),u);else if(null!==t)switch(typeof t){case"string":{const o=e.parseEditorState(t);e.setEditorState(o,u);break}case"object":e.setEditorState(t,u);break;case"function":e.update((()=>{n().isEmpty()&&t(e)}),u)}}(e,f),v=e}return[v,E]}),[]);return m((()=>{const e=c.editable,[t]=f;t.setEditable(void 0===e||e)}),[]),a.createElement(t.Provider,{value:f},l)}export{f as LexicalComposer};
3 changes: 3 additions & 0 deletions packages/lexical/dist/LexicalEditor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
import type { EditorState, SerializedEditorState } from './LexicalEditorState';
import type { DOMConversion, DOMConversionMap, DOMExportOutput, NodeKey } from './LexicalNode';
import { type PointType } from '.';
import { LexicalNode } from './LexicalNode';
export type Spread<T1, T2> = Omit<T2, keyof T1> & T1;
export type KlassConstructor<Cls extends GenericConstructor<any>> = GenericConstructor<InstanceType<Cls>> & {
Expand Down Expand Up @@ -104,6 +105,7 @@ export type EditorConfig = {
disableEvents?: boolean;
namespace: string;
theme: EditorThemeClasses;
customGetAdjacentNode?: (focus: PointType, isBackward: boolean) => null | LexicalNode;
};
export type LexicalNodeReplacement = {
replace: Klass<LexicalNode>;
Expand All @@ -126,6 +128,7 @@ export type CreateEditorArgs = {
editable?: boolean;
theme?: EditorThemeClasses;
html?: HTMLConfig;
customGetAdjacentNode?: (focus: PointType, isBackward: boolean) => null | LexicalNode;
};
export type RegisteredNodes = Map<string, RegisteredNode>;
export type RegisteredNode = {
Expand Down
8 changes: 8 additions & 0 deletions packages/lexical/npm/Lexical.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,13 @@ function resolveElement(element, isBackward, focusOffset) {
return block.getChildAtIndex(isBackward ? offset - 1 : offset);
}
function $getAdjacentNode(focus, isBackward) {
const customGetAdjacentNode = getActiveEditor()._config.customGetAdjacentNode;
if (customGetAdjacentNode) {
const result = customGetAdjacentNode(focus, isBackward);
if (result) {
return result;
}
}
const focusOffset = focus.offset;
if (focus.type === 'element') {
const block = focus.getNode();
Expand Down Expand Up @@ -9131,6 +9138,7 @@ function createEditor(editorConfig) {
}
}
const editor = new LexicalEditor(editorState, parentEditor, registeredNodes, {
customGetAdjacentNode: config.customGetAdjacentNode,
disableEvents,
namespace,
theme
Expand Down
8 changes: 8 additions & 0 deletions packages/lexical/npm/Lexical.dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,13 @@ function resolveElement(element, isBackward, focusOffset) {
return block.getChildAtIndex(isBackward ? offset - 1 : offset);
}
function $getAdjacentNode(focus, isBackward) {
const customGetAdjacentNode = getActiveEditor()._config.customGetAdjacentNode;
if (customGetAdjacentNode) {
const result = customGetAdjacentNode(focus, isBackward);
if (result) {
return result;
}
}
const focusOffset = focus.offset;
if (focus.type === 'element') {
const block = focus.getNode();
Expand Down Expand Up @@ -9129,6 +9136,7 @@ function createEditor(editorConfig) {
}
}
const editor = new LexicalEditor(editorState, parentEditor, registeredNodes, {
customGetAdjacentNode: config.customGetAdjacentNode,
disableEvents,
namespace,
theme
Expand Down
Loading

0 comments on commit 369937f

Please sign in to comment.