ag-common 0.0.387 → 0.0.389
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/dist/common/helpers/math.d.ts +0 -2
- package/dist/common/helpers/math.js +1 -6
- package/dist/common/helpers/random.d.ts +3 -0
- package/dist/common/helpers/random.js +17 -7
- package/dist/ui/components/Search/AutoHideSearchBox.d.ts +8 -0
- package/dist/ui/components/Search/AutoHideSearchBox.js +103 -0
- package/dist/ui/components/Search/index.d.ts +1 -0
- package/dist/ui/components/Search/index.js +1 -0
- package/dist/ui/components/Toast/base.js +1 -1
- package/package.json +1 -1
|
@@ -6,8 +6,6 @@ export declare function clamp({ value, min, max, }: {
|
|
|
6
6
|
max: number;
|
|
7
7
|
}): number;
|
|
8
8
|
export declare function sumArray(array: number[]): number;
|
|
9
|
-
/** returns number < max */
|
|
10
|
-
export declare const getRandomInt: (max: number) => number;
|
|
11
9
|
export declare function isNumber(val: string): boolean;
|
|
12
10
|
export declare function toFixedDown(num: number, scale: number): number;
|
|
13
11
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rangePercentage = exports.toFixedDown = exports.isNumber = exports.
|
|
3
|
+
exports.rangePercentage = exports.toFixedDown = exports.isNumber = 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}})?`);
|
|
@@ -37,11 +37,6 @@ function sumArray(array) {
|
|
|
37
37
|
return array.reduce((a, b) => a + b, 0);
|
|
38
38
|
}
|
|
39
39
|
exports.sumArray = sumArray;
|
|
40
|
-
/** returns number < max */
|
|
41
|
-
const getRandomInt = (max) => {
|
|
42
|
-
return Math.floor(Math.random() * Math.floor(max));
|
|
43
|
-
};
|
|
44
|
-
exports.getRandomInt = getRandomInt;
|
|
45
40
|
function isNumber(val) {
|
|
46
41
|
const re = new RegExp(`(\\d+\\.?\\d*)(\\d)`);
|
|
47
42
|
const m = val.toString().match(re);
|
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shuffle = void 0;
|
|
3
|
+
exports.shuffle = exports.randomDecimal = exports.random = void 0;
|
|
4
|
+
function random(max, seed) {
|
|
5
|
+
seed = seed || new Date().getTime();
|
|
6
|
+
const ret = (seed * 9301 + 49297) % 233280;
|
|
7
|
+
const rnd = ret / 233280;
|
|
8
|
+
return Math.ceil(rnd * max);
|
|
9
|
+
}
|
|
10
|
+
exports.random = random;
|
|
11
|
+
/** between 0 and 1. seed defaults to now.getTime() */
|
|
12
|
+
const randomDecimal = function (seed) {
|
|
13
|
+
seed = seed || new Date().getTime();
|
|
14
|
+
const x = Math.sin((seed += 1)) * 10000;
|
|
15
|
+
return x - Math.floor(x);
|
|
16
|
+
};
|
|
17
|
+
exports.randomDecimal = randomDecimal;
|
|
4
18
|
function shuffle(array, seed) {
|
|
5
19
|
let currentIndex = array.length;
|
|
6
20
|
let temporaryValue;
|
|
7
21
|
let randomIndex;
|
|
8
|
-
|
|
9
|
-
const random = function () {
|
|
10
|
-
const x = Math.sin((seed += 1)) * 10000;
|
|
11
|
-
return x - Math.floor(x);
|
|
12
|
-
};
|
|
22
|
+
const r = (0, exports.randomDecimal)(seed);
|
|
13
23
|
// While there remain elements to shuffle...
|
|
14
24
|
while (currentIndex !== 0) {
|
|
15
25
|
// Pick a remaining element...
|
|
16
|
-
randomIndex = Math.floor(
|
|
26
|
+
randomIndex = Math.floor(r * currentIndex);
|
|
17
27
|
currentIndex -= 1;
|
|
18
28
|
// And swap it with the current element.
|
|
19
29
|
temporaryValue = array[currentIndex];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface IAutoHideSearchBox {
|
|
3
|
+
searchText: string;
|
|
4
|
+
setSearchText: (val: string, enterPressed: boolean) => void;
|
|
5
|
+
onOpenToggle?: (open: boolean) => void;
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const AutoHideSearchBox: (p: IAutoHideSearchBox) => JSX.Element;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.AutoHideSearchBox = void 0;
|
|
30
|
+
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
31
|
+
const react_1 = __importStar(require("react"));
|
|
32
|
+
const helpers_1 = require("../../helpers");
|
|
33
|
+
const icons_1 = require("../../icons");
|
|
34
|
+
const styles_1 = require("../../styles");
|
|
35
|
+
const SearchBox_1 = require("./SearchBox");
|
|
36
|
+
const Base = styled_1.default.div `
|
|
37
|
+
display: flex;
|
|
38
|
+
flex-flow: row;
|
|
39
|
+
align-items: center;
|
|
40
|
+
margin-left: 1rem;
|
|
41
|
+
|
|
42
|
+
@media ${styles_1.bigScreen} {
|
|
43
|
+
width: 20rem;
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
const Icon = styled_1.default.div `
|
|
47
|
+
display: flex;
|
|
48
|
+
margin-right: 0.5rem;
|
|
49
|
+
> svg {
|
|
50
|
+
width: 1.2rem;
|
|
51
|
+
height: 1.2rem;
|
|
52
|
+
fill: white;
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
55
|
+
const SearchBoxStyled = (0, styled_1.default)(SearchBox_1.SearchBox) `
|
|
56
|
+
transition: width 200ms ease-in-out;
|
|
57
|
+
|
|
58
|
+
overflow: hidden;
|
|
59
|
+
padding: 0;
|
|
60
|
+
&[data-open='false'] {
|
|
61
|
+
width: 0;
|
|
62
|
+
padding: 0;
|
|
63
|
+
}
|
|
64
|
+
@media ${styles_1.smallScreen} {
|
|
65
|
+
padding: 0;
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
const AutoHideSearchBox = (p) => {
|
|
69
|
+
const [open, setOpen] = (0, react_1.useState)(!!p.searchText);
|
|
70
|
+
const textEditRef = (0, react_1.createRef)();
|
|
71
|
+
(0, helpers_1.useGranularEffect)(() => {
|
|
72
|
+
var _a;
|
|
73
|
+
const newOpen = !!p.searchText;
|
|
74
|
+
if (newOpen !== open) {
|
|
75
|
+
setOpen(!open);
|
|
76
|
+
(_a = p.onOpenToggle) === null || _a === void 0 ? void 0 : _a.call(p, !open);
|
|
77
|
+
}
|
|
78
|
+
}, [p.searchText], [open]);
|
|
79
|
+
return (react_1.default.createElement(Base, { className: p.className, "data-open": open },
|
|
80
|
+
react_1.default.createElement(Icon, { style: { cursor: 'pointer' }, onClick: () => {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
if (open) {
|
|
83
|
+
p.setSearchText('', false);
|
|
84
|
+
}
|
|
85
|
+
setOpen(!open);
|
|
86
|
+
(_a = p.onOpenToggle) === null || _a === void 0 ? void 0 : _a.call(p, !open);
|
|
87
|
+
if (!open) {
|
|
88
|
+
(_b = textEditRef.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
89
|
+
}
|
|
90
|
+
} },
|
|
91
|
+
open && react_1.default.createElement(icons_1.CrossIcon, null),
|
|
92
|
+
!open && react_1.default.createElement(icons_1.Magnify, { colour: "white" })),
|
|
93
|
+
react_1.default.createElement(SearchBoxStyled, Object.assign({ ref: textEditRef }, p, { className: "", "data-open": open, defaultValue: p.searchText, setSearchText: (val, enter) => {
|
|
94
|
+
//we dont want empty enters to do anything
|
|
95
|
+
if (val === '' && enter) {
|
|
96
|
+
p.setSearchText(val, false);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
p.setSearchText(val, enter);
|
|
100
|
+
}
|
|
101
|
+
} }))));
|
|
102
|
+
};
|
|
103
|
+
exports.AutoHideSearchBox = AutoHideSearchBox;
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./AutoHideSearchBox"), exports);
|
|
17
18
|
__exportStar(require("./Base"), exports);
|
|
18
19
|
__exportStar(require("./Dialog"), exports);
|
|
19
20
|
__exportStar(require("./Inline"), exports);
|
|
@@ -138,7 +138,7 @@ const ToastProvider = ({ children, providerOptions, }) => {
|
|
|
138
138
|
const [toasts, setToasts] = (0, react_1.useState)([]);
|
|
139
139
|
const addToast = (message, options) => setToasts((currentToasts) => [
|
|
140
140
|
...currentToasts,
|
|
141
|
-
{ id: (0, common_1.
|
|
141
|
+
{ id: (0, common_1.random)(10000).toString(), message, options },
|
|
142
142
|
]);
|
|
143
143
|
const close = (id) => setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
|
|
144
144
|
const contextValue = (0, react_1.useMemo)(() => ({ addToast }), []);
|