chore(a11y): merge labelConfig with defaults

This commit is contained in:
Abbey Yacoe
2025-05-22 11:38:02 +02:00
parent 6081f687bf
commit 48c5467851
5 changed files with 15 additions and 5 deletions
+1 -1
View File
@@ -67,7 +67,7 @@ const A11y = () => {
'a11yDescription.edge.default': 'Custom Edge Desc.', 'a11yDescription.edge.default': 'Custom Edge Desc.',
'controls.zoomin.title': 'Custom Zoom in', 'controls.zoomin.title': 'Custom Zoom in',
'controls.zoomout.title': 'Custom Zoom Out', 'controls.zoomout.title': 'Custom Zoom Out',
'controls.fitview.title': 'Custom Fit View', // 'controls.fitview.title': 'Custom Fit View',
'controls.interactive.title': 'Custom Toggle Interactivity', 'controls.interactive.title': 'Custom Toggle Interactivity',
}} }}
> >
@@ -39,7 +39,7 @@
'a11yDescription.edge.default': 'Svelte Custom Edge Desc.', 'a11yDescription.edge.default': 'Svelte Custom Edge Desc.',
'controls.zoomin.title': 'Svelte Custom Zoom in', 'controls.zoomin.title': 'Svelte Custom Zoom in',
'controls.zoomout.title': 'Svelte Custom Zoom Out', 'controls.zoomout.title': 'Svelte Custom Zoom Out',
'controls.fitview.title': 'Svelte Custom Fit View', // 'controls.fitview.title': 'Svelte Custom Fit View',
'controls.interactive.title': 'Svelte Custom Toggle Interactivity', 'controls.interactive.title': 'Svelte Custom Toggle Interactivity',
}} }}
> >
@@ -5,7 +5,7 @@
*/ */
import { useEffect, useRef } from 'react'; import { useEffect, useRef } from 'react';
import { shallow } from 'zustand/shallow'; import { shallow } from 'zustand/shallow';
import { infiniteExtent, type CoordinateExtent } from '@xyflow/system'; import { infiniteExtent, type CoordinateExtent, mergeLabelConfig, LabelConfig } from '@xyflow/system';
import { useStore, useStoreApi } from '../../hooks/useStore'; import { useStore, useStoreApi } from '../../hooks/useStore';
import type { Node, Edge, ReactFlowState, ReactFlowProps, FitViewOptions } from '../../types'; import type { Node, Edge, ReactFlowState, ReactFlowProps, FitViewOptions } from '../../types';
@@ -157,6 +157,10 @@ export function StoreUpdater<NodeType extends Node = Node, EdgeType extends Edge
// Renamed fields // Renamed fields
else if (fieldName === 'fitView') store.setState({ fitViewQueued: fieldValue as boolean }); else if (fieldName === 'fitView') store.setState({ fitViewQueued: fieldValue as boolean });
else if (fieldName === 'fitViewOptions') store.setState({ fitViewOptions: fieldValue as FitViewOptions }); else if (fieldName === 'fitViewOptions') store.setState({ fitViewOptions: fieldValue as FitViewOptions });
if (fieldName === 'labelConfig') {
store.setState({ labelConfig: mergeLabelConfig(fieldValue as LabelConfig) });
}
// General case // General case
else store.setState({ [fieldName]: fieldValue }); else store.setState({ [fieldName]: fieldValue });
} }
@@ -7,7 +7,7 @@ import {
getViewportForBounds, getViewportForBounds,
updateConnectionLookup, updateConnectionLookup,
initialConnection, initialConnection,
defaultLabelConfig, mergeLabelConfig,
type SelectionRect, type SelectionRect,
type SnapGrid, type SnapGrid,
type MarkerProps, type MarkerProps,
@@ -291,7 +291,7 @@ export function getInitialStore<NodeType extends Node = Node, EdgeType extends E
noPanClass: string = $derived(signals.props.noPanClass ?? 'nopan'); noPanClass: string = $derived(signals.props.noPanClass ?? 'nopan');
noDragClass: string = $derived(signals.props.noDragClass ?? 'nodrag'); noDragClass: string = $derived(signals.props.noDragClass ?? 'nodrag');
noWheelClass: string = $derived(signals.props.noWheelClass ?? 'nowheel'); noWheelClass: string = $derived(signals.props.noWheelClass ?? 'nowheel');
labelConfig: LabelConfig = $derived(signals.props.labelConfig ?? defaultLabelConfig); labelConfig: LabelConfig = $derived(mergeLabelConfig(signals.props.labelConfig));
// _viewport is the internal viewport. // _viewport is the internal viewport.
// when binding to viewport, we operate on signals.viewport instead // when binding to viewport, we operate on signals.viewport instead
+6
View File
@@ -16,6 +16,8 @@ import type {
import { type Viewport } from '../types'; import { type Viewport } from '../types';
import { getNodePositionWithOrigin, isInternalNodeBase } from './graph'; import { getNodePositionWithOrigin, isInternalNodeBase } from './graph';
import { defaultLabelConfig, type LabelConfig } from '../constants';
export const clamp = (val: number, min = 0, max = 1): number => Math.min(Math.max(val, min), max); export const clamp = (val: number, min = 0, max = 1): number => Math.min(Math.max(val, min), max);
export const clampPosition = ( export const clampPosition = (
@@ -418,3 +420,7 @@ export function withResolvers<T>(): {
}); });
return { promise, resolve, reject }; return { promise, resolve, reject };
} }
export function mergeLabelConfig(partial?: Partial<LabelConfig>): LabelConfig {
return { ...defaultLabelConfig, ...(partial || {}) };
}