@defra/interactive-map 0.0.56-alpha → 0.0.57-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 (137) hide show
  1. package/dist/esm/im-core.js +1 -1
  2. package/dist/umd/im-core.js +1 -1
  3. package/dist/umd/index.js +1 -1
  4. package/docs/api/button-definition.md +11 -0
  5. package/docs/api/context.md +2 -0
  6. package/docs/api.md +3 -1
  7. package/docs/plugins/draw.md +189 -33
  8. package/package.json +1 -1
  9. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  10. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  11. package/plugins/datasets/dist/umd/index.js +1 -1
  12. package/plugins/datasets/src/initialise/DatasetsInit.jsx +6 -17
  13. package/plugins/datasets/src/initialise/DatasetsInit.test.jsx +3 -43
  14. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  15. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  16. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  17. package/plugins/draw/dist/esm/index.js +1 -1
  18. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  19. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  20. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  21. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  22. package/plugins/draw/dist/umd/index.js +1 -1
  23. package/plugins/draw/src/DrawInit.jsx +9 -6
  24. package/plugins/draw/src/DrawInit.test.jsx +15 -0
  25. package/plugins/draw/src/adapterEvents.js +78 -44
  26. package/plugins/draw/src/adapters/adapterContract.test.js +3 -3
  27. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +18 -10
  28. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +31 -22
  29. package/plugins/draw/src/adapters/maplibre/drawEvents.js +2 -1
  30. package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.js +13 -12
  31. package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.test.js +5 -5
  32. package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.js +1 -1
  33. package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.test.js +2 -2
  34. package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.js +6 -9
  35. package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.test.js +4 -4
  36. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +6 -9
  37. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +1 -1
  38. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.js +8 -14
  39. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.test.js +37 -8
  40. package/plugins/draw/src/adapters/maplibre/modes/editPointMode.js +11 -1
  41. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.js +14 -19
  42. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.test.js +41 -4
  43. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode.js +12 -1
  44. package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +3 -1
  45. package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.js +9 -10
  46. package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.test.js +5 -24
  47. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +10 -7
  48. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +12 -7
  49. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +5 -0
  50. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +7 -3
  51. package/plugins/draw/src/adapters/openlayers/draw/DrawMode.js +11 -11
  52. package/plugins/draw/src/adapters/openlayers/draw/DrawMode.test.js +15 -15
  53. package/plugins/draw/src/adapters/openlayers/edit/EditMode.js +21 -28
  54. package/plugins/draw/src/adapters/openlayers/edit/EditMode.test.js +26 -5
  55. package/plugins/draw/src/adapters/openlayers/edit/selectionState.js +5 -6
  56. package/plugins/draw/src/adapters/openlayers/edit/selectionState.test.js +2 -12
  57. package/plugins/draw/src/adapters/openlayers/edit/undoOps.js +9 -0
  58. package/plugins/draw/src/adapters/openlayers/edit/undoOps.test.js +7 -0
  59. package/plugins/draw/src/adapters/openlayers/point/drawPointMode.js +6 -9
  60. package/plugins/draw/src/adapters/openlayers/point/drawPointMode.test.js +3 -3
  61. package/plugins/draw/src/adapters/openlayers/point/editPointMode.js +18 -9
  62. package/plugins/draw/src/adapters/openlayers/point/editPointMode.test.js +29 -4
  63. package/plugins/draw/src/adapters/openlayers/point/pointOps.js +3 -2
  64. package/plugins/draw/src/adapters/openlayers/point/pointOps.test.js +6 -0
  65. package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.js +3 -4
  66. package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.test.js +2 -12
  67. package/plugins/draw/src/api/createNewShape.js +4 -4
  68. package/plugins/draw/src/api/createNewShape.test.js +1 -1
  69. package/plugins/draw/src/api/editFeature.js +8 -11
  70. package/plugins/draw/src/api/editFeature.test.js +33 -22
  71. package/plugins/draw/src/api/newLine.test.js +3 -3
  72. package/plugins/draw/src/api/newPoint.js +4 -5
  73. package/plugins/draw/src/api/newPoint.test.js +3 -3
  74. package/plugins/draw/src/api/newPolygon.test.js +3 -3
  75. package/plugins/draw/src/api/recheckGeometry.js +32 -0
  76. package/plugins/draw/src/api/recheckGeometry.test.js +55 -0
  77. package/plugins/draw/src/api/setGeometry.js +33 -0
  78. package/plugins/draw/src/api/setGeometry.test.js +48 -0
  79. package/plugins/draw/src/api/split.js +23 -22
  80. package/plugins/draw/src/api/split.test.js +33 -18
  81. package/plugins/draw/src/events.js +265 -77
  82. package/plugins/draw/src/events.test.js +708 -34
  83. package/plugins/draw/src/hooks/useSpatialList.js +10 -11
  84. package/plugins/draw/src/hooks/useSpatialList.test.js +3 -3
  85. package/plugins/draw/src/manifest.js +30 -15
  86. package/plugins/draw/src/manifest.test.js +91 -9
  87. package/plugins/draw/src/reducer.js +31 -9
  88. package/plugins/draw/src/reducer.test.js +35 -3
  89. package/plugins/draw/src/utils/drawModes.js +27 -0
  90. package/plugins/draw/src/utils/drawModes.test.js +27 -0
  91. package/plugins/draw/src/utils/needsDrawTarget.js +1 -5
  92. package/plugins/draw/src/utils/needsDrawTarget.test.js +1 -11
  93. package/plugins/draw/src/utils/touchTarget.js +34 -26
  94. package/plugins/draw/src/utils/touchTarget.test.js +32 -20
  95. package/plugins/draw/src/validation/commitChecks.js +185 -0
  96. package/plugins/draw/src/validation/commitChecks.test.js +205 -0
  97. package/plugins/draw/src/validation/liveDrawChecks.js +11 -11
  98. package/plugins/draw/src/validation/liveDrawChecks.test.js +37 -37
  99. package/plugins/draw/src/validation/liveStroke.js +6 -6
  100. package/plugins/draw/src/validation/liveStroke.test.js +27 -27
  101. package/plugins/draw/src/validation/rules.js +16 -14
  102. package/plugins/draw/src/validation/rules.test.js +5 -5
  103. package/plugins/draw/src/validation/validateGeometry.js +58 -31
  104. package/plugins/draw/src/validation/validateGeometry.test.js +68 -44
  105. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  106. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  107. package/plugins/interact/dist/umd/index.js +1 -1
  108. package/plugins/interact/src/hooks/useInteractionHandlers.js +3 -5
  109. package/plugins/interact/src/hooks/useInteractionHandlers.test.js +4 -3
  110. package/plugins/interact/src/hooks/useSpatialList.js +16 -17
  111. package/plugins/interact/src/hooks/useSpatialList.test.js +9 -9
  112. package/plugins/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  113. package/plugins/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  114. package/plugins/map-styles/src/MapStyles.jsx +2 -2
  115. package/providers/maplibre/dist/esm/index.js +1 -1
  116. package/providers/maplibre/dist/umd/index.js +1 -1
  117. package/providers/maplibre/src/index.js +11 -2
  118. package/providers/maplibre/src/index.test.js +23 -1
  119. package/providers/maplibre/src/utils/detectModuleWorker.js +8 -19
  120. package/providers/maplibre/src/utils/detectModuleWorker.test.js +19 -23
  121. package/providers/maplibre/src/utils/workerUrl.js +12 -0
  122. package/providers/maplibre/src/utils/workerUrl.test.js +14 -1
  123. package/src/App/components/MapButton/MapButton.jsx +6 -0
  124. package/src/App/components/MapButton/MapButton.test.jsx +10 -0
  125. package/src/App/components/Markers/Markers.jsx +3 -5
  126. package/src/App/components/Markers/Markers.test.jsx +9 -11
  127. package/src/App/components/Panel/Panel.jsx +2 -9
  128. package/src/App/hooks/useInterfaceAPI.js +16 -4
  129. package/src/App/hooks/useInterfaceAPI.test.js +66 -1
  130. package/src/App/renderer/mapButtons.js +2 -1
  131. package/src/App/renderer/mapButtons.test.js +9 -0
  132. package/src/App/store/MapProvider.jsx +3 -0
  133. package/src/App/store/MapProvider.test.jsx +24 -0
  134. package/src/config/mapSizeScales.js +3 -0
  135. package/src/types.js +4 -0
  136. package/src/utils/focusAfterPanelClose.js +9 -0
  137. package/src/utils/focusAfterPanelClose.test.js +40 -0
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see index.js.LICENSE.txt */
2
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("defra",[],e):"object"==typeof exports?exports.defra=e():(t.defra=t.defra||{},t.defra.drawPlugin=e())}(Object("undefined"!=typeof self?self:this),function(){return function(){"use strict";var t,e,r={738:function(t){t.exports=preactCompat}},n={};function o(t){var e=n[t];if(void 0!==e)return e.exports;var i=n[t]={exports:{}};return r[t].call(i.exports,i,i.exports,o),i.exports}o.m=r,o.d=function(t,e){for(var r in e)o.o(e,r)&&!o.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o.f={},o.e=function(t){return Promise.all(Object.keys(o.f).reduce(function(e,r){return o.f[r](t,e),e},[]))},o.u=function(t){return{356:"im-draw-ml-adapter",568:"im-draw-plugin",722:"im-draw-ol-adapter"}[t]+".js"},o.miniCssF=function(t){},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},t={},e="defra.drawPlugin:",o.l=function(r,n,i,u){if(t[r])t[r].push(n);else{var c,a;if(void 0!==i)for(var f=document.getElementsByTagName("script"),l=0;l<f.length;l++){var p=f[l];if(p.getAttribute("src")==r||p.getAttribute("data-webpack")==e+i){c=p;break}}c||(a=!0,(c=document.createElement("script")).charset="utf-8",o.nc&&c.setAttribute("nonce",o.nc),c.setAttribute("data-webpack",e+i),c.src=r),t[r]=[n];var s=function(e,n){c.onerror=c.onload=null,clearTimeout(d);var o=t[r];if(delete t[r],c.parentNode&&c.parentNode.removeChild(c),o&&o.forEach(function(t){return t(n)}),e)return e(n)},d=setTimeout(s.bind(null,void 0,{type:"timeout",target:c}),12e4);c.onerror=s.bind(null,c.onerror),c.onload=s.bind(null,c.onload),a&&document.head.appendChild(c)}},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},function(){var t;o.g.importScripts&&(t=o.g.location+"");var e=o.g.document;if(!t&&e&&(e.currentScript&&"SCRIPT"===e.currentScript.tagName.toUpperCase()&&(t=e.currentScript.src),!t)){var r=e.getElementsByTagName("script");if(r.length)for(var n=r.length-1;n>-1&&(!t||!/^http(s?):/.test(t));)t=r[n--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=t}(),function(){var t={57:0};o.f.j=function(e,r){var n=o.o(t,e)?t[e]:void 0;if(0!==n)if(n)r.push(n[2]);else{var i=new Promise(function(r,o){n=t[e]=[r,o]});r.push(n[2]=i);var u=o.p+o.u(e),c=new Error;o.l(u,function(r){if(o.o(t,e)&&(0!==(n=t[e])&&(t[e]=void 0),n)){var i=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+i+": "+u+")",c.name="ChunkLoadError",c.type=i,c.request=u,n[1](c)}},"chunk-"+e,e)}};var e=function(e,r){var n,i,u=r[0],c=r[1],a=r[2],f=0;if(u.some(function(e){return 0!==t[e]})){for(n in c)o.o(c,n)&&(o.m[n]=c[n]);a&&a(o)}for(e&&e(r);f<u.length;f++)i=u[f],o.o(t,i)&&t[i]&&t[i][0](),t[i]=0},r=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap||[];r.forEach(e.bind(null,0)),r.push=e.bind(null,r.push.bind(r))}();var i={};function u(t){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u(t)}function c(){var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof f?n:f,l=Object.create(c.prototype);return a(l,"_invoke",function(r,n,o){var i,c,a,f=0,l=o||[],p=!1,s={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,r){return i=e,c=0,a=t,s.n=r,u}};function d(r,n){for(c=r,a=n,e=0;!p&&f&&!o&&e<l.length;e++){var o,i=l[e],d=s.p,b=i[2];r>3?(o=b===n)&&(a=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,s.v=n,s.n=i[1]):d<b&&(o=r<3||i[0]>n||n>b)&&(i[4]=r,i[5]=n,s.n=b,c=0))}if(o||r>1)return u;throw p=!0,n}return function(o,l,b){if(f>1)throw TypeError("Generator is already running");for(p&&1===l&&d(l,b),c=l,a=b;(e=c<2?t:a)||!p;){i||(c?c<3?(c>1&&(s.n=-1),d(c,a)):s.n=a:s.v=a);try{if(f=2,i){if(c||(o="next"),e=i[o]){if(!(e=e.call(i,a)))throw TypeError("iterator result is not an object");if(!e.done)return e;a=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(a=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=t}else if((e=(p=s.n<0)?a:r.call(n,s))!==u)break}catch(e){i=t,c=1,a=e}finally{f=1}}return{value:e,done:p}}}(r,o,i),!0),l}var u={};function f(){}function l(){}function p(){}e=Object.getPrototypeOf;var s=[][n]?e(e([][n]())):(a(e={},n,function(){return this}),e),d=p.prototype=f.prototype=Object.create(s);function b(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,a(t,o,"GeneratorFunction")),t.prototype=Object.create(d),t}return l.prototype=p,a(d,"constructor",p),a(p,"constructor",l),l.displayName="GeneratorFunction",a(p,o,"GeneratorFunction"),a(d),a(d,o,"Generator"),a(d,n,function(){return this}),a(d,"toString",function(){return"[object Generator]"}),(c=function(){return{w:i,m:b}})()}function a(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}a=function(t,e,r,n){function i(e,r){a(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},a(t,e,r,n)}function f(t,e,r,n,o,i,u){try{var c=t[i](u),a=c.value}catch(t){return void r(t)}c.done?e(a):Promise.resolve(a).then(n,o)}function l(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function p(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?l(Object(r),!0).forEach(function(e){s(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function s(t,e,r){return(e=function(t){var e=function(t){if("object"!=u(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=u(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==u(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function d(){var t,e;return p(p({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{id:"draw",load:(t=c().m(function t(){var e;return c().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,o.e(568).then(o.bind(o,841));case 1:return e=t.v.manifest,t.a(2,e)}},t)}),e=function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function u(t){f(i,n,o,u,c,"next",t)}function c(t){f(i,n,o,u,c,"throw",t)}u(void 0)})},function(){return e.apply(this,arguments)})})}return o.d(i,{default:function(){return d}}),i.default}()});
2
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("defra",[],e):"object"==typeof exports?exports.defra=e():(t.defra=t.defra||{},t.defra.drawPlugin=e())}(Object("undefined"!=typeof self?self:this),function(){return function(){"use strict";var t,e,r={738:function(t){t.exports=preactCompat}},n={};function o(t){var e=n[t];if(void 0!==e)return e.exports;var i=n[t]={exports:{}};return r[t].call(i.exports,i,i.exports,o),i.exports}o.m=r,o.d=function(t,e){for(var r in e)o.o(e,r)&&!o.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o.f={},o.e=function(t){return Promise.all(Object.keys(o.f).reduce(function(e,r){return o.f[r](t,e),e},[]))},o.u=function(t){return{356:"im-draw-ml-adapter",568:"im-draw-plugin",722:"im-draw-ol-adapter"}[t]+".js"},o.miniCssF=function(t){},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},t={},e="defra.drawPlugin:",o.l=function(r,n,i,u){if(t[r])t[r].push(n);else{var c,a;if(void 0!==i)for(var f=document.getElementsByTagName("script"),l=0;l<f.length;l++){var p=f[l];if(p.getAttribute("src")==r||p.getAttribute("data-webpack")==e+i){c=p;break}}c||(a=!0,(c=document.createElement("script")).charset="utf-8",o.nc&&c.setAttribute("nonce",o.nc),c.setAttribute("data-webpack",e+i),c.src=r),t[r]=[n];var s=function(e,n){c.onerror=c.onload=null,clearTimeout(d);var o=t[r];if(delete t[r],c.parentNode&&c.parentNode.removeChild(c),o&&o.forEach(function(t){return t(n)}),e)return e(n)},d=setTimeout(s.bind(null,void 0,{type:"timeout",target:c}),12e4);c.onerror=s.bind(null,c.onerror),c.onload=s.bind(null,c.onload),a&&document.head.appendChild(c)}},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},function(){var t;o.g.importScripts&&(t=o.g.location+"");var e=o.g.document;if(!t&&e&&(e.currentScript&&"SCRIPT"===e.currentScript.tagName.toUpperCase()&&(t=e.currentScript.src),!t)){var r=e.getElementsByTagName("script");if(r.length)for(var n=r.length-1;n>-1&&(!t||!/^http(s?):/.test(t));)t=r[n--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=t}(),function(){var t={57:0};o.f.j=function(e,r){var n=o.o(t,e)?t[e]:void 0;if(0!==n)if(n)r.push(n[2]);else{var i=new Promise(function(r,o){n=t[e]=[r,o]});r.push(n[2]=i);var u=o.p+o.u(e),c=new Error;o.l(u,function(r){if(o.o(t,e)&&(0!==(n=t[e])&&(t[e]=void 0),n)){var i=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+i+": "+u+")",c.name="ChunkLoadError",c.type=i,c.request=u,n[1](c)}},"chunk-"+e,e)}};var e=function(e,r){var n,i,u=r[0],c=r[1],a=r[2],f=0;if(u.some(function(e){return 0!==t[e]})){for(n in c)o.o(c,n)&&(o.m[n]=c[n]);a&&a(o)}for(e&&e(r);f<u.length;f++)i=u[f],o.o(t,i)&&t[i]&&t[i][0](),t[i]=0},r=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap||[];r.forEach(e.bind(null,0)),r.push=e.bind(null,r.push.bind(r))}();var i={};function u(t){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u(t)}function c(){var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof f?n:f,l=Object.create(c.prototype);return a(l,"_invoke",function(r,n,o){var i,c,a,f=0,l=o||[],p=!1,s={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,r){return i=e,c=0,a=t,s.n=r,u}};function d(r,n){for(c=r,a=n,e=0;!p&&f&&!o&&e<l.length;e++){var o,i=l[e],d=s.p,b=i[2];r>3?(o=b===n)&&(a=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,s.v=n,s.n=i[1]):d<b&&(o=r<3||i[0]>n||n>b)&&(i[4]=r,i[5]=n,s.n=b,c=0))}if(o||r>1)return u;throw p=!0,n}return function(o,l,b){if(f>1)throw TypeError("Generator is already running");for(p&&1===l&&d(l,b),c=l,a=b;(e=c<2?t:a)||!p;){i||(c?c<3?(c>1&&(s.n=-1),d(c,a)):s.n=a:s.v=a);try{if(f=2,i){if(c||(o="next"),e=i[o]){if(!(e=e.call(i,a)))throw TypeError("iterator result is not an object");if(!e.done)return e;a=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(a=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=t}else if((e=(p=s.n<0)?a:r.call(n,s))!==u)break}catch(e){i=t,c=1,a=e}finally{f=1}}return{value:e,done:p}}}(r,o,i),!0),l}var u={};function f(){}function l(){}function p(){}e=Object.getPrototypeOf;var s=[][n]?e(e([][n]())):(a(e={},n,function(){return this}),e),d=p.prototype=f.prototype=Object.create(s);function b(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,a(t,o,"GeneratorFunction")),t.prototype=Object.create(d),t}return l.prototype=p,a(d,"constructor",p),a(p,"constructor",l),l.displayName="GeneratorFunction",a(p,o,"GeneratorFunction"),a(d),a(d,o,"Generator"),a(d,n,function(){return this}),a(d,"toString",function(){return"[object Generator]"}),(c=function(){return{w:i,m:b}})()}function a(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}a=function(t,e,r,n){function i(e,r){a(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},a(t,e,r,n)}function f(t,e,r,n,o,i,u){try{var c=t[i](u),a=c.value}catch(t){return void r(t)}c.done?e(a):Promise.resolve(a).then(n,o)}function l(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function p(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?l(Object(r),!0).forEach(function(e){s(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function s(t,e,r){return(e=function(t){var e=function(t){if("object"!=u(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=u(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==u(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function d(){var t,e;return p(p({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{id:"draw",load:(t=c().m(function t(){var e;return c().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,o.e(568).then(o.bind(o,362));case 1:return e=t.v.manifest,t.a(2,e)}},t)}),e=function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function u(t){f(i,n,o,u,c,"next",t)}function c(t){f(i,n,o,u,c,"throw",t)}u(void 0)})},function(){return e.apply(this,arguments)})})}return o.d(i,{default:function(){return d}}),i.default}()});
@@ -4,7 +4,8 @@ import { loadDrawAdapter } from './adapters/loadDrawAdapter.js'
4
4
  import { attachEvents } from './events.js'
5
5
  import { useSpatialList } from './hooks/useSpatialList.js'
6
6
  import { APPLICATION_MODE_ID } from './defaults.js'
7
- import { needsDrawTarget, isDrawingMode } from './utils/needsDrawTarget.js'
7
+ import { needsDrawTarget } from './utils/needsDrawTarget.js'
8
+ import { isDrawingMode, isSessionMode } from './utils/drawModes.js'
8
9
  import { logger } from '../../../src/services/logger.js'
9
10
 
10
11
  // Resolves in a later task, after any effects Preact is still running
@@ -71,8 +72,9 @@ export const DrawInit = ({ appState, appConfig, mapState, pluginConfig, pluginSt
71
72
  // Mirrored in the render body so the crosshair effect's cleanup below can read the CURRENT
72
73
  // shouldShowCrosshair decision, not the stale one its closure captured when it last ran.
73
74
  const shouldShowCrosshairRef = useRef(false)
74
- shouldShowCrosshairRef.current = needsDrawTarget({ appState, pluginState }) ||
75
- (isDrawingMode(pluginState.mode) && appState.interfaceType === 'keyboard')
75
+ // Not while a finished shape is held waiting on its check — there's nothing left to place.
76
+ shouldShowCrosshairRef.current = !pluginState.holding && (needsDrawTarget({ appState, pluginState }) ||
77
+ (isDrawingMode(pluginState.mode) && appState.interfaceType === 'keyboard'))
76
78
 
77
79
  useLoadDrawAdapter({ mapState, pluginConfig, pluginState, mapProvider, eventBus, symbolRegistry })
78
80
 
@@ -111,12 +113,12 @@ export const DrawInit = ({ appState, appConfig, mapState, pluginConfig, pluginSt
111
113
  crossHair.hide()
112
114
  }
113
115
  }
114
- }, [pluginState.mode, appState.interfaceType, appState.expandedButtons])
116
+ }, [pluginState.mode, pluginState.holding, appState.interfaceType, appState.expandedButtons])
115
117
 
116
118
  // Keep the active draw/edit session's interface type in sync so the touch offset target and
117
119
  // rubber band update immediately if the input device changes mid-session.
118
120
  useEffect(() => {
119
- if (!['edit_vertex', 'edit_point', 'draw_polygon', 'draw_line', 'draw_point'].includes(pluginState.mode) || !mapProvider.draw) {
121
+ if (!isSessionMode(pluginState.mode) || !mapProvider.draw) {
120
122
  return undefined
121
123
  }
122
124
  mapProvider.draw.setInterfaceType(appState.interfaceType)
@@ -138,7 +140,8 @@ export const DrawInit = ({ appState, appConfig, mapState, pluginConfig, pluginSt
138
140
  pluginState,
139
141
  events: EVENTS,
140
142
  eventBus,
141
- hints
143
+ hints,
144
+ announce: services.announce
142
145
  })
143
146
  }, [mapProvider, appState, pluginState])
144
147
  }
@@ -314,6 +314,21 @@ describe('crosshair', () => {
314
314
 
315
315
  expect(props.mapState.crossHair.hide).toHaveBeenCalled()
316
316
  })
317
+
318
+ test('hides the crosshair while a finished shape is held waiting on its check', async () => {
319
+ const { props } = makeProps({
320
+ appState: { interfaceType: 'touch', mode: null, layoutRefs: { viewportRef: { current: null } } },
321
+ pluginState: { dispatch: jest.fn(), mode: 'draw_polygon', holding: false }
322
+ })
323
+ const result = await renderInit(props)
324
+ expect(props.mapState.crossHair.fixAtCenter).toHaveBeenCalled()
325
+
326
+ // Holding doesn't change the mode, so the effect must re-run on holding itself
327
+ props.pluginState.holding = true
328
+ result.rerender(<DrawInit {...props} />)
329
+
330
+ expect(props.mapState.crossHair.hide).toHaveBeenCalled()
331
+ })
317
332
  })
318
333
 
319
334
  describe('interface type sync', () => {
@@ -1,47 +1,52 @@
1
1
  /**
2
- * What stage of the draw/edit lifecycle a geometry validation call is running at.
3
- * Passed as `context.phase` through validateGeometry (validation/validateGeometry.js)
4
- * to the default rules (validation/rules.js) and the user's `onGeometryChange` callback.
2
+ * What stage of the draw/edit lifecycle a geometry check is running at. Passed as
3
+ * `context.phase` through validateGeometry (validation/validateGeometry.js) to the
4
+ * default rules (validation/rules.js) and to the user's callbacks:
5
+ * - 'preview' and 'place' go to `onGeometryPreview`, which must answer synchronously
6
+ * - every other phase goes to `onGeometryChange`, which may return a Promise
5
7
  *
6
- * @typedef {'preview' | 'place' | 'create' | 'edit-start' |
7
- * 'commit-add' | 'commit-move' | 'commit-insert' | 'commit-delete'} GeometryChangePhase
8
+ * @typedef {'preview' | 'place' | 'change' | 'create' | 'edit-start' | 'edit-finish' | 'recheck'} GeometryChangePhase
8
9
  *
9
- * 'preview' - live, in-progress feedback (drag / rubber-band); nothing
10
- * has committed yet, and nothing can be vetoed at this stage.
11
- * While drawing, this single check also drives the
12
- * Add-point button (see liveDrawChecks.js) — it isn't only
13
- * a display concern, just never a commit/veto one.
14
- * 'place' - a candidate vertex is genuinely about to be committed
15
- * (a real click/tap/Add-point press), evaluated once,
16
- * synchronously; a HARD_RULES failure vetoes it outright
17
- * and it never appears. Never fires continuously — that's
18
- * 'preview''s job (see above).
19
- * 'create' - a whole new feature just finished being drawn.
20
- * 'edit-start' - an existing feature was just loaded into an edit session;
21
- * nothing has changed yet, this is the baseline check.
22
- * 'commit-add' - a vertex was added while drawing.
23
- * 'commit-move' - a vertex was dragged/nudged while editing.
24
- * 'commit-insert' - a vertex was inserted at a midpoint while editing.
25
- * 'commit-delete' - a vertex was removed while editing.
10
+ * 'preview' - live, in-progress feedback (drag / rubber-band); nothing
11
+ * has committed yet, and nothing can be vetoed at this stage.
12
+ * While drawing, this single check also drives the
13
+ * Add-point button (see liveDrawChecks.js); while editing,
14
+ * it also gates Done.
15
+ * 'place' - a candidate vertex is genuinely about to be committed
16
+ * (a real click/tap/Add-point press), evaluated once,
17
+ * synchronously; a PLACE_RULES failure vetoes it outright
18
+ * and it never appears. Never fires continuously — that's
19
+ * 'preview''s job (see above).
20
+ * 'create' - a whole new feature finished without a passing or pending
21
+ * result for its final geometry (e.g. a new point), or its
22
+ * last result asked for recheckOnFinish, so it's checked now.
23
+ * 'edit-start' - an existing feature was just loaded into an edit session;
24
+ * nothing has changed yet, this is the baseline check.
25
+ * 'edit-finish' - Done was pressed on an edit whose last result asked for
26
+ * recheckOnFinish, so it's checked now.
27
+ * 'recheck' - the unchanged shape is checked again (recheckGeometry), with
28
+ * any detail it was given as `event.detail`.
29
+ * 'change' - the shape changed: a vertex was added, moved, inserted or
30
+ * removed, the whole shape was replaced (setGeometry), or a
31
+ * change was undone.
26
32
  */
27
33
 
34
+ // The phase every committed change reports (see GeometryChangePhase)
35
+ export const CHANGE_PHASE = 'change'
36
+
28
37
  /**
29
- * The single event object passed to a user's `onGeometryChange` callback
30
- * (validateGeometry.js) — `onGeometryChange({ feature, ...context })`. Not every
31
- * field is present on every phase; see each field's own doc below.
38
+ * The event object passed to a user's `onGeometryPreview` or `onGeometryChange`
39
+ * callback — `callback({ feature, ...context })`. Not every field is present on every
40
+ * phase; see each field's own doc below.
32
41
  *
33
- * While drawing, every rubber-band mouse-move invokes this callback ONCE,
42
+ * While drawing, every rubber-band mouse-move invokes `onGeometryPreview` ONCE,
34
43
  * throttled to one call per animation frame, always with `phase: 'preview'` —
35
44
  * even before any vertex is committed, since a location-based rule can be
36
45
  * meaningful against a single candidate point. Its verdict is combined
37
46
  * (internally, in liveDrawChecks.js) with two independently-floored built-in
38
- * checks to drive BOTH the dashed stroke / Done gate AND the Add-point button —
39
- * you don't need to do anything to support both; they share this one call. A
40
- * separate, genuinely momentary call with `phase: 'place'` (see
41
- * GeometryChangePhase) fires only for a real placement attempt, evaluated
42
- * synchronously, never continuously. Earlier versions of this plugin called
43
- * the callback twice per mouse-move (once per phase, for the same instant) —
44
- * that's been unified into the single 'preview' call described here.
47
+ * checks to drive BOTH the dashed stroke AND the Add-point button. A separate,
48
+ * genuinely momentary call with `phase: 'place'` (see GeometryChangePhase) fires
49
+ * only for a real placement attempt, evaluated synchronously, never continuously.
45
50
  *
46
51
  * @typedef {object} GeometryChangeEvent
47
52
  * @property {object} feature - GeoJSON feature representing the shape at this
@@ -50,19 +55,45 @@
50
55
  * committed/candidate feature for that specific change.
51
56
  * @property {GeometryChangePhase} phase - what stage of the draw/edit lifecycle
52
57
  * this is. Always present.
53
- * @property {'draw_polygon' | 'draw_line' | 'edit_vertex'} mode - the active draw
54
- * mode. Always present.
58
+ * @property {'draw_polygon' | 'draw_line' | 'draw_point' | 'edit_vertex' | 'edit_point'} mode -
59
+ * the active draw mode. Always present.
55
60
  * @property {number} [vertexIndex] - index of the vertex being placed, added,
56
- * moved, inserted, or deleted. Present on 'place' and every 'commit-*' phase;
57
- * absent on 'preview', 'create', and 'edit-start' (those have no single vertex
58
- * to point at).
61
+ * moved, inserted, or deleted. Present on 'place' and on a 'change' to a single
62
+ * vertex; absent on 'preview', 'create', 'edit-start', 'edit-finish', 'recheck' and a
63
+ * setGeometry 'change' (those have no single vertex to point at).
59
64
  * @property {number} [numVertices] - count of already-committed vertices,
60
65
  * excluding any in-progress rubber-band cursor point. Present on every
61
66
  * 'preview' call, with no minimum — including 0, against the very first
62
67
  * candidate point, before any vertex is committed. Note this is a lower bar
63
- * than the built-in live rules, which stay skipped until the geometry type's
68
+ * than the built-in preview rules, which stay skipped until the geometry type's
64
69
  * minimum vertex count is reached (self-intersection/area are meaningless
65
70
  * below that).
71
+ * @property {*} [detail] - the value passed to recheckGeometry(detail). Present on
72
+ * 'recheck' only, when one was given.
73
+ */
74
+
75
+ /**
76
+ * What a user's `onGeometryPreview` or `onGeometryChange` callback returns, after
77
+ * normaliseResult (validation/validateGeometry.js). `true`/`undefined` and `false`
78
+ * are shorthands for valid and invalid.
79
+ *
80
+ * @typedef {object} GeometryCheckResult
81
+ * @property {boolean} valid
82
+ * @property {string} [reason] - shown as a hint toast and sent with draw:geometryinvalid
83
+ * @property {string} [announcement] - announced to screen readers in place of draw's own
84
+ * message; the reason then isn't shown as a hint, as the consumer presents it
85
+ * @property {boolean} [recheckOnFinish] - `onGeometryChange` only: don't reuse this
86
+ * result when the shape is finished, check it again with phase 'create'
87
+ */
88
+
89
+ /**
90
+ * The second argument passed to a user's `onGeometryChange` callback —
91
+ * `onGeometryChange(event, { signal, revision })` (validation/commitChecks.js).
92
+ *
93
+ * @typedef {object} GeometryCheckContext
94
+ * @property {AbortSignal} signal - aborted when a newer change is checked or the
95
+ * session ends; a result for an aborted check is ignored.
96
+ * @property {number} revision - increases with every check.
66
97
  */
67
98
 
68
99
  /**
@@ -89,14 +120,17 @@
89
120
  * - Preview (draw/split live update): the in-progress
90
121
  * feature itself (has `coordinates`, no `phase`).
91
122
  * - Commit-level validation: `{ feature, phase, vertexIndex }`
92
- * where phase ∈ 'commit-add' | 'commit-move' |
93
- * 'commit-insert' | 'commit-delete' (see GeometryChangePhase).
94
- * events.js validates these and reverts invalid ones.
123
+ * where phase is 'change' (CHANGE_PHASE, see
124
+ * GeometryChangePhase). events.js checks these
125
+ * (validation/commitChecks.js) to gate Done; it never
126
+ * reverts them.
95
127
  * Listeners must guard for the shape they expect.
96
128
  * INTERFACE_TYPE_CHANGE { interfaceType: 'mouse' | 'touch' | 'keyboard' }
97
- * PLACEMENT_BLOCKED { feature, reason, phase: 'place', mode, vertexIndex } —
129
+ * PLACEMENT_BLOCKED { feature, reason, source, announcement?, phase: 'place', mode, vertexIndex } —
130
+ * built by validateGeometry.js's toPlacementBlocked; source is
131
+ * 'rules' or 'callback'.
98
132
  * a REAL placement attempt (click/tap/Add-point press)
99
- * was rejected by validatePlacement (hard rule or user
133
+ * was rejected by validatePlacement (placement rule or user
100
134
  * callback), evaluated once, synchronously; feature is
101
135
  * the candidate geometry that was refused. Distinct from
102
136
  * CAN_PLACE_CHANGE below, which is a continuous forecast
@@ -25,7 +25,7 @@ const CONTRACT_METHODS = [
25
25
  'setSnapLayers',
26
26
  'isSnapEnabled',
27
27
  'setFeatureProperty',
28
- 'setGeometryValid',
28
+ 'setCanFinish',
29
29
  'setInvalid',
30
30
  'on',
31
31
  'off',
@@ -40,8 +40,8 @@ describe.each([
40
40
  expect(typeof Adapter.prototype[method]).toBe('function')
41
41
  })
42
42
 
43
- test('exposes the _geometryValidator accessor pair (user callback storage)', () => {
44
- const descriptor = Object.getOwnPropertyDescriptor(Adapter.prototype, '_geometryValidator')
43
+ test('exposes the _previewValidator accessor pair (onGeometryPreview storage)', () => {
44
+ const descriptor = Object.getOwnPropertyDescriptor(Adapter.prototype, '_previewValidator')
45
45
  expect(typeof descriptor?.get).toBe('function')
46
46
  expect(typeof descriptor?.set).toBe('function')
47
47
  })
@@ -64,6 +64,7 @@ export const displayedShape = (mode, coordinates) => {
64
64
  * done() / cancel() / undo() / deleteVertex()
65
65
  * nudgeSelectedVertex(dx, dy, isLargeStep)
66
66
  * getVertexItems() / selectVertex(index) / insertVertexAtMidpoint(index)
67
+ * setGeometry(geometry)
67
68
  * get(id) / add(feature) / setStyle(id, properties) / delete(id) / deleteAll()
68
69
  * setSnapEnabled(bool) / setSnapLayers(layers) / isSnapEnabled()
69
70
  * setFeatureProperty(id, property, value) / setDrawingPreviewProperty(property, value)
@@ -202,9 +203,9 @@ export class MaplibreDrawAdapter {
202
203
  const shape = displayedShape(mode, event.coordinates)
203
204
  if (!shape) { return }
204
205
  if (mode === 'draw_polygon' || mode === 'draw_line') {
205
- this._liveDrawChecks.update({ feature: shape.feature, numVertices: shape.numVertices, context: { mode }, onGeometryChange: this._geometryValidator })
206
+ this._liveDrawChecks.update({ feature: shape.feature, numVertices: shape.numVertices, context: { mode }, onGeometryPreview: this._previewValidator })
206
207
  } else {
207
- this._liveStroke.update({ ...shape, context: { mode }, onGeometryChange: this._geometryValidator })
208
+ this._liveStroke.update({ ...shape, context: { mode }, onGeometryPreview: this._previewValidator })
208
209
  }
209
210
  }
210
211
 
@@ -282,16 +283,23 @@ export class MaplibreDrawAdapter {
282
283
  this._map.fire(CUSTOM_DRAW_EVENTS.INSERT_VERTEX_AT_MIDPOINT, { index })
283
284
  }
284
285
 
285
- // Record the current geometry validity so the draw mode can block finish gestures
286
- // (double-click / click-to-close) while the in-progress shape is invalid.
287
- setGeometryValid (valid) {
288
- this._map._drawGeometryValid = valid
286
+ // Replaces the edited shape as a single undoable change. Bridged into
287
+ // the mode via a custom event, same pattern as insertVertexAtMidpoint.
288
+ setGeometry (geometry) {
289
+ this._map.fire(CUSTOM_DRAW_EVENTS.SET_GEOMETRY, { geometry })
289
290
  }
290
291
 
291
- // The api entry points assign the active user validator to the adapter; store it
292
- // on the map (like _drawGeometryValid) so modes can veto placements synchronously.
293
- set _geometryValidator (fn) { this._map._drawGeometryValidator = fn }
294
- get _geometryValidator () { return this._map._drawGeometryValidator }
292
+ // Record whether the in-progress shape can be finished, so the draw mode can block finish
293
+ // gestures (double-click / click-to-close) while its latest check has failed.
294
+ setCanFinish (canFinish) {
295
+ this._map._drawCanFinish = canFinish
296
+ }
297
+
298
+ // The api entry points assign the session's onGeometryPreview callback to the adapter
299
+ // (see validation/commitChecks.js's startCheckSession); store it on the map (like
300
+ // _drawCanFinish) so modes can veto placements synchronously.
301
+ set _previewValidator (fn) { this._map._drawPreviewValidator = fn }
302
+ get _previewValidator () { return this._map._drawPreviewValidator }
295
303
 
296
304
  // Committed-verdict write (events.js, edit mode): routed through the live-stroke
297
305
  // controller so its cached state stays in sync with the rendered layers.
@@ -315,7 +315,7 @@ describe('live invalid stroke (draw mode)', () => {
315
315
 
316
316
  test('commit-level (has a phase) events do not drive the stroke; events.js owns those', () => {
317
317
  const { map } = drawPolygonSetup()
318
- onHandler(map, CUSTOM_DRAW_EVENTS.GEOMETRY_CHANGE)({ feature: bowtie, phase: 'commit-add', vertexIndex: 3 })
318
+ onHandler(map, CUSTOM_DRAW_EVENTS.GEOMETRY_CHANGE)({ feature: bowtie, phase: 'change', vertexIndex: 3 })
319
319
  expect(map.setLayoutProperty).not.toHaveBeenCalled()
320
320
  })
321
321
 
@@ -355,13 +355,13 @@ describe('live invalid stroke (draw mode)', () => {
355
355
  test('the user callback runs ONCE per frame in draw mode, with phase preview, driving both the stroke and Add point from that single call', () => {
356
356
  jest.useFakeTimers()
357
357
  const { map, bus } = drawPolygonSetup()
358
- map._drawGeometryValidator = jest.fn(() => ({ valid: false, reason: 'outside region' }))
358
+ map._drawPreviewValidator = jest.fn(() => ({ valid: false, reason: 'outside region' }))
359
359
  const fire = onHandler(map, CUSTOM_DRAW_EVENTS.GEOMETRY_CHANGE)
360
360
  fire(square)
361
- expect(map._drawGeometryValidator).not.toHaveBeenCalled() // deferred to the frame
361
+ expect(map._drawPreviewValidator).not.toHaveBeenCalled() // deferred to the frame
362
362
  jest.runAllTimers()
363
- expect(map._drawGeometryValidator).toHaveBeenCalledTimes(1) // not once per gate
364
- expect(map._drawGeometryValidator).toHaveBeenCalledWith(expect.objectContaining({ phase: 'preview' }))
363
+ expect(map._drawPreviewValidator).toHaveBeenCalledTimes(1) // not once per gate
364
+ expect(map._drawPreviewValidator).toHaveBeenCalledWith(expect.objectContaining({ phase: 'preview' }))
365
365
  expect(map.setLayoutProperty).toHaveBeenCalledWith('stroke-active-invalid.hot', 'visibility', 'visible')
366
366
  expect(bus.emit).toHaveBeenCalledWith('canplacechange', expect.objectContaining({ canPlace: false, reason: 'outside region' }))
367
367
  jest.useRealTimers()
@@ -370,12 +370,12 @@ describe('live invalid stroke (draw mode)', () => {
370
370
  test('the user callback runs even before any vertex is placed, gating both the stroke and Add point from the very first candidate point', () => {
371
371
  jest.useFakeTimers()
372
372
  const { map, bus } = drawPolygonSetup()
373
- map._drawGeometryValidator = jest.fn(() => ({ valid: false, reason: 'outside region' }))
373
+ map._drawPreviewValidator = jest.fn(() => ({ valid: false, reason: 'outside region' }))
374
374
  const fire = onHandler(map, CUSTOM_DRAW_EVENTS.GEOMETRY_CHANGE)
375
375
  // Zero committed vertices — coordinates is just the rubber-band cursor point.
376
376
  fire({ type: 'draw.geometrychange', coordinates: [[[5, 5]]] })
377
377
  jest.runAllTimers()
378
- expect(map._drawGeometryValidator).toHaveBeenCalledWith(expect.objectContaining({ numVertices: 0, phase: 'preview' }))
378
+ expect(map._drawPreviewValidator).toHaveBeenCalledWith(expect.objectContaining({ numVertices: 0, phase: 'preview' }))
379
379
  expect(bus.emit).toHaveBeenCalledWith('canplacechange', expect.objectContaining({ canPlace: false, reason: 'outside region' }))
380
380
  expect(map.setLayoutProperty).toHaveBeenCalledWith('stroke-active-invalid.hot', 'visibility', 'visible')
381
381
  jest.useRealTimers()
@@ -430,7 +430,7 @@ describe('live invalid stroke (edit mode)', () => {
430
430
  const { map, draw, bus } = editSetup()
431
431
  draw.getMode.mockReturnValue('edit_point')
432
432
  const fire = onHandler(map, CUSTOM_DRAW_EVENTS.GEOMETRY_CHANGE)
433
- map._drawGeometryValidator = () => ({ valid: false, reason: 'outside region' })
433
+ map._drawPreviewValidator = () => ({ valid: false, reason: 'outside region' })
434
434
  fire({ type: 'draw.geometrychange', coordinates: [5, 5] })
435
435
  jest.runAllTimers()
436
436
  expect(bus.emit).toHaveBeenCalledWith('validitychange', expect.objectContaining({ valid: false, reason: 'outside region' }))
@@ -446,25 +446,34 @@ describe('live invalid stroke (edit mode)', () => {
446
446
  test('the user callback runs throttled during an edit drag', () => {
447
447
  jest.useFakeTimers()
448
448
  const { map } = editSetup()
449
- map._drawGeometryValidator = jest.fn(() => ({ valid: false, reason: 'outside region' }))
449
+ map._drawPreviewValidator = jest.fn(() => ({ valid: false, reason: 'outside region' }))
450
450
  const fire = onHandler(map, CUSTOM_DRAW_EVENTS.GEOMETRY_CHANGE)
451
451
  fire({ type: 'draw.geometrychange', coordinates: [[[0, 0], [10, 0], [10, 10], [0, 10]]] })
452
452
  fire({ type: 'draw.geometrychange', coordinates: [[[0, 0], [10, 0], [10, 10], [0, 11]]] })
453
- expect(map._drawGeometryValidator).not.toHaveBeenCalled() // deferred to the frame
453
+ expect(map._drawPreviewValidator).not.toHaveBeenCalled() // deferred to the frame
454
454
  jest.runAllTimers()
455
- expect(map._drawGeometryValidator).toHaveBeenCalledTimes(1) // trailing edge only
455
+ expect(map._drawPreviewValidator).toHaveBeenCalledTimes(1) // trailing edge only
456
456
  expect(map.setLayoutProperty).toHaveBeenCalledWith('stroke-active-invalid.hot', 'visibility', 'visible')
457
457
  jest.useRealTimers()
458
458
  })
459
459
  })
460
460
 
461
- describe('_geometryValidator accessor', () => {
462
- test('stores the validator on the map for modes to read, and reads it back', () => {
461
+ describe('_previewValidator accessor', () => {
462
+ test('stores the preview validator on the map for modes to read, and reads it back', () => {
463
463
  const { adapter, map } = setup()
464
464
  const validator = () => true
465
- adapter._geometryValidator = validator
466
- expect(map._drawGeometryValidator).toBe(validator)
467
- expect(adapter._geometryValidator).toBe(validator)
465
+ adapter._previewValidator = validator
466
+ expect(map._drawPreviewValidator).toBe(validator)
467
+ expect(adapter._previewValidator).toBe(validator)
468
+ })
469
+ })
470
+
471
+ describe('setGeometry', () => {
472
+ test('bridges into the active mode via a custom event', () => {
473
+ const { adapter, map } = setup()
474
+ const geometry = { type: 'Polygon', coordinates: [[[0, 0], [1, 0], [1, 1], [0, 0]]] }
475
+ adapter.setGeometry(geometry)
476
+ expect(map.fire).toHaveBeenCalledWith('draw.setgeometry', { geometry })
468
477
  })
469
478
  })
470
479
 
@@ -511,13 +520,13 @@ describe('changeMode', () => {
511
520
  })
512
521
  })
513
522
 
514
- describe('setGeometryValid', () => {
523
+ describe('setCanFinish', () => {
515
524
  test('records validity on the map for the draw mode to read', () => {
516
525
  const { adapter, map } = setup()
517
- adapter.setGeometryValid(false)
518
- expect(map._drawGeometryValid).toBe(false)
519
- adapter.setGeometryValid(true)
520
- expect(map._drawGeometryValid).toBe(true)
526
+ adapter.setCanFinish(false)
527
+ expect(map._drawCanFinish).toBe(false)
528
+ adapter.setCanFinish(true)
529
+ expect(map._drawCanFinish).toBe(true)
521
530
  })
522
531
  })
523
532
 
@@ -766,7 +775,7 @@ describe('simple delegations', () => {
766
775
  const render = jest.fn()
767
776
  // A commit event (has a phase) must not become the cached preview target — it
768
777
  // carries a `feature`, not the live `properties` object rubber-band moves do.
769
- onHandler(map, CUSTOM_DRAW_EVENTS.GEOMETRY_CHANGE)({ feature: {}, phase: 'commit-add', ctx: { store: { render } } })
778
+ onHandler(map, CUSTOM_DRAW_EVENTS.GEOMETRY_CHANGE)({ feature: {}, phase: 'change', ctx: { store: { render } } })
770
779
 
771
780
  expect(() => adapter.setDrawingPreviewProperty('splitter', 'valid')).not.toThrow()
772
781
  expect(render).not.toHaveBeenCalled()
@@ -30,7 +30,8 @@ export const CUSTOM_DRAW_EVENTS = {
30
30
  PLACEMENT_BLOCKED: 'draw.placementblocked',
31
31
  NUDGE_VERTEX: 'draw.nudgevertex',
32
32
  SELECT_VERTEX: 'draw.selectvertex',
33
- INSERT_VERTEX_AT_MIDPOINT: 'draw.insertvertexatmidpoint'
33
+ INSERT_VERTEX_AT_MIDPOINT: 'draw.insertvertexatmidpoint',
34
+ SET_GEOMETRY: 'draw.setgeometry'
34
35
  }
35
36
 
36
37
  // Native MapLibre map event (not a draw event) — fires whenever the map style data changes.
@@ -2,25 +2,26 @@ import {
2
2
  getSnapInstance, isSnapActive, isSnapEnabled, createSnappedEvent, createSnappedClickEvent
3
3
  } from '../../utils/snapHelpers.js'
4
4
  import { attemptPlacement } from '../../../../validation/validateGeometry.js'
5
+ import { CHANGE_PHASE } from '../../../../adapterEvents.js'
5
6
 
6
7
  // The commit-level geometrychange payload for a vertex commit: the placed-only
7
8
  // geometry (trailing rubber-band point dropped so validation tests the committed shape).
8
- const placedDrawGeometryChange = (feature, getCoords, phase) => {
9
+ const placedDrawGeometryChange = (feature, getCoords) => {
9
10
  const placed = getCoords(feature).slice(0, -1)
10
11
  const type = feature.toGeoJSON().geometry.type
11
12
  const geometry = type === 'Polygon'
12
13
  ? { type: 'Polygon', coordinates: [placed] }
13
14
  : { type: 'LineString', coordinates: placed }
14
- return { feature: { type: 'Feature', geometry, properties: {} }, phase, vertexIndex: Math.max(0, placed.length - 1) }
15
+ return { feature: { type: 'Feature', geometry, properties: {} }, phase: CHANGE_PHASE, vertexIndex: Math.max(0, placed.length - 1) }
15
16
  }
16
17
 
17
18
  // Fire a commit-level geometrychange for validation, deferred a tick so it runs after
18
19
  // the current click settles.
19
- const scheduleDrawValidation = (map, getFeature, getCoords, state, phase) => {
20
+ const scheduleDrawValidation = (map, getFeature, getCoords, state) => {
20
21
  setTimeout(() => {
21
22
  const feature = getFeature(state)
22
23
  if (!feature) { return }
23
- map.fire('draw.geometrychange', placedDrawGeometryChange(feature, getCoords, phase))
24
+ map.fire('draw.geometrychange', placedDrawGeometryChange(feature, getCoords))
24
25
  }, 0)
25
26
  }
26
27
 
@@ -38,7 +39,7 @@ const createClickHelpers = ({ geometryType, getFeature, getCoords }) => ({
38
39
  return e.originalEvent.button > 0 || this.map._undoInProgress || e.originalEvent.target !== this.map.getCanvas()
39
40
  },
40
41
 
41
- // Attempt a placement through the shared hard rules + user callback. On a veto
42
+ // Attempt a placement through the shared placement rules + user callback. On a veto
42
43
  // the vertex never appears and a draw.placementblocked event carries the
43
44
  // reason. The trailing rubber-band coord is dropped so the candidate is placed
44
45
  // vertices + the point about to be placed.
@@ -49,7 +50,7 @@ const createClickHelpers = ({ geometryType, getFeature, getCoords }) => ({
49
50
  placed: getCoords(feature).slice(0, -1),
50
51
  point,
51
52
  geometryType,
52
- onGeometryChange: this.map._drawGeometryValidator
53
+ onGeometryPreview: this.map._drawPreviewValidator
53
54
  })
54
55
  if (!result.valid) {
55
56
  this.map.fire('draw.placementblocked', result.blocked)
@@ -66,8 +67,8 @@ const createClickHelpers = ({ geometryType, getFeature, getCoords }) => ({
66
67
 
67
68
  // Emit a commit-level geometrychange after a vertex commit (placement or undo)
68
69
  // so the validation layer can gate the Done button.
69
- emitDrawValidation (state, phase = 'commit-add') {
70
- scheduleDrawValidation(this.map, getFeature, getCoords, state, phase)
70
+ emitDrawValidation (state) {
71
+ scheduleDrawValidation(this.map, getFeature, getCoords, state)
71
72
  },
72
73
 
73
74
  onTap () {
@@ -107,8 +108,8 @@ const createClickActions = ({ ParentMode, getFeature, getCoords, validateClick,
107
108
  if (this._isIgnorableClick(e)) {
108
109
  return
109
110
  }
110
- // Block a finish/close gesture (clicking a placed vertex) while the shape is invalid.
111
- if (this.map._drawGeometryValid === false && e.featureTarget?.properties?.meta === 'vertex') {
111
+ // Block a finish/close gesture (clicking a placed vertex) while the shape can't be finished.
112
+ if (this.map._drawCanFinish === false && e.featureTarget?.properties?.meta === 'vertex') {
112
113
  return
113
114
  }
114
115
  const snap = getSnapInstance(this.map)
@@ -146,9 +147,9 @@ const createClickActions = ({ ParentMode, getFeature, getCoords, validateClick,
146
147
 
147
148
  if (!validateClick(feature)) {
148
149
  // For lines: clicking same spot (like double-click) should finish the line — but
149
- // only when the geometry is valid, so an invalid line can't be completed.
150
+ // only when it can be finished, so a line whose check failed can't be completed.
150
151
  // isValidLineClick only returns false with 2+ coords, so coords.length is always > 1 here.
151
- if (finishOnInvalidClick && this.map._drawGeometryValid !== false) {
152
+ if (finishOnInvalidClick && this.map._drawCanFinish !== false) {
152
153
  coords.pop()
153
154
  this.map.fire('draw.create', { features: [feature.toGeoJSON()] })
154
155
  this.changeMode('simple_select', { featureIds: [feature.id] })
@@ -49,7 +49,7 @@ describe('mouse clicks (polygon)', () => {
49
49
 
50
50
  test('the user callback can veto a mouse placement (and receives phase "place")', () => {
51
51
  const { ctx, state } = setup(DrawPolygonMode)
52
- ctx.map._drawGeometryValidator = jest.fn((event) =>
52
+ ctx.map._drawPreviewValidator = jest.fn((event) =>
53
53
  event.phase === 'place' ? { valid: false, reason: 'outside region' } : { valid: true })
54
54
  clickAt(ctx, state, 0, 0)
55
55
  expect(state.polygon.coordinates[0]).toHaveLength(0) // first vertex vetoed
@@ -87,7 +87,7 @@ describe('mouse clicks (polygon)', () => {
87
87
  clickAt(ctx, state, 10, 0)
88
88
  jest.runAllTimers()
89
89
  const geomChange = firedWith(ctx.map, 'draw.geometrychange').pop()
90
- expect(geomChange).toEqual(expect.objectContaining({ phase: 'commit-add', feature: expect.any(Object) }))
90
+ expect(geomChange).toEqual(expect.objectContaining({ phase: 'change', feature: expect.any(Object) }))
91
91
  jest.useRealTimers()
92
92
  })
93
93
 
@@ -116,7 +116,7 @@ describe('mouse clicks (polygon)', () => {
116
116
  clickAt(ctx, state, 0, 0)
117
117
  clickAt(ctx, state, 10, 0)
118
118
  clickAt(ctx, state, 5, 10)
119
- ctx.map._drawGeometryValid = false
119
+ ctx.map._drawCanFinish = false
120
120
  const lenBefore = state.polygon.coordinates[0].length
121
121
  ctx.onClick(state, { ...clickEvent(ctx, 0, 0), featureTarget: { properties: { meta: 'vertex' } } })
122
122
  expect(state.polygon.coordinates[0].length).toBe(lenBefore) // finish gesture ignored
@@ -146,7 +146,7 @@ describe('add-vertex button and doClick', () => {
146
146
  const { ctx, state } = setup(DrawLineMode)
147
147
  clickAt(ctx, state, 0, 0)
148
148
  clickAt(ctx, state, 10, 0)
149
- ctx.map._drawGeometryValid = false
149
+ ctx.map._drawCanFinish = false
150
150
  // Rubber-band duplicates the last placed vertex → a finish gesture.
151
151
  state.line.setCoordinates([[0, 0], [10, 0], [10, 0]])
152
152
  ctx.doClick(state)
@@ -178,7 +178,7 @@ describe('add-vertex button and doClick', () => {
178
178
 
179
179
  test('the user callback can veto a doClick placement', () => {
180
180
  const { ctx, state } = setup(DrawPolygonMode)
181
- ctx.map._drawGeometryValidator = () => ({ valid: false, reason: 'outside region' })
181
+ ctx.map._drawPreviewValidator = () => ({ valid: false, reason: 'outside region' })
182
182
  ctx.doClick(state)
183
183
  expect(state.polygon.coordinates[0]).toHaveLength(0)
184
184
  expect(firedWith(ctx.map, 'draw.placementblocked').pop()).toEqual(
@@ -39,7 +39,7 @@ const createUndoStackHandlers = ({ geometryType, getFeature }) => ({
39
39
  this.undoVertex(state)
40
40
  // An undo commits a vertex removal, so it must re-validate like any other
41
41
  // commit — otherwise the Done gate goes stale.
42
- this.emitDrawValidation(state, 'commit-delete')
42
+ this.emitDrawValidation(state)
43
43
  }
44
44
  },
45
45