@hailin-zheng/editor-core 2.1.18 → 2.1.19
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/index-cjs.d.ts +0 -1
- package/index-cjs.js +627 -560
- package/index-cjs.js.map +1 -1
- package/index.d.ts +0 -1
- package/index.js +627 -559
- package/index.js.map +1 -1
- package/med_editor/doc-editor.d.ts +2 -0
- package/med_editor/editor-core.d.ts +4 -0
- package/med_editor/framework/common-util.d.ts +1 -0
- package/med_editor/framework/document-arrange.d.ts +9 -4
- package/med_editor/framework/document-context.d.ts +0 -8
- package/med_editor/framework/document-paint.d.ts +3 -3
- package/med_editor/framework/document-print-offscreen.d.ts +4 -4
- package/med_editor/framework/document-svg.d.ts +10 -4
- package/med_editor/framework/element-define.d.ts +1 -3
- package/med_editor/framework/element-props.d.ts +15 -1
- package/med_editor/framework/element-reader.d.ts +6 -1
- package/med_editor/framework/event-subject.d.ts +9 -0
- package/med_editor/framework/impl/comments/comment-element-impl.d.ts +7 -0
- package/med_editor/framework/impl/comments/comments-container-impl.d.ts +2 -22
- package/med_editor/framework/impl/data-element/data-element-image-impl.d.ts +0 -2
- package/med_editor/framework/impl/document/doc-impl.d.ts +20 -2
- package/med_editor/framework/impl/picture/image-impl.d.ts +0 -2
- package/med_editor/framework/range-util.d.ts +1 -1
- package/med_editor/framework/selection-overlays.d.ts +4 -2
- package/package.json +1 -1
- package/med_editor/framework/document-images-loader.d.ts +0 -20
package/index-cjs.js
CHANGED
@@ -582,6 +582,16 @@ class CommonUtil {
|
|
582
582
|
}
|
583
583
|
return str;
|
584
584
|
}
|
585
|
+
//随机生成rgb颜色
|
586
|
+
static randomRgbColor(opacity = -1) {
|
587
|
+
let r = Math.floor(Math.random() * 256); //随机生成256以内r值
|
588
|
+
let g = Math.floor(Math.random() * 256); //随机生成256以内g值
|
589
|
+
let b = Math.floor(Math.random() * 256); //随机生成256以内b值
|
590
|
+
if (opacity === -1) {
|
591
|
+
return `rgb(${r},${g},${b})`; //返回rgb(r,g,b)格式颜色
|
592
|
+
}
|
593
|
+
return `rgba(${r},${g},${b},${opacity})`; //返回rgba(r,g,b,a)格式颜色
|
594
|
+
}
|
585
595
|
/**
|
586
596
|
* 判断一个数值是否在另一个数值的增益区间中
|
587
597
|
* @param val
|
@@ -1101,6 +1111,40 @@ class SubjectSubscription$1 extends Subscription$1 {
|
|
1101
1111
|
function fromEvent(dom, type) {
|
1102
1112
|
return new DOMEventSource(dom, type);
|
1103
1113
|
}
|
1114
|
+
class EventBus {
|
1115
|
+
subs = new Map();
|
1116
|
+
on(event, handler) {
|
1117
|
+
let handlers = this.subs.get(event);
|
1118
|
+
if (!handlers) {
|
1119
|
+
handlers = [];
|
1120
|
+
this.subs.set(event, handlers);
|
1121
|
+
}
|
1122
|
+
const sub = new Subject$1();
|
1123
|
+
sub.subscribe(handler);
|
1124
|
+
handlers.push(sub);
|
1125
|
+
}
|
1126
|
+
off(event) {
|
1127
|
+
const subs = this.subs.get(event);
|
1128
|
+
if (subs) {
|
1129
|
+
subs.forEach(item => item.unsubscribe());
|
1130
|
+
}
|
1131
|
+
this.subs.delete(event);
|
1132
|
+
}
|
1133
|
+
emit(event, data) {
|
1134
|
+
const subs = this.subs.get(event);
|
1135
|
+
if (subs) {
|
1136
|
+
subs.forEach(item => item.next(data));
|
1137
|
+
}
|
1138
|
+
}
|
1139
|
+
clear() {
|
1140
|
+
this.subs.forEach((subs) => {
|
1141
|
+
subs.forEach((sub) => {
|
1142
|
+
sub.unsubscribe();
|
1143
|
+
});
|
1144
|
+
});
|
1145
|
+
this.subs.clear();
|
1146
|
+
}
|
1147
|
+
}
|
1104
1148
|
|
1105
1149
|
class Rect {
|
1106
1150
|
x = 0;
|
@@ -1705,17 +1749,7 @@ class ViewOptions {
|
|
1705
1749
|
//两个页的间距
|
1706
1750
|
docSpace = 0;
|
1707
1751
|
//是否显示审阅窗口
|
1708
|
-
|
1709
|
-
get showReviewWindow() {
|
1710
|
-
return this._showReviewWindow;
|
1711
|
-
}
|
1712
|
-
set showReviewWindow(value) {
|
1713
|
-
if (value === this._showReviewWindow) {
|
1714
|
-
return;
|
1715
|
-
}
|
1716
|
-
this._showReviewWindow = value;
|
1717
|
-
// this.onChange.next();
|
1718
|
-
}
|
1752
|
+
showReviewWindow = false;
|
1719
1753
|
//审阅窗口宽度
|
1720
1754
|
reviewWindowWidth = 200;
|
1721
1755
|
//缩放
|
@@ -2400,32 +2434,47 @@ class CommContentProps extends INotifyPropertyChanged {
|
|
2400
2434
|
createId;
|
2401
2435
|
createName;
|
2402
2436
|
createDate;
|
2437
|
+
text;
|
2403
2438
|
clone(dest) {
|
2404
2439
|
const clone = dest ?? new CommContentProps();
|
2405
2440
|
super.cloneAttachedProperty(clone);
|
2406
2441
|
clone.id = this.id;
|
2442
|
+
clone.text = this.text;
|
2407
2443
|
return clone;
|
2408
2444
|
}
|
2409
2445
|
getSerializeProps(viewOptions) {
|
2410
2446
|
return {
|
2411
|
-
id: this.id
|
2447
|
+
id: this.id,
|
2448
|
+
text: this.text
|
2412
2449
|
};
|
2413
2450
|
}
|
2414
2451
|
}
|
2415
2452
|
class CommProps extends INotifyPropertyChanged {
|
2416
2453
|
id;
|
2417
2454
|
markType;
|
2455
|
+
text;
|
2456
|
+
userId;
|
2457
|
+
userName;
|
2458
|
+
date;
|
2418
2459
|
clone(dest) {
|
2419
2460
|
const clone = dest ?? new CommProps();
|
2420
2461
|
super.cloneAttachedProperty(clone);
|
2421
2462
|
clone.id = this.id;
|
2422
2463
|
clone.markType = this.markType;
|
2464
|
+
clone.text = this.text;
|
2465
|
+
clone.userId = this.userId;
|
2466
|
+
clone.userName = this.userName;
|
2467
|
+
clone.date = this.date;
|
2423
2468
|
return clone;
|
2424
2469
|
}
|
2425
2470
|
getSerializeProps(viewOptions) {
|
2426
2471
|
return {
|
2427
2472
|
id: this.id,
|
2428
|
-
markType: this.markType
|
2473
|
+
markType: this.markType,
|
2474
|
+
text: this.text,
|
2475
|
+
userId: this.userId,
|
2476
|
+
userName: this.userName,
|
2477
|
+
date: this.date
|
2429
2478
|
};
|
2430
2479
|
}
|
2431
2480
|
}
|
@@ -2753,63 +2802,6 @@ class CommsContainerElement extends BlockContainerElement {
|
|
2753
2802
|
}
|
2754
2803
|
return clone;
|
2755
2804
|
}
|
2756
|
-
markPairs = [];
|
2757
|
-
/**
|
2758
|
-
* 清除所有的批注标识组合
|
2759
|
-
*/
|
2760
|
-
clearMarkItems() {
|
2761
|
-
this.markPairs.length = 0;
|
2762
|
-
}
|
2763
|
-
identifyCommMark(markElement) {
|
2764
|
-
const { id } = markElement.props;
|
2765
|
-
let matchItem = this.markPairs.find(item => item.id === id);
|
2766
|
-
if (!matchItem) {
|
2767
|
-
matchItem = { id };
|
2768
|
-
this.markPairs.push(matchItem);
|
2769
|
-
}
|
2770
|
-
matchItem[markElement.props.markType] = markElement;
|
2771
|
-
}
|
2772
|
-
/**
|
2773
|
-
* 根据id,移除批注标记以及批注内容
|
2774
|
-
* @param id
|
2775
|
-
*/
|
2776
|
-
removeCommMark(id) {
|
2777
|
-
const matchIndex = this.markPairs.findIndex(item => item.id === id);
|
2778
|
-
if (matchIndex >= 0) {
|
2779
|
-
const matchItem = this.markPairs[matchIndex];
|
2780
|
-
matchItem.start?.remove();
|
2781
|
-
matchItem.end?.remove();
|
2782
|
-
this.markPairs.splice(matchIndex, 1);
|
2783
|
-
}
|
2784
|
-
const commContent = this.getCommContent(id);
|
2785
|
-
if (commContent) {
|
2786
|
-
commContent.remove();
|
2787
|
-
}
|
2788
|
-
}
|
2789
|
-
/**
|
2790
|
-
* 清除所有批注
|
2791
|
-
*/
|
2792
|
-
clearAllComms() {
|
2793
|
-
for (let i = 0; i < this.markPairs.length; i++) {
|
2794
|
-
const { start, end } = this.markPairs[i];
|
2795
|
-
if (start) {
|
2796
|
-
start.remove();
|
2797
|
-
}
|
2798
|
-
if (end) {
|
2799
|
-
end.remove();
|
2800
|
-
}
|
2801
|
-
}
|
2802
|
-
this.clearItems();
|
2803
|
-
}
|
2804
|
-
getCommContent(id) {
|
2805
|
-
for (let i = 0; i < this.length; i++) {
|
2806
|
-
const commContent = this.getChild(i);
|
2807
|
-
if (commContent.props.id === id) {
|
2808
|
-
return commContent;
|
2809
|
-
}
|
2810
|
-
}
|
2811
|
-
return null;
|
2812
|
-
}
|
2813
2805
|
}
|
2814
2806
|
class CommsContainerRenderObject extends BlockContainerRenderObject {
|
2815
2807
|
//批注内容是否已经重组,只要重新绘制的时候组合一次即可
|
@@ -3271,7 +3263,7 @@ class DocumentElement extends BlockContainerElement {
|
|
3271
3263
|
bodyElement;
|
3272
3264
|
headerElement;
|
3273
3265
|
footerElement;
|
3274
|
-
commentsContainerElement;
|
3266
|
+
//commentsContainerElement!: CommsContainerElement;
|
3275
3267
|
headerEditState = false;
|
3276
3268
|
constructor() {
|
3277
3269
|
super('doc');
|
@@ -3349,6 +3341,49 @@ class DocumentElement extends BlockContainerElement {
|
|
3349
3341
|
ss.clear();
|
3350
3342
|
this.refreshView();
|
3351
3343
|
}
|
3344
|
+
markPairs = [];
|
3345
|
+
/**
|
3346
|
+
* 清除所有的批注标识组合
|
3347
|
+
*/
|
3348
|
+
clearMarkItems() {
|
3349
|
+
this.markPairs.length = 0;
|
3350
|
+
}
|
3351
|
+
identifyCommMark(markElement) {
|
3352
|
+
const { id } = markElement.props;
|
3353
|
+
let matchItem = this.markPairs.find(item => item.id === id);
|
3354
|
+
if (!matchItem) {
|
3355
|
+
matchItem = { id };
|
3356
|
+
this.markPairs.push(matchItem);
|
3357
|
+
}
|
3358
|
+
matchItem[markElement.props.markType] = markElement;
|
3359
|
+
}
|
3360
|
+
/**
|
3361
|
+
* 根据id,移除批注标记以及批注内容
|
3362
|
+
* @param id
|
3363
|
+
*/
|
3364
|
+
removeCommMark(id) {
|
3365
|
+
const matchIndex = this.markPairs.findIndex(item => item.id === id);
|
3366
|
+
if (matchIndex >= 0) {
|
3367
|
+
const matchItem = this.markPairs[matchIndex];
|
3368
|
+
matchItem.start?.remove();
|
3369
|
+
matchItem.end?.remove();
|
3370
|
+
this.markPairs.splice(matchIndex, 1);
|
3371
|
+
}
|
3372
|
+
}
|
3373
|
+
/**
|
3374
|
+
* 清除所有批注
|
3375
|
+
*/
|
3376
|
+
clearAllComms() {
|
3377
|
+
for (let i = 0; i < this.markPairs.length; i++) {
|
3378
|
+
const { start, end } = this.markPairs[i];
|
3379
|
+
if (start) {
|
3380
|
+
start.remove();
|
3381
|
+
}
|
3382
|
+
if (end) {
|
3383
|
+
end.remove();
|
3384
|
+
}
|
3385
|
+
}
|
3386
|
+
}
|
3352
3387
|
}
|
3353
3388
|
class DocumentRenderObject extends BlockContainerRenderObject {
|
3354
3389
|
constructor(ele) {
|
@@ -4706,7 +4741,7 @@ class TableRowRenderObject extends MuiltBlockLineRenderObject {
|
|
4706
4741
|
//被截断的行是否需要重新计算高度
|
4707
4742
|
remeasureState = true;
|
4708
4743
|
//当前行是否存在合并单元格
|
4709
|
-
hasMergeCells =
|
4744
|
+
hasMergeCells = undefined;
|
4710
4745
|
render(e) {
|
4711
4746
|
}
|
4712
4747
|
clone() {
|
@@ -5345,7 +5380,7 @@ class DocumentCursor {
|
|
5345
5380
|
}
|
5346
5381
|
|
5347
5382
|
class RangeUtil {
|
5348
|
-
static
|
5383
|
+
static getSectionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl) {
|
5349
5384
|
if (ancestorCommonControl instanceof TableElement || ancestorCommonControl instanceof TableRowElement) {
|
5350
5385
|
const tbElement = ancestorCommonControl instanceof TableElement ? ancestorCommonControl : ancestorCommonControl.parent;
|
5351
5386
|
return this.getTableSelectionRange(startControl, startOffset, endControl, endOffset, tbElement);
|
@@ -5424,7 +5459,7 @@ class RangeUtil {
|
|
5424
5459
|
});
|
5425
5460
|
}
|
5426
5461
|
else {
|
5427
|
-
const cellRange = this.
|
5462
|
+
const cellRange = this.getSectionRange(cellFirstLeafElement, 0, cellLastLeafElement, 1, cell);
|
5428
5463
|
cellRanges.push(cellRange);
|
5429
5464
|
}
|
5430
5465
|
}
|
@@ -7263,12 +7298,42 @@ class CommentsUtil {
|
|
7263
7298
|
}
|
7264
7299
|
}
|
7265
7300
|
|
7301
|
+
let activeEditorContext = null;
|
7302
|
+
function setActiveEditorContext(ctx) {
|
7303
|
+
activeEditorContext = ctx;
|
7304
|
+
}
|
7305
|
+
function getActiveEditorContext() {
|
7306
|
+
return activeEditorContext;
|
7307
|
+
}
|
7308
|
+
function createSignal(state) {
|
7309
|
+
let _state = state;
|
7310
|
+
const activeCtx = activeEditorContext;
|
7311
|
+
const signal = {
|
7312
|
+
get value() {
|
7313
|
+
return _state;
|
7314
|
+
},
|
7315
|
+
set value(v) {
|
7316
|
+
if (v === _state) {
|
7317
|
+
return;
|
7318
|
+
}
|
7319
|
+
_state = v;
|
7320
|
+
signal.onChange();
|
7321
|
+
},
|
7322
|
+
onChange: () => {
|
7323
|
+
activeCtx?.onChange();
|
7324
|
+
}
|
7325
|
+
};
|
7326
|
+
return signal;
|
7327
|
+
}
|
7328
|
+
|
7266
7329
|
class CommentElement extends LeafElement {
|
7330
|
+
color;
|
7267
7331
|
constructor() {
|
7268
7332
|
super('comm');
|
7269
7333
|
this.isDecorate = true;
|
7270
7334
|
this.disableClick = true;
|
7271
7335
|
this.props = new CommProps();
|
7336
|
+
this.color = CommonUtil.randomRgbColor(0.5);
|
7272
7337
|
}
|
7273
7338
|
createRenderObject() {
|
7274
7339
|
const render = new CommentRenderObject(this);
|
@@ -7321,6 +7386,7 @@ class CommentRenderObject extends LeafRenderObject {
|
|
7321
7386
|
}
|
7322
7387
|
}
|
7323
7388
|
}];
|
7389
|
+
this.createCommentTips(event);
|
7324
7390
|
return t;
|
7325
7391
|
}
|
7326
7392
|
clone() {
|
@@ -7328,6 +7394,90 @@ class CommentRenderObject extends LeafRenderObject {
|
|
7328
7394
|
clone.rect = ElementUtil.cloneRect(this.rect);
|
7329
7395
|
return clone;
|
7330
7396
|
}
|
7397
|
+
createCommentTips(event) {
|
7398
|
+
if (this.element.props.markType === 'end') {
|
7399
|
+
return;
|
7400
|
+
}
|
7401
|
+
if (this.element.paintRenders.indexOf(this) !== 0) {
|
7402
|
+
return;
|
7403
|
+
}
|
7404
|
+
const appCtx = getActiveEditorContext();
|
7405
|
+
const opType = '批注:';
|
7406
|
+
const content = this.element.props.text;
|
7407
|
+
const left = 5;
|
7408
|
+
let sel = 'div.tg-container';
|
7409
|
+
const node = {
|
7410
|
+
sel,
|
7411
|
+
key: this.element.props.id,
|
7412
|
+
data: {
|
7413
|
+
style: {
|
7414
|
+
left: `${left}px`,
|
7415
|
+
top: `${event.globalPos.y}px`
|
7416
|
+
},
|
7417
|
+
on: {
|
7418
|
+
click: (e) => {
|
7419
|
+
e.stopPropagation();
|
7420
|
+
appCtx?.emit('comment-click', {
|
7421
|
+
...this.element.props
|
7422
|
+
});
|
7423
|
+
//this.showCommentRange(appCtx!);
|
7424
|
+
},
|
7425
|
+
dblclick: (e) => {
|
7426
|
+
e.stopPropagation();
|
7427
|
+
appCtx?.emit('comment-dblclick', {
|
7428
|
+
...this.element.props
|
7429
|
+
});
|
7430
|
+
}
|
7431
|
+
}
|
7432
|
+
},
|
7433
|
+
children: [{
|
7434
|
+
sel: 'div.header',
|
7435
|
+
data: {},
|
7436
|
+
children: [{
|
7437
|
+
sel: 'span.header-user',
|
7438
|
+
data: {},
|
7439
|
+
text: this.element.props.userName,
|
7440
|
+
}, {
|
7441
|
+
sel: 'span.header-date',
|
7442
|
+
data: {},
|
7443
|
+
text: this.element.props.date,
|
7444
|
+
}]
|
7445
|
+
}, {
|
7446
|
+
sel: 'div.content',
|
7447
|
+
data: {},
|
7448
|
+
text: opType + content
|
7449
|
+
}, {
|
7450
|
+
sel: 'div.bg',
|
7451
|
+
data: {
|
7452
|
+
style: {
|
7453
|
+
background: this.element.color
|
7454
|
+
}
|
7455
|
+
}
|
7456
|
+
}]
|
7457
|
+
};
|
7458
|
+
event.addChangeTips(node);
|
7459
|
+
// <div class="container">
|
7460
|
+
// <div class="header">
|
7461
|
+
// <span class="header-user">张三</span>
|
7462
|
+
// <span class="header-date">2023.1.21 16:06</span>
|
7463
|
+
// </div>
|
7464
|
+
// <div class="content">修改了字符串</div>
|
7465
|
+
// </div>
|
7466
|
+
}
|
7467
|
+
/**
|
7468
|
+
* 显示批注范围
|
7469
|
+
* @private
|
7470
|
+
*/
|
7471
|
+
showCommentRange(appCtx) {
|
7472
|
+
const doc = ElementUtil.getParent(this.element, (item) => item.type === 'doc');
|
7473
|
+
const commPair = doc.treeFilter(item => item instanceof CommentElement && item.props.id === this.element.props.id);
|
7474
|
+
if (commPair.length === 2) {
|
7475
|
+
const range = new SelectionRange();
|
7476
|
+
range.setStart(commPair[0], 0);
|
7477
|
+
range.setEnd(commPair[1], 1);
|
7478
|
+
appCtx.selectionState.addRange(range);
|
7479
|
+
}
|
7480
|
+
}
|
7331
7481
|
}
|
7332
7482
|
class CommentFactory extends ElementFactory {
|
7333
7483
|
match(type) {
|
@@ -7338,6 +7488,7 @@ class CommentFactory extends ElementFactory {
|
|
7338
7488
|
const props = data.props;
|
7339
7489
|
ele.props.id = props.id;
|
7340
7490
|
ele.props.markType = props.markType;
|
7491
|
+
ele.props.text = props.text;
|
7341
7492
|
return ele;
|
7342
7493
|
}
|
7343
7494
|
}
|
@@ -8901,18 +9052,6 @@ class DataElementImage extends DataElementLeaf {
|
|
8901
9052
|
this.props.clone(clone.props);
|
8902
9053
|
return clone;
|
8903
9054
|
}
|
8904
|
-
loadImage(ctx) {
|
8905
|
-
if (this.status === 'no') {
|
8906
|
-
this.status = 'loading';
|
8907
|
-
const onCallback = (status) => {
|
8908
|
-
this.status = status;
|
8909
|
-
if (status === 'completed') {
|
8910
|
-
this.refreshView();
|
8911
|
-
}
|
8912
|
-
};
|
8913
|
-
ctx.imageLoader.loadImage(this.props.src, onCallback);
|
8914
|
-
}
|
8915
|
-
}
|
8916
9055
|
destroy() {
|
8917
9056
|
super.destroy();
|
8918
9057
|
}
|
@@ -8928,38 +9067,6 @@ class DataElementImage extends DataElementLeaf {
|
|
8928
9067
|
}
|
8929
9068
|
class DataImageRenderObject extends ResizeLeafRenderObject {
|
8930
9069
|
render(e) {
|
8931
|
-
const { render, position, docCtx } = e;
|
8932
|
-
const dataImgElement = this.element;
|
8933
|
-
const picProps = dataImgElement.props;
|
8934
|
-
if (dataImgElement.status === 'no') {
|
8935
|
-
dataImgElement.loadImage(docCtx);
|
8936
|
-
return;
|
8937
|
-
}
|
8938
|
-
if (dataImgElement.status === 'completed') {
|
8939
|
-
const imageSource = docCtx.imageLoader.getImage(picProps.src);
|
8940
|
-
if (!imageSource) {
|
8941
|
-
return;
|
8942
|
-
}
|
8943
|
-
if (picProps.border === 'all') {
|
8944
|
-
render.contentContext.strokeRect(position.x, position.y, this.rect.width, this.rect.height, 'black');
|
8945
|
-
}
|
8946
|
-
render.contentContext.ctx.drawImage(imageSource, 0, 0, imageSource.naturalWidth, imageSource.naturalHeight, position.x + 2, position.y + 2, picProps.width, picProps.height);
|
8947
|
-
}
|
8948
|
-
if (render.drawMode === 'view') {
|
8949
|
-
let { x, y } = position;
|
8950
|
-
const { width, height } = this.rect;
|
8951
|
-
const lineWidth = 5;
|
8952
|
-
const paintColor = '#0050b3';
|
8953
|
-
render.contentContext.strokeLines([{ x: x + lineWidth, y }, { x, y }, { x, y: y + height }, {
|
8954
|
-
x: x + lineWidth,
|
8955
|
-
y: y + height
|
8956
|
-
}], 1, paintColor);
|
8957
|
-
x = x + width;
|
8958
|
-
render.contentContext.strokeLines([{ x: x - lineWidth, y }, { x, y }, { x, y: y + height }, {
|
8959
|
-
x: x - lineWidth,
|
8960
|
-
y: y + height
|
8961
|
-
}], 1, paintColor);
|
8962
|
-
}
|
8963
9070
|
}
|
8964
9071
|
clone() {
|
8965
9072
|
const clone = new DataImageRenderObject(this.element);
|
@@ -9836,51 +9943,12 @@ class PictureElement extends LeafElement {
|
|
9836
9943
|
this.props.clone(clone.props);
|
9837
9944
|
return clone;
|
9838
9945
|
}
|
9839
|
-
loadImage(ctx) {
|
9840
|
-
if (this.status === 'no') {
|
9841
|
-
this.status = 'loading';
|
9842
|
-
//this.imageSource = new Image();
|
9843
|
-
//this.imageSource.src = this.props.src;
|
9844
|
-
// const onload = (e: any) => {
|
9845
|
-
// this.isLoad = 'completed';
|
9846
|
-
// this.refreshView('appearance');
|
9847
|
-
// };
|
9848
|
-
// const onerror = (e: any) => {
|
9849
|
-
// this.isLoad = 'error';
|
9850
|
-
// console.error(e);
|
9851
|
-
// };
|
9852
|
-
const onCallback = (status) => {
|
9853
|
-
this.status = status;
|
9854
|
-
if (status === 'completed') {
|
9855
|
-
this.refreshView();
|
9856
|
-
}
|
9857
|
-
};
|
9858
|
-
ctx.imageLoader.loadImage(this.props.src, onCallback);
|
9859
|
-
}
|
9860
|
-
}
|
9861
9946
|
destroy() {
|
9862
9947
|
super.destroy();
|
9863
9948
|
}
|
9864
9949
|
}
|
9865
9950
|
class PictureRenderObject extends ResizeLeafRenderObject {
|
9866
9951
|
render(e) {
|
9867
|
-
const { render, position, docCtx } = e;
|
9868
|
-
const picElement = this.element;
|
9869
|
-
const picProps = picElement.props;
|
9870
|
-
if (picElement.status === 'no') {
|
9871
|
-
picElement.loadImage(docCtx);
|
9872
|
-
return;
|
9873
|
-
}
|
9874
|
-
if (picElement.status === 'completed') {
|
9875
|
-
const imageSource = docCtx.imageLoader.getImage(picProps.src);
|
9876
|
-
if (!imageSource) {
|
9877
|
-
return;
|
9878
|
-
}
|
9879
|
-
if (picProps.border === 'all') {
|
9880
|
-
render.contentContext.strokeRect(position.x, position.y, this.rect.width, this.rect.height, 'black');
|
9881
|
-
}
|
9882
|
-
render.contentContext.ctx.drawImage(imageSource, 0, 0, imageSource.naturalWidth, imageSource.naturalHeight, position.x + 2, position.y + 2, picProps.width, picProps.height);
|
9883
|
-
}
|
9884
9952
|
}
|
9885
9953
|
clone() {
|
9886
9954
|
const clone = new PictureRenderObject(this.element);
|
@@ -13297,29 +13365,29 @@ class ElementPaint {
|
|
13297
13365
|
this.renderCtx.contentContext.fillRect(currPosition.x, currPosition.y, renderObject.rect.width, renderObject.rect.height, this.viewOptions.selectionOverlaysColor);
|
13298
13366
|
}
|
13299
13367
|
}
|
13300
|
-
if (inViewPort && this.viewOptions.showReviewWindow && this.docCtx.document.commentsContainerElement.cacheRender.selectedSet.has(element)) {
|
13301
|
-
|
13302
|
-
|
13303
|
-
|
13304
|
-
|
13305
|
-
|
13306
|
-
|
13307
|
-
|
13308
|
-
|
13309
|
-
|
13310
|
-
|
13311
|
-
|
13312
|
-
|
13313
|
-
|
13314
|
-
|
13315
|
-
|
13316
|
-
|
13317
|
-
|
13318
|
-
|
13319
|
-
|
13320
|
-
|
13321
|
-
|
13322
|
-
}
|
13368
|
+
// if (inViewPort && this.viewOptions.showReviewWindow && (<CommsContainerRenderObject>this.docCtx.document.commentsContainerElement.cacheRender).selectedSet.has(element)) {
|
13369
|
+
// if (renderObject instanceof LeafRenderObject || renderObject instanceof DataElementRenderObject) {
|
13370
|
+
// const measureCommContainer=<CommsContainerRenderObject>this.docCtx.document.commentsContainerElement.cacheRender;
|
13371
|
+
// const range = measureCommContainer.selectedSet.get(element) as SelectionContentRange;
|
13372
|
+
// if (range.isFullSelected) {
|
13373
|
+
// let commentRangePaintColor = '#ffd591';
|
13374
|
+
// for (let i = 0; i < measureCommContainer.commentRangeStatus.length; i++) {
|
13375
|
+
// const commentRangeStatus = measureCommContainer.commentRangeStatus[i];
|
13376
|
+
// if (commentRangeStatus.commContent.focus) {
|
13377
|
+
// if (RangeUtil.checkElementFullInRange(commentRangeStatus.range, element)) {
|
13378
|
+
// commentRangePaintColor = '#fa8c16';
|
13379
|
+
// }
|
13380
|
+
// }
|
13381
|
+
// }
|
13382
|
+
// const overlayRect = { x: currPosition.x, y: currPosition.y, width: rw, height: rh };
|
13383
|
+
// const paraLinePos = ElementUtil.getParaLinePos(renderObject, {
|
13384
|
+
// x: currPosition.x,
|
13385
|
+
// y: currPosition.y
|
13386
|
+
// });
|
13387
|
+
// this.renderCtx.overlaysContext.fillRect(overlayRect.x, paraLinePos.y, overlayRect.width, paraLinePos.height, commentRangePaintColor);
|
13388
|
+
// }
|
13389
|
+
// }
|
13390
|
+
// }
|
13323
13391
|
}
|
13324
13392
|
/**
|
13325
13393
|
* 触发页面绘制结束事件
|
@@ -13338,149 +13406,30 @@ class ElementPaint {
|
|
13338
13406
|
const { x: rx, y: ry } = renderObject.rect;
|
13339
13407
|
const currPosition = { x: rx + parent.x, y: ry + parent.y };
|
13340
13408
|
if (renderObject instanceof BranchRenderObject) {
|
13341
|
-
const nextRenderFn = onceTask(() => {
|
13342
|
-
for (let i = 0; i < renderObject.length; i++) {
|
13343
|
-
const child = renderObject.getChild(i);
|
13344
|
-
this.drawPage(renderCtx, docCtx, child, currPosition);
|
13345
|
-
}
|
13346
|
-
});
|
13347
|
-
const renderData = {
|
13348
|
-
position: currPosition,
|
13349
|
-
nextRender: nextRenderFn,
|
13350
|
-
render: renderCtx,
|
13351
|
-
docCtx
|
13352
|
-
};
|
13353
|
-
renderObject.render(renderData);
|
13354
|
-
nextRenderFn();
|
13355
|
-
}
|
13356
|
-
else if (renderObject instanceof LeafRenderObject) {
|
13357
|
-
const renderData = {
|
13358
|
-
position: currPosition,
|
13359
|
-
nextRender: () => { },
|
13360
|
-
render: renderCtx,
|
13361
|
-
docCtx: docCtx
|
13362
|
-
};
|
13363
|
-
renderObject.render(renderData);
|
13364
|
-
}
|
13365
|
-
}
|
13366
|
-
}
|
13367
|
-
|
13368
|
-
/**
|
13369
|
-
* 用于处理选区拖蓝
|
13370
|
-
*/
|
13371
|
-
class SelectionOverlays {
|
13372
|
-
selectionState;
|
13373
|
-
selectionRange;
|
13374
|
-
selectedSets = new Map();
|
13375
|
-
constructor(selectionState) {
|
13376
|
-
this.selectionState = selectionState;
|
13377
|
-
}
|
13378
|
-
getSelectionTreeData() {
|
13379
|
-
let { ancestorCommonControl, startControl, startOffset, endControl, endOffset, collapsed } = this.selectionState;
|
13380
|
-
this.selectedSets.clear();
|
13381
|
-
if (this.selectionRange) {
|
13382
|
-
this.selectionRange.selectedChildren.length = 0;
|
13383
|
-
}
|
13384
|
-
this.selectionRange = null;
|
13385
|
-
if (!startControl || !endControl || !ancestorCommonControl) {
|
13386
|
-
//this.selectionRange?.selectedChildren.length=0;
|
13387
|
-
this.selectionState.selectedRange = null;
|
13388
|
-
return;
|
13389
|
-
}
|
13390
|
-
if (collapsed) {
|
13391
|
-
const commonRange = RangeUtil.getSelctionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
|
13392
|
-
this.selectionState.selectedRange = commonRange;
|
13393
|
-
this.selectedSets.clear();
|
13394
|
-
return;
|
13395
|
-
}
|
13396
|
-
const fixStartElement = this.fixStartSelectionElement(startControl, startOffset, ancestorCommonControl);
|
13397
|
-
startControl = fixStartElement.element;
|
13398
|
-
startOffset = fixStartElement.offset;
|
13399
|
-
const fixEndElement = this.fixEndSelectionElement(endControl, endOffset, ancestorCommonControl);
|
13400
|
-
endControl = fixEndElement.element;
|
13401
|
-
endOffset = fixEndElement.offset;
|
13402
|
-
const commonRange = RangeUtil.getSelctionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
|
13403
|
-
//console.log(commonRange);
|
13404
|
-
this.selectionRange = commonRange;
|
13405
|
-
this.convertSelectRangeToSet();
|
13406
|
-
this.selectionState.selectedRange = commonRange;
|
13407
|
-
}
|
13408
|
-
convertSelectRangeToSet() {
|
13409
|
-
this.selectedSets.clear();
|
13410
|
-
if (this.selectionRange) {
|
13411
|
-
SelectionOverlays.addToSets(this.selectionRange, this.selectedSets);
|
13412
|
-
}
|
13413
|
-
}
|
13414
|
-
static addToSets(range, set) {
|
13415
|
-
set.set(range.target, range);
|
13416
|
-
for (let i = 0; i < range.selectedChildren.length; i++) {
|
13417
|
-
//单元格全部选中效果,单元格整个拖蓝即可
|
13418
|
-
if (range.isFullSelected && range.target.type === 'tbc') {
|
13419
|
-
continue;
|
13420
|
-
}
|
13421
|
-
this.addToSets(range.selectedChildren[i], set);
|
13422
|
-
}
|
13423
|
-
}
|
13424
|
-
/**
|
13425
|
-
* 添加到批注集合
|
13426
|
-
* @param range
|
13427
|
-
* @param set
|
13428
|
-
*/
|
13429
|
-
static addToCommentSets(range, set) {
|
13430
|
-
set.set(range.target, range);
|
13431
|
-
for (let i = 0; i < range.selectedChildren.length; i++) {
|
13432
|
-
this.addToCommentSets(range.selectedChildren[i], set);
|
13433
|
-
}
|
13434
|
-
}
|
13435
|
-
/**
|
13436
|
-
* 修正开始选区内容
|
13437
|
-
* 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
|
13438
|
-
*/
|
13439
|
-
fixStartSelectionElement(element, offset, ancestorCommonControl) {
|
13440
|
-
if (!(ancestorCommonControl instanceof TableElement)) {
|
13441
|
-
const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
|
13442
|
-
if (lookupParentCell) {
|
13443
|
-
if (!lookupParentCell.parent || !lookupParentCell.parent.parent) ;
|
13444
|
-
const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
|
13445
|
-
const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
|
13446
|
-
if (ancestorCommonControlIndex < lookupParentTbIndex) {
|
13447
|
-
const rowFirstLeafElement = ElementUtil.getFirstLeafElement(lookupParentCell.parent);
|
13448
|
-
if (!rowFirstLeafElement) {
|
13449
|
-
throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
|
13450
|
-
}
|
13451
|
-
return {
|
13452
|
-
element: rowFirstLeafElement,
|
13453
|
-
offset: 0
|
13454
|
-
};
|
13455
|
-
}
|
13456
|
-
}
|
13457
|
-
}
|
13458
|
-
return { element, offset };
|
13459
|
-
}
|
13460
|
-
/**
|
13461
|
-
* 修正开始选区内容
|
13462
|
-
* 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
|
13463
|
-
*/
|
13464
|
-
fixEndSelectionElement(element, offset, ancestorCommonControl) {
|
13465
|
-
if (!(ancestorCommonControl instanceof TableElement)) {
|
13466
|
-
const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
|
13467
|
-
if (lookupParentCell) {
|
13468
|
-
const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
|
13469
|
-
const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
|
13470
|
-
if (ancestorCommonControlIndex < lookupParentTbIndex) {
|
13471
|
-
const rowLastLeafElement = ElementUtil.getLastLeafElement(lookupParentCell.parent);
|
13472
|
-
if (!rowLastLeafElement) {
|
13473
|
-
ElementUtil.getLastLeafElement(lookupParentCell.parent);
|
13474
|
-
throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
|
13475
|
-
}
|
13476
|
-
return {
|
13477
|
-
element: rowLastLeafElement,
|
13478
|
-
offset: 1
|
13479
|
-
};
|
13409
|
+
const nextRenderFn = onceTask(() => {
|
13410
|
+
for (let i = 0; i < renderObject.length; i++) {
|
13411
|
+
const child = renderObject.getChild(i);
|
13412
|
+
this.drawPage(renderCtx, docCtx, child, currPosition);
|
13480
13413
|
}
|
13481
|
-
}
|
13414
|
+
});
|
13415
|
+
const renderData = {
|
13416
|
+
position: currPosition,
|
13417
|
+
nextRender: nextRenderFn,
|
13418
|
+
render: renderCtx,
|
13419
|
+
docCtx
|
13420
|
+
};
|
13421
|
+
renderObject.render(renderData);
|
13422
|
+
nextRenderFn();
|
13423
|
+
}
|
13424
|
+
else if (renderObject instanceof LeafRenderObject) {
|
13425
|
+
const renderData = {
|
13426
|
+
position: currPosition,
|
13427
|
+
nextRender: () => { },
|
13428
|
+
render: renderCtx,
|
13429
|
+
docCtx: docCtx
|
13430
|
+
};
|
13431
|
+
renderObject.render(renderData);
|
13482
13432
|
}
|
13483
|
-
return { element, offset };
|
13484
13433
|
}
|
13485
13434
|
}
|
13486
13435
|
|
@@ -13532,78 +13481,6 @@ class DocumentEvalFunc {
|
|
13532
13481
|
}
|
13533
13482
|
}
|
13534
13483
|
|
13535
|
-
class DocumentImagesBaseLoader {
|
13536
|
-
images = [];
|
13537
|
-
clear() {
|
13538
|
-
this.images.length = 0;
|
13539
|
-
}
|
13540
|
-
loadImage(src, onCallback) {
|
13541
|
-
if (!src) {
|
13542
|
-
return;
|
13543
|
-
}
|
13544
|
-
//已经存在的资源不需要重新加载
|
13545
|
-
let matchItem = this.images.find(item => item.src === src);
|
13546
|
-
if (matchItem) {
|
13547
|
-
if (matchItem.loadStatus === 'no') {
|
13548
|
-
matchItem.cbs.push(onCallback);
|
13549
|
-
}
|
13550
|
-
else {
|
13551
|
-
onCallback(matchItem.loadStatus);
|
13552
|
-
}
|
13553
|
-
return;
|
13554
|
-
}
|
13555
|
-
const task = this.createRequestImage(src);
|
13556
|
-
const imgItem = {
|
13557
|
-
ele: undefined,
|
13558
|
-
src,
|
13559
|
-
cbs: [onCallback],
|
13560
|
-
loadStatus: 'no',
|
13561
|
-
task
|
13562
|
-
};
|
13563
|
-
this.images.push(imgItem);
|
13564
|
-
// if (this.viewOptions.resourceMode === 'immediate') {
|
13565
|
-
// ele.onload = (e) => { this.invokeImgLoad(src, 'completed'); };
|
13566
|
-
// ele.onerror = (e) => { this.invokeImgLoad(src, 'error'); };
|
13567
|
-
// }
|
13568
|
-
}
|
13569
|
-
invokeImgLoad(src, status, data) {
|
13570
|
-
const img = this.images.find(item => item.src === src);
|
13571
|
-
if (img) {
|
13572
|
-
img.loadStatus = status;
|
13573
|
-
img.cbs.forEach(cb => cb(status));
|
13574
|
-
img.ele = data;
|
13575
|
-
}
|
13576
|
-
}
|
13577
|
-
getLoadTasks() {
|
13578
|
-
return this.images.map(item => item.task);
|
13579
|
-
}
|
13580
|
-
getImage(src) {
|
13581
|
-
const img = this.images.find(item => item.src === src);
|
13582
|
-
return img?.ele;
|
13583
|
-
}
|
13584
|
-
/**
|
13585
|
-
* 判断图片是否都已经加载完毕
|
13586
|
-
* 用于打印时判断,如果当前图片没有加载完毕就打印,图片是打印不出来
|
13587
|
-
* @returns
|
13588
|
-
*/
|
13589
|
-
imagesLoadCompleted() {
|
13590
|
-
if (this.images.length === 0) {
|
13591
|
-
return true;
|
13592
|
-
}
|
13593
|
-
return this.images.every(item => ['completed', 'error'].includes(item.loadStatus));
|
13594
|
-
}
|
13595
|
-
}
|
13596
|
-
class DocumentImagesLoader extends DocumentImagesBaseLoader {
|
13597
|
-
createRequestImage(url) {
|
13598
|
-
const ele = new Image();
|
13599
|
-
ele.src = url;
|
13600
|
-
return new Promise((r, i) => {
|
13601
|
-
ele.onload = (e) => { this.invokeImgLoad(url, 'completed', ele); r(); };
|
13602
|
-
ele.onerror = (e) => { this.invokeImgLoad(url, 'error', ele); r(); };
|
13603
|
-
});
|
13604
|
-
}
|
13605
|
-
}
|
13606
|
-
|
13607
13484
|
/**
|
13608
13485
|
* 当前打开的文档的上下文信息,当前文档所有的属性设置都暴露在上下文中
|
13609
13486
|
*/
|
@@ -13616,7 +13493,7 @@ class EditorContext {
|
|
13616
13493
|
//文档刷新的订阅事件
|
13617
13494
|
//refSub!: Subscription;
|
13618
13495
|
syncRefresh;
|
13619
|
-
imageLoader;
|
13496
|
+
//imageLoader: IImageLoader;
|
13620
13497
|
dynamicFunc;
|
13621
13498
|
docChange;
|
13622
13499
|
clearPrevDocCb;
|
@@ -13626,7 +13503,7 @@ class EditorContext {
|
|
13626
13503
|
this.selectionState = selectionState;
|
13627
13504
|
this.viewOptions = viewOptions;
|
13628
13505
|
this.dynamicFunc = new DocumentEvalFunc(this);
|
13629
|
-
this.imageLoader = new DocumentImagesLoader();
|
13506
|
+
//this.imageLoader = new DocumentImagesLoader();
|
13630
13507
|
this.selectionState.onChangedEvent.subscribe(() => {
|
13631
13508
|
this.syncRefresh?.();
|
13632
13509
|
});
|
@@ -13667,7 +13544,7 @@ class EditorContext {
|
|
13667
13544
|
}
|
13668
13545
|
clear() {
|
13669
13546
|
this.selectionState.clear();
|
13670
|
-
this.imageLoader.clear();
|
13547
|
+
//this.imageLoader.clear();
|
13671
13548
|
this.dynamicFunc.destroyScripts();
|
13672
13549
|
this.isDirty = false;
|
13673
13550
|
}
|
@@ -13709,7 +13586,7 @@ class EditorContext {
|
|
13709
13586
|
this.document.destroy();
|
13710
13587
|
this.clearPrevDocCb?.();
|
13711
13588
|
//this.ele_types_handlers.length = 0;
|
13712
|
-
this.imageLoader.clear();
|
13589
|
+
//this.imageLoader.clear();
|
13713
13590
|
this._document = null;
|
13714
13591
|
}
|
13715
13592
|
/**
|
@@ -13744,6 +13621,17 @@ class EditorContext {
|
|
13744
13621
|
return this._document.modifyFlag === exports.ModifyFlag.None ? 'appearance' : 'content';
|
13745
13622
|
}
|
13746
13623
|
}
|
13624
|
+
// export interface IImageLoader {
|
13625
|
+
// clear(): void;
|
13626
|
+
//
|
13627
|
+
// loadImage(src: string, onCallback: (status: ImgLoadStatus) => void): void;
|
13628
|
+
//
|
13629
|
+
// getImage(src: string): HTMLImageElement | undefined;
|
13630
|
+
//
|
13631
|
+
// imagesLoadCompleted(): boolean;
|
13632
|
+
//
|
13633
|
+
// getLoadTasks(): Array<Promise<void>>;
|
13634
|
+
// }
|
13747
13635
|
/**
|
13748
13636
|
* 文档上下文
|
13749
13637
|
*/
|
@@ -14637,13 +14525,139 @@ class ParagraphMeasure {
|
|
14637
14525
|
}
|
14638
14526
|
}
|
14639
14527
|
|
14528
|
+
/**
|
14529
|
+
* 用于处理选区拖蓝
|
14530
|
+
*/
|
14531
|
+
class SelectionOverlays {
|
14532
|
+
selectionState;
|
14533
|
+
selectionRange;
|
14534
|
+
//选区对象集合
|
14535
|
+
selectionEleSets = new Map();
|
14536
|
+
//批注对象集合
|
14537
|
+
commRangeSets = new Map();
|
14538
|
+
constructor(selectionState) {
|
14539
|
+
this.selectionState = selectionState;
|
14540
|
+
}
|
14541
|
+
getSelectionTreeData() {
|
14542
|
+
let { ancestorCommonControl, startControl, startOffset, endControl, endOffset, collapsed } = this.selectionState;
|
14543
|
+
this.selectionEleSets.clear();
|
14544
|
+
if (this.selectionRange) {
|
14545
|
+
this.selectionRange.selectedChildren.length = 0;
|
14546
|
+
}
|
14547
|
+
this.selectionRange = null;
|
14548
|
+
if (!startControl || !endControl || !ancestorCommonControl) {
|
14549
|
+
//this.selectionRange?.selectedChildren.length=0;
|
14550
|
+
this.selectionState.selectedRange = null;
|
14551
|
+
return;
|
14552
|
+
}
|
14553
|
+
if (collapsed) {
|
14554
|
+
const commonRange = RangeUtil.getSectionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
|
14555
|
+
this.selectionState.selectedRange = commonRange;
|
14556
|
+
this.selectionEleSets.clear();
|
14557
|
+
return;
|
14558
|
+
}
|
14559
|
+
const fixStartElement = this.fixStartSelectionElement(startControl, startOffset, ancestorCommonControl);
|
14560
|
+
startControl = fixStartElement.element;
|
14561
|
+
startOffset = fixStartElement.offset;
|
14562
|
+
const fixEndElement = this.fixEndSelectionElement(endControl, endOffset, ancestorCommonControl);
|
14563
|
+
endControl = fixEndElement.element;
|
14564
|
+
endOffset = fixEndElement.offset;
|
14565
|
+
const commonRange = RangeUtil.getSectionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
|
14566
|
+
//console.log(commonRange);
|
14567
|
+
this.selectionRange = commonRange;
|
14568
|
+
this.convertSelectRangeToSet();
|
14569
|
+
this.selectionState.selectedRange = commonRange;
|
14570
|
+
}
|
14571
|
+
convertSelectRangeToSet() {
|
14572
|
+
this.selectionEleSets.clear();
|
14573
|
+
if (this.selectionRange) {
|
14574
|
+
SelectionOverlays.addToSets(this.selectionRange, this.selectionEleSets);
|
14575
|
+
}
|
14576
|
+
}
|
14577
|
+
static addToSets(range, set) {
|
14578
|
+
set.set(range.target, range);
|
14579
|
+
for (let i = 0; i < range.selectedChildren.length; i++) {
|
14580
|
+
//单元格全部选中效果,单元格整个拖蓝即可
|
14581
|
+
if (range.isFullSelected && range.target.type === 'tbc') {
|
14582
|
+
continue;
|
14583
|
+
}
|
14584
|
+
this.addToSets(range.selectedChildren[i], set);
|
14585
|
+
}
|
14586
|
+
}
|
14587
|
+
/**
|
14588
|
+
* 添加到批注集合
|
14589
|
+
* @param range
|
14590
|
+
* @param set
|
14591
|
+
* @param rangeColor 用以显示批注区间的颜色
|
14592
|
+
*/
|
14593
|
+
static addToCommentSets(range, set, rangeColor) {
|
14594
|
+
range['rangeColor'] = rangeColor;
|
14595
|
+
set.set(range.target, range);
|
14596
|
+
for (let i = 0; i < range.selectedChildren.length; i++) {
|
14597
|
+
this.addToCommentSets(range.selectedChildren[i], set, rangeColor);
|
14598
|
+
}
|
14599
|
+
}
|
14600
|
+
/**
|
14601
|
+
* 修正开始选区内容
|
14602
|
+
* 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
|
14603
|
+
*/
|
14604
|
+
fixStartSelectionElement(element, offset, ancestorCommonControl) {
|
14605
|
+
if (!(ancestorCommonControl instanceof TableElement)) {
|
14606
|
+
const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
|
14607
|
+
if (lookupParentCell) {
|
14608
|
+
if (!lookupParentCell.parent || !lookupParentCell.parent.parent) ;
|
14609
|
+
const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
|
14610
|
+
const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
|
14611
|
+
if (ancestorCommonControlIndex < lookupParentTbIndex) {
|
14612
|
+
const rowFirstLeafElement = ElementUtil.getFirstLeafElement(lookupParentCell.parent);
|
14613
|
+
if (!rowFirstLeafElement) {
|
14614
|
+
throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
|
14615
|
+
}
|
14616
|
+
return {
|
14617
|
+
element: rowFirstLeafElement,
|
14618
|
+
offset: 0
|
14619
|
+
};
|
14620
|
+
}
|
14621
|
+
}
|
14622
|
+
}
|
14623
|
+
return { element, offset };
|
14624
|
+
}
|
14625
|
+
/**
|
14626
|
+
* 修正开始选区内容
|
14627
|
+
* 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
|
14628
|
+
*/
|
14629
|
+
fixEndSelectionElement(element, offset, ancestorCommonControl) {
|
14630
|
+
if (!(ancestorCommonControl instanceof TableElement)) {
|
14631
|
+
const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
|
14632
|
+
if (lookupParentCell) {
|
14633
|
+
const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
|
14634
|
+
const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
|
14635
|
+
if (ancestorCommonControlIndex < lookupParentTbIndex) {
|
14636
|
+
const rowLastLeafElement = ElementUtil.getLastLeafElement(lookupParentCell.parent);
|
14637
|
+
if (!rowLastLeafElement) {
|
14638
|
+
ElementUtil.getLastLeafElement(lookupParentCell.parent);
|
14639
|
+
throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
|
14640
|
+
}
|
14641
|
+
return {
|
14642
|
+
element: rowLastLeafElement,
|
14643
|
+
offset: 1
|
14644
|
+
};
|
14645
|
+
}
|
14646
|
+
}
|
14647
|
+
}
|
14648
|
+
return { element, offset };
|
14649
|
+
}
|
14650
|
+
}
|
14651
|
+
|
14640
14652
|
class DocumentArrange {
|
14641
14653
|
docCtx;
|
14642
14654
|
renderCtx;
|
14655
|
+
seo;
|
14643
14656
|
options;
|
14644
|
-
constructor(docCtx, renderCtx) {
|
14657
|
+
constructor(docCtx, renderCtx, seo) {
|
14645
14658
|
this.docCtx = docCtx;
|
14646
14659
|
this.renderCtx = renderCtx;
|
14660
|
+
this.seo = seo;
|
14647
14661
|
this.options = this.docCtx.viewOptions;
|
14648
14662
|
}
|
14649
14663
|
/**
|
@@ -14665,24 +14679,25 @@ class DocumentArrange {
|
|
14665
14679
|
parser: new DynamicContextParser(doc, this.docCtx.selectionState),
|
14666
14680
|
createParaFn: () => this.createDefaultPara()
|
14667
14681
|
};
|
14668
|
-
doc.
|
14682
|
+
doc.clearMarkItems();
|
14669
14683
|
this.clearPaintCache(doc, data);
|
14670
|
-
this.docCtx.viewOptions.showReviewWindow = this.docCtx.document.commentsContainerElement.markPairs.length > 0;
|
14684
|
+
//this.docCtx.viewOptions.showReviewWindow = this.docCtx.document.commentsContainerElement.markPairs.length > 0;
|
14671
14685
|
const docRenders = this.arrangeDoc();
|
14672
14686
|
this.setMeasureCompletedModifyFlag(doc);
|
14673
14687
|
this.cacheDocRenders(docRenders);
|
14688
|
+
this.generateCommRange();
|
14674
14689
|
return docRenders;
|
14675
14690
|
});
|
14676
14691
|
}
|
14677
|
-
commentsRender;
|
14692
|
+
//commentsRender!: CommsContainerRenderObject;
|
14678
14693
|
arrangeDoc() {
|
14679
14694
|
const doc = this.docCtx.document;
|
14680
14695
|
const docRender = doc.createRenderObject();
|
14681
14696
|
const innerRect = docRender.getInnerRect();
|
14682
14697
|
const headerRender = this.measureControl(doc.headerElement, innerRect.width);
|
14683
14698
|
const footerRender = this.measureControl(doc.footerElement, innerRect.width);
|
14684
|
-
const commentsRender = this.measureControl(doc.commentsContainerElement, this.options.reviewWindowWidth);
|
14685
|
-
this.commentsRender = commentsRender;
|
14699
|
+
//const commentsRender = this.measureControl(doc.commentsContainerElement, this.options.reviewWindowWidth) as CommsContainerRenderObject;
|
14700
|
+
//this.commentsRender = commentsRender;
|
14686
14701
|
const { headerLine, footerLine } = docRender;
|
14687
14702
|
let bodyMarginTop = headerLine + headerRender.rect.height + 6;
|
14688
14703
|
let bodyMarginBottom = footerLine + footerRender.rect.height;
|
@@ -14777,15 +14792,15 @@ class DocumentArrange {
|
|
14777
14792
|
cloneFooterRender.rect.x = limitRect.x;
|
14778
14793
|
cloneFooterRender.rect.y = documentRender.rect.height - bodyMarginBottom;
|
14779
14794
|
currColumn === 0 && documentRender.addChild(cloneFooterRender);
|
14780
|
-
//审阅模式,添加审阅窗口
|
14781
|
-
if (this.options.showReviewWindow && commentsRender) {
|
14782
|
-
|
14783
|
-
|
14784
|
-
|
14785
|
-
|
14786
|
-
|
14787
|
-
|
14788
|
-
}
|
14795
|
+
// //审阅模式,添加审阅窗口
|
14796
|
+
// if (this.options.showReviewWindow && commentsRender) {
|
14797
|
+
// const commentsContainer = this.createRenderObject(commentsRender.element) as CommsContainerRenderObject;
|
14798
|
+
// commentsContainer.padding.top = bodyMarginTop;
|
14799
|
+
// commentsContainer.rect.height = documentRender.rect.height;
|
14800
|
+
// documentRender.addChild(commentsContainer);
|
14801
|
+
// commentsContainer.rect.x = documentRender.rect.x + documentRender.rect.width;
|
14802
|
+
// documentRender.rect.width += this.options.reviewWindowWidth;
|
14803
|
+
// }
|
14789
14804
|
currColumn++;
|
14790
14805
|
if (currColumn === docColumns) {
|
14791
14806
|
currColumn = 0;
|
@@ -14813,8 +14828,7 @@ class DocumentArrange {
|
|
14813
14828
|
}
|
14814
14829
|
if (element instanceof BlockContentElement) {
|
14815
14830
|
const pRange = new ParagraphMeasure(this.options, this.renderCtx);
|
14816
|
-
|
14817
|
-
return innerLineRects;
|
14831
|
+
return pRange.measureParagraph(element, maxWidth);
|
14818
14832
|
}
|
14819
14833
|
else if (element instanceof BlockContainerElement) {
|
14820
14834
|
const renders = [];
|
@@ -14952,7 +14966,6 @@ class DocumentArrange {
|
|
14952
14966
|
* 切割渲染元素
|
14953
14967
|
* @param tbRender 被切割的对象
|
14954
14968
|
* @param limitHeight
|
14955
|
-
* @param addFunc
|
14956
14969
|
* @returns
|
14957
14970
|
*/
|
14958
14971
|
cutTable(tbRender, limitHeight) {
|
@@ -14982,6 +14995,10 @@ class DocumentArrange {
|
|
14982
14995
|
while (currRow) {
|
14983
14996
|
const rowContentHeight = this.getBlockLineHeight(currRow);
|
14984
14997
|
if (rowContentHeight + sumHeight > limitHeight) {
|
14998
|
+
//行存在最小高度,且当前行跨页的情况下,不截断该行
|
14999
|
+
if (currRow.element.props.minHeight) {
|
15000
|
+
break;
|
15001
|
+
}
|
14985
15002
|
//限制的外框尺寸
|
14986
15003
|
const availHeight = limitHeight - sumHeight;
|
14987
15004
|
const limitRenderInnerHeight = ElementUtil.innerRectMaxHeight(tbRender, availHeight);
|
@@ -15222,7 +15239,7 @@ class DocumentArrange {
|
|
15222
15239
|
}
|
15223
15240
|
identifyComment(ele) {
|
15224
15241
|
if (ele instanceof CommentElement) {
|
15225
|
-
this.docCtx.document.
|
15242
|
+
this.docCtx.document.identifyCommMark(ele);
|
15226
15243
|
}
|
15227
15244
|
}
|
15228
15245
|
cacheDoc;
|
@@ -15233,6 +15250,22 @@ class DocumentArrange {
|
|
15233
15250
|
});
|
15234
15251
|
this.cacheDoc = null;
|
15235
15252
|
}
|
15253
|
+
/**
|
15254
|
+
* 生成批注区间信息
|
15255
|
+
* @param renderTree
|
15256
|
+
*/
|
15257
|
+
generateCommRange() {
|
15258
|
+
this.seo.commRangeSets.clear();
|
15259
|
+
const commMarks = this.docCtx.document.markPairs;
|
15260
|
+
for (let i = 0; i < commMarks.length; i++) {
|
15261
|
+
const commMark = commMarks[i];
|
15262
|
+
if (commMark.start && commMark.end) {
|
15263
|
+
const ancestor = DocumentSelection.getAncestorCommonControl(commMark.start, commMark.end);
|
15264
|
+
const range = RangeUtil.getSectionRange(commMark.start, 0, commMark.end, 1, ancestor);
|
15265
|
+
SelectionOverlays.addToCommentSets(range, this.seo.commRangeSets, commMark.start.color);
|
15266
|
+
}
|
15267
|
+
}
|
15268
|
+
}
|
15236
15269
|
cacheRenders(renderTree) {
|
15237
15270
|
if (renderTree.element) {
|
15238
15271
|
renderTree.element.paintRenders.push(renderTree);
|
@@ -16328,7 +16361,7 @@ class ElementRenderCut {
|
|
16328
16361
|
class DocumentPaint {
|
16329
16362
|
renderContext;
|
16330
16363
|
docCtx;
|
16331
|
-
|
16364
|
+
seo;
|
16332
16365
|
elementMeasure;
|
16333
16366
|
elementRenderCut;
|
16334
16367
|
elementPaint;
|
@@ -16336,10 +16369,10 @@ class DocumentPaint {
|
|
16336
16369
|
docContainer;
|
16337
16370
|
//commsContainer!: CommsContainerRenderObject;
|
16338
16371
|
viewOptions;
|
16339
|
-
constructor(renderContext, docCtx,
|
16372
|
+
constructor(renderContext, docCtx, seo) {
|
16340
16373
|
this.renderContext = renderContext;
|
16341
16374
|
this.docCtx = docCtx;
|
16342
|
-
this.
|
16375
|
+
this.seo = seo;
|
16343
16376
|
this.viewOptions = this.docCtx.viewOptions;
|
16344
16377
|
this.elementMeasure = new ElementMeasure(this.docCtx, this.renderContext);
|
16345
16378
|
this.elementRenderCut = new ElementRenderCut(this.viewOptions, this.renderContext);
|
@@ -16361,7 +16394,7 @@ class DocumentPaint {
|
|
16361
16394
|
// //console.timeEnd('排版计时');
|
16362
16395
|
// //console.time('断页计时');
|
16363
16396
|
// const docPages = this.elementRenderCut.cutPage(documentRender, this.docCtx.document);
|
16364
|
-
const newMeasure = new DocumentArrange(this.docCtx, this.renderContext);
|
16397
|
+
const newMeasure = new DocumentArrange(this.docCtx, this.renderContext, this.seo);
|
16365
16398
|
const docPages = newMeasure.measureDoc();
|
16366
16399
|
// this.commsContainer = newMeasure.commentsRender as CommsContainerRenderObject;
|
16367
16400
|
// if (this.commsContainer) {
|
@@ -16458,7 +16491,7 @@ class DocumentPaint {
|
|
16458
16491
|
}
|
16459
16492
|
}
|
16460
16493
|
refreshView() {
|
16461
|
-
this.elementPaint.drawPages(this.docContainer, this.
|
16494
|
+
this.elementPaint.drawPages(this.docContainer, this.seo.selectionEleSets);
|
16462
16495
|
}
|
16463
16496
|
getDocPages() {
|
16464
16497
|
return this.docPages;
|
@@ -16473,31 +16506,31 @@ class DocumentPaint {
|
|
16473
16506
|
if (!this.viewOptions.showReviewWindow) {
|
16474
16507
|
return;
|
16475
16508
|
}
|
16476
|
-
const cce = this.docCtx.document.commentsContainerElement;
|
16477
|
-
const set = new Map();
|
16478
|
-
const commentRangeStatus = [];
|
16479
|
-
for (let i = 0; i < cce.length; i++) {
|
16480
|
-
|
16481
|
-
|
16482
|
-
|
16483
|
-
|
16484
|
-
|
16485
|
-
|
16486
|
-
|
16487
|
-
|
16488
|
-
|
16489
|
-
|
16490
|
-
|
16491
|
-
|
16492
|
-
|
16493
|
-
|
16494
|
-
|
16495
|
-
|
16496
|
-
|
16497
|
-
|
16498
|
-
}
|
16499
|
-
cce.cacheRender.selectedSet = set;
|
16500
|
-
cce.cacheRender.commentRangeStatus = commentRangeStatus;
|
16509
|
+
// const cce = this.docCtx.document.commentsContainerElement;
|
16510
|
+
// const set = new Map<Element, SelectionContentRange>();
|
16511
|
+
// const commentRangeStatus: Array<CommentRangeStatus> = [];
|
16512
|
+
// for (let i = 0; i < cce.length; i++) {
|
16513
|
+
// const commContent = cce.getChild(i) as CommContentElement;
|
16514
|
+
// const commMarkPair = cce.markPairs.find(item => item.id === commContent.props.id);
|
16515
|
+
// if (commMarkPair) {
|
16516
|
+
// if (commMarkPair.start) {
|
16517
|
+
// commContent.startMark = commMarkPair.start;
|
16518
|
+
// }
|
16519
|
+
// if (commMarkPair.end) {
|
16520
|
+
// commContent.endMark = commMarkPair.end;
|
16521
|
+
// }
|
16522
|
+
// }
|
16523
|
+
// const {startMark, endMark, props: {id}, focus} = commContent;
|
16524
|
+
// const ancestorCommonControl = DocumentSelection.getAncestorCommonControl(startMark, endMark);
|
16525
|
+
// const commonRange = RangeUtil.getSectionRange(startMark, 0, endMark, 1, ancestorCommonControl);
|
16526
|
+
// SelectionOverlays.addToCommentSets(commonRange, set);
|
16527
|
+
// commentRangeStatus.push({
|
16528
|
+
// commContent,
|
16529
|
+
// range: commonRange
|
16530
|
+
// })
|
16531
|
+
// }
|
16532
|
+
// (<CommsContainerRenderObject>cce.cacheRender).selectedSet = set;
|
16533
|
+
// (<CommsContainerRenderObject>cce.cacheRender).commentRangeStatus = commentRangeStatus;
|
16501
16534
|
}
|
16502
16535
|
}
|
16503
16536
|
|
@@ -16697,15 +16730,15 @@ class ElementReader {
|
|
16697
16730
|
document.bodyElement = document.find((item) => item instanceof DocumentBodyElement);
|
16698
16731
|
document.headerElement = document.find((item) => item instanceof DocumentHeaderElement);
|
16699
16732
|
document.footerElement = document.find((item) => item instanceof DocumentFooterElement);
|
16700
|
-
document.commentsContainerElement = document.find((item) => item instanceof CommsContainerElement);
|
16701
|
-
if (!document.commentsContainerElement) {
|
16702
|
-
|
16703
|
-
}
|
16733
|
+
// document.commentsContainerElement = document.find((item) => item instanceof CommsContainerElement) as CommsContainerElement;
|
16734
|
+
// if (!document.commentsContainerElement) {
|
16735
|
+
// document.commentsContainerElement = new CommsContainerElement();
|
16736
|
+
// }
|
16704
16737
|
document.clearItems();
|
16705
16738
|
document.addChild(document.headerElement);
|
16706
16739
|
document.addChild(document.bodyElement);
|
16707
16740
|
document.addChild(document.footerElement);
|
16708
|
-
document.addChild(document.commentsContainerElement);
|
16741
|
+
//document.addChild(document.commentsContainerElement);
|
16709
16742
|
this.docCtx.document = document;
|
16710
16743
|
document.viewOptions = this.docCtx.viewOptions;
|
16711
16744
|
const width = Math.floor(document.props.width * this.docCtx.viewOptions.mmToPixelsRatio);
|
@@ -16713,7 +16746,7 @@ class ElementReader {
|
|
16713
16746
|
this.docCtx.viewOptions.docPageSettings = new PageOptions(width, height, document.props.orient);
|
16714
16747
|
//this.viewOptions.viewSettings.width = this.viewOptions.docPageSettings.width + 10;
|
16715
16748
|
}
|
16716
|
-
readElement(data) {
|
16749
|
+
readElement(data, strictMode = false) {
|
16717
16750
|
if (typeof data === 'string') {
|
16718
16751
|
data = JSON.parse(data);
|
16719
16752
|
}
|
@@ -16728,19 +16761,27 @@ class ElementReader {
|
|
16728
16761
|
const children = data.children || [];
|
16729
16762
|
for (const child of children) {
|
16730
16763
|
//element.addChild(this.readElement(child));
|
16731
|
-
|
16764
|
+
const childEle = this.readElement(child);
|
16765
|
+
childEle && childArr.push(childEle);
|
16732
16766
|
}
|
16733
16767
|
}
|
16734
16768
|
factory.readCompleted(element, childArr);
|
16735
16769
|
return element;
|
16736
16770
|
}
|
16737
16771
|
}
|
16738
|
-
|
16772
|
+
if (strictMode) {
|
16773
|
+
throw new Error('未知的元素类型:' + type, data);
|
16774
|
+
}
|
16775
|
+
else {
|
16776
|
+
console.error('未知的元素类型:' + type, data);
|
16777
|
+
return null;
|
16778
|
+
}
|
16739
16779
|
}
|
16740
|
-
|
16741
|
-
|
16742
|
-
|
16743
|
-
|
16780
|
+
/**
|
16781
|
+
* 读取扩展属性
|
16782
|
+
* @param data
|
16783
|
+
* @param element
|
16784
|
+
*/
|
16744
16785
|
readExtendsProps(data, element) {
|
16745
16786
|
if (!data.props) {
|
16746
16787
|
return;
|
@@ -19588,7 +19629,7 @@ class DocumentChange {
|
|
19588
19629
|
return paragraph;
|
19589
19630
|
}
|
19590
19631
|
const last = ElementUtil.getLastLeafElement(paragraph);
|
19591
|
-
const selectedParaRange = RangeUtil.
|
19632
|
+
const selectedParaRange = RangeUtil.getSectionRange(startControl, startOffset, last, 1, paragraph);
|
19592
19633
|
selectedParaRange.isFullSelected = false;
|
19593
19634
|
const breakPara = ElementUtil.cloneRange(selectedParaRange, true);
|
19594
19635
|
ElementUtil.fixParagraphContent(paragraph);
|
@@ -20210,22 +20251,26 @@ class DocumentChange {
|
|
20210
20251
|
const id = nanoid.nanoid(5);
|
20211
20252
|
const startCommMark = new CommentElement();
|
20212
20253
|
startCommMark.props.id = id;
|
20254
|
+
startCommMark.props.userId = this.viewOptions.editUser.id;
|
20255
|
+
startCommMark.props.userName = this.viewOptions.editUser.name;
|
20256
|
+
startCommMark.props.date = CommonUtil.formatNow('YYYY-MM-DD HH:mm:ss');
|
20213
20257
|
startCommMark.props.markType = 'start';
|
20214
20258
|
const endCommMark = new CommentElement();
|
20215
20259
|
endCommMark.props.id = id;
|
20216
20260
|
endCommMark.props.markType = 'end';
|
20217
20261
|
this.insertElement(endControl, endOffset, [endCommMark]);
|
20218
20262
|
this.insertElement(startControl, startOffset, [startCommMark]);
|
20219
|
-
|
20220
|
-
commContent
|
20221
|
-
commContent.props.
|
20222
|
-
commContent.props.
|
20223
|
-
commContent.props.
|
20224
|
-
|
20225
|
-
|
20226
|
-
|
20227
|
-
|
20228
|
-
|
20263
|
+
startCommMark.props.text = '插入测试批注信息' + new Date();
|
20264
|
+
// const commContent = new CommContentElement();
|
20265
|
+
// commContent.props.id = id;
|
20266
|
+
// commContent.props.createId = this.viewOptions.editUser.id;
|
20267
|
+
// commContent.props.createName = this.viewOptions.editUser.name;
|
20268
|
+
// commContent.props.createDate = new Date();
|
20269
|
+
// const pos = this.docComment.getCommMarkIndex(startCommMark);
|
20270
|
+
// if (pos < 0) {
|
20271
|
+
// throw new Error('获取插入的批注位置不正确');
|
20272
|
+
// }
|
20273
|
+
// this.docCtx.document.commentsContainerElement.addChild(commContent, pos);
|
20229
20274
|
this.selectionState.clear();
|
20230
20275
|
}
|
20231
20276
|
validate() {
|
@@ -20249,8 +20294,8 @@ class DocumentChange {
|
|
20249
20294
|
validateElement.props.title = caption + '验证';
|
20250
20295
|
validateElement.props.id = id;
|
20251
20296
|
validateElement.setContent(item.error);
|
20252
|
-
|
20253
|
-
this.docCtx.document.commentsContainerElement.addChild(validateElement, pos);
|
20297
|
+
this.docComment.getCommMarkIndex(startCommMark);
|
20298
|
+
//this.docCtx.document.commentsContainerElement.addChild(validateElement, pos);
|
20254
20299
|
});
|
20255
20300
|
this.docCtx.selectionState.clear();
|
20256
20301
|
return false;
|
@@ -20676,7 +20721,6 @@ class DocumentComment {
|
|
20676
20721
|
// }
|
20677
20722
|
// this.commMarkList = commList;
|
20678
20723
|
// this.commContentList = commContentList;
|
20679
|
-
this.docCtx.viewOptions.showReviewWindow = this.docCtx.document.commentsContainerElement.markPairs.length > 0;
|
20680
20724
|
this.isDirty = false;
|
20681
20725
|
}
|
20682
20726
|
/**
|
@@ -20712,28 +20756,46 @@ class DocumentComment {
|
|
20712
20756
|
if (!endRange) {
|
20713
20757
|
return;
|
20714
20758
|
}
|
20715
|
-
const
|
20716
|
-
|
20717
|
-
|
20718
|
-
|
20719
|
-
if (!startMark || !endMark) {
|
20720
|
-
continue;
|
20721
|
-
}
|
20722
|
-
const commPair = {
|
20723
|
-
startMark,
|
20724
|
-
endMark,
|
20725
|
-
startMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, startMark),
|
20726
|
-
endMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, endMark),
|
20727
|
-
};
|
20728
|
-
commPairs.push(commPair);
|
20729
|
-
}
|
20730
|
-
for (let i = 0; i < commPairs.length; i++) {
|
20731
|
-
const commPair = commPairs[i];
|
20732
|
-
if (commPair.endMarkStatus) {
|
20733
|
-
this.removeComment(commPair.endMark.props.id);
|
20759
|
+
const selectedComms = [];
|
20760
|
+
RangeUtil.recursionTraversalRangeHandler(selectedRange, (range) => {
|
20761
|
+
if (range.target instanceof CommentElement && range.isFullSelected) {
|
20762
|
+
selectedComms.push(range.target);
|
20734
20763
|
}
|
20735
|
-
|
20764
|
+
});
|
20765
|
+
if (selectedComms.length > 0) {
|
20766
|
+
const ids = selectedComms.map(item => item.props.id);
|
20767
|
+
const commList = this.docCtx.document.treeFilter(item => item.type === 'comm' && ids.indexOf(item.props.id) >= 0);
|
20768
|
+
commList.forEach(item => item.remove());
|
20769
|
+
return;
|
20736
20770
|
}
|
20771
|
+
return;
|
20772
|
+
// const commPairs: Array<CommMarkSelectedStatus> = [];
|
20773
|
+
// const markPairs = this.docCtx.document.commentsContainerElement.markPairs;
|
20774
|
+
// for (let i = 0; i < markPairs.length; i++) {
|
20775
|
+
// const {start: startMark, end: endMark} = markPairs[i];
|
20776
|
+
// if (!startMark || !endMark) {
|
20777
|
+
// continue;
|
20778
|
+
// }
|
20779
|
+
// const commPair: CommMarkSelectedStatus = {
|
20780
|
+
// startMark,
|
20781
|
+
// endMark,
|
20782
|
+
// startMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, startMark),
|
20783
|
+
// endMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, endMark),
|
20784
|
+
// };
|
20785
|
+
// commPairs.push(commPair)
|
20786
|
+
// }
|
20787
|
+
//
|
20788
|
+
// for (let i = 0; i < commPairs.length; i++) {
|
20789
|
+
// const commPair = commPairs[i];
|
20790
|
+
// if (commPair.endMarkStatus) {
|
20791
|
+
// this.removeComment(commPair.endMark.props.id);
|
20792
|
+
// } else if (commPair.startMarkStatus) {
|
20793
|
+
// // const newStartMark = new CommentElement();
|
20794
|
+
// // newStartMark.props.id = commPair.startMark.props.id;
|
20795
|
+
// // commPair.startMark.isDecorate = false;
|
20796
|
+
// // DocumentChange.insertElement(endRange.target, endRange.endOffset, [newStartMark]);
|
20797
|
+
// }
|
20798
|
+
// }
|
20737
20799
|
}
|
20738
20800
|
}
|
20739
20801
|
/**
|
@@ -20741,7 +20803,7 @@ class DocumentComment {
|
|
20741
20803
|
* @param id
|
20742
20804
|
*/
|
20743
20805
|
removeComment(id) {
|
20744
|
-
this.docCtx.document.
|
20806
|
+
this.docCtx.document.removeCommMark(id);
|
20745
20807
|
}
|
20746
20808
|
getCommMarkIndex(commMark) {
|
20747
20809
|
const markType = commMark.props.markType;
|
@@ -20753,7 +20815,7 @@ class DocumentComment {
|
|
20753
20815
|
* 清除所有批注
|
20754
20816
|
*/
|
20755
20817
|
clearAllComments() {
|
20756
|
-
this.docCtx.document.
|
20818
|
+
this.docCtx.document.clearAllComms();
|
20757
20819
|
this.docCtx.selectionState.clear();
|
20758
20820
|
}
|
20759
20821
|
/**
|
@@ -21179,15 +21241,15 @@ class ElementTrackManage {
|
|
21179
21241
|
|
21180
21242
|
class DocumentSvg {
|
21181
21243
|
viewOptions;
|
21182
|
-
|
21244
|
+
sso;
|
21183
21245
|
renderCtx;
|
21184
21246
|
highlights = [];
|
21185
21247
|
mode = "view";
|
21186
21248
|
//当前页位置
|
21187
21249
|
pagePos;
|
21188
|
-
constructor(viewOptions,
|
21250
|
+
constructor(viewOptions, sso, renderCtx) {
|
21189
21251
|
this.viewOptions = viewOptions;
|
21190
|
-
this.
|
21252
|
+
this.sso = sso;
|
21191
21253
|
this.renderCtx = renderCtx;
|
21192
21254
|
}
|
21193
21255
|
getVNode(render, selectionRects, parentPos) {
|
@@ -21197,22 +21259,8 @@ class DocumentSvg {
|
|
21197
21259
|
width: render.rect.width,
|
21198
21260
|
height: render.rect.height
|
21199
21261
|
};
|
21200
|
-
|
21201
|
-
|
21202
|
-
if (render.element && render instanceof LeafRenderObject) {
|
21203
|
-
if (range.isFullSelected) {
|
21204
|
-
selectionRects.push(currPos);
|
21205
|
-
}
|
21206
|
-
else {
|
21207
|
-
if (render.element instanceof TextGroupElement && range.endOffset > range.startOffset) {
|
21208
|
-
const { startX, endX } = ElementUtil.getTextRenderHorX(render, range.startOffset, range.endOffset);
|
21209
|
-
const width = endX - startX;
|
21210
|
-
const x = currPos.x + startX;
|
21211
|
-
selectionRects.push({ x, y: currPos.y, width, height: currPos.height });
|
21212
|
-
}
|
21213
|
-
}
|
21214
|
-
}
|
21215
|
-
}
|
21262
|
+
//处理选区遮罩
|
21263
|
+
this.createSelectionRect(render, selectionRects, currPos);
|
21216
21264
|
//审阅窗口重新计算位置
|
21217
21265
|
if (this.viewOptions.showReviewWindow && render instanceof CommsContainerRenderObject) {
|
21218
21266
|
CommentsUtil.arrangeComments(render);
|
@@ -21276,12 +21324,18 @@ class DocumentSvg {
|
|
21276
21324
|
if (selectionRectsTemp.length > 0) {
|
21277
21325
|
const startX = selectionRectsTemp[0].x;
|
21278
21326
|
const endX = selectionRectsTemp[selectionRectsTemp.length - 1].x + selectionRectsTemp[selectionRectsTemp.length - 1].width;
|
21279
|
-
selectionRects.push({
|
21327
|
+
selectionRects.push({
|
21328
|
+
x: startX,
|
21329
|
+
y: currPos.y,
|
21330
|
+
width: endX - startX,
|
21331
|
+
height: currPos.height,
|
21332
|
+
color: selectionRectsTemp[0].color
|
21333
|
+
});
|
21280
21334
|
selectionRectsTemp.length = 0;
|
21281
21335
|
}
|
21282
21336
|
}
|
21283
21337
|
else if (render instanceof TableCellRenderObject) {
|
21284
|
-
if (this.
|
21338
|
+
if (this.sso.selectionEleSets.has(render.element) && this.sso.selectionEleSets.get(render.element)?.isFullSelected) {
|
21285
21339
|
selectionRects.push(currPos);
|
21286
21340
|
selectionRectsTemp.length = 0;
|
21287
21341
|
}
|
@@ -21323,11 +21377,39 @@ class DocumentSvg {
|
|
21323
21377
|
}
|
21324
21378
|
return currVNode;
|
21325
21379
|
}
|
21380
|
+
createSelectionRect(render, selectionRects, currPos) {
|
21381
|
+
const items = [this.sso.selectionEleSets, this.sso.commRangeSets];
|
21382
|
+
for (const item of items) {
|
21383
|
+
if (item.has(render.element)) {
|
21384
|
+
const range = item.get(render.element);
|
21385
|
+
if (render.element && render instanceof LeafRenderObject) {
|
21386
|
+
if (range.isFullSelected) {
|
21387
|
+
selectionRects.push({ ...currPos, color: range['rangeColor'] });
|
21388
|
+
}
|
21389
|
+
else {
|
21390
|
+
if (render.element instanceof TextGroupElement && range.endOffset > range.startOffset) {
|
21391
|
+
const { startX, endX } = ElementUtil.getTextRenderHorX(render, range.startOffset, range.endOffset);
|
21392
|
+
const width = endX - startX;
|
21393
|
+
const x = currPos.x + startX;
|
21394
|
+
// @ts-ignore
|
21395
|
+
selectionRects.push({
|
21396
|
+
x,
|
21397
|
+
y: currPos.y,
|
21398
|
+
width,
|
21399
|
+
height: currPos.height,
|
21400
|
+
color: range['rangeColor']
|
21401
|
+
});
|
21402
|
+
}
|
21403
|
+
}
|
21404
|
+
}
|
21405
|
+
}
|
21406
|
+
}
|
21407
|
+
}
|
21326
21408
|
getHTMLVNode(docRenders) {
|
21327
21409
|
this.counterMap = {};
|
21328
|
-
|
21410
|
+
return docRenders.filter(item => this.checkInViewBox(item)).map(item => {
|
21329
21411
|
const pageSvg = this.getPageSvgVNode(item);
|
21330
|
-
|
21412
|
+
return {
|
21331
21413
|
sel: 'div.page-unit',
|
21332
21414
|
data: {
|
21333
21415
|
style: {
|
@@ -21342,9 +21424,7 @@ class DocumentSvg {
|
|
21342
21424
|
},
|
21343
21425
|
children: [pageSvg]
|
21344
21426
|
};
|
21345
|
-
return pageUnit;
|
21346
21427
|
});
|
21347
|
-
return pageNodes;
|
21348
21428
|
}
|
21349
21429
|
/**
|
21350
21430
|
* 判断当前元素是否在视窗内
|
@@ -21382,7 +21462,7 @@ class DocumentSvg {
|
|
21382
21462
|
ns: 'http://www.w3.org/2000/svg',
|
21383
21463
|
attrs: {
|
21384
21464
|
stroke: 'none',
|
21385
|
-
fill: 'rgb(85,165,255)',
|
21465
|
+
fill: item.color ?? 'rgb(85,165,255)',
|
21386
21466
|
'paint-order': 'stroke fill markers',
|
21387
21467
|
d: `M${item.x} ${item.y} L${item.x + item.width} ${item.y} L${item.x + item.width} ${item.y + item.height} L${item.x} ${item.y + item.height} Z`,
|
21388
21468
|
'fill-opacity': '0.5'
|
@@ -26392,7 +26472,10 @@ class DocumentPrintOffscreenBase {
|
|
26392
26472
|
const ss = new SelectionState();
|
26393
26473
|
this.docCtx = new EditorContext(ss, this.viewOptions);
|
26394
26474
|
this.renderCtx = this.createRenderCtx(ctx, this.viewOptions, this.docCtx);
|
26395
|
-
this.documentPaint = new DocumentPaint(this.renderCtx, this.docCtx,
|
26475
|
+
this.documentPaint = new DocumentPaint(this.renderCtx, this.docCtx, {
|
26476
|
+
selectionEleSets: new Map(),
|
26477
|
+
commRangeSets: new Map()
|
26478
|
+
});
|
26396
26479
|
this.elementReader = new ElementReader(this.docCtx);
|
26397
26480
|
this.docCtx.syncRefresh = () => {
|
26398
26481
|
};
|
@@ -26407,8 +26490,8 @@ class DocumentPrintOffscreenBase {
|
|
26407
26490
|
// const docProps = this.docCtx.document.props;
|
26408
26491
|
// printNodes(canvasNodes, {...docProps});
|
26409
26492
|
// }
|
26410
|
-
|
26411
|
-
|
26493
|
+
print(data, ranges = null) {
|
26494
|
+
this.prepare(data);
|
26412
26495
|
const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, ranges);
|
26413
26496
|
if (!canvasNodes.length) {
|
26414
26497
|
console.warn('无可打印页');
|
@@ -26423,7 +26506,7 @@ class DocumentPrintOffscreenBase {
|
|
26423
26506
|
/**
|
26424
26507
|
* 续打
|
26425
26508
|
*/
|
26426
|
-
|
26509
|
+
printForContinuation(data, options) {
|
26427
26510
|
this.afterRenderEvent.subscribe((event) => {
|
26428
26511
|
const { index, renderCtx, docRender, pageSvgVNode } = event;
|
26429
26512
|
if (index === options.startDocIndex && options.startY !== 0) {
|
@@ -26437,7 +26520,7 @@ class DocumentPrintOffscreenBase {
|
|
26437
26520
|
pageSvgVNode.data.attrs['clip-path'] = `url(#${'page-clip-' + index})`;
|
26438
26521
|
}
|
26439
26522
|
});
|
26440
|
-
|
26523
|
+
this.prepare(data);
|
26441
26524
|
const printRanges = new Array(this.documentPaint.docPages.length).fill(0).map((item, index) => index).filter(index => index >= options.startDocIndex);
|
26442
26525
|
let svgNodes = this.getSvgNodes(this.documentPaint.docPages, printRanges);
|
26443
26526
|
if (!svgNodes.length) {
|
@@ -26462,8 +26545,8 @@ class DocumentPrintOffscreenBase {
|
|
26462
26545
|
// }
|
26463
26546
|
// return canvasNodes.map(node => node.toDataURL());
|
26464
26547
|
// }
|
26465
|
-
|
26466
|
-
|
26548
|
+
getPrintNodes(data, ranges = null) {
|
26549
|
+
this.prepare(data);
|
26467
26550
|
const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, ranges);
|
26468
26551
|
return canvasNodes;
|
26469
26552
|
}
|
@@ -26474,11 +26557,11 @@ class DocumentPrintOffscreenBase {
|
|
26474
26557
|
* 读取数据,排版
|
26475
26558
|
* @param data
|
26476
26559
|
*/
|
26477
|
-
|
26560
|
+
prepare(data) {
|
26478
26561
|
//将doc的json格式数据读取转化为DocumentElement的树
|
26479
26562
|
this.elementReader.read(data);
|
26480
26563
|
this.documentPaint.rePages();
|
26481
|
-
await Promise.all(this.docCtx.imageLoader.getLoadTasks());
|
26564
|
+
//await Promise.all(this.docCtx.imageLoader.getLoadTasks());
|
26482
26565
|
const { scale, docPageSettings: { width, height } } = this.viewOptions;
|
26483
26566
|
this.renderCtx.update({ scale, width, height });
|
26484
26567
|
ElementUtil.setCanvasProps(this.renderCtx.mainContext.ctx.canvas, this.renderCtx.mainContext.ctx, {
|
@@ -26513,7 +26596,10 @@ class DocumentPrintOffscreenBase {
|
|
26513
26596
|
// return canvasList;
|
26514
26597
|
// }
|
26515
26598
|
getSvgNodes(docRenders, printRanges = null) {
|
26516
|
-
const docSvgHelper = new DocumentSvg(this.viewOptions,
|
26599
|
+
const docSvgHelper = new DocumentSvg(this.viewOptions, {
|
26600
|
+
selectionEleSets: new Map,
|
26601
|
+
commRangeSets: new Map()
|
26602
|
+
}, this.renderCtx); //.getHTMLVNode(docRenders) as Array<EditorVNodeObject>;
|
26517
26603
|
docSvgHelper.mode = 'print';
|
26518
26604
|
const patch = init([
|
26519
26605
|
modules.class,
|
@@ -26557,31 +26643,6 @@ class DocumentPrintOffscreen extends DocumentPrintOffscreenBase {
|
|
26557
26643
|
}
|
26558
26644
|
}
|
26559
26645
|
|
26560
|
-
let activeEditorContext = null;
|
26561
|
-
function setActiveEditorContext(ctx) {
|
26562
|
-
activeEditorContext = ctx;
|
26563
|
-
}
|
26564
|
-
function createSignal(state) {
|
26565
|
-
let _state = state;
|
26566
|
-
const activeCtx = activeEditorContext;
|
26567
|
-
const signal = {
|
26568
|
-
get value() {
|
26569
|
-
return _state;
|
26570
|
-
},
|
26571
|
-
set value(v) {
|
26572
|
-
if (v === _state) {
|
26573
|
-
return;
|
26574
|
-
}
|
26575
|
-
_state = v;
|
26576
|
-
signal.onChange();
|
26577
|
-
},
|
26578
|
-
onChange: () => {
|
26579
|
-
activeCtx?.onChange();
|
26580
|
-
}
|
26581
|
-
};
|
26582
|
-
return signal;
|
26583
|
-
}
|
26584
|
-
|
26585
26646
|
/**
|
26586
26647
|
* 渲染日历虚拟节点处理类
|
26587
26648
|
*/
|
@@ -27450,6 +27511,8 @@ class DocEditor {
|
|
27450
27511
|
onDestroy = new Subject$1();
|
27451
27512
|
beforeNodePatch = new Subject$1();
|
27452
27513
|
afterNodePatch = new Subject$1();
|
27514
|
+
//自定义事件传递消息
|
27515
|
+
eventBus;
|
27453
27516
|
editInput;
|
27454
27517
|
scrollContainer;
|
27455
27518
|
constructor(svgContainer) {
|
@@ -27480,13 +27543,14 @@ class DocEditor {
|
|
27480
27543
|
this.renderContext.init({ width: 500, height: 500, scale: 1 });
|
27481
27544
|
this.selectionState = this.documentSelection.selectionState;
|
27482
27545
|
this.selectionOverlays = new SelectionOverlays(this.documentSelection.selectionState);
|
27483
|
-
this.documentPaint = new DocumentPaint(this.renderContext, this.docCtx, this.selectionOverlays
|
27546
|
+
this.documentPaint = new DocumentPaint(this.renderContext, this.docCtx, this.selectionOverlays);
|
27484
27547
|
this.documentInput = new DocumentInput(this.docCtx);
|
27485
27548
|
this.docComment = new DocumentComment(this.docCtx);
|
27486
27549
|
this.elementReader = new ElementReader(this.docCtx);
|
27487
27550
|
this.documentChange = new DocumentChange(this.elementReader, this.docCtx, this.docComment, this.documentInput);
|
27488
27551
|
this.documentEvent = new DocumentEvent(this.documentPaint, this.docCtx, this.documentInput);
|
27489
27552
|
this.historyMange = new ElementTrackManage(this.docCtx, this.elementReader);
|
27553
|
+
this.eventBus = new EventBus();
|
27490
27554
|
this.createPatch();
|
27491
27555
|
this.documentEvent.hitInfoChanged.subscribe((hitInfo) => {
|
27492
27556
|
this.hitInfoChanged(hitInfo);
|
@@ -28071,6 +28135,7 @@ class DocEditor {
|
|
28071
28135
|
this.docCtx.destroy();
|
28072
28136
|
this.documentEvent.clearSubEvent();
|
28073
28137
|
this.selectionState.destroy();
|
28138
|
+
this.eventBus.clear();
|
28074
28139
|
this.destroyDOM();
|
28075
28140
|
this.flushTask = null;
|
28076
28141
|
Object.keys(this).forEach(key => {
|
@@ -28584,7 +28649,7 @@ class DocEditor {
|
|
28584
28649
|
this.tipContainer = tipsContainer;
|
28585
28650
|
docContent.data.style.height = this.documentPaint.getDocumentContainerHeight().height + 'px';
|
28586
28651
|
const docRenders = this.documentPaint.docContainer.getItems();
|
28587
|
-
const svgGenerator = new DocumentSvg(this.viewOptions, this.selectionOverlays
|
28652
|
+
const svgGenerator = new DocumentSvg(this.viewOptions, this.selectionOverlays, this.renderContext);
|
28588
28653
|
const vNode = svgGenerator.getHTMLVNode(docRenders);
|
28589
28654
|
const children = docContent.children;
|
28590
28655
|
children.push(tipsContainer);
|
@@ -28891,7 +28956,7 @@ class DocEditor {
|
|
28891
28956
|
rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
|
28892
28957
|
}
|
28893
28958
|
version() {
|
28894
|
-
return "2.1.
|
28959
|
+
return "2.1.19";
|
28895
28960
|
}
|
28896
28961
|
switchPageHeaderEditor() {
|
28897
28962
|
this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
|
@@ -28901,6 +28966,9 @@ class DocEditor {
|
|
28901
28966
|
const paraTexts = paras.map(item => ElementSerialize.serializeString(item, { all: false }));
|
28902
28967
|
return paraTexts.join('\n');
|
28903
28968
|
}
|
28969
|
+
emit(event, args) {
|
28970
|
+
this.eventBus.emit(event, args);
|
28971
|
+
}
|
28904
28972
|
}
|
28905
28973
|
|
28906
28974
|
/**
|
@@ -29172,8 +29240,6 @@ exports.DocumentFooterRenderObject = DocumentFooterRenderObject;
|
|
29172
29240
|
exports.DocumentHeaderElement = DocumentHeaderElement;
|
29173
29241
|
exports.DocumentHeaderFactory = DocumentHeaderFactory;
|
29174
29242
|
exports.DocumentHeaderRenderObject = DocumentHeaderRenderObject;
|
29175
|
-
exports.DocumentImagesBaseLoader = DocumentImagesBaseLoader;
|
29176
|
-
exports.DocumentImagesLoader = DocumentImagesLoader;
|
29177
29243
|
exports.DocumentInput = DocumentInput;
|
29178
29244
|
exports.DocumentPaint = DocumentPaint;
|
29179
29245
|
exports.DocumentPrintOffscreen = DocumentPrintOffscreen;
|
@@ -29191,6 +29257,7 @@ exports.ElementPaint = ElementPaint;
|
|
29191
29257
|
exports.ElementReader = ElementReader;
|
29192
29258
|
exports.ElementSerialize = ElementSerialize;
|
29193
29259
|
exports.ElementUtil = ElementUtil;
|
29260
|
+
exports.EventBus = EventBus;
|
29194
29261
|
exports.EventMap = EventMap;
|
29195
29262
|
exports.EventSourceCore = EventSourceCore$1;
|
29196
29263
|
exports.FillNullSpaceElement = FillNullSpaceElement;
|