1- import { useEffect , useState } from 'react' ;
1+ import { useEffect , useLayoutEffect , useState } from 'react' ;
22import { useSelector , useDispatch } from 'react-redux' ;
33import { useIntl } from 'react-intl' ;
44import { gpx } from '@tmcw/togeojson' ;
@@ -7,6 +7,19 @@ import '@openstreetmap/id/dist/iD.css';
77
88import { OSM_CLIENT_ID , OSM_REDIRECT_URI , OSM_SERVER_URL } from '../config' ;
99import messages from './messages' ;
10+ import {
11+ registerIdEditorStylesheet ,
12+ activateIdEditorStylesheet ,
13+ } from '../utils/idEditorStylesheets' ;
14+
15+ // @openstreetmap /id has no real ESM/CJS exports — it only assigns itself to
16+ // window.iD as a side effect on import. Capture it here, right after the
17+ // import above forces that assignment, so this module keeps its own private
18+ // reference instead of the shared global, which @osm-sandbox/sandbox-id
19+ // (imported by sandboxEditor.js) later overwrites.
20+ const officialID = window . iD ;
21+
22+ registerIdEditorStylesheet ( 'official' ) ;
1023
1124export default function Editor ( { setDisable, comment, presets, imagery, gpxUrl, extraIdParams } ) {
1225 const dispatch = useDispatch ( ) ;
@@ -19,13 +32,21 @@ export default function Editor({ setDisable, comment, presets, imagery, gpxUrl,
1932 const customSource =
2033 iDContext && iDContext . background ( ) && iDContext . background ( ) . findSource ( 'custom' ) ;
2134
35+ // Only one of the OSM iD editor / Sandbox editor is ever mounted at a
36+ // time, but both of their stylesheets stay loaded for the whole page
37+ // session once visited. Disable the other one's so its rules can't leak
38+ // into this editor via their shared ".ideditor" root class.
39+ useLayoutEffect ( ( ) => {
40+ activateIdEditorStylesheet ( 'official' ) ;
41+ } , [ ] ) ;
42+
2243 useEffect ( ( ) => {
2344 if ( ! customImageryIsSet && imagery && customSource ) {
2445 if ( imagery . startsWith ( 'http' ) ) {
2546 iDContext . background ( ) . baseLayerSource ( customSource . template ( imagery ) ) ;
2647 setCustomImageryIsSet ( true ) ;
2748 // this line is needed to update the value on the custom background dialog
28- window . iD . prefs ( 'background-custom-template' , imagery ) ;
49+ officialID . prefs ( 'background-custom-template' , imagery ) ;
2950 } else {
3051 const imagerySource = iDContext . background ( ) . findSource ( imagery ) ;
3152 if ( imagerySource ) {
@@ -52,7 +73,7 @@ export default function Editor({ setDisable, comment, presets, imagery, gpxUrl,
5273 const offsetStr = params . get ( 'offset' ) ; // "10,-10"
5374 if ( ! offsetStr ) return ;
5475 const offsetInMeters = offsetStr . split ( ',' ) . map ( Number ) ; // [10, -10]
55- const offset = window . iD . geoMetersToOffset ( offsetInMeters ) ;
76+ const offset = officialID . geoMetersToOffset ( offsetInMeters ) ;
5677 iDContext . background ( ) . offset ( offset ) ;
5778 } else {
5879 // reset offset if params not present
@@ -66,13 +87,13 @@ export default function Editor({ setDisable, comment, presets, imagery, gpxUrl,
6687 if ( iDContext === null ) {
6788 // we need to keep iD context on redux store because iD works better if
6889 // the context is not restarted while running in the same browser session
69- dispatch ( { type : 'SET_EDITOR' , context : window . iD . coreContext ( ) } ) ;
90+ dispatch ( { type : 'SET_EDITOR' , context : officialID . coreContext ( ) } ) ;
7091 }
7192 }
7293 } , [ windowInit , iDContext , dispatch ] ) ;
7394
7495 // Reset context on unmount so the sandbox editor always gets a fresh context
75- // from its own window.iD (sandbox-id), preventing cross-editor context bleed.
96+ // from its own iD module (sandbox-id), preventing cross-editor context bleed.
7697 useEffect ( ( ) => {
7798 return ( ) => {
7899 dispatch ( { type : 'SET_EDITOR' , context : null } ) ;
@@ -90,12 +111,12 @@ export default function Editor({ setDisable, comment, presets, imagery, gpxUrl,
90111 // if presets is not a populated list we need to set it as null
91112 try {
92113 if ( presets . length ) {
93- window . iD . presetManager . addablePresetIDs ( presets ) ;
114+ officialID . presetManager . addablePresetIDs ( presets ) ;
94115 } else {
95- window . iD . presetManager . addablePresetIDs ( null ) ;
116+ officialID . presetManager . addablePresetIDs ( null ) ;
96117 }
97118 } catch ( e ) {
98- window . iD . presetManager . addablePresetIDs ( null ) ;
119+ officialID . presetManager . addablePresetIDs ( null ) ;
99120 }
100121 // setup the context
101122 iDContext
0 commit comments