@node-projects/web-component-designer 0.1.352 → 0.1.353
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/elements/helper/contextMenu/ContextMenu.d.ts +11 -1
- package/dist/elements/helper/contextMenu/ContextMenu.js +134 -115
- package/dist/elements/helper/contextMenu/ContextMenu.js.map +1 -1
- package/dist/elements/item/DesignItem.d.ts +1 -1
- package/dist/elements/widgets/designerView/DomConverter.d.ts +1 -1
- package/dist/index-min.js +7 -7
- package/dist/index-min.js.map +2 -2
- package/jest.config.js +9 -3
- package/package.json +1 -1
- package/tests/ContextMenu.test.ts +133 -0
package/jest.config.js
CHANGED
|
@@ -5,11 +5,17 @@ export default {
|
|
|
5
5
|
testEnvironment: "node",
|
|
6
6
|
extensionsToTreatAsEsm: ['.ts', '.mts'],
|
|
7
7
|
transform: {
|
|
8
|
-
'^.+\\.(mts|ts|tsx)$': [
|
|
8
|
+
'^.+\\.(mts|ts|tsx|mjs|js)$': [
|
|
9
9
|
"ts-jest",
|
|
10
10
|
{
|
|
11
|
-
"useESM": true
|
|
11
|
+
"useESM": true,
|
|
12
|
+
"tsconfig": {
|
|
13
|
+
"allowJs": true
|
|
14
|
+
}
|
|
12
15
|
}
|
|
13
16
|
]
|
|
14
|
-
}
|
|
17
|
+
},
|
|
18
|
+
transformIgnorePatterns: [
|
|
19
|
+
'/node_modules/(?!(?:@node-projects/base-custom-webcomponent)(?:/|$))'
|
|
20
|
+
]
|
|
15
21
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/** @jest-environment jsdom */
|
|
2
|
+
|
|
3
|
+
import { afterAll, afterEach, beforeAll, beforeEach, expect, test } from '@jest/globals';
|
|
4
|
+
|
|
5
|
+
let ContextMenu: typeof import('../src/elements/helper/contextMenu/ContextMenu').ContextMenu;
|
|
6
|
+
|
|
7
|
+
const originalCSSStyleSheet = globalThis.CSSStyleSheet;
|
|
8
|
+
const originalShowPopover = HTMLElement.prototype.showPopover;
|
|
9
|
+
const originalHidePopover = HTMLElement.prototype.hidePopover;
|
|
10
|
+
const originalMatches = HTMLElement.prototype.matches;
|
|
11
|
+
const popoverOpenAttribute = 'data-test-popover-open';
|
|
12
|
+
|
|
13
|
+
function makeRect(left: number, top: number, width: number, height: number): DOMRect {
|
|
14
|
+
return {
|
|
15
|
+
x: left,
|
|
16
|
+
y: top,
|
|
17
|
+
width,
|
|
18
|
+
height,
|
|
19
|
+
top,
|
|
20
|
+
right: left + width,
|
|
21
|
+
bottom: top + height,
|
|
22
|
+
left,
|
|
23
|
+
toJSON() {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
} as DOMRect;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
beforeAll(async () => {
|
|
30
|
+
Object.defineProperty(globalThis, 'CSSStyleSheet', {
|
|
31
|
+
configurable: true,
|
|
32
|
+
value: class {
|
|
33
|
+
replaceSync() {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(document, 'adoptedStyleSheets', {
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true,
|
|
40
|
+
value: []
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
HTMLElement.prototype.showPopover = function () {
|
|
44
|
+
this.setAttribute(popoverOpenAttribute, '');
|
|
45
|
+
};
|
|
46
|
+
HTMLElement.prototype.hidePopover = function () {
|
|
47
|
+
this.removeAttribute(popoverOpenAttribute);
|
|
48
|
+
};
|
|
49
|
+
HTMLElement.prototype.matches = function (selectors: string) {
|
|
50
|
+
if (selectors === ':popover-open') {
|
|
51
|
+
return this.hasAttribute(popoverOpenAttribute);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return originalMatches.call(this, selectors);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
({ ContextMenu } = await import('../src/elements/helper/contextMenu/ContextMenu'));
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
beforeEach(() => {
|
|
61
|
+
document.body.innerHTML = '';
|
|
62
|
+
document.adoptedStyleSheets = [];
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
afterEach(() => {
|
|
66
|
+
ContextMenu?.closeAll();
|
|
67
|
+
document.body.innerHTML = '';
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
afterAll(() => {
|
|
71
|
+
Object.defineProperty(globalThis, 'CSSStyleSheet', {
|
|
72
|
+
configurable: true,
|
|
73
|
+
value: originalCSSStyleSheet
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
if (originalShowPopover == null)
|
|
77
|
+
delete HTMLElement.prototype.showPopover;
|
|
78
|
+
else
|
|
79
|
+
HTMLElement.prototype.showPopover = originalShowPopover;
|
|
80
|
+
|
|
81
|
+
if (originalHidePopover == null)
|
|
82
|
+
delete HTMLElement.prototype.hidePopover;
|
|
83
|
+
else
|
|
84
|
+
HTMLElement.prototype.hidePopover = originalHidePopover;
|
|
85
|
+
|
|
86
|
+
HTMLElement.prototype.matches = originalMatches;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('displays the root menu as a manual popover', () => {
|
|
90
|
+
const menu = new ContextMenu([{ title: 'Item' }]);
|
|
91
|
+
menu.display(new MouseEvent('contextmenu', { bubbles: true, cancelable: true, clientX: 48, clientY: 64 }));
|
|
92
|
+
|
|
93
|
+
const menuElement = document.querySelector('.context_menu') as HTMLDivElement;
|
|
94
|
+
|
|
95
|
+
expect(menuElement.getAttribute('popover')).toBe('manual');
|
|
96
|
+
expect(menuElement.hasAttribute(popoverOpenAttribute)).toBe(true);
|
|
97
|
+
expect(menuElement.style.left).toBe('50px');
|
|
98
|
+
expect(menuElement.style.top).toBe('66px');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('opens submenus as manual popovers', () => {
|
|
102
|
+
new ContextMenu([{ title: 'Parent', children: [{ title: 'Child' }] }]);
|
|
103
|
+
|
|
104
|
+
const parentItem = document.querySelector('.context_menu li') as HTMLLIElement;
|
|
105
|
+
const childmenu = parentItem.querySelector('ul') as HTMLUListElement;
|
|
106
|
+
Object.defineProperty(parentItem, 'getBoundingClientRect', {
|
|
107
|
+
configurable: true,
|
|
108
|
+
value: () => makeRect(40, 20, 80, 24)
|
|
109
|
+
});
|
|
110
|
+
Object.defineProperty(childmenu, 'getBoundingClientRect', {
|
|
111
|
+
configurable: true,
|
|
112
|
+
value: () => makeRect(0, 0, 90, 100)
|
|
113
|
+
});
|
|
114
|
+
Object.defineProperty(childmenu, 'offsetWidth', { configurable: true, value: 90 });
|
|
115
|
+
Object.defineProperty(childmenu, 'offsetHeight', { configurable: true, value: 100 });
|
|
116
|
+
|
|
117
|
+
parentItem.dispatchEvent(new MouseEvent('mouseenter', { bubbles: true }));
|
|
118
|
+
|
|
119
|
+
expect(childmenu.getAttribute('popover')).toBe('manual');
|
|
120
|
+
expect(childmenu.classList.contains('context_menu_submenu_popover')).toBe(true);
|
|
121
|
+
expect(childmenu.hasAttribute(popoverOpenAttribute)).toBe(true);
|
|
122
|
+
expect(childmenu.style.left).toBe('120px');
|
|
123
|
+
expect(childmenu.style.top).toBe('20px');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('closeAll removes the menu from the document', () => {
|
|
127
|
+
const menu = new ContextMenu([{ title: 'Item' }]);
|
|
128
|
+
menu.display(new MouseEvent('contextmenu', { bubbles: true, cancelable: true, clientX: 12, clientY: 24 }));
|
|
129
|
+
|
|
130
|
+
ContextMenu.closeAll();
|
|
131
|
+
|
|
132
|
+
expect(document.querySelector('.context_menu')).toBeNull();
|
|
133
|
+
});
|