| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268 | 1×
1×
1×
1×
1397×
1397×
1×
2825×
2825×
2×
2825×
2825×
2825×
1×
87×
87×
87×
87×
10×
77×
34×
43×
43×
1×
10×
10×
10×
10×
10×
10×
10×
10×
3×
10×
10×
10×
10×
1×
34×
34×
34×
34×
34×
34×
34×
34×
34×
34×
34×
34×
34×
34×
34×
34×
34×
1×
34×
34×
34×
34×
34×
34×
2×
32×
18×
14×
5×
9×
9×
34×
1×
34×
34×
1×
34×
34×
34×
34×
34×
4×
30×
1×
34×
34×
34×
34×
34×
34×
34×
34×
34×
34×
34×
15×
19×
1×
19×
1×
34×
34×
34×
34×
34×
31×
31×
1×
1×
2×
2×
34×
1×
34×
34×
34×
34×
34×
28×
28×
5×
5×
1×
1×
34×
2×
34×
1×
34×
1×
33×
31×
2×
1×
1×
1×
1×
34×
2×
32×
1×
31×
26×
5×
1×
68×
34×
34×
1×
43×
43×
43×
43×
43×
43×
43×
43×
43×
43×
43×
43×
1×
77×
77×
77×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-popups", "@syncfusion/ej2-base", "../../../common/utils/dom"], function (require, exports, ej2_popups_1, ej2_base_1, dom_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var PopupRenderer = (function () {
function PopupRenderer(manager) {
this.parent = manager;
this.editorElement = this.parent.rootEditorElement;
}
PopupRenderer.prototype.renderPopup = function (args) {
var element = args.element;
if (typeof element == 'string') {
element = document.querySelector(element);
}
var popupObj = new ej2_popups_1.Popup(element, {
targetType: 'relative',
relateTo: this.editorElement,
content: args.content,
collision: { X: 'fit', Y: 'fit' },
actionOnScroll: 'hide',
showAnimation: {
name: 'FadeIn'
},
width: args.width,
height: args.height
});
popupObj.hide();
return popupObj;
};
PopupRenderer.prototype.adjustPopupPositionRelativeToTarget = function (target, popup) {
var isInlineTbar = popup.element.classList.contains('e-blockeditor-inline-toolbar-popup');
var isblkActionPopup = popup.element.classList.contains('e-blockeditor-blockaction-popup');
var isTableGripperPopup = popup.element.classList.contains('e-table-gripper-action-popup');
if (isblkActionPopup) {
this.positionBlockActionPopup(target, popup);
}
else if (isInlineTbar) {
this.positionInlineToolbar(target, popup);
}
else Eif (isTableGripperPopup) {
this.positionTableGripperActionPopup(target, popup);
}
};
PopupRenderer.prototype.positionBlockActionPopup = function (target, popup) {
ej2_base_1.addClass([popup.element], 'e-be-action-popup-hide');
var targetRect = target.getBoundingClientRect();
var popupRect = popup.element.getBoundingClientRect();
var editorRect = dom_1.getElementRect(this.editorElement);
var editorScrollTop = this.editorElement.scrollTop || 0;
var adjustedX = targetRect.left - editorRect.left;
var adjustedY = targetRect.top + editorScrollTop - editorRect.top + 30;
if (targetRect.bottom + popupRect.height > editorRect.bottom) {
adjustedY = adjustedY - popupRect.height - targetRect.height - 15;
}
popup.position.X = adjustedX;
popup.position.Y = adjustedY;
ej2_base_1.removeClass([popup.element], 'e-be-action-popup-hide');
popup.dataBind();
};
PopupRenderer.prototype.positionInlineToolbar = function (target, popup) {
ej2_base_1.addClass([popup.element], 'e-be-inline-tlbr-hide');
var popupRect = popup.element.getBoundingClientRect();
var relativeElem = this.parent.currentFocusedBlock;
Iif (ej2_base_1.isNullOrUndefined(relativeElem)) {
return;
}
var selection = this.parent.nodeSelection.getSelection();
var clientRects = target.getClientRects();
var direction = this.getSelectionDirection(selection);
var rangeDomRect = clientRects.length === 0 ? target.getBoundingClientRect() :
direction === 'Backward' ? clientRects[0] : clientRects[clientRects.length - 1];
var offsetCalculationParam = {
blockElement: relativeElem,
blockRect: relativeElem.getBoundingClientRect(),
range: target,
rangeRect: rangeDomRect,
direction: direction,
contentPanelElement: this.parent.rootEditorElement,
editPanelDomRect: this.parent.blockContainer.getBoundingClientRect(),
popupRect: popupRect
};
var offsetX = this.calculateOffsetX(offsetCalculationParam);
var offsetY = this.calculateOffsetY(offsetCalculationParam);
var positionProps = {
positionX: offsetX,
positionY: offsetY
};
positionProps = this.handleVerticalCollision(offsetCalculationParam, positionProps);
var popupProps = {
offsetX: positionProps.positionX,
offsetY: positionProps.positionY,
relateTo: relativeElem
};
ej2_base_1.removeClass([popup.element], 'e-be-inline-tlbr-hide');
popup.setProperties(popupProps);
popup.dataBind();
};
PopupRenderer.prototype.calculateOffsetX = function (args) {
var width = args.popupRect.width;
var finalX;
var buffer = 16.5;
var rangeEdge = args.direction === 'Backward' ? args.rangeRect.left : args.rangeRect.right;
var relativePosition = rangeEdge - args.blockRect.left;
if (relativePosition < width / 4) {
finalX = relativePosition - buffer;
}
else if (relativePosition > width / 4 && relativePosition < width / 2) {
finalX = relativePosition - width / 4;
}
else if (relativePosition > width / 2 && relativePosition < (width * 3 / 4)) {
finalX = relativePosition - width / 2;
}
else Iif (relativePosition > (width * 3 / 4) && relativePosition < width) {
finalX = relativePosition - (width * 3 / 4);
}
else {
finalX = relativePosition - width + buffer;
}
return finalX;
};
PopupRenderer.prototype.calculateOffsetY = function (args) {
var finalY = args.rangeRect.bottom - args.blockRect.top + 6;
return finalY;
};
PopupRenderer.prototype.getSelectionDirection = function (selection) {
Iif (selection && selection.rangeCount > 0 && selection.getRangeAt(0).collapsed) {
return 'Forward';
}
var range = new Range();
range.setStart(selection.anchorNode, selection.anchorOffset);
range.setEnd(selection.focusNode, selection.focusOffset);
if (range.collapsed) {
return 'Backward';
}
else {
return 'Forward';
}
};
PopupRenderer.prototype.handleVerticalCollision = function (offsetParams, positionProps) {
var scrollTopParentElement = this.parent.scrollParentElements && this.parent.scrollParentElements.length > 0 &&
this.parent.scrollParentElements[0].nodeName !== '#document' ? this.parent.scrollParentElements[0] : this.parent.rootEditorElement;
var scrollParentRect = scrollTopParentElement.getBoundingClientRect();
var blockRect = offsetParams.blockRect;
var topViewPortSpace = blockRect.top;
var botViewPortSpace = blockRect.bottom;
var spaceAbove = this.getSpaceAbove(offsetParams, scrollParentRect);
var spaceBelow = this.getSpaceBelow(offsetParams, scrollParentRect);
var totalPopupHeight = (10 + offsetParams.popupRect.height);
var isTopPosition = this.isElemVisible(blockRect, 'top') && spaceAbove > totalPopupHeight && topViewPortSpace > totalPopupHeight;
var isBotPosition = offsetParams.direction === 'Backward' && isTopPosition ? false : this.isElemVisible(blockRect, 'bottom') && spaceBelow > totalPopupHeight && botViewPortSpace > totalPopupHeight;
if (isBotPosition) {
return positionProps;
}
else if (isTopPosition) {
positionProps.positionY = -(offsetParams.popupRect.height + 10) + (offsetParams.rangeRect.top - offsetParams.blockRect.top);
}
return positionProps;
};
PopupRenderer.prototype.getSpaceAbove = function (args, scrollParentRect) {
var spaceAbove;
var blockRect = args.blockRect;
var parentRect = args.editPanelDomRect;
var collision = this.getTopCollisionType(blockRect, parentRect, scrollParentRect);
switch (collision) {
case 'ParentElement':
spaceAbove = blockRect.top - parentRect.top;
break;
case 'ScrollableContainer':
spaceAbove = scrollParentRect.top - parentRect.top;
break;
case 'ViewPort':
case 'Hidden':
spaceAbove = blockRect.top;
break;
}
return spaceAbove;
};
PopupRenderer.prototype.getSpaceBelow = function (args, scrollParentRect) {
var spaceBelow;
var blockRect = args.blockRect;
var parentRect = args.editPanelDomRect;
var collision = this.getBottomCollisionType(blockRect, parentRect, scrollParentRect);
switch (collision) {
case 'Hidden':
case 'ParentElement':
spaceBelow = parentRect.bottom - blockRect.bottom;
break;
case 'ScrollableContainer':
spaceBelow = scrollParentRect.bottom - blockRect.bottom;
break;
case 'ViewPort':
spaceBelow = window.innerHeight - blockRect.bottom;
break;
}
if ((window.innerHeight - blockRect.bottom) < (args.popupRect.height + 10)) {
spaceBelow = 0;
}
return spaceBelow;
};
PopupRenderer.prototype.getTopCollisionType = function (blockRect, parentRect, scrollParentRect) {
if (blockRect.top < 0 || blockRect.top >= window.innerHeight) {
return 'Hidden';
}
else {
if (parentRect.top > 0) {
return 'ParentElement';
}
else {
if (scrollParentRect.top < 0) {
return 'ViewPort';
}
Eif (scrollParentRect.top > 0) {
return 'ScrollableContainer';
}
}
}
return 'ParentElement';
};
PopupRenderer.prototype.getBottomCollisionType = function (blockRect, parentRect, scrollParentRect) {
if (blockRect.bottom < 0 || blockRect.bottom >= window.innerHeight) {
return 'Hidden';
}
else {
if (scrollParentRect.bottom >= window.innerHeight && parentRect.bottom >= window.innerHeight) {
return 'ViewPort';
}
else {
if (parentRect.bottom <= scrollParentRect.bottom) {
return 'ParentElement';
}
else {
return 'ScrollableContainer';
}
}
}
};
PopupRenderer.prototype.isElemVisible = function (elemRect, value) {
if (value === 'top') {
return elemRect.top >= 0 && elemRect.top <= window.innerHeight;
}
else {
return elemRect.bottom <= window.innerHeight && elemRect.bottom >= 0;
}
};
PopupRenderer.prototype.positionTableGripperActionPopup = function (target, popup) {
ej2_base_1.addClass([popup.element], 'e-be-gripper-action-popup-hide');
var isColumnGripper = target.classList.contains('e-col-action-handle');
var popupRect = popup.element.getBoundingClientRect();
var targetRect = target.getBoundingClientRect();
var editorRect = this.editorElement.getBoundingClientRect();
var scrollTop = this.editorElement.scrollTop;
var offsetX = (targetRect.left - editorRect.left) + (isColumnGripper ? (targetRect.width / 2 - popupRect.width / 2) : 0);
var offsetY = targetRect.top + scrollTop - editorRect.top - popupRect.height - 5;
popup.position.X = offsetX;
popup.position.Y = offsetY;
ej2_base_1.removeClass([popup.element], 'e-be-gripper-action-popup-hide');
popup.dataBind();
};
PopupRenderer.prototype.destroyPopup = function (popup) {
Eif (popup) {
popup.destroy();
popup.element.remove();
}
};
return PopupRenderer;
}());
exports.PopupRenderer = PopupRenderer;
});
|