@chayns-components/core 5.0.0-beta.1370 → 5.0.0-beta.1373
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/lib/cjs/components/context-menu/ContextMenu.js +14 -15
- package/lib/cjs/components/context-menu/ContextMenu.js.map +1 -1
- package/lib/cjs/components/context-menu/ContextMenu.types.js +31 -0
- package/lib/cjs/components/context-menu/ContextMenu.types.js.map +1 -0
- package/lib/cjs/components/context-menu/ContextMenu.utils.js +12 -0
- package/lib/cjs/components/context-menu/ContextMenu.utils.js.map +1 -0
- package/lib/cjs/components/context-menu/context-menu-content/ContextMenuContent.js +18 -19
- package/lib/cjs/components/context-menu/context-menu-content/ContextMenuContent.js.map +1 -1
- package/lib/cjs/components/context-menu/context-menu-content/ContextMenuContent.styles.js +11 -26
- package/lib/cjs/components/context-menu/context-menu-content/ContextMenuContent.styles.js.map +1 -1
- package/lib/cjs/components/filter/Filter.js.map +1 -1
- package/lib/cjs/components/sharing-bar/SharingBar.js.map +1 -1
- package/lib/cjs/index.js +2 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types/contextMenu.js +0 -15
- package/lib/cjs/types/contextMenu.js.map +1 -1
- package/lib/cjs/types/general.js +6 -0
- package/lib/cjs/types/general.js.map +1 -0
- package/lib/esm/components/context-menu/ContextMenu.js +10 -11
- package/lib/esm/components/context-menu/ContextMenu.js.map +1 -1
- package/lib/esm/components/context-menu/ContextMenu.types.js +29 -0
- package/lib/esm/components/context-menu/ContextMenu.types.js.map +1 -0
- package/lib/esm/components/context-menu/ContextMenu.utils.js +5 -0
- package/lib/esm/components/context-menu/ContextMenu.utils.js.map +1 -0
- package/lib/esm/components/context-menu/context-menu-content/ContextMenuContent.js +14 -15
- package/lib/esm/components/context-menu/context-menu-content/ContextMenuContent.js.map +1 -1
- package/lib/esm/components/context-menu/context-menu-content/ContextMenuContent.styles.js +4 -19
- package/lib/esm/components/context-menu/context-menu-content/ContextMenuContent.styles.js.map +1 -1
- package/lib/esm/components/filter/Filter.js.map +1 -1
- package/lib/esm/components/sharing-bar/SharingBar.js.map +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types/contextMenu.js +0 -9
- package/lib/esm/types/contextMenu.js.map +1 -1
- package/lib/esm/types/general.js +2 -0
- package/lib/esm/types/general.js.map +1 -0
- package/lib/types/components/context-menu/ContextMenu.d.ts +2 -79
- package/lib/types/components/context-menu/ContextMenu.types.d.ts +147 -0
- package/lib/types/components/context-menu/ContextMenu.utils.d.ts +2 -0
- package/lib/types/components/context-menu/context-menu-content/ContextMenuContent.d.ts +1 -3
- package/lib/types/components/context-menu/context-menu-content/ContextMenuContent.styles.d.ts +1 -4
- package/lib/types/components/sharing-bar/SharingBar.d.ts +1 -1
- package/lib/types/index.d.ts +2 -2
- package/lib/types/types/contextMenu.d.ts +0 -8
- package/lib/types/types/general.d.ts +4 -0
- package/package.json +3 -3
|
@@ -9,11 +9,12 @@ var _react = require("motion/react");
|
|
|
9
9
|
var _react2 = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _reactDom = require("react-dom");
|
|
11
11
|
var _uuid = require("../../hooks/uuid");
|
|
12
|
-
var _contextMenu = require("../../types/contextMenu");
|
|
13
12
|
var _environment = require("../../utils/environment");
|
|
14
13
|
var _Icon = _interopRequireDefault(require("../icon/Icon"));
|
|
15
14
|
var _ContextMenuContent = _interopRequireDefault(require("./context-menu-content/ContextMenuContent"));
|
|
16
15
|
var _ContextMenu = require("./ContextMenu.styles");
|
|
16
|
+
var _ContextMenu2 = require("./ContextMenu.types");
|
|
17
|
+
var _ContextMenu3 = require("./ContextMenu.utils");
|
|
17
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
19
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
19
20
|
const ContextMenu = /*#__PURE__*/(0, _react2.forwardRef)(({
|
|
@@ -24,14 +25,13 @@ const ContextMenu = /*#__PURE__*/(0, _react2.forwardRef)(({
|
|
|
24
25
|
}),
|
|
25
26
|
container,
|
|
26
27
|
coordinates,
|
|
27
|
-
shouldHidePopupArrow = false,
|
|
28
|
-
items,
|
|
29
28
|
headline,
|
|
29
|
+
items,
|
|
30
30
|
onHide,
|
|
31
|
-
shouldDisableClick = false,
|
|
32
31
|
onShow,
|
|
33
32
|
shouldCloseOnPopupClick = true,
|
|
34
|
-
|
|
33
|
+
shouldDisableClick = false,
|
|
34
|
+
shouldHidePopupArrow = false,
|
|
35
35
|
shouldShowHoverEffect = false,
|
|
36
36
|
zIndex = 20
|
|
37
37
|
}, ref) => {
|
|
@@ -39,9 +39,9 @@ const ContextMenu = /*#__PURE__*/(0, _react2.forwardRef)(({
|
|
|
39
39
|
x: 0,
|
|
40
40
|
y: 0
|
|
41
41
|
});
|
|
42
|
+
const [internalAlignment, setInternalAlignment] = (0, _react2.useState)(_ContextMenu2.ContextMenuAlignment.TopLeft);
|
|
42
43
|
const [newContainer, setNewContainer] = (0, _react2.useState)(container ?? null);
|
|
43
|
-
const [focusedIndex, setFocusedIndex] = (0, _react2.useState)(0);
|
|
44
|
-
const [internalAlignment, setInternalAlignment] = (0, _react2.useState)(_contextMenu.ContextMenuAlignment.TopLeft);
|
|
44
|
+
const [focusedIndex, setFocusedIndex] = (0, _react2.useState)((0, _ContextMenu3.getDefaultFocusedIndex)(items));
|
|
45
45
|
const [isContentShown, setIsContentShown] = (0, _react2.useState)(false);
|
|
46
46
|
const [portal, setPortal] = (0, _react2.useState)();
|
|
47
47
|
const uuid = (0, _uuid.useUuid)();
|
|
@@ -50,9 +50,9 @@ const ContextMenu = /*#__PURE__*/(0, _react2.forwardRef)(({
|
|
|
50
50
|
const isTouch = (0, _environment.useIsTouch)();
|
|
51
51
|
(0, _react2.useEffect)(() => {
|
|
52
52
|
if (isContentShown) {
|
|
53
|
-
setFocusedIndex(0);
|
|
53
|
+
setFocusedIndex((0, _ContextMenu3.getDefaultFocusedIndex)(items));
|
|
54
54
|
}
|
|
55
|
-
}, [isContentShown]);
|
|
55
|
+
}, [isContentShown, items]);
|
|
56
56
|
(0, _react2.useEffect)(() => {
|
|
57
57
|
if (contextMenuRef.current && !container) {
|
|
58
58
|
const el = contextMenuRef.current;
|
|
@@ -144,14 +144,14 @@ const ContextMenu = /*#__PURE__*/(0, _react2.forwardRef)(({
|
|
|
144
144
|
});
|
|
145
145
|
if (x < width / 2) {
|
|
146
146
|
if (y < height / 2) {
|
|
147
|
-
setInternalAlignment(
|
|
147
|
+
setInternalAlignment(_ContextMenu2.ContextMenuAlignment.BottomRight);
|
|
148
148
|
} else {
|
|
149
|
-
setInternalAlignment(
|
|
149
|
+
setInternalAlignment(_ContextMenu2.ContextMenuAlignment.TopRight);
|
|
150
150
|
}
|
|
151
151
|
} else if (y < height / 2) {
|
|
152
|
-
setInternalAlignment(
|
|
152
|
+
setInternalAlignment(_ContextMenu2.ContextMenuAlignment.BottomLeft);
|
|
153
153
|
} else {
|
|
154
|
-
setInternalAlignment(
|
|
154
|
+
setInternalAlignment(_ContextMenu2.ContextMenuAlignment.TopLeft);
|
|
155
155
|
}
|
|
156
156
|
setIsContentShown(true);
|
|
157
157
|
}
|
|
@@ -199,7 +199,6 @@ const ContextMenu = /*#__PURE__*/(0, _react2.forwardRef)(({
|
|
|
199
199
|
}, isContentShown && /*#__PURE__*/_react2.default.createElement(_ContextMenuContent.default, {
|
|
200
200
|
coordinates: coordinates ?? internalCoordinates,
|
|
201
201
|
items: items,
|
|
202
|
-
shouldSeparateLastItem: shouldSeparateLastItem,
|
|
203
202
|
zIndex: zIndex,
|
|
204
203
|
headline: headline,
|
|
205
204
|
shouldHidePopupArrow: shouldHidePopupArrow,
|
|
@@ -215,7 +214,7 @@ const ContextMenu = /*#__PURE__*/(0, _react2.forwardRef)(({
|
|
|
215
214
|
}
|
|
216
215
|
}
|
|
217
216
|
})), newContainer));
|
|
218
|
-
}, [alignment, newContainer, coordinates, internalAlignment, internalCoordinates, isContentShown, items, uuid, zIndex, shouldHidePopupArrow, headline,
|
|
217
|
+
}, [alignment, newContainer, coordinates, internalAlignment, internalCoordinates, isContentShown, items, uuid, zIndex, shouldHidePopupArrow, headline, focusedIndex, handleHide]);
|
|
219
218
|
return /*#__PURE__*/_react2.default.createElement(_react2.default.Fragment, null, /*#__PURE__*/_react2.default.createElement(_ContextMenu.StyledContextMenu, {
|
|
220
219
|
className: "beta-chayns-context-menu",
|
|
221
220
|
$isActive: isContentShown && shouldShowHoverEffect,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenu.js","names":["_chaynsApi","require","_react","_react2","_interopRequireWildcard","_reactDom","_uuid","_contextMenu","_environment","_Icon","_interopRequireDefault","_ContextMenuContent","_ContextMenu","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ContextMenu","forwardRef","alignment","children","createElement","icons","size","container","coordinates","shouldHidePopupArrow","items","headline","onHide","shouldDisableClick","onShow","shouldCloseOnPopupClick","shouldSeparateLastItem","shouldShowHoverEffect","zIndex","ref","internalCoordinates","setInternalCoordinates","useState","x","y","newContainer","setNewContainer","focusedIndex","setFocusedIndex","internalAlignment","setInternalAlignment","ContextMenuAlignment","TopLeft","isContentShown","setIsContentShown","portal","setPortal","uuid","useUuid","contextMenuContentRef","useRef","contextMenuRef","isTouch","useIsTouch","useEffect","current","el","element","closest","Element","handleHide","useCallback","handleKey","key","preventDefault","prev","Math","min","length","max","item","onClick","document","addEventListener","removeEventListener","handleShow","result","createDialog","type","DialogType","SELECT","buttons","list","map","text","isSelected","index","name","id","icon","isValidElement","undefined","open","_items$result$","height","childrenHeight","left","childrenLeft","top","childrenTop","width","childrenWidth","getBoundingClientRect","zoomX","offsetWidth","zoomY","offsetHeight","scrollLeft","scrollTop","BottomRight","TopRight","BottomLeft","handleClick","event","stopPropagation","handleDocumentClick","_contextMenuContentRe","contains","target","useImperativeHandle","hide","show","window","createPortal","AnimatePresence","initial","onKeySelect","Fragment","StyledContextMenu","className","$isActive","$shouldAddHoverEffect","displayName","_default","exports"],"sources":["../../../../src/components/context-menu/ContextMenu.tsx"],"sourcesContent":["import { createDialog, DialogType } from 'chayns-api';\nimport { AnimatePresence } from 'motion/react';\nimport React, {\n forwardRef,\n isValidElement,\n MouseEvent,\n MouseEventHandler,\n ReactNode,\n ReactPortal,\n useCallback,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { useUuid } from '../../hooks/uuid';\nimport { ContextMenuAlignment } from '../../types/contextMenu';\nimport { useIsTouch } from '../../utils/environment';\nimport Icon from '../icon/Icon';\nimport ContextMenuContent from './context-menu-content/ContextMenuContent';\nimport { StyledContextMenu } from './ContextMenu.styles';\n\nexport type ContextMenuCoordinates = {\n x: number;\n y: number;\n};\n\nexport type ContextMenuItem = {\n icons: string[] | ReactNode;\n key: string;\n onClick: (event?: MouseEvent<HTMLDivElement>) => Promise<void> | void;\n isSelected?: boolean;\n text: string;\n shouldShowSpacer?: boolean;\n};\n\nexport interface ContextMenuRef {\n hide: VoidFunction;\n show: VoidFunction;\n}\n\ntype ContextMenuProps = {\n /**\n * Optional custom alignment used instead of calculating it using the\n * alignment within the page. The available alignment can be taken from the\n * ContextMenuAlignment enum.\n */\n alignment?: ContextMenuAlignment;\n /**\n * The element over which the content of the `ContextMenu` should be displayed. The default is an ellipsis icon.\n */\n children?: ReactNode;\n /**\n * The element where the content of the `ContextMenu` should be rendered via React Portal.\n */\n container?: Element;\n /**\n * Optional own coordinates to be used instead of calculating the alignment\n * based on the alignment of the children.\n */\n coordinates?: ContextMenuCoordinates;\n /**\n * The headline of the contextmenu.\n */\n headline?: string;\n /**\n * The items that will be displayed in the content of the `ContextMenu`. Custom icon elements only works on desktop.\n */\n items: ContextMenuItem[];\n /**\n * Function to be executed when the content of the Context menu has been hidden.\n */\n onHide?: VoidFunction;\n /**\n * Function to be executed when the content of the Context menu has been shown.\n */\n onShow?: VoidFunction;\n /**\n * Whether the popup should be closed if its clicked.\n */\n shouldCloseOnPopupClick?: boolean;\n /**\n * Whether the arrow of the popup should be hidden.\n */\n shouldHidePopupArrow?: boolean;\n /**\n * Whether the last item should be separated.\n */\n shouldSeparateLastItem?: boolean;\n /**\n * Whether the hover effect should be shown.\n */\n shouldShowHoverEffect?: boolean;\n /**\n * Whether the click should be disabled.\n */\n shouldDisableClick?: boolean;\n /**\n * The z-index of the popup.\n */\n zIndex?: number;\n};\n\ninterface SelectDialogResult {\n buttonType: number;\n result: number[];\n}\n\nconst ContextMenu = forwardRef<ContextMenuRef, ContextMenuProps>(\n (\n {\n alignment,\n children = <Icon icons={['ts-ellipsis_v']} size={18} />,\n container,\n coordinates,\n shouldHidePopupArrow = false,\n items,\n headline,\n onHide,\n shouldDisableClick = false,\n onShow,\n shouldCloseOnPopupClick = true,\n shouldSeparateLastItem = false,\n shouldShowHoverEffect = false,\n zIndex = 20,\n },\n ref,\n ) => {\n const [internalCoordinates, setInternalCoordinates] = useState<ContextMenuCoordinates>({\n x: 0,\n y: 0,\n });\n const [newContainer, setNewContainer] = useState<Element | null>(container ?? null);\n const [focusedIndex, setFocusedIndex] = useState<number>(0);\n\n const [internalAlignment, setInternalAlignment] = useState<ContextMenuAlignment>(\n ContextMenuAlignment.TopLeft,\n );\n\n const [isContentShown, setIsContentShown] = useState(false);\n const [portal, setPortal] = useState<ReactPortal>();\n\n const uuid = useUuid();\n\n const contextMenuContentRef = useRef<HTMLDivElement>(null);\n const contextMenuRef = useRef<HTMLSpanElement>(null);\n\n const isTouch = useIsTouch();\n\n useEffect(() => {\n if (isContentShown) {\n setFocusedIndex(0);\n }\n }, [isContentShown]);\n\n useEffect(() => {\n if (contextMenuRef.current && !container) {\n const el = contextMenuRef.current as HTMLElement;\n\n const element = el.closest('.dialog-inner, .page-provider, .tapp, body');\n\n setNewContainer(element);\n }\n }, [container]);\n\n useEffect(() => {\n if (container instanceof Element) {\n setNewContainer(container);\n }\n }, [container]);\n\n const handleHide = useCallback(() => {\n setIsContentShown(false);\n }, []);\n\n useEffect(() => {\n if (!isContentShown) return () => {};\n\n const handleKey = (e: KeyboardEvent) => {\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setFocusedIndex((prev) => Math.min(prev + 1, items.length - 1));\n }\n\n if (e.key === 'ArrowUp') {\n e.preventDefault();\n setFocusedIndex((prev) => Math.max(prev - 1, 0));\n }\n\n if (e.key === 'Enter') {\n e.preventDefault();\n const item = items[focusedIndex];\n if (item) {\n void item.onClick();\n\n if (shouldCloseOnPopupClick) {\n handleHide();\n }\n }\n }\n\n if (e.key === 'Escape') {\n handleHide();\n }\n };\n\n document.addEventListener('keydown', handleKey);\n\n return () => document.removeEventListener('keydown', handleKey);\n }, [isContentShown, items, focusedIndex, handleHide, shouldCloseOnPopupClick]);\n\n const handleShow = useCallback(async () => {\n if (isTouch) {\n const { result } = (await createDialog({\n type: DialogType.SELECT,\n buttons: [],\n list: items.map(({ icons, text, isSelected }, index) => ({\n name: text,\n id: index,\n isSelected,\n icon: isValidElement(icons) ? undefined : (icons as string)[0],\n })),\n }).open()) as SelectDialogResult;\n\n if (result && typeof result[0] === 'number') {\n void items[result[0]]?.onClick();\n }\n } else if (contextMenuRef.current) {\n if (!newContainer) {\n return;\n }\n\n const {\n height: childrenHeight,\n left: childrenLeft,\n top: childrenTop,\n width: childrenWidth,\n } = contextMenuRef.current.getBoundingClientRect();\n\n const { height, width, top, left } = newContainer.getBoundingClientRect();\n\n const zoomX = width / (newContainer as HTMLElement).offsetWidth;\n const zoomY = height / (newContainer as HTMLElement).offsetHeight;\n\n const x =\n (childrenLeft + childrenWidth / 2 - left) / zoomX + newContainer.scrollLeft;\n const y = (childrenTop + childrenHeight / 2 - top) / zoomY + newContainer.scrollTop;\n\n setInternalCoordinates({ x, y });\n\n if (x < width / 2) {\n if (y < height / 2) {\n setInternalAlignment(ContextMenuAlignment.BottomRight);\n } else {\n setInternalAlignment(ContextMenuAlignment.TopRight);\n }\n } else if (y < height / 2) {\n setInternalAlignment(ContextMenuAlignment.BottomLeft);\n } else {\n setInternalAlignment(ContextMenuAlignment.TopLeft);\n }\n\n setIsContentShown(true);\n }\n }, [isTouch, items, newContainer]);\n\n const handleClick = useCallback<MouseEventHandler<HTMLDivElement>>(\n (event) => {\n if (shouldDisableClick) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n void handleShow();\n },\n [handleShow, shouldDisableClick],\n );\n\n const handleDocumentClick = useCallback<EventListener>(\n (event) => {\n if (\n !shouldCloseOnPopupClick &&\n contextMenuContentRef.current?.contains(event.target as Node)\n ) {\n return;\n }\n\n handleHide();\n },\n [handleHide, shouldCloseOnPopupClick],\n );\n\n useImperativeHandle(\n ref,\n () => ({\n hide: handleHide,\n show: handleShow,\n }),\n [handleHide, handleShow],\n );\n\n useEffect(() => {\n if (isContentShown) {\n document.addEventListener('click', handleDocumentClick, true);\n window.addEventListener('blur', handleHide);\n\n if (typeof onShow === 'function') {\n onShow();\n }\n } else if (typeof onHide === 'function') {\n onHide();\n }\n\n return () => {\n document.removeEventListener('click', handleDocumentClick, true);\n window.removeEventListener('blur', handleHide);\n };\n }, [handleDocumentClick, handleHide, isContentShown, onHide, onShow]);\n\n useEffect(() => {\n if (!newContainer) {\n return;\n }\n\n setPortal(() =>\n createPortal(\n <AnimatePresence initial={false}>\n {isContentShown && (\n <ContextMenuContent\n coordinates={coordinates ?? internalCoordinates}\n items={items}\n shouldSeparateLastItem={shouldSeparateLastItem}\n zIndex={zIndex}\n headline={headline}\n shouldHidePopupArrow={shouldHidePopupArrow}\n key={`contextMenu_${uuid}`}\n alignment={alignment ?? internalAlignment}\n ref={contextMenuContentRef}\n focusedIndex={focusedIndex}\n onKeySelect={(index) => {\n const item = items[index];\n if (item) {\n void item.onClick();\n handleHide();\n }\n }}\n />\n )}\n </AnimatePresence>,\n newContainer,\n ),\n );\n }, [\n alignment,\n newContainer,\n coordinates,\n internalAlignment,\n internalCoordinates,\n isContentShown,\n items,\n uuid,\n zIndex,\n shouldHidePopupArrow,\n headline,\n shouldSeparateLastItem,\n focusedIndex,\n handleHide,\n ]);\n\n return (\n <>\n <StyledContextMenu\n className=\"beta-chayns-context-menu\"\n $isActive={isContentShown && shouldShowHoverEffect}\n $shouldAddHoverEffect={!isTouch && shouldShowHoverEffect}\n onClick={handleClick}\n ref={contextMenuRef}\n >\n {children}\n </StyledContextMenu>\n {portal}\n </>\n );\n },\n);\n\nContextMenu.displayName = 'ContextMenu';\n\nexport default ContextMenu;\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAC,uBAAA,CAAAH,OAAA;AAaA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AACA,IAAAO,YAAA,GAAAP,OAAA;AACA,IAAAQ,KAAA,GAAAC,sBAAA,CAAAT,OAAA;AACA,IAAAU,mBAAA,GAAAD,sBAAA,CAAAT,OAAA;AACA,IAAAW,YAAA,GAAAX,OAAA;AAAyD,SAAAS,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAT,wBAAAS,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CA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YAAY,EACZuB,UAAU,CACb,CAAC;EAEF,oBACI/E,OAAA,CAAAY,OAAA,CAAAqB,aAAA,CAAAjC,OAAA,CAAAY,OAAA,CAAAsI,QAAA,qBACIlJ,OAAA,CAAAY,OAAA,CAAAqB,aAAA,CAACxB,YAAA,CAAA0I,iBAAiB;IACdC,SAAS,EAAC,0BAA0B;IACpCC,SAAS,EAAEvF,cAAc,IAAIhB,qBAAsB;IACnDwG,qBAAqB,EAAE,CAAC/E,OAAO,IAAIzB,qBAAsB;IACzD4C,OAAO,EAAEyC,WAAY;IACrBnF,GAAG,EAAEsB;EAAe,GAEnBtC,QACc,CAAC,EACnBgC,MACH,CAAC;AAEX,CACJ,CAAC;AAEDnC,WAAW,CAAC0H,WAAW,GAAG,aAAa;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA7I,OAAA,GAEzBiB,WAAW","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"ContextMenu.js","names":["_chaynsApi","require","_react","_react2","_interopRequireWildcard","_reactDom","_uuid","_environment","_Icon","_interopRequireDefault","_ContextMenuContent","_ContextMenu","_ContextMenu2","_ContextMenu3","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ContextMenu","forwardRef","alignment","children","createElement","icons","size","container","coordinates","headline","items","onHide","onShow","shouldCloseOnPopupClick","shouldDisableClick","shouldHidePopupArrow","shouldShowHoverEffect","zIndex","ref","internalCoordinates","setInternalCoordinates","useState","x","y","internalAlignment","setInternalAlignment","ContextMenuAlignment","TopLeft","newContainer","setNewContainer","focusedIndex","setFocusedIndex","getDefaultFocusedIndex","isContentShown","setIsContentShown","portal","setPortal","uuid","useUuid","contextMenuContentRef","useRef","contextMenuRef","isTouch","useIsTouch","useEffect","current","el","element","closest","Element","handleHide","useCallback","handleKey","key","preventDefault","prev","Math","min","length","max","item","onClick","document","addEventListener","removeEventListener","handleShow","result","createDialog","type","DialogType","SELECT","buttons","list","map","text","isSelected","index","name","id","icon","isValidElement","undefined","open","_items$result$","height","childrenHeight","left","childrenLeft","top","childrenTop","width","childrenWidth","getBoundingClientRect","zoomX","offsetWidth","zoomY","offsetHeight","scrollLeft","scrollTop","BottomRight","TopRight","BottomLeft","handleClick","event","stopPropagation","handleDocumentClick","_contextMenuContentRe","contains","target","useImperativeHandle","hide","show","window","createPortal","AnimatePresence","initial","onKeySelect","Fragment","StyledContextMenu","className","$isActive","$shouldAddHoverEffect","displayName","_default","exports"],"sources":["../../../../src/components/context-menu/ContextMenu.tsx"],"sourcesContent":["import { createDialog, DialogType } from 'chayns-api';\nimport { AnimatePresence } from 'motion/react';\nimport React, {\n forwardRef,\n isValidElement,\n MouseEventHandler,\n ReactPortal,\n useCallback,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { useUuid } from '../../hooks/uuid';\nimport { useIsTouch } from '../../utils/environment';\nimport Icon from '../icon/Icon';\nimport ContextMenuContent from './context-menu-content/ContextMenuContent';\nimport { StyledContextMenu } from './ContextMenu.styles';\nimport {\n ContextMenuAlignment,\n type ContextMenuCoordinates,\n type ContextMenuProps,\n type ContextMenuRef,\n} from './ContextMenu.types';\nimport { SelectDialogResult } from '../../types/general';\nimport { getDefaultFocusedIndex } from './ContextMenu.utils';\n\nconst ContextMenu = forwardRef<ContextMenuRef, ContextMenuProps>(\n (\n {\n alignment,\n children = <Icon icons={['ts-ellipsis_v']} size={18} />,\n container,\n coordinates,\n headline,\n items,\n onHide,\n onShow,\n shouldCloseOnPopupClick = true,\n shouldDisableClick = false,\n shouldHidePopupArrow = false,\n shouldShowHoverEffect = false,\n zIndex = 20,\n },\n ref,\n ) => {\n const [internalCoordinates, setInternalCoordinates] = useState<ContextMenuCoordinates>({\n x: 0,\n y: 0,\n });\n\n const [internalAlignment, setInternalAlignment] = useState<ContextMenuAlignment>(\n ContextMenuAlignment.TopLeft,\n );\n\n const [newContainer, setNewContainer] = useState(container ?? null);\n const [focusedIndex, setFocusedIndex] = useState(getDefaultFocusedIndex(items));\n const [isContentShown, setIsContentShown] = useState(false);\n const [portal, setPortal] = useState<ReactPortal>();\n\n const uuid = useUuid();\n\n const contextMenuContentRef = useRef<HTMLDivElement>(null);\n const contextMenuRef = useRef<HTMLSpanElement>(null);\n\n const isTouch = useIsTouch();\n\n useEffect(() => {\n if (isContentShown) {\n setFocusedIndex(getDefaultFocusedIndex(items));\n }\n }, [isContentShown, items]);\n\n useEffect(() => {\n if (contextMenuRef.current && !container) {\n const el = contextMenuRef.current as HTMLElement;\n\n const element = el.closest('.dialog-inner, .page-provider, .tapp, body');\n\n setNewContainer(element);\n }\n }, [container]);\n\n useEffect(() => {\n if (container instanceof Element) {\n setNewContainer(container);\n }\n }, [container]);\n\n const handleHide = useCallback(() => {\n setIsContentShown(false);\n }, []);\n\n useEffect(() => {\n if (!isContentShown) return () => {};\n\n const handleKey = (e: KeyboardEvent) => {\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setFocusedIndex((prev) => Math.min(prev + 1, items.length - 1));\n }\n\n if (e.key === 'ArrowUp') {\n e.preventDefault();\n setFocusedIndex((prev) => Math.max(prev - 1, 0));\n }\n\n if (e.key === 'Enter') {\n e.preventDefault();\n const item = items[focusedIndex];\n if (item) {\n void item.onClick();\n\n if (shouldCloseOnPopupClick) {\n handleHide();\n }\n }\n }\n\n if (e.key === 'Escape') {\n handleHide();\n }\n };\n\n document.addEventListener('keydown', handleKey);\n\n return () => document.removeEventListener('keydown', handleKey);\n }, [isContentShown, items, focusedIndex, handleHide, shouldCloseOnPopupClick]);\n\n const handleShow = useCallback(async () => {\n if (isTouch) {\n const { result } = (await createDialog({\n type: DialogType.SELECT,\n buttons: [],\n list: items.map(({ icons, text, isSelected }, index) => ({\n name: text,\n id: index,\n isSelected,\n icon: isValidElement(icons) ? undefined : (icons as string)[0],\n })),\n }).open()) as SelectDialogResult;\n\n if (result && typeof result[0] === 'number') {\n void items[result[0]]?.onClick();\n }\n } else if (contextMenuRef.current) {\n if (!newContainer) {\n return;\n }\n\n const {\n height: childrenHeight,\n left: childrenLeft,\n top: childrenTop,\n width: childrenWidth,\n } = contextMenuRef.current.getBoundingClientRect();\n\n const { height, width, top, left } = newContainer.getBoundingClientRect();\n\n const zoomX = width / (newContainer as HTMLElement).offsetWidth;\n const zoomY = height / (newContainer as HTMLElement).offsetHeight;\n\n const x =\n (childrenLeft + childrenWidth / 2 - left) / zoomX + newContainer.scrollLeft;\n const y = (childrenTop + childrenHeight / 2 - top) / zoomY + newContainer.scrollTop;\n\n setInternalCoordinates({ x, y });\n\n if (x < width / 2) {\n if (y < height / 2) {\n setInternalAlignment(ContextMenuAlignment.BottomRight);\n } else {\n setInternalAlignment(ContextMenuAlignment.TopRight);\n }\n } else if (y < height / 2) {\n setInternalAlignment(ContextMenuAlignment.BottomLeft);\n } else {\n setInternalAlignment(ContextMenuAlignment.TopLeft);\n }\n\n setIsContentShown(true);\n }\n }, [isTouch, items, newContainer]);\n\n const handleClick = useCallback<MouseEventHandler<HTMLDivElement>>(\n (event) => {\n if (shouldDisableClick) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n void handleShow();\n },\n [handleShow, shouldDisableClick],\n );\n\n const handleDocumentClick = useCallback<EventListener>(\n (event) => {\n if (\n !shouldCloseOnPopupClick &&\n contextMenuContentRef.current?.contains(event.target as Node)\n ) {\n return;\n }\n\n handleHide();\n },\n [handleHide, shouldCloseOnPopupClick],\n );\n\n useImperativeHandle(\n ref,\n () => ({\n hide: handleHide,\n show: handleShow,\n }),\n [handleHide, handleShow],\n );\n\n useEffect(() => {\n if (isContentShown) {\n document.addEventListener('click', handleDocumentClick, true);\n window.addEventListener('blur', handleHide);\n\n if (typeof onShow === 'function') {\n onShow();\n }\n } else if (typeof onHide === 'function') {\n onHide();\n }\n\n return () => {\n document.removeEventListener('click', handleDocumentClick, true);\n window.removeEventListener('blur', handleHide);\n };\n }, [handleDocumentClick, handleHide, isContentShown, onHide, onShow]);\n\n useEffect(() => {\n if (!newContainer) {\n return;\n }\n\n setPortal(() =>\n createPortal(\n <AnimatePresence initial={false}>\n {isContentShown && (\n <ContextMenuContent\n coordinates={coordinates ?? internalCoordinates}\n items={items}\n zIndex={zIndex}\n headline={headline}\n shouldHidePopupArrow={shouldHidePopupArrow}\n key={`contextMenu_${uuid}`}\n alignment={alignment ?? internalAlignment}\n ref={contextMenuContentRef}\n focusedIndex={focusedIndex}\n onKeySelect={(index) => {\n const item = items[index];\n if (item) {\n void item.onClick();\n handleHide();\n }\n }}\n />\n )}\n </AnimatePresence>,\n newContainer,\n ),\n );\n }, [\n alignment,\n newContainer,\n coordinates,\n internalAlignment,\n internalCoordinates,\n isContentShown,\n items,\n uuid,\n zIndex,\n shouldHidePopupArrow,\n headline,\n focusedIndex,\n handleHide,\n ]);\n\n return (\n <>\n <StyledContextMenu\n className=\"beta-chayns-context-menu\"\n $isActive={isContentShown && shouldShowHoverEffect}\n $shouldAddHoverEffect={!isTouch && shouldShowHoverEffect}\n onClick={handleClick}\n ref={contextMenuRef}\n >\n {children}\n </StyledContextMenu>\n {portal}\n </>\n );\n },\n);\n\nContextMenu.displayName = 'ContextMenu';\n\nexport default ContextMenu;\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAC,uBAAA,CAAAH,OAAA;AAWA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAC,sBAAA,CAAAR,OAAA;AACA,IAAAS,mBAAA,GAAAD,sBAAA,CAAAR,OAAA;AACA,IAAAU,YAAA,GAAAV,OAAA;AACA,IAAAW,aAAA,GAAAX,OAAA;AAOA,IAAAY,aAAA,GAAAZ,OAAA;AAA6D,SAAAQ,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC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YAAY,EACZpB,WAAW,EACXgB,iBAAiB,EACjBL,mBAAmB,EACnBc,cAAc,EACdvB,KAAK,EACL2B,IAAI,EACJpB,MAAM,EACNF,oBAAoB,EACpBN,QAAQ,EACRqB,YAAY,EACZoB,UAAU,CACb,CAAC;EAEF,oBACIhF,OAAA,CAAAa,OAAA,CAAAqB,aAAA,CAAAlC,OAAA,CAAAa,OAAA,CAAAsI,QAAA,qBACInJ,OAAA,CAAAa,OAAA,CAAAqB,aAAA,CAAC1B,YAAA,CAAA4I,iBAAiB;IACdC,SAAS,EAAC,0BAA0B;IACpCC,SAAS,EAAEvF,cAAc,IAAIjB,qBAAsB;IACnDyG,qBAAqB,EAAE,CAAC/E,OAAO,IAAI1B,qBAAsB;IACzD6C,OAAO,EAAEyC,WAAY;IACrBpF,GAAG,EAAEuB;EAAe,GAEnBtC,QACc,CAAC,EACnBgC,MACH,CAAC;AAEX,CACJ,CAAC;AAEDnC,WAAW,CAAC0H,WAAW,GAAG,aAAa;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA7I,OAAA,GAEzBiB,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ContextMenuAlignment = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Enum representing the possible alignments for the context menu.
|
|
9
|
+
*/
|
|
10
|
+
let ContextMenuAlignment = exports.ContextMenuAlignment = /*#__PURE__*/function (ContextMenuAlignment) {
|
|
11
|
+
ContextMenuAlignment[ContextMenuAlignment["TopLeft"] = 0] = "TopLeft";
|
|
12
|
+
ContextMenuAlignment[ContextMenuAlignment["BottomLeft"] = 1] = "BottomLeft";
|
|
13
|
+
ContextMenuAlignment[ContextMenuAlignment["TopRight"] = 2] = "TopRight";
|
|
14
|
+
ContextMenuAlignment[ContextMenuAlignment["BottomRight"] = 3] = "BottomRight";
|
|
15
|
+
ContextMenuAlignment[ContextMenuAlignment["TopCenter"] = 4] = "TopCenter";
|
|
16
|
+
ContextMenuAlignment[ContextMenuAlignment["BottomCenter"] = 5] = "BottomCenter";
|
|
17
|
+
return ContextMenuAlignment;
|
|
18
|
+
}({});
|
|
19
|
+
/**
|
|
20
|
+
* Type representing the coordinates for positioning the context menu.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Type representing an item in the context menu.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Props for the ContextMenu component.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Ref interface for the ContextMenu component.
|
|
30
|
+
*/
|
|
31
|
+
//# sourceMappingURL=ContextMenu.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextMenu.types.js","names":["ContextMenuAlignment","exports"],"sources":["../../../../src/components/context-menu/ContextMenu.types.ts"],"sourcesContent":["import type { MouseEvent, ReactNode } from 'react';\n\n/**\n * Enum representing the possible alignments for the context menu.\n */\nexport enum ContextMenuAlignment {\n TopLeft,\n BottomLeft,\n TopRight,\n BottomRight,\n TopCenter,\n BottomCenter,\n}\n\n/**\n * Type representing the coordinates for positioning the context menu.\n */\nexport type ContextMenuCoordinates = {\n /** The x-coordinate. */\n x: number;\n /** The y-coordinate. */\n y: number;\n};\n\n/**\n * Type representing an item in the context menu.\n */\nexport type ContextMenuItem = {\n /** Optional icons for the item. Can be strings or React nodes. */\n icons?: string[] | ReactNode;\n /** Whether the item is selected. */\n isSelected?: boolean;\n /** Unique key for the item. */\n key: string;\n /** Function called when the item is clicked. */\n onClick: (event?: MouseEvent<HTMLDivElement>) => Promise<void> | void;\n /** Whether to show a spacer after the item. */\n shouldShowSpacer?: boolean;\n /** The text displayed for the item. */\n text: string;\n};\n\n/**\n * Props for the ContextMenu component.\n */\nexport type ContextMenuProps = {\n /**\n * Context menu alignment\n * @description Optional custom alignment used instead of calculating it using the alignment\n * within the page. The available alignments can be taken from the ContextMenuAlignment enum.\n * @example alignment={ContextMenuAlignment.TopLeft}\n * @optional\n */\n alignment?: ContextMenuAlignment;\n /**\n * Children element\n * @description The element over which the content of the ContextMenu should be displayed.\n * @example children={<Icon icons={['fa fa-paper-clip']} />\n * @default <Icon icons={['ts-ellipsis_v']} size={18} />\n * @optional\n */\n children?: ReactNode;\n /**\n * Container element\n * @description The element where the content of the ContextMenu should be rendered via React Portal.\n * @example container={document.body}\n * @optional\n */\n container?: Element;\n /**\n * Custom coordinates\n * @description Optional own coordinates to be used instead of calculating the alignment based\n * on the alignment of the children.\n * @example coordinates={{ x: 100, y: 200 }}\n * @optional\n */\n coordinates?: ContextMenuCoordinates;\n /**\n * Context menu headline\n * @description The headline of the context menu. If not provided, no headline will be displayed.\n * @example headline=\"Options\"\n * @optional\n */\n headline?: string;\n /**\n * Menu items\n * @description The items that will be displayed in the content of the ContextMenu. Custom icon\n * elements only will be displayed on desktop devices.\n * @example items={[{ key: '1', text: 'Option 1', onClick: () => {} }]}\n */\n items: ContextMenuItem[];\n /**\n * Hide callback function\n * @description Function to be executed when the content of the Context menu has been hidden.\n * @example onHide={() => console.log('Menu hidden')}\n * @optional\n */\n onHide?: VoidFunction;\n /**\n * Show callback function\n * @description Function to be executed when the content of the Context menu has been shown.\n * @example onShow={() => console.log('Menu shown')}\n * @optional\n */\n onShow?: VoidFunction;\n /**\n * Close on popup click flag\n * @description Whether the popup should be closed if it is clicked.\n * @default true\n * @optional\n */\n shouldCloseOnPopupClick?: boolean;\n /**\n * Disable click flag\n * @description Whether the click should be disabled.\n * @default false\n * @optional\n */\n shouldDisableClick?: boolean;\n /**\n * Hide popup arrow flag\n * @description Whether the arrow of the popup should be hidden.\n * @default false\n * @optional\n */\n shouldHidePopupArrow?: boolean;\n /**\n * Show hover effect flag\n * @description Whether the hover effect should be shown.\n * @default false\n * @optional\n */\n shouldShowHoverEffect?: boolean;\n /**\n * Z-index value\n * @description The z-index of the popup.\n * @example zIndex={100}\n * @default 20\n * @optional\n */\n zIndex?: number;\n};\n\n/**\n * Ref interface for the ContextMenu component.\n */\nexport interface ContextMenuRef {\n /** Hides the context menu. */\n hide: VoidFunction;\n /** Shows the context menu. */\n show: VoidFunction;\n}\n"],"mappings":";;;;;;AAEA;AACA;AACA;AAFA,IAGYA,oBAAoB,GAAAC,OAAA,CAAAD,oBAAA,0BAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAAA,OAApBA,oBAAoB;AAAA;AAShC;AACA;AACA;AAQA;AACA;AACA;AAgBA;AACA;AACA;AAmGA;AACA;AACA","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDefaultFocusedIndex = void 0;
|
|
7
|
+
const getDefaultFocusedIndex = items => {
|
|
8
|
+
const firstSelectedIndex = items.findIndex(item => item.isSelected);
|
|
9
|
+
return firstSelectedIndex !== -1 ? firstSelectedIndex : 0;
|
|
10
|
+
};
|
|
11
|
+
exports.getDefaultFocusedIndex = getDefaultFocusedIndex;
|
|
12
|
+
//# sourceMappingURL=ContextMenu.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextMenu.utils.js","names":["getDefaultFocusedIndex","items","firstSelectedIndex","findIndex","item","isSelected","exports"],"sources":["../../../../src/components/context-menu/ContextMenu.utils.ts"],"sourcesContent":["import type { ContextMenuItem } from './ContextMenu.types';\n\nexport const getDefaultFocusedIndex = (items: ContextMenuItem[]): number => {\n const firstSelectedIndex = items.findIndex((item) => item.isSelected);\n\n return firstSelectedIndex !== -1 ? firstSelectedIndex : 0;\n};\n"],"mappings":";;;;;;AAEO,MAAMA,sBAAsB,GAAIC,KAAwB,IAAa;EACxE,MAAMC,kBAAkB,GAAGD,KAAK,CAACE,SAAS,CAAEC,IAAI,IAAKA,IAAI,CAACC,UAAU,CAAC;EAErE,OAAOH,kBAAkB,KAAK,CAAC,CAAC,GAAGA,kBAAkB,GAAG,CAAC;AAC7D,CAAC;AAACI,OAAA,CAAAN,sBAAA,GAAAA,sBAAA","ignoreList":[]}
|
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
-
var _contextMenu = require("../../../types/contextMenu");
|
|
9
8
|
var _Icon = _interopRequireDefault(require("../../icon/Icon"));
|
|
10
9
|
var _ContextMenuContent = require("./ContextMenuContent.styles");
|
|
10
|
+
var _ContextMenu = require("../ContextMenu.types");
|
|
11
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
13
|
const ContextMenuContent = /*#__PURE__*/_react.default.forwardRef(({
|
|
@@ -18,14 +18,13 @@ const ContextMenuContent = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
18
18
|
shouldHidePopupArrow,
|
|
19
19
|
headline,
|
|
20
20
|
onKeySelect,
|
|
21
|
-
focusedIndex
|
|
22
|
-
shouldSeparateLastItem
|
|
21
|
+
focusedIndex
|
|
23
22
|
}, ref) => {
|
|
24
|
-
const isBottomLeftAlignment = alignment ===
|
|
25
|
-
const isTopLeftAlignment = alignment ===
|
|
26
|
-
const isTopRightAlignment = alignment ===
|
|
27
|
-
const isTopCenterAlignment = alignment ===
|
|
28
|
-
const isBottomCenterAlignment = alignment ===
|
|
23
|
+
const isBottomLeftAlignment = alignment === _ContextMenu.ContextMenuAlignment.BottomLeft;
|
|
24
|
+
const isTopLeftAlignment = alignment === _ContextMenu.ContextMenuAlignment.TopLeft;
|
|
25
|
+
const isTopRightAlignment = alignment === _ContextMenu.ContextMenuAlignment.TopRight;
|
|
26
|
+
const isTopCenterAlignment = alignment === _ContextMenu.ContextMenuAlignment.TopCenter;
|
|
27
|
+
const isBottomCenterAlignment = alignment === _ContextMenu.ContextMenuAlignment.BottomCenter;
|
|
29
28
|
const percentageOffsetX = (0, _react.useMemo)(() => {
|
|
30
29
|
if (isBottomLeftAlignment || isTopLeftAlignment) {
|
|
31
30
|
return -100;
|
|
@@ -55,7 +54,15 @@ const ContextMenuContent = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
55
54
|
shouldShowSpacer
|
|
56
55
|
}, index) => {
|
|
57
56
|
const isFocused = index === focusedIndex;
|
|
58
|
-
|
|
57
|
+
let iconElement = null;
|
|
58
|
+
if (/*#__PURE__*/(0, _react.isValidElement)(icons)) {
|
|
59
|
+
iconElement = icons;
|
|
60
|
+
} else if (Array.isArray(icons) && icons.length > 0) {
|
|
61
|
+
iconElement = /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemIconWrapper, null, /*#__PURE__*/_react.default.createElement(_Icon.default, {
|
|
62
|
+
icons: icons
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
return /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItem, {
|
|
59
66
|
key: `context-menu-item-${key}`,
|
|
60
67
|
"data-index": index
|
|
61
68
|
}, /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemWrapper, {
|
|
@@ -74,16 +81,8 @@ const ContextMenuContent = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
74
81
|
onKeySelect(index);
|
|
75
82
|
}
|
|
76
83
|
}
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
})), /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemText, null, text)), shouldShowSpacer && /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemSpacer, null));
|
|
80
|
-
if (shouldSeparateLastItem && index + 1 === items.length) {
|
|
81
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
|
|
82
|
-
key: `context-menu-item-${key}`
|
|
83
|
-
}, /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemBorder, null), item);
|
|
84
|
-
}
|
|
85
|
-
return item;
|
|
86
|
-
}), [items, focusedIndex, shouldHidePopupArrow, shouldSeparateLastItem, onKeySelect]);
|
|
84
|
+
}, iconElement, /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemText, null, text)), shouldShowSpacer && /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemSpacer, null));
|
|
85
|
+
}), [items, focusedIndex, shouldHidePopupArrow, onKeySelect]);
|
|
87
86
|
return /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledMotionContextMenuContent, {
|
|
88
87
|
animate: {
|
|
89
88
|
opacity: 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenuContent.js","names":["_react","_interopRequireWildcard","require","_contextMenu","_Icon","_interopRequireDefault","_ContextMenuContent","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ContextMenuContent","React","forwardRef","alignment","coordinates","items","zIndex","shouldHidePopupArrow","headline","onKeySelect","focusedIndex","shouldSeparateLastItem","ref","isBottomLeftAlignment","ContextMenuAlignment","BottomLeft","isTopLeftAlignment","TopLeft","isTopRightAlignment","TopRight","isTopCenterAlignment","TopCenter","isBottomCenterAlignment","BottomCenter","percentageOffsetX","useMemo","anchorOffsetX","percentageOffsetY","anchorOffsetY","exitAndInitialY","content","map","onClick","key","text","icons","shouldShowSpacer","index","isFocused","item","createElement","StyledContextMenuContentItem","StyledContextMenuContentItemWrapper","event","preventDefault","stopPropagation","tabIndex","$shouldHidePopupArrow","$isFocused","onKeyDown","isValidElement","StyledContextMenuContentItemIconWrapper","StyledContextMenuContentItemText","StyledContextMenuContentItemSpacer","length","Fragment","StyledContextMenuContentItemBorder","StyledMotionContextMenuContent","animate","opacity","y","exit","initial","$position","$zIndex","style","left","x","top","transition","ease","transformTemplate","StyledContextMenuContentHeadline","displayName","_default","exports"],"sources":["../../../../../src/components/context-menu/context-menu-content/ContextMenuContent.tsx"],"sourcesContent":["import React, { isValidElement, useMemo } from 'react';\nimport { ContextMenuAlignment } from '../../../types/contextMenu';\nimport Icon from '../../icon/Icon';\nimport type { ContextMenuCoordinates, ContextMenuItem } from '../ContextMenu';\nimport {\n StyledContextMenuContentHeadline,\n StyledContextMenuContentItem,\n StyledContextMenuContentItemBorder,\n StyledContextMenuContentItemIconWrapper,\n StyledContextMenuContentItemSpacer,\n StyledContextMenuContentItemText,\n StyledContextMenuContentItemWrapper,\n StyledMotionContextMenuContent,\n} from './ContextMenuContent.styles';\n\ntype ContextMenuContentProps = {\n alignment: ContextMenuAlignment;\n coordinates: ContextMenuCoordinates;\n items: ContextMenuItem[];\n shouldHidePopupArrow: boolean;\n headline?: string;\n zIndex: number;\n shouldSeparateLastItem: boolean;\n focusedIndex: number;\n onKeySelect: (index: number) => void;\n};\n\nconst ContextMenuContent = React.forwardRef<HTMLDivElement, ContextMenuContentProps>(\n (\n {\n alignment,\n coordinates,\n items,\n zIndex,\n shouldHidePopupArrow,\n headline,\n onKeySelect,\n focusedIndex,\n shouldSeparateLastItem,\n },\n ref,\n ) => {\n const isBottomLeftAlignment = alignment === ContextMenuAlignment.BottomLeft;\n const isTopLeftAlignment = alignment === ContextMenuAlignment.TopLeft;\n const isTopRightAlignment = alignment === ContextMenuAlignment.TopRight;\n const isTopCenterAlignment = alignment === ContextMenuAlignment.TopCenter;\n const isBottomCenterAlignment = alignment === ContextMenuAlignment.BottomCenter;\n\n const percentageOffsetX = useMemo(() => {\n if (isBottomLeftAlignment || isTopLeftAlignment) {\n return -100;\n }\n\n if (isBottomCenterAlignment || isTopCenterAlignment) {\n return -50;\n }\n\n return 0;\n }, [\n isBottomCenterAlignment,\n isBottomLeftAlignment,\n isTopCenterAlignment,\n isTopLeftAlignment,\n ]);\n\n const anchorOffsetX = useMemo(() => {\n if (isBottomLeftAlignment || isTopLeftAlignment) {\n return 15;\n }\n\n if (isBottomCenterAlignment || isTopCenterAlignment) {\n return 0;\n }\n\n return -15;\n }, [\n isBottomCenterAlignment,\n isBottomLeftAlignment,\n isTopCenterAlignment,\n isTopLeftAlignment,\n ]);\n\n const percentageOffsetY =\n isTopRightAlignment || isTopLeftAlignment || isTopCenterAlignment ? -100 : 0;\n\n const anchorOffsetY =\n isTopRightAlignment || isTopLeftAlignment || isTopCenterAlignment ? -21 : 21;\n\n const exitAndInitialY = isTopLeftAlignment || isTopRightAlignment ? -16 : 16;\n\n const content = useMemo(\n () =>\n items.map(({ onClick, key, text, icons, shouldShowSpacer }, index) => {\n const isFocused = index === focusedIndex;\n\n const item = (\n <StyledContextMenuContentItem\n key={`context-menu-item-${key}`}\n data-index={index}\n >\n <StyledContextMenuContentItemWrapper\n key={key}\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n void onClick(event);\n }}\n tabIndex={0}\n $shouldHidePopupArrow={shouldHidePopupArrow}\n $isFocused={isFocused}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n onKeySelect(index);\n }\n }}\n >\n {isValidElement(icons) ? (\n icons\n ) : (\n <StyledContextMenuContentItemIconWrapper>\n <Icon icons={icons as string[]} />\n </StyledContextMenuContentItemIconWrapper>\n )}\n <StyledContextMenuContentItemText>\n {text}\n </StyledContextMenuContentItemText>\n </StyledContextMenuContentItemWrapper>\n\n {shouldShowSpacer && <StyledContextMenuContentItemSpacer />}\n </StyledContextMenuContentItem>\n );\n\n if (shouldSeparateLastItem && index + 1 === items.length) {\n return (\n <React.Fragment key={`context-menu-item-${key}`}>\n <StyledContextMenuContentItemBorder />\n {item}\n </React.Fragment>\n );\n }\n\n return item;\n }),\n [items, focusedIndex, shouldHidePopupArrow, shouldSeparateLastItem, onKeySelect],\n );\n\n return (\n <StyledMotionContextMenuContent\n animate={{ opacity: 1, y: 0 }}\n exit={{ opacity: 0, y: exitAndInitialY }}\n initial={{ opacity: 0, y: exitAndInitialY }}\n $position={alignment}\n $shouldHidePopupArrow={shouldHidePopupArrow}\n $zIndex={zIndex}\n ref={ref}\n style={{ left: coordinates.x, top: coordinates.y }}\n transition={{ ease: 'anticipate' }}\n transformTemplate={({ y = '0px' }) => `\n translateX(${percentageOffsetX}%)\n translateY(${percentageOffsetY}%)\n translateX(${anchorOffsetX}px)\n translateY(${anchorOffsetY}px)\n translateY(${y})\n `}\n >\n {headline && (\n <StyledContextMenuContentHeadline>{headline}</StyledContextMenuContentHeadline>\n )}\n {content}\n </StyledMotionContextMenuContent>\n );\n },\n);\n\nContextMenuContent.displayName = 'ContextMenuContent';\n\nexport default ContextMenuContent;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,IAAAI,mBAAA,GAAAJ,OAAA;AASqC,SAAAG,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAN,wBAAAM,CAAA,EA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AAQ,iBACLlC,MAAA,CAAAS,OAAA,CAAAyD,aAAA,CAAC5D,mBAAA,CAAA4F,gCAAgC,QAAEhE,QAA2C,CACjF,EACAsB,OAC2B,CAAC;AAEzC,CACJ,CAAC;AAED9B,kBAAkB,CAACyE,WAAW,GAAG,oBAAoB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA5F,OAAA,GAEvCiB,kBAAkB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"ContextMenuContent.js","names":["_react","_interopRequireWildcard","require","_Icon","_interopRequireDefault","_ContextMenuContent","_ContextMenu","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ContextMenuContent","React","forwardRef","alignment","coordinates","items","zIndex","shouldHidePopupArrow","headline","onKeySelect","focusedIndex","ref","isBottomLeftAlignment","ContextMenuAlignment","BottomLeft","isTopLeftAlignment","TopLeft","isTopRightAlignment","TopRight","isTopCenterAlignment","TopCenter","isBottomCenterAlignment","BottomCenter","percentageOffsetX","useMemo","anchorOffsetX","percentageOffsetY","anchorOffsetY","exitAndInitialY","content","map","onClick","key","text","icons","shouldShowSpacer","index","isFocused","iconElement","isValidElement","Array","isArray","length","createElement","StyledContextMenuContentItemIconWrapper","StyledContextMenuContentItem","StyledContextMenuContentItemWrapper","event","preventDefault","stopPropagation","tabIndex","$shouldHidePopupArrow","$isFocused","onKeyDown","StyledContextMenuContentItemText","StyledContextMenuContentItemSpacer","StyledMotionContextMenuContent","animate","opacity","y","exit","initial","$position","$zIndex","style","left","x","top","transition","ease","transformTemplate","StyledContextMenuContentHeadline","displayName","_default","exports"],"sources":["../../../../../src/components/context-menu/context-menu-content/ContextMenuContent.tsx"],"sourcesContent":["import React, { isValidElement, useMemo } from 'react';\nimport Icon from '../../icon/Icon';\nimport {\n StyledContextMenuContentHeadline,\n StyledContextMenuContentItem,\n StyledContextMenuContentItemIconWrapper,\n StyledContextMenuContentItemSpacer,\n StyledContextMenuContentItemText,\n StyledContextMenuContentItemWrapper,\n StyledMotionContextMenuContent,\n} from './ContextMenuContent.styles';\nimport {\n ContextMenuAlignment,\n type ContextMenuCoordinates,\n type ContextMenuItem,\n} from '../ContextMenu.types';\n\ntype ContextMenuContentProps = {\n alignment: ContextMenuAlignment;\n coordinates: ContextMenuCoordinates;\n items: ContextMenuItem[];\n shouldHidePopupArrow: boolean;\n headline?: string;\n zIndex: number;\n focusedIndex: number;\n onKeySelect: (index: number) => void;\n};\n\nconst ContextMenuContent = React.forwardRef<HTMLDivElement, ContextMenuContentProps>(\n (\n {\n alignment,\n coordinates,\n items,\n zIndex,\n shouldHidePopupArrow,\n headline,\n onKeySelect,\n focusedIndex,\n },\n ref,\n ) => {\n const isBottomLeftAlignment = alignment === ContextMenuAlignment.BottomLeft;\n const isTopLeftAlignment = alignment === ContextMenuAlignment.TopLeft;\n const isTopRightAlignment = alignment === ContextMenuAlignment.TopRight;\n const isTopCenterAlignment = alignment === ContextMenuAlignment.TopCenter;\n const isBottomCenterAlignment = alignment === ContextMenuAlignment.BottomCenter;\n\n const percentageOffsetX = useMemo(() => {\n if (isBottomLeftAlignment || isTopLeftAlignment) {\n return -100;\n }\n\n if (isBottomCenterAlignment || isTopCenterAlignment) {\n return -50;\n }\n\n return 0;\n }, [\n isBottomCenterAlignment,\n isBottomLeftAlignment,\n isTopCenterAlignment,\n isTopLeftAlignment,\n ]);\n\n const anchorOffsetX = useMemo(() => {\n if (isBottomLeftAlignment || isTopLeftAlignment) {\n return 15;\n }\n\n if (isBottomCenterAlignment || isTopCenterAlignment) {\n return 0;\n }\n\n return -15;\n }, [\n isBottomCenterAlignment,\n isBottomLeftAlignment,\n isTopCenterAlignment,\n isTopLeftAlignment,\n ]);\n\n const percentageOffsetY =\n isTopRightAlignment || isTopLeftAlignment || isTopCenterAlignment ? -100 : 0;\n\n const anchorOffsetY =\n isTopRightAlignment || isTopLeftAlignment || isTopCenterAlignment ? -21 : 21;\n\n const exitAndInitialY = isTopLeftAlignment || isTopRightAlignment ? -16 : 16;\n\n const content = useMemo(\n () =>\n items.map(({ onClick, key, text, icons, shouldShowSpacer }, index) => {\n const isFocused = index === focusedIndex;\n\n let iconElement = null;\n\n if (isValidElement(icons)) {\n iconElement = icons;\n } else if (Array.isArray(icons) && icons.length > 0) {\n iconElement = (\n <StyledContextMenuContentItemIconWrapper>\n <Icon icons={icons} />\n </StyledContextMenuContentItemIconWrapper>\n );\n }\n\n return (\n <StyledContextMenuContentItem\n key={`context-menu-item-${key}`}\n data-index={index}\n >\n <StyledContextMenuContentItemWrapper\n key={key}\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n void onClick(event);\n }}\n tabIndex={0}\n $shouldHidePopupArrow={shouldHidePopupArrow}\n $isFocused={isFocused}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n onKeySelect(index);\n }\n }}\n >\n {iconElement}\n <StyledContextMenuContentItemText>\n {text}\n </StyledContextMenuContentItemText>\n </StyledContextMenuContentItemWrapper>\n {shouldShowSpacer && <StyledContextMenuContentItemSpacer />}\n </StyledContextMenuContentItem>\n );\n }),\n [items, focusedIndex, shouldHidePopupArrow, onKeySelect],\n );\n\n return (\n <StyledMotionContextMenuContent\n animate={{ opacity: 1, y: 0 }}\n exit={{ opacity: 0, y: exitAndInitialY }}\n initial={{ opacity: 0, y: exitAndInitialY }}\n $position={alignment}\n $shouldHidePopupArrow={shouldHidePopupArrow}\n $zIndex={zIndex}\n ref={ref}\n style={{ left: coordinates.x, top: coordinates.y }}\n transition={{ ease: 'anticipate' }}\n transformTemplate={({ y = '0px' }) => `\n translateX(${percentageOffsetX}%)\n translateY(${percentageOffsetY}%)\n translateX(${anchorOffsetX}px)\n translateY(${anchorOffsetY}px)\n translateY(${y})\n `}\n >\n {headline && (\n <StyledContextMenuContentHeadline>{headline}</StyledContextMenuContentHeadline>\n )}\n {content}\n </StyledMotionContextMenuContent>\n );\n },\n);\n\nContextMenuContent.displayName = 'Context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AC,KAAK;AACtD,iCAAiCpC,iBAAiB;AAClD,iCAAiCG,iBAAiB;AAClD,iCAAiCD,aAAa;AAC9C,iCAAiCE,aAAa;AAC9C,iCAAiCgC,CAAC;AAClC;EAAkB,GAEDnD,QAAQ,iBACLlC,MAAA,CAAAS,OAAA,CAAA4D,aAAA,CAAChE,mBAAA,CAAA4F,gCAAgC,QAAE/D,QAA2C,CACjF,EACAqB,OAC2B,CAAC;AAEzC,CACJ,CAAC;AAED7B,kBAAkB,CAACwE,WAAW,GAAG,oBAAoB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA3F,OAAA,GAEvCiB,kBAAkB","ignoreList":[]}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.StyledMotionContextMenuContent = exports.StyledContextMenuContentItemWrapper = exports.StyledContextMenuContentItemText = exports.StyledContextMenuContentItemSpacer = exports.StyledContextMenuContentItemIconWrapper = exports.
|
|
6
|
+
exports.StyledMotionContextMenuContent = exports.StyledContextMenuContentItemWrapper = exports.StyledContextMenuContentItemText = exports.StyledContextMenuContentItemSpacer = exports.StyledContextMenuContentItemIconWrapper = exports.StyledContextMenuContentItem = exports.StyledContextMenuContentHeadline = void 0;
|
|
7
7
|
var _react = require("motion/react");
|
|
8
8
|
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
9
|
-
var
|
|
9
|
+
var _ContextMenu = require("../ContextMenu.types");
|
|
10
10
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
11
11
|
const StyledMotionContextMenuContent = exports.StyledMotionContextMenuContent = (0, _styledComponents.default)(_react.motion.div)`
|
|
12
12
|
background-color: ${({
|
|
@@ -47,37 +47,37 @@ const StyledMotionContextMenuContent = exports.StyledMotionContextMenuContent =
|
|
|
47
47
|
$position
|
|
48
48
|
}) => {
|
|
49
49
|
switch ($position) {
|
|
50
|
-
case
|
|
50
|
+
case _ContextMenu.ContextMenuAlignment.TopLeft:
|
|
51
51
|
return (0, _styledComponents.css)`
|
|
52
52
|
bottom: -7px;
|
|
53
53
|
right: 7px;
|
|
54
54
|
transform: rotate(45deg);
|
|
55
55
|
`;
|
|
56
|
-
case
|
|
56
|
+
case _ContextMenu.ContextMenuAlignment.BottomLeft:
|
|
57
57
|
return (0, _styledComponents.css)`
|
|
58
58
|
top: -7px;
|
|
59
59
|
right: 7px;
|
|
60
60
|
transform: rotate(225deg);
|
|
61
61
|
`;
|
|
62
|
-
case
|
|
62
|
+
case _ContextMenu.ContextMenuAlignment.TopRight:
|
|
63
63
|
return (0, _styledComponents.css)`
|
|
64
64
|
transform: rotate(45deg);
|
|
65
65
|
bottom: -7px;
|
|
66
66
|
left: 7px;
|
|
67
67
|
`;
|
|
68
|
-
case
|
|
68
|
+
case _ContextMenu.ContextMenuAlignment.BottomRight:
|
|
69
69
|
return (0, _styledComponents.css)`
|
|
70
70
|
transform: rotate(225deg);
|
|
71
71
|
top: -7px;
|
|
72
72
|
left: 7px;
|
|
73
73
|
`;
|
|
74
|
-
case
|
|
74
|
+
case _ContextMenu.ContextMenuAlignment.TopCenter:
|
|
75
75
|
return (0, _styledComponents.css)`
|
|
76
76
|
bottom: -7px;
|
|
77
77
|
right: 45%;
|
|
78
78
|
transform: rotate(45deg);
|
|
79
79
|
`;
|
|
80
|
-
case
|
|
80
|
+
case _ContextMenu.ContextMenuAlignment.BottomCenter:
|
|
81
81
|
return (0, _styledComponents.css)`
|
|
82
82
|
transform: rotate(225deg);
|
|
83
83
|
top: -7px;
|
|
@@ -105,20 +105,11 @@ const StyledMotionContextMenuContent = exports.StyledMotionContextMenuContent =
|
|
|
105
105
|
`;
|
|
106
106
|
const StyledContextMenuContentItem = exports.StyledContextMenuContentItem = _styledComponents.default.div``;
|
|
107
107
|
const StyledContextMenuContentItemSpacer = exports.StyledContextMenuContentItemSpacer = _styledComponents.default.div`
|
|
108
|
-
|
|
109
|
-
margin-bottom: 10px;
|
|
110
|
-
|
|
111
|
-
&:before {
|
|
112
|
-
position: absolute;
|
|
113
|
-
bottom: -5px;
|
|
114
|
-
height: 1px;
|
|
115
|
-
background-color: ${({
|
|
108
|
+
background-color: ${({
|
|
116
109
|
theme
|
|
117
110
|
}) => theme['003']};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
content: '';
|
|
121
|
-
}
|
|
111
|
+
height: 1px;
|
|
112
|
+
width: 100%;
|
|
122
113
|
`;
|
|
123
114
|
const StyledContextMenuContentItemWrapper = exports.StyledContextMenuContentItemWrapper = _styledComponents.default.div`
|
|
124
115
|
cursor: pointer;
|
|
@@ -150,12 +141,6 @@ const StyledContextMenuContentItemIconWrapper = exports.StyledContextMenuContent
|
|
|
150
141
|
margin: 0 8px 0 3px;
|
|
151
142
|
width: 20px;
|
|
152
143
|
`;
|
|
153
|
-
const StyledContextMenuContentItemBorder = exports.StyledContextMenuContentItemBorder = _styledComponents.default.div`
|
|
154
|
-
width: 100%;
|
|
155
|
-
border-top: ${({
|
|
156
|
-
theme
|
|
157
|
-
}) => `1px solid rgba(${theme['text-rgb'] ?? '34, 34, 34'}, 0.2)`};
|
|
158
|
-
`;
|
|
159
144
|
const StyledContextMenuContentHeadline = exports.StyledContextMenuContentHeadline = _styledComponents.default.div`
|
|
160
145
|
width: 100%;
|
|
161
146
|
margin: 3px 6px;
|
package/lib/cjs/components/context-menu/context-menu-content/ContextMenuContent.styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenuContent.styles.js","names":["_react","require","_styledComponents","_interopRequireWildcard","
|
|
1
|
+
{"version":3,"file":"ContextMenuContent.styles.js","names":["_react","require","_styledComponents","_interopRequireWildcard","_ContextMenu","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","StyledMotionContextMenuContent","exports","styled","motion","div","theme","$shouldHidePopupArrow","text","$zIndex","css","$position","ContextMenuAlignment","TopLeft","BottomLeft","TopRight","BottomRight","TopCenter","BottomCenter","undefined","StyledContextMenuContentItem","StyledContextMenuContentItemSpacer","StyledContextMenuContentItemWrapper","$isFocused","StyledContextMenuContentItemIconWrapper","StyledContextMenuContentHeadline","StyledContextMenuContentItemText"],"sources":["../../../../../src/components/context-menu/context-menu-content/ContextMenuContent.styles.ts"],"sourcesContent":["import { motion } from 'motion/react';\nimport styled, { css } from 'styled-components';\nimport type { WithTheme } from '../../color-scheme-provider/ColorSchemeProvider';\nimport { ContextMenuAlignment } from '../ContextMenu.types';\n\ntype StyledMotionContextMenuContentProps = WithTheme<{\n $position: ContextMenuAlignment;\n $zIndex: number;\n $shouldHidePopupArrow: boolean;\n}>;\n\nexport const StyledMotionContextMenuContent = styled(\n motion.div,\n)<StyledMotionContextMenuContentProps>`\n background-color: ${({ theme }: StyledMotionContextMenuContentProps) => theme['001']};\n border: 1px solid rgba(0, 0, 0, 0.1);\n border-radius: ${({ $shouldHidePopupArrow }) => ($shouldHidePopupArrow ? '6px' : '3px')};\n box-shadow: 1px 3px 8px rgb(0 0 0 / 30%);\n color: ${({ theme }: StyledMotionContextMenuContentProps) => theme.text};\n pointer-events: all;\n position: absolute;\n z-index: ${({ $zIndex }) => $zIndex};\n\n &::after {\n background-color: inherit;\n border-bottom: 1px solid rgba(0, 0, 0, 0.1);\n border-right: 1px solid rgba(0, 0, 0, 0.1);\n box-shadow: 2px 2px 8px rgb(4 3 4 / 10%);\n content: '';\n height: 14px;\n position: absolute;\n width: 14px;\n z-index: -2;\n\n ${({ $shouldHidePopupArrow }) =>\n $shouldHidePopupArrow &&\n css`\n display: none;\n `}\n\n ${({ $position }) => {\n switch ($position) {\n case ContextMenuAlignment.TopLeft:\n return css`\n bottom: -7px;\n right: 7px;\n transform: rotate(45deg);\n `;\n case ContextMenuAlignment.BottomLeft:\n return css`\n top: -7px;\n right: 7px;\n transform: rotate(225deg);\n `;\n case ContextMenuAlignment.TopRight:\n return css`\n transform: rotate(45deg);\n bottom: -7px;\n left: 7px;\n `;\n case ContextMenuAlignment.BottomRight:\n return css`\n transform: rotate(225deg);\n top: -7px;\n left: 7px;\n `;\n case ContextMenuAlignment.TopCenter:\n return css`\n bottom: -7px;\n right: 45%;\n transform: rotate(45deg);\n `;\n case ContextMenuAlignment.BottomCenter:\n return css`\n transform: rotate(225deg);\n top: -7px;\n left: 45%;\n `;\n\n default:\n return undefined;\n }\n }}\n }\n\n &::before {\n background-color: inherit;\n bottom: 0;\n content: '';\n left: 0;\n position: absolute;\n right: 0;\n top: 0;\n border-radius: ${({ $shouldHidePopupArrow }) => ($shouldHidePopupArrow ? '6px' : '3px')};\n z-index: -1;\n }\n`;\n\nexport const StyledContextMenuContentItem = styled.div``;\n\ntype StyledContextMenuContentItemSpacerProps = WithTheme<unknown>;\n\nexport const StyledContextMenuContentItemSpacer = styled.div<StyledContextMenuContentItemSpacerProps>`\n background-color: ${({ theme }) => theme['003']};\n height: 1px;\n width: 100%;\n`;\n\ntype StyledContextMenuContentItemWrapperProps = WithTheme<{\n $shouldHidePopupArrow: boolean;\n $isFocused: boolean;\n}>;\n\nexport const StyledContextMenuContentItemWrapper = styled.div<StyledContextMenuContentItemWrapperProps>`\n cursor: pointer;\n display: flex;\n padding: 5px 8px 5px 5px;\n transition: background-color 0.3s ease;\n border-radius: ${({ $shouldHidePopupArrow }) => ($shouldHidePopupArrow ? '3px' : 0)};\n margin: ${({ $shouldHidePopupArrow }) => ($shouldHidePopupArrow ? '3px' : 0)};\n\n ${({ $isFocused, theme }) =>\n $isFocused &&\n css`\n background-color: ${theme['secondary-103']};\n `}\n\n &:hover {\n background-color: ${({ theme }: StyledContextMenuContentItemWrapperProps) =>\n theme['secondary-103']};\n }\n`;\n\nexport const StyledContextMenuContentItemIconWrapper = styled.div`\n flex: 0 0 auto;\n margin: 0 8px 0 3px;\n width: 20px;\n`;\n\nexport const StyledContextMenuContentHeadline = styled.div`\n width: 100%;\n margin: 3px 6px;\n opacity: 50%;\n font-weight: bold;\n`;\n\nexport const StyledContextMenuContentItemText = styled.div`\n flex: 0 0 auto;\n white-space: nowrap;\n`;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAC,uBAAA,CAAAF,OAAA;AAEA,IAAAG,YAAA,GAAAH,OAAA;AAA4D,SAAAE,wBAAAE,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CA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