@deck.gl/react 8.8.22 → 8.8.23
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.
- package/package.json +2 -2
- package/typed/deckgl.js +0 -194
- package/typed/index.js +0 -21
- package/typed/utils/evaluate-children.js +0 -33
- package/typed/utils/extract-jsx-layers.js +0 -77
- package/typed/utils/extract-styles.js +0 -32
- package/typed/utils/inherits-from.js +0 -10
- package/typed/utils/position-children-under-views.js +0 -75
- package/typed/utils/use-isomorphic-layout-effect.js +0 -5
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.
|
|
5
|
+
"version": "8.8.23",
|
|
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": "
|
|
34
|
+
"gitHead": "b2fed6c73de5fe21d4198f9c42cf387e0e08ac6a"
|
|
35
35
|
}
|
package/typed/deckgl.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
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
|
-
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
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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';
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
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,5 +0,0 @@
|
|
|
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;
|