@optiaxiom/proteus 1.0.0 → 1.1.0
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/esm/_virtual/_openai-shim-script.js +3 -2
- package/dist/esm/assets/src/proteus-chart/{ProteusChart.css.ts.vanilla-BeRNNwBj.css → ProteusChart.css.ts.vanilla-yGx8JdKz.css} +2 -2
- package/dist/esm/assets/src/proteus-chart/{ProteusChartTooltipContent.css.ts.vanilla-Df_IhL_i.css → ProteusChartTooltipContent.css.ts.vanilla-HapBe2oo.css} +2 -2
- package/dist/esm/assets/src/proteus-document/{ProteusDocumentShell.css.ts.vanilla-CyMtrn1n.css → ProteusDocumentShell.css.ts.vanilla-BPytQ9pT.css} +2 -2
- package/dist/esm/assets/src/proteus-image-carousel/{ProteusImageCarousel.css.ts.vanilla-Dbf7yRF1.css → ProteusImageCarousel.css.ts.vanilla-DnlXoyv1.css} +2 -2
- package/dist/esm/assets/src/proteus-question/{ProteusQuestion.css.ts.vanilla-cmHZWqNR.css → ProteusQuestion.css.ts.vanilla-CpDgoW0l.css} +2 -2
- package/dist/esm/hooks/useEffectEvent.js +11 -10
- package/dist/esm/hooks/useObserveValue.js +24 -30
- package/dist/esm/icons/IconAngleLeft.js +13 -19
- package/dist/esm/icons/IconAngleRight.js +13 -19
- package/dist/esm/icons/IconX.js +10 -18
- package/dist/esm/icons/withIcon.js +17 -28
- package/dist/esm/index.js +22 -17
- package/dist/esm/proteus-action/ProteusAction.js +44 -39
- package/dist/esm/proteus-bridge/ProteusBridge.js +71 -85
- package/dist/esm/proteus-card-link/ProteusCardLink.js +24 -37
- package/dist/esm/proteus-chart/ProteusChart-css.js +14 -5
- package/dist/esm/proteus-chart/ProteusChart.js +86 -84
- package/dist/esm/proteus-chart/ProteusChartContext.js +3 -3
- package/dist/esm/proteus-chart/ProteusChartTooltipContent-css.js +23 -6
- package/dist/esm/proteus-chart/ProteusChartTooltipContent.js +52 -66
- package/dist/esm/proteus-data-table/ProteusDataTable.js +28 -29
- package/dist/esm/proteus-date-input/ProteusDateInput.js +23 -0
- package/dist/esm/proteus-document/ProteusDocumentContext.js +4 -3
- package/dist/esm/proteus-document/ProteusDocumentPathContext.js +6 -5
- package/dist/esm/proteus-document/ProteusDocumentRenderer.js +25 -33
- package/dist/esm/proteus-document/ProteusDocumentShell-css.js +32 -6
- package/dist/esm/proteus-document/ProteusDocumentShell.js +226 -219
- package/dist/esm/proteus-document/getProteusValue.js +28 -42
- package/dist/esm/proteus-document/resolveProteusProp.js +31 -49
- package/dist/esm/proteus-document/resolveProteusValue.js +73 -136
- package/dist/esm/proteus-document/schemas.js +42 -45
- package/dist/esm/proteus-document/useResolveProteusValues.js +10 -16
- package/dist/esm/proteus-element/ProteusElement.js +114 -180
- package/dist/esm/proteus-federated/ProteusFederated.js +51 -52
- package/dist/esm/proteus-file-icon/ProteusFileIcon.js +29 -38
- package/dist/esm/proteus-file-upload/ProteusFileUpload.js +107 -133
- package/dist/esm/proteus-image/ProteusImage.js +99 -106
- package/dist/esm/proteus-image/downloadFile.js +3 -2
- package/dist/esm/proteus-image-carousel/ProteusImageCarousel-css.js +49 -11
- package/dist/esm/proteus-image-carousel/ProteusImageCarousel.js +151 -163
- package/dist/esm/proteus-input/ProteusInput.js +19 -27
- package/dist/esm/proteus-length/ProteusLength.js +10 -0
- package/dist/esm/proteus-map/ProteusMap.js +18 -31
- package/dist/esm/proteus-map-index/ProteusMapIndex.js +11 -0
- package/dist/esm/proteus-pill-menu/ProteusPillMenu.js +65 -0
- package/dist/esm/proteus-pill-menu/useInputValueChangeInteraction.js +36 -0
- package/dist/esm/proteus-question/ProteusQuestion-css.js +40 -8
- package/dist/esm/proteus-question/ProteusQuestion.js +324 -400
- package/dist/esm/proteus-select/ProteusSelect.js +25 -40
- package/dist/esm/proteus-show/ProteusShow.js +10 -18
- package/dist/esm/proteus-switch/ProteusSwitch.js +33 -36
- package/dist/esm/proteus-textarea/ProteusTextarea.js +18 -27
- package/dist/esm/proteus-value/ProteusValue.js +4 -4
- package/dist/esm/schema/public-schema.js +4537 -0
- package/dist/esm/schema/runtime-schema.js +4460 -0
- package/dist/esm/spec.js +5 -1
- package/dist/esm/use-proteus-value/useProteusValue.js +8 -12
- package/dist/index.d.ts +516 -347
- package/dist/spec.d.ts +5 -9952
- package/package.json +4 -4
- package/dist/esm/icons/IconCalendar.js +0 -20
- package/dist/esm/schema/public-schema.json.js +0 -9026
- package/dist/esm/schema/runtime-schema.json.js +0 -8959
|
@@ -1,90 +1,76 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
2
|
+
import { useProteusDocumentContext } from "../proteus-document/ProteusDocumentContext.js";
|
|
3
|
+
import { OPENAI_SHIM_SCRIPT } from "../_virtual/_openai-shim-script.js";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { AppBridge, PostMessageTransport } from "@modelcontextprotocol/ext-apps/app-bridge";
|
|
7
|
+
//#region src/proteus-bridge/ProteusBridge.tsx
|
|
8
8
|
function ProteusBridge({ height = 400, resource }) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return () => {
|
|
74
|
-
void bridge.close();
|
|
75
|
-
};
|
|
76
|
-
}, [iframe, onEvent]);
|
|
77
|
-
return result?.isError || !html ? null : /* @__PURE__ */ jsx(
|
|
78
|
-
"iframe",
|
|
79
|
-
{
|
|
80
|
-
ref: setIframe,
|
|
81
|
-
sandbox: "allow-scripts allow-popups allow-popups-to-escape-sandbox allow-forms",
|
|
82
|
-
srcDoc: mimeType === "text/html+skybridge" ? OPENAI_SHIM_SCRIPT + html : html,
|
|
83
|
-
style: { border: "none", height, width: "100%" },
|
|
84
|
-
title: "Opal Widget"
|
|
85
|
-
}
|
|
86
|
-
);
|
|
9
|
+
const { data, onEvent, useResource } = useProteusDocumentContext("@optiaxiom/proteus/ProteusBridge");
|
|
10
|
+
const result = useResource?.(resource);
|
|
11
|
+
const html = result?.data?.text ?? "";
|
|
12
|
+
const mimeType = result?.data?.mimeType;
|
|
13
|
+
const [iframe, setIframe] = useState(null);
|
|
14
|
+
const dataRef = useRef(data);
|
|
15
|
+
dataRef.current = data;
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!iframe?.contentWindow) return;
|
|
18
|
+
const bridge = new AppBridge(null, {
|
|
19
|
+
name: "Opal",
|
|
20
|
+
version: "1.0.0"
|
|
21
|
+
}, {
|
|
22
|
+
logging: {},
|
|
23
|
+
openLinks: {},
|
|
24
|
+
serverTools: {}
|
|
25
|
+
}, { hostContext: {
|
|
26
|
+
containerDimensions: { maxHeight: iframe.clientHeight },
|
|
27
|
+
displayMode: "inline"
|
|
28
|
+
} });
|
|
29
|
+
bridge.oncalltool = async (params) => {
|
|
30
|
+
const result = await onEvent({
|
|
31
|
+
interaction: params.name,
|
|
32
|
+
params: params.arguments ?? {}
|
|
33
|
+
});
|
|
34
|
+
return { content: [{
|
|
35
|
+
text: JSON.stringify(result ?? ""),
|
|
36
|
+
type: "text"
|
|
37
|
+
}] };
|
|
38
|
+
};
|
|
39
|
+
bridge.onmessage = async (params) => {
|
|
40
|
+
await onEvent({ message: params.content?.filter((content) => content.type === "text").map((content) => content.text).join("\n\n") ?? "" });
|
|
41
|
+
return {};
|
|
42
|
+
};
|
|
43
|
+
bridge.onopenlink = async ({ url }) => {
|
|
44
|
+
window.open(url, "_blank", "noopener");
|
|
45
|
+
return {};
|
|
46
|
+
};
|
|
47
|
+
bridge.addEventListener("sizechange", ({ height }) => {
|
|
48
|
+
if (height != null) iframe.style.height = `${height}px`;
|
|
49
|
+
});
|
|
50
|
+
bridge.addEventListener("initialized", () => {
|
|
51
|
+
bridge.sendToolResult({ content: [{
|
|
52
|
+
text: JSON.stringify(dataRef.current),
|
|
53
|
+
type: "text"
|
|
54
|
+
}] });
|
|
55
|
+
});
|
|
56
|
+
const transport = new PostMessageTransport(iframe.contentWindow, iframe.contentWindow);
|
|
57
|
+
bridge.connect(transport);
|
|
58
|
+
return () => {
|
|
59
|
+
bridge.close();
|
|
60
|
+
};
|
|
61
|
+
}, [iframe, onEvent]);
|
|
62
|
+
return result?.isError || !html ? null : /* @__PURE__ */ jsx("iframe", {
|
|
63
|
+
ref: setIframe,
|
|
64
|
+
sandbox: "allow-scripts allow-popups allow-popups-to-escape-sandbox allow-forms",
|
|
65
|
+
srcDoc: mimeType === "text/html+skybridge" ? OPENAI_SHIM_SCRIPT + html : html,
|
|
66
|
+
style: {
|
|
67
|
+
border: "none",
|
|
68
|
+
height,
|
|
69
|
+
width: "100%"
|
|
70
|
+
},
|
|
71
|
+
title: "Opal Widget"
|
|
72
|
+
});
|
|
87
73
|
}
|
|
88
74
|
ProteusBridge.displayName = "@optiaxiom/proteus/ProteusBridge";
|
|
89
|
-
|
|
75
|
+
//#endregion
|
|
90
76
|
export { ProteusBridge };
|
|
@@ -1,41 +1,28 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
function ProteusCardLink({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
event.preventDefault();
|
|
26
|
-
if (loading) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
setLoading(true);
|
|
30
|
-
await onEvent(resolvedOnClick);
|
|
31
|
-
setLoading(false);
|
|
32
|
-
} : void 0,
|
|
33
|
-
target: "_blank",
|
|
34
|
-
...props,
|
|
35
|
-
children
|
|
36
|
-
}
|
|
37
|
-
);
|
|
2
|
+
import { useProteusDocumentContext } from "../proteus-document/ProteusDocumentContext.js";
|
|
3
|
+
import { useResolveProteusValues } from "../proteus-document/useResolveProteusValues.js";
|
|
4
|
+
import { CardLink } from "@optiaxiom/react";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
//#region src/proteus-card-link/ProteusCardLink.tsx
|
|
8
|
+
function ProteusCardLink({ children, onClick, ...props }) {
|
|
9
|
+
const { onEvent } = useProteusDocumentContext("@optiaxiom/proteus/ProteusCardLink");
|
|
10
|
+
const resolvedOnClick = useResolveProteusValues(onClick ?? {});
|
|
11
|
+
const [loading, setLoading] = useState(false);
|
|
12
|
+
return /* @__PURE__ */ jsx(CardLink, {
|
|
13
|
+
"aria-busy": loading || void 0,
|
|
14
|
+
onClick: onClick ? async (event) => {
|
|
15
|
+
event.preventDefault();
|
|
16
|
+
if (loading) return;
|
|
17
|
+
setLoading(true);
|
|
18
|
+
await onEvent(resolvedOnClick);
|
|
19
|
+
setLoading(false);
|
|
20
|
+
} : void 0,
|
|
21
|
+
target: "_blank",
|
|
22
|
+
...props,
|
|
23
|
+
children
|
|
24
|
+
});
|
|
38
25
|
}
|
|
39
26
|
ProteusCardLink.displayName = "@optiaxiom/proteus/ProteusCardLink";
|
|
40
|
-
|
|
27
|
+
//#endregion
|
|
41
28
|
export { ProteusCardLink };
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { recipe } from
|
|
3
|
-
|
|
4
|
-
var chart = recipe({base:[
|
|
5
|
-
|
|
1
|
+
import "./../assets/src/proteus-chart/ProteusChart.css.ts.vanilla-yGx8JdKz.css";
|
|
2
|
+
import { recipe } from "@optiaxiom/react/css-runtime";
|
|
3
|
+
//#region src/proteus-chart/ProteusChart.css.ts
|
|
4
|
+
var chart = recipe({ base: [
|
|
5
|
+
{
|
|
6
|
+
border: "1",
|
|
7
|
+
borderColor: "border.tertiary",
|
|
8
|
+
fontSize: "sm",
|
|
9
|
+
p: "16"
|
|
10
|
+
},
|
|
11
|
+
"ProteusChart__jmlqij1",
|
|
12
|
+
"ProteusChart__jmlqij0"
|
|
13
|
+
] });
|
|
14
|
+
//#endregion
|
|
6
15
|
export { chart };
|
|
@@ -1,89 +1,91 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
const DEFAULT_COLORS = [
|
|
2
|
+
import { chart } from "./ProteusChart-css.js";
|
|
3
|
+
import { ProteusChartContext } from "./ProteusChartContext.js";
|
|
4
|
+
import { ProteusChartTooltipContent } from "./ProteusChartTooltipContent.js";
|
|
5
|
+
import { Box, theme } from "@optiaxiom/react";
|
|
6
|
+
import { useRef } from "react";
|
|
7
|
+
import { get } from "jsonpointer";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { Bar, BarChart, CartesianGrid, Line, LineChart, ResponsiveContainer, Tooltip as Tooltip$1, XAxis, YAxis } from "recharts";
|
|
10
|
+
//#region src/proteus-chart/ProteusChart.tsx
|
|
11
|
+
const DEFAULT_COLORS = [
|
|
12
|
+
"#096DD9",
|
|
13
|
+
"#E59700",
|
|
14
|
+
"#38C56C",
|
|
15
|
+
"#D1D8DE"
|
|
16
|
+
];
|
|
12
17
|
const getColor = (index) => DEFAULT_COLORS[index % DEFAULT_COLORS.length];
|
|
13
|
-
const ProteusChart = ({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
i
|
|
84
|
-
))
|
|
85
|
-
] }) }) }) });
|
|
18
|
+
const ProteusChart = ({ data, layout = "horizontal", series, type, xAxisKey }) => {
|
|
19
|
+
const isVertical = layout === "vertical";
|
|
20
|
+
const ChartComponent = type === "bar" ? BarChart : LineChart;
|
|
21
|
+
const Chart = type === "bar" ? Bar : Line;
|
|
22
|
+
const CategoryAxis = isVertical ? YAxis : XAxis;
|
|
23
|
+
const ValueAxis = isVertical ? XAxis : YAxis;
|
|
24
|
+
const containerRef = useRef(null);
|
|
25
|
+
return /* @__PURE__ */ jsx(ProteusChartContext.Provider, {
|
|
26
|
+
value: containerRef,
|
|
27
|
+
children: /* @__PURE__ */ jsx(Box, {
|
|
28
|
+
asChild: true,
|
|
29
|
+
ref: containerRef,
|
|
30
|
+
...chart(),
|
|
31
|
+
children: /* @__PURE__ */ jsx(ResponsiveContainer, {
|
|
32
|
+
aspect: 16 / 9,
|
|
33
|
+
width: "100%",
|
|
34
|
+
children: /* @__PURE__ */ jsxs(ChartComponent, {
|
|
35
|
+
data,
|
|
36
|
+
layout,
|
|
37
|
+
children: [
|
|
38
|
+
/* @__PURE__ */ jsx(CartesianGrid, {
|
|
39
|
+
stroke: theme.colors["border.secondary"],
|
|
40
|
+
strokeDasharray: "4 4",
|
|
41
|
+
vertical: false
|
|
42
|
+
}),
|
|
43
|
+
/* @__PURE__ */ jsx(CategoryAxis, {
|
|
44
|
+
axisLine: false,
|
|
45
|
+
dataKey: (row) => get(row, "/" + xAxisKey),
|
|
46
|
+
padding: {
|
|
47
|
+
left: 16,
|
|
48
|
+
right: 16
|
|
49
|
+
},
|
|
50
|
+
tick: { fill: theme.colors["fg.secondary"] },
|
|
51
|
+
tickFormatter: (value) => value.length > 30 ? value.slice(0, 30) + "…" : value,
|
|
52
|
+
tickLine: false,
|
|
53
|
+
tickMargin: 8,
|
|
54
|
+
type: "category",
|
|
55
|
+
width: isVertical ? "auto" : void 0
|
|
56
|
+
}),
|
|
57
|
+
/* @__PURE__ */ jsx(ValueAxis, {
|
|
58
|
+
axisLine: { stroke: theme.colors["border.default"] },
|
|
59
|
+
minTickGap: 32,
|
|
60
|
+
tick: { fill: theme.colors["fg.secondary"] },
|
|
61
|
+
tickFormatter: (value) => new Intl.NumberFormat(void 0, {
|
|
62
|
+
compactDisplay: "short",
|
|
63
|
+
notation: "compact"
|
|
64
|
+
}).format(value),
|
|
65
|
+
tickMargin: 8,
|
|
66
|
+
type: "number",
|
|
67
|
+
width: isVertical ? void 0 : "auto"
|
|
68
|
+
}),
|
|
69
|
+
/* @__PURE__ */ jsx(Tooltip$1, {
|
|
70
|
+
content: ProteusChartTooltipContent,
|
|
71
|
+
cursor: false,
|
|
72
|
+
portal: document.body
|
|
73
|
+
}),
|
|
74
|
+
series?.map((s, i) => /* @__PURE__ */ jsx(Chart, {
|
|
75
|
+
dataKey: (row) => get(row, "/" + s.dataKey),
|
|
76
|
+
dot: false,
|
|
77
|
+
fill: getColor(i),
|
|
78
|
+
name: s.name ?? s.dataKey,
|
|
79
|
+
radius: type === "bar" ? 4 : void 0,
|
|
80
|
+
stroke: getColor(i),
|
|
81
|
+
type: "natural"
|
|
82
|
+
}, i))
|
|
83
|
+
]
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
});
|
|
86
88
|
};
|
|
87
89
|
ProteusChart.displayName = "@optiaxiom/proteus/ProteusChart";
|
|
88
|
-
|
|
90
|
+
//#endregion
|
|
89
91
|
export { ProteusChart };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { createContext, useContext } from
|
|
3
|
-
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
//#region src/proteus-chart/ProteusChartContext.tsx
|
|
4
4
|
const ProteusChartContext = createContext(void 0);
|
|
5
5
|
const useProteusChartContainer = () => useContext(ProteusChartContext);
|
|
6
|
-
|
|
6
|
+
//#endregion
|
|
7
7
|
export { ProteusChartContext, useProteusChartContainer };
|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
var tooltip = recipe({base:[{
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { recipe } from "@optiaxiom/react/css-runtime";
|
|
2
|
+
import "./../assets/src/proteus-chart/ProteusChartTooltipContent.css.ts.vanilla-HapBe2oo.css";
|
|
3
|
+
//#region src/proteus-chart/ProteusChartTooltipContent.css.ts
|
|
4
|
+
var tooltip = recipe({ base: [{
|
|
5
|
+
bg: "bg.default",
|
|
6
|
+
border: "1",
|
|
7
|
+
borderColor: "border.secondary",
|
|
8
|
+
display: "grid",
|
|
9
|
+
fontSize: "sm",
|
|
10
|
+
gap: "6",
|
|
11
|
+
pointerEvents: "none",
|
|
12
|
+
px: "8",
|
|
13
|
+
py: "10",
|
|
14
|
+
rounded: "lg",
|
|
15
|
+
shadow: "lg",
|
|
16
|
+
transition: "all",
|
|
17
|
+
z: "popover"
|
|
18
|
+
}, "ProteusChartTooltipContent__1gsvq810"] });
|
|
19
|
+
var value = recipe({ base: [{
|
|
20
|
+
color: "fg.default",
|
|
21
|
+
fontWeight: "500"
|
|
22
|
+
}, "ProteusChartTooltipContent__1gsvq811"] });
|
|
23
|
+
//#endregion
|
|
7
24
|
export { tooltip, value };
|
|
@@ -1,70 +1,56 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
2
|
+
import { applyFormatter } from "../proteus-document/getProteusValue.js";
|
|
3
|
+
import { useProteusChartContainer } from "./ProteusChartContext.js";
|
|
4
|
+
import { tooltip, value } from "./ProteusChartTooltipContent-css.js";
|
|
5
|
+
import { Box, Group } from "@optiaxiom/react";
|
|
6
|
+
import { useRef } from "react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
//#region src/proteus-chart/ProteusChartTooltipContent.tsx
|
|
9
9
|
const OFFSET = 10;
|
|
10
|
-
function ProteusChartTooltipContent({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
size: "10",
|
|
55
|
-
style: { backgroundColor: item.color }
|
|
56
|
-
}
|
|
57
|
-
),
|
|
58
|
-
/* @__PURE__ */ jsx(Box, { color: "fg.tertiary", children: item.name ?? String(item.dataKey) })
|
|
59
|
-
] }),
|
|
60
|
-
/* @__PURE__ */ jsx(Box, { ...value(), children: applyFormatter(item.value, "Number") })
|
|
61
|
-
]
|
|
62
|
-
},
|
|
63
|
-
i
|
|
64
|
-
)) })
|
|
65
|
-
]
|
|
66
|
-
}
|
|
67
|
-
);
|
|
10
|
+
function ProteusChartTooltipContent({ active, coordinate, label, payload }) {
|
|
11
|
+
const containerRef = useProteusChartContainer();
|
|
12
|
+
const ref = useRef(null);
|
|
13
|
+
if (!active || !payload?.length) return null;
|
|
14
|
+
const wrapperRect = containerRef?.current?.querySelector(".recharts-wrapper")?.getBoundingClientRect();
|
|
15
|
+
const tooltipRect = ref.current?.getBoundingClientRect();
|
|
16
|
+
const cx = coordinate?.x ?? 0;
|
|
17
|
+
const cy = coordinate?.y ?? 0;
|
|
18
|
+
const th = tooltipRect?.height ?? 0;
|
|
19
|
+
const translateX = cx + OFFSET;
|
|
20
|
+
const translateY = cy - th / 2;
|
|
21
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
22
|
+
ref,
|
|
23
|
+
style: {
|
|
24
|
+
left: 0,
|
|
25
|
+
top: 0,
|
|
26
|
+
transform: `translate(${(wrapperRect?.left ?? 0) + translateX + window.scrollX}px, ${(wrapperRect?.top ?? 0) + translateY + window.scrollY}px)`
|
|
27
|
+
},
|
|
28
|
+
...tooltip(),
|
|
29
|
+
children: [label && /* @__PURE__ */ jsx(Box, {
|
|
30
|
+
fontWeight: "500",
|
|
31
|
+
children: label
|
|
32
|
+
}), /* @__PURE__ */ jsx("div", { children: payload.filter((item) => item.type !== "none").map((item, i) => /* @__PURE__ */ jsxs(Box, {
|
|
33
|
+
alignItems: "center",
|
|
34
|
+
display: "flex",
|
|
35
|
+
gap: "8",
|
|
36
|
+
justifyContent: "space-between",
|
|
37
|
+
children: [/* @__PURE__ */ jsxs(Group, {
|
|
38
|
+
gap: "8",
|
|
39
|
+
children: [/* @__PURE__ */ jsx(Box, {
|
|
40
|
+
flex: "none",
|
|
41
|
+
rounded: "xs",
|
|
42
|
+
size: "10",
|
|
43
|
+
style: { backgroundColor: item.color }
|
|
44
|
+
}), /* @__PURE__ */ jsx(Box, {
|
|
45
|
+
color: "fg.tertiary",
|
|
46
|
+
children: item.name ?? String(item.dataKey)
|
|
47
|
+
})]
|
|
48
|
+
}), /* @__PURE__ */ jsx(Box, {
|
|
49
|
+
...value(),
|
|
50
|
+
children: applyFormatter(item.value, "Number")
|
|
51
|
+
})]
|
|
52
|
+
}, i)) })]
|
|
53
|
+
});
|
|
68
54
|
}
|
|
69
|
-
|
|
55
|
+
//#endregion
|
|
70
56
|
export { ProteusChartTooltipContent };
|