@topconsultnpm/sdkui-react 6.20.0-dev1.92 → 6.20.0-dev1.94

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.
@@ -137,8 +137,8 @@ const TMContextMenu = ({ items, trigger = 'right', children, target, externalCon
137
137
  style.webkitTouchCallout = 'none';
138
138
  style.webkitUserSelect = 'none';
139
139
  style.userSelect = 'none';
140
- el.addEventListener('touchstart', handleTouchStart, { passive: true });
141
- el.addEventListener('touchmove', handleTouchMove, { passive: true });
140
+ el.addEventListener('touchstart', handleTouchStart, { passive: false });
141
+ el.addEventListener('touchmove', handleTouchMove, { passive: false });
142
142
  el.addEventListener('touchend', handleTouchEnd);
143
143
  el.addEventListener('touchcancel', handleTouchEnd);
144
144
  el.addEventListener('contextmenu', handleContextMenu);
@@ -356,7 +356,12 @@ const TMDataGrid = React.forwardRef((props, ref) => {
356
356
  // other properties
357
357
  disabled: disabled, autoNavigateToFocusedRow: autoNavigateToFocusedRow, focusedRowKey: focusedRowKey, columnHidingEnabled: columnHidingEnabled, columnResizingMode: columnResizingMode, columnAutoWidth: columnAutoWidth, allowColumnResizing: allowColumnResizing, allowColumnReordering: allowColumnReordering, showBorders: showBorders, showRowLines: showRowLines, showColumnLines: showColumnLines, showColumnHeaders: showColumnHeaders, rowAlternationEnabled: rowAlternationEnabled, wordWrapEnabled: wordWrapEnabled, noDataText: noDataText,
358
358
  // styles
359
- width: width, height: height, style: { userSelect: 'none' }, children: [dataColumns.map((column, index) => (_jsx(Column, { ...column }, column.caption + index.toString()))), sorting && _jsx(Sorting, { ...sorting }), selection && _jsx(Selection, { ...selection }), scrolling && _jsx(Scrolling, { ...scrolling }), summary && _jsx(Summary, { ...summary }), showHeaderFilter && _jsx(HeaderFilter, { visible: true, ...headerFilter }), rowDragging && _jsx(RowDragging, { ...rowDragging }), filterRow && _jsx(FilterRow, { ...filterRow }), showFilterPanel && _jsx(FilterPanel, { visible: true }), showHeaderColumnChooser && _jsxs(ColumnChooser, { height: "400px", enabled: !showHeaderColumnChooser, mode: "select", children: [_jsx(Position, { my: "center", at: "center", of: window }), _jsx(ColumnChooserSearch, { enabled: true }), _jsx(ColumnChooserSelection, { allowSelectAll: false, selectByClick: true, recursive: true })] }), stateStoring && _jsx(StateStoring, { ...stateStoring }), groupPanel && _jsx(GroupPanel, { ...groupPanel }), _jsx(Grouping, { contextMenuEnabled: true, ...grouping }), _jsx(LoadPanel, { enabled: showLoadPanel }), _jsx(SearchPanel, { visible: showSearchPanel, searchVisibleColumnsOnly: true, highlightSearchText: true }), editing && _jsx(Editing, { ...editing }), paging && _jsx(Paging, { ...paging }), pager && _jsx(Pager, { ...pager, visible: totalRecordCount > pageSize }), masterDetail && _jsx(MasterDetail, { ...masterDetail })] }) }), counterConfig.show && _jsx("div", { style: { width: "100%", height: "25px", display: "flex", alignItems: "center", gap: "15px", backgroundColor: "#e0e0e0" }, children: _jsx(TMCounterContainer, { items: counterValues, bgColorContainer: counterConfig.bgColorContainer, bgColorItem: counterConfig.bgColorItem, hoverColorItem: counterConfig.hoverColorItem, textColorItem: counterConfig.textColorItem }) }), customContextMenuItems && (_jsx(TMContextMenu, { target: ".dx-data-row", items: processCustomContextMenuItems(customContextMenuItems, customContextMenuRowKey), externalControl: {
359
+ width: width, height: height, style: {
360
+ userSelect: 'none',
361
+ // Temporary: iOS-specific styles to prevent default long-press menu and text selection
362
+ WebkitTouchCallout: 'none',
363
+ WebkitUserSelect: 'none'
364
+ }, children: [dataColumns.map((column, index) => (_jsx(Column, { ...column }, column.caption + index.toString()))), sorting && _jsx(Sorting, { ...sorting }), selection && _jsx(Selection, { ...selection }), scrolling && _jsx(Scrolling, { ...scrolling }), summary && _jsx(Summary, { ...summary }), showHeaderFilter && _jsx(HeaderFilter, { visible: true, ...headerFilter }), rowDragging && _jsx(RowDragging, { ...rowDragging }), filterRow && _jsx(FilterRow, { ...filterRow }), showFilterPanel && _jsx(FilterPanel, { visible: true }), showHeaderColumnChooser && _jsxs(ColumnChooser, { height: "400px", enabled: !showHeaderColumnChooser, mode: "select", children: [_jsx(Position, { my: "center", at: "center", of: window }), _jsx(ColumnChooserSearch, { enabled: true }), _jsx(ColumnChooserSelection, { allowSelectAll: false, selectByClick: true, recursive: true })] }), stateStoring && _jsx(StateStoring, { ...stateStoring }), groupPanel && _jsx(GroupPanel, { ...groupPanel }), _jsx(Grouping, { contextMenuEnabled: true, ...grouping }), _jsx(LoadPanel, { enabled: showLoadPanel }), _jsx(SearchPanel, { visible: showSearchPanel, searchVisibleColumnsOnly: true, highlightSearchText: true }), editing && _jsx(Editing, { ...editing }), paging && _jsx(Paging, { ...paging }), pager && _jsx(Pager, { ...pager, visible: totalRecordCount > pageSize }), masterDetail && _jsx(MasterDetail, { ...masterDetail })] }) }), counterConfig.show && _jsx("div", { style: { width: "100%", height: "25px", display: "flex", alignItems: "center", gap: "15px", backgroundColor: "#e0e0e0" }, children: _jsx(TMCounterContainer, { items: counterValues, bgColorContainer: counterConfig.bgColorContainer, bgColorItem: counterConfig.bgColorItem, hoverColorItem: counterConfig.hoverColorItem, textColorItem: counterConfig.textColorItem }) }), customContextMenuItems && (_jsx(TMContextMenu, { target: ".dx-data-row", items: processCustomContextMenuItems(customContextMenuItems, customContextMenuRowKey), externalControl: {
360
365
  visible: customContextMenuVisible,
361
366
  position: customContextMenuPosition,
362
367
  onClose: () => setCustomContextMenuVisible(false)
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useMemo, useRef, useState } from 'react';
3
3
  import styled from 'styled-components';
4
4
  import { ObjectClasses } from '@topconsultnpm/sdk-ts';
5
- import TMContextMenu, { useTMContextMenu } from './TMContextMenu';
5
+ import TMContextMenu from '../NewComponents/ContextMenu/TMContextMenu';
6
6
  import { IconApply, IconCloseCircle, IconColumns, IconDown, IconHide, IconShow, IconUp, IconVisible } from '../../helper/TMIcons';
7
7
  import { TMSearchBar } from '../sidebar/TMHeader';
8
8
  import TMTooltip from './TMTooltip';
@@ -26,9 +26,17 @@ const TMListView = ({ customGroupingHeaders, headerBackGroundColor, header, show
26
26
  const [isFocused, setIsFocused] = useState(false);
27
27
  const [showOrderMenu, setShowOrderMenu] = useState(false);
28
28
  const [showOrderOptions, setShowOrderOptions] = useState(false);
29
+ const [contextMenuVisible, setContextMenuVisible] = useState(false);
30
+ const [contextMenuPosition, setContextMenuPosition] = useState({ x: 0, y: 0 });
31
+ const [orderMenuVisible, setOrderMenuVisible] = useState(false);
32
+ const [orderMenuPosition, setOrderMenuPosition] = useState({ x: 0, y: 0 });
29
33
  useEffect(() => { setCurrentDataSource(dataSource); }, [dataSource]);
30
- const openContextMenu = (e) => { setIsFocused(true); };
31
- let [coords, show] = useTMContextMenu(contRef);
34
+ const openContextMenu = (e) => {
35
+ e.preventDefault();
36
+ setIsFocused(true);
37
+ setContextMenuVisible(true);
38
+ setContextMenuPosition({ x: e.clientX, y: e.clientY });
39
+ };
32
40
  useEffect(() => { if (orderBy) {
33
41
  setOrderedBy(orderBy);
34
42
  } }, [orderBy]);
@@ -235,10 +243,10 @@ const TMListView = ({ customGroupingHeaders, headerBackGroundColor, header, show
235
243
  for (let key of searchKeys) {
236
244
  arr.push({
237
245
  disabled: !localShowId && key === exprKey,
238
- isSelected: key === orderedBy,
239
- onItemClick: () => { setOrderedBy(key); setShowOrderOptions(false); },
246
+ onClick: () => { setOrderedBy(key); setShowOrderOptions(false); setOrderMenuVisible(false); },
240
247
  icon: _jsx(IconColumns, { fontSize: 16 }),
241
- text: _jsxs("div", { style: { display: 'flex', flexDirection: 'row', alignItems: 'center', gap: 10 }, children: [key, " ", key === orderedBy && _jsx(IconApply, { fontSize: 14, color: 'gray' })] })
248
+ name: key,
249
+ rightIcon: key === orderedBy ? _jsx(IconApply, { fontSize: 14, color: 'gray' }) : undefined
242
250
  });
243
251
  }
244
252
  }
@@ -328,16 +336,16 @@ const TMListView = ({ customGroupingHeaders, headerBackGroundColor, header, show
328
336
  if (showSearch === undefined) {
329
337
  items.push({
330
338
  icon: localShowSearch ? _jsx(IconHide, { fontSize: 16 }) : _jsx(IconShow, { fontSize: 16 }),
331
- onItemClick: () => setLocalShowSearch(!localShowSearch),
332
- text: localShowSearch ? SDKUI_Localizator.HideSearch : SDKUI_Localizator.ShowSearch
339
+ onClick: () => setLocalShowSearch(!localShowSearch),
340
+ name: localShowSearch ? SDKUI_Localizator.HideSearch : SDKUI_Localizator.ShowSearch
333
341
  });
334
342
  }
335
343
  // Add ID menu item only if showId prop is undefined
336
344
  if (showId === undefined) {
337
345
  items.push({
338
346
  icon: localShowId ? _jsx(IconHide, { fontSize: 16 }) : _jsx(IconShow, { fontSize: 16 }),
339
- onItemClick: () => setLocalShowId(!localShowId),
340
- text: localShowId ? SDKUI_Localizator.ID_Hide : SDKUI_Localizator.ID_Show,
347
+ onClick: () => setLocalShowId(!localShowId),
348
+ name: localShowId ? SDKUI_Localizator.ID_Hide : SDKUI_Localizator.ID_Show,
341
349
  });
342
350
  }
343
351
  // Add order menu item only if grouping length is zero
@@ -345,21 +353,31 @@ const TMListView = ({ customGroupingHeaders, headerBackGroundColor, header, show
345
353
  items.push({
346
354
  icon: showOrderMenu ? _jsx(IconHide, { fontSize: 16 }) : _jsx(IconShow, { fontSize: 16 }),
347
355
  disabled: searchKeys.length === 0,
348
- onItemClick: () => setShowOrderMenu(!showOrderMenu),
349
- text: showOrderMenu ? 'Nascondi menu di ordinamento' : 'Mostra menu di ordinamento'
356
+ onClick: () => setShowOrderMenu(!showOrderMenu),
357
+ name: showOrderMenu ? 'Nascondi menu di ordinamento' : 'Mostra menu di ordinamento'
350
358
  });
351
359
  }
352
360
  return items;
353
361
  };
354
362
  const contextMenuItems = generateContextMenuItems(localShowSearch, localShowId, showOrderMenu, grouping, searchKeys);
355
- return (_jsxs(StyledListViewContainer, { ref: contRef, onContextMenu: openContextMenu, children: [(show && contextMenuItems.length > 0) && _jsx(TMContextMenu, { coords: coords, items: contextMenuItems }), showOrderOptions &&
356
- _jsx(TMContextMenu, { items: orderMenuItems(), coords: { x: orderRef.current?.getBoundingClientRect().left, y: orderRef.current?.getBoundingClientRect().top - (searchKeys.length * 30) - 10 } }), header && _jsx("div", { style: { width: '100%', height: '40px', backgroundColor: headerBackGroundColor ?? `${customColor}30`, marginBottom: '3px', display: 'flex', alignItems: 'center' }, children: header }), localShowSearch &&
363
+ return (_jsxs(StyledListViewContainer, { ref: contRef, onContextMenu: openContextMenu, children: [contextMenuItems.length > 0 && (_jsx(TMContextMenu, { items: contextMenuItems, externalControl: {
364
+ visible: contextMenuVisible,
365
+ position: contextMenuPosition,
366
+ onClose: () => setContextMenuVisible(false)
367
+ } })), showOrderOptions && orderRef.current && (_jsx(TMContextMenu, { items: orderMenuItems(), externalControl: {
368
+ visible: orderMenuVisible || showOrderOptions,
369
+ position: {
370
+ x: orderRef.current.getBoundingClientRect().left,
371
+ y: orderRef.current.getBoundingClientRect().top - (searchKeys.length * 30) - 10
372
+ },
373
+ onClose: () => { setOrderMenuVisible(false); setShowOrderOptions(false); }
374
+ } })), header && _jsx("div", { style: { width: '100%', height: '40px', backgroundColor: headerBackGroundColor ?? `${customColor}30`, marginBottom: '3px', display: 'flex', alignItems: 'center' }, children: header }), localShowSearch &&
357
375
  _jsx(StyledSearchContainer, { children: _jsxs(StyledSearchContainer, { children: [_jsx(TMSearchBar, { marginLeft: '0px', maxWidth: '300px', searchValue: searchValue, onSearchValueChanged: (e) => setSearchValue(e) }), _jsx(TMTooltip, { content: 'Nascondi ricerca', children: _jsx(IconCloseCircle, { style: { cursor: 'pointer' }, color: 'red', fontSize: 14, onClick: () => { setSearchValue(''); setLocalShowSearch(false); } }) })] }) }), _jsx("div", { ref: listRef, onClick: () => setIsFocused(true), style: { width: '100%', overflow: 'auto', height: listHeight() }, children: currentDataSource.length > 0 ?
358
376
  grouping.length === 0 ? memoList : groupedMemoList :
359
377
  searchValue.length > 0 ? _jsx("div", { style: { width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center' }, children: "No data found" }) :
360
378
  _jsx("div", { style: { width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center' }, children: "No data" }) }), (searchValue.length > 0 || showOrderMenu) &&
361
379
  _jsxs(StyledListViewFooter, { "$bgColor": `${customColor}20`, children: [showOrderMenu &&
362
- _jsxs("div", { style: { width: 'max-content', display: 'flex', alignItems: 'center', gap: 5 }, children: [_jsx("div", { style: { width: 'max-content' }, children: "Ordinato per" }), _jsx("div", { ref: orderRef, onClick: () => { setShowOrderOptions(!showOrderOptions); }, style: { cursor: 'pointer', fontWeight: 'bold' }, children: orderedBy.length > 0 ? orderedBy : 'Nulla' }), orderedBy.length > 0 && _jsxs(TMTooltip, { content: orderDir ? 'ASC' : 'DESC', children: [" ", orderDir ? _jsx(IconUp, { style: { cursor: 'pointer' }, onClick: () => setOrderDir(false), fontSize: 14 }) : _jsx(IconDown, { style: { cursor: 'pointer' }, onClick: () => setOrderDir(true), fontSize: 14 }), " "] }), _jsx(TMTooltip, { content: 'Annulla ordinamento', children: _jsx(IconCloseCircle, { style: { cursor: 'pointer' }, color: 'red', fontSize: 14, onClick: () => { setOrderedBy(''); setShowOrderMenu(false); setShowOrderOptions(false); } }) })] }), searchValue.length > 0 && _jsxs("div", { style: { display: 'flex', alignItems: 'center', width: '100%', justifyContent: 'flex-end', gap: 5 }, children: [_jsx(TMTooltip, { content: 'Visibili', children: _jsx(IconVisible, { fontSize: 14 }) }), currentDataSource.length] })] })] }));
380
+ _jsxs("div", { style: { width: 'max-content', display: 'flex', alignItems: 'center', gap: 5 }, children: [_jsx("div", { style: { width: 'max-content' }, children: "Ordinato per" }), _jsx("div", { ref: orderRef, onClick: () => { setShowOrderOptions(!showOrderOptions); setOrderMenuVisible(!orderMenuVisible); }, style: { cursor: 'pointer', fontWeight: 'bold' }, children: orderedBy.length > 0 ? orderedBy : 'Nulla' }), orderedBy.length > 0 && _jsxs(TMTooltip, { content: orderDir ? 'ASC' : 'DESC', children: [" ", orderDir ? _jsx(IconUp, { style: { cursor: 'pointer' }, onClick: () => setOrderDir(false), fontSize: 14 }) : _jsx(IconDown, { style: { cursor: 'pointer' }, onClick: () => setOrderDir(true), fontSize: 14 }), " "] }), _jsx(TMTooltip, { content: 'Annulla ordinamento', children: _jsx(IconCloseCircle, { style: { cursor: 'pointer' }, color: 'red', fontSize: 14, onClick: () => { setOrderedBy(''); setShowOrderMenu(false); setShowOrderOptions(false); } }) })] }), searchValue.length > 0 && _jsxs("div", { style: { display: 'flex', alignItems: 'center', width: '100%', justifyContent: 'flex-end', gap: 5 }, children: [_jsx(TMTooltip, { content: 'Visibili', children: _jsx(IconVisible, { fontSize: 14 }) }), currentDataSource.length] })] })] }));
363
381
  };
364
382
  export default TMListView;
365
383
  export const CustomListViewHeader = (props) => {
@@ -131,7 +131,7 @@ const TMDistinctValues = ({ tid, mid, layoutMode = LayoutModes.None, allowAppend
131
131
  return md.dataDomain === undefined || md.dataDomain === MetadataDataDomains.None;
132
132
  };
133
133
  const renderContent = () => {
134
- return (_jsxs(StyledDistinctValues, { children: [isVisibleAppend() && _jsx(TMCheckBox, { elementStyle: { position: 'absolute', right: '15px', top: '15px', zIndex: 10000 }, label: 'Accoda', value: isAppendMode, onValueChanged: () => { setIsAppendMode(!isAppendMode); } }), _jsx(TMDataGrid, { focusedRowKey: focusedItem ? focusedItem.rowIndex : undefined, selection: { showCheckBoxesMode: 'none' }, searchPanel: { highlightCaseSensitive: true, visible: true }, dataColumns: customColumns, dataSource: dataSource, keyExpr: 'rowIndex', height: 'calc(100%)', onFocusedRowChanged: onFocusedRowChanged, paging: { pageSize: 30 }, summary: customSummary })] }));
134
+ return (_jsxs(StyledDistinctValues, { children: [isVisibleAppend() && _jsx(TMCheckBox, { elementStyle: { position: 'absolute', right: '15px', top: '15px', zIndex: 10000 }, label: 'Accoda', value: isAppendMode, onValueChanged: () => { setIsAppendMode(!isAppendMode); } }), _jsx(TMDataGrid, { focusedRowKey: focusedItem ? focusedItem.rowIndex : undefined, selection: { showCheckBoxesMode: 'none' }, searchPanel: { highlightCaseSensitive: true, visible: true }, dataColumns: customColumns, dataSource: dataSource, keyExpr: 'rowIndex', height: 'calc(100%)', onFocusedRowChanged: onFocusedRowChanged, paging: { pageSize: 30 }, summary: customSummary, onRowDblClick: () => !isAppendMode && onClosePanelCallback?.() })] }));
135
135
  };
136
136
  return (_jsx(_Fragment, { children: isModal
137
137
  ? _jsx(TMModal, { title: SDKUI_Localizator.DistinctValues + (md?.nameLoc ? ` (${md?.nameLoc})` : ''), height: '600px', width: '500px', resizable: true, onClose: onClosePanelCallback, children: renderContent() })
@@ -2,7 +2,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
2
2
  import { useState, useEffect, useRef } from 'react';
3
3
  import { StyledEditorContainer, StyledEditorIcon, StyledEditorLabel, StyledTextareaEditor } from './TMEditorStyled';
4
4
  import { FontSize, TMColors } from '../../utils/theme';
5
- import TMContextMenu, { useContextMenu } from '../base/TMContextMenuOLD';
5
+ import TMContextMenu from '../NewComponents/ContextMenu/TMContextMenu';
6
6
  import { TMExceptionBoxManager } from '../base/TMPopUp';
7
7
  import TMLayoutContainer, { TMLayoutItem } from '../base/TMLayout';
8
8
  import TMVilViewer from '../base/TMVilViewer';
@@ -35,14 +35,10 @@ const TMTextArea = (props) => {
35
35
  const [isFocused, setIsFocused] = useState(false);
36
36
  // Stores the current value of the textarea
37
37
  const [currentValue, setCurrentValue] = useState(value);
38
- // Stores the items for the context menu
39
- const [formulaMenuItems, setFormulaMenuItems] = useState([]);
40
38
  // Stores the calculated number of rows for the textarea
41
39
  const [calculatedRows, setCalculatedRows] = useState(rows ?? 1);
42
40
  //Show chooserForm formulaItems
43
41
  const [showFormulaItemsChooser, setShowFormulaItemsChooser] = useState(false);
44
- // Manages the state for the custom context menu
45
- const { clicked, setClicked, points, setPoints } = useContextMenu();
46
42
  const deviceType = useDeviceType();
47
43
  // Attach a `ResizeObserver` to the textarea to monitor changes in width: dynamically updates rows based on textarea content and width
48
44
  useEffect(() => {
@@ -69,16 +65,15 @@ const TMTextArea = (props) => {
69
65
  setCalculatedRows(newRowCount);
70
66
  }
71
67
  }, [currentValue, autoCalculateRows]);
72
- // Populate the formula menu items whenever the `formulaItems` prop changes
73
- useEffect(() => {
74
- if (formulaItems && formulaItems.length > 0) {
75
- let menuItems = [];
76
- for (const formula of formulaItems) {
77
- menuItems.push({ text: formula });
78
- }
79
- setFormulaMenuItems(menuItems);
80
- }
81
- }, [formulaItems]);
68
+ // Build context menu items for formulas
69
+ const getFormulaMenuItems = () => {
70
+ if (!formulaItems || formulaItems.length === 0)
71
+ return [];
72
+ return formulaItems.map(formula => ({
73
+ name: formula,
74
+ onClick: () => insertText(formula)
75
+ }));
76
+ };
82
77
  function getFormulaDataSorce() {
83
78
  let fiarray = [];
84
79
  if (!formulaItems)
@@ -153,20 +148,8 @@ const TMTextArea = (props) => {
153
148
  };
154
149
  // Renders the textarea
155
150
  const renderTextArea = () => {
156
- return _jsxs(_Fragment, { children: [_jsx(StyledTextareaEditor, { ref: inputRef, autoFocus: autoFocus, readOnly: readOnly, disabled: disabled, value: currentValue, placeholder: placeHolder, rows: calculatedRows, maxLength: maxLength, spellCheck: false, onFocus: () => setIsFocused(true), onBlur: (e) => { setIsFocused(false); if (currentValue != value)
157
- onBlur?.(currentValue); }, onChange: (e) => { setCurrentValue(e.target.value); onValueChanged?.(e); }, onContextMenu: (e) => {
158
- if (formulaItems.length <= 0)
159
- return;
160
- // prevent default right click behavior
161
- e.preventDefault();
162
- // set our click state to true when a user right clicks
163
- setClicked(true);
164
- const bounds = e.currentTarget.getBoundingClientRect();
165
- const x = e.clientX - bounds.left;
166
- const y = e.clientY - bounds.top;
167
- // set the x and y coordinates of our users right click
168
- setPoints({ x, y });
169
- }, "$isMobile": deviceType === DeviceType.MOBILE, "$maxHeight": maxHeight, "$disabled": disabled, "$vil": validationItems, "$isModified": isModifiedWhen, "$fontSize": fontSize, "$width": width, "$resize": resize }), _jsxs("div", { style: { display: 'flex', flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', position: 'absolute', right: '6px', top: calculatedRows === 1 ? (label.length > 0 ? '20px' : '7px') : (label.length > 0 ? '22px' : '7px'), pointerEvents: disabled ? 'none' : 'auto', opacity: disabled ? 0.4 : 1 }, children: [formulaItems.length > 0 &&
151
+ const textareaElement = _jsxs(_Fragment, { children: [_jsx(StyledTextareaEditor, { ref: inputRef, autoFocus: autoFocus, readOnly: readOnly, disabled: disabled, value: currentValue, placeholder: placeHolder, rows: calculatedRows, maxLength: maxLength, spellCheck: false, onFocus: () => setIsFocused(true), onBlur: (e) => { setIsFocused(false); if (currentValue != value)
152
+ onBlur?.(currentValue); }, onChange: (e) => { setCurrentValue(e.target.value); onValueChanged?.(e); }, "$isMobile": deviceType === DeviceType.MOBILE, "$maxHeight": maxHeight, "$disabled": disabled, "$vil": validationItems, "$isModified": isModifiedWhen, "$fontSize": fontSize, "$width": width, "$resize": resize }), _jsxs("div", { style: { display: 'flex', flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', position: 'absolute', right: '6px', top: calculatedRows === 1 ? (label.length > 0 ? '20px' : '7px') : (label.length > 0 ? '22px' : '7px'), pointerEvents: disabled ? 'none' : 'auto', opacity: disabled ? 0.4 : 1 }, children: [formulaItems.length > 0 &&
170
153
  _jsx(StyledTextAreaEditorButton, { onClick: () => {
171
154
  setShowFormulaItemsChooser(true);
172
155
  }, children: _jsx(IconDataList, {}) }), showClearButton && currentValue &&
@@ -178,7 +161,12 @@ const TMTextArea = (props) => {
178
161
  onBlur?.(undefined);
179
162
  }, children: _jsx(IconClearButton, {}) }), buttons.map((buttonItem, index) => {
180
163
  return (_jsx(StyledTextAreaEditorButton, { onClick: buttonItem.onClick, children: _jsx(TMTooltip, { content: buttonItem.text, children: buttonItem.icon }) }, buttonItem.text));
181
- })] }), openFormulaItemsChooser(), formulaItems.length > 0 && clicked && (_jsx(TMContextMenu, { menuData: formulaMenuItems, top: points.y, left: points.x, onMenuItemClick: (formula) => insertText(formula) })), _jsx(TMVilViewer, { vil: validationItems })] });
164
+ })] }), openFormulaItemsChooser(), _jsx(TMVilViewer, { vil: validationItems })] });
165
+ // Wrap with context menu if formula items exist
166
+ if (formulaItems.length > 0) {
167
+ return (_jsx(TMContextMenu, { items: getFormulaMenuItems(), trigger: "right", children: textareaElement }));
168
+ }
169
+ return textareaElement;
182
170
  };
183
171
  // Layout for the textarea with a left-aligned label
184
172
  const renderedLeftLabelTextArea = () => {
@@ -1,7 +1,6 @@
1
1
  export { default as ShowAlert } from './base/TMAlert';
2
2
  export { default as TMButton } from './base/TMButton';
3
3
  export { default as TMClosableList } from './base/TMClosableList';
4
- export * from './base/TMContextMenu';
5
4
  export { default as TMDropDownMenu } from './base/TMDropDownMenu';
6
5
  export * from './base/TMListView';
7
6
  export { default as TMList } from './base/TMList';
@@ -25,7 +24,6 @@ export { default as TMToggleButton } from './base/TMToggleButton';
25
24
  export { default as TMTooltip } from './base/TMTooltip';
26
25
  export { default as TMVilViewer } from './base/TMVilViewer';
27
26
  export { default as TMUserAvatar } from './base/TMUserAvatar';
28
- export { default as TMFloatingToolbar } from './base/TMFloatingToolbar';
29
27
  export { default as TMDropDown } from './editors/TMDropDown';
30
28
  export { default as TMTreeDropDown } from './editors/TMTreeDropDown';
31
29
  export { default as TMSummary } from './editors/TMSummary';
@@ -2,7 +2,6 @@
2
2
  export { default as ShowAlert } from './base/TMAlert';
3
3
  export { default as TMButton } from './base/TMButton';
4
4
  export { default as TMClosableList } from './base/TMClosableList';
5
- export * from './base/TMContextMenu';
6
5
  export { default as TMDropDownMenu } from './base/TMDropDownMenu';
7
6
  export * from './base/TMListView';
8
7
  export { default as TMList } from './base/TMList';
@@ -26,7 +25,6 @@ export { default as TMToggleButton } from './base/TMToggleButton';
26
25
  export { default as TMTooltip } from './base/TMTooltip';
27
26
  export { default as TMVilViewer } from './base/TMVilViewer';
28
27
  export { default as TMUserAvatar } from './base/TMUserAvatar';
29
- export { default as TMFloatingToolbar } from './base/TMFloatingToolbar';
30
28
  //editors
31
29
  export { default as TMDropDown } from './editors/TMDropDown';
32
30
  export { default as TMTreeDropDown } from './editors/TMTreeDropDown';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topconsultnpm/sdkui-react",
3
- "version": "6.20.0-dev1.92",
3
+ "version": "6.20.0-dev1.94",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -1,25 +0,0 @@
1
- import React, { ReactNode } from 'react';
2
- export interface ITMContextMenuItemProps {
3
- icon?: ReactNode;
4
- text?: any;
5
- items?: ITMContextMenuItemProps[];
6
- disabled?: boolean;
7
- isSelected?: boolean;
8
- id?: string;
9
- onItemClick?: () => void;
10
- onItemMouseOver?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
11
- }
12
- export interface ITMContextMenuProps {
13
- items?: ITMContextMenuItemProps[];
14
- coords?: {
15
- x: number;
16
- y: number;
17
- };
18
- subMenuDir?: 'left' | 'right';
19
- }
20
- declare const TMContextMenu: ({ items, coords, subMenuDir, }: ITMContextMenuProps) => import("react/jsx-runtime").JSX.Element;
21
- export declare const useTMContextMenu: (ref: React.RefObject<HTMLElement>) => (boolean | {
22
- x: number;
23
- y: number;
24
- })[];
25
- export default TMContextMenu;
@@ -1,109 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useEffect, useRef, useState } from 'react';
3
- import styled from 'styled-components';
4
- import { IconRight } from '../../helper/TMIcons';
5
- const StyledContextMenuContainer = styled.div `
6
- display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; z-index: 300; position: fixed; top: ${props => `${props.$top}px`}; left: ${props => `${props.$left}px`}; right: ${props => `${props.$right}px`}; bottom: ${props => `${props.$bottom}px`}; width: max-content; height: max-content; background-color: white; box-shadow: 1px 1px 2px #00000040;
7
- `;
8
- const StyledContextMenuItem = styled.div `
9
- cursor: ${props => !props.$disabled ? 'pointer' : 'default'}; display: flex; align-items: center; gap: 5px; transition: ease 100ms; padding: 5px; background-color: ${props => props.$isSelected && '#e9e9e9'}; width: 100%; height: 100%; color: ${props => props.$disabled && '#d0d0d0'}; &:hover { background-color: ${props => !props.$disabled && '#e9e9e9'} ; }
10
- `;
11
- const TMContextMenu = ({ items = [], coords = { x: 0, y: 0 }, subMenuDir = 'right', }) => {
12
- // Coordinates for sub-menus
13
- const [subMenuCoords, setSubMenuCoords] = useState({ x: 0, y: 0 });
14
- // Track which item is currently hovered
15
- const [hoveredItem, setHoveredItem] = useState(null);
16
- // Size of the menu
17
- const [menuSize, setMenuSize] = useState({ x: 0, y: 0 });
18
- // Current direction for submenus
19
- const [currentSubMenuDir, setCurrentSubMenuDir] = useState(subMenuDir);
20
- // Reference to the context menu DOM element
21
- const contextMenuRef = useRef(null);
22
- // Uupdate submenu direction based on incoming props
23
- useEffect(() => setCurrentSubMenuDir(subMenuDir), [subMenuDir]);
24
- // Calculate the size of the context menu and adjust submenu direction
25
- // Run this effect only once when the component mounts
26
- useEffect(() => {
27
- if (contextMenuRef.current) {
28
- setMenuSize({
29
- x: contextMenuRef.current.getBoundingClientRect().width || 0,
30
- y: contextMenuRef.current.getBoundingClientRect().height || 0,
31
- });
32
- }
33
- }, []);
34
- useEffect(() => {
35
- // This effect checks the width on resize
36
- const handleResize = () => {
37
- if (window.innerWidth <= coords.x + menuSize.x) {
38
- // Change direction to left if menu goes beyond right edge
39
- setCurrentSubMenuDir('left');
40
- }
41
- else {
42
- // Default to right if there's space
43
- setCurrentSubMenuDir('right');
44
- }
45
- };
46
- // Attach event listener
47
- window.addEventListener('resize', handleResize);
48
- handleResize(); // Call it initially to set the direction
49
- // Clean up the event listener on unmount
50
- return () => {
51
- window.removeEventListener('resize', handleResize);
52
- };
53
- }, [coords, menuSize.x]); // Only watch coords and the width of menuSize
54
- // Handle mouse over event on items to potentially show submenus
55
- const onItemMouseOver = (item, index) => {
56
- if (!item.disabled && item.items && item.items.length > 0) {
57
- setHoveredItem(index);
58
- const boundingRect = contextMenuRef.current?.getBoundingClientRect();
59
- if (boundingRect) {
60
- // Calculate the sub-menu position based on the current item position
61
- const subMenuX = currentSubMenuDir === 'right' ? boundingRect.right : boundingRect.left - menuSize.x;
62
- const subMenuY = boundingRect.top + index * 30; // Adjust Y coordinate to match item
63
- setSubMenuCoords({ x: subMenuX, y: subMenuY });
64
- }
65
- }
66
- else {
67
- // Clear hover state if the item has no sub-menu
68
- setHoveredItem(null); // If no submenu, clear hover state
69
- }
70
- };
71
- return (_jsx(StyledContextMenuContainer, { ref: contextMenuRef, "$left": currentSubMenuDir === 'right' ? coords.x : 'none', "$top": window.innerHeight > coords.y + menuSize.y ? coords.y : 'none', "$right": currentSubMenuDir === 'left' ? window.innerWidth - coords.x : 'none', "$bottom": window.innerHeight <= coords.y + menuSize.y ? window.innerHeight - coords.y : 'none', children: items.map((item, index) => (_jsxs("div", { style: { width: '100%' }, children: [_jsxs(StyledContextMenuItem, { id: item.id, onMouseOver: () => onItemMouseOver(item, index), onMouseEnter: () => onItemMouseOver(item, index), "$isSelected": item.isSelected, "$disabled": item.disabled, onClick: () => !item.disabled && item.onItemClick && item.onItemClick(), children: [_jsx("div", { style: { transform: 'translateY(3px)' }, children: item.icon }), _jsx("div", { style: { width: '100%' }, children: item.items && item.items.length > 0 ? (_jsxs("div", { style: {
72
- width: '100%',
73
- display: 'flex',
74
- alignItems: 'center',
75
- gap: 5,
76
- justifyContent: 'space-between',
77
- }, children: [item.text, " ", _jsx(IconRight, { style: { transform: 'translateY(1px)' }, fontSize: 10 })] })) : (_jsx("div", { style: { width: '100%' }, children: item.text })) })] }), item.items && item.items.length > 0 && hoveredItem === index && (_jsx(TMContextMenu, { subMenuDir: currentSubMenuDir, coords: subMenuCoords, items: item.items }))] }, index))) }));
78
- };
79
- export const useTMContextMenu = (ref) => {
80
- // Coordinates for the context menu
81
- const [coords, setCoords] = useState({ x: 0, y: 0 });
82
- // State to control visibility of the context menu
83
- const [showContextMenu, setShowContexMenu] = useState(false);
84
- // Effect to hide context menu when clicking outside of the referenced element
85
- useEffect(() => {
86
- const menu = ref.current;
87
- const deSelectAll = (e) => { if (menu && !menu.contains(e.target)) {
88
- setShowContexMenu(false);
89
- } };
90
- window.addEventListener('contextmenu', deSelectAll);
91
- return () => { window.removeEventListener('contextmenu', deSelectAll); };
92
- }, []);
93
- // Effect to hide context menu on left-click anywhere
94
- useEffect(() => {
95
- const handleClick = () => { setShowContexMenu(false); };
96
- window.addEventListener("click", handleClick);
97
- return () => { window.removeEventListener("click", handleClick); };
98
- }, []);
99
- // Effect to show context menu on right-click and prevent default context menu
100
- useEffect(() => {
101
- let menu = ref.current;
102
- if (menu) {
103
- menu?.addEventListener('contextmenu', (e) => { e.preventDefault(); setShowContexMenu(true); setCoords({ x: e.pageX, y: e.pageY }); });
104
- }
105
- return () => menu?.removeEventListener('contextmenu', (e) => { setCoords({ x: e.pageX, y: e.pageY }); });
106
- }, [ref]);
107
- return [coords, showContextMenu];
108
- };
109
- export default TMContextMenu;
@@ -1,26 +0,0 @@
1
- import React from 'react';
2
- export declare const useContextMenu: () => {
3
- clicked: boolean;
4
- setClicked: React.Dispatch<React.SetStateAction<boolean>>;
5
- points: {
6
- x: number;
7
- y: number;
8
- };
9
- setPoints: React.Dispatch<React.SetStateAction<{
10
- x: number;
11
- y: number;
12
- }>>;
13
- };
14
- export declare const Container: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
15
- $top: number;
16
- $left: number;
17
- }>> & string;
18
- export declare const MenuOption: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
19
- interface ITMContextMenu {
20
- menuData: any[];
21
- onMenuItemClick?: (item: string) => void;
22
- top: number;
23
- left: number;
24
- }
25
- declare const TMContextMenuOLD: React.FunctionComponent<ITMContextMenu>;
26
- export default TMContextMenuOLD;
@@ -1,56 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useEffect, useState } from 'react';
3
- import styled from 'styled-components';
4
- import { Colors, FontSize } from '../../utils/theme';
5
- // #region Hook useContextMenu
6
- export const useContextMenu = () => {
7
- // boolean value to determine if the user has right clicked
8
- const [clicked, setClicked] = useState(false);
9
- // allows us to track the x,y coordinates of the users right click
10
- const [points, setPoints] = useState({ x: 0, y: 0 });
11
- useEffect(() => {
12
- // reset clicked to false on user click
13
- const handleClick = () => {
14
- setClicked(false);
15
- };
16
- // add listener for user click
17
- document.addEventListener("click", handleClick);
18
- // clean up listener function to avoid memory leaks
19
- return () => {
20
- document.removeEventListener("click", handleClick);
21
- };
22
- }, []);
23
- return { clicked, setClicked, points, setPoints };
24
- };
25
- // #endregion
26
- export const Container = styled.div `
27
- position: absolute;
28
- padding: 5px 5px;
29
- background-color: white;
30
- width: max-content;
31
- height: max-content;
32
- border-radius: 2px;
33
- display: flex;
34
- flex-direction: column;
35
- justify-content: flex-start;
36
- align-items: center;
37
- box-shadow: 2px 2px 10px #00000030;
38
- z-index: 2;
39
- top: ${(props) => props.$top || 0}px;
40
- left: ${(props) => props.$left || 0}px;
41
- `;
42
- export const MenuOption = styled.div `
43
- width: 100%;
44
- height: 20px;
45
- padding: 3px;
46
- cursor: pointer;
47
- font-size: ${FontSize.defaultFontSize};
48
-
49
- &:hover {
50
- color: ${Colors.primary};
51
- }
52
- `;
53
- const TMContextMenuOLD = ({ menuData, top, left, onMenuItemClick }) => {
54
- return (_jsx(_Fragment, { children: _jsx(Container, { "$top": top, "$left": left, children: menuData.map((item, index) => (_jsx(MenuOption, { onClick: (e) => onMenuItemClick?.(e.target.innerText), children: item.text }, index))) }) }));
55
- };
56
- export default TMContextMenuOLD;
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- interface ITMFloatingToolbarProps {
3
- children: React.ReactNode;
4
- backgroundColor: string | undefined;
5
- initialLeft?: string;
6
- initialTop?: string;
7
- }
8
- declare const TMFloatingToolbar: ({ children, backgroundColor, initialLeft, initialTop }: ITMFloatingToolbarProps) => import("react/jsx-runtime").JSX.Element;
9
- export default TMFloatingToolbar;
@@ -1,101 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useEffect, useRef } from 'react';
3
- import styled from 'styled-components';
4
- import { IconDraggabledots } from '../../helper/TMIcons';
5
- const StyledFloatingToolbarContainer = styled.div `
6
- position: absolute;
7
- width: max-content;
8
- height: max-content;
9
- display: flex;
10
- flex-direction: row;
11
- background-color: ${props => `${props.$backgroundColor}a6`};
12
- left: calc(50% - 90px);
13
- top: calc(100% - 40px);
14
- border-radius: 8px;
15
- z-index: 10;
16
- &:hover {
17
- background: ${props => props.$backgroundColor};
18
- }
19
- `;
20
- const StyledFloatingToolbarDraggable = styled.div `
21
- display: flex;
22
- align-items: center;
23
- justify-content: center;
24
- width: 25px;
25
- height: 100%;
26
- background-color: ${props => `${props.$backgroundColor}FF`};
27
- border-top-left-radius: 8px;
28
- border-bottom-left-radius: 8px;
29
- padding: 10px 0px 10px 0px;
30
- &:hover {
31
- cursor: grab;
32
- }
33
- `;
34
- const StyledFloatingToolbar = styled.div `
35
- width: max-content;
36
- display: flex;
37
- flex-direction: row;
38
- padding: 10px 10px 10px 20px;
39
- gap: 8px;
40
- border-radius: 8px;
41
- `;
42
- const TMFloatingToolbar = ({ children, backgroundColor, initialLeft, initialTop }) => {
43
- const boxRef = useRef(null);
44
- const boxDraggableRef = useRef(null);
45
- const isClicked = useRef(false);
46
- const coords = useRef({
47
- startX: 0,
48
- startY: 0,
49
- lastX: 0,
50
- lastY: 0
51
- });
52
- useEffect(() => {
53
- if (!boxRef.current)
54
- return;
55
- if (!boxDraggableRef.current)
56
- return;
57
- let container = boxRef.current?.parentElement;
58
- if (!container)
59
- return;
60
- const box = boxRef.current;
61
- box.style.top = initialTop ?? `0px`;
62
- box.style.left = initialLeft ?? `0px`;
63
- const onMouseDown = (e) => {
64
- isClicked.current = true;
65
- coords.current.startX = e.clientX;
66
- coords.current.startY = e.clientY;
67
- coords.current.lastX = box.offsetLeft;
68
- coords.current.lastY = box.offsetTop;
69
- };
70
- const onMouseUp = (e) => {
71
- isClicked.current = false;
72
- coords.current.lastX = box.offsetLeft;
73
- coords.current.lastY = box.offsetTop;
74
- };
75
- const onMouseMove = (e) => {
76
- if (!isClicked.current)
77
- return;
78
- const nextX = e.clientX - coords.current.startX + coords.current.lastX;
79
- const nextY = e.clientY - coords.current.startY + coords.current.lastY;
80
- const screenWidth = container.getBoundingClientRect().width;
81
- const screenHeight = container.getBoundingClientRect().height;
82
- const boundedX = Math.max(0, Math.min(screenWidth - box.getBoundingClientRect().width, nextX));
83
- const boundedY = Math.max(0, Math.min(screenHeight - box.getBoundingClientRect().height, nextY));
84
- box.style.top = `${boundedY}px`;
85
- box.style.left = `${boundedX}px`;
86
- };
87
- boxDraggableRef.current?.addEventListener('mousedown', onMouseDown);
88
- window.addEventListener('mouseup', onMouseUp);
89
- window.addEventListener('mousemove', onMouseMove);
90
- window.addEventListener('mouseleave', onMouseUp);
91
- const cleanup = () => {
92
- boxDraggableRef.current?.removeEventListener('mousedown', onMouseDown);
93
- window.removeEventListener('mouseup', onMouseUp);
94
- window.removeEventListener('mousemove', onMouseMove);
95
- window.removeEventListener('mouseleave', onMouseUp);
96
- };
97
- return cleanup;
98
- }, [initialLeft, initialTop]);
99
- return (_jsxs(StyledFloatingToolbarContainer, { ref: boxRef, "$backgroundColor": backgroundColor, children: [_jsx(StyledFloatingToolbarDraggable, { ref: boxDraggableRef, "$backgroundColor": backgroundColor, children: _jsx(IconDraggabledots, { color: 'white' }) }), _jsx(StyledFloatingToolbar, { "$backgroundColor": backgroundColor, children: children })] }));
100
- };
101
- export default TMFloatingToolbar;