@mountaya/studio 0.0.0-stage → 0.1.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 +39 -0
- package/LICENCE.fr.txt +280 -0
- package/LICENSE.txt +262 -0
- package/README.md +917 -2
- package/dist/agent/index.cjs +2854 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +1257 -0
- package/dist/agent/index.d.ts +1257 -0
- package/dist/agent/index.js +2818 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/bus-BwiNiXdH.d.ts +514 -0
- package/dist/bus-DzmhPwdK.d.cts +514 -0
- package/dist/chainModel-B23pEP_1.d.cts +127 -0
- package/dist/chainModel-B23pEP_1.d.ts +127 -0
- package/dist/chunk-2HFY7ETU.js +5721 -0
- package/dist/chunk-2HFY7ETU.js.map +1 -0
- package/dist/chunk-355TOXSB.js +72 -0
- package/dist/chunk-355TOXSB.js.map +1 -0
- package/dist/chunk-4ZCUZVSV.js +10275 -0
- package/dist/chunk-4ZCUZVSV.js.map +1 -0
- package/dist/chunk-6HEKY3NF.js +95 -0
- package/dist/chunk-6HEKY3NF.js.map +1 -0
- package/dist/chunk-7GFLGGBX.cjs +8 -0
- package/dist/chunk-7GFLGGBX.cjs.map +1 -0
- package/dist/chunk-7NBRCENN.cjs +19 -0
- package/dist/chunk-7NBRCENN.cjs.map +1 -0
- package/dist/chunk-AF5GCXE3.js +8 -0
- package/dist/chunk-AF5GCXE3.js.map +1 -0
- package/dist/chunk-CJDIFRGZ.cjs +2005 -0
- package/dist/chunk-CJDIFRGZ.cjs.map +1 -0
- package/dist/chunk-CNPZY7N3.js +349 -0
- package/dist/chunk-CNPZY7N3.js.map +1 -0
- package/dist/chunk-DZJHTWSF.cjs +45 -0
- package/dist/chunk-DZJHTWSF.cjs.map +1 -0
- package/dist/chunk-EABIHHWA.js +42 -0
- package/dist/chunk-EABIHHWA.js.map +1 -0
- package/dist/chunk-EKZWV6RS.cjs +415 -0
- package/dist/chunk-EKZWV6RS.cjs.map +1 -0
- package/dist/chunk-EOKRXXAC.cjs +24 -0
- package/dist/chunk-EOKRXXAC.cjs.map +1 -0
- package/dist/chunk-F73W2ZTJ.js +1126 -0
- package/dist/chunk-F73W2ZTJ.js.map +1 -0
- package/dist/chunk-H4DVOZ5O.js +1897 -0
- package/dist/chunk-H4DVOZ5O.js.map +1 -0
- package/dist/chunk-HI52PBFT.cjs +10314 -0
- package/dist/chunk-HI52PBFT.cjs.map +1 -0
- package/dist/chunk-IDBXFBLG.cjs +1225 -0
- package/dist/chunk-IDBXFBLG.cjs.map +1 -0
- package/dist/chunk-LBWTJZUJ.js +297 -0
- package/dist/chunk-LBWTJZUJ.js.map +1 -0
- package/dist/chunk-NCLA6DKD.cjs +310 -0
- package/dist/chunk-NCLA6DKD.cjs.map +1 -0
- package/dist/chunk-O4MC5DPD.js +19 -0
- package/dist/chunk-O4MC5DPD.js.map +1 -0
- package/dist/chunk-OP37FKW6.cjs +98 -0
- package/dist/chunk-OP37FKW6.cjs.map +1 -0
- package/dist/chunk-OQSYFH3Z.cjs +5945 -0
- package/dist/chunk-OQSYFH3Z.cjs.map +1 -0
- package/dist/chunk-PACIO4NS.cjs +26 -0
- package/dist/chunk-PACIO4NS.cjs.map +1 -0
- package/dist/chunk-PSZ2R3TC.cjs +75 -0
- package/dist/chunk-PSZ2R3TC.cjs.map +1 -0
- package/dist/chunk-QFO5CZG2.cjs +136 -0
- package/dist/chunk-QFO5CZG2.cjs.map +1 -0
- package/dist/chunk-QL63MUEW.cjs +140 -0
- package/dist/chunk-QL63MUEW.cjs.map +1 -0
- package/dist/chunk-RFUPPVZO.js +17 -0
- package/dist/chunk-RFUPPVZO.js.map +1 -0
- package/dist/chunk-RPG2LWMP.js +23 -0
- package/dist/chunk-RPG2LWMP.js.map +1 -0
- package/dist/chunk-TIBXK6B7.cjs +12 -0
- package/dist/chunk-TIBXK6B7.cjs.map +1 -0
- package/dist/chunk-UU65VNEV.js +381 -0
- package/dist/chunk-UU65VNEV.js.map +1 -0
- package/dist/chunk-VGX6TR2I.js +209 -0
- package/dist/chunk-VGX6TR2I.js.map +1 -0
- package/dist/chunk-WUTDDBVP.js +130 -0
- package/dist/chunk-WUTDDBVP.js.map +1 -0
- package/dist/chunk-WVQQLKCI.cjs +224 -0
- package/dist/chunk-WVQQLKCI.cjs.map +1 -0
- package/dist/chunk-WZYXG3SE.js +111 -0
- package/dist/chunk-WZYXG3SE.js.map +1 -0
- package/dist/chunk-XDI2X3KE.js +6 -0
- package/dist/chunk-XDI2X3KE.js.map +1 -0
- package/dist/chunk-XKHLRIC7.cjs +381 -0
- package/dist/chunk-XKHLRIC7.cjs.map +1 -0
- package/dist/context-DNtd2WUv.d.cts +11666 -0
- package/dist/context-DgB72Bur.d.ts +11666 -0
- package/dist/directorThreads-CqmvsV8b.d.cts +80 -0
- package/dist/directorThreads-CqmvsV8b.d.ts +80 -0
- package/dist/en-Bu4Ti9Ev.d.cts +2315 -0
- package/dist/en-Bu4Ti9Ev.d.ts +2315 -0
- package/dist/engines/index.cjs +3446 -0
- package/dist/engines/index.cjs.map +1 -0
- package/dist/engines/index.d.cts +2216 -0
- package/dist/engines/index.d.ts +2216 -0
- package/dist/engines/index.js +3416 -0
- package/dist/engines/index.js.map +1 -0
- package/dist/handlers/index.cjs +99 -0
- package/dist/handlers/index.cjs.map +1 -0
- package/dist/handlers/index.d.cts +445 -0
- package/dist/handlers/index.d.ts +445 -0
- package/dist/handlers/index.js +42 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/index.cjs +4562 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7297 -0
- package/dist/index.d.ts +7297 -0
- package/dist/index.js +3223 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/index.cjs +977 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +313 -0
- package/dist/plugins/index.d.ts +313 -0
- package/dist/plugins/index.js +933 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/saveFile-j-1kkApx.d.cts +123 -0
- package/dist/saveFile-j-1kkApx.d.ts +123 -0
- package/dist/seams/index.cjs +152 -0
- package/dist/seams/index.cjs.map +1 -0
- package/dist/seams/index.d.cts +485 -0
- package/dist/seams/index.d.ts +485 -0
- package/dist/seams/index.js +79 -0
- package/dist/seams/index.js.map +1 -0
- package/dist/shareLink-B6hlt942.d.ts +144 -0
- package/dist/shareLink-C7rIMb7x.d.ts +527 -0
- package/dist/shareLink-CnTxxXjp.d.cts +144 -0
- package/dist/shareLink-DyZVYH2V.d.cts +527 -0
- package/dist/strings/fr/index.cjs +2121 -0
- package/dist/strings/fr/index.cjs.map +1 -0
- package/dist/strings/fr/index.d.cts +19 -0
- package/dist/strings/fr/index.d.ts +19 -0
- package/dist/strings/fr/index.js +2119 -0
- package/dist/strings/fr/index.js.map +1 -0
- package/dist/strings/index.cjs +2678 -0
- package/dist/strings/index.cjs.map +1 -0
- package/dist/strings/index.d.cts +731 -0
- package/dist/strings/index.d.ts +731 -0
- package/dist/strings/index.js +2644 -0
- package/dist/strings/index.js.map +1 -0
- package/dist/studioPlugin-C3C7VjMy.d.ts +847 -0
- package/dist/studioPlugin-Cf3OBNUv.d.cts +847 -0
- package/dist/tabs-B2nRO4p_.d.cts +15 -0
- package/dist/tabs-B2nRO4p_.d.ts +15 -0
- package/dist/testing/index.cjs +292 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +306 -0
- package/dist/testing/index.d.ts +306 -0
- package/dist/testing/index.js +284 -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 +43 -0
- package/dist/time/index.d.ts +43 -0
- package/dist/time/index.js +26 -0
- package/dist/time/index.js.map +1 -0
- package/dist/types-BzJRV6UI.d.cts +845 -0
- package/dist/types-BzJRV6UI.d.ts +845 -0
- package/dist/zoneForm-CdYNtnnA.d.cts +320 -0
- package/dist/zoneForm-mG85yt5e.d.ts +320 -0
- package/package.json +225 -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 +28 -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 +454 -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 +858 -0
- package/src/bus/rules/confirmation.ts +22 -0
- package/src/bus/rules/defineRegistry.ts +26 -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 +805 -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 +573 -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 +87 -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 +213 -0
- package/src/embed/rules/snippet.ts +531 -0
- package/src/embed/rules/tableCode.ts +269 -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 +1086 -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 +1052 -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 +200 -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 +209 -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 +34 -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 +198 -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,3446 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkXKHLRIC7_cjs = require('../chunk-XKHLRIC7.cjs');
|
|
4
|
+
var chunk7NBRCENN_cjs = require('../chunk-7NBRCENN.cjs');
|
|
5
|
+
var chunkDZJHTWSF_cjs = require('../chunk-DZJHTWSF.cjs');
|
|
6
|
+
var chunkEKZWV6RS_cjs = require('../chunk-EKZWV6RS.cjs');
|
|
7
|
+
var chunkIDBXFBLG_cjs = require('../chunk-IDBXFBLG.cjs');
|
|
8
|
+
var chunkPACIO4NS_cjs = require('../chunk-PACIO4NS.cjs');
|
|
9
|
+
var chunkEOKRXXAC_cjs = require('../chunk-EOKRXXAC.cjs');
|
|
10
|
+
var chunkQL63MUEW_cjs = require('../chunk-QL63MUEW.cjs');
|
|
11
|
+
var data = require('@mountaya/elements/data');
|
|
12
|
+
var geo = require('@mountaya/elements/geo');
|
|
13
|
+
var profile = require('@mountaya/elements/profile');
|
|
14
|
+
var errors = require('@mountaya/elements/errors');
|
|
15
|
+
var collab = require('@mountaya/elements/collab');
|
|
16
|
+
var z = require('zod');
|
|
17
|
+
var i18n = require('@mountaya/elements/i18n');
|
|
18
|
+
|
|
19
|
+
function _interopNamespace(e) {
|
|
20
|
+
if (e && e.__esModule) return e;
|
|
21
|
+
var n = Object.create(null);
|
|
22
|
+
if (e) {
|
|
23
|
+
Object.keys(e).forEach(function (k) {
|
|
24
|
+
if (k !== 'default') {
|
|
25
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
26
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () { return e[k]; }
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
n.default = e;
|
|
34
|
+
return Object.freeze(n);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var z__namespace = /*#__PURE__*/_interopNamespace(z);
|
|
38
|
+
|
|
39
|
+
var baseMapContent = { collectionId: null, itineraryId: null };
|
|
40
|
+
var sameContent = (a, b) => a.collectionId === b.collectionId && a.itineraryId === b.itineraryId;
|
|
41
|
+
var isBaseMap = (content) => sameContent(content, baseMapContent);
|
|
42
|
+
var collectionOf = (config) => config.fitCollection === void 0 ? null : config.collection ?? null;
|
|
43
|
+
var expectsCollectionOf = (config) => config.fitCollection !== void 0 && config.expectsCollection === true;
|
|
44
|
+
var expectsContent = (config) => config.expectsItinerary || expectsCollectionOf(config);
|
|
45
|
+
var contentOf = (config) => {
|
|
46
|
+
if (config.itinerary !== null) {
|
|
47
|
+
return { collectionId: null, itineraryId: config.itinerary.id };
|
|
48
|
+
}
|
|
49
|
+
const collection = collectionOf(config);
|
|
50
|
+
return collection === null || config.expectsItinerary ? baseMapContent : { collectionId: collection.id, itineraryId: null };
|
|
51
|
+
};
|
|
52
|
+
var lockSizeOf = (config) => config.lockCanvasSize === void 0 ? config.canvasSize : config.lockCanvasSize;
|
|
53
|
+
var questionOf = (config, client) => ({
|
|
54
|
+
canvasHeight: config.canvasSize?.height ?? null,
|
|
55
|
+
canvasWidth: config.canvasSize?.width ?? null,
|
|
56
|
+
client,
|
|
57
|
+
collectionBounds: collectionOf(config)?.bounds ?? null,
|
|
58
|
+
collectionId: collectionOf(config)?.id ?? null,
|
|
59
|
+
expectsCollection: expectsCollectionOf(config),
|
|
60
|
+
expectsItinerary: config.expectsItinerary,
|
|
61
|
+
itinerary: config.itinerary,
|
|
62
|
+
lockHeight: lockSizeOf(config)?.height ?? null,
|
|
63
|
+
lockWidth: lockSizeOf(config)?.width ?? null,
|
|
64
|
+
measuredPanelHeight: config.measuredPanelHeight,
|
|
65
|
+
showAnalysis: config.sections.showAnalysis,
|
|
66
|
+
showCharacteristics: config.sections.showCharacteristics,
|
|
67
|
+
showElevation: config.sections.showElevation,
|
|
68
|
+
zoomMax: config.zoomRange.zoomMax,
|
|
69
|
+
zoomMin: config.zoomRange.zoomMin
|
|
70
|
+
});
|
|
71
|
+
var sameQuestion = (a, b) => a.client === b.client && a.itinerary === b.itinerary && a.expectsItinerary === b.expectsItinerary && a.collectionId === b.collectionId && sameLock(a.collectionBounds, b.collectionBounds) && a.expectsCollection === b.expectsCollection && Object.is(a.measuredPanelHeight, b.measuredPanelHeight) && Object.is(a.canvasWidth, b.canvasWidth) && Object.is(a.canvasHeight, b.canvasHeight) && Object.is(a.lockWidth, b.lockWidth) && Object.is(a.lockHeight, b.lockHeight) && a.showAnalysis === b.showAnalysis && a.showCharacteristics === b.showCharacteristics && a.showElevation === b.showElevation && Object.is(a.zoomMax, b.zoomMax) && Object.is(a.zoomMin, b.zoomMin);
|
|
72
|
+
var sameSize = (a, b) => a === null || b === null ? a === b : Object.is(a.width, b.width) && Object.is(a.height, b.height);
|
|
73
|
+
var largestOf = (a, b) => {
|
|
74
|
+
const first = chunkXKHLRIC7_cjs.measuredCanvas(a);
|
|
75
|
+
const second = chunkXKHLRIC7_cjs.measuredCanvas(b);
|
|
76
|
+
if (first === null || second === null) {
|
|
77
|
+
return first ?? second;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
height: Math.max(first.height, second.height),
|
|
81
|
+
width: Math.max(first.width, second.width)
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
var laidOutAtNoArea = (size) => size !== null && Number.isFinite(size.width) && Number.isFinite(size.height) && (size.width <= 0 || size.height <= 0);
|
|
85
|
+
var isEmpty = (constraints) => constraints.maxBounds === void 0 && constraints.maxZoom === void 0 && constraints.minZoom === void 0;
|
|
86
|
+
var sameLock = (a, b) => a === null || a === void 0 || b === null || b === void 0 ? a === b : a.every((edge, index) => Object.is(edge, b[index]));
|
|
87
|
+
var standsAs = (decided, applied) => (decided.maxBounds === void 0 || sameLock(decided.maxBounds, applied.maxBounds)) && (decided.maxZoom === void 0 || Object.is(decided.maxZoom, applied.maxZoom)) && (decided.minZoom === void 0 || Object.is(decided.minZoom, applied.minZoom));
|
|
88
|
+
var sameRange = (a, b) => Object.is(a.zoomMax, b.zoomMax) && Object.is(a.zoomMin, b.zoomMin);
|
|
89
|
+
var EmbedFramingEngine = class {
|
|
90
|
+
config;
|
|
91
|
+
snapshot;
|
|
92
|
+
listeners = /* @__PURE__ */ new Set();
|
|
93
|
+
/** The client the framing below was made on; a replaced one starts from nothing. */
|
|
94
|
+
framingClient = null;
|
|
95
|
+
/** The question the last framing step answered, or null when the next step must run in full. */
|
|
96
|
+
asked = null;
|
|
97
|
+
/** The fit waiting for its paint, or null. */
|
|
98
|
+
pendingFit = null;
|
|
99
|
+
/** The settle with no fit waiting for its paint, or null. */
|
|
100
|
+
pendingReveal = null;
|
|
101
|
+
/**
|
|
102
|
+
* Whether a settle has been reported on {@link framingClient}. Until one has, a publisher's own
|
|
103
|
+
* view settles without waiting for its itinerary, which is what lifts a cold load's cover.
|
|
104
|
+
*/
|
|
105
|
+
reported = false;
|
|
106
|
+
/**
|
|
107
|
+
* The constraints the last itinerary or collection framed on {@link framingClient} left
|
|
108
|
+
* standing, or null.
|
|
109
|
+
*/
|
|
110
|
+
standing = null;
|
|
111
|
+
/**
|
|
112
|
+
* Every constraint written to {@link framingClient}, each member as it was written last. A
|
|
113
|
+
* member never written is absent, so the first write of anything is news.
|
|
114
|
+
*/
|
|
115
|
+
applied = {};
|
|
116
|
+
/**
|
|
117
|
+
* Whether a pan lock stands on {@link framingClient}. The next constraints that decide no lock
|
|
118
|
+
* (the base map alone, an itinerary with no extent) release it.
|
|
119
|
+
*/
|
|
120
|
+
locked = false;
|
|
121
|
+
/**
|
|
122
|
+
* Whether a content switch made with nothing framed is still unanswered: an itinerary or a
|
|
123
|
+
* collection is, or was, expected, or the configured id changed, and since then nothing was
|
|
124
|
+
* framed and the base map alone was not set to settle again. A switch that ends with nothing to
|
|
125
|
+
* frame settles the base map again. Answered when that settle starts, not when it paints, so an
|
|
126
|
+
* expectation that rises after it is a wait of its own, owed its own settle.
|
|
127
|
+
*/
|
|
128
|
+
awaited;
|
|
129
|
+
/** The configured itinerary's id as last stated, or undefined when it was left out. */
|
|
130
|
+
configuredId;
|
|
131
|
+
/** Whether nobody is watching. A parked engine frames nothing and reports nothing. */
|
|
132
|
+
parked = true;
|
|
133
|
+
disposed = false;
|
|
134
|
+
/**
|
|
135
|
+
* Constructing one holds the configuration and does nothing else: no client is read, framed or
|
|
136
|
+
* constrained. A React binding constructs during a render React is free to throw away, and a
|
|
137
|
+
* constructor with a side effect would leave the discarded copy framing.
|
|
138
|
+
*/
|
|
139
|
+
constructor(config) {
|
|
140
|
+
this.config = config;
|
|
141
|
+
const content = contentOf(config);
|
|
142
|
+
this.awaited = isBaseMap(content) && expectsContent(config);
|
|
143
|
+
this.configuredId = config.configuredItineraryId;
|
|
144
|
+
this.snapshot = { bounds: null, framed: false, ...content };
|
|
145
|
+
}
|
|
146
|
+
/** getSnapshot returns the current answer, by reference and stable between changes. */
|
|
147
|
+
getSnapshot() {
|
|
148
|
+
return this.snapshot;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* subscribe registers a listener for every change of the snapshot, and returns its own
|
|
152
|
+
* unsubscribe, which is idempotent.
|
|
153
|
+
*
|
|
154
|
+
* The first listener resumes the engine and the last one leaving parks it, which is the whole
|
|
155
|
+
* lifecycle a component can express correctly: React tears an effect down and sets it up again
|
|
156
|
+
* with the same object under StrictMode, so a latch here would leave a live surface bound to a
|
|
157
|
+
* dead engine.
|
|
158
|
+
*/
|
|
159
|
+
subscribe(listener) {
|
|
160
|
+
if (this.disposed) {
|
|
161
|
+
return () => void 0;
|
|
162
|
+
}
|
|
163
|
+
const subscription = () => listener();
|
|
164
|
+
this.listeners.add(subscription);
|
|
165
|
+
if (this.parked) {
|
|
166
|
+
this.parked = false;
|
|
167
|
+
this.step();
|
|
168
|
+
}
|
|
169
|
+
return () => {
|
|
170
|
+
if (!this.listeners.delete(subscription) || this.listeners.size > 0 || this.parked) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
this.parked = true;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* configure replaces the configuration, and frames again only when what a framing is decided
|
|
178
|
+
* from changed.
|
|
179
|
+
*
|
|
180
|
+
* A binding calls it after every render, so it compares the inputs a framing reads (the client
|
|
181
|
+
* and the itinerary by identity, the rest by value) and does nothing more when they are
|
|
182
|
+
* unchanged: `fit`, `fitCollection` and `onFramed` are read when they are used, so a fresh
|
|
183
|
+
* closure per render costs nothing. Parked or not, the snapshot answers for the new content,
|
|
184
|
+
* and for a replaced client, before this returns: unframed, under the active id, until its
|
|
185
|
+
* framing settles. Only the framing waits for a subscriber.
|
|
186
|
+
*/
|
|
187
|
+
configure(config) {
|
|
188
|
+
if (this.disposed) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
this.config = config;
|
|
192
|
+
if (config.client !== this.framingClient) {
|
|
193
|
+
this.restart(config.client);
|
|
194
|
+
}
|
|
195
|
+
const content = contentOf(config);
|
|
196
|
+
if (!sameContent(content, this.snapshot)) {
|
|
197
|
+
this.asked = null;
|
|
198
|
+
this.publish({ bounds: null, framed: false, ...content });
|
|
199
|
+
}
|
|
200
|
+
const configuredId = config.configuredItineraryId;
|
|
201
|
+
const switched = configuredId !== void 0 && this.configuredId !== void 0 && configuredId !== this.configuredId;
|
|
202
|
+
this.configuredId = configuredId;
|
|
203
|
+
if (isBaseMap(content) && !this.awaited && (expectsContent(config) || switched)) {
|
|
204
|
+
this.awaited = true;
|
|
205
|
+
this.asked = null;
|
|
206
|
+
}
|
|
207
|
+
this.step();
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* dispose parks the engine and drops every listener, for good: a settle still on its way reports
|
|
211
|
+
* nothing.
|
|
212
|
+
*
|
|
213
|
+
* Idempotent, and every call after it is a no-op rather than an error: an owner torn down
|
|
214
|
+
* mid-load should not have to guard the calls it already queued.
|
|
215
|
+
*/
|
|
216
|
+
dispose() {
|
|
217
|
+
if (this.disposed) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
this.disposed = true;
|
|
221
|
+
this.parked = true;
|
|
222
|
+
this.pendingFit = null;
|
|
223
|
+
this.pendingReveal = null;
|
|
224
|
+
this.listeners.clear();
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* step brings the framing in line with the configuration. It runs in full only when the question
|
|
228
|
+
* changed since the last step, when the active itinerary did, or when work the last one started
|
|
229
|
+
* was dropped while parked.
|
|
230
|
+
*/
|
|
231
|
+
step() {
|
|
232
|
+
if (this.parked || this.disposed) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const { client } = this.config;
|
|
236
|
+
if (client !== this.framingClient) {
|
|
237
|
+
this.restart(client);
|
|
238
|
+
}
|
|
239
|
+
if (client === null) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const question = questionOf(this.config, client);
|
|
243
|
+
if (this.asked !== null && (sameQuestion(this.asked, question) || sameQuestion(this.asked, this.whileFitting(question)))) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
this.asked = question;
|
|
247
|
+
this.frame(client, question);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* whileFitting answers `question` as the fit on its way was asked it, when the canvas has since
|
|
251
|
+
* gone to nothing: neither size the configuration states measures anything (see
|
|
252
|
+
* `measuredCanvas`). A canvas with no area has nothing to frame, so it asks nothing new, the fit
|
|
253
|
+
* on its way stands, and a canvas that comes back at the size that fit was asked for is the
|
|
254
|
+
* question already answered. With no fit on its way, or while either size still measures
|
|
255
|
+
* something, the question is the configuration's own.
|
|
256
|
+
*
|
|
257
|
+
* It is read to compare and never to record: another input that changes while the canvas
|
|
258
|
+
* measures nothing is a question of its own, recorded with the sizes the configuration states.
|
|
259
|
+
* It starts no fit while the page has laid the canvas out at no area (see {@link unlaid}), so
|
|
260
|
+
* the canvas that comes back is the one framed for it.
|
|
261
|
+
*/
|
|
262
|
+
whileFitting(question) {
|
|
263
|
+
const asked = this.asked;
|
|
264
|
+
if (asked === null || this.pendingFit === null || largestOf(this.config.canvasSize, lockSizeOf(this.config)) !== null) {
|
|
265
|
+
return question;
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
...question,
|
|
269
|
+
canvasHeight: asked.canvasHeight,
|
|
270
|
+
canvasWidth: asked.canvasWidth,
|
|
271
|
+
lockHeight: asked.lockHeight,
|
|
272
|
+
lockWidth: asked.lockWidth
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* restart forgets every framing made on the previous client, so a replaced client (or the map
|
|
277
|
+
* arriving) frames and locks from nothing. A settle still on its way for the previous client is
|
|
278
|
+
* dropped.
|
|
279
|
+
*/
|
|
280
|
+
restart(client) {
|
|
281
|
+
this.framingClient = client;
|
|
282
|
+
this.asked = null;
|
|
283
|
+
this.pendingFit = null;
|
|
284
|
+
this.pendingReveal = null;
|
|
285
|
+
this.reported = false;
|
|
286
|
+
this.standing = null;
|
|
287
|
+
this.locked = false;
|
|
288
|
+
this.applied = {};
|
|
289
|
+
const content = contentOf(this.config);
|
|
290
|
+
if (this.snapshot.framed || !sameContent(this.snapshot, content)) {
|
|
291
|
+
this.publish({ bounds: null, framed: false, ...content });
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/** frame runs one framing step for `question` on `client`. */
|
|
295
|
+
frame(client, question) {
|
|
296
|
+
const { itinerary, zoomRange } = this.config;
|
|
297
|
+
const deferred = client.hadInitialViewHash();
|
|
298
|
+
const content = contentOf(this.config);
|
|
299
|
+
const collection = collectionOf(this.config);
|
|
300
|
+
if (isBaseMap(content)) {
|
|
301
|
+
this.pendingFit = null;
|
|
302
|
+
if (this.pendingReveal !== null && !isBaseMap(this.pendingReveal)) {
|
|
303
|
+
this.pendingReveal = null;
|
|
304
|
+
}
|
|
305
|
+
if (expectsContent(this.config)) {
|
|
306
|
+
this.awaitContent(client, deferred);
|
|
307
|
+
} else {
|
|
308
|
+
this.showBaseMap(client);
|
|
309
|
+
}
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
this.awaited = false;
|
|
313
|
+
if (this.pendingReveal !== null && isBaseMap(this.pendingReveal)) {
|
|
314
|
+
this.pendingReveal = null;
|
|
315
|
+
}
|
|
316
|
+
if (this.settledFor(content) || this.pendingReveal !== null && sameContent(this.pendingReveal, content)) {
|
|
317
|
+
this.rangeAgain(client, content);
|
|
318
|
+
this.lockAgain(client, content);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (!deferred && (this.unlaid() || this.resizing())) {
|
|
322
|
+
this.awaitResize(client);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const bounds = itinerary === null ? collection?.bounds ?? null : geo.boundsOf(data.segmentGeometries(data.segmentsForSelection(itinerary, null)));
|
|
326
|
+
const padding = profile.embedFitPadding(
|
|
327
|
+
{
|
|
328
|
+
showAnalysis: question.showAnalysis,
|
|
329
|
+
showCharacteristics: question.showCharacteristics,
|
|
330
|
+
showElevation: question.showElevation
|
|
331
|
+
},
|
|
332
|
+
question.measuredPanelHeight
|
|
333
|
+
);
|
|
334
|
+
const framing = !deferred && bounds !== null ? client.cameraForBounds(bounds, padding, chunkEKZWV6RS_cjs.ITINERARY_FIT_MAX_ZOOM) : null;
|
|
335
|
+
const input = {
|
|
336
|
+
bounds,
|
|
337
|
+
// The larger of the two sizes: under a publisher's own view the lock is sized for a canvas
|
|
338
|
+
// the page has laid out and the renderer has yet to resize to. Under a fit the two agree.
|
|
339
|
+
canvasSize: largestOf(this.config.canvasSize, lockSizeOf(this.config)),
|
|
340
|
+
framing,
|
|
341
|
+
padding,
|
|
342
|
+
// Read before the lock is applied: the camera no fit will move, which the lock must hold.
|
|
343
|
+
view: deferred ? client.getViewport() : null,
|
|
344
|
+
zoomRange
|
|
345
|
+
};
|
|
346
|
+
this.standing = { content, input };
|
|
347
|
+
this.constrain(client, chunkXKHLRIC7_cjs.embedConstraintsFor(input));
|
|
348
|
+
if (deferred) {
|
|
349
|
+
this.revealWithoutFit(client, bounds, content);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
const pending = { bounds, ...content };
|
|
353
|
+
this.pendingFit = pending;
|
|
354
|
+
const fitting = itinerary === null && collection !== null && this.config.fitCollection !== void 0 ? this.config.fitCollection(collection.bounds, padding, chunkEKZWV6RS_cjs.ITINERARY_FIT_MAX_ZOOM) : this.config.fit(padding);
|
|
355
|
+
fitting.then(() => client.waitForRender()).then(
|
|
356
|
+
() => {
|
|
357
|
+
if (this.pendingFit !== pending) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
this.pendingFit = null;
|
|
361
|
+
if (this.parked || this.disposed) {
|
|
362
|
+
this.asked = null;
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (this.resizing()) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
if (this.asked !== question && this.unlaid()) {
|
|
369
|
+
this.asked = null;
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
this.settle(pending);
|
|
373
|
+
},
|
|
374
|
+
() => {
|
|
375
|
+
if (this.pendingFit === pending) {
|
|
376
|
+
this.pendingFit = null;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* resizing reports whether the page has laid the canvas out at a size the renderer has yet to
|
|
383
|
+
* resize to: `lockCanvasSize` measures a canvas `canvasSize` does not state. Never with no
|
|
384
|
+
* `lockCanvasSize`, and never while it measures nothing.
|
|
385
|
+
*/
|
|
386
|
+
resizing() {
|
|
387
|
+
const ahead = chunkXKHLRIC7_cjs.measuredCanvas(lockSizeOf(this.config));
|
|
388
|
+
return ahead !== null && !sameSize(ahead, chunkXKHLRIC7_cjs.measuredCanvas(this.config.canvasSize));
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* unlaid reports whether the page has laid the canvas out at no area: no size the
|
|
392
|
+
* configuration states measures anything, and one of them, `canvasSize` or `lockCanvasSize`,
|
|
393
|
+
* states a layout with no area (see {@link laidOutAtNoArea}). An embed mounted in a frame
|
|
394
|
+
* nobody is shown yet reads so. Never for a host that states no size at all, or one that is
|
|
395
|
+
* not a number: neither is a layout, and the embed is framed as it stands.
|
|
396
|
+
*
|
|
397
|
+
* A renderer gives a container with no area a canvas of its own default size, so a fit asked
|
|
398
|
+
* for now would frame a canvas nobody sees, and its settle would report a view the reader is
|
|
399
|
+
* never shown.
|
|
400
|
+
*/
|
|
401
|
+
unlaid() {
|
|
402
|
+
const { canvasSize } = this.config;
|
|
403
|
+
const lockSize = lockSizeOf(this.config);
|
|
404
|
+
return largestOf(canvasSize, lockSize) === null && (laidOutAtNoArea(canvasSize) || laidOutAtNoArea(lockSize));
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* awaitResize runs the framing step for an itinerary a fit frames while there is no canvas to
|
|
408
|
+
* frame yet: the page has laid it out at no area (see {@link unlaid}), or the renderer has yet
|
|
409
|
+
* to resize to it (see {@link resizing}). It starts no fit, since one asked for now would
|
|
410
|
+
* frame the canvas as it was, and it leaves a fit already on its way in flight. The step that
|
|
411
|
+
* finds a canvas with an area, at a size the two agree on, frames in full, and the fit it
|
|
412
|
+
* starts replaces that one.
|
|
413
|
+
*
|
|
414
|
+
* What stands on the client meanwhile is what {@link awaitContent} leaves there. The pan lock
|
|
415
|
+
* of the last framing, this itinerary's or the outgoing one's, is widened for the size ahead
|
|
416
|
+
* (see {@link lockAgain}), so the renderer resizes inside it. On a client nothing was framed
|
|
417
|
+
* on, the organization's zoom range applies at once: it reads no canvas, so it has nothing to
|
|
418
|
+
* wait for, and a host whose two sizes never agree is not left with a map no range holds.
|
|
419
|
+
*/
|
|
420
|
+
awaitResize(client) {
|
|
421
|
+
if (this.standing === null) {
|
|
422
|
+
this.constrain(client, this.zoomRangeAlone());
|
|
423
|
+
} else {
|
|
424
|
+
this.rangeAgain(client, this.standing.content);
|
|
425
|
+
this.lockAgain(client, this.standing.content);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* awaitContent runs the framing step for an itinerary or a collection that is expected and not
|
|
430
|
+
* framed yet: the itinerary's detail is loading, a content switch cleared the outgoing one
|
|
431
|
+
* first, or the collection's specification has not answered.
|
|
432
|
+
*
|
|
433
|
+
* The constraints of the last itinerary or collection framed on this client stay until the next
|
|
434
|
+
* framing replaces them, the zoom floor that framing lowered included; the pan lock among them
|
|
435
|
+
* still follows a canvas that outgrows it (see {@link lockAgain}). On a client nothing was
|
|
436
|
+
* framed on, the organization's zoom range applies at once.
|
|
437
|
+
*/
|
|
438
|
+
awaitContent(client, deferred) {
|
|
439
|
+
if (this.standing === null) {
|
|
440
|
+
this.constrain(client, this.zoomRangeAlone());
|
|
441
|
+
} else {
|
|
442
|
+
this.rangeAgain(client, this.standing.content);
|
|
443
|
+
this.lockAgain(client, this.standing.content);
|
|
444
|
+
}
|
|
445
|
+
if (deferred && !this.reported) {
|
|
446
|
+
this.revealWithoutFit(client, null, baseMapContent);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* showBaseMap runs the framing step for the base map alone: no itinerary or collection is
|
|
451
|
+
* framed and none is expected. The organization's zoom range applies as it is, the pan lock an
|
|
452
|
+
* itinerary or a collection left standing is released (see {@link constrain}), and the view
|
|
453
|
+
* settles on the map's next render.
|
|
454
|
+
*/
|
|
455
|
+
showBaseMap(client) {
|
|
456
|
+
this.standing = null;
|
|
457
|
+
this.constrain(client, this.zoomRangeAlone());
|
|
458
|
+
if (this.awaited) {
|
|
459
|
+
this.awaited = false;
|
|
460
|
+
if (this.snapshot.framed) {
|
|
461
|
+
this.publish({ bounds: null, framed: false, ...baseMapContent });
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
this.revealWithoutFit(client, null, baseMapContent);
|
|
465
|
+
}
|
|
466
|
+
/** zoomRangeAlone decides the constraints with no itinerary to lock to: the zoom range alone. */
|
|
467
|
+
zoomRangeAlone() {
|
|
468
|
+
return chunkXKHLRIC7_cjs.embedConstraintsFor({
|
|
469
|
+
bounds: null,
|
|
470
|
+
canvasSize: null,
|
|
471
|
+
framing: null,
|
|
472
|
+
padding: 0,
|
|
473
|
+
zoomRange: this.config.zoomRange
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* rangeAgain applies the configuration's zoom range over the framing of `content` when it is not
|
|
478
|
+
* the range that framing was decided from: the same route, camera, canvas and padding, under
|
|
479
|
+
* the range as it is stated now. The zoom range alone, so the pan lock stays as it is and no
|
|
480
|
+
* camera is moved by a fit.
|
|
481
|
+
*
|
|
482
|
+
* The floor is the one a framing under this range would have set, lowered to the zoom the fit
|
|
483
|
+
* landed on, so a range that arrives late leaves the embed where it would have opened. A range
|
|
484
|
+
* that does not state both ends decides no clamp, so the one on the map is released
|
|
485
|
+
* (see {@link rangeRelease}).
|
|
486
|
+
*/
|
|
487
|
+
rangeAgain(client, content) {
|
|
488
|
+
const standing = this.standing;
|
|
489
|
+
const { zoomRange } = this.config;
|
|
490
|
+
if (standing === null || !sameContent(standing.content, content) || sameRange(standing.input.zoomRange, zoomRange)) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
const input = { ...standing.input, zoomRange };
|
|
494
|
+
this.standing = { content, input };
|
|
495
|
+
const { maxZoom, minZoom } = chunkXKHLRIC7_cjs.embedConstraintsFor(input);
|
|
496
|
+
this.apply(
|
|
497
|
+
client,
|
|
498
|
+
maxZoom !== void 0 && minZoom !== void 0 ? { maxZoom, minZoom } : this.rangeRelease()
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* rangeRelease is the constraints that release the zoom range this engine wrote to the client:
|
|
503
|
+
* a null for each end, which hands the map back its own window. Nothing while no range of the
|
|
504
|
+
* engine's stands there, so a map no range was written to is told nothing.
|
|
505
|
+
*/
|
|
506
|
+
rangeRelease() {
|
|
507
|
+
const { maxZoom, minZoom } = this.applied;
|
|
508
|
+
return typeof maxZoom === "number" || typeof minZoom === "number" ? { maxZoom: null, minZoom: null } : {};
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* lockAgain widens the pan lock of the framing of `content` when the canvas has outgrown the one
|
|
512
|
+
* it was sized for: the same route, camera and padding, on a canvas as wide as the widest and as
|
|
513
|
+
* tall as the tallest it has been handed since the framing, as `canvasSize` or as
|
|
514
|
+
* `lockCanvasSize`. The lock alone, so the zoom range stays as the framing set it, and no
|
|
515
|
+
* camera is moved.
|
|
516
|
+
*
|
|
517
|
+
* The lock only grows. The renderer keeps its canvas inside the lock at the size the canvas has
|
|
518
|
+
* when the lock is applied, and a new size is handed over before the renderer resizes: a lock
|
|
519
|
+
* sized for a smaller canvas would be narrower than the one the renderer still holds. A canvas
|
|
520
|
+
* that reads unmeasured changes nothing either.
|
|
521
|
+
*/
|
|
522
|
+
lockAgain(client, content) {
|
|
523
|
+
const standing = this.standing;
|
|
524
|
+
if (standing === null || !sameContent(standing.content, content) || standing.input.bounds === null) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
const sizedFor = chunkXKHLRIC7_cjs.measuredCanvas(standing.input.canvasSize);
|
|
528
|
+
const largest = largestOf(sizedFor, largestOf(this.config.canvasSize, lockSizeOf(this.config)));
|
|
529
|
+
if (largest === null || sameSize(sizedFor, largest)) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
const input = { ...standing.input, canvasSize: largest };
|
|
533
|
+
this.standing = { content, input };
|
|
534
|
+
const { maxBounds } = chunkXKHLRIC7_cjs.embedConstraintsFor(input);
|
|
535
|
+
if (maxBounds !== void 0) {
|
|
536
|
+
this.apply(client, { maxBounds });
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* constrain applies one framing step's constraints, in one call, and only when they decide
|
|
541
|
+
* something.
|
|
542
|
+
*
|
|
543
|
+
* Constraints that decide no pan lock release the one standing, with a null `maxBounds`: there
|
|
544
|
+
* is no route left to hold the camera to, whether the embed is the base map alone or its next
|
|
545
|
+
* itinerary has no extent. Constraints that decide no zoom range release the one standing the
|
|
546
|
+
* same way (see {@link rangeRelease}): the configuration states none any more.
|
|
547
|
+
*/
|
|
548
|
+
constrain(client, decided) {
|
|
549
|
+
const ranged = decided.maxZoom === void 0 ? { ...decided, ...this.rangeRelease() } : decided;
|
|
550
|
+
const constraints = ranged.maxBounds === void 0 && this.locked ? { ...ranged, maxBounds: null } : ranged;
|
|
551
|
+
this.apply(client, constraints);
|
|
552
|
+
if (constraints.maxBounds !== void 0) {
|
|
553
|
+
this.locked = constraints.maxBounds !== null;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* apply writes `constraints` to the client, unless they decide nothing or every member they
|
|
558
|
+
* state already stands there as stated. A resize under the zoom range alone, and a framing
|
|
559
|
+
* asked again for the inputs it had, decide what the map already holds, and writing it again
|
|
560
|
+
* would have the renderer enforce an unchanged range and lock once more.
|
|
561
|
+
*
|
|
562
|
+
* The set is written whole when any member is news, so a caller's one call stays one call.
|
|
563
|
+
*/
|
|
564
|
+
apply(client, constraints) {
|
|
565
|
+
if (isEmpty(constraints) || standsAs(constraints, this.applied)) {
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
client.setConstraints(constraints);
|
|
569
|
+
this.applied = { ...this.applied, ...constraints };
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* revealWithoutFit settles the view on the map's next render, for a view no fit will move: an
|
|
573
|
+
* embed of the base map alone, an itinerary that failed to load, or a publisher's own view.
|
|
574
|
+
*
|
|
575
|
+
* Once for what it answers, `content`: a view already settled for it, or settling, is left
|
|
576
|
+
* alone. A settle on its way for anything else is replaced, since both would wait on the same
|
|
577
|
+
* render and only the active one is worth reporting.
|
|
578
|
+
*/
|
|
579
|
+
revealWithoutFit(client, bounds, content) {
|
|
580
|
+
if (this.settledFor(content) || this.pendingReveal !== null && sameContent(this.pendingReveal, content)) {
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
const pending = { bounds, ...content };
|
|
584
|
+
this.pendingReveal = pending;
|
|
585
|
+
client.waitForRender().then(
|
|
586
|
+
() => {
|
|
587
|
+
if (this.pendingReveal !== pending) {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
this.pendingReveal = null;
|
|
591
|
+
if (this.parked || this.disposed) {
|
|
592
|
+
this.asked = null;
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
this.settle(pending);
|
|
596
|
+
},
|
|
597
|
+
() => {
|
|
598
|
+
if (this.pendingReveal === pending) {
|
|
599
|
+
this.pendingReveal = null;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* settledFor reports whether the initial view of `content` has settled on the current client.
|
|
606
|
+
* The snapshot is the one record of it: it answers for the active content and reads unframed
|
|
607
|
+
* from a content switch, or a replaced client, until that settle.
|
|
608
|
+
*/
|
|
609
|
+
settledFor(content) {
|
|
610
|
+
return this.snapshot.framed && sameContent(this.snapshot, content);
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* settle reports one settle: through the snapshot, then to `onFramed`. A settle on its way for
|
|
614
|
+
* anything but the active content is dropped before it lands (see {@link frame}), so the
|
|
615
|
+
* snapshot is written only for the content it answers for, and never goes back to a content
|
|
616
|
+
* the reader has left.
|
|
617
|
+
*/
|
|
618
|
+
settle(pending) {
|
|
619
|
+
this.reported = true;
|
|
620
|
+
if (sameContent(pending, contentOf(this.config))) {
|
|
621
|
+
this.publish({
|
|
622
|
+
bounds: pending.bounds,
|
|
623
|
+
collectionId: pending.collectionId,
|
|
624
|
+
framed: true,
|
|
625
|
+
itineraryId: pending.itineraryId
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
try {
|
|
629
|
+
this.config.onFramed?.(pending.bounds);
|
|
630
|
+
} catch (fault) {
|
|
631
|
+
chunkPACIO4NS_cjs.surfaceFault(fault);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
/** publish shows `snapshot` and tells every listener. */
|
|
635
|
+
publish(snapshot) {
|
|
636
|
+
this.snapshot = snapshot;
|
|
637
|
+
chunkPACIO4NS_cjs.notifyListeners(this.listeners);
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
var MAX_TIMER_MS = 2 ** 31 - 1;
|
|
641
|
+
|
|
642
|
+
// src/embed/engines/embedReady.ts
|
|
643
|
+
var coveredSnapshot = { covered: true };
|
|
644
|
+
var revealedSnapshot = { covered: false };
|
|
645
|
+
var timeoutFrom = (timeoutMs) => {
|
|
646
|
+
if (timeoutMs === void 0) {
|
|
647
|
+
return chunkXKHLRIC7_cjs.EMBED_COVER_MAX_MS;
|
|
648
|
+
}
|
|
649
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 0 || timeoutMs > MAX_TIMER_MS) {
|
|
650
|
+
throw new errors.MountayaElementsError(
|
|
651
|
+
`EmbedReadyEngine: timeoutMs is ${String(timeoutMs)}; pass a number of milliseconds from 0 to ${MAX_TIMER_MS}, or omit it for ${chunkXKHLRIC7_cjs.EMBED_COVER_MAX_MS}.`
|
|
652
|
+
);
|
|
653
|
+
}
|
|
654
|
+
return timeoutMs;
|
|
655
|
+
};
|
|
656
|
+
var EmbedReadyEngine = class {
|
|
657
|
+
config;
|
|
658
|
+
clock;
|
|
659
|
+
timeoutMs;
|
|
660
|
+
snapshot = coveredSnapshot;
|
|
661
|
+
listeners = /* @__PURE__ */ new Set();
|
|
662
|
+
/** The deadline waiting on the clock, or null while none is. */
|
|
663
|
+
deadline = null;
|
|
664
|
+
/** Whether nobody is watching. A parked engine arms nothing and posts nothing. */
|
|
665
|
+
parked = true;
|
|
666
|
+
disposed = false;
|
|
667
|
+
/**
|
|
668
|
+
* Constructing one holds the options and does nothing else: no deadline is armed and nothing is
|
|
669
|
+
* posted. A React binding constructs during a render React is free to throw away, and a
|
|
670
|
+
* constructor with a side effect would leave the discarded copy waiting.
|
|
671
|
+
*
|
|
672
|
+
* @throws {MountayaElementsError} When `timeoutMs` is not a finite number from 0 to
|
|
673
|
+
* 2,147,483,647.
|
|
674
|
+
*/
|
|
675
|
+
constructor(options) {
|
|
676
|
+
const { clock, timeoutMs, ...config } = options;
|
|
677
|
+
this.clock = clock;
|
|
678
|
+
this.timeoutMs = timeoutFrom(timeoutMs);
|
|
679
|
+
this.config = config;
|
|
680
|
+
}
|
|
681
|
+
/** getSnapshot returns the current answer, by reference and stable between changes. */
|
|
682
|
+
getSnapshot() {
|
|
683
|
+
return this.snapshot;
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* subscribe registers a listener for every change of the snapshot, and returns its own
|
|
687
|
+
* unsubscribe, which is idempotent.
|
|
688
|
+
*
|
|
689
|
+
* The first listener resumes the engine and the last one leaving parks it, which is the whole
|
|
690
|
+
* lifecycle a component can express correctly: React tears an effect down and sets it up again
|
|
691
|
+
* with the same object under StrictMode, so a latch here would leave a live surface bound to a
|
|
692
|
+
* dead engine. A binding hands its framework a STABLE `subscribe`; a fresh closure per render
|
|
693
|
+
* parks and resumes on every render.
|
|
694
|
+
*/
|
|
695
|
+
subscribe(listener) {
|
|
696
|
+
if (this.disposed) {
|
|
697
|
+
return () => void 0;
|
|
698
|
+
}
|
|
699
|
+
const subscription = () => listener();
|
|
700
|
+
this.listeners.add(subscription);
|
|
701
|
+
if (this.parked) {
|
|
702
|
+
this.parked = false;
|
|
703
|
+
this.arm();
|
|
704
|
+
}
|
|
705
|
+
return () => {
|
|
706
|
+
if (!this.listeners.delete(subscription) || this.listeners.size > 0 || this.parked) {
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
this.parked = true;
|
|
710
|
+
this.disarm();
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* configure replaces the configuration the next ready event is assembled from. It moves nothing:
|
|
715
|
+
* the deadline stays where it is and a posted event stays posted, so a binding calls it after
|
|
716
|
+
* every render at the cost of an assignment.
|
|
717
|
+
*/
|
|
718
|
+
configure(config) {
|
|
719
|
+
if (!this.disposed) {
|
|
720
|
+
this.config = config;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* settle reports that the initial view has painted, framed on `bounds` (`[west, south, east,
|
|
725
|
+
* north]`, the itinerary's or the collection's, or null when neither frames it): the cover lifts
|
|
726
|
+
* and a ready event is posted.
|
|
727
|
+
* Called on the cold load and again after every content switch, and each call posts. A call
|
|
728
|
+
* while parked, or after {@link EmbedReadyEngine.dispose}, does nothing.
|
|
729
|
+
*/
|
|
730
|
+
settle(bounds) {
|
|
731
|
+
if (this.parked || this.disposed) {
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
const { configuredItineraryId, itineraryFailed } = this.config;
|
|
735
|
+
this.disarm();
|
|
736
|
+
this.reveal();
|
|
737
|
+
this.post(bounds, chunkXKHLRIC7_cjs.resolveFramedError(configuredItineraryId, itineraryFailed));
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* dispose drops the deadline and every listener, for good.
|
|
741
|
+
*
|
|
742
|
+
* Idempotent, and every call after it is a no-op rather than an error: an owner torn down
|
|
743
|
+
* mid-load should not have to guard the calls it already queued.
|
|
744
|
+
*/
|
|
745
|
+
dispose() {
|
|
746
|
+
if (this.disposed) {
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
this.disposed = true;
|
|
750
|
+
this.parked = true;
|
|
751
|
+
this.disarm();
|
|
752
|
+
this.listeners.clear();
|
|
753
|
+
}
|
|
754
|
+
/** arm waits out the deadline while the cover is up. */
|
|
755
|
+
arm() {
|
|
756
|
+
if (!this.snapshot.covered || this.deadline !== null) {
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
const deadline = { cancel: () => void 0 };
|
|
760
|
+
this.deadline = deadline;
|
|
761
|
+
deadline.cancel = this.clock.after(this.timeoutMs, () => {
|
|
762
|
+
if (this.deadline !== deadline) {
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
this.deadline = null;
|
|
766
|
+
this.expire();
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
/** disarm drops the deadline, if one is armed. */
|
|
770
|
+
disarm() {
|
|
771
|
+
const deadline = this.deadline;
|
|
772
|
+
this.deadline = null;
|
|
773
|
+
deadline?.cancel();
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* expire lifts the cover at the deadline and says `"timeout"`. It runs only for the deadline the
|
|
777
|
+
* engine still holds, so the engine is watched and nothing has settled: a settle, a park and a
|
|
778
|
+
* dispose each drop the deadline, and a lifted cover arms no other.
|
|
779
|
+
*/
|
|
780
|
+
expire() {
|
|
781
|
+
this.reveal();
|
|
782
|
+
this.post(null, "timeout");
|
|
783
|
+
}
|
|
784
|
+
/** post hands one ready event to the host, assembled from the configuration as it stands. */
|
|
785
|
+
post(bounds, error) {
|
|
786
|
+
const { activeItineraryId, activeTerrain, configTerrain, onReady } = this.config;
|
|
787
|
+
const payload = chunkXKHLRIC7_cjs.buildReadyPayload({
|
|
788
|
+
activeItineraryId,
|
|
789
|
+
activeTerrain,
|
|
790
|
+
bounds,
|
|
791
|
+
configTerrain,
|
|
792
|
+
error
|
|
793
|
+
});
|
|
794
|
+
try {
|
|
795
|
+
onReady?.(payload);
|
|
796
|
+
} catch (fault) {
|
|
797
|
+
chunkPACIO4NS_cjs.surfaceFault(fault);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
/** reveal lifts the cover, and tells every listener when that is news. */
|
|
801
|
+
reveal() {
|
|
802
|
+
if (this.snapshot === revealedSnapshot) {
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
this.snapshot = revealedSnapshot;
|
|
806
|
+
chunkPACIO4NS_cjs.notifyListeners(this.listeners);
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
var FRAMING_PAGE_SESSION_TIMEOUT_MS = 1e4;
|
|
810
|
+
var timeoutFrom2 = (timeoutMs) => {
|
|
811
|
+
if (timeoutMs === void 0) {
|
|
812
|
+
return FRAMING_PAGE_SESSION_TIMEOUT_MS;
|
|
813
|
+
}
|
|
814
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > MAX_TIMER_MS) {
|
|
815
|
+
throw new errors.MountayaElementsError(
|
|
816
|
+
`askFramingPageForSession: timeoutMs is ${String(timeoutMs)}; pass a number of milliseconds from 1 to ${MAX_TIMER_MS}, or omit it for ${FRAMING_PAGE_SESSION_TIMEOUT_MS}.`
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
return timeoutMs;
|
|
820
|
+
};
|
|
821
|
+
var askFramingPageForSession = (options) => {
|
|
822
|
+
const timeoutMs = timeoutFrom2(options.timeoutMs);
|
|
823
|
+
const { clock, embed } = options;
|
|
824
|
+
return new Promise((resolve, reject) => {
|
|
825
|
+
if (Object.is(embed.parent, embed)) {
|
|
826
|
+
reject(
|
|
827
|
+
new errors.MountayaElementsError(
|
|
828
|
+
"askFramingPageForSession: the embed is not framed, so no page can hand it a session token."
|
|
829
|
+
)
|
|
830
|
+
);
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
let cancel = () => {
|
|
834
|
+
};
|
|
835
|
+
const listener = (event) => {
|
|
836
|
+
if (event.source !== embed.parent) {
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
const parsed = chunkIDBXFBLG_cjs.setSessionTokenMessageSchema.safeParse(event.data);
|
|
840
|
+
if (!parsed.success) {
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
cancel();
|
|
844
|
+
embed.removeEventListener("message", listener);
|
|
845
|
+
resolve({
|
|
846
|
+
expires_at: new Date(parsed.data.expiresAt),
|
|
847
|
+
token: parsed.data.token,
|
|
848
|
+
user_id: null
|
|
849
|
+
});
|
|
850
|
+
};
|
|
851
|
+
embed.addEventListener("message", listener);
|
|
852
|
+
cancel = clock.after(timeoutMs, () => {
|
|
853
|
+
embed.removeEventListener("message", listener);
|
|
854
|
+
reject(
|
|
855
|
+
new errors.MountayaElementsError(
|
|
856
|
+
`askFramingPageForSession: the framing page answered no session token within ${timeoutMs} ms.`
|
|
857
|
+
)
|
|
858
|
+
);
|
|
859
|
+
});
|
|
860
|
+
embed.parent.postMessage({ type: chunkIDBXFBLG_cjs.REQUEST_SESSION_TOKEN_MESSAGE }, "*");
|
|
861
|
+
});
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
// src/itinerary/handlers/restItineraryPace.ts
|
|
865
|
+
var fetchItineraryPace = async (client, itineraryId, { signal, speedKmh, surface }) => {
|
|
866
|
+
const params = {
|
|
867
|
+
itinerary_id: itineraryId,
|
|
868
|
+
// The absent option is omitted rather than sent empty, the shape the export
|
|
869
|
+
// uses: the server reads its own default for an omitted parameter.
|
|
870
|
+
query: {
|
|
871
|
+
speed: speedKmh,
|
|
872
|
+
...surface === void 0 ? {} : { surface }
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
const { data } = await (signal === void 0 ? client.studio.itineraries.getItineraryPace(params) : client.studio.itineraries.getItineraryPace(params, { signal }));
|
|
876
|
+
return {
|
|
877
|
+
bySegmentId: new Map(data.segments.map((segment) => [segment.id, segment])),
|
|
878
|
+
durationSeconds: data.duration
|
|
879
|
+
};
|
|
880
|
+
};
|
|
881
|
+
|
|
882
|
+
// src/itinerary/engines/itineraryPace.ts
|
|
883
|
+
var PACE_DEBOUNCE_MS = 250;
|
|
884
|
+
var PACE_ANSWER_CAPACITY = 32;
|
|
885
|
+
var isRateStep = (shown, next) => shown !== null && shown.client === next.client && shown.itineraryId === next.itineraryId && shown.revision === next.revision && shown.surface === next.surface;
|
|
886
|
+
var revisionKey = (revision) => `${typeof revision}\0${revision ?? ""}`;
|
|
887
|
+
var paceKey = (itineraryId, speedKmh, surface, revision) => [itineraryId, speedKmh, surface ?? "", revision].join("\0");
|
|
888
|
+
var debounceFrom = (debounceMs) => {
|
|
889
|
+
if (debounceMs === void 0) {
|
|
890
|
+
return PACE_DEBOUNCE_MS;
|
|
891
|
+
}
|
|
892
|
+
if (!Number.isFinite(debounceMs) || debounceMs < 0 || debounceMs > MAX_TIMER_MS) {
|
|
893
|
+
throw new errors.MountayaElementsError(
|
|
894
|
+
`ItineraryPaceEngine: debounceMs is ${String(debounceMs)}; pass a number of milliseconds from 0 to ${MAX_TIMER_MS}, or omit it for ${PACE_DEBOUNCE_MS}.`
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
return debounceMs;
|
|
898
|
+
};
|
|
899
|
+
var ItineraryPaceEngine = class {
|
|
900
|
+
config;
|
|
901
|
+
debounceMs;
|
|
902
|
+
snapshot = null;
|
|
903
|
+
/** The question the snapshot answers, or null while it is null. */
|
|
904
|
+
shown = null;
|
|
905
|
+
listeners = /* @__PURE__ */ new Set();
|
|
906
|
+
/**
|
|
907
|
+
* The answers the current client has given and the engine keeps, by their {@link paceKey}, in
|
|
908
|
+
* the order they were last read: the first is the least recently read.
|
|
909
|
+
*/
|
|
910
|
+
answers = /* @__PURE__ */ new Map();
|
|
911
|
+
/** The re-time on its way, or null. */
|
|
912
|
+
inFlight = null;
|
|
913
|
+
timer = null;
|
|
914
|
+
/** Whether nobody is watching. A parked engine asks for nothing. */
|
|
915
|
+
parked = true;
|
|
916
|
+
disposed = false;
|
|
917
|
+
/**
|
|
918
|
+
* Constructing one holds the options and does nothing else: no timer and no request. A React
|
|
919
|
+
* binding constructs during a render React is free to throw away, and a constructor with a
|
|
920
|
+
* side effect would leave the discarded copy asking.
|
|
921
|
+
*
|
|
922
|
+
* @throws {MountayaElementsError} When `debounceMs` is not a finite number from 0 to
|
|
923
|
+
* 2,147,483,647.
|
|
924
|
+
*/
|
|
925
|
+
constructor(options) {
|
|
926
|
+
const { debounceMs, ...config } = options;
|
|
927
|
+
this.debounceMs = debounceFrom(debounceMs);
|
|
928
|
+
this.config = config;
|
|
929
|
+
}
|
|
930
|
+
/** getSnapshot returns the current answer, by reference and stable between changes. */
|
|
931
|
+
getSnapshot() {
|
|
932
|
+
return this.snapshot;
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* subscribe registers a listener for every change of the snapshot, and returns its own
|
|
936
|
+
* unsubscribe.
|
|
937
|
+
*
|
|
938
|
+
* The first listener resumes the engine and the last one leaving parks it, which is the whole
|
|
939
|
+
* lifecycle a component can express correctly: React tears an effect down and sets it up again
|
|
940
|
+
* with the same object under StrictMode, so a latch here would leave a live surface bound to a
|
|
941
|
+
* dead engine. A binding hands its framework a STABLE `subscribe`; a fresh closure per render
|
|
942
|
+
* parks and resumes on every render.
|
|
943
|
+
*
|
|
944
|
+
* After {@link ItineraryPaceEngine.dispose} the listener is not held and is never told, and
|
|
945
|
+
* the function returned does nothing.
|
|
946
|
+
*/
|
|
947
|
+
subscribe(listener) {
|
|
948
|
+
if (this.disposed) {
|
|
949
|
+
return () => void 0;
|
|
950
|
+
}
|
|
951
|
+
this.listeners.add(listener);
|
|
952
|
+
if (this.parked) {
|
|
953
|
+
this.parked = false;
|
|
954
|
+
this.schedule();
|
|
955
|
+
}
|
|
956
|
+
return () => {
|
|
957
|
+
this.listeners.delete(listener);
|
|
958
|
+
if (this.listeners.size > 0 || this.parked) {
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
this.parked = true;
|
|
962
|
+
this.cancelPending();
|
|
963
|
+
this.abandon(null);
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* configure replaces the configuration, and asks again only when the question changed.
|
|
968
|
+
*
|
|
969
|
+
* A binding calls it on every render, so it compares the question the configuration asks (the
|
|
970
|
+
* itinerary, its revision, the rate, the surface, and whether there is a client at all) and
|
|
971
|
+
* does nothing when that is unchanged and the client is the same object. A client replaced by
|
|
972
|
+
* another is a new question even when the rest is not: the credential it carries decides which
|
|
973
|
+
* copy a re-time without a surface answers for, so the answers the previous client gave are
|
|
974
|
+
* dropped, its request in flight is aborted, and the question is asked again through the new
|
|
975
|
+
* client. Another {@link ItineraryPaceConfig.revision} of the same itinerary is a new question
|
|
976
|
+
* too: the answers kept for that itinerary are dropped, its re-time in flight is aborted, and
|
|
977
|
+
* the snapshot is null until the answer lands.
|
|
978
|
+
*
|
|
979
|
+
* Parked or not, the snapshot is settled for the new configuration before this returns: the
|
|
980
|
+
* answer kept for it, the previous one across a rate step, or null. Only the request waits for a
|
|
981
|
+
* subscriber.
|
|
982
|
+
*
|
|
983
|
+
* After {@link ItineraryPaceEngine.dispose} it does nothing: the configuration is not taken and
|
|
984
|
+
* the snapshot stays the one the engine showed.
|
|
985
|
+
*/
|
|
986
|
+
configure(config) {
|
|
987
|
+
if (this.disposed) {
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
const before = this.request()?.key ?? null;
|
|
991
|
+
const replacesClient = config.client !== this.config.client;
|
|
992
|
+
this.config = config;
|
|
993
|
+
if (replacesClient) {
|
|
994
|
+
this.answers.clear();
|
|
995
|
+
this.abandon(null);
|
|
996
|
+
}
|
|
997
|
+
const request = this.request();
|
|
998
|
+
if (request !== null) {
|
|
999
|
+
this.forgetOtherRevisions(request);
|
|
1000
|
+
}
|
|
1001
|
+
if (replacesClient || (request?.key ?? null) !== before) {
|
|
1002
|
+
this.schedule();
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* dispose drops the pending debounce and every listener and aborts the re-time in flight, for
|
|
1007
|
+
* good.
|
|
1008
|
+
*
|
|
1009
|
+
* It changes nothing a reader holds: {@link ItineraryPaceEngine.getSnapshot} goes on returning
|
|
1010
|
+
* the snapshot the engine showed when it was disposed, the answer included, and no listener is
|
|
1011
|
+
* told. Idempotent, and every call after it is a no-op rather than an error: an owner torn
|
|
1012
|
+
* down mid-step should not have to guard the calls it already queued.
|
|
1013
|
+
*/
|
|
1014
|
+
dispose() {
|
|
1015
|
+
if (this.disposed) {
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
this.disposed = true;
|
|
1019
|
+
this.parked = true;
|
|
1020
|
+
this.cancelPending();
|
|
1021
|
+
this.abandon(null);
|
|
1022
|
+
this.listeners.clear();
|
|
1023
|
+
}
|
|
1024
|
+
/** request resolves the current configuration into the re-time it asks for, or null. */
|
|
1025
|
+
request() {
|
|
1026
|
+
const { client, itineraryId, speedKmh, surface } = this.config;
|
|
1027
|
+
if (client === void 0 || !itineraryId || speedKmh === null) {
|
|
1028
|
+
return null;
|
|
1029
|
+
}
|
|
1030
|
+
const revision = revisionKey(this.config.revision);
|
|
1031
|
+
return {
|
|
1032
|
+
client,
|
|
1033
|
+
itineraryId,
|
|
1034
|
+
key: paceKey(itineraryId, speedKmh, surface, revision),
|
|
1035
|
+
revision,
|
|
1036
|
+
speedKmh,
|
|
1037
|
+
surface
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
/** readKept answers the answer kept for `key`, which becomes the most recently read. */
|
|
1041
|
+
readKept(key) {
|
|
1042
|
+
const kept = this.answers.get(key);
|
|
1043
|
+
if (kept !== void 0) {
|
|
1044
|
+
this.answers.delete(key);
|
|
1045
|
+
this.answers.set(key, kept);
|
|
1046
|
+
}
|
|
1047
|
+
return kept;
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* keep holds an answer as the most recently read, and drops the least recently read beyond
|
|
1051
|
+
* {@link PACE_ANSWER_CAPACITY}.
|
|
1052
|
+
*/
|
|
1053
|
+
keep(key, kept) {
|
|
1054
|
+
this.answers.delete(key);
|
|
1055
|
+
this.answers.set(key, kept);
|
|
1056
|
+
for (const oldest of this.answers.keys()) {
|
|
1057
|
+
if (this.answers.size <= PACE_ANSWER_CAPACITY) {
|
|
1058
|
+
break;
|
|
1059
|
+
}
|
|
1060
|
+
this.answers.delete(oldest);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* forgetOtherRevisions drops every answer kept for the itinerary `request` names under another
|
|
1065
|
+
* revision than the one it names, two revisions being one as {@link revisionKey} writes them.
|
|
1066
|
+
* Another itinerary's answers stay.
|
|
1067
|
+
*/
|
|
1068
|
+
forgetOtherRevisions(request) {
|
|
1069
|
+
for (const [key, kept] of this.answers) {
|
|
1070
|
+
if (kept.itineraryId === request.itineraryId && kept.revision !== request.revision) {
|
|
1071
|
+
this.answers.delete(key);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* schedule answers the current configuration: at once when it can, after the debounce
|
|
1077
|
+
* otherwise. The re-time in flight for any other question is aborted first, and the previous
|
|
1078
|
+
* answer stays on screen only across a rate step (see {@link isRateStep}). A parked engine
|
|
1079
|
+
* answers as far as it can without asking, and its first subscriber asks the rest.
|
|
1080
|
+
*/
|
|
1081
|
+
schedule() {
|
|
1082
|
+
this.cancelPending();
|
|
1083
|
+
if (this.disposed) {
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
const request = this.request();
|
|
1087
|
+
this.abandon(request?.key ?? null);
|
|
1088
|
+
if (request === null) {
|
|
1089
|
+
this.commit(null, null);
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
const kept = this.readKept(request.key);
|
|
1093
|
+
if (kept !== void 0) {
|
|
1094
|
+
this.commit(kept.answer, request);
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
if (!isRateStep(this.shown, request)) {
|
|
1098
|
+
this.commit(null, null);
|
|
1099
|
+
}
|
|
1100
|
+
if (this.parked) {
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
if (this.debounceMs === 0) {
|
|
1104
|
+
this.ask(request);
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
this.timer = setTimeout(() => {
|
|
1108
|
+
this.timer = null;
|
|
1109
|
+
const current = this.request();
|
|
1110
|
+
if (current !== null) {
|
|
1111
|
+
this.ask(current);
|
|
1112
|
+
}
|
|
1113
|
+
}, this.debounceMs);
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* ask resolves one request, unless the same question is already on its way, in which case the
|
|
1117
|
+
* answer that lands serves it.
|
|
1118
|
+
*/
|
|
1119
|
+
ask(request) {
|
|
1120
|
+
const kept = this.readKept(request.key);
|
|
1121
|
+
if (kept !== void 0) {
|
|
1122
|
+
this.commit(kept.answer, request);
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
if (this.inFlight?.key === request.key) {
|
|
1126
|
+
return;
|
|
1127
|
+
}
|
|
1128
|
+
const inFlight = { controller: new AbortController(), key: request.key };
|
|
1129
|
+
this.inFlight = inFlight;
|
|
1130
|
+
fetchItineraryPace(request.client, request.itineraryId, {
|
|
1131
|
+
signal: inFlight.controller.signal,
|
|
1132
|
+
speedKmh: request.speedKmh,
|
|
1133
|
+
surface: request.surface
|
|
1134
|
+
}).then(
|
|
1135
|
+
(answer) => {
|
|
1136
|
+
if (!this.settle(inFlight)) {
|
|
1137
|
+
return;
|
|
1138
|
+
}
|
|
1139
|
+
this.keep(request.key, {
|
|
1140
|
+
answer,
|
|
1141
|
+
itineraryId: request.itineraryId,
|
|
1142
|
+
revision: request.revision
|
|
1143
|
+
});
|
|
1144
|
+
if (this.isLive(request.key)) {
|
|
1145
|
+
this.commit(answer, request);
|
|
1146
|
+
}
|
|
1147
|
+
},
|
|
1148
|
+
() => {
|
|
1149
|
+
if (this.settle(inFlight) && this.isLive(request.key)) {
|
|
1150
|
+
this.commit(null, null);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
);
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* settle retires a re-time that has landed, and reports whether its answer still counts: false
|
|
1157
|
+
* for one aborted before it landed, whatever its transport delivered.
|
|
1158
|
+
*/
|
|
1159
|
+
settle(inFlight) {
|
|
1160
|
+
if (this.inFlight === inFlight) {
|
|
1161
|
+
this.inFlight = null;
|
|
1162
|
+
}
|
|
1163
|
+
return !inFlight.controller.signal.aborted;
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* abandon aborts the re-time in flight unless it asks `keep`, the key the configuration asks
|
|
1167
|
+
* for now; null keeps none.
|
|
1168
|
+
*/
|
|
1169
|
+
abandon(keep) {
|
|
1170
|
+
if (this.inFlight === null || this.inFlight.key === keep) {
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
this.inFlight.controller.abort();
|
|
1174
|
+
this.inFlight = null;
|
|
1175
|
+
}
|
|
1176
|
+
/** isLive reports whether an answer for `key` is still the one the snapshot should show. */
|
|
1177
|
+
isLive(key) {
|
|
1178
|
+
return !this.parked && !this.disposed && this.request()?.key === key;
|
|
1179
|
+
}
|
|
1180
|
+
cancelPending() {
|
|
1181
|
+
if (this.timer !== null) {
|
|
1182
|
+
clearTimeout(this.timer);
|
|
1183
|
+
this.timer = null;
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
/** commit shows `snapshot`, the answer to `answers`, and tells every listener when it changed. */
|
|
1187
|
+
commit(snapshot, answers) {
|
|
1188
|
+
if (this.disposed) {
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
1191
|
+
this.shown = snapshot === null ? null : answers;
|
|
1192
|
+
if (snapshot === this.snapshot) {
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
1195
|
+
this.snapshot = snapshot;
|
|
1196
|
+
chunkPACIO4NS_cjs.notifyListeners(this.listeners);
|
|
1197
|
+
}
|
|
1198
|
+
};
|
|
1199
|
+
var throttleFrom = (throttleMs) => {
|
|
1200
|
+
if (throttleMs === void 0) {
|
|
1201
|
+
return chunkXKHLRIC7_cjs.PROFILE_MARKER_THROTTLE_MS;
|
|
1202
|
+
}
|
|
1203
|
+
if (!Number.isFinite(throttleMs) || throttleMs < 0 || throttleMs > MAX_TIMER_MS) {
|
|
1204
|
+
throw new errors.MountayaElementsError(
|
|
1205
|
+
`ProfileMarkerEngine: throttleMs is ${String(throttleMs)}; pass a number of milliseconds from 0 to ${MAX_TIMER_MS}, or omit it for ${chunkXKHLRIC7_cjs.PROFILE_MARKER_THROTTLE_MS}.`
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1208
|
+
return throttleMs;
|
|
1209
|
+
};
|
|
1210
|
+
var ProfileMarkerEngine = class {
|
|
1211
|
+
throttleMs;
|
|
1212
|
+
listeners = /* @__PURE__ */ new Set();
|
|
1213
|
+
/** The sample the marker rests on, or null while it is cleared. */
|
|
1214
|
+
resting = null;
|
|
1215
|
+
/** The hover waiting for the open window to end, or null while none waits. */
|
|
1216
|
+
held = null;
|
|
1217
|
+
/** The window that is open, or null between two bursts. */
|
|
1218
|
+
timer = null;
|
|
1219
|
+
disposed = false;
|
|
1220
|
+
/**
|
|
1221
|
+
* The constructor reads its option and does nothing else: no timer starts until a hover is
|
|
1222
|
+
* made under a listener.
|
|
1223
|
+
*
|
|
1224
|
+
* @throws {MountayaElementsError} When `throttleMs` is not a finite number from 0 to
|
|
1225
|
+
* 2,147,483,647.
|
|
1226
|
+
*/
|
|
1227
|
+
constructor(options = {}) {
|
|
1228
|
+
this.throttleMs = throttleFrom(options.throttleMs);
|
|
1229
|
+
}
|
|
1230
|
+
/** getSnapshot answers the sample the marker rests on, or null while it is cleared. */
|
|
1231
|
+
getSnapshot = () => this.resting;
|
|
1232
|
+
/**
|
|
1233
|
+
* subscribe holds a listener until the release it returns is called, and tells it each time
|
|
1234
|
+
* the marker moves or is cleared.
|
|
1235
|
+
*
|
|
1236
|
+
* The last listener to leave ends the open window and drops the held hover unwritten. After
|
|
1237
|
+
* {@link ProfileMarkerEngine.dispose} the listener is not held and is never told, and the
|
|
1238
|
+
* release does nothing.
|
|
1239
|
+
*/
|
|
1240
|
+
subscribe = (listener) => {
|
|
1241
|
+
if (this.disposed) {
|
|
1242
|
+
return () => {
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1245
|
+
this.listeners.add(listener);
|
|
1246
|
+
return () => {
|
|
1247
|
+
this.listeners.delete(listener);
|
|
1248
|
+
if (this.listeners.size === 0) {
|
|
1249
|
+
this.endWindow();
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1252
|
+
};
|
|
1253
|
+
/**
|
|
1254
|
+
* hover takes one hover of the chart: the sample under the pointer, or null as the pointer
|
|
1255
|
+
* leaves.
|
|
1256
|
+
*
|
|
1257
|
+
* A sample moves the marker at once when no window is open, and waits for the open window to
|
|
1258
|
+
* end otherwise. Null clears the marker at once, whatever is held. After
|
|
1259
|
+
* {@link ProfileMarkerEngine.dispose} it does nothing.
|
|
1260
|
+
*/
|
|
1261
|
+
hover(point) {
|
|
1262
|
+
if (this.disposed) {
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
if (point === null) {
|
|
1266
|
+
this.endWindow();
|
|
1267
|
+
this.rest(null);
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1270
|
+
if (this.timer !== null) {
|
|
1271
|
+
this.held = point;
|
|
1272
|
+
return;
|
|
1273
|
+
}
|
|
1274
|
+
this.rest(point);
|
|
1275
|
+
if (this.resting === point) {
|
|
1276
|
+
this.openWindow();
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* dispose ends the open window, drops the held hover and every listener, for good. The
|
|
1281
|
+
* snapshot keeps the sample the marker rested on, no listener is told, and every later call
|
|
1282
|
+
* does nothing. Calling it twice is safe.
|
|
1283
|
+
*/
|
|
1284
|
+
dispose() {
|
|
1285
|
+
if (this.disposed) {
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
this.disposed = true;
|
|
1289
|
+
this.endWindow();
|
|
1290
|
+
this.listeners.clear();
|
|
1291
|
+
}
|
|
1292
|
+
/** rest moves the marker to `point` and tells the listeners, unless it rests there already. */
|
|
1293
|
+
rest(point) {
|
|
1294
|
+
if (this.resting === point) {
|
|
1295
|
+
return;
|
|
1296
|
+
}
|
|
1297
|
+
this.resting = point;
|
|
1298
|
+
chunkPACIO4NS_cjs.notifyListeners(this.listeners);
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* openWindow starts the window a write opens, unless one is open already. With nobody
|
|
1302
|
+
* listening, or with a throttle of zero, there is no rate to keep and no window.
|
|
1303
|
+
*/
|
|
1304
|
+
openWindow() {
|
|
1305
|
+
if (this.timer !== null || this.throttleMs === 0 || this.listeners.size === 0) {
|
|
1306
|
+
return;
|
|
1307
|
+
}
|
|
1308
|
+
this.timer = setTimeout(() => {
|
|
1309
|
+
this.timer = null;
|
|
1310
|
+
const held = this.held;
|
|
1311
|
+
if (held === null) {
|
|
1312
|
+
return;
|
|
1313
|
+
}
|
|
1314
|
+
this.held = null;
|
|
1315
|
+
this.rest(held);
|
|
1316
|
+
if (this.resting === held) {
|
|
1317
|
+
this.openWindow();
|
|
1318
|
+
}
|
|
1319
|
+
}, this.throttleMs);
|
|
1320
|
+
}
|
|
1321
|
+
/** endWindow closes the open window, if any, and drops the hover it held. */
|
|
1322
|
+
endWindow() {
|
|
1323
|
+
if (this.timer !== null) {
|
|
1324
|
+
clearTimeout(this.timer);
|
|
1325
|
+
}
|
|
1326
|
+
this.timer = null;
|
|
1327
|
+
this.held = null;
|
|
1328
|
+
}
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
// src/segments/rules/hazardPrompt.ts
|
|
1332
|
+
var promptKey = (hazards) => [...hazards].sort().join("|");
|
|
1333
|
+
var createHazardPromptGate = (ask) => {
|
|
1334
|
+
const pending = /* @__PURE__ */ new Map();
|
|
1335
|
+
return (hazards) => {
|
|
1336
|
+
const key = promptKey(hazards);
|
|
1337
|
+
const asking = pending.get(key);
|
|
1338
|
+
if (asking) {
|
|
1339
|
+
return asking;
|
|
1340
|
+
}
|
|
1341
|
+
const answer = ask(hazards).finally(() => {
|
|
1342
|
+
pending.delete(key);
|
|
1343
|
+
});
|
|
1344
|
+
pending.set(key, answer);
|
|
1345
|
+
return answer;
|
|
1346
|
+
};
|
|
1347
|
+
};
|
|
1348
|
+
|
|
1349
|
+
// src/segments/rules/liveSegmentProjection.ts
|
|
1350
|
+
var buildLiveSegmentForDraft = (base, segmentId, itineraryId, mode, route, draftName, draftColor) => chunkIDBXFBLG_cjs.buildLiveSegment(
|
|
1351
|
+
base ?? chunkIDBXFBLG_cjs.synthesizeDraftSegment({
|
|
1352
|
+
draftColor,
|
|
1353
|
+
draftName,
|
|
1354
|
+
itineraryId,
|
|
1355
|
+
mode,
|
|
1356
|
+
segmentId
|
|
1357
|
+
}),
|
|
1358
|
+
route
|
|
1359
|
+
);
|
|
1360
|
+
|
|
1361
|
+
// src/segments/engines/segmentDraft.ts
|
|
1362
|
+
var idleSnapshot = {
|
|
1363
|
+
armed: false,
|
|
1364
|
+
mode: null,
|
|
1365
|
+
segmentId: null,
|
|
1366
|
+
viaCount: 0
|
|
1367
|
+
};
|
|
1368
|
+
var sameArming = (a, b) => a.client === b.client && a.context === b.context && a.segmentId === b.segmentId && a.mode === b.mode && a.activitySlug === b.activitySlug && a.draftColor === b.draftColor && a.pinnedEnd === b.pinnedEnd && a.pinnedStart === b.pinnedStart && a.seedVias === b.seedVias;
|
|
1369
|
+
var sameListenKey = (a, b) => a.client === b.client && a.context === b.context && a.itineraryId === b.itineraryId && a.mode === b.mode && a.segmentId === b.segmentId;
|
|
1370
|
+
var throttleFrom2 = (throttleMs) => {
|
|
1371
|
+
if (throttleMs === void 0) {
|
|
1372
|
+
return collab.LIVE_SEGMENT_THROTTLE_MS;
|
|
1373
|
+
}
|
|
1374
|
+
if (!Number.isFinite(throttleMs) || throttleMs < 0 || throttleMs > MAX_TIMER_MS) {
|
|
1375
|
+
throw new errors.MountayaElementsError(
|
|
1376
|
+
`SegmentDraftEngine: throttleMs is ${String(throttleMs)}; pass a number of milliseconds from 0 to ${MAX_TIMER_MS}, or omit it for ${collab.LIVE_SEGMENT_THROTTLE_MS}.`
|
|
1377
|
+
);
|
|
1378
|
+
}
|
|
1379
|
+
return throttleMs;
|
|
1380
|
+
};
|
|
1381
|
+
var SegmentDraftEngine = class {
|
|
1382
|
+
config;
|
|
1383
|
+
throttleMs;
|
|
1384
|
+
snapshot = idleSnapshot;
|
|
1385
|
+
subscriptions = /* @__PURE__ */ new Set();
|
|
1386
|
+
/** The store the session is watched in, and the subscription watching it, while running. */
|
|
1387
|
+
watching = null;
|
|
1388
|
+
/** What the open edit was armed with, or null while nothing is armed. */
|
|
1389
|
+
arming = null;
|
|
1390
|
+
/**
|
|
1391
|
+
* What the map client refused to arm, or null. Held until the session it was for closes or one
|
|
1392
|
+
* of its inputs changes, so a session on its way out is not handed to the map again. A park
|
|
1393
|
+
* keeps it: the session it names is still on its way out when the next subscriber arrives.
|
|
1394
|
+
*/
|
|
1395
|
+
refused = null;
|
|
1396
|
+
/** The subscription to the armed map's drafts, or null while nothing is armed. */
|
|
1397
|
+
listening = null;
|
|
1398
|
+
/** The handles the armed edit's latest draft holds. */
|
|
1399
|
+
viaCount = 0;
|
|
1400
|
+
/** Whether a reconcile is running, so one a store write starts inside it runs after it. */
|
|
1401
|
+
reconciling = false;
|
|
1402
|
+
/** Whether the store changed during the running reconcile, which then runs again. */
|
|
1403
|
+
stale = false;
|
|
1404
|
+
/** Whether nobody is watching. A parked engine arms nothing and reads no draft. */
|
|
1405
|
+
parked = true;
|
|
1406
|
+
disposed = false;
|
|
1407
|
+
/**
|
|
1408
|
+
* One dialog per hazard question, however many routing round trips ask it. Held for the
|
|
1409
|
+
* engine's life rather than per arming: a gate built beside the routing function would forget
|
|
1410
|
+
* the dialog already on screen, which is the state it exists to track.
|
|
1411
|
+
*/
|
|
1412
|
+
hazardGate = createHazardPromptGate(
|
|
1413
|
+
(hazards) => this.askAboutHazards(hazards)
|
|
1414
|
+
);
|
|
1415
|
+
/**
|
|
1416
|
+
* The session's record of accepted hazards, read and written through the store the engine is
|
|
1417
|
+
* configured with when the routing function asks. The store outlives every routing function
|
|
1418
|
+
* the editor is armed with, which is the point: an answer outlives a re-arm.
|
|
1419
|
+
*/
|
|
1420
|
+
hazardMemo = {
|
|
1421
|
+
accept: (keys) => {
|
|
1422
|
+
this.config.context.ui.getState().acknowledgeRouteHazards(keys);
|
|
1423
|
+
},
|
|
1424
|
+
accepted: () => this.config.context.ui.getState().segmentEditSession?.acknowledgedRouteHazards ?? []
|
|
1425
|
+
};
|
|
1426
|
+
/**
|
|
1427
|
+
* Constructing one holds the options and does nothing else: nothing is armed, no store is read
|
|
1428
|
+
* and nothing is written. A React binding constructs during a render React is free to throw
|
|
1429
|
+
* away, and a constructor with a side effect would leave the discarded copy acting.
|
|
1430
|
+
*
|
|
1431
|
+
* @throws {MountayaElementsError} When `throttleMs` is not a finite number from 0 to
|
|
1432
|
+
* 2,147,483,647.
|
|
1433
|
+
*/
|
|
1434
|
+
constructor(options) {
|
|
1435
|
+
const { throttleMs, ...config } = options;
|
|
1436
|
+
this.throttleMs = throttleFrom2(throttleMs);
|
|
1437
|
+
this.config = config;
|
|
1438
|
+
}
|
|
1439
|
+
/** getSnapshot returns the current answer, by reference and stable between changes. */
|
|
1440
|
+
getSnapshot() {
|
|
1441
|
+
return this.snapshot;
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* subscribe registers a listener for every change of the snapshot, and returns its own
|
|
1445
|
+
* unsubscribe, which is idempotent.
|
|
1446
|
+
*
|
|
1447
|
+
* The first listener starts the engine and the last one leaving parks it, which is the whole
|
|
1448
|
+
* lifecycle a component can express correctly: React tears an effect down and sets it up again
|
|
1449
|
+
* with the same object under StrictMode, so a latch here would leave a live surface bound to a
|
|
1450
|
+
* dead engine. Each call is its own subscription, so two owners subscribing one shared function
|
|
1451
|
+
* each hold the engine until they release it.
|
|
1452
|
+
*/
|
|
1453
|
+
subscribe(listener) {
|
|
1454
|
+
if (this.disposed) {
|
|
1455
|
+
return () => {
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
const subscription = { listener };
|
|
1459
|
+
this.subscriptions.add(subscription);
|
|
1460
|
+
if (this.parked) {
|
|
1461
|
+
this.parked = false;
|
|
1462
|
+
this.reconcile();
|
|
1463
|
+
}
|
|
1464
|
+
return () => {
|
|
1465
|
+
if (!this.subscriptions.delete(subscription) || this.subscriptions.size > 0) {
|
|
1466
|
+
return;
|
|
1467
|
+
}
|
|
1468
|
+
if (!this.parked) {
|
|
1469
|
+
this.park();
|
|
1470
|
+
}
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* configure replaces the configuration, and arms again only when an arming input changed.
|
|
1475
|
+
*
|
|
1476
|
+
* A binding calls it on every render, so a configuration carrying the same client and the same
|
|
1477
|
+
* context does nothing beyond the assignment: the bus, the collaboration session and the words
|
|
1478
|
+
* are read when they are used. A parked engine keeps the configuration for its next subscriber.
|
|
1479
|
+
*/
|
|
1480
|
+
configure(config) {
|
|
1481
|
+
if (this.disposed) {
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1484
|
+
this.config = config;
|
|
1485
|
+
if (!this.parked) {
|
|
1486
|
+
this.reconcile();
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
/**
|
|
1490
|
+
* dispose parks the engine and drops every listener, for good.
|
|
1491
|
+
*
|
|
1492
|
+
* Idempotent, and every call after it is a no-op rather than an error: an owner torn down
|
|
1493
|
+
* mid-edit should not have to guard the calls it already queued. A disposed engine writes no
|
|
1494
|
+
* store either: the cancel it dispatched for a refused begin runs on the bus, and a session that
|
|
1495
|
+
* cancel leaves open is not closed by the engine.
|
|
1496
|
+
*
|
|
1497
|
+
* The snapshot of a disposed engine reads `armed: false`. The engine holds a session and no
|
|
1498
|
+
* answer to a question, so there is nothing a reader could keep showing: the session is over
|
|
1499
|
+
* for this engine, and the snapshot says so.
|
|
1500
|
+
*/
|
|
1501
|
+
dispose() {
|
|
1502
|
+
if (this.disposed) {
|
|
1503
|
+
return;
|
|
1504
|
+
}
|
|
1505
|
+
this.disposed = true;
|
|
1506
|
+
if (!this.parked) {
|
|
1507
|
+
this.park();
|
|
1508
|
+
}
|
|
1509
|
+
this.subscriptions.clear();
|
|
1510
|
+
}
|
|
1511
|
+
/**
|
|
1512
|
+
* reconcile brings the arming and the draft subscription in line with the store and the
|
|
1513
|
+
* configuration, then publishes the snapshot. A store write it makes, or one a listener makes
|
|
1514
|
+
* while it runs, runs it again once it finishes rather than inside it.
|
|
1515
|
+
*/
|
|
1516
|
+
reconcile() {
|
|
1517
|
+
if (this.parked) {
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
if (this.reconciling) {
|
|
1521
|
+
this.stale = true;
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
this.reconciling = true;
|
|
1525
|
+
try {
|
|
1526
|
+
do {
|
|
1527
|
+
this.stale = false;
|
|
1528
|
+
this.step();
|
|
1529
|
+
} while (this.stale && !this.parked);
|
|
1530
|
+
} finally {
|
|
1531
|
+
this.reconciling = false;
|
|
1532
|
+
}
|
|
1533
|
+
this.publish();
|
|
1534
|
+
}
|
|
1535
|
+
/** step is one pass of {@link SegmentDraftEngine.reconcile}. */
|
|
1536
|
+
step() {
|
|
1537
|
+
const { client, context } = this.config;
|
|
1538
|
+
this.watch(context.ui);
|
|
1539
|
+
const state = context.ui.getState();
|
|
1540
|
+
const session = state.segmentEditSession;
|
|
1541
|
+
if (client === null || session === null || session.segmentId === "") {
|
|
1542
|
+
this.unlisten();
|
|
1543
|
+
this.arming = null;
|
|
1544
|
+
this.refused = null;
|
|
1545
|
+
return;
|
|
1546
|
+
}
|
|
1547
|
+
const key = {
|
|
1548
|
+
client,
|
|
1549
|
+
context,
|
|
1550
|
+
itineraryId: state.activeItinerary?.id ?? null,
|
|
1551
|
+
mode: session.mode,
|
|
1552
|
+
segmentId: session.segmentId
|
|
1553
|
+
};
|
|
1554
|
+
if (this.listening !== null && !sameListenKey(this.listening, key)) {
|
|
1555
|
+
this.unlisten();
|
|
1556
|
+
}
|
|
1557
|
+
const arming = {
|
|
1558
|
+
activitySlug: session.activitySlug,
|
|
1559
|
+
client,
|
|
1560
|
+
context,
|
|
1561
|
+
draftColor: session.draftColor,
|
|
1562
|
+
mode: session.mode,
|
|
1563
|
+
pinnedEnd: session.pinnedEnd,
|
|
1564
|
+
pinnedStart: session.pinnedStart,
|
|
1565
|
+
seedVias: session.seedVias,
|
|
1566
|
+
segmentId: session.segmentId
|
|
1567
|
+
};
|
|
1568
|
+
if (this.refused !== null && sameArming(this.refused, arming)) {
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
if (this.arming === null || !sameArming(this.arming, arming)) {
|
|
1572
|
+
try {
|
|
1573
|
+
client.beginSegmentEdit(
|
|
1574
|
+
chunkXKHLRIC7_cjs.buildSegmentEditOptions(session, {
|
|
1575
|
+
client: context.api?.client,
|
|
1576
|
+
confirmHazards: this.hazardGate,
|
|
1577
|
+
hazardMemo: this.hazardMemo,
|
|
1578
|
+
onViaCapRefused: () => this.refuseViaCap()
|
|
1579
|
+
})
|
|
1580
|
+
);
|
|
1581
|
+
} catch (refusal) {
|
|
1582
|
+
this.unlisten();
|
|
1583
|
+
this.arming = null;
|
|
1584
|
+
this.refused = arming;
|
|
1585
|
+
this.endRefused(context, chunkIDBXFBLG_cjs.segmentEditSessionMark(session), refusal);
|
|
1586
|
+
return;
|
|
1587
|
+
}
|
|
1588
|
+
this.arming = arming;
|
|
1589
|
+
this.refused = null;
|
|
1590
|
+
}
|
|
1591
|
+
if (this.listening === null) {
|
|
1592
|
+
this.listen(key);
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
/**
|
|
1596
|
+
* endRefused ends the session whose begin the map client refused, and hands the refusal to the
|
|
1597
|
+
* program.
|
|
1598
|
+
*
|
|
1599
|
+
* The session is ended by `studio.itinerary.segment.editCancel` through `bus`, the tool path
|
|
1600
|
+
* that owns every disposal: it gives back the lock the begin took and ends whatever edit the map
|
|
1601
|
+
* still holds. Where that tool does not answer `ok` (it is refused, it rejects, or the bus
|
|
1602
|
+
* states no result at all), the store's session is closed directly, so no session stays open
|
|
1603
|
+
* over a map that is editing nothing. A parked engine still closes it, since its surface may
|
|
1604
|
+
* mount again. A disposed one writes nothing, as {@link SegmentDraftEngine.dispose} promises:
|
|
1605
|
+
* the session is left to the engine that takes its place, which meets the same refusal.
|
|
1606
|
+
*
|
|
1607
|
+
* The refused session is the one closed directly, and no other: it is told by `mark`, its
|
|
1608
|
+
* {@link segmentEditSessionMark}, so a session begun since on the same segment stays open.
|
|
1609
|
+
*
|
|
1610
|
+
* The refusal names the option the map lacked. It is a defect of the program that armed the
|
|
1611
|
+
* session and not of the store write that woke the engine, so it leaves through
|
|
1612
|
+
* {@link surfaceFault}.
|
|
1613
|
+
*
|
|
1614
|
+
* The reader is told as well, since an uncaught error says nothing on screen and the session
|
|
1615
|
+
* closes under them: an `error` alert in the bundle's `editing.segmentEditBeginFailed`, read
|
|
1616
|
+
* when the refusal is told so a locale change is heard. It is raised after the cancel is asked
|
|
1617
|
+
* for, so a bus that answers one verb at a time ends the session first.
|
|
1618
|
+
*/
|
|
1619
|
+
endRefused(context, mark, refusal) {
|
|
1620
|
+
chunkPACIO4NS_cjs.surfaceFault(refusal);
|
|
1621
|
+
const close = () => {
|
|
1622
|
+
if (this.disposed) {
|
|
1623
|
+
return;
|
|
1624
|
+
}
|
|
1625
|
+
const state = context.ui.getState();
|
|
1626
|
+
const open = state.segmentEditSession;
|
|
1627
|
+
if (open !== null && chunkIDBXFBLG_cjs.segmentEditSessionMark(open) === mark) {
|
|
1628
|
+
state.cancelSegmentEdit();
|
|
1629
|
+
}
|
|
1630
|
+
};
|
|
1631
|
+
void Promise.resolve(
|
|
1632
|
+
this.config.bus.dispatch(context, "studio.itinerary.segment.editCancel", {})
|
|
1633
|
+
).then((result) => {
|
|
1634
|
+
if (result?.ok !== true) {
|
|
1635
|
+
close();
|
|
1636
|
+
}
|
|
1637
|
+
}, close);
|
|
1638
|
+
this.raiseAlert(context, {
|
|
1639
|
+
level: "error",
|
|
1640
|
+
message: this.config.strings.editing.segmentEditBeginFailed
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
/**
|
|
1644
|
+
* raiseAlert raises one alert through the bus, and holds a bus that rejects it.
|
|
1645
|
+
*
|
|
1646
|
+
* Nothing follows an alert: the map has already declined what the alert reports, and a refused
|
|
1647
|
+
* begin has reached the program through {@link surfaceFault} and is closed by its cancel. So a
|
|
1648
|
+
* rejection is dropped, where one left unhandled would end a Node process with an error that is
|
|
1649
|
+
* none of the package's.
|
|
1650
|
+
*/
|
|
1651
|
+
raiseAlert(context, alert) {
|
|
1652
|
+
void Promise.resolve(this.config.bus.dispatch(context, "studio.alert.show", alert)).then(
|
|
1653
|
+
void 0,
|
|
1654
|
+
() => {
|
|
1655
|
+
}
|
|
1656
|
+
);
|
|
1657
|
+
}
|
|
1658
|
+
/** watch follows the store the session lives in, leaving the previous one if it changed. */
|
|
1659
|
+
watch(ui) {
|
|
1660
|
+
if (this.watching?.ui === ui) {
|
|
1661
|
+
return;
|
|
1662
|
+
}
|
|
1663
|
+
this.unwatch();
|
|
1664
|
+
this.watching = { release: ui.subscribe(() => this.reconcile()), ui };
|
|
1665
|
+
}
|
|
1666
|
+
unwatch() {
|
|
1667
|
+
this.watching?.release();
|
|
1668
|
+
this.watching = null;
|
|
1669
|
+
}
|
|
1670
|
+
/** listen starts reading the armed map's drafts for the edit `key` names. */
|
|
1671
|
+
listen(key) {
|
|
1672
|
+
const listening = {
|
|
1673
|
+
...key,
|
|
1674
|
+
projected: null,
|
|
1675
|
+
release: () => {
|
|
1676
|
+
},
|
|
1677
|
+
// A zero-delay window still coalesces the routes a single turn of the event loop delivers,
|
|
1678
|
+
// so a zero window takes no throttle at all.
|
|
1679
|
+
throttle: this.throttleMs === 0 ? null : new collab.TrailingThrottle(
|
|
1680
|
+
this.throttleMs,
|
|
1681
|
+
(routed) => this.project(listening, routed),
|
|
1682
|
+
// The first route of a burst is the one the reader is waiting on: a drag whose
|
|
1683
|
+
// profile appears one window late reads as lag.
|
|
1684
|
+
{ leading: true }
|
|
1685
|
+
)
|
|
1686
|
+
};
|
|
1687
|
+
this.listening = listening;
|
|
1688
|
+
listening.release = key.client.onSegmentDraftChange((draft) => this.receive(listening, draft));
|
|
1689
|
+
}
|
|
1690
|
+
/**
|
|
1691
|
+
* unlisten stops reading the map's drafts, drops the pending route, and clears the live segment,
|
|
1692
|
+
* so a surface opened again over the session reads a clean slot until the next route lands.
|
|
1693
|
+
*/
|
|
1694
|
+
unlisten() {
|
|
1695
|
+
const listening = this.listening;
|
|
1696
|
+
if (listening === null) {
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
this.listening = null;
|
|
1700
|
+
this.viaCount = 0;
|
|
1701
|
+
listening.release();
|
|
1702
|
+
listening.throttle?.cancel();
|
|
1703
|
+
listening.context.ui.getState().setSegmentEditLiveSegment(null);
|
|
1704
|
+
}
|
|
1705
|
+
/** receive handles one draft the armed map reported, as the class docblock sets out. */
|
|
1706
|
+
receive(listening, draft) {
|
|
1707
|
+
if (this.listening !== listening) {
|
|
1708
|
+
return;
|
|
1709
|
+
}
|
|
1710
|
+
if (draft.vias.length !== this.viaCount) {
|
|
1711
|
+
this.viaCount = draft.vias.length;
|
|
1712
|
+
this.publish();
|
|
1713
|
+
if (this.listening !== listening) {
|
|
1714
|
+
return;
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
const ui = listening.context.ui;
|
|
1718
|
+
const disposition = chunkXKHLRIC7_cjs.draftChangeDisposition({
|
|
1719
|
+
agentDriving: ui.getState().agentDriving,
|
|
1720
|
+
programmatic: draft.programmatic
|
|
1721
|
+
});
|
|
1722
|
+
if (disposition === "drop") {
|
|
1723
|
+
return;
|
|
1724
|
+
}
|
|
1725
|
+
if (disposition === "record") {
|
|
1726
|
+
const geometry = geo.buildSegmentGeometry(listening.mode, draft.vias);
|
|
1727
|
+
if (draft.phase === "live") {
|
|
1728
|
+
ui.getState().setSegmentEditLiveDraft(geometry);
|
|
1729
|
+
} else {
|
|
1730
|
+
ui.getState().pushSegmentDraft(geometry);
|
|
1731
|
+
}
|
|
1732
|
+
if (this.listening !== listening) {
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
if (draft.route) {
|
|
1737
|
+
const projected = listening.projected;
|
|
1738
|
+
if (projected?.route === draft.route && ui.getState().segmentEditSession?.liveSegment === projected.liveSegment) {
|
|
1739
|
+
return;
|
|
1740
|
+
}
|
|
1741
|
+
const routed = {
|
|
1742
|
+
route: draft.route,
|
|
1743
|
+
routedFor: draft.programmatic ? draft.vias : void 0
|
|
1744
|
+
};
|
|
1745
|
+
if (listening.throttle === null) {
|
|
1746
|
+
this.project(listening, routed);
|
|
1747
|
+
} else {
|
|
1748
|
+
listening.throttle.push(routed);
|
|
1749
|
+
}
|
|
1750
|
+
return;
|
|
1751
|
+
}
|
|
1752
|
+
if (draft.phase === "live") {
|
|
1753
|
+
return;
|
|
1754
|
+
}
|
|
1755
|
+
listening.throttle?.cancel();
|
|
1756
|
+
if (disposition === "record") {
|
|
1757
|
+
this.fallBack(listening);
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* project writes one route onto the live segment the profile reads, and hands the same segment
|
|
1762
|
+
* to the collaboration session.
|
|
1763
|
+
*/
|
|
1764
|
+
project(listening, { route, routedFor }) {
|
|
1765
|
+
if (this.listening !== listening) {
|
|
1766
|
+
return;
|
|
1767
|
+
}
|
|
1768
|
+
const state = listening.context.ui.getState();
|
|
1769
|
+
const itinerary = state.activeItinerary;
|
|
1770
|
+
const session = state.segmentEditSession;
|
|
1771
|
+
const liveSegment = buildLiveSegmentForDraft(
|
|
1772
|
+
itinerary?.segments.find((segment) => segment.id === listening.segmentId),
|
|
1773
|
+
listening.segmentId,
|
|
1774
|
+
itinerary?.id ?? "",
|
|
1775
|
+
session?.mode ?? "directions",
|
|
1776
|
+
route,
|
|
1777
|
+
session?.draftName ?? null,
|
|
1778
|
+
session?.draftColor ?? null
|
|
1779
|
+
);
|
|
1780
|
+
listening.projected = { liveSegment, route };
|
|
1781
|
+
state.setSegmentEditLiveSegment(liveSegment, routedFor);
|
|
1782
|
+
this.config.collab?.sendDraft({ id: listening.segmentId, kind: "segment" }, liveSegment);
|
|
1783
|
+
}
|
|
1784
|
+
/**
|
|
1785
|
+
* fallBack writes what the live segment is once a settled draft resolves no route: nothing for
|
|
1786
|
+
* a persisted segment, which the profile then shows as saved, and the draft's synthetic
|
|
1787
|
+
* segment for one drawn from scratch, which has no saved version to show and would otherwise
|
|
1788
|
+
* lose its row until a route lands.
|
|
1789
|
+
*/
|
|
1790
|
+
fallBack(listening) {
|
|
1791
|
+
const state = listening.context.ui.getState();
|
|
1792
|
+
const session = state.segmentEditSession;
|
|
1793
|
+
const persisted = state.activeItinerary?.segments?.find(
|
|
1794
|
+
(segment) => segment.id === listening.segmentId
|
|
1795
|
+
);
|
|
1796
|
+
if (!persisted && session) {
|
|
1797
|
+
state.setSegmentEditLiveSegment(
|
|
1798
|
+
chunkIDBXFBLG_cjs.synthesizeDraftSegment({
|
|
1799
|
+
draftColor: session.draftColor,
|
|
1800
|
+
draftName: session.draftName,
|
|
1801
|
+
itineraryId: state.activeItinerary?.id ?? "",
|
|
1802
|
+
mode: session.mode,
|
|
1803
|
+
segmentId: session.segmentId
|
|
1804
|
+
})
|
|
1805
|
+
);
|
|
1806
|
+
return;
|
|
1807
|
+
}
|
|
1808
|
+
state.setSegmentEditLiveSegment(null);
|
|
1809
|
+
}
|
|
1810
|
+
/** refuseViaCap warns that a click was declined at the router's via ceiling. */
|
|
1811
|
+
refuseViaCap() {
|
|
1812
|
+
const { context, strings } = this.config;
|
|
1813
|
+
this.raiseAlert(context, {
|
|
1814
|
+
level: "warning",
|
|
1815
|
+
message: strings.editing.segmentViaCapRefused(geo.DIRECTIONS_VIA_MAX)
|
|
1816
|
+
});
|
|
1817
|
+
}
|
|
1818
|
+
/**
|
|
1819
|
+
* askAboutHazards puts a routed line's new hazards to the context's confirm gate, in the words
|
|
1820
|
+
* the engine was last handed, and adopts the line when the context has no gate.
|
|
1821
|
+
*/
|
|
1822
|
+
askAboutHazards(hazards) {
|
|
1823
|
+
const { context, strings } = this.config;
|
|
1824
|
+
if (!context.confirm) {
|
|
1825
|
+
return Promise.resolve(true);
|
|
1826
|
+
}
|
|
1827
|
+
return context.confirm(
|
|
1828
|
+
chunkXKHLRIC7_cjs.routeHazardConfirmation(hazards, {
|
|
1829
|
+
closing: strings.editing.routeHazardClosing,
|
|
1830
|
+
hazards: strings.editing.routeHazards,
|
|
1831
|
+
severalTitle: strings.editing.routeHazardsTitle
|
|
1832
|
+
})
|
|
1833
|
+
);
|
|
1834
|
+
}
|
|
1835
|
+
/**
|
|
1836
|
+
* park stops watching and reading, and drops what the running engine armed.
|
|
1837
|
+
*
|
|
1838
|
+
* A refused arming is kept. Its session stays open until the cancel the engine asked for lands,
|
|
1839
|
+
* and a surface mounted again meanwhile would otherwise hand it to the map a second time and ask
|
|
1840
|
+
* for a second cancel, which closes whichever session is open when it runs. A session begun
|
|
1841
|
+
* since holds a seed array of its own, so it never reads as the refused one.
|
|
1842
|
+
*/
|
|
1843
|
+
park() {
|
|
1844
|
+
this.parked = true;
|
|
1845
|
+
this.unwatch();
|
|
1846
|
+
this.unlisten();
|
|
1847
|
+
this.arming = null;
|
|
1848
|
+
this.publish();
|
|
1849
|
+
}
|
|
1850
|
+
/** publish settles the snapshot and tells every listener when it changed. */
|
|
1851
|
+
publish() {
|
|
1852
|
+
const listening = this.listening;
|
|
1853
|
+
const next = listening === null ? idleSnapshot : {
|
|
1854
|
+
armed: true,
|
|
1855
|
+
mode: listening.mode,
|
|
1856
|
+
segmentId: listening.segmentId,
|
|
1857
|
+
viaCount: this.viaCount
|
|
1858
|
+
};
|
|
1859
|
+
const current = this.snapshot;
|
|
1860
|
+
if (current.armed === next.armed && current.mode === next.mode && current.segmentId === next.segmentId && current.viaCount === next.viaCount) {
|
|
1861
|
+
return;
|
|
1862
|
+
}
|
|
1863
|
+
this.snapshot = next;
|
|
1864
|
+
if (this.disposed) {
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
chunkPACIO4NS_cjs.notifyListeners(Array.from(this.subscriptions, ({ listener }) => listener));
|
|
1868
|
+
}
|
|
1869
|
+
};
|
|
1870
|
+
z__namespace.object({
|
|
1871
|
+
failedCollectionIds: z__namespace.array(z__namespace.string()).optional()
|
|
1872
|
+
});
|
|
1873
|
+
var mintedShareTokenSchema = z__namespace.object({ shareToken: chunkIDBXFBLG_cjs.issuedShareTokenSchema.shape.shareToken });
|
|
1874
|
+
var mintedShareToken = (result) => {
|
|
1875
|
+
if (!result.ok) {
|
|
1876
|
+
return null;
|
|
1877
|
+
}
|
|
1878
|
+
const parsed = mintedShareTokenSchema.safeParse(result.data);
|
|
1879
|
+
return parsed.success ? parsed.data.shareToken : null;
|
|
1880
|
+
};
|
|
1881
|
+
|
|
1882
|
+
// src/share/engines/shareLink.ts
|
|
1883
|
+
var skipped = { status: "skipped" };
|
|
1884
|
+
var withheld = { status: "withheld" };
|
|
1885
|
+
var unworded = { failure: null, retryable: true };
|
|
1886
|
+
var sameTarget = (a, b) => a.kind === b.kind && a.id === b.id;
|
|
1887
|
+
var sameActions = (a, b) => a.disable === b.disable && a.rotate === b.rotate;
|
|
1888
|
+
var heldBack = (actions) => ({
|
|
1889
|
+
disable: actions.disable === "ready" ? "waiting" : actions.disable,
|
|
1890
|
+
rotate: actions.rotate === "ready" ? "waiting" : actions.rotate
|
|
1891
|
+
});
|
|
1892
|
+
var answered = async (run, settle) => {
|
|
1893
|
+
let result;
|
|
1894
|
+
try {
|
|
1895
|
+
result = await run();
|
|
1896
|
+
} catch (error) {
|
|
1897
|
+
result = chunkQL63MUEW_cjs.failureFromThrown(error);
|
|
1898
|
+
}
|
|
1899
|
+
return settle(result);
|
|
1900
|
+
};
|
|
1901
|
+
var readToken = (result) => {
|
|
1902
|
+
if (!result.ok) {
|
|
1903
|
+
return { failure: result, retryable: chunkEKZWV6RS_cjs.isRetryableShareLinkFailure(result) };
|
|
1904
|
+
}
|
|
1905
|
+
if (result.token === null) {
|
|
1906
|
+
return { token: null };
|
|
1907
|
+
}
|
|
1908
|
+
const issued = chunkIDBXFBLG_cjs.issuedShareTokenSchema.safeParse({ shareToken: result.token });
|
|
1909
|
+
return issued.success ? { token: issued.data.shareToken } : unworded;
|
|
1910
|
+
};
|
|
1911
|
+
var ShareLinkEngine = class {
|
|
1912
|
+
config;
|
|
1913
|
+
/** The target the state below answers for, replaced only by one that differs by kind or id. */
|
|
1914
|
+
target;
|
|
1915
|
+
token;
|
|
1916
|
+
known;
|
|
1917
|
+
readFailure = null;
|
|
1918
|
+
mintFailure = null;
|
|
1919
|
+
change = null;
|
|
1920
|
+
reading = false;
|
|
1921
|
+
minting = false;
|
|
1922
|
+
/**
|
|
1923
|
+
* Whether the link has been read under this target, so that no later subscriber reads again:
|
|
1924
|
+
* its token, that none is set, its failure or its read in flight is what the engine holds. A
|
|
1925
|
+
* settled disable raises it, since its reader asked for no link.
|
|
1926
|
+
*/
|
|
1927
|
+
asked = false;
|
|
1928
|
+
/**
|
|
1929
|
+
* The action called under this target and not yet answered, a confirmation being asked
|
|
1930
|
+
* included, or null. One slot, because a link takes one management action at a time.
|
|
1931
|
+
*/
|
|
1932
|
+
acting = null;
|
|
1933
|
+
/** Whether the confirmation of {@link acting} was approved, so its request is running. */
|
|
1934
|
+
running = false;
|
|
1935
|
+
/** Counts the targets answered for: an answer sent under an earlier one is ignored. */
|
|
1936
|
+
epoch = 0;
|
|
1937
|
+
/**
|
|
1938
|
+
* Counts the requests that left, a read and a create when they are sent and a reset or a
|
|
1939
|
+
* disable at its approval, so each one holds its place in the order they were sent.
|
|
1940
|
+
*/
|
|
1941
|
+
sent = 0;
|
|
1942
|
+
/**
|
|
1943
|
+
* The highest place a settled write outranks, or zero while none has settled: a read or a
|
|
1944
|
+
* create sent at or before it has its answer dropped. A reset outranks every request sent by the
|
|
1945
|
+
* time it settles, and a disable the ones sent before it.
|
|
1946
|
+
*/
|
|
1947
|
+
outranked = 0;
|
|
1948
|
+
/**
|
|
1949
|
+
* The place of the read or the create whose answer the engine holds, or zero while it holds
|
|
1950
|
+
* none of theirs.
|
|
1951
|
+
*/
|
|
1952
|
+
answeredAt = 0;
|
|
1953
|
+
/** The place of the latest read whose answer landed while nobody watched, or zero. */
|
|
1954
|
+
unheard = 0;
|
|
1955
|
+
/** The place of the read whose failure the engine holds, or zero while it holds none. */
|
|
1956
|
+
readFailedAt = 0;
|
|
1957
|
+
/** The place of the create whose failure the engine holds, or zero while it holds none. */
|
|
1958
|
+
mintFailedAt = 0;
|
|
1959
|
+
/** The place of the read sent last, or zero before any, which `reading` follows. */
|
|
1960
|
+
latestRead = 0;
|
|
1961
|
+
/** The place of the create sent last, or zero before any, which `minting` follows. */
|
|
1962
|
+
latestMint = 0;
|
|
1963
|
+
snapshot;
|
|
1964
|
+
subscriptions = /* @__PURE__ */ new Set();
|
|
1965
|
+
/** Whether nobody is watching. A parked engine asks for nothing and runs no command. */
|
|
1966
|
+
parked = true;
|
|
1967
|
+
disposed = false;
|
|
1968
|
+
/**
|
|
1969
|
+
* Constructing one holds the options and does nothing else: nothing is read and no tool is run.
|
|
1970
|
+
* A React binding constructs during a render React is free to throw away, and a constructor
|
|
1971
|
+
* with a side effect would leave the discarded copy reading.
|
|
1972
|
+
*/
|
|
1973
|
+
constructor(options) {
|
|
1974
|
+
const { token, ...config } = options;
|
|
1975
|
+
this.config = config;
|
|
1976
|
+
this.target = config.target;
|
|
1977
|
+
this.token = token ?? null;
|
|
1978
|
+
this.known = this.token !== null;
|
|
1979
|
+
this.snapshot = this.compose();
|
|
1980
|
+
}
|
|
1981
|
+
/** getSnapshot returns the current answer, by reference and stable between changes. */
|
|
1982
|
+
getSnapshot() {
|
|
1983
|
+
return this.snapshot;
|
|
1984
|
+
}
|
|
1985
|
+
/**
|
|
1986
|
+
* subscribe registers a listener for every change of the snapshot, and returns its own
|
|
1987
|
+
* unsubscribe, which is idempotent.
|
|
1988
|
+
*
|
|
1989
|
+
* The first listener resumes the engine, which reads the link unless it already has, and the
|
|
1990
|
+
* last one leaving parks it. That is the whole lifecycle a component can express correctly:
|
|
1991
|
+
* React tears an effect down and sets it up again with the same object under StrictMode, so a
|
|
1992
|
+
* latch here would leave a live surface bound to a dead engine. Each call is its own
|
|
1993
|
+
* subscription, so two owners subscribing one shared function each hold the engine until they
|
|
1994
|
+
* release it.
|
|
1995
|
+
*/
|
|
1996
|
+
subscribe(listener) {
|
|
1997
|
+
if (this.disposed) {
|
|
1998
|
+
return () => void 0;
|
|
1999
|
+
}
|
|
2000
|
+
const subscription = { listener };
|
|
2001
|
+
this.subscriptions.add(subscription);
|
|
2002
|
+
if (this.parked) {
|
|
2003
|
+
this.parked = false;
|
|
2004
|
+
this.ask();
|
|
2005
|
+
}
|
|
2006
|
+
return () => {
|
|
2007
|
+
if (!this.subscriptions.delete(subscription) || this.subscriptions.size > 0) {
|
|
2008
|
+
return;
|
|
2009
|
+
}
|
|
2010
|
+
this.parked = true;
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
/**
|
|
2014
|
+
* configure replaces the configuration, and tells its listeners only when the answer changed.
|
|
2015
|
+
*
|
|
2016
|
+
* A binding calls it on every render, so an unchanged configuration costs a comparison. A
|
|
2017
|
+
* changed capability or scope moves the snapshot's `actions`, and a scope that turns
|
|
2018
|
+
* `"organization"` sends the read a `"pending"` one held. A target that differs by kind or id
|
|
2019
|
+
* is another question: the token, what the engine knew, the failures and the latest change are
|
|
2020
|
+
* dropped, the answer of anything in flight for the previous target is ignored, an action still
|
|
2021
|
+
* running for it holds back none of the new target's, and the link is read again. A parked
|
|
2022
|
+
* engine keeps the configuration for its next subscriber.
|
|
2023
|
+
*/
|
|
2024
|
+
configure(config) {
|
|
2025
|
+
if (this.disposed) {
|
|
2026
|
+
return;
|
|
2027
|
+
}
|
|
2028
|
+
this.config = config;
|
|
2029
|
+
if (!sameTarget(this.target, config.target)) {
|
|
2030
|
+
this.target = config.target;
|
|
2031
|
+
this.epoch += 1;
|
|
2032
|
+
this.token = null;
|
|
2033
|
+
this.known = false;
|
|
2034
|
+
this.readFailure = null;
|
|
2035
|
+
this.readFailedAt = 0;
|
|
2036
|
+
this.mintFailure = null;
|
|
2037
|
+
this.mintFailedAt = 0;
|
|
2038
|
+
this.change = null;
|
|
2039
|
+
this.acting = null;
|
|
2040
|
+
this.running = false;
|
|
2041
|
+
this.reading = false;
|
|
2042
|
+
this.minting = false;
|
|
2043
|
+
this.asked = false;
|
|
2044
|
+
}
|
|
2045
|
+
this.publish();
|
|
2046
|
+
if (!this.parked) {
|
|
2047
|
+
this.ask();
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
/**
|
|
2051
|
+
* dispose parks the engine and drops every listener, for good.
|
|
2052
|
+
*
|
|
2053
|
+
* Idempotent, and every call after it is a no-op rather than an error: an owner torn down
|
|
2054
|
+
* mid-request should not have to guard the calls it already queued. A request in flight still
|
|
2055
|
+
* reaches the tool it was sent to; its answer changes nothing here.
|
|
2056
|
+
*/
|
|
2057
|
+
dispose() {
|
|
2058
|
+
if (this.disposed) {
|
|
2059
|
+
return;
|
|
2060
|
+
}
|
|
2061
|
+
this.disposed = true;
|
|
2062
|
+
this.parked = true;
|
|
2063
|
+
this.subscriptions.clear();
|
|
2064
|
+
}
|
|
2065
|
+
/**
|
|
2066
|
+
* read reads the link again, and resolves once that read has answered.
|
|
2067
|
+
*
|
|
2068
|
+
* The first subscriber reads by itself. This is the retry a surface offers under a
|
|
2069
|
+
* `readFailure` whose `retryable` is true. The previous failure leaves the snapshot while the
|
|
2070
|
+
* read is in flight, so a surface shows its pending state.
|
|
2071
|
+
*
|
|
2072
|
+
* It does nothing, and resolves at once, while a read is in flight, while the scope is not
|
|
2073
|
+
* `"organization"`, while the viewer does not hold `canManage`, while parked, and after
|
|
2074
|
+
* {@link ShareLinkEngine.dispose}. It never rejects.
|
|
2075
|
+
*/
|
|
2076
|
+
async read() {
|
|
2077
|
+
if (this.parked || this.disposed || this.reading || !this.mayAsk()) {
|
|
2078
|
+
return;
|
|
2079
|
+
}
|
|
2080
|
+
await this.runAsk("read");
|
|
2081
|
+
}
|
|
2082
|
+
/**
|
|
2083
|
+
* mint creates the link through `studio.shareLink.mint`, and resolves once that create has
|
|
2084
|
+
* answered: the reader's Create, which a surface offers once the snapshot is `known` with no
|
|
2085
|
+
* token. The verb gets or creates, so a link made elsewhere in the meantime is the one it
|
|
2086
|
+
* answers, and no URL already handed out is retired. A refusal is the snapshot's `mintFailure`,
|
|
2087
|
+
* and asking again is its retry.
|
|
2088
|
+
*
|
|
2089
|
+
* It does nothing, and resolves at once, while a create is in flight, while a link is held,
|
|
2090
|
+
* while a reset or a disable of this link is in flight, while the scope is not
|
|
2091
|
+
* `"organization"`, while the viewer does not hold `canManage`, while parked, and after
|
|
2092
|
+
* {@link ShareLinkEngine.dispose}. It never rejects.
|
|
2093
|
+
*/
|
|
2094
|
+
async mint() {
|
|
2095
|
+
if (this.parked || this.disposed || this.minting || this.token !== null || this.acting !== null || !this.mayAsk()) {
|
|
2096
|
+
return;
|
|
2097
|
+
}
|
|
2098
|
+
await this.runAsk("mint");
|
|
2099
|
+
}
|
|
2100
|
+
/**
|
|
2101
|
+
* rotate resets the link through `studio.shareLink.rotate`: the token held is retired, every
|
|
2102
|
+
* URL carrying it stops working, and the snapshot takes the one issued in its place.
|
|
2103
|
+
*
|
|
2104
|
+
* The tool bus asks the confirmation inside the dispatch, so the tool runs in a context whose
|
|
2105
|
+
* confirm gate the engine layers over the configured one: the snapshot's `busy` turns
|
|
2106
|
+
* `"rotate"` when the gate approves, never while it is asked. A context with no confirm gate
|
|
2107
|
+
* refuses, as the bus does for one.
|
|
2108
|
+
*
|
|
2109
|
+
* It runs only while the snapshot's `actions.rotate` is `"ready"`, which it is not while a
|
|
2110
|
+
* reset or a disable of this target is in flight (one whose confirmation is still asked
|
|
2111
|
+
* included), and while somebody is watching; otherwise it resolves `"skipped"`. One at a time,
|
|
2112
|
+
* because two writes side by side would leave the token to whichever answer landed last. A
|
|
2113
|
+
* refusal leaves the link, the latest change and a read's or a create's failure as they were.
|
|
2114
|
+
* An answer that lands once the engine answers for another target, or after
|
|
2115
|
+
* {@link ShareLinkEngine.dispose}, changes nothing either, and the outcome still says what the
|
|
2116
|
+
* verb came to.
|
|
2117
|
+
*
|
|
2118
|
+
* It never rejects. A `dispatch` that throws or rejects resolves `"refused"` with the failure
|
|
2119
|
+
* the tool bus builds for a handler that throws, and leaves the reset free to be asked again.
|
|
2120
|
+
* So does an `ok` answer that holds no token, with the `internal` refusal the verb gives for a
|
|
2121
|
+
* link that holds none: its sentence says the link held may no longer open. The engine then
|
|
2122
|
+
* reads the link that stands, and drops the answer of a read or a create sent before the reset,
|
|
2123
|
+
* which may carry the link it retired. That read is sent as the first one is, to a watched
|
|
2124
|
+
* engine under the `"organization"` scope: a parked engine sends it for its next subscriber,
|
|
2125
|
+
* and another scope once it turns `"organization"`.
|
|
2126
|
+
*/
|
|
2127
|
+
rotate() {
|
|
2128
|
+
return this.act("rotate");
|
|
2129
|
+
}
|
|
2130
|
+
/**
|
|
2131
|
+
* disable revokes the link through `studio.shareLink.disable`: every URL carrying its token
|
|
2132
|
+
* stops working, and the snapshot holds no token and knows that none is set. No later
|
|
2133
|
+
* subscriber reads it again; {@link ShareLinkEngine.mint} creates another.
|
|
2134
|
+
*
|
|
2135
|
+
* On a `"personal"` resource a `not-found` answer settles it too, with `linkWasActive` false:
|
|
2136
|
+
* no link was active, which is what the reader asked for (`isShareLinkDisableSettled`).
|
|
2137
|
+
*
|
|
2138
|
+
* The confirmation, the `busy` flag (`"disable"`) and the conditions it runs under are
|
|
2139
|
+
* {@link ShareLinkEngine.rotate}'s, read off `actions.disable`.
|
|
2140
|
+
*/
|
|
2141
|
+
disable() {
|
|
2142
|
+
return this.act("disable");
|
|
2143
|
+
}
|
|
2144
|
+
/** ask sends the first read of a target, once a scope that can hold a link is known. */
|
|
2145
|
+
ask() {
|
|
2146
|
+
if (this.asked || !this.mayAsk()) {
|
|
2147
|
+
return;
|
|
2148
|
+
}
|
|
2149
|
+
void this.runAsk("read");
|
|
2150
|
+
}
|
|
2151
|
+
/**
|
|
2152
|
+
* mayAsk reports whether the link may be read or created as configured: the resource is an
|
|
2153
|
+
* organization's, and the viewer holds the edit grant every request of its link needs.
|
|
2154
|
+
*/
|
|
2155
|
+
mayAsk() {
|
|
2156
|
+
return this.config.scope === "organization" && this.config.canManage;
|
|
2157
|
+
}
|
|
2158
|
+
/**
|
|
2159
|
+
* runAsk sends one read or one create and keeps its answer, unless the engine has moved on by
|
|
2160
|
+
* then or a write sent after it has settled.
|
|
2161
|
+
*/
|
|
2162
|
+
async runAsk(kind) {
|
|
2163
|
+
const epoch = this.epoch;
|
|
2164
|
+
this.sent += 1;
|
|
2165
|
+
const place = this.sent;
|
|
2166
|
+
if (kind === "read") {
|
|
2167
|
+
this.latestRead = place;
|
|
2168
|
+
this.asked = true;
|
|
2169
|
+
this.reading = true;
|
|
2170
|
+
this.readFailure = null;
|
|
2171
|
+
this.readFailedAt = 0;
|
|
2172
|
+
} else {
|
|
2173
|
+
this.latestMint = place;
|
|
2174
|
+
this.minting = true;
|
|
2175
|
+
this.mintFailure = null;
|
|
2176
|
+
this.mintFailedAt = 0;
|
|
2177
|
+
}
|
|
2178
|
+
this.publish();
|
|
2179
|
+
const answer = kind === "read" ? await this.sendRead() : await this.sendMint();
|
|
2180
|
+
if (this.disposed || epoch !== this.epoch) {
|
|
2181
|
+
return;
|
|
2182
|
+
}
|
|
2183
|
+
if (kind === "read" && place === this.latestRead) {
|
|
2184
|
+
this.reading = false;
|
|
2185
|
+
}
|
|
2186
|
+
if (kind === "mint" && place === this.latestMint) {
|
|
2187
|
+
this.minting = false;
|
|
2188
|
+
}
|
|
2189
|
+
if (place <= this.outranked || place < this.answeredAt) {
|
|
2190
|
+
this.publish();
|
|
2191
|
+
return;
|
|
2192
|
+
}
|
|
2193
|
+
if (kind === "read" && this.parked) {
|
|
2194
|
+
this.asked = false;
|
|
2195
|
+
this.unheard = place;
|
|
2196
|
+
this.publish();
|
|
2197
|
+
return;
|
|
2198
|
+
}
|
|
2199
|
+
if ("failure" in answer) {
|
|
2200
|
+
if (kind === "read") {
|
|
2201
|
+
this.readFailure = answer;
|
|
2202
|
+
this.readFailedAt = place;
|
|
2203
|
+
} else {
|
|
2204
|
+
this.mintFailure = answer;
|
|
2205
|
+
this.mintFailedAt = place;
|
|
2206
|
+
}
|
|
2207
|
+
this.publish();
|
|
2208
|
+
return;
|
|
2209
|
+
}
|
|
2210
|
+
this.token = answer.token;
|
|
2211
|
+
this.known = true;
|
|
2212
|
+
this.change = kind === "read" ? "read" : "minted";
|
|
2213
|
+
this.answeredAt = place;
|
|
2214
|
+
if (this.readFailedAt < place) {
|
|
2215
|
+
this.readFailure = null;
|
|
2216
|
+
this.readFailedAt = 0;
|
|
2217
|
+
}
|
|
2218
|
+
if (this.mintFailedAt < place) {
|
|
2219
|
+
this.mintFailure = null;
|
|
2220
|
+
this.mintFailedAt = 0;
|
|
2221
|
+
}
|
|
2222
|
+
this.publish();
|
|
2223
|
+
}
|
|
2224
|
+
/** sendRead reads the link through the configured read, a throw answered as a refusal. */
|
|
2225
|
+
async sendRead() {
|
|
2226
|
+
try {
|
|
2227
|
+
return readToken(await this.config.read(this.config.context, this.target));
|
|
2228
|
+
} catch {
|
|
2229
|
+
return unworded;
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
/** sendMint creates the link through the bus, a dispatch that throws answered as a refusal. */
|
|
2233
|
+
async sendMint() {
|
|
2234
|
+
try {
|
|
2235
|
+
const result = await this.config.dispatch(
|
|
2236
|
+
this.config.context,
|
|
2237
|
+
"studio.shareLink.mint",
|
|
2238
|
+
this.target
|
|
2239
|
+
);
|
|
2240
|
+
if (!result.ok) {
|
|
2241
|
+
return { failure: result, retryable: chunkEKZWV6RS_cjs.isRetryableShareLinkFailure(result) };
|
|
2242
|
+
}
|
|
2243
|
+
const token = mintedShareToken(result);
|
|
2244
|
+
return token === null ? unworded : { token };
|
|
2245
|
+
} catch {
|
|
2246
|
+
return unworded;
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
/** act runs one management action and settles the snapshot with its answer. */
|
|
2250
|
+
act(action) {
|
|
2251
|
+
if (this.parked || this.disposed || this.acting !== null || this.snapshot.actions[action] !== "ready") {
|
|
2252
|
+
return Promise.resolve(skipped);
|
|
2253
|
+
}
|
|
2254
|
+
const epoch = this.epoch;
|
|
2255
|
+
const { context, dispatch, scope } = this.config;
|
|
2256
|
+
this.sent += 1;
|
|
2257
|
+
let place = this.sent;
|
|
2258
|
+
const confirming = chunk7NBRCENN_cjs.layerToolContext(context, {
|
|
2259
|
+
confirm: async (request) => {
|
|
2260
|
+
const approved = await context.confirm?.(request) ?? false;
|
|
2261
|
+
if (approved && !this.disposed && epoch === this.epoch) {
|
|
2262
|
+
this.sent += 1;
|
|
2263
|
+
place = this.sent;
|
|
2264
|
+
this.running = true;
|
|
2265
|
+
this.publish();
|
|
2266
|
+
}
|
|
2267
|
+
return approved;
|
|
2268
|
+
}
|
|
2269
|
+
});
|
|
2270
|
+
const target = this.target;
|
|
2271
|
+
this.acting = action;
|
|
2272
|
+
this.publish();
|
|
2273
|
+
if (action === "rotate") {
|
|
2274
|
+
return answered(
|
|
2275
|
+
() => dispatch(confirming, "studio.shareLink.rotate", target),
|
|
2276
|
+
(result) => this.settleRotate(epoch, result)
|
|
2277
|
+
);
|
|
2278
|
+
}
|
|
2279
|
+
return answered(
|
|
2280
|
+
() => dispatch(confirming, "studio.shareLink.disable", target),
|
|
2281
|
+
// The place is read once the answer is in: the gate moves it when it approves.
|
|
2282
|
+
(result) => this.settleDisable(epoch, scope, place, result)
|
|
2283
|
+
);
|
|
2284
|
+
}
|
|
2285
|
+
/**
|
|
2286
|
+
* settleRotate ends a reset with its answer. The token it issued is the newest whatever a read
|
|
2287
|
+
* or a create answered or will answer, so every request sent by now is outranked.
|
|
2288
|
+
*
|
|
2289
|
+
* An `ok` answer that holds no token is refused as the verb refuses a link that holds none,
|
|
2290
|
+
* and the engine was handed no link to show. The server answered `ok` all the same, so it may
|
|
2291
|
+
* have retired the link held: every read and create sent by now is outranked, since its answer
|
|
2292
|
+
* may carry that link, and the engine reads which link stands
|
|
2293
|
+
* ({@link ShareLinkEngine.readStandingLink}). Until that read answers, the link and the latest
|
|
2294
|
+
* change read as they did.
|
|
2295
|
+
*/
|
|
2296
|
+
settleRotate(epoch, result) {
|
|
2297
|
+
if (!result.ok) {
|
|
2298
|
+
return this.refuse(epoch, result);
|
|
2299
|
+
}
|
|
2300
|
+
const shareToken = mintedShareToken(result);
|
|
2301
|
+
if (shareToken === null) {
|
|
2302
|
+
this.finish(epoch, () => {
|
|
2303
|
+
this.outranked = this.sent;
|
|
2304
|
+
});
|
|
2305
|
+
this.readStandingLink(epoch);
|
|
2306
|
+
return { failure: chunkEKZWV6RS_cjs.tokenlessAnswerRefusal("rotate"), status: "refused" };
|
|
2307
|
+
}
|
|
2308
|
+
this.finish(epoch, () => {
|
|
2309
|
+
this.outranked = this.sent;
|
|
2310
|
+
this.token = shareToken;
|
|
2311
|
+
this.known = true;
|
|
2312
|
+
this.change = "rotated";
|
|
2313
|
+
this.readFailure = null;
|
|
2314
|
+
this.readFailedAt = 0;
|
|
2315
|
+
this.mintFailure = null;
|
|
2316
|
+
this.mintFailedAt = 0;
|
|
2317
|
+
});
|
|
2318
|
+
return { linkWasActive: true, status: "settled" };
|
|
2319
|
+
}
|
|
2320
|
+
/**
|
|
2321
|
+
* readStandingLink reads which link stands, once a reset answered `ok` with no token.
|
|
2322
|
+
*
|
|
2323
|
+
* It is sent while somebody watches a resource whose scope is `"organization"`, the one scope a
|
|
2324
|
+
* read is sent under, for a viewer who holds the grant. On a parked engine, and under a scope or
|
|
2325
|
+
* a grant that takes no read by now, the question is left open: the next subscriber asks it,
|
|
2326
|
+
* or the configuration that takes one does. An engine that was disposed, or that answers for
|
|
2327
|
+
* another target by now, asks nothing.
|
|
2328
|
+
*/
|
|
2329
|
+
readStandingLink(epoch) {
|
|
2330
|
+
if (this.disposed || epoch !== this.epoch) {
|
|
2331
|
+
return;
|
|
2332
|
+
}
|
|
2333
|
+
if (this.parked || !this.mayAsk()) {
|
|
2334
|
+
this.asked = false;
|
|
2335
|
+
return;
|
|
2336
|
+
}
|
|
2337
|
+
void this.runAsk("read");
|
|
2338
|
+
}
|
|
2339
|
+
/**
|
|
2340
|
+
* settleDisable ends a disable with its answer, judged under the scope it was sent under and
|
|
2341
|
+
* at the place it left in.
|
|
2342
|
+
*/
|
|
2343
|
+
settleDisable(epoch, scope, place, result) {
|
|
2344
|
+
if (!result.ok && !chunkEKZWV6RS_cjs.isShareLinkDisableSettled(result, scope)) {
|
|
2345
|
+
return this.refuse(epoch, result);
|
|
2346
|
+
}
|
|
2347
|
+
this.finish(epoch, () => {
|
|
2348
|
+
if (place < this.answeredAt) {
|
|
2349
|
+
return;
|
|
2350
|
+
}
|
|
2351
|
+
this.outranked = place;
|
|
2352
|
+
this.token = null;
|
|
2353
|
+
this.known = true;
|
|
2354
|
+
this.change = "disabled";
|
|
2355
|
+
if (this.readFailedAt < place) {
|
|
2356
|
+
this.readFailure = null;
|
|
2357
|
+
this.readFailedAt = 0;
|
|
2358
|
+
}
|
|
2359
|
+
if (this.mintFailedAt < place) {
|
|
2360
|
+
this.mintFailure = null;
|
|
2361
|
+
this.mintFailedAt = 0;
|
|
2362
|
+
}
|
|
2363
|
+
if (place > this.unheard) {
|
|
2364
|
+
this.asked = true;
|
|
2365
|
+
}
|
|
2366
|
+
});
|
|
2367
|
+
return { linkWasActive: result.ok, status: "settled" };
|
|
2368
|
+
}
|
|
2369
|
+
/**
|
|
2370
|
+
* refuse ends an action whose verb did not run or failed, and answers what it came to:
|
|
2371
|
+
* `"withheld"` for a confirmation nobody approved, `"refused"` with the failure otherwise.
|
|
2372
|
+
* Nothing in the snapshot changes but the action in flight.
|
|
2373
|
+
*/
|
|
2374
|
+
refuse(epoch, failure) {
|
|
2375
|
+
this.finish(epoch);
|
|
2376
|
+
return chunkEOKRXXAC_cjs.isConfirmationWithheld(failure) ? withheld : { failure, status: "refused" };
|
|
2377
|
+
}
|
|
2378
|
+
/**
|
|
2379
|
+
* finish ends the action in flight: an action may be called again, and the snapshot stops
|
|
2380
|
+
* spinning and takes what `apply` writes, in one change. An engine that was disposed, or that
|
|
2381
|
+
* answers for another target by now, keeps everything as it is: the action it holds, if any,
|
|
2382
|
+
* is the new target's.
|
|
2383
|
+
*/
|
|
2384
|
+
finish(epoch, apply) {
|
|
2385
|
+
if (this.disposed || epoch !== this.epoch) {
|
|
2386
|
+
return;
|
|
2387
|
+
}
|
|
2388
|
+
this.acting = null;
|
|
2389
|
+
this.running = false;
|
|
2390
|
+
apply?.();
|
|
2391
|
+
this.publish();
|
|
2392
|
+
}
|
|
2393
|
+
/** compose assembles the snapshot the engine's state stands for now. */
|
|
2394
|
+
compose() {
|
|
2395
|
+
const { canManage, scope } = this.config;
|
|
2396
|
+
const offered = chunkEKZWV6RS_cjs.shareLinkActions({ canManage, scope, token: this.token });
|
|
2397
|
+
return {
|
|
2398
|
+
actions: this.acting === null ? offered : heldBack(offered),
|
|
2399
|
+
busy: this.running ? this.acting : null,
|
|
2400
|
+
change: this.change,
|
|
2401
|
+
known: this.known,
|
|
2402
|
+
mintFailure: this.mintFailure,
|
|
2403
|
+
minting: this.minting,
|
|
2404
|
+
readFailure: this.readFailure,
|
|
2405
|
+
reading: this.reading,
|
|
2406
|
+
target: this.target,
|
|
2407
|
+
token: this.token
|
|
2408
|
+
};
|
|
2409
|
+
}
|
|
2410
|
+
/** publish replaces the snapshot when the state moved it, and tells every listener. */
|
|
2411
|
+
publish() {
|
|
2412
|
+
const current = this.snapshot;
|
|
2413
|
+
const next = this.compose();
|
|
2414
|
+
const actions = sameActions(current.actions, next.actions) ? current.actions : next.actions;
|
|
2415
|
+
if (actions === current.actions && next.busy === current.busy && next.change === current.change && next.known === current.known && next.mintFailure === current.mintFailure && next.minting === current.minting && next.readFailure === current.readFailure && next.reading === current.reading && next.target === current.target && next.token === current.token) {
|
|
2416
|
+
return;
|
|
2417
|
+
}
|
|
2418
|
+
this.snapshot = { ...next, actions };
|
|
2419
|
+
chunkPACIO4NS_cjs.notifyListeners([...this.subscriptions].map((subscription) => subscription.listener));
|
|
2420
|
+
}
|
|
2421
|
+
};
|
|
2422
|
+
var queryKeyOf = (source) => source === null ? null : JSON.stringify(source);
|
|
2423
|
+
var noFacts = {
|
|
2424
|
+
createMethod: null,
|
|
2425
|
+
createSerial: 0,
|
|
2426
|
+
inherited: null,
|
|
2427
|
+
origin: null,
|
|
2428
|
+
session: null,
|
|
2429
|
+
zone: null
|
|
2430
|
+
};
|
|
2431
|
+
var factsOf = (state) => {
|
|
2432
|
+
const zone = state.activeZone;
|
|
2433
|
+
const itinerary = state.activeItinerary;
|
|
2434
|
+
return {
|
|
2435
|
+
createMethod: state.zoneCreateMethod,
|
|
2436
|
+
createSerial: state.zoneCreateSerial,
|
|
2437
|
+
// The flag and the itinerary are separate slots: a create inherits only while the itinerary
|
|
2438
|
+
// it was begun inside is still open, and only a create inherits at all.
|
|
2439
|
+
inherited: zone === null && state.zoneCreateInheritsItinerary && itinerary !== null ? {
|
|
2440
|
+
activityId: itinerary.activity_id,
|
|
2441
|
+
itineraryId: itinerary.id,
|
|
2442
|
+
organizationId: itinerary.organization_id ?? null
|
|
2443
|
+
} : null,
|
|
2444
|
+
origin: state.zoneCreateOrigin,
|
|
2445
|
+
session: state.zoneEditSession,
|
|
2446
|
+
zone
|
|
2447
|
+
};
|
|
2448
|
+
};
|
|
2449
|
+
var sameIds = (a, b) => a.length === b.length && a.every((id, index) => id === b[index]);
|
|
2450
|
+
var sameMembers = (a, b) => {
|
|
2451
|
+
const keys = Object.keys(a);
|
|
2452
|
+
return keys.length === Object.keys(b).length && keys.every((key) => Object.is(a[key], b[key]));
|
|
2453
|
+
};
|
|
2454
|
+
var readsSame = (a, b) => a.activeZone === b.activeZone && a.activeItinerary === b.activeItinerary && a.zoneCreateInheritsItinerary === b.zoneCreateInheritsItinerary && a.zoneCreateMethod === b.zoneCreateMethod && a.zoneCreateOrigin === b.zoneCreateOrigin && a.zoneCreateSerial === b.zoneCreateSerial && a.zoneEditSession === b.zoneEditSession;
|
|
2455
|
+
var debounceFrom2 = (debounceMs) => {
|
|
2456
|
+
if (debounceMs === void 0) {
|
|
2457
|
+
return chunkEKZWV6RS_cjs.ZONE_PREVIEW_DEBOUNCE_MS;
|
|
2458
|
+
}
|
|
2459
|
+
if (!Number.isFinite(debounceMs) || debounceMs < 0 || debounceMs > MAX_TIMER_MS) {
|
|
2460
|
+
throw new errors.MountayaElementsError(
|
|
2461
|
+
`ZoneFormEngine: debounceMs is ${String(debounceMs)}; pass a number of milliseconds from 0 to ${MAX_TIMER_MS}, or omit it for ${chunkEKZWV6RS_cjs.ZONE_PREVIEW_DEBOUNCE_MS}.`
|
|
2462
|
+
);
|
|
2463
|
+
}
|
|
2464
|
+
return debounceMs;
|
|
2465
|
+
};
|
|
2466
|
+
var ZoneFormEngine = class {
|
|
2467
|
+
config;
|
|
2468
|
+
debounceMs;
|
|
2469
|
+
ids;
|
|
2470
|
+
ui;
|
|
2471
|
+
draft = {
|
|
2472
|
+
activityId: null,
|
|
2473
|
+
collectionIds: [],
|
|
2474
|
+
createLevel: chunkIDBXFBLG_cjs.DEFAULT_ZONE_LEVEL,
|
|
2475
|
+
createMode: chunkIDBXFBLG_cjs.DEFAULT_ZONE_MODE,
|
|
2476
|
+
description: "",
|
|
2477
|
+
endAt: null,
|
|
2478
|
+
name: "",
|
|
2479
|
+
organizationId: null,
|
|
2480
|
+
range: chunkEKZWV6RS_cjs.ZONE_DEFAULT_DISTANCE_RANGE_METERS,
|
|
2481
|
+
rangeType: "distance",
|
|
2482
|
+
speedKmh: null,
|
|
2483
|
+
startAt: null,
|
|
2484
|
+
windowOpen: false
|
|
2485
|
+
};
|
|
2486
|
+
/** Whether the name is the reader's own, which stops it following anything. */
|
|
2487
|
+
nameTouched = false;
|
|
2488
|
+
/** Whether the organization is the reader's own choice, null included, which no default fills. */
|
|
2489
|
+
organizationChosen = false;
|
|
2490
|
+
/** The subjects a save is in flight for. A subject saves once at a time, and each on its own. */
|
|
2491
|
+
saving = /* @__PURE__ */ new Set();
|
|
2492
|
+
/** Whether a draw has been asked for and not answered yet. */
|
|
2493
|
+
drawing = false;
|
|
2494
|
+
drawFailure = null;
|
|
2495
|
+
pickFailure = null;
|
|
2496
|
+
/** Counts the origin picks asked for: the refusal of an earlier one is dropped. */
|
|
2497
|
+
pickSerial = 0;
|
|
2498
|
+
/** The origin the last seed read, which a pick that lands moves; undefined until the first. */
|
|
2499
|
+
origin = void 0;
|
|
2500
|
+
saveFailure = null;
|
|
2501
|
+
/**
|
|
2502
|
+
* The latest save's refusal of its reachability query, with the query it was sent with, as
|
|
2503
|
+
* {@link queryKeyOf} writes it; null when the latest save met none.
|
|
2504
|
+
*/
|
|
2505
|
+
sourceRefusal = null;
|
|
2506
|
+
previewFailure = null;
|
|
2507
|
+
/** Whether the store's `zoneFormUnsaved` holds this engine's true, written by it. */
|
|
2508
|
+
unsavedWritten = false;
|
|
2509
|
+
/**
|
|
2510
|
+
* Whether the reader changed anything since the subject opened: typed a field, switched the
|
|
2511
|
+
* method or picked an origin. A computed create opens saveable on what it was opened with, and
|
|
2512
|
+
* leaving it untouched loses nothing the reader did, so it is unsaved only once this holds.
|
|
2513
|
+
*/
|
|
2514
|
+
touched = false;
|
|
2515
|
+
/** The zone the metadata was seeded from; undefined until the first seed. */
|
|
2516
|
+
bound = void 0;
|
|
2517
|
+
/**
|
|
2518
|
+
* What the failures and a save in flight answer for: the bound zone, or a create, by its
|
|
2519
|
+
* serial, the method it is authored by and the itinerary it inherits from. Null until the
|
|
2520
|
+
* first seed.
|
|
2521
|
+
*/
|
|
2522
|
+
subject = null;
|
|
2523
|
+
/**
|
|
2524
|
+
* Counts the subjects a save or a draw can answer for: a refusal sent under an earlier one is
|
|
2525
|
+
* dropped.
|
|
2526
|
+
*/
|
|
2527
|
+
subjectEpoch = 0;
|
|
2528
|
+
/**
|
|
2529
|
+
* The create the fields were last seeded for: its serial and the id of the itinerary it
|
|
2530
|
+
* inherits from, and undefined while a zone is bound and before the first seed.
|
|
2531
|
+
*/
|
|
2532
|
+
create = void 0;
|
|
2533
|
+
/** The serial of the create the fields were last seeded for, while the last seed was a create. */
|
|
2534
|
+
createSerial = void 0;
|
|
2535
|
+
/** The zone and the catalog the reachability parameters were last seeded from. */
|
|
2536
|
+
sourceSeed = null;
|
|
2537
|
+
/** The store state and the configuration the snapshot was last settled against. */
|
|
2538
|
+
settled = null;
|
|
2539
|
+
/**
|
|
2540
|
+
* The name and the description last judged, with the verdicts, so a pass that moved neither
|
|
2541
|
+
* parses nothing.
|
|
2542
|
+
*/
|
|
2543
|
+
judged = null;
|
|
2544
|
+
snapshot;
|
|
2545
|
+
subscriptions = /* @__PURE__ */ new Set();
|
|
2546
|
+
/** Ends the watch on the store, while running. */
|
|
2547
|
+
unwatch = null;
|
|
2548
|
+
/** The key of the preview asked for or waited on; undefined when none has been considered. */
|
|
2549
|
+
previewKey = void 0;
|
|
2550
|
+
/** The preview the pending debounce asks for. */
|
|
2551
|
+
previewInput = null;
|
|
2552
|
+
/**
|
|
2553
|
+
* Counts the questions a preview can answer, and the subjects it can answer for: an answer
|
|
2554
|
+
* from an earlier one is ignored.
|
|
2555
|
+
*/
|
|
2556
|
+
previewEpoch = 0;
|
|
2557
|
+
timer = null;
|
|
2558
|
+
/** Whether a reconcile is running, so one started inside it runs after it. */
|
|
2559
|
+
reconciling = false;
|
|
2560
|
+
/** Whether something changed during the running reconcile, which then runs again. */
|
|
2561
|
+
stale = false;
|
|
2562
|
+
/**
|
|
2563
|
+
* Whether nobody is watching. A parked engine watches no store, asks for no preview and answers
|
|
2564
|
+
* no command.
|
|
2565
|
+
*/
|
|
2566
|
+
parked = true;
|
|
2567
|
+
disposed = false;
|
|
2568
|
+
/**
|
|
2569
|
+
* Constructing one holds the options and does nothing else: no store is read, no timer armed
|
|
2570
|
+
* and no tool run. A React binding constructs during a render React is free to throw away, and
|
|
2571
|
+
* a constructor with a side effect would leave the discarded copy acting.
|
|
2572
|
+
*
|
|
2573
|
+
* @throws {MountayaElementsError} When `debounceMs` is not a finite number from 0 to
|
|
2574
|
+
* 2,147,483,647.
|
|
2575
|
+
*/
|
|
2576
|
+
constructor(options) {
|
|
2577
|
+
const { debounceMs, ids, ui, ...config } = options;
|
|
2578
|
+
this.debounceMs = debounceFrom2(debounceMs);
|
|
2579
|
+
this.ids = ids;
|
|
2580
|
+
this.ui = ui;
|
|
2581
|
+
this.config = config;
|
|
2582
|
+
this.snapshot = this.view(noFacts).snapshot;
|
|
2583
|
+
}
|
|
2584
|
+
/**
|
|
2585
|
+
* getSnapshot returns the current answer, by reference and stable between changes.
|
|
2586
|
+
*
|
|
2587
|
+
* A parked engine settles it on the read: it reads the store and seeds the fields for the zone
|
|
2588
|
+
* bound now, without watching the store, arming a timer or running a tool. So a surface's first
|
|
2589
|
+
* render, and a server's only one, show the bound zone.
|
|
2590
|
+
*/
|
|
2591
|
+
getSnapshot() {
|
|
2592
|
+
this.settle();
|
|
2593
|
+
return this.snapshot;
|
|
2594
|
+
}
|
|
2595
|
+
/**
|
|
2596
|
+
* subscribe registers a listener for every change of the snapshot, and returns its own
|
|
2597
|
+
* unsubscribe, which is idempotent.
|
|
2598
|
+
*
|
|
2599
|
+
* The first listener starts the engine and the last one leaving parks it, which is the whole
|
|
2600
|
+
* lifecycle a component can express correctly: React tears an effect down and sets it up again
|
|
2601
|
+
* with the same object under StrictMode, so a latch here would leave a live surface bound to a
|
|
2602
|
+
* dead engine. Each call is its own subscription, so two owners subscribing one shared function
|
|
2603
|
+
* each hold the engine until they release it.
|
|
2604
|
+
*/
|
|
2605
|
+
subscribe(listener) {
|
|
2606
|
+
if (this.disposed) {
|
|
2607
|
+
return () => {
|
|
2608
|
+
};
|
|
2609
|
+
}
|
|
2610
|
+
const subscription = { listener };
|
|
2611
|
+
this.subscriptions.add(subscription);
|
|
2612
|
+
if (this.parked) {
|
|
2613
|
+
this.parked = false;
|
|
2614
|
+
this.unwatch = this.ui.subscribe((state) => this.watch(state));
|
|
2615
|
+
this.reconcile();
|
|
2616
|
+
}
|
|
2617
|
+
return () => {
|
|
2618
|
+
if (!this.subscriptions.delete(subscription) || this.subscriptions.size > 0) {
|
|
2619
|
+
return;
|
|
2620
|
+
}
|
|
2621
|
+
if (!this.parked) {
|
|
2622
|
+
this.park();
|
|
2623
|
+
}
|
|
2624
|
+
};
|
|
2625
|
+
}
|
|
2626
|
+
/**
|
|
2627
|
+
* configure replaces the configuration, and settles the form again only when a member changed.
|
|
2628
|
+
*
|
|
2629
|
+
* A binding calls it on every render, so it compares every member by identity and does nothing
|
|
2630
|
+
* when all are the ones it holds. A changed one seeds what waited on it: a catalog that
|
|
2631
|
+
* arrives seeds the activity, collections that arrive are followed, and a name still following
|
|
2632
|
+
* its parameters is written again in the new language. A parked engine keeps the configuration
|
|
2633
|
+
* for its next read.
|
|
2634
|
+
*/
|
|
2635
|
+
configure(config) {
|
|
2636
|
+
if (this.disposed || sameMembers(this.config, config)) {
|
|
2637
|
+
return;
|
|
2638
|
+
}
|
|
2639
|
+
this.config = config;
|
|
2640
|
+
if (!this.parked) {
|
|
2641
|
+
this.reconcile();
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
/**
|
|
2645
|
+
* dispose parks the engine and drops every listener, for good.
|
|
2646
|
+
*
|
|
2647
|
+
* Idempotent, and every call after it is a no-op rather than an error: an owner torn down
|
|
2648
|
+
* mid-save should not have to guard the calls it already queued. A save in flight still reaches
|
|
2649
|
+
* the tool it was sent to; its answer changes nothing here.
|
|
2650
|
+
*/
|
|
2651
|
+
dispose() {
|
|
2652
|
+
if (this.disposed) {
|
|
2653
|
+
return;
|
|
2654
|
+
}
|
|
2655
|
+
this.disposed = true;
|
|
2656
|
+
if (!this.parked) {
|
|
2657
|
+
this.park();
|
|
2658
|
+
}
|
|
2659
|
+
this.subscriptions.clear();
|
|
2660
|
+
}
|
|
2661
|
+
/**
|
|
2662
|
+
* edit writes the given fields, and applies the rule each one carries:
|
|
2663
|
+
*
|
|
2664
|
+
* - `name` makes the name the reader's own, so it stops following the parameters. On a create
|
|
2665
|
+
* whose draft a proposal named it also clears that name from the draft, so the one typed is
|
|
2666
|
+
* shown.
|
|
2667
|
+
* - `name`, `description`, `startAt` and `endAt` clear the previous save's failure.
|
|
2668
|
+
* - `windowOpen: false` clears both bounds, so a hidden window never persists a constraint its
|
|
2669
|
+
* reader cannot see.
|
|
2670
|
+
* - `rangeType` resets `range` to that measure's default and never reinterprets the number,
|
|
2671
|
+
* and a switch to `"distance"` drops the pace, which a distance does not depend on.
|
|
2672
|
+
* - `speedKmh` holds beside a time budget only: on a distance budget it is dropped, so a later
|
|
2673
|
+
* switch to `"time"` starts from the activity's own pace.
|
|
2674
|
+
* - `organizationId` makes the organization the reader's own choice, `null` included: a create
|
|
2675
|
+
* then stays personal beside a `defaultOrganizationId`. On a create whose draft a proposal
|
|
2676
|
+
* filed, or whose draw was armed under another, it is also written on the draft, so the one
|
|
2677
|
+
* picked is shown and saved.
|
|
2678
|
+
* - `level`, while a draw is armed, also runs `studio.zone.setLevel`, which recolours the draft.
|
|
2679
|
+
* A refusal leaves the draft as it was, and the form goes back to the severity it held. On a
|
|
2680
|
+
* create it is also written on the store (`zoneCreatePickedLevel`), which the step of a
|
|
2681
|
+
* proposal that joins the create records, so an undo of the proposal shows it again.
|
|
2682
|
+
*
|
|
2683
|
+
* `rangeType` and `windowOpen` are applied before the fields they reset, so an edit naming both
|
|
2684
|
+
* keeps the value it names. `mode` is the shape a draw is armed with; once armed, and for a
|
|
2685
|
+
* saved zone, the snapshot shows the session's or the zone's own. While the snapshot's
|
|
2686
|
+
* `inherits` is true, `organizationId`, `activityId` and `collectionIds` follow the itinerary
|
|
2687
|
+
* and an edit of one does not hold.
|
|
2688
|
+
*
|
|
2689
|
+
* A call while parked, or after {@link ZoneFormEngine.dispose}, does nothing.
|
|
2690
|
+
*/
|
|
2691
|
+
edit(fields) {
|
|
2692
|
+
if (this.parked || this.disposed) {
|
|
2693
|
+
return;
|
|
2694
|
+
}
|
|
2695
|
+
this.touched = true;
|
|
2696
|
+
const { draft } = this;
|
|
2697
|
+
if (fields.rangeType !== void 0) {
|
|
2698
|
+
draft.rangeType = fields.rangeType;
|
|
2699
|
+
draft.range = fields.rangeType === "time" ? chunkEKZWV6RS_cjs.ZONE_DEFAULT_TIME_RANGE_SECONDS : chunkEKZWV6RS_cjs.ZONE_DEFAULT_DISTANCE_RANGE_METERS;
|
|
2700
|
+
if (fields.rangeType === "distance") {
|
|
2701
|
+
draft.speedKmh = null;
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
if (fields.windowOpen !== void 0) {
|
|
2705
|
+
draft.windowOpen = fields.windowOpen;
|
|
2706
|
+
if (!fields.windowOpen) {
|
|
2707
|
+
draft.startAt = null;
|
|
2708
|
+
draft.endAt = null;
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
if (fields.name !== void 0) {
|
|
2712
|
+
draft.name = fields.name;
|
|
2713
|
+
this.nameTouched = true;
|
|
2714
|
+
const session = this.ui.getState().zoneEditSession;
|
|
2715
|
+
if (this.bound === null && session?.intent === "create" && session.name !== null) {
|
|
2716
|
+
this.ui.getState().setZoneEditName(null);
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
if (fields.description !== void 0) {
|
|
2720
|
+
draft.description = fields.description;
|
|
2721
|
+
}
|
|
2722
|
+
if (fields.startAt !== void 0) {
|
|
2723
|
+
draft.startAt = fields.startAt;
|
|
2724
|
+
}
|
|
2725
|
+
if (fields.endAt !== void 0) {
|
|
2726
|
+
draft.endAt = fields.endAt;
|
|
2727
|
+
}
|
|
2728
|
+
if (fields.name !== void 0 || fields.description !== void 0 || fields.startAt !== void 0 || fields.endAt !== void 0) {
|
|
2729
|
+
this.saveFailure = null;
|
|
2730
|
+
}
|
|
2731
|
+
if (fields.activityId !== void 0) {
|
|
2732
|
+
draft.activityId = fields.activityId;
|
|
2733
|
+
}
|
|
2734
|
+
if (fields.collectionIds !== void 0 && !sameIds(draft.collectionIds, fields.collectionIds)) {
|
|
2735
|
+
draft.collectionIds = [...fields.collectionIds];
|
|
2736
|
+
}
|
|
2737
|
+
if (fields.mode !== void 0) {
|
|
2738
|
+
draft.createMode = fields.mode;
|
|
2739
|
+
}
|
|
2740
|
+
if (fields.organizationId !== void 0) {
|
|
2741
|
+
draft.organizationId = fields.organizationId;
|
|
2742
|
+
this.organizationChosen = true;
|
|
2743
|
+
const session = this.ui.getState().zoneEditSession;
|
|
2744
|
+
if (this.bound === null && session?.intent === "create" && session.organizationId !== fields.organizationId) {
|
|
2745
|
+
this.ui.getState().setZoneEditOrganization(fields.organizationId);
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
if (fields.range !== void 0) {
|
|
2749
|
+
draft.range = fields.range;
|
|
2750
|
+
}
|
|
2751
|
+
if (fields.speedKmh !== void 0) {
|
|
2752
|
+
draft.speedKmh = draft.rangeType === "time" ? fields.speedKmh : null;
|
|
2753
|
+
}
|
|
2754
|
+
const held = { level: draft.createLevel, pick: this.ui.getState().zoneCreatePickedLevel };
|
|
2755
|
+
if (fields.level !== void 0) {
|
|
2756
|
+
draft.createLevel = fields.level;
|
|
2757
|
+
if (this.bound === null && held.pick !== fields.level) {
|
|
2758
|
+
this.ui.getState().setZoneCreatePickedLevel(fields.level);
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
this.reconcile();
|
|
2762
|
+
if (fields.level !== void 0 && this.snapshot.armed) {
|
|
2763
|
+
void this.recolour(fields.level, held);
|
|
2764
|
+
}
|
|
2765
|
+
}
|
|
2766
|
+
/**
|
|
2767
|
+
* ask runs one tool and answers its result, or null where the host's bus rejected the call.
|
|
2768
|
+
*
|
|
2769
|
+
* A tool bus's dispatch never rejects, and a host's own may. A call it rejects made no answer:
|
|
2770
|
+
* the rejection is held here, so none is left unhandled by a call the form does not await, and
|
|
2771
|
+
* the caller goes on as it does for a tool that did nothing. A save is awaited by its caller
|
|
2772
|
+
* and is not asked through here: its rejection is the caller's to read.
|
|
2773
|
+
*/
|
|
2774
|
+
async ask(name, input) {
|
|
2775
|
+
try {
|
|
2776
|
+
return await this.config.dispatch(name, input);
|
|
2777
|
+
} catch {
|
|
2778
|
+
return null;
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
/**
|
|
2782
|
+
* recolour sets the armed draft's severity, through `studio.zone.setLevel`. A refusal leaves
|
|
2783
|
+
* the draft painted as it was, and so does a call the bus rejects, so the form goes back to the
|
|
2784
|
+
* severity it held and a create's pick to the one the store held, unless its reader has chosen
|
|
2785
|
+
* another since or the form answers for another subject by then.
|
|
2786
|
+
*/
|
|
2787
|
+
async recolour(level, held) {
|
|
2788
|
+
const epoch = this.subjectEpoch;
|
|
2789
|
+
const result = await this.ask("studio.zone.setLevel", { level });
|
|
2790
|
+
if (result?.ok !== true && !this.disposed && epoch === this.subjectEpoch && this.draft.createLevel === level) {
|
|
2791
|
+
this.draft.createLevel = held.level;
|
|
2792
|
+
if (this.bound === null && this.ui.getState().zoneCreatePickedLevel === level) {
|
|
2793
|
+
this.ui.getState().setZoneCreatePickedLevel(held.pick);
|
|
2794
|
+
}
|
|
2795
|
+
this.reconcile();
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
/**
|
|
2799
|
+
* setMethod switches how a create is authored, through `studio.zone.setCreateMethod`, and
|
|
2800
|
+
* clears the preview's and the save's failures, which described the method left behind. The
|
|
2801
|
+
* same two are cleared when another caller of that tool switches it. A switch the tool refuses
|
|
2802
|
+
* left no method behind: the two failures stand again, for as long as the form answers for the
|
|
2803
|
+
* same create. A call while parked, or after {@link ZoneFormEngine.dispose}, does nothing.
|
|
2804
|
+
*/
|
|
2805
|
+
setMethod(method) {
|
|
2806
|
+
if (this.parked || this.disposed) {
|
|
2807
|
+
return;
|
|
2808
|
+
}
|
|
2809
|
+
this.touched = true;
|
|
2810
|
+
void this.switchMethod(method);
|
|
2811
|
+
}
|
|
2812
|
+
/** switchMethod asks for the switch, and puts back what it cleared when the tool refuses. */
|
|
2813
|
+
async switchMethod(method) {
|
|
2814
|
+
const epoch = this.subjectEpoch;
|
|
2815
|
+
const held = {
|
|
2816
|
+
preview: this.previewFailure,
|
|
2817
|
+
save: this.saveFailure,
|
|
2818
|
+
source: this.sourceRefusal
|
|
2819
|
+
};
|
|
2820
|
+
const answer = this.ask("studio.zone.setCreateMethod", { method });
|
|
2821
|
+
this.saveFailure = null;
|
|
2822
|
+
this.sourceRefusal = null;
|
|
2823
|
+
this.previewFailure = null;
|
|
2824
|
+
this.reconcile();
|
|
2825
|
+
const result = await answer;
|
|
2826
|
+
if (result?.ok === true || this.disposed || epoch !== this.subjectEpoch) {
|
|
2827
|
+
return;
|
|
2828
|
+
}
|
|
2829
|
+
this.saveFailure ??= held.save;
|
|
2830
|
+
this.sourceRefusal ??= held.source;
|
|
2831
|
+
this.previewFailure ??= held.preview;
|
|
2832
|
+
this.reconcile();
|
|
2833
|
+
}
|
|
2834
|
+
/**
|
|
2835
|
+
* beginOriginPick arms the map for the click that places a reachability zone's origin, through
|
|
2836
|
+
* `studio.zone.beginOriginPick`.
|
|
2837
|
+
*
|
|
2838
|
+
* A refusal is kept as the snapshot's `pickFailure`, for as long as the form answers for the
|
|
2839
|
+
* create or the zone the pick was asked for and no later pick was asked.
|
|
2840
|
+
*
|
|
2841
|
+
* A call while parked, or after {@link ZoneFormEngine.dispose}, does nothing.
|
|
2842
|
+
*/
|
|
2843
|
+
beginOriginPick() {
|
|
2844
|
+
if (this.parked || this.disposed) {
|
|
2845
|
+
return;
|
|
2846
|
+
}
|
|
2847
|
+
this.touched = true;
|
|
2848
|
+
this.pickFailure = null;
|
|
2849
|
+
this.reconcile();
|
|
2850
|
+
void this.pick();
|
|
2851
|
+
}
|
|
2852
|
+
/** pick asks for the origin pick, and keeps a refusal while it is the latest and its form's. */
|
|
2853
|
+
async pick() {
|
|
2854
|
+
const epoch = this.subjectEpoch;
|
|
2855
|
+
this.pickSerial += 1;
|
|
2856
|
+
const asked = this.pickSerial;
|
|
2857
|
+
const result = await this.ask("studio.zone.beginOriginPick", {});
|
|
2858
|
+
if (result === null || result.ok || this.disposed || epoch !== this.subjectEpoch || asked !== this.pickSerial) {
|
|
2859
|
+
return;
|
|
2860
|
+
}
|
|
2861
|
+
this.pickFailure = result;
|
|
2862
|
+
this.reconcile();
|
|
2863
|
+
}
|
|
2864
|
+
/**
|
|
2865
|
+
* beginDraw arms the map to draw a new zone, through `studio.zone.editBegin`, in the form's
|
|
2866
|
+
* shape and severity and under its organization. The zone's id is minted by the `ids` seam: a
|
|
2867
|
+
* zone cannot persist empty, so the draw session needs a handle before there is a zone to name.
|
|
2868
|
+
*
|
|
2869
|
+
* A refusal is kept as the snapshot's `drawFailure`, for as long as the form answers for the
|
|
2870
|
+
* create the draw was asked for.
|
|
2871
|
+
*
|
|
2872
|
+
* It does nothing while a zone is bound, while a draw or a reshape is armed, while an earlier
|
|
2873
|
+
* call is still unanswered, while no shape is chosen, while parked, or after
|
|
2874
|
+
* {@link ZoneFormEngine.dispose}.
|
|
2875
|
+
*/
|
|
2876
|
+
beginDraw() {
|
|
2877
|
+
if (this.parked || this.disposed || this.drawing) {
|
|
2878
|
+
return;
|
|
2879
|
+
}
|
|
2880
|
+
const facts = factsOf(this.ui.getState());
|
|
2881
|
+
const { createLevel, createMode, organizationId } = this.draft;
|
|
2882
|
+
if (facts.zone !== null || facts.session !== null || createMode === null) {
|
|
2883
|
+
return;
|
|
2884
|
+
}
|
|
2885
|
+
this.drawing = true;
|
|
2886
|
+
this.drawFailure = null;
|
|
2887
|
+
this.reconcile();
|
|
2888
|
+
void this.draw({
|
|
2889
|
+
intent: "create",
|
|
2890
|
+
level: createLevel,
|
|
2891
|
+
mode: createMode,
|
|
2892
|
+
organizationId: organizationId ?? void 0,
|
|
2893
|
+
zoneId: this.ids.next()
|
|
2894
|
+
});
|
|
2895
|
+
}
|
|
2896
|
+
/** draw asks for the draw session, and keeps a refusal while its create is the form's. */
|
|
2897
|
+
async draw(input) {
|
|
2898
|
+
const epoch = this.subjectEpoch;
|
|
2899
|
+
const result = await this.ask("studio.zone.editBegin", input);
|
|
2900
|
+
if (result !== null && !result.ok && !this.disposed && epoch === this.subjectEpoch) {
|
|
2901
|
+
this.drawFailure = result;
|
|
2902
|
+
}
|
|
2903
|
+
this.drawing = false;
|
|
2904
|
+
this.reconcile();
|
|
2905
|
+
}
|
|
2906
|
+
/**
|
|
2907
|
+
* save persists the form through the one tool call {@link zoneSaveRequest} routes it to, and
|
|
2908
|
+
* resolves once the tool has answered. It resolves at once, having sent nothing, when a save
|
|
2909
|
+
* of the same zone or the same create is already in flight, when the form has nothing to
|
|
2910
|
+
* send, while parked, and after {@link ZoneFormEngine.dispose}. A save in flight for another
|
|
2911
|
+
* zone holds back no save of this one.
|
|
2912
|
+
*
|
|
2913
|
+
* A refusal is kept as the snapshot's `saveFailure` and the fields stay as typed, so a retry is
|
|
2914
|
+
* one more call. A refusal that lands once the form answers for another zone, or once a create
|
|
2915
|
+
* has switched method or changed the itinerary it inherits from, is dropped: it describes a
|
|
2916
|
+
* form nobody is looking at. One that lands once the form has come back to the zone or the
|
|
2917
|
+
* create it was sent for is kept, since the snapshot read `saving` for it all along. A refusal
|
|
2918
|
+
* of the reachability query the fields stated as the save left is kept as the snapshot's
|
|
2919
|
+
* `sourceFailure` instead, for the surface to show at the query's fields. A create
|
|
2920
|
+
* that lost some of its collections raises a warning through `studio.alert.show`: the zone
|
|
2921
|
+
* exists, and the reader should know where it was not filed.
|
|
2922
|
+
*
|
|
2923
|
+
* It never rejects while `dispatch` does not.
|
|
2924
|
+
*/
|
|
2925
|
+
async save() {
|
|
2926
|
+
const { subject } = this;
|
|
2927
|
+
if (this.parked || this.disposed || subject === null || this.saving.has(subject)) {
|
|
2928
|
+
return;
|
|
2929
|
+
}
|
|
2930
|
+
this.saveFailure = null;
|
|
2931
|
+
this.sourceRefusal = null;
|
|
2932
|
+
const request = this.saveRequest();
|
|
2933
|
+
if (request === null) {
|
|
2934
|
+
this.reconcile();
|
|
2935
|
+
return;
|
|
2936
|
+
}
|
|
2937
|
+
const query = queryKeyOf(this.statedSource());
|
|
2938
|
+
this.saving.add(subject);
|
|
2939
|
+
this.reconcile();
|
|
2940
|
+
try {
|
|
2941
|
+
const result = await this.run(request);
|
|
2942
|
+
if (this.disposed) {
|
|
2943
|
+
return;
|
|
2944
|
+
}
|
|
2945
|
+
if (!result.ok) {
|
|
2946
|
+
if (subject !== this.subject) {
|
|
2947
|
+
return;
|
|
2948
|
+
}
|
|
2949
|
+
if (query !== null && chunkDZJHTWSF_cjs.zoneSourceRefused(result)) {
|
|
2950
|
+
this.sourceRefusal = { failure: result, query };
|
|
2951
|
+
} else {
|
|
2952
|
+
this.saveFailure = result;
|
|
2953
|
+
}
|
|
2954
|
+
return;
|
|
2955
|
+
}
|
|
2956
|
+
const failed = result.data !== void 0 && "failedCollectionIds" in result.data ? result.data.failedCollectionIds : [];
|
|
2957
|
+
if (failed.length > 0) {
|
|
2958
|
+
void this.ask("studio.alert.show", {
|
|
2959
|
+
level: "warning",
|
|
2960
|
+
message: this.config.strings.zoneForm.collectionAttachWarning(failed.length)
|
|
2961
|
+
});
|
|
2962
|
+
}
|
|
2963
|
+
} finally {
|
|
2964
|
+
this.saving.delete(subject);
|
|
2965
|
+
this.reconcile();
|
|
2966
|
+
}
|
|
2967
|
+
}
|
|
2968
|
+
/** run dispatches a save request, each arm with its own tool's input. */
|
|
2969
|
+
run(request) {
|
|
2970
|
+
switch (request.name) {
|
|
2971
|
+
case "studio.zone.create":
|
|
2972
|
+
return this.config.dispatch(request.name, request.input);
|
|
2973
|
+
case "studio.zone.editCommit":
|
|
2974
|
+
return this.config.dispatch(request.name, request.input);
|
|
2975
|
+
case "studio.zone.update":
|
|
2976
|
+
return this.config.dispatch(request.name, request.input);
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
/** saveRequest routes the form as it stands to the tool call that persists it, or to null. */
|
|
2980
|
+
saveRequest() {
|
|
2981
|
+
const facts = factsOf(this.ui.getState());
|
|
2982
|
+
const { fields, method } = this.snapshot;
|
|
2983
|
+
const { zone } = facts;
|
|
2984
|
+
return chunkEKZWV6RS_cjs.zoneSaveRequest({
|
|
2985
|
+
canEdit: zone === null || chunkEKZWV6RS_cjs.canEditOwnedResource(
|
|
2986
|
+
{ createdById: zone.created_by.id, organizationId: zone.organization_id },
|
|
2987
|
+
this.config.userId,
|
|
2988
|
+
this.config.writableOrganizationIds
|
|
2989
|
+
),
|
|
2990
|
+
fields,
|
|
2991
|
+
method,
|
|
2992
|
+
session: facts.session,
|
|
2993
|
+
source: this.sourceFor(facts, method),
|
|
2994
|
+
zone
|
|
2995
|
+
});
|
|
2996
|
+
}
|
|
2997
|
+
/** statedSource is the reachability query the fields state as the store stands, or null. */
|
|
2998
|
+
statedSource() {
|
|
2999
|
+
return this.sourceFor(factsOf(this.ui.getState()), this.snapshot.method);
|
|
3000
|
+
}
|
|
3001
|
+
/**
|
|
3002
|
+
* publishUnsaved writes whether the form holds something unsaved on the store's
|
|
3003
|
+
* `zoneFormUnsaved`, where `studio.zone.publish` and the publication band read it, when that
|
|
3004
|
+
* answer moved. A parked engine writes nothing: its reads run inside a render, and a form
|
|
3005
|
+
* nobody watches holds nothing for anyone to lose.
|
|
3006
|
+
*
|
|
3007
|
+
* The store hears of the write at once, and so does this engine's own watch, which finds no slot
|
|
3008
|
+
* it reads moved and runs no pass.
|
|
3009
|
+
*/
|
|
3010
|
+
publishUnsaved(unsaved) {
|
|
3011
|
+
if (this.parked || this.disposed || unsaved === this.unsavedWritten) {
|
|
3012
|
+
return;
|
|
3013
|
+
}
|
|
3014
|
+
this.unsavedWritten = unsaved;
|
|
3015
|
+
this.ui.getState().setZoneFormUnsaved(unsaved);
|
|
3016
|
+
}
|
|
3017
|
+
/**
|
|
3018
|
+
* park stops watching the store, drops the pending preview and forgets the one in flight. The
|
|
3019
|
+
* unsaved answer it wrote is taken back: a form that unmounts holds nothing any more.
|
|
3020
|
+
*/
|
|
3021
|
+
park() {
|
|
3022
|
+
if (this.unsavedWritten) {
|
|
3023
|
+
this.unsavedWritten = false;
|
|
3024
|
+
this.ui.getState().setZoneFormUnsaved(false);
|
|
3025
|
+
}
|
|
3026
|
+
this.parked = true;
|
|
3027
|
+
this.unwatch?.();
|
|
3028
|
+
this.unwatch = null;
|
|
3029
|
+
this.cancelPending();
|
|
3030
|
+
this.previewKey = void 0;
|
|
3031
|
+
this.previewInput = null;
|
|
3032
|
+
this.previewEpoch += 1;
|
|
3033
|
+
}
|
|
3034
|
+
/** settle brings a parked engine's snapshot in line with the store and the configuration. */
|
|
3035
|
+
settle() {
|
|
3036
|
+
if (this.disposed || !this.parked) {
|
|
3037
|
+
return;
|
|
3038
|
+
}
|
|
3039
|
+
const { settled } = this;
|
|
3040
|
+
if (settled !== null && settled.config === this.config && readsSame(settled.state, this.ui.getState())) {
|
|
3041
|
+
return;
|
|
3042
|
+
}
|
|
3043
|
+
this.reconcile();
|
|
3044
|
+
}
|
|
3045
|
+
/**
|
|
3046
|
+
* watch answers one notification of the store: it runs a pass when a slot the form reads
|
|
3047
|
+
* moved, and nothing otherwise, so a hover or a selection costs the form one comparison.
|
|
3048
|
+
*/
|
|
3049
|
+
watch(state) {
|
|
3050
|
+
const { settled } = this;
|
|
3051
|
+
if (settled !== null && settled.config === this.config && readsSame(settled.state, state)) {
|
|
3052
|
+
this.settled = { config: settled.config, state };
|
|
3053
|
+
return;
|
|
3054
|
+
}
|
|
3055
|
+
this.reconcile();
|
|
3056
|
+
}
|
|
3057
|
+
/**
|
|
3058
|
+
* reconcile seeds the fields from the store and the configuration, publishes the snapshot and
|
|
3059
|
+
* follows the preview it is worth. A change made while it runs, by a listener or by a tool a
|
|
3060
|
+
* preview runs at once, runs it again once it finishes rather than inside it.
|
|
3061
|
+
*/
|
|
3062
|
+
reconcile() {
|
|
3063
|
+
if (this.disposed) {
|
|
3064
|
+
return;
|
|
3065
|
+
}
|
|
3066
|
+
if (this.reconciling) {
|
|
3067
|
+
this.stale = true;
|
|
3068
|
+
return;
|
|
3069
|
+
}
|
|
3070
|
+
this.reconciling = true;
|
|
3071
|
+
try {
|
|
3072
|
+
do {
|
|
3073
|
+
this.stale = false;
|
|
3074
|
+
const state = this.ui.getState();
|
|
3075
|
+
this.settled = { config: this.config, state };
|
|
3076
|
+
const facts = factsOf(state);
|
|
3077
|
+
this.seed(facts);
|
|
3078
|
+
const view = this.view(facts);
|
|
3079
|
+
this.commit(view.snapshot);
|
|
3080
|
+
this.publishUnsaved(view.changed);
|
|
3081
|
+
this.followPreview(view);
|
|
3082
|
+
} while (this.stale && !this.disposed);
|
|
3083
|
+
} finally {
|
|
3084
|
+
this.reconciling = false;
|
|
3085
|
+
}
|
|
3086
|
+
}
|
|
3087
|
+
/** seed brings the fields in line with the bound zone, the create's context and the catalog. */
|
|
3088
|
+
seed(facts) {
|
|
3089
|
+
const { draft } = this;
|
|
3090
|
+
const { activities, defaultOrganizationId, inheritedCollectionIds } = this.config;
|
|
3091
|
+
const { inherited, zone } = facts;
|
|
3092
|
+
const previous = this.bound;
|
|
3093
|
+
if (zone !== previous) {
|
|
3094
|
+
this.bound = zone;
|
|
3095
|
+
if (zone !== null && previous != null && previous.id === zone.id) {
|
|
3096
|
+
this.follow(previous, zone, facts.session);
|
|
3097
|
+
} else {
|
|
3098
|
+
this.seedMetadata(zone);
|
|
3099
|
+
}
|
|
3100
|
+
} else if (zone === null && facts.createSerial !== this.createSerial) {
|
|
3101
|
+
this.seedMetadata(null);
|
|
3102
|
+
}
|
|
3103
|
+
this.createSerial = zone === null ? facts.createSerial : void 0;
|
|
3104
|
+
const create = zone === null ? `${facts.createSerial}:${inherited?.itineraryId ?? ""}` : void 0;
|
|
3105
|
+
const subject = zone === null ? `create:${facts.createMethod ?? chunkIDBXFBLG_cjs.DEFAULT_ZONE_CREATE_METHOD}:${create ?? ""}` : `zone:${zone.id}`;
|
|
3106
|
+
if (subject !== this.subject) {
|
|
3107
|
+
this.subject = subject;
|
|
3108
|
+
this.touched = false;
|
|
3109
|
+
this.drawFailure = null;
|
|
3110
|
+
this.pickFailure = null;
|
|
3111
|
+
this.saveFailure = null;
|
|
3112
|
+
this.sourceRefusal = null;
|
|
3113
|
+
this.previewFailure = null;
|
|
3114
|
+
this.subjectEpoch += 1;
|
|
3115
|
+
this.previewEpoch += 1;
|
|
3116
|
+
}
|
|
3117
|
+
if (facts.origin !== this.origin) {
|
|
3118
|
+
this.origin = facts.origin;
|
|
3119
|
+
this.pickFailure = null;
|
|
3120
|
+
}
|
|
3121
|
+
if (facts.session !== null) {
|
|
3122
|
+
this.drawFailure = null;
|
|
3123
|
+
}
|
|
3124
|
+
if (create !== this.create) {
|
|
3125
|
+
this.create = create;
|
|
3126
|
+
if (create !== void 0) {
|
|
3127
|
+
this.resetCreate();
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
this.seedParameters(zone);
|
|
3131
|
+
if (zone !== null) {
|
|
3132
|
+
return;
|
|
3133
|
+
}
|
|
3134
|
+
if (inherited) {
|
|
3135
|
+
draft.organizationId = inherited.organizationId;
|
|
3136
|
+
if (!sameIds(draft.collectionIds, inheritedCollectionIds)) {
|
|
3137
|
+
draft.collectionIds = [...inheritedCollectionIds];
|
|
3138
|
+
}
|
|
3139
|
+
if (activities.length > 0) {
|
|
3140
|
+
draft.activityId = inherited.activityId;
|
|
3141
|
+
}
|
|
3142
|
+
} else {
|
|
3143
|
+
if (draft.organizationId === null && !this.organizationChosen) {
|
|
3144
|
+
draft.organizationId = defaultOrganizationId;
|
|
3145
|
+
}
|
|
3146
|
+
if (draft.activityId === null && activities.length > 0) {
|
|
3147
|
+
draft.activityId = chunkEKZWV6RS_cjs.firstRoutableActivityId(activities);
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
if (!this.nameTouched) {
|
|
3151
|
+
const name = chunkEKZWV6RS_cjs.zoneAutoName({
|
|
3152
|
+
activityName: this.activityName(),
|
|
3153
|
+
language: this.config.language,
|
|
3154
|
+
method: facts.createMethod ?? chunkIDBXFBLG_cjs.DEFAULT_ZONE_CREATE_METHOD,
|
|
3155
|
+
proposedName: facts.session?.name ?? null,
|
|
3156
|
+
range: draft.range,
|
|
3157
|
+
rangeType: draft.rangeType,
|
|
3158
|
+
strings: this.config.strings.zoneForm
|
|
3159
|
+
});
|
|
3160
|
+
if (name !== null) {
|
|
3161
|
+
draft.name = name;
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
}
|
|
3165
|
+
/**
|
|
3166
|
+
* seedParameters brings the reachability parameters in line with the query `zone` is stored
|
|
3167
|
+
* with and with the catalog, and drops an activity the catalog lists no more.
|
|
3168
|
+
*/
|
|
3169
|
+
seedParameters(zone) {
|
|
3170
|
+
const { draft } = this;
|
|
3171
|
+
const { activities } = this.config;
|
|
3172
|
+
const seeded = this.sourceSeed;
|
|
3173
|
+
if (seeded?.zone !== zone || seeded.activities !== activities) {
|
|
3174
|
+
this.sourceSeed = { activities, zone };
|
|
3175
|
+
const source = zone?.source;
|
|
3176
|
+
if (source) {
|
|
3177
|
+
const says = chunkEKZWV6RS_cjs.parametersOf(activities, source);
|
|
3178
|
+
const earlier = seeded?.zone?.id === zone?.id ? seeded?.zone?.source : void 0;
|
|
3179
|
+
if (seeded && earlier && draft.activityId === chunkEKZWV6RS_cjs.activityIdForSlug(seeded.activities, earlier.activity)) {
|
|
3180
|
+
draft.activityId = chunkEKZWV6RS_cjs.activityIdForSlug(activities, earlier.activity);
|
|
3181
|
+
}
|
|
3182
|
+
const said = earlier ? chunkEKZWV6RS_cjs.parametersOf(activities, earlier) : null;
|
|
3183
|
+
const held = {
|
|
3184
|
+
activityId: draft.activityId,
|
|
3185
|
+
range: draft.range,
|
|
3186
|
+
rangeType: draft.rangeType,
|
|
3187
|
+
speedKmh: draft.speedKmh
|
|
3188
|
+
};
|
|
3189
|
+
if (said === null || sameMembers(held, said) || sameMembers(held, says)) {
|
|
3190
|
+
draft.activityId = says.activityId;
|
|
3191
|
+
draft.rangeType = says.rangeType;
|
|
3192
|
+
draft.range = says.range;
|
|
3193
|
+
draft.speedKmh = says.speedKmh;
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
}
|
|
3197
|
+
if (draft.activityId !== null && activities.length > 0 && chunkEKZWV6RS_cjs.activityForId(activities, draft.activityId) === null) {
|
|
3198
|
+
const stored = zone?.source?.activity;
|
|
3199
|
+
draft.activityId = stored === void 0 ? null : chunkEKZWV6RS_cjs.activityIdForSlug(activities, stored);
|
|
3200
|
+
}
|
|
3201
|
+
}
|
|
3202
|
+
/**
|
|
3203
|
+
* seedMetadata seeds what a zone says from `zone`, and from a create's defaults for none: the
|
|
3204
|
+
* name, the description, the window and the severity.
|
|
3205
|
+
*/
|
|
3206
|
+
seedMetadata(zone) {
|
|
3207
|
+
const { draft } = this;
|
|
3208
|
+
draft.name = zone?.name ?? "";
|
|
3209
|
+
draft.description = zone?.description ?? "";
|
|
3210
|
+
draft.startAt = zone?.start_at ?? null;
|
|
3211
|
+
draft.endAt = zone?.end_at ?? null;
|
|
3212
|
+
draft.windowOpen = draft.startAt !== null || draft.endAt !== null;
|
|
3213
|
+
draft.createLevel = zone?.level ?? chunkIDBXFBLG_cjs.DEFAULT_ZONE_LEVEL;
|
|
3214
|
+
this.nameTouched = zone !== null;
|
|
3215
|
+
}
|
|
3216
|
+
/**
|
|
3217
|
+
* follow brings the fields in line with the bound zone written again: `previous` is what it
|
|
3218
|
+
* said and `next` what it says now.
|
|
3219
|
+
*
|
|
3220
|
+
* A field the reader has not moved off what the zone said takes what it says now, and so does
|
|
3221
|
+
* one that already says it, which is how the reader's own save lands in its stored spelling.
|
|
3222
|
+
* Any other is what the reader typed and has not saved, and stays. The window is one answer,
|
|
3223
|
+
* its bounds and whether it is open, taken whole from the reader once they moved any of it,
|
|
3224
|
+
* so no bound a collaborator chose is ever paired with one the reader did.
|
|
3225
|
+
*
|
|
3226
|
+
* The severity of a reshape armed on the zone is shown over the form's own, so it follows by
|
|
3227
|
+
* the same rule: while `session` still paints the severity the zone said, it is set to the one
|
|
3228
|
+
* the zone says now, through `studio.zone.setLevel`. One the reader moved is theirs and stays.
|
|
3229
|
+
* Left as it was, the form would read unsaved after a collaborator's change of severity, and
|
|
3230
|
+
* its save would write the old one back.
|
|
3231
|
+
*/
|
|
3232
|
+
follow(previous, next, session) {
|
|
3233
|
+
const { draft } = this;
|
|
3234
|
+
if (session !== null && session.zoneId === next.id && session.level === previous.level && next.level !== previous.level) {
|
|
3235
|
+
void this.ask("studio.zone.setLevel", { level: next.level });
|
|
3236
|
+
}
|
|
3237
|
+
if (!chunkEKZWV6RS_cjs.typedOver("name", draft.name, previous, next)) {
|
|
3238
|
+
draft.name = next.name;
|
|
3239
|
+
}
|
|
3240
|
+
if (!chunkEKZWV6RS_cjs.typedOver("description", draft.description, previous, next)) {
|
|
3241
|
+
draft.description = next.description ?? "";
|
|
3242
|
+
}
|
|
3243
|
+
if (!chunkEKZWV6RS_cjs.typedOver("level", draft.createLevel, previous, next)) {
|
|
3244
|
+
draft.createLevel = next.level;
|
|
3245
|
+
}
|
|
3246
|
+
const windowTyped = chunkEKZWV6RS_cjs.typedOver("startAt", draft.startAt, previous, next) || chunkEKZWV6RS_cjs.typedOver("endAt", draft.endAt, previous, next) || draft.windowOpen !== chunkEKZWV6RS_cjs.windowOpens(previous) && draft.windowOpen !== chunkEKZWV6RS_cjs.windowOpens(next);
|
|
3247
|
+
if (!windowTyped) {
|
|
3248
|
+
draft.startAt = next.start_at;
|
|
3249
|
+
draft.endAt = next.end_at;
|
|
3250
|
+
draft.windowOpen = chunkEKZWV6RS_cjs.windowOpens(next);
|
|
3251
|
+
}
|
|
3252
|
+
}
|
|
3253
|
+
/**
|
|
3254
|
+
* resetCreate returns the fields a create seeds for itself to a create's defaults: where it is
|
|
3255
|
+
* filed, the shape it is drawn in and the parameters it is computed from. What the zone says
|
|
3256
|
+
* is seeded from the zone, bound or not.
|
|
3257
|
+
*/
|
|
3258
|
+
resetCreate() {
|
|
3259
|
+
const { draft } = this;
|
|
3260
|
+
this.organizationChosen = false;
|
|
3261
|
+
draft.activityId = null;
|
|
3262
|
+
if (draft.collectionIds.length > 0) {
|
|
3263
|
+
draft.collectionIds = [];
|
|
3264
|
+
}
|
|
3265
|
+
draft.createMode = chunkIDBXFBLG_cjs.DEFAULT_ZONE_MODE;
|
|
3266
|
+
draft.organizationId = null;
|
|
3267
|
+
draft.range = chunkEKZWV6RS_cjs.ZONE_DEFAULT_DISTANCE_RANGE_METERS;
|
|
3268
|
+
draft.rangeType = "distance";
|
|
3269
|
+
draft.speedKmh = null;
|
|
3270
|
+
}
|
|
3271
|
+
/** activityName is the chosen activity's name in the reader's language, or null. */
|
|
3272
|
+
activityName() {
|
|
3273
|
+
const { activityId } = this.draft;
|
|
3274
|
+
const activity = activityId === null ? null : chunkEKZWV6RS_cjs.activityForId(this.config.activities, activityId);
|
|
3275
|
+
return activity ? i18n.localizedName(activity, this.config.language) : null;
|
|
3276
|
+
}
|
|
3277
|
+
/** sourceFor is the reachability query the fields state under `facts`, or null. */
|
|
3278
|
+
sourceFor(facts, method) {
|
|
3279
|
+
const { activityId, range, rangeType, speedKmh } = this.draft;
|
|
3280
|
+
const activity = activityId === null ? null : chunkEKZWV6RS_cjs.activityForId(this.config.activities, activityId);
|
|
3281
|
+
return chunkEKZWV6RS_cjs.zoneSourceQuery({
|
|
3282
|
+
activitySlug: activity?.slug ?? null,
|
|
3283
|
+
method,
|
|
3284
|
+
origin: facts.origin,
|
|
3285
|
+
range,
|
|
3286
|
+
rangeType,
|
|
3287
|
+
speedKmh
|
|
3288
|
+
});
|
|
3289
|
+
}
|
|
3290
|
+
/** view reads the form as it stands under `facts`. */
|
|
3291
|
+
view(facts) {
|
|
3292
|
+
const { draft } = this;
|
|
3293
|
+
const { session, zone } = facts;
|
|
3294
|
+
const method = zone === null ? facts.createMethod ?? chunkIDBXFBLG_cjs.DEFAULT_ZONE_CREATE_METHOD : zone.source ? "reachability" : "draw";
|
|
3295
|
+
const fields = {
|
|
3296
|
+
activityId: draft.activityId,
|
|
3297
|
+
collectionIds: draft.collectionIds,
|
|
3298
|
+
description: draft.description,
|
|
3299
|
+
endAt: draft.endAt,
|
|
3300
|
+
// An armed session carries the severity the draft is painted in.
|
|
3301
|
+
level: session?.level ?? draft.createLevel,
|
|
3302
|
+
mode: zone === null ? session?.mode ?? draft.createMode : zone.mode,
|
|
3303
|
+
// A create's draft a proposal named is shown under that name, and under the form's own
|
|
3304
|
+
// where none did or its reader typed over it.
|
|
3305
|
+
name: zone === null ? session?.name ?? draft.name : draft.name,
|
|
3306
|
+
// A create's session carries the organization it is filed under, a proposal's included.
|
|
3307
|
+
organizationId: zone === null ? session?.organizationId ?? draft.organizationId : draft.organizationId,
|
|
3308
|
+
range: draft.range,
|
|
3309
|
+
rangeType: draft.rangeType,
|
|
3310
|
+
speedKmh: draft.speedKmh,
|
|
3311
|
+
startAt: draft.startAt,
|
|
3312
|
+
windowOpen: draft.windowOpen
|
|
3313
|
+
};
|
|
3314
|
+
const source = this.sourceFor(facts, method);
|
|
3315
|
+
const armed = session !== null;
|
|
3316
|
+
const metadataDirty = zone !== null && chunkEKZWV6RS_cjs.isZoneMetadataDirty(fields, zone);
|
|
3317
|
+
const sourceDirty = zone !== null && chunkEKZWV6RS_cjs.isZoneSourceDirty(source, zone.source);
|
|
3318
|
+
const { descriptionValid, nameValid } = this.judge(fields.name, fields.description);
|
|
3319
|
+
const saving = this.subject !== null && this.saving.has(this.subject);
|
|
3320
|
+
const windowValid = !chunkEKZWV6RS_cjs.isZoneWindowInvalid(fields.startAt, fields.endAt);
|
|
3321
|
+
const reachabilityCreate = zone === null && method === "reachability";
|
|
3322
|
+
const previewFailure = source === null ? null : this.previewFailure;
|
|
3323
|
+
const refused = this.sourceRefusal;
|
|
3324
|
+
const sourceFailure = refused !== null && refused.query === queryKeyOf(source) ? refused.failure : null;
|
|
3325
|
+
const unsaved = zone === null ? reachabilityCreate ? source !== null && previewFailure === null : chunkEKZWV6RS_cjs.isZoneGeometryDirty(session) : chunkEKZWV6RS_cjs.isZoneGeometryDirty(session) || metadataDirty || sourceDirty;
|
|
3326
|
+
const changed = reachabilityCreate ? unsaved && this.touched : unsaved;
|
|
3327
|
+
const preview = source === null ? null : {
|
|
3328
|
+
activity: source.activity,
|
|
3329
|
+
level: fields.level,
|
|
3330
|
+
location: source.location,
|
|
3331
|
+
ranges: [source.range],
|
|
3332
|
+
rangeType: source.range_type,
|
|
3333
|
+
speed: source.speed
|
|
3334
|
+
};
|
|
3335
|
+
return {
|
|
3336
|
+
preview,
|
|
3337
|
+
previewKey: preview === null ? null : JSON.stringify(preview),
|
|
3338
|
+
snapshot: {
|
|
3339
|
+
armed,
|
|
3340
|
+
descriptionValid,
|
|
3341
|
+
drawFailure: this.drawFailure,
|
|
3342
|
+
fields,
|
|
3343
|
+
inherits: facts.inherited !== null,
|
|
3344
|
+
method,
|
|
3345
|
+
nameValid,
|
|
3346
|
+
pickFailure: this.pickFailure,
|
|
3347
|
+
previewFailure,
|
|
3348
|
+
saveFailure: this.saveFailure,
|
|
3349
|
+
saveOffered: reachabilityCreate || armed || metadataDirty || sourceDirty,
|
|
3350
|
+
saveReady: !saving && nameValid && descriptionValid && windowValid && unsaved,
|
|
3351
|
+
saving,
|
|
3352
|
+
sourceFailure,
|
|
3353
|
+
windowValid,
|
|
3354
|
+
zoneId: zone?.id ?? null
|
|
3355
|
+
},
|
|
3356
|
+
changed
|
|
3357
|
+
};
|
|
3358
|
+
}
|
|
3359
|
+
/**
|
|
3360
|
+
* judge holds a name and a description to the bounds the tools hold them to. It parses only a
|
|
3361
|
+
* text it has not just judged, so a pass that moved neither, a drag's every frame among them,
|
|
3362
|
+
* parses nothing.
|
|
3363
|
+
*/
|
|
3364
|
+
judge(name, description) {
|
|
3365
|
+
const last = this.judged;
|
|
3366
|
+
if (last !== null && last.name === name && last.description === description) {
|
|
3367
|
+
return last;
|
|
3368
|
+
}
|
|
3369
|
+
const judged = {
|
|
3370
|
+
description,
|
|
3371
|
+
descriptionValid: chunkIDBXFBLG_cjs.zoneDescriptionSchema.safeParse(description).success,
|
|
3372
|
+
name,
|
|
3373
|
+
nameValid: chunkIDBXFBLG_cjs.zoneNameSchema.safeParse(name).success
|
|
3374
|
+
};
|
|
3375
|
+
this.judged = judged;
|
|
3376
|
+
return judged;
|
|
3377
|
+
}
|
|
3378
|
+
/** commit publishes `next` when it differs from the snapshot, and tells every listener. */
|
|
3379
|
+
commit(next) {
|
|
3380
|
+
const fields = sameMembers(this.snapshot.fields, next.fields) ? this.snapshot.fields : next.fields;
|
|
3381
|
+
const snapshot = { ...next, fields };
|
|
3382
|
+
if (sameMembers(this.snapshot, snapshot)) {
|
|
3383
|
+
return;
|
|
3384
|
+
}
|
|
3385
|
+
this.snapshot = snapshot;
|
|
3386
|
+
chunkPACIO4NS_cjs.notifyListeners(Array.from(this.subscriptions, (subscription) => subscription.listener));
|
|
3387
|
+
}
|
|
3388
|
+
/**
|
|
3389
|
+
* followPreview asks for the preview `view` is worth, after the debounce, unless that very
|
|
3390
|
+
* preview is already asked for or waited on. A parked engine asks for none.
|
|
3391
|
+
*/
|
|
3392
|
+
followPreview(view) {
|
|
3393
|
+
if (this.parked || view.previewKey === this.previewKey) {
|
|
3394
|
+
return;
|
|
3395
|
+
}
|
|
3396
|
+
this.cancelPending();
|
|
3397
|
+
this.previewKey = view.previewKey;
|
|
3398
|
+
this.previewInput = view.preview;
|
|
3399
|
+
this.previewEpoch += 1;
|
|
3400
|
+
if (view.preview === null) {
|
|
3401
|
+
this.previewFailure = null;
|
|
3402
|
+
return;
|
|
3403
|
+
}
|
|
3404
|
+
if (this.debounceMs === 0) {
|
|
3405
|
+
this.askPreview();
|
|
3406
|
+
return;
|
|
3407
|
+
}
|
|
3408
|
+
this.timer = setTimeout(() => {
|
|
3409
|
+
this.timer = null;
|
|
3410
|
+
this.askPreview();
|
|
3411
|
+
}, this.debounceMs);
|
|
3412
|
+
}
|
|
3413
|
+
/** askPreview runs the preview waited on, and keeps its answer while its question stands. */
|
|
3414
|
+
askPreview() {
|
|
3415
|
+
const input = this.previewInput;
|
|
3416
|
+
if (input === null) {
|
|
3417
|
+
return;
|
|
3418
|
+
}
|
|
3419
|
+
const epoch = this.previewEpoch;
|
|
3420
|
+
void this.ask("studio.zone.reachabilityPreview", input).then((result) => {
|
|
3421
|
+
if (result === null || epoch !== this.previewEpoch || this.parked) {
|
|
3422
|
+
return;
|
|
3423
|
+
}
|
|
3424
|
+
this.previewFailure = result.ok ? null : result;
|
|
3425
|
+
this.reconcile();
|
|
3426
|
+
});
|
|
3427
|
+
}
|
|
3428
|
+
cancelPending() {
|
|
3429
|
+
if (this.timer !== null) {
|
|
3430
|
+
clearTimeout(this.timer);
|
|
3431
|
+
this.timer = null;
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
};
|
|
3435
|
+
|
|
3436
|
+
exports.EmbedFramingEngine = EmbedFramingEngine;
|
|
3437
|
+
exports.EmbedReadyEngine = EmbedReadyEngine;
|
|
3438
|
+
exports.FRAMING_PAGE_SESSION_TIMEOUT_MS = FRAMING_PAGE_SESSION_TIMEOUT_MS;
|
|
3439
|
+
exports.ItineraryPaceEngine = ItineraryPaceEngine;
|
|
3440
|
+
exports.ProfileMarkerEngine = ProfileMarkerEngine;
|
|
3441
|
+
exports.SegmentDraftEngine = SegmentDraftEngine;
|
|
3442
|
+
exports.ShareLinkEngine = ShareLinkEngine;
|
|
3443
|
+
exports.ZoneFormEngine = ZoneFormEngine;
|
|
3444
|
+
exports.askFramingPageForSession = askFramingPageForSession;
|
|
3445
|
+
//# sourceMappingURL=index.cjs.map
|
|
3446
|
+
//# sourceMappingURL=index.cjs.map
|