@mountaya/studio 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/LICENCE.fr.txt +280 -0
- package/LICENSE.txt +262 -0
- package/README.md +917 -2
- package/dist/agent/index.cjs +2600 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +1237 -0
- package/dist/agent/index.d.ts +1237 -0
- package/dist/agent/index.js +2581 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/chunk-3Oi_Zrtm.js +9 -0
- package/dist/chunk-3Oi_Zrtm.js.map +1 -0
- package/dist/chunk-B18OPIu_.js +6 -0
- package/dist/chunk-B18OPIu_.js.map +1 -0
- package/dist/chunk-B5Uz3Qct.cjs +15 -0
- package/dist/chunk-B5Uz3Qct.cjs.map +1 -0
- package/dist/chunk-BBEJwkd3.d.cts +839 -0
- package/dist/chunk-BIEc_SkR.cjs +29 -0
- package/dist/chunk-BIEc_SkR.cjs.map +1 -0
- package/dist/chunk-BKMFOe-N.js +171 -0
- package/dist/chunk-BKMFOe-N.js.map +1 -0
- package/dist/chunk-BP4uy7E1.d.ts +11583 -0
- package/dist/chunk-BSHTsFiB.js +1403 -0
- package/dist/chunk-BSHTsFiB.js.map +1 -0
- package/dist/chunk-BTUUABGI.js +17 -0
- package/dist/chunk-BTUUABGI.js.map +1 -0
- package/dist/chunk-BaPiaz5X.cjs +115 -0
- package/dist/chunk-BaPiaz5X.cjs.map +1 -0
- package/dist/chunk-BeCVpkYr.cjs +542 -0
- package/dist/chunk-BeCVpkYr.cjs.map +1 -0
- package/dist/chunk-BgngsvK8.cjs +6202 -0
- package/dist/chunk-BgngsvK8.cjs.map +1 -0
- package/dist/chunk-BhInd7CJ.d.cts +253 -0
- package/dist/chunk-Bn6ZbxkS.cjs +27 -0
- package/dist/chunk-By9ZnkVI.js +60 -0
- package/dist/chunk-By9ZnkVI.js.map +1 -0
- package/dist/chunk-BzqPhxsz.cjs +367 -0
- package/dist/chunk-BzqPhxsz.cjs.map +1 -0
- package/dist/chunk-C2mMX81q.d.ts +443 -0
- package/dist/chunk-C2rr9Q0V.cjs +1402 -0
- package/dist/chunk-C2rr9Q0V.cjs.map +1 -0
- package/dist/chunk-CDJCbwIQ.d.cts +78 -0
- package/dist/chunk-CLGvBOVH.d.cts +1654 -0
- package/dist/chunk-COdw1dc6.d.ts +525 -0
- package/dist/chunk-CQCJnT2i.d.ts +511 -0
- package/dist/chunk-CSyHY67q.cjs +353 -0
- package/dist/chunk-CSyHY67q.cjs.map +1 -0
- package/dist/chunk-CiK1Iqrv.js +950 -0
- package/dist/chunk-CiK1Iqrv.js.map +1 -0
- package/dist/chunk-CmJBgSwZ.cjs +24 -0
- package/dist/chunk-CmJBgSwZ.cjs.map +1 -0
- package/dist/chunk-CnrsRK2u.cjs +83 -0
- package/dist/chunk-CnrsRK2u.cjs.map +1 -0
- package/dist/chunk-Co782_9r.js +326 -0
- package/dist/chunk-Co782_9r.js.map +1 -0
- package/dist/chunk-Csr3KDpZ.cjs +32 -0
- package/dist/chunk-Csr3KDpZ.cjs.map +1 -0
- package/dist/chunk-CwkmccXv.js +89 -0
- package/dist/chunk-CwkmccXv.js.map +1 -0
- package/dist/chunk-D0Q4iL9B.cjs +255 -0
- package/dist/chunk-D0Q4iL9B.cjs.map +1 -0
- package/dist/chunk-DFwiSzUS.cjs +72 -0
- package/dist/chunk-DFwiSzUS.cjs.map +1 -0
- package/dist/chunk-DIFayl2P.d.cts +443 -0
- package/dist/chunk-DIGF58ux.d.cts +525 -0
- package/dist/chunk-DKuuuld5.js +101 -0
- package/dist/chunk-DKuuuld5.js.map +1 -0
- package/dist/chunk-DMePkFEo.js +5054 -0
- package/dist/chunk-DMePkFEo.js.map +1 -0
- package/dist/chunk-DO5SIBgu.js +305 -0
- package/dist/chunk-DO5SIBgu.js.map +1 -0
- package/dist/chunk-DOQ_7eE5.d.ts +6662 -0
- package/dist/chunk-DThaaNeb.d.cts +15 -0
- package/dist/chunk-DThaaNeb.d.ts +15 -0
- package/dist/chunk-DUQzjUJy.d.ts +78 -0
- package/dist/chunk-DX37IPhV.cjs +1903 -0
- package/dist/chunk-DX37IPhV.cjs.map +1 -0
- package/dist/chunk-Damps5Tk.cjs +155 -0
- package/dist/chunk-Damps5Tk.cjs.map +1 -0
- package/dist/chunk-DbK5PhpJ.d.ts +1654 -0
- package/dist/chunk-De0vAASv.d.ts +253 -0
- package/dist/chunk-DhSZ7YZt.d.cts +6662 -0
- package/dist/chunk-DjEvqvPA.cjs +43 -0
- package/dist/chunk-DjEvqvPA.cjs.map +1 -0
- package/dist/chunk-DkwDzwvu.d.cts +121 -0
- package/dist/chunk-DkwDzwvu.d.ts +121 -0
- package/dist/chunk-Dmszv9If.js +71 -0
- package/dist/chunk-Dmszv9If.js.map +1 -0
- package/dist/chunk-Dp_ftNWY.d.cts +511 -0
- package/dist/chunk-DsHQySz0.js +31 -0
- package/dist/chunk-DsHQySz0.js.map +1 -0
- package/dist/chunk-DwoUyHHh.js +281 -0
- package/dist/chunk-DwoUyHHh.js.map +1 -0
- package/dist/chunk-IaIDQflj.d.cts +2315 -0
- package/dist/chunk-IaIDQflj.d.ts +2315 -0
- package/dist/chunk-cVXLsZfL.d.ts +839 -0
- package/dist/chunk-mIaCX9EJ.d.cts +11583 -0
- package/dist/chunk-nJQxbOwQ.cjs +8962 -0
- package/dist/chunk-nJQxbOwQ.cjs.map +1 -0
- package/dist/chunk-o9jaxhCO.js +8852 -0
- package/dist/chunk-o9jaxhCO.js.map +1 -0
- package/dist/chunk-p-Tt_Lwz.js +14 -0
- package/dist/chunk-p-Tt_Lwz.js.map +1 -0
- package/dist/engines/index.cjs +2091 -0
- package/dist/engines/index.cjs.map +1 -0
- package/dist/engines/index.d.cts +2176 -0
- package/dist/engines/index.d.ts +2176 -0
- package/dist/engines/index.js +2075 -0
- package/dist/engines/index.js.map +1 -0
- package/dist/handlers/index.cjs +53 -0
- package/dist/handlers/index.cjs.map +1 -0
- package/dist/handlers/index.d.cts +403 -0
- package/dist/handlers/index.d.ts +403 -0
- package/dist/handlers/index.js +33 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/index.cjs +3511 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +3033 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/index.cjs +510 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +296 -0
- package/dist/plugins/index.d.ts +296 -0
- package/dist/plugins/index.js +489 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/seams/index.cjs +89 -0
- package/dist/seams/index.cjs.map +1 -0
- package/dist/seams/index.d.cts +452 -0
- package/dist/seams/index.d.ts +452 -0
- package/dist/seams/index.js +49 -0
- package/dist/seams/index.js.map +1 -0
- package/dist/strings/fr/index.cjs +2135 -0
- package/dist/strings/fr/index.cjs.map +1 -0
- package/dist/strings/fr/index.d.cts +17 -0
- package/dist/strings/fr/index.d.ts +17 -0
- package/dist/strings/fr/index.js +2130 -0
- package/dist/strings/fr/index.js.map +1 -0
- package/dist/strings/index.cjs +2384 -0
- package/dist/strings/index.cjs.map +1 -0
- package/dist/strings/index.d.cts +3 -0
- package/dist/strings/index.d.ts +3 -0
- package/dist/strings/index.js +2353 -0
- package/dist/strings/index.js.map +1 -0
- package/dist/testing/index.cjs +230 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +246 -0
- package/dist/testing/index.d.ts +246 -0
- package/dist/testing/index.js +219 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/time/index.cjs +28 -0
- package/dist/time/index.cjs.map +1 -0
- package/dist/time/index.d.cts +41 -0
- package/dist/time/index.d.ts +41 -0
- package/dist/time/index.js +23 -0
- package/dist/time/index.js.map +1 -0
- package/package.json +224 -4
- package/src/agent/engines/agentThreads.ts +1601 -0
- package/src/agent/engines/directorChat.ts +500 -0
- package/src/agent/index.ts +67 -0
- package/src/agent/rules/agentEditLock.ts +115 -0
- package/src/agent/rules/agentErrorCopy.ts +44 -0
- package/src/agent/rules/copilotOrganization.ts +36 -0
- package/src/agent/rules/playbook.gen.ts +444 -0
- package/src/agent/rules/router.ts +518 -0
- package/src/agent/rules/stateDelta.ts +29 -0
- package/src/agent/rules/studioRouter.ts +123 -0
- package/src/agent/rules/surfaces.gen.ts +633 -0
- package/src/agent/rules/threadsUrl.ts +48 -0
- package/src/agent/rules/transcriptObserver.ts +90 -0
- package/src/agent/stores/agentThreads.ts +451 -0
- package/src/bus/contracts/noData.ts +18 -0
- package/src/bus/contracts/shared.ts +172 -0
- package/src/bus/contracts/studioTools.ts +224 -0
- package/src/bus/rules/bus.ts +857 -0
- package/src/bus/rules/confirmation.ts +22 -0
- package/src/bus/rules/defineRegistry.ts +24 -0
- package/src/bus/rules/errors.ts +401 -0
- package/src/bus/rules/handlerErrors.ts +103 -0
- package/src/bus/rules/handlerRegistry.ts +627 -0
- package/src/bus/rules/inputSchema.ts +232 -0
- package/src/bus/rules/invalidInput.ts +441 -0
- package/src/bus/rules/lateBoundTools.ts +100 -0
- package/src/bus/rules/studioRegistry.ts +324 -0
- package/src/bus/rules/studioToolBus.ts +73 -0
- package/src/bus/rules/types.ts +804 -0
- package/src/chrome/contracts/alert.ts +42 -0
- package/src/chrome/contracts/itinerary.ts +26 -0
- package/src/chrome/contracts/map.ts +23 -0
- package/src/chrome/contracts/overlay.ts +46 -0
- package/src/chrome/contracts/panel.ts +29 -0
- package/src/chrome/contracts/question.ts +52 -0
- package/src/chrome/contracts/selection.ts +26 -0
- package/src/chrome/contracts/sidenav.ts +23 -0
- package/src/chrome/contracts/snapshot.ts +319 -0
- package/src/chrome/contracts/state.ts +22 -0
- package/src/chrome/contracts/tabs.ts +56 -0
- package/src/chrome/handlers/alert.ts +91 -0
- package/src/chrome/handlers/introspection.ts +180 -0
- package/src/chrome/handlers/panels.ts +42 -0
- package/src/chrome/handlers/question.ts +24 -0
- package/src/chrome/handlers/sidenav.ts +116 -0
- package/src/chrome/handlers/snapshot.ts +451 -0
- package/src/chrome/handlers/stateDelta.ts +125 -0
- package/src/chrome/handlers/tabs.ts +143 -0
- package/src/chrome/handlers/timestamp.ts +19 -0
- package/src/chrome/rules/agentSelectors.ts +210 -0
- package/src/chrome/rules/mapAlert.ts +13 -0
- package/src/chrome/rules/question.ts +25 -0
- package/src/chrome/rules/tabs.ts +13 -0
- package/src/chrome/stores/activeDraftSession.ts +134 -0
- package/src/chrome/stores/chrome.ts +527 -0
- package/src/chrome/stores/uiStore.ts +575 -0
- package/src/collab/contracts/collab.ts +261 -0
- package/src/collab/handlers/collab.ts +468 -0
- package/src/collab/rules/toolNames.ts +33 -0
- package/src/collab/stores/collab.ts +899 -0
- package/src/collections/contracts/collection.ts +182 -0
- package/src/collections/handlers/collectionAttach.ts +141 -0
- package/src/collections/handlers/collections.ts +499 -0
- package/src/collections/handlers/heldCollection.ts +42 -0
- package/src/collections/handlers/restCollections.ts +386 -0
- package/src/collections/rules/collections.ts +138 -0
- package/src/collections/rules/entityCollections.ts +53 -0
- package/src/collections/stores/collections.ts +133 -0
- package/src/data/contracts/data.ts +233 -0
- package/src/data/contracts/itinerary.ts +71 -0
- package/src/data/handlers/activityResolve.ts +76 -0
- package/src/data/handlers/data.ts +200 -0
- package/src/data/handlers/graphql.ts +26 -0
- package/src/data/handlers/mutationSink.ts +1577 -0
- package/src/data/handlers/profile.ts +83 -0
- package/src/data/handlers/writeThrough.ts +417 -0
- package/src/data/rules/cache.ts +181 -0
- package/src/data/rules/dataTypes.ts +40 -0
- package/src/data/rules/keys.ts +106 -0
- package/src/data/rules/persistence.ts +1058 -0
- package/src/data/rules/requestBody.ts +43 -0
- package/src/data/rules/restErrors.ts +354 -0
- package/src/data/rules/sessionSurface.ts +156 -0
- package/src/data/rules/toolResultData.ts +73 -0
- package/src/data/rules/uuid.ts +24 -0
- package/src/edit/contracts/edit.ts +37 -0
- package/src/edit/contracts/itinerary.ts +57 -0
- package/src/edit/handlers/draftCommit.ts +257 -0
- package/src/edit/handlers/editDiscard.ts +34 -0
- package/src/edit/handlers/editLock.ts +949 -0
- package/src/edit/handlers/editor.ts +203 -0
- package/src/edit/handlers/formUnsaved.ts +24 -0
- package/src/edit/rules/draftMetadata.ts +117 -0
- package/src/edit/rules/editKeyboard.ts +222 -0
- package/src/edit/rules/editShortcuts.ts +102 -0
- package/src/edit/rules/editTooltip.ts +174 -0
- package/src/edit/rules/editorTaken.ts +49 -0
- package/src/edit/rules/history.ts +26 -0
- package/src/edit/rules/unsavedWork.ts +60 -0
- package/src/edit/stores/editorReservation.ts +70 -0
- package/src/edit/stores/formsUnsaved.ts +54 -0
- package/src/embed/contracts/embed.ts +48 -0
- package/src/embed/engines/embedFraming.ts +1329 -0
- package/src/embed/engines/embedReady.ts +353 -0
- package/src/embed/engines/framingPageSession.ts +169 -0
- package/src/embed/handlers/embed.ts +130 -0
- package/src/embed/rules/allowedDomains.ts +71 -0
- package/src/embed/rules/bridgeMessages.ts +224 -0
- package/src/embed/rules/defaults.ts +173 -0
- package/src/embed/rules/displaySeed.ts +115 -0
- package/src/embed/rules/embedAllowlist.ts +146 -0
- package/src/embed/rules/embedConstraints.ts +215 -0
- package/src/embed/rules/embedElements.ts +277 -0
- package/src/embed/rules/embedSectionFields.ts +126 -0
- package/src/embed/rules/embedSecurity.ts +116 -0
- package/src/embed/rules/fieldDependencies.ts +89 -0
- package/src/embed/rules/fieldOptions.ts +138 -0
- package/src/embed/rules/layerOptions.ts +161 -0
- package/src/embed/rules/readyProtocol.ts +66 -0
- package/src/embed/rules/safetyRules.ts +215 -0
- package/src/embed/rules/snippet.ts +531 -0
- package/src/embed/rules/tableCode.ts +270 -0
- package/src/embed/stores/embed.ts +60 -0
- package/src/embed/stores/embedContent.ts +77 -0
- package/src/engines/index.ts +81 -0
- package/src/handlers/index.ts +66 -0
- package/src/index.ts +1065 -0
- package/src/itinerary/contracts/itinerary.ts +705 -0
- package/src/itinerary/engines/itineraryPace.ts +612 -0
- package/src/itinerary/engines/profileMarker.ts +238 -0
- package/src/itinerary/handlers/importStaging.ts +352 -0
- package/src/itinerary/handlers/itinerary.ts +572 -0
- package/src/itinerary/handlers/itineraryDuplicate.ts +177 -0
- package/src/itinerary/handlers/itineraryExport.ts +117 -0
- package/src/itinerary/handlers/itineraryImport.ts +783 -0
- package/src/itinerary/handlers/itineraryPublish.ts +118 -0
- package/src/itinerary/handlers/itinerarySelection.ts +354 -0
- package/src/itinerary/handlers/itinerarySuggest.ts +1186 -0
- package/src/itinerary/handlers/itineraryUnpublish.ts +101 -0
- package/src/itinerary/handlers/publicationScope.ts +118 -0
- package/src/itinerary/handlers/restItineraries.ts +752 -0
- package/src/itinerary/handlers/restItineraryExport.ts +70 -0
- package/src/itinerary/handlers/restItineraryImport.ts +311 -0
- package/src/itinerary/handlers/restItineraryPace.ts +87 -0
- package/src/itinerary/handlers/restItineraryRecord.ts +36 -0
- package/src/itinerary/handlers/suggestParams.ts +379 -0
- package/src/itinerary/handlers/suggestStaging.ts +363 -0
- package/src/itinerary/handlers/surfaceOpen.ts +389 -0
- package/src/itinerary/rules/activity.ts +139 -0
- package/src/itinerary/rules/analysis.ts +42 -0
- package/src/itinerary/rules/ceiling.ts +49 -0
- package/src/itinerary/rules/createFlow.ts +107 -0
- package/src/itinerary/rules/densify.ts +440 -0
- package/src/itinerary/rules/draftSurface.ts +219 -0
- package/src/itinerary/rules/editorView.ts +83 -0
- package/src/itinerary/rules/export.ts +159 -0
- package/src/itinerary/rules/friendlyName.ts +77 -0
- package/src/itinerary/rules/import.ts +1050 -0
- package/src/itinerary/rules/importFiles.ts +140 -0
- package/src/itinerary/rules/importTotals.ts +77 -0
- package/src/itinerary/rules/liveSegment.ts +712 -0
- package/src/itinerary/rules/lngLat.ts +17 -0
- package/src/itinerary/rules/mapSync.ts +100 -0
- package/src/itinerary/rules/previewRender.ts +416 -0
- package/src/itinerary/rules/profileReadout.ts +216 -0
- package/src/itinerary/rules/routing.ts +707 -0
- package/src/itinerary/rules/suggest.ts +522 -0
- package/src/itinerary/rules/suggestionPreview.ts +119 -0
- package/src/itinerary/rules/view.ts +61 -0
- package/src/itinerary/stores/importSession.ts +319 -0
- package/src/itinerary/stores/itinerary.ts +331 -0
- package/src/itinerary/stores/itineraryDuplicate.ts +76 -0
- package/src/itinerary/stores/sessionIdentity.ts +43 -0
- package/src/itinerary/stores/suggestSession.ts +418 -0
- package/src/layers/contracts/itinerary.ts +46 -0
- package/src/layers/contracts/overlay.ts +132 -0
- package/src/layers/handlers/enrichment.ts +36 -0
- package/src/layers/handlers/overlay.ts +406 -0
- package/src/layers/handlers/restLayers.ts +94 -0
- package/src/layers/handlers/tiles.ts +25 -0
- package/src/layers/rules/layers.ts +212 -0
- package/src/layers/rules/overlayInstant.ts +12 -0
- package/src/layers/rules/reachabilityIcon.ts +18 -0
- package/src/layers/rules/readout.ts +102 -0
- package/src/layers/stores/layers.ts +262 -0
- package/src/map/contracts/contextmenu.ts +33 -0
- package/src/map/contracts/geolocate.ts +37 -0
- package/src/map/contracts/map.ts +146 -0
- package/src/map/contracts/streetview.ts +53 -0
- package/src/map/contracts/terrain.ts +152 -0
- package/src/map/handlers/contextMenu.ts +135 -0
- package/src/map/handlers/geolocate.ts +52 -0
- package/src/map/handlers/map.ts +391 -0
- package/src/map/handlers/streetview.ts +94 -0
- package/src/map/handlers/terrain.ts +663 -0
- package/src/map/rules/baseTerrain.ts +75 -0
- package/src/map/rules/clickTargets.ts +464 -0
- package/src/map/rules/constraints.ts +32 -0
- package/src/map/rules/contextMenuReadout.ts +67 -0
- package/src/map/rules/coordinates.ts +71 -0
- package/src/map/rules/itineraryFit.ts +8 -0
- package/src/map/rules/mapEvents.ts +64 -0
- package/src/map/rules/mapProjection.ts +476 -0
- package/src/map/rules/terrainReading.ts +62 -0
- package/src/plugins/contracts/ids.ts +66 -0
- package/src/plugins/contracts/plugin.ts +202 -0
- package/src/plugins/contracts/slots.ts +137 -0
- package/src/plugins/engines/studioPlugin.ts +1365 -0
- package/src/plugins/index.ts +111 -0
- package/src/plugins/rules/contributions.ts +152 -0
- package/src/plugins/rules/errors.ts +60 -0
- package/src/plugins/rules/ids.ts +42 -0
- package/src/plugins/rules/validation.ts +249 -0
- package/src/rules/listeners.ts +57 -0
- package/src/rules/origin.ts +13 -0
- package/src/rules/storeWrite.ts +37 -0
- package/src/rules/types.ts +136 -0
- package/src/seams/index.ts +79 -0
- package/src/seams/rules/clock.ts +28 -0
- package/src/seams/rules/formatters.ts +211 -0
- package/src/seams/rules/ids.ts +102 -0
- package/src/seams/rules/links.ts +66 -0
- package/src/seams/rules/navigation.ts +222 -0
- package/src/seams/rules/notify.ts +49 -0
- package/src/seams/rules/persistenceDrawer.ts +220 -0
- package/src/seams/rules/saveFile.ts +101 -0
- package/src/seams/rules/seams.ts +156 -0
- package/src/seams/rules/storage.ts +116 -0
- package/src/search/contracts/overlay.ts +74 -0
- package/src/search/contracts/search.ts +197 -0
- package/src/search/handlers/pois.ts +57 -0
- package/src/search/handlers/search.ts +280 -0
- package/src/search/rules/params.ts +925 -0
- package/src/search/rules/poiGroups.ts +138 -0
- package/src/search/rules/searchFetch.ts +139 -0
- package/src/search/rules/timeWindow.ts +30 -0
- package/src/search/stores/search.ts +51 -0
- package/src/segments/contracts/itinerary.ts +433 -0
- package/src/segments/contracts/segment.ts +35 -0
- package/src/segments/engines/segmentDraft.ts +926 -0
- package/src/segments/handlers/chainGuards.ts +67 -0
- package/src/segments/handlers/directions.ts +44 -0
- package/src/segments/handlers/itineraryEcho.ts +45 -0
- package/src/segments/handlers/roadAccessDialog.ts +34 -0
- package/src/segments/handlers/segment.ts +111 -0
- package/src/segments/handlers/segmentEdit.ts +1341 -0
- package/src/segments/handlers/segmentGroups.ts +347 -0
- package/src/segments/handlers/segmentStructure.ts +1144 -0
- package/src/segments/rules/chain.ts +196 -0
- package/src/segments/rules/chainModel.ts +217 -0
- package/src/segments/rules/colors.ts +11 -0
- package/src/segments/rules/commit.ts +76 -0
- package/src/segments/rules/draft.ts +90 -0
- package/src/segments/rules/draftDisposition.ts +43 -0
- package/src/segments/rules/draftSegmentEdit.ts +129 -0
- package/src/segments/rules/engine.ts +222 -0
- package/src/segments/rules/groupSave.ts +234 -0
- package/src/segments/rules/hazardPrompt.ts +60 -0
- package/src/segments/rules/itineraryEcho.ts +40 -0
- package/src/segments/rules/liveSegmentProjection.ts +55 -0
- package/src/segments/rules/merge.ts +51 -0
- package/src/segments/rules/metrics.ts +456 -0
- package/src/segments/rules/naming.ts +168 -0
- package/src/segments/rules/segmentArming.ts +144 -0
- package/src/segments/rules/splitPick.ts +84 -0
- package/src/segments/rules/viaSimplify.ts +230 -0
- package/src/segments/stores/directions.ts +77 -0
- package/src/segments/stores/roadAccessDialog.ts +58 -0
- package/src/segments/stores/segmentEdit.ts +922 -0
- package/src/segments/stores/segmentGroupEdit.ts +84 -0
- package/src/segments/stores/segmentSplit.ts +77 -0
- package/src/share/contracts/share.ts +39 -0
- package/src/share/contracts/shareLink.ts +63 -0
- package/src/share/engines/shareLink.ts +1053 -0
- package/src/share/handlers/share.ts +47 -0
- package/src/share/handlers/shareLink.ts +231 -0
- package/src/share/handlers/shareScope.ts +54 -0
- package/src/share/rules/link.ts +89 -0
- package/src/share/rules/shareLink.ts +218 -0
- package/src/share/rules/targets.ts +92 -0
- package/src/share/rules/viewConfig.ts +95 -0
- package/src/share/stores/share.ts +58 -0
- package/src/strings/fr/index.ts +18 -0
- package/src/strings/fr/rules/fr.ts +2368 -0
- package/src/strings/index.ts +98 -0
- package/src/strings/rules/confirmCopy.ts +156 -0
- package/src/strings/rules/draftToolNames.ts +94 -0
- package/src/strings/rules/en.ts +2519 -0
- package/src/strings/rules/failureAlert.ts +115 -0
- package/src/strings/rules/formError.ts +400 -0
- package/src/strings/rules/maneuvers.ts +107 -0
- package/src/strings/rules/outputOptions.ts +126 -0
- package/src/strings/rules/publicationState.ts +100 -0
- package/src/strings/rules/routeHazardCopy.ts +62 -0
- package/src/strings/rules/searchLabels.ts +50 -0
- package/src/strings/rules/segmentChainVerbs.ts +62 -0
- package/src/strings/rules/studioCopy.ts +130 -0
- package/src/strings/rules/unitOptions.ts +119 -0
- package/src/testing/checkedBus.ts +226 -0
- package/src/testing/index.ts +30 -0
- package/src/testing/plugins.ts +106 -0
- package/src/testing/studio.ts +267 -0
- package/src/testing/urlSeam.ts +153 -0
- package/src/time/index.ts +12 -0
- package/src/time/rules/sun.ts +78 -0
- package/src/video/contracts/cameraSchemas.ts +266 -0
- package/src/video/contracts/profileSchemas.ts +37 -0
- package/src/video/contracts/video.ts +601 -0
- package/src/video/handlers/video.ts +1638 -0
- package/src/video/handlers/videoDirector.ts +114 -0
- package/src/video/rules/previewRefresh.ts +76 -0
- package/src/video/rules/profileSource.ts +51 -0
- package/src/video/rules/routeSpans.ts +79 -0
- package/src/video/rules/shotDefaults.ts +28 -0
- package/src/video/rules/stepOrder.ts +17 -0
- package/src/video/rules/videoSnapshot.ts +136 -0
- package/src/video/stores/directorThreads.ts +167 -0
- package/src/video/stores/videoExport.ts +290 -0
- package/src/viewer/contracts/preferences.ts +40 -0
- package/src/viewer/handlers/preferences.ts +91 -0
- package/src/viewer/rules/capabilities.ts +42 -0
- package/src/viewer/rules/config.ts +266 -0
- package/src/viewer/rules/context.ts +375 -0
- package/src/viewer/rules/ownership.ts +134 -0
- package/src/viewer/rules/platformViewer.ts +199 -0
- package/src/viewer/rules/scope.ts +197 -0
- package/src/viewer/rules/url.ts +145 -0
- package/src/viewer/rules/viewer.ts +307 -0
- package/src/viewer/rules/viewerSeam.ts +49 -0
- package/src/viewer/rules/viewerUnits.ts +34 -0
- package/src/waypoints/contracts/itinerary.ts +417 -0
- package/src/waypoints/handlers/poiWaypointStyle.ts +32 -0
- package/src/waypoints/handlers/waypointDetailsDialog.ts +38 -0
- package/src/waypoints/handlers/waypointEdit.ts +1073 -0
- package/src/waypoints/rules/amenities.ts +30 -0
- package/src/waypoints/rules/defaults.ts +31 -0
- package/src/waypoints/rules/details.ts +213 -0
- package/src/waypoints/rules/detailsDraft.ts +312 -0
- package/src/waypoints/rules/detailsPreview.ts +76 -0
- package/src/waypoints/rules/detailsSave.ts +356 -0
- package/src/waypoints/rules/draftDirty.ts +45 -0
- package/src/waypoints/rules/icons.ts +32 -0
- package/src/waypoints/rules/liveWaypoint.ts +63 -0
- package/src/waypoints/rules/naming.ts +185 -0
- package/src/waypoints/rules/sections.ts +77 -0
- package/src/waypoints/rules/waypointDraft.ts +62 -0
- package/src/waypoints/stores/waypointDetails.ts +62 -0
- package/src/waypoints/stores/waypointEdit.ts +566 -0
- package/src/zones/contracts/collection.ts +37 -0
- package/src/zones/contracts/zone.ts +528 -0
- package/src/zones/engines/zoneForm.ts +1773 -0
- package/src/zones/handlers/restZones.ts +287 -0
- package/src/zones/handlers/zonePublish.ts +206 -0
- package/src/zones/handlers/zoneUnpublish.ts +56 -0
- package/src/zones/handlers/zones.ts +2254 -0
- package/src/zones/rules/geometry.ts +946 -0
- package/src/zones/rules/zoneDefaults.ts +34 -0
- package/src/zones/rules/zoneDraft.ts +54 -0
- package/src/zones/rules/zoneForm.ts +563 -0
- package/src/zones/rules/zoneMetadata.ts +29 -0
- package/src/zones/rules/zoneSource.ts +87 -0
- package/src/zones/rules/zoneSourceRefusal.ts +104 -0
- package/src/zones/stores/zoneEdit.ts +998 -0
|
@@ -0,0 +1,2075 @@
|
|
|
1
|
+
import { A as windowOpens, C as firstRoutableActivityId, D as isZoneWindowInvalid, E as isZoneSourceDirty, F as DEFAULT_ZONE_LEVEL, I as DEFAULT_ZONE_MODE, M as zoneSaveRequest, N as zoneSourceQuery, O as parametersOf, S as activityIdForSlug, T as isZoneMetadataDirty, a as tokenlessAnswerRefusal, b as ZONE_DEFAULT_TIME_RANGE_SECONDS, c as canEditOwnedResource, j as zoneAutoName, k as typedOver, n as isShareLinkDisableSettled, r as shareLinkActions, t as isRetryableShareLinkFailure, u as activityForId, w as isZoneGeometryDirty, y as ZONE_DEFAULT_DISTANCE_RANGE_METERS } from "../chunk-Co782_9r.js";
|
|
2
|
+
import { n as surfaceFault, t as notifyListeners } from "../chunk-BTUUABGI.js";
|
|
3
|
+
import { c as resolveFramedError, l as embedConstraintsFor, n as routeHazardConfirmation, o as EMBED_COVER_MAX_MS, r as draftChangeDisposition, s as buildReadyPayload, t as buildSegmentEditOptions, u as measuredCanvas } from "../chunk-DO5SIBgu.js";
|
|
4
|
+
import { R as REQUEST_SESSION_TOKEN_MESSAGE, Y as setSessionTokenMessageSchema, a as zoneDescriptionSchema, f as segmentEditSessionMark, m as synthesizeDraftSegment, o as zoneNameSchema, s as issuedShareTokenSchema, v as buildLiveSegment } from "../chunk-CiK1Iqrv.js";
|
|
5
|
+
import { r as isConfirmationWithheld } from "../chunk-p-Tt_Lwz.js";
|
|
6
|
+
import { a as failureFromThrown } from "../chunk-DKuuuld5.js";
|
|
7
|
+
import { t as layerToolContext } from "../chunk-3Oi_Zrtm.js";
|
|
8
|
+
import { n as zoneSourceRefused } from "../chunk-DsHQySz0.js";
|
|
9
|
+
import * as z$1 from "zod";
|
|
10
|
+
import { DIRECTIONS_VIA_MAX, boundsOf, buildSegmentGeometry } from "@mountaya/elements/geo";
|
|
11
|
+
import { segmentGeometries, segmentsForSelection } from "@mountaya/elements/data";
|
|
12
|
+
import { MountayaElementsError } from "@mountaya/elements/errors";
|
|
13
|
+
import { embedFitPadding } from "@mountaya/elements/profile";
|
|
14
|
+
import { localizedName } from "@mountaya/elements/i18n";
|
|
15
|
+
import { LIVE_SEGMENT_THROTTLE_MS, TrailingThrottle } from "@mountaya/elements/collab";
|
|
16
|
+
const baseMapContent = {
|
|
17
|
+
collectionId: null,
|
|
18
|
+
itineraryId: null
|
|
19
|
+
};
|
|
20
|
+
const sameContent = (a, b) => a.collectionId === b.collectionId && a.itineraryId === b.itineraryId;
|
|
21
|
+
const isBaseMap = (content) => sameContent(content, baseMapContent);
|
|
22
|
+
const collectionOf = (config) => config.fitCollection === void 0 ? null : config.collection ?? null;
|
|
23
|
+
const expectsCollectionOf = (config) => config.fitCollection !== void 0 && config.expectsCollection === true;
|
|
24
|
+
const expectsContent = (config) => config.expectsItinerary || expectsCollectionOf(config);
|
|
25
|
+
const contentOf = (config) => {
|
|
26
|
+
if (config.itinerary !== null) return {
|
|
27
|
+
collectionId: null,
|
|
28
|
+
itineraryId: config.itinerary.id
|
|
29
|
+
};
|
|
30
|
+
const collection = collectionOf(config);
|
|
31
|
+
return collection === null || config.expectsItinerary ? baseMapContent : {
|
|
32
|
+
collectionId: collection.id,
|
|
33
|
+
itineraryId: null
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const lockSizeOf = (config) => config.lockCanvasSize === void 0 ? config.canvasSize : config.lockCanvasSize;
|
|
37
|
+
const questionOf = (config, client) => ({
|
|
38
|
+
canvasHeight: config.canvasSize?.height ?? null,
|
|
39
|
+
canvasWidth: config.canvasSize?.width ?? null,
|
|
40
|
+
client,
|
|
41
|
+
collectionBounds: collectionOf(config)?.bounds ?? null,
|
|
42
|
+
collectionId: collectionOf(config)?.id ?? null,
|
|
43
|
+
expectsCollection: expectsCollectionOf(config),
|
|
44
|
+
expectsItinerary: config.expectsItinerary,
|
|
45
|
+
itinerary: config.itinerary,
|
|
46
|
+
lockHeight: lockSizeOf(config)?.height ?? null,
|
|
47
|
+
lockWidth: lockSizeOf(config)?.width ?? null,
|
|
48
|
+
measuredPanelHeight: config.measuredPanelHeight,
|
|
49
|
+
showAnalysis: config.sections.showAnalysis,
|
|
50
|
+
showCharacteristics: config.sections.showCharacteristics,
|
|
51
|
+
showElevation: config.sections.showElevation,
|
|
52
|
+
zoomMax: config.zoomRange.zoomMax,
|
|
53
|
+
zoomMin: config.zoomRange.zoomMin
|
|
54
|
+
});
|
|
55
|
+
const 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);
|
|
56
|
+
const sameSize = (a, b) => a === null || b === null ? a === b : Object.is(a.width, b.width) && Object.is(a.height, b.height);
|
|
57
|
+
const largestOf = (a, b) => {
|
|
58
|
+
const first = measuredCanvas(a);
|
|
59
|
+
const second = measuredCanvas(b);
|
|
60
|
+
if (first === null || second === null) return first ?? second;
|
|
61
|
+
return {
|
|
62
|
+
height: Math.max(first.height, second.height),
|
|
63
|
+
width: Math.max(first.width, second.width)
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
const laidOutAtNoArea = (size) => size !== null && Number.isFinite(size.width) && Number.isFinite(size.height) && (size.width <= 0 || size.height <= 0);
|
|
67
|
+
const isEmpty = (constraints) => constraints.maxBounds === void 0 && constraints.maxZoom === void 0 && constraints.minZoom === void 0;
|
|
68
|
+
const sameLock = (a, b) => a === null || a === void 0 || b === null || b === void 0 ? a === b : a.every((edge, index) => Object.is(edge, b[index]));
|
|
69
|
+
const 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));
|
|
70
|
+
const sameRange = (a, b) => Object.is(a.zoomMax, b.zoomMax) && Object.is(a.zoomMin, b.zoomMin);
|
|
71
|
+
var EmbedFramingEngine = class {
|
|
72
|
+
config;
|
|
73
|
+
snapshot;
|
|
74
|
+
listeners = /* @__PURE__ */ new Set();
|
|
75
|
+
framingClient = null;
|
|
76
|
+
asked = null;
|
|
77
|
+
pendingFit = null;
|
|
78
|
+
pendingReveal = null;
|
|
79
|
+
reported = false;
|
|
80
|
+
standing = null;
|
|
81
|
+
applied = {};
|
|
82
|
+
locked = false;
|
|
83
|
+
awaited;
|
|
84
|
+
configuredId;
|
|
85
|
+
parked = true;
|
|
86
|
+
disposed = false;
|
|
87
|
+
constructor(config) {
|
|
88
|
+
this.config = config;
|
|
89
|
+
const content = contentOf(config);
|
|
90
|
+
this.awaited = isBaseMap(content) && expectsContent(config);
|
|
91
|
+
this.configuredId = config.configuredItineraryId;
|
|
92
|
+
this.snapshot = {
|
|
93
|
+
bounds: null,
|
|
94
|
+
framed: false,
|
|
95
|
+
...content
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
getSnapshot() {
|
|
99
|
+
return this.snapshot;
|
|
100
|
+
}
|
|
101
|
+
subscribe(listener) {
|
|
102
|
+
if (this.disposed) return () => void 0;
|
|
103
|
+
const subscription = () => listener();
|
|
104
|
+
this.listeners.add(subscription);
|
|
105
|
+
if (this.parked) {
|
|
106
|
+
this.parked = false;
|
|
107
|
+
this.step();
|
|
108
|
+
}
|
|
109
|
+
return () => {
|
|
110
|
+
if (!this.listeners.delete(subscription) || this.listeners.size > 0 || this.parked) return;
|
|
111
|
+
this.parked = true;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
configure(config) {
|
|
115
|
+
if (this.disposed) return;
|
|
116
|
+
this.config = config;
|
|
117
|
+
if (config.client !== this.framingClient) this.restart(config.client);
|
|
118
|
+
const content = contentOf(config);
|
|
119
|
+
if (!sameContent(content, this.snapshot)) {
|
|
120
|
+
this.asked = null;
|
|
121
|
+
this.publish({
|
|
122
|
+
bounds: null,
|
|
123
|
+
framed: false,
|
|
124
|
+
...content
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const configuredId = config.configuredItineraryId;
|
|
128
|
+
const switched = configuredId !== void 0 && this.configuredId !== void 0 && configuredId !== this.configuredId;
|
|
129
|
+
this.configuredId = configuredId;
|
|
130
|
+
if (isBaseMap(content) && !this.awaited && (expectsContent(config) || switched)) {
|
|
131
|
+
this.awaited = true;
|
|
132
|
+
this.asked = null;
|
|
133
|
+
}
|
|
134
|
+
this.step();
|
|
135
|
+
}
|
|
136
|
+
dispose() {
|
|
137
|
+
if (this.disposed) return;
|
|
138
|
+
this.disposed = true;
|
|
139
|
+
this.parked = true;
|
|
140
|
+
this.pendingFit = null;
|
|
141
|
+
this.pendingReveal = null;
|
|
142
|
+
this.listeners.clear();
|
|
143
|
+
}
|
|
144
|
+
step() {
|
|
145
|
+
if (this.parked || this.disposed) return;
|
|
146
|
+
const { client } = this.config;
|
|
147
|
+
if (client !== this.framingClient) this.restart(client);
|
|
148
|
+
if (client === null) return;
|
|
149
|
+
const question = questionOf(this.config, client);
|
|
150
|
+
if (this.asked !== null && (sameQuestion(this.asked, question) || sameQuestion(this.asked, this.whileFitting(question)))) return;
|
|
151
|
+
this.asked = question;
|
|
152
|
+
this.frame(client, question);
|
|
153
|
+
}
|
|
154
|
+
whileFitting(question) {
|
|
155
|
+
const asked = this.asked;
|
|
156
|
+
if (asked === null || this.pendingFit === null || largestOf(this.config.canvasSize, lockSizeOf(this.config)) !== null) return question;
|
|
157
|
+
return {
|
|
158
|
+
...question,
|
|
159
|
+
canvasHeight: asked.canvasHeight,
|
|
160
|
+
canvasWidth: asked.canvasWidth,
|
|
161
|
+
lockHeight: asked.lockHeight,
|
|
162
|
+
lockWidth: asked.lockWidth
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
restart(client) {
|
|
166
|
+
this.framingClient = client;
|
|
167
|
+
this.asked = null;
|
|
168
|
+
this.pendingFit = null;
|
|
169
|
+
this.pendingReveal = null;
|
|
170
|
+
this.reported = false;
|
|
171
|
+
this.standing = null;
|
|
172
|
+
this.locked = false;
|
|
173
|
+
this.applied = {};
|
|
174
|
+
const content = contentOf(this.config);
|
|
175
|
+
if (this.snapshot.framed || !sameContent(this.snapshot, content)) this.publish({
|
|
176
|
+
bounds: null,
|
|
177
|
+
framed: false,
|
|
178
|
+
...content
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
frame(client, question) {
|
|
182
|
+
const { itinerary, zoomRange } = this.config;
|
|
183
|
+
const deferred = client.hadInitialViewHash();
|
|
184
|
+
const content = contentOf(this.config);
|
|
185
|
+
const collection = collectionOf(this.config);
|
|
186
|
+
if (isBaseMap(content)) {
|
|
187
|
+
this.pendingFit = null;
|
|
188
|
+
if (this.pendingReveal !== null && !isBaseMap(this.pendingReveal)) this.pendingReveal = null;
|
|
189
|
+
if (expectsContent(this.config)) this.awaitContent(client, deferred);
|
|
190
|
+
else this.showBaseMap(client);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
this.awaited = false;
|
|
194
|
+
if (this.pendingReveal !== null && isBaseMap(this.pendingReveal)) this.pendingReveal = null;
|
|
195
|
+
if (this.settledFor(content) || this.pendingReveal !== null && sameContent(this.pendingReveal, content)) {
|
|
196
|
+
this.rangeAgain(client, content);
|
|
197
|
+
this.lockAgain(client, content);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (!deferred && (this.unlaid() || this.resizing())) {
|
|
201
|
+
this.awaitResize(client);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const bounds = itinerary === null ? collection?.bounds ?? null : boundsOf(segmentGeometries(segmentsForSelection(itinerary, null)));
|
|
205
|
+
const padding = embedFitPadding({
|
|
206
|
+
showAnalysis: question.showAnalysis,
|
|
207
|
+
showCharacteristics: question.showCharacteristics,
|
|
208
|
+
showElevation: question.showElevation
|
|
209
|
+
}, question.measuredPanelHeight);
|
|
210
|
+
const framing = !deferred && bounds !== null ? client.cameraForBounds(bounds, padding, 13) : null;
|
|
211
|
+
const input = {
|
|
212
|
+
bounds,
|
|
213
|
+
canvasSize: largestOf(this.config.canvasSize, lockSizeOf(this.config)),
|
|
214
|
+
framing,
|
|
215
|
+
padding,
|
|
216
|
+
view: deferred ? client.getViewport() : null,
|
|
217
|
+
zoomRange
|
|
218
|
+
};
|
|
219
|
+
this.standing = {
|
|
220
|
+
content,
|
|
221
|
+
input
|
|
222
|
+
};
|
|
223
|
+
this.constrain(client, embedConstraintsFor(input));
|
|
224
|
+
if (deferred) {
|
|
225
|
+
this.revealWithoutFit(client, bounds, content);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const pending = {
|
|
229
|
+
bounds,
|
|
230
|
+
...content
|
|
231
|
+
};
|
|
232
|
+
this.pendingFit = pending;
|
|
233
|
+
(itinerary === null && collection !== null && this.config.fitCollection !== void 0 ? this.config.fitCollection(collection.bounds, padding, 13) : this.config.fit(padding)).then(() => client.waitForRender()).then(() => {
|
|
234
|
+
if (this.pendingFit !== pending) return;
|
|
235
|
+
this.pendingFit = null;
|
|
236
|
+
if (this.parked || this.disposed) {
|
|
237
|
+
this.asked = null;
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (this.resizing()) return;
|
|
241
|
+
if (this.asked !== question && this.unlaid()) {
|
|
242
|
+
this.asked = null;
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
this.settle(pending);
|
|
246
|
+
}, () => {
|
|
247
|
+
if (this.pendingFit === pending) this.pendingFit = null;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
resizing() {
|
|
251
|
+
const ahead = measuredCanvas(lockSizeOf(this.config));
|
|
252
|
+
return ahead !== null && !sameSize(ahead, measuredCanvas(this.config.canvasSize));
|
|
253
|
+
}
|
|
254
|
+
unlaid() {
|
|
255
|
+
const { canvasSize } = this.config;
|
|
256
|
+
const lockSize = lockSizeOf(this.config);
|
|
257
|
+
return largestOf(canvasSize, lockSize) === null && (laidOutAtNoArea(canvasSize) || laidOutAtNoArea(lockSize));
|
|
258
|
+
}
|
|
259
|
+
awaitResize(client) {
|
|
260
|
+
if (this.standing === null) this.constrain(client, this.zoomRangeAlone());
|
|
261
|
+
else {
|
|
262
|
+
this.rangeAgain(client, this.standing.content);
|
|
263
|
+
this.lockAgain(client, this.standing.content);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
awaitContent(client, deferred) {
|
|
267
|
+
if (this.standing === null) this.constrain(client, this.zoomRangeAlone());
|
|
268
|
+
else {
|
|
269
|
+
this.rangeAgain(client, this.standing.content);
|
|
270
|
+
this.lockAgain(client, this.standing.content);
|
|
271
|
+
}
|
|
272
|
+
if (deferred && !this.reported) this.revealWithoutFit(client, null, baseMapContent);
|
|
273
|
+
}
|
|
274
|
+
showBaseMap(client) {
|
|
275
|
+
this.standing = null;
|
|
276
|
+
this.constrain(client, this.zoomRangeAlone());
|
|
277
|
+
if (this.awaited) {
|
|
278
|
+
this.awaited = false;
|
|
279
|
+
if (this.snapshot.framed) this.publish({
|
|
280
|
+
bounds: null,
|
|
281
|
+
framed: false,
|
|
282
|
+
...baseMapContent
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
this.revealWithoutFit(client, null, baseMapContent);
|
|
286
|
+
}
|
|
287
|
+
zoomRangeAlone() {
|
|
288
|
+
return embedConstraintsFor({
|
|
289
|
+
bounds: null,
|
|
290
|
+
canvasSize: null,
|
|
291
|
+
framing: null,
|
|
292
|
+
padding: 0,
|
|
293
|
+
zoomRange: this.config.zoomRange
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
rangeAgain(client, content) {
|
|
297
|
+
const standing = this.standing;
|
|
298
|
+
const { zoomRange } = this.config;
|
|
299
|
+
if (standing === null || !sameContent(standing.content, content) || sameRange(standing.input.zoomRange, zoomRange)) return;
|
|
300
|
+
const input = {
|
|
301
|
+
...standing.input,
|
|
302
|
+
zoomRange
|
|
303
|
+
};
|
|
304
|
+
this.standing = {
|
|
305
|
+
content,
|
|
306
|
+
input
|
|
307
|
+
};
|
|
308
|
+
const { maxZoom, minZoom } = embedConstraintsFor(input);
|
|
309
|
+
this.apply(client, maxZoom !== void 0 && minZoom !== void 0 ? {
|
|
310
|
+
maxZoom,
|
|
311
|
+
minZoom
|
|
312
|
+
} : this.rangeRelease());
|
|
313
|
+
}
|
|
314
|
+
rangeRelease() {
|
|
315
|
+
const { maxZoom, minZoom } = this.applied;
|
|
316
|
+
return typeof maxZoom === "number" || typeof minZoom === "number" ? {
|
|
317
|
+
maxZoom: null,
|
|
318
|
+
minZoom: null
|
|
319
|
+
} : {};
|
|
320
|
+
}
|
|
321
|
+
lockAgain(client, content) {
|
|
322
|
+
const standing = this.standing;
|
|
323
|
+
if (standing === null || !sameContent(standing.content, content) || standing.input.bounds === null) return;
|
|
324
|
+
const sizedFor = measuredCanvas(standing.input.canvasSize);
|
|
325
|
+
const largest = largestOf(sizedFor, largestOf(this.config.canvasSize, lockSizeOf(this.config)));
|
|
326
|
+
if (largest === null || sameSize(sizedFor, largest)) return;
|
|
327
|
+
const input = {
|
|
328
|
+
...standing.input,
|
|
329
|
+
canvasSize: largest
|
|
330
|
+
};
|
|
331
|
+
this.standing = {
|
|
332
|
+
content,
|
|
333
|
+
input
|
|
334
|
+
};
|
|
335
|
+
const { maxBounds } = embedConstraintsFor(input);
|
|
336
|
+
if (maxBounds !== void 0) this.apply(client, { maxBounds });
|
|
337
|
+
}
|
|
338
|
+
constrain(client, decided) {
|
|
339
|
+
const ranged = decided.maxZoom === void 0 ? {
|
|
340
|
+
...decided,
|
|
341
|
+
...this.rangeRelease()
|
|
342
|
+
} : decided;
|
|
343
|
+
const constraints = ranged.maxBounds === void 0 && this.locked ? {
|
|
344
|
+
...ranged,
|
|
345
|
+
maxBounds: null
|
|
346
|
+
} : ranged;
|
|
347
|
+
this.apply(client, constraints);
|
|
348
|
+
if (constraints.maxBounds !== void 0) this.locked = constraints.maxBounds !== null;
|
|
349
|
+
}
|
|
350
|
+
apply(client, constraints) {
|
|
351
|
+
if (isEmpty(constraints) || standsAs(constraints, this.applied)) return;
|
|
352
|
+
client.setConstraints(constraints);
|
|
353
|
+
this.applied = {
|
|
354
|
+
...this.applied,
|
|
355
|
+
...constraints
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
revealWithoutFit(client, bounds, content) {
|
|
359
|
+
if (this.settledFor(content) || this.pendingReveal !== null && sameContent(this.pendingReveal, content)) return;
|
|
360
|
+
const pending = {
|
|
361
|
+
bounds,
|
|
362
|
+
...content
|
|
363
|
+
};
|
|
364
|
+
this.pendingReveal = pending;
|
|
365
|
+
client.waitForRender().then(() => {
|
|
366
|
+
if (this.pendingReveal !== pending) return;
|
|
367
|
+
this.pendingReveal = null;
|
|
368
|
+
if (this.parked || this.disposed) {
|
|
369
|
+
this.asked = null;
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
this.settle(pending);
|
|
373
|
+
}, () => {
|
|
374
|
+
if (this.pendingReveal === pending) this.pendingReveal = null;
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
settledFor(content) {
|
|
378
|
+
return this.snapshot.framed && sameContent(this.snapshot, content);
|
|
379
|
+
}
|
|
380
|
+
settle(pending) {
|
|
381
|
+
this.reported = true;
|
|
382
|
+
if (sameContent(pending, contentOf(this.config))) this.publish({
|
|
383
|
+
bounds: pending.bounds,
|
|
384
|
+
collectionId: pending.collectionId,
|
|
385
|
+
framed: true,
|
|
386
|
+
itineraryId: pending.itineraryId
|
|
387
|
+
});
|
|
388
|
+
try {
|
|
389
|
+
this.config.onFramed?.(pending.bounds);
|
|
390
|
+
} catch (fault) {
|
|
391
|
+
surfaceFault(fault);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
publish(snapshot) {
|
|
395
|
+
this.snapshot = snapshot;
|
|
396
|
+
notifyListeners(this.listeners);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
const MAX_TIMER_MS = 2 ** 31 - 1;
|
|
400
|
+
const coveredSnapshot = { covered: true };
|
|
401
|
+
const revealedSnapshot = { covered: false };
|
|
402
|
+
const timeoutFrom$1 = (timeoutMs) => {
|
|
403
|
+
if (timeoutMs === void 0) return EMBED_COVER_MAX_MS;
|
|
404
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 0 || timeoutMs > MAX_TIMER_MS) throw new MountayaElementsError(`EmbedReadyEngine: timeoutMs is ${String(timeoutMs)}; pass a number of milliseconds from 0 to ${MAX_TIMER_MS}, or omit it for ${EMBED_COVER_MAX_MS}.`);
|
|
405
|
+
return timeoutMs;
|
|
406
|
+
};
|
|
407
|
+
var EmbedReadyEngine = class {
|
|
408
|
+
config;
|
|
409
|
+
clock;
|
|
410
|
+
timeoutMs;
|
|
411
|
+
snapshot = coveredSnapshot;
|
|
412
|
+
listeners = /* @__PURE__ */ new Set();
|
|
413
|
+
deadline = null;
|
|
414
|
+
parked = true;
|
|
415
|
+
disposed = false;
|
|
416
|
+
constructor(options) {
|
|
417
|
+
const { clock, timeoutMs, ...config } = options;
|
|
418
|
+
this.clock = clock;
|
|
419
|
+
this.timeoutMs = timeoutFrom$1(timeoutMs);
|
|
420
|
+
this.config = config;
|
|
421
|
+
}
|
|
422
|
+
getSnapshot() {
|
|
423
|
+
return this.snapshot;
|
|
424
|
+
}
|
|
425
|
+
subscribe(listener) {
|
|
426
|
+
if (this.disposed) return () => void 0;
|
|
427
|
+
const subscription = () => listener();
|
|
428
|
+
this.listeners.add(subscription);
|
|
429
|
+
if (this.parked) {
|
|
430
|
+
this.parked = false;
|
|
431
|
+
this.arm();
|
|
432
|
+
}
|
|
433
|
+
return () => {
|
|
434
|
+
if (!this.listeners.delete(subscription) || this.listeners.size > 0 || this.parked) return;
|
|
435
|
+
this.parked = true;
|
|
436
|
+
this.disarm();
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
configure(config) {
|
|
440
|
+
if (!this.disposed) this.config = config;
|
|
441
|
+
}
|
|
442
|
+
settle(bounds) {
|
|
443
|
+
if (this.parked || this.disposed) return;
|
|
444
|
+
const { configuredItineraryId, itineraryFailed } = this.config;
|
|
445
|
+
this.disarm();
|
|
446
|
+
this.reveal();
|
|
447
|
+
this.post(bounds, resolveFramedError(configuredItineraryId, itineraryFailed));
|
|
448
|
+
}
|
|
449
|
+
dispose() {
|
|
450
|
+
if (this.disposed) return;
|
|
451
|
+
this.disposed = true;
|
|
452
|
+
this.parked = true;
|
|
453
|
+
this.disarm();
|
|
454
|
+
this.listeners.clear();
|
|
455
|
+
}
|
|
456
|
+
arm() {
|
|
457
|
+
if (!this.snapshot.covered || this.deadline !== null) return;
|
|
458
|
+
const deadline = { cancel: () => void 0 };
|
|
459
|
+
this.deadline = deadline;
|
|
460
|
+
deadline.cancel = this.clock.after(this.timeoutMs, () => {
|
|
461
|
+
if (this.deadline !== deadline) return;
|
|
462
|
+
this.deadline = null;
|
|
463
|
+
this.expire();
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
disarm() {
|
|
467
|
+
const deadline = this.deadline;
|
|
468
|
+
this.deadline = null;
|
|
469
|
+
deadline?.cancel();
|
|
470
|
+
}
|
|
471
|
+
expire() {
|
|
472
|
+
this.reveal();
|
|
473
|
+
this.post(null, "timeout");
|
|
474
|
+
}
|
|
475
|
+
post(bounds, error) {
|
|
476
|
+
const { activeItineraryId, activeTerrain, configTerrain, onReady } = this.config;
|
|
477
|
+
const payload = buildReadyPayload({
|
|
478
|
+
activeItineraryId,
|
|
479
|
+
activeTerrain,
|
|
480
|
+
bounds,
|
|
481
|
+
configTerrain,
|
|
482
|
+
error
|
|
483
|
+
});
|
|
484
|
+
try {
|
|
485
|
+
onReady?.(payload);
|
|
486
|
+
} catch (fault) {
|
|
487
|
+
surfaceFault(fault);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
reveal() {
|
|
491
|
+
if (this.snapshot === revealedSnapshot) return;
|
|
492
|
+
this.snapshot = revealedSnapshot;
|
|
493
|
+
notifyListeners(this.listeners);
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
const FRAMING_PAGE_SESSION_TIMEOUT_MS = 1e4;
|
|
497
|
+
const timeoutFrom = (timeoutMs) => {
|
|
498
|
+
if (timeoutMs === void 0) return FRAMING_PAGE_SESSION_TIMEOUT_MS;
|
|
499
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > MAX_TIMER_MS) throw new MountayaElementsError(`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}.`);
|
|
500
|
+
return timeoutMs;
|
|
501
|
+
};
|
|
502
|
+
const askFramingPageForSession = (options) => {
|
|
503
|
+
const timeoutMs = timeoutFrom(options.timeoutMs);
|
|
504
|
+
const { clock, embed } = options;
|
|
505
|
+
return new Promise((resolve, reject) => {
|
|
506
|
+
if (Object.is(embed.parent, embed)) {
|
|
507
|
+
reject(new MountayaElementsError("askFramingPageForSession: the embed is not framed, so no page can hand it a session token."));
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
let cancel = () => {};
|
|
511
|
+
const listener = (event) => {
|
|
512
|
+
if (event.source !== embed.parent) return;
|
|
513
|
+
const parsed = setSessionTokenMessageSchema.safeParse(event.data);
|
|
514
|
+
if (!parsed.success) return;
|
|
515
|
+
cancel();
|
|
516
|
+
embed.removeEventListener("message", listener);
|
|
517
|
+
resolve({
|
|
518
|
+
expires_at: new Date(parsed.data.expiresAt),
|
|
519
|
+
token: parsed.data.token,
|
|
520
|
+
user_id: null
|
|
521
|
+
});
|
|
522
|
+
};
|
|
523
|
+
embed.addEventListener("message", listener);
|
|
524
|
+
cancel = clock.after(timeoutMs, () => {
|
|
525
|
+
embed.removeEventListener("message", listener);
|
|
526
|
+
reject(new MountayaElementsError(`askFramingPageForSession: the framing page answered no session token within ${timeoutMs} ms.`));
|
|
527
|
+
});
|
|
528
|
+
embed.parent.postMessage({ type: REQUEST_SESSION_TOKEN_MESSAGE }, "*");
|
|
529
|
+
});
|
|
530
|
+
};
|
|
531
|
+
const fetchItineraryPace = async (client, itineraryId, { signal, speedKmh, surface }) => {
|
|
532
|
+
const params = {
|
|
533
|
+
itinerary_id: itineraryId,
|
|
534
|
+
query: {
|
|
535
|
+
speed: speedKmh,
|
|
536
|
+
...surface === void 0 ? {} : { surface }
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
const { data } = await (signal === void 0 ? client.studio.itineraries.getItineraryPace(params) : client.studio.itineraries.getItineraryPace(params, { signal }));
|
|
540
|
+
return {
|
|
541
|
+
bySegmentId: new Map(data.segments.map((segment) => [segment.id, segment])),
|
|
542
|
+
durationSeconds: data.duration
|
|
543
|
+
};
|
|
544
|
+
};
|
|
545
|
+
const PACE_DEBOUNCE_MS = 250;
|
|
546
|
+
const isRateStep = (shown, next) => shown !== null && shown.client === next.client && shown.itineraryId === next.itineraryId && shown.revision === next.revision && shown.surface === next.surface;
|
|
547
|
+
const revisionKey = (revision) => `${typeof revision}\0${revision ?? ""}`;
|
|
548
|
+
const paceKey = (itineraryId, speedKmh, surface, revision) => [
|
|
549
|
+
itineraryId,
|
|
550
|
+
speedKmh,
|
|
551
|
+
surface ?? "",
|
|
552
|
+
revision
|
|
553
|
+
].join("\0");
|
|
554
|
+
const debounceFrom$1 = (debounceMs) => {
|
|
555
|
+
if (debounceMs === void 0) return PACE_DEBOUNCE_MS;
|
|
556
|
+
if (!Number.isFinite(debounceMs) || debounceMs < 0 || debounceMs > MAX_TIMER_MS) throw new MountayaElementsError(`ItineraryPaceEngine: debounceMs is ${String(debounceMs)}; pass a number of milliseconds from 0 to ${MAX_TIMER_MS}, or omit it for ${PACE_DEBOUNCE_MS}.`);
|
|
557
|
+
return debounceMs;
|
|
558
|
+
};
|
|
559
|
+
var ItineraryPaceEngine = class {
|
|
560
|
+
config;
|
|
561
|
+
debounceMs;
|
|
562
|
+
snapshot = null;
|
|
563
|
+
shown = null;
|
|
564
|
+
listeners = /* @__PURE__ */ new Set();
|
|
565
|
+
answers = /* @__PURE__ */ new Map();
|
|
566
|
+
inFlight = null;
|
|
567
|
+
timer = null;
|
|
568
|
+
parked = true;
|
|
569
|
+
disposed = false;
|
|
570
|
+
constructor(options) {
|
|
571
|
+
const { debounceMs, ...config } = options;
|
|
572
|
+
this.debounceMs = debounceFrom$1(debounceMs);
|
|
573
|
+
this.config = config;
|
|
574
|
+
}
|
|
575
|
+
getSnapshot() {
|
|
576
|
+
return this.snapshot;
|
|
577
|
+
}
|
|
578
|
+
subscribe(listener) {
|
|
579
|
+
if (this.disposed) return () => void 0;
|
|
580
|
+
this.listeners.add(listener);
|
|
581
|
+
if (this.parked) {
|
|
582
|
+
this.parked = false;
|
|
583
|
+
this.schedule();
|
|
584
|
+
}
|
|
585
|
+
return () => {
|
|
586
|
+
this.listeners.delete(listener);
|
|
587
|
+
if (this.listeners.size > 0 || this.parked) return;
|
|
588
|
+
this.parked = true;
|
|
589
|
+
this.cancelPending();
|
|
590
|
+
this.abandon(null);
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
configure(config) {
|
|
594
|
+
if (this.disposed) return;
|
|
595
|
+
const before = this.request()?.key ?? null;
|
|
596
|
+
const replacesClient = config.client !== this.config.client;
|
|
597
|
+
this.config = config;
|
|
598
|
+
if (replacesClient) {
|
|
599
|
+
this.answers.clear();
|
|
600
|
+
this.abandon(null);
|
|
601
|
+
}
|
|
602
|
+
const request = this.request();
|
|
603
|
+
if (request !== null) this.forgetOtherRevisions(request);
|
|
604
|
+
if (replacesClient || (request?.key ?? null) !== before) this.schedule();
|
|
605
|
+
}
|
|
606
|
+
dispose() {
|
|
607
|
+
if (this.disposed) return;
|
|
608
|
+
this.disposed = true;
|
|
609
|
+
this.parked = true;
|
|
610
|
+
this.cancelPending();
|
|
611
|
+
this.abandon(null);
|
|
612
|
+
this.listeners.clear();
|
|
613
|
+
}
|
|
614
|
+
request() {
|
|
615
|
+
const { client, itineraryId, speedKmh, surface } = this.config;
|
|
616
|
+
if (client === void 0 || !itineraryId || speedKmh === null) return null;
|
|
617
|
+
const revision = revisionKey(this.config.revision);
|
|
618
|
+
return {
|
|
619
|
+
client,
|
|
620
|
+
itineraryId,
|
|
621
|
+
key: paceKey(itineraryId, speedKmh, surface, revision),
|
|
622
|
+
revision,
|
|
623
|
+
speedKmh,
|
|
624
|
+
surface
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
readKept(key) {
|
|
628
|
+
const kept = this.answers.get(key);
|
|
629
|
+
if (kept !== void 0) {
|
|
630
|
+
this.answers.delete(key);
|
|
631
|
+
this.answers.set(key, kept);
|
|
632
|
+
}
|
|
633
|
+
return kept;
|
|
634
|
+
}
|
|
635
|
+
keep(key, kept) {
|
|
636
|
+
this.answers.delete(key);
|
|
637
|
+
this.answers.set(key, kept);
|
|
638
|
+
for (const oldest of this.answers.keys()) {
|
|
639
|
+
if (this.answers.size <= 32) break;
|
|
640
|
+
this.answers.delete(oldest);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
forgetOtherRevisions(request) {
|
|
644
|
+
for (const [key, kept] of this.answers) if (kept.itineraryId === request.itineraryId && kept.revision !== request.revision) this.answers.delete(key);
|
|
645
|
+
}
|
|
646
|
+
schedule() {
|
|
647
|
+
this.cancelPending();
|
|
648
|
+
if (this.disposed) return;
|
|
649
|
+
const request = this.request();
|
|
650
|
+
this.abandon(request?.key ?? null);
|
|
651
|
+
if (request === null) {
|
|
652
|
+
this.commit(null, null);
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
const kept = this.readKept(request.key);
|
|
656
|
+
if (kept !== void 0) {
|
|
657
|
+
this.commit(kept.answer, request);
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
if (!isRateStep(this.shown, request)) this.commit(null, null);
|
|
661
|
+
if (this.parked) return;
|
|
662
|
+
if (this.debounceMs === 0) {
|
|
663
|
+
this.ask(request);
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
this.timer = setTimeout(() => {
|
|
667
|
+
this.timer = null;
|
|
668
|
+
const current = this.request();
|
|
669
|
+
if (current !== null) this.ask(current);
|
|
670
|
+
}, this.debounceMs);
|
|
671
|
+
}
|
|
672
|
+
ask(request) {
|
|
673
|
+
const kept = this.readKept(request.key);
|
|
674
|
+
if (kept !== void 0) {
|
|
675
|
+
this.commit(kept.answer, request);
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
if (this.inFlight?.key === request.key) return;
|
|
679
|
+
const inFlight = {
|
|
680
|
+
controller: new AbortController(),
|
|
681
|
+
key: request.key
|
|
682
|
+
};
|
|
683
|
+
this.inFlight = inFlight;
|
|
684
|
+
fetchItineraryPace(request.client, request.itineraryId, {
|
|
685
|
+
signal: inFlight.controller.signal,
|
|
686
|
+
speedKmh: request.speedKmh,
|
|
687
|
+
surface: request.surface
|
|
688
|
+
}).then((answer) => {
|
|
689
|
+
if (!this.settle(inFlight)) return;
|
|
690
|
+
this.keep(request.key, {
|
|
691
|
+
answer,
|
|
692
|
+
itineraryId: request.itineraryId,
|
|
693
|
+
revision: request.revision
|
|
694
|
+
});
|
|
695
|
+
if (this.isLive(request.key)) this.commit(answer, request);
|
|
696
|
+
}, () => {
|
|
697
|
+
if (this.settle(inFlight) && this.isLive(request.key)) this.commit(null, null);
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
settle(inFlight) {
|
|
701
|
+
if (this.inFlight === inFlight) this.inFlight = null;
|
|
702
|
+
return !inFlight.controller.signal.aborted;
|
|
703
|
+
}
|
|
704
|
+
abandon(keep) {
|
|
705
|
+
if (this.inFlight === null || this.inFlight.key === keep) return;
|
|
706
|
+
this.inFlight.controller.abort();
|
|
707
|
+
this.inFlight = null;
|
|
708
|
+
}
|
|
709
|
+
isLive(key) {
|
|
710
|
+
return !this.parked && !this.disposed && this.request()?.key === key;
|
|
711
|
+
}
|
|
712
|
+
cancelPending() {
|
|
713
|
+
if (this.timer !== null) {
|
|
714
|
+
clearTimeout(this.timer);
|
|
715
|
+
this.timer = null;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
commit(snapshot, answers) {
|
|
719
|
+
if (this.disposed) return;
|
|
720
|
+
this.shown = snapshot === null ? null : answers;
|
|
721
|
+
if (snapshot === this.snapshot) return;
|
|
722
|
+
this.snapshot = snapshot;
|
|
723
|
+
notifyListeners(this.listeners);
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
const throttleFrom$1 = (throttleMs) => {
|
|
727
|
+
if (throttleMs === void 0) return 60;
|
|
728
|
+
if (!Number.isFinite(throttleMs) || throttleMs < 0 || throttleMs > MAX_TIMER_MS) throw new MountayaElementsError(`ProfileMarkerEngine: throttleMs is ${String(throttleMs)}; pass a number of milliseconds from 0 to ${MAX_TIMER_MS}, or omit it for 60.`);
|
|
729
|
+
return throttleMs;
|
|
730
|
+
};
|
|
731
|
+
var ProfileMarkerEngine = class {
|
|
732
|
+
throttleMs;
|
|
733
|
+
listeners = /* @__PURE__ */ new Set();
|
|
734
|
+
resting = null;
|
|
735
|
+
held = null;
|
|
736
|
+
timer = null;
|
|
737
|
+
disposed = false;
|
|
738
|
+
constructor(options = {}) {
|
|
739
|
+
this.throttleMs = throttleFrom$1(options.throttleMs);
|
|
740
|
+
}
|
|
741
|
+
getSnapshot = () => this.resting;
|
|
742
|
+
subscribe = (listener) => {
|
|
743
|
+
if (this.disposed) return () => {};
|
|
744
|
+
this.listeners.add(listener);
|
|
745
|
+
return () => {
|
|
746
|
+
this.listeners.delete(listener);
|
|
747
|
+
if (this.listeners.size === 0) this.endWindow();
|
|
748
|
+
};
|
|
749
|
+
};
|
|
750
|
+
hover(point) {
|
|
751
|
+
if (this.disposed) return;
|
|
752
|
+
if (point === null) {
|
|
753
|
+
this.endWindow();
|
|
754
|
+
this.rest(null);
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
if (this.timer !== null) {
|
|
758
|
+
this.held = point;
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
this.rest(point);
|
|
762
|
+
if (this.resting === point) this.openWindow();
|
|
763
|
+
}
|
|
764
|
+
dispose() {
|
|
765
|
+
if (this.disposed) return;
|
|
766
|
+
this.disposed = true;
|
|
767
|
+
this.endWindow();
|
|
768
|
+
this.listeners.clear();
|
|
769
|
+
}
|
|
770
|
+
rest(point) {
|
|
771
|
+
if (this.resting === point) return;
|
|
772
|
+
this.resting = point;
|
|
773
|
+
notifyListeners(this.listeners);
|
|
774
|
+
}
|
|
775
|
+
openWindow() {
|
|
776
|
+
if (this.timer !== null || this.throttleMs === 0 || this.listeners.size === 0) return;
|
|
777
|
+
this.timer = setTimeout(() => {
|
|
778
|
+
this.timer = null;
|
|
779
|
+
const held = this.held;
|
|
780
|
+
if (held === null) return;
|
|
781
|
+
this.held = null;
|
|
782
|
+
this.rest(held);
|
|
783
|
+
if (this.resting === held) this.openWindow();
|
|
784
|
+
}, this.throttleMs);
|
|
785
|
+
}
|
|
786
|
+
endWindow() {
|
|
787
|
+
if (this.timer !== null) clearTimeout(this.timer);
|
|
788
|
+
this.timer = null;
|
|
789
|
+
this.held = null;
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
const promptKey = (hazards) => [...hazards].sort().join("|");
|
|
793
|
+
const createHazardPromptGate = (ask) => {
|
|
794
|
+
const pending = /* @__PURE__ */ new Map();
|
|
795
|
+
return (hazards) => {
|
|
796
|
+
const key = promptKey(hazards);
|
|
797
|
+
const asking = pending.get(key);
|
|
798
|
+
if (asking) return asking;
|
|
799
|
+
const answer = ask(hazards).finally(() => {
|
|
800
|
+
pending.delete(key);
|
|
801
|
+
});
|
|
802
|
+
pending.set(key, answer);
|
|
803
|
+
return answer;
|
|
804
|
+
};
|
|
805
|
+
};
|
|
806
|
+
const buildLiveSegmentForDraft = (base, segmentId, itineraryId, mode, route, draftName, draftColor) => buildLiveSegment(base ?? synthesizeDraftSegment({
|
|
807
|
+
draftColor,
|
|
808
|
+
draftName,
|
|
809
|
+
itineraryId,
|
|
810
|
+
mode,
|
|
811
|
+
segmentId
|
|
812
|
+
}), route);
|
|
813
|
+
const idleSnapshot = {
|
|
814
|
+
armed: false,
|
|
815
|
+
mode: null,
|
|
816
|
+
segmentId: null,
|
|
817
|
+
viaCount: 0
|
|
818
|
+
};
|
|
819
|
+
const 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;
|
|
820
|
+
const sameListenKey = (a, b) => a.client === b.client && a.context === b.context && a.itineraryId === b.itineraryId && a.mode === b.mode && a.segmentId === b.segmentId;
|
|
821
|
+
const throttleFrom = (throttleMs) => {
|
|
822
|
+
if (throttleMs === void 0) return LIVE_SEGMENT_THROTTLE_MS;
|
|
823
|
+
if (!Number.isFinite(throttleMs) || throttleMs < 0 || throttleMs > MAX_TIMER_MS) throw new MountayaElementsError(`SegmentDraftEngine: throttleMs is ${String(throttleMs)}; pass a number of milliseconds from 0 to ${MAX_TIMER_MS}, or omit it for ${LIVE_SEGMENT_THROTTLE_MS}.`);
|
|
824
|
+
return throttleMs;
|
|
825
|
+
};
|
|
826
|
+
var SegmentDraftEngine = class {
|
|
827
|
+
config;
|
|
828
|
+
throttleMs;
|
|
829
|
+
snapshot = idleSnapshot;
|
|
830
|
+
subscriptions = /* @__PURE__ */ new Set();
|
|
831
|
+
watching = null;
|
|
832
|
+
arming = null;
|
|
833
|
+
refused = null;
|
|
834
|
+
listening = null;
|
|
835
|
+
viaCount = 0;
|
|
836
|
+
reconciling = false;
|
|
837
|
+
stale = false;
|
|
838
|
+
parked = true;
|
|
839
|
+
disposed = false;
|
|
840
|
+
hazardGate = createHazardPromptGate((hazards) => this.askAboutHazards(hazards));
|
|
841
|
+
hazardMemo = {
|
|
842
|
+
accept: (keys) => {
|
|
843
|
+
this.config.context.ui.getState().acknowledgeRouteHazards(keys);
|
|
844
|
+
},
|
|
845
|
+
accepted: () => this.config.context.ui.getState().segmentEditSession?.acknowledgedRouteHazards ?? []
|
|
846
|
+
};
|
|
847
|
+
constructor(options) {
|
|
848
|
+
const { throttleMs, ...config } = options;
|
|
849
|
+
this.throttleMs = throttleFrom(throttleMs);
|
|
850
|
+
this.config = config;
|
|
851
|
+
}
|
|
852
|
+
getSnapshot() {
|
|
853
|
+
return this.snapshot;
|
|
854
|
+
}
|
|
855
|
+
subscribe(listener) {
|
|
856
|
+
if (this.disposed) return () => {};
|
|
857
|
+
const subscription = { listener };
|
|
858
|
+
this.subscriptions.add(subscription);
|
|
859
|
+
if (this.parked) {
|
|
860
|
+
this.parked = false;
|
|
861
|
+
this.reconcile();
|
|
862
|
+
}
|
|
863
|
+
return () => {
|
|
864
|
+
if (!this.subscriptions.delete(subscription) || this.subscriptions.size > 0) return;
|
|
865
|
+
if (!this.parked) this.park();
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
configure(config) {
|
|
869
|
+
if (this.disposed) return;
|
|
870
|
+
this.config = config;
|
|
871
|
+
if (!this.parked) this.reconcile();
|
|
872
|
+
}
|
|
873
|
+
dispose() {
|
|
874
|
+
if (this.disposed) return;
|
|
875
|
+
this.disposed = true;
|
|
876
|
+
if (!this.parked) this.park();
|
|
877
|
+
this.subscriptions.clear();
|
|
878
|
+
}
|
|
879
|
+
reconcile() {
|
|
880
|
+
if (this.parked) return;
|
|
881
|
+
if (this.reconciling) {
|
|
882
|
+
this.stale = true;
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
this.reconciling = true;
|
|
886
|
+
try {
|
|
887
|
+
do {
|
|
888
|
+
this.stale = false;
|
|
889
|
+
this.step();
|
|
890
|
+
} while (this.stale && !this.parked);
|
|
891
|
+
} finally {
|
|
892
|
+
this.reconciling = false;
|
|
893
|
+
}
|
|
894
|
+
this.publish();
|
|
895
|
+
}
|
|
896
|
+
step() {
|
|
897
|
+
const { client, context } = this.config;
|
|
898
|
+
this.watch(context.ui);
|
|
899
|
+
const state = context.ui.getState();
|
|
900
|
+
const session = state.segmentEditSession;
|
|
901
|
+
if (client === null || session === null || session.segmentId === "") {
|
|
902
|
+
this.unlisten();
|
|
903
|
+
this.arming = null;
|
|
904
|
+
this.refused = null;
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
const key = {
|
|
908
|
+
client,
|
|
909
|
+
context,
|
|
910
|
+
itineraryId: state.activeItinerary?.id ?? null,
|
|
911
|
+
mode: session.mode,
|
|
912
|
+
segmentId: session.segmentId
|
|
913
|
+
};
|
|
914
|
+
if (this.listening !== null && !sameListenKey(this.listening, key)) this.unlisten();
|
|
915
|
+
const arming = {
|
|
916
|
+
activitySlug: session.activitySlug,
|
|
917
|
+
client,
|
|
918
|
+
context,
|
|
919
|
+
draftColor: session.draftColor,
|
|
920
|
+
mode: session.mode,
|
|
921
|
+
pinnedEnd: session.pinnedEnd,
|
|
922
|
+
pinnedStart: session.pinnedStart,
|
|
923
|
+
seedVias: session.seedVias,
|
|
924
|
+
segmentId: session.segmentId
|
|
925
|
+
};
|
|
926
|
+
if (this.refused !== null && sameArming(this.refused, arming)) return;
|
|
927
|
+
if (this.arming === null || !sameArming(this.arming, arming)) {
|
|
928
|
+
try {
|
|
929
|
+
client.beginSegmentEdit(buildSegmentEditOptions(session, {
|
|
930
|
+
client: context.api?.client,
|
|
931
|
+
confirmHazards: this.hazardGate,
|
|
932
|
+
hazardMemo: this.hazardMemo,
|
|
933
|
+
onViaCapRefused: () => this.refuseViaCap()
|
|
934
|
+
}));
|
|
935
|
+
} catch (refusal) {
|
|
936
|
+
this.unlisten();
|
|
937
|
+
this.arming = null;
|
|
938
|
+
this.refused = arming;
|
|
939
|
+
this.endRefused(context, segmentEditSessionMark(session), refusal);
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
this.arming = arming;
|
|
943
|
+
this.refused = null;
|
|
944
|
+
}
|
|
945
|
+
if (this.listening === null) this.listen(key);
|
|
946
|
+
}
|
|
947
|
+
endRefused(context, mark, refusal) {
|
|
948
|
+
surfaceFault(refusal);
|
|
949
|
+
const close = () => {
|
|
950
|
+
if (this.disposed) return;
|
|
951
|
+
const state = context.ui.getState();
|
|
952
|
+
const open = state.segmentEditSession;
|
|
953
|
+
if (open !== null && segmentEditSessionMark(open) === mark) state.cancelSegmentEdit();
|
|
954
|
+
};
|
|
955
|
+
Promise.resolve(this.config.bus.dispatch(context, "studio.itinerary.segment.editCancel", {})).then((result) => {
|
|
956
|
+
if (result?.ok !== true) close();
|
|
957
|
+
}, close);
|
|
958
|
+
this.raiseAlert(context, {
|
|
959
|
+
level: "error",
|
|
960
|
+
message: this.config.strings.editing.segmentEditBeginFailed
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
raiseAlert(context, alert) {
|
|
964
|
+
Promise.resolve(this.config.bus.dispatch(context, "studio.alert.show", alert)).then(void 0, () => {});
|
|
965
|
+
}
|
|
966
|
+
watch(ui) {
|
|
967
|
+
if (this.watching?.ui === ui) return;
|
|
968
|
+
this.unwatch();
|
|
969
|
+
this.watching = {
|
|
970
|
+
release: ui.subscribe(() => this.reconcile()),
|
|
971
|
+
ui
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
unwatch() {
|
|
975
|
+
this.watching?.release();
|
|
976
|
+
this.watching = null;
|
|
977
|
+
}
|
|
978
|
+
listen(key) {
|
|
979
|
+
const listening = {
|
|
980
|
+
...key,
|
|
981
|
+
projected: null,
|
|
982
|
+
release: () => {},
|
|
983
|
+
throttle: this.throttleMs === 0 ? null : new TrailingThrottle(this.throttleMs, (routed) => this.project(listening, routed), { leading: true })
|
|
984
|
+
};
|
|
985
|
+
this.listening = listening;
|
|
986
|
+
listening.release = key.client.onSegmentDraftChange((draft) => this.receive(listening, draft));
|
|
987
|
+
}
|
|
988
|
+
unlisten() {
|
|
989
|
+
const listening = this.listening;
|
|
990
|
+
if (listening === null) return;
|
|
991
|
+
this.listening = null;
|
|
992
|
+
this.viaCount = 0;
|
|
993
|
+
listening.release();
|
|
994
|
+
listening.throttle?.cancel();
|
|
995
|
+
listening.context.ui.getState().setSegmentEditLiveSegment(null);
|
|
996
|
+
}
|
|
997
|
+
receive(listening, draft) {
|
|
998
|
+
if (this.listening !== listening) return;
|
|
999
|
+
if (draft.vias.length !== this.viaCount) {
|
|
1000
|
+
this.viaCount = draft.vias.length;
|
|
1001
|
+
this.publish();
|
|
1002
|
+
if (this.listening !== listening) return;
|
|
1003
|
+
}
|
|
1004
|
+
const ui = listening.context.ui;
|
|
1005
|
+
const disposition = draftChangeDisposition({
|
|
1006
|
+
agentDriving: ui.getState().agentDriving,
|
|
1007
|
+
programmatic: draft.programmatic
|
|
1008
|
+
});
|
|
1009
|
+
if (disposition === "drop") return;
|
|
1010
|
+
if (disposition === "record") {
|
|
1011
|
+
const geometry = buildSegmentGeometry(listening.mode, draft.vias);
|
|
1012
|
+
if (draft.phase === "live") ui.getState().setSegmentEditLiveDraft(geometry);
|
|
1013
|
+
else ui.getState().pushSegmentDraft(geometry);
|
|
1014
|
+
if (this.listening !== listening) return;
|
|
1015
|
+
}
|
|
1016
|
+
if (draft.route) {
|
|
1017
|
+
const projected = listening.projected;
|
|
1018
|
+
if (projected?.route === draft.route && ui.getState().segmentEditSession?.liveSegment === projected.liveSegment) return;
|
|
1019
|
+
const routed = {
|
|
1020
|
+
route: draft.route,
|
|
1021
|
+
routedFor: draft.programmatic ? draft.vias : void 0
|
|
1022
|
+
};
|
|
1023
|
+
if (listening.throttle === null) this.project(listening, routed);
|
|
1024
|
+
else listening.throttle.push(routed);
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
if (draft.phase === "live") return;
|
|
1028
|
+
listening.throttle?.cancel();
|
|
1029
|
+
if (disposition === "record") this.fallBack(listening);
|
|
1030
|
+
}
|
|
1031
|
+
project(listening, { route, routedFor }) {
|
|
1032
|
+
if (this.listening !== listening) return;
|
|
1033
|
+
const state = listening.context.ui.getState();
|
|
1034
|
+
const itinerary = state.activeItinerary;
|
|
1035
|
+
const session = state.segmentEditSession;
|
|
1036
|
+
const liveSegment = buildLiveSegmentForDraft(itinerary?.segments.find((segment) => segment.id === listening.segmentId), listening.segmentId, itinerary?.id ?? "", session?.mode ?? "directions", route, session?.draftName ?? null, session?.draftColor ?? null);
|
|
1037
|
+
listening.projected = {
|
|
1038
|
+
liveSegment,
|
|
1039
|
+
route
|
|
1040
|
+
};
|
|
1041
|
+
state.setSegmentEditLiveSegment(liveSegment, routedFor);
|
|
1042
|
+
this.config.collab?.sendDraft({
|
|
1043
|
+
id: listening.segmentId,
|
|
1044
|
+
kind: "segment"
|
|
1045
|
+
}, liveSegment);
|
|
1046
|
+
}
|
|
1047
|
+
fallBack(listening) {
|
|
1048
|
+
const state = listening.context.ui.getState();
|
|
1049
|
+
const session = state.segmentEditSession;
|
|
1050
|
+
if (!state.activeItinerary?.segments?.find((segment) => segment.id === listening.segmentId) && session) {
|
|
1051
|
+
state.setSegmentEditLiveSegment(synthesizeDraftSegment({
|
|
1052
|
+
draftColor: session.draftColor,
|
|
1053
|
+
draftName: session.draftName,
|
|
1054
|
+
itineraryId: state.activeItinerary?.id ?? "",
|
|
1055
|
+
mode: session.mode,
|
|
1056
|
+
segmentId: session.segmentId
|
|
1057
|
+
}));
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
state.setSegmentEditLiveSegment(null);
|
|
1061
|
+
}
|
|
1062
|
+
refuseViaCap() {
|
|
1063
|
+
const { context, strings } = this.config;
|
|
1064
|
+
this.raiseAlert(context, {
|
|
1065
|
+
level: "warning",
|
|
1066
|
+
message: strings.editing.segmentViaCapRefused(DIRECTIONS_VIA_MAX)
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
askAboutHazards(hazards) {
|
|
1070
|
+
const { context, strings } = this.config;
|
|
1071
|
+
if (!context.confirm) return Promise.resolve(true);
|
|
1072
|
+
return context.confirm(routeHazardConfirmation(hazards, {
|
|
1073
|
+
closing: strings.editing.routeHazardClosing,
|
|
1074
|
+
hazards: strings.editing.routeHazards,
|
|
1075
|
+
severalTitle: strings.editing.routeHazardsTitle
|
|
1076
|
+
}));
|
|
1077
|
+
}
|
|
1078
|
+
park() {
|
|
1079
|
+
this.parked = true;
|
|
1080
|
+
this.unwatch();
|
|
1081
|
+
this.unlisten();
|
|
1082
|
+
this.arming = null;
|
|
1083
|
+
this.publish();
|
|
1084
|
+
}
|
|
1085
|
+
publish() {
|
|
1086
|
+
const listening = this.listening;
|
|
1087
|
+
const next = listening === null ? idleSnapshot : {
|
|
1088
|
+
armed: true,
|
|
1089
|
+
mode: listening.mode,
|
|
1090
|
+
segmentId: listening.segmentId,
|
|
1091
|
+
viaCount: this.viaCount
|
|
1092
|
+
};
|
|
1093
|
+
const current = this.snapshot;
|
|
1094
|
+
if (current.armed === next.armed && current.mode === next.mode && current.segmentId === next.segmentId && current.viaCount === next.viaCount) return;
|
|
1095
|
+
this.snapshot = next;
|
|
1096
|
+
if (this.disposed) return;
|
|
1097
|
+
notifyListeners(Array.from(this.subscriptions, ({ listener }) => listener));
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
z$1.object({ failedCollectionIds: z$1.array(z$1.string()).optional() });
|
|
1101
|
+
const mintedShareTokenSchema = z$1.object({ shareToken: issuedShareTokenSchema.shape.shareToken });
|
|
1102
|
+
const mintedShareToken = (result) => {
|
|
1103
|
+
if (!result.ok) return null;
|
|
1104
|
+
const parsed = mintedShareTokenSchema.safeParse(result.data);
|
|
1105
|
+
return parsed.success ? parsed.data.shareToken : null;
|
|
1106
|
+
};
|
|
1107
|
+
const skipped = { status: "skipped" };
|
|
1108
|
+
const withheld = { status: "withheld" };
|
|
1109
|
+
const unworded = {
|
|
1110
|
+
failure: null,
|
|
1111
|
+
retryable: true
|
|
1112
|
+
};
|
|
1113
|
+
const sameTarget = (a, b) => a.kind === b.kind && a.id === b.id;
|
|
1114
|
+
const sameActions = (a, b) => a.disable === b.disable && a.rotate === b.rotate;
|
|
1115
|
+
const heldBack = (actions) => ({
|
|
1116
|
+
disable: actions.disable === "ready" ? "waiting" : actions.disable,
|
|
1117
|
+
rotate: actions.rotate === "ready" ? "waiting" : actions.rotate
|
|
1118
|
+
});
|
|
1119
|
+
const answered = async (run, settle) => {
|
|
1120
|
+
let result;
|
|
1121
|
+
try {
|
|
1122
|
+
result = await run();
|
|
1123
|
+
} catch (error) {
|
|
1124
|
+
result = failureFromThrown(error);
|
|
1125
|
+
}
|
|
1126
|
+
return settle(result);
|
|
1127
|
+
};
|
|
1128
|
+
const readToken = (result) => {
|
|
1129
|
+
if (!result.ok) return {
|
|
1130
|
+
failure: result,
|
|
1131
|
+
retryable: isRetryableShareLinkFailure(result)
|
|
1132
|
+
};
|
|
1133
|
+
if (result.token === null) return { token: null };
|
|
1134
|
+
const issued = issuedShareTokenSchema.safeParse({ shareToken: result.token });
|
|
1135
|
+
return issued.success ? { token: issued.data.shareToken } : unworded;
|
|
1136
|
+
};
|
|
1137
|
+
var ShareLinkEngine = class {
|
|
1138
|
+
config;
|
|
1139
|
+
target;
|
|
1140
|
+
token;
|
|
1141
|
+
known;
|
|
1142
|
+
readFailure = null;
|
|
1143
|
+
mintFailure = null;
|
|
1144
|
+
change = null;
|
|
1145
|
+
reading = false;
|
|
1146
|
+
minting = false;
|
|
1147
|
+
asked = false;
|
|
1148
|
+
acting = null;
|
|
1149
|
+
running = false;
|
|
1150
|
+
epoch = 0;
|
|
1151
|
+
sent = 0;
|
|
1152
|
+
outranked = 0;
|
|
1153
|
+
answeredAt = 0;
|
|
1154
|
+
unheard = 0;
|
|
1155
|
+
readFailedAt = 0;
|
|
1156
|
+
mintFailedAt = 0;
|
|
1157
|
+
latestRead = 0;
|
|
1158
|
+
latestMint = 0;
|
|
1159
|
+
snapshot;
|
|
1160
|
+
subscriptions = /* @__PURE__ */ new Set();
|
|
1161
|
+
parked = true;
|
|
1162
|
+
disposed = false;
|
|
1163
|
+
constructor(options) {
|
|
1164
|
+
const { token, ...config } = options;
|
|
1165
|
+
this.config = config;
|
|
1166
|
+
this.target = config.target;
|
|
1167
|
+
this.token = token ?? null;
|
|
1168
|
+
this.known = this.token !== null;
|
|
1169
|
+
this.snapshot = this.compose();
|
|
1170
|
+
}
|
|
1171
|
+
getSnapshot() {
|
|
1172
|
+
return this.snapshot;
|
|
1173
|
+
}
|
|
1174
|
+
subscribe(listener) {
|
|
1175
|
+
if (this.disposed) return () => void 0;
|
|
1176
|
+
const subscription = { listener };
|
|
1177
|
+
this.subscriptions.add(subscription);
|
|
1178
|
+
if (this.parked) {
|
|
1179
|
+
this.parked = false;
|
|
1180
|
+
this.ask();
|
|
1181
|
+
}
|
|
1182
|
+
return () => {
|
|
1183
|
+
if (!this.subscriptions.delete(subscription) || this.subscriptions.size > 0) return;
|
|
1184
|
+
this.parked = true;
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
configure(config) {
|
|
1188
|
+
if (this.disposed) return;
|
|
1189
|
+
this.config = config;
|
|
1190
|
+
if (!sameTarget(this.target, config.target)) {
|
|
1191
|
+
this.target = config.target;
|
|
1192
|
+
this.epoch += 1;
|
|
1193
|
+
this.token = null;
|
|
1194
|
+
this.known = false;
|
|
1195
|
+
this.readFailure = null;
|
|
1196
|
+
this.readFailedAt = 0;
|
|
1197
|
+
this.mintFailure = null;
|
|
1198
|
+
this.mintFailedAt = 0;
|
|
1199
|
+
this.change = null;
|
|
1200
|
+
this.acting = null;
|
|
1201
|
+
this.running = false;
|
|
1202
|
+
this.reading = false;
|
|
1203
|
+
this.minting = false;
|
|
1204
|
+
this.asked = false;
|
|
1205
|
+
}
|
|
1206
|
+
this.publish();
|
|
1207
|
+
if (!this.parked) this.ask();
|
|
1208
|
+
}
|
|
1209
|
+
dispose() {
|
|
1210
|
+
if (this.disposed) return;
|
|
1211
|
+
this.disposed = true;
|
|
1212
|
+
this.parked = true;
|
|
1213
|
+
this.subscriptions.clear();
|
|
1214
|
+
}
|
|
1215
|
+
async read() {
|
|
1216
|
+
if (this.parked || this.disposed || this.reading || !this.mayAsk()) return;
|
|
1217
|
+
await this.runAsk("read");
|
|
1218
|
+
}
|
|
1219
|
+
async mint() {
|
|
1220
|
+
if (this.parked || this.disposed || this.minting || this.token !== null || this.acting !== null || !this.mayAsk()) return;
|
|
1221
|
+
await this.runAsk("mint");
|
|
1222
|
+
}
|
|
1223
|
+
rotate() {
|
|
1224
|
+
return this.act("rotate");
|
|
1225
|
+
}
|
|
1226
|
+
disable() {
|
|
1227
|
+
return this.act("disable");
|
|
1228
|
+
}
|
|
1229
|
+
ask() {
|
|
1230
|
+
if (this.asked || !this.mayAsk()) return;
|
|
1231
|
+
this.runAsk("read");
|
|
1232
|
+
}
|
|
1233
|
+
mayAsk() {
|
|
1234
|
+
return this.config.scope === "organization" && this.config.canManage;
|
|
1235
|
+
}
|
|
1236
|
+
async runAsk(kind) {
|
|
1237
|
+
const epoch = this.epoch;
|
|
1238
|
+
this.sent += 1;
|
|
1239
|
+
const place = this.sent;
|
|
1240
|
+
if (kind === "read") {
|
|
1241
|
+
this.latestRead = place;
|
|
1242
|
+
this.asked = true;
|
|
1243
|
+
this.reading = true;
|
|
1244
|
+
this.readFailure = null;
|
|
1245
|
+
this.readFailedAt = 0;
|
|
1246
|
+
} else {
|
|
1247
|
+
this.latestMint = place;
|
|
1248
|
+
this.minting = true;
|
|
1249
|
+
this.mintFailure = null;
|
|
1250
|
+
this.mintFailedAt = 0;
|
|
1251
|
+
}
|
|
1252
|
+
this.publish();
|
|
1253
|
+
const answer = kind === "read" ? await this.sendRead() : await this.sendMint();
|
|
1254
|
+
if (this.disposed || epoch !== this.epoch) return;
|
|
1255
|
+
if (kind === "read" && place === this.latestRead) this.reading = false;
|
|
1256
|
+
if (kind === "mint" && place === this.latestMint) this.minting = false;
|
|
1257
|
+
if (place <= this.outranked || place < this.answeredAt) {
|
|
1258
|
+
this.publish();
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
if (kind === "read" && this.parked) {
|
|
1262
|
+
this.asked = false;
|
|
1263
|
+
this.unheard = place;
|
|
1264
|
+
this.publish();
|
|
1265
|
+
return;
|
|
1266
|
+
}
|
|
1267
|
+
if ("failure" in answer) {
|
|
1268
|
+
if (kind === "read") {
|
|
1269
|
+
this.readFailure = answer;
|
|
1270
|
+
this.readFailedAt = place;
|
|
1271
|
+
} else {
|
|
1272
|
+
this.mintFailure = answer;
|
|
1273
|
+
this.mintFailedAt = place;
|
|
1274
|
+
}
|
|
1275
|
+
this.publish();
|
|
1276
|
+
return;
|
|
1277
|
+
}
|
|
1278
|
+
this.token = answer.token;
|
|
1279
|
+
this.known = true;
|
|
1280
|
+
this.change = kind === "read" ? "read" : "minted";
|
|
1281
|
+
this.answeredAt = place;
|
|
1282
|
+
if (this.readFailedAt < place) {
|
|
1283
|
+
this.readFailure = null;
|
|
1284
|
+
this.readFailedAt = 0;
|
|
1285
|
+
}
|
|
1286
|
+
if (this.mintFailedAt < place) {
|
|
1287
|
+
this.mintFailure = null;
|
|
1288
|
+
this.mintFailedAt = 0;
|
|
1289
|
+
}
|
|
1290
|
+
this.publish();
|
|
1291
|
+
}
|
|
1292
|
+
async sendRead() {
|
|
1293
|
+
try {
|
|
1294
|
+
return readToken(await this.config.read(this.config.context, this.target));
|
|
1295
|
+
} catch {
|
|
1296
|
+
return unworded;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
async sendMint() {
|
|
1300
|
+
try {
|
|
1301
|
+
const result = await this.config.dispatch(this.config.context, "studio.shareLink.mint", this.target);
|
|
1302
|
+
if (!result.ok) return {
|
|
1303
|
+
failure: result,
|
|
1304
|
+
retryable: isRetryableShareLinkFailure(result)
|
|
1305
|
+
};
|
|
1306
|
+
const token = mintedShareToken(result);
|
|
1307
|
+
return token === null ? unworded : { token };
|
|
1308
|
+
} catch {
|
|
1309
|
+
return unworded;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
act(action) {
|
|
1313
|
+
if (this.parked || this.disposed || this.acting !== null || this.snapshot.actions[action] !== "ready") return Promise.resolve(skipped);
|
|
1314
|
+
const epoch = this.epoch;
|
|
1315
|
+
const { context, dispatch, scope } = this.config;
|
|
1316
|
+
this.sent += 1;
|
|
1317
|
+
let place = this.sent;
|
|
1318
|
+
const confirming = layerToolContext(context, { confirm: async (request) => {
|
|
1319
|
+
const approved = await context.confirm?.(request) ?? false;
|
|
1320
|
+
if (approved && !this.disposed && epoch === this.epoch) {
|
|
1321
|
+
this.sent += 1;
|
|
1322
|
+
place = this.sent;
|
|
1323
|
+
this.running = true;
|
|
1324
|
+
this.publish();
|
|
1325
|
+
}
|
|
1326
|
+
return approved;
|
|
1327
|
+
} });
|
|
1328
|
+
const target = this.target;
|
|
1329
|
+
this.acting = action;
|
|
1330
|
+
this.publish();
|
|
1331
|
+
if (action === "rotate") return answered(() => dispatch(confirming, "studio.shareLink.rotate", target), (result) => this.settleRotate(epoch, result));
|
|
1332
|
+
return answered(() => dispatch(confirming, "studio.shareLink.disable", target), (result) => this.settleDisable(epoch, scope, place, result));
|
|
1333
|
+
}
|
|
1334
|
+
settleRotate(epoch, result) {
|
|
1335
|
+
if (!result.ok) return this.refuse(epoch, result);
|
|
1336
|
+
const shareToken = mintedShareToken(result);
|
|
1337
|
+
if (shareToken === null) {
|
|
1338
|
+
this.finish(epoch, () => {
|
|
1339
|
+
this.outranked = this.sent;
|
|
1340
|
+
});
|
|
1341
|
+
this.readStandingLink(epoch);
|
|
1342
|
+
return {
|
|
1343
|
+
failure: tokenlessAnswerRefusal("rotate"),
|
|
1344
|
+
status: "refused"
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
this.finish(epoch, () => {
|
|
1348
|
+
this.outranked = this.sent;
|
|
1349
|
+
this.token = shareToken;
|
|
1350
|
+
this.known = true;
|
|
1351
|
+
this.change = "rotated";
|
|
1352
|
+
this.readFailure = null;
|
|
1353
|
+
this.readFailedAt = 0;
|
|
1354
|
+
this.mintFailure = null;
|
|
1355
|
+
this.mintFailedAt = 0;
|
|
1356
|
+
});
|
|
1357
|
+
return {
|
|
1358
|
+
linkWasActive: true,
|
|
1359
|
+
status: "settled"
|
|
1360
|
+
};
|
|
1361
|
+
}
|
|
1362
|
+
readStandingLink(epoch) {
|
|
1363
|
+
if (this.disposed || epoch !== this.epoch) return;
|
|
1364
|
+
if (this.parked || !this.mayAsk()) {
|
|
1365
|
+
this.asked = false;
|
|
1366
|
+
return;
|
|
1367
|
+
}
|
|
1368
|
+
this.runAsk("read");
|
|
1369
|
+
}
|
|
1370
|
+
settleDisable(epoch, scope, place, result) {
|
|
1371
|
+
if (!result.ok && !isShareLinkDisableSettled(result, scope)) return this.refuse(epoch, result);
|
|
1372
|
+
this.finish(epoch, () => {
|
|
1373
|
+
if (place < this.answeredAt) return;
|
|
1374
|
+
this.outranked = place;
|
|
1375
|
+
this.token = null;
|
|
1376
|
+
this.known = true;
|
|
1377
|
+
this.change = "disabled";
|
|
1378
|
+
if (this.readFailedAt < place) {
|
|
1379
|
+
this.readFailure = null;
|
|
1380
|
+
this.readFailedAt = 0;
|
|
1381
|
+
}
|
|
1382
|
+
if (this.mintFailedAt < place) {
|
|
1383
|
+
this.mintFailure = null;
|
|
1384
|
+
this.mintFailedAt = 0;
|
|
1385
|
+
}
|
|
1386
|
+
if (place > this.unheard) this.asked = true;
|
|
1387
|
+
});
|
|
1388
|
+
return {
|
|
1389
|
+
linkWasActive: result.ok,
|
|
1390
|
+
status: "settled"
|
|
1391
|
+
};
|
|
1392
|
+
}
|
|
1393
|
+
refuse(epoch, failure) {
|
|
1394
|
+
this.finish(epoch);
|
|
1395
|
+
return isConfirmationWithheld(failure) ? withheld : {
|
|
1396
|
+
failure,
|
|
1397
|
+
status: "refused"
|
|
1398
|
+
};
|
|
1399
|
+
}
|
|
1400
|
+
finish(epoch, apply) {
|
|
1401
|
+
if (this.disposed || epoch !== this.epoch) return;
|
|
1402
|
+
this.acting = null;
|
|
1403
|
+
this.running = false;
|
|
1404
|
+
apply?.();
|
|
1405
|
+
this.publish();
|
|
1406
|
+
}
|
|
1407
|
+
compose() {
|
|
1408
|
+
const { canManage, scope } = this.config;
|
|
1409
|
+
const offered = shareLinkActions({
|
|
1410
|
+
canManage,
|
|
1411
|
+
scope,
|
|
1412
|
+
token: this.token
|
|
1413
|
+
});
|
|
1414
|
+
return {
|
|
1415
|
+
actions: this.acting === null ? offered : heldBack(offered),
|
|
1416
|
+
busy: this.running ? this.acting : null,
|
|
1417
|
+
change: this.change,
|
|
1418
|
+
known: this.known,
|
|
1419
|
+
mintFailure: this.mintFailure,
|
|
1420
|
+
minting: this.minting,
|
|
1421
|
+
readFailure: this.readFailure,
|
|
1422
|
+
reading: this.reading,
|
|
1423
|
+
target: this.target,
|
|
1424
|
+
token: this.token
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
publish() {
|
|
1428
|
+
const current = this.snapshot;
|
|
1429
|
+
const next = this.compose();
|
|
1430
|
+
const actions = sameActions(current.actions, next.actions) ? current.actions : next.actions;
|
|
1431
|
+
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) return;
|
|
1432
|
+
this.snapshot = {
|
|
1433
|
+
...next,
|
|
1434
|
+
actions
|
|
1435
|
+
};
|
|
1436
|
+
notifyListeners([...this.subscriptions].map((subscription) => subscription.listener));
|
|
1437
|
+
}
|
|
1438
|
+
};
|
|
1439
|
+
const queryKeyOf = (source) => source === null ? null : JSON.stringify(source);
|
|
1440
|
+
const noFacts = {
|
|
1441
|
+
createMethod: null,
|
|
1442
|
+
createSerial: 0,
|
|
1443
|
+
inherited: null,
|
|
1444
|
+
origin: null,
|
|
1445
|
+
session: null,
|
|
1446
|
+
zone: null
|
|
1447
|
+
};
|
|
1448
|
+
const factsOf = (state) => {
|
|
1449
|
+
const zone = state.activeZone;
|
|
1450
|
+
const itinerary = state.activeItinerary;
|
|
1451
|
+
return {
|
|
1452
|
+
createMethod: state.zoneCreateMethod,
|
|
1453
|
+
createSerial: state.zoneCreateSerial,
|
|
1454
|
+
inherited: zone === null && state.zoneCreateInheritsItinerary && itinerary !== null ? {
|
|
1455
|
+
activityId: itinerary.activity_id,
|
|
1456
|
+
itineraryId: itinerary.id,
|
|
1457
|
+
organizationId: itinerary.organization_id ?? null
|
|
1458
|
+
} : null,
|
|
1459
|
+
origin: state.zoneCreateOrigin,
|
|
1460
|
+
session: state.zoneEditSession,
|
|
1461
|
+
zone
|
|
1462
|
+
};
|
|
1463
|
+
};
|
|
1464
|
+
const sameIds = (a, b) => a.length === b.length && a.every((id, index) => id === b[index]);
|
|
1465
|
+
const sameMembers = (a, b) => {
|
|
1466
|
+
const keys = Object.keys(a);
|
|
1467
|
+
return keys.length === Object.keys(b).length && keys.every((key) => Object.is(a[key], b[key]));
|
|
1468
|
+
};
|
|
1469
|
+
const 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;
|
|
1470
|
+
const debounceFrom = (debounceMs) => {
|
|
1471
|
+
if (debounceMs === void 0) return 600;
|
|
1472
|
+
if (!Number.isFinite(debounceMs) || debounceMs < 0 || debounceMs > MAX_TIMER_MS) throw new MountayaElementsError(`ZoneFormEngine: debounceMs is ${String(debounceMs)}; pass a number of milliseconds from 0 to ${MAX_TIMER_MS}, or omit it for 600.`);
|
|
1473
|
+
return debounceMs;
|
|
1474
|
+
};
|
|
1475
|
+
var ZoneFormEngine = class {
|
|
1476
|
+
config;
|
|
1477
|
+
debounceMs;
|
|
1478
|
+
ids;
|
|
1479
|
+
ui;
|
|
1480
|
+
draft = {
|
|
1481
|
+
activityId: null,
|
|
1482
|
+
collectionIds: [],
|
|
1483
|
+
createLevel: DEFAULT_ZONE_LEVEL,
|
|
1484
|
+
createMode: DEFAULT_ZONE_MODE,
|
|
1485
|
+
description: "",
|
|
1486
|
+
endAt: null,
|
|
1487
|
+
name: "",
|
|
1488
|
+
organizationId: null,
|
|
1489
|
+
range: ZONE_DEFAULT_DISTANCE_RANGE_METERS,
|
|
1490
|
+
rangeType: "distance",
|
|
1491
|
+
speedKmh: null,
|
|
1492
|
+
startAt: null,
|
|
1493
|
+
windowOpen: false
|
|
1494
|
+
};
|
|
1495
|
+
nameTouched = false;
|
|
1496
|
+
organizationChosen = false;
|
|
1497
|
+
saving = /* @__PURE__ */ new Set();
|
|
1498
|
+
drawing = false;
|
|
1499
|
+
drawFailure = null;
|
|
1500
|
+
pickFailure = null;
|
|
1501
|
+
pickSerial = 0;
|
|
1502
|
+
origin = void 0;
|
|
1503
|
+
saveFailure = null;
|
|
1504
|
+
sourceRefusal = null;
|
|
1505
|
+
previewFailure = null;
|
|
1506
|
+
unsavedWritten = false;
|
|
1507
|
+
touched = false;
|
|
1508
|
+
bound = void 0;
|
|
1509
|
+
subject = null;
|
|
1510
|
+
subjectEpoch = 0;
|
|
1511
|
+
create = void 0;
|
|
1512
|
+
createSerial = void 0;
|
|
1513
|
+
sourceSeed = null;
|
|
1514
|
+
settled = null;
|
|
1515
|
+
judged = null;
|
|
1516
|
+
snapshot;
|
|
1517
|
+
subscriptions = /* @__PURE__ */ new Set();
|
|
1518
|
+
unwatch = null;
|
|
1519
|
+
previewKey = void 0;
|
|
1520
|
+
previewInput = null;
|
|
1521
|
+
previewEpoch = 0;
|
|
1522
|
+
timer = null;
|
|
1523
|
+
reconciling = false;
|
|
1524
|
+
stale = false;
|
|
1525
|
+
parked = true;
|
|
1526
|
+
disposed = false;
|
|
1527
|
+
constructor(options) {
|
|
1528
|
+
const { debounceMs, ids, ui, ...config } = options;
|
|
1529
|
+
this.debounceMs = debounceFrom(debounceMs);
|
|
1530
|
+
this.ids = ids;
|
|
1531
|
+
this.ui = ui;
|
|
1532
|
+
this.config = config;
|
|
1533
|
+
this.snapshot = this.view(noFacts).snapshot;
|
|
1534
|
+
}
|
|
1535
|
+
getSnapshot() {
|
|
1536
|
+
this.settle();
|
|
1537
|
+
return this.snapshot;
|
|
1538
|
+
}
|
|
1539
|
+
subscribe(listener) {
|
|
1540
|
+
if (this.disposed) return () => {};
|
|
1541
|
+
const subscription = { listener };
|
|
1542
|
+
this.subscriptions.add(subscription);
|
|
1543
|
+
if (this.parked) {
|
|
1544
|
+
this.parked = false;
|
|
1545
|
+
this.unwatch = this.ui.subscribe((state) => this.watch(state));
|
|
1546
|
+
this.reconcile();
|
|
1547
|
+
}
|
|
1548
|
+
return () => {
|
|
1549
|
+
if (!this.subscriptions.delete(subscription) || this.subscriptions.size > 0) return;
|
|
1550
|
+
if (!this.parked) this.park();
|
|
1551
|
+
};
|
|
1552
|
+
}
|
|
1553
|
+
configure(config) {
|
|
1554
|
+
if (this.disposed || sameMembers(this.config, config)) return;
|
|
1555
|
+
this.config = config;
|
|
1556
|
+
if (!this.parked) this.reconcile();
|
|
1557
|
+
}
|
|
1558
|
+
dispose() {
|
|
1559
|
+
if (this.disposed) return;
|
|
1560
|
+
this.disposed = true;
|
|
1561
|
+
if (!this.parked) this.park();
|
|
1562
|
+
this.subscriptions.clear();
|
|
1563
|
+
}
|
|
1564
|
+
edit(fields) {
|
|
1565
|
+
if (this.parked || this.disposed) return;
|
|
1566
|
+
this.touched = true;
|
|
1567
|
+
const { draft } = this;
|
|
1568
|
+
if (fields.rangeType !== void 0) {
|
|
1569
|
+
draft.rangeType = fields.rangeType;
|
|
1570
|
+
draft.range = fields.rangeType === "time" ? ZONE_DEFAULT_TIME_RANGE_SECONDS : ZONE_DEFAULT_DISTANCE_RANGE_METERS;
|
|
1571
|
+
if (fields.rangeType === "distance") draft.speedKmh = null;
|
|
1572
|
+
}
|
|
1573
|
+
if (fields.windowOpen !== void 0) {
|
|
1574
|
+
draft.windowOpen = fields.windowOpen;
|
|
1575
|
+
if (!fields.windowOpen) {
|
|
1576
|
+
draft.startAt = null;
|
|
1577
|
+
draft.endAt = null;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
if (fields.name !== void 0) {
|
|
1581
|
+
draft.name = fields.name;
|
|
1582
|
+
this.nameTouched = true;
|
|
1583
|
+
const session = this.ui.getState().zoneEditSession;
|
|
1584
|
+
if (this.bound === null && session?.intent === "create" && session.name !== null) this.ui.getState().setZoneEditName(null);
|
|
1585
|
+
}
|
|
1586
|
+
if (fields.description !== void 0) draft.description = fields.description;
|
|
1587
|
+
if (fields.startAt !== void 0) draft.startAt = fields.startAt;
|
|
1588
|
+
if (fields.endAt !== void 0) draft.endAt = fields.endAt;
|
|
1589
|
+
if (fields.name !== void 0 || fields.description !== void 0 || fields.startAt !== void 0 || fields.endAt !== void 0) this.saveFailure = null;
|
|
1590
|
+
if (fields.activityId !== void 0) draft.activityId = fields.activityId;
|
|
1591
|
+
if (fields.collectionIds !== void 0 && !sameIds(draft.collectionIds, fields.collectionIds)) draft.collectionIds = [...fields.collectionIds];
|
|
1592
|
+
if (fields.mode !== void 0) draft.createMode = fields.mode;
|
|
1593
|
+
if (fields.organizationId !== void 0) {
|
|
1594
|
+
draft.organizationId = fields.organizationId;
|
|
1595
|
+
this.organizationChosen = true;
|
|
1596
|
+
const session = this.ui.getState().zoneEditSession;
|
|
1597
|
+
if (this.bound === null && session?.intent === "create" && session.organizationId !== fields.organizationId) this.ui.getState().setZoneEditOrganization(fields.organizationId);
|
|
1598
|
+
}
|
|
1599
|
+
if (fields.range !== void 0) draft.range = fields.range;
|
|
1600
|
+
if (fields.speedKmh !== void 0) draft.speedKmh = draft.rangeType === "time" ? fields.speedKmh : null;
|
|
1601
|
+
const held = {
|
|
1602
|
+
level: draft.createLevel,
|
|
1603
|
+
pick: this.ui.getState().zoneCreatePickedLevel
|
|
1604
|
+
};
|
|
1605
|
+
if (fields.level !== void 0) {
|
|
1606
|
+
draft.createLevel = fields.level;
|
|
1607
|
+
if (this.bound === null && held.pick !== fields.level) this.ui.getState().setZoneCreatePickedLevel(fields.level);
|
|
1608
|
+
}
|
|
1609
|
+
this.reconcile();
|
|
1610
|
+
if (fields.level !== void 0 && this.snapshot.armed) this.recolour(fields.level, held);
|
|
1611
|
+
}
|
|
1612
|
+
async ask(name, input) {
|
|
1613
|
+
try {
|
|
1614
|
+
return await this.config.dispatch(name, input);
|
|
1615
|
+
} catch {
|
|
1616
|
+
return null;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
async recolour(level, held) {
|
|
1620
|
+
const epoch = this.subjectEpoch;
|
|
1621
|
+
if ((await this.ask("studio.zone.setLevel", { level }))?.ok !== true && !this.disposed && epoch === this.subjectEpoch && this.draft.createLevel === level) {
|
|
1622
|
+
this.draft.createLevel = held.level;
|
|
1623
|
+
if (this.bound === null && this.ui.getState().zoneCreatePickedLevel === level) this.ui.getState().setZoneCreatePickedLevel(held.pick);
|
|
1624
|
+
this.reconcile();
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
setMethod(method) {
|
|
1628
|
+
if (this.parked || this.disposed) return;
|
|
1629
|
+
this.touched = true;
|
|
1630
|
+
this.switchMethod(method);
|
|
1631
|
+
}
|
|
1632
|
+
async switchMethod(method) {
|
|
1633
|
+
const epoch = this.subjectEpoch;
|
|
1634
|
+
const held = {
|
|
1635
|
+
preview: this.previewFailure,
|
|
1636
|
+
save: this.saveFailure,
|
|
1637
|
+
source: this.sourceRefusal
|
|
1638
|
+
};
|
|
1639
|
+
const answer = this.ask("studio.zone.setCreateMethod", { method });
|
|
1640
|
+
this.saveFailure = null;
|
|
1641
|
+
this.sourceRefusal = null;
|
|
1642
|
+
this.previewFailure = null;
|
|
1643
|
+
this.reconcile();
|
|
1644
|
+
if ((await answer)?.ok === true || this.disposed || epoch !== this.subjectEpoch) return;
|
|
1645
|
+
this.saveFailure ??= held.save;
|
|
1646
|
+
this.sourceRefusal ??= held.source;
|
|
1647
|
+
this.previewFailure ??= held.preview;
|
|
1648
|
+
this.reconcile();
|
|
1649
|
+
}
|
|
1650
|
+
beginOriginPick() {
|
|
1651
|
+
if (this.parked || this.disposed) return;
|
|
1652
|
+
this.touched = true;
|
|
1653
|
+
this.pickFailure = null;
|
|
1654
|
+
this.reconcile();
|
|
1655
|
+
this.pick();
|
|
1656
|
+
}
|
|
1657
|
+
async pick() {
|
|
1658
|
+
const epoch = this.subjectEpoch;
|
|
1659
|
+
this.pickSerial += 1;
|
|
1660
|
+
const asked = this.pickSerial;
|
|
1661
|
+
const result = await this.ask("studio.zone.beginOriginPick", {});
|
|
1662
|
+
if (result === null || result.ok || this.disposed || epoch !== this.subjectEpoch || asked !== this.pickSerial) return;
|
|
1663
|
+
this.pickFailure = result;
|
|
1664
|
+
this.reconcile();
|
|
1665
|
+
}
|
|
1666
|
+
beginDraw() {
|
|
1667
|
+
if (this.parked || this.disposed || this.drawing) return;
|
|
1668
|
+
const facts = factsOf(this.ui.getState());
|
|
1669
|
+
const { createLevel, createMode, organizationId } = this.draft;
|
|
1670
|
+
if (facts.zone !== null || facts.session !== null || createMode === null) return;
|
|
1671
|
+
this.drawing = true;
|
|
1672
|
+
this.drawFailure = null;
|
|
1673
|
+
this.reconcile();
|
|
1674
|
+
this.draw({
|
|
1675
|
+
intent: "create",
|
|
1676
|
+
level: createLevel,
|
|
1677
|
+
mode: createMode,
|
|
1678
|
+
organizationId: organizationId ?? void 0,
|
|
1679
|
+
zoneId: this.ids.next()
|
|
1680
|
+
});
|
|
1681
|
+
}
|
|
1682
|
+
async draw(input) {
|
|
1683
|
+
const epoch = this.subjectEpoch;
|
|
1684
|
+
const result = await this.ask("studio.zone.editBegin", input);
|
|
1685
|
+
if (result !== null && !result.ok && !this.disposed && epoch === this.subjectEpoch) this.drawFailure = result;
|
|
1686
|
+
this.drawing = false;
|
|
1687
|
+
this.reconcile();
|
|
1688
|
+
}
|
|
1689
|
+
async save() {
|
|
1690
|
+
const { subject } = this;
|
|
1691
|
+
if (this.parked || this.disposed || subject === null || this.saving.has(subject)) return;
|
|
1692
|
+
this.saveFailure = null;
|
|
1693
|
+
this.sourceRefusal = null;
|
|
1694
|
+
const request = this.saveRequest();
|
|
1695
|
+
if (request === null) {
|
|
1696
|
+
this.reconcile();
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
const query = queryKeyOf(this.statedSource());
|
|
1700
|
+
this.saving.add(subject);
|
|
1701
|
+
this.reconcile();
|
|
1702
|
+
try {
|
|
1703
|
+
const result = await this.run(request);
|
|
1704
|
+
if (this.disposed) return;
|
|
1705
|
+
if (!result.ok) {
|
|
1706
|
+
if (subject !== this.subject) return;
|
|
1707
|
+
if (query !== null && zoneSourceRefused(result)) this.sourceRefusal = {
|
|
1708
|
+
failure: result,
|
|
1709
|
+
query
|
|
1710
|
+
};
|
|
1711
|
+
else this.saveFailure = result;
|
|
1712
|
+
return;
|
|
1713
|
+
}
|
|
1714
|
+
const failed = result.data !== void 0 && "failedCollectionIds" in result.data ? result.data.failedCollectionIds : [];
|
|
1715
|
+
if (failed.length > 0) this.ask("studio.alert.show", {
|
|
1716
|
+
level: "warning",
|
|
1717
|
+
message: this.config.strings.zoneForm.collectionAttachWarning(failed.length)
|
|
1718
|
+
});
|
|
1719
|
+
} finally {
|
|
1720
|
+
this.saving.delete(subject);
|
|
1721
|
+
this.reconcile();
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
run(request) {
|
|
1725
|
+
switch (request.name) {
|
|
1726
|
+
case "studio.zone.create": return this.config.dispatch(request.name, request.input);
|
|
1727
|
+
case "studio.zone.editCommit": return this.config.dispatch(request.name, request.input);
|
|
1728
|
+
case "studio.zone.update": return this.config.dispatch(request.name, request.input);
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
saveRequest() {
|
|
1732
|
+
const facts = factsOf(this.ui.getState());
|
|
1733
|
+
const { fields, method } = this.snapshot;
|
|
1734
|
+
const { zone } = facts;
|
|
1735
|
+
return zoneSaveRequest({
|
|
1736
|
+
canEdit: zone === null || canEditOwnedResource({
|
|
1737
|
+
createdById: zone.created_by.id,
|
|
1738
|
+
organizationId: zone.organization_id
|
|
1739
|
+
}, this.config.userId, this.config.writableOrganizationIds),
|
|
1740
|
+
fields,
|
|
1741
|
+
method,
|
|
1742
|
+
session: facts.session,
|
|
1743
|
+
source: this.sourceFor(facts, method),
|
|
1744
|
+
zone
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
statedSource() {
|
|
1748
|
+
return this.sourceFor(factsOf(this.ui.getState()), this.snapshot.method);
|
|
1749
|
+
}
|
|
1750
|
+
publishUnsaved(unsaved) {
|
|
1751
|
+
if (this.parked || this.disposed || unsaved === this.unsavedWritten) return;
|
|
1752
|
+
this.unsavedWritten = unsaved;
|
|
1753
|
+
this.ui.getState().setZoneFormUnsaved(unsaved);
|
|
1754
|
+
}
|
|
1755
|
+
park() {
|
|
1756
|
+
if (this.unsavedWritten) {
|
|
1757
|
+
this.unsavedWritten = false;
|
|
1758
|
+
this.ui.getState().setZoneFormUnsaved(false);
|
|
1759
|
+
}
|
|
1760
|
+
this.parked = true;
|
|
1761
|
+
this.unwatch?.();
|
|
1762
|
+
this.unwatch = null;
|
|
1763
|
+
this.cancelPending();
|
|
1764
|
+
this.previewKey = void 0;
|
|
1765
|
+
this.previewInput = null;
|
|
1766
|
+
this.previewEpoch += 1;
|
|
1767
|
+
}
|
|
1768
|
+
settle() {
|
|
1769
|
+
if (this.disposed || !this.parked) return;
|
|
1770
|
+
const { settled } = this;
|
|
1771
|
+
if (settled !== null && settled.config === this.config && readsSame(settled.state, this.ui.getState())) return;
|
|
1772
|
+
this.reconcile();
|
|
1773
|
+
}
|
|
1774
|
+
watch(state) {
|
|
1775
|
+
const { settled } = this;
|
|
1776
|
+
if (settled !== null && settled.config === this.config && readsSame(settled.state, state)) {
|
|
1777
|
+
this.settled = {
|
|
1778
|
+
config: settled.config,
|
|
1779
|
+
state
|
|
1780
|
+
};
|
|
1781
|
+
return;
|
|
1782
|
+
}
|
|
1783
|
+
this.reconcile();
|
|
1784
|
+
}
|
|
1785
|
+
reconcile() {
|
|
1786
|
+
if (this.disposed) return;
|
|
1787
|
+
if (this.reconciling) {
|
|
1788
|
+
this.stale = true;
|
|
1789
|
+
return;
|
|
1790
|
+
}
|
|
1791
|
+
this.reconciling = true;
|
|
1792
|
+
try {
|
|
1793
|
+
do {
|
|
1794
|
+
this.stale = false;
|
|
1795
|
+
const state = this.ui.getState();
|
|
1796
|
+
this.settled = {
|
|
1797
|
+
config: this.config,
|
|
1798
|
+
state
|
|
1799
|
+
};
|
|
1800
|
+
const facts = factsOf(state);
|
|
1801
|
+
this.seed(facts);
|
|
1802
|
+
const view = this.view(facts);
|
|
1803
|
+
this.commit(view.snapshot);
|
|
1804
|
+
this.publishUnsaved(view.changed);
|
|
1805
|
+
this.followPreview(view);
|
|
1806
|
+
} while (this.stale && !this.disposed);
|
|
1807
|
+
} finally {
|
|
1808
|
+
this.reconciling = false;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
seed(facts) {
|
|
1812
|
+
const { draft } = this;
|
|
1813
|
+
const { activities, defaultOrganizationId, inheritedCollectionIds } = this.config;
|
|
1814
|
+
const { inherited, zone } = facts;
|
|
1815
|
+
const previous = this.bound;
|
|
1816
|
+
if (zone !== previous) {
|
|
1817
|
+
this.bound = zone;
|
|
1818
|
+
if (zone !== null && previous != null && previous.id === zone.id) this.follow(previous, zone, facts.session);
|
|
1819
|
+
else this.seedMetadata(zone);
|
|
1820
|
+
} else if (zone === null && facts.createSerial !== this.createSerial) this.seedMetadata(null);
|
|
1821
|
+
this.createSerial = zone === null ? facts.createSerial : void 0;
|
|
1822
|
+
const create = zone === null ? `${facts.createSerial}:${inherited?.itineraryId ?? ""}` : void 0;
|
|
1823
|
+
const subject = zone === null ? `create:${facts.createMethod ?? "draw"}:${create ?? ""}` : `zone:${zone.id}`;
|
|
1824
|
+
if (subject !== this.subject) {
|
|
1825
|
+
this.subject = subject;
|
|
1826
|
+
this.touched = false;
|
|
1827
|
+
this.drawFailure = null;
|
|
1828
|
+
this.pickFailure = null;
|
|
1829
|
+
this.saveFailure = null;
|
|
1830
|
+
this.sourceRefusal = null;
|
|
1831
|
+
this.previewFailure = null;
|
|
1832
|
+
this.subjectEpoch += 1;
|
|
1833
|
+
this.previewEpoch += 1;
|
|
1834
|
+
}
|
|
1835
|
+
if (facts.origin !== this.origin) {
|
|
1836
|
+
this.origin = facts.origin;
|
|
1837
|
+
this.pickFailure = null;
|
|
1838
|
+
}
|
|
1839
|
+
if (facts.session !== null) this.drawFailure = null;
|
|
1840
|
+
if (create !== this.create) {
|
|
1841
|
+
this.create = create;
|
|
1842
|
+
if (create !== void 0) this.resetCreate();
|
|
1843
|
+
}
|
|
1844
|
+
this.seedParameters(zone);
|
|
1845
|
+
if (zone !== null) return;
|
|
1846
|
+
if (inherited) {
|
|
1847
|
+
draft.organizationId = inherited.organizationId;
|
|
1848
|
+
if (!sameIds(draft.collectionIds, inheritedCollectionIds)) draft.collectionIds = [...inheritedCollectionIds];
|
|
1849
|
+
if (activities.length > 0) draft.activityId = inherited.activityId;
|
|
1850
|
+
} else {
|
|
1851
|
+
if (draft.organizationId === null && !this.organizationChosen) draft.organizationId = defaultOrganizationId;
|
|
1852
|
+
if (draft.activityId === null && activities.length > 0) draft.activityId = firstRoutableActivityId(activities);
|
|
1853
|
+
}
|
|
1854
|
+
if (!this.nameTouched) {
|
|
1855
|
+
const name = zoneAutoName({
|
|
1856
|
+
activityName: this.activityName(),
|
|
1857
|
+
language: this.config.language,
|
|
1858
|
+
method: facts.createMethod ?? "draw",
|
|
1859
|
+
proposedName: facts.session?.name ?? null,
|
|
1860
|
+
range: draft.range,
|
|
1861
|
+
rangeType: draft.rangeType,
|
|
1862
|
+
strings: this.config.strings.zoneForm
|
|
1863
|
+
});
|
|
1864
|
+
if (name !== null) draft.name = name;
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
seedParameters(zone) {
|
|
1868
|
+
const { draft } = this;
|
|
1869
|
+
const { activities } = this.config;
|
|
1870
|
+
const seeded = this.sourceSeed;
|
|
1871
|
+
if (seeded?.zone !== zone || seeded.activities !== activities) {
|
|
1872
|
+
this.sourceSeed = {
|
|
1873
|
+
activities,
|
|
1874
|
+
zone
|
|
1875
|
+
};
|
|
1876
|
+
const source = zone?.source;
|
|
1877
|
+
if (source) {
|
|
1878
|
+
const says = parametersOf(activities, source);
|
|
1879
|
+
const earlier = seeded?.zone?.id === zone?.id ? seeded?.zone?.source : void 0;
|
|
1880
|
+
if (seeded && earlier && draft.activityId === activityIdForSlug(seeded.activities, earlier.activity)) draft.activityId = activityIdForSlug(activities, earlier.activity);
|
|
1881
|
+
const said = earlier ? parametersOf(activities, earlier) : null;
|
|
1882
|
+
const held = {
|
|
1883
|
+
activityId: draft.activityId,
|
|
1884
|
+
range: draft.range,
|
|
1885
|
+
rangeType: draft.rangeType,
|
|
1886
|
+
speedKmh: draft.speedKmh
|
|
1887
|
+
};
|
|
1888
|
+
if (said === null || sameMembers(held, said) || sameMembers(held, says)) {
|
|
1889
|
+
draft.activityId = says.activityId;
|
|
1890
|
+
draft.rangeType = says.rangeType;
|
|
1891
|
+
draft.range = says.range;
|
|
1892
|
+
draft.speedKmh = says.speedKmh;
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
if (draft.activityId !== null && activities.length > 0 && activityForId(activities, draft.activityId) === null) {
|
|
1897
|
+
const stored = zone?.source?.activity;
|
|
1898
|
+
draft.activityId = stored === void 0 ? null : activityIdForSlug(activities, stored);
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
seedMetadata(zone) {
|
|
1902
|
+
const { draft } = this;
|
|
1903
|
+
draft.name = zone?.name ?? "";
|
|
1904
|
+
draft.description = zone?.description ?? "";
|
|
1905
|
+
draft.startAt = zone?.start_at ?? null;
|
|
1906
|
+
draft.endAt = zone?.end_at ?? null;
|
|
1907
|
+
draft.windowOpen = draft.startAt !== null || draft.endAt !== null;
|
|
1908
|
+
draft.createLevel = zone?.level ?? "info";
|
|
1909
|
+
this.nameTouched = zone !== null;
|
|
1910
|
+
}
|
|
1911
|
+
follow(previous, next, session) {
|
|
1912
|
+
const { draft } = this;
|
|
1913
|
+
if (session !== null && session.zoneId === next.id && session.level === previous.level && next.level !== previous.level) this.ask("studio.zone.setLevel", { level: next.level });
|
|
1914
|
+
if (!typedOver("name", draft.name, previous, next)) draft.name = next.name;
|
|
1915
|
+
if (!typedOver("description", draft.description, previous, next)) draft.description = next.description ?? "";
|
|
1916
|
+
if (!typedOver("level", draft.createLevel, previous, next)) draft.createLevel = next.level;
|
|
1917
|
+
if (!(typedOver("startAt", draft.startAt, previous, next) || typedOver("endAt", draft.endAt, previous, next) || draft.windowOpen !== windowOpens(previous) && draft.windowOpen !== windowOpens(next))) {
|
|
1918
|
+
draft.startAt = next.start_at;
|
|
1919
|
+
draft.endAt = next.end_at;
|
|
1920
|
+
draft.windowOpen = windowOpens(next);
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
resetCreate() {
|
|
1924
|
+
const { draft } = this;
|
|
1925
|
+
this.organizationChosen = false;
|
|
1926
|
+
draft.activityId = null;
|
|
1927
|
+
if (draft.collectionIds.length > 0) draft.collectionIds = [];
|
|
1928
|
+
draft.createMode = DEFAULT_ZONE_MODE;
|
|
1929
|
+
draft.organizationId = null;
|
|
1930
|
+
draft.range = ZONE_DEFAULT_DISTANCE_RANGE_METERS;
|
|
1931
|
+
draft.rangeType = "distance";
|
|
1932
|
+
draft.speedKmh = null;
|
|
1933
|
+
}
|
|
1934
|
+
activityName() {
|
|
1935
|
+
const { activityId } = this.draft;
|
|
1936
|
+
const activity = activityId === null ? null : activityForId(this.config.activities, activityId);
|
|
1937
|
+
return activity ? localizedName(activity, this.config.language) : null;
|
|
1938
|
+
}
|
|
1939
|
+
sourceFor(facts, method) {
|
|
1940
|
+
const { activityId, range, rangeType, speedKmh } = this.draft;
|
|
1941
|
+
const activity = activityId === null ? null : activityForId(this.config.activities, activityId);
|
|
1942
|
+
return zoneSourceQuery({
|
|
1943
|
+
activitySlug: activity?.slug ?? null,
|
|
1944
|
+
method,
|
|
1945
|
+
origin: facts.origin,
|
|
1946
|
+
range,
|
|
1947
|
+
rangeType,
|
|
1948
|
+
speedKmh
|
|
1949
|
+
});
|
|
1950
|
+
}
|
|
1951
|
+
view(facts) {
|
|
1952
|
+
const { draft } = this;
|
|
1953
|
+
const { session, zone } = facts;
|
|
1954
|
+
const method = zone === null ? facts.createMethod ?? "draw" : zone.source ? "reachability" : "draw";
|
|
1955
|
+
const fields = {
|
|
1956
|
+
activityId: draft.activityId,
|
|
1957
|
+
collectionIds: draft.collectionIds,
|
|
1958
|
+
description: draft.description,
|
|
1959
|
+
endAt: draft.endAt,
|
|
1960
|
+
level: session?.level ?? draft.createLevel,
|
|
1961
|
+
mode: zone === null ? session?.mode ?? draft.createMode : zone.mode,
|
|
1962
|
+
name: zone === null ? session?.name ?? draft.name : draft.name,
|
|
1963
|
+
organizationId: zone === null ? session?.organizationId ?? draft.organizationId : draft.organizationId,
|
|
1964
|
+
range: draft.range,
|
|
1965
|
+
rangeType: draft.rangeType,
|
|
1966
|
+
speedKmh: draft.speedKmh,
|
|
1967
|
+
startAt: draft.startAt,
|
|
1968
|
+
windowOpen: draft.windowOpen
|
|
1969
|
+
};
|
|
1970
|
+
const source = this.sourceFor(facts, method);
|
|
1971
|
+
const armed = session !== null;
|
|
1972
|
+
const metadataDirty = zone !== null && isZoneMetadataDirty(fields, zone);
|
|
1973
|
+
const sourceDirty = zone !== null && isZoneSourceDirty(source, zone.source);
|
|
1974
|
+
const { descriptionValid, nameValid } = this.judge(fields.name, fields.description);
|
|
1975
|
+
const saving = this.subject !== null && this.saving.has(this.subject);
|
|
1976
|
+
const windowValid = !isZoneWindowInvalid(fields.startAt, fields.endAt);
|
|
1977
|
+
const reachabilityCreate = zone === null && method === "reachability";
|
|
1978
|
+
const previewFailure = source === null ? null : this.previewFailure;
|
|
1979
|
+
const refused = this.sourceRefusal;
|
|
1980
|
+
const sourceFailure = refused !== null && refused.query === queryKeyOf(source) ? refused.failure : null;
|
|
1981
|
+
const unsaved = zone === null ? reachabilityCreate ? source !== null && previewFailure === null : isZoneGeometryDirty(session) : isZoneGeometryDirty(session) || metadataDirty || sourceDirty;
|
|
1982
|
+
const changed = reachabilityCreate ? unsaved && this.touched : unsaved;
|
|
1983
|
+
const preview = source === null ? null : {
|
|
1984
|
+
activity: source.activity,
|
|
1985
|
+
level: fields.level,
|
|
1986
|
+
location: source.location,
|
|
1987
|
+
ranges: [source.range],
|
|
1988
|
+
rangeType: source.range_type,
|
|
1989
|
+
speed: source.speed
|
|
1990
|
+
};
|
|
1991
|
+
return {
|
|
1992
|
+
preview,
|
|
1993
|
+
previewKey: preview === null ? null : JSON.stringify(preview),
|
|
1994
|
+
snapshot: {
|
|
1995
|
+
armed,
|
|
1996
|
+
descriptionValid,
|
|
1997
|
+
drawFailure: this.drawFailure,
|
|
1998
|
+
fields,
|
|
1999
|
+
inherits: facts.inherited !== null,
|
|
2000
|
+
method,
|
|
2001
|
+
nameValid,
|
|
2002
|
+
pickFailure: this.pickFailure,
|
|
2003
|
+
previewFailure,
|
|
2004
|
+
saveFailure: this.saveFailure,
|
|
2005
|
+
saveOffered: reachabilityCreate || armed || metadataDirty || sourceDirty,
|
|
2006
|
+
saveReady: !saving && nameValid && descriptionValid && windowValid && unsaved,
|
|
2007
|
+
saving,
|
|
2008
|
+
sourceFailure,
|
|
2009
|
+
windowValid,
|
|
2010
|
+
zoneId: zone?.id ?? null
|
|
2011
|
+
},
|
|
2012
|
+
changed
|
|
2013
|
+
};
|
|
2014
|
+
}
|
|
2015
|
+
judge(name, description) {
|
|
2016
|
+
const last = this.judged;
|
|
2017
|
+
if (last !== null && last.name === name && last.description === description) return last;
|
|
2018
|
+
const judged = {
|
|
2019
|
+
description,
|
|
2020
|
+
descriptionValid: zoneDescriptionSchema.safeParse(description).success,
|
|
2021
|
+
name,
|
|
2022
|
+
nameValid: zoneNameSchema.safeParse(name).success
|
|
2023
|
+
};
|
|
2024
|
+
this.judged = judged;
|
|
2025
|
+
return judged;
|
|
2026
|
+
}
|
|
2027
|
+
commit(next) {
|
|
2028
|
+
const fields = sameMembers(this.snapshot.fields, next.fields) ? this.snapshot.fields : next.fields;
|
|
2029
|
+
const snapshot = {
|
|
2030
|
+
...next,
|
|
2031
|
+
fields
|
|
2032
|
+
};
|
|
2033
|
+
if (sameMembers(this.snapshot, snapshot)) return;
|
|
2034
|
+
this.snapshot = snapshot;
|
|
2035
|
+
notifyListeners(Array.from(this.subscriptions, (subscription) => subscription.listener));
|
|
2036
|
+
}
|
|
2037
|
+
followPreview(view) {
|
|
2038
|
+
if (this.parked || view.previewKey === this.previewKey) return;
|
|
2039
|
+
this.cancelPending();
|
|
2040
|
+
this.previewKey = view.previewKey;
|
|
2041
|
+
this.previewInput = view.preview;
|
|
2042
|
+
this.previewEpoch += 1;
|
|
2043
|
+
if (view.preview === null) {
|
|
2044
|
+
this.previewFailure = null;
|
|
2045
|
+
return;
|
|
2046
|
+
}
|
|
2047
|
+
if (this.debounceMs === 0) {
|
|
2048
|
+
this.askPreview();
|
|
2049
|
+
return;
|
|
2050
|
+
}
|
|
2051
|
+
this.timer = setTimeout(() => {
|
|
2052
|
+
this.timer = null;
|
|
2053
|
+
this.askPreview();
|
|
2054
|
+
}, this.debounceMs);
|
|
2055
|
+
}
|
|
2056
|
+
askPreview() {
|
|
2057
|
+
const input = this.previewInput;
|
|
2058
|
+
if (input === null) return;
|
|
2059
|
+
const epoch = this.previewEpoch;
|
|
2060
|
+
this.ask("studio.zone.reachabilityPreview", input).then((result) => {
|
|
2061
|
+
if (result === null || epoch !== this.previewEpoch || this.parked) return;
|
|
2062
|
+
this.previewFailure = result.ok ? null : result;
|
|
2063
|
+
this.reconcile();
|
|
2064
|
+
});
|
|
2065
|
+
}
|
|
2066
|
+
cancelPending() {
|
|
2067
|
+
if (this.timer !== null) {
|
|
2068
|
+
clearTimeout(this.timer);
|
|
2069
|
+
this.timer = null;
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
};
|
|
2073
|
+
export { EmbedFramingEngine, EmbedReadyEngine, FRAMING_PAGE_SESSION_TIMEOUT_MS, ItineraryPaceEngine, ProfileMarkerEngine, SegmentDraftEngine, ShareLinkEngine, ZoneFormEngine, askFramingPageForSession };
|
|
2074
|
+
|
|
2075
|
+
//# sourceMappingURL=index.js.map
|