@mountaya/studio 0.0.0-stage → 0.2.0
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/CHANGELOG.md +69 -0
- package/LICENCE.fr.txt +280 -0
- package/LICENSE.txt +262 -0
- package/README.md +917 -2
- package/dist/agent/index.cjs +2600 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +1237 -0
- package/dist/agent/index.d.ts +1237 -0
- package/dist/agent/index.js +2581 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/chunk-3Oi_Zrtm.js +9 -0
- package/dist/chunk-3Oi_Zrtm.js.map +1 -0
- package/dist/chunk-B18OPIu_.js +6 -0
- package/dist/chunk-B18OPIu_.js.map +1 -0
- package/dist/chunk-B5Uz3Qct.cjs +15 -0
- package/dist/chunk-B5Uz3Qct.cjs.map +1 -0
- package/dist/chunk-BBEJwkd3.d.cts +839 -0
- package/dist/chunk-BIEc_SkR.cjs +29 -0
- package/dist/chunk-BIEc_SkR.cjs.map +1 -0
- package/dist/chunk-BKMFOe-N.js +171 -0
- package/dist/chunk-BKMFOe-N.js.map +1 -0
- package/dist/chunk-BP4uy7E1.d.ts +11583 -0
- package/dist/chunk-BSHTsFiB.js +1403 -0
- package/dist/chunk-BSHTsFiB.js.map +1 -0
- package/dist/chunk-BTUUABGI.js +17 -0
- package/dist/chunk-BTUUABGI.js.map +1 -0
- package/dist/chunk-BaPiaz5X.cjs +115 -0
- package/dist/chunk-BaPiaz5X.cjs.map +1 -0
- package/dist/chunk-BeCVpkYr.cjs +542 -0
- package/dist/chunk-BeCVpkYr.cjs.map +1 -0
- package/dist/chunk-BgngsvK8.cjs +6202 -0
- package/dist/chunk-BgngsvK8.cjs.map +1 -0
- package/dist/chunk-BhInd7CJ.d.cts +253 -0
- package/dist/chunk-Bn6ZbxkS.cjs +27 -0
- package/dist/chunk-By9ZnkVI.js +60 -0
- package/dist/chunk-By9ZnkVI.js.map +1 -0
- package/dist/chunk-BzqPhxsz.cjs +367 -0
- package/dist/chunk-BzqPhxsz.cjs.map +1 -0
- package/dist/chunk-C2mMX81q.d.ts +443 -0
- package/dist/chunk-C2rr9Q0V.cjs +1402 -0
- package/dist/chunk-C2rr9Q0V.cjs.map +1 -0
- package/dist/chunk-CDJCbwIQ.d.cts +78 -0
- package/dist/chunk-CLGvBOVH.d.cts +1654 -0
- package/dist/chunk-COdw1dc6.d.ts +525 -0
- package/dist/chunk-CQCJnT2i.d.ts +511 -0
- package/dist/chunk-CSyHY67q.cjs +353 -0
- package/dist/chunk-CSyHY67q.cjs.map +1 -0
- package/dist/chunk-CiK1Iqrv.js +950 -0
- package/dist/chunk-CiK1Iqrv.js.map +1 -0
- package/dist/chunk-CmJBgSwZ.cjs +24 -0
- package/dist/chunk-CmJBgSwZ.cjs.map +1 -0
- package/dist/chunk-CnrsRK2u.cjs +83 -0
- package/dist/chunk-CnrsRK2u.cjs.map +1 -0
- package/dist/chunk-Co782_9r.js +326 -0
- package/dist/chunk-Co782_9r.js.map +1 -0
- package/dist/chunk-Csr3KDpZ.cjs +32 -0
- package/dist/chunk-Csr3KDpZ.cjs.map +1 -0
- package/dist/chunk-CwkmccXv.js +89 -0
- package/dist/chunk-CwkmccXv.js.map +1 -0
- package/dist/chunk-D0Q4iL9B.cjs +255 -0
- package/dist/chunk-D0Q4iL9B.cjs.map +1 -0
- package/dist/chunk-DFwiSzUS.cjs +72 -0
- package/dist/chunk-DFwiSzUS.cjs.map +1 -0
- package/dist/chunk-DIFayl2P.d.cts +443 -0
- package/dist/chunk-DIGF58ux.d.cts +525 -0
- package/dist/chunk-DKuuuld5.js +101 -0
- package/dist/chunk-DKuuuld5.js.map +1 -0
- package/dist/chunk-DMePkFEo.js +5054 -0
- package/dist/chunk-DMePkFEo.js.map +1 -0
- package/dist/chunk-DO5SIBgu.js +305 -0
- package/dist/chunk-DO5SIBgu.js.map +1 -0
- package/dist/chunk-DOQ_7eE5.d.ts +6662 -0
- package/dist/chunk-DThaaNeb.d.cts +15 -0
- package/dist/chunk-DThaaNeb.d.ts +15 -0
- package/dist/chunk-DUQzjUJy.d.ts +78 -0
- package/dist/chunk-DX37IPhV.cjs +1903 -0
- package/dist/chunk-DX37IPhV.cjs.map +1 -0
- package/dist/chunk-Damps5Tk.cjs +155 -0
- package/dist/chunk-Damps5Tk.cjs.map +1 -0
- package/dist/chunk-DbK5PhpJ.d.ts +1654 -0
- package/dist/chunk-De0vAASv.d.ts +253 -0
- package/dist/chunk-DhSZ7YZt.d.cts +6662 -0
- package/dist/chunk-DjEvqvPA.cjs +43 -0
- package/dist/chunk-DjEvqvPA.cjs.map +1 -0
- package/dist/chunk-DkwDzwvu.d.cts +121 -0
- package/dist/chunk-DkwDzwvu.d.ts +121 -0
- package/dist/chunk-Dmszv9If.js +71 -0
- package/dist/chunk-Dmszv9If.js.map +1 -0
- package/dist/chunk-Dp_ftNWY.d.cts +511 -0
- package/dist/chunk-DsHQySz0.js +31 -0
- package/dist/chunk-DsHQySz0.js.map +1 -0
- package/dist/chunk-DwoUyHHh.js +281 -0
- package/dist/chunk-DwoUyHHh.js.map +1 -0
- package/dist/chunk-IaIDQflj.d.cts +2315 -0
- package/dist/chunk-IaIDQflj.d.ts +2315 -0
- package/dist/chunk-cVXLsZfL.d.ts +839 -0
- package/dist/chunk-mIaCX9EJ.d.cts +11583 -0
- package/dist/chunk-nJQxbOwQ.cjs +8962 -0
- package/dist/chunk-nJQxbOwQ.cjs.map +1 -0
- package/dist/chunk-o9jaxhCO.js +8852 -0
- package/dist/chunk-o9jaxhCO.js.map +1 -0
- package/dist/chunk-p-Tt_Lwz.js +14 -0
- package/dist/chunk-p-Tt_Lwz.js.map +1 -0
- package/dist/engines/index.cjs +2091 -0
- package/dist/engines/index.cjs.map +1 -0
- package/dist/engines/index.d.cts +2176 -0
- package/dist/engines/index.d.ts +2176 -0
- package/dist/engines/index.js +2075 -0
- package/dist/engines/index.js.map +1 -0
- package/dist/handlers/index.cjs +53 -0
- package/dist/handlers/index.cjs.map +1 -0
- package/dist/handlers/index.d.cts +403 -0
- package/dist/handlers/index.d.ts +403 -0
- package/dist/handlers/index.js +33 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/index.cjs +3511 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +3033 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/index.cjs +510 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +296 -0
- package/dist/plugins/index.d.ts +296 -0
- package/dist/plugins/index.js +489 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/seams/index.cjs +89 -0
- package/dist/seams/index.cjs.map +1 -0
- package/dist/seams/index.d.cts +452 -0
- package/dist/seams/index.d.ts +452 -0
- package/dist/seams/index.js +49 -0
- package/dist/seams/index.js.map +1 -0
- package/dist/strings/fr/index.cjs +2135 -0
- package/dist/strings/fr/index.cjs.map +1 -0
- package/dist/strings/fr/index.d.cts +17 -0
- package/dist/strings/fr/index.d.ts +17 -0
- package/dist/strings/fr/index.js +2130 -0
- package/dist/strings/fr/index.js.map +1 -0
- package/dist/strings/index.cjs +2384 -0
- package/dist/strings/index.cjs.map +1 -0
- package/dist/strings/index.d.cts +3 -0
- package/dist/strings/index.d.ts +3 -0
- package/dist/strings/index.js +2353 -0
- package/dist/strings/index.js.map +1 -0
- package/dist/testing/index.cjs +230 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +246 -0
- package/dist/testing/index.d.ts +246 -0
- package/dist/testing/index.js +219 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/time/index.cjs +28 -0
- package/dist/time/index.cjs.map +1 -0
- package/dist/time/index.d.cts +41 -0
- package/dist/time/index.d.ts +41 -0
- package/dist/time/index.js +23 -0
- package/dist/time/index.js.map +1 -0
- package/package.json +224 -4
- package/src/agent/engines/agentThreads.ts +1601 -0
- package/src/agent/engines/directorChat.ts +500 -0
- package/src/agent/index.ts +67 -0
- package/src/agent/rules/agentEditLock.ts +115 -0
- package/src/agent/rules/agentErrorCopy.ts +44 -0
- package/src/agent/rules/copilotOrganization.ts +36 -0
- package/src/agent/rules/playbook.gen.ts +444 -0
- package/src/agent/rules/router.ts +518 -0
- package/src/agent/rules/stateDelta.ts +29 -0
- package/src/agent/rules/studioRouter.ts +123 -0
- package/src/agent/rules/surfaces.gen.ts +633 -0
- package/src/agent/rules/threadsUrl.ts +48 -0
- package/src/agent/rules/transcriptObserver.ts +90 -0
- package/src/agent/stores/agentThreads.ts +451 -0
- package/src/bus/contracts/noData.ts +18 -0
- package/src/bus/contracts/shared.ts +172 -0
- package/src/bus/contracts/studioTools.ts +224 -0
- package/src/bus/rules/bus.ts +857 -0
- package/src/bus/rules/confirmation.ts +22 -0
- package/src/bus/rules/defineRegistry.ts +24 -0
- package/src/bus/rules/errors.ts +401 -0
- package/src/bus/rules/handlerErrors.ts +103 -0
- package/src/bus/rules/handlerRegistry.ts +627 -0
- package/src/bus/rules/inputSchema.ts +232 -0
- package/src/bus/rules/invalidInput.ts +441 -0
- package/src/bus/rules/lateBoundTools.ts +100 -0
- package/src/bus/rules/studioRegistry.ts +324 -0
- package/src/bus/rules/studioToolBus.ts +73 -0
- package/src/bus/rules/types.ts +804 -0
- package/src/chrome/contracts/alert.ts +42 -0
- package/src/chrome/contracts/itinerary.ts +26 -0
- package/src/chrome/contracts/map.ts +23 -0
- package/src/chrome/contracts/overlay.ts +46 -0
- package/src/chrome/contracts/panel.ts +29 -0
- package/src/chrome/contracts/question.ts +52 -0
- package/src/chrome/contracts/selection.ts +26 -0
- package/src/chrome/contracts/sidenav.ts +23 -0
- package/src/chrome/contracts/snapshot.ts +319 -0
- package/src/chrome/contracts/state.ts +22 -0
- package/src/chrome/contracts/tabs.ts +56 -0
- package/src/chrome/handlers/alert.ts +91 -0
- package/src/chrome/handlers/introspection.ts +180 -0
- package/src/chrome/handlers/panels.ts +42 -0
- package/src/chrome/handlers/question.ts +24 -0
- package/src/chrome/handlers/sidenav.ts +116 -0
- package/src/chrome/handlers/snapshot.ts +451 -0
- package/src/chrome/handlers/stateDelta.ts +125 -0
- package/src/chrome/handlers/tabs.ts +143 -0
- package/src/chrome/handlers/timestamp.ts +19 -0
- package/src/chrome/rules/agentSelectors.ts +210 -0
- package/src/chrome/rules/mapAlert.ts +13 -0
- package/src/chrome/rules/question.ts +25 -0
- package/src/chrome/rules/tabs.ts +13 -0
- package/src/chrome/stores/activeDraftSession.ts +134 -0
- package/src/chrome/stores/chrome.ts +527 -0
- package/src/chrome/stores/uiStore.ts +575 -0
- package/src/collab/contracts/collab.ts +261 -0
- package/src/collab/handlers/collab.ts +468 -0
- package/src/collab/rules/toolNames.ts +33 -0
- package/src/collab/stores/collab.ts +899 -0
- package/src/collections/contracts/collection.ts +182 -0
- package/src/collections/handlers/collectionAttach.ts +141 -0
- package/src/collections/handlers/collections.ts +499 -0
- package/src/collections/handlers/heldCollection.ts +42 -0
- package/src/collections/handlers/restCollections.ts +386 -0
- package/src/collections/rules/collections.ts +138 -0
- package/src/collections/rules/entityCollections.ts +53 -0
- package/src/collections/stores/collections.ts +133 -0
- package/src/data/contracts/data.ts +233 -0
- package/src/data/contracts/itinerary.ts +71 -0
- package/src/data/handlers/activityResolve.ts +76 -0
- package/src/data/handlers/data.ts +200 -0
- package/src/data/handlers/graphql.ts +26 -0
- package/src/data/handlers/mutationSink.ts +1577 -0
- package/src/data/handlers/profile.ts +83 -0
- package/src/data/handlers/writeThrough.ts +417 -0
- package/src/data/rules/cache.ts +181 -0
- package/src/data/rules/dataTypes.ts +40 -0
- package/src/data/rules/keys.ts +106 -0
- package/src/data/rules/persistence.ts +1058 -0
- package/src/data/rules/requestBody.ts +43 -0
- package/src/data/rules/restErrors.ts +354 -0
- package/src/data/rules/sessionSurface.ts +156 -0
- package/src/data/rules/toolResultData.ts +73 -0
- package/src/data/rules/uuid.ts +24 -0
- package/src/edit/contracts/edit.ts +37 -0
- package/src/edit/contracts/itinerary.ts +57 -0
- package/src/edit/handlers/draftCommit.ts +257 -0
- package/src/edit/handlers/editDiscard.ts +34 -0
- package/src/edit/handlers/editLock.ts +949 -0
- package/src/edit/handlers/editor.ts +203 -0
- package/src/edit/handlers/formUnsaved.ts +24 -0
- package/src/edit/rules/draftMetadata.ts +117 -0
- package/src/edit/rules/editKeyboard.ts +222 -0
- package/src/edit/rules/editShortcuts.ts +102 -0
- package/src/edit/rules/editTooltip.ts +174 -0
- package/src/edit/rules/editorTaken.ts +49 -0
- package/src/edit/rules/history.ts +26 -0
- package/src/edit/rules/unsavedWork.ts +60 -0
- package/src/edit/stores/editorReservation.ts +70 -0
- package/src/edit/stores/formsUnsaved.ts +54 -0
- package/src/embed/contracts/embed.ts +48 -0
- package/src/embed/engines/embedFraming.ts +1329 -0
- package/src/embed/engines/embedReady.ts +353 -0
- package/src/embed/engines/framingPageSession.ts +169 -0
- package/src/embed/handlers/embed.ts +130 -0
- package/src/embed/rules/allowedDomains.ts +71 -0
- package/src/embed/rules/bridgeMessages.ts +224 -0
- package/src/embed/rules/defaults.ts +173 -0
- package/src/embed/rules/displaySeed.ts +115 -0
- package/src/embed/rules/embedAllowlist.ts +146 -0
- package/src/embed/rules/embedConstraints.ts +215 -0
- package/src/embed/rules/embedElements.ts +277 -0
- package/src/embed/rules/embedSectionFields.ts +126 -0
- package/src/embed/rules/embedSecurity.ts +116 -0
- package/src/embed/rules/fieldDependencies.ts +89 -0
- package/src/embed/rules/fieldOptions.ts +138 -0
- package/src/embed/rules/layerOptions.ts +161 -0
- package/src/embed/rules/readyProtocol.ts +66 -0
- package/src/embed/rules/safetyRules.ts +215 -0
- package/src/embed/rules/snippet.ts +531 -0
- package/src/embed/rules/tableCode.ts +270 -0
- package/src/embed/stores/embed.ts +60 -0
- package/src/embed/stores/embedContent.ts +77 -0
- package/src/engines/index.ts +81 -0
- package/src/handlers/index.ts +66 -0
- package/src/index.ts +1065 -0
- package/src/itinerary/contracts/itinerary.ts +705 -0
- package/src/itinerary/engines/itineraryPace.ts +612 -0
- package/src/itinerary/engines/profileMarker.ts +238 -0
- package/src/itinerary/handlers/importStaging.ts +352 -0
- package/src/itinerary/handlers/itinerary.ts +572 -0
- package/src/itinerary/handlers/itineraryDuplicate.ts +177 -0
- package/src/itinerary/handlers/itineraryExport.ts +117 -0
- package/src/itinerary/handlers/itineraryImport.ts +783 -0
- package/src/itinerary/handlers/itineraryPublish.ts +118 -0
- package/src/itinerary/handlers/itinerarySelection.ts +354 -0
- package/src/itinerary/handlers/itinerarySuggest.ts +1186 -0
- package/src/itinerary/handlers/itineraryUnpublish.ts +101 -0
- package/src/itinerary/handlers/publicationScope.ts +118 -0
- package/src/itinerary/handlers/restItineraries.ts +752 -0
- package/src/itinerary/handlers/restItineraryExport.ts +70 -0
- package/src/itinerary/handlers/restItineraryImport.ts +311 -0
- package/src/itinerary/handlers/restItineraryPace.ts +87 -0
- package/src/itinerary/handlers/restItineraryRecord.ts +36 -0
- package/src/itinerary/handlers/suggestParams.ts +379 -0
- package/src/itinerary/handlers/suggestStaging.ts +363 -0
- package/src/itinerary/handlers/surfaceOpen.ts +389 -0
- package/src/itinerary/rules/activity.ts +139 -0
- package/src/itinerary/rules/analysis.ts +42 -0
- package/src/itinerary/rules/ceiling.ts +49 -0
- package/src/itinerary/rules/createFlow.ts +107 -0
- package/src/itinerary/rules/densify.ts +440 -0
- package/src/itinerary/rules/draftSurface.ts +219 -0
- package/src/itinerary/rules/editorView.ts +83 -0
- package/src/itinerary/rules/export.ts +159 -0
- package/src/itinerary/rules/friendlyName.ts +77 -0
- package/src/itinerary/rules/import.ts +1050 -0
- package/src/itinerary/rules/importFiles.ts +140 -0
- package/src/itinerary/rules/importTotals.ts +77 -0
- package/src/itinerary/rules/liveSegment.ts +712 -0
- package/src/itinerary/rules/lngLat.ts +17 -0
- package/src/itinerary/rules/mapSync.ts +100 -0
- package/src/itinerary/rules/previewRender.ts +416 -0
- package/src/itinerary/rules/profileReadout.ts +216 -0
- package/src/itinerary/rules/routing.ts +707 -0
- package/src/itinerary/rules/suggest.ts +522 -0
- package/src/itinerary/rules/suggestionPreview.ts +119 -0
- package/src/itinerary/rules/view.ts +61 -0
- package/src/itinerary/stores/importSession.ts +319 -0
- package/src/itinerary/stores/itinerary.ts +331 -0
- package/src/itinerary/stores/itineraryDuplicate.ts +76 -0
- package/src/itinerary/stores/sessionIdentity.ts +43 -0
- package/src/itinerary/stores/suggestSession.ts +418 -0
- package/src/layers/contracts/itinerary.ts +46 -0
- package/src/layers/contracts/overlay.ts +132 -0
- package/src/layers/handlers/enrichment.ts +36 -0
- package/src/layers/handlers/overlay.ts +406 -0
- package/src/layers/handlers/restLayers.ts +94 -0
- package/src/layers/handlers/tiles.ts +25 -0
- package/src/layers/rules/layers.ts +212 -0
- package/src/layers/rules/overlayInstant.ts +12 -0
- package/src/layers/rules/reachabilityIcon.ts +18 -0
- package/src/layers/rules/readout.ts +102 -0
- package/src/layers/stores/layers.ts +262 -0
- package/src/map/contracts/contextmenu.ts +33 -0
- package/src/map/contracts/geolocate.ts +37 -0
- package/src/map/contracts/map.ts +146 -0
- package/src/map/contracts/streetview.ts +53 -0
- package/src/map/contracts/terrain.ts +152 -0
- package/src/map/handlers/contextMenu.ts +135 -0
- package/src/map/handlers/geolocate.ts +52 -0
- package/src/map/handlers/map.ts +391 -0
- package/src/map/handlers/streetview.ts +94 -0
- package/src/map/handlers/terrain.ts +663 -0
- package/src/map/rules/baseTerrain.ts +75 -0
- package/src/map/rules/clickTargets.ts +464 -0
- package/src/map/rules/constraints.ts +32 -0
- package/src/map/rules/contextMenuReadout.ts +67 -0
- package/src/map/rules/coordinates.ts +71 -0
- package/src/map/rules/itineraryFit.ts +8 -0
- package/src/map/rules/mapEvents.ts +64 -0
- package/src/map/rules/mapProjection.ts +476 -0
- package/src/map/rules/terrainReading.ts +62 -0
- package/src/plugins/contracts/ids.ts +66 -0
- package/src/plugins/contracts/plugin.ts +202 -0
- package/src/plugins/contracts/slots.ts +137 -0
- package/src/plugins/engines/studioPlugin.ts +1365 -0
- package/src/plugins/index.ts +111 -0
- package/src/plugins/rules/contributions.ts +152 -0
- package/src/plugins/rules/errors.ts +60 -0
- package/src/plugins/rules/ids.ts +42 -0
- package/src/plugins/rules/validation.ts +249 -0
- package/src/rules/listeners.ts +57 -0
- package/src/rules/origin.ts +13 -0
- package/src/rules/storeWrite.ts +37 -0
- package/src/rules/types.ts +136 -0
- package/src/seams/index.ts +79 -0
- package/src/seams/rules/clock.ts +28 -0
- package/src/seams/rules/formatters.ts +211 -0
- package/src/seams/rules/ids.ts +102 -0
- package/src/seams/rules/links.ts +66 -0
- package/src/seams/rules/navigation.ts +222 -0
- package/src/seams/rules/notify.ts +49 -0
- package/src/seams/rules/persistenceDrawer.ts +220 -0
- package/src/seams/rules/saveFile.ts +101 -0
- package/src/seams/rules/seams.ts +156 -0
- package/src/seams/rules/storage.ts +116 -0
- package/src/search/contracts/overlay.ts +74 -0
- package/src/search/contracts/search.ts +197 -0
- package/src/search/handlers/pois.ts +57 -0
- package/src/search/handlers/search.ts +280 -0
- package/src/search/rules/params.ts +925 -0
- package/src/search/rules/poiGroups.ts +138 -0
- package/src/search/rules/searchFetch.ts +139 -0
- package/src/search/rules/timeWindow.ts +30 -0
- package/src/search/stores/search.ts +51 -0
- package/src/segments/contracts/itinerary.ts +433 -0
- package/src/segments/contracts/segment.ts +35 -0
- package/src/segments/engines/segmentDraft.ts +926 -0
- package/src/segments/handlers/chainGuards.ts +67 -0
- package/src/segments/handlers/directions.ts +44 -0
- package/src/segments/handlers/itineraryEcho.ts +45 -0
- package/src/segments/handlers/roadAccessDialog.ts +34 -0
- package/src/segments/handlers/segment.ts +111 -0
- package/src/segments/handlers/segmentEdit.ts +1341 -0
- package/src/segments/handlers/segmentGroups.ts +347 -0
- package/src/segments/handlers/segmentStructure.ts +1144 -0
- package/src/segments/rules/chain.ts +196 -0
- package/src/segments/rules/chainModel.ts +217 -0
- package/src/segments/rules/colors.ts +11 -0
- package/src/segments/rules/commit.ts +76 -0
- package/src/segments/rules/draft.ts +90 -0
- package/src/segments/rules/draftDisposition.ts +43 -0
- package/src/segments/rules/draftSegmentEdit.ts +129 -0
- package/src/segments/rules/engine.ts +222 -0
- package/src/segments/rules/groupSave.ts +234 -0
- package/src/segments/rules/hazardPrompt.ts +60 -0
- package/src/segments/rules/itineraryEcho.ts +40 -0
- package/src/segments/rules/liveSegmentProjection.ts +55 -0
- package/src/segments/rules/merge.ts +51 -0
- package/src/segments/rules/metrics.ts +456 -0
- package/src/segments/rules/naming.ts +168 -0
- package/src/segments/rules/segmentArming.ts +144 -0
- package/src/segments/rules/splitPick.ts +84 -0
- package/src/segments/rules/viaSimplify.ts +230 -0
- package/src/segments/stores/directions.ts +77 -0
- package/src/segments/stores/roadAccessDialog.ts +58 -0
- package/src/segments/stores/segmentEdit.ts +922 -0
- package/src/segments/stores/segmentGroupEdit.ts +84 -0
- package/src/segments/stores/segmentSplit.ts +77 -0
- package/src/share/contracts/share.ts +39 -0
- package/src/share/contracts/shareLink.ts +63 -0
- package/src/share/engines/shareLink.ts +1053 -0
- package/src/share/handlers/share.ts +47 -0
- package/src/share/handlers/shareLink.ts +231 -0
- package/src/share/handlers/shareScope.ts +54 -0
- package/src/share/rules/link.ts +89 -0
- package/src/share/rules/shareLink.ts +218 -0
- package/src/share/rules/targets.ts +92 -0
- package/src/share/rules/viewConfig.ts +95 -0
- package/src/share/stores/share.ts +58 -0
- package/src/strings/fr/index.ts +18 -0
- package/src/strings/fr/rules/fr.ts +2368 -0
- package/src/strings/index.ts +98 -0
- package/src/strings/rules/confirmCopy.ts +156 -0
- package/src/strings/rules/draftToolNames.ts +94 -0
- package/src/strings/rules/en.ts +2519 -0
- package/src/strings/rules/failureAlert.ts +115 -0
- package/src/strings/rules/formError.ts +400 -0
- package/src/strings/rules/maneuvers.ts +107 -0
- package/src/strings/rules/outputOptions.ts +126 -0
- package/src/strings/rules/publicationState.ts +100 -0
- package/src/strings/rules/routeHazardCopy.ts +62 -0
- package/src/strings/rules/searchLabels.ts +50 -0
- package/src/strings/rules/segmentChainVerbs.ts +62 -0
- package/src/strings/rules/studioCopy.ts +130 -0
- package/src/strings/rules/unitOptions.ts +119 -0
- package/src/testing/checkedBus.ts +226 -0
- package/src/testing/index.ts +30 -0
- package/src/testing/plugins.ts +106 -0
- package/src/testing/studio.ts +267 -0
- package/src/testing/urlSeam.ts +153 -0
- package/src/time/index.ts +12 -0
- package/src/time/rules/sun.ts +78 -0
- package/src/video/contracts/cameraSchemas.ts +266 -0
- package/src/video/contracts/profileSchemas.ts +37 -0
- package/src/video/contracts/video.ts +601 -0
- package/src/video/handlers/video.ts +1638 -0
- package/src/video/handlers/videoDirector.ts +114 -0
- package/src/video/rules/previewRefresh.ts +76 -0
- package/src/video/rules/profileSource.ts +51 -0
- package/src/video/rules/routeSpans.ts +79 -0
- package/src/video/rules/shotDefaults.ts +28 -0
- package/src/video/rules/stepOrder.ts +17 -0
- package/src/video/rules/videoSnapshot.ts +136 -0
- package/src/video/stores/directorThreads.ts +167 -0
- package/src/video/stores/videoExport.ts +290 -0
- package/src/viewer/contracts/preferences.ts +40 -0
- package/src/viewer/handlers/preferences.ts +91 -0
- package/src/viewer/rules/capabilities.ts +42 -0
- package/src/viewer/rules/config.ts +266 -0
- package/src/viewer/rules/context.ts +375 -0
- package/src/viewer/rules/ownership.ts +134 -0
- package/src/viewer/rules/platformViewer.ts +199 -0
- package/src/viewer/rules/scope.ts +197 -0
- package/src/viewer/rules/url.ts +145 -0
- package/src/viewer/rules/viewer.ts +307 -0
- package/src/viewer/rules/viewerSeam.ts +49 -0
- package/src/viewer/rules/viewerUnits.ts +34 -0
- package/src/waypoints/contracts/itinerary.ts +417 -0
- package/src/waypoints/handlers/poiWaypointStyle.ts +32 -0
- package/src/waypoints/handlers/waypointDetailsDialog.ts +38 -0
- package/src/waypoints/handlers/waypointEdit.ts +1073 -0
- package/src/waypoints/rules/amenities.ts +30 -0
- package/src/waypoints/rules/defaults.ts +31 -0
- package/src/waypoints/rules/details.ts +213 -0
- package/src/waypoints/rules/detailsDraft.ts +312 -0
- package/src/waypoints/rules/detailsPreview.ts +76 -0
- package/src/waypoints/rules/detailsSave.ts +356 -0
- package/src/waypoints/rules/draftDirty.ts +45 -0
- package/src/waypoints/rules/icons.ts +32 -0
- package/src/waypoints/rules/liveWaypoint.ts +63 -0
- package/src/waypoints/rules/naming.ts +185 -0
- package/src/waypoints/rules/sections.ts +77 -0
- package/src/waypoints/rules/waypointDraft.ts +62 -0
- package/src/waypoints/stores/waypointDetails.ts +62 -0
- package/src/waypoints/stores/waypointEdit.ts +566 -0
- package/src/zones/contracts/collection.ts +37 -0
- package/src/zones/contracts/zone.ts +528 -0
- package/src/zones/engines/zoneForm.ts +1773 -0
- package/src/zones/handlers/restZones.ts +287 -0
- package/src/zones/handlers/zonePublish.ts +206 -0
- package/src/zones/handlers/zoneUnpublish.ts +56 -0
- package/src/zones/handlers/zones.ts +2254 -0
- package/src/zones/rules/geometry.ts +946 -0
- package/src/zones/rules/zoneDefaults.ts +34 -0
- package/src/zones/rules/zoneDraft.ts +54 -0
- package/src/zones/rules/zoneForm.ts +563 -0
- package/src/zones/rules/zoneMetadata.ts +29 -0
- package/src/zones/rules/zoneSource.ts +87 -0
- package/src/zones/rules/zoneSourceRefusal.ts +104 -0
- package/src/zones/stores/zoneEdit.ts +998 -0
|
@@ -0,0 +1,926 @@
|
|
|
1
|
+
import type { Mountaya } from "@mountaya/client";
|
|
2
|
+
import { LIVE_SEGMENT_THROTTLE_MS, TrailingThrottle } from "@mountaya/elements/collab";
|
|
3
|
+
import type { ItinerarySegment, SegmentEditMode } from "@mountaya/elements/data";
|
|
4
|
+
import { MountayaElementsError } from "@mountaya/elements/errors";
|
|
5
|
+
import { buildSegmentGeometry, DIRECTIONS_VIA_MAX } from "@mountaya/elements/geo";
|
|
6
|
+
import type { MapClient, SegmentDraft } from "@mountaya/elements/map-client";
|
|
7
|
+
import type { SegmentRoute } from "@mountaya/elements/seams";
|
|
8
|
+
|
|
9
|
+
import type { StudioToolInputs, StudioToolOutputs } from "../../bus/contracts/studioTools.js";
|
|
10
|
+
import type { ToolBusContext, ToolBusDispatch, ToolResult } from "../../bus/rules/types.js";
|
|
11
|
+
import type { UiStoreApi } from "../../chrome/stores/uiStore.js";
|
|
12
|
+
import type { RouteAdvisory, RouteHazardMemo } from "../../itinerary/rules/routing.js";
|
|
13
|
+
import { notifyListeners, surfaceFault } from "../../rules/listeners.js";
|
|
14
|
+
import { MAX_TIMER_MS } from "../../seams/rules/clock.js";
|
|
15
|
+
import type { StudioStrings } from "../../strings/rules/en.js";
|
|
16
|
+
import { draftChangeDisposition } from "../rules/draftDisposition.js";
|
|
17
|
+
import { createHazardPromptGate, type HazardPromptGate } from "../rules/hazardPrompt.js";
|
|
18
|
+
import { buildLiveSegmentForDraft } from "../rules/liveSegmentProjection.js";
|
|
19
|
+
import { buildSegmentEditOptions, routeHazardConfirmation } from "../rules/segmentArming.js";
|
|
20
|
+
import {
|
|
21
|
+
type SegmentEditSession,
|
|
22
|
+
segmentEditSessionMark,
|
|
23
|
+
synthesizeDraftSegment,
|
|
24
|
+
} from "../stores/segmentEdit.js";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* SegmentDraftContext is the part of a tool context a {@link SegmentDraftEngine} reads: the UI
|
|
28
|
+
* store the segment edit session lives in, the client a routed edit resolves through, and the
|
|
29
|
+
* confirm gate a route's hazards are put to.
|
|
30
|
+
*
|
|
31
|
+
* A studio's own tool context satisfies it structurally, so a binding hands over the context it
|
|
32
|
+
* already dispatches with.
|
|
33
|
+
*/
|
|
34
|
+
export interface SegmentDraftContext extends ToolBusContext {
|
|
35
|
+
/**
|
|
36
|
+
* Where the client a directions edit routes through and a freehand edit analyses through comes
|
|
37
|
+
* from. Absent, the editor is armed with neither resolver.
|
|
38
|
+
*/
|
|
39
|
+
readonly api?: { readonly client: Mountaya } | undefined;
|
|
40
|
+
/** The store holding the segment edit session the engine arms for and records into. */
|
|
41
|
+
readonly ui: UiStoreApi;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* SegmentDraftConfig is what a segment edit's drafts run against, all of it replaceable mid-life
|
|
46
|
+
* through {@link SegmentDraftEngine.configure}.
|
|
47
|
+
*/
|
|
48
|
+
export interface SegmentDraftConfig {
|
|
49
|
+
/**
|
|
50
|
+
* The bus the via ceiling's warning is raised through, as `studio.alert.show`, and a session
|
|
51
|
+
* whose begin the map client refused is ended through, as `studio.itinerary.segment.editCancel`,
|
|
52
|
+
* then told of through, as `studio.alert.show` again.
|
|
53
|
+
*
|
|
54
|
+
* A bus that rejects a dispatch is held, so the engine leaves no rejection unhandled: a
|
|
55
|
+
* rejected cancel closes the refused session directly, and a rejected alert is dropped, since
|
|
56
|
+
* nothing follows one.
|
|
57
|
+
*/
|
|
58
|
+
readonly bus: ToolBusDispatch<SegmentDraftContext, StudioToolInputs, StudioToolOutputs>;
|
|
59
|
+
/**
|
|
60
|
+
* The map client the edit is armed on and its drafts are read from, or null while there is no
|
|
61
|
+
* map, in which case nothing is armed.
|
|
62
|
+
*
|
|
63
|
+
* Required even so, because an engine without a client is silent: a key the caller has to write
|
|
64
|
+
* makes forgetting it a compile error rather than an edit that never arms.
|
|
65
|
+
*
|
|
66
|
+
* Compared by identity. A replaced client is armed afresh and read from then on, and the
|
|
67
|
+
* previous client's editor is left to the tool path, which owns every disposal.
|
|
68
|
+
*/
|
|
69
|
+
readonly client: MapClient | null;
|
|
70
|
+
/**
|
|
71
|
+
* The live collaboration session the edit's live segment is handed to as the person drags, so
|
|
72
|
+
* a peer previews it. Null or omitted on an itinerary nobody else is editing. The session paces
|
|
73
|
+
* what it sends at its own rate, so every write the engine makes is handed over.
|
|
74
|
+
*/
|
|
75
|
+
readonly collab?:
|
|
76
|
+
| {
|
|
77
|
+
/**
|
|
78
|
+
* Sends the draft a peer should preview for one entity: the edit's live segment. A
|
|
79
|
+
* session that relays any value, as `CollabEngine.sendDraft` does, fits.
|
|
80
|
+
*/
|
|
81
|
+
readonly sendDraft: (
|
|
82
|
+
entity: { readonly id: string; readonly kind: "segment" },
|
|
83
|
+
draft: ItinerarySegment,
|
|
84
|
+
) => void;
|
|
85
|
+
}
|
|
86
|
+
| null
|
|
87
|
+
| undefined;
|
|
88
|
+
/**
|
|
89
|
+
* The tool context the edit runs in. Compared by identity: another context arms the open
|
|
90
|
+
* session again, since its client and its store may differ.
|
|
91
|
+
*/
|
|
92
|
+
readonly context: SegmentDraftContext;
|
|
93
|
+
/**
|
|
94
|
+
* The words the via ceiling's warning and the route-hazard prompt are written in, and the
|
|
95
|
+
* sentence a refused begin is told in (`editing.segmentEditBeginFailed`).
|
|
96
|
+
*/
|
|
97
|
+
readonly strings: Pick<StudioStrings, "editing">;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* SegmentDraftEngineOptions is the {@link SegmentDraftConfig} an engine starts with, plus the one
|
|
102
|
+
* setting that is fixed for its life.
|
|
103
|
+
*/
|
|
104
|
+
export interface SegmentDraftEngineOptions extends SegmentDraftConfig {
|
|
105
|
+
/**
|
|
106
|
+
* The window a burst of routed drafts is paced to before the live segment is written, in
|
|
107
|
+
* milliseconds. The first route of a burst is written at once and the last one on the window's
|
|
108
|
+
* trailing edge, so the profile never ends a step behind the geometry. Zero writes every route
|
|
109
|
+
* as it arrives. A whole or fractional number from 0 to 2,147,483,647, the longest delay a timer
|
|
110
|
+
* honours.
|
|
111
|
+
*
|
|
112
|
+
* The default is the rate a collaboration session sends the same live segment at, so a peer's
|
|
113
|
+
* preview advances as smoothly as the local profile.
|
|
114
|
+
*
|
|
115
|
+
* @default 60
|
|
116
|
+
*/
|
|
117
|
+
readonly throttleMs?: number | undefined;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* SegmentDraftEngineSnapshot is what a {@link SegmentDraftEngine} answers: whether a segment edit
|
|
122
|
+
* is armed, which one, and how many handles its latest draft holds.
|
|
123
|
+
*
|
|
124
|
+
* It names the segment it answers for, so a reader holding a snapshot knows which edit it counts
|
|
125
|
+
* and never takes one edit's count for the next one's.
|
|
126
|
+
*/
|
|
127
|
+
export interface SegmentDraftEngineSnapshot {
|
|
128
|
+
/** Whether an edit is armed on the configured map client and its drafts are being read. */
|
|
129
|
+
readonly armed: boolean;
|
|
130
|
+
/** How the armed edit is authored, or null while nothing is armed. */
|
|
131
|
+
readonly mode: SegmentEditMode | null;
|
|
132
|
+
/** The segment the armed edit stands for, or null while nothing is armed. */
|
|
133
|
+
readonly segmentId: string | null;
|
|
134
|
+
/**
|
|
135
|
+
* The handles the armed edit's latest draft holds: the vias of a directions edit, the vertices
|
|
136
|
+
* of a freehand one. Zero until the first draft, and while nothing is armed.
|
|
137
|
+
*/
|
|
138
|
+
readonly viaCount: number;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** idleSnapshot is the answer while nothing is armed: one object, so its identity is stable. */
|
|
142
|
+
const idleSnapshot: SegmentDraftEngineSnapshot = {
|
|
143
|
+
armed: false,
|
|
144
|
+
mode: null,
|
|
145
|
+
segmentId: null,
|
|
146
|
+
viaCount: 0,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/** One {@link SegmentDraftEngine.subscribe} call, held by identity so each one leaves once. */
|
|
150
|
+
interface Subscription {
|
|
151
|
+
readonly listener: () => void;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Arming is what an armed edit was armed with. A change of any member arms it again, which is the
|
|
156
|
+
* map client's no-op unless the segment, the mode or the seed changed.
|
|
157
|
+
*/
|
|
158
|
+
interface Arming {
|
|
159
|
+
readonly activitySlug: string | null;
|
|
160
|
+
readonly client: MapClient;
|
|
161
|
+
readonly context: SegmentDraftContext;
|
|
162
|
+
readonly draftColor: string | null;
|
|
163
|
+
readonly mode: SegmentEditMode;
|
|
164
|
+
readonly pinnedEnd: SegmentEditSession["pinnedEnd"];
|
|
165
|
+
readonly pinnedStart: SegmentEditSession["pinnedStart"];
|
|
166
|
+
readonly seedVias: SegmentEditSession["seedVias"];
|
|
167
|
+
readonly segmentId: string;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* ListenKey is what one subscription to a map's drafts is for. A change of any member ends it and
|
|
172
|
+
* starts another, which drops the live segment its routes projected.
|
|
173
|
+
*
|
|
174
|
+
* The open itinerary is part of it because a live segment is projected onto the itinerary it
|
|
175
|
+
* belongs to: another itinerary's residue describes nothing the reader is editing.
|
|
176
|
+
*/
|
|
177
|
+
interface ListenKey {
|
|
178
|
+
readonly client: MapClient;
|
|
179
|
+
readonly context: SegmentDraftContext;
|
|
180
|
+
readonly itineraryId: string | null;
|
|
181
|
+
readonly mode: SegmentEditMode;
|
|
182
|
+
readonly segmentId: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* RoutedDraft is one route a draft carried, with the handles it was routed for when the draft says
|
|
187
|
+
* so: a programmatic draft re-applies the route its own handles resolved to, where an interactive
|
|
188
|
+
* one carries the route of the handles before it until a new one resolves.
|
|
189
|
+
*/
|
|
190
|
+
interface RoutedDraft {
|
|
191
|
+
readonly route: SegmentRoute;
|
|
192
|
+
readonly routedFor: readonly (readonly number[])[] | undefined;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Listening is one subscription to a map's drafts, with the throttle pacing its routes. */
|
|
196
|
+
interface Listening extends ListenKey {
|
|
197
|
+
/**
|
|
198
|
+
* The route the last projection read and the live segment it wrote, or null before the first
|
|
199
|
+
* one. A draft carrying that route again while the store still holds that segment has nothing
|
|
200
|
+
* to write.
|
|
201
|
+
*/
|
|
202
|
+
projected: { readonly liveSegment: ItinerarySegment; readonly route: SegmentRoute } | null;
|
|
203
|
+
/** Ends the subscription. */
|
|
204
|
+
release: () => void;
|
|
205
|
+
/** The throttle pacing its routes, or null under a zero window, which writes each at once. */
|
|
206
|
+
readonly throttle: TrailingThrottle<RoutedDraft> | null;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** sameArming reports whether two armings would hand the map client the same inputs. */
|
|
210
|
+
const sameArming = (a: Arming, b: Arming): boolean =>
|
|
211
|
+
a.client === b.client &&
|
|
212
|
+
a.context === b.context &&
|
|
213
|
+
a.segmentId === b.segmentId &&
|
|
214
|
+
a.mode === b.mode &&
|
|
215
|
+
a.activitySlug === b.activitySlug &&
|
|
216
|
+
a.draftColor === b.draftColor &&
|
|
217
|
+
a.pinnedEnd === b.pinnedEnd &&
|
|
218
|
+
a.pinnedStart === b.pinnedStart &&
|
|
219
|
+
a.seedVias === b.seedVias;
|
|
220
|
+
|
|
221
|
+
/** sameListenKey reports whether two subscriptions would read the same drafts for the same edit. */
|
|
222
|
+
const sameListenKey = (a: ListenKey, b: ListenKey): boolean =>
|
|
223
|
+
a.client === b.client &&
|
|
224
|
+
a.context === b.context &&
|
|
225
|
+
a.itineraryId === b.itineraryId &&
|
|
226
|
+
a.mode === b.mode &&
|
|
227
|
+
a.segmentId === b.segmentId;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* throttleFrom reads the window an engine is constructed with, refusing a value no timer can keep.
|
|
231
|
+
*
|
|
232
|
+
* @throws {MountayaElementsError} When `throttleMs` is not a finite number from 0 to
|
|
233
|
+
* {@link MAX_TIMER_MS}. A `NaN` or a negative window fires at once and an `Infinity` or an
|
|
234
|
+
* oversized one fires at once too, so each would be a throttle that paces nothing while reading
|
|
235
|
+
* as a setting.
|
|
236
|
+
*/
|
|
237
|
+
const throttleFrom = (throttleMs: number | undefined): number => {
|
|
238
|
+
if (throttleMs === undefined) {
|
|
239
|
+
return LIVE_SEGMENT_THROTTLE_MS;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (!Number.isFinite(throttleMs) || throttleMs < 0 || throttleMs > MAX_TIMER_MS) {
|
|
243
|
+
throw new MountayaElementsError(
|
|
244
|
+
`SegmentDraftEngine: throttleMs is ${String(throttleMs)}; pass a number of milliseconds ` +
|
|
245
|
+
`from 0 to ${MAX_TIMER_MS}, or omit it for ${LIVE_SEGMENT_THROTTLE_MS}.`,
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return throttleMs;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* SegmentDraftEngine is the machine behind a segment edit's drafts: it arms the map's segment
|
|
254
|
+
* editor for the open edit session and turns every draft the editor reports into the store's
|
|
255
|
+
* history, the live segment the elevation profile reads and the preview a collaborator sees.
|
|
256
|
+
*
|
|
257
|
+
* What it does, in the order a session meets it:
|
|
258
|
+
*
|
|
259
|
+
* - **Arming.** While a segment edit session is open in `context.ui` and a map client is set, the
|
|
260
|
+
* client is armed through `beginSegmentEdit` with {@link buildSegmentEditOptions}: a directions
|
|
261
|
+
* edit routes through `context.api.client`, a freehand edit analyses its line through it, and a
|
|
262
|
+
* click past the router's via ceiling raises a warning through `bus`. It is armed again when an
|
|
263
|
+
* arming input changes (the segment, the mode, the activity, the colour, a pin, the seed, the
|
|
264
|
+
* client or the context). The engine never ends an edit: the tool path that commits or cancels
|
|
265
|
+
* one owns the disposal, so parking or disposing leaves the map's editor where it is.
|
|
266
|
+
* - **A refused begin.** A map client that refuses the begin (a directions edit with no activity
|
|
267
|
+
* or no router, a seed its drawing library refuses) has taken no edit. Nothing is armed, the
|
|
268
|
+
* session is ended through `studio.itinerary.segment.editCancel` on `bus`, the reader is told
|
|
269
|
+
* the edit did not open through `studio.alert.show`, in the bundle's
|
|
270
|
+
* `editing.segmentEditBeginFailed`, and the refusal reaches the program as an uncaught error on
|
|
271
|
+
* a microtask, never through the store write that woke the engine. Each happens once per
|
|
272
|
+
* refused session, however many times a surface parks and resumes the engine before the cancel
|
|
273
|
+
* lands. The session that follows is armed afresh.
|
|
274
|
+
* - **Disposition.** Every draft is handed to {@link draftChangeDisposition}: a person's change
|
|
275
|
+
* while the co-pilot drives is dropped whole, a programmatic change is previewed and never
|
|
276
|
+
* recorded, and a person's change is recorded.
|
|
277
|
+
* - **History.** A recorded draft is routed by its phase: a `live` frame of a drag moves the draft
|
|
278
|
+
* through `setSegmentEditLiveDraft`, and the `settled` draft closing it records one undo step
|
|
279
|
+
* through `pushSegmentDraft`, so a drag of any length is one step.
|
|
280
|
+
* - **Live segment.** A draft carrying a route projects it onto the live segment through
|
|
281
|
+
* {@link buildLiveSegmentForDraft}, paced to `throttleMs`: the first route of a burst lands at
|
|
282
|
+
* once and the last one on the window's trailing edge. The same segment goes to `collab`. The
|
|
283
|
+
* map's editor hands its cached route to every draft until a new one resolves, so a draft
|
|
284
|
+
* carrying the route the last write read writes nothing while the store still holds what that
|
|
285
|
+
* write produced: a drag over one route rebuilds the profile once. A
|
|
286
|
+
* `live` frame with no route leaves the live segment as it stands. A `settled` draft with no
|
|
287
|
+
* route drops any pending route and falls back: to nothing for a persisted segment, so the
|
|
288
|
+
* profile shows the segment as saved, and to the draft's synthetic segment for one drawn from
|
|
289
|
+
* scratch, so its row stays visible. A programmatic draft with no route is the echo of an undo
|
|
290
|
+
* or a redo, which restored the live segment itself, so it is left untouched.
|
|
291
|
+
* - **Hazards.** A routed line crossing a hazard the session has not accepted is put to
|
|
292
|
+
* `context.confirm` as {@link routeHazardConfirmation}, once per question however many routing
|
|
293
|
+
* round trips ask it, and the answer is remembered in the session, so the same way is not asked
|
|
294
|
+
* about twice in one edit. With no confirm gate the line is adopted.
|
|
295
|
+
*
|
|
296
|
+
* The snapshot names the armed edit and counts its latest draft's handles (see
|
|
297
|
+
* {@link SegmentDraftEngineSnapshot}). It changes only when one of those does, never per frame of
|
|
298
|
+
* a drag, so a surface following it re-renders once per handle added or removed. Every listener
|
|
299
|
+
* is told of a change. One that throws stops neither the engine nor the listeners after it, and
|
|
300
|
+
* its fault reaches the program as an uncaught error on a microtask.
|
|
301
|
+
*
|
|
302
|
+
* Time follows the engines' rule: the throttle keeps the rate a profile is worth rebuilding at,
|
|
303
|
+
* which is no duration the product chose, so it runs on the runtime's timer through
|
|
304
|
+
* `TrailingThrottle` with its window as the `throttleMs` option, and the engine takes no `Clock`.
|
|
305
|
+
* A host that froze its clock would otherwise freeze every live profile with it.
|
|
306
|
+
*
|
|
307
|
+
* The lifecycle is the listeners. Constructing one arms nothing, reads no store and writes
|
|
308
|
+
* nothing; the first subscriber starts watching the store and arms the open session; the last
|
|
309
|
+
* unsubscribe parks: it stops reading the map's drafts, drops the pending route and clears the
|
|
310
|
+
* live segment, so a surface mounted again over the same session starts from a clean slot until
|
|
311
|
+
* the next route lands. React's StrictMode mounts, unmounts and mounts again, which parks and
|
|
312
|
+
* resumes and leaves one subscription to the map's drafts. `dispose()` is the latch, for an owner
|
|
313
|
+
* that is not a component. The callbacks the editor was armed with read the configuration when
|
|
314
|
+
* they run, so a warning or a prompt raised after a locale change reads the new words.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* declare const map: MapClient;
|
|
319
|
+
* declare const strings: StudioStrings;
|
|
320
|
+
* declare const session: SegmentDraftConfig["collab"];
|
|
321
|
+
*
|
|
322
|
+
* const drafts = new SegmentDraftEngine({ bus, client: map, context: ctx, strings });
|
|
323
|
+
* const release = drafts.subscribe(() => {
|
|
324
|
+
* console.log(drafts.getSnapshot().viaCount);
|
|
325
|
+
* });
|
|
326
|
+
*
|
|
327
|
+
* drafts.configure({ bus, client: map, collab: session, context: ctx, strings });
|
|
328
|
+
* release();
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
export class SegmentDraftEngine {
|
|
332
|
+
private config: SegmentDraftConfig;
|
|
333
|
+
private readonly throttleMs: number;
|
|
334
|
+
|
|
335
|
+
private snapshot: SegmentDraftEngineSnapshot = idleSnapshot;
|
|
336
|
+
private readonly subscriptions = new Set<Subscription>();
|
|
337
|
+
|
|
338
|
+
/** The store the session is watched in, and the subscription watching it, while running. */
|
|
339
|
+
private watching: { readonly release: () => void; readonly ui: UiStoreApi } | null = null;
|
|
340
|
+
/** What the open edit was armed with, or null while nothing is armed. */
|
|
341
|
+
private arming: Arming | null = null;
|
|
342
|
+
/**
|
|
343
|
+
* What the map client refused to arm, or null. Held until the session it was for closes or one
|
|
344
|
+
* of its inputs changes, so a session on its way out is not handed to the map again. A park
|
|
345
|
+
* keeps it: the session it names is still on its way out when the next subscriber arrives.
|
|
346
|
+
*/
|
|
347
|
+
private refused: Arming | null = null;
|
|
348
|
+
/** The subscription to the armed map's drafts, or null while nothing is armed. */
|
|
349
|
+
private listening: Listening | null = null;
|
|
350
|
+
/** The handles the armed edit's latest draft holds. */
|
|
351
|
+
private viaCount = 0;
|
|
352
|
+
|
|
353
|
+
/** Whether a reconcile is running, so one a store write starts inside it runs after it. */
|
|
354
|
+
private reconciling = false;
|
|
355
|
+
/** Whether the store changed during the running reconcile, which then runs again. */
|
|
356
|
+
private stale = false;
|
|
357
|
+
|
|
358
|
+
/** Whether nobody is watching. A parked engine arms nothing and reads no draft. */
|
|
359
|
+
private parked = true;
|
|
360
|
+
private disposed = false;
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* One dialog per hazard question, however many routing round trips ask it. Held for the
|
|
364
|
+
* engine's life rather than per arming: a gate built beside the routing function would forget
|
|
365
|
+
* the dialog already on screen, which is the state it exists to track.
|
|
366
|
+
*/
|
|
367
|
+
private readonly hazardGate: HazardPromptGate = createHazardPromptGate((hazards) =>
|
|
368
|
+
this.askAboutHazards(hazards),
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* The session's record of accepted hazards, read and written through the store the engine is
|
|
373
|
+
* configured with when the routing function asks. The store outlives every routing function
|
|
374
|
+
* the editor is armed with, which is the point: an answer outlives a re-arm.
|
|
375
|
+
*/
|
|
376
|
+
private readonly hazardMemo: RouteHazardMemo = {
|
|
377
|
+
accept: (keys) => {
|
|
378
|
+
this.config.context.ui.getState().acknowledgeRouteHazards(keys);
|
|
379
|
+
},
|
|
380
|
+
accepted: () =>
|
|
381
|
+
this.config.context.ui.getState().segmentEditSession?.acknowledgedRouteHazards ?? [],
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Constructing one holds the options and does nothing else: nothing is armed, no store is read
|
|
386
|
+
* and nothing is written. A React binding constructs during a render React is free to throw
|
|
387
|
+
* away, and a constructor with a side effect would leave the discarded copy acting.
|
|
388
|
+
*
|
|
389
|
+
* @throws {MountayaElementsError} When `throttleMs` is not a finite number from 0 to
|
|
390
|
+
* 2,147,483,647.
|
|
391
|
+
*/
|
|
392
|
+
constructor(options: SegmentDraftEngineOptions) {
|
|
393
|
+
const { throttleMs, ...config } = options;
|
|
394
|
+
this.throttleMs = throttleFrom(throttleMs);
|
|
395
|
+
this.config = config;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** getSnapshot returns the current answer, by reference and stable between changes. */
|
|
399
|
+
getSnapshot(): SegmentDraftEngineSnapshot {
|
|
400
|
+
return this.snapshot;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* subscribe registers a listener for every change of the snapshot, and returns its own
|
|
405
|
+
* unsubscribe, which is idempotent.
|
|
406
|
+
*
|
|
407
|
+
* The first listener starts the engine and the last one leaving parks it, which is the whole
|
|
408
|
+
* lifecycle a component can express correctly: React tears an effect down and sets it up again
|
|
409
|
+
* with the same object under StrictMode, so a latch here would leave a live surface bound to a
|
|
410
|
+
* dead engine. Each call is its own subscription, so two owners subscribing one shared function
|
|
411
|
+
* each hold the engine until they release it.
|
|
412
|
+
*/
|
|
413
|
+
subscribe(listener: () => void): () => void {
|
|
414
|
+
if (this.disposed) {
|
|
415
|
+
return () => {};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const subscription: Subscription = { listener };
|
|
419
|
+
this.subscriptions.add(subscription);
|
|
420
|
+
|
|
421
|
+
if (this.parked) {
|
|
422
|
+
this.parked = false;
|
|
423
|
+
this.reconcile();
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return () => {
|
|
427
|
+
if (!this.subscriptions.delete(subscription) || this.subscriptions.size > 0) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (!this.parked) {
|
|
432
|
+
this.park();
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* configure replaces the configuration, and arms again only when an arming input changed.
|
|
439
|
+
*
|
|
440
|
+
* A binding calls it on every render, so a configuration carrying the same client and the same
|
|
441
|
+
* context does nothing beyond the assignment: the bus, the collaboration session and the words
|
|
442
|
+
* are read when they are used. A parked engine keeps the configuration for its next subscriber.
|
|
443
|
+
*/
|
|
444
|
+
configure(config: SegmentDraftConfig): void {
|
|
445
|
+
if (this.disposed) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
this.config = config;
|
|
450
|
+
if (!this.parked) {
|
|
451
|
+
this.reconcile();
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* dispose parks the engine and drops every listener, for good.
|
|
457
|
+
*
|
|
458
|
+
* Idempotent, and every call after it is a no-op rather than an error: an owner torn down
|
|
459
|
+
* mid-edit should not have to guard the calls it already queued. A disposed engine writes no
|
|
460
|
+
* store either: the cancel it dispatched for a refused begin runs on the bus, and a session that
|
|
461
|
+
* cancel leaves open is not closed by the engine.
|
|
462
|
+
*
|
|
463
|
+
* The snapshot of a disposed engine reads `armed: false`. The engine holds a session and no
|
|
464
|
+
* answer to a question, so there is nothing a reader could keep showing: the session is over
|
|
465
|
+
* for this engine, and the snapshot says so.
|
|
466
|
+
*/
|
|
467
|
+
dispose(): void {
|
|
468
|
+
if (this.disposed) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
this.disposed = true;
|
|
473
|
+
if (!this.parked) {
|
|
474
|
+
this.park();
|
|
475
|
+
}
|
|
476
|
+
this.subscriptions.clear();
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* reconcile brings the arming and the draft subscription in line with the store and the
|
|
481
|
+
* configuration, then publishes the snapshot. A store write it makes, or one a listener makes
|
|
482
|
+
* while it runs, runs it again once it finishes rather than inside it.
|
|
483
|
+
*/
|
|
484
|
+
private reconcile(): void {
|
|
485
|
+
if (this.parked) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
if (this.reconciling) {
|
|
490
|
+
this.stale = true;
|
|
491
|
+
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
this.reconciling = true;
|
|
496
|
+
try {
|
|
497
|
+
do {
|
|
498
|
+
this.stale = false;
|
|
499
|
+
this.step();
|
|
500
|
+
} while (this.stale && !this.parked);
|
|
501
|
+
} finally {
|
|
502
|
+
this.reconciling = false;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
this.publish();
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** step is one pass of {@link SegmentDraftEngine.reconcile}. */
|
|
509
|
+
private step(): void {
|
|
510
|
+
const { client, context } = this.config;
|
|
511
|
+
this.watch(context.ui);
|
|
512
|
+
|
|
513
|
+
const state = context.ui.getState();
|
|
514
|
+
const session = state.segmentEditSession;
|
|
515
|
+
if (client === null || session === null || session.segmentId === "") {
|
|
516
|
+
this.unlisten();
|
|
517
|
+
this.arming = null;
|
|
518
|
+
this.refused = null;
|
|
519
|
+
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
const key: ListenKey = {
|
|
524
|
+
client,
|
|
525
|
+
context,
|
|
526
|
+
itineraryId: state.activeItinerary?.id ?? null,
|
|
527
|
+
mode: session.mode,
|
|
528
|
+
segmentId: session.segmentId,
|
|
529
|
+
};
|
|
530
|
+
if (this.listening !== null && !sameListenKey(this.listening, key)) {
|
|
531
|
+
this.unlisten();
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const arming: Arming = {
|
|
535
|
+
activitySlug: session.activitySlug,
|
|
536
|
+
client,
|
|
537
|
+
context,
|
|
538
|
+
draftColor: session.draftColor,
|
|
539
|
+
mode: session.mode,
|
|
540
|
+
pinnedEnd: session.pinnedEnd,
|
|
541
|
+
pinnedStart: session.pinnedStart,
|
|
542
|
+
seedVias: session.seedVias,
|
|
543
|
+
segmentId: session.segmentId,
|
|
544
|
+
};
|
|
545
|
+
if (this.refused !== null && sameArming(this.refused, arming)) {
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
if (this.arming === null || !sameArming(this.arming, arming)) {
|
|
550
|
+
try {
|
|
551
|
+
client.beginSegmentEdit(
|
|
552
|
+
buildSegmentEditOptions(session, {
|
|
553
|
+
client: context.api?.client,
|
|
554
|
+
confirmHazards: this.hazardGate,
|
|
555
|
+
hazardMemo: this.hazardMemo,
|
|
556
|
+
onViaCapRefused: () => this.refuseViaCap(),
|
|
557
|
+
}),
|
|
558
|
+
);
|
|
559
|
+
} catch (refusal) {
|
|
560
|
+
// The map took no edit, so nothing is armed and there is no draft to read.
|
|
561
|
+
this.unlisten();
|
|
562
|
+
this.arming = null;
|
|
563
|
+
this.refused = arming;
|
|
564
|
+
this.endRefused(context, segmentEditSessionMark(session), refusal);
|
|
565
|
+
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// Recorded once the map took it: an arming recorded ahead of a refusal would read as armed.
|
|
570
|
+
this.arming = arming;
|
|
571
|
+
this.refused = null;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
if (this.listening === null) {
|
|
575
|
+
this.listen(key);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* endRefused ends the session whose begin the map client refused, and hands the refusal to the
|
|
581
|
+
* program.
|
|
582
|
+
*
|
|
583
|
+
* The session is ended by `studio.itinerary.segment.editCancel` through `bus`, the tool path
|
|
584
|
+
* that owns every disposal: it gives back the lock the begin took and ends whatever edit the map
|
|
585
|
+
* still holds. Where that tool does not answer `ok` (it is refused, it rejects, or the bus
|
|
586
|
+
* states no result at all), the store's session is closed directly, so no session stays open
|
|
587
|
+
* over a map that is editing nothing. A parked engine still closes it, since its surface may
|
|
588
|
+
* mount again. A disposed one writes nothing, as {@link SegmentDraftEngine.dispose} promises:
|
|
589
|
+
* the session is left to the engine that takes its place, which meets the same refusal.
|
|
590
|
+
*
|
|
591
|
+
* The refused session is the one closed directly, and no other: it is told by `mark`, its
|
|
592
|
+
* {@link segmentEditSessionMark}, so a session begun since on the same segment stays open.
|
|
593
|
+
*
|
|
594
|
+
* The refusal names the option the map lacked. It is a defect of the program that armed the
|
|
595
|
+
* session and not of the store write that woke the engine, so it leaves through
|
|
596
|
+
* {@link surfaceFault}.
|
|
597
|
+
*
|
|
598
|
+
* The reader is told as well, since an uncaught error says nothing on screen and the session
|
|
599
|
+
* closes under them: an `error` alert in the bundle's `editing.segmentEditBeginFailed`, read
|
|
600
|
+
* when the refusal is told so a locale change is heard. It is raised after the cancel is asked
|
|
601
|
+
* for, so a bus that answers one verb at a time ends the session first.
|
|
602
|
+
*/
|
|
603
|
+
private endRefused(context: SegmentDraftContext, mark: object, refusal: unknown): void {
|
|
604
|
+
surfaceFault(refusal);
|
|
605
|
+
|
|
606
|
+
const close = (): void => {
|
|
607
|
+
if (this.disposed) {
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
const state = context.ui.getState();
|
|
612
|
+
const open = state.segmentEditSession;
|
|
613
|
+
if (open !== null && segmentEditSessionMark(open) === mark) {
|
|
614
|
+
state.cancelSegmentEdit();
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
// What the dispatch answered is read as a promise whatever it is, as raiseAlert reads it: a
|
|
619
|
+
// bus that answers none, as a double written over a bare spy does, states no result, and
|
|
620
|
+
// the session is then closed directly as it is for a cancel that rejects or is refused.
|
|
621
|
+
void Promise.resolve(
|
|
622
|
+
this.config.bus.dispatch(context, "studio.itinerary.segment.editCancel", {}),
|
|
623
|
+
).then((result: ToolResult | undefined) => {
|
|
624
|
+
if (result?.ok !== true) {
|
|
625
|
+
close();
|
|
626
|
+
}
|
|
627
|
+
}, close);
|
|
628
|
+
|
|
629
|
+
this.raiseAlert(context, {
|
|
630
|
+
level: "error",
|
|
631
|
+
message: this.config.strings.editing.segmentEditBeginFailed,
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* raiseAlert raises one alert through the bus, and holds a bus that rejects it.
|
|
637
|
+
*
|
|
638
|
+
* Nothing follows an alert: the map has already declined what the alert reports, and a refused
|
|
639
|
+
* begin has reached the program through {@link surfaceFault} and is closed by its cancel. So a
|
|
640
|
+
* rejection is dropped, where one left unhandled would end a Node process with an error that is
|
|
641
|
+
* none of the package's.
|
|
642
|
+
*/
|
|
643
|
+
private raiseAlert(
|
|
644
|
+
context: SegmentDraftContext,
|
|
645
|
+
alert: StudioToolInputs["studio.alert.show"],
|
|
646
|
+
): void {
|
|
647
|
+
// What the dispatch answered is read as a promise whatever it is: a bus that answers none,
|
|
648
|
+
// as a double written over a bare spy does, is held the same way.
|
|
649
|
+
void Promise.resolve(this.config.bus.dispatch(context, "studio.alert.show", alert)).then(
|
|
650
|
+
undefined,
|
|
651
|
+
() => {
|
|
652
|
+
// Dropped: nothing follows an alert.
|
|
653
|
+
},
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/** watch follows the store the session lives in, leaving the previous one if it changed. */
|
|
658
|
+
private watch(ui: UiStoreApi): void {
|
|
659
|
+
if (this.watching?.ui === ui) {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
this.unwatch();
|
|
664
|
+
this.watching = { release: ui.subscribe(() => this.reconcile()), ui };
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
private unwatch(): void {
|
|
668
|
+
this.watching?.release();
|
|
669
|
+
this.watching = null;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/** listen starts reading the armed map's drafts for the edit `key` names. */
|
|
673
|
+
private listen(key: ListenKey): void {
|
|
674
|
+
const listening: Listening = {
|
|
675
|
+
...key,
|
|
676
|
+
projected: null,
|
|
677
|
+
release: () => {},
|
|
678
|
+
// A zero-delay window still coalesces the routes a single turn of the event loop delivers,
|
|
679
|
+
// so a zero window takes no throttle at all.
|
|
680
|
+
throttle:
|
|
681
|
+
this.throttleMs === 0
|
|
682
|
+
? null
|
|
683
|
+
: new TrailingThrottle<RoutedDraft>(
|
|
684
|
+
this.throttleMs,
|
|
685
|
+
(routed) => this.project(listening, routed),
|
|
686
|
+
// The first route of a burst is the one the reader is waiting on: a drag whose
|
|
687
|
+
// profile appears one window late reads as lag.
|
|
688
|
+
{ leading: true },
|
|
689
|
+
),
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
this.listening = listening;
|
|
693
|
+
listening.release = key.client.onSegmentDraftChange((draft) => this.receive(listening, draft));
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* unlisten stops reading the map's drafts, drops the pending route, and clears the live segment,
|
|
698
|
+
* so a surface opened again over the session reads a clean slot until the next route lands.
|
|
699
|
+
*/
|
|
700
|
+
private unlisten(): void {
|
|
701
|
+
const listening = this.listening;
|
|
702
|
+
if (listening === null) {
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
this.listening = null;
|
|
707
|
+
this.viaCount = 0;
|
|
708
|
+
listening.release();
|
|
709
|
+
listening.throttle?.cancel();
|
|
710
|
+
listening.context.ui.getState().setSegmentEditLiveSegment(null);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/** receive handles one draft the armed map reported, as the class docblock sets out. */
|
|
714
|
+
private receive(listening: Listening, draft: SegmentDraft): void {
|
|
715
|
+
// A draft from a subscription the engine has left answers a question nobody is asking.
|
|
716
|
+
if (this.listening !== listening) {
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// The count follows the map's draft whoever moved it, a dropped change included: it is what
|
|
721
|
+
// the map shows.
|
|
722
|
+
if (draft.vias.length !== this.viaCount) {
|
|
723
|
+
this.viaCount = draft.vias.length;
|
|
724
|
+
this.publish();
|
|
725
|
+
if (this.listening !== listening) {
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
const ui = listening.context.ui;
|
|
731
|
+
const disposition = draftChangeDisposition({
|
|
732
|
+
agentDriving: ui.getState().agentDriving,
|
|
733
|
+
programmatic: draft.programmatic,
|
|
734
|
+
});
|
|
735
|
+
if (disposition === "drop") {
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
if (disposition === "record") {
|
|
740
|
+
const geometry = buildSegmentGeometry(listening.mode, draft.vias);
|
|
741
|
+
if (draft.phase === "live") {
|
|
742
|
+
ui.getState().setSegmentEditLiveDraft(geometry);
|
|
743
|
+
} else {
|
|
744
|
+
ui.getState().pushSegmentDraft(geometry);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// A store listener may answer the write by closing the edit, or by opening another, and
|
|
748
|
+
// the draft's route or fallback would then land on an edit it does not belong to.
|
|
749
|
+
if (this.listening !== listening) {
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
if (draft.route) {
|
|
755
|
+
// The map's editor hands its cached route to every draft until a new one resolves: each
|
|
756
|
+
// frame of a drag and the settled draft closing it. Written once, it has nothing more to
|
|
757
|
+
// say while the live segment it produced is the one the store holds.
|
|
758
|
+
const projected = listening.projected;
|
|
759
|
+
if (
|
|
760
|
+
projected?.route === draft.route &&
|
|
761
|
+
ui.getState().segmentEditSession?.liveSegment === projected.liveSegment
|
|
762
|
+
) {
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
const routed: RoutedDraft = {
|
|
767
|
+
route: draft.route,
|
|
768
|
+
routedFor: draft.programmatic ? draft.vias : undefined,
|
|
769
|
+
};
|
|
770
|
+
if (listening.throttle === null) {
|
|
771
|
+
this.project(listening, routed);
|
|
772
|
+
} else {
|
|
773
|
+
listening.throttle.push(routed);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// The engine re-emits its cached route on every frame of a drag, so a frame with none holds
|
|
780
|
+
// the profile the panel shows; the settled draft falls back once, when the drag ends.
|
|
781
|
+
if (draft.phase === "live") {
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// Cancelling also resets the window, so the next route that resolves lands at once.
|
|
786
|
+
listening.throttle?.cancel();
|
|
787
|
+
if (disposition === "record") {
|
|
788
|
+
this.fallBack(listening);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* project writes one route onto the live segment the profile reads, and hands the same segment
|
|
794
|
+
* to the collaboration session.
|
|
795
|
+
*/
|
|
796
|
+
private project(listening: Listening, { route, routedFor }: RoutedDraft): void {
|
|
797
|
+
// A defence rather than a path: receive stops at a left subscription before it pushes a
|
|
798
|
+
// route, and unlisten cancels the throttle, so no route of a left edit reaches this line.
|
|
799
|
+
if (this.listening !== listening) {
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
const state = listening.context.ui.getState();
|
|
804
|
+
const itinerary = state.activeItinerary;
|
|
805
|
+
const session = state.segmentEditSession;
|
|
806
|
+
const liveSegment = buildLiveSegmentForDraft(
|
|
807
|
+
itinerary?.segments.find((segment) => segment.id === listening.segmentId),
|
|
808
|
+
listening.segmentId,
|
|
809
|
+
itinerary?.id ?? "",
|
|
810
|
+
session?.mode ?? "directions",
|
|
811
|
+
route,
|
|
812
|
+
session?.draftName ?? null,
|
|
813
|
+
session?.draftColor ?? null,
|
|
814
|
+
);
|
|
815
|
+
listening.projected = { liveSegment, route };
|
|
816
|
+
state.setSegmentEditLiveSegment(liveSegment, routedFor);
|
|
817
|
+
this.config.collab?.sendDraft({ id: listening.segmentId, kind: "segment" }, liveSegment);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* fallBack writes what the live segment is once a settled draft resolves no route: nothing for
|
|
822
|
+
* a persisted segment, which the profile then shows as saved, and the draft's synthetic
|
|
823
|
+
* segment for one drawn from scratch, which has no saved version to show and would otherwise
|
|
824
|
+
* lose its row until a route lands.
|
|
825
|
+
*/
|
|
826
|
+
private fallBack(listening: Listening): void {
|
|
827
|
+
const state = listening.context.ui.getState();
|
|
828
|
+
const session = state.segmentEditSession;
|
|
829
|
+
const persisted = state.activeItinerary?.segments?.find(
|
|
830
|
+
(segment) => segment.id === listening.segmentId,
|
|
831
|
+
);
|
|
832
|
+
|
|
833
|
+
if (!persisted && session) {
|
|
834
|
+
state.setSegmentEditLiveSegment(
|
|
835
|
+
synthesizeDraftSegment({
|
|
836
|
+
draftColor: session.draftColor,
|
|
837
|
+
draftName: session.draftName,
|
|
838
|
+
itineraryId: state.activeItinerary?.id ?? "",
|
|
839
|
+
mode: session.mode,
|
|
840
|
+
segmentId: session.segmentId,
|
|
841
|
+
}),
|
|
842
|
+
);
|
|
843
|
+
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
state.setSegmentEditLiveSegment(null);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/** refuseViaCap warns that a click was declined at the router's via ceiling. */
|
|
851
|
+
private refuseViaCap(): void {
|
|
852
|
+
const { context, strings } = this.config;
|
|
853
|
+
this.raiseAlert(context, {
|
|
854
|
+
level: "warning",
|
|
855
|
+
message: strings.editing.segmentViaCapRefused(DIRECTIONS_VIA_MAX),
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* askAboutHazards puts a routed line's new hazards to the context's confirm gate, in the words
|
|
861
|
+
* the engine was last handed, and adopts the line when the context has no gate.
|
|
862
|
+
*/
|
|
863
|
+
private askAboutHazards(hazards: RouteAdvisory[]): Promise<boolean> {
|
|
864
|
+
const { context, strings } = this.config;
|
|
865
|
+
if (!context.confirm) {
|
|
866
|
+
return Promise.resolve(true);
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
return context.confirm(
|
|
870
|
+
routeHazardConfirmation(hazards, {
|
|
871
|
+
closing: strings.editing.routeHazardClosing,
|
|
872
|
+
hazards: strings.editing.routeHazards,
|
|
873
|
+
severalTitle: strings.editing.routeHazardsTitle,
|
|
874
|
+
}),
|
|
875
|
+
);
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* park stops watching and reading, and drops what the running engine armed.
|
|
880
|
+
*
|
|
881
|
+
* A refused arming is kept. Its session stays open until the cancel the engine asked for lands,
|
|
882
|
+
* and a surface mounted again meanwhile would otherwise hand it to the map a second time and ask
|
|
883
|
+
* for a second cancel, which closes whichever session is open when it runs. A session begun
|
|
884
|
+
* since holds a seed array of its own, so it never reads as the refused one.
|
|
885
|
+
*/
|
|
886
|
+
private park(): void {
|
|
887
|
+
this.parked = true;
|
|
888
|
+
this.unwatch();
|
|
889
|
+
this.unlisten();
|
|
890
|
+
this.arming = null;
|
|
891
|
+
this.publish();
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
/** publish settles the snapshot and tells every listener when it changed. */
|
|
895
|
+
private publish(): void {
|
|
896
|
+
const listening = this.listening;
|
|
897
|
+
const next: SegmentDraftEngineSnapshot =
|
|
898
|
+
listening === null
|
|
899
|
+
? idleSnapshot
|
|
900
|
+
: {
|
|
901
|
+
armed: true,
|
|
902
|
+
mode: listening.mode,
|
|
903
|
+
segmentId: listening.segmentId,
|
|
904
|
+
viaCount: this.viaCount,
|
|
905
|
+
};
|
|
906
|
+
|
|
907
|
+
const current = this.snapshot;
|
|
908
|
+
if (
|
|
909
|
+
current.armed === next.armed &&
|
|
910
|
+
current.mode === next.mode &&
|
|
911
|
+
current.segmentId === next.segmentId &&
|
|
912
|
+
current.viaCount === next.viaCount
|
|
913
|
+
) {
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
this.snapshot = next;
|
|
918
|
+
if (this.disposed) {
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
// Every listener is told, and one that throws stops neither the engine nor the others: the
|
|
923
|
+
// snapshot changes inside a store write or a map's draft, which its fault must not unwind.
|
|
924
|
+
notifyListeners(Array.from(this.subscriptions, ({ listener }) => listener));
|
|
925
|
+
}
|
|
926
|
+
}
|