@deck.gl/react 8.8.0-beta.3 → 8.8.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.
@@ -53,15 +53,11 @@ function redrawDeck(thisRef) {
53
53
  }
54
54
  }
55
55
 
56
- function createDeckInstance(thisRef, props) {
57
- var DeckClass = props.Deck || _core.Deck;
56
+ function createDeckInstance(thisRef, DeckClass, props) {
58
57
  var deck = new DeckClass(_objectSpread(_objectSpread({}, props), {}, {
59
- style: null,
60
- width: '100%',
61
- height: '100%',
62
58
  _customRender: function _customRender(redrawReason) {
63
59
  thisRef.redrawReason = redrawReason;
64
- var viewports = deck.viewManager.getViewports();
60
+ var viewports = deck.getViewports();
65
61
 
66
62
  if (thisRef.lastRenderedViewports !== viewports) {
67
63
  thisRef.forceUpdate();
@@ -125,6 +121,8 @@ var DeckGL = (0, _react.forwardRef)(function (props, ref) {
125
121
  style: null,
126
122
  width: '100%',
127
123
  height: '100%',
124
+ parent: containerRef.current,
125
+ canvas: canvasRef.current,
128
126
  layers: jsxProps.layers,
129
127
  views: jsxProps.views,
130
128
  onViewStateChange: handleViewStateChange,
@@ -139,20 +137,11 @@ var DeckGL = (0, _react.forwardRef)(function (props, ref) {
139
137
 
140
138
  return forwardProps;
141
139
  }, [props]);
142
-
143
- var _useState3 = (0, _react.useState)(false),
144
- _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
145
- isDeckLoaded = _useState4[0],
146
- setIsDeckLoaded = _useState4[1];
147
-
148
140
  (0, _react.useEffect)(function () {
149
- thisRef.deck = createDeckInstance(thisRef, _objectSpread(_objectSpread({}, deckProps), {}, {
141
+ var DeckClass = props.Deck || _core.Deck;
142
+ thisRef.deck = createDeckInstance(thisRef, DeckClass, _objectSpread(_objectSpread({}, deckProps), {}, {
150
143
  parent: containerRef.current,
151
- canvas: canvasRef.current,
152
- onLoad: function onLoad() {
153
- setIsDeckLoaded(true);
154
- if (deckProps.onLoad) deckProps.onLoad();
155
- }
144
+ canvas: canvasRef.current
156
145
  }));
157
146
  return function () {
158
147
  var _thisRef$deck;
@@ -176,7 +165,7 @@ var DeckGL = (0, _react.forwardRef)(function (props, ref) {
176
165
  (0, _react.useImperativeHandle)(ref, function () {
177
166
  return getRefHandles(thisRef);
178
167
  }, []);
179
- var currentViewports = thisRef.deck && isDeckLoaded ? thisRef.deck.getViewports() : undefined;
168
+ var currentViewports = thisRef.deck && thisRef.deck.isInitialized ? thisRef.deck.getViewports() : undefined;
180
169
  var ContextProvider = props.ContextProvider,
181
170
  width = props.width,
182
171
  height = props.height,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/deckgl.ts"],"names":["getRefHandles","thisRef","deck","pickObject","opts","pickMultipleObjects","pickObjects","redrawDeck","redrawReason","_drawLayers","createDeckInstance","props","DeckClass","Deck","style","width","height","_customRender","viewports","viewManager","getViewports","lastRenderedViewports","forceUpdate","DeckGL","ref","version","setVersion","_thisRef","control","v","current","containerRef","canvasRef","jsxProps","layers","views","children","inRender","handleViewStateChange","params","viewState","viewStateUpdateRequested","onViewStateChange","handleInteractionStateChange","interactionStateUpdateRequested","onInteractionStateChange","deckProps","forwardProps","setProps","isDeckLoaded","setIsDeckLoaded","parent","canvas","onLoad","finalize","currentViewports","undefined","ContextProvider","id","containerStyle","canvasStyle","childrenUnderViews","key","defaultProps"],"mappings":";;;;;;;;;;;;;AAoBA;;AASA;;AACA;;AAEA;;AACA;;AACA;;;;;;AAoCA,SAASA,aAAT,CAAuBC,OAAvB,EAA4D;AAC1D,SAAO;AACL,QAAIC,IAAJ,GAAW;AACT,aAAOD,OAAO,CAACC,IAAf;AACD,KAHI;;AAKLC,IAAAA,UAAU,EAAE,oBAAAC,IAAI;AAAA,aAAIH,OAAO,CAACC,IAAR,CAAcC,UAAd,CAAyBC,IAAzB,CAAJ;AAAA,KALX;AAMLC,IAAAA,mBAAmB,EAAE,6BAAAD,IAAI;AAAA,aAAIH,OAAO,CAACC,IAAR,CAAcG,mBAAd,CA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,yCAA2B;AACpDzB,MAAAA,QAAQ,EAAEH,QAAQ,CAACG,QADiC;AAEpDlC,MAAAA,IAAI,EAAED,OAAO,CAACC,IAFsC;AAGpDuD,MAAAA,eAAe,EAAfA;AAHoD,KAA3B,CAA3B;AAMA,QAAML,MAAM,GAAG,0BAAc,QAAd,EAAwB;AACrCU,MAAAA,GAAG,EAAE,QADgC;AAErCJ,MAAAA,EAAE,EAAEA,EAAE,IAAI,gBAF2B;AAGrClC,MAAAA,GAAG,EAAEQ,SAHgC;AAIrClB,MAAAA,KAAK,EAAE8C;AAJ8B,KAAxB,CAAf;AAQA3D,IAAAA,OAAO,CAAC2B,OAAR,GAAkB,0BAChB,KADgB,EAEhB;AAAC8B,MAAAA,EAAE,YAAKA,EAAE,IAAI,QAAX,aAAH;AAAkClC,MAAAA,GAAG,EAAEO,YAAvC;AAAqDjB,MAAAA,KAAK,EAAE6C;AAA5D,KAFgB,EAGhB,CAACP,MAAD,EAASS,kBAAT,CAHgB,CAAlB;AAKD;;AAEDxB,EAAAA,QAAQ,GAAG,KAAX;AACA,SAAOpC,OAAO,CAAC2B,OAAf;AACD,CA3Jc,CAAf;AA6JAL,MAAM,CAACwC,YAAP,GAAsBlD,WAAKkD,YAA3B;eAEexC,M","sourcesContent":["// Copyright (c) 2015 - 2017 Uber Technologies, Inc.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\nimport * as React from 'react';\nimport {\n createElement,\n useRef,\n useState,\n useMemo,\n useEffect,\n useImperativeHandle,\n forwardRef\n} from 'react';\nimport {Deck} from '@deck.gl/core';\nimport useIsomorphicLayoutEffect from './utils/use-isomorphic-layout-effect';\n\nimport extractJSXLayers from './utils/extract-jsx-layers';\nimport positionChildrenUnderViews from './utils/position-children-under-views';\nimport extractStyles from './utils/extract-styles';\n\nimport type {DeckGLContextValue} from './utils/position-children-under-views';\nimport type {DeckProps, Viewport} from '@deck.gl/core';\n\n/* eslint-disable max-statements, accessor-pairs */\ntype DeckInstanceRef = {\n deck?: Deck;\n redrawReason?: string | null;\n lastRenderedViewports?: Viewport[];\n viewStateUpdateRequested?: any;\n interactionStateUpdateRequested?: any;\n forceUpdate: () => void;\n version: number;\n control: React.ReactHTMLElement<HTMLElement> | null;\n};\n\n// Remove prop types in the base Deck class that support externally supplied canvas/WebGLContext\n/** DeckGL React component props */\nexport type DeckGLProps = Omit<\n DeckProps,\n 'width' | 'height' | 'gl' | 'parent' | 'canvas' | '_customRender'\n> & {\n width?: string | number;\n height?: string | number;\n children?: React.ReactNode;\n ContextProvider?: React.Context<DeckGLContextValue>['Provider'];\n};\n\nexport type DeckGLRef = {\n deck?: Deck;\n pickObject: Deck['pickObject'];\n pickObjects: Deck['pickObjects'];\n pickMultipleObjects: Deck['pickMultipleObjects'];\n};\n\nfunction getRefHandles(thisRef: DeckInstanceRef): DeckGLRef {\n return {\n get deck() {\n return thisRef.deck;\n },\n // The following method can only be called after ref is available, by which point deck is defined in useEffect\n pickObject: opts => thisRef.deck!.pickObject(opts),\n pickMultipleObjects: opts => thisRef.deck!.pickMultipleObjects(opts),\n pickObjects: opts => thisRef.deck!.pickObjects(opts)\n };\n}\n\nfunction redrawDeck(thisRef: DeckInstanceRef) {\n if (thisRef.redrawReason) {\n // Only redraw if we have received a dirty flag\n // @ts-expect-error accessing protected method\n thisRef.deck._drawLayers(thisRef.redrawReason);\n thisRef.redrawReason = null;\n }\n}\n\nfunction createDeckInstance(thisRef: DeckInstanceRef, props): Deck {\n // Allows a subclass of Deck to be used\n // TODO - update propTypes / defaultProps?\n const DeckClass = props.Deck || Deck;\n const deck = new DeckClass({\n ...props,\n style: null,\n width: '100%',\n height: '100%',\n // The Deck's animation loop is independent from React's render cycle, causing potential\n // synchronization issues. We provide this custom render function to make sure that React\n // and Deck update on the same schedule.\n _customRender: redrawReason => {\n // Save the dirty flag for later\n thisRef.redrawReason = redrawReason;\n\n // Viewport/view state is passed to child components as props.\n // If they have changed, we need to trigger a React rerender to update children props.\n const viewports = deck.viewManager.getViewports();\n if (thisRef.lastRenderedViewports !== viewports) {\n // Viewports have changed, update children props first.\n // This will delay the Deck canvas redraw till after React update (in useLayoutEffect)\n // so that the canvas does not get rendered before the child components update.\n thisRef.forceUpdate();\n } else {\n redrawDeck(thisRef);\n }\n }\n });\n return deck;\n}\n\nconst DeckGL = forwardRef<DeckGLRef, DeckGLProps>((props, ref) => {\n // A mechanism to force redraw\n const [version, setVersion] = useState(0);\n // A reference to persistent states\n const _thisRef = useRef<DeckInstanceRef>({\n control: null,\n version,\n forceUpdate: () => setVersion(v => v + 1)\n });\n const thisRef = _thisRef.current;\n // DOM refs\n const containerRef = useRef(null);\n const canvasRef = useRef(null);\n\n // extract any deck.gl layers masquerading as react elements from props.children\n const jsxProps = useMemo(\n () => extractJSXLayers(props),\n [props.layers, props.views, props.children]\n );\n\n // Callbacks\n let inRender = true;\n\n const handleViewStateChange: DeckProps['onViewStateChange'] = params => {\n if (inRender && props.viewState) {\n // Callback may invoke a state update. Defer callback to after render() to avoid React error\n // In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once\n // Store deferred parameters in ref so that we can access it in another render\n thisRef.viewStateUpdateRequested = params;\n return null;\n }\n thisRef.viewStateUpdateRequested = null;\n return props.onViewStateChange?.(params);\n };\n\n const handleInteractionStateChange: DeckProps['onInteractionStateChange'] = params => {\n if (inRender) {\n // Callback may invoke a state update. Defer callback to after render() to avoid React error\n // In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once\n // Store deferred parameters in ref so that we can access it in another render\n thisRef.interactionStateUpdateRequested = params;\n } else {\n thisRef.interactionStateUpdateRequested = null;\n props.onInteractionStateChange?.(params);\n }\n };\n\n // Update Deck's props. If Deck needs redraw, this will trigger a call to `_customRender` in\n // the next animation frame.\n // Needs to be called both from initial mount, and when new props are received\n const deckProps = useMemo(() => {\n const forwardProps: DeckProps = {\n ...props,\n // Override user styling props. We will set the canvas style in render()\n style: null,\n width: '100%',\n height: '100%',\n layers: jsxProps.layers,\n views: jsxProps.views,\n onViewStateChange: handleViewStateChange,\n onInteractionStateChange: handleInteractionStateChange\n };\n\n // The defaultValue for _customRender is null, which would overwrite the definition\n // of _customRender. Remove to avoid frequently redeclaring the method here.\n delete forwardProps._customRender;\n\n if (thisRef.deck) {\n thisRef.deck.setProps(forwardProps);\n }\n\n return forwardProps;\n }, [props]);\n\n const [isDeckLoaded, setIsDeckLoaded] = useState(false);\n\n useEffect(() => {\n thisRef.deck = createDeckInstance(thisRef, {\n ...deckProps,\n parent: containerRef.current,\n canvas: canvasRef.current,\n onLoad: () => {\n setIsDeckLoaded(true);\n if (deckProps.onLoad) deckProps.onLoad();\n }\n });\n\n return () => thisRef.deck?.finalize();\n }, []);\n\n useIsomorphicLayoutEffect(() => {\n // render has just been called. The children are positioned based on the current view state.\n // Redraw Deck canvas immediately, if necessary, using the current view state, so that it\n // matches the child components.\n redrawDeck(thisRef);\n\n // Execute deferred callbacks\n const {viewStateUpdateRequested, interactionStateUpdateRequested} = thisRef;\n if (viewStateUpdateRequested) {\n handleViewStateChange(viewStateUpdateRequested);\n }\n if (interactionStateUpdateRequested) {\n handleInteractionStateChange(interactionStateUpdateRequested);\n }\n });\n\n useImperativeHandle(ref, () => getRefHandles(thisRef), []);\n\n const currentViewports = thisRef.deck && isDeckLoaded ? thisRef.deck.getViewports() : undefined;\n\n const {ContextProvider, width, height, id, style} = props;\n\n const {containerStyle, canvasStyle} = useMemo(\n () => extractStyles({width, height, style}),\n [width, height, style]\n );\n\n // Props changes may lead to 3 types of updates:\n // 1. Only the WebGL canvas - updated in Deck's render cycle (next animation frame)\n // 2. Only the DOM - updated in React's lifecycle (now)\n // 3. Both the WebGL canvas and the DOM - defer React rerender to next animation frame just\n // before Deck redraw to ensure perfect synchronization & avoid excessive redraw\n // This is because multiple changes may happen to Deck between two frames e.g. transition\n if (\n (!thisRef.viewStateUpdateRequested && thisRef.lastRenderedViewports === currentViewports) || // case 2\n thisRef.version !== version // case 3 just before deck redraws\n ) {\n thisRef.lastRenderedViewports = currentViewports;\n thisRef.version = version;\n\n // Render the background elements (typically react-map-gl instances)\n // using the view descriptors\n const childrenUnderViews = positionChildrenUnderViews({\n children: jsxProps.children,\n deck: thisRef.deck,\n ContextProvider\n });\n\n const canvas = createElement('canvas', {\n key: 'canvas',\n id: id || 'deckgl-overlay',\n ref: canvasRef,\n style: canvasStyle\n });\n\n // Render deck.gl as the last child\n thisRef.control = createElement(\n 'div',\n {id: `${id || 'deckgl'}-wrapper`, ref: containerRef, style: containerStyle},\n [canvas, childrenUnderViews]\n );\n }\n\n inRender = false;\n return thisRef.control;\n});\n\nDeckGL.defaultProps = Deck.defaultProps;\n\nexport default DeckGL;\n"],"file":"deckgl.js"}
1
+ {"version":3,"sources":["../../src/deckgl.ts"],"names":["getRefHandles","thisRef","deck","pickObject","opts","pickMultipleObjects","pickObjects","redrawDeck","redrawReason","_drawLayers","createDeckInstance","DeckClass","props","_customRender","viewports","getViewports","lastRenderedViewports","forceUpdate","DeckGL","ref","version","setVersion","_thisRef","control","v","current","containerRef","canvasRef","jsxProps","layers","views","children","inRender","handleViewStateChange","params","viewState","viewStateUpdateRequested","onViewStateChange","handleInteractionStateChange","interactionStateUpdateRequested","onInteractionStateChange","deckProps","forwardProps","style","width","height","parent","canvas","setProps","Deck","finalize","currentViewports","isInitialized","undefined","ContextProvider","id","containerStyle","canvasStyle","childrenUnderViews","key","defaultProps"],"mappings":";;;;;;;;;;;;;AAoBA;;AASA;;AACA;;AAEA;;AACA;;AACA;;;;;;AAqCA,SAASA,aAAT,CAAuBC,OAAvB,EAA4D;AAC1D,SAAO;AACL,QAAIC,IAAJ,GAAW;AACT,aAAOD,OAAO,CAACC,IAAf;AACD,KAHI;;AAKLC,IAAAA,UAAU,EAAE,oBAAAC,IAAI;AAAA,aAAIH,OAAO,CAACC,IAAR,CAAcC,UAAd,CAAyBC,IAAzB,CAAJ;AAAA,KALX;AAMLC,IAAAA,mBAAmB,EAAE,6BAAAD,IAAI;AAAA,aAAIH,OAAO,CAACC,IAAR,CAAcG,mBAAd,CAAkCD,IAAlC,CAAJ;AAAA,KANpB;AAOLE,IAAAA,WAAW,EAAE,qBAAAF,IAAI;AAAA,aAAIH,OAAO,CAACC,IAAR,CAAcI,WAAd,CAA0BF,IAA1B,CAAJ;AAAA;AAPZ,GAAP;AASD;;AAED,SAASG,UAAT,CAAoBN,OAApB,EAA8C;AAC5C,MAAIA,OAAO,CAACO,YAAZ,EAA0B;AAGxBP,IAAAA,OAAO,CAACC,IAAR,CAAaO,WAAb,CAAyBR,OAAO,CAACO,YAAjC;;AACAP,IAAAA,OAAO,CAACO,YAAR,GAAuB,IAAvB;AACD;AACF;;AAED,SAASE,kBAAT,CACET,OADF,EAEEU,SAFF,EAGEC,KAHF,EAIQ;AACN,MAAMV,IAAI,GAAG,IAAIS,SAAJ,iCACRC,KADQ;AAKXC,IAAAA,aAAa,EAAE,uBAAAL,YAAY,EAAI;AAE7BP,MAAAA,OAAO,CAACO,YAAR,GAAuBA,YAAvB;AAIA,UAAMM,SAAS,GAAGZ,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\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\nimport * as React from 'react';\nimport {\n createElement,\n useRef,\n useState,\n useMemo,\n useEffect,\n useImperativeHandle,\n forwardRef\n} from 'react';\nimport {Deck} from '@deck.gl/core';\nimport useIsomorphicLayoutEffect from './utils/use-isomorphic-layout-effect';\n\nimport extractJSXLayers from './utils/extract-jsx-layers';\nimport positionChildrenUnderViews from './utils/position-children-under-views';\nimport extractStyles from './utils/extract-styles';\n\nimport type {DeckGLContextValue} from './utils/position-children-under-views';\nimport type {DeckProps, Viewport} from '@deck.gl/core';\n\n/* eslint-disable max-statements, accessor-pairs */\ntype DeckInstanceRef = {\n deck?: Deck;\n redrawReason?: string | null;\n lastRenderedViewports?: Viewport[];\n viewStateUpdateRequested?: any;\n interactionStateUpdateRequested?: any;\n forceUpdate: () => void;\n version: number;\n control: React.ReactHTMLElement<HTMLElement> | null;\n};\n\n// Remove prop types in the base Deck class that support externally supplied canvas/WebGLContext\n/** DeckGL React component props */\nexport type DeckGLProps = Omit<\n DeckProps,\n 'width' | 'height' | 'gl' | 'parent' | 'canvas' | '_customRender'\n> & {\n Deck?: typeof Deck;\n width?: string | number;\n height?: string | number;\n children?: React.ReactNode;\n ContextProvider?: React.Context<DeckGLContextValue>['Provider'];\n};\n\nexport type DeckGLRef = {\n deck?: Deck;\n pickObject: Deck['pickObject'];\n pickObjects: Deck['pickObjects'];\n pickMultipleObjects: Deck['pickMultipleObjects'];\n};\n\nfunction getRefHandles(thisRef: DeckInstanceRef): DeckGLRef {\n return {\n get deck() {\n return thisRef.deck;\n },\n // The following method can only be called after ref is available, by which point deck is defined in useEffect\n pickObject: opts => thisRef.deck!.pickObject(opts),\n pickMultipleObjects: opts => thisRef.deck!.pickMultipleObjects(opts),\n pickObjects: opts => thisRef.deck!.pickObjects(opts)\n };\n}\n\nfunction redrawDeck(thisRef: DeckInstanceRef) {\n if (thisRef.redrawReason) {\n // Only redraw if we have received a dirty flag\n // @ts-expect-error accessing protected method\n thisRef.deck._drawLayers(thisRef.redrawReason);\n thisRef.redrawReason = null;\n }\n}\n\nfunction createDeckInstance(\n thisRef: DeckInstanceRef,\n DeckClass: typeof Deck,\n props: DeckProps\n): Deck {\n const deck = new DeckClass({\n ...props,\n // The Deck's animation loop is independent from React's render cycle, causing potential\n // synchronization issues. We provide this custom render function to make sure that React\n // and Deck update on the same schedule.\n _customRender: redrawReason => {\n // Save the dirty flag for later\n thisRef.redrawReason = redrawReason;\n\n // Viewport/view state is passed to child components as props.\n // If they have changed, we need to trigger a React rerender to update children props.\n const viewports = deck.getViewports();\n if (thisRef.lastRenderedViewports !== viewports) {\n // Viewports have changed, update children props first.\n // This will delay the Deck canvas redraw till after React update (in useLayoutEffect)\n // so that the canvas does not get rendered before the child components update.\n thisRef.forceUpdate();\n } else {\n redrawDeck(thisRef);\n }\n }\n });\n return deck;\n}\n\nconst DeckGL = forwardRef<DeckGLRef, DeckGLProps>((props, ref) => {\n // A mechanism to force redraw\n const [version, setVersion] = useState(0);\n // A reference to persistent states\n const _thisRef = useRef<DeckInstanceRef>({\n control: null,\n version,\n forceUpdate: () => setVersion(v => v + 1)\n });\n const thisRef = _thisRef.current;\n // DOM refs\n const containerRef = useRef(null);\n const canvasRef = useRef(null);\n\n // extract any deck.gl layers masquerading as react elements from props.children\n const jsxProps = useMemo(\n () => extractJSXLayers(props),\n [props.layers, props.views, props.children]\n );\n\n // Callbacks\n let inRender = true;\n\n const handleViewStateChange: DeckProps['onViewStateChange'] = params => {\n if (inRender && props.viewState) {\n // Callback may invoke a state update. Defer callback to after render() to avoid React error\n // In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once\n // Store deferred parameters in ref so that we can access it in another render\n thisRef.viewStateUpdateRequested = params;\n return null;\n }\n thisRef.viewStateUpdateRequested = null;\n return props.onViewStateChange?.(params);\n };\n\n const handleInteractionStateChange: DeckProps['onInteractionStateChange'] = params => {\n if (inRender) {\n // Callback may invoke a state update. Defer callback to after render() to avoid React error\n // In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once\n // Store deferred parameters in ref so that we can access it in another render\n thisRef.interactionStateUpdateRequested = params;\n } else {\n thisRef.interactionStateUpdateRequested = null;\n props.onInteractionStateChange?.(params);\n }\n };\n\n // Update Deck's props. If Deck needs redraw, this will trigger a call to `_customRender` in\n // the next animation frame.\n // Needs to be called both from initial mount, and when new props are received\n const deckProps = useMemo(() => {\n const forwardProps: DeckProps = {\n ...props,\n // Override user styling props. We will set the canvas style in render()\n style: null,\n width: '100%',\n height: '100%',\n parent: containerRef.current,\n canvas: canvasRef.current,\n layers: jsxProps.layers,\n views: jsxProps.views,\n onViewStateChange: handleViewStateChange,\n onInteractionStateChange: handleInteractionStateChange\n };\n\n // The defaultValue for _customRender is null, which would overwrite the definition\n // of _customRender. Remove to avoid frequently redeclaring the method here.\n delete forwardProps._customRender;\n\n if (thisRef.deck) {\n thisRef.deck.setProps(forwardProps);\n }\n\n return forwardProps;\n }, [props]);\n\n useEffect(() => {\n const DeckClass = props.Deck || Deck;\n\n thisRef.deck = createDeckInstance(thisRef, DeckClass, {\n ...deckProps,\n parent: containerRef.current,\n canvas: canvasRef.current\n });\n\n return () => thisRef.deck?.finalize();\n }, []);\n\n useIsomorphicLayoutEffect(() => {\n // render has just been called. The children are positioned based on the current view state.\n // Redraw Deck canvas immediately, if necessary, using the current view state, so that it\n // matches the child components.\n redrawDeck(thisRef);\n\n // Execute deferred callbacks\n const {viewStateUpdateRequested, interactionStateUpdateRequested} = thisRef;\n if (viewStateUpdateRequested) {\n handleViewStateChange(viewStateUpdateRequested);\n }\n if (interactionStateUpdateRequested) {\n handleInteractionStateChange(interactionStateUpdateRequested);\n }\n });\n\n useImperativeHandle(ref, () => getRefHandles(thisRef), []);\n\n const currentViewports =\n thisRef.deck && thisRef.deck.isInitialized ? thisRef.deck.getViewports() : undefined;\n\n const {ContextProvider, width, height, id, style} = props;\n\n const {containerStyle, canvasStyle} = useMemo(\n () => extractStyles({width, height, style}),\n [width, height, style]\n );\n\n // Props changes may lead to 3 types of updates:\n // 1. Only the WebGL canvas - updated in Deck's render cycle (next animation frame)\n // 2. Only the DOM - updated in React's lifecycle (now)\n // 3. Both the WebGL canvas and the DOM - defer React rerender to next animation frame just\n // before Deck redraw to ensure perfect synchronization & avoid excessive redraw\n // This is because multiple changes may happen to Deck between two frames e.g. transition\n if (\n (!thisRef.viewStateUpdateRequested && thisRef.lastRenderedViewports === currentViewports) || // case 2\n thisRef.version !== version // case 3 just before deck redraws\n ) {\n thisRef.lastRenderedViewports = currentViewports;\n thisRef.version = version;\n\n // Render the background elements (typically react-map-gl instances)\n // using the view descriptors\n const childrenUnderViews = positionChildrenUnderViews({\n children: jsxProps.children,\n deck: thisRef.deck,\n ContextProvider\n });\n\n const canvas = createElement('canvas', {\n key: 'canvas',\n id: id || 'deckgl-overlay',\n ref: canvasRef,\n style: canvasStyle\n });\n\n // Render deck.gl as the last child\n thisRef.control = createElement(\n 'div',\n {id: `${id || 'deckgl'}-wrapper`, ref: containerRef, style: containerStyle},\n [canvas, childrenUnderViews]\n );\n }\n\n inRender = false;\n return thisRef.control;\n});\n\nDeckGL.defaultProps = Deck.defaultProps;\n\nexport default DeckGL;\n"],"file":"deckgl.js"}
@@ -25,15 +25,11 @@ function redrawDeck(thisRef) {
25
25
  }
26
26
  }
27
27
 
28
- function createDeckInstance(thisRef, props) {
29
- const DeckClass = props.Deck || Deck;
28
+ function createDeckInstance(thisRef, DeckClass, props) {
30
29
  const deck = new DeckClass({ ...props,
31
- style: null,
32
- width: '100%',
33
- height: '100%',
34
30
  _customRender: redrawReason => {
35
31
  thisRef.redrawReason = redrawReason;
36
- const viewports = deck.viewManager.getViewports();
32
+ const viewports = deck.getViewports();
37
33
 
38
34
  if (thisRef.lastRenderedViewports !== viewports) {
39
35
  thisRef.forceUpdate();
@@ -88,6 +84,8 @@ const DeckGL = forwardRef((props, ref) => {
88
84
  style: null,
89
85
  width: '100%',
90
86
  height: '100%',
87
+ parent: containerRef.current,
88
+ canvas: canvasRef.current,
91
89
  layers: jsxProps.layers,
92
90
  views: jsxProps.views,
93
91
  onViewStateChange: handleViewStateChange,
@@ -101,15 +99,11 @@ const DeckGL = forwardRef((props, ref) => {
101
99
 
102
100
  return forwardProps;
103
101
  }, [props]);
104
- const [isDeckLoaded, setIsDeckLoaded] = useState(false);
105
102
  useEffect(() => {
106
- thisRef.deck = createDeckInstance(thisRef, { ...deckProps,
103
+ const DeckClass = props.Deck || Deck;
104
+ thisRef.deck = createDeckInstance(thisRef, DeckClass, { ...deckProps,
107
105
  parent: containerRef.current,
108
- canvas: canvasRef.current,
109
- onLoad: () => {
110
- setIsDeckLoaded(true);
111
- if (deckProps.onLoad) deckProps.onLoad();
112
- }
106
+ canvas: canvasRef.current
113
107
  });
114
108
  return () => {
115
109
  var _thisRef$deck;
@@ -133,7 +127,7 @@ const DeckGL = forwardRef((props, ref) => {
133
127
  }
134
128
  });
135
129
  useImperativeHandle(ref, () => getRefHandles(thisRef), []);
136
- const currentViewports = thisRef.deck && isDeckLoaded ? thisRef.deck.getViewports() : undefined;
130
+ const currentViewports = thisRef.deck && thisRef.deck.isInitialized ? thisRef.deck.getViewports() : undefined;
137
131
  const {
138
132
  ContextProvider,
139
133
  width,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/deckgl.ts"],"names":["createElement","useRef","useState","useMemo","useEffect","useImperativeHandle","forwardRef","Deck","useIsomorphicLayoutEffect","extractJSXLayers","positionChildrenUnderViews","extractStyles","getRefHandles","thisRef","deck","pickObject","opts","pickMultipleObjects","pickObjects","redrawDeck","redrawReason","_drawLayers","createDeckInstance","props","DeckClass","style","width","height","_customRender","viewports","viewManager","getViewports","lastRenderedViewports","forceUpdate","DeckGL","ref","version","setVersion","_thisRef","control","v","current","containerRef","canvasRef","jsxProps","layers","views","children","inRender","handleViewStateChange","params","viewState","viewStateUpdateRequested","onViewStateChange","handleInteractionStateChange","interactionStateUpdateRequested","onInteractionStateChange","deckProps","forwardProps","setProps","isDeckLoaded","setIsDeckLoaded","parent","canvas","onLoad","finalize","currentViewports","undefined","ContextProvider","id","containerStyle","canvasStyle","childrenUnderViews","key","defaultProps"],"mappings":"AAoBA,SACEA,aADF,EAEEC,MAFF,EAGEC,QAHF,EAIEC,OAJF,EAKEC,SALF,EAMEC,mBANF,EAOEC,UAPF,QAQO,OARP;AASA,SAAQC,IAAR,QAAmB,eAAnB;AACA,OAAOC,yBAAP,MAAsC,sCAAtC;AAEA,OAAOC,gBAAP,MAA6B,4BAA7B;AACA,OAAOC,0BAAP,MAAuC,uCAAvC;AACA,OAAOC,aAAP,MAA0B,wBAA1B;;AAoCA,SAASC,aAAT,CAAuBC,OAAvB,EAA4D;AAC1D,SAAO;AACL,QAAIC,IAAJ,GAAW;AACT,aAAOD,OAAO,CAACC,IAAf;AACD,KAHI;;AAKLC,IAAAA,UAAU,EAAEC,IAAI,IAAIH,OAAO,CAACC,IAAR,CAAcC,UAAd,CAAyBC,IAAzB,CALf;AAMLC,IAAAA,mBAAmB,EAAED,IAAI,IAAIH,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AG,EAAE,QADgC;AAErCJ,MAAAA,EAAE,EAAEA,EAAE,IAAI,gBAF2B;AAGrClC,MAAAA,GAAG,EAAEQ,SAHgC;AAIrClB,MAAAA,KAAK,EAAE8C;AAJ8B,KAAX,CAA5B;AAQA1D,IAAAA,OAAO,CAAC0B,OAAR,GAAkBvC,aAAa,CAC7B,KAD6B,EAE7B;AAACqE,MAAAA,EAAE,YAAKA,EAAE,IAAI,QAAX,aAAH;AAAkClC,MAAAA,GAAG,EAAEO,YAAvC;AAAqDjB,MAAAA,KAAK,EAAE6C;AAA5D,KAF6B,EAG7B,CAACP,MAAD,EAASS,kBAAT,CAH6B,CAA/B;AAKD;;AAEDxB,EAAAA,QAAQ,GAAG,KAAX;AACA,SAAOnC,OAAO,CAAC0B,OAAf;AACD,CA3JwB,CAAzB;AA6JAL,MAAM,CAACwC,YAAP,GAAsBnE,IAAI,CAACmE,YAA3B;AAEA,eAAexC,MAAf","sourcesContent":["// Copyright (c) 2015 - 2017 Uber Technologies, Inc.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\nimport * as React from 'react';\nimport {\n createElement,\n useRef,\n useState,\n useMemo,\n useEffect,\n useImperativeHandle,\n forwardRef\n} from 'react';\nimport {Deck} from '@deck.gl/core';\nimport useIsomorphicLayoutEffect from './utils/use-isomorphic-layout-effect';\n\nimport extractJSXLayers from './utils/extract-jsx-layers';\nimport positionChildrenUnderViews from './utils/position-children-under-views';\nimport extractStyles from './utils/extract-styles';\n\nimport type {DeckGLContextValue} from './utils/position-children-under-views';\nimport type {DeckProps, Viewport} from '@deck.gl/core';\n\n/* eslint-disable max-statements, accessor-pairs */\ntype DeckInstanceRef = {\n deck?: Deck;\n redrawReason?: string | null;\n lastRenderedViewports?: Viewport[];\n viewStateUpdateRequested?: any;\n interactionStateUpdateRequested?: any;\n forceUpdate: () => void;\n version: number;\n control: React.ReactHTMLElement<HTMLElement> | null;\n};\n\n// Remove prop types in the base Deck class that support externally supplied canvas/WebGLContext\n/** DeckGL React component props */\nexport type DeckGLProps = Omit<\n DeckProps,\n 'width' | 'height' | 'gl' | 'parent' | 'canvas' | '_customRender'\n> & {\n width?: string | number;\n height?: string | number;\n children?: React.ReactNode;\n ContextProvider?: React.Context<DeckGLContextValue>['Provider'];\n};\n\nexport type DeckGLRef = {\n deck?: Deck;\n pickObject: Deck['pickObject'];\n pickObjects: Deck['pickObjects'];\n pickMultipleObjects: Deck['pickMultipleObjects'];\n};\n\nfunction getRefHandles(thisRef: DeckInstanceRef): DeckGLRef {\n return {\n get deck() {\n return thisRef.deck;\n },\n // The following method can only be called after ref is available, by which point deck is defined in useEffect\n pickObject: opts => thisRef.deck!.pickObject(opts),\n pickMultipleObjects: opts => thisRef.deck!.pickMultipleObjects(opts),\n pickObjects: opts => thisRef.deck!.pickObjects(opts)\n };\n}\n\nfunction redrawDeck(thisRef: DeckInstanceRef) {\n if (thisRef.redrawReason) {\n // Only redraw if we have received a dirty flag\n // @ts-expect-error accessing protected method\n thisRef.deck._drawLayers(thisRef.redrawReason);\n thisRef.redrawReason = null;\n }\n}\n\nfunction createDeckInstance(thisRef: DeckInstanceRef, props): Deck {\n // Allows a subclass of Deck to be used\n // TODO - update propTypes / defaultProps?\n const DeckClass = props.Deck || Deck;\n const deck = new DeckClass({\n ...props,\n style: null,\n width: '100%',\n height: '100%',\n // The Deck's animation loop is independent from React's render cycle, causing potential\n // synchronization issues. We provide this custom render function to make sure that React\n // and Deck update on the same schedule.\n _customRender: redrawReason => {\n // Save the dirty flag for later\n thisRef.redrawReason = redrawReason;\n\n // Viewport/view state is passed to child components as props.\n // If they have changed, we need to trigger a React rerender to update children props.\n const viewports = deck.viewManager.getViewports();\n if (thisRef.lastRenderedViewports !== viewports) {\n // Viewports have changed, update children props first.\n // This will delay the Deck canvas redraw till after React update (in useLayoutEffect)\n // so that the canvas does not get rendered before the child components update.\n thisRef.forceUpdate();\n } else {\n redrawDeck(thisRef);\n }\n }\n });\n return deck;\n}\n\nconst DeckGL = forwardRef<DeckGLRef, DeckGLProps>((props, ref) => {\n // A mechanism to force redraw\n const [version, setVersion] = useState(0);\n // A reference to persistent states\n const _thisRef = useRef<DeckInstanceRef>({\n control: null,\n version,\n forceUpdate: () => setVersion(v => v + 1)\n });\n const thisRef = _thisRef.current;\n // DOM refs\n const containerRef = useRef(null);\n const canvasRef = useRef(null);\n\n // extract any deck.gl layers masquerading as react elements from props.children\n const jsxProps = useMemo(\n () => extractJSXLayers(props),\n [props.layers, props.views, props.children]\n );\n\n // Callbacks\n let inRender = true;\n\n const handleViewStateChange: DeckProps['onViewStateChange'] = params => {\n if (inRender && props.viewState) {\n // Callback may invoke a state update. Defer callback to after render() to avoid React error\n // In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once\n // Store deferred parameters in ref so that we can access it in another render\n thisRef.viewStateUpdateRequested = params;\n return null;\n }\n thisRef.viewStateUpdateRequested = null;\n return props.onViewStateChange?.(params);\n };\n\n const handleInteractionStateChange: DeckProps['onInteractionStateChange'] = params => {\n if (inRender) {\n // Callback may invoke a state update. Defer callback to after render() to avoid React error\n // In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once\n // Store deferred parameters in ref so that we can access it in another render\n thisRef.interactionStateUpdateRequested = params;\n } else {\n thisRef.interactionStateUpdateRequested = null;\n props.onInteractionStateChange?.(params);\n }\n };\n\n // Update Deck's props. If Deck needs redraw, this will trigger a call to `_customRender` in\n // the next animation frame.\n // Needs to be called both from initial mount, and when new props are received\n const deckProps = useMemo(() => {\n const forwardProps: DeckProps = {\n ...props,\n // Override user styling props. We will set the canvas style in render()\n style: null,\n width: '100%',\n height: '100%',\n layers: jsxProps.layers,\n views: jsxProps.views,\n onViewStateChange: handleViewStateChange,\n onInteractionStateChange: handleInteractionStateChange\n };\n\n // The defaultValue for _customRender is null, which would overwrite the definition\n // of _customRender. Remove to avoid frequently redeclaring the method here.\n delete forwardProps._customRender;\n\n if (thisRef.deck) {\n thisRef.deck.setProps(forwardProps);\n }\n\n return forwardProps;\n }, [props]);\n\n const [isDeckLoaded, setIsDeckLoaded] = useState(false);\n\n useEffect(() => {\n thisRef.deck = createDeckInstance(thisRef, {\n ...deckProps,\n parent: containerRef.current,\n canvas: canvasRef.current,\n onLoad: () => {\n setIsDeckLoaded(true);\n if (deckProps.onLoad) deckProps.onLoad();\n }\n });\n\n return () => thisRef.deck?.finalize();\n }, []);\n\n useIsomorphicLayoutEffect(() => {\n // render has just been called. The children are positioned based on the current view state.\n // Redraw Deck canvas immediately, if necessary, using the current view state, so that it\n // matches the child components.\n redrawDeck(thisRef);\n\n // Execute deferred callbacks\n const {viewStateUpdateRequested, interactionStateUpdateRequested} = thisRef;\n if (viewStateUpdateRequested) {\n handleViewStateChange(viewStateUpdateRequested);\n }\n if (interactionStateUpdateRequested) {\n handleInteractionStateChange(interactionStateUpdateRequested);\n }\n });\n\n useImperativeHandle(ref, () => getRefHandles(thisRef), []);\n\n const currentViewports = thisRef.deck && isDeckLoaded ? thisRef.deck.getViewports() : undefined;\n\n const {ContextProvider, width, height, id, style} = props;\n\n const {containerStyle, canvasStyle} = useMemo(\n () => extractStyles({width, height, style}),\n [width, height, style]\n );\n\n // Props changes may lead to 3 types of updates:\n // 1. Only the WebGL canvas - updated in Deck's render cycle (next animation frame)\n // 2. Only the DOM - updated in React's lifecycle (now)\n // 3. Both the WebGL canvas and the DOM - defer React rerender to next animation frame just\n // before Deck redraw to ensure perfect synchronization & avoid excessive redraw\n // This is because multiple changes may happen to Deck between two frames e.g. transition\n if (\n (!thisRef.viewStateUpdateRequested && thisRef.lastRenderedViewports === currentViewports) || // case 2\n thisRef.version !== version // case 3 just before deck redraws\n ) {\n thisRef.lastRenderedViewports = currentViewports;\n thisRef.version = version;\n\n // Render the background elements (typically react-map-gl instances)\n // using the view descriptors\n const childrenUnderViews = positionChildrenUnderViews({\n children: jsxProps.children,\n deck: thisRef.deck,\n ContextProvider\n });\n\n const canvas = createElement('canvas', {\n key: 'canvas',\n id: id || 'deckgl-overlay',\n ref: canvasRef,\n style: canvasStyle\n });\n\n // Render deck.gl as the last child\n thisRef.control = createElement(\n 'div',\n {id: `${id || 'deckgl'}-wrapper`, ref: containerRef, style: containerStyle},\n [canvas, childrenUnderViews]\n );\n }\n\n inRender = false;\n return thisRef.control;\n});\n\nDeckGL.defaultProps = Deck.defaultProps;\n\nexport default DeckGL;\n"],"file":"deckgl.js"}
1
+ {"version":3,"sources":["../../src/deckgl.ts"],"names":["createElement","useRef","useState","useMemo","useEffect","useImperativeHandle","forwardRef","Deck","useIsomorphicLayoutEffect","extractJSXLayers","positionChildrenUnderViews","extractStyles","getRefHandles","thisRef","deck","pickObject","opts","pickMultipleObjects","pickObjects","redrawDeck","redrawReason","_drawLayers","createDeckInstance","DeckClass","props","_customRender","viewports","getViewports","lastRenderedViewports","forceUpdate","DeckGL","ref","version","setVersion","_thisRef","control","v","current","containerRef","canvasRef","jsxProps","layers","views","children","inRender","handleViewStateChange","params","viewState","viewStateUpdateRequested","onViewStateChange","handleInteractionStateChange","interactionStateUpdateRequested","onInteractionStateChange","deckProps","forwardProps","style","width","height","parent","canvas","setProps","finalize","currentViewports","isInitialized","undefined","ContextProvider","id","containerStyle","canvasStyle","childrenUnderViews","key","defaultProps"],"mappings":"AAoBA,SACEA,aADF,EAEEC,MAFF,EAGEC,QAHF,EAIEC,OAJF,EAKEC,SALF,EAMEC,mBANF,EAOEC,UAPF,QAQO,OARP;AASA,SAAQC,IAAR,QAAmB,eAAnB;AACA,OAAOC,yBAAP,MAAsC,sCAAtC;AAEA,OAAOC,gBAAP,MAA6B,4BAA7B;AACA,OAAOC,0BAAP,MAAuC,uCAAvC;AACA,OAAOC,aAAP,MAA0B,wBAA1B;;AAqCA,SAASC,aAAT,CAAuBC,OAAvB,EAA4D;AAC1D,SAAO;AACL,QAAIC,IAAJ,GAAW;AACT,aAAOD,OAAO,CAACC,IAAf;AACD,KAHI;;AAKLC,IAAAA,UAAU,EAAEC,IAAI,IAAIH,OAAO,CAACC,IAAR,CAAcC,UAAd,CAAyBC,IAAzB,CALf;AAMLC,IAAAA,mBAAmB,EAAED,IAAI,IAAIH,OAAO,CAACC,IAAR,CAAcG,mBAAd,CAAkCD,IAAlC,CANxB;AAOLE,IAAAA,WAAW,EAAEF,IAAI,IAAIH,OAAO,CAACC,IAAR,CAAcI,WAAd,CAA0BF,IAA1B;AAPhB,GAAP;AASD;;AAED,SAASG,UAAT,CAAoBN,OAApB,EAA8C;AAC5C,MAAIA,OAAO,CAACO,YAAZ,EAA0B;AAGxBP,IAAAA,OAAO,CAACC,IAAR,CAAaO,WAAb,CAAyBR,OAAO,CAACO,YAAjC;;AACAP,IAAAA,OAAO,CAACO,YAAR,GAAuB,IAAvB;AACD;AACF;;AAED,SAASE,kBAAT,CACET,OADF,EAEEU,SAFF,EAGEC,KAHF,EAIQ;AACN,QAAMV,IAAI,GAAG,IAAIS,SAAJ,CAAc,EACzB,GAAGC,KADsB;AAKzBC,IAAAA,aAAa,EAAEL,YAAY,IAAI;AAE7BP,MAAAA,OAAO,CAACO,YAAR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,CAACmC,wBAAT,IAAqCnC,OAAO,CAACe,qBAAR,KAAkCkC,gBAAxE,IACAjD,OAAO,CAACmB,OAAR,KAAoBA,OAFtB,EAGE;AACAnB,IAAAA,OAAO,CAACe,qBAAR,GAAgCkC,gBAAhC;AACAjD,IAAAA,OAAO,CAACmB,OAAR,GAAkBA,OAAlB;AAIA,UAAMqC,kBAAkB,GAAG3D,0BAA0B,CAAC;AACpDiC,MAAAA,QAAQ,EAAEH,QAAQ,CAACG,QADiC;AAEpD7B,MAAAA,IAAI,EAAED,OAAO,CAACC,IAFsC;AAGpDmD,MAAAA;AAHoD,KAAD,CAArD;AAMA,UAAMN,MAAM,GAAG3D,aAAa,CAAC,QAAD,EAAW;AACrCsE,MAAAA,GAAG,EAAE,QADgC;AAErCJ,MAAAA,EAAE,EAAEA,EAAE,IAAI,gBAF2B;AAGrCnC,MAAAA,GAAG,EAAEQ,SAHgC;AAIrCgB,MAAAA,KAAK,EAAEa;AAJ8B,KAAX,CAA5B;AAQAvD,IAAAA,OAAO,CAACsB,OAAR,GAAkBnC,aAAa,CAC7B,KAD6B,EAE7B;AAACkE,MAAAA,EAAE,YAAKA,EAAE,IAAI,QAAX,aAAH;AAAkCnC,MAAAA,GAAG,EAAEO,YAAvC;AAAqDiB,MAAAA,KAAK,EAAEY;AAA5D,KAF6B,EAG7B,CAACR,MAAD,EAASU,kBAAT,CAH6B,CAA/B;AAKD;;AAEDzB,EAAAA,QAAQ,GAAG,KAAX;AACA,SAAO/B,OAAO,CAACsB,OAAf;AACD,CA1JwB,CAAzB;AA4JAL,MAAM,CAACyC,YAAP,GAAsBhE,IAAI,CAACgE,YAA3B;AAEA,eAAezC,MAAf","sourcesContent":["// Copyright (c) 2015 - 2017 Uber Technologies, Inc.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\nimport * as React from 'react';\nimport {\n createElement,\n useRef,\n useState,\n useMemo,\n useEffect,\n useImperativeHandle,\n forwardRef\n} from 'react';\nimport {Deck} from '@deck.gl/core';\nimport useIsomorphicLayoutEffect from './utils/use-isomorphic-layout-effect';\n\nimport extractJSXLayers from './utils/extract-jsx-layers';\nimport positionChildrenUnderViews from './utils/position-children-under-views';\nimport extractStyles from './utils/extract-styles';\n\nimport type {DeckGLContextValue} from './utils/position-children-under-views';\nimport type {DeckProps, Viewport} from '@deck.gl/core';\n\n/* eslint-disable max-statements, accessor-pairs */\ntype DeckInstanceRef = {\n deck?: Deck;\n redrawReason?: string | null;\n lastRenderedViewports?: Viewport[];\n viewStateUpdateRequested?: any;\n interactionStateUpdateRequested?: any;\n forceUpdate: () => void;\n version: number;\n control: React.ReactHTMLElement<HTMLElement> | null;\n};\n\n// Remove prop types in the base Deck class that support externally supplied canvas/WebGLContext\n/** DeckGL React component props */\nexport type DeckGLProps = Omit<\n DeckProps,\n 'width' | 'height' | 'gl' | 'parent' | 'canvas' | '_customRender'\n> & {\n Deck?: typeof Deck;\n width?: string | number;\n height?: string | number;\n children?: React.ReactNode;\n ContextProvider?: React.Context<DeckGLContextValue>['Provider'];\n};\n\nexport type DeckGLRef = {\n deck?: Deck;\n pickObject: Deck['pickObject'];\n pickObjects: Deck['pickObjects'];\n pickMultipleObjects: Deck['pickMultipleObjects'];\n};\n\nfunction getRefHandles(thisRef: DeckInstanceRef): DeckGLRef {\n return {\n get deck() {\n return thisRef.deck;\n },\n // The following method can only be called after ref is available, by which point deck is defined in useEffect\n pickObject: opts => thisRef.deck!.pickObject(opts),\n pickMultipleObjects: opts => thisRef.deck!.pickMultipleObjects(opts),\n pickObjects: opts => thisRef.deck!.pickObjects(opts)\n };\n}\n\nfunction redrawDeck(thisRef: DeckInstanceRef) {\n if (thisRef.redrawReason) {\n // Only redraw if we have received a dirty flag\n // @ts-expect-error accessing protected method\n thisRef.deck._drawLayers(thisRef.redrawReason);\n thisRef.redrawReason = null;\n }\n}\n\nfunction createDeckInstance(\n thisRef: DeckInstanceRef,\n DeckClass: typeof Deck,\n props: DeckProps\n): Deck {\n const deck = new DeckClass({\n ...props,\n // The Deck's animation loop is independent from React's render cycle, causing potential\n // synchronization issues. We provide this custom render function to make sure that React\n // and Deck update on the same schedule.\n _customRender: redrawReason => {\n // Save the dirty flag for later\n thisRef.redrawReason = redrawReason;\n\n // Viewport/view state is passed to child components as props.\n // If they have changed, we need to trigger a React rerender to update children props.\n const viewports = deck.getViewports();\n if (thisRef.lastRenderedViewports !== viewports) {\n // Viewports have changed, update children props first.\n // This will delay the Deck canvas redraw till after React update (in useLayoutEffect)\n // so that the canvas does not get rendered before the child components update.\n thisRef.forceUpdate();\n } else {\n redrawDeck(thisRef);\n }\n }\n });\n return deck;\n}\n\nconst DeckGL = forwardRef<DeckGLRef, DeckGLProps>((props, ref) => {\n // A mechanism to force redraw\n const [version, setVersion] = useState(0);\n // A reference to persistent states\n const _thisRef = useRef<DeckInstanceRef>({\n control: null,\n version,\n forceUpdate: () => setVersion(v => v + 1)\n });\n const thisRef = _thisRef.current;\n // DOM refs\n const containerRef = useRef(null);\n const canvasRef = useRef(null);\n\n // extract any deck.gl layers masquerading as react elements from props.children\n const jsxProps = useMemo(\n () => extractJSXLayers(props),\n [props.layers, props.views, props.children]\n );\n\n // Callbacks\n let inRender = true;\n\n const handleViewStateChange: DeckProps['onViewStateChange'] = params => {\n if (inRender && props.viewState) {\n // Callback may invoke a state update. Defer callback to after render() to avoid React error\n // In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once\n // Store deferred parameters in ref so that we can access it in another render\n thisRef.viewStateUpdateRequested = params;\n return null;\n }\n thisRef.viewStateUpdateRequested = null;\n return props.onViewStateChange?.(params);\n };\n\n const handleInteractionStateChange: DeckProps['onInteractionStateChange'] = params => {\n if (inRender) {\n // Callback may invoke a state update. Defer callback to after render() to avoid React error\n // In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once\n // Store deferred parameters in ref so that we can access it in another render\n thisRef.interactionStateUpdateRequested = params;\n } else {\n thisRef.interactionStateUpdateRequested = null;\n props.onInteractionStateChange?.(params);\n }\n };\n\n // Update Deck's props. If Deck needs redraw, this will trigger a call to `_customRender` in\n // the next animation frame.\n // Needs to be called both from initial mount, and when new props are received\n const deckProps = useMemo(() => {\n const forwardProps: DeckProps = {\n ...props,\n // Override user styling props. We will set the canvas style in render()\n style: null,\n width: '100%',\n height: '100%',\n parent: containerRef.current,\n canvas: canvasRef.current,\n layers: jsxProps.layers,\n views: jsxProps.views,\n onViewStateChange: handleViewStateChange,\n onInteractionStateChange: handleInteractionStateChange\n };\n\n // The defaultValue for _customRender is null, which would overwrite the definition\n // of _customRender. Remove to avoid frequently redeclaring the method here.\n delete forwardProps._customRender;\n\n if (thisRef.deck) {\n thisRef.deck.setProps(forwardProps);\n }\n\n return forwardProps;\n }, [props]);\n\n useEffect(() => {\n const DeckClass = props.Deck || Deck;\n\n thisRef.deck = createDeckInstance(thisRef, DeckClass, {\n ...deckProps,\n parent: containerRef.current,\n canvas: canvasRef.current\n });\n\n return () => thisRef.deck?.finalize();\n }, []);\n\n useIsomorphicLayoutEffect(() => {\n // render has just been called. The children are positioned based on the current view state.\n // Redraw Deck canvas immediately, if necessary, using the current view state, so that it\n // matches the child components.\n redrawDeck(thisRef);\n\n // Execute deferred callbacks\n const {viewStateUpdateRequested, interactionStateUpdateRequested} = thisRef;\n if (viewStateUpdateRequested) {\n handleViewStateChange(viewStateUpdateRequested);\n }\n if (interactionStateUpdateRequested) {\n handleInteractionStateChange(interactionStateUpdateRequested);\n }\n });\n\n useImperativeHandle(ref, () => getRefHandles(thisRef), []);\n\n const currentViewports =\n thisRef.deck && thisRef.deck.isInitialized ? thisRef.deck.getViewports() : undefined;\n\n const {ContextProvider, width, height, id, style} = props;\n\n const {containerStyle, canvasStyle} = useMemo(\n () => extractStyles({width, height, style}),\n [width, height, style]\n );\n\n // Props changes may lead to 3 types of updates:\n // 1. Only the WebGL canvas - updated in Deck's render cycle (next animation frame)\n // 2. Only the DOM - updated in React's lifecycle (now)\n // 3. Both the WebGL canvas and the DOM - defer React rerender to next animation frame just\n // before Deck redraw to ensure perfect synchronization & avoid excessive redraw\n // This is because multiple changes may happen to Deck between two frames e.g. transition\n if (\n (!thisRef.viewStateUpdateRequested && thisRef.lastRenderedViewports === currentViewports) || // case 2\n thisRef.version !== version // case 3 just before deck redraws\n ) {\n thisRef.lastRenderedViewports = currentViewports;\n thisRef.version = version;\n\n // Render the background elements (typically react-map-gl instances)\n // using the view descriptors\n const childrenUnderViews = positionChildrenUnderViews({\n children: jsxProps.children,\n deck: thisRef.deck,\n ContextProvider\n });\n\n const canvas = createElement('canvas', {\n key: 'canvas',\n id: id || 'deckgl-overlay',\n ref: canvasRef,\n style: canvasStyle\n });\n\n // Render deck.gl as the last child\n thisRef.control = createElement(\n 'div',\n {id: `${id || 'deckgl'}-wrapper`, ref: containerRef, style: containerStyle},\n [canvas, childrenUnderViews]\n );\n }\n\n inRender = false;\n return thisRef.control;\n});\n\nDeckGL.defaultProps = Deck.defaultProps;\n\nexport default DeckGL;\n"],"file":"deckgl.js"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@deck.gl/react",
3
3
  "description": "React Components for deck.gl",
4
4
  "license": "MIT",
5
- "version": "8.8.0-beta.3",
5
+ "version": "8.8.0",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
@@ -31,5 +31,5 @@
31
31
  "react": ">=16.3",
32
32
  "react-dom": ">=16.3"
33
33
  },
34
- "gitHead": "bb459e1b4a4e3674ee9832d775d39211541d17b4"
34
+ "gitHead": "4fda19a4ca2f02bcb756eca0f20c6534ab744be3"
35
35
  }
package/src/deckgl.ts CHANGED
@@ -55,6 +55,7 @@ export type DeckGLProps = Omit<
55
55
  DeckProps,
56
56
  'width' | 'height' | 'gl' | 'parent' | 'canvas' | '_customRender'
57
57
  > & {
58
+ Deck?: typeof Deck;
58
59
  width?: string | number;
59
60
  height?: string | number;
60
61
  children?: React.ReactNode;
@@ -89,15 +90,13 @@ function redrawDeck(thisRef: DeckInstanceRef) {
89
90
  }
90
91
  }
91
92
 
92
- function createDeckInstance(thisRef: DeckInstanceRef, props): Deck {
93
- // Allows a subclass of Deck to be used
94
- // TODO - update propTypes / defaultProps?
95
- const DeckClass = props.Deck || Deck;
93
+ function createDeckInstance(
94
+ thisRef: DeckInstanceRef,
95
+ DeckClass: typeof Deck,
96
+ props: DeckProps
97
+ ): Deck {
96
98
  const deck = new DeckClass({
97
99
  ...props,
98
- style: null,
99
- width: '100%',
100
- height: '100%',
101
100
  // The Deck's animation loop is independent from React's render cycle, causing potential
102
101
  // synchronization issues. We provide this custom render function to make sure that React
103
102
  // and Deck update on the same schedule.
@@ -107,7 +106,7 @@ function createDeckInstance(thisRef: DeckInstanceRef, props): Deck {
107
106
 
108
107
  // Viewport/view state is passed to child components as props.
109
108
  // If they have changed, we need to trigger a React rerender to update children props.
110
- const viewports = deck.viewManager.getViewports();
109
+ const viewports = deck.getViewports();
111
110
  if (thisRef.lastRenderedViewports !== viewports) {
112
111
  // Viewports have changed, update children props first.
113
112
  // This will delay the Deck canvas redraw till after React update (in useLayoutEffect)
@@ -178,6 +177,8 @@ const DeckGL = forwardRef<DeckGLRef, DeckGLProps>((props, ref) => {
178
177
  style: null,
179
178
  width: '100%',
180
179
  height: '100%',
180
+ parent: containerRef.current,
181
+ canvas: canvasRef.current,
181
182
  layers: jsxProps.layers,
182
183
  views: jsxProps.views,
183
184
  onViewStateChange: handleViewStateChange,
@@ -195,17 +196,13 @@ const DeckGL = forwardRef<DeckGLRef, DeckGLProps>((props, ref) => {
195
196
  return forwardProps;
196
197
  }, [props]);
197
198
 
198
- const [isDeckLoaded, setIsDeckLoaded] = useState(false);
199
-
200
199
  useEffect(() => {
201
- thisRef.deck = createDeckInstance(thisRef, {
200
+ const DeckClass = props.Deck || Deck;
201
+
202
+ thisRef.deck = createDeckInstance(thisRef, DeckClass, {
202
203
  ...deckProps,
203
204
  parent: containerRef.current,
204
- canvas: canvasRef.current,
205
- onLoad: () => {
206
- setIsDeckLoaded(true);
207
- if (deckProps.onLoad) deckProps.onLoad();
208
- }
205
+ canvas: canvasRef.current
209
206
  });
210
207
 
211
208
  return () => thisRef.deck?.finalize();
@@ -229,7 +226,8 @@ const DeckGL = forwardRef<DeckGLRef, DeckGLProps>((props, ref) => {
229
226
 
230
227
  useImperativeHandle(ref, () => getRefHandles(thisRef), []);
231
228
 
232
- const currentViewports = thisRef.deck && isDeckLoaded ? thisRef.deck.getViewports() : undefined;
229
+ const currentViewports =
230
+ thisRef.deck && thisRef.deck.isInitialized ? thisRef.deck.getViewports() : undefined;
233
231
 
234
232
  const {ContextProvider, width, height, id, style} = props;
235
233
 
package/typed/deckgl.d.ts CHANGED
@@ -4,6 +4,7 @@ import type { DeckGLContextValue } from './utils/position-children-under-views';
4
4
  import type { DeckProps } from '@deck.gl/core/typed';
5
5
  /** DeckGL React component props */
6
6
  export declare type DeckGLProps = Omit<DeckProps, 'width' | 'height' | 'gl' | 'parent' | 'canvas' | '_customRender'> & {
7
+ Deck?: typeof Deck;
7
8
  width?: string | number;
8
9
  height?: string | number;
9
10
  children?: React.ReactNode;
@@ -15,7 +16,8 @@ export declare type DeckGLRef = {
15
16
  pickObjects: Deck['pickObjects'];
16
17
  pickMultipleObjects: Deck['pickMultipleObjects'];
17
18
  };
18
- declare const DeckGL: React.ForwardRefExoticComponent<Omit<DeckProps, "canvas" | "width" | "height" | "gl" | "parent" | "_customRender"> & {
19
+ declare const DeckGL: React.ForwardRefExoticComponent<Omit<DeckProps, "width" | "height" | "gl" | "parent" | "canvas" | "_customRender"> & {
20
+ Deck?: typeof Deck | undefined;
19
21
  width?: string | number | undefined;
20
22
  height?: string | number | undefined;
21
23
  children?: React.ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"deckgl.d.ts","sourceRoot":"","sources":["../src/deckgl.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,OAAO,EAAC,IAAI,EAAC,MAAM,eAAe,CAAC;AAOnC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,uCAAuC,CAAC;AAC9E,OAAO,KAAK,EAAC,SAAS,EAAW,MAAM,eAAe,CAAC;AAevD,mCAAmC;AACnC,oBAAY,WAAW,GAAG,IAAI,CAC5B,SAAS,EACT,OAAO,GAAG,QAAQ,GAAG,IAAI,GAAG,QAAQ,GAAG,QAAQ,GAAG,eAAe,CAClE,GAAG;IACF,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,eAAe,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC;CACjE,CAAC;AAEF,oBAAY,SAAS,GAAG;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAC/B,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAC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ies, 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
+ import { createElement, useRef, useState, useMemo, useEffect, useImperativeHandle, forwardRef } from 'react';
21
+ import { Deck } from '@deck.gl/core';
22
+ import useIsomorphicLayoutEffect from './utils/use-isomorphic-layout-effect';
23
+ import extractJSXLayers from './utils/extract-jsx-layers';
24
+ import positionChildrenUnderViews from './utils/position-children-under-views';
25
+ import extractStyles from './utils/extract-styles';
26
+ /* eslint-disable max-statements, accessor-pairs */
27
+ function getRefHandles(thisRef) {
28
+ const handles = {
29
+ pickObject: opts => thisRef.deck.pickObject(opts),
30
+ pickMultipleObjects: opts => thisRef.deck.pickMultipleObjects(opts),
31
+ pickObjects: opts => thisRef.deck.pickObjects(opts)
32
+ };
33
+ Object.defineProperty(handles, 'deck', {
34
+ get: () => thisRef.deck
35
+ });
36
+ return handles;
37
+ }
38
+ function redrawDeck(thisRef) {
39
+ if (thisRef.redrawReason) {
40
+ // Only redraw if we have received a dirty flag
41
+ thisRef.deck._drawLayers(thisRef.redrawReason);
42
+ thisRef.redrawReason = null;
43
+ }
44
+ }
45
+ function createDeckInstance(thisRef, props) {
46
+ // Allows a subclass of Deck to be used
47
+ // TODO - update propTypes / defaultProps?
48
+ const DeckClass = props.Deck || Deck;
49
+ const deck = new DeckClass({
50
+ ...props,
51
+ style: null,
52
+ width: '100%',
53
+ height: '100%',
54
+ // The Deck's animation loop is independent from React's render cycle, causing potential
55
+ // synchronization issues. We provide this custom render function to make sure that React
56
+ // and Deck update on the same schedule.
57
+ _customRender: redrawReason => {
58
+ // Save the dirty flag for later
59
+ thisRef.redrawReason = redrawReason;
60
+ // Viewport/view state is passed to child components as props.
61
+ // If they have changed, we need to trigger a React rerender to update children props.
62
+ const viewports = deck.viewManager.getViewports();
63
+ if (thisRef.lastRenderedViewports !== viewports) {
64
+ // Viewports have changed, update children props first.
65
+ // This will delay the Deck canvas redraw till after React update (in useLayoutEffect)
66
+ // so that the canvas does not get rendered before the child components update.
67
+ thisRef.forceUpdate(v => v + 1);
68
+ }
69
+ else {
70
+ redrawDeck(thisRef);
71
+ }
72
+ }
73
+ });
74
+ return deck;
75
+ }
76
+ const DeckGL = forwardRef((props, ref) => {
77
+ // A reference to persistent states
78
+ const _thisRef = useRef({});
79
+ const thisRef = _thisRef.current;
80
+ // A mechanism to force redraw
81
+ const [version, setVersion] = useState(0);
82
+ thisRef.forceUpdate = setVersion;
83
+ // DOM refs
84
+ const containerRef = useRef(null);
85
+ const canvasRef = useRef(null);
86
+ // extract any deck.gl layers masquerading as react elements from props.children
87
+ const jsxProps = useMemo(() => extractJSXLayers(props), [props.layers, props.views, props.children]);
88
+ // Callbacks
89
+ let inRender = true;
90
+ const handleViewStateChange = params => {
91
+ if (inRender && props.viewState) {
92
+ // Callback may invoke a state update. Defer callback to after render() to avoid React error
93
+ // In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once
94
+ // Store deferred parameters in ref so that we can access it in another render
95
+ thisRef.viewStateUpdateRequested = params;
96
+ return null;
97
+ }
98
+ thisRef.viewStateUpdateRequested = null;
99
+ return props.onViewStateChange(params);
100
+ };
101
+ const handleInteractionStateChange = params => {
102
+ if (inRender) {
103
+ // Callback may invoke a state update. Defer callback to after render() to avoid React error
104
+ // In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once
105
+ // Store deferred parameters in ref so that we can access it in another render
106
+ thisRef.interactionStateUpdateRequested = params;
107
+ }
108
+ else {
109
+ thisRef.interactionStateUpdateRequested = null;
110
+ props.onInteractionStateChange(params);
111
+ }
112
+ };
113
+ // Update Deck's props. If Deck needs redraw, this will trigger a call to `_customRender` in
114
+ // the next animation frame.
115
+ // Needs to be called both from initial mount, and when new props are received
116
+ const deckProps = useMemo(() => {
117
+ const forwardProps = {
118
+ ...props,
119
+ // Override user styling props. We will set the canvas style in render()
120
+ style: null,
121
+ width: '100%',
122
+ height: '100%',
123
+ layers: jsxProps.layers,
124
+ views: jsxProps.views,
125
+ onViewStateChange: handleViewStateChange,
126
+ onInteractionStateChange: handleInteractionStateChange
127
+ };
128
+ // The defaultValue for _customRender is null, which would overwrite the definition
129
+ // of _customRender. Remove to avoid frequently redeclaring the method here.
130
+ delete forwardProps._customRender;
131
+ if (thisRef.deck) {
132
+ thisRef.deck.setProps(forwardProps);
133
+ }
134
+ return forwardProps;
135
+ }, [props]);
136
+ useEffect(() => {
137
+ thisRef.deck = createDeckInstance(thisRef, {
138
+ ...deckProps,
139
+ parent: containerRef.current,
140
+ canvas: canvasRef.current
141
+ });
142
+ return () => thisRef.deck.finalize();
143
+ }, []);
144
+ useIsomorphicLayoutEffect(() => {
145
+ // render has just been called. The children are positioned based on the current view state.
146
+ // Redraw Deck canvas immediately, if necessary, using the current view state, so that it
147
+ // matches the child components.
148
+ redrawDeck(thisRef);
149
+ // Execute deferred callbacks
150
+ const { viewStateUpdateRequested, interactionStateUpdateRequested } = thisRef;
151
+ if (viewStateUpdateRequested) {
152
+ handleViewStateChange(viewStateUpdateRequested);
153
+ }
154
+ if (interactionStateUpdateRequested) {
155
+ handleInteractionStateChange(interactionStateUpdateRequested);
156
+ }
157
+ });
158
+ useImperativeHandle(ref, () => getRefHandles(thisRef), []);
159
+ const { viewManager } = thisRef.deck || {};
160
+ const currentViewports = viewManager && viewManager.getViewports();
161
+ const { ContextProvider, width, height, id, style } = props;
162
+ const { containerStyle, canvasStyle } = useMemo(() => extractStyles({ width, height, style }), [width, height, style]);
163
+ // Props changes may lead to 3 types of updates:
164
+ // 1. Only the WebGL canvas - updated in Deck's render cycle (next animation frame)
165
+ // 2. Only the DOM - updated in React's lifecycle (now)
166
+ // 3. Both the WebGL canvas and the DOM - defer React rerender to next animation frame just
167
+ // before Deck redraw to ensure perfect synchronization & avoid excessive redraw
168
+ // This is because multiple changes may happen to Deck between two frames e.g. transition
169
+ if ((!thisRef.viewStateUpdateRequested && thisRef.lastRenderedViewports === currentViewports) || // case 2
170
+ thisRef.version !== version // case 3 just before deck redraws
171
+ ) {
172
+ thisRef.lastRenderedViewports = currentViewports;
173
+ thisRef.version = version;
174
+ // Render the background elements (typically react-map-gl instances)
175
+ // using the view descriptors
176
+ const childrenUnderViews = positionChildrenUnderViews({
177
+ children: jsxProps.children,
178
+ deck: thisRef.deck,
179
+ ContextProvider
180
+ });
181
+ const canvas = createElement('canvas', {
182
+ key: 'canvas',
183
+ id: id || 'deckgl-overlay',
184
+ ref: canvasRef,
185
+ style: canvasStyle
186
+ });
187
+ // Render deck.gl as the last child
188
+ thisRef.control = createElement('div', { id: `${id || 'deckgl'}-wrapper`, ref: containerRef, style: containerStyle }, [canvas, childrenUnderViews]);
189
+ }
190
+ inRender = false;
191
+ return thisRef.control;
192
+ });
193
+ DeckGL.defaultProps = Deck.defaultProps;
194
+ export default DeckGL;
package/typed/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';
21
+ export { default } from './deckgl';
@@ -0,0 +1,33 @@
1
+ import { cloneElement } from 'react';
2
+ const MAP_STYLE = { position: 'absolute', zIndex: -1 };
3
+ export default function evaluateChildren(children, childProps) {
4
+ if (!children) {
5
+ return children;
6
+ }
7
+ if (typeof children === 'function') {
8
+ return children(childProps);
9
+ }
10
+ if (Array.isArray(children)) {
11
+ return children.map(child => evaluateChildren(child, childProps));
12
+ }
13
+ // Special treatment for react-map-gl's Map component
14
+ // to support shorthand use case <DeckGL><StaticMap /></DeckGL>
15
+ if (isReactMap(children)) {
16
+ // Place map under the canvas
17
+ childProps.style = MAP_STYLE;
18
+ return cloneElement(children, childProps);
19
+ }
20
+ if (needsDeckGLViewProps(children)) {
21
+ return cloneElement(children, childProps);
22
+ }
23
+ return children;
24
+ }
25
+ function isReactMap(child) {
26
+ const componentClass = child && child.type;
27
+ const componentProps = componentClass && componentClass.defaultProps;
28
+ return componentProps && componentProps.mapStyle;
29
+ }
30
+ function needsDeckGLViewProps(child) {
31
+ const componentClass = child && child.type;
32
+ return componentClass && componentClass.deckGLViewProps;
33
+ }
@@ -0,0 +1,77 @@
1
+ import React, { createElement } from 'react';
2
+ import { inheritsFrom } from './inherits-from';
3
+ import { Layer, View } from '@deck.gl/core';
4
+ // recursively wrap render callbacks in `View`
5
+ function wrapInView(node) {
6
+ if (!node) {
7
+ return node;
8
+ }
9
+ if (typeof node === 'function') {
10
+ // React.Children does not traverse functions.
11
+ // All render callbacks must be protected under a <View>
12
+ return createElement(View, {}, node);
13
+ }
14
+ if (Array.isArray(node)) {
15
+ return node.map(wrapInView);
16
+ }
17
+ if (node.type === React.Fragment) {
18
+ return wrapInView(node.props.children);
19
+ }
20
+ if (inheritsFrom(node.type, View)) {
21
+ return node;
22
+ }
23
+ return node;
24
+ }
25
+ // extracts any deck.gl layers masquerading as react elements from props.children
26
+ export default function extractJSXLayers({ children, layers, views }) {
27
+ const reactChildren = []; // extract real react elements (i.e. not deck.gl layers)
28
+ const jsxLayers = []; // extracted layer from react children, will add to deck.gl layer array
29
+ const jsxViews = {};
30
+ // React.children
31
+ React.Children.forEach(wrapInView(children), reactElement => {
32
+ if (reactElement) {
33
+ // For some reason Children.forEach doesn't filter out `null`s
34
+ const ElementType = reactElement.type;
35
+ if (inheritsFrom(ElementType, Layer)) {
36
+ const layer = createLayer(ElementType, reactElement.props);
37
+ jsxLayers.push(layer);
38
+ }
39
+ else {
40
+ reactChildren.push(reactElement);
41
+ }
42
+ // empty id => default view
43
+ if (ElementType !== View && inheritsFrom(ElementType, View) && reactElement.props.id) {
44
+ const view = new ElementType(reactElement.props);
45
+ jsxViews[view.id] = view;
46
+ }
47
+ }
48
+ });
49
+ // Avoid modifying views if no JSX views were found
50
+ if (Object.keys(jsxViews).length > 0) {
51
+ // If a view is specified in both views prop and JSX, use the one in views
52
+ if (Array.isArray(views)) {
53
+ views.forEach(view => {
54
+ jsxViews[view.id] = view;
55
+ });
56
+ }
57
+ else if (views) {
58
+ jsxViews[views.id] = views;
59
+ }
60
+ views = Object.values(jsxViews);
61
+ }
62
+ // Avoid modifying layers array if no JSX layers were found
63
+ layers = jsxLayers.length > 0 ? [...jsxLayers, ...layers] : layers;
64
+ return { layers, children: reactChildren, views };
65
+ }
66
+ function createLayer(LayerType, reactProps) {
67
+ const props = {};
68
+ // Layer.defaultProps is treated as ReactElement.defaultProps and merged into react props
69
+ // Remove them
70
+ const defaultProps = LayerType.defaultProps || {};
71
+ for (const key in reactProps) {
72
+ if (defaultProps[key] !== reactProps[key]) {
73
+ props[key] = reactProps[key];
74
+ }
75
+ }
76
+ return new LayerType(props);
77
+ }
@@ -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
+ }
@@ -0,0 +1,75 @@
1
+ import { createElement } from 'react';
2
+ import { View } from '@deck.gl/core';
3
+ import { inheritsFrom } from './inherits-from';
4
+ import evaluateChildren from './evaluate-children';
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
+ const { viewManager } = deck || {};
9
+ if (!viewManager || !viewManager.views.length) {
10
+ return [];
11
+ }
12
+ const views = {};
13
+ const defaultViewId = viewManager.views[0].id;
14
+ // Sort children by view id
15
+ for (const child of children) {
16
+ // Unless child is a View, position / render as part of the default view
17
+ let viewId = defaultViewId;
18
+ let viewChildren = child;
19
+ if (inheritsFrom(child.type, View)) {
20
+ viewId = child.props.id || defaultViewId;
21
+ viewChildren = child.props.children;
22
+ }
23
+ const viewport = viewManager.getViewport(viewId);
24
+ const viewState = viewManager.getViewState(viewId);
25
+ // Drop (auto-hide) elements with viewId that are not matched by any current view
26
+ if (viewport) {
27
+ const { x, y, width, height } = viewport;
28
+ // Resolve potentially relative dimensions using the deck.gl container size
29
+ viewChildren = evaluateChildren(viewChildren, {
30
+ x,
31
+ y,
32
+ width,
33
+ height,
34
+ viewport,
35
+ viewState
36
+ });
37
+ if (!views[viewId]) {
38
+ views[viewId] = {
39
+ viewport,
40
+ children: []
41
+ };
42
+ }
43
+ views[viewId].children.push(viewChildren);
44
+ }
45
+ }
46
+ // Render views
47
+ return Object.keys(views).map(viewId => {
48
+ const { viewport, children: viewChildren } = views[viewId];
49
+ const { x, y, width, height } = viewport;
50
+ const style = {
51
+ position: 'absolute',
52
+ left: x,
53
+ top: y,
54
+ width,
55
+ height
56
+ };
57
+ const key = `view-${viewId}`;
58
+ // If children is passed as an array, React will throw the "each element in a list needs
59
+ // a key" warning. Sending each child as separate arguments removes this requirement.
60
+ const viewElement = createElement('div', { key, id: key, style }, ...viewChildren);
61
+ if (ContextProvider) {
62
+ const contextValue = {
63
+ viewport,
64
+ container: deck.canvas.offsetParent,
65
+ eventManager: deck.eventManager,
66
+ onViewStateChange: params => {
67
+ params.viewId = viewId;
68
+ deck._onViewStateChange(params);
69
+ }
70
+ };
71
+ return createElement(ContextProvider, { key, value: contextValue }, viewElement);
72
+ }
73
+ return viewElement;
74
+ });
75
+ }
@@ -1,4 +1,4 @@
1
- import { useLayoutEffect } from 'react';
2
- declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
1
+ import { useEffect } from 'react';
2
+ declare const useIsomorphicLayoutEffect: typeof useEffect;
3
3
  export default useIsomorphicLayoutEffect;
4
4
  //# sourceMappingURL=use-isomorphic-layout-effect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-isomorphic-layout-effect.d.ts","sourceRoot":"","sources":["../../src/utils/use-isomorphic-layout-effect.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,eAAe,EAAC,MAAM,OAAO,CAAC;AAEjD,QAAA,MAAM,yBAAyB,wBAA8D,CAAC;AAE9F,eAAe,yBAAyB,CAAC"}
1
+ {"version":3,"file":"use-isomorphic-layout-effect.d.ts","sourceRoot":"","sources":["../../src/utils/use-isomorphic-layout-effect.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAkB,MAAM,OAAO,CAAC;AAEjD,QAAA,MAAM,yBAAyB,kBAA8D,CAAC;AAE9F,eAAe,yBAAyB,CAAC"}
@@ -0,0 +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
3
+ import { useEffect, useLayoutEffect } from 'react';
4
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
5
+ export default useIsomorphicLayoutEffect;
package/CHANGELOG.md DELETED
File without changes