@chayns-components/core 5.0.0-beta.25 → 5.0.0-beta.26

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -19,9 +19,9 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
19
19
 
20
20
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
21
 
22
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
22
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
23
23
 
24
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
24
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
25
25
 
26
26
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
27
 
@@ -1,4 +1,4 @@
1
- import React, { MouseEventHandler, ReactNode } from 'react';
1
+ import React, { MouseEvent, ReactNode } from 'react';
2
2
  import { ContextMenuAlignment } from './constants/alignment';
3
3
  export declare type ContextMenuCoordinates = {
4
4
  x: number;
@@ -7,7 +7,7 @@ export declare type ContextMenuCoordinates = {
7
7
  export declare type ContextMenuItem = {
8
8
  icons: string[];
9
9
  key: string;
10
- onClick: MouseEventHandler<HTMLDivElement>;
10
+ onClick: (event?: MouseEvent<HTMLDivElement>) => void;
11
11
  text: string;
12
12
  };
13
13
  declare type ContextMenuRef = {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -29,6 +29,10 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
29
29
 
30
30
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
31
31
 
32
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
33
+
34
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
35
+
32
36
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
33
37
 
34
38
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -72,50 +76,90 @@ var ContextMenu = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
72
76
  isContentShown = _useState6[0],
73
77
  setIsContentShown = _useState6[1];
74
78
 
75
- var uuid = (0, _uuid.useUuid)();
79
+ var uuid = (0, _uuid.useUuid)(); // ToDo: Replace with hook if new chayns api is ready
80
+
76
81
  var contextMenuContentRef = (0, _react.useRef)(null);
77
82
  var contextMenuRef = (0, _react.useRef)(null);
78
83
  var handleHide = (0, _react.useCallback)(function () {
79
84
  setIsContentShown(false);
80
85
  }, []);
81
- var handleShow = (0, _react.useCallback)(function () {
82
- if (contextMenuRef.current) {
83
- var rootElement = document.querySelector('.tapp') || document.body;
84
-
85
- var _contextMenuRef$curre = contextMenuRef.current.getBoundingClientRect(),
86
- x = _contextMenuRef$curre.x,
87
- y = _contextMenuRef$curre.y,
88
- childrenHeight = _contextMenuRef$curre.height,
89
- childrenWidth = _contextMenuRef$curre.width;
90
-
91
- setInternalCoordinates({
92
- x: x + childrenWidth / 2,
93
- y: y + childrenHeight / 2
94
- });
95
-
96
- var _rootElement$getBound = rootElement.getBoundingClientRect(),
97
- height = _rootElement$getBound.height,
98
- width = _rootElement$getBound.width;
99
-
100
- if (x < width / 2) {
101
- if (y < height / 2) {
102
- setInternalAlignment(_alignment.ContextMenuAlignment.BottomRight);
103
- } else {
104
- setInternalAlignment(_alignment.ContextMenuAlignment.TopRight);
86
+ var handleShow = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
87
+ var _chayns$env, isMobile, isTablet, _selection$, _yield$chayns$dialog$, buttonType, selection, _items$selection$0$va, rootElement, _contextMenuRef$curre, x, y, childrenHeight, childrenWidth, _rootElement$getBound, height, width;
88
+
89
+ return regeneratorRuntime.wrap(function _callee$(_context) {
90
+ while (1) {
91
+ switch (_context.prev = _context.next) {
92
+ case 0:
93
+ _chayns$env = chayns.env, isMobile = _chayns$env.isMobile, isTablet = _chayns$env.isTablet;
94
+
95
+ if (!(isMobile || isTablet)) {
96
+ _context.next = 10;
97
+ break;
98
+ }
99
+
100
+ _context.next = 4;
101
+ return chayns.dialog.select({
102
+ buttons: [],
103
+ list: items.map(function (_ref3, index) {
104
+ var icons = _ref3.icons,
105
+ text = _ref3.text;
106
+ return {
107
+ name: text,
108
+ value: index,
109
+ icon: icons[0]
110
+ };
111
+ }),
112
+ type: 2
113
+ });
114
+
115
+ case 4:
116
+ _yield$chayns$dialog$ = _context.sent;
117
+ buttonType = _yield$chayns$dialog$.buttonType;
118
+ selection = _yield$chayns$dialog$.selection;
119
+
120
+ if (buttonType === 1 && typeof ((_selection$ = selection[0]) === null || _selection$ === void 0 ? void 0 : _selection$.value) === 'number') {
121
+ (_items$selection$0$va = items[selection[0].value]) === null || _items$selection$0$va === void 0 ? void 0 : _items$selection$0$va.onClick();
122
+ }
123
+
124
+ _context.next = 11;
125
+ break;
126
+
127
+ case 10:
128
+ if (contextMenuRef.current) {
129
+ rootElement = document.querySelector('.tapp') || document.body;
130
+ _contextMenuRef$curre = contextMenuRef.current.getBoundingClientRect(), x = _contextMenuRef$curre.x, y = _contextMenuRef$curre.y, childrenHeight = _contextMenuRef$curre.height, childrenWidth = _contextMenuRef$curre.width;
131
+ setInternalCoordinates({
132
+ x: x + childrenWidth / 2,
133
+ y: y + childrenHeight / 2
134
+ });
135
+ _rootElement$getBound = rootElement.getBoundingClientRect(), height = _rootElement$getBound.height, width = _rootElement$getBound.width;
136
+
137
+ if (x < width / 2) {
138
+ if (y < height / 2) {
139
+ setInternalAlignment(_alignment.ContextMenuAlignment.BottomRight);
140
+ } else {
141
+ setInternalAlignment(_alignment.ContextMenuAlignment.TopRight);
142
+ }
143
+ } else if (y < height / 2) {
144
+ setInternalAlignment(_alignment.ContextMenuAlignment.BottomLeft);
145
+ } else {
146
+ setInternalAlignment(_alignment.ContextMenuAlignment.TopLeft);
147
+ }
148
+
149
+ setIsContentShown(true);
150
+ }
151
+
152
+ case 11:
153
+ case "end":
154
+ return _context.stop();
105
155
  }
106
- } else if (y < height / 2) {
107
- setInternalAlignment(_alignment.ContextMenuAlignment.BottomLeft);
108
- } else {
109
- setInternalAlignment(_alignment.ContextMenuAlignment.TopLeft);
110
156
  }
111
-
112
- setIsContentShown(true);
113
- }
114
- }, []);
157
+ }, _callee);
158
+ })), []);
115
159
  var handleClick = (0, _react.useCallback)(function (event) {
116
160
  event.preventDefault();
117
161
  event.stopPropagation();
118
- handleShow();
162
+ void handleShow();
119
163
  }, [handleShow]);
120
164
  var handleDocumentClick = (0, _react.useCallback)(function (event) {
121
165
  var _contextMenuContentRe;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/context-menu/ContextMenu.tsx"],"names":["ContextMenu","ref","alignment","children","container","document","body","coordinates","items","onHide","onShow","x","y","internalCoordinates","setInternalCoordinates","ContextMenuAlignment","TopLeft","internalAlignment","setInternalAlignment","isContentShown","setIsContentShown","uuid","contextMenuContentRef","contextMenuRef","handleHide","handleShow","current","rootElement","querySelector","getBoundingClientRect","childrenHeight","height","childrenWidth","width","BottomRight","TopRight","BottomLeft","handleClick","event","preventDefault","stopPropagation","handleDocumentClick","contains","target","hide","show","addEventListener","window","removeEventListener","portal","displayName"],"mappings":";;;;;;;;;AAAA;;AACA;;AAWA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;AAqDA,IAAMA,WAAW,gBAAG,uBAChB,gBAUIC,GAVJ,EAWK;AAAA,MATGC,SASH,QATGA,SASH;AAAA,2BARGC,QAQH;AAAA,MARGA,QAQH,2CARc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SAZJ,CADJ;AAAA,GADW,EAgBX,CACIA,SADJ,EAEIG,WAFJ,EAGIM,mBAHJ,EAIII,iBAJJ,EAKIE,cALJ,EAMIX,KANJ,EAOIN,SAPJ,EAQImB,IARJ,CAhBW,CAAf;AA4BA,sBACI,yEACI,6BAAC,8BAAD;AACI,IAAA,SAAS,EAAC,0BADd;AAEI,IAAA,OAAO,EAAEgB,WAFb;AAGI,IAAA,GAAG,EAAEd;AAHT,KAKKpB,QALL,CADJ,EAQK8C,MARL,CADJ;AAYH,CAvJe,CAApB;AA0JAjD,WAAW,CAACkD,WAAZ,GAA0B,aAA1B;eAEelD,W","sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, {\n forwardRef,\n MouseEventHandler,\n ReactNode,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { useUuid } from '../../hooks/uuid';\nimport Icon from '../icon/Icon';\nimport { ContextMenuAlignment } from './constants/alignment';\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[];\n key: string;\n onClick: MouseEventHandler<HTMLDivElement>;\n text: string;\n};\n\ntype 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.\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 items that will be displayed in the content of the `ContextMenu`.\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\nconst ContextMenu = forwardRef<ContextMenuRef, ContextMenuProps>(\n (\n {\n alignment,\n children = <Icon icons={['ts-ellipsis_v']} />,\n container = document.body,\n coordinates,\n items,\n onHide,\n onShow,\n },\n ref\n ) => {\n const [internalCoordinates, setInternalCoordinates] = useState<ContextMenuCoordinates>({\n x: 0,\n y: 0,\n });\n const [internalAlignment, setInternalAlignment] = useState<ContextMenuAlignment>(\n ContextMenuAlignment.TopLeft\n );\n const [isContentShown, setIsContentShown] = useState(false);\n\n const uuid = useUuid();\n\n const contextMenuContentRef = useRef<HTMLDivElement>(null);\n const contextMenuRef = useRef<HTMLSpanElement>(null);\n\n const handleHide = useCallback(() => {\n setIsContentShown(false);\n }, []);\n\n const handleShow = useCallback(() => {\n if (contextMenuRef.current) {\n const rootElement = document.querySelector('.tapp') || document.body;\n\n const {\n x,\n y,\n height: childrenHeight,\n width: childrenWidth,\n } = contextMenuRef.current.getBoundingClientRect();\n\n setInternalCoordinates({ x: x + childrenWidth / 2, y: y + childrenHeight / 2 });\n\n const { height, width } = rootElement.getBoundingClientRect();\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 }, []);\n\n const handleClick = useCallback<MouseEventHandler<HTMLDivElement>>(\n (event) => {\n event.preventDefault();\n event.stopPropagation();\n\n handleShow();\n },\n [handleShow]\n );\n\n const handleDocumentClick = useCallback<EventListener>(\n (event) => {\n if (!contextMenuContentRef.current?.contains(event.target as Node)) {\n event.preventDefault();\n event.stopPropagation();\n }\n\n handleHide();\n },\n [handleHide]\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 const portal = useMemo(\n () =>\n createPortal(\n <AnimatePresence initial={false}>\n {isContentShown && (\n <ContextMenuContent\n coordinates={coordinates ?? internalCoordinates}\n items={items}\n key={`contextMenu_${uuid}`}\n alignment={alignment ?? internalAlignment}\n ref={contextMenuContentRef}\n />\n )}\n </AnimatePresence>,\n container\n ),\n [\n container,\n coordinates,\n internalCoordinates,\n internalAlignment,\n isContentShown,\n items,\n alignment,\n uuid,\n ]\n );\n\n return (\n <>\n <StyledContextMenu\n className=\"beta-chayns-context-menu\"\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"],"file":"ContextMenu.js"}
1
+ {"version":3,"sources":["../../../src/components/context-menu/ContextMenu.tsx"],"names":["ContextMenu","ref","alignment","children","container","document","body","coordinates","items","onHide","onShow","x","y","internalCoordinates","setInternalCoordinates","ContextMenuAlignment","TopLeft","internalAlignment","setInternalAlignment","isContentShown","setIsContentShown","uuid","contextMenuContentRef","contextMenuRef","handleHide","handleShow","chayns","env","isMobile","isTablet","dialog","select","buttons","list","map","index","icons","text","name","value","icon","type","buttonType","selection","onClick","current","rootElement","querySelector","getBoundingClientRect","childrenHeight","height","childrenWidth","width","BottomRight","TopRight","BottomLeft","handleClick","event","preventDefault","stopPropagation","handleDocumentClick","contains","target","hide","show","addEventListener","window","removeEventListener","portal","displayName"],"mappings":";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CACIA,SADJ,EAEIG,WAFJ,EAGIM,mBAHJ,EAIII,iBAJJ,EAKIE,cALJ,EAMIX,KANJ,EAOIN,SAPJ,EAQImB,IARJ,CAhBW,CAAf;AA4BA,sBACI,yEACI,6BAAC,8BAAD;AACI,IAAA,SAAS,EAAC,0BADd;AAEI,IAAA,OAAO,EAAEmC,WAFb;AAGI,IAAA,GAAG,EAAEjC;AAHT,KAKKpB,QALL,CADJ,EAQKiE,MARL,CADJ;AAYH,CAzKe,CAApB;AA4KApE,WAAW,CAACqE,WAAZ,GAA0B,aAA1B;eAEerE,W","sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, {\n forwardRef,\n MouseEvent,\n MouseEventHandler,\n ReactNode,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { useUuid } from '../../hooks/uuid';\nimport Icon from '../icon/Icon';\nimport { ContextMenuAlignment } from './constants/alignment';\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[];\n key: string;\n onClick: (event?: MouseEvent<HTMLDivElement>) => void;\n text: string;\n};\n\ntype 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.\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 items that will be displayed in the content of the `ContextMenu`.\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\nconst ContextMenu = forwardRef<ContextMenuRef, ContextMenuProps>(\n (\n {\n alignment,\n children = <Icon icons={['ts-ellipsis_v']} />,\n container = document.body,\n coordinates,\n items,\n onHide,\n onShow,\n },\n ref\n ) => {\n const [internalCoordinates, setInternalCoordinates] = useState<ContextMenuCoordinates>({\n x: 0,\n y: 0,\n });\n const [internalAlignment, setInternalAlignment] = useState<ContextMenuAlignment>(\n ContextMenuAlignment.TopLeft\n );\n const [isContentShown, setIsContentShown] = useState(false);\n\n const uuid = useUuid();\n\n // ToDo: Replace with hook if new chayns api is ready\n const contextMenuContentRef = useRef<HTMLDivElement>(null);\n const contextMenuRef = useRef<HTMLSpanElement>(null);\n\n const handleHide = useCallback(() => {\n setIsContentShown(false);\n }, []);\n\n const handleShow = useCallback(async () => {\n const { isMobile, isTablet } = chayns.env;\n\n if (isMobile || isTablet) {\n // ToDo: Replace with new api function if new api is ready\n const { buttonType, selection } = await chayns.dialog.select({\n buttons: [],\n list: items.map(({ icons, text }, index) => ({\n name: text,\n value: index,\n icon: icons[0],\n })),\n type: 2,\n });\n\n if (buttonType === 1 && typeof selection[0]?.value === 'number') {\n items[selection[0].value]?.onClick();\n }\n } else if (contextMenuRef.current) {\n const rootElement = document.querySelector('.tapp') || document.body;\n\n const {\n x,\n y,\n height: childrenHeight,\n width: childrenWidth,\n } = contextMenuRef.current.getBoundingClientRect();\n\n setInternalCoordinates({ x: x + childrenWidth / 2, y: y + childrenHeight / 2 });\n\n const { height, width } = rootElement.getBoundingClientRect();\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 }, []);\n\n const handleClick = useCallback<MouseEventHandler<HTMLDivElement>>(\n (event) => {\n event.preventDefault();\n event.stopPropagation();\n\n void handleShow();\n },\n [handleShow]\n );\n\n const handleDocumentClick = useCallback<EventListener>(\n (event) => {\n if (!contextMenuContentRef.current?.contains(event.target as Node)) {\n event.preventDefault();\n event.stopPropagation();\n }\n\n handleHide();\n },\n [handleHide]\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 const portal = useMemo(\n () =>\n createPortal(\n <AnimatePresence initial={false}>\n {isContentShown && (\n <ContextMenuContent\n coordinates={coordinates ?? internalCoordinates}\n items={items}\n key={`contextMenu_${uuid}`}\n alignment={alignment ?? internalAlignment}\n ref={contextMenuContentRef}\n />\n )}\n </AnimatePresence>,\n container\n ),\n [\n container,\n coordinates,\n internalCoordinates,\n internalAlignment,\n isContentShown,\n items,\n alignment,\n uuid,\n ]\n );\n\n return (\n <>\n <StyledContextMenu\n className=\"beta-chayns-context-menu\"\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"],"file":"ContextMenu.js"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -0,0 +1,56 @@
1
+ declare global {
2
+ let chayns: Chayns;
3
+ }
4
+ export interface Chayns {
5
+ dialog: Dialog;
6
+ env: Env;
7
+ }
8
+ export interface Dialog {
9
+ select(config: {
10
+ title?: string;
11
+ message?: string;
12
+ list: Array<SelectDialogItem>;
13
+ multiselect?: boolean;
14
+ type?: SelectType;
15
+ preventCloseOnClick?: boolean;
16
+ buttons?: DialogButton[];
17
+ selectAllButton?: string;
18
+ }): Promise<SelectDialogResult>;
19
+ }
20
+ declare enum ButtonText {
21
+ Cancel = "Abbrechen",
22
+ No = "Nein",
23
+ Ok = "OK",
24
+ Yes = "Ja"
25
+ }
26
+ export declare enum ButtonType {
27
+ Cancel = -1,
28
+ Negative = 0,
29
+ Positive = 1
30
+ }
31
+ export interface DialogButton {
32
+ text: ButtonText | string;
33
+ buttonType: ButtonType | number;
34
+ collapseTime?: number;
35
+ textColor?: string;
36
+ backgroundColor?: string;
37
+ }
38
+ export interface SelectDialogItem {
39
+ name: string;
40
+ value: string | number;
41
+ isSelected?: boolean;
42
+ }
43
+ export interface SelectDialogResult {
44
+ buttonType: ButtonType | number;
45
+ selection: Array<SelectDialogItem>;
46
+ }
47
+ declare enum SelectType {
48
+ Default = 0,
49
+ Icon = 1,
50
+ IconAndText
51
+ }
52
+ export interface Env {
53
+ isMobile: boolean;
54
+ isTablet: boolean;
55
+ }
56
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ButtonType = void 0;
7
+ var ButtonType;
8
+ exports.ButtonType = ButtonType;
9
+
10
+ (function (ButtonType) {
11
+ ButtonType[ButtonType["Cancel"] = -1] = "Cancel";
12
+ ButtonType[ButtonType["Negative"] = 0] = "Negative";
13
+ ButtonType[ButtonType["Positive"] = 1] = "Positive";
14
+ })(ButtonType || (exports.ButtonType = ButtonType = {}));
15
+ //# sourceMappingURL=chayns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/chayns.ts"],"names":["ButtonType"],"mappings":";;;;;;IA6BYA,U;;;WAAAA,U;AAAAA,EAAAA,U,CAAAA,U;AAAAA,EAAAA,U,CAAAA,U;AAAAA,EAAAA,U,CAAAA,U;GAAAA,U,0BAAAA,U","sourcesContent":["declare global {\n let chayns: Chayns;\n}\n\nexport interface Chayns {\n dialog: Dialog;\n env: Env;\n}\n\nexport interface Dialog {\n select(config: {\n title?: string;\n message?: string;\n list: Array<SelectDialogItem>;\n multiselect?: boolean;\n type?: SelectType;\n preventCloseOnClick?: boolean;\n buttons?: DialogButton[];\n selectAllButton?: string;\n }): Promise<SelectDialogResult>;\n}\n\ndeclare enum ButtonText {\n Cancel = 'Abbrechen',\n No = 'Nein',\n Ok = 'OK',\n Yes = 'Ja',\n}\n\nexport enum ButtonType {\n Cancel = -1,\n Negative = 0,\n Positive = 1,\n}\n\nexport interface DialogButton {\n text: ButtonText | string;\n buttonType: ButtonType | number;\n collapseTime?: number;\n textColor?: string;\n backgroundColor?: string;\n}\n\nexport interface SelectDialogItem {\n name: string;\n value: string | number;\n isSelected?: boolean;\n}\n\nexport interface SelectDialogResult {\n buttonType: ButtonType | number;\n selection: Array<SelectDialogItem>;\n}\n\ndeclare enum SelectType {\n Default = 0,\n Icon = 1,\n IconAndText,\n}\n\nexport interface Env {\n isMobile: boolean;\n isTablet: boolean;\n}\n"],"file":"chayns.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chayns-components/core",
3
- "version": "5.0.0-beta.25",
3
+ "version": "5.0.0-beta.26",
4
4
  "description": "A set of beautiful React components for developing your own applications with chayns.",
5
5
  "keywords": [
6
6
  "chayns",
@@ -33,25 +33,25 @@
33
33
  "url": "https://github.com/TobitSoftware/chayns-components/issues"
34
34
  },
35
35
  "devDependencies": {
36
- "@babel/cli": "^7.15.7",
37
- "@babel/core": "^7.15.8",
38
- "@babel/preset-env": "^7.15.8",
39
- "@babel/preset-react": "^7.14.5",
40
- "@babel/preset-typescript": "^7.15.0",
41
- "@types/react": "^17.0.27",
42
- "@types/react-dom": "^17.0.9",
43
- "@types/styled-components": "^5.1.15",
44
- "@types/uuid": "^8.3.1",
45
- "babel-loader": "^8.2.2",
36
+ "@babel/cli": "^7.17.3",
37
+ "@babel/core": "^7.17.5",
38
+ "@babel/preset-env": "^7.16.11",
39
+ "@babel/preset-react": "^7.16.7",
40
+ "@babel/preset-typescript": "^7.16.7",
41
+ "@types/react": "^17.0.39",
42
+ "@types/react-dom": "^17.0.11",
43
+ "@types/styled-components": "^5.1.23",
44
+ "@types/uuid": "^8.3.4",
45
+ "babel-loader": "^8.2.3",
46
46
  "lerna": "^4.0.0",
47
47
  "react": "^17.0.2",
48
48
  "react-dom": "^17.0.2",
49
- "typescript": "^4.4.3"
49
+ "typescript": "^4.5.5"
50
50
  },
51
51
  "dependencies": {
52
52
  "clsx": "^1.1.1",
53
- "framer-motion": "^4.1.17",
54
- "styled-components": "^5.3.1",
53
+ "framer-motion": "^6.2.6",
54
+ "styled-components": "^5.3.3",
55
55
  "uuid": "^8.3.2"
56
56
  },
57
57
  "peerDependencies": {
@@ -61,5 +61,5 @@
61
61
  "publishConfig": {
62
62
  "access": "public"
63
63
  },
64
- "gitHead": "bbd2561950d231cbe1c30c4e1d1c8e2a3da106ec"
64
+ "gitHead": "0f89b97adce5d9ae2add65b32785642fea23c75b"
65
65
  }