@lexical/react 0.2.6 → 0.2.7

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.
@@ -6,4 +6,6 @@
6
6
  *
7
7
  */
8
8
 
9
- export default function LexicalMarkdownShortcutPlugin(): JSX.Element | null;
9
+ export default function LexicalMarkdownShortcutPlugin(arg0: {
10
+ transformers: Array<Transformer>;
11
+ }): JSX.Element | null;
@@ -8,7 +8,8 @@
8
8
 
9
9
  var markdown = require('@lexical/markdown');
10
10
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
11
- var react = require('react');
11
+ var React = require('react');
12
+ var lexical = require('lexical');
12
13
 
13
14
  /**
14
15
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -18,11 +19,105 @@ var react = require('react');
18
19
  *
19
20
  *
20
21
  */
22
+ lexical.createCommand();
23
+
24
+ function HorizontalRuleComponent() {
25
+ return /*#__PURE__*/React.createElement("hr", null);
26
+ }
27
+
28
+ class HorizontalRuleNode extends lexical.DecoratorNode {
29
+ static getType() {
30
+ return 'horizontalrule';
31
+ }
32
+
33
+ static clone(node) {
34
+ return new HorizontalRuleNode(node.__key);
35
+ }
36
+
37
+ static importDOM() {
38
+ return {
39
+ hr: node => ({
40
+ conversion: convertHorizontalRuleElement,
41
+ priority: 0
42
+ })
43
+ };
44
+ }
45
+
46
+ exportDOM() {
47
+ return {
48
+ element: document.createElement('hr')
49
+ };
50
+ }
51
+
52
+ createDOM() {
53
+ const div = document.createElement('div');
54
+ div.style.display = 'contents';
55
+ return div;
56
+ }
57
+
58
+ getTextContent() {
59
+ return '\n';
60
+ }
61
+
62
+ isTopLevel() {
63
+ return true;
64
+ }
65
+
66
+ updateDOM() {
67
+ return false;
68
+ }
69
+
70
+ decorate() {
71
+ return /*#__PURE__*/React.createElement(HorizontalRuleComponent, null);
72
+ }
73
+
74
+ }
75
+
76
+ function convertHorizontalRuleElement() {
77
+ return {
78
+ node: $createHorizontalRuleNode()
79
+ };
80
+ }
81
+
82
+ function $createHorizontalRuleNode() {
83
+ return new HorizontalRuleNode();
84
+ }
85
+ function $isHorizontalRuleNode(node) {
86
+ return node instanceof HorizontalRuleNode;
87
+ }
88
+
89
+ /**
90
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
91
+ *
92
+ * This source code is licensed under the MIT license found in the
93
+ * LICENSE file in the root directory of this source tree.
94
+ *
95
+ *
96
+ */
97
+ const HR = {
98
+ export: node => {
99
+ return $isHorizontalRuleNode(node) ? '***' : null;
100
+ },
101
+ regExp: /^(---|\*\*\*|___)\s?$/,
102
+ replace: (parentNode, _1, _2, isImport) => {
103
+ const line = $createHorizontalRuleNode(); // TODO: Get rid of isImport flag
104
+
105
+ if (isImport || parentNode.getNextSibling() != null) {
106
+ parentNode.replace(line);
107
+ } else {
108
+ parentNode.insertBefore(line);
109
+ }
110
+
111
+ line.selectNext();
112
+ },
113
+ type: 'element'
114
+ };
115
+ const DEFAULT_TRANSFORMERS = [HR, ...markdown.TRANSFORMERS];
21
116
  function LexicalMarkdownShortcutPlugin({
22
- transformers
117
+ transformers = DEFAULT_TRANSFORMERS
23
118
  }) {
24
119
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
25
- react.useEffect(() => {
120
+ React.useEffect(() => {
26
121
  return markdown.registerMarkdownShortcuts(editor, transformers);
27
122
  }, [editor, transformers]);
28
123
  return null;
@@ -4,4 +4,6 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- var c=require("@lexical/markdown"),d=require("@lexical/react/LexicalComposerContext"),e=require("react");module.exports=function({transformers:a}){const [b]=d.useLexicalComposerContext();e.useEffect(()=>c.registerMarkdownShortcuts(b,a),[b,a]);return null};
7
+ var c=require("@lexical/markdown"),d=require("@lexical/react/LexicalComposerContext"),e=require("react"),f=require("lexical");f.createCommand();function g(){return e.createElement("hr",null)}
8
+ class h extends f.DecoratorNode{static getType(){return"horizontalrule"}static clone(a){return new h(a.__key)}static importDOM(){return{hr:()=>({conversion:k,priority:0})}}exportDOM(){return{element:document.createElement("hr")}}createDOM(){const a=document.createElement("div");a.style.display="contents";return a}getTextContent(){return"\n"}isTopLevel(){return!0}updateDOM(){return!1}decorate(){return e.createElement(g,null)}}function k(){return{node:new h}}
9
+ const m=[{export:a=>a instanceof h?"***":null,regExp:/^(---|\*\*\*|___)\s?$/,replace:(a,b,n,l)=>{b=new h;l||null!=a.getNextSibling()?a.replace(b):a.insertBefore(b);b.selectNext()},type:"element"},...c.TRANSFORMERS];module.exports=function({transformers:a=m}){const [b]=d.useLexicalComposerContext();e.useEffect(()=>c.registerMarkdownShortcuts(b,a),[b,a]);return null};
package/package.json CHANGED
@@ -8,28 +8,28 @@
8
8
  "rich-text"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.2.6",
11
+ "version": "0.2.7",
12
12
  "dependencies": {
13
- "@lexical/clipboard": "0.2.6",
14
- "@lexical/list": "0.2.6",
15
- "@lexical/table": "0.2.6",
16
- "@lexical/yjs": "0.2.6",
17
- "@lexical/hashtag": "0.2.6",
18
- "@lexical/selection": "0.2.6",
19
- "@lexical/utils": "0.2.6",
20
- "@lexical/dragon": "0.2.6",
21
- "@lexical/plain-text": "0.2.6",
22
- "@lexical/rich-text": "0.2.6",
23
- "@lexical/code": "0.2.6",
24
- "@lexical/text": "0.2.6",
25
- "@lexical/link": "0.2.6",
26
- "@lexical/overflow": "0.2.6",
27
- "@lexical/history": "0.2.6",
28
- "@lexical/markdown": "0.2.6",
29
- "@lexical/mark": "0.2.6"
13
+ "@lexical/clipboard": "0.2.7",
14
+ "@lexical/list": "0.2.7",
15
+ "@lexical/table": "0.2.7",
16
+ "@lexical/yjs": "0.2.7",
17
+ "@lexical/hashtag": "0.2.7",
18
+ "@lexical/selection": "0.2.7",
19
+ "@lexical/utils": "0.2.7",
20
+ "@lexical/dragon": "0.2.7",
21
+ "@lexical/plain-text": "0.2.7",
22
+ "@lexical/rich-text": "0.2.7",
23
+ "@lexical/code": "0.2.7",
24
+ "@lexical/text": "0.2.7",
25
+ "@lexical/link": "0.2.7",
26
+ "@lexical/overflow": "0.2.7",
27
+ "@lexical/history": "0.2.7",
28
+ "@lexical/markdown": "0.2.7",
29
+ "@lexical/mark": "0.2.7"
30
30
  },
31
31
  "peerDependencies": {
32
- "lexical": "0.2.6",
32
+ "lexical": "0.2.7",
33
33
  "react": ">=17.x",
34
34
  "react-dom": ">=17.x"
35
35
  },