@webiny/lexical-nodes 6.0.0-beta.0 → 6.0.0-rc.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.
Files changed (83) hide show
  1. package/FontColorNode.d.ts +24 -22
  2. package/FontColorNode.js +114 -103
  3. package/FontColorNode.js.map +1 -1
  4. package/HeadingNode.d.ts +30 -20
  5. package/HeadingNode.js +185 -176
  6. package/HeadingNode.js.map +1 -1
  7. package/ImageNode.d.ts +2 -12
  8. package/ImageNode.js +119 -193
  9. package/ImageNode.js.map +1 -1
  10. package/LinkNode.d.ts +6 -6
  11. package/LinkNode.js +249 -347
  12. package/LinkNode.js.map +1 -1
  13. package/ListItemNode.d.ts +6 -5
  14. package/ListItemNode.js +275 -352
  15. package/ListItemNode.js.map +1 -1
  16. package/ListNode.d.ts +32 -19
  17. package/ListNode.js +170 -210
  18. package/ListNode.js.map +1 -1
  19. package/ParagraphNode.d.ts +30 -20
  20. package/ParagraphNode.js +144 -201
  21. package/ParagraphNode.js.map +1 -1
  22. package/QuoteNode.d.ts +27 -20
  23. package/QuoteNode.js +102 -208
  24. package/QuoteNode.js.map +1 -1
  25. package/README.md +9 -4
  26. package/components/ImageNode/ImageComponent.d.ts +2 -7
  27. package/components/ImageNode/ImageComponent.js +72 -166
  28. package/components/ImageNode/ImageComponent.js.map +1 -1
  29. package/components/ImageNode/ImageResizer.d.ts +1 -8
  30. package/components/ImageNode/ImageResizer.js +80 -95
  31. package/components/ImageNode/ImageResizer.js.map +1 -1
  32. package/generateInitialLexicalValue.d.ts +4 -0
  33. package/generateInitialLexicalValue.js +27 -0
  34. package/generateInitialLexicalValue.js.map +1 -0
  35. package/index.d.ts +19 -23
  36. package/index.js +50 -233
  37. package/index.js.map +1 -1
  38. package/package.json +22 -19
  39. package/prepareLexicalState.d.ts +2 -0
  40. package/prepareLexicalState.js +53 -0
  41. package/prepareLexicalState.js.map +1 -0
  42. package/types.d.ts +5 -9
  43. package/types.js +1 -5
  44. package/types.js.map +1 -1
  45. package/utils/clearNodeFormating.d.ts +2 -2
  46. package/utils/clearNodeFormating.js +12 -18
  47. package/utils/clearNodeFormating.js.map +1 -1
  48. package/utils/formatList.d.ts +4 -4
  49. package/utils/formatList.js +171 -208
  50. package/utils/formatList.js.map +1 -1
  51. package/utils/formatToHeading.d.ts +2 -2
  52. package/utils/formatToHeading.js +8 -15
  53. package/utils/formatToHeading.js.map +1 -1
  54. package/utils/formatToParagraph.d.ts +1 -1
  55. package/utils/formatToParagraph.js +8 -16
  56. package/utils/formatToParagraph.js.map +1 -1
  57. package/utils/formatToQuote.d.ts +1 -1
  58. package/utils/formatToQuote.js +10 -17
  59. package/utils/formatToQuote.js.map +1 -1
  60. package/utils/getStyleId.d.ts +11 -0
  61. package/utils/getStyleId.js +14 -0
  62. package/utils/getStyleId.js.map +1 -0
  63. package/utils/listNode.d.ts +14 -4
  64. package/utils/listNode.js +43 -49
  65. package/utils/listNode.js.map +1 -1
  66. package/utils/toggleLink.d.ts +1 -1
  67. package/utils/toggleLink.js +41 -45
  68. package/utils/toggleLink.js.map +1 -1
  69. package/TypographyNode.d.ts +0 -39
  70. package/TypographyNode.js +0 -147
  71. package/TypographyNode.js.map +0 -1
  72. package/components/ImageNode/ContentEditable.css +0 -22
  73. package/components/ImageNode/ContentEditable.d.ts +0 -12
  74. package/components/ImageNode/ContentEditable.js +0 -26
  75. package/components/ImageNode/ContentEditable.js.map +0 -1
  76. package/components/ImageNode/ImageComponent.css +0 -43
  77. package/components/ImageNode/Placeholder.css +0 -20
  78. package/components/ImageNode/Placeholder.d.ts +0 -15
  79. package/components/ImageNode/Placeholder.js +0 -30
  80. package/components/ImageNode/Placeholder.js.map +0 -1
  81. package/components/ImageNode/SharedHistoryContext.d.ts +0 -10
  82. package/components/ImageNode/SharedHistoryContext.js +0 -27
  83. package/components/ImageNode/SharedHistoryContext.js.map +0 -1
@@ -1,35 +1,31 @@
1
- "use strict";
1
+ import { $getSelection, $isElementNode, $isRangeSelection } from "lexical";
2
+ import { $createLinkNode, $isLinkNode } from "../LinkNode.js";
2
3
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.toggleLink = toggleLink;
7
- var _lexical = require("lexical");
8
- var _LinkNode = require("../LinkNode");
9
4
  /**
10
5
  * Generates or updates a LinkNode. It can also delete a LinkNode if the URL is null,
11
6
  * but saves any children and brings them up to the parent node.
12
7
  * @param url - The URL the link directs to.
13
8
  * @param attributes - Optional HTML a tag attributes. { target, rel, title }
14
9
  */
15
- function toggleLink(url) {
16
- var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17
- var target = attributes.target,
18
- title = attributes.title,
19
- alt = attributes.alt;
20
- var rel = attributes.rel === undefined ? "noreferrer" : attributes.rel;
21
- var selection = (0, _lexical.$getSelection)();
22
- if (!(0, _lexical.$isRangeSelection)(selection)) {
10
+ export function toggleLink(url, attributes = {}) {
11
+ const {
12
+ target,
13
+ title,
14
+ alt
15
+ } = attributes;
16
+ const rel = attributes.rel === undefined ? "noreferrer" : attributes.rel;
17
+ const selection = $getSelection();
18
+ if (!$isRangeSelection(selection)) {
23
19
  return;
24
20
  }
25
- var nodes = selection.extract();
21
+ const nodes = selection.extract();
26
22
  if (url === null) {
27
23
  // Remove LinkNodes
28
- nodes.forEach(function (node) {
29
- var parent = node.getParent();
30
- if ((0, _LinkNode.$isLinkNode)(parent)) {
31
- var children = parent.getChildren();
32
- for (var i = 0; i < children.length; i++) {
24
+ nodes.forEach(node => {
25
+ const parent = node.getParent();
26
+ if ($isLinkNode(parent)) {
27
+ const children = parent.getChildren();
28
+ for (let i = 0; i < children.length; i++) {
33
29
  parent.insertBefore(children[i]);
34
30
  }
35
31
  parent.remove();
@@ -38,35 +34,35 @@ function toggleLink(url) {
38
34
  } else {
39
35
  // Add or merge LinkNodes
40
36
  if (nodes.length === 1) {
41
- var firstNode = nodes[0];
37
+ const firstNode = nodes[0];
42
38
  // if the first node is a LinkNode or if its
43
39
  // parent is a LinkNode, we update the URL, target and rel.
44
- var _linkNode = (0, _LinkNode.$isLinkNode)(firstNode) ? firstNode : $getLinkAncestor(firstNode);
45
- if (_linkNode !== null) {
46
- _linkNode.setURL(url);
40
+ const linkNode = $isLinkNode(firstNode) ? firstNode : $getLinkAncestor(firstNode);
41
+ if (linkNode !== null) {
42
+ linkNode.setURL(url);
47
43
  if (target !== undefined) {
48
- _linkNode.setTarget(target);
44
+ linkNode.setTarget(target);
49
45
  }
50
46
  if (rel !== null) {
51
- _linkNode.setRel(rel);
47
+ linkNode.setRel(rel);
52
48
  }
53
49
  if (title !== undefined) {
54
- _linkNode.setTitle(title);
50
+ linkNode.setTitle(title);
55
51
  }
56
52
  if (alt !== undefined) {
57
- _linkNode.setAlt(alt);
53
+ linkNode.setAlt(alt);
58
54
  }
59
55
  return;
60
56
  }
61
57
  }
62
- var prevParent = null;
63
- var linkNode = null;
64
- nodes.forEach(function (node) {
65
- var parent = node.getParent();
66
- if (parent === linkNode || parent === null || (0, _lexical.$isElementNode)(node) && !node.isInline()) {
58
+ let prevParent = null;
59
+ let linkNode = null;
60
+ nodes.forEach(node => {
61
+ const parent = node.getParent();
62
+ if (parent === linkNode || parent === null || $isElementNode(node) && !node.isInline()) {
67
63
  return;
68
64
  }
69
- if ((0, _LinkNode.$isLinkNode)(parent)) {
65
+ if ($isLinkNode(parent)) {
70
66
  linkNode = parent;
71
67
  parent.setURL(url);
72
68
  if (target !== undefined) {
@@ -85,12 +81,12 @@ function toggleLink(url) {
85
81
  }
86
82
  if (!parent.is(prevParent)) {
87
83
  prevParent = parent;
88
- linkNode = (0, _LinkNode.$createLinkNode)(url, {
89
- rel: rel,
90
- target: target,
91
- alt: alt
84
+ linkNode = $createLinkNode(url, {
85
+ rel,
86
+ target,
87
+ alt
92
88
  });
93
- if ((0, _LinkNode.$isLinkNode)(parent)) {
89
+ if ($isLinkNode(parent)) {
94
90
  if (node.getPreviousSibling() === null) {
95
91
  parent.insertBefore(linkNode);
96
92
  } else {
@@ -100,13 +96,13 @@ function toggleLink(url) {
100
96
  node.insertBefore(linkNode);
101
97
  }
102
98
  }
103
- if ((0, _LinkNode.$isLinkNode)(node)) {
99
+ if ($isLinkNode(node)) {
104
100
  if (node.is(linkNode)) {
105
101
  return;
106
102
  }
107
103
  if (linkNode !== null) {
108
- var children = node.getChildren();
109
- for (var i = 0; i < children.length; i++) {
104
+ const children = node.getChildren();
105
+ for (let i = 0; i < children.length; i++) {
110
106
  linkNode.append(children[i]);
111
107
  }
112
108
  }
@@ -120,14 +116,14 @@ function toggleLink(url) {
120
116
  }
121
117
  }
122
118
  function $getLinkAncestor(node) {
123
- var ancestor = $getAncestor(node, _LinkNode.$isLinkNode);
119
+ const ancestor = $getAncestor(node, $isLinkNode);
124
120
  if (!ancestor) {
125
121
  return null;
126
122
  }
127
123
  return ancestor;
128
124
  }
129
125
  function $getAncestor(node, predicate) {
130
- var parent = node;
126
+ let parent = node;
131
127
  while (parent !== null && (parent = parent.getParent()) !== null && !predicate(parent)) {}
132
128
  return parent;
133
129
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_lexical","require","_LinkNode","toggleLink","url","attributes","arguments","length","undefined","target","title","alt","rel","selection","$getSelection","$isRangeSelection","nodes","extract","forEach","node","parent","getParent","$isLinkNode","children","getChildren","i","insertBefore","remove","firstNode","linkNode","$getLinkAncestor","setURL","setTarget","setRel","setTitle","setAlt","prevParent","$isElementNode","isInline","is","$createLinkNode","getPreviousSibling","insertAfter","append","ancestor","$getAncestor","predicate"],"sources":["toggleLink.ts"],"sourcesContent":["import {\n $getSelection,\n $isElementNode,\n $isRangeSelection,\n ElementNode,\n LexicalNode\n} from \"lexical\";\nimport { $createLinkNode, $isLinkNode, LinkAttributes, LinkNode } from \"~/LinkNode\";\n\n/**\n * Generates or updates a LinkNode. It can also delete a LinkNode if the URL is null,\n * but saves any children and brings them up to the parent node.\n * @param url - The URL the link directs to.\n * @param attributes - Optional HTML a tag attributes. { target, rel, title }\n */\nexport function toggleLink(url: null | string, attributes: LinkAttributes = {}): void {\n const { target, title, alt } = attributes;\n const rel = attributes.rel === undefined ? \"noreferrer\" : attributes.rel;\n const selection = $getSelection();\n\n if (!$isRangeSelection(selection)) {\n return;\n }\n const nodes = selection.extract();\n\n if (url === null) {\n // Remove LinkNodes\n nodes.forEach(node => {\n const parent = node.getParent();\n\n if ($isLinkNode(parent)) {\n const children = parent.getChildren();\n\n for (let i = 0; i < children.length; i++) {\n parent.insertBefore(children[i]);\n }\n\n parent.remove();\n }\n });\n } else {\n // Add or merge LinkNodes\n if (nodes.length === 1) {\n const firstNode = nodes[0];\n // if the first node is a LinkNode or if its\n // parent is a LinkNode, we update the URL, target and rel.\n const linkNode = $isLinkNode(firstNode) ? firstNode : $getLinkAncestor(firstNode);\n if (linkNode !== null) {\n linkNode.setURL(url);\n if (target !== undefined) {\n linkNode.setTarget(target);\n }\n if (rel !== null) {\n linkNode.setRel(rel);\n }\n if (title !== undefined) {\n linkNode.setTitle(title);\n }\n\n if (alt !== undefined) {\n linkNode.setAlt(alt);\n }\n return;\n }\n }\n\n let prevParent: ElementNode | LinkNode | null = null;\n let linkNode: LinkNode | null = null;\n\n nodes.forEach(node => {\n const parent = node.getParent();\n\n if (\n parent === linkNode ||\n parent === null ||\n ($isElementNode(node) && !node.isInline())\n ) {\n return;\n }\n\n if ($isLinkNode(parent)) {\n linkNode = parent;\n parent.setURL(url);\n if (target !== undefined) {\n parent.setTarget(target);\n }\n if (rel !== null) {\n linkNode.setRel(rel);\n }\n if (title !== undefined) {\n linkNode.setTitle(title);\n }\n if (alt !== undefined) {\n linkNode.setAlt(alt);\n }\n return;\n }\n\n if (!parent.is(prevParent)) {\n prevParent = parent;\n linkNode = $createLinkNode(url, { rel, target, alt });\n\n if ($isLinkNode(parent)) {\n if (node.getPreviousSibling() === null) {\n parent.insertBefore(linkNode);\n } else {\n parent.insertAfter(linkNode);\n }\n } else {\n node.insertBefore(linkNode);\n }\n }\n\n if ($isLinkNode(node)) {\n if (node.is(linkNode)) {\n return;\n }\n if (linkNode !== null) {\n const children = node.getChildren();\n\n for (let i = 0; i < children.length; i++) {\n linkNode.append(children[i]);\n }\n }\n\n node.remove();\n return;\n }\n\n if (linkNode !== null) {\n linkNode.append(node);\n }\n });\n }\n}\n\nfunction $getLinkAncestor(node: LexicalNode): LinkNode | null {\n const ancestor = $getAncestor(node, $isLinkNode);\n if (!ancestor) {\n return null;\n }\n\n return ancestor as LinkNode;\n}\n\nfunction $getAncestor<NodeType extends LexicalNode = LexicalNode>(\n node: LexicalNode,\n predicate: (ancestor: LexicalNode) => ancestor is NodeType\n): null | LexicalNode {\n let parent: null | LexicalNode = node;\n while (parent !== null && (parent = parent.getParent()) !== null && !predicate(parent)) {}\n return parent;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAOA,IAAAC,SAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,UAAUA,CAACC,GAAkB,EAAyC;EAAA,IAAvCC,UAA0B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAC1E,IAAQG,MAAM,GAAiBJ,UAAU,CAAjCI,MAAM;IAAEC,KAAK,GAAUL,UAAU,CAAzBK,KAAK;IAAEC,GAAG,GAAKN,UAAU,CAAlBM,GAAG;EAC1B,IAAMC,GAAG,GAAGP,UAAU,CAACO,GAAG,KAAKJ,SAAS,GAAG,YAAY,GAAGH,UAAU,CAACO,GAAG;EACxE,IAAMC,SAAS,GAAG,IAAAC,sBAAa,EAAC,CAAC;EAEjC,IAAI,CAAC,IAAAC,0BAAiB,EAACF,SAAS,CAAC,EAAE;IAC/B;EACJ;EACA,IAAMG,KAAK,GAAGH,SAAS,CAACI,OAAO,CAAC,CAAC;EAEjC,IAAIb,GAAG,KAAK,IAAI,EAAE;IACd;IACAY,KAAK,CAACE,OAAO,CAAC,UAAAC,IAAI,EAAI;MAClB,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MACJ;MAEA,IAAI,IAAAP,qBAAW,EAACH,IAAI,CAAC,EAAE;QACnB,IAAIA,IAAI,CAACoB,EAAE,CAACV,QAAQ,CAAC,EAAE;UACnB;QACJ;QACA,IAAIA,QAAQ,KAAK,IAAI,EAAE;UACnB,IAAMN,QAAQ,GAAGJ,IAAI,CAACK,WAAW,CAAC,CAAC;UAEnC,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,QAAQ,CAAChB,MAAM,EAAEkB,CAAC,EAAE,EAAE;YACtCI,QAAQ,CAACc,MAAM,CAACpB,QAAQ,CAACE,CAAC,CAAC,CAAC;UAChC;QACJ;QAEAN,IAAI,CAACQ,MAAM,CAAC,CAAC;QACb;MACJ;MAEA,IAAIE,QAAQ,KAAK,IAAI,EAAE;QACnBA,QAAQ,CAACc,MAAM,CAACxB,IAAI,CAAC;MACzB;IACJ,CAAC,CAAC;EACN;AACJ;AAEA,SAASW,gBAAgBA,CAACX,IAAiB,EAAmB;EAC1D,IAAMyB,QAAQ,GAAGC,YAAY,CAAC1B,IAAI,EAAEG,qBAAW,CAAC;EAChD,IAAI,CAACsB,QAAQ,EAAE;IACX,OAAO,IAAI;EACf;EAEA,OAAOA,QAAQ;AACnB;AAEA,SAASC,YAAYA,CACjB1B,IAAiB,EACjB2B,SAA0D,EACxC;EAClB,IAAI1B,MAA0B,GAAGD,IAAI;EACrC,OAAOC,MAAM,KAAK,IAAI,IAAI,CAACA,MAAM,GAAGA,MAAM,CAACC,SAAS,CAAC,CAAC,MAAM,IAAI,IAAI,CAACyB,SAAS,CAAC1B,MAAM,CAAC,EAAE,CAAC;EACzF,OAAOA,MAAM;AACjB","ignoreList":[]}
1
+ {"version":3,"names":["$getSelection","$isElementNode","$isRangeSelection","$createLinkNode","$isLinkNode","toggleLink","url","attributes","target","title","alt","rel","undefined","selection","nodes","extract","forEach","node","parent","getParent","children","getChildren","i","length","insertBefore","remove","firstNode","linkNode","$getLinkAncestor","setURL","setTarget","setRel","setTitle","setAlt","prevParent","isInline","is","getPreviousSibling","insertAfter","append","ancestor","$getAncestor","predicate"],"sources":["toggleLink.ts"],"sourcesContent":["import type { ElementNode, LexicalNode } from \"lexical\";\nimport { $getSelection, $isElementNode, $isRangeSelection } from \"lexical\";\nimport type { LinkAttributes, LinkNode } from \"~/LinkNode.js\";\nimport { $createLinkNode, $isLinkNode } from \"~/LinkNode.js\";\n\n/**\n * Generates or updates a LinkNode. It can also delete a LinkNode if the URL is null,\n * but saves any children and brings them up to the parent node.\n * @param url - The URL the link directs to.\n * @param attributes - Optional HTML a tag attributes. { target, rel, title }\n */\nexport function toggleLink(url: null | string, attributes: LinkAttributes = {}): void {\n const { target, title, alt } = attributes;\n const rel = attributes.rel === undefined ? \"noreferrer\" : attributes.rel;\n const selection = $getSelection();\n\n if (!$isRangeSelection(selection)) {\n return;\n }\n const nodes = selection.extract();\n\n if (url === null) {\n // Remove LinkNodes\n nodes.forEach(node => {\n const parent = node.getParent();\n\n if ($isLinkNode(parent)) {\n const children = parent.getChildren();\n\n for (let i = 0; i < children.length; i++) {\n parent.insertBefore(children[i]);\n }\n\n parent.remove();\n }\n });\n } else {\n // Add or merge LinkNodes\n if (nodes.length === 1) {\n const firstNode = nodes[0];\n // if the first node is a LinkNode or if its\n // parent is a LinkNode, we update the URL, target and rel.\n const linkNode = $isLinkNode(firstNode) ? firstNode : $getLinkAncestor(firstNode);\n if (linkNode !== null) {\n linkNode.setURL(url);\n if (target !== undefined) {\n linkNode.setTarget(target);\n }\n if (rel !== null) {\n linkNode.setRel(rel);\n }\n if (title !== undefined) {\n linkNode.setTitle(title);\n }\n\n if (alt !== undefined) {\n linkNode.setAlt(alt);\n }\n return;\n }\n }\n\n let prevParent: ElementNode | LinkNode | null = null;\n let linkNode: LinkNode | null = null;\n\n nodes.forEach(node => {\n const parent = node.getParent();\n\n if (\n parent === linkNode ||\n parent === null ||\n ($isElementNode(node) && !node.isInline())\n ) {\n return;\n }\n\n if ($isLinkNode(parent)) {\n linkNode = parent;\n parent.setURL(url);\n if (target !== undefined) {\n parent.setTarget(target);\n }\n if (rel !== null) {\n linkNode.setRel(rel);\n }\n if (title !== undefined) {\n linkNode.setTitle(title);\n }\n if (alt !== undefined) {\n linkNode.setAlt(alt);\n }\n return;\n }\n\n if (!parent.is(prevParent)) {\n prevParent = parent;\n linkNode = $createLinkNode(url, { rel, target, alt });\n\n if ($isLinkNode(parent)) {\n if (node.getPreviousSibling() === null) {\n parent.insertBefore(linkNode);\n } else {\n parent.insertAfter(linkNode);\n }\n } else {\n node.insertBefore(linkNode);\n }\n }\n\n if ($isLinkNode(node)) {\n if (node.is(linkNode)) {\n return;\n }\n if (linkNode !== null) {\n const children = node.getChildren();\n\n for (let i = 0; i < children.length; i++) {\n linkNode.append(children[i]);\n }\n }\n\n node.remove();\n return;\n }\n\n if (linkNode !== null) {\n linkNode.append(node);\n }\n });\n }\n}\n\nfunction $getLinkAncestor(node: LexicalNode): LinkNode | null {\n const ancestor = $getAncestor(node, $isLinkNode);\n if (!ancestor) {\n return null;\n }\n\n return ancestor as LinkNode;\n}\n\nfunction $getAncestor<NodeType extends LexicalNode = LexicalNode>(\n node: LexicalNode,\n predicate: (ancestor: LexicalNode) => ancestor is NodeType\n): null | LexicalNode {\n let parent: null | LexicalNode = node;\n while (parent !== null && (parent = parent.getParent()) !== null && !predicate(parent)) {}\n return parent;\n}\n"],"mappings":"AACA,SAASA,aAAa,EAAEC,cAAc,EAAEC,iBAAiB,QAAQ,SAAS;AAE1E,SAASC,eAAe,EAAEC,WAAW;;AAErC;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACC,GAAkB,EAAEC,UAA0B,GAAG,CAAC,CAAC,EAAQ;EAClF,MAAM;IAAEC,MAAM;IAAEC,KAAK;IAAEC;EAAI,CAAC,GAAGH,UAAU;EACzC,MAAMI,GAAG,GAAGJ,UAAU,CAACI,GAAG,KAAKC,SAAS,GAAG,YAAY,GAAGL,UAAU,CAACI,GAAG;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exicalCommand, LexicalEditor, LexicalNode, NodeKey, SerializedElementNode, Spread } from "lexical";
2
- import { EditorTheme, TypographyHTMLTag, TypographyValue } from "@webiny/lexical-theme";
3
- export declare const ADD_TYPOGRAPHY_COMMAND: LexicalCommand<TypographyPayload>;
4
- export interface TypographyPayload {
5
- value: TypographyValue;
6
- caption?: LexicalEditor;
7
- key?: NodeKey;
8
- }
9
- export declare type SerializedTypographyNode = Spread<{
10
- tag: TypographyHTMLTag;
11
- styleId: string;
12
- name: string;
13
- typographyStyles: Record<string, any>;
14
- type: "typography-el-node";
15
- version: 1;
16
- }, SerializedElementNode>;
17
- /**
18
- * Main responsibility of this node is to apply custom or Webiny theme typography to selected text.
19
- * Extends the original ElementNode node to add additional transformation and support for webiny theme typography.
20
- */
21
- export declare class TypographyNode extends ElementNode {
22
- __styleId: string;
23
- __tag: TypographyHTMLTag;
24
- __name: string;
25
- __css: Record<string, any>;
26
- constructor(value: TypographyValue, key?: NodeKey);
27
- static getType(): string;
28
- static clone(node: TypographyNode): TypographyNode;
29
- getTypographyValue(): TypographyValue;
30
- addStylesHTMLElement(element: HTMLElement, theme: EditorTheme): HTMLElement;
31
- exportJSON(): SerializedTypographyNode;
32
- static importJSON(serializedNode: SerializedTypographyNode): TypographyNode;
33
- createDOM(config: EditorConfig): HTMLElement;
34
- updateDOM(): boolean;
35
- insertNewAfter(): TypographyNode;
36
- collapseAtStart(): true;
37
- }
38
- export declare const $createTypographyNode: (value: TypographyValue, key?: NodeKey) => TypographyNode;
39
- export declare const $isTypographyNode: (node: ElementNode | LexicalNode | null) => node is TypographyNode;
package/TypographyNode.js DELETED
@@ -1,147 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.TypographyNode = exports.ADD_TYPOGRAPHY_COMMAND = exports.$isTypographyNode = exports.$createTypographyNode = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _callSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/callSuper"));
12
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
13
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
14
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
15
- var _lexical = require("lexical");
16
- var _utils = require("@lexical/utils");
17
- var _ParagraphNode = require("./ParagraphNode");
18
- // Command and payload
19
- var ADD_TYPOGRAPHY_COMMAND = exports.ADD_TYPOGRAPHY_COMMAND = (0, _lexical.createCommand)("ADD_TYPOGRAPHY_COMMAND");
20
- var TypographyNodeAttrName = "data-typography-style-id";
21
-
22
- // Node
23
- /**
24
- * Main responsibility of this node is to apply custom or Webiny theme typography to selected text.
25
- * Extends the original ElementNode node to add additional transformation and support for webiny theme typography.
26
- */
27
- var TypographyNode = exports.TypographyNode = /*#__PURE__*/function (_ElementNode) {
28
- function TypographyNode(value, key) {
29
- var _this;
30
- (0, _classCallCheck2.default)(this, TypographyNode);
31
- _this = (0, _callSuper2.default)(this, TypographyNode, [key]);
32
- _this.__tag = value.tag;
33
- _this.__styleId = value.id;
34
- _this.__name = value.name;
35
- _this.__css = value.css;
36
- return _this;
37
- }
38
- (0, _inherits2.default)(TypographyNode, _ElementNode);
39
- return (0, _createClass2.default)(TypographyNode, [{
40
- key: "getTypographyValue",
41
- value: function getTypographyValue() {
42
- return {
43
- tag: this.__tag,
44
- css: this.__css,
45
- id: this.__styleId,
46
- name: this.__name
47
- };
48
- }
49
- }, {
50
- key: "addStylesHTMLElement",
51
- value: function addStylesHTMLElement(element, theme) {
52
- var typographyStyleValue = theme?.emotionMap ? theme?.emotionMap[this.__styleId] : undefined;
53
- if (typographyStyleValue) {
54
- this.__css = typographyStyleValue.styles;
55
- (0, _utils.addClassNamesToElement)(element, typographyStyleValue.className);
56
- }
57
- element.setAttribute(TypographyNodeAttrName, this.__styleId);
58
- return element;
59
- }
60
- }, {
61
- key: "exportJSON",
62
- value: function exportJSON() {
63
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _get2.default)((0, _getPrototypeOf2.default)(TypographyNode.prototype), "exportJSON", this).call(this)), {}, {
64
- tag: this.__tag,
65
- typographyStyles: this.__css,
66
- name: this.__name,
67
- styleId: this.__styleId,
68
- type: "typography-el-node",
69
- version: 1
70
- });
71
- }
72
- }, {
73
- key: "createDOM",
74
- value: function createDOM(config) {
75
- var tag = this.__tag;
76
- var element = document.createElement(tag);
77
- return this.addStylesHTMLElement(element, config.theme);
78
- }
79
- }, {
80
- key: "updateDOM",
81
- value: function updateDOM() {
82
- return false;
83
- }
84
- }, {
85
- key: "insertNewAfter",
86
- value: function insertNewAfter() {
87
- var newElement = $createTypographyNode({
88
- tag: this.__tag,
89
- name: this.__name,
90
- css: this.__css,
91
- id: this.__styleId
92
- });
93
- var direction = this.getDirection();
94
- newElement.setDirection(direction);
95
- this.insertAfter(newElement);
96
- return newElement;
97
- }
98
- }, {
99
- key: "collapseAtStart",
100
- value: function collapseAtStart() {
101
- var paragraph = (0, _ParagraphNode.$createParagraphNode)();
102
- var children = this.getChildren();
103
- children.forEach(function (child) {
104
- return paragraph.append(child);
105
- });
106
- this.replace(paragraph);
107
- return true;
108
- }
109
- }], [{
110
- key: "getType",
111
- value: function getType() {
112
- return "typography-el-node";
113
- }
114
- }, {
115
- key: "clone",
116
- value: function clone(node) {
117
- return new TypographyNode({
118
- css: node.__css,
119
- id: node.__styleId,
120
- name: node.__name,
121
- tag: node.__tag
122
- }, node.__key);
123
- }
124
- }, {
125
- key: "importJSON",
126
- value: function importJSON(serializedNode) {
127
- var node = new TypographyNode({
128
- id: serializedNode.styleId,
129
- css: serializedNode.typographyStyles,
130
- tag: serializedNode.tag,
131
- name: serializedNode.name
132
- });
133
- node.setFormat(serializedNode.format);
134
- node.setIndent(serializedNode.indent);
135
- node.setDirection(serializedNode.direction);
136
- return node;
137
- }
138
- }]);
139
- }(_lexical.ElementNode);
140
- var $createTypographyNode = exports.$createTypographyNode = function $createTypographyNode(value, key) {
141
- return new TypographyNode(value, key);
142
- };
143
- var $isTypographyNode = exports.$isTypographyNode = function $isTypographyNode(node) {
144
- return node instanceof TypographyNode;
145
- };
146
-
147
- //# sourceMappingURL=TypographyNode.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_lexical","require","_utils","_ParagraphNode","ADD_TYPOGRAPHY_COMMAND","exports","createCommand","TypographyNodeAttrName","TypographyNode","_ElementNode","value","key","_this","_classCallCheck2","default","_callSuper2","__tag","tag","__styleId","id","__name","name","__css","css","_inherits2","_createClass2","getTypographyValue","addStylesHTMLElement","element","theme","typographyStyleValue","emotionMap","undefined","styles","addClassNamesToElement","className","setAttribute","exportJSON","_objectSpread2","_get2","_getPrototypeOf2","prototype","call","typographyStyles","styleId","type","version","createDOM","config","document","createElement","updateDOM","insertNewAfter","newElement","$createTypographyNode","direction","getDirection","setDirection","insertAfter","collapseAtStart","paragraph","$createParagraphNode","children","getChildren","forEach","child","append","replace","getType","clone","node","__key","importJSON","serializedNode","setFormat","format","setIndent","indent","ElementNode","$isTypographyNode"],"sources":["TypographyNode.ts"],"sourcesContent":["import {\n createCommand,\n EditorConfig,\n ElementNode,\n LexicalCommand,\n LexicalEditor,\n LexicalNode,\n NodeKey,\n SerializedElementNode,\n Spread\n} from \"lexical\";\nimport { addClassNamesToElement } from \"@lexical/utils\";\nimport { EditorTheme, TypographyHTMLTag, TypographyValue } from \"@webiny/lexical-theme\";\nimport { $createParagraphNode } from \"~/ParagraphNode\";\n\n// Command and payload\nexport const ADD_TYPOGRAPHY_COMMAND: LexicalCommand<TypographyPayload> =\n createCommand(\"ADD_TYPOGRAPHY_COMMAND\");\n\nconst TypographyNodeAttrName = \"data-typography-style-id\";\n\nexport interface TypographyPayload {\n value: TypographyValue;\n caption?: LexicalEditor;\n key?: NodeKey;\n}\n\n// Node\nexport type SerializedTypographyNode = Spread<\n {\n tag: TypographyHTMLTag;\n styleId: string;\n name: string;\n typographyStyles: Record<string, any>;\n type: \"typography-el-node\";\n version: 1;\n },\n SerializedElementNode\n>;\n\n/**\n * Main responsibility of this node is to apply custom or Webiny theme typography to selected text.\n * Extends the original ElementNode node to add additional transformation and support for webiny theme typography.\n */\nexport class TypographyNode extends ElementNode {\n __styleId: string;\n __tag: TypographyHTMLTag;\n __name: string;\n __css: Record<string, any>;\n\n constructor(value: TypographyValue, key?: NodeKey) {\n super(key);\n this.__tag = value.tag;\n this.__styleId = value.id;\n this.__name = value.name;\n this.__css = value.css;\n }\n\n static override getType(): string {\n return \"typography-el-node\";\n }\n\n static override clone(node: TypographyNode): TypographyNode {\n return new TypographyNode(\n {\n css: node.__css,\n id: node.__styleId,\n name: node.__name,\n tag: node.__tag\n },\n node.__key\n );\n }\n getTypographyValue(): TypographyValue {\n return {\n tag: this.__tag,\n css: this.__css,\n id: this.__styleId,\n name: this.__name\n };\n }\n\n addStylesHTMLElement(element: HTMLElement, theme: EditorTheme): HTMLElement {\n const typographyStyleValue = theme?.emotionMap\n ? theme?.emotionMap[this.__styleId]\n : undefined;\n if (typographyStyleValue) {\n this.__css = typographyStyleValue.styles;\n addClassNamesToElement(element, typographyStyleValue.className);\n }\n element.setAttribute(TypographyNodeAttrName, this.__styleId);\n\n return element;\n }\n\n override exportJSON(): SerializedTypographyNode {\n return {\n ...super.exportJSON(),\n tag: this.__tag,\n typographyStyles: this.__css,\n name: this.__name,\n styleId: this.__styleId,\n type: \"typography-el-node\",\n version: 1\n };\n }\n\n static override importJSON(serializedNode: SerializedTypographyNode): TypographyNode {\n const node = new TypographyNode({\n id: serializedNode.styleId,\n css: serializedNode.typographyStyles,\n tag: serializedNode.tag,\n name: serializedNode.name\n });\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n return node;\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const tag = this.__tag;\n const element = document.createElement(tag);\n return this.addStylesHTMLElement(element, config.theme);\n }\n\n override updateDOM(): boolean {\n return false;\n }\n\n override insertNewAfter(): TypographyNode {\n const newElement = $createTypographyNode({\n tag: this.__tag,\n name: this.__name,\n css: this.__css,\n id: this.__styleId\n });\n const direction = this.getDirection();\n newElement.setDirection(direction);\n this.insertAfter(newElement);\n return newElement;\n }\n\n override collapseAtStart(): true {\n const paragraph = $createParagraphNode();\n const children = this.getChildren();\n children.forEach(child => paragraph.append(child));\n this.replace(paragraph);\n return true;\n }\n}\n\nexport const $createTypographyNode = (value: TypographyValue, key?: NodeKey): TypographyNode => {\n return new TypographyNode(value, key);\n};\n\nexport const $isTypographyNode = (\n node: ElementNode | LexicalNode | null\n): node is TypographyNode => {\n return node instanceof TypographyNode;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAWA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,cAAA,GAAAF,OAAA;AAEA;AACO,IAAMG,sBAAyD,GAAAC,OAAA,CAAAD,sBAAA,GAClE,IAAAE,sBAAa,EAAC,wBAAwB,CAAC;AAE3C,IAAMC,sBAAsB,GAAG,0BAA0B;;AAQzD;AAaA;AACA;AACA;AACA;AAHA,IAIaC,cAAc,GAAAH,OAAA,CAAAG,cAAA,0BAAAC,YAAA;EAMvB,SAAAD,eAAYE,KAAsB,EAAEC,GAAa,EAAE;IAAA,IAAAC,KAAA;IAAA,IAAAC,gBAAA,CAAAC,OAAA,QAAAN,cAAA;IAC/CI,KAAA,OAAAG,WAAA,CAAAD,OAAA,QAAAN,cAAA,GAAMG,GAAG;IACTC,KAAA,CAAKI,KAAK,GAAGN,KAAK,CAACO,GAAG;IACtBL,KAAA,CAAKM,SAAS,GAAGR,KAAK,CAACS,EAAE;IACzBP,KAAA,CAAKQ,MAAM,GAAG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AC","ignoreList":[]}
@@ -1,22 +0,0 @@
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
- .ContentEditable__root {
10
- border: 0;
11
- font-size: 15px;
12
- display: block;
13
- position: relative;
14
- outline: 0;
15
- padding: 8px 28px 40px;
16
- }
17
- @media (max-width: 1025px) {
18
- .ContentEditable__root {
19
- padding-left: 8px;
20
- padding-right: 8px;
21
- }
22
- }
@@ -1,12 +0,0 @@
1
- /// <reference types="react" />
2
- /**
3
- * Copyright (c) Meta Platforms, Inc. and affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- *
8
- */
9
- import "./ContentEditable.css";
10
- export declare function LexicalContentEditable({ className }: {
11
- className?: string;
12
- }): JSX.Element;
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.LexicalContentEditable = LexicalContentEditable;
8
- require("./ContentEditable.css");
9
- var _LexicalContentEditable = require("@lexical/react/LexicalContentEditable");
10
- var React = _interopRequireWildcard(require("react"));
11
- /**
12
- * Copyright (c) Meta Platforms, Inc. and affiliates.
13
- *
14
- * This source code is licensed under the MIT license found in the
15
- * LICENSE file in the root directory of this source tree.
16
- *
17
- */
18
-
19
- function LexicalContentEditable(_ref) {
20
- var className = _ref.className;
21
- return /*#__PURE__*/React.createElement(_LexicalContentEditable.ContentEditable, {
22
- className: className || "ContentEditable__root"
23
- });
24
- }
25
-
26
- //# sourceMappingURL=ContentEditable.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["require","_LexicalContentEditable","React","_interopRequireWildcard","LexicalContentEditable","_ref","className","createElement","ContentEditable"],"sources":["ContentEditable.tsx"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport \"./ContentEditable.css\";\n\nimport { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\nimport * as React from \"react\";\n\nexport function LexicalContentEditable({ className }: { className?: string }): JSX.Element {\n return <ContentEditable className={className || \"ContentEditable__root\"} />;\n}\n"],"mappings":";;;;;;;AAOAA,OAAA;AAEA,IAAAC,uBAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAC,uBAAA,CAAAH,OAAA;AAVA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMO,SAASI,sBAAsBA,CAAAC,IAAA,EAAqD;EAAA,IAAlDC,SAAS,GAAAD,IAAA,CAATC,SAAS;EAC9C,oBAAOJ,KAAA,CAAAK,aAAA,CAACN,uBAAA,CAAAO,eAAe;IAACF,SAAS,EAAEA,SAAS,IAAI;EAAwB,CAAE,CAAC;AAC/E","ignoreList":[]}
@@ -1,43 +0,0 @@
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
-
10
- .ImageNode__contentEditable {
11
- min-height: 20px;
12
- border: 0px;
13
- resize: none;
14
- cursor: text;
15
- caret-color: rgb(5, 5, 5);
16
- display: block;
17
- position: relative;
18
- outline: 0px;
19
- padding: 10px;
20
- user-select: text;
21
- font-size: 12px;
22
- width: calc(100% - 20px);
23
- white-space: pre-wrap;
24
- word-break: break-word;
25
- }
26
-
27
- .ImageNode__placeholder {
28
- font-size: 12px;
29
- color: #888;
30
- overflow: hidden;
31
- position: absolute;
32
- text-overflow: ellipsis;
33
- top: 10px;
34
- left: 10px;
35
- user-select: none;
36
- white-space: nowrap;
37
- display: inline-block;
38
- pointer-events: none;
39
- }
40
-
41
- .image-control-wrapper--resizing {
42
- touch-action: none;
43
- }
@@ -1,20 +0,0 @@
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
-
10
- .Placeholder__root {
11
- font-size: 15px;
12
- margin-top: -20px;
13
- color: #999;
14
- overflow: hidden;
15
- position: relative;
16
- text-overflow: ellipsis;
17
- user-select: none;
18
- white-space: nowrap;
19
- pointer-events: none;
20
- }
@@ -1,15 +0,0 @@
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
- import "./Placeholder.css";
9
- import * as React from "react";
10
- import { ReactNode } from "react";
11
- export declare function Placeholder({ children, className, styles }: {
12
- children: ReactNode;
13
- className?: string;
14
- styles?: React.CSSProperties;
15
- }): JSX.Element;
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.Placeholder = Placeholder;
9
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
10
- require("./Placeholder.css");
11
- var React = _interopRequireWildcard(require("react"));
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
-
20
- function Placeholder(_ref) {
21
- var children = _ref.children,
22
- className = _ref.className,
23
- styles = _ref.styles;
24
- return /*#__PURE__*/React.createElement("div", {
25
- style: (0, _objectSpread2.default)({}, styles),
26
- className: className || "Placeholder__root"
27
- }, children);
28
- }
29
-
30
- //# sourceMappingURL=Placeholder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["require","React","_interopRequireWildcard","Placeholder","_ref","children","className","styles","createElement","style","_objectSpread2","default"],"sources":["Placeholder.tsx"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport \"./Placeholder.css\";\n\nimport * as React from \"react\";\nimport { ReactNode } from \"react\";\n\nexport function Placeholder({\n children,\n className,\n styles\n}: {\n children: ReactNode;\n className?: string;\n styles?: React.CSSProperties;\n}): JSX.Element {\n return (\n <div style={{ ...styles }} className={className || \"Placeholder__root\"}>\n {children}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAQAA,OAAA;AAEA,IAAAC,KAAA,GAAAC,uBAAA,CAAAF,OAAA;AAVA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOO,SAASG,WAAWA,CAAAC,IAAA,EAQX;EAAA,IAPZC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IACRC,SAAS,GAAAF,IAAA,CAATE,SAAS;IACTC,MAAM,GAAAH,IAAA,CAANG,MAAM;EAMN,oBACIN,KAAA,CAAAO,aAAA;IAAKC,KAAK,MAAAC,cAAA,CAAAC,OAAA,MAAOJ,MAAM,CAAG;IAACD,SAAS,EAAEA,SAAS,IAAI;EAAoB,GAClED,QACA,CAAC;AAEd","ignoreList":[]}
@@ -1,10 +0,0 @@
1
- import { ReactNode } from "react";
2
- import { HistoryState } from "@lexical/history";
3
- declare type ContextShape = {
4
- historyState?: HistoryState;
5
- };
6
- export declare const SharedHistoryContext: ({ children }: {
7
- children: ReactNode;
8
- }) => JSX.Element;
9
- export declare const useSharedHistoryContext: () => ContextShape;
10
- export {};
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.useSharedHistoryContext = exports.SharedHistoryContext = void 0;
8
- var _react = _interopRequireWildcard(require("react"));
9
- var React = _react;
10
- var _history = require("@lexical/history");
11
- var Context = /*#__PURE__*/(0, _react.createContext)({});
12
- var SharedHistoryContext = exports.SharedHistoryContext = function SharedHistoryContext(_ref) {
13
- var children = _ref.children;
14
- var historyContext = (0, _react.useMemo)(function () {
15
- return {
16
- historyState: (0, _history.createEmptyHistoryState)()
17
- };
18
- }, []);
19
- return /*#__PURE__*/React.createElement(Context.Provider, {
20
- value: historyContext
21
- }, children);
22
- };
23
- var useSharedHistoryContext = exports.useSharedHistoryContext = function useSharedHistoryContext() {
24
- return (0, _react.useContext)(Context);
25
- };
26
-
27
- //# sourceMappingURL=SharedHistoryContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","React","_history","Context","createContext","SharedHistoryContext","exports","_ref","children","historyContext","useMemo","historyState","createEmptyHistoryState","createElement","Provider","value","useSharedHistoryContext","useContext"],"sources":["SharedHistoryContext.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { createContext, ReactNode, useContext, useMemo } from \"react\";\nimport { createEmptyHistoryState, HistoryState } from \"@lexical/history\";\n\ntype ContextShape = {\n historyState?: HistoryState;\n};\n\nconst Context: React.Context<ContextShape> = createContext({});\n\nexport const SharedHistoryContext = ({ children }: { children: ReactNode }): JSX.Element => {\n const historyContext = useMemo(() => ({ historyState: createEmptyHistoryState() }), []);\n return <Context.Provider value={historyContext}>{children}</Context.Provider>;\n};\n\nexport const useSharedHistoryContext = (): ContextShape => {\n return useContext(Context);\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA+B,IAAAC,KAAA,GAAAH,MAAA;AAE/B,IAAAI,QAAA,GAAAF,OAAA;AAMA,IAAMG,OAAoC,gBAAG,IAAAC,oBAAa,EAAC,CAAC,CAAC,CAAC;AAEvD,IAAMC,oBAAoB,GAAAC,OAAA,CAAAD,oBAAA,GAAG,SAAvBA,oBAAoBA,CAAAE,IAAA,EAA2D;EAAA,IAArDC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;EAC3C,IAAMC,cAAc,GAAG,IAAAC,cAAO,EAAC;IAAA,OAAO;MAAEC,YAAY,EAAE,IAAAC,gCAAuB,EAAC;IAAE,CAAC;EAAA,CAAC,EAAE,EAAE,CAAC;EACvF,oBAAOX,KAAA,CAAAY,aAAA,CAACV,OAAO,CAACW,QAAQ;IAACC,KAAK,EAAEN;EAAe,GAAED,QAA2B,CAAC;AACjF,CAAC;AAEM,IAAMQ,uBAAuB,GAAAV,OAAA,CAAAU,uBAAA,GAAG,SAA1BA,uBAAuBA,CAAA,EAAuB;EACvD,OAAO,IAAAC,iBAAU,EAACd,OAAO,CAAC;AAC9B,CAAC","ignoreList":[]}