@asup/context-menu 1.1.0 → 1.1.2
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/README.md +35 -0
- package/dist/cjs/main.css +70 -0
- package/dist/cjs/main.css.map +1 -1
- package/dist/cjs/main.js +244 -6
- package/dist/cjs/main.js.map +1 -1
- package/dist/context-menu.d.ts +17 -0
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/main.css +70 -0
- package/dist/main.css.map +1 -1
- package/dist/main.js +214 -2
- package/dist/main.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -56,3 +56,38 @@ import { ContextMenuProvider, iMenuItem } from '@asup/context-menu';
|
|
|
56
56
|
</ContextMenuHandler>
|
|
57
57
|
|
|
58
58
|
```
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
import { ContextWindowStack, ContextWindow }
|
|
62
|
+
|
|
63
|
+
// Context window stack needs to cover the application, or portion where context windows cannot clash with each other
|
|
64
|
+
<ContextWindowStack>
|
|
65
|
+
...rest of app
|
|
66
|
+
|
|
67
|
+
<ContextWindow
|
|
68
|
+
id='window-1'
|
|
69
|
+
title={'Window 1'}
|
|
70
|
+
visible={visible}
|
|
71
|
+
style={ window styling, applied to the window div}
|
|
72
|
+
onOpen={ called function on opening}
|
|
73
|
+
onClose={ called function on closing (close cross in the window)}
|
|
74
|
+
>
|
|
75
|
+
{window contents}
|
|
76
|
+
</ContextWindow>
|
|
77
|
+
|
|
78
|
+
<ContextWindow
|
|
79
|
+
id='window-2'
|
|
80
|
+
title={'Window 2'}
|
|
81
|
+
visible={visible}
|
|
82
|
+
style={ window styling, applied to the window div}
|
|
83
|
+
onOpen={ called function on opening}
|
|
84
|
+
onClose={ called function on closing (close cross in the window)}
|
|
85
|
+
>
|
|
86
|
+
{window contents}
|
|
87
|
+
</ContextWindow>
|
|
88
|
+
|
|
89
|
+
...end of app
|
|
90
|
+
|
|
91
|
+
</ContextWindowStack>
|
|
92
|
+
|
|
93
|
+
```
|
package/dist/cjs/main.css
CHANGED
|
@@ -65,4 +65,74 @@
|
|
|
65
65
|
flex-grow: 1;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
.contextwindow {
|
|
69
|
+
z-index: 2001;
|
|
70
|
+
resize: both;
|
|
71
|
+
background-color: #fafafa;
|
|
72
|
+
border: 1px solid #000;
|
|
73
|
+
border-top-left-radius: 8px;
|
|
74
|
+
border-top-right-radius: 8px;
|
|
75
|
+
border-bottom-left-radius: 8px;
|
|
76
|
+
justify-content: flex-start;
|
|
77
|
+
margin: 0;
|
|
78
|
+
padding: 4px;
|
|
79
|
+
transition: opacity .25s linear;
|
|
80
|
+
position: absolute;
|
|
81
|
+
overflow: auto;
|
|
82
|
+
box-shadow: 6px 6px 6px rgba(64, 64, 64, .5);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.contextwindow-title {
|
|
86
|
+
text-transform: capitalize;
|
|
87
|
+
height: 24px;
|
|
88
|
+
cursor: grab;
|
|
89
|
+
border-bottom: 1px dashed #000;
|
|
90
|
+
flex-grow: 1;
|
|
91
|
+
margin: 0 4px 3px;
|
|
92
|
+
padding-bottom: 4px;
|
|
93
|
+
font-size: 18px;
|
|
94
|
+
font-weight: 600;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.contextwindow-title.moving {
|
|
98
|
+
cursor: grabbing;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.contextwindow-title-text {
|
|
102
|
+
display: inline-block;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.contextwindow-title-close {
|
|
106
|
+
float: right;
|
|
107
|
+
cursor: auto;
|
|
108
|
+
font-size: small;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.contextwindow-body {
|
|
112
|
+
height: calc(100% - 40px);
|
|
113
|
+
margin-right: 4px;
|
|
114
|
+
padding-bottom: 8px;
|
|
115
|
+
overflow: auto;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.contextwindow-body::-webkit-scrollbar {
|
|
119
|
+
width: 8px;
|
|
120
|
+
height: 8px;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.contextwindow-body::-webkit-scrollbar-track {
|
|
124
|
+
background: #fff;
|
|
125
|
+
border-radius: 8px;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.contextwindow-body::-webkit-scrollbar-thumb {
|
|
129
|
+
background: #d3d3d3;
|
|
130
|
+
border: none;
|
|
131
|
+
border-radius: 8px;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.contextwindow-body::-webkit-scrollbar-thumb:hover {
|
|
135
|
+
background: gray;
|
|
136
|
+
}
|
|
137
|
+
|
|
68
138
|
/*# sourceMappingURL=main.css.map */
|
package/dist/cjs/main.css.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA;;;;;;;;;;AAWA;;;;AAIA;;;;;;;;;;;;;AAaA;;;;;AAKA;;;;AAIA;;;;AAIA;;;;AAIA;;;;;AAKA;;;;;AAKA;;;;AAIA;;;;;AAKA","sources":["src/components/ContextMenu.css"],"sourcesContent":[".context-menu {\n position: absolute;\n visibility: hidden;\n border: 1px solid;\n border-color: rgb(17, 20, 24);\n border-radius: 8px;\n opacity: 1;\n background-color: rgb(251, 253, 246);\n z-index: 10000;\n}\n\n.context-menu.visible {\n visibility: inherit;\n}\n\n.context-menu-item {\n color: rgb(17, 20, 24);\n cursor: pointer;\n padding: 0 4px;\n min-width: 80px;\n height: 21px;\n position: relative;\n display: flex;\n flex-direction: row;\n justify-content: space-between;\n white-space: nowrap;\n}\n\n.context-menu-item.disabled {\n background-color: rgba(0, 0, 0, 0.2);\n cursor: not-allowed;\n}\n\n.context-menu-item:first-child {\n padding-top: 4px;\n}\n\n.context-menu-item:last-child {\n padding-bottom: 4px;\n}\n\n.context-menu-item:not(.disabled):hover {\n background-color: rgb(251, 233, 230);\n}\n\n.context-menu-item:hover:first-child {\n border-top-left-radius: 6px;\n border-top-right-radius: 6px;\n}\n\n.context-menu-item:hover:last-child {\n border-bottom-left-radius: 6px;\n border-bottom-right-radius: 6px;\n}\n\n.context-menu-item .caret-holder {\n align-self: flex-end;\n}\n\n.context-menu-item .caret-holder .sub-menu {\n z-index: 1;\n position: relative;\n}\n\n.context-menu-item-label {\n flex-grow: 1;\n}\n"],"names":[],"version":3,"file":"main.css.map"}
|
|
1
|
+
{"mappings":"AAAA;;;;;;;;;;AAWA;;;;AAIA;;;;;;;;;;;;;AAaA;;;;;AAKA;;;;AAIA;;;;AAIA;;;;AAIA;;;;;AAKA;;;;;AAKA;;;;AAIA;;;;;AAKA;;;;AChEA;;;;;;;;;;;;;;;;;AAiBA;;;;;;;;;;;;AAYA;;;;AAIA;;;;AAIA;;;;;;AAMA;;;;;;;AAOA;;;;;AAKA;;;;;AAKA;;;;;;AAMA","sources":["src/components/ContextMenu.css","src/components/ContextWindow.css"],"sourcesContent":[".context-menu {\n position: absolute;\n visibility: hidden;\n border: 1px solid;\n border-color: rgb(17, 20, 24);\n border-radius: 8px;\n opacity: 1;\n background-color: rgb(251, 253, 246);\n z-index: 10000;\n}\n\n.context-menu.visible {\n visibility: inherit;\n}\n\n.context-menu-item {\n color: rgb(17, 20, 24);\n cursor: pointer;\n padding: 0 4px;\n min-width: 80px;\n height: 21px;\n position: relative;\n display: flex;\n flex-direction: row;\n justify-content: space-between;\n white-space: nowrap;\n}\n\n.context-menu-item.disabled {\n background-color: rgba(0, 0, 0, 0.2);\n cursor: not-allowed;\n}\n\n.context-menu-item:first-child {\n padding-top: 4px;\n}\n\n.context-menu-item:last-child {\n padding-bottom: 4px;\n}\n\n.context-menu-item:not(.disabled):hover {\n background-color: rgb(251, 233, 230);\n}\n\n.context-menu-item:hover:first-child {\n border-top-left-radius: 6px;\n border-top-right-radius: 6px;\n}\n\n.context-menu-item:hover:last-child {\n border-bottom-left-radius: 6px;\n border-bottom-right-radius: 6px;\n}\n\n.context-menu-item .caret-holder {\n align-self: flex-end;\n}\n\n.context-menu-item .caret-holder .sub-menu {\n z-index: 1;\n position: relative;\n}\n\n.context-menu-item-label {\n flex-grow: 1;\n}\n",".contextwindow {\n z-index: 2001;\n border: 1px black solid;\n margin: 0;\n padding: 4px;\n background-color: rgb(250, 250, 250);\n box-shadow: 6px 6px 6px rgb(64, 64, 64, 0.5);\n transition: opacity 0.25s linear;\n justify-content: flex-start;\n position: absolute;\n border-top-left-radius: 8px;\n border-top-right-radius: 8px;\n border-bottom-left-radius: 8px;\n resize: both;\n overflow: auto;\n}\n\n.contextwindow-title {\n text-transform: capitalize;\n border-bottom: 1px black dashed;\n padding-bottom: 4px;\n margin: 0 4px 3px 4px;\n font-size: 18px;\n font-weight: 600;\n flex-grow: 1;\n height: 24px;\n cursor: grab;\n}\n\n.contextwindow-title.moving {\n cursor: grabbing;\n}\n\n.contextwindow-title-text {\n display: inline-block;\n}\n\n.contextwindow-title-close {\n float: right;\n font-size: small;\n cursor: auto;\n}\n\n.contextwindow-body {\n overflow: auto;\n padding-bottom: 8px;\n margin-right: 4px;\n height: calc(100% - 40px);\n}\n\n.contextwindow-body::-webkit-scrollbar {\n width: 8px;\n height: 8px;\n}\n\n.contextwindow-body::-webkit-scrollbar-track {\n background: white;\n border-radius: 8px;\n}\n\n.contextwindow-body::-webkit-scrollbar-thumb {\n background: lightgrey;\n border: none;\n border-radius: 8px;\n}\n\n.contextwindow-body::-webkit-scrollbar-thumb:hover {\n background: grey;\n}\n"],"names":[],"version":3,"file":"main.css.map"}
|
package/dist/cjs/main.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
require("./main.css");
|
|
2
|
-
var $gTuX4$
|
|
2
|
+
var $gTuX4$swchelperscjs_sliced_to_arraycjs = require("@swc/helpers/cjs/_sliced_to_array.cjs");
|
|
3
3
|
var $gTuX4$reactjsxruntime = require("react/jsx-runtime");
|
|
4
4
|
var $gTuX4$react = require("react");
|
|
5
5
|
var $gTuX4$reactdom = require("react-dom");
|
|
6
|
+
var $gTuX4$swchelperscjs_object_spreadcjs = require("@swc/helpers/cjs/_object_spread.cjs");
|
|
7
|
+
var $gTuX4$swchelperscjs_object_spread_propscjs = require("@swc/helpers/cjs/_object_spread_props.cjs");
|
|
8
|
+
var $gTuX4$swchelperscjs_to_consumable_arraycjs = require("@swc/helpers/cjs/_to_consumable_array.cjs");
|
|
6
9
|
|
|
7
10
|
function $parcel$exportWildcard(dest, source) {
|
|
8
11
|
Object.keys(source).forEach(function(key) {
|
|
@@ -29,6 +32,8 @@ function $parcel$interopDefault(a) {
|
|
|
29
32
|
var $a68bd8a6c0fd98c2$exports = {};
|
|
30
33
|
|
|
31
34
|
$parcel$export($a68bd8a6c0fd98c2$exports, "ContextMenuHandler", function () { return $3c568ee547c732c3$export$ed4f9641643dc7e4; });
|
|
35
|
+
$parcel$export($a68bd8a6c0fd98c2$exports, "ContextWindow", function () { return $46fb0088a1bbb6d8$export$1af8984c69ba1b24; });
|
|
36
|
+
$parcel$export($a68bd8a6c0fd98c2$exports, "ContextWindowStack", function () { return $16208d559c772441$export$9f37482ccd50dad2; });
|
|
32
37
|
|
|
33
38
|
|
|
34
39
|
|
|
@@ -41,7 +46,7 @@ $parcel$export($a68bd8a6c0fd98c2$exports, "ContextMenuHandler", function () { re
|
|
|
41
46
|
|
|
42
47
|
var $2275c4645c0c5e94$export$a9c522a6d7beb830 = function(param) {
|
|
43
48
|
var entries = param.entries, target = param.target, toClose = param.toClose;
|
|
44
|
-
var _useState = (0,
|
|
49
|
+
var _useState = (0, $gTuX4$swchelperscjs_sliced_to_arraycjs._)((0, $gTuX4$react.useState)(false), 2), visible = _useState[0], setVisible = _useState[1];
|
|
45
50
|
return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsxs)("span", {
|
|
46
51
|
className: "caret-holder",
|
|
47
52
|
onMouseEnter: function() {
|
|
@@ -122,10 +127,10 @@ var $3c568ee547c732c3$export$ed4f9641643dc7e4 = function(param) {
|
|
|
122
127
|
// Menu resources
|
|
123
128
|
var divRef = (0, $gTuX4$react.useRef)(null);
|
|
124
129
|
var menuRef = (0, $gTuX4$react.useRef)(null);
|
|
125
|
-
var _useState = (0,
|
|
126
|
-
var _useState1 = (0,
|
|
127
|
-
var _useState2 = (0,
|
|
128
|
-
var _useState3 = (0,
|
|
130
|
+
var _useState = (0, $gTuX4$swchelperscjs_sliced_to_arraycjs._)((0, $gTuX4$react.useState)(0), 2), menuXPos = _useState[0], setMenuXPos = _useState[1];
|
|
131
|
+
var _useState1 = (0, $gTuX4$swchelperscjs_sliced_to_arraycjs._)((0, $gTuX4$react.useState)(0), 2), menuYPos = _useState1[0], setMenuYPos = _useState1[1];
|
|
132
|
+
var _useState2 = (0, $gTuX4$swchelperscjs_sliced_to_arraycjs._)((0, $gTuX4$react.useState)(false), 2), menuVisible = _useState2[0], setMenuVisible = _useState2[1];
|
|
133
|
+
var _useState3 = (0, $gTuX4$swchelperscjs_sliced_to_arraycjs._)((0, $gTuX4$react.useState)(null), 2), target = _useState3[0], setTarget = _useState3[1];
|
|
129
134
|
// Show menu when context is requested
|
|
130
135
|
var showMenu = function(e) {
|
|
131
136
|
var sel = window.getSelection();
|
|
@@ -186,6 +191,239 @@ var $3c568ee547c732c3$export$ed4f9641643dc7e4 = function(param) {
|
|
|
186
191
|
|
|
187
192
|
|
|
188
193
|
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
var $16208d559c772441$export$aff5d0593e3727b0 = /*#__PURE__*/ (0, $gTuX4$react.createContext)(null);
|
|
205
|
+
var $16208d559c772441$var$pushToTop = function(windowId, minZIndex, windowList, setWindowList) {
|
|
206
|
+
var otherWindows = windowList.filter(function(w) {
|
|
207
|
+
return w.windowId !== windowId;
|
|
208
|
+
}).map(function(w, i) {
|
|
209
|
+
return {
|
|
210
|
+
windowId: w.windowId,
|
|
211
|
+
zIndex: minZIndex + i
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
setWindowList((0, $gTuX4$swchelperscjs_to_consumable_arraycjs._)(otherWindows).concat([
|
|
215
|
+
{
|
|
216
|
+
windowId: windowId,
|
|
217
|
+
zIndex: minZIndex + otherWindows.length
|
|
218
|
+
}
|
|
219
|
+
]));
|
|
220
|
+
};
|
|
221
|
+
var $16208d559c772441$export$9f37482ccd50dad2 = function(param) {
|
|
222
|
+
var _param_minZIndex = param.minZIndex, minZIndex = _param_minZIndex === void 0 ? 1000 : _param_minZIndex, children = param.children;
|
|
223
|
+
var _useState = (0, $gTuX4$swchelperscjs_sliced_to_arraycjs._)((0, $gTuX4$react.useState)([]), 2), currentWindows = _useState[0], setCurrentWindows = _useState[1];
|
|
224
|
+
return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)($16208d559c772441$export$aff5d0593e3727b0.Provider, {
|
|
225
|
+
value: {
|
|
226
|
+
currentWindows: currentWindows.map(function(w) {
|
|
227
|
+
return {
|
|
228
|
+
windowId: w.windowId,
|
|
229
|
+
zIndex: minZIndex + w.zIndex
|
|
230
|
+
};
|
|
231
|
+
}),
|
|
232
|
+
pushToTop: function(ret) {
|
|
233
|
+
return $16208d559c772441$var$pushToTop(ret, minZIndex, currentWindows, setCurrentWindows);
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
children: children
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
var $c986bcdcae4b83bd$export$d81cfea7c54be196 = function(divRef) {
|
|
242
|
+
if (!divRef.current) return {
|
|
243
|
+
translateX: 0,
|
|
244
|
+
translateY: 0
|
|
245
|
+
};
|
|
246
|
+
else {
|
|
247
|
+
var innerBounce = 16;
|
|
248
|
+
var posn = divRef.current.getBoundingClientRect();
|
|
249
|
+
var translateX = 0;
|
|
250
|
+
if (posn.left < innerBounce) translateX = -posn.left + innerBounce;
|
|
251
|
+
else if (posn.right > window.innerWidth) translateX = Math.max(-posn.left + innerBounce, window.innerWidth - posn.right - innerBounce);
|
|
252
|
+
var translateY = 0;
|
|
253
|
+
if (posn.top < innerBounce) translateY = -posn.top + innerBounce;
|
|
254
|
+
else if (posn.bottom > window.innerHeight) translateY = Math.max(-posn.top + innerBounce, window.innerHeight - posn.bottom - innerBounce);
|
|
255
|
+
return {
|
|
256
|
+
translateX: translateX,
|
|
257
|
+
translateY: translateY
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
var $46fb0088a1bbb6d8$export$1af8984c69ba1b24 = function(param) {
|
|
264
|
+
var id = param.id, visible = param.visible, title = param.title, style = param.style, children = param.children, onOpen = param.onOpen, onClose = param.onClose;
|
|
265
|
+
var windowStack = (0, $gTuX4$react.useContext)((0, $16208d559c772441$export$aff5d0593e3727b0));
|
|
266
|
+
var windowId = (0, $gTuX4$react.useRef)(null);
|
|
267
|
+
var divRef = (0, $gTuX4$react.useRef)(null);
|
|
268
|
+
var windowRef = (0, $gTuX4$react.useRef)(null);
|
|
269
|
+
var _useState = (0, $gTuX4$swchelperscjs_sliced_to_arraycjs._)((0, $gTuX4$react.useState)(false), 2), windowVisible = _useState[0], setWindowVisible = _useState[1];
|
|
270
|
+
var zIndex = (0, $gTuX4$react.useMemo)(function() {
|
|
271
|
+
var _windowStack_currentWindows_find;
|
|
272
|
+
var _windowStack_currentWindows_find_zIndex;
|
|
273
|
+
return (_windowStack_currentWindows_find_zIndex = (_windowStack_currentWindows_find = windowStack === null || windowStack === void 0 ? void 0 : windowStack.currentWindows.find(function(w) {
|
|
274
|
+
return w.windowId === windowId.current;
|
|
275
|
+
})) === null || _windowStack_currentWindows_find === void 0 ? void 0 : _windowStack_currentWindows_find.zIndex) !== null && _windowStack_currentWindows_find_zIndex !== void 0 ? _windowStack_currentWindows_find_zIndex : 1;
|
|
276
|
+
}, [
|
|
277
|
+
windowStack === null || windowStack === void 0 ? void 0 : windowStack.currentWindows
|
|
278
|
+
]);
|
|
279
|
+
// Position
|
|
280
|
+
var windowPos = (0, $gTuX4$react.useRef)({
|
|
281
|
+
x: 0,
|
|
282
|
+
y: 0
|
|
283
|
+
});
|
|
284
|
+
var _useState1 = (0, $gTuX4$swchelperscjs_sliced_to_arraycjs._)((0, $gTuX4$react.useState)(false), 2), moving = _useState1[0], setMoving = _useState1[1];
|
|
285
|
+
var move = (0, $gTuX4$react.useCallback)(function(x, y) {
|
|
286
|
+
if (windowRef.current && windowPos.current) {
|
|
287
|
+
var window1 = windowRef.current;
|
|
288
|
+
var pos = windowPos.current;
|
|
289
|
+
pos.x += x;
|
|
290
|
+
pos.y += y;
|
|
291
|
+
window1.style.transform = "translate(".concat(pos.x, "px, ").concat(pos.y, "px)");
|
|
292
|
+
}
|
|
293
|
+
}, []);
|
|
294
|
+
var checkPosition = (0, $gTuX4$react.useCallback)(function() {
|
|
295
|
+
var chkPos = (0, $c986bcdcae4b83bd$export$d81cfea7c54be196)(windowRef);
|
|
296
|
+
move(chkPos.translateX, chkPos.translateY);
|
|
297
|
+
}, [
|
|
298
|
+
move
|
|
299
|
+
]);
|
|
300
|
+
var mouseMove = (0, $gTuX4$react.useCallback)(function(e) {
|
|
301
|
+
e.preventDefault();
|
|
302
|
+
e.stopPropagation();
|
|
303
|
+
move(e.movementX, e.movementY);
|
|
304
|
+
}, [
|
|
305
|
+
move
|
|
306
|
+
]);
|
|
307
|
+
var mouseUp = (0, $gTuX4$react.useCallback)(function(e) {
|
|
308
|
+
e.preventDefault();
|
|
309
|
+
e.stopPropagation();
|
|
310
|
+
setMoving(false);
|
|
311
|
+
checkPosition();
|
|
312
|
+
document.removeEventListener("mousemove", mouseMove);
|
|
313
|
+
document.removeEventListener("mouseup", mouseUp);
|
|
314
|
+
window.removeEventListener("resize", checkPosition);
|
|
315
|
+
if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement)) e.target.style.userSelect = "auto";
|
|
316
|
+
}, [
|
|
317
|
+
checkPosition,
|
|
318
|
+
mouseMove
|
|
319
|
+
]);
|
|
320
|
+
// Update visibility
|
|
321
|
+
(0, $gTuX4$react.useEffect)(function() {
|
|
322
|
+
if (windowStack) {
|
|
323
|
+
if (visible && !windowVisible) {
|
|
324
|
+
if (!windowId.current) {
|
|
325
|
+
var _Math;
|
|
326
|
+
var maxWindowId = (_Math = Math).max.apply(_Math, [
|
|
327
|
+
0
|
|
328
|
+
].concat((0, $gTuX4$swchelperscjs_to_consumable_arraycjs._)(windowStack.currentWindows.map(function(w) {
|
|
329
|
+
return w.windowId;
|
|
330
|
+
}))));
|
|
331
|
+
windowId.current = maxWindowId + 1;
|
|
332
|
+
}
|
|
333
|
+
windowStack.pushToTop(windowId.current);
|
|
334
|
+
setWindowVisible(visible);
|
|
335
|
+
onOpen && onOpen();
|
|
336
|
+
// Get starting position
|
|
337
|
+
if (divRef.current && windowRef.current) {
|
|
338
|
+
var parentPos = divRef.current.getBoundingClientRect();
|
|
339
|
+
var pos = windowRef.current.getBoundingClientRect();
|
|
340
|
+
var windowHeight = pos.bottom - pos.top;
|
|
341
|
+
windowRef.current.style.left = "".concat(parentPos.left, "px");
|
|
342
|
+
windowRef.current.style.top = "".concat(parentPos.bottom + windowHeight < window.innerHeight ? parentPos.bottom : Math.max(0, parentPos.top - windowHeight), "px");
|
|
343
|
+
windowRef.current.style.transform = "";
|
|
344
|
+
windowPos.current = {
|
|
345
|
+
x: 0,
|
|
346
|
+
y: 0
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
} else if (windowId.current && !visible && windowVisible) setWindowVisible(false);
|
|
350
|
+
}
|
|
351
|
+
}, [
|
|
352
|
+
onOpen,
|
|
353
|
+
visible,
|
|
354
|
+
windowStack,
|
|
355
|
+
windowVisible
|
|
356
|
+
]);
|
|
357
|
+
var _style_minHeight, _style_minWidth, _style_maxHeight, _style_maxWidth;
|
|
358
|
+
return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
|
|
359
|
+
className: "contentwindow-anchor",
|
|
360
|
+
ref: divRef,
|
|
361
|
+
children: windowStack && /*#__PURE__*/ (0, $gTuX4$reactdom.createPortal)(/*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsxs)("div", {
|
|
362
|
+
id: id,
|
|
363
|
+
className: "contextwindow",
|
|
364
|
+
style: (0, $gTuX4$swchelperscjs_object_spread_propscjs._)((0, $gTuX4$swchelperscjs_object_spreadcjs._)({}, style), {
|
|
365
|
+
opacity: moving ? 0.8 : windowVisible ? 1 : 0,
|
|
366
|
+
visibility: windowVisible ? "visible" : "hidden",
|
|
367
|
+
zIndex: zIndex !== null && zIndex !== void 0 ? zIndex : 1,
|
|
368
|
+
minHeight: (_style_minHeight = style === null || style === void 0 ? void 0 : style.minHeight) !== null && _style_minHeight !== void 0 ? _style_minHeight : "150px",
|
|
369
|
+
minWidth: (_style_minWidth = style === null || style === void 0 ? void 0 : style.minWidth) !== null && _style_minWidth !== void 0 ? _style_minWidth : "200px",
|
|
370
|
+
maxHeight: (_style_maxHeight = style === null || style === void 0 ? void 0 : style.maxHeight) !== null && _style_maxHeight !== void 0 ? _style_maxHeight : "1000px",
|
|
371
|
+
maxWidth: (_style_maxWidth = style === null || style === void 0 ? void 0 : style.maxWidth) !== null && _style_maxWidth !== void 0 ? _style_maxWidth : "1000px"
|
|
372
|
+
}),
|
|
373
|
+
onClickCapture: function() {
|
|
374
|
+
windowId && windowId.current && windowStack.pushToTop(windowId.current);
|
|
375
|
+
},
|
|
376
|
+
ref: windowRef,
|
|
377
|
+
children: [
|
|
378
|
+
/*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsxs)("div", {
|
|
379
|
+
className: "contextwindow-title ".concat(moving ? "moving" : ""),
|
|
380
|
+
onMouseDown: function(e) {
|
|
381
|
+
if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement)) e.target.style.userSelect = "none";
|
|
382
|
+
setMoving(true);
|
|
383
|
+
windowId && windowId.current && windowStack.pushToTop(windowId.current);
|
|
384
|
+
document.addEventListener("mouseup", mouseUp);
|
|
385
|
+
document.addEventListener("mousemove", mouseMove);
|
|
386
|
+
window.addEventListener("resize", function() {
|
|
387
|
+
return checkPosition();
|
|
388
|
+
});
|
|
389
|
+
},
|
|
390
|
+
children: [
|
|
391
|
+
/*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("span", {
|
|
392
|
+
className: "contextwindow-title-text",
|
|
393
|
+
children: title
|
|
394
|
+
}),
|
|
395
|
+
/*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("span", {
|
|
396
|
+
className: "contextwindow-title-close",
|
|
397
|
+
children: /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("svg", {
|
|
398
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
399
|
+
width: "16",
|
|
400
|
+
height: "16",
|
|
401
|
+
fill: "currentColor",
|
|
402
|
+
viewBox: "0 0 16 16",
|
|
403
|
+
onClick: onClose,
|
|
404
|
+
"aria-label": "Close window",
|
|
405
|
+
children: /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("path", {
|
|
406
|
+
d: "M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"
|
|
407
|
+
})
|
|
408
|
+
})
|
|
409
|
+
})
|
|
410
|
+
]
|
|
411
|
+
}),
|
|
412
|
+
/*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
|
|
413
|
+
className: "contextwindow-body",
|
|
414
|
+
children: /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
|
|
415
|
+
children: children
|
|
416
|
+
})
|
|
417
|
+
})
|
|
418
|
+
]
|
|
419
|
+
}), document.body)
|
|
420
|
+
});
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|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AAQ,OAAO,IACd,CAAA,AAAC,EAAE,MAAM,YAAY,WAAW,EAAC,CAAA,mBAAA,QAAQ,OAAO,cAAf,8BAAA,KAAA,IAAA,iBAAiB,SAAS,EAAE,MAAM,MAClE,CAAE,CAAA,EAAE,MAAM,YAAY,OAAM,CAAC,GAE/B,eAAe,KAAK;IAExB,GAAG,EAAE;IAEL,oCAAoC;IACpC,CAAA,GAAA,sBAAS,AAAD,EAAE,WAAM;QACd,IAAI,aAAa,SAAS,gBAAgB,CAAC,aAAa;aACnD,SAAS,mBAAmB,CAAC,aAAa;QAC/C,OAAO,WAAM;YACX,SAAS,mBAAmB,CAAC,aAAa;QAC5C;IACF,GAAG;QAAC;QAAa;KAAY;IAE7B,qBACE;;0BACE,gCAAC;gBACC,eAAe;gBACf,WAAU;gBACV,OAAO;0BAEN;;YAEF,6BACC,CAAA,GAAA,4BAAY,AAAD,gBACT,gCAAC;gBACC,OAAO;oBAAE,UAAU;oBAAY,KAAK;oBAAG,MAAM;gBAAE;gBAC/C,KAAK;0BAEL,cAAA,gCAAC,CAAA,GAAA,yCAAW,AAAD;oBACT,SAAS,IAAI;oBACb,KAAK;oBACL,SAAS;oBACT,MAAM;oBACN,MAAM;oBACN,QAAQ;oBACR,SAAS;+BAAM,eAAe,KAAK;;;gBAGvC,SAAS,IAAI;;;AAIvB;;ADtFA;;ADAA","sources":["src/main.ts","src/components/index.ts","src/components/ContextMenuHandler.tsx","src/components/ContextMenu.tsx","src/components/SubMenu.tsx"],"sourcesContent":["export * from './components';\n","import { ContextMenuHandler } from './ContextMenuHandler';\nimport { iMenuItem } from './interface';\n\nexport { ContextMenuHandler };\nexport type { iMenuItem };\n","import { MouseEvent, useCallback, useEffect, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { ContextMenu } from './ContextMenu';\nimport { iMenuItem } from './interface';\nimport './ContextMenu.scss';\n\nexport const ContextMenuHandler = ({\n children,\n menuItems,\n style = {\n height: 'fit-content',\n width: 'fit-content',\n },\n}: {\n children: JSX.Element[] | JSX.Element;\n menuItems: iMenuItem[];\n style?: React.CSSProperties;\n}): JSX.Element => {\n // Menu resources\n const divRef = useRef<HTMLDivElement | null>(null);\n const menuRef = useRef<HTMLDivElement | null>(null);\n const [menuXPos, setMenuXPos] = useState<number>(0);\n const [menuYPos, setMenuYPos] = useState<number>(0);\n const [menuVisible, setMenuVisible] = useState<boolean>(false);\n const [target, setTarget] = useState<Range | null>(null);\n\n // Show menu when context is requested\n const showMenu = (e: MouseEvent<HTMLDivElement>) => {\n const sel = window.getSelection();\n setTarget(sel && sel.rangeCount > 0 ? sel.getRangeAt(0) : null);\n e.preventDefault();\n e.stopPropagation();\n setMenuVisible(true);\n setMenuXPos(e.pageX);\n setMenuYPos(e.pageY);\n };\n\n // Handle click off the menu\n const handleClick = useCallback((e: globalThis.MouseEvent) => {\n if (\n menuRef.current &&\n ((e.target instanceof Element && !menuRef.current?.contains(e.target)) ||\n !(e.target instanceof Element))\n ) {\n setMenuVisible(false);\n }\n }, []);\n\n // Update the document click handler\n useEffect(() => {\n if (menuVisible) document.addEventListener('mousedown', handleClick);\n else document.removeEventListener('mousedown', handleClick);\n return () => {\n document.removeEventListener('mousedown', handleClick);\n };\n }, [handleClick, menuVisible]);\n\n return (\n <>\n <div\n onContextMenu={showMenu}\n className='context-menu-handler'\n style={style}\n >\n {children}\n </div>\n {menuVisible &&\n createPortal(\n <div\n style={{ position: 'absolute', top: 0, left: 0 }}\n ref={divRef}\n >\n <ContextMenu\n visible={true}\n ref={menuRef}\n entries={menuItems}\n xPos={menuXPos}\n yPos={menuYPos}\n target={target}\n toClose={() => setMenuVisible(false)}\n />\n </div>,\n document.body,\n )}\n </>\n );\n};\n","import React from 'react';\nimport { iMenuItem } from './interface';\nimport { SubMenu } from './SubMenu';\n\nexport interface contextMenuProps {\n visible: boolean;\n entries: iMenuItem[];\n target: Range | null;\n xPos: number;\n yPos: number;\n toClose: () => void;\n}\n\nexport const ContextMenu = React.forwardRef<HTMLDivElement, contextMenuProps>(\n ({ visible, entries, target, xPos, yPos, toClose }, ref): JSX.Element => {\n ContextMenu.displayName = 'ContextMenu';\n\n return (\n <div\n ref={ref}\n className={`context-menu${visible ? ' visible' : ''}`}\n style={{\n top: `${yPos}px`,\n left: `${xPos}px`,\n }}\n >\n {entries.map((e, i) => (\n <div\n key={i}\n className={`context-menu-item${e.disabled ? ' disabled' : ''}`}\n onClick={(ev) => {\n ev.preventDefault();\n ev.stopPropagation();\n e.action && !e.disabled && e.action(target);\n !e.disabled && toClose();\n }}\n >\n <span className='context-menu-item-label'>{e.label}</span>\n {e.group && (\n <SubMenu\n toClose={toClose}\n entries={e.group}\n target={target}\n />\n )}\n </div>\n ))}\n </div>\n );\n },\n);\n","import { useState } from 'react';\nimport { ContextMenu } from './ContextMenu';\nimport { iMenuItem } from './interface';\n\nexport interface subMenuProps {\n entries: iMenuItem[];\n target: Range | null;\n toClose: () => void;\n}\n\nexport const SubMenu = ({ entries, target, toClose }: subMenuProps): JSX.Element => {\n const [visible, setVisible] = useState<boolean>(false);\n\n return (\n <span\n className='caret-holder'\n onMouseEnter={() => {\n setVisible(true);\n }}\n onMouseLeave={() => {\n setVisible(false);\n }}\n >\n <svg\n xmlns='http://www.w3.org/2000/svg'\n width='16'\n height='16'\n fill='currentColor'\n viewBox='0 0 16 16'\n >\n <path d='m12.14 8.753-5.482 4.796c-.646.566-1.658.106-1.658-.753V3.204a1 1 0 0 1 1.659-.753l5.48 4.796a1 1 0 0 1 0 1.506z' />\n </svg>\n <div className='sub-menu'>\n <ContextMenu\n visible={visible}\n entries={entries}\n target={target}\n xPos={14}\n yPos={-21}\n toClose={toClose}\n />\n </div>\n </span>\n );\n};\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AIUO,IAAM,4CAAU;QAAG,gBAAA,SAAS,eAAA,QAAQ,gBAAA;IACzC,IAA8B,2DAAA,C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UAAU;mCAAM;;oBAC1C;;sCAEA,gCAAC;4BAAK,WAAU;sCAA4B;;sCAC5C,gCAAC;4BAAK,WAAU;sCACd,cAAA,gCAAC;gCACC,OAAM;gCACN,OAAM;gCACN,QAAO;gCACP,MAAK;gCACL,SAAQ;gCACR,SAAS;gCACT,cAAW;0CAEX,cAAA,gCAAC;oCAAK,GAAE;;;;;;8BAId,gCAAC;oBAAI,WAAU;8BACb,cAAA,gCAAC;kCAAK;;;;YAGV,SAAS;;AAInB;;","sources":["src/main.ts","src/components/index.ts","src/components/ContextMenuHandler.tsx","src/components/ContextMenu.tsx","src/components/SubMenu.tsx","src/components/ContextWindow.tsx","src/components/ContextWindowStack.tsx","src/functions/chkPosition.ts"],"sourcesContent":["export * from './components';\n","import { ContextMenuHandler } from './ContextMenuHandler';\nimport { ContextWindow } from './ContextWindow';\nimport { ContextWindowStack } from './ContextWindowStack';\nimport { iMenuItem } from './interface';\n\nexport { ContextMenuHandler, ContextWindow, ContextWindowStack };\nexport type { iMenuItem };\n","import { MouseEvent, useCallback, useEffect, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { ContextMenu } from './ContextMenu';\nimport { iMenuItem } from './interface';\nimport './ContextMenu.css';\n\nexport const ContextMenuHandler = ({\n children,\n menuItems,\n style = {\n height: 'fit-content',\n width: 'fit-content',\n },\n}: {\n children: JSX.Element[] | JSX.Element;\n menuItems: iMenuItem[];\n style?: React.CSSProperties;\n}): JSX.Element => {\n // Menu resources\n const divRef = useRef<HTMLDivElement | null>(null);\n const menuRef = useRef<HTMLDivElement | null>(null);\n const [menuXPos, setMenuXPos] = useState<number>(0);\n const [menuYPos, setMenuYPos] = useState<number>(0);\n const [menuVisible, setMenuVisible] = useState<boolean>(false);\n const [target, setTarget] = useState<Range | null>(null);\n\n // Show menu when context is requested\n const showMenu = (e: MouseEvent<HTMLDivElement>) => {\n const sel = window.getSelection();\n setTarget(sel && sel.rangeCount > 0 ? sel.getRangeAt(0) : null);\n e.preventDefault();\n e.stopPropagation();\n setMenuVisible(true);\n setMenuXPos(e.pageX);\n setMenuYPos(e.pageY);\n };\n\n // Handle click off the menu\n const handleClick = useCallback((e: globalThis.MouseEvent) => {\n if (\n menuRef.current &&\n ((e.target instanceof Element && !menuRef.current?.contains(e.target)) ||\n !(e.target instanceof Element))\n ) {\n setMenuVisible(false);\n }\n }, []);\n\n // Update the document click handler\n useEffect(() => {\n if (menuVisible) document.addEventListener('mousedown', handleClick);\n else document.removeEventListener('mousedown', handleClick);\n return () => {\n document.removeEventListener('mousedown', handleClick);\n };\n }, [handleClick, menuVisible]);\n\n return (\n <>\n <div\n onContextMenu={showMenu}\n className='context-menu-handler'\n style={style}\n >\n {children}\n </div>\n {menuVisible &&\n createPortal(\n <div\n style={{ position: 'absolute', top: 0, left: 0 }}\n ref={divRef}\n >\n <ContextMenu\n visible={true}\n ref={menuRef}\n entries={menuItems}\n xPos={menuXPos}\n yPos={menuYPos}\n target={target}\n toClose={() => setMenuVisible(false)}\n />\n </div>,\n document.body,\n )}\n </>\n );\n};\n","import React from 'react';\nimport { iMenuItem } from './interface';\nimport { SubMenu } from './SubMenu';\n\nexport interface contextMenuProps {\n visible: boolean;\n entries: iMenuItem[];\n target: Range | null;\n xPos: number;\n yPos: number;\n toClose: () => void;\n}\n\nexport const ContextMenu = React.forwardRef<HTMLDivElement, contextMenuProps>(\n ({ visible, entries, target, xPos, yPos, toClose }, ref): JSX.Element => {\n ContextMenu.displayName = 'ContextMenu';\n\n return (\n <div\n ref={ref}\n className={`context-menu${visible ? ' visible' : ''}`}\n style={{\n top: `${yPos}px`,\n left: `${xPos}px`,\n }}\n >\n {entries.map((e, i) => (\n <div\n key={i}\n className={`context-menu-item${e.disabled ? ' disabled' : ''}`}\n onClick={(ev) => {\n ev.preventDefault();\n ev.stopPropagation();\n e.action && !e.disabled && e.action(target);\n !e.disabled && toClose();\n }}\n >\n <span className='context-menu-item-label'>{e.label}</span>\n {e.group && (\n <SubMenu\n toClose={toClose}\n entries={e.group}\n target={target}\n />\n )}\n </div>\n ))}\n </div>\n );\n },\n);\n","import { useState } from 'react';\nimport { ContextMenu } from './ContextMenu';\nimport { iMenuItem } from './interface';\n\nexport interface subMenuProps {\n entries: iMenuItem[];\n target: Range | null;\n toClose: () => void;\n}\n\nexport const SubMenu = ({ entries, target, toClose }: subMenuProps): JSX.Element => {\n const [visible, setVisible] = useState<boolean>(false);\n\n return (\n <span\n className='caret-holder'\n onMouseEnter={() => {\n setVisible(true);\n }}\n onMouseLeave={() => {\n setVisible(false);\n }}\n >\n <svg\n xmlns='http://www.w3.org/2000/svg'\n width='16'\n height='16'\n fill='currentColor'\n viewBox='0 0 16 16'\n >\n <path d='m12.14 8.753-5.482 4.796c-.646.566-1.658.106-1.658-.753V3.204a1 1 0 0 1 1.659-.753l5.48 4.796a1 1 0 0 1 0 1.506z' />\n </svg>\n <div className='sub-menu'>\n <ContextMenu\n visible={visible}\n entries={entries}\n target={target}\n xPos={14}\n yPos={-21}\n toClose={toClose}\n />\n </div>\n </span>\n );\n};\n","import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport './ContextWindow.css';\nimport { ContextWindowStackContext } from './ContextWindowStack';\nimport { chkPosition } from '../functions/chkPosition';\n\ninterface ContextWindowProps {\n id: string;\n visible: boolean;\n onOpen?: () => void;\n onClose?: () => void;\n title: string;\n style?: React.CSSProperties;\n children: JSX.Element[] | JSX.Element | string;\n}\n\nexport const ContextWindow = ({\n id,\n visible,\n title,\n style,\n children,\n onOpen,\n onClose,\n}: ContextWindowProps): JSX.Element => {\n const windowStack = useContext(ContextWindowStackContext);\n const windowId = useRef<number | null>(null);\n const divRef = useRef<HTMLDivElement | null>(null);\n const windowRef = useRef<HTMLDivElement | null>(null);\n const [windowVisible, setWindowVisible] = useState<boolean>(false);\n const zIndex = useMemo(() => {\n return windowStack?.currentWindows.find((w) => w.windowId === windowId.current)?.zIndex ?? 1;\n }, [windowStack?.currentWindows]);\n\n // Position\n const windowPos = useRef<{ x: number; y: number }>({ x: 0, y: 0 });\n const [moving, setMoving] = useState<boolean>(false);\n\n const move = useCallback((x: number, y: number) => {\n if (windowRef.current && windowPos.current) {\n const window = windowRef.current;\n const pos = windowPos.current;\n pos.x += x;\n pos.y += y;\n window.style.transform = `translate(${pos.x}px, ${pos.y}px)`;\n }\n }, []);\n\n const checkPosition = useCallback(() => {\n const chkPos = chkPosition(windowRef);\n move(chkPos.translateX, chkPos.translateY);\n }, [move]);\n\n const mouseMove = useCallback(\n (e: MouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n move(e.movementX, e.movementY);\n },\n [move],\n );\n\n const mouseUp = useCallback(\n (e: MouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n setMoving(false);\n checkPosition();\n document.removeEventListener('mousemove', mouseMove);\n document.removeEventListener('mouseup', mouseUp);\n window.removeEventListener('resize', checkPosition);\n if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement))\n e.target.style.userSelect = 'auto';\n },\n [checkPosition, mouseMove],\n );\n\n // Update visibility\n useEffect(() => {\n if (windowStack) {\n if (visible && !windowVisible) {\n if (!windowId.current) {\n const maxWindowId = Math.max(0, ...windowStack.currentWindows.map((w) => w.windowId));\n windowId.current = maxWindowId + 1;\n }\n windowStack.pushToTop(windowId.current);\n setWindowVisible(visible);\n onOpen && onOpen();\n // Get starting position\n if (divRef.current && windowRef.current) {\n const parentPos = divRef.current.getBoundingClientRect();\n const pos = windowRef.current.getBoundingClientRect();\n const windowHeight = pos.bottom - pos.top;\n windowRef.current.style.left = `${parentPos.left}px`;\n windowRef.current.style.top = `${\n parentPos.bottom + windowHeight < window.innerHeight\n ? parentPos.bottom\n : Math.max(0, parentPos.top - windowHeight)\n }px`;\n windowRef.current.style.transform = '';\n windowPos.current = { x: 0, y: 0 };\n }\n } else if (windowId.current && !visible && windowVisible) {\n setWindowVisible(false);\n }\n }\n }, [onOpen, visible, windowStack, windowVisible]);\n\n return (\n <div\n className='contentwindow-anchor'\n ref={divRef}\n >\n {windowStack &&\n createPortal(\n <div\n id={id}\n className='contextwindow'\n style={{\n ...style,\n opacity: moving ? 0.8 : windowVisible ? 1 : 0,\n visibility: windowVisible ? 'visible' : 'hidden',\n zIndex: zIndex ?? 1,\n minHeight: style?.minHeight ?? '150px',\n minWidth: style?.minWidth ?? '200px',\n maxHeight: style?.maxHeight ?? '1000px',\n maxWidth: style?.maxWidth ?? '1000px',\n }}\n onClickCapture={() => {\n windowId && windowId.current && windowStack.pushToTop(windowId.current);\n }}\n ref={windowRef}\n >\n <div\n className={`contextwindow-title ${moving ? 'moving' : ''}`}\n onMouseDown={(e: React.MouseEvent) => {\n if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement))\n e.target.style.userSelect = 'none';\n setMoving(true);\n windowId && windowId.current && windowStack.pushToTop(windowId.current);\n document.addEventListener('mouseup', mouseUp);\n document.addEventListener('mousemove', mouseMove);\n window.addEventListener('resize', () => checkPosition());\n }}\n >\n <span className='contextwindow-title-text'>{title}</span>\n <span className='contextwindow-title-close'>\n <svg\n xmlns='http://www.w3.org/2000/svg'\n width='16'\n height='16'\n fill='currentColor'\n viewBox='0 0 16 16'\n onClick={onClose}\n aria-label='Close window'\n >\n <path d='M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z' />\n </svg>\n </span>\n </div>\n <div className='contextwindow-body'>\n <div>{children}</div>\n </div>\n </div>,\n document.body,\n )}\n </div>\n );\n};\n","import { createContext, useState } from 'react';\n\nexport interface ContextWindowZIndex {\n windowId: number;\n zIndex: number;\n}\n\nexport interface ContextWindowStackContextProps {\n currentWindows: ContextWindowZIndex[];\n pushToTop: (ret: number) => void;\n}\n\nexport const ContextWindowStackContext = createContext<ContextWindowStackContextProps | null>(null);\n\ninterface ContextWindowStackProps {\n id?: string;\n minZIndex?: number;\n children?: JSX.Element[] | JSX.Element;\n}\n\nconst pushToTop = (\n windowId: number,\n minZIndex: number,\n windowList: ContextWindowZIndex[],\n setWindowList: (ret: ContextWindowZIndex[]) => void,\n) => {\n const otherWindows = windowList\n .filter((w) => w.windowId !== windowId)\n .map((w, i) => ({ windowId: w.windowId, zIndex: minZIndex + i }));\n setWindowList([...otherWindows, { windowId, zIndex: minZIndex + otherWindows.length }]);\n};\n\nexport const ContextWindowStack = ({\n minZIndex = 1000,\n children,\n}: ContextWindowStackProps): JSX.Element => {\n const [currentWindows, setCurrentWindows] = useState<ContextWindowZIndex[]>([]);\n\n return (\n <ContextWindowStackContext.Provider\n value={{\n currentWindows: currentWindows.map((w) => ({\n windowId: w.windowId,\n zIndex: minZIndex + w.zIndex,\n })),\n pushToTop: (ret: number) => pushToTop(ret, minZIndex, currentWindows, setCurrentWindows),\n }}\n >\n {children}\n </ContextWindowStackContext.Provider>\n );\n};\n","import { RefObject } from 'react';\n\n/**\n * Check that an existing div is inside the viewport\n * @param divRef Check div is inside view port, and return n\n * @returns \\{ translateX, translateY \\} Amount to move on X and Y axis\n */\nexport const chkPosition = (\n divRef: RefObject<HTMLDivElement>,\n): { translateX: number; translateY: number } => {\n if (!divRef.current) {\n return { translateX: 0, translateY: 0 };\n } else {\n const innerBounce = 16;\n const posn = divRef.current.getBoundingClientRect();\n let translateX = 0;\n if (posn.left < innerBounce) {\n translateX = -posn.left + innerBounce;\n } else if (posn.right > window.innerWidth) {\n translateX = Math.max(-posn.left + innerBounce, window.innerWidth - posn.right - innerBounce);\n }\n let translateY = 0;\n if (posn.top < innerBounce) {\n translateY = -posn.top + innerBounce;\n } else if (posn.bottom > window.innerHeight) {\n translateY = Math.max(\n -posn.top + innerBounce,\n window.innerHeight - posn.bottom - innerBounce,\n );\n }\n return { translateX, translateY };\n }\n};\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/context-menu.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from "react";
|
|
1
2
|
export interface iMenuItem {
|
|
2
3
|
label: string;
|
|
3
4
|
disabled?: boolean;
|
|
@@ -9,5 +10,21 @@ export const ContextMenuHandler: ({ children, menuItems, style, }: {
|
|
|
9
10
|
menuItems: iMenuItem[];
|
|
10
11
|
style?: import("react").CSSProperties | undefined;
|
|
11
12
|
}) => JSX.Element;
|
|
13
|
+
interface ContextWindowStackProps {
|
|
14
|
+
id?: string;
|
|
15
|
+
minZIndex?: number;
|
|
16
|
+
children?: JSX.Element[] | JSX.Element;
|
|
17
|
+
}
|
|
18
|
+
export const ContextWindowStack: ({ minZIndex, children, }: ContextWindowStackProps) => JSX.Element;
|
|
19
|
+
interface ContextWindowProps {
|
|
20
|
+
id: string;
|
|
21
|
+
visible: boolean;
|
|
22
|
+
onOpen?: () => void;
|
|
23
|
+
onClose?: () => void;
|
|
24
|
+
title: string;
|
|
25
|
+
style?: React.CSSProperties;
|
|
26
|
+
children: JSX.Element[] | JSX.Element | string;
|
|
27
|
+
}
|
|
28
|
+
export const ContextWindow: ({ id, visible, title, style, children, onOpen, onClose, }: ContextWindowProps) => JSX.Element;
|
|
12
29
|
|
|
13
30
|
//# sourceMappingURL=context-menu.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA;IACE,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,CAAC;IACzC,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;CACrB;AGCD,OAAO,MAAM;cAQD,WAAW,EAAE,GAAG,WAAW;eAC1B,SAAS,EAAE;;MAEpB,WAqEH,CAAC","sources":["src/src/components/interface.ts","src/src/components/SubMenu.tsx","src/src/components/ContextMenu.tsx","src/src/components/ContextMenuHandler.tsx","src/src/components/index.ts","src/src/main.ts","src/main.ts"],"sourcesContent":[null,null,null,null,null,null,"export * from './components';\n"],"names":[],"version":3,"file":"context-menu.d.ts.map"}
|
|
1
|
+
{"mappings":";AAAA;IACE,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,CAAC;IACzC,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;CACrB;AGCD,OAAO,MAAM;cAQD,WAAW,EAAE,GAAG,WAAW;eAC1B,SAAS,EAAE;;MAEpB,WAqEH,CAAC;ACxEF;IACE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,IAAI,OAAO,EAAE,GAAG,IAAI,OAAO,CAAC;CACxC;AAcD,OAAO,MAAM,+CAGV,uBAAuB,KAAG,WAgB5B,CAAC;AE7CF;IACE,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,aAAa,CAAC;IAC5B,QAAQ,EAAE,IAAI,OAAO,EAAE,GAAG,IAAI,OAAO,GAAG,MAAM,CAAC;CAChD;AAED,OAAO,MAAM,2EAQV,kBAAkB,KAAG,WAgJvB,CAAC","sources":["src/src/components/interface.ts","src/src/components/SubMenu.tsx","src/src/components/ContextMenu.tsx","src/src/components/ContextMenuHandler.tsx","src/src/components/ContextWindowStack.tsx","src/src/functions/chkPosition.ts","src/src/components/ContextWindow.tsx","src/src/components/index.ts","src/src/main.ts","src/main.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,"export * from './components';\n"],"names":[],"version":3,"file":"context-menu.d.ts.map"}
|
package/dist/main.css
CHANGED
|
@@ -65,4 +65,74 @@
|
|
|
65
65
|
flex-grow: 1;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
.contextwindow {
|
|
69
|
+
z-index: 2001;
|
|
70
|
+
resize: both;
|
|
71
|
+
background-color: #fafafa;
|
|
72
|
+
border: 1px solid #000;
|
|
73
|
+
border-top-left-radius: 8px;
|
|
74
|
+
border-top-right-radius: 8px;
|
|
75
|
+
border-bottom-left-radius: 8px;
|
|
76
|
+
justify-content: flex-start;
|
|
77
|
+
margin: 0;
|
|
78
|
+
padding: 4px;
|
|
79
|
+
transition: opacity .25s linear;
|
|
80
|
+
position: absolute;
|
|
81
|
+
overflow: auto;
|
|
82
|
+
box-shadow: 6px 6px 6px rgba(64, 64, 64, .5);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.contextwindow-title {
|
|
86
|
+
text-transform: capitalize;
|
|
87
|
+
height: 24px;
|
|
88
|
+
cursor: grab;
|
|
89
|
+
border-bottom: 1px dashed #000;
|
|
90
|
+
flex-grow: 1;
|
|
91
|
+
margin: 0 4px 3px;
|
|
92
|
+
padding-bottom: 4px;
|
|
93
|
+
font-size: 18px;
|
|
94
|
+
font-weight: 600;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.contextwindow-title.moving {
|
|
98
|
+
cursor: grabbing;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.contextwindow-title-text {
|
|
102
|
+
display: inline-block;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.contextwindow-title-close {
|
|
106
|
+
float: right;
|
|
107
|
+
cursor: auto;
|
|
108
|
+
font-size: small;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.contextwindow-body {
|
|
112
|
+
height: calc(100% - 40px);
|
|
113
|
+
margin-right: 4px;
|
|
114
|
+
padding-bottom: 8px;
|
|
115
|
+
overflow: auto;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.contextwindow-body::-webkit-scrollbar {
|
|
119
|
+
width: 8px;
|
|
120
|
+
height: 8px;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.contextwindow-body::-webkit-scrollbar-track {
|
|
124
|
+
background: #fff;
|
|
125
|
+
border-radius: 8px;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.contextwindow-body::-webkit-scrollbar-thumb {
|
|
129
|
+
background: #d3d3d3;
|
|
130
|
+
border: none;
|
|
131
|
+
border-radius: 8px;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.contextwindow-body::-webkit-scrollbar-thumb:hover {
|
|
135
|
+
background: gray;
|
|
136
|
+
}
|
|
137
|
+
|
|
68
138
|
/*# sourceMappingURL=main.css.map */
|
package/dist/main.css.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA;;;;;;;;;;AAWA;;;;AAIA;;;;;;;;;;;;;AAaA;;;;;AAKA;;;;AAIA;;;;AAIA;;;;AAIA;;;;;AAKA;;;;;AAKA;;;;AAIA;;;;;AAKA","sources":["src/components/ContextMenu.css"],"sourcesContent":[".context-menu {\n position: absolute;\n visibility: hidden;\n border: 1px solid;\n border-color: rgb(17, 20, 24);\n border-radius: 8px;\n opacity: 1;\n background-color: rgb(251, 253, 246);\n z-index: 10000;\n}\n\n.context-menu.visible {\n visibility: inherit;\n}\n\n.context-menu-item {\n color: rgb(17, 20, 24);\n cursor: pointer;\n padding: 0 4px;\n min-width: 80px;\n height: 21px;\n position: relative;\n display: flex;\n flex-direction: row;\n justify-content: space-between;\n white-space: nowrap;\n}\n\n.context-menu-item.disabled {\n background-color: rgba(0, 0, 0, 0.2);\n cursor: not-allowed;\n}\n\n.context-menu-item:first-child {\n padding-top: 4px;\n}\n\n.context-menu-item:last-child {\n padding-bottom: 4px;\n}\n\n.context-menu-item:not(.disabled):hover {\n background-color: rgb(251, 233, 230);\n}\n\n.context-menu-item:hover:first-child {\n border-top-left-radius: 6px;\n border-top-right-radius: 6px;\n}\n\n.context-menu-item:hover:last-child {\n border-bottom-left-radius: 6px;\n border-bottom-right-radius: 6px;\n}\n\n.context-menu-item .caret-holder {\n align-self: flex-end;\n}\n\n.context-menu-item .caret-holder .sub-menu {\n z-index: 1;\n position: relative;\n}\n\n.context-menu-item-label {\n flex-grow: 1;\n}\n"],"names":[],"version":3,"file":"main.css.map"}
|
|
1
|
+
{"mappings":"AAAA;;;;;;;;;;AAWA;;;;AAIA;;;;;;;;;;;;;AAaA;;;;;AAKA;;;;AAIA;;;;AAIA;;;;AAIA;;;;;AAKA;;;;;AAKA;;;;AAIA;;;;;AAKA;;;;AChEA;;;;;;;;;;;;;;;;;AAiBA;;;;;;;;;;;;AAYA;;;;AAIA;;;;AAIA;;;;;;AAMA;;;;;;;AAOA;;;;;AAKA;;;;;AAKA;;;;;;AAMA","sources":["src/components/ContextMenu.css","src/components/ContextWindow.css"],"sourcesContent":[".context-menu {\n position: absolute;\n visibility: hidden;\n border: 1px solid;\n border-color: rgb(17, 20, 24);\n border-radius: 8px;\n opacity: 1;\n background-color: rgb(251, 253, 246);\n z-index: 10000;\n}\n\n.context-menu.visible {\n visibility: inherit;\n}\n\n.context-menu-item {\n color: rgb(17, 20, 24);\n cursor: pointer;\n padding: 0 4px;\n min-width: 80px;\n height: 21px;\n position: relative;\n display: flex;\n flex-direction: row;\n justify-content: space-between;\n white-space: nowrap;\n}\n\n.context-menu-item.disabled {\n background-color: rgba(0, 0, 0, 0.2);\n cursor: not-allowed;\n}\n\n.context-menu-item:first-child {\n padding-top: 4px;\n}\n\n.context-menu-item:last-child {\n padding-bottom: 4px;\n}\n\n.context-menu-item:not(.disabled):hover {\n background-color: rgb(251, 233, 230);\n}\n\n.context-menu-item:hover:first-child {\n border-top-left-radius: 6px;\n border-top-right-radius: 6px;\n}\n\n.context-menu-item:hover:last-child {\n border-bottom-left-radius: 6px;\n border-bottom-right-radius: 6px;\n}\n\n.context-menu-item .caret-holder {\n align-self: flex-end;\n}\n\n.context-menu-item .caret-holder .sub-menu {\n z-index: 1;\n position: relative;\n}\n\n.context-menu-item-label {\n flex-grow: 1;\n}\n",".contextwindow {\n z-index: 2001;\n border: 1px black solid;\n margin: 0;\n padding: 4px;\n background-color: rgb(250, 250, 250);\n box-shadow: 6px 6px 6px rgb(64, 64, 64, 0.5);\n transition: opacity 0.25s linear;\n justify-content: flex-start;\n position: absolute;\n border-top-left-radius: 8px;\n border-top-right-radius: 8px;\n border-bottom-left-radius: 8px;\n resize: both;\n overflow: auto;\n}\n\n.contextwindow-title {\n text-transform: capitalize;\n border-bottom: 1px black dashed;\n padding-bottom: 4px;\n margin: 0 4px 3px 4px;\n font-size: 18px;\n font-weight: 600;\n flex-grow: 1;\n height: 24px;\n cursor: grab;\n}\n\n.contextwindow-title.moving {\n cursor: grabbing;\n}\n\n.contextwindow-title-text {\n display: inline-block;\n}\n\n.contextwindow-title-close {\n float: right;\n font-size: small;\n cursor: auto;\n}\n\n.contextwindow-body {\n overflow: auto;\n padding-bottom: 8px;\n margin-right: 4px;\n height: calc(100% - 40px);\n}\n\n.contextwindow-body::-webkit-scrollbar {\n width: 8px;\n height: 8px;\n}\n\n.contextwindow-body::-webkit-scrollbar-track {\n background: white;\n border-radius: 8px;\n}\n\n.contextwindow-body::-webkit-scrollbar-thumb {\n background: lightgrey;\n border: none;\n border-radius: 8px;\n}\n\n.contextwindow-body::-webkit-scrollbar-thumb:hover {\n background: grey;\n}\n"],"names":[],"version":3,"file":"main.css.map"}
|
package/dist/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./main.css";
|
|
2
2
|
import {jsxs as $duWW8$jsxs, Fragment as $duWW8$Fragment, jsx as $duWW8$jsx} from "react/jsx-runtime";
|
|
3
|
-
import $duWW8$react, {useRef as $duWW8$useRef, useState as $duWW8$useState, useCallback as $duWW8$useCallback, useEffect as $duWW8$useEffect} from "react";
|
|
3
|
+
import $duWW8$react, {useRef as $duWW8$useRef, useState as $duWW8$useState, useCallback as $duWW8$useCallback, useEffect as $duWW8$useEffect, useContext as $duWW8$useContext, useMemo as $duWW8$useMemo, createContext as $duWW8$createContext} from "react";
|
|
4
4
|
import {createPortal as $duWW8$createPortal} from "react-dom";
|
|
5
5
|
|
|
6
6
|
function $parcel$export(e, n, v, s) {
|
|
@@ -9,6 +9,8 @@ function $parcel$export(e, n, v, s) {
|
|
|
9
9
|
var $b65191f6d0a0a991$exports = {};
|
|
10
10
|
|
|
11
11
|
$parcel$export($b65191f6d0a0a991$exports, "ContextMenuHandler", function () { return $1e1c1e9e0b943830$export$ed4f9641643dc7e4; });
|
|
12
|
+
$parcel$export($b65191f6d0a0a991$exports, "ContextWindow", function () { return $b5e8657823def5be$export$1af8984c69ba1b24; });
|
|
13
|
+
$parcel$export($b65191f6d0a0a991$exports, "ContextWindowStack", function () { return $17c46b9e6a2eb66e$export$9f37482ccd50dad2; });
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
|
|
@@ -159,5 +161,215 @@ const $1e1c1e9e0b943830$export$ed4f9641643dc7e4 = ({ children: children , menuIt
|
|
|
159
161
|
|
|
160
162
|
|
|
161
163
|
|
|
162
|
-
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
const $17c46b9e6a2eb66e$export$aff5d0593e3727b0 = /*#__PURE__*/ (0, $duWW8$createContext)(null);
|
|
167
|
+
const $17c46b9e6a2eb66e$var$pushToTop = (windowId, minZIndex, windowList, setWindowList)=>{
|
|
168
|
+
const otherWindows = windowList.filter((w)=>w.windowId !== windowId).map((w, i)=>({
|
|
169
|
+
windowId: w.windowId,
|
|
170
|
+
zIndex: minZIndex + i
|
|
171
|
+
}));
|
|
172
|
+
setWindowList([
|
|
173
|
+
...otherWindows,
|
|
174
|
+
{
|
|
175
|
+
windowId: windowId,
|
|
176
|
+
zIndex: minZIndex + otherWindows.length
|
|
177
|
+
}
|
|
178
|
+
]);
|
|
179
|
+
};
|
|
180
|
+
const $17c46b9e6a2eb66e$export$9f37482ccd50dad2 = ({ minZIndex: minZIndex = 1000 , children: children })=>{
|
|
181
|
+
const [currentWindows, setCurrentWindows] = (0, $duWW8$useState)([]);
|
|
182
|
+
return /*#__PURE__*/ (0, $duWW8$jsx)($17c46b9e6a2eb66e$export$aff5d0593e3727b0.Provider, {
|
|
183
|
+
value: {
|
|
184
|
+
currentWindows: currentWindows.map((w)=>({
|
|
185
|
+
windowId: w.windowId,
|
|
186
|
+
zIndex: minZIndex + w.zIndex
|
|
187
|
+
})),
|
|
188
|
+
pushToTop: (ret)=>$17c46b9e6a2eb66e$var$pushToTop(ret, minZIndex, currentWindows, setCurrentWindows)
|
|
189
|
+
},
|
|
190
|
+
children: children
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
const $ab4d5d6bf03370d0$export$d81cfea7c54be196 = (divRef)=>{
|
|
196
|
+
if (!divRef.current) return {
|
|
197
|
+
translateX: 0,
|
|
198
|
+
translateY: 0
|
|
199
|
+
};
|
|
200
|
+
else {
|
|
201
|
+
const innerBounce = 16;
|
|
202
|
+
const posn = divRef.current.getBoundingClientRect();
|
|
203
|
+
let translateX = 0;
|
|
204
|
+
if (posn.left < innerBounce) translateX = -posn.left + innerBounce;
|
|
205
|
+
else if (posn.right > window.innerWidth) translateX = Math.max(-posn.left + innerBounce, window.innerWidth - posn.right - innerBounce);
|
|
206
|
+
let translateY = 0;
|
|
207
|
+
if (posn.top < innerBounce) translateY = -posn.top + innerBounce;
|
|
208
|
+
else if (posn.bottom > window.innerHeight) translateY = Math.max(-posn.top + innerBounce, window.innerHeight - posn.bottom - innerBounce);
|
|
209
|
+
return {
|
|
210
|
+
translateX: translateX,
|
|
211
|
+
translateY: translateY
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
const $b5e8657823def5be$export$1af8984c69ba1b24 = ({ id: id , visible: visible , title: title , style: style , children: children , onOpen: onOpen , onClose: onClose })=>{
|
|
218
|
+
const windowStack = (0, $duWW8$useContext)((0, $17c46b9e6a2eb66e$export$aff5d0593e3727b0));
|
|
219
|
+
const windowId = (0, $duWW8$useRef)(null);
|
|
220
|
+
const divRef = (0, $duWW8$useRef)(null);
|
|
221
|
+
const windowRef = (0, $duWW8$useRef)(null);
|
|
222
|
+
const [windowVisible, setWindowVisible] = (0, $duWW8$useState)(false);
|
|
223
|
+
const zIndex = (0, $duWW8$useMemo)(()=>{
|
|
224
|
+
var _windowStack_currentWindows_find;
|
|
225
|
+
var _windowStack_currentWindows_find_zIndex;
|
|
226
|
+
return (_windowStack_currentWindows_find_zIndex = (_windowStack_currentWindows_find = windowStack === null || windowStack === void 0 ? void 0 : windowStack.currentWindows.find((w)=>w.windowId === windowId.current)) === null || _windowStack_currentWindows_find === void 0 ? void 0 : _windowStack_currentWindows_find.zIndex) !== null && _windowStack_currentWindows_find_zIndex !== void 0 ? _windowStack_currentWindows_find_zIndex : 1;
|
|
227
|
+
}, [
|
|
228
|
+
windowStack === null || windowStack === void 0 ? void 0 : windowStack.currentWindows
|
|
229
|
+
]);
|
|
230
|
+
// Position
|
|
231
|
+
const windowPos = (0, $duWW8$useRef)({
|
|
232
|
+
x: 0,
|
|
233
|
+
y: 0
|
|
234
|
+
});
|
|
235
|
+
const [moving, setMoving] = (0, $duWW8$useState)(false);
|
|
236
|
+
const move = (0, $duWW8$useCallback)((x, y)=>{
|
|
237
|
+
if (windowRef.current && windowPos.current) {
|
|
238
|
+
const window1 = windowRef.current;
|
|
239
|
+
const pos = windowPos.current;
|
|
240
|
+
pos.x += x;
|
|
241
|
+
pos.y += y;
|
|
242
|
+
window1.style.transform = `translate(${pos.x}px, ${pos.y}px)`;
|
|
243
|
+
}
|
|
244
|
+
}, []);
|
|
245
|
+
const checkPosition = (0, $duWW8$useCallback)(()=>{
|
|
246
|
+
const chkPos = (0, $ab4d5d6bf03370d0$export$d81cfea7c54be196)(windowRef);
|
|
247
|
+
move(chkPos.translateX, chkPos.translateY);
|
|
248
|
+
}, [
|
|
249
|
+
move
|
|
250
|
+
]);
|
|
251
|
+
const mouseMove = (0, $duWW8$useCallback)((e)=>{
|
|
252
|
+
e.preventDefault();
|
|
253
|
+
e.stopPropagation();
|
|
254
|
+
move(e.movementX, e.movementY);
|
|
255
|
+
}, [
|
|
256
|
+
move
|
|
257
|
+
]);
|
|
258
|
+
const mouseUp = (0, $duWW8$useCallback)((e)=>{
|
|
259
|
+
e.preventDefault();
|
|
260
|
+
e.stopPropagation();
|
|
261
|
+
setMoving(false);
|
|
262
|
+
checkPosition();
|
|
263
|
+
document.removeEventListener("mousemove", mouseMove);
|
|
264
|
+
document.removeEventListener("mouseup", mouseUp);
|
|
265
|
+
window.removeEventListener("resize", checkPosition);
|
|
266
|
+
if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement)) e.target.style.userSelect = "auto";
|
|
267
|
+
}, [
|
|
268
|
+
checkPosition,
|
|
269
|
+
mouseMove
|
|
270
|
+
]);
|
|
271
|
+
// Update visibility
|
|
272
|
+
(0, $duWW8$useEffect)(()=>{
|
|
273
|
+
if (windowStack) {
|
|
274
|
+
if (visible && !windowVisible) {
|
|
275
|
+
if (!windowId.current) {
|
|
276
|
+
const maxWindowId = Math.max(0, ...windowStack.currentWindows.map((w)=>w.windowId));
|
|
277
|
+
windowId.current = maxWindowId + 1;
|
|
278
|
+
}
|
|
279
|
+
windowStack.pushToTop(windowId.current);
|
|
280
|
+
setWindowVisible(visible);
|
|
281
|
+
onOpen && onOpen();
|
|
282
|
+
// Get starting position
|
|
283
|
+
if (divRef.current && windowRef.current) {
|
|
284
|
+
const parentPos = divRef.current.getBoundingClientRect();
|
|
285
|
+
const pos = windowRef.current.getBoundingClientRect();
|
|
286
|
+
const windowHeight = pos.bottom - pos.top;
|
|
287
|
+
windowRef.current.style.left = `${parentPos.left}px`;
|
|
288
|
+
windowRef.current.style.top = `${parentPos.bottom + windowHeight < window.innerHeight ? parentPos.bottom : Math.max(0, parentPos.top - windowHeight)}px`;
|
|
289
|
+
windowRef.current.style.transform = "";
|
|
290
|
+
windowPos.current = {
|
|
291
|
+
x: 0,
|
|
292
|
+
y: 0
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
} else if (windowId.current && !visible && windowVisible) setWindowVisible(false);
|
|
296
|
+
}
|
|
297
|
+
}, [
|
|
298
|
+
onOpen,
|
|
299
|
+
visible,
|
|
300
|
+
windowStack,
|
|
301
|
+
windowVisible
|
|
302
|
+
]);
|
|
303
|
+
var _style_minHeight, _style_minWidth, _style_maxHeight, _style_maxWidth;
|
|
304
|
+
return /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
305
|
+
className: "contentwindow-anchor",
|
|
306
|
+
ref: divRef,
|
|
307
|
+
children: windowStack && /*#__PURE__*/ (0, $duWW8$createPortal)(/*#__PURE__*/ (0, $duWW8$jsxs)("div", {
|
|
308
|
+
id: id,
|
|
309
|
+
className: "contextwindow",
|
|
310
|
+
style: {
|
|
311
|
+
...style,
|
|
312
|
+
opacity: moving ? 0.8 : windowVisible ? 1 : 0,
|
|
313
|
+
visibility: windowVisible ? "visible" : "hidden",
|
|
314
|
+
zIndex: zIndex !== null && zIndex !== void 0 ? zIndex : 1,
|
|
315
|
+
minHeight: (_style_minHeight = style === null || style === void 0 ? void 0 : style.minHeight) !== null && _style_minHeight !== void 0 ? _style_minHeight : "150px",
|
|
316
|
+
minWidth: (_style_minWidth = style === null || style === void 0 ? void 0 : style.minWidth) !== null && _style_minWidth !== void 0 ? _style_minWidth : "200px",
|
|
317
|
+
maxHeight: (_style_maxHeight = style === null || style === void 0 ? void 0 : style.maxHeight) !== null && _style_maxHeight !== void 0 ? _style_maxHeight : "1000px",
|
|
318
|
+
maxWidth: (_style_maxWidth = style === null || style === void 0 ? void 0 : style.maxWidth) !== null && _style_maxWidth !== void 0 ? _style_maxWidth : "1000px"
|
|
319
|
+
},
|
|
320
|
+
onClickCapture: ()=>{
|
|
321
|
+
windowId && windowId.current && windowStack.pushToTop(windowId.current);
|
|
322
|
+
},
|
|
323
|
+
ref: windowRef,
|
|
324
|
+
children: [
|
|
325
|
+
/*#__PURE__*/ (0, $duWW8$jsxs)("div", {
|
|
326
|
+
className: `contextwindow-title ${moving ? "moving" : ""}`,
|
|
327
|
+
onMouseDown: (e)=>{
|
|
328
|
+
if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement)) e.target.style.userSelect = "none";
|
|
329
|
+
setMoving(true);
|
|
330
|
+
windowId && windowId.current && windowStack.pushToTop(windowId.current);
|
|
331
|
+
document.addEventListener("mouseup", mouseUp);
|
|
332
|
+
document.addEventListener("mousemove", mouseMove);
|
|
333
|
+
window.addEventListener("resize", ()=>checkPosition());
|
|
334
|
+
},
|
|
335
|
+
children: [
|
|
336
|
+
/*#__PURE__*/ (0, $duWW8$jsx)("span", {
|
|
337
|
+
className: "contextwindow-title-text",
|
|
338
|
+
children: title
|
|
339
|
+
}),
|
|
340
|
+
/*#__PURE__*/ (0, $duWW8$jsx)("span", {
|
|
341
|
+
className: "contextwindow-title-close",
|
|
342
|
+
children: /*#__PURE__*/ (0, $duWW8$jsx)("svg", {
|
|
343
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
344
|
+
width: "16",
|
|
345
|
+
height: "16",
|
|
346
|
+
fill: "currentColor",
|
|
347
|
+
viewBox: "0 0 16 16",
|
|
348
|
+
onClick: onClose,
|
|
349
|
+
"aria-label": "Close window",
|
|
350
|
+
children: /*#__PURE__*/ (0, $duWW8$jsx)("path", {
|
|
351
|
+
d: "M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"
|
|
352
|
+
})
|
|
353
|
+
})
|
|
354
|
+
})
|
|
355
|
+
]
|
|
356
|
+
}),
|
|
357
|
+
/*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
358
|
+
className: "contextwindow-body",
|
|
359
|
+
children: /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
360
|
+
children: children
|
|
361
|
+
})
|
|
362
|
+
})
|
|
363
|
+
]
|
|
364
|
+
}), document.body)
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
export {$1e1c1e9e0b943830$export$ed4f9641643dc7e4 as ContextMenuHandler, $b5e8657823def5be$export$1af8984c69ba1b24 as ContextWindow, $17c46b9e6a2eb66e$export$9f37482ccd50dad2 as ContextWindowStack};
|
|
163
375
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;AEAA;;;ACAA;;ACAA;;;AAUO,MAAM,4CAAU,CAAC,WAAE,QAAO,UAAE,OAAM,WAAE,QAAO,EAAgB,GAAkB;IAClF,MAAM,CAAC,SAAS,WAAW,GAAG,CAAA,GAAA,eAAO,EAAW,KAAK;IAErD,qBACE,iBAAC;QACC,WAAU;QACV,cAAc,IAAM;YAClB,WAAW,IAAI;QACjB;QACA,cAAc,IAAM;YAClB,WAAW,KAAK;QAClB;;0BAEA,gBAAC;gBACC,OAAM;gBACN,OAAM;gBACN,QAAO;gBACP,MAAK;gBACL,SAAQ;0BAER,cAAA,gBAAC;oBAAK,GAAE;;;0BAEV,gBAAC;gBAAI,WAAU;0BACb,cAAA,gBAAC,CAAA,GAAA,yCAAW,AAAD;oBACT,SAAS;oBACT,SAAS;oBACT,QAAQ;oBACR,MAAM;oBACN,MAAM;oBACN,SAAS;;;;;AAKnB;;;AD/BO,MAAM,0DAAc,CAAA,GAAA,YAAI,EAAE,UAAU,CACzC,CAAC,WAAE,QAAO,WAAE,QAAO,UAAE,OAAM,QAAE,KAAI,QAAE,KAAI,WAAE,QAAO,EAAE,EAAE,MAAqB;IACvE,0CAAY,WAAW,GAAG;IAE1B,qB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B,UAAU,OAAO,IAAI,UAAU,GAAG,IAAI,IAAI,UAAU,CAAC,KAAK,IAAI;QAC9D,EAAE,cAAc;QAChB,EAAE,eAAe;QACjB,eAAe,IAAI;QACnB,YAAY,EAAE,KAAK;QACnB,YAAY,EAAE,KAAK;IACrB;IAEA,4BAA4B;IAC5B,MAAM,cAAc,CAAA,GAAA,kBAAW,AAAD,EAAE,CAAC,IAA6B;YAGxB;QAFpC,IACE,QAAQ,OAAO,IACd,CAAA,AAAC,EAAE,MAAM,YAAY,WAAW,EAAC,CAAA,mBAAA,QAAQ,OAAO,cAAf,8BAAA,KAAA,IAAA,iBAAiB,SAAS,EAAE,MAAM,MAClE,CAAE,CAAA,EAAE,MAAM,YAAY,OAAM,CAAC,GAE/B,eAAe,KAAK;IAExB,GAAG,EAAE;IAEL,oCAAoC;IACpC,CAAA,GAAA,gBAAS,AAAD,EAAE,IAAM;QACd,IAAI,aAAa,SAAS,gBAAgB,CAAC,aAAa;aACnD,SAAS,mBAAmB,CAAC,aAAa;QAC/C,OAAO,IAAM;YACX,SAAS,mBAAmB,CAAC,aAAa;QAC5C;IACF,GAAG;QAAC;QAAa;KAAY;IAE7B,qBACE;;0BACE,gBAAC;gBACC,eAAe;gBACf,WAAU;gBACV,OAAO;0BAEN;;YAEF,6BACC,CAAA,GAAA,mBAAY,AAAD,gBACT,gBAAC;gBACC,OAAO;oBAAE,UAAU;oBAAY,KAAK;oBAAG,MAAM;gBAAE;gBAC/C,KAAK;0BAEL,cAAA,gBAAC,CAAA,GAAA,yCAAW,AAAD;oBACT,SAAS,IAAI;oBACb,KAAK;oBACL,SAAS;oBACT,MAAM;oBACN,MAAM;oBACN,QAAQ;oBACR,SAAS,IAAM,eAAe,KAAK;;gBAGvC,SAAS,IAAI;;;AAIvB;;ADtFA;;ADAA","sources":["src/main.ts","src/components/index.ts","src/components/ContextMenuHandler.tsx","src/components/ContextMenu.tsx","src/components/SubMenu.tsx"],"sourcesContent":["export * from './components';\n","import { ContextMenuHandler } from './ContextMenuHandler';\nimport { iMenuItem } from './interface';\n\nexport { ContextMenuHandler };\nexport type { iMenuItem };\n","import { MouseEvent, useCallback, useEffect, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { ContextMenu } from './ContextMenu';\nimport { iMenuItem } from './interface';\nimport './ContextMenu.scss';\n\nexport const ContextMenuHandler = ({\n children,\n menuItems,\n style = {\n height: 'fit-content',\n width: 'fit-content',\n },\n}: {\n children: JSX.Element[] | JSX.Element;\n menuItems: iMenuItem[];\n style?: React.CSSProperties;\n}): JSX.Element => {\n // Menu resources\n const divRef = useRef<HTMLDivElement | null>(null);\n const menuRef = useRef<HTMLDivElement | null>(null);\n const [menuXPos, setMenuXPos] = useState<number>(0);\n const [menuYPos, setMenuYPos] = useState<number>(0);\n const [menuVisible, setMenuVisible] = useState<boolean>(false);\n const [target, setTarget] = useState<Range | null>(null);\n\n // Show menu when context is requested\n const showMenu = (e: MouseEvent<HTMLDivElement>) => {\n const sel = window.getSelection();\n setTarget(sel && sel.rangeCount > 0 ? sel.getRangeAt(0) : null);\n e.preventDefault();\n e.stopPropagation();\n setMenuVisible(true);\n setMenuXPos(e.pageX);\n setMenuYPos(e.pageY);\n };\n\n // Handle click off the menu\n const handleClick = useCallback((e: globalThis.MouseEvent) => {\n if (\n menuRef.current &&\n ((e.target instanceof Element && !menuRef.current?.contains(e.target)) ||\n !(e.target instanceof Element))\n ) {\n setMenuVisible(false);\n }\n }, []);\n\n // Update the document click handler\n useEffect(() => {\n if (menuVisible) document.addEventListener('mousedown', handleClick);\n else document.removeEventListener('mousedown', handleClick);\n return () => {\n document.removeEventListener('mousedown', handleClick);\n };\n }, [handleClick, menuVisible]);\n\n return (\n <>\n <div\n onContextMenu={showMenu}\n className='context-menu-handler'\n style={style}\n >\n {children}\n </div>\n {menuVisible &&\n createPortal(\n <div\n style={{ position: 'absolute', top: 0, left: 0 }}\n ref={divRef}\n >\n <ContextMenu\n visible={true}\n ref={menuRef}\n entries={menuItems}\n xPos={menuXPos}\n yPos={menuYPos}\n target={target}\n toClose={() => setMenuVisible(false)}\n />\n </div>,\n document.body,\n )}\n </>\n );\n};\n","import React from 'react';\nimport { iMenuItem } from './interface';\nimport { SubMenu } from './SubMenu';\n\nexport interface contextMenuProps {\n visible: boolean;\n entries: iMenuItem[];\n target: Range | null;\n xPos: number;\n yPos: number;\n toClose: () => void;\n}\n\nexport const ContextMenu = React.forwardRef<HTMLDivElement, contextMenuProps>(\n ({ visible, entries, target, xPos, yPos, toClose }, ref): JSX.Element => {\n ContextMenu.displayName = 'ContextMenu';\n\n return (\n <div\n ref={ref}\n className={`context-menu${visible ? ' visible' : ''}`}\n style={{\n top: `${yPos}px`,\n left: `${xPos}px`,\n }}\n >\n {entries.map((e, i) => (\n <div\n key={i}\n className={`context-menu-item${e.disabled ? ' disabled' : ''}`}\n onClick={(ev) => {\n ev.preventDefault();\n ev.stopPropagation();\n e.action && !e.disabled && e.action(target);\n !e.disabled && toClose();\n }}\n >\n <span className='context-menu-item-label'>{e.label}</span>\n {e.group && (\n <SubMenu\n toClose={toClose}\n entries={e.group}\n target={target}\n />\n )}\n </div>\n ))}\n </div>\n );\n },\n);\n","import { useState } from 'react';\nimport { ContextMenu } from './ContextMenu';\nimport { iMenuItem } from './interface';\n\nexport interface subMenuProps {\n entries: iMenuItem[];\n target: Range | null;\n toClose: () => void;\n}\n\nexport const SubMenu = ({ entries, target, toClose }: subMenuProps): JSX.Element => {\n const [visible, setVisible] = useState<boolean>(false);\n\n return (\n <span\n className='caret-holder'\n onMouseEnter={() => {\n setVisible(true);\n }}\n onMouseLeave={() => {\n setVisible(false);\n }}\n >\n <svg\n xmlns='http://www.w3.org/2000/svg'\n width='16'\n height='16'\n fill='currentColor'\n viewBox='0 0 16 16'\n >\n <path d='m12.14 8.753-5.482 4.796c-.646.566-1.658.106-1.658-.753V3.204a1 1 0 0 1 1.659-.753l5.48 4.796a1 1 0 0 1 0 1.506z' />\n </svg>\n <div className='sub-menu'>\n <ContextMenu\n visible={visible}\n entries={entries}\n target={target}\n xPos={14}\n yPos={-21}\n toClose={toClose}\n />\n </div>\n </span>\n );\n};\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;AIUO,MAAM,4CAAU,CAAC,WAAE,QAAO,UAAE,OAAM,WAAE,QAAO,EAAgB;IAChE,MAAM,CAAC,SAAS,WAAW,GAAG,CAAA,GAAA,eAAO,EAAW;IAEhD,qBACE,iBAAC;QACC,WAAU;QACV,cAAc;YACZ,WAAW;QACb;QACA,cAAc;YACZ,WAAW;QACb;;0BAEA,gBAAC;gBACC,OAAM;gBACN,OAAM;gBACN,QAAO;gBACP,MAAK;gBACL,SAAQ;0BAER,cAAA,gBAAC;oBAAK,GAAE;;;0BAEV,gBAAC;gBAAI,WAAU;0BACb,cAAA,gBAAC,CAAA,GAAA,yCAAU;oBACT,SAAS;oBACT,SAAS;oBACT,QAAQ;oBACR,MAAM;oBACN,MAAM;oBACN,SAAS;;;;;AAKnB;;;AD/BO,MAAM,0DAAc,CAAA,GAAA,YAAI,EAAE,WAC/B,CAAC,WAAE,QAAO,WAAE,QAAO,UAAE,OAAM,QAAE,KAAI,QAAE,KAAI,WAAE,QAAO,EAAE,EAAE;IAClD,0CAAY,cAAc;IAE1B,qBACE,gBAAC;QACC,KAAK;QACL,WAAW,CAAC,YAAY,EAAE,UAAU,aAAa,GAAG,CAAC;QACrD,OAAO;YACL,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;YAChB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;QACnB;kBAEC,QAAQ,IAAI,CAAC,GAAG,kBACf,iBAAC;gBAEC,WAAW,CAAC,iBAAiB,EAAE,EAAE,WAAW,cAAc,GAAG,CAAC;gBAC9D,SAAS,CAAC;oBACR,GAAG;oBACH,GAAG;oBACH,EAAE,UAAU,CAAC,EAAE,YAAY,EAAE,OAAO;oBACpC,CAAC,EAAE,YAAY;gBACjB;;kCAE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,EAAE,OAAO,MAAM,aAAa;wBAC9B,UAAU;wBACV,YAAY,SAAS,WAAW,YAAY,UAAU,SAAS;wBAC/D,SAAS,iBAAiB,WAAW;wBACrC,SAAS,iBAAiB,aAAa;wBACvC,OAAO,iBAAiB,UAAU,IAAM;oBAC1C;;sCAEA,gBAAC;4BAAK,WAAU;sCAA4B;;sCAC5C,gBAAC;4BAAK,WAAU;sCACd,cAAA,gBAAC;gCACC,OAAM;gCACN,OAAM;gCACN,QAAO;gCACP,MAAK;gCACL,SAAQ;gCACR,SAAS;gCACT,cAAW;0CAEX,cAAA,gBAAC;oCAAK,GAAE;;;;;;8BAId,gBAAC;oBAAI,WAAU;8BACb,cAAA,gBAAC;kCAAK;;;;YAGV,SAAS;;AAInB;;","sources":["src/main.ts","src/components/index.ts","src/components/ContextMenuHandler.tsx","src/components/ContextMenu.tsx","src/components/SubMenu.tsx","src/components/ContextWindow.tsx","src/components/ContextWindowStack.tsx","src/functions/chkPosition.ts"],"sourcesContent":["export * from './components';\n","import { ContextMenuHandler } from './ContextMenuHandler';\nimport { ContextWindow } from './ContextWindow';\nimport { ContextWindowStack } from './ContextWindowStack';\nimport { iMenuItem } from './interface';\n\nexport { ContextMenuHandler, ContextWindow, ContextWindowStack };\nexport type { iMenuItem };\n","import { MouseEvent, useCallback, useEffect, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { ContextMenu } from './ContextMenu';\nimport { iMenuItem } from './interface';\nimport './ContextMenu.css';\n\nexport const ContextMenuHandler = ({\n children,\n menuItems,\n style = {\n height: 'fit-content',\n width: 'fit-content',\n },\n}: {\n children: JSX.Element[] | JSX.Element;\n menuItems: iMenuItem[];\n style?: React.CSSProperties;\n}): JSX.Element => {\n // Menu resources\n const divRef = useRef<HTMLDivElement | null>(null);\n const menuRef = useRef<HTMLDivElement | null>(null);\n const [menuXPos, setMenuXPos] = useState<number>(0);\n const [menuYPos, setMenuYPos] = useState<number>(0);\n const [menuVisible, setMenuVisible] = useState<boolean>(false);\n const [target, setTarget] = useState<Range | null>(null);\n\n // Show menu when context is requested\n const showMenu = (e: MouseEvent<HTMLDivElement>) => {\n const sel = window.getSelection();\n setTarget(sel && sel.rangeCount > 0 ? sel.getRangeAt(0) : null);\n e.preventDefault();\n e.stopPropagation();\n setMenuVisible(true);\n setMenuXPos(e.pageX);\n setMenuYPos(e.pageY);\n };\n\n // Handle click off the menu\n const handleClick = useCallback((e: globalThis.MouseEvent) => {\n if (\n menuRef.current &&\n ((e.target instanceof Element && !menuRef.current?.contains(e.target)) ||\n !(e.target instanceof Element))\n ) {\n setMenuVisible(false);\n }\n }, []);\n\n // Update the document click handler\n useEffect(() => {\n if (menuVisible) document.addEventListener('mousedown', handleClick);\n else document.removeEventListener('mousedown', handleClick);\n return () => {\n document.removeEventListener('mousedown', handleClick);\n };\n }, [handleClick, menuVisible]);\n\n return (\n <>\n <div\n onContextMenu={showMenu}\n className='context-menu-handler'\n style={style}\n >\n {children}\n </div>\n {menuVisible &&\n createPortal(\n <div\n style={{ position: 'absolute', top: 0, left: 0 }}\n ref={divRef}\n >\n <ContextMenu\n visible={true}\n ref={menuRef}\n entries={menuItems}\n xPos={menuXPos}\n yPos={menuYPos}\n target={target}\n toClose={() => setMenuVisible(false)}\n />\n </div>,\n document.body,\n )}\n </>\n );\n};\n","import React from 'react';\nimport { iMenuItem } from './interface';\nimport { SubMenu } from './SubMenu';\n\nexport interface contextMenuProps {\n visible: boolean;\n entries: iMenuItem[];\n target: Range | null;\n xPos: number;\n yPos: number;\n toClose: () => void;\n}\n\nexport const ContextMenu = React.forwardRef<HTMLDivElement, contextMenuProps>(\n ({ visible, entries, target, xPos, yPos, toClose }, ref): JSX.Element => {\n ContextMenu.displayName = 'ContextMenu';\n\n return (\n <div\n ref={ref}\n className={`context-menu${visible ? ' visible' : ''}`}\n style={{\n top: `${yPos}px`,\n left: `${xPos}px`,\n }}\n >\n {entries.map((e, i) => (\n <div\n key={i}\n className={`context-menu-item${e.disabled ? ' disabled' : ''}`}\n onClick={(ev) => {\n ev.preventDefault();\n ev.stopPropagation();\n e.action && !e.disabled && e.action(target);\n !e.disabled && toClose();\n }}\n >\n <span className='context-menu-item-label'>{e.label}</span>\n {e.group && (\n <SubMenu\n toClose={toClose}\n entries={e.group}\n target={target}\n />\n )}\n </div>\n ))}\n </div>\n );\n },\n);\n","import { useState } from 'react';\nimport { ContextMenu } from './ContextMenu';\nimport { iMenuItem } from './interface';\n\nexport interface subMenuProps {\n entries: iMenuItem[];\n target: Range | null;\n toClose: () => void;\n}\n\nexport const SubMenu = ({ entries, target, toClose }: subMenuProps): JSX.Element => {\n const [visible, setVisible] = useState<boolean>(false);\n\n return (\n <span\n className='caret-holder'\n onMouseEnter={() => {\n setVisible(true);\n }}\n onMouseLeave={() => {\n setVisible(false);\n }}\n >\n <svg\n xmlns='http://www.w3.org/2000/svg'\n width='16'\n height='16'\n fill='currentColor'\n viewBox='0 0 16 16'\n >\n <path d='m12.14 8.753-5.482 4.796c-.646.566-1.658.106-1.658-.753V3.204a1 1 0 0 1 1.659-.753l5.48 4.796a1 1 0 0 1 0 1.506z' />\n </svg>\n <div className='sub-menu'>\n <ContextMenu\n visible={visible}\n entries={entries}\n target={target}\n xPos={14}\n yPos={-21}\n toClose={toClose}\n />\n </div>\n </span>\n );\n};\n","import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport './ContextWindow.css';\nimport { ContextWindowStackContext } from './ContextWindowStack';\nimport { chkPosition } from '../functions/chkPosition';\n\ninterface ContextWindowProps {\n id: string;\n visible: boolean;\n onOpen?: () => void;\n onClose?: () => void;\n title: string;\n style?: React.CSSProperties;\n children: JSX.Element[] | JSX.Element | string;\n}\n\nexport const ContextWindow = ({\n id,\n visible,\n title,\n style,\n children,\n onOpen,\n onClose,\n}: ContextWindowProps): JSX.Element => {\n const windowStack = useContext(ContextWindowStackContext);\n const windowId = useRef<number | null>(null);\n const divRef = useRef<HTMLDivElement | null>(null);\n const windowRef = useRef<HTMLDivElement | null>(null);\n const [windowVisible, setWindowVisible] = useState<boolean>(false);\n const zIndex = useMemo(() => {\n return windowStack?.currentWindows.find((w) => w.windowId === windowId.current)?.zIndex ?? 1;\n }, [windowStack?.currentWindows]);\n\n // Position\n const windowPos = useRef<{ x: number; y: number }>({ x: 0, y: 0 });\n const [moving, setMoving] = useState<boolean>(false);\n\n const move = useCallback((x: number, y: number) => {\n if (windowRef.current && windowPos.current) {\n const window = windowRef.current;\n const pos = windowPos.current;\n pos.x += x;\n pos.y += y;\n window.style.transform = `translate(${pos.x}px, ${pos.y}px)`;\n }\n }, []);\n\n const checkPosition = useCallback(() => {\n const chkPos = chkPosition(windowRef);\n move(chkPos.translateX, chkPos.translateY);\n }, [move]);\n\n const mouseMove = useCallback(\n (e: MouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n move(e.movementX, e.movementY);\n },\n [move],\n );\n\n const mouseUp = useCallback(\n (e: MouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n setMoving(false);\n checkPosition();\n document.removeEventListener('mousemove', mouseMove);\n document.removeEventListener('mouseup', mouseUp);\n window.removeEventListener('resize', checkPosition);\n if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement))\n e.target.style.userSelect = 'auto';\n },\n [checkPosition, mouseMove],\n );\n\n // Update visibility\n useEffect(() => {\n if (windowStack) {\n if (visible && !windowVisible) {\n if (!windowId.current) {\n const maxWindowId = Math.max(0, ...windowStack.currentWindows.map((w) => w.windowId));\n windowId.current = maxWindowId + 1;\n }\n windowStack.pushToTop(windowId.current);\n setWindowVisible(visible);\n onOpen && onOpen();\n // Get starting position\n if (divRef.current && windowRef.current) {\n const parentPos = divRef.current.getBoundingClientRect();\n const pos = windowRef.current.getBoundingClientRect();\n const windowHeight = pos.bottom - pos.top;\n windowRef.current.style.left = `${parentPos.left}px`;\n windowRef.current.style.top = `${\n parentPos.bottom + windowHeight < window.innerHeight\n ? parentPos.bottom\n : Math.max(0, parentPos.top - windowHeight)\n }px`;\n windowRef.current.style.transform = '';\n windowPos.current = { x: 0, y: 0 };\n }\n } else if (windowId.current && !visible && windowVisible) {\n setWindowVisible(false);\n }\n }\n }, [onOpen, visible, windowStack, windowVisible]);\n\n return (\n <div\n className='contentwindow-anchor'\n ref={divRef}\n >\n {windowStack &&\n createPortal(\n <div\n id={id}\n className='contextwindow'\n style={{\n ...style,\n opacity: moving ? 0.8 : windowVisible ? 1 : 0,\n visibility: windowVisible ? 'visible' : 'hidden',\n zIndex: zIndex ?? 1,\n minHeight: style?.minHeight ?? '150px',\n minWidth: style?.minWidth ?? '200px',\n maxHeight: style?.maxHeight ?? '1000px',\n maxWidth: style?.maxWidth ?? '1000px',\n }}\n onClickCapture={() => {\n windowId && windowId.current && windowStack.pushToTop(windowId.current);\n }}\n ref={windowRef}\n >\n <div\n className={`contextwindow-title ${moving ? 'moving' : ''}`}\n onMouseDown={(e: React.MouseEvent) => {\n if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement))\n e.target.style.userSelect = 'none';\n setMoving(true);\n windowId && windowId.current && windowStack.pushToTop(windowId.current);\n document.addEventListener('mouseup', mouseUp);\n document.addEventListener('mousemove', mouseMove);\n window.addEventListener('resize', () => checkPosition());\n }}\n >\n <span className='contextwindow-title-text'>{title}</span>\n <span className='contextwindow-title-close'>\n <svg\n xmlns='http://www.w3.org/2000/svg'\n width='16'\n height='16'\n fill='currentColor'\n viewBox='0 0 16 16'\n onClick={onClose}\n aria-label='Close window'\n >\n <path d='M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z' />\n </svg>\n </span>\n </div>\n <div className='contextwindow-body'>\n <div>{children}</div>\n </div>\n </div>,\n document.body,\n )}\n </div>\n );\n};\n","import { createContext, useState } from 'react';\n\nexport interface ContextWindowZIndex {\n windowId: number;\n zIndex: number;\n}\n\nexport interface ContextWindowStackContextProps {\n currentWindows: ContextWindowZIndex[];\n pushToTop: (ret: number) => void;\n}\n\nexport const ContextWindowStackContext = createContext<ContextWindowStackContextProps | null>(null);\n\ninterface ContextWindowStackProps {\n id?: string;\n minZIndex?: number;\n children?: JSX.Element[] | JSX.Element;\n}\n\nconst pushToTop = (\n windowId: number,\n minZIndex: number,\n windowList: ContextWindowZIndex[],\n setWindowList: (ret: ContextWindowZIndex[]) => void,\n) => {\n const otherWindows = windowList\n .filter((w) => w.windowId !== windowId)\n .map((w, i) => ({ windowId: w.windowId, zIndex: minZIndex + i }));\n setWindowList([...otherWindows, { windowId, zIndex: minZIndex + otherWindows.length }]);\n};\n\nexport const ContextWindowStack = ({\n minZIndex = 1000,\n children,\n}: ContextWindowStackProps): JSX.Element => {\n const [currentWindows, setCurrentWindows] = useState<ContextWindowZIndex[]>([]);\n\n return (\n <ContextWindowStackContext.Provider\n value={{\n currentWindows: currentWindows.map((w) => ({\n windowId: w.windowId,\n zIndex: minZIndex + w.zIndex,\n })),\n pushToTop: (ret: number) => pushToTop(ret, minZIndex, currentWindows, setCurrentWindows),\n }}\n >\n {children}\n </ContextWindowStackContext.Provider>\n );\n};\n","import { RefObject } from 'react';\n\n/**\n * Check that an existing div is inside the viewport\n * @param divRef Check div is inside view port, and return n\n * @returns \\{ translateX, translateY \\} Amount to move on X and Y axis\n */\nexport const chkPosition = (\n divRef: RefObject<HTMLDivElement>,\n): { translateX: number; translateY: number } => {\n if (!divRef.current) {\n return { translateX: 0, translateY: 0 };\n } else {\n const innerBounce = 16;\n const posn = divRef.current.getBoundingClientRect();\n let translateX = 0;\n if (posn.left < innerBounce) {\n translateX = -posn.left + innerBounce;\n } else if (posn.right > window.innerWidth) {\n translateX = Math.max(-posn.left + innerBounce, window.innerWidth - posn.right - innerBounce);\n }\n let translateY = 0;\n if (posn.top < innerBounce) {\n translateY = -posn.top + innerBounce;\n } else if (posn.bottom > window.innerHeight) {\n translateY = Math.max(\n -posn.top + innerBounce,\n window.innerHeight - posn.bottom - innerBounce,\n );\n }\n return { translateX, translateY };\n }\n};\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asup/context-menu",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "REACT Typescript Context menu component",
|
|
5
5
|
"author": "Paul Thomas <@PaulDThomas>",
|
|
6
6
|
"private": false,
|
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
},
|
|
20
20
|
"homepage": "https://github.com/PaulDThomas/context-menu#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@swc/helpers": "^0.
|
|
22
|
+
"@swc/helpers": "^0.5.1",
|
|
23
23
|
"react": "^18.0.0",
|
|
24
24
|
"react-dom": "^18.0.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
+
"@swc/helpers": "^0.5.1",
|
|
27
28
|
"react": "^18.0.0",
|
|
28
29
|
"react-dom": "^18.0.0"
|
|
29
30
|
},
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
"@parcel/transformer-typescript-types": "^2.8.0",
|
|
35
36
|
"@parcel/transformer-webmanifest": "^2.7.0",
|
|
36
37
|
"@testing-library/jest-dom": "^5.16.5",
|
|
37
|
-
"@testing-library/react": "^
|
|
38
|
+
"@testing-library/react": "^14.0.0",
|
|
38
39
|
"@testing-library/user-event": "^14.4.3",
|
|
39
40
|
"@types/jest": "^29.2.2",
|
|
40
41
|
"@types/node": "^18.11.9",
|