@lexical/react 0.13.1 → 0.14.1
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.dev.esm.js +131 -0
- package/LexicalAutoEmbedPlugin.esm.js +13 -0
- package/LexicalAutoEmbedPlugin.js +1 -1
- package/LexicalAutoEmbedPlugin.prod.esm.js +7 -0
- package/LexicalAutoFocusPlugin.dev.esm.js +42 -0
- package/LexicalAutoFocusPlugin.esm.js +10 -0
- package/LexicalAutoFocusPlugin.js +1 -1
- package/LexicalAutoFocusPlugin.prod.esm.js +7 -0
- package/LexicalAutoLinkPlugin.dev.esm.js +312 -0
- package/LexicalAutoLinkPlugin.dev.js +3 -1
- package/LexicalAutoLinkPlugin.esm.js +11 -0
- package/LexicalAutoLinkPlugin.js +1 -1
- package/LexicalAutoLinkPlugin.prod.esm.js +7 -0
- package/LexicalBlockWithAlignableContents.dev.esm.js +86 -0
- package/LexicalBlockWithAlignableContents.dev.js +1 -0
- package/LexicalBlockWithAlignableContents.esm.js +10 -0
- package/LexicalBlockWithAlignableContents.js +1 -1
- package/LexicalBlockWithAlignableContents.prod.esm.js +7 -0
- package/LexicalBlockWithAlignableContents.prod.js +1 -1
- package/LexicalCharacterLimitPlugin.d.ts +4 -1
- package/LexicalCharacterLimitPlugin.dev.esm.js +272 -0
- package/LexicalCharacterLimitPlugin.dev.js +12 -4
- package/LexicalCharacterLimitPlugin.esm.js +10 -0
- package/LexicalCharacterLimitPlugin.js +1 -1
- package/LexicalCharacterLimitPlugin.prod.esm.js +7 -0
- package/LexicalCharacterLimitPlugin.prod.js +9 -9
- package/LexicalCheckListPlugin.dev.esm.js +203 -0
- package/LexicalCheckListPlugin.esm.js +10 -0
- package/LexicalCheckListPlugin.js +1 -1
- package/LexicalCheckListPlugin.prod.esm.js +7 -0
- package/LexicalClearEditorPlugin.dev.esm.js +64 -0
- package/LexicalClearEditorPlugin.esm.js +10 -0
- package/LexicalClearEditorPlugin.js +1 -1
- package/LexicalClearEditorPlugin.prod.esm.js +7 -0
- package/LexicalClickableLinkPlugin.dev.esm.js +95 -0
- package/LexicalClickableLinkPlugin.esm.js +10 -0
- package/LexicalClickableLinkPlugin.js +1 -1
- package/LexicalClickableLinkPlugin.prod.esm.js +7 -0
- package/LexicalCollaborationContext.dev.esm.js +36 -0
- package/LexicalCollaborationContext.esm.js +11 -0
- package/LexicalCollaborationContext.js +1 -1
- package/LexicalCollaborationContext.prod.esm.js +7 -0
- package/LexicalCollaborationPlugin.dev.esm.js +308 -0
- package/LexicalCollaborationPlugin.esm.js +10 -0
- package/LexicalCollaborationPlugin.js +1 -1
- package/LexicalCollaborationPlugin.prod.esm.js +7 -0
- package/LexicalComposer.dev.esm.js +129 -0
- package/LexicalComposer.esm.js +10 -0
- package/LexicalComposer.js +1 -1
- package/LexicalComposer.prod.esm.js +7 -0
- package/LexicalComposerContext.dev.esm.js +42 -0
- package/LexicalComposerContext.esm.js +12 -0
- package/LexicalComposerContext.js +1 -1
- package/LexicalComposerContext.prod.esm.js +7 -0
- package/LexicalContentEditable.dev.esm.js +107 -0
- package/LexicalContentEditable.dev.js +5 -1
- package/LexicalContentEditable.esm.js +10 -0
- package/LexicalContentEditable.js +1 -1
- package/LexicalContentEditable.prod.esm.js +7 -0
- package/LexicalContentEditable.prod.js +3 -3
- package/LexicalContextMenuPlugin.dev.esm.js +455 -0
- package/LexicalContextMenuPlugin.dev.js +3 -1
- package/LexicalContextMenuPlugin.esm.js +11 -0
- package/LexicalContextMenuPlugin.js +1 -1
- package/LexicalContextMenuPlugin.prod.esm.js +7 -0
- package/LexicalDecoratorBlockNode.dev.esm.js +46 -0
- package/LexicalDecoratorBlockNode.esm.js +11 -0
- package/LexicalDecoratorBlockNode.js +1 -1
- package/LexicalDecoratorBlockNode.prod.esm.js +7 -0
- package/LexicalEditorRefPlugin.dev.esm.js +40 -0
- package/LexicalEditorRefPlugin.dev.js +10 -5
- package/LexicalEditorRefPlugin.esm.js +10 -0
- package/LexicalEditorRefPlugin.js +1 -1
- package/LexicalEditorRefPlugin.prod.esm.js +7 -0
- package/LexicalEditorRefPlugin.prod.js +1 -1
- package/LexicalErrorBoundary.dev.esm.js +157 -0
- package/LexicalErrorBoundary.esm.js +10 -0
- package/LexicalErrorBoundary.js +1 -1
- package/LexicalErrorBoundary.prod.esm.js +7 -0
- package/LexicalHashtagPlugin.dev.esm.js +163 -0
- package/LexicalHashtagPlugin.esm.js +10 -0
- package/LexicalHashtagPlugin.js +1 -1
- package/LexicalHashtagPlugin.prod.esm.js +7 -0
- package/LexicalHistoryPlugin.dev.esm.js +41 -0
- package/LexicalHistoryPlugin.esm.js +11 -0
- package/LexicalHistoryPlugin.js +1 -1
- package/LexicalHistoryPlugin.prod.esm.js +7 -0
- package/LexicalHorizontalRuleNode.dev.esm.js +118 -0
- package/LexicalHorizontalRuleNode.dev.js +1 -0
- package/LexicalHorizontalRuleNode.esm.js +13 -0
- package/LexicalHorizontalRuleNode.js +1 -1
- package/LexicalHorizontalRuleNode.prod.esm.js +7 -0
- package/LexicalHorizontalRuleNode.prod.js +1 -1
- package/LexicalHorizontalRulePlugin.dev.esm.js +39 -0
- package/LexicalHorizontalRulePlugin.esm.js +10 -0
- package/LexicalHorizontalRulePlugin.js +1 -1
- package/LexicalHorizontalRulePlugin.prod.esm.js +7 -0
- package/LexicalLinkPlugin.dev.esm.js +79 -0
- package/LexicalLinkPlugin.dev.js +6 -2
- package/LexicalLinkPlugin.esm.js +10 -0
- package/LexicalLinkPlugin.js +1 -1
- package/LexicalLinkPlugin.prod.esm.js +7 -0
- package/LexicalLinkPlugin.prod.js +1 -1
- package/LexicalListPlugin.dev.esm.js +59 -0
- package/LexicalListPlugin.esm.js +10 -0
- package/LexicalListPlugin.js +1 -1
- package/LexicalListPlugin.prod.esm.js +7 -0
- package/LexicalMarkdownShortcutPlugin.dev.esm.js +49 -0
- package/LexicalMarkdownShortcutPlugin.esm.js +11 -0
- package/LexicalMarkdownShortcutPlugin.js +1 -1
- package/LexicalMarkdownShortcutPlugin.prod.esm.js +7 -0
- package/LexicalNestedComposer.dev.esm.js +105 -0
- package/LexicalNestedComposer.esm.js +10 -0
- package/LexicalNestedComposer.js +1 -1
- package/LexicalNestedComposer.prod.esm.js +7 -0
- package/LexicalNodeEventPlugin.dev.esm.js +56 -0
- package/LexicalNodeEventPlugin.esm.js +10 -0
- package/LexicalNodeEventPlugin.js +1 -1
- package/LexicalNodeEventPlugin.prod.esm.js +7 -0
- package/LexicalNodeMenuPlugin.dev.esm.js +466 -0
- package/LexicalNodeMenuPlugin.dev.js +3 -1
- package/LexicalNodeMenuPlugin.esm.js +11 -0
- package/LexicalNodeMenuPlugin.js +1 -1
- package/LexicalNodeMenuPlugin.prod.esm.js +7 -0
- package/LexicalOnChangePlugin.dev.esm.js +62 -0
- package/LexicalOnChangePlugin.esm.js +10 -0
- package/LexicalOnChangePlugin.js +1 -1
- package/LexicalOnChangePlugin.prod.esm.js +7 -0
- package/LexicalPlainTextPlugin.dev.esm.js +161 -0
- package/LexicalPlainTextPlugin.esm.js +10 -0
- package/LexicalPlainTextPlugin.js +1 -1
- package/LexicalPlainTextPlugin.prod.esm.js +7 -0
- package/LexicalRichTextPlugin.dev.esm.js +161 -0
- package/LexicalRichTextPlugin.esm.js +10 -0
- package/LexicalRichTextPlugin.js +1 -1
- package/LexicalRichTextPlugin.prod.esm.js +7 -0
- package/LexicalTabIndentationPlugin.dev.esm.js +76 -0
- package/LexicalTabIndentationPlugin.esm.js +11 -0
- package/LexicalTabIndentationPlugin.js +1 -1
- package/LexicalTabIndentationPlugin.prod.esm.js +7 -0
- package/LexicalTableOfContents.dev.esm.js +157 -0
- package/LexicalTableOfContents.esm.js +10 -0
- package/LexicalTableOfContents.js +1 -1
- package/LexicalTableOfContents.prod.esm.js +7 -0
- package/LexicalTablePlugin.dev.esm.js +163 -0
- package/LexicalTablePlugin.esm.js +10 -0
- package/LexicalTablePlugin.js +1 -1
- package/LexicalTablePlugin.prod.esm.js +7 -0
- package/LexicalTreeView.dev.esm.js +483 -0
- package/LexicalTreeView.dev.js +3 -1
- package/LexicalTreeView.esm.js +10 -0
- package/LexicalTreeView.js +1 -1
- package/LexicalTreeView.prod.esm.js +7 -0
- package/LexicalTypeaheadMenuPlugin.dev.esm.js +569 -0
- package/LexicalTypeaheadMenuPlugin.dev.js +3 -1
- package/LexicalTypeaheadMenuPlugin.esm.js +16 -0
- package/LexicalTypeaheadMenuPlugin.js +1 -1
- package/LexicalTypeaheadMenuPlugin.prod.esm.js +7 -0
- package/package.json +583 -20
- package/useLexicalEditable.dev.esm.js +82 -0
- package/useLexicalEditable.esm.js +10 -0
- package/useLexicalEditable.js +1 -1
- package/useLexicalEditable.prod.esm.js +7 -0
- package/useLexicalIsTextContentEmpty.dev.esm.js +51 -0
- package/useLexicalIsTextContentEmpty.esm.js +10 -0
- package/useLexicalIsTextContentEmpty.js +1 -1
- package/useLexicalIsTextContentEmpty.prod.esm.js +7 -0
- package/useLexicalNodeSelection.dev.esm.js +69 -0
- package/useLexicalNodeSelection.esm.js +10 -0
- package/useLexicalNodeSelection.js +1 -1
- package/useLexicalNodeSelection.prod.esm.js +7 -0
- package/useLexicalSubscription.dev.esm.js +63 -0
- package/useLexicalSubscription.esm.js +10 -0
- package/useLexicalSubscription.js +1 -1
- package/useLexicalSubscription.prod.esm.js +7 -0
- package/useLexicalTextEntity.dev.esm.js +26 -0
- package/useLexicalTextEntity.esm.js +10 -0
- package/useLexicalTextEntity.js +1 -1
- package/useLexicalTextEntity.prod.esm.js +7 -0
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
8
|
+
import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection';
|
|
9
|
+
import { mergeRegister } from '@lexical/utils';
|
|
10
|
+
import { createCommand, DecoratorNode, $applyNodeReplacement, $isNodeSelection, $getSelection, $getNodeByKey, CLICK_COMMAND, COMMAND_PRIORITY_LOW, KEY_DELETE_COMMAND, KEY_BACKSPACE_COMMAND } from 'lexical';
|
|
11
|
+
import * as React from 'react';
|
|
12
|
+
import { useCallback, useEffect } from 'react';
|
|
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
|
+
const INSERT_HORIZONTAL_RULE_COMMAND = createCommand('INSERT_HORIZONTAL_RULE_COMMAND');
|
|
22
|
+
function HorizontalRuleComponent({
|
|
23
|
+
nodeKey
|
|
24
|
+
}) {
|
|
25
|
+
const [editor] = useLexicalComposerContext();
|
|
26
|
+
const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
|
|
27
|
+
const onDelete = useCallback(event => {
|
|
28
|
+
if (isSelected && $isNodeSelection($getSelection())) {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
const node = $getNodeByKey(nodeKey);
|
|
31
|
+
if ($isHorizontalRuleNode(node)) {
|
|
32
|
+
node.remove();
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}, [isSelected, nodeKey]);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
return mergeRegister(editor.registerCommand(CLICK_COMMAND, event => {
|
|
40
|
+
const hrElem = editor.getElementByKey(nodeKey);
|
|
41
|
+
if (event.target === hrElem) {
|
|
42
|
+
if (!event.shiftKey) {
|
|
43
|
+
clearSelection();
|
|
44
|
+
}
|
|
45
|
+
setSelected(!isSelected);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_DELETE_COMMAND, onDelete, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_BACKSPACE_COMMAND, onDelete, COMMAND_PRIORITY_LOW));
|
|
50
|
+
}, [clearSelection, editor, isSelected, nodeKey, onDelete, setSelected]);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const hrElem = editor.getElementByKey(nodeKey);
|
|
53
|
+
if (hrElem !== null) {
|
|
54
|
+
hrElem.className = isSelected ? 'selected' : '';
|
|
55
|
+
}
|
|
56
|
+
}, [editor, isSelected, nodeKey]);
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
class HorizontalRuleNode extends DecoratorNode {
|
|
60
|
+
static getType() {
|
|
61
|
+
return 'horizontalrule';
|
|
62
|
+
}
|
|
63
|
+
static clone(node) {
|
|
64
|
+
return new HorizontalRuleNode(node.__key);
|
|
65
|
+
}
|
|
66
|
+
static importJSON(serializedNode) {
|
|
67
|
+
return $createHorizontalRuleNode();
|
|
68
|
+
}
|
|
69
|
+
static importDOM() {
|
|
70
|
+
return {
|
|
71
|
+
hr: () => ({
|
|
72
|
+
conversion: convertHorizontalRuleElement,
|
|
73
|
+
priority: 0
|
|
74
|
+
})
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
exportJSON() {
|
|
78
|
+
return {
|
|
79
|
+
type: 'horizontalrule',
|
|
80
|
+
version: 1
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
exportDOM() {
|
|
84
|
+
return {
|
|
85
|
+
element: document.createElement('hr')
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
createDOM() {
|
|
89
|
+
return document.createElement('hr');
|
|
90
|
+
}
|
|
91
|
+
getTextContent() {
|
|
92
|
+
return '\n';
|
|
93
|
+
}
|
|
94
|
+
isInline() {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
updateDOM() {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
decorate() {
|
|
101
|
+
return /*#__PURE__*/React.createElement(HorizontalRuleComponent, {
|
|
102
|
+
nodeKey: this.__key
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function convertHorizontalRuleElement() {
|
|
107
|
+
return {
|
|
108
|
+
node: $createHorizontalRuleNode()
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function $createHorizontalRuleNode() {
|
|
112
|
+
return $applyNodeReplacement(new HorizontalRuleNode());
|
|
113
|
+
}
|
|
114
|
+
function $isHorizontalRuleNode(node) {
|
|
115
|
+
return node instanceof HorizontalRuleNode;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { $createHorizontalRuleNode, $isHorizontalRuleNode, HorizontalRuleNode, INSERT_HORIZONTAL_RULE_COMMAND };
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
import * as modDev from './LexicalHorizontalRuleNode.dev.esm.js';
|
|
8
|
+
import * as modProd from './LexicalHorizontalRuleNode.prod.esm.js';
|
|
9
|
+
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
10
|
+
export const $createHorizontalRuleNode = mod.$createHorizontalRuleNode;
|
|
11
|
+
export const $isHorizontalRuleNode = mod.$isHorizontalRuleNode;
|
|
12
|
+
export const HorizontalRuleNode = mod.HorizontalRuleNode;
|
|
13
|
+
export const INSERT_HORIZONTAL_RULE_COMMAND = mod.INSERT_HORIZONTAL_RULE_COMMAND;
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const LexicalHorizontalRuleNode = process.env.NODE_ENV === 'development' ? require('./LexicalHorizontalRuleNode.dev.js') : require('./LexicalHorizontalRuleNode.prod.js')
|
|
8
|
+
const LexicalHorizontalRuleNode = process.env.NODE_ENV === 'development' ? require('./LexicalHorizontalRuleNode.dev.js') : require('./LexicalHorizontalRuleNode.prod.js');
|
|
9
9
|
module.exports = LexicalHorizontalRuleNode;
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLexicalNodeSelection as t}from"@lexical/react/useLexicalNodeSelection";import{mergeRegister as r}from"@lexical/utils";import{createCommand as n,DecoratorNode as o,$applyNodeReplacement as i,$isNodeSelection as c,$getSelection as a,$getNodeByKey as l,CLICK_COMMAND as u,COMMAND_PRIORITY_LOW as m,KEY_DELETE_COMMAND as s,KEY_BACKSPACE_COMMAND as p}from"lexical";import*as f from"react";import{useCallback as d,useEffect as x}from"react";const y=n("INSERT_HORIZONTAL_RULE_COMMAND");function O({nodeKey:n}){const[o]=e(),[i,f,y]=t(n),O=d((e=>{if(i&&c(a())){e.preventDefault();const t=l(n);if(E(t))return t.remove(),!0}return!1}),[i,n]);return x((()=>r(o.registerCommand(u,(e=>{const t=o.getElementByKey(n);return e.target===t&&(e.shiftKey||y(),f(!i),!0)}),m),o.registerCommand(s,O,m),o.registerCommand(p,O,m))),[y,o,i,n,O,f]),x((()=>{const e=o.getElementByKey(n);null!==e&&(e.className=i?"selected":"")}),[o,i,n]),null}class g extends o{static getType(){return"horizontalrule"}static clone(e){return new g(e.__key)}static importJSON(e){return C()}static importDOM(){return{hr:()=>({conversion:h,priority:0})}}exportJSON(){return{type:"horizontalrule",version:1}}exportDOM(){return{element:document.createElement("hr")}}createDOM(){return document.createElement("hr")}getTextContent(){return"\n"}isInline(){return!1}updateDOM(){return!1}decorate(){return f.createElement(O,{nodeKey:this.__key})}}function h(){return{node:C()}}function C(){return i(new g)}function E(e){return e instanceof g}export{C as $createHorizontalRuleNode,E as $isHorizontalRuleNode,g as HorizontalRuleNode,y as INSERT_HORIZONTAL_RULE_COMMAND};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var a=require("@lexical/react/LexicalComposerContext"),f=require("@lexical/react/useLexicalNodeSelection"),g=require("@lexical/utils"),k=require("lexical"),n=require("react");let p=k.createCommand("INSERT_HORIZONTAL_RULE_COMMAND");
|
|
8
|
-
function q({nodeKey:b}){let [d]=a.useLexicalComposerContext(),[e,l,m]=f.useLexicalNodeSelection(b),h=n.useCallback(c=>
|
|
8
|
+
function q({nodeKey:b}){let [d]=a.useLexicalComposerContext(),[e,l,m]=f.useLexicalNodeSelection(b),h=n.useCallback(c=>e&&k.$isNodeSelection(k.$getSelection())&&(c.preventDefault(),c=k.$getNodeByKey(b),r(c))?(c.remove(),!0):!1,[e,b]);n.useEffect(()=>g.mergeRegister(d.registerCommand(k.CLICK_COMMAND,c=>{let v=d.getElementByKey(b);return c.target===v?(c.shiftKey||m(),l(!e),!0):!1},k.COMMAND_PRIORITY_LOW),d.registerCommand(k.KEY_DELETE_COMMAND,h,k.COMMAND_PRIORITY_LOW),d.registerCommand(k.KEY_BACKSPACE_COMMAND,
|
|
9
9
|
h,k.COMMAND_PRIORITY_LOW)),[m,d,e,b,h,l]);n.useEffect(()=>{let c=d.getElementByKey(b);null!==c&&(c.className=e?"selected":"")},[d,e,b]);return null}
|
|
10
10
|
class t extends k.DecoratorNode{static getType(){return"horizontalrule"}static clone(b){return new t(b.__key)}static importJSON(){return u()}static importDOM(){return{hr:()=>({conversion:w,priority:0})}}exportJSON(){return{type:"horizontalrule",version:1}}exportDOM(){return{element:document.createElement("hr")}}createDOM(){return document.createElement("hr")}getTextContent(){return"\n"}isInline(){return!1}updateDOM(){return!1}decorate(){return n.createElement(q,{nodeKey:this.__key})}}
|
|
11
11
|
function w(){return{node:u()}}function u(){return k.$applyNodeReplacement(new t)}function r(b){return b instanceof t}exports.$createHorizontalRuleNode=u;exports.$isHorizontalRuleNode=r;exports.HorizontalRuleNode=t;exports.INSERT_HORIZONTAL_RULE_COMMAND=p
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
8
|
+
import { INSERT_HORIZONTAL_RULE_COMMAND, $createHorizontalRuleNode } from '@lexical/react/LexicalHorizontalRuleNode';
|
|
9
|
+
import { $insertNodeToNearestRoot } from '@lexical/utils';
|
|
10
|
+
import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR } from 'lexical';
|
|
11
|
+
import { useEffect } from 'react';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
|
+
*
|
|
16
|
+
* This source code is licensed under the MIT license found in the
|
|
17
|
+
* LICENSE file in the root directory of this source tree.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
function HorizontalRulePlugin() {
|
|
21
|
+
const [editor] = useLexicalComposerContext();
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
return editor.registerCommand(INSERT_HORIZONTAL_RULE_COMMAND, type => {
|
|
24
|
+
const selection = $getSelection();
|
|
25
|
+
if (!$isRangeSelection(selection)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const focusNode = selection.focus.getNode();
|
|
29
|
+
if (focusNode !== null) {
|
|
30
|
+
const horizontalRuleNode = $createHorizontalRuleNode();
|
|
31
|
+
$insertNodeToNearestRoot(horizontalRuleNode);
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}, COMMAND_PRIORITY_EDITOR);
|
|
35
|
+
}, [editor]);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { HorizontalRulePlugin };
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
import * as modDev from './LexicalHorizontalRulePlugin.dev.esm.js';
|
|
8
|
+
import * as modProd from './LexicalHorizontalRulePlugin.prod.esm.js';
|
|
9
|
+
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
10
|
+
export const HorizontalRulePlugin = mod.HorizontalRulePlugin;
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const LexicalHorizontalRulePlugin = process.env.NODE_ENV === 'development' ? require('./LexicalHorizontalRulePlugin.dev.js') : require('./LexicalHorizontalRulePlugin.prod.js')
|
|
8
|
+
const LexicalHorizontalRulePlugin = process.env.NODE_ENV === 'development' ? require('./LexicalHorizontalRulePlugin.dev.js') : require('./LexicalHorizontalRulePlugin.prod.js');
|
|
9
9
|
module.exports = LexicalHorizontalRulePlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
import{useLexicalComposerContext as o}from"@lexical/react/LexicalComposerContext";import{INSERT_HORIZONTAL_RULE_COMMAND as r,$createHorizontalRuleNode as t}from"@lexical/react/LexicalHorizontalRuleNode";import{$insertNodeToNearestRoot as e}from"@lexical/utils";import{$getSelection as i,$isRangeSelection as l,COMMAND_PRIORITY_EDITOR as c}from"lexical";import{useEffect as m}from"react";function n(){const[n]=o();return m((()=>n.registerCommand(r,(o=>{const r=i();if(!l(r))return!1;if(null!==r.focus.getNode()){const o=t();e(o)}return!0}),c)),[n]),null}export{n as HorizontalRulePlugin};
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
import { LinkNode, TOGGLE_LINK_COMMAND, toggleLink } from '@lexical/link';
|
|
8
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
9
|
+
import { mergeRegister, objectKlassEquals } from '@lexical/utils';
|
|
10
|
+
import { COMMAND_PRIORITY_LOW, PASTE_COMMAND, $getSelection, $isRangeSelection, $isElementNode } from 'lexical';
|
|
11
|
+
import { useEffect } from 'react';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
|
+
*
|
|
16
|
+
* This source code is licensed under the MIT license found in the
|
|
17
|
+
* LICENSE file in the root directory of this source tree.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
function LinkPlugin({
|
|
21
|
+
validateUrl
|
|
22
|
+
}) {
|
|
23
|
+
const [editor] = useLexicalComposerContext();
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!editor.hasNodes([LinkNode])) {
|
|
26
|
+
throw new Error('LinkPlugin: LinkNode not registered on editor');
|
|
27
|
+
}
|
|
28
|
+
return mergeRegister(editor.registerCommand(TOGGLE_LINK_COMMAND, payload => {
|
|
29
|
+
if (payload === null) {
|
|
30
|
+
toggleLink(payload);
|
|
31
|
+
return true;
|
|
32
|
+
} else if (typeof payload === 'string') {
|
|
33
|
+
if (validateUrl === undefined || validateUrl(payload)) {
|
|
34
|
+
toggleLink(payload);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
} else {
|
|
39
|
+
const {
|
|
40
|
+
url,
|
|
41
|
+
target,
|
|
42
|
+
rel,
|
|
43
|
+
title
|
|
44
|
+
} = payload;
|
|
45
|
+
toggleLink(url, {
|
|
46
|
+
rel,
|
|
47
|
+
target,
|
|
48
|
+
title
|
|
49
|
+
});
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}, COMMAND_PRIORITY_LOW), validateUrl !== undefined ? editor.registerCommand(PASTE_COMMAND, event => {
|
|
53
|
+
const selection = $getSelection();
|
|
54
|
+
if (!$isRangeSelection(selection) || selection.isCollapsed() || !objectKlassEquals(event, ClipboardEvent)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const clipboardEvent = event;
|
|
58
|
+
if (clipboardEvent.clipboardData === null) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const clipboardText = clipboardEvent.clipboardData.getData('text');
|
|
62
|
+
if (!validateUrl(clipboardText)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
// If we select nodes that are elements then avoid applying the link.
|
|
66
|
+
if (!selection.getNodes().some(node => $isElementNode(node))) {
|
|
67
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, clipboardText);
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}, COMMAND_PRIORITY_LOW) : () => {
|
|
73
|
+
// Don't paste arbritrary text as a link when there's no validate function
|
|
74
|
+
});
|
|
75
|
+
}, [editor, validateUrl]);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { LinkPlugin };
|
package/LexicalLinkPlugin.dev.js
CHANGED
|
@@ -53,10 +53,14 @@ function LinkPlugin({
|
|
|
53
53
|
}
|
|
54
54
|
}, lexical.COMMAND_PRIORITY_LOW), validateUrl !== undefined ? editor.registerCommand(lexical.PASTE_COMMAND, event => {
|
|
55
55
|
const selection = lexical.$getSelection();
|
|
56
|
-
if (!lexical.$isRangeSelection(selection) || selection.isCollapsed() || !(event
|
|
56
|
+
if (!lexical.$isRangeSelection(selection) || selection.isCollapsed() || !utils.objectKlassEquals(event, ClipboardEvent)) {
|
|
57
57
|
return false;
|
|
58
58
|
}
|
|
59
|
-
const
|
|
59
|
+
const clipboardEvent = event;
|
|
60
|
+
if (clipboardEvent.clipboardData === null) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const clipboardText = clipboardEvent.clipboardData.getData('text');
|
|
60
64
|
if (!validateUrl(clipboardText)) {
|
|
61
65
|
return false;
|
|
62
66
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
import * as modDev from './LexicalLinkPlugin.dev.esm.js';
|
|
8
|
+
import * as modProd from './LexicalLinkPlugin.prod.esm.js';
|
|
9
|
+
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
10
|
+
export const LinkPlugin = mod.LinkPlugin;
|
package/LexicalLinkPlugin.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const LexicalLinkPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalLinkPlugin.dev.js') : require('./LexicalLinkPlugin.prod.js')
|
|
8
|
+
const LexicalLinkPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalLinkPlugin.dev.js') : require('./LexicalLinkPlugin.prod.js');
|
|
9
9
|
module.exports = LexicalLinkPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
import{LinkNode as t,TOGGLE_LINK_COMMAND as r,toggleLink as e}from"@lexical/link";import{useLexicalComposerContext as o}from"@lexical/react/LexicalComposerContext";import{mergeRegister as i,objectKlassEquals as n}from"@lexical/utils";import{COMMAND_PRIORITY_LOW as l,PASTE_COMMAND as a,$getSelection as m,$isRangeSelection as s,$isElementNode as c}from"lexical";import{useEffect as d}from"react";function u({validateUrl:u}){const[p]=o();return d((()=>{if(!p.hasNodes([t]))throw new Error("LinkPlugin: LinkNode not registered on editor");return i(p.registerCommand(r,(t=>{if(null===t)return e(t),!0;if("string"==typeof t)return!(void 0!==u&&!u(t))&&(e(t),!0);{const{url:r,target:o,rel:i,title:n}=t;return e(r,{rel:i,target:o,title:n}),!0}}),l),void 0!==u?p.registerCommand(a,(t=>{const e=m();if(!s(e)||e.isCollapsed()||!n(t,ClipboardEvent))return!1;const o=t;if(null===o.clipboardData)return!1;const i=o.clipboardData.getData("text");return!!u(i)&&(!e.getNodes().some((t=>c(t)))&&(p.dispatchCommand(r,i),t.preventDefault(),!0))}),l):()=>{})}),[p,u]),null}export{u as LinkPlugin};
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var b=require("@lexical/link"),c=require("@lexical/react/LexicalComposerContext"),k=require("@lexical/utils"),l=require("lexical"),m=require("react");
|
|
8
8
|
exports.LinkPlugin=function({validateUrl:d}){let [e]=c.useLexicalComposerContext();m.useEffect(()=>{if(!e.hasNodes([b.LinkNode]))throw Error("LinkPlugin: LinkNode not registered on editor");return k.mergeRegister(e.registerCommand(b.TOGGLE_LINK_COMMAND,a=>{if(null===a)return b.toggleLink(a),!0;if("string"===typeof a)return void 0===d||d(a)?(b.toggleLink(a),!0):!1;let {url:f,target:g,rel:h,title:n}=a;b.toggleLink(f,{rel:h,target:g,title:n});return!0},l.COMMAND_PRIORITY_LOW),void 0!==d?e.registerCommand(l.PASTE_COMMAND,
|
|
9
|
-
a=>{let f=l.$getSelection();if(!l.$isRangeSelection(f)||f.isCollapsed()||!(a
|
|
9
|
+
a=>{let f=l.$getSelection();if(!l.$isRangeSelection(f)||f.isCollapsed()||!k.objectKlassEquals(a,ClipboardEvent)||null===a.clipboardData)return!1;let g=a.clipboardData.getData("text");return d(g)?f.getNodes().some(h=>l.$isElementNode(h))?!1:(e.dispatchCommand(b.TOGGLE_LINK_COMMAND,g),a.preventDefault(),!0):!1},l.COMMAND_PRIORITY_LOW):()=>{})},[e,d]);return null}
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
import { INSERT_ORDERED_LIST_COMMAND, insertList, INSERT_UNORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND, removeList, $handleListInsertParagraph, ListNode, ListItemNode } from '@lexical/list';
|
|
8
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
9
|
+
import { useEffect } from 'react';
|
|
10
|
+
import { mergeRegister } from '@lexical/utils';
|
|
11
|
+
import { COMMAND_PRIORITY_LOW, INSERT_PARAGRAPH_COMMAND } from 'lexical';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
|
+
*
|
|
16
|
+
* This source code is licensed under the MIT license found in the
|
|
17
|
+
* LICENSE file in the root directory of this source tree.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
function useList(editor) {
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
return mergeRegister(editor.registerCommand(INSERT_ORDERED_LIST_COMMAND, () => {
|
|
23
|
+
insertList(editor, 'number');
|
|
24
|
+
return true;
|
|
25
|
+
}, COMMAND_PRIORITY_LOW), editor.registerCommand(INSERT_UNORDERED_LIST_COMMAND, () => {
|
|
26
|
+
insertList(editor, 'bullet');
|
|
27
|
+
return true;
|
|
28
|
+
}, COMMAND_PRIORITY_LOW), editor.registerCommand(REMOVE_LIST_COMMAND, () => {
|
|
29
|
+
removeList(editor);
|
|
30
|
+
return true;
|
|
31
|
+
}, COMMAND_PRIORITY_LOW), editor.registerCommand(INSERT_PARAGRAPH_COMMAND, () => {
|
|
32
|
+
const hasHandledInsertParagraph = $handleListInsertParagraph();
|
|
33
|
+
if (hasHandledInsertParagraph) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}, COMMAND_PRIORITY_LOW));
|
|
38
|
+
}, [editor]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
43
|
+
*
|
|
44
|
+
* This source code is licensed under the MIT license found in the
|
|
45
|
+
* LICENSE file in the root directory of this source tree.
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
function ListPlugin() {
|
|
49
|
+
const [editor] = useLexicalComposerContext();
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!editor.hasNodes([ListNode, ListItemNode])) {
|
|
52
|
+
throw new Error('ListPlugin: ListNode and/or ListItemNode not registered on editor');
|
|
53
|
+
}
|
|
54
|
+
}, [editor]);
|
|
55
|
+
useList(editor);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { ListPlugin };
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
import * as modDev from './LexicalListPlugin.dev.esm.js';
|
|
8
|
+
import * as modProd from './LexicalListPlugin.prod.esm.js';
|
|
9
|
+
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
10
|
+
export const ListPlugin = mod.ListPlugin;
|
package/LexicalListPlugin.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const LexicalListPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalListPlugin.dev.js') : require('./LexicalListPlugin.prod.js')
|
|
8
|
+
const LexicalListPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalListPlugin.dev.js') : require('./LexicalListPlugin.prod.js');
|
|
9
9
|
module.exports = LexicalListPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
import{INSERT_ORDERED_LIST_COMMAND as r,insertList as e,INSERT_UNORDERED_LIST_COMMAND as o,REMOVE_LIST_COMMAND as t,removeList as i,$handleListInsertParagraph as m,ListNode as n,ListItemNode as l}from"@lexical/list";import{useLexicalComposerContext as s}from"@lexical/react/LexicalComposerContext";import{useEffect as a}from"react";import{mergeRegister as c}from"@lexical/utils";import{COMMAND_PRIORITY_LOW as d,INSERT_PARAGRAPH_COMMAND as f}from"lexical";function u(){const[u]=s();return a((()=>{if(!u.hasNodes([n,l]))throw new Error("ListPlugin: ListNode and/or ListItemNode not registered on editor")}),[u]),function(n){a((()=>c(n.registerCommand(r,(()=>(e(n,"number"),!0)),d),n.registerCommand(o,(()=>(e(n,"bullet"),!0)),d),n.registerCommand(t,(()=>(i(n),!0)),d),n.registerCommand(f,(()=>!!m()),d))),[n])}(u),null}export{u as ListPlugin};
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
import { TRANSFORMERS, registerMarkdownShortcuts } from '@lexical/markdown';
|
|
8
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
9
|
+
import { HorizontalRuleNode, $isHorizontalRuleNode, $createHorizontalRuleNode } from '@lexical/react/LexicalHorizontalRuleNode';
|
|
10
|
+
import { useEffect } from 'react';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
const HR = {
|
|
20
|
+
dependencies: [HorizontalRuleNode],
|
|
21
|
+
export: node => {
|
|
22
|
+
return $isHorizontalRuleNode(node) ? '***' : null;
|
|
23
|
+
},
|
|
24
|
+
regExp: /^(---|\*\*\*|___)\s?$/,
|
|
25
|
+
replace: (parentNode, _1, _2, isImport) => {
|
|
26
|
+
const line = $createHorizontalRuleNode();
|
|
27
|
+
|
|
28
|
+
// TODO: Get rid of isImport flag
|
|
29
|
+
if (isImport || parentNode.getNextSibling() != null) {
|
|
30
|
+
parentNode.replace(line);
|
|
31
|
+
} else {
|
|
32
|
+
parentNode.insertBefore(line);
|
|
33
|
+
}
|
|
34
|
+
line.selectNext();
|
|
35
|
+
},
|
|
36
|
+
type: 'element'
|
|
37
|
+
};
|
|
38
|
+
const DEFAULT_TRANSFORMERS = [HR, ...TRANSFORMERS];
|
|
39
|
+
function MarkdownShortcutPlugin({
|
|
40
|
+
transformers = DEFAULT_TRANSFORMERS
|
|
41
|
+
}) {
|
|
42
|
+
const [editor] = useLexicalComposerContext();
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
return registerMarkdownShortcuts(editor, transformers);
|
|
45
|
+
}, [editor, transformers]);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { DEFAULT_TRANSFORMERS, MarkdownShortcutPlugin };
|
|
@@ -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
|
+
import * as modDev from './LexicalMarkdownShortcutPlugin.dev.esm.js';
|
|
8
|
+
import * as modProd from './LexicalMarkdownShortcutPlugin.prod.esm.js';
|
|
9
|
+
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
10
|
+
export const DEFAULT_TRANSFORMERS = mod.DEFAULT_TRANSFORMERS;
|
|
11
|
+
export const MarkdownShortcutPlugin = mod.MarkdownShortcutPlugin;
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const LexicalMarkdownShortcutPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalMarkdownShortcutPlugin.dev.js') : require('./LexicalMarkdownShortcutPlugin.prod.js')
|
|
8
|
+
const LexicalMarkdownShortcutPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalMarkdownShortcutPlugin.dev.js') : require('./LexicalMarkdownShortcutPlugin.prod.js');
|
|
9
9
|
module.exports = LexicalMarkdownShortcutPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
import{TRANSFORMERS as e,registerMarkdownShortcuts as r}from"@lexical/markdown";import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{HorizontalRuleNode as o,$isHorizontalRuleNode as l,$createHorizontalRuleNode as n}from"@lexical/react/LexicalHorizontalRuleNode";import{useEffect as c}from"react";const i=[{dependencies:[o],export:e=>l(e)?"***":null,regExp:/^(---|\*\*\*|___)\s?$/,replace:(e,r,t,o)=>{const l=n();o||null!=e.getNextSibling()?e.replace(l):e.insertBefore(l),l.selectNext()},type:"element"},...e];function a({transformers:e=i}){const[o]=t();return c((()=>r(o,e)),[o,e]),null}export{i as DEFAULT_TRANSFORMERS,a as MarkdownShortcutPlugin};
|
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
import { useCollaborationContext } from '@lexical/react/LexicalCollaborationContext';
|
|
8
|
+
import { LexicalComposerContext, createLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
9
|
+
import * as React from 'react';
|
|
10
|
+
import { useRef, useContext, useMemo, useEffect } from 'react';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
function LexicalNestedComposer({
|
|
20
|
+
initialEditor,
|
|
21
|
+
children,
|
|
22
|
+
initialNodes,
|
|
23
|
+
initialTheme,
|
|
24
|
+
skipCollabChecks
|
|
25
|
+
}) {
|
|
26
|
+
const wasCollabPreviouslyReadyRef = useRef(false);
|
|
27
|
+
const parentContext = useContext(LexicalComposerContext);
|
|
28
|
+
if (parentContext == null) {
|
|
29
|
+
{
|
|
30
|
+
throw Error(`Unexpected parent context null on a nested composer`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const [parentEditor, {
|
|
34
|
+
getTheme: getParentTheme
|
|
35
|
+
}] = parentContext;
|
|
36
|
+
const composerContext = useMemo(() => {
|
|
37
|
+
const composerTheme = initialTheme || getParentTheme() || undefined;
|
|
38
|
+
const context = createLexicalComposerContext(parentContext, composerTheme);
|
|
39
|
+
if (composerTheme !== undefined) {
|
|
40
|
+
initialEditor._config.theme = composerTheme;
|
|
41
|
+
}
|
|
42
|
+
initialEditor._parentEditor = parentEditor;
|
|
43
|
+
if (!initialNodes) {
|
|
44
|
+
const parentNodes = initialEditor._nodes = new Map(parentEditor._nodes);
|
|
45
|
+
for (const [type, entry] of parentNodes) {
|
|
46
|
+
initialEditor._nodes.set(type, {
|
|
47
|
+
exportDOM: entry.exportDOM,
|
|
48
|
+
klass: entry.klass,
|
|
49
|
+
replace: entry.replace,
|
|
50
|
+
replaceWithKlass: entry.replaceWithKlass,
|
|
51
|
+
transforms: new Set()
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
for (let klass of initialNodes) {
|
|
56
|
+
let replace = null;
|
|
57
|
+
let replaceWithKlass = null;
|
|
58
|
+
if (typeof klass !== 'function') {
|
|
59
|
+
const options = klass;
|
|
60
|
+
klass = options.replace;
|
|
61
|
+
replace = options.with;
|
|
62
|
+
replaceWithKlass = options.withKlass || null;
|
|
63
|
+
}
|
|
64
|
+
const registeredKlass = initialEditor._nodes.get(klass.getType());
|
|
65
|
+
initialEditor._nodes.set(klass.getType(), {
|
|
66
|
+
exportDOM: registeredKlass ? registeredKlass.exportDOM : undefined,
|
|
67
|
+
klass,
|
|
68
|
+
replace,
|
|
69
|
+
replaceWithKlass,
|
|
70
|
+
transforms: new Set()
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
initialEditor._config.namespace = parentEditor._config.namespace;
|
|
75
|
+
initialEditor._editable = parentEditor._editable;
|
|
76
|
+
return [initialEditor, context];
|
|
77
|
+
},
|
|
78
|
+
// We only do this for init
|
|
79
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
80
|
+
[]);
|
|
81
|
+
|
|
82
|
+
// If collaboration is enabled, make sure we don't render the children until the collaboration subdocument is ready.
|
|
83
|
+
const {
|
|
84
|
+
isCollabActive,
|
|
85
|
+
yjsDocMap
|
|
86
|
+
} = useCollaborationContext();
|
|
87
|
+
const isCollabReady = skipCollabChecks || wasCollabPreviouslyReadyRef.current || yjsDocMap.has(initialEditor.getKey());
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (isCollabReady) {
|
|
90
|
+
wasCollabPreviouslyReadyRef.current = true;
|
|
91
|
+
}
|
|
92
|
+
}, [isCollabReady]);
|
|
93
|
+
|
|
94
|
+
// Update `isEditable` state of nested editor in response to the same change on parent editor.
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
return parentEditor.registerEditableListener(editable => {
|
|
97
|
+
initialEditor.setEditable(editable);
|
|
98
|
+
});
|
|
99
|
+
}, [initialEditor, parentEditor]);
|
|
100
|
+
return /*#__PURE__*/React.createElement(LexicalComposerContext.Provider, {
|
|
101
|
+
value: composerContext
|
|
102
|
+
}, !isCollabActive || isCollabReady ? children : null);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { LexicalNestedComposer };
|