@depup/lexical__react 0.41.0-depup.0 → 0.42.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LexicalAutoEmbedPlugin.d.ts +2 -2
- package/LexicalAutoEmbedPlugin.js.flow +4 -4
- package/LexicalDecoratorBlockNode.d.ts +2 -0
- package/LexicalDecoratorBlockNode.dev.js +7 -0
- package/LexicalDecoratorBlockNode.dev.mjs +7 -0
- package/LexicalDecoratorBlockNode.prod.js +1 -1
- package/LexicalDecoratorBlockNode.prod.mjs +1 -1
- package/LexicalDraggableBlockPlugin.dev.js +2 -4
- package/LexicalDraggableBlockPlugin.dev.mjs +2 -4
- package/LexicalDraggableBlockPlugin.prod.js +1 -1
- package/LexicalDraggableBlockPlugin.prod.mjs +1 -1
- package/LexicalExtensionComposer.d.ts +1 -1
- package/LexicalExtensionEditorComposer.d.ts +20 -0
- package/LexicalExtensionEditorComposer.dev.js +55 -0
- package/LexicalExtensionEditorComposer.dev.mjs +53 -0
- package/LexicalExtensionEditorComposer.js +11 -0
- package/LexicalExtensionEditorComposer.js.flow +27 -0
- package/{LexicalContextMenuPlugin.mjs → LexicalExtensionEditorComposer.mjs} +3 -4
- package/{LexicalContextMenuPlugin.node.mjs → LexicalExtensionEditorComposer.node.mjs} +2 -3
- package/LexicalExtensionEditorComposer.prod.js +9 -0
- package/LexicalExtensionEditorComposer.prod.mjs +9 -0
- package/LexicalHorizontalRulePlugin.d.ts +3 -0
- package/LexicalHorizontalRulePlugin.dev.js +4 -0
- package/LexicalHorizontalRulePlugin.dev.mjs +4 -0
- package/LexicalMarkdownShortcutPlugin.dev.js +4 -4
- package/LexicalMarkdownShortcutPlugin.dev.mjs +1 -1
- package/LexicalMarkdownShortcutPlugin.prod.js +1 -1
- package/LexicalMarkdownShortcutPlugin.prod.mjs +1 -1
- package/LexicalNodeContextMenuPlugin.dev.js +2 -4
- package/LexicalNodeContextMenuPlugin.dev.mjs +2 -4
- package/LexicalNodeContextMenuPlugin.prod.js +1 -1
- package/LexicalNodeContextMenuPlugin.prod.mjs +1 -1
- package/LexicalNodeEventPlugin.dev.js +2 -4
- package/LexicalNodeEventPlugin.dev.mjs +2 -4
- package/LexicalNodeEventPlugin.prod.js +1 -1
- package/LexicalNodeEventPlugin.prod.mjs +1 -1
- package/LexicalNodeMenuPlugin.d.ts +1 -1
- package/LexicalNodeMenuPlugin.dev.js +53 -2
- package/LexicalNodeMenuPlugin.dev.mjs +54 -3
- package/LexicalNodeMenuPlugin.js.flow +3 -2
- package/LexicalNodeMenuPlugin.prod.js +1 -1
- package/LexicalNodeMenuPlugin.prod.mjs +1 -1
- package/LexicalReactPluginHostExtension.dev.mjs +1 -1
- package/LexicalReactPluginHostExtension.prod.mjs +1 -1
- package/LexicalSelectionAlwaysOnDisplay.d.ts +1 -1
- package/LexicalTablePlugin.d.ts +1 -7
- package/LexicalTablePlugin.dev.js +2 -5
- package/LexicalTablePlugin.dev.mjs +2 -5
- package/LexicalTablePlugin.prod.js +1 -1
- package/LexicalTablePlugin.prod.mjs +1 -1
- package/LexicalTypeaheadMenuPlugin.d.ts +1 -1
- package/LexicalTypeaheadMenuPlugin.dev.js +53 -2
- package/LexicalTypeaheadMenuPlugin.dev.mjs +54 -3
- package/LexicalTypeaheadMenuPlugin.js.flow +8 -7
- package/LexicalTypeaheadMenuPlugin.prod.js +1 -1
- package/LexicalTypeaheadMenuPlugin.prod.mjs +1 -1
- package/README.md +2 -2
- package/changes.json +1 -1
- package/package.json +50 -50
- package/shared/LexicalMenu.d.ts +5 -4
- package/useExtensionComponent.d.ts +2 -0
- package/useLexicalExtensionComponent.dev.js +8 -0
- package/useLexicalExtensionComponent.dev.mjs +8 -2
- package/useLexicalExtensionComponent.mjs +3 -1
- package/useLexicalExtensionComponent.node.mjs +3 -1
- package/useLexicalExtensionComponent.prod.js +1 -1
- package/useLexicalExtensionComponent.prod.mjs +1 -1
- package/LexicalContextMenuPlugin.d.ts +0 -42
- package/LexicalContextMenuPlugin.dev.js +0 -526
- package/LexicalContextMenuPlugin.dev.mjs +0 -511
- package/LexicalContextMenuPlugin.js +0 -11
- package/LexicalContextMenuPlugin.js.flow +0 -13
- package/LexicalContextMenuPlugin.prod.js +0 -9
- package/LexicalContextMenuPlugin.prod.mjs +0 -9
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { CommandListenerPriority, LexicalNode } from 'lexical';
|
|
9
9
|
import type { JSX } from 'react';
|
|
10
|
-
import { MenuOption, MenuRenderFn } from '@lexical/react/LexicalNodeMenuPlugin';
|
|
10
|
+
import { MenuOption, type MenuRenderFn } from '@lexical/react/LexicalNodeMenuPlugin';
|
|
11
11
|
import { LexicalCommand, LexicalEditor } from 'lexical';
|
|
12
12
|
export type EmbedMatchResult<TEmbedMatchResult = unknown> = {
|
|
13
13
|
url: string;
|
|
@@ -32,7 +32,7 @@ type LexicalAutoEmbedPluginProps<TEmbedConfig extends EmbedConfig> = {
|
|
|
32
32
|
embedConfigs: Array<TEmbedConfig>;
|
|
33
33
|
onOpenEmbedModalForConfig: (embedConfig: TEmbedConfig) => void;
|
|
34
34
|
getMenuOptions: (activeEmbedConfig: TEmbedConfig, embedFn: () => void, dismissFn: () => void) => Array<AutoEmbedOption>;
|
|
35
|
-
menuRenderFn
|
|
35
|
+
menuRenderFn?: MenuRenderFn<AutoEmbedOption>;
|
|
36
36
|
menuCommandPriority?: CommandListenerPriority;
|
|
37
37
|
};
|
|
38
38
|
export declare function LexicalAutoEmbedPlugin<TEmbedConfig extends EmbedConfig>({ embedConfigs, onOpenEmbedModalForConfig, getMenuOptions, menuRenderFn, menuCommandPriority, }: LexicalAutoEmbedPluginProps<TEmbedConfig>): JSX.Element | null;
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
import type {LexicalNode, MutationListener} from 'lexical';
|
|
11
11
|
|
|
12
12
|
import {MenuOption} from '@lexical/react/LexicalTypeaheadMenuPlugin';
|
|
13
|
+
import type {MenuRenderFn} from '@lexical/react/LexicalTypeaheadMenuPlugin';
|
|
13
14
|
import type {LexicalCommand, LexicalEditor, NodeKey, TextNode} from 'lexical';
|
|
14
15
|
import * as React from 'react';
|
|
15
16
|
import {createCommand} from 'lexical';
|
|
16
|
-
import type {MenuRenderFn} from './LexicalTypeaheadMenuPlugin';
|
|
17
17
|
|
|
18
18
|
export type EmbedMatchResult = {
|
|
19
19
|
url: string,
|
|
@@ -43,17 +43,17 @@ type LexicalAutoEmbedPluginProps<TEmbedConfig> = {
|
|
|
43
43
|
embedFn: () => void,
|
|
44
44
|
dismissFn: () => void,
|
|
45
45
|
) => Array<AutoEmbedOption>,
|
|
46
|
-
menuRenderFn
|
|
46
|
+
menuRenderFn?: MenuRenderFn<AutoEmbedOption>,
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
declare export class AutoEmbedOption extends MenuOption {
|
|
50
50
|
title: string;
|
|
51
|
-
icon
|
|
51
|
+
icon?: React.MixedElement;
|
|
52
52
|
onSelect: (targetNode: LexicalNode | null) => void;
|
|
53
53
|
constructor(
|
|
54
54
|
title: string,
|
|
55
55
|
options: {
|
|
56
|
-
icon
|
|
56
|
+
icon?: React.MixedElement,
|
|
57
57
|
onSelect: (targetNode: LexicalNode | null) => void,
|
|
58
58
|
},
|
|
59
59
|
): void;
|
|
@@ -14,12 +14,14 @@ export type SerializedDecoratorBlockNode = Spread<{
|
|
|
14
14
|
export declare class DecoratorBlockNode extends DecoratorNode<JSX.Element> {
|
|
15
15
|
__format: ElementFormatType;
|
|
16
16
|
constructor(format?: ElementFormatType, key?: NodeKey);
|
|
17
|
+
afterCloneFrom(prevNode: this): void;
|
|
17
18
|
exportJSON(): SerializedDecoratorBlockNode;
|
|
18
19
|
updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedDecoratorBlockNode>): this;
|
|
19
20
|
canIndent(): false;
|
|
20
21
|
createDOM(): HTMLElement;
|
|
21
22
|
updateDOM(): false;
|
|
22
23
|
setFormat(format: ElementFormatType): this;
|
|
24
|
+
getFormat(): ElementFormatType;
|
|
23
25
|
isInline(): false;
|
|
24
26
|
}
|
|
25
27
|
export declare function $isDecoratorBlockNode(node: LexicalNode | null | undefined): node is DecoratorBlockNode;
|
|
@@ -24,6 +24,10 @@ class DecoratorBlockNode extends lexical.DecoratorNode {
|
|
|
24
24
|
super(key);
|
|
25
25
|
this.__format = format || '';
|
|
26
26
|
}
|
|
27
|
+
afterCloneFrom(prevNode) {
|
|
28
|
+
super.afterCloneFrom(prevNode);
|
|
29
|
+
this.__format = prevNode.__format;
|
|
30
|
+
}
|
|
27
31
|
exportJSON() {
|
|
28
32
|
return {
|
|
29
33
|
...super.exportJSON(),
|
|
@@ -47,6 +51,9 @@ class DecoratorBlockNode extends lexical.DecoratorNode {
|
|
|
47
51
|
self.__format = format;
|
|
48
52
|
return self;
|
|
49
53
|
}
|
|
54
|
+
getFormat() {
|
|
55
|
+
return this.getLatest().__format;
|
|
56
|
+
}
|
|
50
57
|
isInline() {
|
|
51
58
|
return false;
|
|
52
59
|
}
|
|
@@ -22,6 +22,10 @@ class DecoratorBlockNode extends DecoratorNode {
|
|
|
22
22
|
super(key);
|
|
23
23
|
this.__format = format || '';
|
|
24
24
|
}
|
|
25
|
+
afterCloneFrom(prevNode) {
|
|
26
|
+
super.afterCloneFrom(prevNode);
|
|
27
|
+
this.__format = prevNode.__format;
|
|
28
|
+
}
|
|
25
29
|
exportJSON() {
|
|
26
30
|
return {
|
|
27
31
|
...super.exportJSON(),
|
|
@@ -45,6 +49,9 @@ class DecoratorBlockNode extends DecoratorNode {
|
|
|
45
49
|
self.__format = format;
|
|
46
50
|
return self;
|
|
47
51
|
}
|
|
52
|
+
getFormat() {
|
|
53
|
+
return this.getLatest().__format;
|
|
54
|
+
}
|
|
48
55
|
isInline() {
|
|
49
56
|
return false;
|
|
50
57
|
}
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var r=require("lexical");class t extends r.DecoratorNode{__format;constructor(r,t){super(t),this.__format=r||""}exportJSON(){return{...super.exportJSON(),format:this.__format||""}}updateFromJSON(r){return super.updateFromJSON(r).setFormat(r.format||"")}canIndent(){return!1}createDOM(){return document.createElement("div")}updateDOM(){return!1}setFormat(r){const t=this.getWritable();return t.__format=r,t}isInline(){return!1}}exports.$isDecoratorBlockNode=function(r){return r instanceof t},exports.DecoratorBlockNode=t;
|
|
9
|
+
"use strict";var r=require("lexical");class t extends r.DecoratorNode{__format;constructor(r,t){super(t),this.__format=r||""}afterCloneFrom(r){super.afterCloneFrom(r),this.__format=r.__format}exportJSON(){return{...super.exportJSON(),format:this.__format||""}}updateFromJSON(r){return super.updateFromJSON(r).setFormat(r.format||"")}canIndent(){return!1}createDOM(){return document.createElement("div")}updateDOM(){return!1}setFormat(r){const t=this.getWritable();return t.__format=r,t}getFormat(){return this.getLatest().__format}isInline(){return!1}}exports.$isDecoratorBlockNode=function(r){return r instanceof t},exports.DecoratorBlockNode=t;
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{DecoratorNode as t}from"lexical";class r extends t{__format;constructor(t,r){super(r),this.__format=t||""}exportJSON(){return{...super.exportJSON(),format:this.__format||""}}updateFromJSON(t){return super.updateFromJSON(t).setFormat(t.format||"")}canIndent(){return!1}createDOM(){return document.createElement("div")}updateDOM(){return!1}setFormat(t){const r=this.getWritable();return r.__format=t,r}isInline(){return!1}}function e(t){return t instanceof r}export{e as $isDecoratorBlockNode,r as DecoratorBlockNode};
|
|
9
|
+
import{DecoratorNode as t}from"lexical";class r extends t{__format;constructor(t,r){super(r),this.__format=t||""}afterCloneFrom(t){super.afterCloneFrom(t),this.__format=t.__format}exportJSON(){return{...super.exportJSON(),format:this.__format||""}}updateFromJSON(t){return super.updateFromJSON(t).setFormat(t.format||"")}canIndent(){return!1}createDOM(){return document.createElement("div")}updateDOM(){return!1}setFormat(t){const r=this.getWritable();return r.__format=t,r}getFormat(){return this.getLatest().__format}isInline(){return!1}}function e(t){return t instanceof r}export{e as $isDecoratorBlockNode,r as DecoratorBlockNode};
|
|
@@ -533,7 +533,7 @@ function useDraggableBlockMenu(editor, anchorElem, menuRef, targetLineRef, isEdi
|
|
|
533
533
|
if (!IS_FIREFOX || !isEditable) {
|
|
534
534
|
return;
|
|
535
535
|
}
|
|
536
|
-
return utils.mergeRegister(editor.registerRootListener(
|
|
536
|
+
return utils.mergeRegister(editor.registerRootListener(rootElement => {
|
|
537
537
|
function onBlur(event) {
|
|
538
538
|
const relatedTarget = event.relatedTarget;
|
|
539
539
|
if (relatedTarget && relatedTarget instanceof HTMLElement && isOnMenu(relatedTarget)) {
|
|
@@ -557,9 +557,7 @@ function useDraggableBlockMenu(editor, anchorElem, menuRef, targetLineRef, isEdi
|
|
|
557
557
|
}
|
|
558
558
|
if (rootElement) {
|
|
559
559
|
rootElement.addEventListener('blur', onBlur, true);
|
|
560
|
-
|
|
561
|
-
if (prevRootElement) {
|
|
562
|
-
prevRootElement.removeEventListener('blur', onBlur, true);
|
|
560
|
+
return () => rootElement.removeEventListener('blur', onBlur, true);
|
|
563
561
|
}
|
|
564
562
|
}),
|
|
565
563
|
// Intercept BLUR_COMMAND if focus is on the menu (fallback in case event propagation wasn't stopped)
|
|
@@ -531,7 +531,7 @@ function useDraggableBlockMenu(editor, anchorElem, menuRef, targetLineRef, isEdi
|
|
|
531
531
|
if (!IS_FIREFOX || !isEditable) {
|
|
532
532
|
return;
|
|
533
533
|
}
|
|
534
|
-
return mergeRegister(editor.registerRootListener(
|
|
534
|
+
return mergeRegister(editor.registerRootListener(rootElement => {
|
|
535
535
|
function onBlur(event) {
|
|
536
536
|
const relatedTarget = event.relatedTarget;
|
|
537
537
|
if (relatedTarget && relatedTarget instanceof HTMLElement && isOnMenu(relatedTarget)) {
|
|
@@ -555,9 +555,7 @@ function useDraggableBlockMenu(editor, anchorElem, menuRef, targetLineRef, isEdi
|
|
|
555
555
|
}
|
|
556
556
|
if (rootElement) {
|
|
557
557
|
rootElement.addEventListener('blur', onBlur, true);
|
|
558
|
-
|
|
559
|
-
if (prevRootElement) {
|
|
560
|
-
prevRootElement.removeEventListener('blur', onBlur, true);
|
|
558
|
+
return () => rootElement.removeEventListener('blur', onBlur, true);
|
|
561
559
|
}
|
|
562
560
|
}),
|
|
563
561
|
// Intercept BLUR_COMMAND if focus is on the menu (fallback in case event propagation wasn't stopped)
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var t=require("@lexical/react/LexicalComposerContext"),e=require("@lexical/rich-text"),n=require("@lexical/utils"),o=require("lexical"),r=require("react"),i=require("react-dom"),s=require("react/jsx-runtime");const l="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,a=l&&"documentMode"in document?document.documentMode:null,c=l&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);l&&"InputEvent"in window&&!a&&new window.InputEvent("input");class u{_x;_y;constructor(t,e){this._x=t,this._y=e}get x(){return this._x}get y(){return this._y}equals({x:t,y:e}){return this.x===t&&this.y===e}calcDeltaXTo({x:t}){return this.x-t}calcDeltaYTo({y:t}){return this.y-t}calcHorizontalDistanceTo(t){return Math.abs(this.calcDeltaXTo(t))}calcVerticalDistance(t){return Math.abs(this.calcDeltaYTo(t))}calcDistanceTo(t){return Math.sqrt(Math.pow(this.calcDeltaXTo(t),2)+Math.pow(this.calcDeltaYTo(t),2))}}class m{_left;_top;_right;_bottom;constructor(t,e,n,o){const[r,i]=e<=o?[e,o]:[o,e],[s,l]=t<=n?[t,n]:[n,t];this._top=r,this._right=l,this._left=s,this._bottom=i}get top(){return this._top}get right(){return this._right}get bottom(){return this._bottom}get left(){return this._left}get width(){return Math.abs(this._left-this._right)}get height(){return Math.abs(this._bottom-this._top)}equals({top:t,left:e,bottom:n,right:o}){return t===this._top&&n===this._bottom&&e===this._left&&o===this._right}contains(t){if(t instanceof u){const{x:e,y:n}=t,o=n<this._top,r=n>this._bottom,i=e<this._left,s=e>this._right;return{reason:{isOnBottomSide:r,isOnLeftSide:i,isOnRightSide:s,isOnTopSide:o},result:!(o||r||i||s)}}{const{top:e,left:n,bottom:o,right:r}=t;return e>=this._top&&e<=this._bottom&&o>=this._top&&o<=this._bottom&&n>=this._left&&n<=this._right&&r>=this._left&&r<=this._right}}intersectsWith(t){const{left:e,top:n,width:o,height:r}=t,{left:i,top:s,width:l,height:a}=this;return(e+o>=i+l?e+o:i+l)-(e<=i?e:i)<=o+l&&(n+r>=s+a?n+r:s+a)-(n<=s?n:s)<=r+a}generateNewRect({left:t=this.left,top:e=this.top,right:n=this.right,bottom:o=this.bottom}){return new m(t,e,n,o)}static fromLTRB(t,e,n,o){return new m(t,e,n,o)}static fromLWTH(t,e,n,o){return new m(t,n,t+e,n+o)}static fromPoints(t,e){const{y:n,x:o}=t,{y:r,x:i}=e;return m.fromLTRB(o,n,i,r)}static fromDOM(t){const{top:e,width:n,left:o,height:r}=t.getBoundingClientRect();return m.fromLWTH(o,n,e,r)}}const g="application/x-lexical-drag-block";let
|
|
9
|
+
"use strict";var t=require("@lexical/react/LexicalComposerContext"),e=require("@lexical/rich-text"),n=require("@lexical/utils"),o=require("lexical"),r=require("react"),i=require("react-dom"),s=require("react/jsx-runtime");const l="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,a=l&&"documentMode"in document?document.documentMode:null,c=l&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);l&&"InputEvent"in window&&!a&&new window.InputEvent("input");class u{_x;_y;constructor(t,e){this._x=t,this._y=e}get x(){return this._x}get y(){return this._y}equals({x:t,y:e}){return this.x===t&&this.y===e}calcDeltaXTo({x:t}){return this.x-t}calcDeltaYTo({y:t}){return this.y-t}calcHorizontalDistanceTo(t){return Math.abs(this.calcDeltaXTo(t))}calcVerticalDistance(t){return Math.abs(this.calcDeltaYTo(t))}calcDistanceTo(t){return Math.sqrt(Math.pow(this.calcDeltaXTo(t),2)+Math.pow(this.calcDeltaYTo(t),2))}}class m{_left;_top;_right;_bottom;constructor(t,e,n,o){const[r,i]=e<=o?[e,o]:[o,e],[s,l]=t<=n?[t,n]:[n,t];this._top=r,this._right=l,this._left=s,this._bottom=i}get top(){return this._top}get right(){return this._right}get bottom(){return this._bottom}get left(){return this._left}get width(){return Math.abs(this._left-this._right)}get height(){return Math.abs(this._bottom-this._top)}equals({top:t,left:e,bottom:n,right:o}){return t===this._top&&n===this._bottom&&e===this._left&&o===this._right}contains(t){if(t instanceof u){const{x:e,y:n}=t,o=n<this._top,r=n>this._bottom,i=e<this._left,s=e>this._right;return{reason:{isOnBottomSide:r,isOnLeftSide:i,isOnRightSide:s,isOnTopSide:o},result:!(o||r||i||s)}}{const{top:e,left:n,bottom:o,right:r}=t;return e>=this._top&&e<=this._bottom&&o>=this._top&&o<=this._bottom&&n>=this._left&&n<=this._right&&r>=this._left&&r<=this._right}}intersectsWith(t){const{left:e,top:n,width:o,height:r}=t,{left:i,top:s,width:l,height:a}=this;return(e+o>=i+l?e+o:i+l)-(e<=i?e:i)<=o+l&&(n+r>=s+a?n+r:s+a)-(n<=s?n:s)<=r+a}generateNewRect({left:t=this.left,top:e=this.top,right:n=this.right,bottom:o=this.bottom}){return new m(t,e,n,o)}static fromLTRB(t,e,n,o){return new m(t,e,n,o)}static fromLWTH(t,e,n,o){return new m(t,n,t+e,n+o)}static fromPoints(t,e){const{y:n,x:o}=t,{y:r,x:i}=e;return m.fromLTRB(o,n,i,r)}static fromDOM(t){const{top:e,width:n,left:o,height:r}=t.getBoundingClientRect();return m.fromLWTH(o,n,e,r)}}const g="application/x-lexical-drag-block";let f=1/0;function d(t){const e=(t,e)=>t?parseFloat(window.getComputedStyle(t)[e]):0,{marginTop:n,marginBottom:o}=window.getComputedStyle(t),r=e(t.previousElementSibling,"marginBottom"),i=e(t.nextElementSibling,"marginTop"),s=Math.max(parseFloat(n),r);return{marginBottom:Math.max(parseFloat(o),i),marginTop:s}}function h(t,e,r,i=!1){const s=t.getBoundingClientRect(),l=function(t){return t.getEditorState().read(()=>o.$getRoot().getChildrenKeys())}(e);let a=null;return e.getEditorState().read(()=>{if(i){const[t,o]=[e.getElementByKey(l[0]),e.getElementByKey(l[l.length-1])],[i,s]=[null!=t?t.getBoundingClientRect():void 0,null!=o?o.getBoundingClientRect():void 0];if(i&&s){const e=n.calculateZoomLevel(t),l=n.calculateZoomLevel(o);if(r.y/e<i.top?a=t:r.y/l>s.bottom&&(a=o),a)return}}let t=0===(o=l.length)?1/0:f>=0&&f<o?f:Math.floor(o/2);var o;let c=0;for(;t>=0&&t<l.length;){const o=l[t],i=e.getElementByKey(o);if(null===i)break;const g=n.calculateZoomLevel(i),h=new u(r.x/g,r.y/g),p=m.fromDOM(i),{marginTop:y,marginBottom:_}=d(i),v=p.generateNewRect({bottom:p.bottom+_,left:s.left,right:s.right,top:p.top-y}),{result:x,reason:{isOnTopSide:E,isOnBottomSide:M}}=v.contains(h);if(x){a=i,f=t;break}0===c&&(c=E?-1:M?1:1/0),t+=c}}),a}function p(t,l,a,u,m,f,p,y,_){const v=l.parentElement,x=r.useRef(!1),[E,M]=r.useState(null),R=r.useCallback(t=>{M(t),_&&_(t)},[_]);return r.useEffect(()=>{function e(e){const o=e.target;if(!n.isHTMLElement(o))return void R(null);if(y(o))return;const r=h(l,t,e);R(r)}function o(){R(null)}return null!=v&&(v.addEventListener("mousemove",e),v.addEventListener("mouseleave",o)),()=>{null!=v&&(v.removeEventListener("mousemove",e),v.removeEventListener("mouseleave",o))}},[v,l,t,y,R]),r.useEffect(()=>{const t=n.calculateZoomLevel(document.getElementsByClassName("ContentEditable__root")[0],!0);a.current&&function(t,e,n,o){if(!t)return void(e.style.display="none");const r=t.getBoundingClientRect(),i=window.getComputedStyle(t),s=e.getBoundingClientRect(),l=n.getBoundingClientRect();let a=parseInt(i.lineHeight,10);isNaN(a)&&(a=r.bottom-r.top);const c=(r.top+(a-(s.height||a))/2-l.top+n.scrollTop)/o;e.style.display="flex",e.style.opacity="1",e.style.transform=`translate(4px, ${c}px)`}(E,a.current,l,t)},[l,E,a]),r.useEffect(()=>{function r(o){if(!x.current)return!1;const[r]=e.eventFiles(o);if(r)return!1;const{pageY:i,target:s}=o;if(!n.isHTMLElement(s))return!1;const a=h(l,t,o,!0),c=u.current;return null!==a&&null!==c&&(function(t,e,n,o){const{top:r,height:i}=e.getBoundingClientRect(),{top:s,width:l}=o.getBoundingClientRect(),{marginTop:a,marginBottom:c}=d(e);let u=r;n>=r?u+=i+c/2:u-=a/2;const m=u-s-2+o.scrollTop;t.style.transform=`translate(24px, ${m}px)`,t.style.width=l-48+"px",t.style.opacity=".4"}(c,a,i/n.calculateZoomLevel(s),l),o.preventDefault(),!0)}return n.mergeRegister(t.registerCommand(o.DRAGOVER_COMMAND,t=>r(t),o.COMMAND_PRIORITY_LOW),t.registerCommand(o.DROP_COMMAND,r=>function(r){if(!x.current)return!1;const[i]=e.eventFiles(r);if(i)return!1;const{target:s,dataTransfer:a,pageY:u}=r,m=null!=a?a.getData(g):"",f=o.$getNodeByKey(m);if(!f)return!1;if(!n.isHTMLElement(s))return!1;const d=h(l,t,r,!0);if(!d)return!1;const p=o.$getNearestNodeFromDOMNode(d);if(!p)return!1;if(p===f)return c&&t.focus(),!0;const y=d.getBoundingClientRect().top;return u/n.calculateZoomLevel(s)>=y?p.insertAfter(f):p.insertBefore(f),R(null),c&&o.$onUpdate(()=>{t.focus()}),!0}(r),o.COMMAND_PRIORITY_HIGH))},[l,t,u,R]),r.useEffect(()=>{if(c&&m)return n.mergeRegister(t.registerRootListener(e=>{function n(n){const r=n.relatedTarget;r&&r instanceof HTMLElement&&y(r)&&(e&&(e.focus({preventScroll:!0}),t.update(()=>{const t=o.$getSelection();null===t||t.dirty||(t.dirty=!0)})),n.stopImmediatePropagation())}if(e)return e.addEventListener("blur",n,!0),()=>e.removeEventListener("blur",n,!0)}),t.registerCommand(o.BLUR_COMMAND,()=>{const e=t.getRootElement(),n=document.activeElement;return!!(e&&n&&n instanceof HTMLElement&&y(n))&&(e.focus({preventScroll:!0}),t.update(()=>{const t=o.$getSelection();null===t||t.dirty||(t.dirty=!0)}),!0)},o.COMMAND_PRIORITY_HIGH))},[t,m,y]),i.createPortal(s.jsxs(s.Fragment,{children:[s.jsx("div",{draggable:!0,onDragStart:function(e){const n=e.dataTransfer;if(!n||!E)return;!function(t,e){const{transform:n}=e.style;e.style.transform="translateZ(0)",t.setDragImage(e,0,0),setTimeout(()=>{e.style.transform=n})}(n,E);let r="";if(t.update(()=>{const t=o.$getNearestNodeFromDOMNode(E);t&&(r=t.getKey())}),x.current=!0,n.setData(g,r),c){const e=t.getRootElement();null!==e&&document.activeElement!==e&&(e.focus({preventScroll:!0}),t.update(()=>{const t=o.$getSelection();null===t||t.dirty||(t.dirty=!0)}))}},onDragEnd:function(){var e;x.current=!1,(e=u.current)&&(e.style.opacity="0",e.style.transform="translate(-10000px, -10000px)"),c&&t.focus()},children:m&&f}),p]}),l)}exports.DraggableBlockPlugin_EXPERIMENTAL=function({anchorElem:e=document.body,menuRef:n,targetLineRef:o,menuComponent:r,targetLineComponent:i,isOnMenu:s,onElementChanged:l}){const[a]=t.useLexicalComposerContext();return p(a,e,n,o,a._editable,r,i,s,l)};
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{eventFiles as e}from"@lexical/rich-text";import{calculateZoomLevel as n,mergeRegister as o,isHTMLElement as r}from"@lexical/utils";import{DRAGOVER_COMMAND as i,COMMAND_PRIORITY_LOW as s,DROP_COMMAND as l,COMMAND_PRIORITY_HIGH as a,BLUR_COMMAND as c,$getSelection as u,$getNodeByKey as m,$getNearestNodeFromDOMNode as g,$onUpdate as h,$getRoot as f}from"lexical";import{useRef as d,useState as p,useCallback as y,useEffect as _}from"react";import{createPortal as x}from"react-dom";import{jsxs as b,Fragment as v,jsx as w}from"react/jsx-runtime";const E="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,T=E&&"documentMode"in document?document.documentMode:null,B=E&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);E&&"InputEvent"in window&&!T&&new window.InputEvent("input");class C{_x;_y;constructor(t,e){this._x=t,this._y=e}get x(){return this._x}get y(){return this._y}equals({x:t,y:e}){return this.x===t&&this.y===e}calcDeltaXTo({x:t}){return this.x-t}calcDeltaYTo({y:t}){return this.y-t}calcHorizontalDistanceTo(t){return Math.abs(this.calcDeltaXTo(t))}calcVerticalDistance(t){return Math.abs(this.calcDeltaYTo(t))}calcDistanceTo(t){return Math.sqrt(Math.pow(this.calcDeltaXTo(t),2)+Math.pow(this.calcDeltaYTo(t),2))}}class R{_left;_top;_right;_bottom;constructor(t,e,n,o){const[r,i]=e<=o?[e,o]:[o,e],[s,l]=t<=n?[t,n]:[n,t];this._top=r,this._right=l,this._left=s,this._bottom=i}get top(){return this._top}get right(){return this._right}get bottom(){return this._bottom}get left(){return this._left}get width(){return Math.abs(this._left-this._right)}get height(){return Math.abs(this._bottom-this._top)}equals({top:t,left:e,bottom:n,right:o}){return t===this._top&&n===this._bottom&&e===this._left&&o===this._right}contains(t){if(t instanceof C){const{x:e,y:n}=t,o=n<this._top,r=n>this._bottom,i=e<this._left,s=e>this._right;return{reason:{isOnBottomSide:r,isOnLeftSide:i,isOnRightSide:s,isOnTopSide:o},result:!(o||r||i||s)}}{const{top:e,left:n,bottom:o,right:r}=t;return e>=this._top&&e<=this._bottom&&o>=this._top&&o<=this._bottom&&n>=this._left&&n<=this._right&&r>=this._left&&r<=this._right}}intersectsWith(t){const{left:e,top:n,width:o,height:r}=t,{left:i,top:s,width:l,height:a}=this;return(e+o>=i+l?e+o:i+l)-(e<=i?e:i)<=o+l&&(n+r>=s+a?n+r:s+a)-(n<=s?n:s)<=r+a}generateNewRect({left:t=this.left,top:e=this.top,right:n=this.right,bottom:o=this.bottom}){return new R(t,e,n,o)}static fromLTRB(t,e,n,o){return new R(t,e,n,o)}static fromLWTH(t,e,n,o){return new R(t,n,t+e,n+o)}static fromPoints(t,e){const{y:n,x:o}=t,{y:r,x:i}=e;return R.fromLTRB(o,n,i,r)}static fromDOM(t){const{top:e,width:n,left:o,height:r}=t.getBoundingClientRect();return R.fromLWTH(o,n,e,r)}}const S="application/x-lexical-drag-block";let D=1/0;function L(t){const e=(t,e)=>t?parseFloat(window.getComputedStyle(t)[e]):0,{marginTop:n,marginBottom:o}=window.getComputedStyle(t),r=e(t.previousElementSibling,"marginBottom"),i=e(t.nextElementSibling,"marginTop"),s=Math.max(parseFloat(n),r);return{marginBottom:Math.max(parseFloat(o),i),marginTop:s}}function M(t,e,o,r=!1){const i=t.getBoundingClientRect(),s=function(t){return t.getEditorState().read(()=>f().getChildrenKeys())}(e);let l=null;return e.getEditorState().read(()=>{if(r){const[t,r]=[e.getElementByKey(s[0]),e.getElementByKey(s[s.length-1])],[i,a]=[null!=t?t.getBoundingClientRect():void 0,null!=r?r.getBoundingClientRect():void 0];if(i&&a){const e=n(t),s=n(r);if(o.y/e<i.top?l=t:o.y/s>a.bottom&&(l=r),l)return}}let t=0===(a=s.length)?1/0:D>=0&&D<a?D:Math.floor(a/2);var a;let c=0;for(;t>=0&&t<s.length;){const r=s[t],a=e.getElementByKey(r);if(null===a)break;const u=n(a),m=new C(o.x/u,o.y/u),g=R.fromDOM(a),{marginTop:h,marginBottom:f}=L(a),d=g.generateNewRect({bottom:g.bottom+f,left:i.left,right:i.right,top:g.top-h}),{result:p,reason:{isOnTopSide:y,isOnBottomSide:_}}=d.contains(m);if(p){l=a,D=t;break}0===c&&(c=y?-1:_?1:1/0),t+=c}}),l}function O(t,f,E,T,C,R,D,O,H){const I=f.parentElement,K=d(!1),[N,Y]=p(null),k=y(t=>{Y(t),H&&H(t)},[H]);return _(()=>{function e(e){const n=e.target;if(!r(n))return void k(null);if(O(n))return;const o=M(f,t,e);k(o)}function n(){k(null)}return null!=I&&(I.addEventListener("mousemove",e),I.addEventListener("mouseleave",n)),()=>{null!=I&&(I.removeEventListener("mousemove",e),I.removeEventListener("mouseleave",n))}},[I,f,t,O,k]),_(()=>{const t=n(document.getElementsByClassName("ContentEditable__root")[0],!0);E.current&&function(t,e,n,o){if(!t)return void(e.style.display="none");const r=t.getBoundingClientRect(),i=window.getComputedStyle(t),s=e.getBoundingClientRect(),l=n.getBoundingClientRect();let a=parseInt(i.lineHeight,10);isNaN(a)&&(a=r.bottom-r.top);const c=(r.top+(a-(s.height||a))/2-l.top+n.scrollTop)/o;e.style.display="flex",e.style.opacity="1",e.style.transform=`translate(4px, ${c}px)`}(N,E.current,f,t)},[f,N,E]),_(()=>{function c(o){if(!K.current)return!1;const[i]=e(o);if(i)return!1;const{pageY:s,target:l}=o;if(!r(l))return!1;const a=M(f,t,o,!0),c=T.current;return null!==a&&null!==c&&(function(t,e,n,o){const{top:r,height:i}=e.getBoundingClientRect(),{top:s,width:l}=o.getBoundingClientRect(),{marginTop:a,marginBottom:c}=L(e);let u=r;n>=r?u+=i+c/2:u-=a/2;const m=u-s-2+o.scrollTop;t.style.transform=`translate(24px, ${m}px)`,t.style.width=l-48+"px",t.style.opacity=".4"}(c,a,s/n(l),f),o.preventDefault(),!0)}return o(t.registerCommand(i,t=>c(t),s),t.registerCommand(l,o=>function(o){if(!K.current)return!1;const[i]=e(o);if(i)return!1;const{target:s,dataTransfer:l,pageY:a}=o,c=null!=l?l.getData(S):"",u=m(c);if(!u)return!1;if(!r(s))return!1;const d=M(f,t,o,!0);if(!d)return!1;const p=g(d);if(!p)return!1;if(p===u)return B&&t.focus(),!0;const y=d.getBoundingClientRect().top;return a/n(s)>=y?p.insertAfter(u):p.insertBefore(u),k(null),B&&h(()=>{t.focus()}),!0}(o),a))},[f,t,T,k]),_(()=>{if(B&&C)return o(t.registerRootListener(
|
|
9
|
+
import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{eventFiles as e}from"@lexical/rich-text";import{calculateZoomLevel as n,mergeRegister as o,isHTMLElement as r}from"@lexical/utils";import{DRAGOVER_COMMAND as i,COMMAND_PRIORITY_LOW as s,DROP_COMMAND as l,COMMAND_PRIORITY_HIGH as a,BLUR_COMMAND as c,$getSelection as u,$getNodeByKey as m,$getNearestNodeFromDOMNode as g,$onUpdate as h,$getRoot as f}from"lexical";import{useRef as d,useState as p,useCallback as y,useEffect as _}from"react";import{createPortal as x}from"react-dom";import{jsxs as b,Fragment as v,jsx as w}from"react/jsx-runtime";const E="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,T=E&&"documentMode"in document?document.documentMode:null,B=E&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);E&&"InputEvent"in window&&!T&&new window.InputEvent("input");class C{_x;_y;constructor(t,e){this._x=t,this._y=e}get x(){return this._x}get y(){return this._y}equals({x:t,y:e}){return this.x===t&&this.y===e}calcDeltaXTo({x:t}){return this.x-t}calcDeltaYTo({y:t}){return this.y-t}calcHorizontalDistanceTo(t){return Math.abs(this.calcDeltaXTo(t))}calcVerticalDistance(t){return Math.abs(this.calcDeltaYTo(t))}calcDistanceTo(t){return Math.sqrt(Math.pow(this.calcDeltaXTo(t),2)+Math.pow(this.calcDeltaYTo(t),2))}}class R{_left;_top;_right;_bottom;constructor(t,e,n,o){const[r,i]=e<=o?[e,o]:[o,e],[s,l]=t<=n?[t,n]:[n,t];this._top=r,this._right=l,this._left=s,this._bottom=i}get top(){return this._top}get right(){return this._right}get bottom(){return this._bottom}get left(){return this._left}get width(){return Math.abs(this._left-this._right)}get height(){return Math.abs(this._bottom-this._top)}equals({top:t,left:e,bottom:n,right:o}){return t===this._top&&n===this._bottom&&e===this._left&&o===this._right}contains(t){if(t instanceof C){const{x:e,y:n}=t,o=n<this._top,r=n>this._bottom,i=e<this._left,s=e>this._right;return{reason:{isOnBottomSide:r,isOnLeftSide:i,isOnRightSide:s,isOnTopSide:o},result:!(o||r||i||s)}}{const{top:e,left:n,bottom:o,right:r}=t;return e>=this._top&&e<=this._bottom&&o>=this._top&&o<=this._bottom&&n>=this._left&&n<=this._right&&r>=this._left&&r<=this._right}}intersectsWith(t){const{left:e,top:n,width:o,height:r}=t,{left:i,top:s,width:l,height:a}=this;return(e+o>=i+l?e+o:i+l)-(e<=i?e:i)<=o+l&&(n+r>=s+a?n+r:s+a)-(n<=s?n:s)<=r+a}generateNewRect({left:t=this.left,top:e=this.top,right:n=this.right,bottom:o=this.bottom}){return new R(t,e,n,o)}static fromLTRB(t,e,n,o){return new R(t,e,n,o)}static fromLWTH(t,e,n,o){return new R(t,n,t+e,n+o)}static fromPoints(t,e){const{y:n,x:o}=t,{y:r,x:i}=e;return R.fromLTRB(o,n,i,r)}static fromDOM(t){const{top:e,width:n,left:o,height:r}=t.getBoundingClientRect();return R.fromLWTH(o,n,e,r)}}const S="application/x-lexical-drag-block";let D=1/0;function L(t){const e=(t,e)=>t?parseFloat(window.getComputedStyle(t)[e]):0,{marginTop:n,marginBottom:o}=window.getComputedStyle(t),r=e(t.previousElementSibling,"marginBottom"),i=e(t.nextElementSibling,"marginTop"),s=Math.max(parseFloat(n),r);return{marginBottom:Math.max(parseFloat(o),i),marginTop:s}}function M(t,e,o,r=!1){const i=t.getBoundingClientRect(),s=function(t){return t.getEditorState().read(()=>f().getChildrenKeys())}(e);let l=null;return e.getEditorState().read(()=>{if(r){const[t,r]=[e.getElementByKey(s[0]),e.getElementByKey(s[s.length-1])],[i,a]=[null!=t?t.getBoundingClientRect():void 0,null!=r?r.getBoundingClientRect():void 0];if(i&&a){const e=n(t),s=n(r);if(o.y/e<i.top?l=t:o.y/s>a.bottom&&(l=r),l)return}}let t=0===(a=s.length)?1/0:D>=0&&D<a?D:Math.floor(a/2);var a;let c=0;for(;t>=0&&t<s.length;){const r=s[t],a=e.getElementByKey(r);if(null===a)break;const u=n(a),m=new C(o.x/u,o.y/u),g=R.fromDOM(a),{marginTop:h,marginBottom:f}=L(a),d=g.generateNewRect({bottom:g.bottom+f,left:i.left,right:i.right,top:g.top-h}),{result:p,reason:{isOnTopSide:y,isOnBottomSide:_}}=d.contains(m);if(p){l=a,D=t;break}0===c&&(c=y?-1:_?1:1/0),t+=c}}),l}function O(t,f,E,T,C,R,D,O,H){const I=f.parentElement,K=d(!1),[N,Y]=p(null),k=y(t=>{Y(t),H&&H(t)},[H]);return _(()=>{function e(e){const n=e.target;if(!r(n))return void k(null);if(O(n))return;const o=M(f,t,e);k(o)}function n(){k(null)}return null!=I&&(I.addEventListener("mousemove",e),I.addEventListener("mouseleave",n)),()=>{null!=I&&(I.removeEventListener("mousemove",e),I.removeEventListener("mouseleave",n))}},[I,f,t,O,k]),_(()=>{const t=n(document.getElementsByClassName("ContentEditable__root")[0],!0);E.current&&function(t,e,n,o){if(!t)return void(e.style.display="none");const r=t.getBoundingClientRect(),i=window.getComputedStyle(t),s=e.getBoundingClientRect(),l=n.getBoundingClientRect();let a=parseInt(i.lineHeight,10);isNaN(a)&&(a=r.bottom-r.top);const c=(r.top+(a-(s.height||a))/2-l.top+n.scrollTop)/o;e.style.display="flex",e.style.opacity="1",e.style.transform=`translate(4px, ${c}px)`}(N,E.current,f,t)},[f,N,E]),_(()=>{function c(o){if(!K.current)return!1;const[i]=e(o);if(i)return!1;const{pageY:s,target:l}=o;if(!r(l))return!1;const a=M(f,t,o,!0),c=T.current;return null!==a&&null!==c&&(function(t,e,n,o){const{top:r,height:i}=e.getBoundingClientRect(),{top:s,width:l}=o.getBoundingClientRect(),{marginTop:a,marginBottom:c}=L(e);let u=r;n>=r?u+=i+c/2:u-=a/2;const m=u-s-2+o.scrollTop;t.style.transform=`translate(24px, ${m}px)`,t.style.width=l-48+"px",t.style.opacity=".4"}(c,a,s/n(l),f),o.preventDefault(),!0)}return o(t.registerCommand(i,t=>c(t),s),t.registerCommand(l,o=>function(o){if(!K.current)return!1;const[i]=e(o);if(i)return!1;const{target:s,dataTransfer:l,pageY:a}=o,c=null!=l?l.getData(S):"",u=m(c);if(!u)return!1;if(!r(s))return!1;const d=M(f,t,o,!0);if(!d)return!1;const p=g(d);if(!p)return!1;if(p===u)return B&&t.focus(),!0;const y=d.getBoundingClientRect().top;return a/n(s)>=y?p.insertAfter(u):p.insertBefore(u),k(null),B&&h(()=>{t.focus()}),!0}(o),a))},[f,t,T,k]),_(()=>{if(B&&C)return o(t.registerRootListener(e=>{function n(n){const o=n.relatedTarget;o&&o instanceof HTMLElement&&O(o)&&(e&&(e.focus({preventScroll:!0}),t.update(()=>{const t=u();null===t||t.dirty||(t.dirty=!0)})),n.stopImmediatePropagation())}if(e)return e.addEventListener("blur",n,!0),()=>e.removeEventListener("blur",n,!0)}),t.registerCommand(c,()=>{const e=t.getRootElement(),n=document.activeElement;return!!(e&&n&&n instanceof HTMLElement&&O(n))&&(e.focus({preventScroll:!0}),t.update(()=>{const t=u();null===t||t.dirty||(t.dirty=!0)}),!0)},a))},[t,C,O]),x(b(v,{children:[w("div",{draggable:!0,onDragStart:function(e){const n=e.dataTransfer;if(!n||!N)return;!function(t,e){const{transform:n}=e.style;e.style.transform="translateZ(0)",t.setDragImage(e,0,0),setTimeout(()=>{e.style.transform=n})}(n,N);let o="";if(t.update(()=>{const t=g(N);t&&(o=t.getKey())}),K.current=!0,n.setData(S,o),B){const e=t.getRootElement();null!==e&&document.activeElement!==e&&(e.focus({preventScroll:!0}),t.update(()=>{const t=u();null===t||t.dirty||(t.dirty=!0)}))}},onDragEnd:function(){var e;K.current=!1,(e=T.current)&&(e.style.opacity="0",e.style.transform="translate(-10000px, -10000px)"),B&&t.focus()},children:C&&R}),D]}),f)}function H({anchorElem:e=document.body,menuRef:n,targetLineRef:o,menuComponent:r,targetLineComponent:i,isOnMenu:s,onElementChanged:l}){const[a]=t();return O(a,e,n,o,a._editable,r,i,s,l)}export{H as DraggableBlockPlugin_EXPERIMENTAL};
|
|
@@ -8,7 +8,7 @@ export interface LexicalExtensionComposerProps {
|
|
|
8
8
|
/**
|
|
9
9
|
* Any children will have access to useLexicalComposerContext (e.g. for React plug-ins or UX)
|
|
10
10
|
*/
|
|
11
|
-
children
|
|
11
|
+
children?: React.ReactNode;
|
|
12
12
|
/**
|
|
13
13
|
* Override the default ContentEditable that is rendered as the first child of the
|
|
14
14
|
* composer. If this is null, then it is your responsibility to render a ContentEditable
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LexicalEditorWithDispose } from 'lexical';
|
|
2
|
+
export interface LexicalExtensionEditorComposerProps {
|
|
3
|
+
/**
|
|
4
|
+
* Your root extension, typically defined with {@link defineExtension}
|
|
5
|
+
*/
|
|
6
|
+
initialEditor: LexicalEditorWithDispose;
|
|
7
|
+
/**
|
|
8
|
+
* Any children will have access to useLexicalComposerContext (e.g. for React plug-ins or UX)
|
|
9
|
+
*/
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The equivalent of LexicalComposer for an editor that was already built for
|
|
14
|
+
* extensions, typically used with nested editors.
|
|
15
|
+
*
|
|
16
|
+
* Make sure that your initialEditor argument is stable (e.g. using module scope or useMemo) so
|
|
17
|
+
* that you are not re-creating the editor on every render! The editor should be built with
|
|
18
|
+
* ReactProviderExtension and ReactExtension dependencies.
|
|
19
|
+
*/
|
|
20
|
+
export declare function LexicalExtensionEditorComposer({ initialEditor: editor, children, }: LexicalExtensionEditorComposerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
var extension = require('@lexical/extension');
|
|
12
|
+
var ReactExtension = require('@lexical/react/ReactExtension');
|
|
13
|
+
var react = require('react');
|
|
14
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the MIT license found in the
|
|
20
|
+
* LICENSE file in the root directory of this source tree.
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* The equivalent of LexicalComposer for an editor that was already built for
|
|
25
|
+
* extensions, typically used with nested editors.
|
|
26
|
+
*
|
|
27
|
+
* Make sure that your initialEditor argument is stable (e.g. using module scope or useMemo) so
|
|
28
|
+
* that you are not re-creating the editor on every render! The editor should be built with
|
|
29
|
+
* ReactProviderExtension and ReactExtension dependencies.
|
|
30
|
+
*/
|
|
31
|
+
function LexicalExtensionEditorComposer({
|
|
32
|
+
initialEditor: editor,
|
|
33
|
+
children
|
|
34
|
+
}) {
|
|
35
|
+
react.useEffect(() => {
|
|
36
|
+
// Strict mode workaround
|
|
37
|
+
let didMount = false;
|
|
38
|
+
queueMicrotask(() => {
|
|
39
|
+
didMount = true;
|
|
40
|
+
});
|
|
41
|
+
return () => {
|
|
42
|
+
if (didMount) {
|
|
43
|
+
editor.dispose();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}, [editor]);
|
|
47
|
+
const {
|
|
48
|
+
Component
|
|
49
|
+
} = extension.getExtensionDependencyFromEditor(editor, ReactExtension.ReactExtension).output;
|
|
50
|
+
return /*#__PURE__*/jsxRuntime.jsx(Component, {
|
|
51
|
+
children: children
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
exports.LexicalExtensionEditorComposer = LexicalExtensionEditorComposer;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { getExtensionDependencyFromEditor } from '@lexical/extension';
|
|
10
|
+
import { ReactExtension } from '@lexical/react/ReactExtension';
|
|
11
|
+
import { useEffect } from 'react';
|
|
12
|
+
import { jsx } from 'react/jsx-runtime';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
16
|
+
*
|
|
17
|
+
* This source code is licensed under the MIT license found in the
|
|
18
|
+
* LICENSE file in the root directory of this source tree.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* The equivalent of LexicalComposer for an editor that was already built for
|
|
23
|
+
* extensions, typically used with nested editors.
|
|
24
|
+
*
|
|
25
|
+
* Make sure that your initialEditor argument is stable (e.g. using module scope or useMemo) so
|
|
26
|
+
* that you are not re-creating the editor on every render! The editor should be built with
|
|
27
|
+
* ReactProviderExtension and ReactExtension dependencies.
|
|
28
|
+
*/
|
|
29
|
+
function LexicalExtensionEditorComposer({
|
|
30
|
+
initialEditor: editor,
|
|
31
|
+
children
|
|
32
|
+
}) {
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
// Strict mode workaround
|
|
35
|
+
let didMount = false;
|
|
36
|
+
queueMicrotask(() => {
|
|
37
|
+
didMount = true;
|
|
38
|
+
});
|
|
39
|
+
return () => {
|
|
40
|
+
if (didMount) {
|
|
41
|
+
editor.dispose();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}, [editor]);
|
|
45
|
+
const {
|
|
46
|
+
Component
|
|
47
|
+
} = getExtensionDependencyFromEditor(editor, ReactExtension).output;
|
|
48
|
+
return /*#__PURE__*/jsx(Component, {
|
|
49
|
+
children: children
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { LexicalExtensionEditorComposer };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict'
|
|
10
|
+
const LexicalExtensionEditorComposer = process.env.NODE_ENV !== 'production' ? require('./LexicalExtensionEditorComposer.dev.js') : require('./LexicalExtensionEditorComposer.prod.js');
|
|
11
|
+
module.exports = LexicalExtensionEditorComposer;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* LexicalExtensionEditorComposer
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
import type {
|
|
16
|
+
LexicalEditorWithDispose,
|
|
17
|
+
EditorThemeClasses,
|
|
18
|
+
LexicalNode,
|
|
19
|
+
LexicalNodeReplacement,
|
|
20
|
+
} from 'lexical';
|
|
21
|
+
|
|
22
|
+
export type LexicalNestedComposerProps = {
|
|
23
|
+
children?: React.Node;
|
|
24
|
+
initialEditor: LexicalEditorWithDispose;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare export function LexicalExtensionEditorComposer(props: LexicalNestedComposerProps): React.Node;
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import * as modDev from './
|
|
10
|
-
import * as modProd from './
|
|
9
|
+
import * as modDev from './LexicalExtensionEditorComposer.dev.mjs';
|
|
10
|
+
import * as modProd from './LexicalExtensionEditorComposer.prod.mjs';
|
|
11
11
|
const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
|
|
12
|
-
export const
|
|
13
|
-
export const MenuOption = mod.MenuOption;
|
|
12
|
+
export const LexicalExtensionEditorComposer = mod.LexicalExtensionEditorComposer;
|
|
@@ -6,6 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
const mod = await (process.env.NODE_ENV !== 'production' ? import('./
|
|
10
|
-
export const
|
|
11
|
-
export const MenuOption = mod.MenuOption;
|
|
9
|
+
const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalExtensionEditorComposer.dev.mjs') : import('./LexicalExtensionEditorComposer.prod.mjs'));
|
|
10
|
+
export const LexicalExtensionEditorComposer = mod.LexicalExtensionEditorComposer;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
"use strict";var e=require("@lexical/extension"),t=require("@lexical/react/ReactExtension"),r=require("react"),i=require("react/jsx-runtime");exports.LexicalExtensionEditorComposer=function({initialEditor:n,children:o}){r.useEffect(()=>{let e=!1;return queueMicrotask(()=>{e=!0}),()=>{e&&n.dispose()}},[n]);const{Component:c}=e.getExtensionDependencyFromEditor(n,t.ReactExtension).output;return i.jsx(c,{children:o})};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import{getExtensionDependencyFromEditor as t}from"@lexical/extension";import{ReactExtension as r}from"@lexical/react/ReactExtension";import{useEffect as e}from"react";import{jsx as o}from"react/jsx-runtime";function i({initialEditor:i,children:n}){e(()=>{let t=!1;return queueMicrotask(()=>{t=!0}),()=>{t&&i.dispose()}},[i]);const{Component:c}=t(i,r).output;return o(c,{children:n})}export{i as LexicalExtensionEditorComposer};
|
|
@@ -22,6 +22,10 @@ var react = require('react');
|
|
|
22
22
|
*
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated A pure Lexical implementation is available in `@lexical/extension` as HorizontalRuleExtension
|
|
28
|
+
*/
|
|
25
29
|
function HorizontalRulePlugin() {
|
|
26
30
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
27
31
|
react.useEffect(() => {
|
|
@@ -20,6 +20,10 @@ import { useEffect } from 'react';
|
|
|
20
20
|
*
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated A pure Lexical implementation is available in `@lexical/extension` as HorizontalRuleExtension
|
|
26
|
+
*/
|
|
23
27
|
function HorizontalRulePlugin() {
|
|
24
28
|
const [editor] = useLexicalComposerContext();
|
|
25
29
|
useEffect(() => {
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
11
|
+
var extension = require('@lexical/extension');
|
|
11
12
|
var markdown = require('@lexical/markdown');
|
|
12
13
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
13
|
-
var LexicalHorizontalRuleNode = require('@lexical/react/LexicalHorizontalRuleNode');
|
|
14
14
|
var react = require('react');
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -22,13 +22,13 @@ var react = require('react');
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
const HR = {
|
|
25
|
-
dependencies: [
|
|
25
|
+
dependencies: [extension.HorizontalRuleNode],
|
|
26
26
|
export: node => {
|
|
27
|
-
return
|
|
27
|
+
return extension.$isHorizontalRuleNode(node) ? '***' : null;
|
|
28
28
|
},
|
|
29
29
|
regExp: /^(---|\*\*\*|___)\s?$/,
|
|
30
30
|
replace: (parentNode, _1, _2, isImport) => {
|
|
31
|
-
const line =
|
|
31
|
+
const line = extension.$createHorizontalRuleNode();
|
|
32
32
|
|
|
33
33
|
// TODO: Get rid of isImport flag
|
|
34
34
|
if (isImport || parentNode.getNextSibling() != null) {
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { HorizontalRuleNode, $createHorizontalRuleNode, $isHorizontalRuleNode } from '@lexical/extension';
|
|
9
10
|
import { TRANSFORMERS, registerMarkdownShortcuts } from '@lexical/markdown';
|
|
10
11
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
11
|
-
import { HorizontalRuleNode, $createHorizontalRuleNode, $isHorizontalRuleNode } from '@lexical/react/LexicalHorizontalRuleNode';
|
|
12
12
|
import { useEffect } from 'react';
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/
|
|
9
|
+
"use strict";var e=require("@lexical/extension"),r=require("@lexical/markdown"),t=require("@lexical/react/LexicalComposerContext"),o=require("react");const l=[{dependencies:[e.HorizontalRuleNode],export:r=>e.$isHorizontalRuleNode(r)?"***":null,regExp:/^(---|\*\*\*|___)\s?$/,replace:(r,t,o,l)=>{const n=e.$createHorizontalRuleNode();l||null!=r.getNextSibling()?r.replace(n):r.insertBefore(n),n.selectNext()},type:"element"},...r.TRANSFORMERS];exports.DEFAULT_TRANSFORMERS=l,exports.MarkdownShortcutPlugin=function({transformers:e=l}){const[n]=t.useLexicalComposerContext();return o.useEffect(()=>r.registerMarkdownShortcuts(n,e),[n,e]),null};
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{
|
|
9
|
+
import{HorizontalRuleNode as e,$createHorizontalRuleNode as r,$isHorizontalRuleNode as t}from"@lexical/extension";import{TRANSFORMERS as o,registerMarkdownShortcuts as n}from"@lexical/markdown";import{useLexicalComposerContext as l}from"@lexical/react/LexicalComposerContext";import{useEffect as c}from"react";const i=[{dependencies:[e],export:e=>t(e)?"***":null,regExp:/^(---|\*\*\*|___)\s?$/,replace:(e,t,o,n)=>{const l=r();n||null!=e.getNextSibling()?e.replace(l):e.insertBefore(l),l.selectNext()},type:"element"},...o];function m({transformers:e=i}){const[r]=l();return c(()=>n(r,e),[r,e]),null}export{i as DEFAULT_TRANSFORMERS,m as MarkdownShortcutPlugin};
|
|
@@ -193,12 +193,10 @@ const NodeContextMenuPlugin = /*#__PURE__*/react.forwardRef(({
|
|
|
193
193
|
setRenderItems(renderableItems);
|
|
194
194
|
setIsOpen(true);
|
|
195
195
|
}
|
|
196
|
-
return editor.registerRootListener(
|
|
197
|
-
if (prevRootElement !== null) {
|
|
198
|
-
prevRootElement.removeEventListener('contextmenu', onContextMenu);
|
|
199
|
-
}
|
|
196
|
+
return editor.registerRootListener(rootElement => {
|
|
200
197
|
if (rootElement !== null) {
|
|
201
198
|
rootElement.addEventListener('contextmenu', onContextMenu);
|
|
199
|
+
return () => rootElement.removeEventListener('contextmenu', onContextMenu);
|
|
202
200
|
}
|
|
203
201
|
});
|
|
204
202
|
}, [items, itemClassName, separatorClassName, refs, editor]);
|
|
@@ -191,12 +191,10 @@ const NodeContextMenuPlugin = /*#__PURE__*/forwardRef(({
|
|
|
191
191
|
setRenderItems(renderableItems);
|
|
192
192
|
setIsOpen(true);
|
|
193
193
|
}
|
|
194
|
-
return editor.registerRootListener(
|
|
195
|
-
if (prevRootElement !== null) {
|
|
196
|
-
prevRootElement.removeEventListener('contextmenu', onContextMenu);
|
|
197
|
-
}
|
|
194
|
+
return editor.registerRootListener(rootElement => {
|
|
198
195
|
if (rootElement !== null) {
|
|
199
196
|
rootElement.addEventListener('contextmenu', onContextMenu);
|
|
197
|
+
return () => rootElement.removeEventListener('contextmenu', onContextMenu);
|
|
200
198
|
}
|
|
201
199
|
});
|
|
202
200
|
}, [items, itemClassName, separatorClassName, refs, editor]);
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@floating-ui/react"),t=require("@lexical/react/LexicalComposerContext"),s=require("lexical"),n=require("react"),i=require("react/jsx-runtime");class a{key;ref;constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}const
|
|
9
|
+
"use strict";var e=require("@floating-ui/react"),t=require("@lexical/react/LexicalComposerContext"),s=require("lexical"),n=require("react"),i=require("react/jsx-runtime");class a{key;ref;constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}const o=n.forwardRef(({className:e,disabled:t,...s},n)=>i.jsx("hr",{className:e})),r=n.forwardRef(({className:e,label:t,disabled:s,icon:n,...a},o)=>i.jsxs("button",{...a,className:e,ref:o,role:"menuitem",disabled:s,children:[n,t]})),l=n.forwardRef(({items:a,className:l,itemClassName:c,separatorClassName:u},d)=>{const[m]=t.useLexicalComposerContext(),[p,h]=n.useState(null),[f,x]=n.useState(!1),y=n.useRef([]),g=n.useRef([]),{refs:N,floatingStyles:b,context:k}=e.useFloating({middleware:[e.offset({alignmentAxis:4,mainAxis:5}),e.flip({fallbackPlacements:["left-start"]}),e.shift({padding:10})],onOpenChange:x,open:f,placement:"right-start",strategy:"fixed",whileElementsMounted:e.autoUpdate}),w=e.useRole(k,{role:"menu"}),C=e.useDismiss(k),$=e.useListNavigation(k,{activeIndex:p,listRef:y,onNavigate:h}),O=e.useTypeahead(k,{activeIndex:p,enabled:f,listRef:g,onMatch:h}),{getFloatingProps:R,getItemProps:v}=e.useInteractions([w,C,$,O]),[S,E]=n.useState([]);return n.useEffect(()=>{function e(e){e.preventDefault(),N.setPositionReference({getBoundingClientRect:()=>({bottom:e.clientY,height:0,left:e.clientX,right:e.clientX,top:e.clientY,width:0,x:e.clientX,y:e.clientY})});let t=[];a&&m.read(()=>{const n=s.$getNearestNodeFromDOMNode(e.target);n&&(t=a.filter(e=>!e.$showOn||e.$showOn(n)))});const n=t.map((e,t)=>"separator"===e.type?{className:u,key:e.key+"-"+t,type:e.type}:{className:c,disabled:e.disabled,icon:e.icon,key:e.key,label:e.title,onClick:()=>m.update(()=>e.$onSelect()),title:e.title,type:e.type});g.current=n.map(e=>e.key),E(n),x(!0)}return m.registerRootListener(t=>{if(null!==t)return t.addEventListener("contextmenu",e),()=>t.removeEventListener("contextmenu",e)})},[a,c,u,N,m]),i.jsx(e.FloatingPortal,{children:f&&i.jsx(e.FloatingOverlay,{lockScroll:!0,children:i.jsx(e.FloatingFocusManager,{context:k,initialFocus:N.floating,children:i.jsx("div",{className:l,ref:N.setFloating,style:b,...R(),children:S.map((e,t)=>"item"===e.type?n.createElement(r,{...v({...e,onClick(){e.onClick(),x(!1)},onMouseUp(){e.onClick(),x(!1)},ref(e){y.current[t]=e},tabIndex:p===t?0:-1}),key:e.key}):"separator"===e.type?n.createElement(o,{...v({...e,ref(e){y.current[t]=e},tabIndex:p===t?0:-1}),key:e.key}):void 0)})})})})});exports.NodeContextMenuOption=class extends a{type;title;icon;disabled;$onSelect;$showOn;constructor(e,t){super(e),this.type="item",this.title=e,this.disabled=t.disabled??!1,this.icon=t.icon??null,this.$onSelect=t.$onSelect,t.$showOn&&(this.$showOn=t.$showOn)}},exports.NodeContextMenuPlugin=l,exports.NodeContextMenuSeparator=class extends a{type;$showOn;constructor(e){super("_separator"),this.type="separator",e&&e.$showOn&&(this.$showOn=e.$showOn)}};
|