@deck.gl/react 8.9.27 → 8.9.28

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.
@@ -1 +1 @@
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,CA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;AAAkCpC,MAAAA,GAAG,EAAEO,YAAvC;AAAqDiB,MAAAA,KAAK,EAAEa;AAA5D,KAFgB,EAGhB,CAACT,MAAD,EAASW,kBAAT,CAHgB,CAAlB;AAKD;;AAED1B,EAAAA,QAAQ,GAAG,KAAX;AACA,SAAO/B,OAAO,CAACsB,OAAf;AACD,CA1Jc,CAAf;AA4JAL,MAAM,CAAC0C,YAAP,GAAsBX,WAAKW,YAA3B;eAEe1C,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 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"}
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;AA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A,QAAMP,MAAM,GAAG,0BAAc,QAAd,EAAwB;AACrCY,MAAAA,GAAG,EAAE,QADgC;AAErCJ,MAAAA,EAAE,EAAEA,EAAE,IAAI,gBAF2B;AAGrCpC,MAAAA,GAAG,EAAEQ,SAHgC;AAIrCgB,MAAAA,KAAK,EAAEc;AAJ8B,KAAxB,CAAf;AAQAxD,IAAAA,OAAO,CAACsB,OAAR,GAAkB,0BAChB,KADgB,EAEhB;AAACgC,MAAAA,EAAE,YAAKA,EAAE,IAAI,QAAX,aAAH;AAAkCpC,MAAAA,GAAG,EAAEO,YAAvC;AAAqDiB,MAAAA,KAAK,EAAEa;AAA5D,KAFgB,EAGhB,CAACT,MAAD,EAASW,kBAAT,CAHgB,CAAlB;AAKD;;AAED1B,EAAAA,QAAQ,GAAG,KAAX;AACA,SAAO/B,OAAO,CAACsB,OAAf;AACD,CA1Jc,CAAf;AA4JAL,MAAM,CAAC0C,YAAP,GAAsBX,WAAKW,YAA3B;eAEe1C,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, {DeckGLRenderCallback} 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 | DeckGLRenderCallback;\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"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/extract-jsx-layers.ts"],"names":["wrapInView","node","View","Array","isArray","map","type","React","Fragment","props","children","extractJSXLayers","layers","views","reactChildren","jsxLayers","jsxViews","Children","forEach","reactElement","ElementType","Layer","layer","createLayer","push","id","view","Object","keys","length","values","LayerType","reactProps","defaultProps","key"],"mappings":";;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;;;;;AAIA,SAASA,UAAT,CAAoBC,IAApB,EAA4D;AAC1D,MAAI,OAAOA,IAAP,KAAgB,UAApB,EAAgC;AAI9B,WAAO,yBAAcC,UAAd,EAAoB,EAApB,EAAwBD,IAAxB,CAAP;AAC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,EAA2C;AACzCzB,MAAAA,KAAK,CAACyB,GAAD,CAAL,GAAaF,UAAU,CAACE,GAAD,CAAvB;AACD;AACF;;AAED,SAAO,IAAIH,SAAJ,CAActB,KAAd,CAAP;AACD","sourcesContent":["import * as React from 'react';\nimport {createElement} from 'react';\nimport {inheritsFrom} from './inherits-from';\nimport {Layer, View} from '@deck.gl/core';\nimport {isComponent} from './evaluate-children';\nimport type {LayersList} from '@deck.gl/core';\n\n// recursively wrap render callbacks in `View`\nfunction wrapInView(node: React.ReactNode): React.ReactNode {\n if (typeof node === 'function') {\n // React.Children does not traverse functions.\n // All render callbacks must be protected under a <View>\n // @ts-expect-error View is not a ReactJSXElement constructor. Only used as a temporary wrapper and will be removed in extractJSXLayers\n return createElement(View, {}, node);\n }\n if (Array.isArray(node)) {\n return node.map(wrapInView);\n }\n if (isComponent(node)) {\n if (node.type === React.Fragment) {\n return wrapInView(node.props.children);\n }\n if (inheritsFrom(node.type, View)) {\n return node;\n }\n }\n return node;\n}\n\n// extracts any deck.gl layers masquerading as react elements from props.children\nexport default function extractJSXLayers({\n children,\n layers = [],\n views = null\n}: {\n children?: React.ReactNode;\n layers?: LayersList;\n views?: View | View[] | null;\n}): {\n children: React.ReactNode[];\n layers: LayersList;\n views: View | View[] | null;\n} {\n const reactChildren: React.ReactNode[] = []; // extract real react elements (i.e. not deck.gl layers)\n const jsxLayers: LayersList = []; // extracted layer from react children, will add to deck.gl layer array\n const jsxViews: Record<string, View> = {};\n\n // React.children\n React.Children.forEach(wrapInView(children), reactElement => {\n if (isComponent(reactElement)) {\n // For some reason Children.forEach doesn't filter out `null`s\n const ElementType = reactElement.type;\n if (inheritsFrom(ElementType, Layer)) {\n const layer = createLayer(ElementType, reactElement.props);\n jsxLayers.push(layer);\n } else {\n reactChildren.push(reactElement);\n }\n\n // empty id => default view\n if (inheritsFrom(ElementType, View) && ElementType !== View && reactElement.props.id) {\n // @ts-ignore Cannot instantiate an abstract class (View)\n const view = new ElementType(reactElement.props);\n jsxViews[view.id] = view;\n }\n } else if (reactElement) {\n reactChildren.push(reactElement);\n }\n });\n\n // Avoid modifying views if no JSX views were found\n if (Object.keys(jsxViews).length > 0) {\n // If a view is specified in both views prop and JSX, use the one in views\n if (Array.isArray(views)) {\n views.forEach(view => {\n jsxViews[view.id] = view;\n });\n } else if (views) {\n jsxViews[views.id] = views;\n }\n views = Object.values(jsxViews);\n }\n\n // Avoid modifying layers array if no JSX layers were found\n layers = jsxLayers.length > 0 ? [...jsxLayers, ...layers] : layers;\n\n return {layers, children: reactChildren, views};\n}\n\nfunction createLayer(LayerType: typeof Layer, reactProps: any): Layer {\n const props = {};\n // Layer.defaultProps is treated as ReactElement.defaultProps and merged into react props\n // Remove them\n const defaultProps = LayerType.defaultProps || {};\n for (const key in reactProps) {\n if (defaultProps[key] !== reactProps[key]) {\n props[key] = reactProps[key];\n }\n }\n // @ts-ignore Cannot instantiate an abstract class (Layer)\n return new LayerType(props);\n}\n"],"file":"extract-jsx-layers.js"}
1
+ {"version":3,"sources":["../../../src/utils/extract-jsx-layers.ts"],"names":["wrapInView","node","View","Array","isArray","map","type","React","Fragment","props","children","extractJSXLayers","layers","views","reactChildren","jsxLayers","jsxViews","Children","forEach","reactElement","ElementType","Layer","layer","createLayer","push","id","view","Object","keys","length","values","LayerType","reactProps","defaultProps","key"],"mappings":";;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;;;;;AAiCA,SAASA,UAAT,CAAoBC,IAApB,EAAmF;AACjF,MAAI,OAAOA,IAAP,KAAgB,UAApB,EAAgC;AAI9B,WAAO,yBAAcC,UAAd,EAAoB,EAApB,EAAwBD,IAAxB,CAAP;AACD;;AACD,MAAIE,KAAK,CAACC,OAAN,CAAcH,IAAd,CAAJ,EAAyB;AACvB,WAAOA,IAAI,CAACI,GAAL,CAASL,UAAT,CAAP;AACD;;AACD,MAAI,mCAAYC,IAAZ,CAAJ,EAAuB;AACrB,QAAIA,IAAI,CAACK,IAAL,KAAcC,KAAK,CAAC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MAAAA,aAAa,CAACU,IAAd,CAAmBL,YAAnB;AACD;AACF,GApBD;;AAuBA,MAAIQ,MAAM,CAACC,IAAP,CAAYZ,QAAZ,EAAsBa,MAAtB,GAA+B,CAAnC,EAAsC;AAEpC,QAAI1B,KAAK,CAACC,OAAN,CAAcS,KAAd,CAAJ,EAA0B;AACxBA,MAAAA,KAAK,CAACK,OAAN,CAAc,UAAAQ,IAAI,EAAI;AACpBV,QAAAA,QAAQ,CAACU,IAAI,CAACD,EAAN,CAAR,GAAoBC,IAApB;AACD,OAFD;AAGD,KAJD,MAIO,IAAIb,KAAJ,EAAW;AAChBG,MAAAA,QAAQ,CAACH,KAAK,CAACY,EAAP,CAAR,GAAqBZ,KAArB;AACD;;AACDA,IAAAA,KAAK,GAAGc,MAAM,CAACG,MAAP,CAAcd,QAAd,CAAR;AACD;;AAGDJ,EAAAA,MAAM,GAAGG,SAAS,CAACc,MAAV,GAAmB,CAAnB,aAA2Bd,SAA3B,mCAAyCH,MAAzC,KAAmDA,MAA5D;AAEA,SAAO;AAACA,IAAAA,MAAM,EAANA,MAAD;AAASF,IAAAA,QAAQ,EAAEI,aAAnB;AAAkCD,IAAAA,KAAK,EAALA;AAAlC,GAAP;AACD;;AAED,SAASU,WAAT,CAAqBQ,SAArB,EAA8CC,UAA9C,EAAsE;AACpE,MAAMvB,KAAK,GAAG,EAAd;AAGA,MAAMwB,YAAY,GAAGF,SAAS,CAACE,YAAV,IAA0B,EAA/C;;AACA,OAAK,IAAMC,GAAX,IAAkBF,UAAlB,EAA8B;AAC5B,QAAIC,YAAY,CAACC,GAAD,CAAZ,KAAsBF,UAAU,CAACE,GAAD,CAApC,EAA2C;AACzCzB,MAAAA,KAAK,CAACyB,GAAD,CAAL,GAAaF,UAAU,CAACE,GAAD,CAAvB;AACD;AACF;;AAED,SAAO,IAAIH,SAAJ,CAActB,KAAd,CAAP;AACD","sourcesContent":["import * as React from 'react';\nimport {createElement} from 'react';\nimport {inheritsFrom} from './inherits-from';\nimport {Layer, View} from '@deck.gl/core';\nimport {isComponent} from './evaluate-children';\nimport type {LayersList, Viewport} from '@deck.gl/core';\n\nexport type DeckGLRenderCallbackArgs = {\n /**\n * the left offset of the current view, in pixels\n */\n x: number;\n /**\n * the top offset of the current view, in pixels\n */\n y: number;\n /**\n * the width of the current view, in pixels\n */\n width: number;\n /**\n * the height of the current view, in pixels\n */\n height: number;\n /**\n * the view state of the current view\n */\n viewState: any;\n /**\n * the `Viewport` instance of the current view\n */\n viewport: Viewport;\n};\n\nexport type DeckGLRenderCallback = (args: DeckGLRenderCallbackArgs) => React.ReactNode;\n\n// recursively wrap render callbacks in `View`\nfunction wrapInView(node: React.ReactNode | DeckGLRenderCallback): React.ReactNode {\n if (typeof node === 'function') {\n // React.Children does not traverse functions.\n // All render callbacks must be protected under a <View>\n // @ts-expect-error View is not a ReactJSXElement constructor. Only used as a temporary wrapper and will be removed in extractJSXLayers\n return createElement(View, {}, node);\n }\n if (Array.isArray(node)) {\n return node.map(wrapInView);\n }\n if (isComponent(node)) {\n if (node.type === React.Fragment) {\n return wrapInView(node.props.children);\n }\n if (inheritsFrom(node.type, View)) {\n return node;\n }\n }\n return node;\n}\n\n// extracts any deck.gl layers masquerading as react elements from props.children\nexport default function extractJSXLayers({\n children,\n layers = [],\n views = null\n}: {\n children?: React.ReactNode | DeckGLRenderCallback;\n layers?: LayersList;\n views?: View | View[] | null;\n}): {\n children: React.ReactNode[];\n layers: LayersList;\n views: View | View[] | null;\n} {\n const reactChildren: React.ReactNode[] = []; // extract real react elements (i.e. not deck.gl layers)\n const jsxLayers: LayersList = []; // extracted layer from react children, will add to deck.gl layer array\n const jsxViews: Record<string, View> = {};\n\n // React.children\n React.Children.forEach(wrapInView(children), reactElement => {\n if (isComponent(reactElement)) {\n // For some reason Children.forEach doesn't filter out `null`s\n const ElementType = reactElement.type;\n if (inheritsFrom(ElementType, Layer)) {\n const layer = createLayer(ElementType, reactElement.props);\n jsxLayers.push(layer);\n } else {\n reactChildren.push(reactElement);\n }\n\n // empty id => default view\n if (inheritsFrom(ElementType, View) && ElementType !== View && reactElement.props.id) {\n // @ts-ignore Cannot instantiate an abstract class (View)\n const view = new ElementType(reactElement.props);\n jsxViews[view.id] = view;\n }\n } else if (reactElement) {\n reactChildren.push(reactElement);\n }\n });\n\n // Avoid modifying views if no JSX views were found\n if (Object.keys(jsxViews).length > 0) {\n // If a view is specified in both views prop and JSX, use the one in views\n if (Array.isArray(views)) {\n views.forEach(view => {\n jsxViews[view.id] = view;\n });\n } else if (views) {\n jsxViews[views.id] = views;\n }\n views = Object.values(jsxViews);\n }\n\n // Avoid modifying layers array if no JSX layers were found\n layers = jsxLayers.length > 0 ? [...jsxLayers, ...layers] : layers;\n\n return {layers, children: reactChildren, views};\n}\n\nfunction createLayer(LayerType: typeof Layer, reactProps: any): Layer {\n const props = {};\n // Layer.defaultProps is treated as ReactElement.defaultProps and merged into react props\n // Remove them\n const defaultProps = LayerType.defaultProps || {};\n for (const key in reactProps) {\n if (defaultProps[key] !== reactProps[key]) {\n props[key] = reactProps[key];\n }\n }\n // @ts-ignore Cannot instantiate an abstract class (Layer)\n return new LayerType(props);\n}\n"],"file":"extract-jsx-layers.js"}
@@ -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","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","ContextPro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AO,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"}
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,MAAqD,4BAArD;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,CA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AAO,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, {DeckGLRenderCallback} 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 | DeckGLRenderCallback;\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"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/extract-jsx-layers.ts"],"names":["React","createElement","inheritsFrom","Layer","View","isComponent","wrapInView","node","Array","isArray","map","type","Fragment","props","children","extractJSXLayers","layers","views","reactChildren","jsxLayers","jsxViews","Children","forEach","reactElement","ElementType","layer","createLayer","push","id","view","Object","keys","length","values","LayerType","reactProps","defaultProps","key"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAAQC,aAAR,QAA4B,OAA5B;AACA,SAAQC,YAAR,QAA2B,iBAA3B;AACA,SAAQC,KAAR,EAAeC,IAAf,QAA0B,eAA1B;AACA,SAAQC,WAAR,QAA0B,qBAA1B;;AAIA,SAASC,UAAT,CAAoBC,IAApB,EAA4D;AAC1D,MAAI,OAAOA,IAAP,KAAgB,UAApB,EAAgC;AAI9B,WAAON,aAAa,CAACG,IAAD,EAAO,EAAP,EAAWG,IAAX,CAApB;AACD;;AACD,MAAIC,KAAK,CAACC,OAAN,CAAcF,IAAd,CAAJ,EAAyB;AACvB,WAAOA,IAAI,CAACG,GAAL,CAASJ,UAAT,CAAP;AACD;;AACD,MAAID,WAAW,CAACE,IAAD,CAAf,EAAuB;AACrB,QAAIA,IAAI,CAACI,IAAL,KAAcX,KAAK,CAACY,QAAxB,EAAkC;AAChC,aAAON,UAAU,CAACC,IAAI,CAACM,KAAL,CAAWC,QAAZ,CAAjB;AACD;;AACD,QAAIZ,YAAY,CAACK,IAAI,CAACI,IA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A+B,CAAnC,EAAsC;AAEpC,QAAIxB,KAAK,CAACC,OAAN,CAAcQ,KAAd,CAAJ,EAA0B;AACxBA,MAAAA,KAAK,CAACK,OAAN,CAAcO,IAAI,IAAI;AACpBT,QAAAA,QAAQ,CAACS,IAAI,CAACD,EAAN,CAAR,GAAoBC,IAApB;AACD,OAFD;AAGD,KAJD,MAIO,IAAIZ,KAAJ,EAAW;AAChBG,MAAAA,QAAQ,CAACH,KAAK,CAACW,EAAP,CAAR,GAAqBX,KAArB;AACD;;AACDA,IAAAA,KAAK,GAAGa,MAAM,CAACG,MAAP,CAAcb,QAAd,CAAR;AACD;;AAGDJ,EAAAA,MAAM,GAAGG,SAAS,CAACa,MAAV,GAAmB,CAAnB,GAAuB,CAAC,GAAGb,SAAJ,EAAe,GAAGH,MAAlB,CAAvB,GAAmDA,MAA5D;AAEA,SAAO;AAACA,IAAAA,MAAD;AAASF,IAAAA,QAAQ,EAAEI,aAAnB;AAAkCD,IAAAA;AAAlC,GAAP;AACD;;AAED,SAASS,WAAT,CAAqBQ,SAArB,EAA8CC,UAA9C,EAAsE;AACpE,QAAMtB,KAAK,GAAG,EAAd;AAGA,QAAMuB,YAAY,GAAGF,SAAS,CAACE,YAAV,IAA0B,EAA/C;;AACA,OAAK,MAAMC,GAAX,IAAkBF,UAAlB,EAA8B;AAC5B,QAAIC,YAAY,CAACC,GAAD,CAAZ,KAAsBF,UAAU,CAACE,GAAD,CAApC,EAA2C;AACzCxB,MAAAA,KAAK,CAACwB,GAAD,CAAL,GAAaF,UAAU,CAACE,GAAD,CAAvB;AACD;AACF;;AAED,SAAO,IAAIH,SAAJ,CAAcrB,KAAd,CAAP;AACD","sourcesContent":["import * as React from 'react';\nimport {createElement} from 'react';\nimport {inheritsFrom} from './inherits-from';\nimport {Layer, View} from '@deck.gl/core';\nimport {isComponent} from './evaluate-children';\nimport type {LayersList} from '@deck.gl/core';\n\n// recursively wrap render callbacks in `View`\nfunction wrapInView(node: React.ReactNode): React.ReactNode {\n if (typeof node === 'function') {\n // React.Children does not traverse functions.\n // All render callbacks must be protected under a <View>\n // @ts-expect-error View is not a ReactJSXElement constructor. Only used as a temporary wrapper and will be removed in extractJSXLayers\n return createElement(View, {}, node);\n }\n if (Array.isArray(node)) {\n return node.map(wrapInView);\n }\n if (isComponent(node)) {\n if (node.type === React.Fragment) {\n return wrapInView(node.props.children);\n }\n if (inheritsFrom(node.type, View)) {\n return node;\n }\n }\n return node;\n}\n\n// extracts any deck.gl layers masquerading as react elements from props.children\nexport default function extractJSXLayers({\n children,\n layers = [],\n views = null\n}: {\n children?: React.ReactNode;\n layers?: LayersList;\n views?: View | View[] | null;\n}): {\n children: React.ReactNode[];\n layers: LayersList;\n views: View | View[] | null;\n} {\n const reactChildren: React.ReactNode[] = []; // extract real react elements (i.e. not deck.gl layers)\n const jsxLayers: LayersList = []; // extracted layer from react children, will add to deck.gl layer array\n const jsxViews: Record<string, View> = {};\n\n // React.children\n React.Children.forEach(wrapInView(children), reactElement => {\n if (isComponent(reactElement)) {\n // For some reason Children.forEach doesn't filter out `null`s\n const ElementType = reactElement.type;\n if (inheritsFrom(ElementType, Layer)) {\n const layer = createLayer(ElementType, reactElement.props);\n jsxLayers.push(layer);\n } else {\n reactChildren.push(reactElement);\n }\n\n // empty id => default view\n if (inheritsFrom(ElementType, View) && ElementType !== View && reactElement.props.id) {\n // @ts-ignore Cannot instantiate an abstract class (View)\n const view = new ElementType(reactElement.props);\n jsxViews[view.id] = view;\n }\n } else if (reactElement) {\n reactChildren.push(reactElement);\n }\n });\n\n // Avoid modifying views if no JSX views were found\n if (Object.keys(jsxViews).length > 0) {\n // If a view is specified in both views prop and JSX, use the one in views\n if (Array.isArray(views)) {\n views.forEach(view => {\n jsxViews[view.id] = view;\n });\n } else if (views) {\n jsxViews[views.id] = views;\n }\n views = Object.values(jsxViews);\n }\n\n // Avoid modifying layers array if no JSX layers were found\n layers = jsxLayers.length > 0 ? [...jsxLayers, ...layers] : layers;\n\n return {layers, children: reactChildren, views};\n}\n\nfunction createLayer(LayerType: typeof Layer, reactProps: any): Layer {\n const props = {};\n // Layer.defaultProps is treated as ReactElement.defaultProps and merged into react props\n // Remove them\n const defaultProps = LayerType.defaultProps || {};\n for (const key in reactProps) {\n if (defaultProps[key] !== reactProps[key]) {\n props[key] = reactProps[key];\n }\n }\n // @ts-ignore Cannot instantiate an abstract class (Layer)\n return new LayerType(props);\n}\n"],"file":"extract-jsx-layers.js"}
1
+ {"version":3,"sources":["../../../src/utils/extract-jsx-layers.ts"],"names":["React","createElement","inheritsFrom","Layer","View","isComponent","wrapInView","node","Array","isArray","map","type","Fragment","props","children","extractJSXLayers","layers","views","reactChildren","jsxLayers","jsxViews","Children","forEach","reactElement","ElementType","layer","createLayer","push","id","view","Object","keys","length","values","LayerType","reactProps","defaultProps","key"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAAQC,aAAR,QAA4B,OAA5B;AACA,SAAQC,YAAR,QAA2B,iBAA3B;AACA,SAAQC,KAAR,EAAeC,IAAf,QAA0B,eAA1B;AACA,SAAQC,WAAR,QAA0B,qBAA1B;;AAiCA,SAASC,UAAT,CAAoBC,IAApB,EAAmF;AACjF,MAAI,OAAOA,IAAP,KAAgB,UAApB,EAAgC;AAI9B,WAAON,aAAa,CAACG,IAAD,EAAO,EAAP,EAAWG,IAAX,CAApB;AACD;;AACD,MAAIC,KAAK,CAACC,OAAN,CAAcF,IAAd,CAAJ,EAAyB;AACvB,WAAOA,IAAI,CAACG,GAAL,CAASJ,UAAT,CAAP;AACD;;AACD,MAAID,WAAW,CAACE,IAAD,CAAf,EAAuB;AACrB,QAAIA,IAAI,CAACI,IAAL,KAAcX,KAAK,CAACY,QAAxB,EAAkC;AAChC,aAAON,UAAU,CAACC,IAAI,CAACM,KAAL,CAAWC,QAAZ,CAAjB;AACD;;AACD,QAAIZ,YAAY,CAACK,IAAI,CAACI,IAAN,EAAYP,IAAZ,CAAhB,EAAmC;AACjC,aAAOG,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,OAAN,CAAcQ,KAAd,CAAJ,EAA0B;AACxBA,MAAAA,KAAK,CAACK,OAAN,CAAcO,IAAI,IAAI;AACpBT,QAAAA,QAAQ,CAACS,IAAI,CAACD,EAAN,CAAR,GAAoBC,IAApB;AACD,OAFD;AAGD,KAJD,MAIO,IAAIZ,KAAJ,EAAW;AAChBG,MAAAA,QAAQ,CAACH,KAAK,CAACW,EAAP,CAAR,GAAqBX,KAArB;AACD;;AACDA,IAAAA,KAAK,GAAGa,MAAM,CAACG,MAAP,CAAcb,QAAd,CAAR;AACD;;AAGDJ,EAAAA,MAAM,GAAGG,SAAS,CAACa,MAAV,GAAmB,CAAnB,GAAuB,CAAC,GAAGb,SAAJ,EAAe,GAAGH,MAAlB,CAAvB,GAAmDA,MAA5D;AAEA,SAAO;AAACA,IAAAA,MAAD;AAASF,IAAAA,QAAQ,EAAEI,aAAnB;AAAkCD,IAAAA;AAAlC,GAAP;AACD;;AAED,SAASS,WAAT,CAAqBQ,SAArB,EAA8CC,UAA9C,EAAsE;AACpE,QAAMtB,KAAK,GAAG,EAAd;AAGA,QAAMuB,YAAY,GAAGF,SAAS,CAACE,YAAV,IAA0B,EAA/C;;AACA,OAAK,MAAMC,GAAX,IAAkBF,UAAlB,EAA8B;AAC5B,QAAIC,YAAY,CAACC,GAAD,CAAZ,KAAsBF,UAAU,CAACE,GAAD,CAApC,EAA2C;AACzCxB,MAAAA,KAAK,CAACwB,GAAD,CAAL,GAAaF,UAAU,CAACE,GAAD,CAAvB;AACD;AACF;;AAED,SAAO,IAAIH,SAAJ,CAAcrB,KAAd,CAAP;AACD","sourcesContent":["import * as React from 'react';\nimport {createElement} from 'react';\nimport {inheritsFrom} from './inherits-from';\nimport {Layer, View} from '@deck.gl/core';\nimport {isComponent} from './evaluate-children';\nimport type {LayersList, Viewport} from '@deck.gl/core';\n\nexport type DeckGLRenderCallbackArgs = {\n /**\n * the left offset of the current view, in pixels\n */\n x: number;\n /**\n * the top offset of the current view, in pixels\n */\n y: number;\n /**\n * the width of the current view, in pixels\n */\n width: number;\n /**\n * the height of the current view, in pixels\n */\n height: number;\n /**\n * the view state of the current view\n */\n viewState: any;\n /**\n * the `Viewport` instance of the current view\n */\n viewport: Viewport;\n};\n\nexport type DeckGLRenderCallback = (args: DeckGLRenderCallbackArgs) => React.ReactNode;\n\n// recursively wrap render callbacks in `View`\nfunction wrapInView(node: React.ReactNode | DeckGLRenderCallback): React.ReactNode {\n if (typeof node === 'function') {\n // React.Children does not traverse functions.\n // All render callbacks must be protected under a <View>\n // @ts-expect-error View is not a ReactJSXElement constructor. Only used as a temporary wrapper and will be removed in extractJSXLayers\n return createElement(View, {}, node);\n }\n if (Array.isArray(node)) {\n return node.map(wrapInView);\n }\n if (isComponent(node)) {\n if (node.type === React.Fragment) {\n return wrapInView(node.props.children);\n }\n if (inheritsFrom(node.type, View)) {\n return node;\n }\n }\n return node;\n}\n\n// extracts any deck.gl layers masquerading as react elements from props.children\nexport default function extractJSXLayers({\n children,\n layers = [],\n views = null\n}: {\n children?: React.ReactNode | DeckGLRenderCallback;\n layers?: LayersList;\n views?: View | View[] | null;\n}): {\n children: React.ReactNode[];\n layers: LayersList;\n views: View | View[] | null;\n} {\n const reactChildren: React.ReactNode[] = []; // extract real react elements (i.e. not deck.gl layers)\n const jsxLayers: LayersList = []; // extracted layer from react children, will add to deck.gl layer array\n const jsxViews: Record<string, View> = {};\n\n // React.children\n React.Children.forEach(wrapInView(children), reactElement => {\n if (isComponent(reactElement)) {\n // For some reason Children.forEach doesn't filter out `null`s\n const ElementType = reactElement.type;\n if (inheritsFrom(ElementType, Layer)) {\n const layer = createLayer(ElementType, reactElement.props);\n jsxLayers.push(layer);\n } else {\n reactChildren.push(reactElement);\n }\n\n // empty id => default view\n if (inheritsFrom(ElementType, View) && ElementType !== View && reactElement.props.id) {\n // @ts-ignore Cannot instantiate an abstract class (View)\n const view = new ElementType(reactElement.props);\n jsxViews[view.id] = view;\n }\n } else if (reactElement) {\n reactChildren.push(reactElement);\n }\n });\n\n // Avoid modifying views if no JSX views were found\n if (Object.keys(jsxViews).length > 0) {\n // If a view is specified in both views prop and JSX, use the one in views\n if (Array.isArray(views)) {\n views.forEach(view => {\n jsxViews[view.id] = view;\n });\n } else if (views) {\n jsxViews[views.id] = views;\n }\n views = Object.values(jsxViews);\n }\n\n // Avoid modifying layers array if no JSX layers were found\n layers = jsxLayers.length > 0 ? [...jsxLayers, ...layers] : layers;\n\n return {layers, children: reactChildren, views};\n}\n\nfunction createLayer(LayerType: typeof Layer, reactProps: any): Layer {\n const props = {};\n // Layer.defaultProps is treated as ReactElement.defaultProps and merged into react props\n // Remove them\n const defaultProps = LayerType.defaultProps || {};\n for (const key in reactProps) {\n if (defaultProps[key] !== reactProps[key]) {\n props[key] = reactProps[key];\n }\n }\n // @ts-ignore Cannot instantiate an abstract class (Layer)\n return new LayerType(props);\n}\n"],"file":"extract-jsx-layers.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.9.27",
5
+ "version": "8.9.28",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
@@ -34,5 +34,5 @@
34
34
  "react": ">=16.3",
35
35
  "react-dom": ">=16.3"
36
36
  },
37
- "gitHead": "e4c46270eada99b9da393b4df3651f41242fce17"
37
+ "gitHead": "38540425fd51d99ef5958235448a7aaeef16556e"
38
38
  }
package/src/deckgl.ts CHANGED
@@ -30,7 +30,7 @@ import {
30
30
  import {Deck} from '@deck.gl/core';
31
31
  import useIsomorphicLayoutEffect from './utils/use-isomorphic-layout-effect';
32
32
 
33
- import extractJSXLayers from './utils/extract-jsx-layers';
33
+ import extractJSXLayers, {DeckGLRenderCallback} from './utils/extract-jsx-layers';
34
34
  import positionChildrenUnderViews from './utils/position-children-under-views';
35
35
  import extractStyles from './utils/extract-styles';
36
36
 
@@ -58,7 +58,7 @@ export type DeckGLProps = Omit<
58
58
  Deck?: typeof Deck;
59
59
  width?: string | number;
60
60
  height?: string | number;
61
- children?: React.ReactNode;
61
+ children?: React.ReactNode | DeckGLRenderCallback;
62
62
  ContextProvider?: React.Context<DeckGLContextValue>['Provider'];
63
63
  };
64
64
 
@@ -3,10 +3,39 @@ import {createElement} from 'react';
3
3
  import {inheritsFrom} from './inherits-from';
4
4
  import {Layer, View} from '@deck.gl/core';
5
5
  import {isComponent} from './evaluate-children';
6
- import type {LayersList} from '@deck.gl/core';
6
+ import type {LayersList, Viewport} from '@deck.gl/core';
7
+
8
+ export type DeckGLRenderCallbackArgs = {
9
+ /**
10
+ * the left offset of the current view, in pixels
11
+ */
12
+ x: number;
13
+ /**
14
+ * the top offset of the current view, in pixels
15
+ */
16
+ y: number;
17
+ /**
18
+ * the width of the current view, in pixels
19
+ */
20
+ width: number;
21
+ /**
22
+ * the height of the current view, in pixels
23
+ */
24
+ height: number;
25
+ /**
26
+ * the view state of the current view
27
+ */
28
+ viewState: any;
29
+ /**
30
+ * the `Viewport` instance of the current view
31
+ */
32
+ viewport: Viewport;
33
+ };
34
+
35
+ export type DeckGLRenderCallback = (args: DeckGLRenderCallbackArgs) => React.ReactNode;
7
36
 
8
37
  // recursively wrap render callbacks in `View`
9
- function wrapInView(node: React.ReactNode): React.ReactNode {
38
+ function wrapInView(node: React.ReactNode | DeckGLRenderCallback): React.ReactNode {
10
39
  if (typeof node === 'function') {
11
40
  // React.Children does not traverse functions.
12
41
  // All render callbacks must be protected under a <View>
@@ -33,7 +62,7 @@ export default function extractJSXLayers({
33
62
  layers = [],
34
63
  views = null
35
64
  }: {
36
- children?: React.ReactNode;
65
+ children?: React.ReactNode | DeckGLRenderCallback;
37
66
  layers?: LayersList;
38
67
  views?: View | View[] | null;
39
68
  }): {
package/typed/deckgl.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Deck } from '@deck.gl/core/typed';
3
+ import { DeckGLRenderCallback } from './utils/extract-jsx-layers';
3
4
  import type { DeckGLContextValue } from './utils/position-children-under-views';
4
5
  import type { DeckProps } from '@deck.gl/core/typed';
5
6
  /** DeckGL React component props */
@@ -7,7 +8,7 @@ export declare type DeckGLProps = Omit<DeckProps, 'width' | 'height' | 'gl' | 'p
7
8
  Deck?: typeof Deck;
8
9
  width?: string | number;
9
10
  height?: string | number;
10
- children?: React.ReactNode;
11
+ children?: React.ReactNode | DeckGLRenderCallback;
11
12
  ContextProvider?: React.Context<DeckGLContextValue>['Provider'];
12
13
  };
13
14
  export declare type DeckGLRef = {
@@ -20,7 +21,7 @@ declare const DeckGL: React.ForwardRefExoticComponent<Omit<DeckProps, "canvas" |
20
21
  Deck?: typeof Deck | undefined;
21
22
  width?: string | number | undefined;
22
23
  height?: string | number | undefined;
23
- children?: React.ReactNode;
24
+ children?: React.ReactNode | DeckGLRenderCallback;
24
25
  ContextProvider?: React.Provider<DeckGLContextValue> | undefined;
25
26
  } & React.RefAttributes<DeckGLRef>>;
26
27
  export default DeckGL;
@@ -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,IAAI,CAAC,EAAE,OAAO,IAAI,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CA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AAI,CAAC,EAAE,IAAI,CAAC;IACZ,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAC/B,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACjC,mBAAmB,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;CAClD,CAAC;AAqDF,QAAA,MAAM,MAAM;;;;eA9DC,MAAM,SAAS,GAAG,oBAAoB;;mCAwNjD,CAAC;AAIH,eAAe,MAAM,CAAC"}
@@ -1,8 +1,35 @@
1
1
  import * as React from 'react';
2
2
  import { View } from '@deck.gl/core/typed';
3
- import type { LayersList } from '@deck.gl/core/typed';
3
+ import type { LayersList, Viewport } from '@deck.gl/core/typed';
4
+ export declare type DeckGLRenderCallbackArgs = {
5
+ /**
6
+ * the left offset of the current view, in pixels
7
+ */
8
+ x: number;
9
+ /**
10
+ * the top offset of the current view, in pixels
11
+ */
12
+ y: number;
13
+ /**
14
+ * the width of the current view, in pixels
15
+ */
16
+ width: number;
17
+ /**
18
+ * the height of the current view, in pixels
19
+ */
20
+ height: number;
21
+ /**
22
+ * the view state of the current view
23
+ */
24
+ viewState: any;
25
+ /**
26
+ * the `Viewport` instance of the current view
27
+ */
28
+ viewport: Viewport;
29
+ };
30
+ export declare type DeckGLRenderCallback = (args: DeckGLRenderCallbackArgs) => React.ReactNode;
4
31
  export default function extractJSXLayers({ children, layers, views }: {
5
- children?: React.ReactNode;
32
+ children?: React.ReactNode | DeckGLRenderCallback;
6
33
  layers?: LayersList;
7
34
  views?: View | View[] | null;
8
35
  }): {
@@ -1 +1 @@
1
- {"version":3,"file":"extract-jsx-layers.d.ts","sourceRoot":"","sources":["../../src/utils/extract-jsx-layers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAQ,IAAI,EAAC,MAAM,eAAe,CAAC;AAE1C,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAyB9C,MAAM,CAAC,OAA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