@modernrelay/orbit-react 0.14.0 → 0.16.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.js CHANGED
@@ -190,6 +190,7 @@ function LabelLayer(props) {
190
190
  const [candidates, setCandidates] = useState([]);
191
191
  const elementsRef = useRef(/* @__PURE__ */ new Map());
192
192
  const positionsRef = useRef(/* @__PURE__ */ new Map());
193
+ const layerRef = useRef(null);
193
194
  useEffect(() => {
194
195
  if (labels === void 0) return void 0;
195
196
  return labels.subscribeCandidates((list) => {
@@ -219,20 +220,43 @@ function LabelLayer(props) {
219
220
  }
220
221
  });
221
222
  }, [labels]);
222
- const onLabelClick = (id, e) => {
223
- e.stopPropagation();
224
- if (e.metaKey || e.shiftKey) {
223
+ const selectLabel = (id, additive) => {
224
+ if (additive) {
225
225
  const cur = instance.store.getState().selection.nodeIds;
226
226
  instance.setSelection(cur.includes(id) ? cur.filter((x) => x !== id) : [...cur, id]);
227
227
  return;
228
228
  }
229
229
  instance.setSelection([id]);
230
230
  };
231
+ const onLabelClick = (id, e) => {
232
+ e.stopPropagation();
233
+ selectLabel(id, e.metaKey || e.shiftKey);
234
+ };
231
235
  const onClusterLabelClick = (key, e) => {
232
236
  e.stopPropagation();
233
237
  instance.selectCluster(key, { additive: e.metaKey || e.shiftKey });
234
238
  };
235
- const layerRef = useRef(null);
239
+ const onLabelKeyDown = (p, e) => {
240
+ if (p.kind !== "cluster" && (e.key === "ContextMenu" || e.key === "F10" && e.shiftKey)) {
241
+ e.preventDefault();
242
+ e.stopPropagation();
243
+ const layerRect = layerRef.current?.getBoundingClientRect();
244
+ if (layerRect === void 0) return;
245
+ const labelRect = e.currentTarget.getBoundingClientRect();
246
+ instance.requestNodeContextMenu(p.id, [
247
+ labelRect.left + labelRect.width / 2 - layerRect.left,
248
+ labelRect.top + labelRect.height / 2 - layerRect.top
249
+ ]);
250
+ return;
251
+ }
252
+ if (e.target !== e.currentTarget) return;
253
+ if (e.key !== "Enter" && e.key !== " ") return;
254
+ e.preventDefault();
255
+ e.stopPropagation();
256
+ const additive = e.metaKey || e.shiftKey;
257
+ if (p.kind === "cluster") instance.selectCluster(p.id, { additive });
258
+ else selectLabel(p.id, additive);
259
+ };
236
260
  const onLabelContextMenu = (id, e) => {
237
261
  e.preventDefault();
238
262
  e.stopPropagation();
@@ -246,17 +270,25 @@ function LabelLayer(props) {
246
270
  const [x, y] = positionsRef.current.get(key) ?? [p.x, p.y];
247
271
  const isCluster = p.kind === "cluster";
248
272
  const className = isCluster ? [props.labelClassName, props.clusterLabelClassName].filter(Boolean).join(" ") || void 0 : props.labelClassName;
273
+ const hasCustomRenderer = isCluster ? props.renderClusterLabel !== void 0 : props.renderNodeLabel !== void 0;
249
274
  return /* @__PURE__ */ jsx(
250
275
  "div",
251
276
  {
252
277
  ...isCluster ? { "data-orbit-cluster-label": p.id } : { "data-orbit-label": p.id },
253
278
  className,
279
+ ...!hasCustomRenderer ? {
280
+ role: "button",
281
+ tabIndex: 0,
282
+ "aria-label": p.text,
283
+ ...!isCluster ? { "aria-haspopup": "menu" } : {}
284
+ } : {},
254
285
  style: { ...LABEL_BASE_STYLE, transform: transformOf(x, y) },
255
286
  ref: (el) => {
256
287
  if (el === null) elementsRef.current.delete(key);
257
288
  else elementsRef.current.set(key, el);
258
289
  },
259
290
  onClick: (e) => isCluster ? onClusterLabelClick(p.id, e) : onLabelClick(p.id, e),
291
+ onKeyDown: (e) => onLabelKeyDown(p, e),
260
292
  onContextMenu: isCluster ? void 0 : (e) => onLabelContextMenu(p.id, e),
261
293
  children: isCluster ? props.renderClusterLabel !== void 0 ? props.renderClusterLabel({
262
294
  clusterKey: p.id,
@@ -385,6 +417,8 @@ function GraphInner(props, ref) {
385
417
  if (props.fitViewOnFirstData !== void 0) {
386
418
  options.fitViewOnFirstData = props.fitViewOnFirstData;
387
419
  }
420
+ if (props.fitViewOnSettle !== void 0) options.fitViewOnSettle = props.fitViewOnSettle;
421
+ if (props.fitViewMaxZoom !== void 0) options.fitViewMaxZoom = props.fitViewMaxZoom;
388
422
  if (props.searchIndex !== void 0) options.searchIndex = props.searchIndex;
389
423
  if (props.limits !== void 0) options.limits = props.limits;
390
424
  if (props.execution !== void 0) options.execution = props.execution;