solid-map-gl 2.1.0 → 2.2.1
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 +5 -5
- package/dist/chunk/BTR7SKE6.js +7 -0
- package/dist/chunk/N4NHJCAS.jsx +28 -0
- package/dist/{index.d.ts → index/index.d.ts} +185 -5
- package/dist/index/index.js +10 -0
- package/dist/{index.jsx → index/index.jsx} +563 -142
- package/dist/testing/index.d.ts +109 -0
- package/dist/testing/index.js +8 -0
- package/dist/testing/index.jsx +334 -0
- package/package.json +38 -22
- package/dist/index.js +0 -11
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import * as vitest from 'vitest';
|
|
2
|
+
import { render } from '@solidjs/testing-library';
|
|
3
|
+
|
|
4
|
+
type MockMap = ReturnType<typeof createMockMap>;
|
|
5
|
+
declare function createMockMap(opts?: {
|
|
6
|
+
isMapLibre?: boolean;
|
|
7
|
+
}): any;
|
|
8
|
+
/** Chainable Marker/Popup-shaped fake — every method returns `this` unless noted. Every
|
|
9
|
+
* constructed instance is pushed onto the class's own `instances` array so tests can grab
|
|
10
|
+
* "the popup/marker this render created" without threading extra plumbing through the mock. */
|
|
11
|
+
declare class MockPopup {
|
|
12
|
+
static instances: MockPopup[];
|
|
13
|
+
options: any;
|
|
14
|
+
open: boolean;
|
|
15
|
+
constructor(options?: any);
|
|
16
|
+
on: vitest.Mock<() => this>;
|
|
17
|
+
off: vitest.Mock<() => this>;
|
|
18
|
+
addTo: vitest.Mock<() => this>;
|
|
19
|
+
remove: vitest.Mock<() => this>;
|
|
20
|
+
setHTML: vitest.Mock<() => this>;
|
|
21
|
+
setDOMContent: vitest.Mock<() => this>;
|
|
22
|
+
setLngLat: vitest.Mock<() => this>;
|
|
23
|
+
trackPointer: vitest.Mock<() => this>;
|
|
24
|
+
isOpen: vitest.Mock<() => boolean>;
|
|
25
|
+
toggle: vitest.Mock<() => this>;
|
|
26
|
+
}
|
|
27
|
+
declare class MockMarker {
|
|
28
|
+
static instances: MockMarker[];
|
|
29
|
+
options: any;
|
|
30
|
+
popup: MockPopup | null;
|
|
31
|
+
constructor(options?: any);
|
|
32
|
+
on: vitest.Mock<() => this>;
|
|
33
|
+
off: vitest.Mock<() => this>;
|
|
34
|
+
addTo: vitest.Mock<() => this>;
|
|
35
|
+
remove: vitest.Mock<() => this>;
|
|
36
|
+
setLngLat: vitest.Mock<() => this>;
|
|
37
|
+
setDraggable: vitest.Mock<() => this>;
|
|
38
|
+
setPopup: vitest.Mock<(p: any) => this>;
|
|
39
|
+
getPopup: vitest.Mock<() => MockPopup>;
|
|
40
|
+
togglePopup: vitest.Mock<() => this>;
|
|
41
|
+
getLngLat: vitest.Mock<() => {
|
|
42
|
+
lng: number;
|
|
43
|
+
lat: number;
|
|
44
|
+
toArray: () => number[];
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
declare class MockControl {
|
|
48
|
+
static instances: MockControl[];
|
|
49
|
+
options: any;
|
|
50
|
+
constructor(options?: any);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Fake `mapLib` module (the `mapbox-gl`/`maplibre-gl` export surface) — covers every class this
|
|
54
|
+
* library reads off `ctx.mapLib`. `Map` is constructable and returns a `createMockMap()` instance,
|
|
55
|
+
* so it doubles as the `props.mapLib` passed to a real `<MapGL>` in integration-style tests.
|
|
56
|
+
*/
|
|
57
|
+
declare function createMockMapLib(opts?: {
|
|
58
|
+
isMapLibre?: boolean;
|
|
59
|
+
}): {
|
|
60
|
+
Map: any;
|
|
61
|
+
Popup: typeof MockPopup;
|
|
62
|
+
Marker: typeof MockMarker;
|
|
63
|
+
NavigationControl: typeof MockControl;
|
|
64
|
+
ScaleControl: typeof MockControl;
|
|
65
|
+
AttributionControl: typeof MockControl;
|
|
66
|
+
GeolocateControl: typeof MockControl;
|
|
67
|
+
FullscreenControl: typeof MockControl;
|
|
68
|
+
LogoControl: typeof MockControl;
|
|
69
|
+
TerrainControl: typeof MockControl;
|
|
70
|
+
MercatorCoordinate: {
|
|
71
|
+
new (): {
|
|
72
|
+
x: number;
|
|
73
|
+
y: number;
|
|
74
|
+
z: number;
|
|
75
|
+
meterInMercatorCoordinateUnits(): number;
|
|
76
|
+
};
|
|
77
|
+
fromLngLat(_lngLat: any, altitude?: number): {
|
|
78
|
+
x: number;
|
|
79
|
+
y: number;
|
|
80
|
+
z: number;
|
|
81
|
+
meterInMercatorCoordinateUnits: () => number;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
version: string;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Fake `@mapbox/mapbox-gl-draw`-shaped `lib` prop for `<Draw>`. The custom modes under
|
|
88
|
+
* `components/Draw/modes` only ever spread `lib.modes.draw_*` at construction time (never call
|
|
89
|
+
* into it eagerly), so an empty `modes` object is enough to exercise `Draw`'s own wiring.
|
|
90
|
+
*/
|
|
91
|
+
declare function createMockDrawLib(): any;
|
|
92
|
+
/** Await a microtask tick — use after triggering mock events before asserting effect results. */
|
|
93
|
+
declare const tick: () => Promise<void>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Renders `ui` inside a `<MapProvider>` backed by a mock map, mirroring how every real
|
|
97
|
+
* component is only ever mounted underneath `<MapGL>`. Reused across component test files
|
|
98
|
+
* instead of hand-wiring `MapProvider` + a mock per test.
|
|
99
|
+
*/
|
|
100
|
+
declare function renderWithMap(ui: () => any, opts?: {
|
|
101
|
+
isMapLibre?: boolean;
|
|
102
|
+
map?: MockMap;
|
|
103
|
+
constants?: Record<string, any>;
|
|
104
|
+
}): ReturnType<typeof render> & {
|
|
105
|
+
map: MockMap;
|
|
106
|
+
mapLib: ReturnType<typeof createMockMapLib>;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export { type MockMap, createMockDrawLib, createMockMap, createMockMapLib, renderWithMap, tick };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { b as b$1 } from '../chunk/BTR7SKE6.js';
|
|
2
|
+
import { vi } from 'vitest';
|
|
3
|
+
import { createComponent } from 'solid-js/web';
|
|
4
|
+
import { render } from '@solidjs/testing-library';
|
|
5
|
+
|
|
6
|
+
var M=(s,e)=>e?`${s}:${e}`:s,b=class{};function L(s={}){let e=!!s.isMapLibre,a=new Map,f=new Map,g=new Map,p=new Set,u=new Set,h={layers:[],sources:{},fog:null,terrain:null,light:null},P=null,k=null,v=null,S=null,T=vi.fn((t,o,c)=>{let l=typeof o=="function"?o:c,y=typeof o=="function"?t:M(t,o);return a.has(y)||a.set(y,new Set),a.get(y).add(l),r}),x=vi.fn((t,o,c)=>{let l=typeof o=="function"?o:c,y=typeof o=="function"?t:M(t,o);return a.get(y)?.delete(l),r}),F=vi.fn((t,o)=>{if(!o)return Promise.resolve();let c=(...l)=>{x(t,c),o(...l);};return T(t,c),r}),O=vi.fn((t,o={},c)=>(a.get(M(t,c))?.forEach(l=>l(o)),r)),w=vi.fn((t,o)=>(f.set(t,{...o,setData:vi.fn(),setUrl:vi.fn(),setTiles:vi.fn(),updateImage:vi.fn()}),r)),I=vi.fn(t=>f.get(t)),R=vi.fn(t=>f.delete(t)),N=vi.fn(()=>true),_=vi.fn((t,o)=>(g.set(t.id,t),r)),U=vi.fn(t=>g.get(t)),D=vi.fn(t=>g.delete(t)),E=vi.fn(),B=vi.fn(),j=vi.fn(),z=vi.fn(),W=vi.fn(),$=vi.fn(),G=vi.fn(),Z=vi.fn(()=>h),H=vi.fn(t=>(h=typeof t=="string"?{...h,styleUrl:t}:{...h,...t},r)),V=vi.fn(()=>true),X=vi.fn(()=>true),q=vi.fn((t,o)=>(p.add(t),r)),J=vi.fn(t=>(p.delete(t),r)),K=vi.fn(t=>p.has(t)),Q=vi.fn(t=>u.has(t)),Y=vi.fn((t,o,c)=>{u.add(t);}),nn=vi.fn(t=>u.delete(t)),tn=vi.fn(),en=vi.fn(),on=vi.fn((t,o)=>{Promise.resolve().then(()=>o(null,{width:1,height:1,data:new Uint8Array(4)}));}),sn=vi.fn(()=>r),rn=vi.fn(()=>r),an=vi.fn(()=>r),cn=vi.fn(()=>r),fn=vi.fn(()=>r),pn=vi.fn(()=>r),ln=vi.fn(),r=Object.assign(new b,{debug:false,debugEvents:false,sourceIdList:[],layerIdList:[],isMapLibre:e,on:T,off:x,once:F,fire:O,addSource:w,getSource:I,removeSource:R,isSourceLoaded:N,addLayer:_,getLayer:U,removeLayer:D,moveLayer:E,setLayoutProperty:B,setPaintProperty:j,setLayerZoomRange:z,setFilter:W,setFeatureState:$,removeFeatureState:G,getStyle:Z,setStyle:H,isStyleLoaded:V,areTilesLoaded:X,addControl:q,removeControl:J,hasControl:K,hasImage:Q,addImage:Y,removeImage:nn,updateImage:tn,loadImage:on,triggerRepaint:en,stop:sn,flyTo:rn,easeTo:an,jumpTo:cn,resetNorthPitch:fn,resize:pn,remove:ln,getCanvas:vi.fn(()=>({style:{}})),getCenter:vi.fn(()=>({lng:0,lat:0,toArray:()=>[0,0]})),getZoom:vi.fn(()=>0),getBearing:vi.fn(()=>0),getPitch:vi.fn(()=>0),getBounds:vi.fn(()=>({getNorthEast:()=>({lng:0,lat:0}),getSouthWest:()=>({lng:0,lat:0})})),cameraForBounds:vi.fn(()=>({})),setProjection:vi.fn(),getFreeCameraOptions:vi.fn(()=>({position:null,lookAtPoint:vi.fn()})),setFreeCameraOptions:vi.fn(),setLight:vi.fn(t=>{v=t;}),getLight:vi.fn(()=>v),setTerrain:vi.fn(t=>{S=t;}),getTerrain:vi.fn(()=>S),...e?{}:{setConfigProperty:vi.fn(),getConfigProperty:vi.fn(),setFog:vi.fn(t=>{k=t;}),getFog:vi.fn(()=>k)},...e?{setSky:vi.fn(t=>{P=t;}),getSky:vi.fn(()=>P)}:{}});return r}var m=class s{static instances=[];options;open=false;constructor(e){this.options=e,s.instances.push(this);}on=vi.fn(()=>this);off=vi.fn(()=>this);addTo=vi.fn(()=>(this.open=true,this));remove=vi.fn(()=>(this.open=false,this));setHTML=vi.fn(()=>this);setDOMContent=vi.fn(()=>this);setLngLat=vi.fn(()=>this);trackPointer=vi.fn(()=>this);isOpen=vi.fn(()=>this.open);toggle=vi.fn(()=>(this.open=!this.open,this))},d=class s{static instances=[];options;popup=null;constructor(e){this.options=e,s.instances.push(this);}on=vi.fn(()=>this);off=vi.fn(()=>this);addTo=vi.fn(()=>this);remove=vi.fn(()=>this);setLngLat=vi.fn(()=>this);setDraggable=vi.fn(()=>this);setPopup=vi.fn(e=>(this.popup=e,this));getPopup=vi.fn(()=>this.popup);togglePopup=vi.fn(()=>(this.popup?.toggle(),this));getLngLat=vi.fn(()=>({lng:0,lat:0,toArray:()=>[0,0]}))},i=class s{static instances=[];options;constructor(e){this.options=e,s.instances.push(this);}};function C(s={}){let e=!!s.isMapLibre;m.instances=[],d.instances=[],i.instances=[];function a(g){let p=L({isMapLibre:e});return a.instances.push(p),Promise.resolve().then(()=>p.fire("load")),p}e||(a.prototype.setConfigProperty=()=>{}),a.instances=[];class f{x=0;y=0;z=0;static fromLngLat(p,u=0){return {x:0,y:0,z:u,meterInMercatorCoordinateUnits:()=>1}}meterInMercatorCoordinateUnits(){return 1}}return {Map:a,Popup:m,Marker:d,NavigationControl:i,ScaleControl:i,AttributionControl:i,GeolocateControl:i,FullscreenControl:i,LogoControl:i,TerrainControl:i,MercatorCoordinate:f,version:"mock"}}function gn(){function s(e){this.options=e,this.onAdd=vi.fn(()=>document.createElement("div")),this.onRemove=vi.fn();}return s.modes={},s.lib={theme:[]},s.constants={classes:{CANVAS:"mapboxgl-canvas",CONTROL_BASE:"mapboxgl-ctrl",CONTROL_PREFIX:"mapboxgl-ctrl-",CONTROL_GROUP:"mapboxgl-ctrl-group",ATTRIBUTION:"mapboxgl-ctrl-attrib"}},s}var un=()=>Promise.resolve().then(()=>Promise.resolve());function mn(s,e={}){let a=e.map||L({isMapLibre:e.isMapLibre}),f=C({isMapLibre:e.isMapLibre});return {...render(()=>createComponent(b$1,{map:a,mapLib:f,get isMapLibre(){return !!e.isMapLibre},get constants(){return e.constants},get children(){return s()}})),map:a,mapLib:f}}
|
|
7
|
+
|
|
8
|
+
export { gn as createMockDrawLib, L as createMockMap, C as createMockMapLib, mn as renderWithMap, un as tick };
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MapProvider
|
|
3
|
+
} from "../chunk/N4NHJCAS.jsx";
|
|
4
|
+
|
|
5
|
+
// src/testUtils/mockMap.ts
|
|
6
|
+
import { vi } from "vitest";
|
|
7
|
+
var key = (event, layerId) => layerId ? `${event}:${layerId}` : event;
|
|
8
|
+
var MockMapInstance = class {
|
|
9
|
+
};
|
|
10
|
+
function createMockMap(opts = {}) {
|
|
11
|
+
const isMapLibre = !!opts.isMapLibre;
|
|
12
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
13
|
+
const sources = /* @__PURE__ */ new Map();
|
|
14
|
+
const layers = /* @__PURE__ */ new Map();
|
|
15
|
+
const controls = /* @__PURE__ */ new Set();
|
|
16
|
+
const images = /* @__PURE__ */ new Set();
|
|
17
|
+
let styleObj = { layers: [], sources: {}, fog: null, terrain: null, light: null };
|
|
18
|
+
let sky = null;
|
|
19
|
+
let fog = null;
|
|
20
|
+
let light = null;
|
|
21
|
+
let terrain = null;
|
|
22
|
+
const on = vi.fn((event, a, b) => {
|
|
23
|
+
const handler = typeof a === "function" ? a : b;
|
|
24
|
+
const k = typeof a === "function" ? event : key(event, a);
|
|
25
|
+
if (!listeners.has(k)) listeners.set(k, /* @__PURE__ */ new Set());
|
|
26
|
+
listeners.get(k).add(handler);
|
|
27
|
+
return map;
|
|
28
|
+
});
|
|
29
|
+
const off = vi.fn((event, a, b) => {
|
|
30
|
+
const handler = typeof a === "function" ? a : b;
|
|
31
|
+
const k = typeof a === "function" ? event : key(event, a);
|
|
32
|
+
listeners.get(k)?.delete(handler);
|
|
33
|
+
return map;
|
|
34
|
+
});
|
|
35
|
+
const once = vi.fn((event, handler) => {
|
|
36
|
+
if (!handler) return Promise.resolve();
|
|
37
|
+
const wrapped = (...args) => {
|
|
38
|
+
off(event, wrapped);
|
|
39
|
+
handler(...args);
|
|
40
|
+
};
|
|
41
|
+
on(event, wrapped);
|
|
42
|
+
return map;
|
|
43
|
+
});
|
|
44
|
+
const fire = vi.fn((event, evt = {}, layerId) => {
|
|
45
|
+
listeners.get(key(event, layerId))?.forEach((h) => h(evt));
|
|
46
|
+
return map;
|
|
47
|
+
});
|
|
48
|
+
const addSource = vi.fn((id, spec) => {
|
|
49
|
+
sources.set(id, {
|
|
50
|
+
...spec,
|
|
51
|
+
setData: vi.fn(),
|
|
52
|
+
setUrl: vi.fn(),
|
|
53
|
+
setTiles: vi.fn(),
|
|
54
|
+
updateImage: vi.fn()
|
|
55
|
+
});
|
|
56
|
+
return map;
|
|
57
|
+
});
|
|
58
|
+
const getSource = vi.fn((id) => sources.get(id));
|
|
59
|
+
const removeSource = vi.fn((id) => sources.delete(id));
|
|
60
|
+
const isSourceLoaded = vi.fn(() => true);
|
|
61
|
+
const addLayer = vi.fn((layer, _beforeId) => {
|
|
62
|
+
layers.set(layer.id, layer);
|
|
63
|
+
return map;
|
|
64
|
+
});
|
|
65
|
+
const getLayer = vi.fn((id) => layers.get(id));
|
|
66
|
+
const removeLayer = vi.fn((id) => layers.delete(id));
|
|
67
|
+
const moveLayer = vi.fn();
|
|
68
|
+
const setLayoutProperty = vi.fn();
|
|
69
|
+
const setPaintProperty = vi.fn();
|
|
70
|
+
const setLayerZoomRange = vi.fn();
|
|
71
|
+
const setFilter = vi.fn();
|
|
72
|
+
const setFeatureState = vi.fn();
|
|
73
|
+
const removeFeatureState = vi.fn();
|
|
74
|
+
const getStyle = vi.fn(() => styleObj);
|
|
75
|
+
const setStyle = vi.fn((s) => {
|
|
76
|
+
styleObj = typeof s === "string" ? { ...styleObj, styleUrl: s } : { ...styleObj, ...s };
|
|
77
|
+
return map;
|
|
78
|
+
});
|
|
79
|
+
const isStyleLoaded = vi.fn(() => true);
|
|
80
|
+
const areTilesLoaded = vi.fn(() => true);
|
|
81
|
+
const addControl = vi.fn((c, _position) => {
|
|
82
|
+
controls.add(c);
|
|
83
|
+
return map;
|
|
84
|
+
});
|
|
85
|
+
const removeControl = vi.fn((c) => {
|
|
86
|
+
controls.delete(c);
|
|
87
|
+
return map;
|
|
88
|
+
});
|
|
89
|
+
const hasControl = vi.fn((c) => controls.has(c));
|
|
90
|
+
const hasImage = vi.fn((id) => images.has(id));
|
|
91
|
+
const addImage = vi.fn((id, _data, _opts) => {
|
|
92
|
+
images.add(id);
|
|
93
|
+
});
|
|
94
|
+
const removeImage = vi.fn((id) => images.delete(id));
|
|
95
|
+
const updateImage = vi.fn();
|
|
96
|
+
const triggerRepaint = vi.fn();
|
|
97
|
+
const loadImage = vi.fn((_url, cb) => {
|
|
98
|
+
Promise.resolve().then(() => cb(null, { width: 1, height: 1, data: new Uint8Array(4) }));
|
|
99
|
+
});
|
|
100
|
+
const stop = vi.fn(() => map);
|
|
101
|
+
const flyTo = vi.fn(() => map);
|
|
102
|
+
const easeTo = vi.fn(() => map);
|
|
103
|
+
const jumpTo = vi.fn(() => map);
|
|
104
|
+
const resetNorthPitch = vi.fn(() => map);
|
|
105
|
+
const resize = vi.fn(() => map);
|
|
106
|
+
const remove = vi.fn();
|
|
107
|
+
const map = Object.assign(new MockMapInstance(), {
|
|
108
|
+
debug: false,
|
|
109
|
+
debugEvents: false,
|
|
110
|
+
sourceIdList: [],
|
|
111
|
+
layerIdList: [],
|
|
112
|
+
isMapLibre,
|
|
113
|
+
on,
|
|
114
|
+
off,
|
|
115
|
+
once,
|
|
116
|
+
fire,
|
|
117
|
+
addSource,
|
|
118
|
+
getSource,
|
|
119
|
+
removeSource,
|
|
120
|
+
isSourceLoaded,
|
|
121
|
+
addLayer,
|
|
122
|
+
getLayer,
|
|
123
|
+
removeLayer,
|
|
124
|
+
moveLayer,
|
|
125
|
+
setLayoutProperty,
|
|
126
|
+
setPaintProperty,
|
|
127
|
+
setLayerZoomRange,
|
|
128
|
+
setFilter,
|
|
129
|
+
setFeatureState,
|
|
130
|
+
removeFeatureState,
|
|
131
|
+
getStyle,
|
|
132
|
+
setStyle,
|
|
133
|
+
isStyleLoaded,
|
|
134
|
+
areTilesLoaded,
|
|
135
|
+
addControl,
|
|
136
|
+
removeControl,
|
|
137
|
+
hasControl,
|
|
138
|
+
hasImage,
|
|
139
|
+
addImage,
|
|
140
|
+
removeImage,
|
|
141
|
+
updateImage,
|
|
142
|
+
loadImage,
|
|
143
|
+
triggerRepaint,
|
|
144
|
+
stop,
|
|
145
|
+
flyTo,
|
|
146
|
+
easeTo,
|
|
147
|
+
jumpTo,
|
|
148
|
+
resetNorthPitch,
|
|
149
|
+
resize,
|
|
150
|
+
remove,
|
|
151
|
+
getCanvas: vi.fn(() => ({ style: {} })),
|
|
152
|
+
getCenter: vi.fn(() => ({ lng: 0, lat: 0, toArray: () => [0, 0] })),
|
|
153
|
+
getZoom: vi.fn(() => 0),
|
|
154
|
+
getBearing: vi.fn(() => 0),
|
|
155
|
+
getPitch: vi.fn(() => 0),
|
|
156
|
+
getBounds: vi.fn(() => ({
|
|
157
|
+
getNorthEast: () => ({ lng: 0, lat: 0 }),
|
|
158
|
+
getSouthWest: () => ({ lng: 0, lat: 0 })
|
|
159
|
+
})),
|
|
160
|
+
cameraForBounds: vi.fn(() => ({})),
|
|
161
|
+
setProjection: vi.fn(),
|
|
162
|
+
getFreeCameraOptions: vi.fn(() => ({ position: null, lookAtPoint: vi.fn() })),
|
|
163
|
+
setFreeCameraOptions: vi.fn(),
|
|
164
|
+
setLight: vi.fn((l) => {
|
|
165
|
+
light = l;
|
|
166
|
+
}),
|
|
167
|
+
getLight: vi.fn(() => light),
|
|
168
|
+
setTerrain: vi.fn((t) => {
|
|
169
|
+
terrain = t;
|
|
170
|
+
}),
|
|
171
|
+
getTerrain: vi.fn(() => terrain),
|
|
172
|
+
// Mapbox-only
|
|
173
|
+
...isMapLibre ? {} : {
|
|
174
|
+
setConfigProperty: vi.fn(),
|
|
175
|
+
getConfigProperty: vi.fn(),
|
|
176
|
+
setFog: vi.fn((f) => {
|
|
177
|
+
fog = f;
|
|
178
|
+
}),
|
|
179
|
+
getFog: vi.fn(() => fog)
|
|
180
|
+
},
|
|
181
|
+
// MapLibre-only
|
|
182
|
+
...isMapLibre ? {
|
|
183
|
+
setSky: vi.fn((s) => {
|
|
184
|
+
sky = s;
|
|
185
|
+
}),
|
|
186
|
+
getSky: vi.fn(() => sky)
|
|
187
|
+
} : {}
|
|
188
|
+
});
|
|
189
|
+
return map;
|
|
190
|
+
}
|
|
191
|
+
var MockPopup = class _MockPopup {
|
|
192
|
+
static instances = [];
|
|
193
|
+
options;
|
|
194
|
+
open = false;
|
|
195
|
+
constructor(options) {
|
|
196
|
+
this.options = options;
|
|
197
|
+
_MockPopup.instances.push(this);
|
|
198
|
+
}
|
|
199
|
+
on = vi.fn(() => this);
|
|
200
|
+
off = vi.fn(() => this);
|
|
201
|
+
addTo = vi.fn(() => {
|
|
202
|
+
this.open = true;
|
|
203
|
+
return this;
|
|
204
|
+
});
|
|
205
|
+
remove = vi.fn(() => {
|
|
206
|
+
this.open = false;
|
|
207
|
+
return this;
|
|
208
|
+
});
|
|
209
|
+
setHTML = vi.fn(() => this);
|
|
210
|
+
setDOMContent = vi.fn(() => this);
|
|
211
|
+
setLngLat = vi.fn(() => this);
|
|
212
|
+
trackPointer = vi.fn(() => this);
|
|
213
|
+
isOpen = vi.fn(() => this.open);
|
|
214
|
+
toggle = vi.fn(() => {
|
|
215
|
+
this.open = !this.open;
|
|
216
|
+
return this;
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
var MockMarker = class _MockMarker {
|
|
220
|
+
static instances = [];
|
|
221
|
+
options;
|
|
222
|
+
popup = null;
|
|
223
|
+
constructor(options) {
|
|
224
|
+
this.options = options;
|
|
225
|
+
_MockMarker.instances.push(this);
|
|
226
|
+
}
|
|
227
|
+
on = vi.fn(() => this);
|
|
228
|
+
off = vi.fn(() => this);
|
|
229
|
+
addTo = vi.fn(() => this);
|
|
230
|
+
remove = vi.fn(() => this);
|
|
231
|
+
setLngLat = vi.fn(() => this);
|
|
232
|
+
setDraggable = vi.fn(() => this);
|
|
233
|
+
setPopup = vi.fn((p) => {
|
|
234
|
+
this.popup = p;
|
|
235
|
+
return this;
|
|
236
|
+
});
|
|
237
|
+
getPopup = vi.fn(() => this.popup);
|
|
238
|
+
togglePopup = vi.fn(() => {
|
|
239
|
+
this.popup?.toggle();
|
|
240
|
+
return this;
|
|
241
|
+
});
|
|
242
|
+
getLngLat = vi.fn(() => ({ lng: 0, lat: 0, toArray: () => [0, 0] }));
|
|
243
|
+
};
|
|
244
|
+
var MockControl = class _MockControl {
|
|
245
|
+
static instances = [];
|
|
246
|
+
options;
|
|
247
|
+
constructor(options) {
|
|
248
|
+
this.options = options;
|
|
249
|
+
_MockControl.instances.push(this);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
function createMockMapLib(opts = {}) {
|
|
253
|
+
const isMapLibre = !!opts.isMapLibre;
|
|
254
|
+
MockPopup.instances = [];
|
|
255
|
+
MockMarker.instances = [];
|
|
256
|
+
MockControl.instances = [];
|
|
257
|
+
function Map2(_options) {
|
|
258
|
+
const instance = createMockMap({ isMapLibre });
|
|
259
|
+
Map2.instances.push(instance);
|
|
260
|
+
Promise.resolve().then(() => instance.fire("load"));
|
|
261
|
+
return instance;
|
|
262
|
+
}
|
|
263
|
+
if (!isMapLibre) Map2.prototype.setConfigProperty = () => {
|
|
264
|
+
};
|
|
265
|
+
Map2.instances = [];
|
|
266
|
+
class MercatorCoordinate {
|
|
267
|
+
x = 0;
|
|
268
|
+
y = 0;
|
|
269
|
+
z = 0;
|
|
270
|
+
static fromLngLat(_lngLat, altitude = 0) {
|
|
271
|
+
return { x: 0, y: 0, z: altitude, meterInMercatorCoordinateUnits: () => 1 };
|
|
272
|
+
}
|
|
273
|
+
meterInMercatorCoordinateUnits() {
|
|
274
|
+
return 1;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
Map: Map2,
|
|
279
|
+
Popup: MockPopup,
|
|
280
|
+
Marker: MockMarker,
|
|
281
|
+
NavigationControl: MockControl,
|
|
282
|
+
ScaleControl: MockControl,
|
|
283
|
+
AttributionControl: MockControl,
|
|
284
|
+
GeolocateControl: MockControl,
|
|
285
|
+
FullscreenControl: MockControl,
|
|
286
|
+
LogoControl: MockControl,
|
|
287
|
+
TerrainControl: MockControl,
|
|
288
|
+
MercatorCoordinate,
|
|
289
|
+
version: "mock"
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function createMockDrawLib() {
|
|
293
|
+
function MapboxDraw(options) {
|
|
294
|
+
this.options = options;
|
|
295
|
+
this.onAdd = vi.fn(() => document.createElement("div"));
|
|
296
|
+
this.onRemove = vi.fn();
|
|
297
|
+
}
|
|
298
|
+
MapboxDraw.modes = {};
|
|
299
|
+
MapboxDraw.lib = { theme: [] };
|
|
300
|
+
MapboxDraw.constants = {
|
|
301
|
+
classes: {
|
|
302
|
+
CANVAS: "mapboxgl-canvas",
|
|
303
|
+
CONTROL_BASE: "mapboxgl-ctrl",
|
|
304
|
+
CONTROL_PREFIX: "mapboxgl-ctrl-",
|
|
305
|
+
CONTROL_GROUP: "mapboxgl-ctrl-group",
|
|
306
|
+
ATTRIBUTION: "mapboxgl-ctrl-attrib"
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
return MapboxDraw;
|
|
310
|
+
}
|
|
311
|
+
var tick = () => Promise.resolve().then(() => Promise.resolve());
|
|
312
|
+
|
|
313
|
+
// src/testUtils/renderWithMap.tsx
|
|
314
|
+
import { render } from "@solidjs/testing-library";
|
|
315
|
+
function renderWithMap(ui, opts = {}) {
|
|
316
|
+
const map = opts.map || createMockMap({ isMapLibre: opts.isMapLibre });
|
|
317
|
+
const mapLib = createMockMapLib({ isMapLibre: opts.isMapLibre });
|
|
318
|
+
const result = render(() => <MapProvider
|
|
319
|
+
map={map}
|
|
320
|
+
mapLib={mapLib}
|
|
321
|
+
isMapLibre={!!opts.isMapLibre}
|
|
322
|
+
constants={opts.constants}
|
|
323
|
+
>
|
|
324
|
+
{ui()}
|
|
325
|
+
</MapProvider>);
|
|
326
|
+
return { ...result, map, mapLib };
|
|
327
|
+
}
|
|
328
|
+
export {
|
|
329
|
+
createMockDrawLib,
|
|
330
|
+
createMockMap,
|
|
331
|
+
createMockMapLib,
|
|
332
|
+
renderWithMap,
|
|
333
|
+
tick
|
|
334
|
+
};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.1
|
|
2
|
+
"version": "2.2.1",
|
|
3
3
|
"name": "solid-map-gl",
|
|
4
4
|
"description": "SolidJS Component Library for Mapbox GL JS & MapLibre GL JS",
|
|
5
5
|
"info": "SolidJS Component Library for Mapbox GL JS & MapLibre GL JS. Mapbox GL JS and MapLibre GL JS are JavaScript libraries that render interactive maps from vector tiles and map styles using WebGL. This project is intended to be as close as possible to the Mapbox GL JS API.",
|
|
@@ -27,20 +27,29 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"source": "./dist/index.jsx",
|
|
30
|
-
"main": "./dist/index.js",
|
|
31
|
-
"module": "./dist/index.js",
|
|
32
|
-
"types": "./dist/index.d.ts",
|
|
30
|
+
"main": "./dist/index/index.js",
|
|
31
|
+
"module": "./dist/index/index.js",
|
|
32
|
+
"types": "./dist/index/index.d.ts",
|
|
33
33
|
"exports": {
|
|
34
|
+
"./package.json": "./package.json",
|
|
34
35
|
".": {
|
|
35
|
-
"types": "./dist/index.d.ts",
|
|
36
|
-
"solid": "./dist/index.jsx",
|
|
36
|
+
"types": "./dist/index/index.d.ts",
|
|
37
|
+
"solid": "./dist/index/index.jsx",
|
|
37
38
|
"import": {
|
|
38
|
-
"types": "./dist/index.d.ts",
|
|
39
|
-
"default": "./dist/index.js"
|
|
39
|
+
"types": "./dist/index/index.d.ts",
|
|
40
|
+
"default": "./dist/index/index.js"
|
|
40
41
|
},
|
|
41
|
-
"default": "./dist/index.js"
|
|
42
|
+
"default": "./dist/index/index.js"
|
|
42
43
|
},
|
|
43
|
-
"./
|
|
44
|
+
"./testing": {
|
|
45
|
+
"types": "./dist/testing/index.d.ts",
|
|
46
|
+
"solid": "./dist/testing/index.jsx",
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./dist/testing/index.d.ts",
|
|
49
|
+
"default": "./dist/testing/index.js"
|
|
50
|
+
},
|
|
51
|
+
"default": "./dist/testing/index.js"
|
|
52
|
+
}
|
|
44
53
|
},
|
|
45
54
|
"scripts": {
|
|
46
55
|
"build": "tsup",
|
|
@@ -52,7 +61,7 @@
|
|
|
52
61
|
},
|
|
53
62
|
"repository": {
|
|
54
63
|
"type": "git",
|
|
55
|
-
"url": "git+https://github.com/
|
|
64
|
+
"url": "git+https://github.com/GIShub4/solid-map-gl.git"
|
|
56
65
|
},
|
|
57
66
|
"browserList": [
|
|
58
67
|
"defaults",
|
|
@@ -61,7 +70,7 @@
|
|
|
61
70
|
"devDependencies": {
|
|
62
71
|
"@solidjs/testing-library": "^0.8.10",
|
|
63
72
|
"@testing-library/jest-dom": "^7.0.1",
|
|
64
|
-
"@vitest/coverage-v8": "^
|
|
73
|
+
"@vitest/coverage-v8": "^5.0.0",
|
|
65
74
|
"jsdom": "^30.0.1",
|
|
66
75
|
"jsdom-worker": "^0.3.0",
|
|
67
76
|
"mapbox-gl": "^3.30.0",
|
|
@@ -73,19 +82,24 @@
|
|
|
73
82
|
"typescript": "^6.0.3",
|
|
74
83
|
"vite": "^8.2.2",
|
|
75
84
|
"vite-plugin-solid": "^2.11.10",
|
|
76
|
-
"vitest": "^
|
|
85
|
+
"vitest": "^5.0.0"
|
|
77
86
|
},
|
|
78
87
|
"peerDependencies": {
|
|
79
88
|
"@babylonjs/core": "^6.24.0",
|
|
89
|
+
"@solidjs/testing-library": "^0.8.0",
|
|
80
90
|
"mapbox-gl": "^3.0.0",
|
|
81
91
|
"maplibre-gl": "^4.0.0 || ^5.0.0 || ^6.0.0",
|
|
82
92
|
"solid-js": "^1.8.0 <2.0.0",
|
|
83
|
-
"three": "^0.157.0"
|
|
93
|
+
"three": "^0.157.0",
|
|
94
|
+
"vitest": "^5.0.0"
|
|
84
95
|
},
|
|
85
96
|
"peerDependenciesMeta": {
|
|
86
97
|
"@babylonjs/core": {
|
|
87
98
|
"optional": true
|
|
88
99
|
},
|
|
100
|
+
"@solidjs/testing-library": {
|
|
101
|
+
"optional": true
|
|
102
|
+
},
|
|
89
103
|
"mapbox-gl": {
|
|
90
104
|
"optional": true
|
|
91
105
|
},
|
|
@@ -94,15 +108,17 @@
|
|
|
94
108
|
},
|
|
95
109
|
"three": {
|
|
96
110
|
"optional": true
|
|
111
|
+
},
|
|
112
|
+
"vitest": {
|
|
113
|
+
"optional": true
|
|
97
114
|
}
|
|
98
115
|
},
|
|
99
|
-
"dependencies": {
|
|
100
|
-
"@turf/area": "^7.3.4",
|
|
101
|
-
"@turf/center-of-mass": "^7.3.4",
|
|
102
|
-
"@turf/centroid": "^7.3.4",
|
|
103
|
-
"@turf/length": "^7.3.4",
|
|
104
|
-
"@turf/midpoint": "^7.3.4"
|
|
105
|
-
},
|
|
106
116
|
"browser": {},
|
|
107
|
-
"typesVersions": {
|
|
117
|
+
"typesVersions": {
|
|
118
|
+
"*": {
|
|
119
|
+
"testing": [
|
|
120
|
+
"./dist/testing/index.d.ts"
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
}
|
|
108
124
|
}
|