@deck.gl/react 8.8.0-alpha.5 → 8.8.0-beta.2
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 +29 -23
- 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 +26 -16
- 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} +65 -26
- package/src/index.ts +26 -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/deckgl.js +194 -0
- package/typed/index.d.ts +4 -1
- package/typed/index.d.ts.map +1 -1
- package/{src → typed}/index.js +2 -3
- package/typed/utils/evaluate-children.d.ts +3 -1
- package/typed/utils/evaluate-children.d.ts.map +1 -1
- package/typed/utils/evaluate-children.js +33 -0
- 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-jsx-layers.js +77 -0
- package/typed/utils/extract-styles.d.ts +6 -15
- package/typed/utils/extract-styles.d.ts.map +1 -1
- package/typed/utils/extract-styles.js +32 -0
- package/typed/utils/inherits-from.d.ts +1 -1
- package/typed/utils/inherits-from.d.ts.map +1 -1
- package/typed/utils/inherits-from.js +10 -0
- 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/position-children-under-views.js +75 -0
- package/typed/utils/use-isomorphic-layout-effect.d.ts +2 -1
- package/typed/utils/use-isomorphic-layout-effect.d.ts.map +1 -1
- package/typed/utils/use-isomorphic-layout-effect.js +5 -0
- package/src/utils/evaluate-children.js +0 -38
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const CANVAS_ONLY_STYLES = {
|
|
2
|
+
mixBlendMode: null
|
|
3
|
+
};
|
|
4
|
+
export default function extractStyles({ width, height, style }) {
|
|
5
|
+
// This styling is enforced for correct positioning with children
|
|
6
|
+
const containerStyle = {
|
|
7
|
+
position: 'absolute',
|
|
8
|
+
zIndex: 0,
|
|
9
|
+
left: 0,
|
|
10
|
+
top: 0,
|
|
11
|
+
width,
|
|
12
|
+
height
|
|
13
|
+
};
|
|
14
|
+
// Fill the container
|
|
15
|
+
const canvasStyle = {
|
|
16
|
+
left: 0,
|
|
17
|
+
top: 0
|
|
18
|
+
};
|
|
19
|
+
if (style) {
|
|
20
|
+
for (const key in style) {
|
|
21
|
+
if (key in CANVAS_ONLY_STYLES) {
|
|
22
|
+
// apply style to the canvas, but not deck's children, e.g. mix-blend-mode
|
|
23
|
+
canvasStyle[key] = style[key];
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
// apply style to the container, e.g. position/flow settings
|
|
27
|
+
containerStyle[key] = style[key];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return { containerStyle, canvasStyle };
|
|
32
|
+
}
|
|
@@ -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"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { View } from '@deck.gl/core';
|
|
3
|
+
import { inheritsFrom } from './inherits-from';
|
|
4
|
+
import evaluateChildren from './evaluate-children';
|
|
5
|
+
// Iterate over views and reposition children associated with views
|
|
6
|
+
// TODO - Can we supply a similar function for the non-React case?
|
|
7
|
+
export default function positionChildrenUnderViews({ children, deck, ContextProvider }) {
|
|
8
|
+
const { viewManager } = deck || {};
|
|
9
|
+
if (!viewManager || !viewManager.views.length) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
const views = {};
|
|
13
|
+
const defaultViewId = viewManager.views[0].id;
|
|
14
|
+
// Sort children by view id
|
|
15
|
+
for (const child of children) {
|
|
16
|
+
// Unless child is a View, position / render as part of the default view
|
|
17
|
+
let viewId = defaultViewId;
|
|
18
|
+
let viewChildren = child;
|
|
19
|
+
if (inheritsFrom(child.type, View)) {
|
|
20
|
+
viewId = child.props.id || defaultViewId;
|
|
21
|
+
viewChildren = child.props.children;
|
|
22
|
+
}
|
|
23
|
+
const viewport = viewManager.getViewport(viewId);
|
|
24
|
+
const viewState = viewManager.getViewState(viewId);
|
|
25
|
+
// Drop (auto-hide) elements with viewId that are not matched by any current view
|
|
26
|
+
if (viewport) {
|
|
27
|
+
const { x, y, width, height } = viewport;
|
|
28
|
+
// Resolve potentially relative dimensions using the deck.gl container size
|
|
29
|
+
viewChildren = evaluateChildren(viewChildren, {
|
|
30
|
+
x,
|
|
31
|
+
y,
|
|
32
|
+
width,
|
|
33
|
+
height,
|
|
34
|
+
viewport,
|
|
35
|
+
viewState
|
|
36
|
+
});
|
|
37
|
+
if (!views[viewId]) {
|
|
38
|
+
views[viewId] = {
|
|
39
|
+
viewport,
|
|
40
|
+
children: []
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
views[viewId].children.push(viewChildren);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Render views
|
|
47
|
+
return Object.keys(views).map(viewId => {
|
|
48
|
+
const { viewport, children: viewChildren } = views[viewId];
|
|
49
|
+
const { x, y, width, height } = viewport;
|
|
50
|
+
const style = {
|
|
51
|
+
position: 'absolute',
|
|
52
|
+
left: x,
|
|
53
|
+
top: y,
|
|
54
|
+
width,
|
|
55
|
+
height
|
|
56
|
+
};
|
|
57
|
+
const key = `view-${viewId}`;
|
|
58
|
+
// If children is passed as an array, React will throw the "each element in a list needs
|
|
59
|
+
// a key" warning. Sending each child as separate arguments removes this requirement.
|
|
60
|
+
const viewElement = createElement('div', { key, id: key, style }, ...viewChildren);
|
|
61
|
+
if (ContextProvider) {
|
|
62
|
+
const contextValue = {
|
|
63
|
+
viewport,
|
|
64
|
+
container: deck.canvas.offsetParent,
|
|
65
|
+
eventManager: deck.eventManager,
|
|
66
|
+
onViewStateChange: params => {
|
|
67
|
+
params.viewId = viewId;
|
|
68
|
+
deck._onViewStateChange(params);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
return createElement(ContextProvider, { key, value: contextValue }, viewElement);
|
|
72
|
+
}
|
|
73
|
+
return viewElement;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -1 +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,EAAC,SAAS,EAAkB,MAAM,OAAO,CAAC;AAEjD,QAAA,MAAM,yBAAyB,kBAA8D,CAAC;AAE9F,eAAe,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// From https://github.com/streamich/react-use/blob/master/src/useIsomorphicLayoutEffect.ts
|
|
2
|
+
// useLayoutEffect but does not trigger warning in server-side rendering
|
|
3
|
+
import { useEffect, useLayoutEffect } from 'react';
|
|
4
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
5
|
+
export default useIsomorphicLayoutEffect;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import {cloneElement} from 'react';
|
|
2
|
-
|
|
3
|
-
const MAP_STYLE = {position: 'absolute', zIndex: -1};
|
|
4
|
-
|
|
5
|
-
export default function evaluateChildren(children, childProps) {
|
|
6
|
-
if (!children) {
|
|
7
|
-
return children;
|
|
8
|
-
}
|
|
9
|
-
if (typeof children === 'function') {
|
|
10
|
-
return children(childProps);
|
|
11
|
-
}
|
|
12
|
-
if (Array.isArray(children)) {
|
|
13
|
-
return children.map(child => evaluateChildren(child, childProps));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Special treatment for react-map-gl's Map component
|
|
17
|
-
// to support shorthand use case <DeckGL><StaticMap /></DeckGL>
|
|
18
|
-
if (isReactMap(children)) {
|
|
19
|
-
// Place map under the canvas
|
|
20
|
-
childProps.style = MAP_STYLE;
|
|
21
|
-
return cloneElement(children, childProps);
|
|
22
|
-
}
|
|
23
|
-
if (needsDeckGLViewProps(children)) {
|
|
24
|
-
return cloneElement(children, childProps);
|
|
25
|
-
}
|
|
26
|
-
return children;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function isReactMap(child) {
|
|
30
|
-
const componentClass = child && child.type;
|
|
31
|
-
const componentProps = componentClass && componentClass.defaultProps;
|
|
32
|
-
return componentProps && componentProps.mapStyle;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function needsDeckGLViewProps(child) {
|
|
36
|
-
const componentClass = child && child.type;
|
|
37
|
-
return componentClass && componentClass.deckGLViewProps;
|
|
38
|
-
}
|