@ocelescope/resources 0.7.0 → 0.9.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/index.d.ts +6 -6
- package/dist/index.js +128 -19
- package/package.json +13 -12
package/dist/index.d.ts
CHANGED
|
@@ -2,14 +2,14 @@ import { Select } from "@mantine/core";
|
|
|
2
2
|
import { GetResourceResponse } from "@ocelescope/api-base";
|
|
3
3
|
import { ComponentProps } from "react";
|
|
4
4
|
//#region src/components/ResourceModal/ResourceModal.d.ts
|
|
5
|
-
declare const ResourceModal: React.FC<{
|
|
5
|
+
export declare const ResourceModal: React.FC<{
|
|
6
6
|
id: string;
|
|
7
7
|
onClose: () => void;
|
|
8
8
|
}>;
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region src/components/ResourceSelect/ResourceSelect.d.ts
|
|
11
|
-
declare const ResourceSelect: React.FC<ComponentProps<typeof Select> & {
|
|
12
|
-
type
|
|
11
|
+
export declare const ResourceSelect: React.FC<Omit<ComponentProps<typeof Select<string>>, "data"> & {
|
|
12
|
+
type?: string;
|
|
13
13
|
}>;
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/types/index.d.ts
|
|
@@ -35,10 +35,10 @@ type VisualizationProps<T extends VisualizationsTypes> = {
|
|
|
35
35
|
isPreview?: boolean;
|
|
36
36
|
menuItems?: ExtraMenuItem[];
|
|
37
37
|
};
|
|
38
|
-
declare const Visualization: ({ visualization, isPreview, menuItems }: VisualizationProps<VisualizationsTypes>) => import("react").JSX.Element;
|
|
39
|
-
declare const ResourceViewer: React.FC<{
|
|
38
|
+
export declare const Visualization: ({ visualization, isPreview, menuItems }: VisualizationProps<VisualizationsTypes>) => import("react").JSX.Element;
|
|
39
|
+
export declare const ResourceViewer: React.FC<{
|
|
40
40
|
id: string;
|
|
41
41
|
isPreview?: boolean;
|
|
42
42
|
}>;
|
|
43
43
|
//#endregion
|
|
44
|
-
export {
|
|
44
|
+
export type { VisualizationsType };
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,76 @@
|
|
|
1
1
|
import { ActionIcon, Alert, Badge, Box, Button, ButtonGroup, Code, Group, LoadingOverlay, Menu, Modal, Popover, ScrollArea, Select, Stack, Text, ThemeIcon, Title } from "@mantine/core";
|
|
2
2
|
import { useResource, useResources } from "@ocelescope/api-base";
|
|
3
3
|
import { DownloadIcon, EyeOffIcon, Maximize2Icon, MaximizeIcon, MinusIcon, PlusIcon, XIcon } from "lucide-react";
|
|
4
|
+
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import dynamic from "next/dynamic.js";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
7
|
import { Graphviz } from "@hpcc-js/wasm-graphviz";
|
|
5
8
|
import FileSaver from "file-saver";
|
|
6
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
-
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
8
9
|
import { TransformComponent, TransformWrapper } from "react-zoom-pan-pinch";
|
|
9
10
|
import { Background, BaseEdge, ControlButton, Controls, EdgeLabelRenderer, Handle, Position, ReactFlow, ReactFlowProvider, applyNodeChanges, getBezierPath, getSmoothStepPath, useInternalNode, useReactFlow } from "@xyflow/react";
|
|
10
11
|
import { toPng, toSvg } from "html-to-image";
|
|
11
12
|
import { jsPDF } from "jspdf";
|
|
12
13
|
import ELK from "elkjs/lib/elk.bundled.js";
|
|
13
|
-
import dynamic from "next/dynamic.js";
|
|
14
14
|
import { DataTable } from "mantine-datatable";
|
|
15
15
|
import dayjs from "dayjs";
|
|
16
16
|
import isBetween from "dayjs/plugin/isBetween.js";
|
|
17
|
+
//#region src/components/ResourceView/Viewers/R4pm.tsx
|
|
18
|
+
const r4pmViewer = (pick) => dynamic(async () => {
|
|
19
|
+
const [components, { wasmLayout }] = await Promise.all([import("@r4pm/components"), import("@r4pm/components/rust-layout/wasm")]);
|
|
20
|
+
const { ViewerConfigProvider } = components;
|
|
21
|
+
const Viewer = pick(components);
|
|
22
|
+
const viewerConfig = { layout: wasmLayout };
|
|
23
|
+
return (props) => /* @__PURE__ */ jsx(ViewerConfigProvider, {
|
|
24
|
+
value: viewerConfig,
|
|
25
|
+
children: /* @__PURE__ */ jsx(Viewer, { ...props })
|
|
26
|
+
});
|
|
27
|
+
}, { ssr: false });
|
|
28
|
+
const ExportFrame = dynamic(() => import("@r4pm/components").then((c) => c.ViewerExportFrame), { ssr: false });
|
|
29
|
+
const R4pmViewerContainer = ({ filename, children }) => /* @__PURE__ */ jsx(Box, {
|
|
30
|
+
h: "100%",
|
|
31
|
+
w: "100%",
|
|
32
|
+
pos: "relative",
|
|
33
|
+
style: { overflow: "hidden" },
|
|
34
|
+
children: /* @__PURE__ */ jsx(ExportFrame, {
|
|
35
|
+
filename,
|
|
36
|
+
style: { height: "100%" },
|
|
37
|
+
children
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/components/ResourceView/Viewers/DFG.tsx
|
|
42
|
+
const R4pmDfg = r4pmViewer((c) => c.DFGViewer);
|
|
43
|
+
const R4pmOcdfg = r4pmViewer((c) => c.OCDFGViewer);
|
|
44
|
+
const toR4pmDfg = ({ activities, directly_follows_relations, start_activities, end_activities }) => ({
|
|
45
|
+
activities: activities ?? {},
|
|
46
|
+
directly_follows_relations: directly_follows_relations ?? [],
|
|
47
|
+
start_activities: start_activities ?? {},
|
|
48
|
+
end_activities: end_activities ?? {}
|
|
49
|
+
});
|
|
50
|
+
const DFGViewer = ({ visualization }) => {
|
|
51
|
+
const dfg = useMemo(() => toR4pmDfg(visualization), [visualization]);
|
|
52
|
+
return /* @__PURE__ */ jsx(R4pmViewerContainer, {
|
|
53
|
+
filename: "dfg",
|
|
54
|
+
children: /* @__PURE__ */ jsx(R4pmDfg, {
|
|
55
|
+
actions: [],
|
|
56
|
+
data: dfg
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
const OCDFGViewer = ({ visualization }) => {
|
|
61
|
+
const ocdfg = useMemo(() => ({
|
|
62
|
+
object_type_to_dfg: Object.fromEntries(Object.entries(visualization.object_type_to_dfg ?? {}).map(([objectType, dfg]) => [objectType, toR4pmDfg(dfg)])),
|
|
63
|
+
object_counts: visualization.object_counts ?? {}
|
|
64
|
+
}), [visualization]);
|
|
65
|
+
return /* @__PURE__ */ jsx(R4pmViewerContainer, {
|
|
66
|
+
filename: "oc-dfg",
|
|
67
|
+
children: /* @__PURE__ */ jsx(R4pmOcdfg, {
|
|
68
|
+
actions: [],
|
|
69
|
+
data: ocdfg
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
//#endregion
|
|
17
74
|
//#region src/components/ResourceView/Viewers/SVG.tsx
|
|
18
75
|
const { saveAs: saveAs$2 } = FileSaver;
|
|
19
76
|
const SvgPanWrapper = ({ children, onDownload }) => {
|
|
@@ -1539,7 +1596,7 @@ const GraphFlowNode = memo(({ data }) => {
|
|
|
1539
1596
|
const initialTokens = style?.initial_tokens ?? null;
|
|
1540
1597
|
const finalTokens = style?.final_tokens ?? null;
|
|
1541
1598
|
const isExternalLabel = Boolean(label && label_pos !== "center" && label_pos != null);
|
|
1542
|
-
const maxLabelLines = height != null ? Math.max(1, Math.floor((height - 4) /
|
|
1599
|
+
const maxLabelLines = height != null ? Math.max(1, Math.floor((height - 4) / 16.8)) : void 0;
|
|
1543
1600
|
return /* @__PURE__ */ jsxs("div", {
|
|
1544
1601
|
style: {
|
|
1545
1602
|
position: "relative",
|
|
@@ -1688,13 +1745,61 @@ const GraphViewer = (props) => /* @__PURE__ */ jsx(Box, {
|
|
|
1688
1745
|
children: /* @__PURE__ */ jsx(GraphFlow, { ...props })
|
|
1689
1746
|
});
|
|
1690
1747
|
//#endregion
|
|
1748
|
+
//#region src/components/ResourceView/Viewers/PetriNet.tsx
|
|
1749
|
+
const R4pmOcpn = r4pmViewer((c) => c.ObjectCentricPetriNetViewer);
|
|
1750
|
+
const R4pmPetriNet = r4pmViewer((c) => c.PetriNetViewer);
|
|
1751
|
+
const toR4pmPetriNet = (visualization) => ({
|
|
1752
|
+
places: (visualization.places ?? []).map(({ id }) => ({ id })),
|
|
1753
|
+
transitions: visualization.transitions ?? [],
|
|
1754
|
+
arcs: visualization.arcs.map(({ source, target, weight }) => ({
|
|
1755
|
+
nodes: [source, target],
|
|
1756
|
+
...weight != null && { weight }
|
|
1757
|
+
})),
|
|
1758
|
+
initial_marking: visualization.initial_marking ?? null,
|
|
1759
|
+
final_marking: visualization.final_marking ?? null
|
|
1760
|
+
});
|
|
1761
|
+
const OCPetriNetViewer = ({ visualization }) => {
|
|
1762
|
+
const ocpnData = useMemo(() => {
|
|
1763
|
+
const places = visualization.places ?? [];
|
|
1764
|
+
const placeInOutMult = Object.fromEntries(places.map(({ id }) => [id, [{}, {}]]));
|
|
1765
|
+
for (const { source, target, variable } of visualization.arcs) {
|
|
1766
|
+
if (!variable) continue;
|
|
1767
|
+
const incoming = placeInOutMult[target];
|
|
1768
|
+
if (incoming) incoming[0][source] = true;
|
|
1769
|
+
const outgoing = placeInOutMult[source];
|
|
1770
|
+
if (outgoing) outgoing[1][target] = true;
|
|
1771
|
+
}
|
|
1772
|
+
return {
|
|
1773
|
+
petri_net: toR4pmPetriNet(visualization),
|
|
1774
|
+
place_object_type: Object.fromEntries(places.map(({ id, object_type }) => [id, object_type])),
|
|
1775
|
+
place_in_out_mult: placeInOutMult
|
|
1776
|
+
};
|
|
1777
|
+
}, [visualization]);
|
|
1778
|
+
return /* @__PURE__ */ jsx(R4pmViewerContainer, {
|
|
1779
|
+
filename: "oc-petri-net",
|
|
1780
|
+
children: /* @__PURE__ */ jsx(R4pmOcpn, { data: ocpnData })
|
|
1781
|
+
});
|
|
1782
|
+
};
|
|
1783
|
+
const PetriNetViewer = ({ visualization }) => {
|
|
1784
|
+
const petriNet = useMemo(() => toR4pmPetriNet(visualization), [visualization]);
|
|
1785
|
+
return /* @__PURE__ */ jsx(R4pmViewerContainer, {
|
|
1786
|
+
filename: "petri-net",
|
|
1787
|
+
children: /* @__PURE__ */ jsx(R4pmPetriNet, { data: petriNet })
|
|
1788
|
+
});
|
|
1789
|
+
};
|
|
1790
|
+
//#endregion
|
|
1691
1791
|
//#region src/components/ResourceView/Viewers/Plotly.tsx
|
|
1692
1792
|
const Plot = dynamic(() => import("react-plotly.js"), { ssr: false });
|
|
1693
1793
|
const PlotlyViewer = ({ visualization, isPreview }) => {
|
|
1694
1794
|
const { data, layout } = visualization.data;
|
|
1695
1795
|
return /* @__PURE__ */ jsx(Plot, {
|
|
1696
1796
|
data,
|
|
1697
|
-
layout: {
|
|
1797
|
+
layout: {
|
|
1798
|
+
...layout,
|
|
1799
|
+
autosize: true,
|
|
1800
|
+
width: void 0,
|
|
1801
|
+
height: void 0
|
|
1802
|
+
},
|
|
1698
1803
|
config: {
|
|
1699
1804
|
responsive: true,
|
|
1700
1805
|
displaylogo: false,
|
|
@@ -1748,23 +1853,24 @@ const TableView = ({ visualization }) => {
|
|
|
1748
1853
|
pageSize,
|
|
1749
1854
|
visualization
|
|
1750
1855
|
]);
|
|
1856
|
+
const paginationProps = visualization.rows.length > PAGE_SIZES[0] ? {
|
|
1857
|
+
totalRecords: visualization.rows.length,
|
|
1858
|
+
recordsPerPage: pageSize,
|
|
1859
|
+
onPageChange: (p) => setPage(p),
|
|
1860
|
+
page,
|
|
1861
|
+
recordsPerPageOptions: [...PAGE_SIZES],
|
|
1862
|
+
onRecordsPerPageChange: (newPageSize) => {
|
|
1863
|
+
setPageSize(newPageSize);
|
|
1864
|
+
setPage(1);
|
|
1865
|
+
}
|
|
1866
|
+
} : {};
|
|
1751
1867
|
return /* @__PURE__ */ jsx(DataTable, {
|
|
1752
1868
|
records,
|
|
1753
1869
|
columns,
|
|
1754
1870
|
withTableBorder: true,
|
|
1755
1871
|
withColumnBorders: true,
|
|
1756
1872
|
withRowBorders: true,
|
|
1757
|
-
...
|
|
1758
|
-
totalRecords: visualization.rows.length,
|
|
1759
|
-
recordsPerPage: pageSize,
|
|
1760
|
-
onPageChange: (p) => setPage(p),
|
|
1761
|
-
page,
|
|
1762
|
-
recordsPerPageOptions: [...PAGE_SIZES],
|
|
1763
|
-
onRecordsPerPageChange: (newPageSize) => {
|
|
1764
|
-
setPageSize(newPageSize);
|
|
1765
|
-
setPage(1);
|
|
1766
|
-
}
|
|
1767
|
-
} : {}
|
|
1873
|
+
...paginationProps
|
|
1768
1874
|
});
|
|
1769
1875
|
};
|
|
1770
1876
|
//#endregion
|
|
@@ -1774,7 +1880,11 @@ const visualizationMap = {
|
|
|
1774
1880
|
svg: SvgViewer,
|
|
1775
1881
|
graph: GraphViewer,
|
|
1776
1882
|
dot: DotToSvgViewer,
|
|
1777
|
-
plotly: PlotlyViewer
|
|
1883
|
+
plotly: PlotlyViewer,
|
|
1884
|
+
r4pm_oc_petri_net: OCPetriNetViewer,
|
|
1885
|
+
r4pm_petri_net: PetriNetViewer,
|
|
1886
|
+
r4pm_dfg: DFGViewer,
|
|
1887
|
+
r4pm_ocdfg: OCDFGViewer
|
|
1778
1888
|
};
|
|
1779
1889
|
const Visualization = ({ visualization, isPreview = false, menuItems }) => {
|
|
1780
1890
|
const Component = visualizationMap[visualization.type];
|
|
@@ -1852,10 +1962,9 @@ const ResourceModal = ({ id, onClose }) => {
|
|
|
1852
1962
|
//#endregion
|
|
1853
1963
|
//#region src/components/ResourceSelect/ResourceSelect.tsx
|
|
1854
1964
|
const ResourceSelect = ({ type, value, ...props }) => {
|
|
1855
|
-
const { data: resources = [] } = useResources({
|
|
1965
|
+
const { data: resources = [] } = useResources({ schema_hash: type ?? null });
|
|
1856
1966
|
return /* @__PURE__ */ jsx(Select, {
|
|
1857
1967
|
...props,
|
|
1858
|
-
value: value ?? null,
|
|
1859
1968
|
data: resources.map(({ name, id }) => ({
|
|
1860
1969
|
value: id,
|
|
1861
1970
|
label: name
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocelescope/resources",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.0",
|
|
5
5
|
"description": "Ocelescope resources: helpers and UI components for rendering and exporting data.",
|
|
6
6
|
"author": "Görkem-Emre Öztürk <goerkem.oeztuerk@rwth-aachen.de>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,26 +30,27 @@
|
|
|
30
30
|
"@floating-ui/react": "^0.27.18",
|
|
31
31
|
"@hpcc-js/wasm-graphviz": "^1.21.0",
|
|
32
32
|
"@mantine/core": "^9.5.1",
|
|
33
|
+
"@ocelescope/api-base": "^0.9.0",
|
|
34
|
+
"@r4pm/components": "^0.3.2",
|
|
33
35
|
"@xyflow/react": "^12.11.3",
|
|
34
|
-
"dayjs": "^1.11.
|
|
36
|
+
"dayjs": "^1.11.23",
|
|
35
37
|
"elkjs": "^0.12.0",
|
|
36
38
|
"file-saver": "^2.0.5",
|
|
37
39
|
"lucide-react": "^1.0.0",
|
|
38
40
|
"mantine-datatable": "^9.4.0",
|
|
39
|
-
"next": "16.3.
|
|
40
|
-
"react": "^19.
|
|
41
|
-
"react-dom": "^19.
|
|
41
|
+
"next": "16.3.6",
|
|
42
|
+
"react": "^19.3.0",
|
|
43
|
+
"react-dom": "^19.3.0",
|
|
42
44
|
"react-plotly.js": "^4.0.0",
|
|
43
|
-
"react-zoom-pan-pinch": "^4.0.0"
|
|
44
|
-
"@ocelescope/api-base": "^0.7.0"
|
|
45
|
+
"react-zoom-pan-pinch": "^4.0.0"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@tsdown/css": "^0.
|
|
48
|
+
"@tsdown/css": "^0.23.0",
|
|
48
49
|
"@types/file-saver": "^2.0.7",
|
|
49
|
-
"@types/node": "^26.
|
|
50
|
-
"@types/react": "^19.
|
|
51
|
-
"@types/react-dom": "^19.
|
|
52
|
-
"tsdown": "^0.
|
|
50
|
+
"@types/node": "^26.6.1",
|
|
51
|
+
"@types/react": "^19.3.0",
|
|
52
|
+
"@types/react-dom": "^19.3.0",
|
|
53
|
+
"tsdown": "^0.23.0",
|
|
53
54
|
"typescript": "^6.0.3"
|
|
54
55
|
},
|
|
55
56
|
"dependencies": {
|