@topconsultnpm/sdkui-react 6.19.0-dev3.6 → 6.19.0-dev3.8

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.
Files changed (39) hide show
  1. package/lib/components/features/documents/TMDcmtForm.js +10 -3
  2. package/lib/components/features/search/TMSearchResult.js +38 -14
  3. package/lib/components/features/search/TMSearchResultsMenuItems.d.ts +2 -2
  4. package/lib/components/features/search/TMSearchResultsMenuItems.js +31 -58
  5. package/lib/components/features/search/TMViewHistoryDcmtForm.d.ts +11 -0
  6. package/lib/components/features/search/TMViewHistoryDcmtForm.js +9 -0
  7. package/lib/helper/SDKUI_Localizator.d.ts +3 -0
  8. package/lib/helper/SDKUI_Localizator.js +42 -6
  9. package/lib/helper/cicoHelper.d.ts +28 -0
  10. package/lib/helper/cicoHelper.js +132 -0
  11. package/package.json +2 -2
  12. package/lib/components/NewComponents/ContextMenu/TMContextMenu.d.ts +0 -4
  13. package/lib/components/NewComponents/ContextMenu/TMContextMenu.js +0 -187
  14. package/lib/components/NewComponents/ContextMenu/hooks.d.ts +0 -11
  15. package/lib/components/NewComponents/ContextMenu/hooks.js +0 -48
  16. package/lib/components/NewComponents/ContextMenu/index.d.ts +0 -2
  17. package/lib/components/NewComponents/ContextMenu/index.js +0 -1
  18. package/lib/components/NewComponents/ContextMenu/styles.d.ts +0 -27
  19. package/lib/components/NewComponents/ContextMenu/styles.js +0 -308
  20. package/lib/components/NewComponents/ContextMenu/types.d.ts +0 -26
  21. package/lib/components/NewComponents/ContextMenu/types.js +0 -1
  22. package/lib/components/NewComponents/FloatingMenuBar/TMFloatingMenuBar.d.ts +0 -4
  23. package/lib/components/NewComponents/FloatingMenuBar/TMFloatingMenuBar.js +0 -370
  24. package/lib/components/NewComponents/FloatingMenuBar/index.d.ts +0 -2
  25. package/lib/components/NewComponents/FloatingMenuBar/index.js +0 -2
  26. package/lib/components/NewComponents/FloatingMenuBar/styles.d.ts +0 -38
  27. package/lib/components/NewComponents/FloatingMenuBar/styles.js +0 -267
  28. package/lib/components/NewComponents/FloatingMenuBar/types.d.ts +0 -30
  29. package/lib/components/NewComponents/FloatingMenuBar/types.js +0 -1
  30. package/lib/components/NewComponents/Notification/Notification.d.ts +0 -4
  31. package/lib/components/NewComponents/Notification/Notification.js +0 -60
  32. package/lib/components/NewComponents/Notification/NotificationContainer.d.ts +0 -8
  33. package/lib/components/NewComponents/Notification/NotificationContainer.js +0 -33
  34. package/lib/components/NewComponents/Notification/index.d.ts +0 -2
  35. package/lib/components/NewComponents/Notification/index.js +0 -2
  36. package/lib/components/NewComponents/Notification/styles.d.ts +0 -21
  37. package/lib/components/NewComponents/Notification/styles.js +0 -180
  38. package/lib/components/NewComponents/Notification/types.d.ts +0 -18
  39. package/lib/components/NewComponents/Notification/types.js +0 -1
@@ -0,0 +1,132 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { AccessLevels, CICO_MetadataNames, SDK_Globals } from "@topconsultnpm/sdk-ts";
3
+ import TMTooltip from "../components/base/TMTooltip";
4
+ import { Globalization, SDKUI_Localizator } from "./index";
5
+ import { DownloadTypes } from "../ts/types";
6
+ export const colors = {
7
+ MEDIUM_GREEN: "#28a745",
8
+ };
9
+ const getCicoInfo = (dtd) => {
10
+ const cico = {
11
+ CICO: 0,
12
+ CanCICO: AccessLevels.No,
13
+ CanDelChronology: AccessLevels.No,
14
+ UserID_MID: 0,
15
+ Date_MID: 0,
16
+ Ver_MID: 0,
17
+ UserID_CanViewOrUpdate: AccessLevels.No,
18
+ Date_CanViewOrUpdate: AccessLevels.No,
19
+ Ver_CanViewOrUpdate: AccessLevels.No,
20
+ };
21
+ if (dtd === undefined)
22
+ return cico;
23
+ cico.CICO = dtd.cico ?? 0;
24
+ cico.CanCICO = dtd.perm?.canCICO ?? AccessLevels.No;
25
+ cico.CanDelChronology = dtd.perm?.canDelChron ?? AccessLevels.No;
26
+ const mdCheckout = dtd.metadata?.find(md => md.name === CICO_MetadataNames.CICO_CheckoutUserID);
27
+ if (mdCheckout) {
28
+ cico.UserID_MID = mdCheckout.fromMID;
29
+ cico.UserID_CanViewOrUpdate = (mdCheckout.perm?.canView == AccessLevels.Yes || mdCheckout.perm?.canUpdate == AccessLevels.Yes) ? AccessLevels.Yes : AccessLevels.No;
30
+ }
31
+ const mdDate = dtd.metadata?.find(md => md.name === CICO_MetadataNames.CICO_CheckoutDate);
32
+ if (mdDate) {
33
+ cico.Date_MID = mdDate.fromMID;
34
+ cico.Date_CanViewOrUpdate = (mdDate.perm?.canView == AccessLevels.Yes || mdDate.perm?.canUpdate == AccessLevels.Yes) ? AccessLevels.Yes : AccessLevels.No;
35
+ }
36
+ const mdVer = dtd.metadata?.find(md => md.name === CICO_MetadataNames.CICO_Version);
37
+ if (mdVer) {
38
+ cico.Ver_MID = mdVer.fromMID;
39
+ cico.Ver_CanViewOrUpdate = (mdVer.perm?.canView == AccessLevels.Yes || mdVer.perm?.canUpdate == AccessLevels.Yes) ? AccessLevels.Yes : AccessLevels.No;
40
+ }
41
+ return cico;
42
+ };
43
+ const findCheckOutUserName = (allUsers, checkoutUserId) => {
44
+ let checkOutUser = allUsers.find(user => user.id === checkoutUserId);
45
+ return checkOutUser ? checkOutUser.name : '-';
46
+ };
47
+ export const cicoIsEnabled = (dcmt, allUsers, dtd) => {
48
+ if (dcmt === undefined || dtd === undefined) {
49
+ return {
50
+ cicoEnabled: false,
51
+ checkoutStatus: { isCheckedOut: false, mode: '', version: 1, icon: null }
52
+ };
53
+ }
54
+ const cicoInfo = getCicoInfo(dtd);
55
+ const CICO_CheckoutUserID_Meta = dtd?.metadata?.find(md => md.name === CICO_MetadataNames.CICO_CheckoutUserID);
56
+ const CICO_CheckoutDate_Meta = dtd?.metadata?.find(md => md.name === CICO_MetadataNames.CICO_CheckoutDate);
57
+ const CICO_Version_Meta = dtd?.metadata?.find(md => md.name === CICO_MetadataNames.CICO_Version);
58
+ const keyVersion = dcmt.TID + "_" + (CICO_Version_Meta?.id ?? 0);
59
+ const versionRaw = CICO_Version_Meta?.id ? dcmt[keyVersion] : undefined;
60
+ const version = (versionRaw != null && !isNaN(Number(versionRaw))) ? Number(versionRaw) : 1;
61
+ let checkoutStatus = { isCheckedOut: false, mode: '', version: version, icon: null, };
62
+ const userID = SDK_Globals.tmSession?.SessionDescr?.userID;
63
+ if (dcmt && CICO_CheckoutUserID_Meta?.id) {
64
+ const keyUserID = dcmt.TID + "_" + CICO_CheckoutUserID_Meta.id;
65
+ const checkoutUserIdValue = dcmt[keyUserID];
66
+ const checkoutUserId = Number(checkoutUserIdValue);
67
+ if (userID && checkoutUserIdValue && !isNaN(checkoutUserId) && checkoutUserId > 0) {
68
+ // editMode: l'utente corrente è quello che ha fatto il checkout
69
+ // lockMode: un altro utente ha fatto il checkout
70
+ const mode = (userID && userID === checkoutUserId) ? 'editMode' : 'lockMode';
71
+ // Recupera i dati aggiuntivi per il tooltip
72
+ const keyDate = dcmt.TID + "_" + (CICO_CheckoutDate_Meta?.id ?? 0);
73
+ const checkoutDate = CICO_CheckoutDate_Meta?.id ? dcmt[keyDate] : undefined;
74
+ const editLockTooltipText = _jsxs(_Fragment, { children: [_jsxs("div", { style: { textAlign: "center" }, children: [mode === 'editMode' && (_jsxs(_Fragment, { children: [_jsx("i", { style: { fontSize: "18px", color: colors.MEDIUM_GREEN, fontWeight: "bold" }, className: "dx-icon-edit" }), SDKUI_Localizator.CurrentUserExtract] })), mode === 'lockMode' && (_jsxs(_Fragment, { children: [_jsx("i", { style: { fontSize: "18px", color: colors.MEDIUM_GREEN, fontWeight: "bold" }, className: "dx-icon-lock" }), SDKUI_Localizator.ExtractedFromOtherUser] }))] }), _jsx("hr", {}), _jsxs("div", { style: { textAlign: "left" }, children: [_jsxs("ul", { children: [_jsxs("li", { children: ["- ", _jsx("span", { style: { fontWeight: 'bold' }, children: SDKUI_Localizator.ExtractedBy }), ": ", findCheckOutUserName(allUsers, checkoutUserId), " (ID: ", checkoutUserId, ")"] }), _jsxs("li", { children: ["- ", _jsx("span", { style: { fontWeight: 'bold' }, children: SDKUI_Localizator.ExtractedOn }), ": ", Globalization.getDateTimeDisplayValue(checkoutDate?.toString())] })] }), _jsx("hr", {}), _jsx("ul", { children: _jsxs("li", { children: ["- ", _jsx("span", { style: { fontWeight: 'bold' }, children: SDKUI_Localizator.Version }), ": ", version ?? 1] }) })] })] });
75
+ const icon = mode === 'editMode'
76
+ ? _jsx(TMTooltip, { content: editLockTooltipText, children: _jsx("i", { style: { fontSize: "18px", color: colors.MEDIUM_GREEN, fontWeight: "bold" }, className: "dx-icon-edit" }) })
77
+ : _jsx(TMTooltip, { content: editLockTooltipText, children: _jsx("i", { style: { fontSize: "18px", color: colors.MEDIUM_GREEN, fontWeight: "bold" }, className: "dx-icon-lock" }) });
78
+ checkoutStatus = { isCheckedOut: true, mode: mode, icon: icon, version: version };
79
+ }
80
+ }
81
+ return {
82
+ cicoEnabled: cicoInfo.CICO === 1 && cicoInfo.CanCICO === AccessLevels.Yes,
83
+ checkoutStatus: checkoutStatus
84
+ };
85
+ };
86
+ const getDownloadFileName = (originalFileName, fileItem, checkout, withTimestampAndExt) => {
87
+ // If no fileItem is provided, return an empty string immediately
88
+ if (fileItem === undefined)
89
+ return '';
90
+ // Retrieve the archiveID from the global session object
91
+ const archiveID = SDK_Globals.tmSession?.SessionDescr?.archiveID;
92
+ // Destructure the fileItem object into properties
93
+ const { DID, TID, FILEEXT } = fileItem;
94
+ // Determine the base name of the file (without its extension)
95
+ // If the file name contains '.', only take the substring before the last dot
96
+ const baseName = originalFileName.includes('.') ? originalFileName.substring(0, originalFileName.lastIndexOf('.')) : originalFileName;
97
+ // Construct a unique identifier for the file combining archiveID, baseName, tid, and did.
98
+ const fileIdentifier = `${archiveID}~${baseName}~${TID}~${DID}`;
99
+ // Determine the extension to append to the file name
100
+ const extension = withTimestampAndExt && FILEEXT ? `.${FILEEXT}` : '';
101
+ // Initialize an empty string for the timestamp (to be appended if needed)
102
+ let timestamp = '';
103
+ // If this is a checkout and timestamps should be added, generate a formatted timestamp
104
+ if (checkout && withTimestampAndExt) {
105
+ const now = new Date();
106
+ const pad = (n) => n.toString().padStart(2, '0');
107
+ // Format the timestamp as YYYYMMDDHHMMSS and prefix with '~'
108
+ timestamp = `~${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
109
+ }
110
+ // Construct and return the final file name: [archiveID]~[name]~[tid]~[did]~[timestamp].[extension]
111
+ return `${checkout ? 'checkout~' : ''}${fileIdentifier}${timestamp}${extension}`;
112
+ };
113
+ export const downloadFilesCallback = async (originalFileName, dcmt, checkout, downloadDcmtsAsync) => {
114
+ const files = [];
115
+ dcmt.forEach(file => {
116
+ if (file.TID && file.DID && file.FILEEXT) {
117
+ let fileName = getDownloadFileName(originalFileName, file, checkout, true);
118
+ /* if(checkout){
119
+ const newItem = {
120
+ TID: file.TID.toString(),
121
+ DID: file.DID.toString(),
122
+ checkoutFolder: "",
123
+ checkoutName: fileName
124
+ };
125
+ updateDraftCheckoutItem(newItem, "addOrUpdate");
126
+ } */
127
+ files.push({ TID: file.TID, DID: file.DID, FILEEXT: file.FILEEXT, fileName });
128
+ }
129
+ });
130
+ if (files.length > 0)
131
+ await downloadDcmtsAsync(files, DownloadTypes.Dcmt, "download");
132
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topconsultnpm/sdkui-react",
3
- "version": "6.19.0-dev3.6",
3
+ "version": "6.19.0-dev3.8",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -39,7 +39,7 @@
39
39
  "lib"
40
40
  ],
41
41
  "dependencies": {
42
- "@topconsultnpm/sdk-ts": "6.19.0-dev3.2",
42
+ "@topconsultnpm/sdk-ts": "6.19.0-dev3.3",
43
43
  "buffer": "^6.0.3",
44
44
  "devextreme": "25.1.7",
45
45
  "devextreme-react": "25.1.7",
@@ -1,4 +0,0 @@
1
- import React from 'react';
2
- import type { TMContextMenuProps } from './types';
3
- declare const TMContextMenu: React.FC<TMContextMenuProps>;
4
- export default TMContextMenu;
@@ -1,187 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useState, useRef, useEffect } from 'react';
3
- import * as S from './styles';
4
- import { useIsMobile, useMenuPosition } from './hooks';
5
- const TMContextMenu = ({ items, trigger = 'right', children }) => {
6
- const [menuState, setMenuState] = useState({
7
- visible: false,
8
- position: { x: 0, y: 0 },
9
- submenuStack: [items],
10
- parentNames: [],
11
- });
12
- const [hoveredSubmenus, setHoveredSubmenus] = useState([]);
13
- const isMobile = useIsMobile();
14
- const menuRef = useRef(null);
15
- const triggerRef = useRef(null);
16
- const submenuTimeoutRef = useRef(null);
17
- const { openLeft, openUp } = useMenuPosition(menuRef, menuState.position);
18
- const handleClose = () => {
19
- setMenuState(prev => ({
20
- ...prev,
21
- visible: false,
22
- submenuStack: [items],
23
- parentNames: [],
24
- }));
25
- setHoveredSubmenus([]);
26
- };
27
- useEffect(() => {
28
- if (!menuState.visible)
29
- return;
30
- const handleClickOutside = (event) => {
31
- const target = event.target;
32
- // Check if click is inside main menu
33
- if (menuRef.current?.contains(target)) {
34
- return;
35
- }
36
- // Check if click is inside any submenu
37
- const submenus = document.querySelectorAll('[data-submenu="true"]');
38
- for (const submenu of Array.from(submenus)) {
39
- if (submenu.contains(target)) {
40
- return;
41
- }
42
- }
43
- // Click is outside all menus, close them
44
- handleClose();
45
- };
46
- document.addEventListener('mousedown', handleClickOutside);
47
- document.addEventListener('touchstart', handleClickOutside);
48
- return () => {
49
- document.removeEventListener('mousedown', handleClickOutside);
50
- document.removeEventListener('touchstart', handleClickOutside);
51
- };
52
- }, [menuState.visible]);
53
- const handleContextMenu = (e) => {
54
- if (trigger === 'right') {
55
- e.preventDefault();
56
- setMenuState({
57
- visible: true,
58
- position: { x: e.clientX, y: e.clientY },
59
- submenuStack: [items],
60
- parentNames: [],
61
- });
62
- }
63
- };
64
- const handleClick = (e) => {
65
- if (trigger === 'left') {
66
- e.preventDefault();
67
- setMenuState({
68
- visible: true,
69
- position: { x: e.clientX, y: e.clientY },
70
- submenuStack: [items],
71
- parentNames: [],
72
- });
73
- }
74
- };
75
- const handleItemClick = (item) => {
76
- if (item.disabled)
77
- return;
78
- // Always execute onClick if present
79
- if (item.onClick) {
80
- item.onClick();
81
- }
82
- if (item.submenu && item.submenu.length > 0) {
83
- if (isMobile) {
84
- // Mobile: Push submenu to stack
85
- setMenuState(prev => ({
86
- ...prev,
87
- submenuStack: [...prev.submenuStack, item.submenu],
88
- parentNames: [...prev.parentNames, item.name],
89
- }));
90
- }
91
- // Desktop: Submenus are handled by hover, don't close menu
92
- }
93
- else {
94
- // No submenu: close menu after executing action
95
- handleClose();
96
- }
97
- };
98
- const handleBack = () => {
99
- setMenuState(prev => ({
100
- ...prev,
101
- submenuStack: prev.submenuStack.slice(0, -1),
102
- parentNames: prev.parentNames.slice(0, -1),
103
- }));
104
- };
105
- const handleMouseEnter = (item, event, depth = 0) => {
106
- if (isMobile || !item.submenu || item.submenu.length === 0)
107
- return;
108
- if (submenuTimeoutRef.current) {
109
- clearTimeout(submenuTimeoutRef.current);
110
- submenuTimeoutRef.current = null;
111
- }
112
- const rect = event.currentTarget.getBoundingClientRect();
113
- // Calculate if submenu should open upward based on available space
114
- // Estimate submenu height: ~35px per item (accounting for smaller padding) + container padding
115
- const estimatedSubmenuHeight = (item.submenu.length * 35) + 8;
116
- const spaceBelow = window.innerHeight - rect.top;
117
- const spaceAbove = rect.bottom;
118
- // Open upward only if there's not enough space below AND there's more space above
119
- const shouldOpenUp = spaceBelow < estimatedSubmenuHeight && spaceAbove > spaceBelow;
120
- // Remove all submenus at this depth and deeper
121
- setHoveredSubmenus(prev => {
122
- const filtered = prev.filter(sub => sub.depth < depth);
123
- if (!item.submenu)
124
- return filtered;
125
- return [
126
- ...filtered,
127
- {
128
- items: item.submenu,
129
- parentRect: rect,
130
- depth: depth,
131
- openUp: shouldOpenUp,
132
- }
133
- ];
134
- });
135
- };
136
- const handleMouseLeave = (depth = 0) => {
137
- if (isMobile)
138
- return;
139
- if (submenuTimeoutRef.current) {
140
- clearTimeout(submenuTimeoutRef.current);
141
- }
142
- const targetDepth = depth;
143
- submenuTimeoutRef.current = setTimeout(() => {
144
- setHoveredSubmenus(prev => prev.filter(sub => sub.depth < targetDepth));
145
- }, 300);
146
- };
147
- const handleSubmenuMouseEnter = () => {
148
- if (submenuTimeoutRef.current) {
149
- clearTimeout(submenuTimeoutRef.current);
150
- submenuTimeoutRef.current = null;
151
- }
152
- };
153
- useEffect(() => {
154
- return () => {
155
- if (submenuTimeoutRef.current) {
156
- clearTimeout(submenuTimeoutRef.current);
157
- }
158
- };
159
- }, []);
160
- const renderMenuItems = (menuItems, depth = 0) => {
161
- return menuItems
162
- .filter(item => item.visible !== false)
163
- .map((item, idx) => {
164
- const itemKey = `${item.name}-${idx}`.replaceAll(/\s+/g, '-');
165
- const handleClick = (e) => {
166
- if (item.disabled)
167
- return;
168
- e.stopPropagation();
169
- handleItemClick(item);
170
- };
171
- const handleRightIconClick = (e) => {
172
- e.stopPropagation();
173
- // if (item.disabled) return;
174
- item.onRightIconClick?.();
175
- };
176
- return (_jsxs(S.MenuItem, { "$disabled": item.disabled, "$hasSubmenu": !!item.submenu && item.submenu.length > 0, "$beginGroup": item.beginGroup, onMouseDown: handleClick, onMouseEnter: (e) => !isMobile && handleMouseEnter(item, e, depth + 1), onMouseLeave: () => !isMobile && handleMouseLeave(depth + 1), children: [_jsxs(S.MenuItemContent, { children: [item.icon && _jsx(S.IconWrapper, { children: item.icon }), _jsx(S.MenuItemName, { children: item.name })] }), item.rightIcon && item.onRightIconClick && (_jsx(S.RightIconButton, { onClick: handleRightIconClick, onMouseDown: (e) => e.stopPropagation(), "aria-label": `Action for ${item.name}`, children: item.rightIcon })), item.submenu && item.submenu.length > 0 && (_jsx(S.SubmenuIndicator, { "$isMobile": isMobile, children: isMobile ? '›' : '▸' }))] }, itemKey));
177
- });
178
- };
179
- const currentMenu = menuState.submenuStack.at(-1) || items;
180
- const currentParentName = menuState.parentNames.at(-1) || '';
181
- return (_jsxs(_Fragment, { children: [_jsx("div", { ref: triggerRef, onContextMenu: handleContextMenu, onClick: handleClick, onKeyDown: (e) => {
182
- if (e.key === 'Enter' || e.key === ' ') {
183
- handleClick(e);
184
- }
185
- }, role: "button", tabIndex: 0, style: { display: 'inline-block' }, children: children }), menuState.visible && (_jsxs(_Fragment, { children: [_jsx(S.Overlay, { onClick: handleClose }), _jsxs(S.MenuContainer, { ref: menuRef, "$x": menuState.position.x, "$y": menuState.position.y, "$openLeft": openLeft, "$openUp": openUp, children: [isMobile && menuState.parentNames.length > 0 && (_jsxs(S.MobileMenuHeader, { children: [_jsx(S.BackButton, { onClick: handleBack, "aria-label": "Go back", children: "\u2190" }), _jsx(S.HeaderTitle, { children: currentParentName })] })), renderMenuItems(currentMenu, 0)] }), !isMobile && hoveredSubmenus.map((submenu, idx) => (_jsx(S.Submenu, { "$parentRect": submenu.parentRect, "$openUp": submenu.openUp, "data-submenu": "true", onMouseEnter: handleSubmenuMouseEnter, onMouseLeave: () => handleMouseLeave(submenu.depth), children: renderMenuItems(submenu.items, submenu.depth) }, `submenu-${submenu.depth}-${idx}`)))] }))] }));
186
- };
187
- export default TMContextMenu;
@@ -1,11 +0,0 @@
1
- export declare const useIsMobile: () => boolean;
2
- export declare const useClickOutside: (callback: () => void) => import("react").RefObject<HTMLDivElement>;
3
- interface Position {
4
- x: number;
5
- y: number;
6
- }
7
- export declare const useMenuPosition: (menuRef: React.RefObject<HTMLDivElement | null>, position: Position) => {
8
- openLeft: boolean;
9
- openUp: boolean;
10
- };
11
- export {};
@@ -1,48 +0,0 @@
1
- import { useState, useEffect, useRef } from 'react';
2
- export const useIsMobile = () => {
3
- const [isMobile, setIsMobile] = useState(false);
4
- useEffect(() => {
5
- const checkMobile = () => {
6
- const mobile = globalThis.innerWidth <= 768 || 'ontouchstart' in globalThis;
7
- setIsMobile(mobile);
8
- };
9
- checkMobile();
10
- window.addEventListener('resize', checkMobile);
11
- return () => window.removeEventListener('resize', checkMobile);
12
- }, []);
13
- return isMobile;
14
- };
15
- export const useClickOutside = (callback) => {
16
- const ref = useRef(null);
17
- useEffect(() => {
18
- const handleClick = (event) => {
19
- if (ref.current && !ref.current.contains(event.target)) {
20
- callback();
21
- }
22
- };
23
- document.addEventListener('mousedown', handleClick);
24
- document.addEventListener('touchstart', handleClick);
25
- return () => {
26
- document.removeEventListener('mousedown', handleClick);
27
- document.removeEventListener('touchstart', handleClick);
28
- };
29
- }, [callback]);
30
- return ref;
31
- };
32
- export const useMenuPosition = (menuRef, position) => {
33
- const [adjustedPosition, setAdjustedPosition] = useState({ openLeft: false, openUp: false });
34
- useEffect(() => {
35
- if (!menuRef.current)
36
- return;
37
- const menuRect = menuRef.current.getBoundingClientRect();
38
- const viewportWidth = window.innerWidth;
39
- const viewportHeight = window.innerHeight;
40
- const spaceRight = viewportWidth - position.x;
41
- const spaceBottom = viewportHeight - position.y;
42
- setAdjustedPosition({
43
- openLeft: spaceRight < menuRect.width + 20,
44
- openUp: spaceBottom < menuRect.height + 20,
45
- });
46
- }, [position, menuRef]);
47
- return adjustedPosition;
48
- };
@@ -1,2 +0,0 @@
1
- export { default as ContextMenu } from './TMContextMenu';
2
- export type { TMContextMenuItemProps, TMContextMenuProps } from './types';
@@ -1 +0,0 @@
1
- export { default as ContextMenu } from './TMContextMenu';
@@ -1,27 +0,0 @@
1
- export declare const MenuContainer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
2
- $x: number;
3
- $y: number;
4
- $openLeft: boolean;
5
- $openUp: boolean;
6
- }>> & string;
7
- export declare const MenuItem: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
8
- $disabled?: boolean;
9
- $hasSubmenu?: boolean;
10
- $beginGroup?: boolean;
11
- }>> & string;
12
- export declare const MenuItemContent: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
13
- export declare const IconWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>> & string;
14
- export declare const MenuItemName: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>> & string;
15
- export declare const RightIconButton: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, never>> & string;
16
- export declare const SubmenuIndicator: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, {
17
- $isMobile?: boolean;
18
- }>> & string;
19
- export declare const Submenu: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
20
- $parentRect: DOMRect;
21
- $openUp?: boolean;
22
- }>> & string;
23
- export declare const MobileMenuHeader: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
24
- export declare const BackButton: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, never>> & string;
25
- export declare const HeaderTitle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, never>> & string;
26
- export declare const MenuDivider: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
27
- export declare const Overlay: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;