@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.
Files changed (139) hide show
  1. package/assets/templates/add-polygons.njk +1 -1
  2. package/assets/templates/add-symbols.njk +4 -4
  3. package/assets/templates/draw-tools.njk +7 -7
  4. package/assets/templates/marker-panel.njk +5 -5
  5. package/assets/templates/place-marker.njk +8 -8
  6. package/assets/templates/search-control.njk +1 -1
  7. package/assets/templates/select-feature.njk +7 -7
  8. package/assets/templates/style-switcher.njk +4 -4
  9. package/assets/templates/toggle-marker-label.njk +3 -3
  10. package/dist/esm/im-core.js +1 -1
  11. package/dist/esm/im-shell.js +1 -1
  12. package/dist/esm/index.js +1 -1
  13. package/dist/umd/im-core.js +1 -1
  14. package/dist/umd/im-core.js.LICENSE.txt +0 -30
  15. package/dist/umd/index.js +1 -1
  16. package/dist/umd/index.js.LICENSE.txt +0 -20
  17. package/docs/api.md +3 -13
  18. package/docs/building-a-plugin.md +2 -2
  19. package/docs/examples/add-marker-with-panel.mdx +46 -44
  20. package/docs/examples/add-polygons.mdx +100 -98
  21. package/docs/examples/add-symbols.mdx +75 -73
  22. package/docs/examples/basic-map.mdx +16 -14
  23. package/docs/examples/button-map.mdx +16 -14
  24. package/docs/examples/draw-tools.mdx +119 -117
  25. package/docs/examples/place-marker.mdx +51 -49
  26. package/docs/examples/search-control.mdx +22 -20
  27. package/docs/examples/select-feature.mdx +107 -105
  28. package/docs/examples/style-switcher.mdx +47 -45
  29. package/docs/examples/toggle-marker-label.mdx +30 -28
  30. package/docs/getting-started.md +26 -24
  31. package/docs/plugins/draw.md +10 -10
  32. package/docs/plugins/interact.md +9 -9
  33. package/docs/plugins/plugin-descriptor.md +1 -1
  34. package/docs/plugins/search.md +3 -3
  35. package/docusaurus.config.cjs +23 -0
  36. package/package.json +3 -7
  37. package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
  38. package/plugins/beta/draw-es/dist/esm/index.js +1 -1
  39. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
  40. package/plugins/beta/draw-ml/dist/esm/index.js +1 -1
  41. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
  42. package/plugins/beta/draw-ml/dist/umd/index.js +1 -1
  43. package/plugins/beta/draw-ol/dist/esm/DrawMode.js +1 -1
  44. package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -1
  45. package/plugins/beta/draw-ol/dist/esm/geometryHelpers.js +1 -1
  46. package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
  47. package/plugins/beta/draw-ol/dist/esm/index.js +1 -1
  48. package/plugins/beta/frame/dist/esm/im-frame-plugin.js +1 -1
  49. package/plugins/beta/frame/dist/esm/index.js +1 -1
  50. package/plugins/beta/frame/dist/umd/im-frame-plugin.js +1 -1
  51. package/plugins/beta/frame/dist/umd/index.js +1 -1
  52. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  53. package/plugins/beta/map-styles/dist/esm/index.js +1 -1
  54. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  55. package/plugins/beta/map-styles/dist/umd/index.js +1 -1
  56. package/plugins/beta/scale-bar/dist/esm/im-scale-bar-plugin.js +1 -1
  57. package/plugins/beta/scale-bar/dist/esm/index.js +1 -1
  58. package/plugins/beta/scale-bar/dist/umd/im-scale-bar-plugin.js +1 -1
  59. package/plugins/beta/scale-bar/dist/umd/index.js +1 -1
  60. package/plugins/beta/use-location/dist/esm/im-use-location-plugin.js +1 -1
  61. package/plugins/beta/use-location/dist/esm/index.js +1 -1
  62. package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -1
  63. package/plugins/beta/use-location/dist/umd/index.js +1 -1
  64. package/plugins/datasets/dist/esm/im-datasets-esri-adapter.js +1 -1
  65. package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  66. package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
  67. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  68. package/plugins/datasets/dist/esm/index.js +1 -1
  69. package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
  70. package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
  71. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  72. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  73. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  74. package/plugins/datasets/dist/umd/index.js +1 -1
  75. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  76. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  77. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  78. package/plugins/draw/dist/esm/index.js +1 -1
  79. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  80. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  81. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  82. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  83. package/plugins/draw/dist/umd/index.js +1 -1
  84. package/plugins/draw/src/adapters/maplibre/styles.js +3 -2
  85. package/plugins/draw/src/adapters/maplibre/styles.test.js +3 -3
  86. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  87. package/plugins/interact/dist/esm/index.js +1 -1
  88. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  89. package/plugins/interact/dist/umd/index.js +1 -1
  90. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  91. package/plugins/map-key/dist/esm/index.js +1 -1
  92. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  93. package/plugins/map-key/dist/umd/index.js +1 -1
  94. package/plugins/menu/dist/esm/im-menu-plugin.js +1 -1
  95. package/plugins/menu/dist/esm/index.js +1 -1
  96. package/plugins/menu/dist/umd/im-menu-plugin.js +1 -1
  97. package/plugins/menu/dist/umd/index.js +1 -1
  98. package/plugins/search/dist/esm/im-search-plugin.js +1 -1
  99. package/plugins/search/dist/esm/index.js +1 -1
  100. package/plugins/search/dist/umd/im-search-plugin.js +1 -1
  101. package/plugins/search/dist/umd/index.js +1 -1
  102. package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
  103. package/providers/beta/esri/dist/esm/index.js +1 -1
  104. package/providers/beta/open-names/dist/esm/im-reverse-geocode.js +1 -1
  105. package/providers/beta/open-names/dist/esm/index.js +1 -1
  106. package/providers/beta/open-names/dist/umd/im-reverse-geocode.js +1 -1
  107. package/providers/beta/open-names/dist/umd/index.js +1 -1
  108. package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  109. package/providers/beta/openlayers/dist/esm/index.js +1 -1
  110. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  111. package/providers/beta/openlayers/dist/umd/index.js +1 -1
  112. package/providers/beta/openlayers/src/index.js +27 -4
  113. package/providers/beta/openlayers/src/index.test.js +47 -0
  114. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  115. package/providers/maplibre/dist/esm/index.js +1 -1
  116. package/providers/maplibre/dist/umd/im-maplibre-framework.js +1 -1
  117. package/providers/maplibre/dist/umd/im-maplibre-framework.js.LICENSE.txt +3 -3
  118. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  119. package/providers/maplibre/dist/umd/im-maplibre-worker.js +2 -0
  120. package/providers/maplibre/dist/umd/im-maplibre-worker.js.LICENSE.txt +4 -0
  121. package/providers/maplibre/dist/umd/index.js +1 -1
  122. package/providers/maplibre/src/index.js +41 -12
  123. package/providers/maplibre/src/index.test.js +43 -12
  124. package/providers/maplibre/src/utils/detectModuleWorker.js +25 -0
  125. package/providers/maplibre/src/utils/detectModuleWorker.test.js +40 -0
  126. package/providers/maplibre/src/utils/spatial.js +22 -12
  127. package/providers/maplibre/src/utils/spatial.test.js +6 -6
  128. package/providers/maplibre/src/utils/workerUrl.js +15 -0
  129. package/providers/maplibre/src/utils/workerUrl.test.js +14 -0
  130. package/rollup.esm.mjs +38 -1
  131. package/src/InteractiveMap/InteractiveMap.js +2 -1
  132. package/src/InteractiveMap/InteractiveMap.test.js +9 -2
  133. package/src/InteractiveMap/domStateManager.js +21 -1
  134. package/src/InteractiveMap/domStateManager.test.js +48 -1
  135. package/src/InteractiveMap/polyfills.js +4 -3
  136. package/src/InteractiveMap/polyfills.test.js +12 -0
  137. package/src/types.js +3 -5
  138. package/webpack.dev.mjs +2 -0
  139. 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 default): intercept URL.createObjectURL
37
- // 2. String URL workers (MapLibre workerUrl, used in CSP environments): intercept Worker constructor
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
- if (typeof url === 'string' && !url.startsWith('blob:')) {
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 to a separately hosted MapLibre worker file (`maplibre-gl-csp-worker.js`).
387
- * Required when running under a Content Security Policy that blocks `blob:` worker
388
- * URLs. The file ships with maplibre-gl and must be served from your own origin.
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
@@ -106,6 +106,8 @@ export default {
106
106
  }
107
107
  })
108
108
  ],
109
+ // maplibre-gl builds a URL from an expression when its worker is cross-origin; harmless
110
+ ignoreWarnings: [{ module: /maplibre-gl/, message: /Critical dependency/ }],
109
111
  module: {
110
112
  rules: [
111
113
  {
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
- globalObject: 'this',
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
- alias: {
113
- preact: false,
114
- 'preact/compat': false,
115
- 'preact/hooks': false,
116
- 'preact/jsx-runtime': false
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,