@node-projects/web-component-designer 0.0.124 → 0.0.126
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/ACKNOWLEDGMENTS +3 -1
- package/dist/elements/helper/contextMenu/ContextMenuHelper.d.ts +0 -27
- package/dist/elements/helper/contextMenu/ContextMenuHelper.js +182 -153
- package/dist/elements/helper/contextMenu/IContextmenuItem.d.ts +3 -2
- package/dist/elements/helper/contextMenu/IContextmenuItem.js +1 -0
- package/dist/elements/helper/contextMenu/IContextmenuItemTmp.d.ts +8 -0
- package/dist/elements/helper/contextMenu/IContextmenuItemTmp.js +2 -0
- package/dist/elements/helper/contextMenu/NewContextmenu.d.ts +30 -0
- package/dist/elements/helper/contextMenu/NewContextmenu.js +274 -0
- package/dist/elements/helper/contextMenu/contextmenu.d.ts +29 -0
- package/dist/elements/helper/contextMenu/contextmenu.js +304 -0
- package/dist/elements/widgets/designerView/designerCanvas.d.ts +2 -2
- package/dist/elements/widgets/designerView/designerCanvas.js +4 -3
- package/dist/elements/widgets/designerView/extensions/contextMenu/CopyPasteContextMenu.d.ts +1 -1
- package/dist/elements/widgets/designerView/extensions/contextMenu/IContextMenuExtension.d.ts +1 -1
- package/dist/elements/widgets/designerView/extensions/contextMenu/ItemsBelowContextMenu.d.ts +1 -1
- package/dist/elements/widgets/designerView/extensions/contextMenu/ItemsBelowContextMenu.js +1 -2
- package/dist/elements/widgets/designerView/extensions/contextMenu/MultipleItemsSelectedContextMenu.d.ts +1 -1
- package/dist/elements/widgets/designerView/extensions/contextMenu/PathContextMenu.d.ts +1 -1
- package/dist/elements/widgets/designerView/extensions/contextMenu/RectContextMenu.d.ts +1 -1
- package/dist/elements/widgets/designerView/extensions/contextMenu/RotateLeftAndRightContextMenu.d.ts +1 -1
- package/dist/elements/widgets/designerView/extensions/contextMenu/SelectAllChildrenContextMenu.d.ts +1 -1
- package/dist/elements/widgets/designerView/extensions/contextMenu/SeperatorContextMenu.d.ts +1 -1
- package/dist/elements/widgets/designerView/extensions/contextMenu/ZMoveContextMenu.d.ts +1 -1
- package/dist/elements/widgets/designerView/extensions/contextMenu/ZoomToElementContextMenu.d.ts +1 -1
- package/dist/elements/widgets/designerView/extensions/svg/PathExtension.js +2 -2
- package/dist/elements/widgets/designerView/tools/PointerTool.js +1 -1
- package/dist/elements/widgets/propertyGrid/PropertyGridPropertyList.js +2 -2
- package/dist/elements/widgets/treeView/treeViewExtended.d.ts +2 -2
- package/dist/elements/widgets/treeView/treeViewExtended.js +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { css } from "@node-projects/base-custom-webcomponent";
|
|
2
|
+
export class ContextMenu {
|
|
3
|
+
static _contextMenuCss = css `
|
|
4
|
+
.context_menu {
|
|
5
|
+
position: fixed;
|
|
6
|
+
opacity: 0;
|
|
7
|
+
transform: scale(0);
|
|
8
|
+
transition: transform 0.1s;
|
|
9
|
+
transform-origin: top left;
|
|
10
|
+
padding: 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.context_menu.display {
|
|
14
|
+
opacity: 1;
|
|
15
|
+
transform: scale(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.context_menu,
|
|
19
|
+
.context_menu * {
|
|
20
|
+
box-sizing: border-box;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.context_menu * {
|
|
24
|
+
position: relative;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.context_menu ul {
|
|
28
|
+
list-style-type: none;
|
|
29
|
+
padding: 0;
|
|
30
|
+
margin: 0;
|
|
31
|
+
background-color: #ccc;
|
|
32
|
+
box-shadow: 0 0 5px #333;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.context_menu li {
|
|
36
|
+
padding: 0;
|
|
37
|
+
padding-right: 1.7em;
|
|
38
|
+
cursor: pointer;
|
|
39
|
+
white-space: nowrap;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.context_menu li:hover {
|
|
43
|
+
background-color: #bbb;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.context_menu li .cm_icon_span {
|
|
47
|
+
width: 1.5em;
|
|
48
|
+
height: 1.2em;
|
|
49
|
+
vertical-align: bottom;
|
|
50
|
+
display: inline-block;
|
|
51
|
+
border-right: 1px solid #aaa;
|
|
52
|
+
margin-right: 5px;
|
|
53
|
+
padding-right: 5px;
|
|
54
|
+
text-align: center;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.context_menu li .cm_sub_span {
|
|
58
|
+
width: 1em;
|
|
59
|
+
display: inline-block;
|
|
60
|
+
text-align: center;
|
|
61
|
+
position: absolute;
|
|
62
|
+
top: 50%;
|
|
63
|
+
right: 0.5em;
|
|
64
|
+
transform: translateY(-50%);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.context_menu li>ul {
|
|
68
|
+
position: absolute;
|
|
69
|
+
top: 0;
|
|
70
|
+
left: 100%;
|
|
71
|
+
opacity: 0;
|
|
72
|
+
transition: opacity 0.2s;
|
|
73
|
+
visibility: hidden;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.context_menu li:hover>ul {
|
|
77
|
+
opacity: 1;
|
|
78
|
+
visibility: visible;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.context_menu li.cm_divider {
|
|
82
|
+
border-bottom: 1px solid #aaa;
|
|
83
|
+
margin: 5px;
|
|
84
|
+
padding: 0;
|
|
85
|
+
cursor: default;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.context_menu li.cm_divider:hover {
|
|
89
|
+
background-color: inherit;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.context_menu.cm_border_right>ul ul {
|
|
93
|
+
left: unset;
|
|
94
|
+
right: 100%;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.context_menu.cm_border_bottom>ul ul {
|
|
98
|
+
top: unset;
|
|
99
|
+
bottom: 0;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.context_menu li[disabled=""] {
|
|
103
|
+
color: #777;
|
|
104
|
+
cursor: default;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.context_menu li[disabled=""]:hover {
|
|
108
|
+
background-color: inherit;
|
|
109
|
+
}`;
|
|
110
|
+
static count = 0;
|
|
111
|
+
menu;
|
|
112
|
+
options;
|
|
113
|
+
num;
|
|
114
|
+
_documentClickBound;
|
|
115
|
+
constructor(menu, options) {
|
|
116
|
+
console.error(this);
|
|
117
|
+
this.num = ContextMenu.count++;
|
|
118
|
+
this.menu = menu;
|
|
119
|
+
this.options = options;
|
|
120
|
+
window.addEventListener("resize", () => {
|
|
121
|
+
if (this.options.closeOnResize ?? true) {
|
|
122
|
+
this.close();
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
this.reload();
|
|
126
|
+
this._documentClickBound = this._documentClick.bind(this);
|
|
127
|
+
}
|
|
128
|
+
reload() {
|
|
129
|
+
if (document.getElementById('cm_' + this.num) == null) {
|
|
130
|
+
var cnt = document.createElement("div");
|
|
131
|
+
cnt.className = "context_menu";
|
|
132
|
+
cnt.id = "cm_" + this.num;
|
|
133
|
+
document.body.appendChild(cnt);
|
|
134
|
+
}
|
|
135
|
+
var container = document.getElementById('cm_' + this.num);
|
|
136
|
+
container.innerHTML = "";
|
|
137
|
+
let shadowRoot = this.options?.shadowRoot ?? document;
|
|
138
|
+
if (shadowRoot.adoptedStyleSheets.indexOf(ContextMenu._contextMenuCss) < 0) {
|
|
139
|
+
shadowRoot.adoptedStyleSheets = [...shadowRoot.adoptedStyleSheets, ContextMenu._contextMenuCss];
|
|
140
|
+
}
|
|
141
|
+
container.appendChild(this.renderLevel(this.menu));
|
|
142
|
+
}
|
|
143
|
+
renderLevel(level) {
|
|
144
|
+
var ul_outer = document.createElement("ul");
|
|
145
|
+
let lastWasDivider = false;
|
|
146
|
+
level.forEach((item) => {
|
|
147
|
+
let li = document.createElement("li");
|
|
148
|
+
if (item.title !== '-') {
|
|
149
|
+
var icon_span = document.createElement("span");
|
|
150
|
+
icon_span.className = 'cm_icon_span';
|
|
151
|
+
if ((item.icon ?? '') != '') {
|
|
152
|
+
icon_span.innerHTML = item.icon;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
icon_span.innerHTML = this.options?.defaultIcon ?? '';
|
|
156
|
+
}
|
|
157
|
+
let text_span = document.createElement("span");
|
|
158
|
+
text_span.className = 'cm_text';
|
|
159
|
+
text_span.innerHTML = item.title;
|
|
160
|
+
let sub_span = document.createElement("span");
|
|
161
|
+
sub_span.className = 'cm_sub_span';
|
|
162
|
+
if (item.children != null) {
|
|
163
|
+
sub_span.innerHTML = this.options?.subIcon ?? '›';
|
|
164
|
+
}
|
|
165
|
+
li.appendChild(icon_span);
|
|
166
|
+
li.appendChild(text_span);
|
|
167
|
+
li.appendChild(sub_span);
|
|
168
|
+
if (item.disabled) {
|
|
169
|
+
li.setAttribute("disabled", "");
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
if (item.action)
|
|
173
|
+
li.addEventListener('click', (e) => item.action(e, item));
|
|
174
|
+
if (typeof item.children !== "undefined") {
|
|
175
|
+
li.appendChild(this.renderLevel(item.children));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
lastWasDivider = false;
|
|
179
|
+
ul_outer.appendChild(li);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
if (!lastWasDivider) {
|
|
183
|
+
li.className = "cm_divider";
|
|
184
|
+
lastWasDivider = true;
|
|
185
|
+
ul_outer.appendChild(li);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
return ul_outer;
|
|
190
|
+
}
|
|
191
|
+
display(event) {
|
|
192
|
+
let menu = document.getElementById('cm_' + this.num);
|
|
193
|
+
let clickCoords = { x: event.clientX, y: event.clientY };
|
|
194
|
+
let clickCoordsX = clickCoords.x;
|
|
195
|
+
let clickCoordsY = clickCoords.y;
|
|
196
|
+
let menuWidth = menu.offsetWidth + 4;
|
|
197
|
+
let menuHeight = menu.offsetHeight + 4;
|
|
198
|
+
let windowWidth = window.innerWidth;
|
|
199
|
+
let windowHeight = window.innerHeight;
|
|
200
|
+
let mouseOffset = this.options?.mouseOffset != null ? this.options.mouseOffset : 2;
|
|
201
|
+
if ((windowWidth - clickCoordsX) < menuWidth) {
|
|
202
|
+
menu.style.left = windowWidth - menuWidth + "px";
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
menu.style.left = (clickCoordsX + mouseOffset) + "px";
|
|
206
|
+
}
|
|
207
|
+
if ((windowHeight - clickCoordsY) < menuHeight) {
|
|
208
|
+
menu.style.top = windowHeight - menuHeight + "px";
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
menu.style.top = (clickCoordsY + mouseOffset) + "px";
|
|
212
|
+
}
|
|
213
|
+
let sizes = ContextUtil.getSizes(menu);
|
|
214
|
+
if ((windowWidth - clickCoordsX) < sizes.width) {
|
|
215
|
+
menu.classList.add("cm_border_right");
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
menu.classList.remove("cm_border_right");
|
|
219
|
+
}
|
|
220
|
+
if ((windowHeight - clickCoordsY) < sizes.height) {
|
|
221
|
+
menu.classList.add("cm_border_bottom");
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
menu.classList.remove("cm_border_bottom");
|
|
225
|
+
}
|
|
226
|
+
menu.classList.add("display");
|
|
227
|
+
if (this.options?.closeOnClick ?? true) {
|
|
228
|
+
window.addEventListener("click", this._documentClickBound);
|
|
229
|
+
}
|
|
230
|
+
event.preventDefault();
|
|
231
|
+
}
|
|
232
|
+
close() {
|
|
233
|
+
document.getElementById('cm_' + this.num).remove();
|
|
234
|
+
window.removeEventListener("click", this._documentClickBound);
|
|
235
|
+
}
|
|
236
|
+
_documentClick() {
|
|
237
|
+
this.close();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
class ContextUtil {
|
|
241
|
+
static getSizes(obj) {
|
|
242
|
+
let lis = obj.getElementsByTagName('li');
|
|
243
|
+
let width_def = 0;
|
|
244
|
+
let height_def = 0;
|
|
245
|
+
for (let i = 0; i < lis.length; i++) {
|
|
246
|
+
let li = lis[i];
|
|
247
|
+
if (li.offsetWidth > width_def) {
|
|
248
|
+
width_def = li.offsetWidth;
|
|
249
|
+
}
|
|
250
|
+
if (li.offsetHeight > height_def) {
|
|
251
|
+
height_def = li.offsetHeight;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
let width = width_def;
|
|
255
|
+
let height = height_def;
|
|
256
|
+
for (let i = 0; i < lis.length; i++) {
|
|
257
|
+
let li = lis[i];
|
|
258
|
+
let ul = li.getElementsByTagName('ul');
|
|
259
|
+
if (typeof ul[0] !== "undefined") {
|
|
260
|
+
let ul_size = ContextUtil.getSizes(ul[0]);
|
|
261
|
+
if (width_def + ul_size.width > width) {
|
|
262
|
+
width = width_def + ul_size.width;
|
|
263
|
+
}
|
|
264
|
+
if (height_def + ul_size.height > height) {
|
|
265
|
+
height = height_def + ul_size.height;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
"width": width,
|
|
271
|
+
"height": height
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IContextMenuItem } from "./IContextMenuItem";
|
|
2
|
+
export interface IContextMenuOptions {
|
|
3
|
+
defaultIcon?: string;
|
|
4
|
+
subIcon?: string;
|
|
5
|
+
mouseOffset?: number;
|
|
6
|
+
shadowRoot?: ShadowRoot | Document;
|
|
7
|
+
}
|
|
8
|
+
export declare class ContextMenu {
|
|
9
|
+
private static _contextMenuCss;
|
|
10
|
+
static count: number;
|
|
11
|
+
menu: IContextMenuItem[];
|
|
12
|
+
options: IContextMenuOptions;
|
|
13
|
+
private num;
|
|
14
|
+
private _windowDownBound;
|
|
15
|
+
private _windowUpBound;
|
|
16
|
+
private _windowKeyUpBound;
|
|
17
|
+
private _windowResizeBound;
|
|
18
|
+
private _menuElement;
|
|
19
|
+
constructor(menu: IContextMenuItem[], options?: IContextMenuOptions);
|
|
20
|
+
reload(): void;
|
|
21
|
+
renderLevel(level: IContextMenuItem[]): HTMLUListElement;
|
|
22
|
+
display(event: MouseEvent): void;
|
|
23
|
+
_windowResize(): void;
|
|
24
|
+
_windowDown(e: MouseEvent): void;
|
|
25
|
+
_windowUp(e: MouseEvent): void;
|
|
26
|
+
_windowKeyUp(e: KeyboardEvent): void;
|
|
27
|
+
static show(menu: IContextMenuItem[], event: MouseEvent, options?: IContextMenuOptions): ContextMenu;
|
|
28
|
+
close(): void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { css } from "@node-projects/base-custom-webcomponent";
|
|
2
|
+
export class ContextMenu {
|
|
3
|
+
static _contextMenuCss = css `
|
|
4
|
+
.context_menu {
|
|
5
|
+
position: fixed;
|
|
6
|
+
opacity: 0;
|
|
7
|
+
transform: scale(0);
|
|
8
|
+
transition: transform 0.1s;
|
|
9
|
+
transform-origin: top left;
|
|
10
|
+
padding: 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.context_menu.display {
|
|
14
|
+
opacity: 1;
|
|
15
|
+
transform: scale(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.context_menu,
|
|
19
|
+
.context_menu * {
|
|
20
|
+
box-sizing: border-box;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.context_menu * {
|
|
24
|
+
position: relative;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.context_menu ul {
|
|
28
|
+
list-style-type: none;
|
|
29
|
+
padding: 0;
|
|
30
|
+
margin: 0;
|
|
31
|
+
background-color: #ccc;
|
|
32
|
+
box-shadow: 0 0 5px #333;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.context_menu li {
|
|
36
|
+
padding: 0;
|
|
37
|
+
padding-right: 1.7em;
|
|
38
|
+
cursor: pointer;
|
|
39
|
+
white-space: nowrap;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.context_menu li:hover {
|
|
43
|
+
background-color: #bbb;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.context_menu li .cm_icon_span {
|
|
47
|
+
width: 1.5em;
|
|
48
|
+
height: 1.2em;
|
|
49
|
+
vertical-align: bottom;
|
|
50
|
+
display: inline-block;
|
|
51
|
+
border-right: 1px solid #aaa;
|
|
52
|
+
margin-right: 5px;
|
|
53
|
+
padding-right: 5px;
|
|
54
|
+
text-align: center;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.context_menu li .cm_sub_span {
|
|
58
|
+
width: 1em;
|
|
59
|
+
display: inline-block;
|
|
60
|
+
text-align: center;
|
|
61
|
+
position: absolute;
|
|
62
|
+
top: 50%;
|
|
63
|
+
right: 0.5em;
|
|
64
|
+
transform: translateY(-50%);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.context_menu li>ul {
|
|
68
|
+
position: absolute;
|
|
69
|
+
top: 0;
|
|
70
|
+
left: 100%;
|
|
71
|
+
opacity: 0;
|
|
72
|
+
transition: opacity 0.2s;
|
|
73
|
+
visibility: hidden;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.context_menu li:hover>ul {
|
|
77
|
+
opacity: 1;
|
|
78
|
+
visibility: visible;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.context_menu li.cm_divider {
|
|
82
|
+
border-bottom: 1px solid #aaa;
|
|
83
|
+
margin: 5px;
|
|
84
|
+
padding: 0;
|
|
85
|
+
cursor: default;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.context_menu li.cm_divider:hover {
|
|
89
|
+
background-color: inherit;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.context_menu.cm_border_right>ul ul {
|
|
93
|
+
left: unset;
|
|
94
|
+
right: 100%;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.context_menu.cm_border_bottom>ul ul {
|
|
98
|
+
top: unset;
|
|
99
|
+
bottom: 0;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.context_menu li[disabled=""] {
|
|
103
|
+
color: #777;
|
|
104
|
+
cursor: default;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.context_menu li[disabled=""]:hover {
|
|
108
|
+
background-color: inherit;
|
|
109
|
+
}`;
|
|
110
|
+
static count = 0;
|
|
111
|
+
menu;
|
|
112
|
+
options;
|
|
113
|
+
num;
|
|
114
|
+
_windowDownBound;
|
|
115
|
+
_windowUpBound;
|
|
116
|
+
_windowKeyUpBound;
|
|
117
|
+
_windowResizeBound;
|
|
118
|
+
_menuElement;
|
|
119
|
+
constructor(menu, options) {
|
|
120
|
+
this.num = ContextMenu.count++;
|
|
121
|
+
this.menu = menu;
|
|
122
|
+
this.options = options;
|
|
123
|
+
this.reload();
|
|
124
|
+
this._windowDownBound = this._windowDown.bind(this);
|
|
125
|
+
this._windowUpBound = this._windowUp.bind(this);
|
|
126
|
+
this._windowKeyUpBound = this._windowKeyUp.bind(this);
|
|
127
|
+
this._windowResizeBound = this._windowResize.bind(this);
|
|
128
|
+
}
|
|
129
|
+
reload() {
|
|
130
|
+
let shadowRoot = this.options?.shadowRoot ?? document;
|
|
131
|
+
if (this._menuElement == null) {
|
|
132
|
+
this._menuElement = document.createElement("div");
|
|
133
|
+
this._menuElement.className = "context_menu";
|
|
134
|
+
this._menuElement.id = "cm_" + this.num;
|
|
135
|
+
if (shadowRoot === document)
|
|
136
|
+
document.body.appendChild(this._menuElement);
|
|
137
|
+
else
|
|
138
|
+
shadowRoot.appendChild(this._menuElement);
|
|
139
|
+
}
|
|
140
|
+
this._menuElement.innerHTML = "";
|
|
141
|
+
if (shadowRoot.adoptedStyleSheets.indexOf(ContextMenu._contextMenuCss) < 0) {
|
|
142
|
+
shadowRoot.adoptedStyleSheets = [...shadowRoot.adoptedStyleSheets, ContextMenu._contextMenuCss];
|
|
143
|
+
}
|
|
144
|
+
this._menuElement.appendChild(this.renderLevel(this.menu));
|
|
145
|
+
}
|
|
146
|
+
renderLevel(level) {
|
|
147
|
+
let ul_outer = document.createElement("ul");
|
|
148
|
+
let lastWasDivider = false;
|
|
149
|
+
level.forEach((item) => {
|
|
150
|
+
let li = document.createElement("li");
|
|
151
|
+
if (item.title !== '-') {
|
|
152
|
+
let icon_span = document.createElement("span");
|
|
153
|
+
icon_span.className = 'cm_icon_span';
|
|
154
|
+
if ((item.icon ?? '') != '') {
|
|
155
|
+
icon_span.innerHTML = item.icon;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
icon_span.innerHTML = this.options?.defaultIcon ?? '';
|
|
159
|
+
}
|
|
160
|
+
let text_span = document.createElement("span");
|
|
161
|
+
text_span.className = 'cm_text';
|
|
162
|
+
text_span.innerHTML = item.title;
|
|
163
|
+
let sub_span = document.createElement("span");
|
|
164
|
+
sub_span.className = 'cm_sub_span';
|
|
165
|
+
if (item.children != null) {
|
|
166
|
+
sub_span.innerHTML = this.options?.subIcon ?? '›';
|
|
167
|
+
}
|
|
168
|
+
li.appendChild(icon_span);
|
|
169
|
+
li.appendChild(text_span);
|
|
170
|
+
li.appendChild(sub_span);
|
|
171
|
+
if (item.disabled) {
|
|
172
|
+
li.setAttribute("disabled", "");
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
if (item.action)
|
|
176
|
+
li.addEventListener('click', (e) => {
|
|
177
|
+
item.action(e, item);
|
|
178
|
+
this.close();
|
|
179
|
+
});
|
|
180
|
+
if (item.children != null) {
|
|
181
|
+
li.appendChild(this.renderLevel(item.children));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
lastWasDivider = false;
|
|
185
|
+
ul_outer.appendChild(li);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
if (!lastWasDivider) {
|
|
189
|
+
li.className = "cm_divider";
|
|
190
|
+
lastWasDivider = true;
|
|
191
|
+
ul_outer.appendChild(li);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
return ul_outer;
|
|
196
|
+
}
|
|
197
|
+
display(event) {
|
|
198
|
+
let menu = this._menuElement;
|
|
199
|
+
let clickCoords = { x: event.clientX, y: event.clientY };
|
|
200
|
+
let clickCoordsX = clickCoords.x;
|
|
201
|
+
let clickCoordsY = clickCoords.y;
|
|
202
|
+
let menuWidth = menu.offsetWidth + 4;
|
|
203
|
+
let menuHeight = menu.offsetHeight + 4;
|
|
204
|
+
let windowWidth = window.innerWidth;
|
|
205
|
+
let windowHeight = window.innerHeight;
|
|
206
|
+
let mouseOffset = this.options?.mouseOffset != null ? this.options.mouseOffset : 2;
|
|
207
|
+
if ((windowWidth - clickCoordsX) < menuWidth) {
|
|
208
|
+
menu.style.left = windowWidth - menuWidth + "px";
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
menu.style.left = (clickCoordsX + mouseOffset) + "px";
|
|
212
|
+
}
|
|
213
|
+
if ((windowHeight - clickCoordsY) < menuHeight) {
|
|
214
|
+
menu.style.top = windowHeight - menuHeight + "px";
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
menu.style.top = (clickCoordsY + mouseOffset) + "px";
|
|
218
|
+
}
|
|
219
|
+
let sizes = ContextUtil.getSizes(menu);
|
|
220
|
+
if ((windowWidth - clickCoordsX) < sizes.width) {
|
|
221
|
+
menu.classList.add("cm_border_right");
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
menu.classList.remove("cm_border_right");
|
|
225
|
+
}
|
|
226
|
+
if ((windowHeight - clickCoordsY) < sizes.height) {
|
|
227
|
+
menu.classList.add("cm_border_bottom");
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
menu.classList.remove("cm_border_bottom");
|
|
231
|
+
}
|
|
232
|
+
menu.classList.add("display");
|
|
233
|
+
window.addEventListener("keyup", this._windowKeyUpBound);
|
|
234
|
+
window.addEventListener("mousedown", this._windowDownBound);
|
|
235
|
+
window.addEventListener("mouseup", this._windowUpBound);
|
|
236
|
+
window.addEventListener("resize", this._windowResizeBound);
|
|
237
|
+
event.preventDefault();
|
|
238
|
+
}
|
|
239
|
+
_windowResize() {
|
|
240
|
+
this.close();
|
|
241
|
+
}
|
|
242
|
+
_windowDown(e) {
|
|
243
|
+
const p = e.composedPath();
|
|
244
|
+
if (p.indexOf(this._menuElement) < 0)
|
|
245
|
+
this.close();
|
|
246
|
+
}
|
|
247
|
+
_windowUp(e) {
|
|
248
|
+
const p = e.composedPath();
|
|
249
|
+
if (p.indexOf(this._menuElement) < 0)
|
|
250
|
+
this.close();
|
|
251
|
+
}
|
|
252
|
+
_windowKeyUp(e) {
|
|
253
|
+
if (e.key === 'Escape') {
|
|
254
|
+
this.close();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
static show(menu, event, options) {
|
|
258
|
+
let ctxMenu = new ContextMenu(menu, options);
|
|
259
|
+
ctxMenu.display(event);
|
|
260
|
+
return ctxMenu;
|
|
261
|
+
}
|
|
262
|
+
close() {
|
|
263
|
+
this._menuElement.remove();
|
|
264
|
+
window.removeEventListener("keyup", this._windowKeyUpBound);
|
|
265
|
+
window.removeEventListener("mousedown", this._windowDownBound);
|
|
266
|
+
window.removeEventListener("mouseup", this._windowUpBound);
|
|
267
|
+
window.removeEventListener("resize", this._windowResizeBound);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
class ContextUtil {
|
|
271
|
+
static getSizes(obj) {
|
|
272
|
+
let lis = obj.getElementsByTagName('li');
|
|
273
|
+
let width_def = 0;
|
|
274
|
+
let height_def = 0;
|
|
275
|
+
for (let i = 0; i < lis.length; i++) {
|
|
276
|
+
let li = lis[i];
|
|
277
|
+
if (li.offsetWidth > width_def) {
|
|
278
|
+
width_def = li.offsetWidth;
|
|
279
|
+
}
|
|
280
|
+
if (li.offsetHeight > height_def) {
|
|
281
|
+
height_def = li.offsetHeight;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
let width = width_def;
|
|
285
|
+
let height = height_def;
|
|
286
|
+
for (let i = 0; i < lis.length; i++) {
|
|
287
|
+
let li = lis[i];
|
|
288
|
+
let ul = li.getElementsByTagName('ul');
|
|
289
|
+
if (typeof ul[0] !== "undefined") {
|
|
290
|
+
let ul_size = ContextUtil.getSizes(ul[0]);
|
|
291
|
+
if (width_def + ul_size.width > width) {
|
|
292
|
+
width = width_def + ul_size.width;
|
|
293
|
+
}
|
|
294
|
+
if (height_def + ul_size.height > height) {
|
|
295
|
+
height = height_def + ul_size.height;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
"width": width,
|
|
301
|
+
"height": height
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}
|
|
@@ -4,7 +4,6 @@ import { IDesignItem } from '../../item/IDesignItem';
|
|
|
4
4
|
import { BaseCustomWebComponentLazyAppend, TypedEvent } from '@node-projects/base-custom-webcomponent';
|
|
5
5
|
import { IDesignerCanvas } from './IDesignerCanvas';
|
|
6
6
|
import { Snaplines } from './Snaplines';
|
|
7
|
-
import { ContextMenuHelper } from '../../helper/contextMenu/ContextMenuHelper';
|
|
8
7
|
import { IPlacementView } from './IPlacementView';
|
|
9
8
|
import { IUiCommandHandler } from '../../../commandHandling/IUiCommandHandler';
|
|
10
9
|
import { IUiCommand } from '../../../commandHandling/IUiCommand';
|
|
@@ -15,6 +14,7 @@ import { OverlayLayerView } from './overlayLayerView';
|
|
|
15
14
|
import { IRect } from "../../../interfaces/IRect.js";
|
|
16
15
|
import { ISize } from "../../../interfaces/ISize.js";
|
|
17
16
|
import { ITool } from "./tools/ITool.js";
|
|
17
|
+
import { ContextMenu } from "../../helper/contextMenu/ContextMenu";
|
|
18
18
|
export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend implements IDesignerCanvas, IPlacementView, IUiCommandHandler {
|
|
19
19
|
serviceContainer: ServiceContainer;
|
|
20
20
|
instanceServiceContainer: InstanceServiceContainer;
|
|
@@ -87,7 +87,7 @@ export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend imp
|
|
|
87
87
|
private _onDragOver;
|
|
88
88
|
private _getPossibleContainerForDrop;
|
|
89
89
|
private _onDrop;
|
|
90
|
-
showDesignItemContextMenu(designItem: IDesignItem, event: MouseEvent):
|
|
90
|
+
showDesignItemContextMenu(designItem: IDesignItem, event: MouseEvent): ContextMenu;
|
|
91
91
|
private _onDblClick;
|
|
92
92
|
private onKeyUp;
|
|
93
93
|
private onKeyDown;
|
|
@@ -8,7 +8,6 @@ import { dragDropFormatNameElementDefinition, dragDropFormatNameBindingObject }
|
|
|
8
8
|
import { ContentService } from '../../services/contentService/ContentService';
|
|
9
9
|
import { InsertAction } from '../../services/undoService/transactionItems/InsertAction';
|
|
10
10
|
import { Snaplines } from './Snaplines';
|
|
11
|
-
import { ContextMenuHelper } from '../../helper/contextMenu/ContextMenuHelper';
|
|
12
11
|
import { DeleteAction } from '../../services/undoService/transactionItems/DeleteAction';
|
|
13
12
|
import { CommandType } from '../../../commandHandling/CommandType';
|
|
14
13
|
import { DefaultHtmlParserService } from "../../services/htmlParserService/DefaultHtmlParserService";
|
|
@@ -20,6 +19,7 @@ import { dataURItoBlob, exportData, sleep } from "../../helper/Helper";
|
|
|
20
19
|
import { DomHelper } from '@node-projects/base-custom-webcomponent/dist/DomHelper';
|
|
21
20
|
import { OverlayLayer } from "./extensions/OverlayLayer";
|
|
22
21
|
import { OverlayLayerView } from './overlayLayerView';
|
|
22
|
+
import { ContextMenu } from "../../helper/contextMenu/ContextMenu";
|
|
23
23
|
export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
24
24
|
// Public Properties
|
|
25
25
|
serviceContainer;
|
|
@@ -639,8 +639,9 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
639
639
|
mnuItems.push(...cme.provideContextMenuItems(event, this, designItem));
|
|
640
640
|
}
|
|
641
641
|
}
|
|
642
|
-
|
|
643
|
-
|
|
642
|
+
let ctxMenu = new ContextMenu(mnuItems, null);
|
|
643
|
+
ctxMenu.display(event);
|
|
644
|
+
return ctxMenu;
|
|
644
645
|
}
|
|
645
646
|
_onDblClick(event) {
|
|
646
647
|
event.preventDefault();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IContextMenuItem } from "../../../../helper/contextMenu/
|
|
1
|
+
import { IContextMenuItem } from "../../../../helper/contextMenu/IContextMenuItem";
|
|
2
2
|
import { IDesignItem } from "../../../../item/IDesignItem";
|
|
3
3
|
import { IDesignerCanvas } from "../../IDesignerCanvas";
|
|
4
4
|
import { ContextmenuInitiator, IContextMenuExtension } from "./IContextMenuExtension";
|
package/dist/elements/widgets/designerView/extensions/contextMenu/IContextMenuExtension.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IContextMenuItem } from "../../../../helper/contextMenu/
|
|
1
|
+
import { IContextMenuItem } from "../../../../helper/contextMenu/IContextMenuItem";
|
|
2
2
|
import { IDesignItem } from "../../../../item/IDesignItem";
|
|
3
3
|
import { IDesignerCanvas } from "../../IDesignerCanvas";
|
|
4
4
|
export declare type ContextmenuInitiator = 'designer' | 'treeView' | 'other';
|
package/dist/elements/widgets/designerView/extensions/contextMenu/ItemsBelowContextMenu.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IContextMenuItem } from "../../../../helper/contextMenu/
|
|
1
|
+
import { IContextMenuItem } from "../../../../helper/contextMenu/IContextMenuItem";
|
|
2
2
|
import { IDesignItem } from "../../../../item/IDesignItem";
|
|
3
3
|
import { IDesignerCanvas } from "../../IDesignerCanvas";
|
|
4
4
|
import { ContextmenuInitiator, IContextMenuExtension } from "./IContextMenuExtension";
|
|
@@ -6,8 +6,7 @@ export class ItemsBelowContextMenu {
|
|
|
6
6
|
provideContextMenuItems(event, designerCanvas, designItem) {
|
|
7
7
|
const lstItems = designerCanvas.elementsFromPoint(event.x, event.y);
|
|
8
8
|
if (lstItems.length > 0) {
|
|
9
|
-
|
|
10
|
-
return [...lstItems.map(x => ({ title: 'select: ' + x.localName + (x.id ? ' (' + x.id + ')' : ''), action: () => this._select(designerCanvas, x) }))];
|
|
9
|
+
return [{ title: 'items below', children: [...lstItems.map(x => ({ title: 'select: ' + x.localName + (x.id ? ' (' + x.id + ')' : ''), action: () => this._select(designerCanvas, x) }))] }];
|
|
11
10
|
}
|
|
12
11
|
return [];
|
|
13
12
|
}
|