@deck.gl/react 8.8.0-alpha.6 → 8.8.0-beta.3
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/dist/es5/deckgl.js +38 -24
- package/dist/es5/deckgl.js.map +1 -1
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/utils/evaluate-children.js +19 -12
- package/dist/es5/utils/evaluate-children.js.map +1 -1
- package/dist/es5/utils/extract-jsx-layers.js +20 -17
- package/dist/es5/utils/extract-jsx-layers.js.map +1 -1
- package/dist/es5/utils/extract-styles.js.map +1 -1
- package/dist/es5/utils/inherits-from.js.map +1 -1
- package/dist/es5/utils/position-children-under-views.js +8 -2
- package/dist/es5/utils/position-children-under-views.js.map +1 -1
- package/dist/es5/utils/use-isomorphic-layout-effect.js.map +1 -1
- package/dist/esm/deckgl.js +31 -17
- package/dist/esm/deckgl.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/evaluate-children.js +13 -12
- package/dist/esm/utils/evaluate-children.js.map +1 -1
- package/dist/esm/utils/extract-jsx-layers.js +16 -14
- package/dist/esm/utils/extract-jsx-layers.js.map +1 -1
- package/dist/esm/utils/extract-styles.js.map +1 -1
- package/dist/esm/utils/inherits-from.js.map +1 -1
- package/dist/esm/utils/position-children-under-views.js +2 -2
- package/dist/esm/utils/position-children-under-views.js.map +1 -1
- package/dist/esm/utils/use-isomorphic-layout-effect.js.map +1 -1
- package/package.json +3 -2
- package/src/{deckgl.js → deckgl.ts} +68 -27
- package/src/{index.js → index.ts} +4 -0
- package/src/utils/evaluate-children.ts +47 -0
- package/src/utils/{extract-jsx-layers.js → extract-jsx-layers.ts} +36 -17
- package/src/utils/{extract-styles.js → extract-styles.ts} +16 -3
- package/src/utils/{inherits-from.js → inherits-from.ts} +1 -1
- package/src/utils/{position-children-under-views.js → position-children-under-views.ts} +36 -7
- package/src/utils/{use-isomorphic-layout-effect.js → use-isomorphic-layout-effect.ts} +0 -0
- package/typed/deckgl.d.ts +23 -1
- package/typed/deckgl.d.ts.map +1 -1
- package/typed/index.d.ts +4 -1
- package/typed/index.d.ts.map +1 -1
- package/typed/utils/evaluate-children.d.ts +3 -1
- package/typed/utils/evaluate-children.d.ts.map +1 -1
- package/typed/utils/extract-jsx-layers.d.ts +9 -6
- package/typed/utils/extract-jsx-layers.d.ts.map +1 -1
- package/typed/utils/extract-styles.d.ts +6 -15
- package/typed/utils/extract-styles.d.ts.map +1 -1
- package/typed/utils/inherits-from.d.ts +1 -1
- package/typed/utils/inherits-from.d.ts.map +1 -1
- package/typed/utils/position-children-under-views.d.ts +13 -4
- package/typed/utils/position-children-under-views.d.ts.map +1 -1
- package/typed/utils/use-isomorphic-layout-effect.d.ts +2 -1
- package/typed/utils/use-isomorphic-layout-effect.d.ts.map +1 -1
- package/src/utils/evaluate-children.js +0 -38
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
18
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
19
|
// THE SOFTWARE.
|
|
20
|
-
|
|
20
|
+
import * as React from 'react';
|
|
21
21
|
import {
|
|
22
22
|
createElement,
|
|
23
23
|
useRef,
|
|
@@ -34,29 +34,62 @@ import extractJSXLayers 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
|
|
|
37
|
+
import type {DeckGLContextValue} from './utils/position-children-under-views';
|
|
38
|
+
import type {DeckProps, Viewport} from '@deck.gl/core';
|
|
39
|
+
|
|
37
40
|
/* eslint-disable max-statements, accessor-pairs */
|
|
41
|
+
type DeckInstanceRef = {
|
|
42
|
+
deck?: Deck;
|
|
43
|
+
redrawReason?: string | null;
|
|
44
|
+
lastRenderedViewports?: Viewport[];
|
|
45
|
+
viewStateUpdateRequested?: any;
|
|
46
|
+
interactionStateUpdateRequested?: any;
|
|
47
|
+
forceUpdate: () => void;
|
|
48
|
+
version: number;
|
|
49
|
+
control: React.ReactHTMLElement<HTMLElement> | null;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Remove prop types in the base Deck class that support externally supplied canvas/WebGLContext
|
|
53
|
+
/** DeckGL React component props */
|
|
54
|
+
export type DeckGLProps = Omit<
|
|
55
|
+
DeckProps,
|
|
56
|
+
'width' | 'height' | 'gl' | 'parent' | 'canvas' | '_customRender'
|
|
57
|
+
> & {
|
|
58
|
+
width?: string | number;
|
|
59
|
+
height?: string | number;
|
|
60
|
+
children?: React.ReactNode;
|
|
61
|
+
ContextProvider?: React.Context<DeckGLContextValue>['Provider'];
|
|
62
|
+
};
|
|
38
63
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
64
|
+
export type DeckGLRef = {
|
|
65
|
+
deck?: Deck;
|
|
66
|
+
pickObject: Deck['pickObject'];
|
|
67
|
+
pickObjects: Deck['pickObjects'];
|
|
68
|
+
pickMultipleObjects: Deck['pickMultipleObjects'];
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
function getRefHandles(thisRef: DeckInstanceRef): DeckGLRef {
|
|
72
|
+
return {
|
|
73
|
+
get deck() {
|
|
74
|
+
return thisRef.deck;
|
|
75
|
+
},
|
|
76
|
+
// The following method can only be called after ref is available, by which point deck is defined in useEffect
|
|
77
|
+
pickObject: opts => thisRef.deck!.pickObject(opts),
|
|
78
|
+
pickMultipleObjects: opts => thisRef.deck!.pickMultipleObjects(opts),
|
|
79
|
+
pickObjects: opts => thisRef.deck!.pickObjects(opts)
|
|
44
80
|
};
|
|
45
|
-
Object.defineProperty(handles, 'deck', {
|
|
46
|
-
get: () => thisRef.deck
|
|
47
|
-
});
|
|
48
|
-
return handles;
|
|
49
81
|
}
|
|
50
82
|
|
|
51
|
-
function redrawDeck(thisRef) {
|
|
83
|
+
function redrawDeck(thisRef: DeckInstanceRef) {
|
|
52
84
|
if (thisRef.redrawReason) {
|
|
53
85
|
// Only redraw if we have received a dirty flag
|
|
86
|
+
// @ts-expect-error accessing protected method
|
|
54
87
|
thisRef.deck._drawLayers(thisRef.redrawReason);
|
|
55
88
|
thisRef.redrawReason = null;
|
|
56
89
|
}
|
|
57
90
|
}
|
|
58
91
|
|
|
59
|
-
function createDeckInstance(thisRef, props) {
|
|
92
|
+
function createDeckInstance(thisRef: DeckInstanceRef, props): Deck {
|
|
60
93
|
// Allows a subclass of Deck to be used
|
|
61
94
|
// TODO - update propTypes / defaultProps?
|
|
62
95
|
const DeckClass = props.Deck || Deck;
|
|
@@ -79,7 +112,7 @@ function createDeckInstance(thisRef, props) {
|
|
|
79
112
|
// Viewports have changed, update children props first.
|
|
80
113
|
// This will delay the Deck canvas redraw till after React update (in useLayoutEffect)
|
|
81
114
|
// so that the canvas does not get rendered before the child components update.
|
|
82
|
-
thisRef.forceUpdate(
|
|
115
|
+
thisRef.forceUpdate();
|
|
83
116
|
} else {
|
|
84
117
|
redrawDeck(thisRef);
|
|
85
118
|
}
|
|
@@ -88,13 +121,16 @@ function createDeckInstance(thisRef, props) {
|
|
|
88
121
|
return deck;
|
|
89
122
|
}
|
|
90
123
|
|
|
91
|
-
const DeckGL = forwardRef((props, ref) => {
|
|
92
|
-
// A reference to persistent states
|
|
93
|
-
const _thisRef = useRef({});
|
|
94
|
-
const thisRef = _thisRef.current;
|
|
124
|
+
const DeckGL = forwardRef<DeckGLRef, DeckGLProps>((props, ref) => {
|
|
95
125
|
// A mechanism to force redraw
|
|
96
126
|
const [version, setVersion] = useState(0);
|
|
97
|
-
|
|
127
|
+
// A reference to persistent states
|
|
128
|
+
const _thisRef = useRef<DeckInstanceRef>({
|
|
129
|
+
control: null,
|
|
130
|
+
version,
|
|
131
|
+
forceUpdate: () => setVersion(v => v + 1)
|
|
132
|
+
});
|
|
133
|
+
const thisRef = _thisRef.current;
|
|
98
134
|
// DOM refs
|
|
99
135
|
const containerRef = useRef(null);
|
|
100
136
|
const canvasRef = useRef(null);
|
|
@@ -108,7 +144,7 @@ const DeckGL = forwardRef((props, ref) => {
|
|
|
108
144
|
// Callbacks
|
|
109
145
|
let inRender = true;
|
|
110
146
|
|
|
111
|
-
const handleViewStateChange = params => {
|
|
147
|
+
const handleViewStateChange: DeckProps['onViewStateChange'] = params => {
|
|
112
148
|
if (inRender && props.viewState) {
|
|
113
149
|
// Callback may invoke a state update. Defer callback to after render() to avoid React error
|
|
114
150
|
// In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once
|
|
@@ -117,10 +153,10 @@ const DeckGL = forwardRef((props, ref) => {
|
|
|
117
153
|
return null;
|
|
118
154
|
}
|
|
119
155
|
thisRef.viewStateUpdateRequested = null;
|
|
120
|
-
return props.onViewStateChange(params);
|
|
156
|
+
return props.onViewStateChange?.(params);
|
|
121
157
|
};
|
|
122
158
|
|
|
123
|
-
const handleInteractionStateChange = params => {
|
|
159
|
+
const handleInteractionStateChange: DeckProps['onInteractionStateChange'] = params => {
|
|
124
160
|
if (inRender) {
|
|
125
161
|
// Callback may invoke a state update. Defer callback to after render() to avoid React error
|
|
126
162
|
// In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once
|
|
@@ -128,7 +164,7 @@ const DeckGL = forwardRef((props, ref) => {
|
|
|
128
164
|
thisRef.interactionStateUpdateRequested = params;
|
|
129
165
|
} else {
|
|
130
166
|
thisRef.interactionStateUpdateRequested = null;
|
|
131
|
-
props.onInteractionStateChange(params);
|
|
167
|
+
props.onInteractionStateChange?.(params);
|
|
132
168
|
}
|
|
133
169
|
};
|
|
134
170
|
|
|
@@ -136,7 +172,7 @@ const DeckGL = forwardRef((props, ref) => {
|
|
|
136
172
|
// the next animation frame.
|
|
137
173
|
// Needs to be called both from initial mount, and when new props are received
|
|
138
174
|
const deckProps = useMemo(() => {
|
|
139
|
-
const forwardProps = {
|
|
175
|
+
const forwardProps: DeckProps = {
|
|
140
176
|
...props,
|
|
141
177
|
// Override user styling props. We will set the canvas style in render()
|
|
142
178
|
style: null,
|
|
@@ -159,14 +195,20 @@ const DeckGL = forwardRef((props, ref) => {
|
|
|
159
195
|
return forwardProps;
|
|
160
196
|
}, [props]);
|
|
161
197
|
|
|
198
|
+
const [isDeckLoaded, setIsDeckLoaded] = useState(false);
|
|
199
|
+
|
|
162
200
|
useEffect(() => {
|
|
163
201
|
thisRef.deck = createDeckInstance(thisRef, {
|
|
164
202
|
...deckProps,
|
|
165
203
|
parent: containerRef.current,
|
|
166
|
-
canvas: canvasRef.current
|
|
204
|
+
canvas: canvasRef.current,
|
|
205
|
+
onLoad: () => {
|
|
206
|
+
setIsDeckLoaded(true);
|
|
207
|
+
if (deckProps.onLoad) deckProps.onLoad();
|
|
208
|
+
}
|
|
167
209
|
});
|
|
168
210
|
|
|
169
|
-
return () => thisRef.deck
|
|
211
|
+
return () => thisRef.deck?.finalize();
|
|
170
212
|
}, []);
|
|
171
213
|
|
|
172
214
|
useIsomorphicLayoutEffect(() => {
|
|
@@ -187,8 +229,7 @@ const DeckGL = forwardRef((props, ref) => {
|
|
|
187
229
|
|
|
188
230
|
useImperativeHandle(ref, () => getRefHandles(thisRef), []);
|
|
189
231
|
|
|
190
|
-
const
|
|
191
|
-
const currentViewports = viewManager && viewManager.getViewports();
|
|
232
|
+
const currentViewports = thisRef.deck && isDeckLoaded ? thisRef.deck.getViewports() : undefined;
|
|
192
233
|
|
|
193
234
|
const {ContextProvider, width, height, id, style} = props;
|
|
194
235
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {cloneElement} from 'react';
|
|
3
|
+
|
|
4
|
+
const MAP_STYLE = {position: 'absolute', zIndex: -1};
|
|
5
|
+
|
|
6
|
+
export default function evaluateChildren(
|
|
7
|
+
children: React.ReactNode,
|
|
8
|
+
childProps: any
|
|
9
|
+
): React.ReactNode {
|
|
10
|
+
if (typeof children === 'function') {
|
|
11
|
+
return children(childProps);
|
|
12
|
+
}
|
|
13
|
+
if (Array.isArray(children)) {
|
|
14
|
+
return children.map(child => evaluateChildren(child, childProps));
|
|
15
|
+
}
|
|
16
|
+
if (isComponent(children)) {
|
|
17
|
+
// Special treatment for react-map-gl's Map component
|
|
18
|
+
// to support shorthand use case <DeckGL><StaticMap /></DeckGL>
|
|
19
|
+
if (isReactMap(children)) {
|
|
20
|
+
// Place map under the canvas
|
|
21
|
+
childProps.style = MAP_STYLE;
|
|
22
|
+
return cloneElement(children, childProps);
|
|
23
|
+
}
|
|
24
|
+
if (needsDeckGLViewProps(children)) {
|
|
25
|
+
return cloneElement(children, childProps);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return children;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function isComponent(child: React.ReactNode): child is React.ReactElement {
|
|
33
|
+
return (child && typeof child === 'object' && 'type' in child) || false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isReactMap(child: React.ReactElement): boolean {
|
|
37
|
+
const componentClass = child.type;
|
|
38
|
+
// @ts-expect-error defaultProps is not defined on JSXElementConstructor
|
|
39
|
+
const componentProps = componentClass && componentClass.defaultProps;
|
|
40
|
+
return componentProps && componentProps.mapStyle;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function needsDeckGLViewProps(child: React.ReactElement): boolean {
|
|
44
|
+
const componentClass = child.type;
|
|
45
|
+
// @ts-expect-error deckGLViewProps is a custom hack defined on the constructor (nebula.gl)
|
|
46
|
+
return componentClass && componentClass.deckGLViewProps;
|
|
47
|
+
}
|
|
@@ -1,38 +1,53 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {createElement} from 'react';
|
|
2
3
|
import {inheritsFrom} from './inherits-from';
|
|
3
4
|
import {Layer, View} from '@deck.gl/core';
|
|
5
|
+
import {isComponent} from './evaluate-children';
|
|
6
|
+
import type {LayersList} from '@deck.gl/core';
|
|
4
7
|
|
|
5
8
|
// recursively wrap render callbacks in `View`
|
|
6
|
-
function wrapInView(node) {
|
|
7
|
-
if (!node) {
|
|
8
|
-
return node;
|
|
9
|
-
}
|
|
9
|
+
function wrapInView(node: React.ReactNode): React.ReactNode {
|
|
10
10
|
if (typeof node === 'function') {
|
|
11
11
|
// React.Children does not traverse functions.
|
|
12
12
|
// All render callbacks must be protected under a <View>
|
|
13
|
+
// @ts-expect-error View is not a ReactJSXElement constructor. Only used as a temporary wrapper and will be removed in extractJSXLayers
|
|
13
14
|
return createElement(View, {}, node);
|
|
14
15
|
}
|
|
15
16
|
if (Array.isArray(node)) {
|
|
16
17
|
return node.map(wrapInView);
|
|
17
18
|
}
|
|
18
|
-
if (node
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
if (isComponent(node)) {
|
|
20
|
+
if (node.type === React.Fragment) {
|
|
21
|
+
return wrapInView(node.props.children);
|
|
22
|
+
}
|
|
23
|
+
if (inheritsFrom(node.type, View)) {
|
|
24
|
+
return node;
|
|
25
|
+
}
|
|
23
26
|
}
|
|
24
27
|
return node;
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
// extracts any deck.gl layers masquerading as react elements from props.children
|
|
28
|
-
export default function extractJSXLayers({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
export default function extractJSXLayers({
|
|
32
|
+
children,
|
|
33
|
+
layers = [],
|
|
34
|
+
views = null
|
|
35
|
+
}: {
|
|
36
|
+
children?: React.ReactNode;
|
|
37
|
+
layers?: LayersList;
|
|
38
|
+
views?: View | View[] | null;
|
|
39
|
+
}): {
|
|
40
|
+
children: React.ReactNode[];
|
|
41
|
+
layers: LayersList;
|
|
42
|
+
views: View | View[] | null;
|
|
43
|
+
} {
|
|
44
|
+
const reactChildren: React.ReactNode[] = []; // extract real react elements (i.e. not deck.gl layers)
|
|
45
|
+
const jsxLayers: LayersList = []; // extracted layer from react children, will add to deck.gl layer array
|
|
46
|
+
const jsxViews: Record<string, View> = {};
|
|
32
47
|
|
|
33
48
|
// React.children
|
|
34
49
|
React.Children.forEach(wrapInView(children), reactElement => {
|
|
35
|
-
if (reactElement) {
|
|
50
|
+
if (isComponent(reactElement)) {
|
|
36
51
|
// For some reason Children.forEach doesn't filter out `null`s
|
|
37
52
|
const ElementType = reactElement.type;
|
|
38
53
|
if (inheritsFrom(ElementType, Layer)) {
|
|
@@ -43,10 +58,13 @@ export default function extractJSXLayers({children, layers, views}) {
|
|
|
43
58
|
}
|
|
44
59
|
|
|
45
60
|
// empty id => default view
|
|
46
|
-
if (ElementType
|
|
61
|
+
if (inheritsFrom(ElementType, View) && ElementType !== View && reactElement.props.id) {
|
|
62
|
+
// @ts-ignore Cannot instantiate an abstract class (View)
|
|
47
63
|
const view = new ElementType(reactElement.props);
|
|
48
64
|
jsxViews[view.id] = view;
|
|
49
65
|
}
|
|
66
|
+
} else if (reactElement) {
|
|
67
|
+
reactChildren.push(reactElement);
|
|
50
68
|
}
|
|
51
69
|
});
|
|
52
70
|
|
|
@@ -69,7 +87,7 @@ export default function extractJSXLayers({children, layers, views}) {
|
|
|
69
87
|
return {layers, children: reactChildren, views};
|
|
70
88
|
}
|
|
71
89
|
|
|
72
|
-
function createLayer(LayerType, reactProps) {
|
|
90
|
+
function createLayer(LayerType: typeof Layer, reactProps: any): Layer {
|
|
73
91
|
const props = {};
|
|
74
92
|
// Layer.defaultProps is treated as ReactElement.defaultProps and merged into react props
|
|
75
93
|
// Remove them
|
|
@@ -79,5 +97,6 @@ function createLayer(LayerType, reactProps) {
|
|
|
79
97
|
props[key] = reactProps[key];
|
|
80
98
|
}
|
|
81
99
|
}
|
|
100
|
+
// @ts-ignore Cannot instantiate an abstract class (Layer)
|
|
82
101
|
return new LayerType(props);
|
|
83
102
|
}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
1
3
|
const CANVAS_ONLY_STYLES = {
|
|
2
4
|
mixBlendMode: null
|
|
3
5
|
};
|
|
4
6
|
|
|
5
|
-
export default function extractStyles({
|
|
7
|
+
export default function extractStyles({
|
|
8
|
+
width,
|
|
9
|
+
height,
|
|
10
|
+
style
|
|
11
|
+
}: {
|
|
12
|
+
width?: string | number;
|
|
13
|
+
height?: string | number;
|
|
14
|
+
style?: Partial<CSSStyleDeclaration> | null;
|
|
15
|
+
}): {
|
|
16
|
+
containerStyle: React.CSSProperties;
|
|
17
|
+
canvasStyle: React.CSSProperties;
|
|
18
|
+
} {
|
|
6
19
|
// This styling is enforced for correct positioning with children
|
|
7
|
-
const containerStyle = {
|
|
20
|
+
const containerStyle: React.CSSProperties = {
|
|
8
21
|
position: 'absolute',
|
|
9
22
|
zIndex: 0,
|
|
10
23
|
left: 0,
|
|
@@ -14,7 +27,7 @@ export default function extractStyles({width, height, style}) {
|
|
|
14
27
|
};
|
|
15
28
|
|
|
16
29
|
// Fill the container
|
|
17
|
-
const canvasStyle = {
|
|
30
|
+
const canvasStyle: React.CSSProperties = {
|
|
18
31
|
left: 0,
|
|
19
32
|
top: 0
|
|
20
33
|
};
|
|
@@ -1,19 +1,45 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
import {createElement} from 'react';
|
|
2
3
|
import {View} from '@deck.gl/core';
|
|
3
4
|
import {inheritsFrom} from './inherits-from';
|
|
4
|
-
import evaluateChildren from './evaluate-children';
|
|
5
|
+
import evaluateChildren, {isComponent} from './evaluate-children';
|
|
6
|
+
|
|
7
|
+
import type {Deck, DeckProps, Viewport} from '@deck.gl/core';
|
|
8
|
+
import type {EventManager} from 'mjolnir.js';
|
|
9
|
+
|
|
10
|
+
export type DeckGLContextValue = {
|
|
11
|
+
viewport: Viewport;
|
|
12
|
+
container: HTMLElement;
|
|
13
|
+
eventManager: EventManager;
|
|
14
|
+
onViewStateChange: DeckProps['onViewStateChange'];
|
|
15
|
+
};
|
|
5
16
|
|
|
6
17
|
// Iterate over views and reposition children associated with views
|
|
7
18
|
// TODO - Can we supply a similar function for the non-React case?
|
|
8
|
-
export default function positionChildrenUnderViews({
|
|
19
|
+
export default function positionChildrenUnderViews({
|
|
20
|
+
children,
|
|
21
|
+
deck,
|
|
22
|
+
ContextProvider
|
|
23
|
+
}: {
|
|
24
|
+
children: React.ReactNode[];
|
|
25
|
+
deck?: Deck;
|
|
26
|
+
ContextProvider?: React.Context<DeckGLContextValue>['Provider'];
|
|
27
|
+
}): React.ReactNode[] {
|
|
28
|
+
// @ts-expect-error accessing protected property
|
|
9
29
|
const {viewManager} = deck || {};
|
|
10
30
|
|
|
11
31
|
if (!viewManager || !viewManager.views.length) {
|
|
12
32
|
return [];
|
|
13
33
|
}
|
|
14
34
|
|
|
15
|
-
const views
|
|
16
|
-
|
|
35
|
+
const views: Record<
|
|
36
|
+
string,
|
|
37
|
+
{
|
|
38
|
+
viewport: Viewport;
|
|
39
|
+
children: React.ReactNode[];
|
|
40
|
+
}
|
|
41
|
+
> = {};
|
|
42
|
+
const defaultViewId = (viewManager.views[0] as View).id;
|
|
17
43
|
|
|
18
44
|
// Sort children by view id
|
|
19
45
|
for (const child of children) {
|
|
@@ -21,12 +47,12 @@ export default function positionChildrenUnderViews({children, deck, ContextProvi
|
|
|
21
47
|
let viewId = defaultViewId;
|
|
22
48
|
let viewChildren = child;
|
|
23
49
|
|
|
24
|
-
if (inheritsFrom(child.type, View)) {
|
|
50
|
+
if (isComponent(child) && inheritsFrom(child.type, View)) {
|
|
25
51
|
viewId = child.props.id || defaultViewId;
|
|
26
52
|
viewChildren = child.props.children;
|
|
27
53
|
}
|
|
28
54
|
|
|
29
|
-
const viewport = viewManager.getViewport(viewId);
|
|
55
|
+
const viewport = viewManager.getViewport(viewId) as Viewport;
|
|
30
56
|
const viewState = viewManager.getViewState(viewId);
|
|
31
57
|
|
|
32
58
|
// Drop (auto-hide) elements with viewId that are not matched by any current view
|
|
@@ -70,12 +96,15 @@ export default function positionChildrenUnderViews({children, deck, ContextProvi
|
|
|
70
96
|
const viewElement = createElement('div', {key, id: key, style}, ...viewChildren);
|
|
71
97
|
|
|
72
98
|
if (ContextProvider) {
|
|
73
|
-
const contextValue = {
|
|
99
|
+
const contextValue: DeckGLContextValue = {
|
|
74
100
|
viewport,
|
|
101
|
+
// @ts-expect-error accessing protected property
|
|
75
102
|
container: deck.canvas.offsetParent,
|
|
103
|
+
// @ts-expect-error accessing protected property
|
|
76
104
|
eventManager: deck.eventManager,
|
|
77
105
|
onViewStateChange: params => {
|
|
78
106
|
params.viewId = viewId;
|
|
107
|
+
// @ts-expect-error accessing protected method
|
|
79
108
|
deck._onViewStateChange(params);
|
|
80
109
|
}
|
|
81
110
|
};
|
|
File without changes
|
package/typed/deckgl.d.ts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Deck } from '@deck.gl/core/typed';
|
|
3
|
+
import type { DeckGLContextValue } from './utils/position-children-under-views';
|
|
4
|
+
import type { DeckProps } from '@deck.gl/core/typed';
|
|
5
|
+
/** DeckGL React component props */
|
|
6
|
+
export declare type DeckGLProps = Omit<DeckProps, 'width' | 'height' | 'gl' | 'parent' | 'canvas' | '_customRender'> & {
|
|
7
|
+
width?: string | number;
|
|
8
|
+
height?: string | number;
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
ContextProvider?: React.Context<DeckGLContextValue>['Provider'];
|
|
11
|
+
};
|
|
12
|
+
export declare type DeckGLRef = {
|
|
13
|
+
deck?: Deck;
|
|
14
|
+
pickObject: Deck['pickObject'];
|
|
15
|
+
pickObjects: Deck['pickObjects'];
|
|
16
|
+
pickMultipleObjects: Deck['pickMultipleObjects'];
|
|
17
|
+
};
|
|
18
|
+
declare const DeckGL: React.ForwardRefExoticComponent<Omit<DeckProps, "canvas" | "width" | "height" | "gl" | "parent" | "_customRender"> & {
|
|
19
|
+
width?: string | number | undefined;
|
|
20
|
+
height?: string | number | undefined;
|
|
21
|
+
children?: React.ReactNode;
|
|
22
|
+
ContextProvider?: React.Provider<DeckGLContextValue> | undefined;
|
|
23
|
+
} & React.RefAttributes<DeckGLRef>>;
|
|
1
24
|
export default DeckGL;
|
|
2
|
-
declare const DeckGL: any;
|
|
3
25
|
//# sourceMappingURL=deckgl.d.ts.map
|
package/typed/deckgl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deckgl.d.ts","sourceRoot":"","sources":["../src/deckgl.
|
|
1
|
+
{"version":3,"file":"deckgl.d.ts","sourceRoot":"","sources":["../src/deckgl.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,OAAO,EAAC,IAAI,EAAC,MAAM,eAAe,CAAC;AAOnC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,uCAAuC,CAAC;AAC9E,OAAO,KAAK,EAAC,SAAS,EAAW,MAAM,eAAe,CAAC;AAevD,mCAAmC;AACnC,oBAAY,WAAW,GAAG,IAAI,CAC5B,SAAS,EACT,OAAO,GAAG,QAAQ,GAAG,IAAI,GAAG,QAAQ,GAAG,QAAQ,GAAG,eAAe,CAClE,GAAG;IACF,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,eAAe,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC;CACjE,CAAC;AAEF,oBAAY,SAAS,GAAG;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAC/B,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACjC,mBAAmB,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;CAClD,CAAC;AAuDF,QAAA,MAAM,MAAM;;;eAhEC,MAAM,SAAS;;mCA2N1B,CAAC;AAIH,eAAe,MAAM,CAAC"}
|
package/typed/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export { default as DeckGL
|
|
1
|
+
export { default as DeckGL } from './deckgl';
|
|
2
|
+
export { default } from './deckgl';
|
|
3
|
+
export type { DeckGLContextValue } from './utils/position-children-under-views';
|
|
4
|
+
export type { DeckGLRef, DeckGLProps } from './deckgl';
|
|
2
5
|
//# sourceMappingURL=index.d.ts.map
|
package/typed/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AAGjC,YAAY,EAAC,kBAAkB,EAAC,MAAM,uCAAuC,CAAC;AAC9E,YAAY,EAAC,SAAS,EAAE,WAAW,EAAC,MAAM,UAAU,CAAC"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export default function evaluateChildren(children: React.ReactNode, childProps: any): React.ReactNode;
|
|
3
|
+
export declare function isComponent(child: React.ReactNode): child is React.ReactElement;
|
|
2
4
|
//# sourceMappingURL=evaluate-children.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate-children.d.ts","sourceRoot":"","sources":["../../src/utils/evaluate-children.
|
|
1
|
+
{"version":3,"file":"evaluate-children.d.ts","sourceRoot":"","sources":["../../src/utils/evaluate-children.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,UAAU,EAAE,GAAG,GACd,KAAK,CAAC,SAAS,CAqBjB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,GAAG,KAAK,IAAI,KAAK,CAAC,YAAY,CAE/E"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View } from '@deck.gl/core/typed';
|
|
3
|
+
import type { LayersList } from '@deck.gl/core/typed';
|
|
1
4
|
export default function extractJSXLayers({ children, layers, views }: {
|
|
2
|
-
children
|
|
3
|
-
layers
|
|
4
|
-
views
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
layers?: LayersList;
|
|
7
|
+
views?: View | View[] | null;
|
|
5
8
|
}): {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
views:
|
|
9
|
+
children: React.ReactNode[];
|
|
10
|
+
layers: LayersList;
|
|
11
|
+
views: View | View[] | null;
|
|
9
12
|
};
|
|
10
13
|
//# sourceMappingURL=extract-jsx-layers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-jsx-layers.d.ts","sourceRoot":"","sources":["../../src/utils/extract-jsx-layers.
|
|
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,OAAO,UAAU,gBAAgB,CAAC,EACvC,QAAQ,EACR,MAAW,EACX,KAAY,EACb,EAAE;IACD,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,KAAK,CAAC,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;CAC9B,GAAG;IACF,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;IAC5B,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;CAC7B,CA6CA"}
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
export default function extractStyles({ width, height, style }: {
|
|
2
|
-
width
|
|
3
|
-
height
|
|
4
|
-
style
|
|
3
|
+
width?: string | number;
|
|
4
|
+
height?: string | number;
|
|
5
|
+
style?: Partial<CSSStyleDeclaration> | null;
|
|
5
6
|
}): {
|
|
6
|
-
containerStyle:
|
|
7
|
-
|
|
8
|
-
zIndex: number;
|
|
9
|
-
left: number;
|
|
10
|
-
top: number;
|
|
11
|
-
width: any;
|
|
12
|
-
height: any;
|
|
13
|
-
};
|
|
14
|
-
canvasStyle: {
|
|
15
|
-
left: number;
|
|
16
|
-
top: number;
|
|
17
|
-
};
|
|
7
|
+
containerStyle: React.CSSProperties;
|
|
8
|
+
canvasStyle: React.CSSProperties;
|
|
18
9
|
};
|
|
19
10
|
//# sourceMappingURL=extract-styles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-styles.d.ts","sourceRoot":"","sources":["../../src/utils/extract-styles.
|
|
1
|
+
{"version":3,"file":"extract-styles.d.ts","sourceRoot":"","sources":["../../src/utils/extract-styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,KAAK,EACL,MAAM,EACN,KAAK,EACN,EAAE;IACD,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC;CAC7C,GAAG;IACF,cAAc,EAAE,KAAK,CAAC,aAAa,CAAC;IACpC,WAAW,EAAE,KAAK,CAAC,aAAa,CAAC;CAClC,CA8BA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export function inheritsFrom(Type: any, ParentType:
|
|
1
|
+
export declare function inheritsFrom<T>(Type: any, ParentType: T): Type is T;
|
|
2
2
|
//# sourceMappingURL=inherits-from.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inherits-from.d.ts","sourceRoot":"","sources":["../../src/utils/inherits-from.
|
|
1
|
+
{"version":3,"file":"inherits-from.d.ts","sourceRoot":"","sources":["../../src/utils/inherits-from.ts"],"names":[],"mappings":"AACA,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,GAAG,IAAI,IAAI,CAAC,CAQnE"}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { Deck, DeckProps, Viewport } from '@deck.gl/core/typed';
|
|
3
|
+
import type { EventManager } from 'mjolnir.js';
|
|
4
|
+
export declare type DeckGLContextValue = {
|
|
5
|
+
viewport: Viewport;
|
|
6
|
+
container: HTMLElement;
|
|
7
|
+
eventManager: EventManager;
|
|
8
|
+
onViewStateChange: DeckProps['onViewStateChange'];
|
|
9
|
+
};
|
|
1
10
|
export default function positionChildrenUnderViews({ children, deck, ContextProvider }: {
|
|
2
|
-
children:
|
|
3
|
-
deck
|
|
4
|
-
ContextProvider
|
|
5
|
-
}):
|
|
11
|
+
children: React.ReactNode[];
|
|
12
|
+
deck?: Deck;
|
|
13
|
+
ContextProvider?: React.Context<DeckGLContextValue>['Provider'];
|
|
14
|
+
}): React.ReactNode[];
|
|
6
15
|
//# sourceMappingURL=position-children-under-views.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"position-children-under-views.d.ts","sourceRoot":"","sources":["../../src/utils/position-children-under-views.
|
|
1
|
+
{"version":3,"file":"position-children-under-views.d.ts","sourceRoot":"","sources":["../../src/utils/position-children-under-views.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,KAAK,EAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAC,MAAM,eAAe,CAAC;AAC7D,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AAE7C,oBAAY,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,WAAW,CAAC;IACvB,YAAY,EAAE,YAAY,CAAC;IAC3B,iBAAiB,EAAE,SAAS,CAAC,mBAAmB,CAAC,CAAC;CACnD,CAAC;AAIF,MAAM,CAAC,OAAO,UAAU,0BAA0B,CAAC,EACjD,QAAQ,EACR,IAAI,EACJ,eAAe,EAChB,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;IAC5B,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,eAAe,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC;CACjE,GAAG,KAAK,CAAC,SAAS,EAAE,CAyFpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-isomorphic-layout-effect.d.ts","sourceRoot":"","sources":["../../src/utils/use-isomorphic-layout-effect.
|
|
1
|
+
{"version":3,"file":"use-isomorphic-layout-effect.d.ts","sourceRoot":"","sources":["../../src/utils/use-isomorphic-layout-effect.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,eAAe,EAAC,MAAM,OAAO,CAAC;AAEjD,QAAA,MAAM,yBAAyB,wBAA8D,CAAC;AAE9F,eAAe,yBAAyB,CAAC"}
|