@neo4j-ndl/react-graph 0.0.2
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/LICENSE +674 -0
- package/lib/LICENSES.txt +229 -0
- package/lib/NOTICE.txt +26 -0
- package/lib/cjs/graph-visualization-buttons.js +175 -0
- package/lib/cjs/graph-visualization-buttons.js.map +1 -0
- package/lib/cjs/graph-visualization-context.js +62 -0
- package/lib/cjs/graph-visualization-context.js.map +1 -0
- package/lib/cjs/graph-visualization-sidepanel.js +56 -0
- package/lib/cjs/graph-visualization-sidepanel.js.map +1 -0
- package/lib/cjs/graph-visualization.js +328 -0
- package/lib/cjs/graph-visualization.js.map +1 -0
- package/lib/cjs/index.js +28 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/map-to-nvl-graph.js +167 -0
- package/lib/cjs/map-to-nvl-graph.js.map +1 -0
- package/lib/cjs/sidepanel-components/button-group.js +96 -0
- package/lib/cjs/sidepanel-components/button-group.js.map +1 -0
- package/lib/cjs/sidepanel-components/clickable-urls.js +46 -0
- package/lib/cjs/sidepanel-components/clickable-urls.js.map +1 -0
- package/lib/cjs/sidepanel-components/details-panel.js +86 -0
- package/lib/cjs/sidepanel-components/details-panel.js.map +1 -0
- package/lib/cjs/sidepanel-components/overview-panel.js +45 -0
- package/lib/cjs/sidepanel-components/overview-panel.js.map +1 -0
- package/lib/cjs/sidepanel-components/properties-table.js +49 -0
- package/lib/cjs/sidepanel-components/properties-table.js.map +1 -0
- package/lib/cjs/sidepanel-components/show-all.js +44 -0
- package/lib/cjs/sidepanel-components/show-all.js.map +1 -0
- package/lib/cjs/sidepanel-components/single-selection-sidepanel-contents.js +35 -0
- package/lib/cjs/sidepanel-components/single-selection-sidepanel-contents.js.map +1 -0
- package/lib/cjs/stories/graph-visualization-barebones.story.js +93 -0
- package/lib/cjs/stories/graph-visualization-barebones.story.js.map +1 -0
- package/lib/cjs/stories/graph-visualization-custom.story.js +74 -0
- package/lib/cjs/stories/graph-visualization-custom.story.js.map +1 -0
- package/lib/cjs/stories/graph-visualization-default.story.js +93 -0
- package/lib/cjs/stories/graph-visualization-default.story.js.map +1 -0
- package/lib/cjs/stories/graph-visualization-highlighting.story.js +30 -0
- package/lib/cjs/stories/graph-visualization-highlighting.story.js.map +1 -0
- package/lib/cjs/stories/graph-visualization-maximalist.story.js +105 -0
- package/lib/cjs/stories/graph-visualization-maximalist.story.js.map +1 -0
- package/lib/cjs/stories/graph-visualization-search.story.js +36 -0
- package/lib/cjs/stories/graph-visualization-search.story.js.map +1 -0
- package/lib/cjs/stories/graph-visualization.stories.js +112 -0
- package/lib/cjs/stories/graph-visualization.stories.js.map +1 -0
- package/lib/cjs/stories/index.js +51 -0
- package/lib/cjs/stories/index.js.map +1 -0
- package/lib/cjs/stories/story-data.js +89 -0
- package/lib/cjs/stories/story-data.js.map +1 -0
- package/lib/cjs/use-managed-node-state.js +262 -0
- package/lib/cjs/use-managed-node-state.js.map +1 -0
- package/lib/cjs/use-semi-controlled-state.js +43 -0
- package/lib/cjs/use-semi-controlled-state.js.map +1 -0
- package/lib/cjs/utils.js +68 -0
- package/lib/cjs/utils.js.map +1 -0
- package/lib/esm/graph-visualization-buttons.js +159 -0
- package/lib/esm/graph-visualization-buttons.js.map +1 -0
- package/lib/esm/graph-visualization-context.js +58 -0
- package/lib/esm/graph-visualization-context.js.map +1 -0
- package/lib/esm/graph-visualization-sidepanel.js +52 -0
- package/lib/esm/graph-visualization-sidepanel.js.map +1 -0
- package/lib/esm/graph-visualization.js +298 -0
- package/lib/esm/graph-visualization.js.map +1 -0
- package/lib/esm/index.js +23 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/map-to-nvl-graph.js +162 -0
- package/lib/esm/map-to-nvl-graph.js.map +1 -0
- package/lib/esm/sidepanel-components/button-group.js +69 -0
- package/lib/esm/sidepanel-components/button-group.js.map +1 -0
- package/lib/esm/sidepanel-components/clickable-urls.js +40 -0
- package/lib/esm/sidepanel-components/clickable-urls.js.map +1 -0
- package/lib/esm/sidepanel-components/details-panel.js +82 -0
- package/lib/esm/sidepanel-components/details-panel.js.map +1 -0
- package/lib/esm/sidepanel-components/overview-panel.js +41 -0
- package/lib/esm/sidepanel-components/overview-panel.js.map +1 -0
- package/lib/esm/sidepanel-components/properties-table.js +45 -0
- package/lib/esm/sidepanel-components/properties-table.js.map +1 -0
- package/lib/esm/sidepanel-components/show-all.js +41 -0
- package/lib/esm/sidepanel-components/show-all.js.map +1 -0
- package/lib/esm/sidepanel-components/single-selection-sidepanel-contents.js +31 -0
- package/lib/esm/sidepanel-components/single-selection-sidepanel-contents.js.map +1 -0
- package/lib/esm/stories/graph-visualization-barebones.story.js +90 -0
- package/lib/esm/stories/graph-visualization-barebones.story.js.map +1 -0
- package/lib/esm/stories/graph-visualization-custom.story.js +71 -0
- package/lib/esm/stories/graph-visualization-custom.story.js.map +1 -0
- package/lib/esm/stories/graph-visualization-default.story.js +90 -0
- package/lib/esm/stories/graph-visualization-default.story.js.map +1 -0
- package/lib/esm/stories/graph-visualization-highlighting.story.js +28 -0
- package/lib/esm/stories/graph-visualization-highlighting.story.js.map +1 -0
- package/lib/esm/stories/graph-visualization-maximalist.story.js +102 -0
- package/lib/esm/stories/graph-visualization-maximalist.story.js.map +1 -0
- package/lib/esm/stories/graph-visualization-search.story.js +34 -0
- package/lib/esm/stories/graph-visualization-search.story.js.map +1 -0
- package/lib/esm/stories/graph-visualization.stories.js +109 -0
- package/lib/esm/stories/graph-visualization.stories.js.map +1 -0
- package/lib/esm/stories/index.js +39 -0
- package/lib/esm/stories/index.js.map +1 -0
- package/lib/esm/stories/story-data.js +86 -0
- package/lib/esm/stories/story-data.js.map +1 -0
- package/lib/esm/use-managed-node-state.js +259 -0
- package/lib/esm/use-managed-node-state.js.map +1 -0
- package/lib/esm/use-semi-controlled-state.js +40 -0
- package/lib/esm/use-semi-controlled-state.js.map +1 -0
- package/lib/esm/utils.js +60 -0
- package/lib/esm/utils.js.map +1 -0
- package/lib/types/graph-visualization-buttons.d.ts +56 -0
- package/lib/types/graph-visualization-context.d.ts +122 -0
- package/lib/types/graph-visualization-sidepanel.d.ts +32 -0
- package/lib/types/graph-visualization.d.ts +178 -0
- package/lib/types/index.d.ts +22 -0
- package/lib/types/map-to-nvl-graph.d.ts +37 -0
- package/lib/types/sidepanel-components/button-group.d.ts +24 -0
- package/lib/types/sidepanel-components/clickable-urls.d.ts +26 -0
- package/lib/types/sidepanel-components/details-panel.d.ts +25 -0
- package/lib/types/sidepanel-components/overview-panel.d.ts +21 -0
- package/lib/types/sidepanel-components/properties-table.d.ts +31 -0
- package/lib/types/sidepanel-components/show-all.d.ts +29 -0
- package/lib/types/sidepanel-components/single-selection-sidepanel-contents.d.ts +21 -0
- package/lib/types/stories/graph-visualization-barebones.story.d.ts +23 -0
- package/lib/types/stories/graph-visualization-custom.story.d.ts +23 -0
- package/lib/types/stories/graph-visualization-default.story.d.ts +23 -0
- package/lib/types/stories/graph-visualization-highlighting.story.d.ts +22 -0
- package/lib/types/stories/graph-visualization-maximalist.story.d.ts +23 -0
- package/lib/types/stories/graph-visualization-search.story.d.ts +22 -0
- package/lib/types/stories/graph-visualization.stories.d.ts +39 -0
- package/lib/types/stories/index.d.ts +32 -0
- package/lib/types/stories/story-data.d.ts +26 -0
- package/lib/types/use-managed-node-state.d.ts +116 -0
- package/lib/types/use-semi-controlled-state.d.ts +23 -0
- package/lib/types/utils.d.ts +29 -0
- package/package.json +79 -0
|
@@ -0,0 +1,328 @@
|
|
|
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 __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.DEFAULT_NVL_OPTIONS = void 0;
|
|
41
|
+
exports.GraphVisualization = GraphVisualization;
|
|
42
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* Copyright (c) "Neo4j"
|
|
46
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
47
|
+
*
|
|
48
|
+
* This file is part of Neo4j.
|
|
49
|
+
*
|
|
50
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
51
|
+
* it under the terms of the GNU General Public License as published by
|
|
52
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
53
|
+
* (at your option) any later version.
|
|
54
|
+
*
|
|
55
|
+
* This program is distributed in the hope that it will be useful,
|
|
56
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
57
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
58
|
+
* GNU General Public License for more details.
|
|
59
|
+
*
|
|
60
|
+
* You should have received a copy of the GNU General Public License
|
|
61
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
62
|
+
*/
|
|
63
|
+
const base_1 = require("@neo4j-ndl/base");
|
|
64
|
+
const react_1 = require("@neo4j-ndl/react");
|
|
65
|
+
const react_2 = require("@neo4j-nvl/react");
|
|
66
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
67
|
+
const react_3 = __importStar(require("react"));
|
|
68
|
+
const graph_visualization_buttons_1 = require("./graph-visualization-buttons");
|
|
69
|
+
const graph_visualization_context_1 = require("./graph-visualization-context");
|
|
70
|
+
const graph_visualization_sidepanel_1 = require("./graph-visualization-sidepanel");
|
|
71
|
+
const map_to_nvl_graph_1 = require("./map-to-nvl-graph");
|
|
72
|
+
const single_selection_sidepanel_contents_1 = require("./sidepanel-components/single-selection-sidepanel-contents");
|
|
73
|
+
const use_managed_node_state_1 = require("./use-managed-node-state");
|
|
74
|
+
const use_semi_controlled_state_1 = require("./use-semi-controlled-state");
|
|
75
|
+
const PLACEMENTS = {
|
|
76
|
+
'bottom-left': 'ndl-graph-visualization-interaction-island ndl-bottom-left',
|
|
77
|
+
'bottom-right': 'ndl-graph-visualization-interaction-island ndl-bottom-right',
|
|
78
|
+
'top-left': 'ndl-graph-visualization-interaction-island ndl-top-left',
|
|
79
|
+
'top-right': 'ndl-graph-visualization-interaction-island ndl-top-right',
|
|
80
|
+
};
|
|
81
|
+
const InteractionIsland = ({ children, className, placement, }) => {
|
|
82
|
+
return (0, jsx_runtime_1.jsx)("div", { className: (0, classnames_1.default)(PLACEMENTS[placement], className), children: children });
|
|
83
|
+
};
|
|
84
|
+
exports.DEFAULT_NVL_OPTIONS = {
|
|
85
|
+
disableTelemetry: true,
|
|
86
|
+
disableWebGL: true,
|
|
87
|
+
maxZoom: 3,
|
|
88
|
+
minZoom: 0.05,
|
|
89
|
+
relationshipThreshold: 0.55,
|
|
90
|
+
useWebGL: false,
|
|
91
|
+
};
|
|
92
|
+
const DEFAULT_COMPONENTS = {
|
|
93
|
+
bottomLeftIsland: null,
|
|
94
|
+
bottomRightIsland: ((0, jsx_runtime_1.jsxs)(react_1.IconButtonArray, { orientation: "vertical", isFloating: true, children: [(0, jsx_runtime_1.jsx)(graph_visualization_buttons_1.ZoomInButton, {}), " ", (0, jsx_runtime_1.jsx)(graph_visualization_buttons_1.ZoomOutButton, {}), " ", (0, jsx_runtime_1.jsx)(graph_visualization_buttons_1.ZoomToFitButton, {})] })),
|
|
95
|
+
topLeftIsland: null,
|
|
96
|
+
topRightIsland: ((0, jsx_runtime_1.jsxs)("div", { className: "ndl-graph-visualization-default-download-group", children: [(0, jsx_runtime_1.jsx)(graph_visualization_buttons_1.DownloadButton, {}), " ", (0, jsx_runtime_1.jsx)(graph_visualization_buttons_1.ToggleSidePanelButton, {})] })),
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* A comprehensive graph visualization component for rendering Neo4j-style graphs with interactive features.
|
|
100
|
+
*
|
|
101
|
+
* @remarks
|
|
102
|
+
* This component provides a complete graph visualization solution with built-in interaction modes,
|
|
103
|
+
* selection handling, zoom controls, and an optional sidepanel. It wraps the NVL (Neo4j Visualization Library)
|
|
104
|
+
* with additional UI controls and state management.
|
|
105
|
+
*
|
|
106
|
+
* The component supports various interaction modes including single selection, box selection, and lasso selection.
|
|
107
|
+
* It also provides customizable UI islands for placing controls at different corners of the visualization.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* Basic usage:
|
|
111
|
+
* ```tsx
|
|
112
|
+
* <GraphVisualization
|
|
113
|
+
* nodes={nodes}
|
|
114
|
+
* rels={relationships}
|
|
115
|
+
* selected={selection}
|
|
116
|
+
* setSelected={setSelection}
|
|
117
|
+
* />
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* With custom controls:
|
|
122
|
+
* ```tsx
|
|
123
|
+
* <GraphVisualization
|
|
124
|
+
* nodes={nodes}
|
|
125
|
+
* rels={relationships}
|
|
126
|
+
* topRightIsland={<CustomControls />}
|
|
127
|
+
* sidepanel={{
|
|
128
|
+
* contents: <CustomSidepanel />,
|
|
129
|
+
* isSidePanelOpen: true,
|
|
130
|
+
* setIsSidePanelOpen: setSidepanelOpen
|
|
131
|
+
* sidePanelWidth: 400,
|
|
132
|
+
* onSidePanelResize: setSidepanelWidth,
|
|
133
|
+
* }}
|
|
134
|
+
* />
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* With highlighting:
|
|
139
|
+
* ```tsx
|
|
140
|
+
* <GraphVisualization
|
|
141
|
+
* nodes={nodes}
|
|
142
|
+
* rels={relationships}
|
|
143
|
+
* // undefined = no highlighting (default behavior)
|
|
144
|
+
* // empty array = no search matches (dims all nodes)
|
|
145
|
+
* // array with IDs = highlight only those items
|
|
146
|
+
* highlightedNodeIds={searchResults.nodeIds}
|
|
147
|
+
* highlightedRelationshipIds={searchResults.relationshipIds}
|
|
148
|
+
* />
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* @param props - {@link GraphVisualizationProps}
|
|
152
|
+
* @returns A React component that renders an interactive graph visualization
|
|
153
|
+
*
|
|
154
|
+
* @alpha
|
|
155
|
+
*/
|
|
156
|
+
function GraphVisualization(_a) {
|
|
157
|
+
var _b, _c;
|
|
158
|
+
var { nvlRef: rawNvlRef, nvlCallbacks, nvlOptions, sidepanel: rawSidepanel, nodes: rawNodes, rels: rawRels, highlightedNodeIds, highlightedRelationshipIds, topLeftIsland = DEFAULT_COMPONENTS.topLeftIsland, topRightIsland = DEFAULT_COMPONENTS.topRightIsland, bottomLeftIsland = DEFAULT_COMPONENTS.bottomLeftIsland, bottomRightIsland = DEFAULT_COMPONENTS.bottomRightIsland, gesture = 'single', setGesture, selected: rawSelected, setSelected: rawSetSelected, interactionMode: rawInteractionMode, setInteractionMode: rawSetInteractionMode, mouseEventCallbacks = {}, className, style, htmlAttributes, ref, as } = _a, restProps = __rest(_a, ["nvlRef", "nvlCallbacks", "nvlOptions", "sidepanel", "nodes", "rels", "highlightedNodeIds", "highlightedRelationshipIds", "topLeftIsland", "topRightIsland", "bottomLeftIsland", "bottomRightIsland", "gesture", "setGesture", "selected", "setSelected", "interactionMode", "setInteractionMode", "mouseEventCallbacks", "className", "style", "htmlAttributes", "ref", "as"]);
|
|
159
|
+
const nvlRef = (0, react_3.useMemo)(() => rawNvlRef !== null && rawNvlRef !== void 0 ? rawNvlRef : react_3.default.createRef(), [rawNvlRef]);
|
|
160
|
+
const instanceId = (0, react_3.useId)();
|
|
161
|
+
// Respect NDL theme changes
|
|
162
|
+
const { theme } = (0, react_1.useNeedleTheme)();
|
|
163
|
+
const { bg, border, text } = base_1.tokens.theme[theme].palette.neutral;
|
|
164
|
+
// key required for nvl react responsiveness
|
|
165
|
+
const [key, setKey] = (0, react_3.useState)(0);
|
|
166
|
+
(0, react_3.useEffect)(() => {
|
|
167
|
+
setKey((prevKey) => prevKey + 1);
|
|
168
|
+
}, [theme]);
|
|
169
|
+
// Semi-control interaction mode and selection state
|
|
170
|
+
const [interactionMode, setInteractionMode] = (0, use_semi_controlled_state_1.useSemicontrolledState)(rawInteractionMode !== null && rawInteractionMode !== void 0 ? rawInteractionMode : 'select', rawSetInteractionMode);
|
|
171
|
+
const [selected, setSelected] = (0, use_semi_controlled_state_1.useSemicontrolledState)(rawSelected !== null && rawSelected !== void 0 ? rawSelected : { nodeIds: [], relationshipIds: [] }, rawSetSelected);
|
|
172
|
+
const nvlGraph = (0, react_3.useMemo)(() => (0, map_to_nvl_graph_1.mapToNvlGraph)(rawNodes, rawRels), [rawNodes, rawRels]);
|
|
173
|
+
const { nodesWithState, relsWithState, wrappedMouseEventCallbacks } = (0, use_managed_node_state_1.useManagedNodeState)({
|
|
174
|
+
gesture,
|
|
175
|
+
highlightedNodeIds,
|
|
176
|
+
highlightedRelationshipIds,
|
|
177
|
+
interactionMode,
|
|
178
|
+
mouseEventCallbacks,
|
|
179
|
+
nvlGraph,
|
|
180
|
+
selected,
|
|
181
|
+
setInteractionMode,
|
|
182
|
+
setSelected,
|
|
183
|
+
});
|
|
184
|
+
const [isSidePanelOpen, setIsSidePanelOpen] = (0, use_semi_controlled_state_1.useSemicontrolledState)((_b = rawSidepanel === null || rawSidepanel === void 0 ? void 0 : rawSidepanel.isSidePanelOpen) !== null && _b !== void 0 ? _b : true, rawSidepanel === null || rawSidepanel === void 0 ? void 0 : rawSidepanel.setIsSidePanelOpen);
|
|
185
|
+
const [sidePanelWidth, setSidePanelWidth] = (0, use_semi_controlled_state_1.useSemicontrolledState)((_c = rawSidepanel === null || rawSidepanel === void 0 ? void 0 : rawSidepanel.sidePanelWidth) !== null && _c !== void 0 ? _c : 400, rawSidepanel === null || rawSidepanel === void 0 ? void 0 : rawSidepanel.onSidePanelResize);
|
|
186
|
+
const sidepanel = (0, react_3.useMemo)(() => {
|
|
187
|
+
if (rawSidepanel === undefined) {
|
|
188
|
+
return {
|
|
189
|
+
children: (0, jsx_runtime_1.jsx)(GraphVisualization.SingleSelectionSidePanelContents, {}),
|
|
190
|
+
isSidePanelOpen,
|
|
191
|
+
onSidePanelResize: setSidePanelWidth,
|
|
192
|
+
setIsSidePanelOpen,
|
|
193
|
+
sidePanelWidth,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
return rawSidepanel;
|
|
197
|
+
}, [
|
|
198
|
+
rawSidepanel,
|
|
199
|
+
isSidePanelOpen,
|
|
200
|
+
setIsSidePanelOpen,
|
|
201
|
+
sidePanelWidth,
|
|
202
|
+
setSidePanelWidth,
|
|
203
|
+
]);
|
|
204
|
+
const Component = as !== null && as !== void 0 ? as : 'div';
|
|
205
|
+
return ((0, jsx_runtime_1.jsx)(Component, Object.assign({ ref: ref, className: (0, classnames_1.default)('ndl-graph-visualization-container', className), style: style }, htmlAttributes, { children: (0, jsx_runtime_1.jsxs)(graph_visualization_context_1.GraphVisualizationContext.Provider, { value: {
|
|
206
|
+
gesture,
|
|
207
|
+
interactionMode,
|
|
208
|
+
nvlGraph,
|
|
209
|
+
nvlInstance: nvlRef,
|
|
210
|
+
selected,
|
|
211
|
+
setGesture,
|
|
212
|
+
sidepanel,
|
|
213
|
+
}, children: [(0, jsx_runtime_1.jsxs)("div", { className: "ndl-graph-visualization", children: [(0, jsx_runtime_1.jsx)(react_2.InteractiveNvlWrapper, Object.assign({ layout: "d3Force", nodes: nodesWithState, rels: relsWithState, nvlOptions: Object.assign(Object.assign(Object.assign({}, exports.DEFAULT_NVL_OPTIONS), { instanceId, styling: {
|
|
214
|
+
defaultRelationshipColor: border.strongest,
|
|
215
|
+
disabledItemColor: bg.strong,
|
|
216
|
+
disabledItemFontColor: text.weakest,
|
|
217
|
+
dropShadowColor: border.weak,
|
|
218
|
+
selectedInnerBorderColor: bg.default,
|
|
219
|
+
} }), nvlOptions), nvlCallbacks: Object.assign({ onLayoutComputing(isComputing) {
|
|
220
|
+
var _a;
|
|
221
|
+
if (!isComputing) {
|
|
222
|
+
(_a = nvlRef.current) === null || _a === void 0 ? void 0 : _a.fit(nvlRef.current.getNodes().map((neighbors) => neighbors.id), { noPan: true });
|
|
223
|
+
}
|
|
224
|
+
} }, nvlCallbacks), mouseEventCallbacks: wrappedMouseEventCallbacks, ref: nvlRef }, restProps), key), topLeftIsland !== null && ((0, jsx_runtime_1.jsx)(InteractionIsland, { placement: "top-left", children: topLeftIsland })), topRightIsland !== null && ((0, jsx_runtime_1.jsx)(InteractionIsland, { placement: "top-right", children: topRightIsland })), bottomLeftIsland !== null && ((0, jsx_runtime_1.jsx)(InteractionIsland, { placement: "bottom-left", children: bottomLeftIsland })), bottomRightIsland !== null && ((0, jsx_runtime_1.jsx)(InteractionIsland, { placement: "bottom-right", children: bottomRightIsland }))] }), sidepanel && (0, jsx_runtime_1.jsx)(graph_visualization_sidepanel_1.GraphVisualizationSidepanel, { sidepanel: sidepanel })] }) })));
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Zoom in button for use within a GraphVisualization component.
|
|
228
|
+
*
|
|
229
|
+
* @remarks
|
|
230
|
+
* Increases zoom level by 1.3x
|
|
231
|
+
*
|
|
232
|
+
* @alpha
|
|
233
|
+
*/
|
|
234
|
+
GraphVisualization.ZoomInButton = graph_visualization_buttons_1.ZoomInButton;
|
|
235
|
+
/**
|
|
236
|
+
* Zoom out button for use within a GraphVisualization component.
|
|
237
|
+
*
|
|
238
|
+
* @remarks
|
|
239
|
+
* Decreases zoom level by 0.7x
|
|
240
|
+
*
|
|
241
|
+
* @alpha
|
|
242
|
+
*/
|
|
243
|
+
GraphVisualization.ZoomOutButton = graph_visualization_buttons_1.ZoomOutButton;
|
|
244
|
+
/**
|
|
245
|
+
* Zoom to fit button for use within a GraphVisualization component.
|
|
246
|
+
*
|
|
247
|
+
* @remarks
|
|
248
|
+
* Automatically adjusts zoom and pan to show all nodes and relationships
|
|
249
|
+
*
|
|
250
|
+
* @alpha
|
|
251
|
+
*/
|
|
252
|
+
GraphVisualization.ZoomToFitButton = graph_visualization_buttons_1.ZoomToFitButton;
|
|
253
|
+
/**
|
|
254
|
+
* Sidepanel toggle button for use within a GraphVisualization component.
|
|
255
|
+
*
|
|
256
|
+
* @remarks
|
|
257
|
+
* Shows or hides the sidepanel containing node and relationship details.
|
|
258
|
+
* Requires a sidepanel to be configured in the GraphVisualization component.
|
|
259
|
+
*
|
|
260
|
+
* @throws Error when used without a configured sidepanel
|
|
261
|
+
*
|
|
262
|
+
* @alpha
|
|
263
|
+
*/
|
|
264
|
+
GraphVisualization.ToggleSidePanelButton = graph_visualization_buttons_1.ToggleSidePanelButton;
|
|
265
|
+
/**
|
|
266
|
+
* Download button for use within a GraphVisualization component.
|
|
267
|
+
*
|
|
268
|
+
* @remarks
|
|
269
|
+
* Opens a dropdown menu with download options. Currently supports PNG format.
|
|
270
|
+
* Captures the current visualization state including zoom level.
|
|
271
|
+
*
|
|
272
|
+
* @alpha
|
|
273
|
+
*/
|
|
274
|
+
GraphVisualization.DownloadButton = graph_visualization_buttons_1.DownloadButton;
|
|
275
|
+
/**
|
|
276
|
+
* Box selection button for use within a GraphVisualization component.
|
|
277
|
+
*
|
|
278
|
+
* @remarks
|
|
279
|
+
* Enables box selection mode where dragging creates a rectangular selection area.
|
|
280
|
+
* Disabled unless the `setGesture` callback is passed.
|
|
281
|
+
* Shows active state when enabled and supports keyboard shortcut 'B'.
|
|
282
|
+
*
|
|
283
|
+
* @alpha
|
|
284
|
+
*/
|
|
285
|
+
GraphVisualization.BoxSelectButton = graph_visualization_buttons_1.BoxSelectButton;
|
|
286
|
+
/**
|
|
287
|
+
* Lasso selection button for use within a GraphVisualization component.
|
|
288
|
+
*
|
|
289
|
+
* @remarks
|
|
290
|
+
* Enables lasso selection mode where dragging creates a free-form selection area.
|
|
291
|
+
* Disabled unless the `setGesture` callback is passed.
|
|
292
|
+
* Shows active state when enabled and supports keyboard shortcut 'L'.
|
|
293
|
+
*
|
|
294
|
+
* @alpha
|
|
295
|
+
*/
|
|
296
|
+
GraphVisualization.LassoSelectButton = graph_visualization_buttons_1.LassoSelectButton;
|
|
297
|
+
/**
|
|
298
|
+
* Single node selection button for use within a GraphVisualization component.
|
|
299
|
+
*
|
|
300
|
+
* @remarks
|
|
301
|
+
* Enables single selection mode where clicking selects individual nodes or relationships.
|
|
302
|
+
* Shows active state when enabled and supports keyboard shortcut 'S'.
|
|
303
|
+
*
|
|
304
|
+
* @alpha
|
|
305
|
+
*/
|
|
306
|
+
GraphVisualization.SingleSelectButton = graph_visualization_buttons_1.SingleSelectButton;
|
|
307
|
+
/**
|
|
308
|
+
* Search button for use within a GraphVisualization component.
|
|
309
|
+
*
|
|
310
|
+
* @remarks
|
|
311
|
+
* Enables search mode where clicking opens a search input for filtering nodes and relationships.
|
|
312
|
+
*
|
|
313
|
+
* @alpha
|
|
314
|
+
*/
|
|
315
|
+
GraphVisualization.SearchButton = graph_visualization_buttons_1.SearchButton;
|
|
316
|
+
/**
|
|
317
|
+
* Single node selection side panel for use within a GraphVisualization component.
|
|
318
|
+
*
|
|
319
|
+
* @remarks
|
|
320
|
+
* Displays detailed information about the selected node or relationship.
|
|
321
|
+
* Panel is automatically opened when a node or relationship is selected.
|
|
322
|
+
* Also when user click on the show panel button in the top right corner.
|
|
323
|
+
*
|
|
324
|
+
* @alpha
|
|
325
|
+
*/
|
|
326
|
+
GraphVisualization.SingleSelectionSidePanelContents =
|
|
327
|
+
single_selection_sidepanel_contents_1.SingleSelectionSidepanelContents;
|
|
328
|
+
//# sourceMappingURL=graph-visualization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-visualization.js","sourceRoot":"","sources":["../../src/graph-visualization.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiMA,gDAoLC;;AArXD;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,0CAAyC;AACzC,4CAI0B;AAE1B,4CAG0B;AAC1B,4DAA2C;AAC3C,+CAAmE;AAEnE,+EAUuC;AACvC,+EASuC;AACvC,mFAA8E;AAC9E,yDAAmD;AACnD,oHAA8G;AAC9G,qEAA+D;AAC/D,2EAAqE;AAIrE,MAAM,UAAU,GAA8B;IAC5C,aAAa,EAAE,4DAA4D;IAC3E,cAAc,EAAE,6DAA6D;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
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) "Neo4j"
|
|
5
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
6
|
+
*
|
|
7
|
+
* This file is part of Neo4j.
|
|
8
|
+
*
|
|
9
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
10
|
+
* it under the terms of the GNU General Public License as published by
|
|
11
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
12
|
+
* (at your option) any later version.
|
|
13
|
+
*
|
|
14
|
+
* This program is distributed in the hope that it will be useful,
|
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
* GNU General Public License for more details.
|
|
18
|
+
*
|
|
19
|
+
* You should have received a copy of the GNU General Public License
|
|
20
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.useGraphVisualizationContext = exports.GraphVisualization = void 0;
|
|
24
|
+
var graph_visualization_1 = require("./graph-visualization");
|
|
25
|
+
Object.defineProperty(exports, "GraphVisualization", { enumerable: true, get: function () { return graph_visualization_1.GraphVisualization; } });
|
|
26
|
+
var graph_visualization_context_1 = require("./graph-visualization-context");
|
|
27
|
+
Object.defineProperty(exports, "useGraphVisualizationContext", { enumerable: true, get: function () { return graph_visualization_context_1.useGraphVisualizationContext; } });
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAEH,6DAA2D;AAAlD,yHAAA,kBAAkB,OAAA;AAC3B,6EAeuC;AAdrC,2IAAA,4BAA4B,OAAA"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) "Neo4j"
|
|
5
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
6
|
+
*
|
|
7
|
+
* This file is part of Neo4j.
|
|
8
|
+
*
|
|
9
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
10
|
+
* it under the terms of the GNU General Public License as published by
|
|
11
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
12
|
+
* (at your option) any later version.
|
|
13
|
+
*
|
|
14
|
+
* This program is distributed in the hope that it will be useful,
|
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
* GNU General Public License for more details.
|
|
18
|
+
*
|
|
19
|
+
* You should have received a copy of the GNU General Public License
|
|
20
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.captionPriorityOrder = exports.NO_LABEL_FALLBACK_COLOR = exports.DEFAULT_REL_COLOR = void 0;
|
|
24
|
+
exports.getDefaultCaptionKey = getDefaultCaptionKey;
|
|
25
|
+
exports.mapToNvlGraph = mapToNvlGraph;
|
|
26
|
+
const word_color_1 = require("@neo4j-devtools/word-color");
|
|
27
|
+
const base_1 = require("@neo4j-ndl/base");
|
|
28
|
+
exports.DEFAULT_REL_COLOR = base_1.tokens.colors.neutral['40'];
|
|
29
|
+
exports.NO_LABEL_FALLBACK_COLOR = base_1.tokens.colors.neutral['40'];
|
|
30
|
+
const sortAlphabetically = (a = '', b = '') => a.toLowerCase().localeCompare(b.toLowerCase());
|
|
31
|
+
function getMostCommonColor(colors) {
|
|
32
|
+
var _a;
|
|
33
|
+
const [firstColor] = colors;
|
|
34
|
+
if (firstColor === undefined) {
|
|
35
|
+
return exports.NO_LABEL_FALLBACK_COLOR;
|
|
36
|
+
}
|
|
37
|
+
const colorCounts = {};
|
|
38
|
+
for (const color of colors) {
|
|
39
|
+
colorCounts[color] = ((_a = colorCounts[color]) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
40
|
+
}
|
|
41
|
+
let maxCount = 0;
|
|
42
|
+
let mostCommonColor = firstColor;
|
|
43
|
+
for (const [color, colorCount] of Object.entries(colorCounts)) {
|
|
44
|
+
if (colorCount > maxCount) {
|
|
45
|
+
maxCount = colorCount;
|
|
46
|
+
mostCommonColor = color;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return mostCommonColor;
|
|
50
|
+
}
|
|
51
|
+
function transformToItemMetada(arg) {
|
|
52
|
+
return Object.entries(arg).reduce((acc, [label, colors]) => {
|
|
53
|
+
acc[label] = {
|
|
54
|
+
mostCommonColor: getMostCommonColor(colors),
|
|
55
|
+
totalCount: colors.length,
|
|
56
|
+
};
|
|
57
|
+
return acc;
|
|
58
|
+
}, {});
|
|
59
|
+
}
|
|
60
|
+
exports.captionPriorityOrder = [
|
|
61
|
+
/^name$/i,
|
|
62
|
+
/^title$/i,
|
|
63
|
+
/^label$/i,
|
|
64
|
+
/name$/i,
|
|
65
|
+
/description$/i,
|
|
66
|
+
/^.+/,
|
|
67
|
+
];
|
|
68
|
+
function getDefaultCaptionKey(options) {
|
|
69
|
+
const captionKeys = options
|
|
70
|
+
.filter((option) => option.type === 'property')
|
|
71
|
+
.map((option) => option.captionKey);
|
|
72
|
+
for (const regex of exports.captionPriorityOrder) {
|
|
73
|
+
const matchingKey = captionKeys.find((key) => regex.test(key));
|
|
74
|
+
if (matchingKey !== undefined) {
|
|
75
|
+
return {
|
|
76
|
+
captionKey: matchingKey,
|
|
77
|
+
type: 'property',
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const typeOption = options.find((option) => option.type === 'type');
|
|
82
|
+
if (typeOption) {
|
|
83
|
+
return typeOption;
|
|
84
|
+
}
|
|
85
|
+
return options.find((option) => option.type === 'id');
|
|
86
|
+
}
|
|
87
|
+
const getDefaultNodeCaption = (item) => {
|
|
88
|
+
const options = Object.keys(item.properties).map((property) => ({
|
|
89
|
+
captionKey: property,
|
|
90
|
+
type: 'property',
|
|
91
|
+
}));
|
|
92
|
+
options.push({ type: 'id' }, { type: 'type' });
|
|
93
|
+
const defaultCaptionKey = getDefaultCaptionKey(options);
|
|
94
|
+
if ((defaultCaptionKey === null || defaultCaptionKey === void 0 ? void 0 : defaultCaptionKey.type) === 'property') {
|
|
95
|
+
const caption = item.properties[defaultCaptionKey.captionKey];
|
|
96
|
+
if (caption !== undefined) {
|
|
97
|
+
// remove quotes from string
|
|
98
|
+
if (caption.type === 'string') {
|
|
99
|
+
return [{ value: caption.stringified.slice(1, -1) }];
|
|
100
|
+
}
|
|
101
|
+
return [{ value: caption.stringified }];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const [firstLabel] = item.labels;
|
|
105
|
+
if ((defaultCaptionKey === null || defaultCaptionKey === void 0 ? void 0 : defaultCaptionKey.type) === 'type' && firstLabel !== undefined) {
|
|
106
|
+
return [{ value: firstLabel }];
|
|
107
|
+
}
|
|
108
|
+
return [{ value: item.id }];
|
|
109
|
+
};
|
|
110
|
+
// Properties can be huge, so we split them out into a separate lookup table
|
|
111
|
+
// to prevent them from making the physics slow
|
|
112
|
+
// here we also apply default colors & captions to nodes and relationships
|
|
113
|
+
// and sample colors for the sidepanel
|
|
114
|
+
// in the future we'll apply styling here as well
|
|
115
|
+
function mapToNvlGraph(rawNodes, rawRels) {
|
|
116
|
+
const labelColorPairs = {};
|
|
117
|
+
const typeColorPairs = {};
|
|
118
|
+
const nodeData = {};
|
|
119
|
+
const relData = {};
|
|
120
|
+
const nodes = rawNodes.map((node) => {
|
|
121
|
+
var _a;
|
|
122
|
+
const [firstLabel] = node.labels;
|
|
123
|
+
const newNode = Object.assign(Object.assign({ captions: getDefaultNodeCaption(node), color: (_a = node.color) !== null && _a !== void 0 ? _a : (firstLabel === undefined
|
|
124
|
+
? exports.NO_LABEL_FALLBACK_COLOR
|
|
125
|
+
: (0, word_color_1.calculateDefaultNodeColors)(firstLabel).backgroundColor) }, node), { labels: undefined, properties: undefined });
|
|
126
|
+
nodeData[node.id] = {
|
|
127
|
+
color: newNode.color,
|
|
128
|
+
id: node.id,
|
|
129
|
+
labelsSorted: [...node.labels].sort(sortAlphabetically),
|
|
130
|
+
properties: node.properties,
|
|
131
|
+
};
|
|
132
|
+
node.labels.forEach((label) => {
|
|
133
|
+
var _a;
|
|
134
|
+
labelColorPairs[label] = [
|
|
135
|
+
...((_a = labelColorPairs[label]) !== null && _a !== void 0 ? _a : []),
|
|
136
|
+
newNode.color,
|
|
137
|
+
];
|
|
138
|
+
});
|
|
139
|
+
return newNode;
|
|
140
|
+
});
|
|
141
|
+
const rels = rawRels.map((rel) => {
|
|
142
|
+
var _a, _b, _c;
|
|
143
|
+
relData[rel.id] = {
|
|
144
|
+
color: (_a = rel.color) !== null && _a !== void 0 ? _a : exports.DEFAULT_REL_COLOR,
|
|
145
|
+
id: rel.id,
|
|
146
|
+
properties: rel.properties,
|
|
147
|
+
type: rel.type,
|
|
148
|
+
};
|
|
149
|
+
typeColorPairs[rel.type] = [
|
|
150
|
+
...((_b = typeColorPairs[rel.type]) !== null && _b !== void 0 ? _b : []),
|
|
151
|
+
(_c = rel.color) !== null && _c !== void 0 ? _c : exports.DEFAULT_REL_COLOR,
|
|
152
|
+
];
|
|
153
|
+
return Object.assign(Object.assign({ captions: [{ value: rel.type }], color: exports.DEFAULT_REL_COLOR }, rel), { properties: undefined, type: undefined });
|
|
154
|
+
});
|
|
155
|
+
const labelMetaData = transformToItemMetada(labelColorPairs);
|
|
156
|
+
const typeMetaData = transformToItemMetada(typeColorPairs);
|
|
157
|
+
const dataLookupTable = {
|
|
158
|
+
labelMetaData,
|
|
159
|
+
labels: Object.keys(labelMetaData).sort((a, b) => sortAlphabetically(a, b)),
|
|
160
|
+
nodes: nodeData,
|
|
161
|
+
relationships: relData,
|
|
162
|
+
typeMetaData,
|
|
163
|
+
types: Object.keys(typeMetaData).sort((a, b) => sortAlphabetically(a, b)),
|
|
164
|
+
};
|
|
165
|
+
return { dataLookupTable, nodes, rels };
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=map-to-nvl-graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-to-nvl-graph.js","sourceRoot":"","sources":["../../src/map-to-nvl-graph.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AA8EH,oDAuBC;AAuCD,sCA2EC;AArND,2DAAwE;AACxE,0CAAyC;AAsB5B,QAAA,iBAAiB,GAAG,aAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAChD,QAAA,uBAAuB,GAAG,aAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnE,MAAM,kBAAkB,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,CAC5C,CAAC,CAAC,WAAW,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAEjD,SAAS,kBAAkB,CAAC,MAAgB;;IAC1C,MAAM,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;IAE5B,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,+BAAuB,CAAC;IACjC,CAAC;IAED,MAAM,WAAW,GAA2B,EAAE,CAAC;IAC/C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,MAAA,WAAW,CAAC,KAAK,CAAC,mCAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACrD,CAAC;IAED,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,eAAe,GAAG,UAAU,CAAC;IAEjC,KAAK,MAAM,CAAC,KAAK,EAAE,UAAU,CAA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M,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3E,KAAK,EAAE,QAAQ;QACf,aAAa,EAAE,OAAO;QACtB,YAAY;QACZ,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KAC1E,CAAC;IAEF,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ButtonGroup = void 0;
|
|
27
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* Copyright (c) "Neo4j"
|
|
31
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
32
|
+
*
|
|
33
|
+
* This file is part of Neo4j.
|
|
34
|
+
*
|
|
35
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
36
|
+
* it under the terms of the GNU General Public License as published by
|
|
37
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
38
|
+
* (at your option) any later version.
|
|
39
|
+
*
|
|
40
|
+
* This program is distributed in the hope that it will be useful,
|
|
41
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
42
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
43
|
+
* GNU General Public License for more details.
|
|
44
|
+
*
|
|
45
|
+
* You should have received a copy of the GNU General Public License
|
|
46
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
47
|
+
*/
|
|
48
|
+
const react_1 = __importStar(require("react"));
|
|
49
|
+
const ButtonGroup = ({ children }) => {
|
|
50
|
+
const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(0);
|
|
51
|
+
const parentRef = (0, react_1.useRef)(null);
|
|
52
|
+
const focusElement = (index) => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
const child = (_b = (_a = parentRef.current) === null || _a === void 0 ? void 0 : _a.children[index]) === null || _b === void 0 ? void 0 : _b.children[0];
|
|
55
|
+
if (child instanceof HTMLElement) {
|
|
56
|
+
child.focus();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const childrenCount = (0, react_1.useMemo)(() => react_1.default.Children.count(children), [children]);
|
|
60
|
+
const safeSetSelectedIndex = (0, react_1.useCallback)((index) => {
|
|
61
|
+
if (index >= childrenCount) {
|
|
62
|
+
setSelectedIndex(childrenCount - 1);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
setSelectedIndex(Math.max(0, index));
|
|
66
|
+
}
|
|
67
|
+
}, [childrenCount, setSelectedIndex]);
|
|
68
|
+
const handleKeyDown = (event) => {
|
|
69
|
+
let newIndx = selectedIndex;
|
|
70
|
+
if (event.key === 'ArrowRight' || event.key === 'ArrowDown') {
|
|
71
|
+
newIndx = (selectedIndex + 1) % react_1.default.Children.count(children);
|
|
72
|
+
safeSetSelectedIndex(newIndx);
|
|
73
|
+
}
|
|
74
|
+
else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') {
|
|
75
|
+
newIndx =
|
|
76
|
+
(selectedIndex - 1 + react_1.default.Children.count(children)) %
|
|
77
|
+
react_1.default.Children.count(children);
|
|
78
|
+
safeSetSelectedIndex(newIndx);
|
|
79
|
+
}
|
|
80
|
+
// set focus to new button
|
|
81
|
+
focusElement(newIndx);
|
|
82
|
+
};
|
|
83
|
+
return (
|
|
84
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
85
|
+
(0, jsx_runtime_1.jsx)("ul", { onKeyDown: (e) => handleKeyDown(e), ref: parentRef, style: { all: 'inherit', listStyleType: 'none' }, children: react_1.default.Children.map(children, (child, index) => {
|
|
86
|
+
if (!react_1.default.isValidElement(child)) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const clonedElement = (0, react_1.cloneElement)(child, {
|
|
90
|
+
tabIndex: selectedIndex === index ? 0 : -1,
|
|
91
|
+
});
|
|
92
|
+
return (0, jsx_runtime_1.jsx)("li", { children: clonedElement }, index);
|
|
93
|
+
}) }));
|
|
94
|
+
};
|
|
95
|
+
exports.ButtonGroup = ButtonGroup;
|
|
96
|
+
//# sourceMappingURL=button-group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button-group.js","sourceR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