ag-common 0.0.698 → 0.0.699
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/ui/components/Modal/Modal.d.ts +1 -1
- package/dist/ui/components/Modal/Modal.js +4 -2
- package/dist/ui/components/TreeChart/TooltipContent.d.ts +7 -0
- package/dist/ui/components/TreeChart/TooltipContent.js +33 -0
- package/dist/ui/components/TreeChart/base.js +35 -13
- package/dist/ui/components/TreeChart/helpers.d.ts +1 -11
- package/dist/ui/components/TreeChart/helpers.js +10 -20
- package/dist/ui/components/TreeChart/types.d.ts +4 -1
- package/dist/ui/helpers/useTooltip.d.ts +9 -9
- package/dist/ui/helpers/useTooltip.js +11 -3
- package/package.json +1 -1
|
@@ -4,4 +4,4 @@ export declare const ModalItem: import("@emotion/styled").StyledComponent<{
|
|
|
4
4
|
theme?: import("@emotion/react").Theme | undefined;
|
|
5
5
|
as?: React.ElementType<any, keyof React.JSX.IntrinsicElements> | undefined;
|
|
6
6
|
}, React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
7
|
-
export declare const Modal: (
|
|
7
|
+
export declare const Modal: (p: IModal) => React.JSX.Element | null;
|
|
@@ -31,6 +31,7 @@ exports.Modal = exports.ModalItem = void 0;
|
|
|
31
31
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
32
32
|
const react_1 = __importStar(require("react"));
|
|
33
33
|
const react_dom_1 = require("react-dom");
|
|
34
|
+
const dom_1 = require("../../helpers/dom");
|
|
34
35
|
const useOnClickOutside_1 = require("../../helpers/useOnClickOutside");
|
|
35
36
|
const styles_1 = require("../../styles");
|
|
36
37
|
const Close_1 = require("../Close");
|
|
@@ -85,7 +86,8 @@ exports.ModalItem = styled_1.default.div `
|
|
|
85
86
|
const CloseStyled = (0, styled_1.default)(Close_1.Close) `
|
|
86
87
|
z-index: 1;
|
|
87
88
|
`;
|
|
88
|
-
const Modal = (
|
|
89
|
+
const Modal = (p) => {
|
|
90
|
+
const { open, setOpen, children, position = 'left', topPosition = 'top', showCloseButton = true, closeOnMoveMouseOutside = false, className, closeOnClickOutside = true, portalId: pidraw, style, } = p;
|
|
89
91
|
let portalId = pidraw;
|
|
90
92
|
if (portalId === undefined) {
|
|
91
93
|
portalId = globalId;
|
|
@@ -158,7 +160,7 @@ const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top'
|
|
|
158
160
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
159
161
|
}
|
|
160
162
|
const Content = (react_1.default.createElement(FixedBackground, null,
|
|
161
|
-
react_1.default.createElement(ModalBase, { "data-bounced": bounced, "data-position": position, "data-topposition": topPosition, ref: ref, className: className, style: style },
|
|
163
|
+
react_1.default.createElement(ModalBase, Object.assign({}, (0, dom_1.filterDataProps)(p), { "data-bounced": bounced, "data-position": position, "data-topposition": topPosition, ref: ref, className: className, style: style }),
|
|
162
164
|
showCloseButton && (react_1.default.createElement(CloseStyled, { "data-type": "modal-close", onClick: (e) => setOpen(false, e) })),
|
|
163
165
|
children)));
|
|
164
166
|
if (portalId && portalElem === undefined) {
|
|
@@ -0,0 +1,33 @@
|
|
|
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.TooltipContent = void 0;
|
|
7
|
+
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const Base = styled_1.default.div `
|
|
10
|
+
padding: 0.5rem;
|
|
11
|
+
border: solid 1px black;
|
|
12
|
+
background-color: white;
|
|
13
|
+
`;
|
|
14
|
+
const Title = styled_1.default.div `
|
|
15
|
+
font-weight: bold;
|
|
16
|
+
`;
|
|
17
|
+
const TooltipContent = ({ data, node, head, }) => {
|
|
18
|
+
var _a;
|
|
19
|
+
let rows = [];
|
|
20
|
+
let n = node;
|
|
21
|
+
while (n) {
|
|
22
|
+
const t = ((_a = data.titleFn) === null || _a === void 0 ? void 0 : _a.call(data, {
|
|
23
|
+
path: n.name,
|
|
24
|
+
pathCount: n.size,
|
|
25
|
+
fullCount: head.size,
|
|
26
|
+
})) || `${n.name} (${n.size}/${head.size})`;
|
|
27
|
+
rows = [t, ...rows];
|
|
28
|
+
n = n.parent;
|
|
29
|
+
}
|
|
30
|
+
return (react_1.default.createElement(Base, null,
|
|
31
|
+
react_1.default.createElement(Title, null, rows.map((r, i) => (react_1.default.createElement("div", { key: r, style: { marginLeft: `${i * 2}px` } }, r))))));
|
|
32
|
+
};
|
|
33
|
+
exports.TooltipContent = TooltipContent;
|
|
@@ -31,9 +31,11 @@ exports.TreeChart = void 0;
|
|
|
31
31
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
32
32
|
const react_1 = __importStar(require("react"));
|
|
33
33
|
const useResize_1 = require("../../helpers/useResize");
|
|
34
|
+
const useTooltip_1 = require("../../helpers/useTooltip");
|
|
34
35
|
const styles_1 = require("../../styles");
|
|
35
36
|
const common_1 = require("../../styles/common");
|
|
36
37
|
const helpers_1 = require("./helpers");
|
|
38
|
+
const TooltipContent_1 = require("./TooltipContent");
|
|
37
39
|
const Base = styled_1.default.div `
|
|
38
40
|
border: solid 1px #ccc;
|
|
39
41
|
max-height: 100%;
|
|
@@ -68,28 +70,38 @@ const Title = styled_1.default.div `
|
|
|
68
70
|
min-height: 1rem;
|
|
69
71
|
line-height: 1rem;
|
|
70
72
|
`;
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
const leaf =
|
|
73
|
+
const Render = ({ n, depth, head, headDim, tnd, UT, }) => {
|
|
74
|
+
const children = Object.values(n.children);
|
|
75
|
+
const leaf = children.length === 0;
|
|
74
76
|
const sizeMult = n.size / head.size;
|
|
75
77
|
const biggerDim = Math.max(headDim.width, headDim.height);
|
|
76
78
|
const nodeSize = Math.floor(biggerDim * sizeMult).toString();
|
|
77
|
-
const title = ((_a = tnd.titleFn) === null || _a === void 0 ? void 0 : _a.call(tnd, {
|
|
78
|
-
path: n.name,
|
|
79
|
-
pathCount: n.size,
|
|
80
|
-
fullCount: head.size,
|
|
81
|
-
})) || `${n.name} (${n.size}/${head.size})`;
|
|
82
79
|
return (react_1.default.createElement(Node, { "data-treenode": true, "data-leaf": leaf.toString(), style: Object.assign({ backgroundColor: (0, styles_1.getColourWheel)(depth) }, (leaf &&
|
|
83
80
|
nodeSize && {
|
|
84
81
|
width: nodeSize + 'px',
|
|
85
82
|
height: nodeSize + 'px',
|
|
86
|
-
})), key: n.name, "data-ch": n.children.length, "data-size": n.size,
|
|
83
|
+
})), key: n.name, "data-ch": n.children.length, "data-size": n.size, onMouseLeave: () => UT.setPos(undefined), onMouseMove: (element) => {
|
|
84
|
+
UT.setPos({
|
|
85
|
+
element,
|
|
86
|
+
parent: null,
|
|
87
|
+
data: { data: tnd, node: n, head },
|
|
88
|
+
});
|
|
89
|
+
element.preventDefault();
|
|
90
|
+
element.stopPropagation();
|
|
91
|
+
} },
|
|
87
92
|
n.name && react_1.default.createElement(Title, null, n.name),
|
|
88
|
-
|
|
93
|
+
children.length > 0 && (react_1.default.createElement(NodeChildren, { "data-type": "nc" }, children.map((c) => Render({
|
|
94
|
+
UT,
|
|
95
|
+
n: c,
|
|
96
|
+
depth: depth + 1,
|
|
97
|
+
head,
|
|
98
|
+
headDim,
|
|
99
|
+
tnd,
|
|
100
|
+
}))))));
|
|
89
101
|
};
|
|
90
102
|
const TreeChart = (tnd) => {
|
|
91
|
-
const
|
|
92
|
-
const head = (0, helpers_1.
|
|
103
|
+
const UT = (0, useTooltip_1.useTooltip)();
|
|
104
|
+
const head = (0, helpers_1.convertToRaw)({ tnd });
|
|
93
105
|
const pd = (0, useResize_1.useResize)();
|
|
94
106
|
const [headDim, setHeadDim] = (0, react_1.useState)();
|
|
95
107
|
const r = (0, react_1.useRef)(null);
|
|
@@ -107,6 +119,16 @@ const TreeChart = (tnd) => {
|
|
|
107
119
|
if (head.size === 0) {
|
|
108
120
|
return react_1.default.createElement("div", null);
|
|
109
121
|
}
|
|
110
|
-
return (react_1.default.createElement(Base, { ref: r, className: tnd.className, style: tnd.style },
|
|
122
|
+
return (react_1.default.createElement(Base, { ref: r, className: tnd.className, style: tnd.style },
|
|
123
|
+
react_1.default.createElement(UT.Comp, { pos: UT.pos }, (p) => react_1.default.createElement(TooltipContent_1.TooltipContent, Object.assign({}, p))),
|
|
124
|
+
headDim &&
|
|
125
|
+
Render({
|
|
126
|
+
UT,
|
|
127
|
+
tnd,
|
|
128
|
+
n: head,
|
|
129
|
+
depth: 0,
|
|
130
|
+
head,
|
|
131
|
+
headDim,
|
|
132
|
+
})));
|
|
111
133
|
};
|
|
112
134
|
exports.TreeChart = TreeChart;
|
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
import type { TreeNodeData, TreeNodeOut } from './types';
|
|
2
|
-
interface TreeNodeRaw {
|
|
3
|
-
name: string;
|
|
4
|
-
size: number;
|
|
5
|
-
depth: number;
|
|
6
|
-
children: {
|
|
7
|
-
[P in string]: TreeNodeRaw;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
2
|
export declare const convertToRaw: ({ tnd: { data, pathDelimiter }, }: {
|
|
11
3
|
tnd: TreeNodeData;
|
|
12
|
-
}) =>
|
|
13
|
-
export declare const toArray: (name: string, raw: TreeNodeRaw) => TreeNodeOut;
|
|
14
|
-
export {};
|
|
4
|
+
}) => TreeNodeOut;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.convertToRaw = void 0;
|
|
4
4
|
const convertToRaw = ({ tnd: { data, pathDelimiter }, }) => {
|
|
5
5
|
if (data.length === 0) {
|
|
6
|
-
return { children: {}, size: 0, name: '', depth: 0 };
|
|
6
|
+
return { children: {}, size: 0, name: '', depth: 0, parent: undefined };
|
|
7
7
|
}
|
|
8
|
-
const dm = {
|
|
8
|
+
const dm = {
|
|
9
|
+
size: 0,
|
|
10
|
+
children: {},
|
|
11
|
+
name: '',
|
|
12
|
+
depth: 0,
|
|
13
|
+
parent: undefined,
|
|
14
|
+
};
|
|
9
15
|
data.forEach((line) => {
|
|
10
16
|
const names = line.path.split(pathDelimiter || '/');
|
|
11
17
|
let node = dm;
|
|
@@ -23,6 +29,7 @@ const convertToRaw = ({ tnd: { data, pathDelimiter }, }) => {
|
|
|
23
29
|
size: 0,
|
|
24
30
|
name: names[a],
|
|
25
31
|
depth: a,
|
|
32
|
+
parent: node,
|
|
26
33
|
};
|
|
27
34
|
}
|
|
28
35
|
node = node.children[names[a]];
|
|
@@ -32,20 +39,3 @@ const convertToRaw = ({ tnd: { data, pathDelimiter }, }) => {
|
|
|
32
39
|
return dm;
|
|
33
40
|
};
|
|
34
41
|
exports.convertToRaw = convertToRaw;
|
|
35
|
-
const toArrayAux = (name, n) => ({
|
|
36
|
-
name,
|
|
37
|
-
size: n.size,
|
|
38
|
-
depth: n.depth,
|
|
39
|
-
children: Object.entries(n.children).map(([cn, cv]) => toArrayAux(cn, cv)),
|
|
40
|
-
});
|
|
41
|
-
const toArray = (name, raw) => {
|
|
42
|
-
const arr = toArrayAux(name, {
|
|
43
|
-
children: raw.children,
|
|
44
|
-
size: 0,
|
|
45
|
-
name: '',
|
|
46
|
-
depth: 0,
|
|
47
|
-
});
|
|
48
|
-
arr.size = arr.children.map((d) => d.size).reduce((a, b) => a + b, 0);
|
|
49
|
-
return arr;
|
|
50
|
-
};
|
|
51
|
-
exports.toArray = toArray;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { MouseEvent } from 'react';
|
|
2
|
-
import React from 'react';
|
|
3
2
|
interface IPos<T> {
|
|
4
3
|
cursor: MouseEvent;
|
|
5
4
|
data: T;
|
|
@@ -10,20 +9,21 @@ interface IPos<T> {
|
|
|
10
9
|
x: number;
|
|
11
10
|
y: number;
|
|
12
11
|
}
|
|
13
|
-
type
|
|
12
|
+
type ITooltipProps = {
|
|
14
13
|
/** default 'ag-tooltip-portal' */
|
|
15
14
|
portalId: string;
|
|
16
15
|
};
|
|
17
|
-
export
|
|
18
|
-
Comp: <
|
|
19
|
-
pos: IPos<
|
|
20
|
-
children: (data:
|
|
21
|
-
}) =>
|
|
16
|
+
export interface IUseTooltip<T> {
|
|
17
|
+
Comp: <T>({ pos, children, }: {
|
|
18
|
+
pos: IPos<T> | undefined;
|
|
19
|
+
children: (data: T) => JSX.Element;
|
|
20
|
+
}) => JSX.Element | null;
|
|
22
21
|
setPos: (p?: {
|
|
23
22
|
element: MouseEvent;
|
|
24
23
|
parent: Element | null;
|
|
25
24
|
data: T;
|
|
26
|
-
}) => void;
|
|
25
|
+
} | undefined) => void;
|
|
27
26
|
pos: IPos<T> | undefined;
|
|
28
|
-
}
|
|
27
|
+
}
|
|
28
|
+
export declare const useTooltip: <T>(p?: ITooltipProps) => IUseTooltip<T>;
|
|
29
29
|
export {};
|
|
@@ -87,7 +87,7 @@ const Comp = ({ pos, children, }) => {
|
|
|
87
87
|
top = 0;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
const Content = (react_1.default.createElement(Base, { ref: ref, style: Object.assign(Object.assign({ left,
|
|
90
|
+
const Content = (react_1.default.createElement(Base, { "data-type": "tooltip-content", ref: ref, style: Object.assign(Object.assign({ left,
|
|
91
91
|
right,
|
|
92
92
|
top,
|
|
93
93
|
bottom, zIndex: 10 }, (pos.usePortal && { position: 'fixed' })), (!(size === null || size === void 0 ? void 0 : size.p) && { zIndex: -1 })) }, children(pos.data)));
|
|
@@ -127,6 +127,8 @@ const useTooltip = (p) => {
|
|
|
127
127
|
let parentLeft = 0;
|
|
128
128
|
let parentWidth = document.body.clientWidth;
|
|
129
129
|
let parentHeight = document.body.clientHeight;
|
|
130
|
+
let x = 0;
|
|
131
|
+
let y = 0;
|
|
130
132
|
if (p.parent) {
|
|
131
133
|
({
|
|
132
134
|
top: parentTop,
|
|
@@ -134,9 +136,15 @@ const useTooltip = (p) => {
|
|
|
134
136
|
width: parentWidth,
|
|
135
137
|
height: parentHeight,
|
|
136
138
|
} = p.parent.getBoundingClientRect());
|
|
139
|
+
x = p.element.pageX - parentLeft;
|
|
140
|
+
y = p.element.pageY - parentTop;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
parentWidth = window.innerWidth;
|
|
144
|
+
parentHeight = window.innerHeight;
|
|
145
|
+
x = p.element.clientX;
|
|
146
|
+
y = p.element.clientY;
|
|
137
147
|
}
|
|
138
|
-
const x = p.element.pageX - parentLeft;
|
|
139
|
-
const y = p.element.pageY - parentTop;
|
|
140
148
|
const p2 = {
|
|
141
149
|
cursor: p.element,
|
|
142
150
|
data: p.data,
|
package/package.json
CHANGED