ag-common 0.0.201 → 0.0.204

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.
Files changed (28) hide show
  1. package/dist/common/helpers/math.d.ts +10 -0
  2. package/dist/common/helpers/math.js +12 -1
  3. package/dist/ui/components/Confirm/index.js +1 -1
  4. package/dist/ui/components/HeadersRaw/index.js +11 -12
  5. package/dist/ui/components/Modal/index.js +5 -1
  6. package/dist/ui/components/Prompt/index.js +1 -1
  7. package/dist/ui/components/Search/Base.d.ts +6 -0
  8. package/dist/ui/components/{SearchModal/SearchModal.js → Search/Base.js} +17 -41
  9. package/dist/ui/components/Search/SearchBox.d.ts +6 -0
  10. package/dist/ui/components/Search/SearchBox.js +10 -0
  11. package/dist/ui/components/Search/SearchModal.d.ts +5 -0
  12. package/dist/ui/components/Search/SearchModal.js +27 -0
  13. package/dist/ui/components/{SearchModal → Search}/index.d.ts +1 -0
  14. package/dist/ui/components/{SearchModal → Search}/index.js +1 -0
  15. package/dist/ui/components/{SearchModal → Search}/searchDialog.d.ts +0 -0
  16. package/dist/ui/components/{SearchModal → Search}/searchDialog.js +23 -1
  17. package/dist/ui/components/{SearchModal → Search}/types.d.ts +0 -0
  18. package/dist/ui/components/{SearchModal → Search}/types.js +0 -0
  19. package/dist/ui/components/Sparkline/index.d.ts +14 -0
  20. package/dist/ui/components/Sparkline/index.js +59 -0
  21. package/dist/ui/components/TextEdit/TextEdit.d.ts +7 -1
  22. package/dist/ui/components/TextEdit/TextEdit.js +5 -1
  23. package/dist/ui/components/index.d.ts +2 -1
  24. package/dist/ui/components/index.js +2 -1
  25. package/dist/ui/helpers/useOnClickOutside.d.ts +5 -1
  26. package/dist/ui/helpers/useOnClickOutside.js +8 -4
  27. package/package.json +1 -1
  28. package/dist/ui/components/SearchModal/SearchModal.d.ts +0 -6
@@ -9,3 +9,13 @@ export declare function sumArray(array: number[]): number;
9
9
  export declare const getRandomInt: (max: number) => number;
10
10
  export declare function isNumber(val: string): boolean;
11
11
  export declare function toFixedDown(num: number, scale: number): number;
12
+ /**
13
+ * get percentage of value within supplied range
14
+ * @param param0
15
+ * @returns
16
+ */
17
+ export declare function rangePercentage({ value, min, max, }: {
18
+ value: number;
19
+ min: number;
20
+ max: number;
21
+ }): number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toFixedDown = exports.isNumber = exports.getRandomInt = exports.sumArray = exports.clamp = exports.roundToHalf = exports.toFixed = void 0;
3
+ exports.rangePercentage = exports.toFixedDown = exports.isNumber = exports.getRandomInt = exports.sumArray = exports.clamp = exports.roundToHalf = exports.toFixed = void 0;
4
4
  const toFixed = (num, fixed) => {
5
5
  var _a, _b;
6
6
  const re = new RegExp(`^-?\\d+(?:.\\d{0,${fixed || -1}})?`);
@@ -63,3 +63,14 @@ function toFixedDown(num, scale) {
63
63
  return +`${Math.round(`${+arr[0]}e${sig}${+arr[1] + scale}`)}e-${scale}`;
64
64
  }
65
65
  exports.toFixedDown = toFixedDown;
66
+ /**
67
+ * get percentage of value within supplied range
68
+ * @param param0
69
+ * @returns
70
+ */
71
+ function rangePercentage({ value, min, max, }) {
72
+ const v = clamp({ value, min, max });
73
+ const r = (v - min) / (max - min);
74
+ return r;
75
+ }
76
+ exports.rangePercentage = rangePercentage;
@@ -56,7 +56,7 @@ const ConfirmModal = ({ wrapper, res, bottomText, topText, okText = 'OK', cancel
56
56
  res(v);
57
57
  }
58
58
  finally {
59
- wrapper.remove();
59
+ react_dom_1.default.unmountComponentAtNode(wrapper);
60
60
  }
61
61
  };
62
62
  return (react_1.default.createElement(Modal_1.Modal, { position: "center", topPosition: "center", open: true, setOpen: () => ret(false), showCloseButton: false, closeOnClickOutside: false },
@@ -7,18 +7,17 @@ exports.HeadersRaw = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const HeadersRaw = ({ title, image, SiteShort, FullSiteUrl, siteDesc, }) => {
9
9
  const fullTitle = `${title ? `${title} | ` : ''}${SiteShort} | ${siteDesc}`;
10
- const titleBlock = title === undefined
11
- ? []
12
- : [
13
- react_1.default.createElement("title", { key: "1" }, fullTitle),
14
- react_1.default.createElement("meta", { key: "2", property: "og:title", content: title }),
15
- react_1.default.createElement("meta", { key: "3", name: "twitter:title", content: title }),
16
- react_1.default.createElement("meta", { key: "4", itemProp: "name", content: title }),
17
- react_1.default.createElement("meta", { key: "5", name: "description", content: fullTitle }),
18
- react_1.default.createElement("meta", { key: "6", itemProp: "description", content: fullTitle }),
19
- react_1.default.createElement("meta", { key: "7", property: "og:description", content: fullTitle }),
20
- react_1.default.createElement("meta", { key: "8", name: "twitter:description", content: fullTitle }),
21
- ];
10
+ const titleFallback = title || fullTitle;
11
+ const titleBlock = [
12
+ react_1.default.createElement("title", { key: "1" }, fullTitle),
13
+ react_1.default.createElement("meta", { key: "2", property: "og:title", content: titleFallback }),
14
+ react_1.default.createElement("meta", { key: "3", name: "twitter:title", content: titleFallback }),
15
+ react_1.default.createElement("meta", { key: "4", itemProp: "name", content: titleFallback }),
16
+ react_1.default.createElement("meta", { key: "5", name: "description", content: fullTitle }),
17
+ react_1.default.createElement("meta", { key: "6", itemProp: "description", content: fullTitle }),
18
+ react_1.default.createElement("meta", { key: "7", property: "og:description", content: fullTitle }),
19
+ react_1.default.createElement("meta", { key: "8", name: "twitter:description", content: fullTitle }),
20
+ ];
22
21
  const imagearr = !image
23
22
  ? []
24
23
  : [
@@ -79,7 +79,11 @@ const CloseStyled = (0, styled_components_1.default)(Close_1.Close) `
79
79
  `;
80
80
  const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'bottom', showCloseButton = true, closeOnMoveMouseOutside = false, className, closeOnClickOutside = true, }) => {
81
81
  const ref = (0, react_1.useRef)(null);
82
- (0, useOnClickOutside_1.useOnClickOutside)({ ref, moveMouseOutside: closeOnMoveMouseOutside }, () => {
82
+ (0, useOnClickOutside_1.useOnClickOutside)({
83
+ disabled: !open,
84
+ ref,
85
+ moveMouseOutside: closeOnMoveMouseOutside,
86
+ }, () => {
83
87
  if (closeOnClickOutside && open) {
84
88
  setOpen(false);
85
89
  }
@@ -81,7 +81,7 @@ const PromptModal = ({ wrapper, res, bottomText, topText, okText = 'OK', cancelT
81
81
  res(v);
82
82
  }
83
83
  finally {
84
- wrapper.remove();
84
+ react_dom_1.default.unmountComponentAtNode(wrapper);
85
85
  }
86
86
  };
87
87
  return (react_1.default.createElement(Modal_1.Modal, { position: "center", topPosition: "center", open: true, setOpen: () => ret(undefined), showCloseButton: false, closeOnClickOutside: false },
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { ISearchDialog, TSearchModalRes } from './types';
3
+ export declare const Base: <T>({ onSelectItem, onSearchTextChange, placeholderText, closeText, renderItem, displayItems, willDisplayItem, getKeyF, }: ISearchDialog<T> & {
4
+ onSearchTextChange?: ((v: string) => void) | undefined;
5
+ onSelectItem?: ((v: TSearchModalRes<T>) => void) | undefined;
6
+ }) => JSX.Element;
@@ -26,32 +26,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.SearchModal = void 0;
30
- const debounce_1 = require("../../helpers/debounce");
31
- const media_1 = require("../../styles/media");
32
- const Modal_1 = require("../Modal");
33
- const TextEdit_1 = require("../TextEdit/TextEdit");
29
+ exports.Base = void 0;
30
+ const helpers_1 = require("../../helpers");
31
+ const TextEdit_1 = require("../TextEdit");
34
32
  const styled_components_1 = __importDefault(require("styled-components"));
35
33
  const react_1 = __importStar(require("react"));
36
- const ModalStyled = (0, styled_components_1.default)(Modal_1.Modal) `
37
- display: flex;
38
- flex-flow: column;
39
- top: 10rem;
40
- @media ${media_1.bigScreen} {
41
- width: 50vw;
42
- max-width: 60rem;
43
- }
44
- @media ${media_1.smallScreen} {
45
- width: 100%;
46
- max-width: 95vw;
47
- }
48
- `;
49
34
  const SearchBox = styled_components_1.default.div `
50
35
  padding: 1rem;
51
36
  display: flex;
52
37
  flex-flow: row;
53
38
  justify-content: center;
54
39
  align-items: center;
40
+ width: calc(100% - 2rem);
41
+ margin: auto;
55
42
  `;
56
43
  const MagnifyIconSvg = (react_1.default.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 490 490" },
57
44
  react_1.default.createElement("path", { fill: "none", stroke: "#000", strokeWidth: "36", strokeLinecap: "round", d: "M280 278a153 153 0 1 0-2 2l170 170m-91-117 110 110-26 26-110-110" })));
@@ -72,6 +59,8 @@ const CloseButton = styled_components_1.default.div `
72
59
  }
73
60
  `;
74
61
  const Content = styled_components_1.default.div `
62
+ width: calc(100% - 2rem);
63
+ margin: auto;
75
64
  display: flex;
76
65
  flex-flow: column;
77
66
  justify-content: flex-start;
@@ -90,37 +79,24 @@ const Row = styled_components_1.default.div `
90
79
  justify-content: center;
91
80
  align-items: center;
92
81
  `;
93
- const SearchModal = ({ res, wrapper, placeholderText, closeText, renderItem, displayItems, willDisplayItem, getKeyF, }) => {
94
- let originalStyle;
95
- (0, react_1.useEffect)(() => {
96
- if (originalStyle === undefined) {
97
- // eslint-disable-next-line react-hooks/exhaustive-deps
98
- originalStyle = window.getComputedStyle(document.body).overflow || '';
99
- document.body.style.overflow = 'hidden';
100
- }
101
- }, []);
82
+ const Base = ({ onSelectItem, onSearchTextChange, placeholderText, closeText, renderItem, displayItems, willDisplayItem, getKeyF, }) => {
102
83
  const [searchText, setSearchText] = (0, react_1.useState)('');
103
84
  const resWrap = (foundItem) => {
104
- try {
105
- document.body.style.overflow = originalStyle || '';
106
- if (!foundItem) {
107
- res(undefined);
108
- }
109
- else {
110
- res({ foundItem, searchText });
111
- }
85
+ if (!foundItem) {
86
+ onSelectItem === null || onSelectItem === void 0 ? void 0 : onSelectItem(undefined);
112
87
  }
113
- finally {
114
- wrapper.remove();
88
+ else {
89
+ onSelectItem === null || onSelectItem === void 0 ? void 0 : onSelectItem({ foundItem, searchText });
115
90
  }
116
91
  };
117
92
  const filteredItems = displayItems.filter((i) => willDisplayItem(searchText, i));
118
- return (react_1.default.createElement(ModalStyled, { position: "center", topPosition: "center", open: true, setOpen: () => resWrap(undefined), showCloseButton: false, closeOnClickOutside: true },
93
+ return (react_1.default.createElement(react_1.default.Fragment, null,
119
94
  react_1.default.createElement(SearchBox, null,
120
- react_1.default.createElement(TextEdit_1.TextEdit, { placeholder: placeholderText, defaultValue: "", onSubmit: (v) => (0, debounce_1.debounce)(() => {
95
+ react_1.default.createElement(TextEdit_1.TextEdit, { placeholder: placeholderText, defaultValue: "", onSubmit: (v) => (0, helpers_1.debounce)(() => {
121
96
  setSearchText(v);
122
- }, { key: 'pagesearch', time: 200 }), defaultEditing: { focus: true }, singleLine: true, leftContent: react_1.default.createElement(Icon, null, MagnifyIconSvg), noGrow: true, allowUndo: false, onEscape: () => resWrap(undefined) }),
97
+ onSearchTextChange === null || onSearchTextChange === void 0 ? void 0 : onSearchTextChange(v);
98
+ }, { key: 'pagesearch', time: 200 }), defaultEditing: { focus: true }, singleLine: true, leftContent: react_1.default.createElement(Icon, null, MagnifyIconSvg), noGrow: true, allowUndo: false, onEscape: () => resWrap(undefined), onClickOutsideWithNoValue: null }),
123
99
  react_1.default.createElement(CloseButton, { onClick: () => resWrap(undefined) }, closeText)),
124
100
  react_1.default.createElement(Content, { "data-hasitems": !!filteredItems.length }, filteredItems.map((i) => (react_1.default.createElement(Row, { key: getKeyF(i), onClick: () => resWrap(i) }, renderItem(searchText, i)))))));
125
101
  };
126
- exports.SearchModal = SearchModal;
102
+ exports.Base = Base;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { ISearchDialog, TSearchModalRes } from './types';
3
+ export declare const SearchBox: <T>(p: ISearchDialog<T> & {
4
+ onSelectItem?: ((v: TSearchModalRes<T>) => void) | undefined;
5
+ onSearchTextChange?: ((v: string) => void) | undefined;
6
+ }) => JSX.Element;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SearchBox = void 0;
7
+ const Base_1 = require("./Base");
8
+ const react_1 = __importDefault(require("react"));
9
+ const SearchBox = (p) => react_1.default.createElement(Base_1.Base, Object.assign({}, p));
10
+ exports.SearchBox = SearchBox;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { ISearchDialog, TSearchModalRes } from './types';
3
+ export declare const SearchModal: <T>(p: ISearchDialog<T> & {
4
+ onSelectItem: (v: TSearchModalRes<T>) => void;
5
+ }) => JSX.Element;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SearchModal = void 0;
7
+ const Base_1 = require("./Base");
8
+ const styles_1 = require("../../styles");
9
+ const Modal_1 = require("../Modal");
10
+ const styled_components_1 = __importDefault(require("styled-components"));
11
+ const react_1 = __importDefault(require("react"));
12
+ const ModalStyled = (0, styled_components_1.default)(Modal_1.Modal) `
13
+ display: flex;
14
+ flex-flow: column;
15
+ top: 10rem;
16
+ @media ${styles_1.bigScreen} {
17
+ width: 50vw;
18
+ max-width: 60rem;
19
+ }
20
+ @media ${styles_1.smallScreen} {
21
+ width: 100%;
22
+ max-width: 95vw;
23
+ }
24
+ `;
25
+ const SearchModal = (p) => (react_1.default.createElement(ModalStyled, { position: "center", topPosition: "center", open: true, setOpen: () => p.onSelectItem(undefined), showCloseButton: false, closeOnClickOutside: true },
26
+ react_1.default.createElement(Base_1.Base, Object.assign({}, p))));
27
+ exports.SearchModal = SearchModal;
@@ -1,3 +1,4 @@
1
1
  export * from './types';
2
2
  export * from './SearchModal';
3
3
  export * from './searchDialog';
4
+ export * from './SearchBox';
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./types"), exports);
18
18
  __exportStar(require("./SearchModal"), exports);
19
19
  __exportStar(require("./searchDialog"), exports);
20
+ __exportStar(require("./SearchBox"), exports);
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.searchDialog = void 0;
16
16
  const SearchModal_1 = require("./SearchModal");
17
+ const common_1 = require("../../../common");
17
18
  const react_1 = __importDefault(require("react"));
18
19
  const react_dom_1 = __importDefault(require("react-dom"));
19
20
  /**
@@ -24,9 +25,30 @@ const react_dom_1 = __importDefault(require("react-dom"));
24
25
  const searchDialog = (p) => __awaiter(void 0, void 0, void 0, function* () {
25
26
  const placeholderText = p.placeholderText || '';
26
27
  const closeText = p.closeText || 'CLOSE';
28
+ let originalStyle;
27
29
  return new Promise((res) => {
30
+ if (document.querySelectorAll('#ag-search-dialog').length !== 0) {
31
+ (0, common_1.error)('searchDialog already open');
32
+ res(undefined);
33
+ return;
34
+ }
28
35
  const wrapper = document.body.appendChild(document.createElement('div'));
29
- react_dom_1.default.render(react_1.default.createElement(SearchModal_1.SearchModal, Object.assign({}, p, { placeholderText: placeholderText, closeText: closeText, res: (r) => res(r), wrapper: wrapper })), wrapper);
36
+ wrapper.id = 'ag-search-dialog';
37
+ if (originalStyle === undefined) {
38
+ // eslint-disable-next-line react-hooks/exhaustive-deps
39
+ originalStyle = window.getComputedStyle(document.body).overflow || '';
40
+ document.body.style.overflow = 'hidden';
41
+ }
42
+ const onSelectItem = (f) => {
43
+ try {
44
+ document.body.style.overflow = originalStyle || '';
45
+ res(f);
46
+ }
47
+ finally {
48
+ react_dom_1.default.unmountComponentAtNode(wrapper);
49
+ }
50
+ };
51
+ react_dom_1.default.render(react_1.default.createElement(SearchModal_1.SearchModal, Object.assign({}, p, { placeholderText: placeholderText, closeText: closeText, onSelectItem: onSelectItem })), wrapper);
30
52
  });
31
53
  });
32
54
  exports.searchDialog = searchDialog;
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ export declare type TSparkLineData = {
3
+ x: number;
4
+ y: number;
5
+ };
6
+ export declare const SparkLine: ({ data: raw, className, pointTitleF, pointColour, }: {
7
+ /**
8
+ * default #4d76ff
9
+ */
10
+ pointColour?: string | undefined;
11
+ className?: string | undefined;
12
+ data: TSparkLineData[];
13
+ pointTitleF?: ((p: TSparkLineData) => string) | undefined;
14
+ }) => JSX.Element;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SparkLine = void 0;
7
+ const math_1 = require("../../../common/helpers/math");
8
+ const react_1 = __importDefault(require("react"));
9
+ const styled_components_1 = __importDefault(require("styled-components"));
10
+ const Base = styled_components_1.default.div `
11
+ width: calc(100% - 2px - 1rem);
12
+ height: 100%;
13
+ border: solid 1px #666;
14
+ border-radius: 0.5rem;
15
+ padding: 0.5rem;
16
+ `;
17
+ const Points = styled_components_1.default.div `
18
+ position: relative;
19
+
20
+ width: 100%;
21
+ height: 100%;
22
+ `;
23
+ const Point = styled_components_1.default.div `
24
+ position: absolute;
25
+ border-width: 2px;
26
+ border-style: solid;
27
+ width: 1px;
28
+ `;
29
+ const SparkLine = ({ data: raw, className, pointTitleF, pointColour = '#4d76ff', }) => {
30
+ const xMin = Math.min(...raw.map((d) => d.x));
31
+ const xMax = Math.max(...raw.map((d) => d.x));
32
+ const yMin = Math.min(...raw.map((d) => d.y));
33
+ const yMax = Math.max(...raw.map((d) => d.y));
34
+ const data = raw.map((orig) => ({
35
+ x: (0, math_1.rangePercentage)({
36
+ value: orig.x,
37
+ min: xMin,
38
+ max: xMax,
39
+ }) * 100,
40
+ y: (0, math_1.rangePercentage)({
41
+ value: orig.y,
42
+ min: yMin,
43
+ max: yMax,
44
+ }) * 100,
45
+ orig,
46
+ }));
47
+ return (react_1.default.createElement(Base, { className: className },
48
+ react_1.default.createElement(Points, null, data.map((p) => {
49
+ var _a;
50
+ return (react_1.default.createElement(Point, { title: (_a = pointTitleF === null || pointTitleF === void 0 ? void 0 : pointTitleF(p.orig)) !== null && _a !== void 0 ? _a : '', key: p.x + ' ' + p.y, style: {
51
+ backgroundColor: pointColour,
52
+ borderColor: pointColour,
53
+ left: p.x + '%',
54
+ bottom: 0,
55
+ height: p.y + '%',
56
+ } }));
57
+ }))));
58
+ };
59
+ exports.SparkLine = SparkLine;
@@ -23,8 +23,14 @@ export declare const TextEdit: ({ defaultValue, defaultEditing, disableEdit, pla
23
23
  */
24
24
  disableEdit?: boolean | undefined;
25
25
  placeholder?: string | undefined;
26
+ /**
27
+ * when the user edits or unselects edit
28
+ */
26
29
  onEditingChange?: ((editing: boolean) => void) | undefined;
27
- onClickOutsideWithNoValue?: (() => void) | undefined;
30
+ /**
31
+ * if null will disable click outside
32
+ */
33
+ onClickOutsideWithNoValue?: (() => void) | null | undefined;
28
34
  onClickNotEditing?: (() => void) | undefined;
29
35
  /**
30
36
  * if true, will not grow. default false
@@ -79,7 +79,11 @@ const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, plac
79
79
  const [value, setValue] = (0, react_1.useState)(defaultValue);
80
80
  const [editing, setEditingRaw] = (0, react_1.useState)(!!defaultEditing);
81
81
  const valueChange = value !== defaultValue;
82
- (0, useOnClickOutside_1.useOnClickOutside)({ ref, moveMouseOutside: false }, () => {
82
+ (0, useOnClickOutside_1.useOnClickOutside)({
83
+ disabled: onClickOutsideWithNoValue === null,
84
+ ref,
85
+ moveMouseOutside: false,
86
+ }, () => {
83
87
  if (valueChange) {
84
88
  onSubmit(value, false);
85
89
  }
@@ -15,8 +15,9 @@ export * from './LogoutButton';
15
15
  export * from './Modal';
16
16
  export * from './Prompt';
17
17
  export * from './RowOrColumn';
18
- export * from './SearchModal';
18
+ export * from './Search';
19
19
  export * from './Sidebar';
20
+ export * from './Sparkline';
20
21
  export * from './Table';
21
22
  export * from './TextEdit';
22
23
  export * from './Toast';
@@ -31,8 +31,9 @@ __exportStar(require("./LogoutButton"), exports);
31
31
  __exportStar(require("./Modal"), exports);
32
32
  __exportStar(require("./Prompt"), exports);
33
33
  __exportStar(require("./RowOrColumn"), exports);
34
- __exportStar(require("./SearchModal"), exports);
34
+ __exportStar(require("./Search"), exports);
35
35
  __exportStar(require("./Sidebar"), exports);
36
+ __exportStar(require("./Sparkline"), exports);
36
37
  __exportStar(require("./Table"), exports);
37
38
  __exportStar(require("./TextEdit"), exports);
38
39
  __exportStar(require("./Toast"), exports);
@@ -1,6 +1,10 @@
1
1
  import { RefObject } from 'react';
2
2
  declare type Event = MouseEvent | TouchEvent;
3
- export declare function useOnClickOutside<T extends HTMLElement = HTMLElement>({ ref, moveMouseOutside }: {
3
+ export declare function useOnClickOutside<T extends HTMLElement = HTMLElement>(p: {
4
+ /**
5
+ * default false
6
+ */
7
+ disabled?: boolean;
4
8
  ref: RefObject<T>;
5
9
  moveMouseOutside?: boolean;
6
10
  }, handler: (event: Event) => void): void;
@@ -2,10 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useOnClickOutside = void 0;
4
4
  const react_1 = require("react");
5
- function useOnClickOutside({ ref, moveMouseOutside }, handler) {
5
+ function useOnClickOutside(p, handler) {
6
6
  (0, react_1.useEffect)(() => {
7
+ if (p.disabled || typeof window === 'undefined') {
8
+ return () => { };
9
+ }
7
10
  const listener = (event) => {
8
- const el = ref === null || ref === void 0 ? void 0 : ref.current;
11
+ var _a;
12
+ const el = (_a = p.ref) === null || _a === void 0 ? void 0 : _a.current;
9
13
  // Do nothing if clicking ref's element or descendent elements
10
14
  if (!el || el.contains((event === null || event === void 0 ? void 0 : event.target) || null)) {
11
15
  return;
@@ -14,7 +18,7 @@ function useOnClickOutside({ ref, moveMouseOutside }, handler) {
14
18
  };
15
19
  document.addEventListener(`mousedown`, listener);
16
20
  document.addEventListener(`touchstart`, listener);
17
- if (moveMouseOutside) {
21
+ if (p.moveMouseOutside) {
18
22
  document.addEventListener(`mousemove`, listener);
19
23
  }
20
24
  return () => {
@@ -23,6 +27,6 @@ function useOnClickOutside({ ref, moveMouseOutside }, handler) {
23
27
  document.removeEventListener(`mousemove`, listener);
24
28
  };
25
29
  // Reload only if ref or handler changes
26
- }, [ref, handler, moveMouseOutside]);
30
+ }, [p, handler]);
27
31
  }
28
32
  exports.useOnClickOutside = useOnClickOutside;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.201",
3
+ "version": "0.0.204",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",
@@ -1,6 +0,0 @@
1
- /// <reference types="react" />
2
- import { ISearchDialog, TSearchModalRes } from './types';
3
- export declare const SearchModal: <T>({ res, wrapper, placeholderText, closeText, renderItem, displayItems, willDisplayItem, getKeyF, }: ISearchDialog<T> & {
4
- res: (v: TSearchModalRes<T>) => void;
5
- wrapper: HTMLDivElement;
6
- }) => JSX.Element;