@skyvexsoftware/stratos-sdk 0.24.0 → 0.25.0

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,7 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useLayoutEffect, useRef, useState } from "react";
2
+ import { Component, useLayoutEffect, useRef, useState, } from "react";
3
3
  import { Map } from "react-map-gl/maplibre";
4
4
  import { useTheme } from "../hooks/useTheme";
5
+ import { Button } from "./button";
5
6
  import { applyStratosLabels } from "./stratos-map-labels";
6
7
  const LIGHT_STYLE = "https://tiles.openfreemap.org/styles/positron";
7
8
  const DARK_STYLE = "https://tiles.openfreemap.org/styles/dark";
@@ -21,6 +22,26 @@ const STYLES = `
21
22
  `;
22
23
  const ATTRIBUTION = { compact: true };
23
24
  const isStratosStyle = (style) => style === LIGHT_STYLE || style === DARK_STYLE;
25
+ // MapLibre draws synchronously inside React's commit, so a GPU that can't
26
+ // compile a shader (or has lost its WebGL context) throws during render.
27
+ // Catch it here so only the map goes, not the plugin page around it.
28
+ class MapErrorBoundary extends Component {
29
+ constructor() {
30
+ super(...arguments);
31
+ this.state = { failed: false };
32
+ }
33
+ static getDerivedStateFromError() {
34
+ return { failed: true };
35
+ }
36
+ render() {
37
+ if (!this.state.failed)
38
+ return this.props.children;
39
+ return (_jsxs("div", { className: "bg-muted text-muted-foreground absolute inset-0 flex flex-col items-center justify-center gap-3 p-4 text-center text-sm", children: [_jsx("p", { children: "Map unavailable. Your graphics driver couldn't draw it." }), _jsx(Button, { variant: "outline", size: "sm", onClick: () => {
40
+ this.props.onRetry();
41
+ this.setState({ failed: false });
42
+ }, children: "Try again" })] }));
43
+ }
44
+ }
24
45
  /**
25
46
  * react-map-gl's `Map` (every prop and child passes through) in Stratos's
26
47
  * map style, light or dark to match the theme, with English labels and the
@@ -33,6 +54,8 @@ export function StratosMap({ lightStyle = LIGHT_STYLE, darkStyle = DARK_STYLE, o
33
54
  const mapStyle = useTheme() === "dark" ? darkStyle : lightStyle;
34
55
  const [loaded, setLoaded] = useState(false);
35
56
  const [drawing, setDrawing] = useState(true);
57
+ // Bumped by "Try again" so MapLibre remounts with a fresh GL context.
58
+ const [attempt, setAttempt] = useState(0);
36
59
  // "style" while a style URL loads (a diffed switch reports idle on the old
37
60
  // style meanwhile), "draw" until the map is next idle, null when drawn.
38
61
  const phase = useRef("draw");
@@ -74,8 +97,8 @@ export function StratosMap({ lightStyle = LIGHT_STYLE, darkStyle = DARK_STYLE, o
74
97
  };
75
98
  return (
76
99
  // No box of its own: the map sizes against the parent as it would bare.
77
- _jsxs("div", { "data-stratos-map": "", "data-attribution-ready": loaded ? "" : undefined, "data-stratos-map-drawing": drawing ? "" : undefined, style: { display: "contents" }, children: [_jsx("style", { href: "stratos-map", precedence: "default", children: STYLES }), _jsx(Map, { ...props, ref: ref, mapStyle: mapStyle,
78
- // Reload Stratos's style from scratch on a theme switch, so style.load
79
- // fires and the label tweaks go back on (a diff would undo them).
80
- styleDiffing: isStratosStyle(mapStyle) ? false : props.styleDiffing, attributionControl: ATTRIBUTION, onLoad: handleLoad })] }));
100
+ _jsxs("div", { "data-stratos-map": "", "data-attribution-ready": loaded ? "" : undefined, "data-stratos-map-drawing": drawing ? "" : undefined, style: { display: "contents" }, children: [_jsx("style", { href: "stratos-map", precedence: "default", children: STYLES }), _jsx(MapErrorBoundary, { onRetry: () => setAttempt((n) => n + 1), children: _jsx(Map, { ...props, ref: ref, mapStyle: mapStyle,
101
+ // Reload Stratos's style from scratch on a theme switch, so style.load
102
+ // fires and the label tweaks go back on (a diff would undo them).
103
+ styleDiffing: isStratosStyle(mapStyle) ? false : props.styleDiffing, attributionControl: ATTRIBUTION, onLoad: handleLoad }, attempt) })] }));
81
104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyvexsoftware/stratos-sdk",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "description": "Plugin SDK for Stratos — types, hooks, and UI components",
5
5
  "author": {
6
6
  "name": "Skyvex Software Pty Ltd",