@defra/interactive-map 0.0.54-alpha → 0.0.55-alpha
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/assets/templates/add-polygons.njk +1 -1
- package/assets/templates/add-symbols.njk +4 -4
- package/assets/templates/draw-tools.njk +7 -7
- package/assets/templates/marker-panel.njk +5 -5
- package/assets/templates/place-marker.njk +8 -8
- package/assets/templates/search-control.njk +1 -1
- package/assets/templates/select-feature.njk +7 -7
- package/assets/templates/style-switcher.njk +4 -4
- package/assets/templates/toggle-marker-label.njk +3 -3
- package/dist/esm/im-core.js +1 -1
- package/dist/esm/im-shell.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/im-core.js.LICENSE.txt +0 -30
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.LICENSE.txt +0 -20
- package/docs/api.md +3 -13
- package/docs/building-a-plugin.md +2 -2
- package/docs/examples/add-marker-with-panel.mdx +46 -44
- package/docs/examples/add-polygons.mdx +100 -98
- package/docs/examples/add-symbols.mdx +75 -73
- package/docs/examples/basic-map.mdx +16 -14
- package/docs/examples/button-map.mdx +16 -14
- package/docs/examples/draw-tools.mdx +119 -117
- package/docs/examples/place-marker.mdx +51 -49
- package/docs/examples/search-control.mdx +22 -20
- package/docs/examples/select-feature.mdx +107 -105
- package/docs/examples/style-switcher.mdx +47 -45
- package/docs/examples/toggle-marker-label.mdx +30 -28
- package/docs/getting-started.md +26 -24
- package/docs/plugins/draw.md +10 -10
- package/docs/plugins/interact.md +9 -9
- package/docs/plugins/plugin-descriptor.md +1 -1
- package/docs/plugins/search.md +3 -3
- package/docusaurus.config.cjs +23 -0
- package/package.json +3 -7
- package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
- package/plugins/beta/draw-es/dist/esm/index.js +1 -1
- package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/esm/index.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/index.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/DrawMode.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/geometryHelpers.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/index.js +1 -1
- package/plugins/beta/frame/dist/esm/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/dist/esm/index.js +1 -1
- package/plugins/beta/frame/dist/umd/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/dist/umd/index.js +1 -1
- package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/esm/index.js +1 -1
- package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/umd/index.js +1 -1
- package/plugins/beta/scale-bar/dist/esm/im-scale-bar-plugin.js +1 -1
- package/plugins/beta/scale-bar/dist/esm/index.js +1 -1
- package/plugins/beta/scale-bar/dist/umd/im-scale-bar-plugin.js +1 -1
- package/plugins/beta/scale-bar/dist/umd/index.js +1 -1
- package/plugins/beta/use-location/dist/esm/im-use-location-plugin.js +1 -1
- package/plugins/beta/use-location/dist/esm/index.js +1 -1
- package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -1
- package/plugins/beta/use-location/dist/umd/index.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-esri-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/esm/index.js +1 -1
- package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
- package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/umd/index.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/esm/index.js +1 -1
- package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/index.js +1 -1
- package/plugins/draw/src/adapters/maplibre/styles.js +3 -2
- package/plugins/draw/src/adapters/maplibre/styles.test.js +3 -3
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/esm/index.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/index.js +1 -1
- package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/esm/index.js +1 -1
- package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/umd/index.js +1 -1
- package/plugins/menu/dist/esm/im-menu-plugin.js +1 -1
- package/plugins/menu/dist/esm/index.js +1 -1
- package/plugins/menu/dist/umd/im-menu-plugin.js +1 -1
- package/plugins/menu/dist/umd/index.js +1 -1
- package/plugins/search/dist/esm/im-search-plugin.js +1 -1
- package/plugins/search/dist/esm/index.js +1 -1
- package/plugins/search/dist/umd/im-search-plugin.js +1 -1
- package/plugins/search/dist/umd/index.js +1 -1
- package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/beta/esri/dist/esm/index.js +1 -1
- package/providers/beta/open-names/dist/esm/im-reverse-geocode.js +1 -1
- package/providers/beta/open-names/dist/esm/index.js +1 -1
- package/providers/beta/open-names/dist/umd/im-reverse-geocode.js +1 -1
- package/providers/beta/open-names/dist/umd/index.js +1 -1
- package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/esm/index.js +1 -1
- package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/umd/index.js +1 -1
- package/providers/beta/openlayers/src/index.js +27 -4
- package/providers/beta/openlayers/src/index.test.js +47 -0
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/esm/index.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-framework.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-framework.js.LICENSE.txt +3 -3
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-worker.js +2 -0
- package/providers/maplibre/dist/umd/im-maplibre-worker.js.LICENSE.txt +4 -0
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/index.js +41 -12
- package/providers/maplibre/src/index.test.js +43 -12
- package/providers/maplibre/src/utils/detectModuleWorker.js +25 -0
- package/providers/maplibre/src/utils/detectModuleWorker.test.js +40 -0
- package/providers/maplibre/src/utils/spatial.js +22 -12
- package/providers/maplibre/src/utils/spatial.test.js +6 -6
- package/providers/maplibre/src/utils/workerUrl.js +15 -0
- package/providers/maplibre/src/utils/workerUrl.test.js +14 -0
- package/rollup.esm.mjs +38 -1
- package/src/InteractiveMap/InteractiveMap.js +2 -1
- package/src/InteractiveMap/InteractiveMap.test.js +9 -2
- package/src/InteractiveMap/domStateManager.js +21 -1
- package/src/InteractiveMap/domStateManager.test.js +48 -1
- package/src/InteractiveMap/polyfills.js +4 -3
- package/src/InteractiveMap/polyfills.test.js +12 -0
- package/src/types.js +3 -5
- package/webpack.dev.mjs +2 -0
- package/webpack.umd.mjs +28 -7
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @jest-environment jsdom
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { updateDOMState, removeLoadingState } from './domStateManager.js'
|
|
5
|
+
import { updateDOMState, removeLoadingState, showPageIfMapInline } from './domStateManager.js'
|
|
6
6
|
import * as queryString from '../utils/queryString.js'
|
|
7
7
|
import * as toggleInertElements from '../utils/toggleInertElements.js'
|
|
8
8
|
|
|
@@ -145,3 +145,50 @@ describe('removeLoadingState', () => {
|
|
|
145
145
|
expect(document.body.classList.contains('im-is-loading')).toBe(false)
|
|
146
146
|
})
|
|
147
147
|
})
|
|
148
|
+
|
|
149
|
+
describe('showPageIfMapInline', () => {
|
|
150
|
+
let rootEl
|
|
151
|
+
|
|
152
|
+
const createMapInstance = (config) => ({
|
|
153
|
+
config: { id: 'map', pageTitle: 'Map View', containerHeight: '500px', hybridWidth: null, maxMobileWidth: 640, ...config },
|
|
154
|
+
rootEl
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
beforeEach(() => {
|
|
158
|
+
rootEl = document.createElement('div')
|
|
159
|
+
document.body.appendChild(rootEl)
|
|
160
|
+
document.body.classList.add('im-is-loading')
|
|
161
|
+
queryString.getQueryParam.mockReturnValue(null)
|
|
162
|
+
window.matchMedia = jest.fn().mockImplementation(() => ({ matches: false }))
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
afterEach(() => {
|
|
166
|
+
document.body.innerHTML = ''
|
|
167
|
+
document.body.classList.remove('im-is-loading')
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it.each([
|
|
171
|
+
['inline', {}],
|
|
172
|
+
['hybrid above hybridWidth', { behaviour: 'hybrid' }]
|
|
173
|
+
])('shows the page and reserves the container height for %s', (_label, config) => {
|
|
174
|
+
showPageIfMapInline(createMapInstance({ behaviour: 'inline', ...config }))
|
|
175
|
+
|
|
176
|
+
expect(document.body.classList.contains('im-is-loading')).toBe(false)
|
|
177
|
+
expect(rootEl.style.height).toBe('500px')
|
|
178
|
+
expect(document.documentElement.classList.contains('im-is-fullscreen')).toBe(false)
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
it.each([
|
|
182
|
+
['mapOnly', { behaviour: 'mapOnly' }, null, false],
|
|
183
|
+
['buttonFirst opened from the URL', { behaviour: 'buttonFirst' }, 'map', false],
|
|
184
|
+
['hybrid below hybridWidth opened from the URL', { behaviour: 'hybrid' }, 'map', true]
|
|
185
|
+
])('keeps the page hidden when the map opens fullscreen: %s', (_label, config, viewParam, isNarrow) => {
|
|
186
|
+
queryString.getQueryParam.mockReturnValue(viewParam)
|
|
187
|
+
window.matchMedia = jest.fn().mockImplementation(() => ({ matches: isNarrow }))
|
|
188
|
+
|
|
189
|
+
showPageIfMapInline(createMapInstance(config))
|
|
190
|
+
|
|
191
|
+
expect(document.body.classList.contains('im-is-loading')).toBe(true)
|
|
192
|
+
expect(rootEl.style.height).toBe('')
|
|
193
|
+
})
|
|
194
|
+
})
|
|
@@ -33,8 +33,8 @@ if (needsThrowIfAborted) {
|
|
|
33
33
|
|
|
34
34
|
// Inject polyfills into web workers — workers have their own global scope so
|
|
35
35
|
// main thread polyfills don't apply. Two cases:
|
|
36
|
-
// 1. Blob URL workers (MapLibre
|
|
37
|
-
// 2. String URL workers
|
|
36
|
+
// 1. Blob URL workers (MapLibre, when its worker is cross-origin): intercept URL.createObjectURL
|
|
37
|
+
// 2. String URL classic workers: intercept Worker constructor
|
|
38
38
|
const needsWorkerPolyfills = (needsThrowIfAborted || needsHasOwn) && typeof URL !== 'undefined' && URL.createObjectURL
|
|
39
39
|
|
|
40
40
|
if (needsWorkerPolyfills) {
|
|
@@ -59,7 +59,8 @@ if (needsWorkerPolyfills) {
|
|
|
59
59
|
const NativeWorker = Worker
|
|
60
60
|
// eslint-disable-next-line no-global-assign
|
|
61
61
|
Worker = function (url, options) {
|
|
62
|
-
|
|
62
|
+
// Module workers can't call importScripts, so they are left unwrapped
|
|
63
|
+
if (typeof url === 'string' && !url.startsWith('blob:') && options?.type !== 'module') {
|
|
63
64
|
const blob = new Blob([`${workerPolyfillCode}importScripts(${JSON.stringify(url)})`], { type: JS_MIME })
|
|
64
65
|
url = _createObjectURL(blob)
|
|
65
66
|
}
|
|
@@ -147,6 +147,18 @@ describe('Worker constructor (string workerUrl)', () => {
|
|
|
147
147
|
expect(MockWorker).toHaveBeenCalledWith('blob:http://localhost/existing', undefined)
|
|
148
148
|
})
|
|
149
149
|
|
|
150
|
+
test('passes module worker URLs through without wrapping', () => {
|
|
151
|
+
const MockWorker = setupWorkerMock()
|
|
152
|
+
const mockCreate = jest.fn(() => 'blob:new')
|
|
153
|
+
URL.createObjectURL = mockCreate
|
|
154
|
+
load()
|
|
155
|
+
|
|
156
|
+
// eslint-disable-next-line no-new
|
|
157
|
+
new Worker('/maplibre-gl-worker.mjs', { type: 'module' }) // NOSONAR
|
|
158
|
+
expect(mockCreate).not.toHaveBeenCalled()
|
|
159
|
+
expect(MockWorker).toHaveBeenCalledWith('/maplibre-gl-worker.mjs', { type: 'module' })
|
|
160
|
+
})
|
|
161
|
+
|
|
150
162
|
test('preserves the Worker prototype', () => {
|
|
151
163
|
const MockWorker = setupWorkerMock()
|
|
152
164
|
const mockProto = { foo: 'bar' }
|
package/src/types.js
CHANGED
|
@@ -383,11 +383,9 @@
|
|
|
383
383
|
* @typedef {Object} MaplibreProviderConfig
|
|
384
384
|
*
|
|
385
385
|
* @property {string} [workerUrl]
|
|
386
|
-
* URL
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
* When set, MapLibre loads the worker from this URL instead of generating an
|
|
390
|
-
* inline blob, so your CSP only needs `worker-src 'self'`.
|
|
386
|
+
* URL of the MapLibre worker file. Set automatically with webpack, Vite and the UMD
|
|
387
|
+
* build; with other bundlers (such as esbuild), serve `maplibre-gl/dist/maplibre-gl-worker.mjs`
|
|
388
|
+
* and set its URL here.
|
|
391
389
|
*/
|
|
392
390
|
|
|
393
391
|
/**
|
package/webpack.dev.mjs
CHANGED
package/webpack.umd.mjs
CHANGED
|
@@ -59,6 +59,10 @@ const createUMDConfig = (entryName, entryPath, libraryPath, outDir, isCore = fal
|
|
|
59
59
|
return {
|
|
60
60
|
mode: 'production',
|
|
61
61
|
|
|
62
|
+
// ES5 so the code that runs before the device check (webpack's runtime and the
|
|
63
|
+
// entry chunks) parses in old browsers, which then show the not-supported message
|
|
64
|
+
target: ['web', 'es5'],
|
|
65
|
+
|
|
62
66
|
entry: { [entryName]: entryPath },
|
|
63
67
|
|
|
64
68
|
parallelism: 100,
|
|
@@ -80,7 +84,8 @@ const createUMDConfig = (entryName, entryPath, libraryPath, outDir, isCore = fal
|
|
|
80
84
|
export: 'default',
|
|
81
85
|
umdNamedDefine: true
|
|
82
86
|
},
|
|
83
|
-
|
|
87
|
+
// Not plain `this`: with the ES5 target the bundle runs in a strict-mode function, where it's undefined
|
|
88
|
+
globalObject: "typeof self !== 'undefined' ? self : this",
|
|
84
89
|
chunkLoadingGlobal: 'webpackChunkdefra_DefraMap',
|
|
85
90
|
auxiliaryComment: {
|
|
86
91
|
root: 'Root Export',
|
|
@@ -109,17 +114,30 @@ const createUMDConfig = (entryName, entryPath, libraryPath, outDir, isCore = fal
|
|
|
109
114
|
|
|
110
115
|
resolve: {
|
|
111
116
|
extensions: ['.tsx', '.ts', '.jsx', '.js'],
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
// Plugins use the core's Preact through the externals above. The core bundles Preact
|
|
118
|
+
// in place of React, as the ESM and dev builds do; React's module code also uses
|
|
119
|
+
// Symbol, which would stop the entry point loading in old browsers.
|
|
120
|
+
alias: externalPreact
|
|
121
|
+
? {
|
|
122
|
+
preact: false,
|
|
123
|
+
'preact/compat': false,
|
|
124
|
+
'preact/hooks': false,
|
|
125
|
+
'preact/jsx-runtime': false
|
|
126
|
+
}
|
|
127
|
+
: {
|
|
128
|
+
react: path.resolve(__dirname, 'node_modules/preact/compat'),
|
|
129
|
+
'react-dom/client': path.resolve(__dirname, 'node_modules/preact/compat/client'),
|
|
130
|
+
'react-dom': path.resolve(__dirname, 'node_modules/preact/compat'),
|
|
131
|
+
'react/jsx-runtime': path.resolve(__dirname, 'node_modules/preact/jsx-runtime')
|
|
132
|
+
}
|
|
118
133
|
},
|
|
119
134
|
|
|
120
135
|
module: {
|
|
121
136
|
rules: [
|
|
122
137
|
{ test: /\.jsx?$/, loader: 'babel-loader', exclude: /node_modules/ },
|
|
138
|
+
// Emitted with a .js extension because some servers don't send a JavaScript
|
|
139
|
+
// content type for .mjs, which module workers require
|
|
140
|
+
{ test: /maplibre-gl-worker\.mjs$/, type: 'asset/resource', generator: { filename: 'im-maplibre-worker.js' } },
|
|
123
141
|
{ test: /\.css$/i, use: [MiniCssExtractPlugin.loader, 'css-loader'] },
|
|
124
142
|
{ test: /\.s[ac]ss$/i, use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'] }
|
|
125
143
|
]
|
|
@@ -127,6 +145,9 @@ const createUMDConfig = (entryName, entryPath, libraryPath, outDir, isCore = fal
|
|
|
127
145
|
|
|
128
146
|
plugins,
|
|
129
147
|
|
|
148
|
+
// maplibre-gl builds a URL from an expression when its worker is cross-origin; harmless
|
|
149
|
+
ignoreWarnings: [{ module: /maplibre-gl/, message: /Critical dependency/ }],
|
|
150
|
+
|
|
130
151
|
optimization: {
|
|
131
152
|
splitChunks: { chunks: () => false },
|
|
132
153
|
removeEmptyChunks: true,
|