@react-fabric/lexical 1.0.0-beta.8 → 1.0.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.
Files changed (148) hide show
  1. package/{src/editor/Lexical.module.css → css/_lexical.css} +79 -13
  2. package/css/styles.css +24 -0
  3. package/dist/cjs/{packages/lexical/src/editor → editor}/LexicalEditor.js +98 -45
  4. package/dist/cjs/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +147 -140
  5. package/dist/cjs/i18n/ar/lexical.json.js +30 -0
  6. package/dist/cjs/i18n/en/lexical.json.js +30 -0
  7. package/{src/plugins/StickyPlugin.ts → dist/cjs/i18n/index.js} +10 -15
  8. package/dist/cjs/index.js +36 -0
  9. package/dist/cjs/plugins/CommentPlugin.js +481 -0
  10. package/dist/cjs/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +17 -20
  11. package/dist/cjs/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +58 -37
  12. package/dist/esm/{packages/lexical/src/editor → editor}/LexicalEditor.js +101 -48
  13. package/dist/esm/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +95 -88
  14. package/dist/esm/i18n/ar/lexical.json.js +25 -0
  15. package/dist/esm/i18n/en/lexical.json.js +25 -0
  16. package/dist/esm/i18n/index.js +33 -0
  17. package/dist/esm/index.js +34 -0
  18. package/dist/esm/plugins/CommentPlugin.js +481 -0
  19. package/dist/esm/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +15 -18
  20. package/dist/esm/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +59 -38
  21. package/dist/types/editor/LexicalEditor.d.ts +33 -4
  22. package/dist/types/hooks/useFormatWatcher.d.ts +7 -4
  23. package/dist/types/i18n/index.d.ts +1 -0
  24. package/dist/types/index.d.ts +27 -0
  25. package/dist/types/plugins/CommentPlugin.d.ts +5 -0
  26. package/dist/types/plugins/DraggableBlockPlugin.d.ts +3 -2
  27. package/dist/types/plugins/ToolbarPlugin.d.ts +1 -1
  28. package/dist/types/utils/index.d.ts +3 -6
  29. package/package.json +18 -18
  30. package/src/editor/LexicalEditor.tsx +95 -55
  31. package/src/hooks/useFormatWatcher.ts +50 -74
  32. package/src/i18n/ar/lexical.json +18 -0
  33. package/src/i18n/en/lexical.json +18 -0
  34. package/src/i18n/index.ts +28 -0
  35. package/src/index.ts +24 -17
  36. package/src/plugins/CommentPlugin.tsx +523 -0
  37. package/src/plugins/DraggableBlockPlugin.tsx +23 -68
  38. package/src/plugins/ToolbarPlugin.tsx +83 -131
  39. package/src/utils/index.ts +12 -108
  40. package/dist/cjs/_virtual/prism.js +0 -5
  41. package/dist/cjs/editor/Lexical.module.css +0 -1
  42. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -432
  43. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -21
  44. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -27
  45. package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +0 -1139
  46. package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +0 -25
  47. package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +0 -50
  48. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +0 -245
  49. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +0 -19
  50. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +0 -18
  51. package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +0 -471
  52. package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +0 -17
  53. package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +0 -24
  54. package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +0 -1275
  55. package/dist/cjs/node_modules/@lexical/list/LexicalList.js +0 -29
  56. package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +0 -29
  57. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -789
  58. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +0 -29
  59. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -26
  60. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -976
  61. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +0 -35
  62. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -35
  63. package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +0 -2792
  64. package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +0 -23
  65. package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +0 -55
  66. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -888
  67. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +0 -35
  68. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -66
  69. package/dist/cjs/node_modules/@mdi/js/mdi.js +0 -8
  70. package/dist/cjs/node_modules/prismjs/components/prism-c.js +0 -82
  71. package/dist/cjs/node_modules/prismjs/components/prism-clike.js +0 -33
  72. package/dist/cjs/node_modules/prismjs/components/prism-cpp.js +0 -101
  73. package/dist/cjs/node_modules/prismjs/components/prism-css.js +0 -66
  74. package/dist/cjs/node_modules/prismjs/components/prism-java.js +0 -126
  75. package/dist/cjs/node_modules/prismjs/components/prism-javascript.js +0 -174
  76. package/dist/cjs/node_modules/prismjs/components/prism-markdown.js +0 -417
  77. package/dist/cjs/node_modules/prismjs/components/prism-markup.js +0 -188
  78. package/dist/cjs/node_modules/prismjs/components/prism-objectivec.js +0 -14
  79. package/dist/cjs/node_modules/prismjs/components/prism-powershell.js +0 -60
  80. package/dist/cjs/node_modules/prismjs/components/prism-python.js +0 -67
  81. package/dist/cjs/node_modules/prismjs/components/prism-rust.js +0 -130
  82. package/dist/cjs/node_modules/prismjs/components/prism-sql.js +0 -34
  83. package/dist/cjs/node_modules/prismjs/components/prism-swift.js +0 -150
  84. package/dist/cjs/node_modules/prismjs/components/prism-typescript.js +0 -62
  85. package/dist/cjs/node_modules/prismjs/prism.js +0 -1951
  86. package/dist/cjs/packages/lexical/src/components/StickyComponent.js +0 -221
  87. package/dist/cjs/packages/lexical/src/index.js +0 -7
  88. package/dist/cjs/packages/lexical/src/nodes/StickyNode.js +0 -218
  89. package/dist/cjs/packages/lexical/src/plugins/StickyPlugin.js +0 -20
  90. package/dist/esm/_virtual/prism.js +0 -5
  91. package/dist/esm/editor/Lexical.module.css +0 -1
  92. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -423
  93. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -19
  94. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -18
  95. package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +0 -1121
  96. package/dist/esm/node_modules/@lexical/code/LexicalCode.js +0 -21
  97. package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +0 -32
  98. package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +0 -244
  99. package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +0 -18
  100. package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +0 -17
  101. package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +0 -463
  102. package/dist/esm/node_modules/@lexical/link/LexicalLink.js +0 -17
  103. package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +0 -16
  104. package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +0 -1262
  105. package/dist/esm/node_modules/@lexical/list/LexicalList.js +0 -23
  106. package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +0 -16
  107. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -781
  108. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +0 -23
  109. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -18
  110. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -957
  111. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +0 -26
  112. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -16
  113. package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +0 -2754
  114. package/dist/esm/node_modules/@lexical/table/LexicalTable.js +0 -20
  115. package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +0 -17
  116. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -839
  117. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +0 -26
  118. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -17
  119. package/dist/esm/node_modules/@mdi/js/mdi.js +0 -7
  120. package/dist/esm/node_modules/prismjs/components/prism-c.js +0 -82
  121. package/dist/esm/node_modules/prismjs/components/prism-clike.js +0 -33
  122. package/dist/esm/node_modules/prismjs/components/prism-cpp.js +0 -101
  123. package/dist/esm/node_modules/prismjs/components/prism-css.js +0 -66
  124. package/dist/esm/node_modules/prismjs/components/prism-java.js +0 -126
  125. package/dist/esm/node_modules/prismjs/components/prism-javascript.js +0 -174
  126. package/dist/esm/node_modules/prismjs/components/prism-markdown.js +0 -417
  127. package/dist/esm/node_modules/prismjs/components/prism-markup.js +0 -188
  128. package/dist/esm/node_modules/prismjs/components/prism-objectivec.js +0 -14
  129. package/dist/esm/node_modules/prismjs/components/prism-powershell.js +0 -60
  130. package/dist/esm/node_modules/prismjs/components/prism-python.js +0 -67
  131. package/dist/esm/node_modules/prismjs/components/prism-rust.js +0 -130
  132. package/dist/esm/node_modules/prismjs/components/prism-sql.js +0 -34
  133. package/dist/esm/node_modules/prismjs/components/prism-swift.js +0 -150
  134. package/dist/esm/node_modules/prismjs/components/prism-typescript.js +0 -62
  135. package/dist/esm/node_modules/prismjs/prism.js +0 -1951
  136. package/dist/esm/packages/lexical/src/components/StickyComponent.js +0 -221
  137. package/dist/esm/packages/lexical/src/index.js +0 -3
  138. package/dist/esm/packages/lexical/src/nodes/StickyNode.js +0 -216
  139. package/dist/esm/packages/lexical/src/plugins/StickyPlugin.js +0 -20
  140. package/dist/types/components/StickyComponent.d.ts +0 -9
  141. package/dist/types/nodes/StickyNode.d.ts +0 -35
  142. package/dist/types/plugins/StickyPlugin.d.ts +0 -1
  143. package/src/components/StickyComponent.tsx +0 -271
  144. package/src/nodes/StickyNode.tsx +0 -249
  145. /package/dist/cjs/{packages/lexical/src/editor → editor}/theme.js +0 -0
  146. /package/dist/cjs/{packages/lexical/src/utils → utils}/index.js +0 -0
  147. /package/dist/esm/{packages/lexical/src/editor → editor}/theme.js +0 -0
  148. /package/dist/esm/{packages/lexical/src/utils → utils}/index.js +0 -0
@@ -21,12 +21,8 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- import {
25
- isArray,
26
- isObject,
27
- isString,
28
- matchString,
29
- } from "@react-fabric/utilities";
24
+ import type { LngLatLike } from "@react-fabric/utilities";
25
+ import { convertToLonLat } from "@react-fabric/utilities";
30
26
 
31
27
  export function isHTMLElement(x: unknown): x is HTMLElement {
32
28
  return x instanceof HTMLElement;
@@ -70,10 +66,7 @@ export class Point {
70
66
  }
71
67
 
72
68
  public calcDistanceTo(point: Point): number {
73
- return Math.sqrt(
74
- Math.pow(this.calcDeltaXTo(point), 2) +
75
- Math.pow(this.calcDeltaYTo(point), 2),
76
- );
69
+ return Math.sqrt(Math.pow(this.calcDeltaXTo(point), 2) + Math.pow(this.calcDeltaYTo(point), 2));
77
70
  }
78
71
  }
79
72
 
@@ -98,11 +91,9 @@ export class Rect {
98
91
  private readonly _bottom: number;
99
92
 
100
93
  constructor(left: number, top: number, right: number, bottom: number) {
101
- const [physicTop, physicBottom] =
102
- top <= bottom ? [top, bottom] : [bottom, top];
94
+ const [physicTop, physicBottom] = top <= bottom ? [top, bottom] : [bottom, top];
103
95
 
104
- const [physicLeft, physicRight] =
105
- left <= right ? [left, right] : [right, left];
96
+ const [physicLeft, physicRight] = left <= right ? [left, right] : [right, left];
106
97
 
107
98
  this._top = physicTop;
108
99
  this._right = physicRight;
@@ -135,12 +126,7 @@ export class Rect {
135
126
  }
136
127
 
137
128
  public equals({ top, left, bottom, right }: Rect): boolean {
138
- return (
139
- top === this._top &&
140
- bottom === this._bottom &&
141
- left === this._left &&
142
- right === this._right
143
- );
129
+ return top === this._top && bottom === this._bottom && left === this._left && right === this._right;
144
130
  }
145
131
 
146
132
  public contains({ x, y }: Point): ContainsPointReturn;
@@ -154,8 +140,7 @@ export class Rect {
154
140
  const isOnLeftSide = x < this._left;
155
141
  const isOnRightSide = x > this._right;
156
142
 
157
- const result =
158
- !isOnTopSide && !isOnBottomSide && !isOnLeftSide && !isOnRightSide;
143
+ const result = !isOnTopSide && !isOnBottomSide && !isOnLeftSide && !isOnRightSide;
159
144
 
160
145
  return {
161
146
  reason: {
@@ -192,30 +177,15 @@ export class Rect {
192
177
  return maxX - minX <= w1 + w2 && maxY - minY <= h1 + h2;
193
178
  }
194
179
 
195
- public generateNewRect({
196
- left = this.left,
197
- top = this.top,
198
- right = this.right,
199
- bottom = this.bottom,
200
- }): Rect {
180
+ public generateNewRect({ left = this.left, top = this.top, right = this.right, bottom = this.bottom }): Rect {
201
181
  return new Rect(left, top, right, bottom);
202
182
  }
203
183
 
204
- static fromLTRB(
205
- left: number,
206
- top: number,
207
- right: number,
208
- bottom: number,
209
- ): Rect {
184
+ static fromLTRB(left: number, top: number, right: number, bottom: number): Rect {
210
185
  return new Rect(left, top, right, bottom);
211
186
  }
212
187
 
213
- static fromLWTH(
214
- left: number,
215
- width: number,
216
- top: number,
217
- height: number,
218
- ): Rect {
188
+ static fromLWTH(left: number, width: number, top: number, height: number): Rect {
219
189
  return new Rect(left, top, left + width, top + height);
220
190
  }
221
191
 
@@ -231,73 +201,7 @@ export class Rect {
231
201
  }
232
202
  }
233
203
 
234
- export const convertLatLng = (lonLat: AnyObject) => {
235
- if (
236
- (isArray(lonLat) && lonLat.length === 2) ||
237
- (isArray(lonLat) && lonLat.length === 3)
238
- ) {
239
- return [Number(lonLat[0]), Number(lonLat[1])];
240
- }
241
-
242
- if (isObject(lonLat)) {
243
- if ("longitude" in lonLat) {
244
- return [lonLat.longitude, lonLat.latitude];
245
- }
246
- return ["lon" in lonLat ? lonLat.lon : lonLat.lng, lonLat.lat];
247
- }
248
-
249
- if (isString(lonLat)) {
250
- const [lat, lon] = lonLat.split(",");
251
- return [+lon, +lat];
252
- }
253
-
254
- throw Error("Invalid geo cooredinates");
255
- };
256
-
257
- export const convertToDMS = (coord: number, isLat = false) => {
258
- const degree = Math.floor(coord);
259
- const hour = (coord - degree) * 60;
260
- const minute = (hour - Math.floor(hour)) * 60;
261
-
262
- return `${degree}˚${Math.floor(hour)}'${minute.toFixed(2)}"${
263
- coord < 0 ? (isLat ? "S" : "W") : isLat ? "N" : "E"
264
- }`;
265
- };
266
-
267
- export const getLocationAsText = (latlon: AnyObject) => {
268
- const [lon, lat] = convertLatLng(latlon);
269
- return `${convertToDMS(lat, true)}, ${convertToDMS(lon)}`;
270
- };
271
-
272
- export const getLocationUrl = (latlon: AnyObject) => {
273
- const [lon, lat] = convertLatLng(latlon);
204
+ export const getLocationUrl = (latlon: LngLatLike) => {
205
+ const [lon, lat] = convertToLonLat(latlon);
274
206
  return `https://google.com/maps/?q=${lat},${lon}`;
275
207
  };
276
-
277
- export const bookmarksFilterHookMatcher = (
278
- bookmark: KeyValue,
279
- query: string,
280
- ) => {
281
- return (
282
- matchString(bookmark.subtype ?? bookmark.type, query) ||
283
- matchString(bookmark.fileName ?? bookmark.name, query) ||
284
- ("message" in bookmark && matchString(bookmark.message ?? "", query)) ||
285
- ("title" in bookmark && matchString(bookmark.title ?? "", query)) ||
286
- ("url" in bookmark && matchString(bookmark.url ?? "", query)) ||
287
- ("category" in bookmark && matchString(bookmark.category ?? "", query)) ||
288
- ("device" in bookmark && matchString(bookmark.device ?? "", query)) ||
289
- ("browser" in bookmark && matchString(bookmark.browser ?? "", query)) ||
290
- ("from" in bookmark &&
291
- bookmark.from.phone &&
292
- matchString(bookmark.from.phone ?? "", query)) ||
293
- ("from" in bookmark &&
294
- bookmark.from.name &&
295
- matchString(bookmark.from.name ?? "", query)) ||
296
- ("to" in bookmark &&
297
- bookmark.to.phone &&
298
- matchString(bookmark.to.phone ?? "", query)) ||
299
- ("to" in bookmark &&
300
- bookmark.to.name &&
301
- matchString(bookmark.to.name ?? "", query))
302
- );
303
- };
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- var prism = {exports: {}};
4
-
5
- exports.__module = prism;
@@ -1 +0,0 @@
1
- @layer util{.lexicalEditor,.lexicalToolbar{margin:0 auto;width:21cm}.lexicalEditor :global{.editor-container.editor-container.editor-container{background-color:#fff;color:#0f172a;font-family:Sakkal Majalla;font-size:18px}.editor-heading-h1{font-size:1.5em;margin-bottom:1.5em;text-transform:capitalize}.editor-heading-h1,.editor-heading-h2{font-weight:600;line-height:1.5;margin-top:1.5em;padding:0 4px}.editor-heading-h2{font-size:1.25em;margin-bottom:1em}.editor-heading-h6{color:#b45309;font-size:.875em;font-weight:600;line-height:1.25;margin-bottom:1.5em;margin-top:1.5em}.editor-paragraph{font-size:1em}.editor-paragraph,.editor-quote{line-height:1.5;margin-bottom:1.5em;margin-top:1.5em}.editor-quote{border-color:#64748b;padding-inline-start:1em}.editor-code,.editor-quote{border-inline-start-width:4px;color:#1e293b;display:block;font-size:1.125em}.editor-code{background-color:#e2e8f0;line-height:1.5;margin-bottom:1.5em;margin-top:1.5em;padding:1em}.editor-textUnderline{text-decoration:underline}.editor-textStrikethrough{text-decoration:line-through}.editor-textUnderlineStrikethrough{text-decoration:underline line-through}.editor-page-break{page-break-after:always}.editor-no-break{page-break-inside:avoid}.editor-textSmall{font-size:.875em}.editor-textBold{font-weight:600}.editor-textItalic{font-style:italic}.editor-textMuted{color:#4b5563}.editor-list-ul{list-style:disc;padding-inline-start:.5em}.editor-list-ol{list-style:decimal;padding-inline-start:.5em}.editor-listItem{margin-inline-start:1em;text-align:start}@media print{body,html{margin:0;min-height:100vh}div,h1,h2,h3,h4,h5,h6,p,span{box-sizing:border-box}body.report-template{background-size:0;min-height:100vh}body:after{background-image:inherit;content:"";height:100vh;inset:0;margin:0 auto;max-width:21cm;position:fixed;-webkit-print-color-adjust:exact;print-color-adjust:exact;width:100vw;z-index:10}.editor-page-break>div,.sticky__container{display:none}.editor-container{position:relative}.editor-editor{box-sizing:border-box;padding:0 2cm}}}}
@@ -1,432 +0,0 @@
1
- 'use strict';
2
-
3
- var LexicalHtml = require('../html/LexicalHtml.js');
4
- var LexicalSelection = require('../selection/LexicalSelection.js');
5
- var LexicalUtils = require('../utils/LexicalUtils.js');
6
- var lexical = require('lexical');
7
-
8
- /**
9
- * Copyright (c) Meta Platforms, Inc. and affiliates.
10
- *
11
- * This source code is licensed under the MIT license found in the
12
- * LICENSE file in the root directory of this source tree.
13
- *
14
- */
15
-
16
-
17
- /**
18
- * Copyright (c) Meta Platforms, Inc. and affiliates.
19
- *
20
- * This source code is licensed under the MIT license found in the
21
- * LICENSE file in the root directory of this source tree.
22
- *
23
- */
24
-
25
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
26
-
27
- /**
28
- * Copyright (c) Meta Platforms, Inc. and affiliates.
29
- *
30
- * This source code is licensed under the MIT license found in the
31
- * LICENSE file in the root directory of this source tree.
32
- *
33
- */
34
-
35
- const getDOMSelection = targetWindow => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
36
- /**
37
- * Returns the *currently selected* Lexical content as an HTML string, relying on the
38
- * logic defined in the exportDOM methods on the LexicalNode classes. Note that
39
- * this will not return the HTML content of the entire editor (unless all the content is included
40
- * in the current selection).
41
- *
42
- * @param editor - LexicalEditor instance to get HTML content from
43
- * @param selection - The selection to use (default is $getSelection())
44
- * @returns a string of HTML content
45
- */
46
- function $getHtmlContent(editor, selection = lexical.$getSelection()) {
47
- if (selection == null) {
48
- {
49
- throw Error(`Expected valid LexicalSelection`);
50
- }
51
- }
52
-
53
- // If we haven't selected anything
54
- if (lexical.$isRangeSelection(selection) && selection.isCollapsed() || selection.getNodes().length === 0) {
55
- return '';
56
- }
57
- return LexicalHtml.$generateHtmlFromNodes(editor, selection);
58
- }
59
-
60
- /**
61
- * Returns the *currently selected* Lexical content as a JSON string, relying on the
62
- * logic defined in the exportJSON methods on the LexicalNode classes. Note that
63
- * this will not return the JSON content of the entire editor (unless all the content is included
64
- * in the current selection).
65
- *
66
- * @param editor - LexicalEditor instance to get the JSON content from
67
- * @param selection - The selection to use (default is $getSelection())
68
- * @returns
69
- */
70
- function $getLexicalContent(editor, selection = lexical.$getSelection()) {
71
- if (selection == null) {
72
- {
73
- throw Error(`Expected valid LexicalSelection`);
74
- }
75
- }
76
-
77
- // If we haven't selected anything
78
- if (lexical.$isRangeSelection(selection) && selection.isCollapsed() || selection.getNodes().length === 0) {
79
- return null;
80
- }
81
- return JSON.stringify($generateJSONFromSelectedNodes(editor, selection));
82
- }
83
-
84
- /**
85
- * Attempts to insert content of the mime-types text/plain or text/uri-list from
86
- * the provided DataTransfer object into the editor at the provided selection.
87
- * text/uri-list is only used if text/plain is not also provided.
88
- *
89
- * @param dataTransfer an object conforming to the [DataTransfer interface] (https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface)
90
- * @param selection the selection to use as the insertion point for the content in the DataTransfer object
91
- */
92
- function $insertDataTransferForPlainText(dataTransfer, selection) {
93
- const text = dataTransfer.getData('text/plain') || dataTransfer.getData('text/uri-list');
94
- if (text != null) {
95
- selection.insertRawText(text);
96
- }
97
- }
98
-
99
- /**
100
- * Attempts to insert content of the mime-types application/x-lexical-editor, text/html,
101
- * text/plain, or text/uri-list (in descending order of priority) from the provided DataTransfer
102
- * object into the editor at the provided selection.
103
- *
104
- * @param dataTransfer an object conforming to the [DataTransfer interface] (https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface)
105
- * @param selection the selection to use as the insertion point for the content in the DataTransfer object
106
- * @param editor the LexicalEditor the content is being inserted into.
107
- */
108
- function $insertDataTransferForRichText(dataTransfer, selection, editor) {
109
- const lexicalString = dataTransfer.getData('application/x-lexical-editor');
110
- if (lexicalString) {
111
- try {
112
- const payload = JSON.parse(lexicalString);
113
- if (payload.namespace === editor._config.namespace && Array.isArray(payload.nodes)) {
114
- const nodes = $generateNodesFromSerializedNodes(payload.nodes);
115
- return $insertGeneratedNodes(editor, nodes, selection);
116
- }
117
- } catch (_unused) {
118
- // Fail silently.
119
- }
120
- }
121
- const htmlString = dataTransfer.getData('text/html');
122
- if (htmlString) {
123
- try {
124
- const parser = new DOMParser();
125
- const dom = parser.parseFromString(htmlString, 'text/html');
126
- const nodes = LexicalHtml.$generateNodesFromDOM(editor, dom);
127
- return $insertGeneratedNodes(editor, nodes, selection);
128
- } catch (_unused2) {
129
- // Fail silently.
130
- }
131
- }
132
-
133
- // Multi-line plain text in rich text mode pasted as separate paragraphs
134
- // instead of single paragraph with linebreaks.
135
- // Webkit-specific: Supports read 'text/uri-list' in clipboard.
136
- const text = dataTransfer.getData('text/plain') || dataTransfer.getData('text/uri-list');
137
- if (text != null) {
138
- if (lexical.$isRangeSelection(selection)) {
139
- const parts = text.split(/(\r?\n|\t)/);
140
- if (parts[parts.length - 1] === '') {
141
- parts.pop();
142
- }
143
- for (let i = 0; i < parts.length; i++) {
144
- const currentSelection = lexical.$getSelection();
145
- if (lexical.$isRangeSelection(currentSelection)) {
146
- const part = parts[i];
147
- if (part === '\n' || part === '\r\n') {
148
- currentSelection.insertParagraph();
149
- } else if (part === '\t') {
150
- currentSelection.insertNodes([lexical.$createTabNode()]);
151
- } else {
152
- currentSelection.insertText(part);
153
- }
154
- }
155
- }
156
- } else {
157
- selection.insertRawText(text);
158
- }
159
- }
160
- }
161
-
162
- /**
163
- * Inserts Lexical nodes into the editor using different strategies depending on
164
- * some simple selection-based heuristics. If you're looking for a generic way to
165
- * to insert nodes into the editor at a specific selection point, you probably want
166
- * {@link lexical.$insertNodes}
167
- *
168
- * @param editor LexicalEditor instance to insert the nodes into.
169
- * @param nodes The nodes to insert.
170
- * @param selection The selection to insert the nodes into.
171
- */
172
- function $insertGeneratedNodes(editor, nodes, selection) {
173
- if (!editor.dispatchCommand(lexical.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, {
174
- nodes,
175
- selection
176
- })) {
177
- selection.insertNodes(nodes);
178
- }
179
- return;
180
- }
181
- function exportNodeToJSON(node) {
182
- const serializedNode = node.exportJSON();
183
- const nodeClass = node.constructor;
184
- if (serializedNode.type !== nodeClass.getType()) {
185
- {
186
- throw Error(`LexicalNode: Node ${nodeClass.name} does not implement .exportJSON().`);
187
- }
188
- }
189
- if (lexical.$isElementNode(node)) {
190
- const serializedChildren = serializedNode.children;
191
- if (!Array.isArray(serializedChildren)) {
192
- {
193
- throw Error(`LexicalNode: Node ${nodeClass.name} is an element but .exportJSON() does not have a children array.`);
194
- }
195
- }
196
- }
197
- return serializedNode;
198
- }
199
- function $appendNodesToJSON(editor, selection, currentNode, targetArray = []) {
200
- let shouldInclude = selection !== null ? currentNode.isSelected(selection) : true;
201
- const shouldExclude = lexical.$isElementNode(currentNode) && currentNode.excludeFromCopy('html');
202
- let target = currentNode;
203
- if (selection !== null) {
204
- let clone = lexical.$cloneWithProperties(currentNode);
205
- clone = lexical.$isTextNode(clone) && selection !== null ? LexicalSelection.$sliceSelectedTextNodeContent(selection, clone) : clone;
206
- target = clone;
207
- }
208
- const children = lexical.$isElementNode(target) ? target.getChildren() : [];
209
- const serializedNode = exportNodeToJSON(target);
210
-
211
- // TODO: TextNode calls getTextContent() (NOT node.__text) within its exportJSON method
212
- // which uses getLatest() to get the text from the original node with the same key.
213
- // This is a deeper issue with the word "clone" here, it's still a reference to the
214
- // same node as far as the LexicalEditor is concerned since it shares a key.
215
- // We need a way to create a clone of a Node in memory with its own key, but
216
- // until then this hack will work for the selected text extract use case.
217
- if (lexical.$isTextNode(target)) {
218
- const text = target.__text;
219
- // If an uncollapsed selection ends or starts at the end of a line of specialized,
220
- // TextNodes, such as code tokens, we will get a 'blank' TextNode here, i.e., one
221
- // with text of length 0. We don't want this, it makes a confusing mess. Reset!
222
- if (text.length > 0) {
223
- serializedNode.text = text;
224
- } else {
225
- shouldInclude = false;
226
- }
227
- }
228
- for (let i = 0; i < children.length; i++) {
229
- const childNode = children[i];
230
- const shouldIncludeChild = $appendNodesToJSON(editor, selection, childNode, serializedNode.children);
231
- if (!shouldInclude && lexical.$isElementNode(currentNode) && shouldIncludeChild && currentNode.extractWithChild(childNode, selection, 'clone')) {
232
- shouldInclude = true;
233
- }
234
- }
235
- if (shouldInclude && !shouldExclude) {
236
- targetArray.push(serializedNode);
237
- } else if (Array.isArray(serializedNode.children)) {
238
- for (let i = 0; i < serializedNode.children.length; i++) {
239
- const serializedChildNode = serializedNode.children[i];
240
- targetArray.push(serializedChildNode);
241
- }
242
- }
243
- return shouldInclude;
244
- }
245
-
246
- // TODO why $ function with Editor instance?
247
- /**
248
- * Gets the Lexical JSON of the nodes inside the provided Selection.
249
- *
250
- * @param editor LexicalEditor to get the JSON content from.
251
- * @param selection Selection to get the JSON content from.
252
- * @returns an object with the editor namespace and a list of serializable nodes as JavaScript objects.
253
- */
254
- function $generateJSONFromSelectedNodes(editor, selection) {
255
- const nodes = [];
256
- const root = lexical.$getRoot();
257
- const topLevelChildren = root.getChildren();
258
- for (let i = 0; i < topLevelChildren.length; i++) {
259
- const topLevelNode = topLevelChildren[i];
260
- $appendNodesToJSON(editor, selection, topLevelNode, nodes);
261
- }
262
- return {
263
- namespace: editor._config.namespace,
264
- nodes
265
- };
266
- }
267
-
268
- /**
269
- * This method takes an array of objects conforming to the BaseSeralizedNode interface and returns
270
- * an Array containing instances of the corresponding LexicalNode classes registered on the editor.
271
- * Normally, you'd get an Array of BaseSerialized nodes from {@link $generateJSONFromSelectedNodes}
272
- *
273
- * @param serializedNodes an Array of objects conforming to the BaseSerializedNode interface.
274
- * @returns an Array of Lexical Node objects.
275
- */
276
- function $generateNodesFromSerializedNodes(serializedNodes) {
277
- const nodes = [];
278
- for (let i = 0; i < serializedNodes.length; i++) {
279
- const serializedNode = serializedNodes[i];
280
- const node = lexical.$parseSerializedNode(serializedNode);
281
- if (lexical.$isTextNode(node)) {
282
- LexicalSelection.$addNodeStyle(node);
283
- }
284
- nodes.push(node);
285
- }
286
- return nodes;
287
- }
288
- const EVENT_LATENCY = 50;
289
- let clipboardEventTimeout = null;
290
-
291
- // TODO custom selection
292
- // TODO potentially have a node customizable version for plain text
293
- /**
294
- * Copies the content of the current selection to the clipboard in
295
- * text/plain, text/html, and application/x-lexical-editor (Lexical JSON)
296
- * formats.
297
- *
298
- * @param editor the LexicalEditor instance to copy content from
299
- * @param event the native browser ClipboardEvent to add the content to.
300
- * @returns
301
- */
302
- async function copyToClipboard(editor, event, data) {
303
- if (clipboardEventTimeout !== null) {
304
- // Prevent weird race conditions that can happen when this function is run multiple times
305
- // synchronously. In the future, we can do better, we can cancel/override the previously running job.
306
- return false;
307
- }
308
- if (event !== null) {
309
- return new Promise((resolve, reject) => {
310
- editor.update(() => {
311
- resolve($copyToClipboardEvent(editor, event, data));
312
- });
313
- });
314
- }
315
- const rootElement = editor.getRootElement();
316
- const windowDocument = editor._window == null ? window.document : editor._window.document;
317
- const domSelection = getDOMSelection(editor._window);
318
- if (rootElement === null || domSelection === null) {
319
- return false;
320
- }
321
- const element = windowDocument.createElement('span');
322
- element.style.cssText = 'position: fixed; top: -1000px;';
323
- element.append(windowDocument.createTextNode('#'));
324
- rootElement.append(element);
325
- const range = new Range();
326
- range.setStart(element, 0);
327
- range.setEnd(element, 1);
328
- domSelection.removeAllRanges();
329
- domSelection.addRange(range);
330
- return new Promise((resolve, reject) => {
331
- const removeListener = editor.registerCommand(lexical.COPY_COMMAND, secondEvent => {
332
- if (LexicalUtils.objectKlassEquals(secondEvent, ClipboardEvent)) {
333
- removeListener();
334
- if (clipboardEventTimeout !== null) {
335
- window.clearTimeout(clipboardEventTimeout);
336
- clipboardEventTimeout = null;
337
- }
338
- resolve($copyToClipboardEvent(editor, secondEvent, data));
339
- }
340
- // Block the entire copy flow while we wait for the next ClipboardEvent
341
- return true;
342
- }, lexical.COMMAND_PRIORITY_CRITICAL);
343
- // If the above hack execCommand hack works, this timeout code should never fire. Otherwise,
344
- // the listener will be quickly freed so that the user can reuse it again
345
- clipboardEventTimeout = window.setTimeout(() => {
346
- removeListener();
347
- clipboardEventTimeout = null;
348
- resolve(false);
349
- }, EVENT_LATENCY);
350
- windowDocument.execCommand('copy');
351
- element.remove();
352
- });
353
- }
354
-
355
- // TODO shouldn't pass editor (pass namespace directly)
356
- function $copyToClipboardEvent(editor, event, data) {
357
- if (data === undefined) {
358
- const domSelection = getDOMSelection(editor._window);
359
- if (!domSelection) {
360
- return false;
361
- }
362
- const anchorDOM = domSelection.anchorNode;
363
- const focusDOM = domSelection.focusNode;
364
- if (anchorDOM !== null && focusDOM !== null && !lexical.isSelectionWithinEditor(editor, anchorDOM, focusDOM)) {
365
- return false;
366
- }
367
- const selection = lexical.$getSelection();
368
- if (selection === null) {
369
- return false;
370
- }
371
- data = $getClipboardDataFromSelection(selection);
372
- }
373
- event.preventDefault();
374
- const clipboardData = event.clipboardData;
375
- if (clipboardData === null) {
376
- return false;
377
- }
378
- setLexicalClipboardDataTransfer(clipboardData, data);
379
- return true;
380
- }
381
- const clipboardDataFunctions = [['text/html', $getHtmlContent], ['application/x-lexical-editor', $getLexicalContent]];
382
-
383
- /**
384
- * Serialize the content of the current selection to strings in
385
- * text/plain, text/html, and application/x-lexical-editor (Lexical JSON)
386
- * formats (as available).
387
- *
388
- * @param selection the selection to serialize (defaults to $getSelection())
389
- * @returns LexicalClipboardData
390
- */
391
- function $getClipboardDataFromSelection(selection = lexical.$getSelection()) {
392
- const clipboardData = {
393
- 'text/plain': selection ? selection.getTextContent() : ''
394
- };
395
- if (selection) {
396
- const editor = lexical.$getEditor();
397
- for (const [mimeType, $editorFn] of clipboardDataFunctions) {
398
- const v = $editorFn(editor, selection);
399
- if (v !== null) {
400
- clipboardData[mimeType] = v;
401
- }
402
- }
403
- }
404
- return clipboardData;
405
- }
406
-
407
- /**
408
- * Call setData on the given clipboardData for each MIME type present
409
- * in the given data (from {@link $getClipboardDataFromSelection})
410
- *
411
- * @param clipboardData the event.clipboardData to populate from data
412
- * @param data The lexical data
413
- */
414
- function setLexicalClipboardDataTransfer(clipboardData, data) {
415
- for (const k in data) {
416
- const v = data[k];
417
- if (v !== undefined) {
418
- clipboardData.setData(k, v);
419
- }
420
- }
421
- }
422
-
423
- exports.$generateJSONFromSelectedNodes = $generateJSONFromSelectedNodes;
424
- exports.$generateNodesFromSerializedNodes = $generateNodesFromSerializedNodes;
425
- exports.$getClipboardDataFromSelection = $getClipboardDataFromSelection;
426
- exports.$getHtmlContent = $getHtmlContent;
427
- exports.$getLexicalContent = $getLexicalContent;
428
- exports.$insertDataTransferForPlainText = $insertDataTransferForPlainText;
429
- exports.$insertDataTransferForRichText = $insertDataTransferForRichText;
430
- exports.$insertGeneratedNodes = $insertGeneratedNodes;
431
- exports.copyToClipboard = copyToClipboard;
432
- exports.setLexicalClipboardDataTransfer = setLexicalClipboardDataTransfer;
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- var LexicalClipboard_dev = require('./LexicalClipboard.dev.js');
4
- var LexicalClipboard_prod = require('./LexicalClipboard.prod.js');
5
-
6
- /**
7
- * Copyright (c) Meta Platforms, Inc. and affiliates.
8
- *
9
- * This source code is licensed under the MIT license found in the
10
- * LICENSE file in the root directory of this source tree.
11
- *
12
- */
13
-
14
- const mod = process.env.NODE_ENV === 'development' ? LexicalClipboard_dev : LexicalClipboard_prod;
15
- const $getClipboardDataFromSelection = mod.$getClipboardDataFromSelection;
16
- const $insertDataTransferForRichText = mod.$insertDataTransferForRichText;
17
- const copyToClipboard = mod.copyToClipboard;
18
-
19
- exports.$getClipboardDataFromSelection = $getClipboardDataFromSelection;
20
- exports.$insertDataTransferForRichText = $insertDataTransferForRichText;
21
- exports.copyToClipboard = copyToClipboard;
@@ -1,27 +0,0 @@
1
- 'use strict';
2
-
3
- var LexicalHtml = require('../html/LexicalHtml.js');
4
- var LexicalSelection = require('../selection/LexicalSelection.js');
5
- var LexicalUtils = require('../utils/LexicalUtils.js');
6
- var lexical = require('lexical');
7
-
8
- /**
9
- * Copyright (c) Meta Platforms, Inc. and affiliates.
10
- *
11
- * This source code is licensed under the MIT license found in the
12
- * LICENSE file in the root directory of this source tree.
13
- *
14
- */
15
-
16
- function w(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var y=w((function(t){const e=new URLSearchParams;e.append("code",t);for(let t=1;t<arguments.length;t++)e.append("v",arguments[t]);throw Error(`Minified Lexical error #${t}; visit https://lexical.dev/docs/error?${e} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const v="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,C=t=>v?(t||window).getSelection():null;function D(e,n=lexical.$getSelection()){return null==n&&y(166),lexical.$isRangeSelection(n)&&n.isCollapsed()||0===n.getNodes().length?"":LexicalHtml.$generateHtmlFromNodes(e,n)}function N(t,e=lexical.$getSelection()){return null==e&&y(166),lexical.$isRangeSelection(e)&&e.isCollapsed()||0===e.getNodes().length?null:JSON.stringify(R(t,e))}function _(t,e){const n=t.getData("text/plain")||t.getData("text/uri-list");null!=n&&e.insertRawText(n);}function T(t,n,o){const r=t.getData("application/x-lexical-editor");if(r)try{const t=JSON.parse(r);if(t.namespace===o._config.namespace&&Array.isArray(t.nodes)){return S(o,E(t.nodes),n)}}catch(t){}const s=t.getData("text/html");if(s)try{const t=(new DOMParser).parseFromString(s,"text/html");return S(o,LexicalHtml.$generateNodesFromDOM(o,t),n)}catch(t){}const a=t.getData("text/plain")||t.getData("text/uri-list");if(null!=a)if(lexical.$isRangeSelection(n)){const t=a.split(/(\r?\n|\t)/);""===t[t.length-1]&&t.pop();for(let e=0;e<t.length;e++){const n=lexical.$getSelection();if(lexical.$isRangeSelection(n)){const o=t[e];"\n"===o||"\r\n"===o?n.insertParagraph():"\t"===o?n.insertNodes([lexical.$createTabNode()]):n.insertText(o);}}}else n.insertRawText(a);}function S(t,e,n){t.dispatchCommand(lexical.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,{nodes:e,selection:n})||n.insertNodes(e);}function A(t,e,n,r=[]){let l=null===e||n.isSelected(e);const i=lexical.$isElementNode(n)&&n.excludeFromCopy("html");let c=n;if(null!==e){let t=lexical.$cloneWithProperties(n);t=lexical.$isTextNode(t)&&null!==e?LexicalSelection.$sliceSelectedTextNodeContent(e,t):t,c=t;}const s=lexical.$isElementNode(c)?c.getChildren():[],a=function(t){const e=t.exportJSON(),n=t.constructor;if(e.type!==n.getType()&&y(58,n.name),lexical.$isElementNode(t)){const t=e.children;Array.isArray(t)||y(59,n.name);}return e}(c);if(lexical.$isTextNode(c)){const t=c.__text;t.length>0?a.text=t:l=!1;}for(let o=0;o<s.length;o++){const r=s[o],i=A(t,e,r,a.children);!l&&lexical.$isElementNode(n)&&i&&n.extractWithChild(r,e,"clone")&&(l=!0);}if(l&&!i)r.push(a);else if(Array.isArray(a.children))for(let t=0;t<a.children.length;t++){const e=a.children[t];r.push(e);}return l}function R(t,e){const n=[],o=lexical.$getRoot().getChildren();for(let r=0;r<o.length;r++){A(t,e,o[r],n);}return {namespace:t._config.namespace,nodes:n}}function E(t){const e=[];for(let o=0;o<t.length;o++){const r=t[o],l=lexical.$parseSerializedNode(r);lexical.$isTextNode(l)&&LexicalSelection.$addNodeStyle(l),e.push(l);}return e}let O=null;async function P(t,e,n){if(null!==O)return !1;if(null!==e)return new Promise(((o,r)=>{t.update((()=>{o(b(t,e,n));}));}));const o=t.getRootElement(),l=null==t._window?window.document:t._window.document,i=C(t._window);if(null===o||null===i)return !1;const c=l.createElement("span");c.style.cssText="position: fixed; top: -1000px;",c.append(l.createTextNode("#")),o.append(c);const s=new Range;return s.setStart(c,0),s.setEnd(c,1),i.removeAllRanges(),i.addRange(s),new Promise(((e,o)=>{const i=t.registerCommand(lexical.COPY_COMMAND,(o=>(LexicalUtils.objectKlassEquals(o,ClipboardEvent)&&(i(),null!==O&&(window.clearTimeout(O),O=null),e(b(t,o,n))),!0)),lexical.COMMAND_PRIORITY_CRITICAL);O=window.setTimeout((()=>{i(),O=null,e(!1);}),50),l.execCommand("copy"),c.remove();}))}function b(t,e,n){if(void 0===n){const e=C(t._window);if(!e)return !1;const o=e.anchorNode,r=e.focusNode;if(null!==o&&null!==r&&!lexical.isSelectionWithinEditor(t,o,r))return !1;const l=lexical.$getSelection();if(null===l)return !1;n=M(l);}e.preventDefault();const o=e.clipboardData;return null!==o&&(F(o,n),!0)}const J=[["text/html",D],["application/x-lexical-editor",N]];function M(t=lexical.$getSelection()){const e={"text/plain":t?t.getTextContent():""};if(t){const n=lexical.$getEditor();for(const[o,r]of J){const l=r(n,t);null!==l&&(e[o]=l);}}return e}function F(t,e){for(const n in e){const o=e[n];void 0!==o&&t.setData(n,o);}}
17
-
18
- exports.$generateJSONFromSelectedNodes = R;
19
- exports.$generateNodesFromSerializedNodes = E;
20
- exports.$getClipboardDataFromSelection = M;
21
- exports.$getHtmlContent = D;
22
- exports.$getLexicalContent = N;
23
- exports.$insertDataTransferForPlainText = _;
24
- exports.$insertDataTransferForRichText = T;
25
- exports.$insertGeneratedNodes = S;
26
- exports.copyToClipboard = P;
27
- exports.setLexicalClipboardDataTransfer = F;