@lad-sapienza/scms-core 0.1.0-alpha.10 → 0.1.0-alpha.11
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/README.md +2 -2
- package/bin/create.mjs +1 -1
- package/components/Map/Map.tsx +16 -0
- package/components/Map/README.md +13 -1
- package/package.json +3 -3
- package/scms.ts +25 -16
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ This package supplies the `core/` framework layer that used to live inside the s
|
|
|
10
10
|
npm install @lad-sapienza/scms-core
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Peer dependencies (install alongside): `astro`, `react`, `react-dom`, `maplibre-gl
|
|
13
|
+
Peer dependencies (install alongside): `astro`, `react`, `react-dom`, `maplibre-gl` (v6+), `@types/react`, `@types/react-dom`.
|
|
14
14
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
@@ -37,7 +37,7 @@ export default defineConfig({
|
|
|
37
37
|
});
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
`scms()` bundles content-asset serving, the Gallery virtual module, Expressive Code, MDX, React, and sitemap integrations into one call, and self-registers the Vite `dedupe`/`optimizeDeps`
|
|
40
|
+
`scms()` bundles content-asset serving, the Gallery virtual module, Expressive Code, MDX, React, and sitemap integrations into one call, and self-registers the Vite config the components need — `dedupe`/`optimizeDeps` for React and `@tanstack/react-table` (avoids duplicate-module "Invalid hook call" errors) and `ssr.noExternal` for `maplibre-gl` (so the `Map` component's MapLibre v6 worker import resolves in the SSR pass). No extra Vite config required in the consumer.
|
|
41
41
|
|
|
42
42
|
Import components from the package root in any `.mdx` file:
|
|
43
43
|
|
package/bin/create.mjs
CHANGED
|
@@ -115,7 +115,7 @@ async function main() {
|
|
|
115
115
|
__ASTRO_VERSION__: bareVersion(peers.astro ?? '7.0.0'),
|
|
116
116
|
__REACT_VERSION__: bareVersion(peers.react ?? '19.0.0'),
|
|
117
117
|
__REACT_DOM_VERSION__: bareVersion(peers['react-dom'] ?? '19.0.0'),
|
|
118
|
-
__MAPLIBRE_VERSION__: bareVersion(peers['maplibre-gl'] ?? '
|
|
118
|
+
__MAPLIBRE_VERSION__: bareVersion(peers['maplibre-gl'] ?? '6.0.0'),
|
|
119
119
|
__TYPES_REACT_VERSION__: bareVersion(peers['@types/react'] ?? '19.0.0'),
|
|
120
120
|
__TYPES_REACT_DOM_VERSION__: bareVersion(peers['@types/react-dom'] ?? '19.0.0'),
|
|
121
121
|
};
|
package/components/Map/Map.tsx
CHANGED
|
@@ -10,6 +10,19 @@ import MapLibreMap, {
|
|
|
10
10
|
type MapRef
|
|
11
11
|
} from '@vis.gl/react-maplibre';
|
|
12
12
|
import 'maplibre-gl/dist/maplibre-gl.css';
|
|
13
|
+
// MapLibre GL JS v6 no longer resolves and loads its Web Worker automatically
|
|
14
|
+
// (v5 did): a bundler-based app must hand the library a worker URL itself
|
|
15
|
+
// before the first map is constructed. `?worker&url` runs the dist worker
|
|
16
|
+
// through Vite's worker pipeline so its sibling `maplibre-gl-shared.mjs` is
|
|
17
|
+
// bundled into a self-contained chunk — a plain `?url` import leaves the worker
|
|
18
|
+
// unable to load that sibling in production builds. This runs at module-eval
|
|
19
|
+
// time, before `@vis.gl/react-maplibre` dynamically imports maplibre-gl and
|
|
20
|
+
// calls `new Map()`, so the URL is always registered in time. Consuming sites
|
|
21
|
+
// need no worker config of their own.
|
|
22
|
+
// See https://maplibre.org/maplibre-gl-js/docs/ (Installation → Bundlers) and
|
|
23
|
+
// https://visgl.github.io/react-map-gl/docs/get-started.
|
|
24
|
+
import { setWorkerUrl } from 'maplibre-gl';
|
|
25
|
+
import maplibreWorkerUrl from 'maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url';
|
|
13
26
|
import type { MapProps, OverlayLayerConfig } from './types';
|
|
14
27
|
import { RasterLayerLibre } from './RasterLayerLibre';
|
|
15
28
|
import { LayerControlIControl } from './LayerControl';
|
|
@@ -24,6 +37,9 @@ import type { FeatureCollection } from 'geojson';
|
|
|
24
37
|
import type { CircleLayerSpecification } from 'maplibre-gl';
|
|
25
38
|
import type { SearchQuery } from './types';
|
|
26
39
|
|
|
40
|
+
// Register the v6 worker URL once, at module load — see the import comment above.
|
|
41
|
+
setWorkerUrl(maplibreWorkerUrl);
|
|
42
|
+
|
|
27
43
|
// Default base layer (OSM)
|
|
28
44
|
const DEFAULT_BASE_LAYERS: BaseLayerConfig[] = [defaultBasemaps.OSM];
|
|
29
45
|
|
package/components/Map/README.md
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
# Map Component
|
|
2
2
|
|
|
3
|
-
Interactive map built on [MapLibre GL JS](https://maplibre.org/) (via
|
|
3
|
+
Interactive map built on [MapLibre GL JS](https://maplibre.org/) **v6** (via
|
|
4
4
|
`@vis.gl/react-maplibre`). Renders a raster basemap, any number of toggleable
|
|
5
5
|
overlay layers pulled from heterogeneous data sources (GeoJSON, CSV, JSON,
|
|
6
6
|
Directus, a generic API, or raster XYZ/WMS tiles), and a built-in layer
|
|
7
7
|
control for switching basemaps and toggling overlays.
|
|
8
8
|
|
|
9
|
+
MapLibre v6 requires **WebGL2** (universally supported by current browsers) and
|
|
10
|
+
no longer auto-loads its Web Worker — `Map.tsx` wires the worker up itself with
|
|
11
|
+
a Vite `?worker&url` import, so consuming sites need no bundler/worker config.
|
|
12
|
+
The `maplibre-gl` peer dependency is `^6`.
|
|
13
|
+
|
|
9
14
|
## Basic usage
|
|
10
15
|
|
|
11
16
|
```mdx
|
|
@@ -199,3 +204,10 @@ exact shape.
|
|
|
199
204
|
only two functions that build tile URL templates — both `baseLayers` and
|
|
200
205
|
raster `overlayLayers` go through them, so there's one place to fix or
|
|
201
206
|
extend tile-URL construction.
|
|
207
|
+
- MapLibre GL JS v6 dropped the automatic worker bootstrap, so `Map.tsx`
|
|
208
|
+
imports `maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url` and calls
|
|
209
|
+
`setWorkerUrl()` at module load, before `@vis.gl/react-maplibre` constructs
|
|
210
|
+
any map. `?worker&url` (not `?url`) routes the worker through Vite's worker
|
|
211
|
+
pipeline so its `maplibre-gl-shared.mjs` sibling is bundled in. `scms.ts`
|
|
212
|
+
adds `ssr.noExternal: ['maplibre-gl']` so that import also resolves in the
|
|
213
|
+
SSR pass for consumers rendering `<Map client:load>`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lad-sapienza/scms-core",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.11",
|
|
4
4
|
"description": "Framework components and Astro integrations for s:CMS — DataTb, Gallery, Map, ZoteroGeoViewer, Record.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "BSD-0-Clause",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@types/react": "^19.2.14",
|
|
36
36
|
"@types/react-dom": "^19.2.3",
|
|
37
37
|
"astro": "^7.2.4",
|
|
38
|
-
"maplibre-gl": "^
|
|
38
|
+
"maplibre-gl": "^6.7.0",
|
|
39
39
|
"react": "^19.2.4",
|
|
40
40
|
"react-dom": "^19.2.4"
|
|
41
41
|
},
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@tanstack/react-table": "^8.21.3",
|
|
49
49
|
"@types/geojson": "^7946.0.16",
|
|
50
50
|
"@types/papaparse": "^5.5.2",
|
|
51
|
-
"@vis.gl/react-maplibre": "^8.1.
|
|
51
|
+
"@vis.gl/react-maplibre": "^8.1.3",
|
|
52
52
|
"astro-expressive-code": "^0.44.1",
|
|
53
53
|
"lucide-react": "^1.8.0",
|
|
54
54
|
"papaparse": "^5.5.3",
|
package/scms.ts
CHANGED
|
@@ -64,22 +64,31 @@ function scmsViteConfigIntegration(): AstroIntegration {
|
|
|
64
64
|
dedupe: HOOK_LIBRARIES,
|
|
65
65
|
},
|
|
66
66
|
optimizeDeps: {
|
|
67
|
-
// papaparse is CommonJS-only (no `module`/`exports` field)
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
// it
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
|
|
67
|
+
// papaparse is CommonJS-only (no `module`/`exports` field). Its
|
|
68
|
+
// importer (CsvSource.tsx) lives in node_modules once this is a
|
|
69
|
+
// published package, so Vite's dev-time dependency scanner no
|
|
70
|
+
// longer discovers it on its own and pre-bundles the CJS→ESM
|
|
71
|
+
// interop — without this entry the browser is served the raw CJS
|
|
72
|
+
// file and crashes with "does not provide an export named
|
|
73
|
+
// 'default'". Must stay explicit.
|
|
74
|
+
//
|
|
75
|
+
// maplibre-gl used to need the same treatment because v5 shipped a
|
|
76
|
+
// UMD `dist/maplibre-gl.js`; v6 is real ESM (`dist/maplibre-gl.mjs`,
|
|
77
|
+
// `"exports"` map, no UMD), so Vite handles it with no interop
|
|
78
|
+
// shim and no explicit entry here. Map.tsx's `?worker&url` worker
|
|
79
|
+
// chunk is a separate, self-contained module and does not go
|
|
80
|
+
// through this pre-bundle.
|
|
81
|
+
include: ['react', 'react-dom', 'react-dom/client', 'react/jsx-runtime', 'react/jsx-dev-runtime', 'papaparse'],
|
|
82
|
+
},
|
|
83
|
+
ssr: {
|
|
84
|
+
// MapLibre GL JS v6's worker is wired up in Map.tsx via a
|
|
85
|
+
// `maplibre-gl/dist/...?worker&url` import (see that file). Vite's
|
|
86
|
+
// worker plugin can only resolve that specifier when maplibre-gl
|
|
87
|
+
// is bundled for SSR rather than externalised to a raw Node
|
|
88
|
+
// `import` — required for consumers that render <Map> with
|
|
89
|
+
// `client:load`/`client:visible` (server pass) rather than
|
|
90
|
+
// `client:only`. MapLibre's own Astro guidance calls for this.
|
|
91
|
+
noExternal: ['maplibre-gl'],
|
|
83
92
|
},
|
|
84
93
|
},
|
|
85
94
|
});
|