ag-common 0.0.686 → 0.0.689

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;
@@ -3,7 +3,7 @@ export declare const GetLogLevel: (l: TLogType) => number;
3
3
  export type TLogShim = (...args: unknown[]) => void;
4
4
  /** if passed in, will use this instead of console.xxx */
5
5
  export declare const SetLogShim: (ls: TLogShim) => void;
6
- export declare const SetLogLevel: (l: TLogType) => void;
6
+ export declare const SetLogLevel: (l?: TLogType) => void;
7
7
  export declare const debug: (...args: unknown[]) => void;
8
8
  export declare const info: (...args: unknown[]) => void;
9
9
  export declare const warn: (...args: unknown[]) => void;
@@ -14,7 +14,7 @@ const SetLogShim = (ls) => {
14
14
  exports.SetLogShim = SetLogShim;
15
15
  let userLogLevel;
16
16
  const SetLogLevel = (l) => {
17
- const lu = l.toUpperCase();
17
+ const lu = (l !== null && l !== void 0 ? l : 'INFO').toUpperCase();
18
18
  if ((0, exports.GetLogLevel)(lu) === -1) {
19
19
  return;
20
20
  }
@@ -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,
@@ -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.686",
2
+ "version": "0.0.689",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",