@windoc/core 0.3.1 → 0.3.3

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.
package/dist/index.mjs CHANGED
@@ -6438,34 +6438,25 @@ var Cursor = class {
6438
6438
  const nextElement = elementList[curIndex + 1];
6439
6439
  const isNearImage = curElement && curElement.type === "image" /* IMAGE */ || nextElement && nextElement.type === "image" /* IMAGE */;
6440
6440
  const isNearSeparator = curElement?.type === "separator" /* SEPARATOR */;
6441
- if (isNearImage || isNearSeparator) {
6441
+ const isNearTab = curElement?.type === "tab" /* TAB */;
6442
+ if (isNearImage || isNearSeparator || isNearTab) {
6442
6443
  const { defaultSize, defaultFont } = this.options;
6443
6444
  const ctx = this.draw.getCtx();
6444
6445
  ctx.save();
6445
6446
  ctx.font = `${defaultSize * (96 / 72) * scale}px ${defaultFont}`;
6446
6447
  const textMetrics = ctx.measureText("M");
6447
6448
  ctx.restore();
6448
- if (isNearSeparator) {
6449
- const textHeight = textMetrics.fontBoundingBoxAscent + textMetrics.fontBoundingBoxDescent;
6450
- effectiveMetrics = {
6451
- width: metrics.width,
6452
- height: textHeight,
6453
- boundingBoxAscent: textMetrics.fontBoundingBoxAscent,
6454
- boundingBoxDescent: textMetrics.fontBoundingBoxDescent
6455
- };
6456
- } else {
6457
- const textHeight = textMetrics.actualBoundingBoxAscent + textMetrics.actualBoundingBoxDescent;
6458
- effectiveMetrics = {
6459
- width: metrics.width,
6460
- height: textHeight,
6461
- boundingBoxAscent: textMetrics.actualBoundingBoxAscent,
6462
- boundingBoxDescent: textMetrics.actualBoundingBoxDescent
6463
- };
6464
- }
6449
+ const textHeight = textMetrics.fontBoundingBoxAscent + textMetrics.fontBoundingBoxDescent;
6450
+ effectiveMetrics = {
6451
+ width: metrics.width,
6452
+ height: textHeight,
6453
+ boundingBoxAscent: textMetrics.fontBoundingBoxAscent,
6454
+ boundingBoxDescent: textMetrics.fontBoundingBoxDescent
6455
+ };
6465
6456
  }
6466
6457
  const cursorPadding = 2 * scale;
6467
6458
  const cursorHeight = effectiveMetrics.boundingBoxAscent + effectiveMetrics.boundingBoxDescent + cursorPadding;
6468
- const cursorTop = isNearImage ? leftTop[1] + cursorPosition.lineHeight - effectiveMetrics.boundingBoxDescent - cursorPadding / 2 + preY : isNearSeparator ? leftTop[1] + ascent - (effectiveMetrics.boundingBoxAscent + effectiveMetrics.boundingBoxDescent + cursorPadding) / 2 + preY : leftTop[1] + ascent - effectiveMetrics.boundingBoxAscent - cursorPadding / 2 + preY;
6459
+ const cursorTop = isNearImage ? leftTop[1] + cursorPosition.lineHeight - cursorHeight + preY : isNearSeparator ? leftTop[1] + ascent - (effectiveMetrics.boundingBoxAscent + effectiveMetrics.boundingBoxDescent + cursorPadding) / 2 + preY : leftTop[1] + ascent - effectiveMetrics.boundingBoxAscent - cursorPadding / 2 + preY;
6469
6460
  const cursorLeft = hitLineStartIndex ? leftTop[0] : rightTop[0];
6470
6461
  agentCursorDom.style.left = `${cursorLeft}px`;
6471
6462
  agentCursorDom.style.top = `${cursorTop}px`;
@@ -7732,6 +7723,12 @@ function left(evt, host) {
7732
7723
  }
7733
7724
  }
7734
7725
  }
7726
+ if (!isCollapsed && !evt.shiftKey) {
7727
+ rangeManager.setRange(startIndex, startIndex);
7728
+ draw.render({ curIndex: startIndex, isSetCursor: true, isSubmitHistory: false, isCompute: false });
7729
+ evt.preventDefault();
7730
+ return;
7731
+ }
7735
7732
  const curIndex = startIndex - moveCount;
7736
7733
  let anchorStartIndex = curIndex;
7737
7734
  let anchorEndIndex = curIndex;
@@ -7868,6 +7865,12 @@ function right(evt, host) {
7868
7865
  }
7869
7866
  }
7870
7867
  }
7868
+ if (!isCollapsed && !evt.shiftKey) {
7869
+ rangeManager.setRange(endIndex, endIndex);
7870
+ draw.render({ curIndex: endIndex, isSetCursor: true, isSubmitHistory: false, isCompute: false });
7871
+ evt.preventDefault();
7872
+ return;
7873
+ }
7871
7874
  const curIndex = endIndex + moveCount;
7872
7875
  let anchorStartIndex = curIndex;
7873
7876
  let anchorEndIndex = curIndex;
@@ -8434,9 +8437,11 @@ function input(data2, host) {
8434
8437
  }
8435
8438
  if (~curIndex) {
8436
8439
  rangeManager.setRange(curIndex, curIndex);
8440
+ const isWordBoundary = !isComposing && /[\s\p{P}]/u.test(data2);
8437
8441
  draw.render({
8438
8442
  curIndex,
8439
- isSubmitHistory: !isComposing
8443
+ isSubmitHistory: !isComposing,
8444
+ isInputHistory: !isComposing && !isWordBoundary
8440
8445
  });
8441
8446
  }
8442
8447
  if (isComposing && ~curIndex) {
@@ -9107,10 +9112,12 @@ var GlobalEvent = class {
9107
9112
  };
9108
9113
 
9109
9114
  // src/core/history/HistoryManager.ts
9115
+ var INPUT_GROUP_INTERVAL = 1e3;
9110
9116
  var HistoryManager = class {
9111
9117
  constructor(draw) {
9112
9118
  this.undoStack = [];
9113
9119
  this.redoStack = [];
9120
+ this.lastInputTime = 0;
9114
9121
  this.maxRecordCount = draw.getOptions().historyMaxRecordCount + 1;
9115
9122
  }
9116
9123
  undo() {
@@ -9138,6 +9145,25 @@ var HistoryManager = class {
9138
9145
  this.undoStack.shift();
9139
9146
  }
9140
9147
  }
9148
+ replaceLatest(fn) {
9149
+ if (this.undoStack.length > 0) {
9150
+ this.undoStack[this.undoStack.length - 1] = fn;
9151
+ } else {
9152
+ this.execute(fn);
9153
+ }
9154
+ if (this.redoStack.length) {
9155
+ this.redoStack = [];
9156
+ }
9157
+ }
9158
+ isInputGroupable() {
9159
+ return Date.now() - this.lastInputTime < INPUT_GROUP_INTERVAL;
9160
+ }
9161
+ recordInputTime() {
9162
+ this.lastInputTime = Date.now();
9163
+ }
9164
+ resetInputTime() {
9165
+ this.lastInputTime = 0;
9166
+ }
9141
9167
  isCanUndo() {
9142
9168
  return this.undoStack.length > 1;
9143
9169
  }
@@ -22318,6 +22344,7 @@ var Draw = class {
22318
22344
  const { header, footer } = this.options;
22319
22345
  const {
22320
22346
  isSubmitHistory = true,
22347
+ isInputHistory = false,
22321
22348
  isSetCursor = true,
22322
22349
  isCompute = true,
22323
22350
  isLazy = true,
@@ -22397,7 +22424,7 @@ var Draw = class {
22397
22424
  this.cursor.focus();
22398
22425
  }
22399
22426
  if (isSubmitHistory && !isFirstRender || curIndex !== void 0 && this.historyManager.isStackEmpty()) {
22400
- this.submitHistory(curIndex);
22427
+ this.submitHistory(curIndex, isInputHistory);
22401
22428
  }
22402
22429
  nextTick(() => {
22403
22430
  this.range.setRangeStyle();
@@ -22460,7 +22487,7 @@ var Draw = class {
22460
22487
  });
22461
22488
  return curIndex;
22462
22489
  }
22463
- submitHistory(curIndex) {
22490
+ submitHistory(curIndex, isInput = false) {
22464
22491
  const positionContext = this.position.getPositionContext();
22465
22492
  const oldElementList = getSlimCloneElementList(this.elementList);
22466
22493
  const oldHeaderElementList = getSlimCloneElementList(
@@ -22473,7 +22500,7 @@ var Draw = class {
22473
22500
  const pageNo = this.pageNo;
22474
22501
  const oldPositionContext = deepClone(positionContext);
22475
22502
  const zone = this.zone.getZone();
22476
- this.historyManager.execute(() => {
22503
+ const fn = () => {
22477
22504
  this.zone.setZone(zone);
22478
22505
  this.setPageNo(pageNo);
22479
22506
  this.position.setPositionContext(deepClone(oldPositionContext));
@@ -22486,7 +22513,17 @@ var Draw = class {
22486
22513
  isSubmitHistory: false,
22487
22514
  isSourceHistory: true
22488
22515
  });
22489
- });
22516
+ };
22517
+ if (isInput && this.historyManager.isInputGroupable()) {
22518
+ this.historyManager.replaceLatest(fn);
22519
+ } else {
22520
+ this.historyManager.execute(fn);
22521
+ }
22522
+ if (isInput) {
22523
+ this.historyManager.recordInputTime();
22524
+ } else {
22525
+ this.historyManager.resetInputTime();
22526
+ }
22490
22527
  }
22491
22528
  destroy() {
22492
22529
  this.container.remove();