@deck.gl/react 9.0.0-beta.1 → 9.0.0-beta.11

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.
Files changed (65) hide show
  1. package/dist/deckgl.d.ts +24 -0
  2. package/dist/deckgl.d.ts.map +1 -0
  3. package/dist/deckgl.js +194 -0
  4. package/dist/index.cjs +382 -0
  5. package/dist/index.cjs.map +7 -0
  6. package/dist/index.d.ts +5 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +21 -0
  9. package/dist/utils/evaluate-children.js +34 -0
  10. package/dist/utils/extract-jsx-layers.js +84 -0
  11. package/dist/utils/extract-styles.js +32 -0
  12. package/dist/utils/inherits-from.js +10 -0
  13. package/{typed → dist}/utils/position-children-under-views.d.ts +3 -2
  14. package/dist/utils/position-children-under-views.d.ts.map +1 -0
  15. package/dist/utils/position-children-under-views.js +80 -0
  16. package/dist/{esm/utils → utils}/use-isomorphic-layout-effect.js +2 -1
  17. package/package.json +23 -14
  18. package/src/deckgl.ts +33 -31
  19. package/src/utils/position-children-under-views.ts +3 -2
  20. package/dist/es5/deckgl.js +0 -212
  21. package/dist/es5/deckgl.js.map +0 -1
  22. package/dist/es5/index.js +0 -22
  23. package/dist/es5/index.js.map +0 -1
  24. package/dist/es5/utils/evaluate-children.js +0 -59
  25. package/dist/es5/utils/evaluate-children.js.map +0 -1
  26. package/dist/es5/utils/extract-jsx-layers.js +0 -109
  27. package/dist/es5/utils/extract-jsx-layers.js.map +0 -1
  28. package/dist/es5/utils/extract-styles.js +0 -43
  29. package/dist/es5/utils/extract-styles.js.map +0 -1
  30. package/dist/es5/utils/inherits-from.js +0 -19
  31. package/dist/es5/utils/inherits-from.js.map +0 -1
  32. package/dist/es5/utils/position-children-under-views.js +0 -138
  33. package/dist/es5/utils/position-children-under-views.js.map +0 -1
  34. package/dist/es5/utils/use-isomorphic-layout-effect.js +0 -13
  35. package/dist/es5/utils/use-isomorphic-layout-effect.js.map +0 -1
  36. package/dist/esm/deckgl.js +0 -173
  37. package/dist/esm/deckgl.js.map +0 -1
  38. package/dist/esm/index.js +0 -3
  39. package/dist/esm/index.js.map +0 -1
  40. package/dist/esm/utils/evaluate-children.js +0 -42
  41. package/dist/esm/utils/evaluate-children.js.map +0 -1
  42. package/dist/esm/utils/extract-jsx-layers.js +0 -89
  43. package/dist/esm/utils/extract-jsx-layers.js.map +0 -1
  44. package/dist/esm/utils/extract-styles.js +0 -37
  45. package/dist/esm/utils/extract-styles.js.map +0 -1
  46. package/dist/esm/utils/inherits-from.js +0 -12
  47. package/dist/esm/utils/inherits-from.js.map +0 -1
  48. package/dist/esm/utils/position-children-under-views.js +0 -106
  49. package/dist/esm/utils/position-children-under-views.js.map +0 -1
  50. package/dist/esm/utils/use-isomorphic-layout-effect.js.map +0 -1
  51. package/typed/deckgl.d.ts +0 -28
  52. package/typed/deckgl.d.ts.map +0 -1
  53. package/typed/index.d.ts +0 -5
  54. package/typed/index.d.ts.map +0 -1
  55. package/typed/utils/position-children-under-views.d.ts.map +0 -1
  56. /package/{typed → dist}/utils/evaluate-children.d.ts +0 -0
  57. /package/{typed → dist}/utils/evaluate-children.d.ts.map +0 -0
  58. /package/{typed → dist}/utils/extract-jsx-layers.d.ts +0 -0
  59. /package/{typed → dist}/utils/extract-jsx-layers.d.ts.map +0 -0
  60. /package/{typed → dist}/utils/extract-styles.d.ts +0 -0
  61. /package/{typed → dist}/utils/extract-styles.d.ts.map +0 -0
  62. /package/{typed → dist}/utils/inherits-from.d.ts +0 -0
  63. /package/{typed → dist}/utils/inherits-from.d.ts.map +0 -0
  64. /package/{typed → dist}/utils/use-isomorphic-layout-effect.d.ts +0 -0
  65. /package/{typed → dist}/utils/use-isomorphic-layout-effect.d.ts.map +0 -0
@@ -0,0 +1,5 @@
1
+ export { default as DeckGL } from "./deckgl.js";
2
+ export { default } from "./deckgl.js";
3
+ export type { DeckGLContextValue } from "./utils/position-children-under-views.js";
4
+ export type { DeckGLRef, DeckGLProps } from "./deckgl.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,oBAAiB;AAC3C,OAAO,EAAC,OAAO,EAAC,oBAAiB;AAGjC,YAAY,EAAC,kBAAkB,EAAC,iDAA8C;AAC9E,YAAY,EAAC,SAAS,EAAE,WAAW,EAAC,oBAAiB"}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ // Copyright (c) 2015 - 2017 Uber Technologies, Inc.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in
11
+ // all copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+ export { default as DeckGL } from "./deckgl.js";
21
+ export { default } from "./deckgl.js";
@@ -0,0 +1,34 @@
1
+ import { cloneElement } from 'react';
2
+ const MAP_STYLE = { position: 'absolute', zIndex: -1 };
3
+ export default function evaluateChildren(children, childProps) {
4
+ if (typeof children === 'function') {
5
+ return children(childProps);
6
+ }
7
+ if (Array.isArray(children)) {
8
+ return children.map(child => evaluateChildren(child, childProps));
9
+ }
10
+ if (isComponent(children)) {
11
+ // Special treatment for react-map-gl's Map component
12
+ // to support shorthand use case <DeckGL><StaticMap /></DeckGL>
13
+ if (isReactMap(children)) {
14
+ // Place map under the canvas
15
+ childProps.style = MAP_STYLE;
16
+ return cloneElement(children, childProps);
17
+ }
18
+ if (needsDeckGLViewProps(children)) {
19
+ return cloneElement(children, childProps);
20
+ }
21
+ }
22
+ return children;
23
+ }
24
+ export function isComponent(child) {
25
+ return (child && typeof child === 'object' && 'type' in child) || false;
26
+ }
27
+ function isReactMap(child) {
28
+ return child.props?.mapStyle;
29
+ }
30
+ function needsDeckGLViewProps(child) {
31
+ const componentClass = child.type;
32
+ // @ts-expect-error deckGLViewProps is a custom hack defined on the constructor (nebula.gl)
33
+ return componentClass && componentClass.deckGLViewProps;
34
+ }
@@ -0,0 +1,84 @@
1
+ import * as React from 'react';
2
+ import { createElement } from 'react';
3
+ import { inheritsFrom } from "./inherits-from.js";
4
+ import { Layer, View } from '@deck.gl/core';
5
+ import { isComponent } from "./evaluate-children.js";
6
+ // recursively wrap render callbacks in `View`
7
+ function wrapInView(node) {
8
+ if (typeof node === 'function') {
9
+ // React.Children does not traverse functions.
10
+ // All render callbacks must be protected under a <View>
11
+ // @ts-expect-error View is not a ReactJSXElement constructor. Only used as a temporary wrapper and will be removed in extractJSXLayers
12
+ return createElement(View, {}, node);
13
+ }
14
+ if (Array.isArray(node)) {
15
+ return node.map(wrapInView);
16
+ }
17
+ if (isComponent(node)) {
18
+ if (node.type === React.Fragment) {
19
+ return wrapInView(node.props.children);
20
+ }
21
+ if (inheritsFrom(node.type, View)) {
22
+ return node;
23
+ }
24
+ }
25
+ return node;
26
+ }
27
+ // extracts any deck.gl layers masquerading as react elements from props.children
28
+ export default function extractJSXLayers({ children, layers = [], views = null }) {
29
+ const reactChildren = []; // extract real react elements (i.e. not deck.gl layers)
30
+ const jsxLayers = []; // extracted layer from react children, will add to deck.gl layer array
31
+ const jsxViews = {};
32
+ // React.children
33
+ React.Children.forEach(wrapInView(children), reactElement => {
34
+ if (isComponent(reactElement)) {
35
+ // For some reason Children.forEach doesn't filter out `null`s
36
+ const ElementType = reactElement.type;
37
+ if (inheritsFrom(ElementType, Layer)) {
38
+ const layer = createLayer(ElementType, reactElement.props);
39
+ jsxLayers.push(layer);
40
+ }
41
+ else {
42
+ reactChildren.push(reactElement);
43
+ }
44
+ // empty id => default view
45
+ if (inheritsFrom(ElementType, View) && ElementType !== View && reactElement.props.id) {
46
+ // @ts-ignore Cannot instantiate an abstract class (View)
47
+ const view = new ElementType(reactElement.props);
48
+ jsxViews[view.id] = view;
49
+ }
50
+ }
51
+ else if (reactElement) {
52
+ reactChildren.push(reactElement);
53
+ }
54
+ });
55
+ // Avoid modifying views if no JSX views were found
56
+ if (Object.keys(jsxViews).length > 0) {
57
+ // If a view is specified in both views prop and JSX, use the one in views
58
+ if (Array.isArray(views)) {
59
+ views.forEach(view => {
60
+ jsxViews[view.id] = view;
61
+ });
62
+ }
63
+ else if (views) {
64
+ jsxViews[views.id] = views;
65
+ }
66
+ views = Object.values(jsxViews);
67
+ }
68
+ // Avoid modifying layers array if no JSX layers were found
69
+ layers = jsxLayers.length > 0 ? [...jsxLayers, ...layers] : layers;
70
+ return { layers, children: reactChildren, views };
71
+ }
72
+ function createLayer(LayerType, reactProps) {
73
+ const props = {};
74
+ // Layer.defaultProps is treated as ReactElement.defaultProps and merged into react props
75
+ // Remove them
76
+ const defaultProps = LayerType.defaultProps || {};
77
+ for (const key in reactProps) {
78
+ if (defaultProps[key] !== reactProps[key]) {
79
+ props[key] = reactProps[key];
80
+ }
81
+ }
82
+ // @ts-ignore Cannot instantiate an abstract class (Layer)
83
+ return new LayerType(props);
84
+ }
@@ -0,0 +1,32 @@
1
+ const CANVAS_ONLY_STYLES = {
2
+ mixBlendMode: null
3
+ };
4
+ export default function extractStyles({ width, height, style }) {
5
+ // This styling is enforced for correct positioning with children
6
+ const containerStyle = {
7
+ position: 'absolute',
8
+ zIndex: 0,
9
+ left: 0,
10
+ top: 0,
11
+ width,
12
+ height
13
+ };
14
+ // Fill the container
15
+ const canvasStyle = {
16
+ left: 0,
17
+ top: 0
18
+ };
19
+ if (style) {
20
+ for (const key in style) {
21
+ if (key in CANVAS_ONLY_STYLES) {
22
+ // apply style to the canvas, but not deck's children, e.g. mix-blend-mode
23
+ canvasStyle[key] = style[key];
24
+ }
25
+ else {
26
+ // apply style to the container, e.g. position/flow settings
27
+ containerStyle[key] = style[key];
28
+ }
29
+ }
30
+ }
31
+ return { containerStyle, canvasStyle };
32
+ }
@@ -0,0 +1,10 @@
1
+ // Check if one JavaScript class inherits from another
2
+ export function inheritsFrom(Type, ParentType) {
3
+ while (Type) {
4
+ if (Type === ParentType) {
5
+ return true;
6
+ }
7
+ Type = Object.getPrototypeOf(Type);
8
+ }
9
+ return false;
10
+ }
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import type { ViewOrViews } from "../deckgl.js";
2
3
  import type { Deck, DeckProps, Viewport } from '@deck.gl/core';
3
4
  import type { EventManager } from 'mjolnir.js';
4
5
  export type DeckGLContextValue = {
@@ -7,9 +8,9 @@ export type DeckGLContextValue = {
7
8
  eventManager: EventManager;
8
9
  onViewStateChange: DeckProps['onViewStateChange'];
9
10
  };
10
- export default function positionChildrenUnderViews({ children, deck, ContextProvider }: {
11
+ export default function positionChildrenUnderViews<ViewsT extends ViewOrViews>({ children, deck, ContextProvider }: {
11
12
  children: React.ReactNode[];
12
- deck?: Deck;
13
+ deck?: Deck<ViewsT>;
13
14
  ContextProvider?: React.Context<DeckGLContextValue>['Provider'];
14
15
  }): React.ReactNode[];
15
16
  //# sourceMappingURL=position-children-under-views.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"position-children-under-views.d.ts","sourceRoot":"","sources":["../../src/utils/position-children-under-views.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,KAAK,EAAC,WAAW,EAAC,qBAAkB;AAC3C,OAAO,KAAK,EAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAC,MAAM,eAAe,CAAC;AAC7D,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AAE7C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,WAAW,CAAC;IACvB,YAAY,EAAE,YAAY,CAAC;IAC3B,iBAAiB,EAAE,SAAS,CAAC,mBAAmB,CAAC,CAAC;CACnD,CAAC;AAIF,MAAM,CAAC,OAAO,UAAU,0BAA0B,CAAC,MAAM,SAAS,WAAW,EAAE,EAC7E,QAAQ,EACR,IAAI,EACJ,eAAe,EAChB,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;IAC5B,IAAI,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACpB,eAAe,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC;CACjE,GAAG,KAAK,CAAC,SAAS,EAAE,CA0FpB"}
@@ -0,0 +1,80 @@
1
+ import { createElement } from 'react';
2
+ import { View } from '@deck.gl/core';
3
+ import { inheritsFrom } from "./inherits-from.js";
4
+ import evaluateChildren, { isComponent } from "./evaluate-children.js";
5
+ // Iterate over views and reposition children associated with views
6
+ // TODO - Can we supply a similar function for the non-React case?
7
+ export default function positionChildrenUnderViews({ children, deck, ContextProvider }) {
8
+ // @ts-expect-error accessing protected property
9
+ const { viewManager } = deck || {};
10
+ if (!viewManager || !viewManager.views.length) {
11
+ return [];
12
+ }
13
+ const views = {};
14
+ const defaultViewId = viewManager.views[0].id;
15
+ // Sort children by view id
16
+ for (const child of children) {
17
+ // Unless child is a View, position / render as part of the default view
18
+ let viewId = defaultViewId;
19
+ let viewChildren = child;
20
+ if (isComponent(child) && inheritsFrom(child.type, View)) {
21
+ viewId = child.props.id || defaultViewId;
22
+ viewChildren = child.props.children;
23
+ }
24
+ const viewport = viewManager.getViewport(viewId);
25
+ const viewState = viewManager.getViewState(viewId);
26
+ // Drop (auto-hide) elements with viewId that are not matched by any current view
27
+ if (viewport) {
28
+ viewState.padding = viewport.padding;
29
+ const { x, y, width, height } = viewport;
30
+ // Resolve potentially relative dimensions using the deck.gl container size
31
+ viewChildren = evaluateChildren(viewChildren, {
32
+ x,
33
+ y,
34
+ width,
35
+ height,
36
+ viewport,
37
+ viewState
38
+ });
39
+ if (!views[viewId]) {
40
+ views[viewId] = {
41
+ viewport,
42
+ children: []
43
+ };
44
+ }
45
+ views[viewId].children.push(viewChildren);
46
+ }
47
+ }
48
+ // Render views
49
+ return Object.keys(views).map(viewId => {
50
+ const { viewport, children: viewChildren } = views[viewId];
51
+ const { x, y, width, height } = viewport;
52
+ const style = {
53
+ position: 'absolute',
54
+ left: x,
55
+ top: y,
56
+ width,
57
+ height
58
+ };
59
+ const key = `view-${viewId}`;
60
+ // If children is passed as an array, React will throw the "each element in a list needs
61
+ // a key" warning. Sending each child as separate arguments removes this requirement.
62
+ const viewElement = createElement('div', { key, id: key, style }, ...viewChildren);
63
+ if (ContextProvider) {
64
+ const contextValue = {
65
+ viewport,
66
+ // @ts-expect-error accessing protected property
67
+ container: deck.canvas.offsetParent,
68
+ // @ts-expect-error accessing protected property
69
+ eventManager: deck.eventManager,
70
+ onViewStateChange: params => {
71
+ params.viewId = viewId;
72
+ // @ts-expect-error accessing protected method
73
+ deck._onViewStateChange(params);
74
+ }
75
+ };
76
+ return createElement(ContextProvider, { key, value: contextValue }, viewElement);
77
+ }
78
+ return viewElement;
79
+ });
80
+ }
@@ -1,4 +1,5 @@
1
+ // From https://github.com/streamich/react-use/blob/master/src/useIsomorphicLayoutEffect.ts
2
+ // useLayoutEffect but does not trigger warning in server-side rendering
1
3
  import { useEffect, useLayoutEffect } from 'react';
2
4
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
3
5
  export default useIsomorphicLayoutEffect;
4
- //# sourceMappingURL=use-isomorphic-layout-effect.js.map
package/package.json CHANGED
@@ -2,7 +2,8 @@
2
2
  "name": "@deck.gl/react",
3
3
  "description": "React Components for deck.gl",
4
4
  "license": "MIT",
5
- "version": "9.0.0-beta.1",
5
+ "type": "module",
6
+ "version": "9.0.0-beta.11",
6
7
  "publishConfig": {
7
8
  "access": "public"
8
9
  },
@@ -16,24 +17,32 @@
16
17
  "type": "git",
17
18
  "url": "https://github.com/visgl/deck.gl.git"
18
19
  },
19
- "main": "dist/es5/index.js",
20
- "module": "dist/esm/index.js",
21
- "types": "typed/index.d.ts",
20
+ "types": "dist/index.d.ts",
21
+ "main": "dist/index.cjs",
22
+ "module": "dist/index.js",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js",
27
+ "require": "./dist/index.cjs"
28
+ }
29
+ },
22
30
  "files": [
23
31
  "dist",
24
- "src",
25
- "typed"
32
+ "src"
26
33
  ],
27
34
  "sideEffects": false,
28
35
  "scripts": {},
29
- "dependencies": {
30
- "@babel/runtime": "^7.0.0"
31
- },
32
36
  "peerDependencies": {
33
- "@deck.gl/core": "^9.0.0-alpha",
34
- "@types/react": ">= 16.3",
35
- "react": ">=16.3",
36
- "react-dom": ">=16.3"
37
+ "@deck.gl/core": "^9.0.0-beta",
38
+ "react": ">=16.3.0",
39
+ "react-dom": ">=16.3.0"
40
+ },
41
+ "devDependencies": {
42
+ "@types/react": "^18.2.0",
43
+ "@types/react-dom": "^18.2.0",
44
+ "react": "^18.2.0",
45
+ "react-dom": "^18.2.0"
37
46
  },
38
- "gitHead": "9628417918bec5cc73c1345bfcd2f2be575741f1"
47
+ "gitHead": "d8a3f5bdb644f85caba9d5c1e74baff8f8a3d439"
39
48
  }
package/src/deckgl.ts CHANGED
@@ -18,15 +18,7 @@
18
18
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  // THE SOFTWARE.
20
20
  import * as React from 'react';
21
- import {
22
- createElement,
23
- useRef,
24
- useState,
25
- useMemo,
26
- useEffect,
27
- useImperativeHandle,
28
- forwardRef
29
- } from 'react';
21
+ import {createElement, useRef, useState, useMemo, useEffect, useImperativeHandle} from 'react';
30
22
  import {Deck} from '@deck.gl/core';
31
23
  import useIsomorphicLayoutEffect from './utils/use-isomorphic-layout-effect';
32
24
 
@@ -35,11 +27,13 @@ import positionChildrenUnderViews from './utils/position-children-under-views';
35
27
  import extractStyles from './utils/extract-styles';
36
28
 
37
29
  import type {DeckGLContextValue} from './utils/position-children-under-views';
38
- import type {DeckProps, Viewport} from '@deck.gl/core';
30
+ import type {DeckProps, View, Viewport} from '@deck.gl/core';
31
+
32
+ export type ViewOrViews = View | View[] | null;
39
33
 
40
34
  /* eslint-disable max-statements, accessor-pairs */
41
- type DeckInstanceRef = {
42
- deck?: Deck;
35
+ type DeckInstanceRef<ViewsT extends ViewOrViews> = {
36
+ deck?: Deck<ViewsT>;
43
37
  redrawReason?: string | null;
44
38
  lastRenderedViewports?: Viewport[];
45
39
  viewStateUpdateRequested?: any;
@@ -51,25 +45,28 @@ type DeckInstanceRef = {
51
45
 
52
46
  // Remove prop types in the base Deck class that support externally supplied canvas/WebGLContext
53
47
  /** DeckGL React component props */
54
- export type DeckGLProps = Omit<
55
- DeckProps,
48
+ export type DeckGLProps<ViewsT extends ViewOrViews = null> = Omit<
49
+ DeckProps<ViewsT>,
56
50
  'width' | 'height' | 'gl' | 'parent' | 'canvas' | '_customRender'
57
51
  > & {
58
52
  Deck?: typeof Deck;
59
53
  width?: string | number;
60
54
  height?: string | number;
61
55
  children?: React.ReactNode | DeckGLRenderCallback;
56
+ ref?: React.Ref<DeckGLRef<ViewsT>>;
62
57
  ContextProvider?: React.Context<DeckGLContextValue>['Provider'];
63
58
  };
64
59
 
65
- export type DeckGLRef = {
66
- deck?: Deck;
60
+ export type DeckGLRef<ViewsT extends ViewOrViews = null> = {
61
+ deck?: Deck<ViewsT>;
67
62
  pickObject: Deck['pickObject'];
68
63
  pickObjects: Deck['pickObjects'];
69
64
  pickMultipleObjects: Deck['pickMultipleObjects'];
70
65
  };
71
66
 
72
- function getRefHandles(thisRef: DeckInstanceRef): DeckGLRef {
67
+ function getRefHandles<ViewsT extends ViewOrViews>(
68
+ thisRef: DeckInstanceRef<ViewsT>
69
+ ): DeckGLRef<ViewsT> {
73
70
  return {
74
71
  get deck() {
75
72
  return thisRef.deck;
@@ -81,7 +78,7 @@ function getRefHandles(thisRef: DeckInstanceRef): DeckGLRef {
81
78
  };
82
79
  }
83
80
 
84
- function redrawDeck(thisRef: DeckInstanceRef) {
81
+ function redrawDeck(thisRef: DeckInstanceRef<any>) {
85
82
  if (thisRef.redrawReason) {
86
83
  // Only redraw if we have received a dirty flag
87
84
  // @ts-expect-error accessing protected method
@@ -90,11 +87,11 @@ function redrawDeck(thisRef: DeckInstanceRef) {
90
87
  }
91
88
  }
92
89
 
93
- function createDeckInstance(
94
- thisRef: DeckInstanceRef,
90
+ function createDeckInstance<ViewsT extends ViewOrViews>(
91
+ thisRef: DeckInstanceRef<ViewsT>,
95
92
  DeckClass: typeof Deck,
96
- props: DeckProps
97
- ): Deck {
93
+ props: DeckProps<ViewsT>
94
+ ): Deck<ViewsT> {
98
95
  const deck = new DeckClass({
99
96
  ...props,
100
97
  // The Deck's animation loop is independent from React's render cycle, causing potential
@@ -120,11 +117,14 @@ function createDeckInstance(
120
117
  return deck;
121
118
  }
122
119
 
123
- const DeckGL = forwardRef<DeckGLRef, DeckGLProps>((props, ref) => {
120
+ function DeckGLWithRef<ViewsT extends ViewOrViews = null>(
121
+ props: DeckGLProps<ViewsT>,
122
+ ref: React.Ref<DeckGLRef<ViewsT>>
123
+ ) {
124
124
  // A mechanism to force redraw
125
125
  const [version, setVersion] = useState(0);
126
126
  // A reference to persistent states
127
- const _thisRef = useRef<DeckInstanceRef>({
127
+ const _thisRef = useRef<DeckInstanceRef<ViewsT>>({
128
128
  control: null,
129
129
  version,
130
130
  forceUpdate: () => setVersion(v => v + 1)
@@ -143,7 +143,7 @@ const DeckGL = forwardRef<DeckGLRef, DeckGLProps>((props, ref) => {
143
143
  // Callbacks
144
144
  let inRender = true;
145
145
 
146
- const handleViewStateChange: DeckProps['onViewStateChange'] = params => {
146
+ const handleViewStateChange: DeckProps<ViewsT>['onViewStateChange'] = params => {
147
147
  if (inRender && props.viewState) {
148
148
  // Callback may invoke a state update. Defer callback to after render() to avoid React error
149
149
  // In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once
@@ -155,7 +155,7 @@ const DeckGL = forwardRef<DeckGLRef, DeckGLProps>((props, ref) => {
155
155
  return props.onViewStateChange?.(params);
156
156
  };
157
157
 
158
- const handleInteractionStateChange: DeckProps['onInteractionStateChange'] = params => {
158
+ const handleInteractionStateChange: DeckProps<ViewsT>['onInteractionStateChange'] = params => {
159
159
  if (inRender) {
160
160
  // Callback may invoke a state update. Defer callback to after render() to avoid React error
161
161
  // In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once
@@ -171,7 +171,7 @@ const DeckGL = forwardRef<DeckGLRef, DeckGLProps>((props, ref) => {
171
171
  // the next animation frame.
172
172
  // Needs to be called both from initial mount, and when new props are received
173
173
  const deckProps = useMemo(() => {
174
- const forwardProps: DeckProps = {
174
+ const forwardProps: DeckProps<ViewsT> = {
175
175
  ...props,
176
176
  // Override user styling props. We will set the canvas style in render()
177
177
  style: null,
@@ -180,7 +180,7 @@ const DeckGL = forwardRef<DeckGLRef, DeckGLProps>((props, ref) => {
180
180
  parent: containerRef.current,
181
181
  canvas: canvasRef.current,
182
182
  layers: jsxProps.layers,
183
- views: jsxProps.views,
183
+ views: jsxProps.views as ViewsT,
184
184
  onViewStateChange: handleViewStateChange,
185
185
  onInteractionStateChange: handleInteractionStateChange
186
186
  };
@@ -229,7 +229,7 @@ const DeckGL = forwardRef<DeckGLRef, DeckGLProps>((props, ref) => {
229
229
  const currentViewports =
230
230
  thisRef.deck && thisRef.deck.isInitialized ? thisRef.deck.getViewports() : undefined;
231
231
 
232
- const {ContextProvider, width, height, id, style} = props;
232
+ const {ContextProvider, width = '100%', height = '100%', id, style} = props;
233
233
 
234
234
  const {containerStyle, canvasStyle} = useMemo(
235
235
  () => extractStyles({width, height, style}),
@@ -274,8 +274,10 @@ const DeckGL = forwardRef<DeckGLRef, DeckGLProps>((props, ref) => {
274
274
 
275
275
  inRender = false;
276
276
  return thisRef.control;
277
- });
277
+ }
278
278
 
279
- DeckGL.defaultProps = Deck.defaultProps;
279
+ const DeckGL = React.forwardRef(DeckGLWithRef) as <ViewsT extends ViewOrViews>(
280
+ props: DeckGLProps<ViewsT>
281
+ ) => React.ReactElement;
280
282
 
281
283
  export default DeckGL;
@@ -4,6 +4,7 @@ import {View} from '@deck.gl/core';
4
4
  import {inheritsFrom} from './inherits-from';
5
5
  import evaluateChildren, {isComponent} from './evaluate-children';
6
6
 
7
+ import type {ViewOrViews} from '../deckgl';
7
8
  import type {Deck, DeckProps, Viewport} from '@deck.gl/core';
8
9
  import type {EventManager} from 'mjolnir.js';
9
10
 
@@ -16,13 +17,13 @@ export type DeckGLContextValue = {
16
17
 
17
18
  // Iterate over views and reposition children associated with views
18
19
  // TODO - Can we supply a similar function for the non-React case?
19
- export default function positionChildrenUnderViews({
20
+ export default function positionChildrenUnderViews<ViewsT extends ViewOrViews>({
20
21
  children,
21
22
  deck,
22
23
  ContextProvider
23
24
  }: {
24
25
  children: React.ReactNode[];
25
- deck?: Deck;
26
+ deck?: Deck<ViewsT>;
26
27
  ContextProvider?: React.Context<DeckGLContextValue>['Provider'];
27
28
  }): React.ReactNode[] {
28
29
  // @ts-expect-error accessing protected property