diff --git a/docs/api-reference/widgets/splitter-widget.md b/docs/api-reference/widgets/splitter-widget.md index 0fc56a4753b..2982ac51cd9 100644 --- a/docs/api-reference/widgets/splitter-widget.md +++ b/docs/api-reference/widgets/splitter-widget.md @@ -45,13 +45,13 @@ import {_SplitterWidget as SplitterWidget} from '@deck.gl/widgets'; import {Deck, OrbitView, type OrbitViewState} from '@deck.gl/core'; import '@deck.gl/widgets/stylesheet.css'; -new Deck({ +new Deck({ initialViewState: { front: {target: [0, 0, 0], rotationX: 0, rotationOrbit: 90, zoom: 0} satisfies OrbitViewState, perspective: {target: [0, 0, 0], rotationX: 45, rotationOrbit: 30, zoom: 0} satisfies OrbitViewState }, widgets: [ - new SplitterWidget({ + new SplitterWidget({ viewLayout: { orientation: 'horizontal', views: [ @@ -141,7 +141,7 @@ function App() { ```ts import {_SplitterWidget as SplitterWidget, type SplitterWidgetProps} from '@deck.gl/widgets'; -new SplitterWidget({} satisfies SplitterWidgetProps); +new SplitterWidget({} satisfies SplitterWidgetProps); ``` ## Types diff --git a/modules/core/src/lib/deck.ts b/modules/core/src/lib/deck.ts index dae456644d8..ec03d240bd9 100644 --- a/modules/core/src/lib/deck.ts +++ b/modules/core/src/lib/deck.ts @@ -183,7 +183,7 @@ export type DeckProps = { /** (Experimental) Fine-tune attribute memory usage. See documentation for details. */ _typedArrayManagerProps?: TypedArrayManagerOptions; /** An array of Widget instances to be added to the parent element. */ - widgets?: Widget[]; + widgets?: Widget[]; /** Called once the GPU Device has been initiated. */ onDeviceInitialized?: (device: Device) => void; diff --git a/modules/widgets/src/splitter-widget.tsx b/modules/widgets/src/splitter-widget.tsx index 19f85486c90..85435c385f4 100644 --- a/modules/widgets/src/splitter-widget.tsx +++ b/modules/widgets/src/splitter-widget.tsx @@ -148,11 +148,11 @@ function evaluateViews(root: ManagedViewLayout): View[] { } /** Properties for the SplitterWidget */ -export type SplitterWidgetProps = WidgetProps & { +export type SplitterWidgetProps = WidgetProps & { /** Stacking views descriptor */ viewLayout: ViewLayout; /** Callback invoked when the splitter is dragged with the new split value */ - onChange?: (views: View[]) => void; + onChange?: (views: ViewsT) => void; /** Callback invoked when dragging starts */ onDragStart?: () => void; /** Callback invoked when dragging ends */ @@ -164,7 +164,10 @@ export type SplitterWidgetProps = WidgetProps & { * across the deck.gl canvas. It positions itself based on the split percentage * of the first view and provides callbacks when dragged. */ -export class SplitterWidget extends Widget { +export class SplitterWidget extends Widget< + SplitterWidgetProps, + ViewsT +> { static defaultProps: Required = { ...Widget.defaultProps, id: 'splitter-widget', @@ -178,17 +181,17 @@ export class SplitterWidget extends Widget { placement = 'fill' as const; viewLayouts!: ManagedViewLayout[]; /** evaluated from the current viewLayouts */ - views!: View[]; + views!: ViewsT; /** views set in the last update */ - lastViews?: View[]; + lastViews?: ViewsT; needsUpdate = true; - constructor(props: SplitterWidgetProps) { + constructor(props: SplitterWidgetProps) { super(props); this.viewLayouts = parseViewLayout(this.props.viewLayout); } - setProps(props: Partial) { + setProps(props: Partial>) { if (props.viewLayout && !deepEqual(props.viewLayout, this.props.viewLayout, -1)) { this.viewLayouts = parseViewLayout(props.viewLayout); this.views = undefined!; @@ -207,9 +210,9 @@ export class SplitterWidget extends Widget { updateHTML() { if (!this.views) { // viewLayouts has changed, re-evaluate - this.views = evaluateViews(this.viewLayouts[0]); + this.views = evaluateViews(this.viewLayouts[0]) as ViewsT; // we send a copy to the callback so that externally set views can be differentiated from internal - this.props.onChange(this.views.slice()); + this.props.onChange(this.views.slice() as ViewsT); } // This method is called inside deck.setProps > widgetManager.setProps > widget.setProps // Calling deck.setProps immediately would cause infinite loop @@ -237,9 +240,9 @@ export class SplitterWidget extends Widget { private onChange(newSplit: number, layout: ManagedViewLayout) { layout.split = newSplit; // layout has updated, re-evaluate - this.views = evaluateViews(this.viewLayouts[0]); + this.views = evaluateViews(this.viewLayouts[0]) as ViewsT; // we send a copy to the callback so that externally set views can be differentiated from internal - this.props.onChange(this.views.slice()); + this.props.onChange(this.views.slice() as ViewsT); this.doUpdate(); }