@inshapardaz/likhari-react 0.1.43-dev.323 → 0.1.43

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.
@@ -1 +1 @@
1
- {"version":3,"file":"joinLinesActions.d.ts","sourceRoot":"","sources":["../../src/join/joinLinesActions.ts"],"names":[],"mappings":"AAoCA,wBAAgB,aAAa,IAAI,OAAO,CAKvC;AAiDD;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CA2B5C"}
1
+ {"version":3,"file":"joinLinesActions.d.ts","sourceRoot":"","sources":["../../src/join/joinLinesActions.ts"],"names":[],"mappings":"AAyBA,wBAAgB,aAAa,IAAI,OAAO,CAKvC;AAuCD;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAyB5C"}
@@ -1,4 +1,4 @@
1
- import { $createTextNode, $getSelection, $isLineBreakNode, $isParagraphNode, $isRangeSelection, $isTextNode, $createParagraphNode, } from 'lexical';
1
+ import { $createTextNode, $getSelection, $isLineBreakNode, $isParagraphNode, $isRangeSelection, $createParagraphNode, } from 'lexical';
2
2
  function $paragraphsInSelection(selection) {
3
3
  const seen = new Set();
4
4
  const paragraphs = [];
@@ -11,30 +11,13 @@ function $paragraphsInSelection(selection) {
11
11
  }
12
12
  return paragraphs;
13
13
  }
14
- /**
15
- * Text nodes in the selection that hold a literal newline. Lexical shows these
16
- * as line breaks, but they are not line-break nodes: content loaded from
17
- * plain text or a foreign Lexical document can be shaped this way.
18
- */
19
- function $textNodesWithNewlines(selection) {
20
- return selection.getNodes().filter((node) => $isTextNode(node) && node.getTextContent().includes('\n'));
21
- }
22
14
  export function $canJoinLines() {
23
15
  const selection = $getSelection();
24
16
  if (!$isRangeSelection(selection) || selection.isCollapsed())
25
17
  return false;
26
18
  if ($paragraphsInSelection(selection).length > 1)
27
19
  return true;
28
- return selection.getNodes().some($isLineBreakNode) || $textNodesWithNewlines(selection).length > 0;
29
- }
30
- /** Replaces the newlines in the selected part of a text node, each by one space (none if one is already there). */
31
- function $replaceNewlinesInText(node, selection) {
32
- const [start, end] = selection.getStartEndPoints() ?? [];
33
- const text = node.getTextContent();
34
- const from = start && start.key === node.getKey() ? start.offset : 0;
35
- const to = end && end.key === node.getKey() ? end.offset : text.length;
36
- const joined = text.slice(from, to).replace(/[ \t]*\r?\n[ \t]*/g, ' ');
37
- node.setTextContent(text.slice(0, from) + joined + text.slice(to));
20
+ return selection.getNodes().some($isLineBreakNode);
38
21
  }
39
22
  /** A soft break becomes one space, unless the text either side already has a space there. */
40
23
  function $replaceBreakWithSpace(lineBreak) {
@@ -84,16 +67,13 @@ export function $joinSelectedLines() {
84
67
  const paragraphs = $paragraphsInSelection(selection);
85
68
  const nodes = selection.getNodes();
86
69
  const lineBreaks = nodes.filter($isLineBreakNode);
87
- const textsWithNewlines = $textNodesWithNewlines(selection);
88
- if (paragraphs.length < 2 && lineBreaks.length === 0 && textsWithNewlines.length === 0)
70
+ if (paragraphs.length < 2 && lineBreaks.length === 0)
89
71
  return false;
90
72
  const last = nodes[nodes.length - 1];
91
73
  const breakAfter = last?.getNextSibling();
92
74
  const trailingBreak = $isLineBreakNode(breakAfter) ? breakAfter : null;
93
75
  for (const lineBreak of lineBreaks)
94
76
  $replaceBreakWithSpace(lineBreak);
95
- for (const textNode of textsWithNewlines)
96
- $replaceNewlinesInText(textNode, selection);
97
77
  const [target, ...rest] = paragraphs;
98
78
  if (!target)
99
79
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inshapardaz/likhari-react",
3
- "version": "0.1.43-dev.323",
3
+ "version": "0.1.43",
4
4
  "description": "React implementation of the Likhari editor, built on @lexical/react.",
5
5
  "license": "MIT",
6
6
  "repository": {