@deck.gl/core 9.2.0 → 9.2.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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "deck.gl core library",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
- "version": "9.2.0",
6
+ "version": "9.2.2",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -58,5 +58,5 @@
58
58
  "gl-matrix": "^3.0.0",
59
59
  "mjolnir.js": "^3.0.0"
60
60
  },
61
- "gitHead": "3db2198607e45909bf4013a272569583cff0edd0"
61
+ "gitHead": "9e183d2ce23bb21d655752ed614da0ce5a6a0458"
62
62
  }
package/src/lib/deck.ts CHANGED
@@ -93,7 +93,7 @@ export type DeckProps<ViewsT extends ViewOrViews = null> = {
93
93
  /** Controls the resolution of drawing buffer used for rendering.
94
94
  * @default `true` (use browser devicePixelRatio)
95
95
  */
96
- useDevicePixels?: boolean;
96
+ useDevicePixels?: boolean | number;
97
97
  /** Extra pixels around the pointer to include while picking.
98
98
  * @default `0`
99
99
  */
@@ -45,7 +45,7 @@ export class TooltipWidget extends Widget<TooltipWidgetProps> {
45
45
  lastViewport?: Viewport;
46
46
 
47
47
  constructor(props: TooltipWidgetProps = {}) {
48
- super(props, TooltipWidget.defaultProps);
48
+ super(props);
49
49
  this.setProps(props);
50
50
  }
51
51
 
@@ -201,12 +201,11 @@ export class WidgetManager {
201
201
  widget.deck = this.deck;
202
202
 
203
203
  // Create an attach the HTML root element
204
- widget.rootElement = widget.onCreateRootElement();
204
+ widget.rootElement = widget._onAdd({deck: this.deck, viewId});
205
205
  if (widget.rootElement) {
206
206
  this._getContainer(viewId, placement).append(widget.rootElement);
207
207
  }
208
208
 
209
- widget.onAdd?.({deck: this.deck, viewId});
210
209
  widget.updateHTML();
211
210
  }
212
211
 
package/src/lib/widget.ts CHANGED
@@ -50,8 +50,12 @@ export abstract class Widget<
50
50
  deck?: Deck<ViewsT>;
51
51
  rootElement?: HTMLDivElement | null;
52
52
 
53
- constructor(props: PropsT, defaultProps: Required<PropsT>) {
54
- this.props = {...defaultProps, ...props};
53
+ constructor(props: PropsT) {
54
+ this.props = {
55
+ // @ts-expect-error `defaultProps` may not exist on constructor
56
+ ...(this.constructor.defaultProps as Required<PropsT>),
57
+ ...props
58
+ };
55
59
  // @ts-expect-error TODO(ib) - why is id considered optional even though we use Required<>
56
60
  this.id = this.props.id;
57
61
  }
@@ -86,16 +90,14 @@ export abstract class Widget<
86
90
  }
87
91
  }
88
92
 
89
- // WIDGET LIFECYCLE
90
-
91
93
  // @note empty method calls have an overhead in V8 but it is very low, ~1ns
92
94
 
93
95
  /**
94
- * Called to create the root DOM element for this widget
96
+ * Common utility to create the root DOM element for this widget
95
97
  * Configures the top-level styles and adds basic class names for theming
96
- * @returns an optional UI element that should be appended to the Deck container
98
+ * @returns an UI element that should be appended to the Deck container
97
99
  */
98
- onCreateRootElement(): HTMLDivElement {
100
+ protected onCreateRootElement(): HTMLDivElement {
99
101
  const CLASS_NAMES = [
100
102
  // Add class names for theming
101
103
  'deck-widget',
@@ -112,16 +114,25 @@ export abstract class Widget<
112
114
  return element;
113
115
  }
114
116
 
117
+ // WIDGET LIFECYCLE
118
+
115
119
  /** Called to render HTML into the root element */
116
120
  abstract onRenderHTML(rootElement: HTMLElement): void;
117
121
 
118
- /** Called after the widget is added to a Deck instance and the DOM rootElement has been created */
122
+ /** Internal API called by Deck when the widget is first added to a Deck instance */
123
+ _onAdd(params: {deck: Deck<any>; viewId: string | null}): HTMLDivElement {
124
+ return this.onAdd(params) ?? this.onCreateRootElement();
125
+ }
126
+
127
+ /** Overridable by subclass - called when the widget is first added to a Deck instance
128
+ * @returns an optional UI element that should be appended to the Deck container
129
+ */
119
130
  onAdd(params: {
120
131
  /** The Deck instance that the widget is attached to */
121
132
  deck: Deck<any>;
122
133
  /** The id of the view that the widget is attached to */
123
134
  viewId: string | null;
124
- }) {}
135
+ }): HTMLDivElement | void {}
125
136
 
126
137
  /** Called when the widget is removed */
127
138
  onRemove(): void {}