@asup/context-menu 1.0.5 → 1.1.1

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 CHANGED
@@ -30,18 +30,64 @@ import { ContextMenuProvider, iMenuItem } from '@asup/context-menu';
30
30
 
31
31
  <ContextMenuHandler
32
32
  menuItems={[
33
- { label: 'Item 1', action: item1Function },
34
- { label: 'Item 2', action: item2Function, group: [
35
- { label: 'Subitem 2.1', action: item21Function }
36
- ...
37
- ]
33
+ {
34
+ label: 'Item 1',
35
+ action: () => {
36
+ console.log('Item 1 function run');
37
+ },
38
+ },
39
+ {
40
+ label: 'Item 2',
41
+ action: () => console.log('Item 2 function run'),
42
+ group: [
43
+ { label: 'Subitem 2.1', action: () => console.log('Item 2.1 function run') },
44
+ ],
45
+ },
46
+ {
47
+ label: 'Item 3',
48
+ action: () => console.log('Item 3 function run'),
49
+ disabled: true,
38
50
  },
39
- { label: 'Item 3', action: item3Function, disabeld: true },
40
- ...
41
51
  ]}
42
52
  >
43
53
  <Chilren
44
54
  where the context menu is applied...
45
55
  />
46
- </ContextMenuProvider>
56
+ </ContextMenuHandler>
57
+
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
+
47
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 */
@@ -1 +1 @@
1
- {"mappings":"AAAA;;;;;;;;;;AAWA;;;;AAIA;;;;;;;;;;;;;AAaA;;;;;AAKA;;;;AAIA;;;;AAIA;;;;AAIA;;;;;AAKA;;;;;AAKA;;;;AAIA;;;;;AAKA","sources":["src/components/ContextMenu.scss"],"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
@@ -3,6 +3,9 @@ var $gTuX4$swchelperslib_sliced_to_arrayjs = require("@swc/helpers/lib/_sliced_t
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$swchelperslib_object_spreadjs = require("@swc/helpers/lib/_object_spread.js");
7
+ var $gTuX4$swchelperslib_object_spread_propsjs = require("@swc/helpers/lib/_object_spread_props.js");
8
+ var $gTuX4$swchelperslib_to_consumable_arrayjs = require("@swc/helpers/lib/_to_consumable_array.js");
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
 
@@ -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, ($parcel$interopDefault($gTuX4$swchelperslib_to_consumable_arrayjs)))(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, ($parcel$interopDefault($gTuX4$swchelperslib_sliced_to_arrayjs)))((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, ($parcel$interopDefault($gTuX4$swchelperslib_sliced_to_arrayjs)))((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, ($parcel$interopDefault($gTuX4$swchelperslib_sliced_to_arrayjs)))((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, ($parcel$interopDefault($gTuX4$swchelperslib_to_consumable_arrayjs)))(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, ($parcel$interopDefault($gTuX4$swchelperslib_object_spread_propsjs)))((0, ($parcel$interopDefault($gTuX4$swchelperslib_object_spreadjs)))({}, 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
+
425
+
426
+
189
427
  $parcel$exportWildcard(module.exports, $a68bd8a6c0fd98c2$exports);
190
428
 
191
429
 
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEAA;;;;ACAA;;ACAA;;;;AAUO,IAAM,4CAAU,gBAA6D;QAA1D,gBAAA,SAAS,eAAA,QAAQ,gBAAA;IACzC,IAA8B,kFAAA,CAAA,GAAA,qBAAO,EAAW,KAAK,OAA9C,UAAuB,cAAd,aAAc;IAE9B,qBACE,iCAAC;QACC,WAAU;QACV,cAAc,WAAM;YAClB,WAAW,IAAI;QACjB;QACA,cAAc,WAAM;YAClB,WAAW,KAAK;QAClB;;0BAEA,gCAAC;gBACC,OAAM;gBACN,OAAM;gBACN,QAAO;gBACP,MAAK;gBACL,SAAQ;0BAER,cAAA,gCAAC;oBAAK,GAAE;;;0BAEV,gCAAC;gBAAI,WAAU;0BACb,cAAA,gCAAC,CAAA,GAAA,yCAAW,AAAD;oBACT,SAAS;oBACT,SAAS;oBACT,QAAQ;oBACR,MAAM;oBACN,MAAM;oBACN,SAAS;;;;;AAKnB;;;AD/BO,IAAM,0DAAc,CAAA,GAAA,sCAAI,EAAE,UAAU,CACzC,gBAAoD,KAAqB;QAAtE,gBAAA,SAAS,gBAAA,SAAS,eAAA,QAAQ,aAAA,MAAM,aAAA,MAAM,gBAAA;IACvC,0CAAY,WAAW,GAAG;IAE1B,qBACE,gCAAC;QACC,KAAK;QACL,WAAW,AAAC,eAAwC,OAA1B,UAAU,aAAa,EAAE;QACnD,OAAO;YACL,KAAK,AAAC,GAAO,OAAL,MAAK;YACb,MAAM,AAAC,GAAO,OAAL,MAAK;QAChB;kBAEC,QAAQ,GAAG,CAAC,SAAC,GAAG;iCACf,iCAAC;gBAEC,WAAW,AAAC,oBAAiD,OAA9B,EAAE,QAAQ,GAAG,cAAc,EAAE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ACE,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,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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEAA;;;;ACAA;;ACAA;;;;AAUO,IAAM,4CAAU,gBAA6D;QAA1D,gBAAA,SAAS,eAAA,QAAQ,gBAAA;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AS,OAAO;wBACtE,SAAS,gBAAgB,CAAC,WAAW;wBACrC,SAAS,gBAAgB,CAAC,aAAa;wBACvC,OAAO,gBAAgB,CAAC,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,IAAI;;AAIvB;;;;;ALxKA","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"}
@@ -1,13 +1,30 @@
1
- export interface iMenuItem {
2
- label: string;
3
- disabled?: boolean;
4
- action?: (target?: Range | null) => void;
5
- group?: iMenuItem[];
6
- }
7
- export const ContextMenuHandler: ({ children, menuItems, style, }: {
8
- children: JSX.Element[] | JSX.Element;
9
- menuItems: iMenuItem[];
10
- style?: import("react").CSSProperties | undefined;
11
- }) => JSX.Element;
1
+ import React from "react";
2
+ export interface iMenuItem {
3
+ label: string;
4
+ disabled?: boolean;
5
+ action?: (target?: Range | null) => void;
6
+ group?: iMenuItem[];
7
+ }
8
+ export const ContextMenuHandler: ({ children, menuItems, style, }: {
9
+ children: JSX.Element[] | JSX.Element;
10
+ menuItems: iMenuItem[];
11
+ style?: import("react").CSSProperties | undefined;
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.scss"],"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
- export {$1e1c1e9e0b943830$export$ed4f9641643dc7e4 as ContextMenuHandler};
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,gBA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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":";;;;;;;;;;;;;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,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B,OAAO;gBACpC,WAAW,CAAA,mBAAA,kBAAA,mBAAA,KAAA,IAAA,MAAO,SAAS,cAAhB,8BAAA,mBAAoB,QAAQ;gBACvC,UAAU,CAAA,kBAAA,kBAAA,mBAAA,KAAA,IAAA,MAAO,QAAQ,cAAf,6BAAA,kBAAmB,QAAQ;YACvC;YACA,gBAAgB,IAAM;gBACpB,YAAY,SAAS,OAAO,IAAI,YAAY,SAAS,CAAC,SAAS,OAAO;YACxE;YACA,KAAK;;8BAEL,iBAAC;oBACC,WAAW,CAAC,oBAAoB,EAAE,SAAS,WAAW,EAAE,CAAC,CAAC;oBAC1D,aAAa,CAAC,IAAwB;wBACpC,IAAI,EAAE,MAAM,IAAK,CAAA,EAAE,MAAM,YAAY,eAAe,EAAE,MAAM,YAAY,UAAS,GAC/E,EAAE,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG;wBAC9B,UAAU,IAAI;wBACd,YAAY,SAAS,OAAO,IAAI,YAAY,SAAS,CAAC,SAAS,OAAO;wBACtE,SAAS,gBAAgB,CAAC,WAAW;wBACrC,SAAS,gBAAgB,CAAC,aAAa;wBACvC,OAAO,gBAAgB,CAAC,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,IAAI;;AAIvB;;;;;ALxKA","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.0.5",
3
+ "version": "1.1.1",
4
4
  "description": "REACT Typescript Context menu component",
5
5
  "author": "Paul Thomas <@PaulDThomas>",
6
6
  "private": false,
@@ -57,7 +57,7 @@
57
57
  "process": "^0.11.10",
58
58
  "ts-jest": "^29.0.3",
59
59
  "ts-node": "^10.9.1",
60
- "typescript": "^4.9.3"
60
+ "typescript": "^5.0.4"
61
61
  },
62
62
  "lint-staged": {
63
63
  "**/*": "prettier --write --ignore-unknown"