@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.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +61 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -698,6 +698,7 @@ interface IDrawOption {
|
|
|
698
698
|
curIndex?: number;
|
|
699
699
|
isSetCursor?: boolean;
|
|
700
700
|
isSubmitHistory?: boolean;
|
|
701
|
+
isInputHistory?: boolean;
|
|
701
702
|
isCompute?: boolean;
|
|
702
703
|
isLazy?: boolean;
|
|
703
704
|
isInit?: boolean;
|
|
@@ -1490,10 +1491,15 @@ declare class HistoryManager {
|
|
|
1490
1491
|
private undoStack;
|
|
1491
1492
|
private redoStack;
|
|
1492
1493
|
private maxRecordCount;
|
|
1494
|
+
private lastInputTime;
|
|
1493
1495
|
constructor(draw: Draw);
|
|
1494
1496
|
undo(): void;
|
|
1495
1497
|
redo(): void;
|
|
1496
1498
|
execute(fn: Function): void;
|
|
1499
|
+
replaceLatest(fn: Function): void;
|
|
1500
|
+
isInputGroupable(): boolean;
|
|
1501
|
+
recordInputTime(): void;
|
|
1502
|
+
resetInputTime(): void;
|
|
1497
1503
|
isCanUndo(): boolean;
|
|
1498
1504
|
isCanRedo(): boolean;
|
|
1499
1505
|
isStackEmpty(): boolean;
|
|
@@ -2534,7 +2540,7 @@ declare class Draw {
|
|
|
2534
2540
|
private _immediateRender;
|
|
2535
2541
|
render(payload?: IDrawOption): void;
|
|
2536
2542
|
setCursor(curIndex: number | undefined): number | undefined;
|
|
2537
|
-
submitHistory(curIndex: number | undefined): void;
|
|
2543
|
+
submitHistory(curIndex: number | undefined, isInput?: boolean): void;
|
|
2538
2544
|
destroy(): void;
|
|
2539
2545
|
clearSideEffect(): void;
|
|
2540
2546
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -698,6 +698,7 @@ interface IDrawOption {
|
|
|
698
698
|
curIndex?: number;
|
|
699
699
|
isSetCursor?: boolean;
|
|
700
700
|
isSubmitHistory?: boolean;
|
|
701
|
+
isInputHistory?: boolean;
|
|
701
702
|
isCompute?: boolean;
|
|
702
703
|
isLazy?: boolean;
|
|
703
704
|
isInit?: boolean;
|
|
@@ -1490,10 +1491,15 @@ declare class HistoryManager {
|
|
|
1490
1491
|
private undoStack;
|
|
1491
1492
|
private redoStack;
|
|
1492
1493
|
private maxRecordCount;
|
|
1494
|
+
private lastInputTime;
|
|
1493
1495
|
constructor(draw: Draw);
|
|
1494
1496
|
undo(): void;
|
|
1495
1497
|
redo(): void;
|
|
1496
1498
|
execute(fn: Function): void;
|
|
1499
|
+
replaceLatest(fn: Function): void;
|
|
1500
|
+
isInputGroupable(): boolean;
|
|
1501
|
+
recordInputTime(): void;
|
|
1502
|
+
resetInputTime(): void;
|
|
1497
1503
|
isCanUndo(): boolean;
|
|
1498
1504
|
isCanRedo(): boolean;
|
|
1499
1505
|
isStackEmpty(): boolean;
|
|
@@ -2534,7 +2540,7 @@ declare class Draw {
|
|
|
2534
2540
|
private _immediateRender;
|
|
2535
2541
|
render(payload?: IDrawOption): void;
|
|
2536
2542
|
setCursor(curIndex: number | undefined): number | undefined;
|
|
2537
|
-
submitHistory(curIndex: number | undefined): void;
|
|
2543
|
+
submitHistory(curIndex: number | undefined, isInput?: boolean): void;
|
|
2538
2544
|
destroy(): void;
|
|
2539
2545
|
clearSideEffect(): void;
|
|
2540
2546
|
}
|
package/dist/index.js
CHANGED
|
@@ -6517,34 +6517,25 @@ var Cursor = class {
|
|
|
6517
6517
|
const nextElement = elementList[curIndex + 1];
|
|
6518
6518
|
const isNearImage = curElement && curElement.type === "image" /* IMAGE */ || nextElement && nextElement.type === "image" /* IMAGE */;
|
|
6519
6519
|
const isNearSeparator = curElement?.type === "separator" /* SEPARATOR */;
|
|
6520
|
-
|
|
6520
|
+
const isNearTab = curElement?.type === "tab" /* TAB */;
|
|
6521
|
+
if (isNearImage || isNearSeparator || isNearTab) {
|
|
6521
6522
|
const { defaultSize, defaultFont } = this.options;
|
|
6522
6523
|
const ctx = this.draw.getCtx();
|
|
6523
6524
|
ctx.save();
|
|
6524
6525
|
ctx.font = `${defaultSize * (96 / 72) * scale}px ${defaultFont}`;
|
|
6525
6526
|
const textMetrics = ctx.measureText("M");
|
|
6526
6527
|
ctx.restore();
|
|
6527
|
-
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
};
|
|
6535
|
-
} else {
|
|
6536
|
-
const textHeight = textMetrics.actualBoundingBoxAscent + textMetrics.actualBoundingBoxDescent;
|
|
6537
|
-
effectiveMetrics = {
|
|
6538
|
-
width: metrics.width,
|
|
6539
|
-
height: textHeight,
|
|
6540
|
-
boundingBoxAscent: textMetrics.actualBoundingBoxAscent,
|
|
6541
|
-
boundingBoxDescent: textMetrics.actualBoundingBoxDescent
|
|
6542
|
-
};
|
|
6543
|
-
}
|
|
6528
|
+
const textHeight = textMetrics.fontBoundingBoxAscent + textMetrics.fontBoundingBoxDescent;
|
|
6529
|
+
effectiveMetrics = {
|
|
6530
|
+
width: metrics.width,
|
|
6531
|
+
height: textHeight,
|
|
6532
|
+
boundingBoxAscent: textMetrics.fontBoundingBoxAscent,
|
|
6533
|
+
boundingBoxDescent: textMetrics.fontBoundingBoxDescent
|
|
6534
|
+
};
|
|
6544
6535
|
}
|
|
6545
6536
|
const cursorPadding = 2 * scale;
|
|
6546
6537
|
const cursorHeight = effectiveMetrics.boundingBoxAscent + effectiveMetrics.boundingBoxDescent + cursorPadding;
|
|
6547
|
-
const cursorTop = isNearImage ? leftTop[1] + cursorPosition.lineHeight -
|
|
6538
|
+
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;
|
|
6548
6539
|
const cursorLeft = hitLineStartIndex ? leftTop[0] : rightTop[0];
|
|
6549
6540
|
agentCursorDom.style.left = `${cursorLeft}px`;
|
|
6550
6541
|
agentCursorDom.style.top = `${cursorTop}px`;
|
|
@@ -7811,6 +7802,12 @@ function left(evt, host) {
|
|
|
7811
7802
|
}
|
|
7812
7803
|
}
|
|
7813
7804
|
}
|
|
7805
|
+
if (!isCollapsed && !evt.shiftKey) {
|
|
7806
|
+
rangeManager.setRange(startIndex, startIndex);
|
|
7807
|
+
draw.render({ curIndex: startIndex, isSetCursor: true, isSubmitHistory: false, isCompute: false });
|
|
7808
|
+
evt.preventDefault();
|
|
7809
|
+
return;
|
|
7810
|
+
}
|
|
7814
7811
|
const curIndex = startIndex - moveCount;
|
|
7815
7812
|
let anchorStartIndex = curIndex;
|
|
7816
7813
|
let anchorEndIndex = curIndex;
|
|
@@ -7947,6 +7944,12 @@ function right(evt, host) {
|
|
|
7947
7944
|
}
|
|
7948
7945
|
}
|
|
7949
7946
|
}
|
|
7947
|
+
if (!isCollapsed && !evt.shiftKey) {
|
|
7948
|
+
rangeManager.setRange(endIndex, endIndex);
|
|
7949
|
+
draw.render({ curIndex: endIndex, isSetCursor: true, isSubmitHistory: false, isCompute: false });
|
|
7950
|
+
evt.preventDefault();
|
|
7951
|
+
return;
|
|
7952
|
+
}
|
|
7950
7953
|
const curIndex = endIndex + moveCount;
|
|
7951
7954
|
let anchorStartIndex = curIndex;
|
|
7952
7955
|
let anchorEndIndex = curIndex;
|
|
@@ -8513,9 +8516,11 @@ function input(data2, host) {
|
|
|
8513
8516
|
}
|
|
8514
8517
|
if (~curIndex) {
|
|
8515
8518
|
rangeManager.setRange(curIndex, curIndex);
|
|
8519
|
+
const isWordBoundary = !isComposing && /[\s\p{P}]/u.test(data2);
|
|
8516
8520
|
draw.render({
|
|
8517
8521
|
curIndex,
|
|
8518
|
-
isSubmitHistory: !isComposing
|
|
8522
|
+
isSubmitHistory: !isComposing,
|
|
8523
|
+
isInputHistory: !isComposing && !isWordBoundary
|
|
8519
8524
|
});
|
|
8520
8525
|
}
|
|
8521
8526
|
if (isComposing && ~curIndex) {
|
|
@@ -9186,10 +9191,12 @@ var GlobalEvent = class {
|
|
|
9186
9191
|
};
|
|
9187
9192
|
|
|
9188
9193
|
// src/core/history/HistoryManager.ts
|
|
9194
|
+
var INPUT_GROUP_INTERVAL = 1e3;
|
|
9189
9195
|
var HistoryManager = class {
|
|
9190
9196
|
constructor(draw) {
|
|
9191
9197
|
this.undoStack = [];
|
|
9192
9198
|
this.redoStack = [];
|
|
9199
|
+
this.lastInputTime = 0;
|
|
9193
9200
|
this.maxRecordCount = draw.getOptions().historyMaxRecordCount + 1;
|
|
9194
9201
|
}
|
|
9195
9202
|
undo() {
|
|
@@ -9217,6 +9224,25 @@ var HistoryManager = class {
|
|
|
9217
9224
|
this.undoStack.shift();
|
|
9218
9225
|
}
|
|
9219
9226
|
}
|
|
9227
|
+
replaceLatest(fn) {
|
|
9228
|
+
if (this.undoStack.length > 0) {
|
|
9229
|
+
this.undoStack[this.undoStack.length - 1] = fn;
|
|
9230
|
+
} else {
|
|
9231
|
+
this.execute(fn);
|
|
9232
|
+
}
|
|
9233
|
+
if (this.redoStack.length) {
|
|
9234
|
+
this.redoStack = [];
|
|
9235
|
+
}
|
|
9236
|
+
}
|
|
9237
|
+
isInputGroupable() {
|
|
9238
|
+
return Date.now() - this.lastInputTime < INPUT_GROUP_INTERVAL;
|
|
9239
|
+
}
|
|
9240
|
+
recordInputTime() {
|
|
9241
|
+
this.lastInputTime = Date.now();
|
|
9242
|
+
}
|
|
9243
|
+
resetInputTime() {
|
|
9244
|
+
this.lastInputTime = 0;
|
|
9245
|
+
}
|
|
9220
9246
|
isCanUndo() {
|
|
9221
9247
|
return this.undoStack.length > 1;
|
|
9222
9248
|
}
|
|
@@ -22397,6 +22423,7 @@ var Draw = class {
|
|
|
22397
22423
|
const { header, footer } = this.options;
|
|
22398
22424
|
const {
|
|
22399
22425
|
isSubmitHistory = true,
|
|
22426
|
+
isInputHistory = false,
|
|
22400
22427
|
isSetCursor = true,
|
|
22401
22428
|
isCompute = true,
|
|
22402
22429
|
isLazy = true,
|
|
@@ -22476,7 +22503,7 @@ var Draw = class {
|
|
|
22476
22503
|
this.cursor.focus();
|
|
22477
22504
|
}
|
|
22478
22505
|
if (isSubmitHistory && !isFirstRender || curIndex !== void 0 && this.historyManager.isStackEmpty()) {
|
|
22479
|
-
this.submitHistory(curIndex);
|
|
22506
|
+
this.submitHistory(curIndex, isInputHistory);
|
|
22480
22507
|
}
|
|
22481
22508
|
nextTick(() => {
|
|
22482
22509
|
this.range.setRangeStyle();
|
|
@@ -22539,7 +22566,7 @@ var Draw = class {
|
|
|
22539
22566
|
});
|
|
22540
22567
|
return curIndex;
|
|
22541
22568
|
}
|
|
22542
|
-
submitHistory(curIndex) {
|
|
22569
|
+
submitHistory(curIndex, isInput = false) {
|
|
22543
22570
|
const positionContext = this.position.getPositionContext();
|
|
22544
22571
|
const oldElementList = getSlimCloneElementList(this.elementList);
|
|
22545
22572
|
const oldHeaderElementList = getSlimCloneElementList(
|
|
@@ -22552,7 +22579,7 @@ var Draw = class {
|
|
|
22552
22579
|
const pageNo = this.pageNo;
|
|
22553
22580
|
const oldPositionContext = deepClone(positionContext);
|
|
22554
22581
|
const zone = this.zone.getZone();
|
|
22555
|
-
|
|
22582
|
+
const fn = () => {
|
|
22556
22583
|
this.zone.setZone(zone);
|
|
22557
22584
|
this.setPageNo(pageNo);
|
|
22558
22585
|
this.position.setPositionContext(deepClone(oldPositionContext));
|
|
@@ -22565,7 +22592,17 @@ var Draw = class {
|
|
|
22565
22592
|
isSubmitHistory: false,
|
|
22566
22593
|
isSourceHistory: true
|
|
22567
22594
|
});
|
|
22568
|
-
}
|
|
22595
|
+
};
|
|
22596
|
+
if (isInput && this.historyManager.isInputGroupable()) {
|
|
22597
|
+
this.historyManager.replaceLatest(fn);
|
|
22598
|
+
} else {
|
|
22599
|
+
this.historyManager.execute(fn);
|
|
22600
|
+
}
|
|
22601
|
+
if (isInput) {
|
|
22602
|
+
this.historyManager.recordInputTime();
|
|
22603
|
+
} else {
|
|
22604
|
+
this.historyManager.resetInputTime();
|
|
22605
|
+
}
|
|
22569
22606
|
}
|
|
22570
22607
|
destroy() {
|
|
22571
22608
|
this.container.remove();
|