@windoc/core 0.3.2 → 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
@@ -8437,9 +8437,11 @@ function input(data2, host) {
8437
8437
  }
8438
8438
  if (~curIndex) {
8439
8439
  rangeManager.setRange(curIndex, curIndex);
8440
+ const isWordBoundary = !isComposing && /[\s\p{P}]/u.test(data2);
8440
8441
  draw.render({
8441
8442
  curIndex,
8442
- isSubmitHistory: !isComposing
8443
+ isSubmitHistory: !isComposing,
8444
+ isInputHistory: !isComposing && !isWordBoundary
8443
8445
  });
8444
8446
  }
8445
8447
  if (isComposing && ~curIndex) {
@@ -9110,10 +9112,12 @@ var GlobalEvent = class {
9110
9112
  };
9111
9113
 
9112
9114
  // src/core/history/HistoryManager.ts
9115
+ var INPUT_GROUP_INTERVAL = 1e3;
9113
9116
  var HistoryManager = class {
9114
9117
  constructor(draw) {
9115
9118
  this.undoStack = [];
9116
9119
  this.redoStack = [];
9120
+ this.lastInputTime = 0;
9117
9121
  this.maxRecordCount = draw.getOptions().historyMaxRecordCount + 1;
9118
9122
  }
9119
9123
  undo() {
@@ -9141,6 +9145,25 @@ var HistoryManager = class {
9141
9145
  this.undoStack.shift();
9142
9146
  }
9143
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
+ }
9144
9167
  isCanUndo() {
9145
9168
  return this.undoStack.length > 1;
9146
9169
  }
@@ -22321,6 +22344,7 @@ var Draw = class {
22321
22344
  const { header, footer } = this.options;
22322
22345
  const {
22323
22346
  isSubmitHistory = true,
22347
+ isInputHistory = false,
22324
22348
  isSetCursor = true,
22325
22349
  isCompute = true,
22326
22350
  isLazy = true,
@@ -22400,7 +22424,7 @@ var Draw = class {
22400
22424
  this.cursor.focus();
22401
22425
  }
22402
22426
  if (isSubmitHistory && !isFirstRender || curIndex !== void 0 && this.historyManager.isStackEmpty()) {
22403
- this.submitHistory(curIndex);
22427
+ this.submitHistory(curIndex, isInputHistory);
22404
22428
  }
22405
22429
  nextTick(() => {
22406
22430
  this.range.setRangeStyle();
@@ -22463,7 +22487,7 @@ var Draw = class {
22463
22487
  });
22464
22488
  return curIndex;
22465
22489
  }
22466
- submitHistory(curIndex) {
22490
+ submitHistory(curIndex, isInput = false) {
22467
22491
  const positionContext = this.position.getPositionContext();
22468
22492
  const oldElementList = getSlimCloneElementList(this.elementList);
22469
22493
  const oldHeaderElementList = getSlimCloneElementList(
@@ -22476,7 +22500,7 @@ var Draw = class {
22476
22500
  const pageNo = this.pageNo;
22477
22501
  const oldPositionContext = deepClone(positionContext);
22478
22502
  const zone = this.zone.getZone();
22479
- this.historyManager.execute(() => {
22503
+ const fn = () => {
22480
22504
  this.zone.setZone(zone);
22481
22505
  this.setPageNo(pageNo);
22482
22506
  this.position.setPositionContext(deepClone(oldPositionContext));
@@ -22489,7 +22513,17 @@ var Draw = class {
22489
22513
  isSubmitHistory: false,
22490
22514
  isSourceHistory: true
22491
22515
  });
22492
- });
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
+ }
22493
22527
  }
22494
22528
  destroy() {
22495
22529
  this.container.remove();