ag-common 0.0.685 → 0.0.688

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.
@@ -25,6 +25,7 @@ const useTranslation = (texts, lang) => {
25
25
  if (v1 || v1 === null) {
26
26
  return v1 !== null && v1 !== void 0 ? v1 : '';
27
27
  }
28
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
28
29
  return (_a = texts[lineText].en) !== null && _a !== void 0 ? _a : '???';
29
30
  };
30
31
  return ret;
@@ -17,7 +17,7 @@ function getStringFromStream(stream) {
17
17
  const reader = stream.getReader();
18
18
  let result = '';
19
19
  try {
20
- // eslint-disable-next-line no-constant-condition
20
+ // eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
21
21
  while (true) {
22
22
  const { done, value } = yield reader.read();
23
23
  if (done)
@@ -50,7 +50,7 @@ const InfiniteScroll = (p) => {
50
50
  const { incrementNumber = 10, scrollDisabled = false } = p;
51
51
  const ref = (0, react_1.createRef)();
52
52
  const [startIndex] = (0, react_1.useState)((_a = p.startIndex) !== null && _a !== void 0 ? _a : 0);
53
- const [endIndex, setEndIndex] = (0, react_1.useState)((startIndex !== null && startIndex !== void 0 ? startIndex : 0) + incrementNumber);
53
+ const [endIndex, setEndIndex] = (0, react_1.useState)(startIndex + incrementNumber);
54
54
  const [startScrollTop, setStartScrollTop] = (0, react_1.useState)(0);
55
55
  const handleScrollTop = (e) => {
56
56
  const { scrollTop, clientHeight, scrollHeight } = e.currentTarget;
@@ -90,7 +90,7 @@ const LegendX = ({ data, lt, tt, colours, style, }) => {
90
90
  }
91
91
  }
92
92
  itemsRaw.push({ v: maxX, group: 0 });
93
- const items = itemsRaw.map((d) => { var _a; return ({ v: (_a = lt(d.v)) !== null && _a !== void 0 ? _a : d.v, group: d.group }); });
93
+ const items = itemsRaw.map((d) => ({ v: lt(d.v), group: d.group }));
94
94
  const ch = maxY.toString().length + 1;
95
95
  return (react_1.default.createElement(Base, { style: Object.assign(Object.assign({}, style), { marginLeft: 'auto', width: `calc(100% - ${ch}ch)` }) },
96
96
  react_1.default.createElement(Bar, null,
@@ -32,8 +32,8 @@ const Total = styled_1.default.span `
32
32
  }
33
33
  `;
34
34
  const TooltipContent = (p) => {
35
- var _a, _b, _c;
36
- const name = (_c = p.tt((_b = (_a = p.selectedXs) === null || _a === void 0 ? void 0 : _a[0].x) !== null && _b !== void 0 ? _b : 0)) !== null && _c !== void 0 ? _c : '';
35
+ var _a, _b;
36
+ const name = p.tt((_b = (_a = p.selectedXs) === null || _a === void 0 ? void 0 : _a[0].x) !== null && _b !== void 0 ? _b : 0);
37
37
  return (react_1.default.createElement(Base, { style: Object.assign(Object.assign({}, p.style), { border: `solid 1px ${p.style.borderColor}` }) },
38
38
  react_1.default.createElement(Title, null, name),
39
39
  react_1.default.createElement(Row, null,
@@ -90,7 +90,7 @@ const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top'
90
90
  if (portalId === undefined) {
91
91
  portalId = globalId;
92
92
  }
93
- const [elem, setElem] = (0, react_1.useState)();
93
+ const [portalElem, setPortalElem] = (0, react_1.useState)();
94
94
  (0, react_1.useEffect)(() => {
95
95
  if (portalId === null ||
96
96
  document.querySelectorAll(`#${portalId}`).length > 0) {
@@ -128,6 +128,17 @@ const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top'
128
128
  ref,
129
129
  moveMouseOutside: closeOnMoveMouseOutside,
130
130
  }, () => {
131
+ var _a;
132
+ //there might be multiple models open, only close the last one on the stack
133
+ if (portalElem) {
134
+ const myid = Array.prototype.indexOf.call(portalElem.children,
135
+ //parent because fixed background is first
136
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.parentElement);
137
+ const childcount = portalElem.children.length;
138
+ if (myid + 1 !== childcount) {
139
+ return;
140
+ }
141
+ }
131
142
  if (closeOnClickOutside && open) {
132
143
  setOpen(false);
133
144
  setBounced(false);
@@ -139,10 +150,10 @@ const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top'
139
150
  }
140
151
  }, [open, bounced]);
141
152
  (0, react_1.useEffect)(() => {
142
- if (elem === undefined && portalId) {
143
- setElem(document.getElementById(portalId));
153
+ if (portalElem === undefined && portalId) {
154
+ setPortalElem(document.getElementById(portalId));
144
155
  }
145
- }, [elem, portalId]);
156
+ }, [portalElem, portalId]);
146
157
  if (!open) {
147
158
  return react_1.default.createElement(react_1.default.Fragment, null);
148
159
  }
@@ -150,11 +161,11 @@ const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top'
150
161
  react_1.default.createElement(ModalBase, { "data-bounced": bounced, "data-position": position, "data-topposition": topPosition, ref: ref, className: className, style: style },
151
162
  showCloseButton && (react_1.default.createElement(CloseStyled, { "data-type": "modal-close", onClick: () => setOpen(false) })),
152
163
  children)));
153
- if (portalId && elem === undefined) {
164
+ if (portalId && portalElem === undefined) {
154
165
  return null;
155
166
  }
156
- if (portalId && elem) {
157
- return (0, react_dom_1.createPortal)(Content, elem);
167
+ if (portalId && portalElem) {
168
+ return (0, react_dom_1.createPortal)(Content, portalElem);
158
169
  }
159
170
  return Content;
160
171
  };
@@ -3,13 +3,18 @@ import React from 'react';
3
3
  interface IPos<T> {
4
4
  cursor: MouseEvent;
5
5
  data: T;
6
+ portalId: string;
6
7
  usePortal: boolean;
7
8
  parentWidth: number;
8
9
  parentHeight: number;
9
10
  x: number;
10
11
  y: number;
11
12
  }
12
- export declare const useTooltip: <T>() => {
13
+ type IUT = {
14
+ /** default 'ag-tooltip-portal' */
15
+ portalId: string;
16
+ };
17
+ export declare const useTooltip: <T>(p?: IUT) => {
13
18
  Comp: <T_1>({ pos, children, }: {
14
19
  pos: IPos<T_1> | undefined;
15
20
  children: (data: T_1) => JSX.Element;
@@ -34,7 +34,6 @@ const Base = styled_1.default.div `
34
34
  position: absolute;
35
35
  z-index: 2;
36
36
  `;
37
- const globalId = 'ag-tooltip-portal';
38
37
  const Comp = ({ pos, children, }) => {
39
38
  const ref = (0, react_1.createRef)();
40
39
  const [size, setSize] = (0, react_1.useState)();
@@ -92,30 +91,32 @@ const Comp = ({ pos, children, }) => {
92
91
  right,
93
92
  top,
94
93
  bottom, zIndex: 10 }, (pos.usePortal && { position: 'fixed' })), (!(size === null || size === void 0 ? void 0 : size.p) && { zIndex: -1 })) }, children(pos.data)));
95
- const e = document.querySelector(`#${globalId}`);
94
+ const e = document.querySelector(`#${pos.portalId}`);
96
95
  if (pos.usePortal && e) {
97
96
  return (0, react_dom_1.createPortal)(Content, e);
98
97
  }
99
98
  return Content;
100
99
  };
101
- const useTooltip = () => {
100
+ const useTooltip = (p) => {
101
+ const portalId = (p === null || p === void 0 ? void 0 : p.portalId) || 'ag-tooltip-portal';
102
102
  const [pos, setPosRaw] = (0, react_1.useState)();
103
103
  (0, react_1.useEffect)(() => {
104
- if (document.querySelectorAll(`#${globalId}`).length > 0) {
104
+ if (document.querySelectorAll(`#${portalId}`).length > 0) {
105
105
  return;
106
106
  }
107
107
  const d = document.createElement('div');
108
- d.id = globalId;
108
+ d.id = portalId;
109
109
  document.body.appendChild(d);
110
110
  return () => {
111
111
  var _a;
112
112
  try {
113
- (_a = document.querySelector(`#${globalId}`)) === null || _a === void 0 ? void 0 : _a.remove();
113
+ (_a = document.querySelector(`#${portalId}`)) === null || _a === void 0 ? void 0 : _a.remove();
114
114
  }
115
115
  catch (e) {
116
116
  //
117
117
  }
118
118
  };
119
+ // eslint-disable-next-line react-hooks/exhaustive-deps
119
120
  }, []);
120
121
  const setPos = (p) => {
121
122
  if (!p) {
@@ -144,6 +145,7 @@ const useTooltip = () => {
144
145
  x,
145
146
  y,
146
147
  usePortal: !p.parent,
148
+ portalId,
147
149
  };
148
150
  setPosRaw(p2);
149
151
  };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.685",
2
+ "version": "0.0.688",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",