@hufe921/canvas-editor 0.9.42 → 0.9.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.
- package/CHANGELOG.md +15 -0
- package/dist/canvas-editor.es.js +150 -62
- package/dist/canvas-editor.es.js.map +1 -1
- package/dist/canvas-editor.umd.js +22 -22
- package/dist/canvas-editor.umd.js.map +1 -1
- package/dist/src/editor/core/cursor/Cursor.d.ts +7 -0
- package/dist/src/editor/core/draw/control/Control.d.ts +1 -0
- package/dist/src/editor/dataset/enum/Editor.d.ts +2 -1
- package/dist/src/editor/interface/Editor.d.ts +1 -0
- package/dist/src/editor/utils/index.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## [0.9.43](https://github.com/Hufe921/canvas-editor/compare/v0.9.42...v0.9.43) (2023-08-04)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* cursor navigation across pages #229 ([a96a77a](https://github.com/Hufe921/canvas-editor/commit/a96a77a237a62f0881a2b106b040f29c840fff58)), closes [#229](https://github.com/Hufe921/canvas-editor/issues/229)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add form mode #221 ([94247c3](https://github.com/Hufe921/canvas-editor/commit/94247c324be8bd3688f4098ab9520fc563d20ded)), closes [#221](https://github.com/Hufe921/canvas-editor/issues/221)
|
|
12
|
+
* cursor following page scrolling #229 ([3db28cc](https://github.com/Hufe921/canvas-editor/commit/3db28cc04f84af502901da51a14e3f63c8a36964)), closes [#229](https://github.com/Hufe921/canvas-editor/issues/229)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
## [0.9.42](https://github.com/Hufe921/canvas-editor/compare/v0.9.41...v0.9.42) (2023-07-31)
|
|
2
17
|
|
|
3
18
|
|
package/dist/canvas-editor.es.js
CHANGED
|
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => {
|
|
|
23
23
|
return value;
|
|
24
24
|
};
|
|
25
25
|
var index = "";
|
|
26
|
-
const version = "0.9.
|
|
26
|
+
const version = "0.9.43";
|
|
27
27
|
var MaxHeightRatio;
|
|
28
28
|
(function(MaxHeightRatio2) {
|
|
29
29
|
MaxHeightRatio2["HALF"] = "half";
|
|
@@ -244,6 +244,18 @@ function convertStringToBase64(input2) {
|
|
|
244
244
|
const base64 = window.btoa(charArray.join(""));
|
|
245
245
|
return base64;
|
|
246
246
|
}
|
|
247
|
+
function findScrollContainer(element) {
|
|
248
|
+
let parent = element.parentElement;
|
|
249
|
+
while (parent) {
|
|
250
|
+
const style = window.getComputedStyle(parent);
|
|
251
|
+
const overflowY = style.getPropertyValue("overflow-y");
|
|
252
|
+
if (parent.scrollHeight > parent.clientHeight && (overflowY === "auto" || overflowY === "scroll")) {
|
|
253
|
+
return parent;
|
|
254
|
+
}
|
|
255
|
+
parent = parent.parentElement;
|
|
256
|
+
}
|
|
257
|
+
return document.documentElement;
|
|
258
|
+
}
|
|
247
259
|
const CURSOR_AGENT_HEIGHT = 12;
|
|
248
260
|
const defaultCursorOption = {
|
|
249
261
|
width: 1,
|
|
@@ -253,6 +265,13 @@ const defaultCursorOption = {
|
|
|
253
265
|
};
|
|
254
266
|
const EDITOR_COMPONENT = "editor-component";
|
|
255
267
|
const EDITOR_PREFIX = "ce";
|
|
268
|
+
var MoveDirection;
|
|
269
|
+
(function(MoveDirection2) {
|
|
270
|
+
MoveDirection2["UP"] = "top";
|
|
271
|
+
MoveDirection2["DOWN"] = "down";
|
|
272
|
+
MoveDirection2["LEFT"] = "left";
|
|
273
|
+
MoveDirection2["RIGHT"] = "right";
|
|
274
|
+
})(MoveDirection || (MoveDirection = {}));
|
|
256
275
|
var ElementType;
|
|
257
276
|
(function(ElementType2) {
|
|
258
277
|
ElementType2["TEXT"] = "text";
|
|
@@ -4619,6 +4638,40 @@ class Cursor {
|
|
|
4619
4638
|
this.cursorDom.style.display = "none";
|
|
4620
4639
|
this._clearBlinkTimeout();
|
|
4621
4640
|
}
|
|
4641
|
+
moveCursorToVisible(payload) {
|
|
4642
|
+
const { cursorPosition, direction } = payload;
|
|
4643
|
+
if (!cursorPosition || !direction)
|
|
4644
|
+
return;
|
|
4645
|
+
const { pageNo, coordinate: { leftTop, leftBottom } } = cursorPosition;
|
|
4646
|
+
const prePageY = pageNo * (this.draw.getHeight() + this.draw.getPageGap()) + this.container.getBoundingClientRect().top;
|
|
4647
|
+
const isUp = direction === MoveDirection.UP;
|
|
4648
|
+
const x = leftBottom[0];
|
|
4649
|
+
const y = isUp ? leftTop[1] + prePageY : leftBottom[1] + prePageY;
|
|
4650
|
+
const scrollContainer = findScrollContainer(this.container);
|
|
4651
|
+
const rect = {
|
|
4652
|
+
left: 0,
|
|
4653
|
+
right: 0,
|
|
4654
|
+
top: 0,
|
|
4655
|
+
bottom: 0
|
|
4656
|
+
};
|
|
4657
|
+
if (scrollContainer === document.documentElement) {
|
|
4658
|
+
rect.right = window.innerWidth;
|
|
4659
|
+
rect.bottom = window.innerHeight;
|
|
4660
|
+
} else {
|
|
4661
|
+
const { left, right, top, bottom } = scrollContainer.getBoundingClientRect();
|
|
4662
|
+
rect.left = left;
|
|
4663
|
+
rect.right = right;
|
|
4664
|
+
rect.top = top;
|
|
4665
|
+
rect.bottom = bottom;
|
|
4666
|
+
}
|
|
4667
|
+
const { maskMargin } = this.options;
|
|
4668
|
+
rect.top += maskMargin[0];
|
|
4669
|
+
rect.bottom -= maskMargin[2];
|
|
4670
|
+
if (!(x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom)) {
|
|
4671
|
+
const { scrollLeft, scrollTop } = scrollContainer;
|
|
4672
|
+
isUp ? scrollContainer.scroll(scrollLeft, scrollTop - (rect.top - y)) : scrollContainer.scroll(scrollLeft, scrollTop + y - rect.bottom);
|
|
4673
|
+
}
|
|
4674
|
+
}
|
|
4622
4675
|
}
|
|
4623
4676
|
var MouseEventButton;
|
|
4624
4677
|
(function(MouseEventButton2) {
|
|
@@ -4925,6 +4978,8 @@ function mouseup(evt, host) {
|
|
|
4925
4978
|
var _a, _b, _c;
|
|
4926
4979
|
if (host.isAllowDrop) {
|
|
4927
4980
|
const draw = host.getDraw();
|
|
4981
|
+
if (draw.isReadonly())
|
|
4982
|
+
return;
|
|
4928
4983
|
const position = draw.getPosition();
|
|
4929
4984
|
const positionList = position.getPositionList();
|
|
4930
4985
|
const rangeManager = draw.getRange();
|
|
@@ -5275,7 +5330,6 @@ function keydown(evt, host) {
|
|
|
5275
5330
|
if (isReadonly)
|
|
5276
5331
|
return;
|
|
5277
5332
|
let anchorPosition = cursorPosition;
|
|
5278
|
-
const isUp = evt.key === KeyMap.Up;
|
|
5279
5333
|
if (evt.shiftKey) {
|
|
5280
5334
|
if (startIndex === cursorPosition.index) {
|
|
5281
5335
|
anchorPosition = positionList[endIndex];
|
|
@@ -5283,62 +5337,83 @@ function keydown(evt, host) {
|
|
|
5283
5337
|
anchorPosition = positionList[startIndex];
|
|
5284
5338
|
}
|
|
5285
5339
|
}
|
|
5286
|
-
const {
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
const curDistance = position2.coordinate.rightTop[0] - leftTop[0];
|
|
5302
|
-
if (curDistance > maxDistance) {
|
|
5303
|
-
maxIndex = position2.index;
|
|
5304
|
-
maxDistance = curDistance;
|
|
5305
|
-
break;
|
|
5306
|
-
}
|
|
5340
|
+
const { index: index22, rowNo, rowIndex, coordinate: { leftTop: [curLeftX], rightTop: [curRightX] } } = anchorPosition;
|
|
5341
|
+
const isUp = evt.key === KeyMap.Up;
|
|
5342
|
+
if (isUp && rowIndex === 0 || !isUp && rowIndex === draw.getRowCount() - 1) {
|
|
5343
|
+
return;
|
|
5344
|
+
}
|
|
5345
|
+
const probablePosition = [];
|
|
5346
|
+
if (isUp) {
|
|
5347
|
+
let p = index22 - 1;
|
|
5348
|
+
while (p > 0) {
|
|
5349
|
+
const position2 = positionList[p];
|
|
5350
|
+
p--;
|
|
5351
|
+
if (position2.rowNo === rowNo)
|
|
5352
|
+
continue;
|
|
5353
|
+
if (probablePosition[0] && probablePosition[0].rowNo !== position2.rowNo) {
|
|
5354
|
+
break;
|
|
5307
5355
|
}
|
|
5308
|
-
|
|
5309
|
-
|
|
5356
|
+
probablePosition.unshift(position2);
|
|
5357
|
+
}
|
|
5358
|
+
} else {
|
|
5359
|
+
let p = index22 + 1;
|
|
5360
|
+
while (p < positionList.length) {
|
|
5361
|
+
const position2 = positionList[p];
|
|
5362
|
+
p++;
|
|
5363
|
+
if (position2.rowNo === rowNo)
|
|
5364
|
+
continue;
|
|
5365
|
+
if (probablePosition[0] && probablePosition[0].rowNo !== position2.rowNo) {
|
|
5366
|
+
break;
|
|
5310
5367
|
}
|
|
5368
|
+
probablePosition.push(position2);
|
|
5311
5369
|
}
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5370
|
+
}
|
|
5371
|
+
let nextIndex = 0;
|
|
5372
|
+
for (let p = 0; p < probablePosition.length; p++) {
|
|
5373
|
+
const nextPosition = probablePosition[p];
|
|
5374
|
+
const { coordinate: { leftTop: [nextLeftX], rightTop: [nextRightX] } } = nextPosition;
|
|
5375
|
+
if (p === probablePosition.length - 1) {
|
|
5376
|
+
nextIndex = nextPosition.index;
|
|
5377
|
+
}
|
|
5378
|
+
if (curRightX <= nextLeftX || curLeftX >= nextRightX)
|
|
5379
|
+
continue;
|
|
5380
|
+
nextIndex = nextPosition.index;
|
|
5381
|
+
break;
|
|
5382
|
+
}
|
|
5383
|
+
if (!nextIndex)
|
|
5384
|
+
return;
|
|
5385
|
+
let anchorStartIndex = nextIndex;
|
|
5386
|
+
let anchorEndIndex = nextIndex;
|
|
5387
|
+
if (evt.shiftKey) {
|
|
5388
|
+
if (startIndex !== endIndex) {
|
|
5389
|
+
if (startIndex === cursorPosition.index) {
|
|
5390
|
+
anchorStartIndex = startIndex;
|
|
5322
5391
|
} else {
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5392
|
+
anchorEndIndex = endIndex;
|
|
5393
|
+
}
|
|
5394
|
+
} else {
|
|
5395
|
+
if (isUp) {
|
|
5396
|
+
anchorEndIndex = endIndex;
|
|
5397
|
+
} else {
|
|
5398
|
+
anchorStartIndex = startIndex;
|
|
5328
5399
|
}
|
|
5329
5400
|
}
|
|
5330
|
-
if (anchorStartIndex > anchorEndIndex) {
|
|
5331
|
-
[anchorStartIndex, anchorEndIndex] = [anchorEndIndex, anchorStartIndex];
|
|
5332
|
-
}
|
|
5333
|
-
rangeManager.setRange(anchorStartIndex, anchorEndIndex);
|
|
5334
|
-
const isCollapsed2 = anchorStartIndex === anchorEndIndex;
|
|
5335
|
-
draw.render({
|
|
5336
|
-
curIndex: isCollapsed2 ? anchorStartIndex : void 0,
|
|
5337
|
-
isSetCursor: isCollapsed2,
|
|
5338
|
-
isSubmitHistory: false,
|
|
5339
|
-
isCompute: false
|
|
5340
|
-
});
|
|
5341
5401
|
}
|
|
5402
|
+
if (anchorStartIndex > anchorEndIndex) {
|
|
5403
|
+
[anchorStartIndex, anchorEndIndex] = [anchorEndIndex, anchorStartIndex];
|
|
5404
|
+
}
|
|
5405
|
+
rangeManager.setRange(anchorStartIndex, anchorEndIndex);
|
|
5406
|
+
const isCollapsed2 = anchorStartIndex === anchorEndIndex;
|
|
5407
|
+
draw.render({
|
|
5408
|
+
curIndex: isCollapsed2 ? anchorStartIndex : void 0,
|
|
5409
|
+
isSetCursor: isCollapsed2,
|
|
5410
|
+
isSubmitHistory: false,
|
|
5411
|
+
isCompute: false
|
|
5412
|
+
});
|
|
5413
|
+
draw.getCursor().moveCursorToVisible({
|
|
5414
|
+
cursorPosition: positionList[isUp ? anchorStartIndex : anchorEndIndex],
|
|
5415
|
+
direction: isUp ? MoveDirection.UP : MoveDirection.DOWN
|
|
5416
|
+
});
|
|
5342
5417
|
} else if (isMod(evt) && evt.key === KeyMap.Z) {
|
|
5343
5418
|
if (isReadonly)
|
|
5344
5419
|
return;
|
|
@@ -6056,6 +6131,7 @@ var EditorMode;
|
|
|
6056
6131
|
EditorMode2["EDIT"] = "edit";
|
|
6057
6132
|
EditorMode2["CLEAN"] = "clean";
|
|
6058
6133
|
EditorMode2["READONLY"] = "readonly";
|
|
6134
|
+
EditorMode2["FORM"] = "form";
|
|
6059
6135
|
})(EditorMode || (EditorMode = {}));
|
|
6060
6136
|
var EditorZone;
|
|
6061
6137
|
(function(EditorZone2) {
|
|
@@ -6419,11 +6495,10 @@ class Position {
|
|
|
6419
6495
|
};
|
|
6420
6496
|
}
|
|
6421
6497
|
adjustPositionContext(payload) {
|
|
6422
|
-
const isReadonly = this.draw.isReadonly();
|
|
6423
6498
|
const positionResult = this.getPositionByXY(payload);
|
|
6424
6499
|
if (!~positionResult.index)
|
|
6425
6500
|
return null;
|
|
6426
|
-
if (positionResult.isControl &&
|
|
6501
|
+
if (positionResult.isControl && this.draw.getMode() !== EditorMode.READONLY) {
|
|
6427
6502
|
const { index: index22, isTable: isTable2, trIndex: trIndex2, tdIndex: tdIndex2, tdValueIndex } = positionResult;
|
|
6428
6503
|
const control = this.draw.getControl();
|
|
6429
6504
|
const { newIndex } = control.moveCursor({
|
|
@@ -7409,13 +7484,6 @@ class ScrollObserver {
|
|
|
7409
7484
|
};
|
|
7410
7485
|
}
|
|
7411
7486
|
}
|
|
7412
|
-
var MoveDirection;
|
|
7413
|
-
(function(MoveDirection2) {
|
|
7414
|
-
MoveDirection2["UP"] = "top";
|
|
7415
|
-
MoveDirection2["DOWN"] = "down";
|
|
7416
|
-
MoveDirection2["LEFT"] = "left";
|
|
7417
|
-
MoveDirection2["RIGHT"] = "right";
|
|
7418
|
-
})(MoveDirection || (MoveDirection = {}));
|
|
7419
7487
|
class SelectionObserver {
|
|
7420
7488
|
constructor(draw) {
|
|
7421
7489
|
__publicField(this, "step", 5);
|
|
@@ -8683,6 +8751,18 @@ class Control {
|
|
|
8683
8751
|
const element = elementList[startIndex];
|
|
8684
8752
|
return element.controlComponent === ControlComponent.POSTFIX;
|
|
8685
8753
|
}
|
|
8754
|
+
isRangeWithinControl() {
|
|
8755
|
+
const { startIndex, endIndex } = this.getRange();
|
|
8756
|
+
if (!~startIndex && !~endIndex)
|
|
8757
|
+
return false;
|
|
8758
|
+
const elementList = this.getElementList();
|
|
8759
|
+
const startElement = elementList[startIndex];
|
|
8760
|
+
const endElement = elementList[endIndex];
|
|
8761
|
+
if ((startElement.type === ElementType.CONTROL || endElement.type === ElementType.CONTROL) && endElement.controlComponent !== ControlComponent.POSTFIX && startElement.controlId === endElement.controlId) {
|
|
8762
|
+
return true;
|
|
8763
|
+
}
|
|
8764
|
+
return false;
|
|
8765
|
+
}
|
|
8686
8766
|
getContainer() {
|
|
8687
8767
|
return this.draw.getContainer();
|
|
8688
8768
|
}
|
|
@@ -10738,7 +10818,14 @@ class Draw {
|
|
|
10738
10818
|
this.mode = payload;
|
|
10739
10819
|
}
|
|
10740
10820
|
isReadonly() {
|
|
10741
|
-
|
|
10821
|
+
switch (this.mode) {
|
|
10822
|
+
case EditorMode.READONLY:
|
|
10823
|
+
return true;
|
|
10824
|
+
case EditorMode.FORM:
|
|
10825
|
+
return !this.control.isRangeWithinControl();
|
|
10826
|
+
default:
|
|
10827
|
+
return false;
|
|
10828
|
+
}
|
|
10742
10829
|
}
|
|
10743
10830
|
getOriginalWidth() {
|
|
10744
10831
|
const { paperDirection, width, height } = this.options;
|
|
@@ -14808,7 +14895,8 @@ class Editor {
|
|
|
14808
14895
|
inactiveAlpha: 0.6,
|
|
14809
14896
|
historyMaxRecordCount: 100,
|
|
14810
14897
|
wordBreak: WordBreak.BREAK_WORD,
|
|
14811
|
-
printPixelRatio: 3
|
|
14898
|
+
printPixelRatio: 3,
|
|
14899
|
+
maskMargin: [0, 0, 0, 0]
|
|
14812
14900
|
}, options), {
|
|
14813
14901
|
header: headerOptions,
|
|
14814
14902
|
footer: footerOptions,
|