x-star-editor 0.3.8 → 0.3.10

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.
@@ -156,7 +156,7 @@ export var editorRender = function editorRender(sourceCode) {
156
156
  if (stack.length) {
157
157
  // 如果栈不为空,说明为块级元素内的文本,每一行都应推到块级元素中
158
158
  if (lines[0]) {
159
- stack[stack.length - 1].element.append(delimiter ? createDelimiter(lines[0]) : lines[0]);
159
+ stack.at(-1).element.append(delimiter ? createDelimiter(lines[0]) : lines[0]);
160
160
  }
161
161
  for (var i = 1; i < lines.length; i++) {
162
162
  for (var j = stack.length - 1; j; j--) {
@@ -165,7 +165,7 @@ export var editorRender = function editorRender(sourceCode) {
165
165
  stack[0].element.append("\u200B");
166
166
  pushElement(0);
167
167
  if (lines[i]) {
168
- stack[stack.length - 1].element.append(delimiter ? createDelimiter(lines[i]) : lines[i]);
168
+ stack.at(-1).element.append(delimiter ? createDelimiter(lines[i]) : lines[i]);
169
169
  }
170
170
  }
171
171
  scanOffset += text.length;
@@ -190,10 +190,10 @@ export var editorRender = function editorRender(sourceCode) {
190
190
  _step;
191
191
  try {
192
192
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
193
- var _node$position, _node$position2;
193
+ var _node$position, _node$position$start, _node$position2, _node$position2$end;
194
194
  var node = _step.value;
195
- var startOffset = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : _node$position.start.offset;
196
- var endOffset = (_node$position2 = node.position) === null || _node$position2 === void 0 ? void 0 : _node$position2.end.offset;
195
+ var startOffset = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : (_node$position$start = _node$position.start) === null || _node$position$start === void 0 ? void 0 : _node$position$start.offset;
196
+ var endOffset = (_node$position2 = node.position) === null || _node$position2 === void 0 ? void 0 : (_node$position2$end = _node$position2.end) === null || _node$position2$end === void 0 ? void 0 : _node$position2$end.offset;
197
197
  if (startOffset === undefined || endOffset === undefined) {
198
198
  continue;
199
199
  }
@@ -223,12 +223,12 @@ export var editorRender = function editorRender(sourceCode) {
223
223
  if (stack.length > 1) {
224
224
  pushElement(stack.length - 1);
225
225
  } else {
226
- var _node$position3;
226
+ var _node$position3, _node$position3$start;
227
227
  // 如果栈大小为 1,说明为块级元素终点
228
228
  stack[0].element.append("\u200B");
229
229
  pushElement(0);
230
230
  // 记录行号,用于同步滚动
231
- block.dataset.line = "".concat((_node$position3 = node.position) === null || _node$position3 === void 0 ? void 0 : _node$position3.start.line);
231
+ block.dataset.line = "".concat((_node$position3 = node.position) === null || _node$position3 === void 0 ? void 0 : (_node$position3$start = _node$position3.start) === null || _node$position3$start === void 0 ? void 0 : _node$position3$start.line);
232
232
  pushBlock();
233
233
  scanOffset++;
234
234
  }
@@ -6,10 +6,10 @@ import { SKIP, visit } from 'unist-util-visit';
6
6
  var rehypeLine = function rehypeLine() {
7
7
  return function (root) {
8
8
  return visit(root, 'element', function (node) {
9
- var _node$properties, _node$position;
9
+ var _node$properties, _node$position, _node$position$start;
10
10
  (_node$properties = node.properties) !== null && _node$properties !== void 0 ? _node$properties : node.properties = {};
11
11
  // 记录行号,用于同步滚动
12
- node.properties['data-line'] = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : _node$position.start.line;
12
+ node.properties['data-line'] = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : (_node$position$start = _node$position.start) === null || _node$position$start === void 0 ? void 0 : _node$position$start.line;
13
13
  return SKIP;
14
14
  });
15
15
  };
@@ -156,8 +156,8 @@ var rehypeMath = function rehypeMath() {
156
156
  return SKIP;
157
157
  }
158
158
  if (node.type === 'text' && index !== null && parent) {
159
- var _node$position;
160
- var startOffset = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : _node$position.start.offset;
159
+ var _node$position, _node$position$start;
160
+ var startOffset = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : (_node$position$start = _node$position.start) === null || _node$position$start === void 0 ? void 0 : _node$position$start.offset;
161
161
  if (startOffset === undefined) {
162
162
  return;
163
163
  }
@@ -7,9 +7,9 @@ var rehypeRawPositions = function rehypeRawPositions() {
7
7
  return function (root) {
8
8
  var rawPositions = [];
9
9
  visit(root, 'raw', function (node) {
10
- var _node$position, _node$position2;
11
- var startOffset = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : _node$position.start.offset;
12
- var endOffset = (_node$position2 = node.position) === null || _node$position2 === void 0 ? void 0 : _node$position2.end.offset;
10
+ var _node$position, _node$position$start, _node$position2, _node$position2$end;
11
+ var startOffset = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : (_node$position$start = _node$position.start) === null || _node$position$start === void 0 ? void 0 : _node$position$start.offset;
12
+ var endOffset = (_node$position2 = node.position) === null || _node$position2 === void 0 ? void 0 : (_node$position2$end = _node$position2.end) === null || _node$position2$end === void 0 ? void 0 : _node$position2$end.offset;
13
13
  if (startOffset === undefined || endOffset === undefined) {
14
14
  return;
15
15
  }
@@ -110,7 +110,7 @@ var XStarEditor = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
110
110
  }
111
111
  }
112
112
  }
113
- for (; fromOffsetTops[fromOffsetTops.length - 1] >= fromLimit || toOffsetTops[toOffsetTops.length - 1] >= toLimit;) {
113
+ for (; fromOffsetTops.at(-1) >= fromLimit || toOffsetTops.at(-1) >= toLimit;) {
114
114
  fromOffsetTops.pop();
115
115
  toOffsetTops.pop();
116
116
  }
@@ -190,7 +190,8 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
190
190
  return;
191
191
  }
192
192
  var listener = function listener(e) {
193
- var targetRange = e.getTargetRanges()[0];
193
+ var _e$getTargetRanges$, _window$getSelection;
194
+ var targetRange = (_e$getTargetRanges$ = e.getTargetRanges()[0]) !== null && _e$getTargetRanges$ !== void 0 ? _e$getTargetRanges$ : (_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.getRangeAt(0);
194
195
  if (!targetRange) {
195
196
  return;
196
197
  }