akanjs 3.3.0-rc.6 → 3.3.0-rc.61
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/README.ko.md +1 -0
- package/README.md +1 -0
- package/base/utils.ts +2 -0
- package/client/appOpenedTab.ts +2 -1
- package/client/clientRuntime.ts +3 -10
- package/client/cn.ts +4 -4
- package/client/cookie.ts +15 -6
- package/client/csrLocation.ts +43 -8
- package/client/csrRuntimeParams.ts +33 -0
- package/client/csrTypes.ts +18 -0
- package/client/device.ts +31 -2
- package/client/dictionaryAsset.ts +103 -25
- package/client/dictionaryGroups.ts +113 -0
- package/client/dictionaryModule.ts +23 -0
- package/client/dictionaryPart.ts +113 -0
- package/client/frameConfig.ts +12 -3
- package/client/index.ts +15 -6
- package/client/keyboardRide.ts +396 -0
- package/client/makePageProto.tsx +22 -2
- package/client/nativeBoot.ts +3 -0
- package/client/nativeErrorReport.ts +55 -0
- package/client/nativeHost.ts +2 -31
- package/client/nativeShell.ts +32 -0
- package/client/pendingNavigation.ts +63 -0
- package/client/reportText.ts +27 -0
- package/client/router.ts +34 -24
- package/client/rscClientErrorSender.ts +85 -0
- package/client/rscNavigation.ts +0 -7
- package/client/scriptPolicy.ts +14 -0
- package/client/sharedContext.ts +3 -1
- package/client/sharedContextKey.ts +2 -0
- package/client/shellState.ts +151 -0
- package/client/shellStateHooks.ts +2 -0
- package/client/translator.ts +7 -1
- package/client/translatorState.ts +18 -1
- package/client/usePendingNavigation.ts +36 -0
- package/common/CodeTranscript.ts +4 -2
- package/common/Logger.ts +4 -1
- package/common/TraceContext.ts +97 -0
- package/common/TrustedProxy.ts +10 -0
- package/common/codeAgentProfile.ts +1 -1
- package/common/codeAgentWire.ts +7 -2
- package/common/index.ts +1 -0
- package/common/inlineToken.ts +26 -0
- package/common/logContext.ts +1 -0
- package/common/sessionTokenContract.ts +7 -0
- package/common/websocketContract.ts +3 -2
- package/constant/constantRegistry.ts +36 -33
- package/constant/immerable.ts +2 -0
- package/constant/immerify.ts +1 -1
- package/constant/index.ts +0 -1
- package/constant/inputParser.ts +7 -0
- package/constant/types.ts +0 -2
- package/constant/via.ts +1 -1
- package/document/documentSchema.ts +0 -3
- package/document/filterMeta.ts +3 -16
- package/fetch/client/fetchClient.ts +28 -57
- package/fetch/client/httpClient.ts +22 -12
- package/fetch/client/modelRuntimes.ts +89 -0
- package/fetch/client/requestScope.ts +4 -1
- package/fetch/client/sliceInitHandle.ts +5 -3
- package/fetch/client/wsClient.ts +10 -6
- package/fetch/fetchType/appliedReturn.type.ts +4 -2
- package/fetch/requestStorage.ts +30 -0
- package/index.ts +38 -1
- package/package.json +268 -58
- package/server/SSR_MEMORY_DIAGNOSIS.md +88 -1
- package/server/admissionQueue.ts +107 -0
- package/server/akanApp.ts +46 -19
- package/server/akanAppHeaders.ts +20 -6
- package/server/akanOption.ts +28 -0
- package/server/akanServer.ts +109 -37
- package/server/appWorker.ts +177 -0
- package/server/appWorkerError.ts +5 -0
- package/server/appWorkerPath.ts +22 -0
- package/server/artifact/builderRpc.ts +1 -0
- package/server/artifact/ipcTypes.ts +4 -0
- package/server/artifact/routeClientCache.ts +4 -0
- package/server/assetHeaders.ts +8 -3
- package/server/cachePolicy.ts +2 -1
- package/server/clientErrorReport.ts +248 -0
- package/server/clientReportId.ts +54 -0
- package/server/console.ts +5 -12
- package/server/devtools/README.md +15 -3
- package/server/devtools/devtoolsAccess.ts +119 -0
- package/server/devtools/devtoolsRouter.ts +55 -40
- package/server/devtools/devtoolsUnlockPage.ts +38 -0
- package/server/devtools/signalSerializer.ts +18 -1
- package/server/devtools/studio/studioDocument.tsx +3 -1
- package/server/devtools/studio/studioRoute.ts +4 -1
- package/server/devtools/types.ts +6 -0
- package/server/di/diLifecycle.ts +25 -186
- package/server/di/moduleSelection.ts +202 -0
- package/server/flightSanitizeRecorded.fixture.json +36 -34
- package/server/forwardedError.ts +43 -0
- package/server/gateway/childSupervisor.ts +8 -4
- package/server/gateway/gatewayChildren.ts +4 -0
- package/server/gateway/gatewayConfig.ts +5 -0
- package/server/gateway/gatewayHttpProxy.ts +10 -2
- package/server/gateway/gatewayStatus.ts +21 -1
- package/server/gateway/gatewayStatusPage.ts +18 -11
- package/server/headSplice.ts +73 -0
- package/server/hmr/clientReport.ts +9 -9
- package/server/hmr/clientScript.ts +4 -1
- package/server/hmr/csrDevShell.ts +7 -4
- package/server/hmr/devArtifactPruner.ts +7 -1
- package/server/hmr/devBaseArtifact.ts +5 -1
- package/server/hmr/wsHub.ts +1 -0
- package/server/htmlResultCache.ts +142 -40
- package/server/imageOptimizer.ts +44 -12
- package/server/index.ts +4 -4
- package/server/lifecycle/buildEnv.ts +2 -0
- package/server/lifecycle/parentChannel.ts +11 -4
- package/server/lifecycle/secretEnv.ts +98 -0
- package/server/lifecycle/shutdownManager.ts +6 -0
- package/server/logging/logForwarder.ts +2 -2
- package/server/logging/logQuery.ts +9 -1
- package/server/logging/serverLogging.ts +24 -10
- package/server/mcp/McpDispatcher.ts +13 -10
- package/server/mcp/McpRouter.ts +2 -0
- package/server/metrics/metricAggregate.ts +27 -0
- package/server/metrics/metricExposition.ts +92 -0
- package/server/metrics/metricMerge.ts +81 -0
- package/server/metrics/metricRegistry.ts +271 -0
- package/server/metrics/pubsubGauges.ts +27 -0
- package/server/metrics/requestMetrics.ts +110 -0
- package/server/metrics/runtimeFamilies.ts +61 -0
- package/server/metrics/slowStatementLog.ts +63 -0
- package/server/metrics/statementMetrics.ts +259 -0
- package/server/metrics/statementPlanCheck.ts +141 -0
- package/server/metrics/statementReport.ts +105 -0
- package/server/migration/migrationRunner.ts +13 -10
- package/server/oauth/OAuthErrors.ts +5 -1
- package/server/ops/statusAccess.ts +23 -3
- package/server/otlp/otlpBatcher.ts +221 -0
- package/server/otlp/otlpConfig.ts +185 -0
- package/server/otlp/otlpEncode.ts +114 -0
- package/server/otlp/otlpExporter.ts +98 -0
- package/server/otlp/otlpSampler.ts +50 -0
- package/server/pageFailure.ts +33 -0
- package/server/processMetricsCollector.ts +1 -0
- package/server/renderBusyResponse.ts +97 -0
- package/server/resolver/databaseModelInstance.ts +21 -19
- package/server/resolver/httpEndpointHandler.ts +43 -0
- package/server/resolver/jobTrace.ts +18 -0
- package/server/resolver/modelFacade.ts +24 -18
- package/server/resolver/modelLoaders.ts +10 -3
- package/server/resolver/signal.resolver.ts +28 -31
- package/server/resolver/timedQuery.ts +8 -4
- package/server/resolver/unmountedRoutes.ts +55 -0
- package/server/routeCacheQuery.ts +58 -0
- package/server/routeCacheTally.ts +70 -0
- package/server/routeElementComposer.tsx +20 -0
- package/server/routeTreeBuilder.ts +6 -0
- package/server/routing/apiRouter.ts +40 -12
- package/server/routing/appWsData.ts +4 -0
- package/server/routing/builtinRoutes.ts +4 -1
- package/server/routing/devBuild.ts +4 -0
- package/server/routing/devRoutes.ts +50 -0
- package/server/routing/devSurfacePolicy.ts +41 -0
- package/server/routing/devSurfaces.ts +101 -0
- package/server/routing/hostAllowlist.ts +2 -0
- package/server/routing/roomReplay.ts +4 -0
- package/server/routing/serverListener.ts +123 -55
- package/server/routing/soloAppRoutes.ts +14 -1
- package/server/routing/webSurfaceHold.ts +117 -0
- package/server/rscClient.tsx +48 -3
- package/server/rscClientChunks.ts +8 -1
- package/server/rscClientErrors.ts +28 -0
- package/server/rscFirstRenderMemory.ts +49 -0
- package/server/rscFlightRenderer.ts +21 -4
- package/server/rscFlightStream.ts +2 -2
- package/server/rscHostRenderStream.ts +5 -3
- package/server/rscHostRequests.ts +17 -3
- package/server/rscRenderAdmission.ts +130 -0
- package/server/rscRenderControl.ts +2 -1
- package/server/rscRenderHandler.ts +112 -31
- package/server/rscRenderLevels.ts +40 -0
- package/server/rscRenderRefusal.ts +23 -0
- package/server/rscRenderStats.ts +3 -0
- package/server/rscResultCaches.ts +20 -2
- package/server/rscRouteDocument.tsx +2 -2
- package/server/rscWorker.tsx +25 -5
- package/server/rscWorkerCache.ts +2 -0
- package/server/rscWorkerHost.ts +35 -4
- package/server/rscWorkerProcess.ts +12 -0
- package/server/rscWorkerRecycler.ts +3 -3
- package/server/scriptPolicy.ts +128 -0
- package/server/selfExec.ts +13 -1
- package/server/serverConfig.ts +12 -0
- package/server/serverMetrics.ts +39 -1
- package/server/sitemap.ts +0 -5
- package/server/ssrFromRscRenderer.tsx +29 -201
- package/server/ssrInlineScripts.ts +196 -0
- package/server/ssrTypes.ts +15 -2
- package/server/systemPageDocument.tsx +6 -2
- package/server/systemPages.tsx +9 -4
- package/server/types.tsx +12 -0
- package/server/vendor/akanjs-client.ts +1 -0
- package/server/webArtifact.ts +16 -5
- package/server/webCsrSurface.ts +55 -21
- package/server/webDocumentRoute.ts +53 -23
- package/server/webRouteContext.ts +48 -11
- package/server/webRouter.ts +19 -12
- package/server/webRscRoute.ts +20 -16
- package/service/agent.service.ts +34 -8
- package/service/agentLoop/agentLoop.ts +35 -24
- package/service/agentLoop/agentLoopTypes.ts +16 -7
- package/service/agentLoop/loopCompaction.ts +1 -1
- package/service/agentLoop/loopContext.ts +33 -0
- package/service/agentLoop/loopToolkits.ts +17 -8
- package/service/index.ts +0 -1
- package/service/ipcTypes.ts +58 -0
- package/service/mentionToken.ts +44 -0
- package/service/predefinedAdaptor/anthropicLlm.ts +18 -17
- package/service/predefinedAdaptor/database.adaptor.ts +43 -9
- package/service/predefinedAdaptor/directoryNotWritableError.ts +30 -0
- package/service/predefinedAdaptor/index.ts +1 -0
- package/service/predefinedAdaptor/llm.adaptor.ts +9 -3
- package/service/predefinedAdaptor/llmContext.ts +26 -0
- package/service/predefinedAdaptor/llmFence.ts +55 -0
- package/service/predefinedAdaptor/openaiDialect.ts +45 -18
- package/service/predefinedAdaptor/solidSqlite.ts +2 -0
- package/service/predefinedAdaptor/sql/driver/bunSqlite.ts +49 -11
- package/service/predefinedAdaptor/sql/driver/postgres.ts +47 -10
- package/service/predefinedAdaptor/sql/statementFingerprint.ts +117 -0
- package/service/predefinedAdaptor/sql/statementPlans.ts +71 -0
- package/service/predefinedAdaptor/sql/statementProbe.ts +110 -0
- package/service/predefinedAdaptor/sql/statementScrub.ts +149 -0
- package/service/predefinedAdaptor/storage.adaptor.ts +5 -0
- package/service/predefinedAdaptor/websocket.adaptor.ts +6 -0
- package/signal/CrossSiteGuard.ts +5 -0
- package/signal/SignalFailure.ts +24 -2
- package/signal/browserError.ts +28 -0
- package/signal/errorReporting.ts +168 -0
- package/signal/httpPeer.ts +9 -0
- package/signal/index.ts +2 -3
- package/signal/openapi/openapi.ts +4 -0
- package/signal/requestTrace.ts +124 -0
- package/signal/roomKey.ts +3 -6
- package/signal/signalContext.ts +15 -22
- package/signal/spanExport.ts +137 -0
- package/signal/trace.ts +168 -37
- package/store/actionErrorMessage.ts +15 -1
- package/store/agent/AgentBridge.ts +6 -2
- package/store/agent/AgentContext.ts +121 -14
- package/store/agent/AgentInline.ts +122 -0
- package/store/agent/StoreCatalogue.ts +1 -1
- package/store/agent/StoreSurfaceSource.ts +27 -9
- package/store/agentic/formFields.ts +7 -2
- package/store/agentic/useFieldTool.ts +2 -1
- package/store/baseSt.ts +7 -12
- package/store/draftStore.ts +2 -2
- package/store/formUploadOf.ts +6 -3
- package/store/index.ts +1 -3
- package/store/shellMirror.ts +49 -0
- package/store/sliceLiveActions.ts +4 -3
- package/store/stateBuilder.ts +1 -6
- package/store/storeFacade.ts +50 -0
- package/store/storeInstance.ts +92 -72
- package/test/signalTestRuntime.ts +9 -2
- package/test/testServer.ts +7 -1
- package/types/base/utils.d.ts +1 -0
- package/types/client/clientRuntime.d.ts +4 -2
- package/types/client/cn.d.ts +0 -4
- package/types/client/cookie.d.ts +4 -3
- package/types/client/csrLocation.d.ts +9 -2
- package/types/client/csrRuntimeParams.d.ts +6 -0
- package/types/client/csrTypes.d.ts +17 -0
- package/types/client/device.d.ts +5 -0
- package/types/client/dictionaryAsset.d.ts +4 -1
- package/types/client/dictionaryGroups.d.ts +7 -0
- package/types/client/dictionaryModule.d.ts +10 -0
- package/types/client/dictionaryPart.d.ts +13 -0
- package/types/client/frameConfig.d.ts +1 -3
- package/types/client/index.d.ts +9 -7
- package/types/client/keyboardRide.d.ts +20 -0
- package/types/client/makePageProto.d.ts +1 -1
- package/types/client/nativeErrorReport.d.ts +10 -0
- package/types/client/nativeHost.d.ts +1 -6
- package/types/client/nativeShell.d.ts +10 -0
- package/types/client/pendingNavigation.d.ts +20 -0
- package/types/client/reportText.d.ts +4 -0
- package/types/client/router.d.ts +7 -0
- package/types/client/rscClientErrorSender.d.ts +12 -0
- package/types/client/rscNavigation.d.ts +0 -10
- package/types/client/scriptPolicy.d.ts +4 -0
- package/types/client/sharedContextKey.d.ts +2 -0
- package/types/client/shellState.d.ts +54 -0
- package/types/client/shellStateHooks.d.ts +1 -0
- package/types/client/translator.d.ts +1 -0
- package/types/client/translatorState.d.ts +9 -1
- package/types/client/usePendingNavigation.d.ts +10 -0
- package/types/common/CodeTranscript.d.ts +1 -0
- package/types/common/Logger.d.ts +2 -0
- package/types/common/TraceContext.d.ts +28 -0
- package/types/common/TrustedProxy.d.ts +1 -0
- package/types/common/codeAgentWire.d.ts +10 -2
- package/types/common/index.d.ts +1 -0
- package/types/common/inlineToken.d.ts +5 -0
- package/types/common/logContext.d.ts +1 -0
- package/types/common/sessionTokenContract.d.ts +6 -0
- package/types/constant/immerable.d.ts +1 -0
- package/types/constant/index.d.ts +1 -1
- package/types/constant/types.d.ts +0 -2
- package/types/document/documentSchema.d.ts +0 -2
- package/types/document/filterMeta.d.ts +0 -13
- package/types/fetch/client/fetchClient.d.ts +4 -4
- package/types/fetch/client/httpClient.d.ts +2 -5
- package/types/fetch/client/modelRuntimes.d.ts +17 -0
- package/types/fetch/client/wsClient.d.ts +3 -3
- package/types/fetch/fetchType/appliedReturn.type.d.ts +4 -0
- package/types/fetch/requestStorage.d.ts +9 -0
- package/types/index.d.ts +42 -1
- package/types/server/admissionQueue.d.ts +26 -0
- package/types/server/akanAppHeaders.d.ts +3 -1
- package/types/server/akanOption.d.ts +16 -1
- package/types/server/akanServer.d.ts +2 -0
- package/types/server/appWorker.d.ts +40 -0
- package/types/server/appWorkerError.d.ts +4 -0
- package/types/server/appWorkerPath.d.ts +9 -0
- package/types/server/artifact/ipcTypes.d.ts +4 -0
- package/types/server/artifact/routeClientCache.d.ts +1 -0
- package/types/server/assetHeaders.d.ts +5 -3
- package/types/server/cachePolicy.d.ts +2 -0
- package/types/server/clientErrorReport.d.ts +27 -0
- package/types/server/clientReportId.d.ts +9 -0
- package/types/server/console.d.ts +0 -7
- package/types/server/devtools/devtoolsAccess.d.ts +12 -0
- package/types/server/devtools/devtoolsRouter.d.ts +0 -1
- package/types/server/devtools/devtoolsUnlockPage.d.ts +11 -0
- package/types/server/devtools/signalSerializer.d.ts +3 -1
- package/types/server/devtools/studio/studioDocument.d.ts +1 -0
- package/types/server/devtools/types.d.ts +5 -0
- package/types/server/di/diLifecycle.d.ts +2 -1
- package/types/server/di/moduleSelection.d.ts +22 -0
- package/types/server/forwardedError.d.ts +13 -0
- package/types/server/gateway/gatewayChildren.d.ts +3 -0
- package/types/server/gateway/gatewayConfig.d.ts +1 -0
- package/types/server/gateway/gatewayHttpProxy.d.ts +1 -0
- package/types/server/gateway/gatewayStatus.d.ts +2 -0
- package/types/server/headSplice.d.ts +11 -0
- package/types/server/hmr/clientReport.d.ts +2 -0
- package/types/server/hmr/csrDevShell.d.ts +3 -1
- package/types/server/hmr/devBaseArtifact.d.ts +1 -0
- package/types/server/hmr/wsHub.d.ts +1 -0
- package/types/server/htmlResultCache.d.ts +13 -3
- package/types/server/index.d.ts +6 -3
- package/types/server/lifecycle/buildEnv.d.ts +1 -0
- package/types/server/lifecycle/parentChannel.d.ts +2 -2
- package/types/server/lifecycle/secretEnv.d.ts +23 -0
- package/types/server/logging/logForwarder.d.ts +1 -0
- package/types/server/logging/logStdoutWriter.d.ts +1 -0
- package/types/server/logging/rotatingLogWriter.d.ts +1 -1
- package/types/server/logging/serverLogging.d.ts +1 -0
- package/types/server/metrics/metricAggregate.d.ts +6 -0
- package/types/server/metrics/metricExposition.d.ts +8 -0
- package/types/server/metrics/metricMerge.d.ts +9 -0
- package/types/server/metrics/metricRegistry.d.ts +76 -0
- package/types/server/metrics/pubsubGauges.d.ts +6 -0
- package/types/server/metrics/requestMetrics.d.ts +22 -0
- package/types/server/metrics/runtimeFamilies.d.ts +9 -0
- package/types/server/metrics/slowStatementLog.d.ts +18 -0
- package/types/server/metrics/statementMetrics.d.ts +45 -0
- package/types/server/metrics/statementPlanCheck.d.ts +16 -0
- package/types/server/metrics/statementReport.d.ts +28 -0
- package/types/server/ops/statusAccess.d.ts +7 -1
- package/types/server/otlp/otlpBatcher.d.ts +18 -0
- package/types/server/otlp/otlpConfig.d.ts +25 -0
- package/types/server/otlp/otlpEncode.d.ts +13 -0
- package/types/server/otlp/otlpExporter.d.ts +18 -0
- package/types/server/otlp/otlpSampler.d.ts +10 -0
- package/types/server/pageFailure.d.ts +14 -0
- package/types/server/renderBusyResponse.d.ts +9 -0
- package/types/server/resolver/httpEndpointHandler.d.ts +14 -0
- package/types/server/resolver/jobTrace.d.ts +5 -0
- package/types/server/resolver/modelLoaders.d.ts +3 -0
- package/types/server/resolver/timedQuery.d.ts +2 -1
- package/types/server/resolver/unmountedRoutes.d.ts +6 -0
- package/types/server/routeCacheQuery.d.ts +11 -0
- package/types/server/routeCacheTally.d.ts +23 -0
- package/types/server/routeElementComposer.d.ts +3 -0
- package/types/server/routing/apiRouter.d.ts +1 -0
- package/types/server/routing/appWsData.d.ts +3 -0
- package/types/server/routing/devBuild.d.ts +3 -0
- package/types/server/routing/devRoutes.d.ts +9 -0
- package/types/server/routing/devSurfacePolicy.d.ts +12 -0
- package/types/server/routing/devSurfaces.d.ts +18 -0
- package/types/server/routing/hostAllowlist.d.ts +1 -0
- package/types/server/routing/roomReplay.d.ts +1 -0
- package/types/server/routing/serverListener.d.ts +6 -1
- package/types/server/routing/soloAppRoutes.d.ts +3 -1
- package/types/server/routing/webSurfaceHold.d.ts +13 -0
- package/types/server/rscClient.d.ts +1 -0
- package/types/server/rscClientChunks.d.ts +3 -1
- package/types/server/rscClientErrors.d.ts +3 -0
- package/types/server/rscFirstRenderMemory.d.ts +16 -0
- package/types/server/rscFlightStream.d.ts +1 -1
- package/types/server/rscHostRenderStream.d.ts +2 -1
- package/types/server/rscRenderAdmission.d.ts +14 -0
- package/types/server/rscRenderControl.d.ts +2 -1
- package/types/server/rscRenderHandler.d.ts +5 -2
- package/types/server/rscRenderLevels.d.ts +8 -0
- package/types/server/rscRenderRefusal.d.ts +9 -0
- package/types/server/rscRenderStats.d.ts +2 -0
- package/types/server/rscResultCaches.d.ts +8 -1
- package/types/server/rscWorkerCache.d.ts +2 -0
- package/types/server/rscWorkerHost.d.ts +2 -1
- package/types/server/rscWorkerProcess.d.ts +1 -0
- package/types/server/rscWorkerRecycler.d.ts +1 -1
- package/types/server/scriptPolicy.d.ts +31 -0
- package/types/server/selfExec.d.ts +1 -0
- package/types/server/serverConfig.d.ts +1 -0
- package/types/server/serverMetrics.d.ts +4 -1
- package/types/server/sitemap.d.ts +0 -2
- package/types/server/ssrFromRscRenderer.d.ts +2 -6
- package/types/server/ssrInlineScripts.d.ts +40 -0
- package/types/server/ssrTypes.d.ts +14 -2
- package/types/server/systemPageDocument.d.ts +3 -1
- package/types/server/systemPages.d.ts +2 -1
- package/types/server/types.d.ts +25 -0
- package/types/server/vendor/akanjs-client.d.ts +1 -0
- package/types/server/webRouteContext.d.ts +8 -5
- package/types/server/webRouter.d.ts +2 -1
- package/types/service/agent.service.d.ts +3 -0
- package/types/service/agentLoop/agentLoopTypes.d.ts +16 -7
- package/types/service/agentLoop/loopContext.d.ts +13 -0
- package/types/service/agentLoop/loopToolkits.d.ts +1 -0
- package/types/service/index.d.ts +0 -1
- package/types/service/ipcTypes.d.ts +62 -0
- package/types/service/mentionToken.d.ts +13 -0
- package/types/service/predefinedAdaptor/anthropicLlm.d.ts +3 -3
- package/types/service/predefinedAdaptor/database.adaptor.d.ts +2 -0
- package/types/service/predefinedAdaptor/directoryNotWritableError.d.ts +6 -0
- package/types/service/predefinedAdaptor/index.d.ts +1 -0
- package/types/service/predefinedAdaptor/llm.adaptor.d.ts +9 -3
- package/types/service/predefinedAdaptor/llmContext.d.ts +11 -0
- package/types/service/predefinedAdaptor/llmFence.d.ts +15 -0
- package/types/service/predefinedAdaptor/openaiDialect.d.ts +3 -3
- package/types/service/predefinedAdaptor/sql/driver/bunSqlite.d.ts +3 -1
- package/types/service/predefinedAdaptor/sql/driver/postgres.d.ts +3 -1
- package/types/service/predefinedAdaptor/sql/statementFingerprint.d.ts +21 -0
- package/types/service/predefinedAdaptor/sql/statementPlans.d.ts +17 -0
- package/types/service/predefinedAdaptor/sql/statementProbe.d.ts +37 -0
- package/types/service/predefinedAdaptor/sql/statementScrub.d.ts +5 -0
- package/types/service/predefinedAdaptor/storage.adaptor.d.ts +1 -0
- package/types/service/predefinedAdaptor/websocket.adaptor.d.ts +3 -0
- package/types/signal/CrossSiteGuard.d.ts +1 -0
- package/types/signal/SignalFailure.d.ts +2 -0
- package/types/signal/browserError.d.ts +20 -0
- package/types/signal/errorReporting.d.ts +27 -0
- package/types/signal/httpPeer.d.ts +5 -0
- package/types/signal/index.d.ts +3 -1
- package/types/signal/requestTrace.d.ts +33 -0
- package/types/signal/signalContext.d.ts +2 -1
- package/types/signal/spanExport.d.ts +47 -0
- package/types/signal/trace.d.ts +33 -12
- package/types/store/actionErrorMessage.d.ts +1 -0
- package/types/store/agent/AgentBridge.d.ts +1 -0
- package/types/store/agent/AgentContext.d.ts +8 -2
- package/types/store/agent/AgentInline.d.ts +21 -0
- package/types/store/agent/StoreSurfaceSource.d.ts +1 -1
- package/types/store/baseSt.d.ts +1 -3
- package/types/store/index.d.ts +2 -2
- package/types/store/shellMirror.d.ts +8 -0
- package/types/store/stateBuilder.d.ts +0 -4
- package/types/store/storeFacade.d.ts +9 -0
- package/types/test/signalTestRuntime.d.ts +1 -1
- package/types/test/testServer.d.ts +2 -0
- package/types/ui/Constant/schemaDoc.d.ts +1 -0
- package/types/ui/Data/Dashboard.d.ts +1 -0
- package/types/ui/Data/ListContainer.d.ts +1 -0
- package/types/ui/Data/QueryMaker.d.ts +1 -0
- package/types/ui/Data/RefPicker.d.ts +1 -0
- package/types/ui/Dialog/LazyLegacyModal.d.ts +1 -0
- package/types/ui/DismissDragGesture.d.ts +9 -0
- package/types/ui/Field/Text.d.ts +2 -2
- package/types/ui/Field/lightRefCache.d.ts +2 -1
- package/types/ui/Field/useRelationWindow.d.ts +2 -1
- package/types/ui/Link/Anchor.d.ts +4 -2
- package/types/ui/Load/StreamDeferred.d.ts +11 -0
- package/types/ui/Load/sliceClaim.d.ts +4 -3
- package/types/ui/Model/resetModels.d.ts +1 -0
- package/types/ui/Reference/origin.d.ts +0 -2
- package/types/ui/Signal/Arg.d.ts +1 -0
- package/types/ui/Signal/Doc.d.ts +1 -0
- package/types/ui/Signal/Endpoint.d.ts +1 -0
- package/types/ui/Signal/RestApi.d.ts +1 -0
- package/types/ui/Signal/WebSocket.d.ts +1 -0
- package/types/ui/Signal/endpointEntries.d.ts +1 -0
- package/types/ui/Signal/makeExample.d.ts +1 -0
- package/types/ui/Signal/useApiDescriptions.d.ts +1 -0
- package/types/ui/System/isSamePathValue.d.ts +2 -0
- package/types/ui/modelRuntime.d.ts +1 -0
- package/types/ui/useDismissDrag.d.ts +10 -3
- package/types/ui/useLeave.d.ts +9 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/project.d.ts +5 -0
- package/types/vendor/@akanjs/native/packages/core/src/boot.d.ts +2 -2
- package/types/vendor/@akanjs/native/plugins/external-view/src/index.d.ts +20 -8
- package/types/vendor/@akanjs/native/plugins/keyboard/src/index.d.ts +3 -2
- package/types/vendor/use-agentic/ToolRunner.d.ts +2 -1
- package/types/vendor/use-agentic/types.d.ts +10 -0
- package/types/webkit/CsrStack.d.ts +2 -1
- package/types/webkit/csrPageReadiness.d.ts +18 -0
- package/types/webkit/csrSlide.d.ts +37 -0
- package/types/webkit/isDragLift.d.ts +5 -0
- package/types/webkit/nativeNavigation.d.ts +4 -2
- package/types/webkit/nativeSplash.d.ts +6 -0
- package/types/webkit/openSurfaces.d.ts +13 -0
- package/types/webkit/scrollerTakesDrag.d.ts +4 -0
- package/types/webkit/useCsrNavigation.d.ts +2 -2
- package/types/webkit/useEscapeKey.d.ts +7 -2
- package/types/webkit/useFrameRuntime.d.ts +3 -2
- package/types/webkit/usePageLocation.d.ts +3 -1
- package/types/webkit/useVisualViewportFrame.d.ts +2 -2
- package/ui/Agent/Chat.tsx +65 -46
- package/ui/Agent/agentSessionOf.ts +2 -1
- package/ui/Agent/fetchRunner.ts +5 -1
- package/ui/Agent/useKeyboardFrame.ts +4 -2
- package/ui/BottomSheet.tsx +3 -7
- package/ui/Constant/schemaDoc.ts +1 -0
- package/ui/Copy.tsx +5 -3
- package/ui/Data/Dashboard.tsx +1 -0
- package/ui/Data/ListContainer.tsx +1 -0
- package/ui/Data/QueryMaker.tsx +1 -0
- package/ui/Data/RefPicker.tsx +1 -0
- package/ui/Dialog/LazyLegacyModal.tsx +5 -0
- package/ui/Dialog/LegacyModal.tsx +3 -4
- package/ui/Dialog/Modal.tsx +40 -22
- package/ui/Dialog/index.tsx +2 -2
- package/ui/Dialog/modalSurface.ts +6 -4
- package/ui/DismissDragGesture.tsx +19 -0
- package/ui/DragAction.tsx +9 -4
- package/ui/Field/Label.tsx +5 -2
- package/ui/Field/Text.tsx +7 -4
- package/ui/Field/index.tsx +2 -3
- package/ui/Field/lightRefCache.ts +9 -8
- package/ui/Field/useRelationOptions.ts +2 -2
- package/ui/Field/useRelationWindow.ts +9 -4
- package/ui/Input.tsx +1 -1
- package/ui/Link/Anchor.tsx +33 -3
- package/ui/Link/activePath.ts +2 -3
- package/ui/Link/index.tsx +11 -1
- package/ui/Load/Stream.tsx +8 -0
- package/ui/Load/StreamDeferred.tsx +27 -0
- package/ui/Load/Units.tsx +1 -1
- package/ui/Load/sliceClaim.ts +11 -5
- package/ui/Model/EditModal.tsx +6 -7
- package/ui/Model/EditWrapper.tsx +2 -3
- package/ui/Model/NewWrapper_Client.tsx +2 -3
- package/ui/Model/ViewEditModal.tsx +4 -5
- package/ui/Model/ViewModal.tsx +2 -3
- package/ui/Model/ViewWrapper.tsx +2 -3
- package/ui/Model/editSeed.ts +1 -1
- package/ui/Model/resetModels.ts +11 -0
- package/ui/Reference/origin.ts +0 -10
- package/ui/Signal/Arg.tsx +4 -1
- package/ui/Signal/Doc.tsx +1 -0
- package/ui/Signal/Endpoint.tsx +4 -1
- package/ui/Signal/RestApi.tsx +1 -0
- package/ui/Signal/WebSocket.tsx +1 -0
- package/ui/Signal/endpointEntries.ts +1 -0
- package/ui/Signal/makeExample.ts +1 -0
- package/ui/Signal/useApiDescriptions.ts +10 -0
- package/ui/System/CSR.tsx +30 -12
- package/ui/System/Client.tsx +74 -58
- package/ui/System/Messages.tsx +31 -47
- package/ui/System/SSR.tsx +4 -2
- package/ui/System/isSamePathValue.ts +13 -0
- package/ui/Tooltip.tsx +1 -1
- package/ui/agentAttrs.ts +1 -1
- package/ui/modelRuntime.ts +2 -0
- package/ui/styles.css +14 -0
- package/ui/useDismissDrag.ts +135 -5
- package/ui/useLeave.ts +42 -0
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeActivity.kt +27 -14
- package/vendor/@akanjs/native/native/desktop/Cargo.lock +1 -0
- package/vendor/@akanjs/native/native/desktop/Cargo.toml +2 -0
- package/vendor/@akanjs/native/native/desktop/src/acl.rs +27 -7
- package/vendor/@akanjs/native/native/desktop/src/external.rs +240 -29
- package/vendor/@akanjs/native/native/desktop/src/lib.rs +3 -3
- package/vendor/@akanjs/native/native/desktop/src/navigation.rs +4 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/acl.ts +10 -2
- package/vendor/@akanjs/native/packages/cli/src/lib/compat.ts +1 -1
- package/vendor/@akanjs/native/packages/cli/src/lib/distribution.ts +1 -1
- package/vendor/@akanjs/native/packages/cli/src/lib/project.ts +11 -1
- package/vendor/@akanjs/native/packages/core/src/boot.ts +2 -2
- package/vendor/@akanjs/native/plugins/external-view/native-plugin.json +26 -0
- package/vendor/@akanjs/native/plugins/external-view/src/desktop.ts +9 -1
- package/vendor/@akanjs/native/plugins/external-view/src/index.ts +20 -8
- package/vendor/@akanjs/native/plugins/keyboard/src/index.ts +3 -2
- package/vendor/use-agentic/AgentSession.ts +1 -1
- package/vendor/use-agentic/Compaction.ts +1 -1
- package/vendor/use-agentic/ToolRunner.ts +12 -0
- package/vendor/use-agentic/WIRE.md +8 -2
- package/vendor/use-agentic/types.ts +10 -0
- package/webkit/CsrRouteTable.ts +1 -1
- package/webkit/CsrStack.ts +17 -9
- package/webkit/McpAppAgent.ts +4 -2
- package/webkit/McpAppFetchBridge.ts +1 -1
- package/webkit/RenderLayer.tsx +163 -78
- package/webkit/bootCsr.tsx +19 -1
- package/webkit/csrPageReadiness.ts +43 -0
- package/webkit/csrSlide.ts +190 -0
- package/webkit/isDragLift.ts +7 -0
- package/webkit/nativeNavigation.ts +41 -3
- package/webkit/nativeSplash.ts +30 -0
- package/webkit/openSurfaces.ts +54 -0
- package/webkit/scrollerTakesDrag.ts +34 -0
- package/webkit/useCsrKeyboard.ts +7 -1
- package/webkit/useCsrNavigation.ts +84 -30
- package/webkit/useCsrStackLifecycle.ts +2 -1
- package/webkit/useCsrTransitions.ts +214 -61
- package/webkit/useCsrValues.ts +15 -6
- package/webkit/useEscapeKey.tsx +10 -23
- package/webkit/useFrameRuntime.ts +13 -8
- package/webkit/usePageLocation.ts +12 -7
- package/webkit/useVisualViewportFrame.tsx +2 -4
- package/ARCHITECTURE.md +0 -199
- package/CHANGELOG.md +0 -5054
- package/CODE_OF_CONDUCT.md +0 -54
- package/CONTRIBUTING.md +0 -109
- package/client/locale.ts +0 -5
- package/service/serviceRegistry.ts +0 -27
- package/types/client/locale.d.ts +0 -6
- package/types/service/serviceRegistry.d.ts +0 -10
- package/vendor/@akanjs/native/CHANGELOG.md +0 -9
- package/vendor/use-agentic/CHANGELOG.md +0 -694
package/README.ko.md
CHANGED
|
@@ -107,6 +107,7 @@ cd dist/apps/<app> && PORT=3000 bun main.js
|
|
|
107
107
|
- `akanjs`는 npm 패키지 하나입니다. subpath(`akanjs/base`, `akanjs/client`, `akanjs/signal`, `akanjs/ui`, …)가 서버
|
|
108
108
|
전용, 클라이언트 전용, UI, 툴링 코드를 나누고([패키지 레퍼런스](https://akanjs.com/references/akanjs/base)), 툴링은
|
|
109
109
|
`@akanjs/cli`와 `@akanjs/devkit`으로 나옵니다.
|
|
110
|
+
- 버전별 변경: [`CHANGELOG.md`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CHANGELOG.md).
|
|
110
111
|
- 기여: [`CONTRIBUTING.md`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CONTRIBUTING.md)와
|
|
111
112
|
[행동 강령](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CODE_OF_CONDUCT.md). 라이선스: MIT
|
|
112
113
|
([`LICENSE`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/LICENSE)).
|
package/README.md
CHANGED
|
@@ -106,6 +106,7 @@ you are running on a public URL.
|
|
|
106
106
|
- `akanjs` is one npm package. Its subpaths (`akanjs/base`, `akanjs/client`, `akanjs/signal`, `akanjs/ui`, …) keep
|
|
107
107
|
server-only, client-only, UI and tooling code apart, and the [package reference](https://akanjs.com/references/akanjs/base)
|
|
108
108
|
covers them; the tooling ships as `@akanjs/cli` and `@akanjs/devkit`.
|
|
109
|
+
- Changes by version: [`CHANGELOG.md`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CHANGELOG.md).
|
|
109
110
|
- Contributing: [`CONTRIBUTING.md`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CONTRIBUTING.md) and
|
|
110
111
|
the [code of conduct](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CODE_OF_CONDUCT.md). License: MIT
|
|
111
112
|
([`LICENSE`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/LICENSE)).
|
package/base/utils.ts
CHANGED
|
@@ -25,3 +25,5 @@ export const applyFnToArrayObjects = <Input, Fn extends (arg: never) => unknown>
|
|
|
25
25
|
if (Array.isArray(arraiedData)) return arraiedData.map((data) => applyFnToArrayObjects(data, fn)) as Result;
|
|
26
26
|
return fn(arraiedData as never) as Result;
|
|
27
27
|
};
|
|
28
|
+
|
|
29
|
+
export const loadedAfter = (..._modules: unknown[]): void => {};
|
package/client/appOpenedTab.ts
CHANGED
package/client/clientRuntime.ts
CHANGED
|
@@ -38,6 +38,8 @@ type RuntimeErr = {
|
|
|
38
38
|
|
|
39
39
|
type RuntimeWs = {
|
|
40
40
|
connected: boolean;
|
|
41
|
+
state?: "connecting" | "open" | "closed" | "gaveUp";
|
|
42
|
+
connect?: (option?: { fresh?: boolean }) => void;
|
|
41
43
|
on: (event: string, handler: (...args: unknown[]) => void) => void;
|
|
42
44
|
off: (event: string, handler: (...args: unknown[]) => void) => void;
|
|
43
45
|
};
|
|
@@ -80,13 +82,6 @@ globalWithRuntime[CLIENT_RUNTIME_KEY] = state;
|
|
|
80
82
|
const missingRuntimeError = () =>
|
|
81
83
|
new Error("Akan client runtime is not registered. Import the generated app client first.");
|
|
82
84
|
|
|
83
|
-
const applyRuntimeErrorConstructor = (runtime: ClientRuntime) => {
|
|
84
|
-
const instance = (runtime.fetch as RuntimeFetch | undefined)?.instance as
|
|
85
|
-
| { setErrorConstructor?: (Err: unknown) => void }
|
|
86
|
-
| undefined;
|
|
87
|
-
if (typeof instance?.setErrorConstructor === "function") instance.setErrorConstructor(runtime.Err);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
85
|
export const registerClientRuntime = <Runtime>(
|
|
91
86
|
runtime: Runtime,
|
|
92
87
|
{ scope = "app" }: { scope?: RuntimeScope } = {},
|
|
@@ -94,12 +89,10 @@ export const registerClientRuntime = <Runtime>(
|
|
|
94
89
|
if (state.scope === "app" && scope === "lib") return runtime;
|
|
95
90
|
state.runtime = runtime as ClientRuntime;
|
|
96
91
|
state.scope = scope;
|
|
97
|
-
applyRuntimeErrorConstructor(state.runtime);
|
|
98
92
|
return runtime;
|
|
99
93
|
};
|
|
100
94
|
|
|
101
|
-
|
|
102
|
-
export const getClientRuntime = () => {
|
|
95
|
+
const getClientRuntime = () => {
|
|
103
96
|
if (!state.runtime) throw missingRuntimeError();
|
|
104
97
|
return state.runtime;
|
|
105
98
|
};
|
package/client/cn.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ClassNameValue, extendTailwindMerge } from "tailwind-merge";
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/** Registered with tailwind-merge so `cn("bg-primary", "bg-open")` resolves to `"bg-open"` instead of keeping both. */
|
|
4
|
+
const colorTokens = [
|
|
5
5
|
"background",
|
|
6
6
|
"foreground",
|
|
7
7
|
"primary",
|
|
@@ -33,8 +33,8 @@ export const colorTokens = [
|
|
|
33
33
|
"ring",
|
|
34
34
|
];
|
|
35
35
|
|
|
36
|
-
/**
|
|
37
|
-
|
|
36
|
+
/** `--radius-box` / `--radius-field`; unregistered, `cn("rounded-field", "rounded-full")` would keep both. */
|
|
37
|
+
const radiusTokens = ["box", "field"];
|
|
38
38
|
|
|
39
39
|
const twMerge = extendTailwindMerge({
|
|
40
40
|
extend: {
|
package/client/cookie.ts
CHANGED
|
@@ -153,25 +153,34 @@ export interface GetOption {
|
|
|
153
153
|
unauthorize: string;
|
|
154
154
|
}
|
|
155
155
|
interface SetAuthOption {
|
|
156
|
-
jwt
|
|
156
|
+
jwt?: string | null;
|
|
157
157
|
}
|
|
158
158
|
const announceAuth = () => {
|
|
159
159
|
if (typeof window !== "undefined") window.dispatchEvent(new Event("akan:auth"));
|
|
160
160
|
};
|
|
161
|
+
|
|
162
|
+
const reopenSocket = () => {
|
|
163
|
+
const { ws } = fetch;
|
|
164
|
+
if (ws?.state === "open" || ws?.state === "connecting") ws.connect?.({ fresh: true });
|
|
165
|
+
};
|
|
161
166
|
/** Sets the active auth token on fetch, then keeps it where the next launch finds it: client storage on a CSR client,
|
|
162
|
-
* the session cookie elsewhere unless the server already holds it there (`SessionCookie.issue`).
|
|
163
|
-
|
|
164
|
-
|
|
167
|
+
* the session cookie elsewhere unless the server already holds it there (`SessionCookie.issue`). An answer with no
|
|
168
|
+
* token beside a session the server holds is a cookie-only session: fetch sends no token and the socket reconnects. */
|
|
169
|
+
export const setAuth = ({ jwt }: SetAuthOption = {}) => {
|
|
170
|
+
const token = jwt ?? "";
|
|
171
|
+
const cookieOnly = !token && serverHoldsSession();
|
|
172
|
+
fetch.setJwt(cookieOnly ? null : token);
|
|
165
173
|
|
|
166
|
-
if (isCsrClient()) void secretStorage.setItem(storedAuthTokenKey(),
|
|
174
|
+
if (isCsrClient()) void secretStorage.setItem(storedAuthTokenKey(), token);
|
|
167
175
|
else {
|
|
168
176
|
|
|
169
177
|
void secretStorage.removeItem(storedAuthTokenKey());
|
|
170
|
-
if (!serverHoldsSession()) setCookie(authTokenKey(),
|
|
178
|
+
if (!serverHoldsSession()) setCookie(authTokenKey(), token);
|
|
171
179
|
}
|
|
172
180
|
|
|
173
181
|
for (const key of retiredAuthTokenKeys()) removeCookie(key);
|
|
174
182
|
void secretStorage.removeItem(legacyAuthTokenKey);
|
|
183
|
+
if (cookieOnly) reopenSocket();
|
|
175
184
|
announceAuth();
|
|
176
185
|
};
|
|
177
186
|
|
package/client/csrLocation.ts
CHANGED
|
@@ -8,8 +8,10 @@ declare global {
|
|
|
8
8
|
export class CsrLocation {
|
|
9
9
|
|
|
10
10
|
#view: URL | null = null;
|
|
11
|
-
#entry: { idx: number | undefined; href: string } | null = null;
|
|
11
|
+
#entry: { idx: number | undefined; href: string; from: string | undefined } | null = null;
|
|
12
12
|
#onBack: ((idx: number) => void) | null = null;
|
|
13
|
+
#backAsked: object | null = null;
|
|
14
|
+
#backSent: object | null = null;
|
|
13
15
|
|
|
14
16
|
/** Reads `href`, a path on the app's origin, as this document's location from now on; a view never moves. */
|
|
15
17
|
view(href: string) {
|
|
@@ -44,25 +46,28 @@ export class CsrLocation {
|
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
/**
|
|
47
|
-
* The entry on screen as of the last write or traversal,
|
|
48
|
-
*
|
|
49
|
+
* The entry on screen as of the last write or traversal, its index, and `from`, the address a push stacked it on
|
|
50
|
+
* (none for an entry a document load or a fragment link made); during a `popstate` it is still the entry left,
|
|
51
|
+
* which `state` no longer reads.
|
|
49
52
|
*/
|
|
50
53
|
entry() {
|
|
51
54
|
return this.#entry ?? this.observe();
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
observe() {
|
|
55
|
-
|
|
58
|
+
const state = window.history?.state;
|
|
59
|
+
this.#entry = { idx: CsrLocation.idxOf(state), href: this.href, from: CsrLocation.#fromOf(state) };
|
|
56
60
|
return this.#entry;
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
push(state: unknown, href: string) {
|
|
60
|
-
|
|
64
|
+
const stacked = CsrLocation.#indexed(state, (this.entry().idx ?? 0) + 1) as { __akanRouter?: object };
|
|
65
|
+
window.history.pushState({ ...stacked, __akanRouter: { ...stacked.__akanRouter, from: this.href } }, "", href);
|
|
61
66
|
this.observe();
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
replace(state: unknown, href?: string) {
|
|
65
|
-
const indexed = CsrLocation.#indexed(state, this.entry().idx ?? 0);
|
|
70
|
+
const indexed = CsrLocation.#rewritten(CsrLocation.#indexed(state, this.entry().idx ?? 0), window.history.state);
|
|
66
71
|
if (href === undefined) window.history.replaceState(indexed, "");
|
|
67
72
|
else window.history.replaceState(indexed, "", href);
|
|
68
73
|
this.observe();
|
|
@@ -73,6 +78,18 @@ export class CsrLocation {
|
|
|
73
78
|
return Number.isInteger(idx) ? (idx as number) : undefined;
|
|
74
79
|
}
|
|
75
80
|
|
|
81
|
+
static #fromOf(state: unknown) {
|
|
82
|
+
const from = (state as { __akanRouter?: { from?: unknown } } | null)?.__akanRouter?.from;
|
|
83
|
+
return typeof from === "string" ? from : undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static #rewritten(state: unknown, live: unknown) {
|
|
87
|
+
const from = CsrLocation.#fromOf(live);
|
|
88
|
+
if (from === undefined || CsrLocation.#fromOf(state) !== undefined) return state;
|
|
89
|
+
const record = (state ?? {}) as { __akanRouter?: object };
|
|
90
|
+
return { ...record, __akanRouter: { ...record.__akanRouter, from } };
|
|
91
|
+
}
|
|
92
|
+
|
|
76
93
|
static #indexed(state: unknown, idx: number) {
|
|
77
94
|
if (CsrLocation.idxOf(state) !== undefined) return state;
|
|
78
95
|
const record = (state ?? {}) as { __akanRouter?: object };
|
|
@@ -84,9 +101,27 @@ export class CsrLocation {
|
|
|
84
101
|
this.#onBack = listener;
|
|
85
102
|
}
|
|
86
103
|
|
|
104
|
+
/** Holds the entry on screen as left until `moving`, a shell's back, settles; `back()` holds it until the pop lands. */
|
|
105
|
+
leaving(moving: unknown) {
|
|
106
|
+
const entry = this.entry();
|
|
107
|
+
this.#backAsked = entry;
|
|
108
|
+
const release = () => {
|
|
109
|
+
if (this.#backAsked === entry) this.#backAsked = null;
|
|
110
|
+
};
|
|
111
|
+
void Promise.resolve(moving).then(release, release);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Whether a back has left the entry on screen and not landed yet. */
|
|
115
|
+
isLeaving() {
|
|
116
|
+
const entry = this.entry();
|
|
117
|
+
return entry === this.#backAsked || entry === this.#backSent;
|
|
118
|
+
}
|
|
119
|
+
|
|
87
120
|
back() {
|
|
88
|
-
const
|
|
89
|
-
if (idx !== undefined) this.#onBack?.(idx - 1);
|
|
121
|
+
const entry = this.entry();
|
|
122
|
+
if (entry.idx !== undefined) this.#onBack?.(entry.idx - 1);
|
|
123
|
+
|
|
124
|
+
if (entry.idx !== undefined && entry.idx > 0) this.#backSent = entry;
|
|
90
125
|
window.history.back();
|
|
91
126
|
}
|
|
92
127
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { csrLocation } from "./csrLocation";
|
|
2
|
+
import { Href } from "./href";
|
|
3
|
+
|
|
4
|
+
/** The params a CSR boot reads off its address (`?csr=true`), which every address it moves to carries along. */
|
|
5
|
+
export class CsrRuntimeParams {
|
|
6
|
+
static readonly #names = ["csr", "akanMobileTarget", "akanMobileBasePath", "akanMobileIndexPath"] as const;
|
|
7
|
+
|
|
8
|
+
static carry(href: string) {
|
|
9
|
+
const currentSearch = new URLSearchParams(csrLocation.search);
|
|
10
|
+
if (currentSearch.get("csr") !== "true" || Href.hasWebScheme(href)) return href;
|
|
11
|
+
|
|
12
|
+
const [hrefWithoutHash, hash = ""] = href.split("#");
|
|
13
|
+
const [pathname, search = ""] = hrefWithoutHash.split("?");
|
|
14
|
+
const nextSearch = new URLSearchParams(search);
|
|
15
|
+
for (const param of CsrRuntimeParams.#names) {
|
|
16
|
+
if (nextSearch.has(param)) continue;
|
|
17
|
+
const value = currentSearch.get(param);
|
|
18
|
+
if (value !== null) nextSearch.set(param, value);
|
|
19
|
+
}
|
|
20
|
+
const query = nextSearch.toString();
|
|
21
|
+
return `${pathname}${query ? `?${query}` : ""}${hash ? `#${hash}` : ""}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static sameRoute(a: string, b: string) {
|
|
25
|
+
const [left, right] = [a, b].map((href) => {
|
|
26
|
+
const url = new URL(href, "http://route.invalid");
|
|
27
|
+
for (const param of CsrRuntimeParams.#names) url.searchParams.delete(param);
|
|
28
|
+
url.searchParams.sort();
|
|
29
|
+
return `${url.pathname}?${url.searchParams.toString()}${url.hash}`;
|
|
30
|
+
});
|
|
31
|
+
return left === right;
|
|
32
|
+
}
|
|
33
|
+
}
|
package/client/csrTypes.ts
CHANGED
|
@@ -21,6 +21,9 @@ export type PageSafeAreaConfig =
|
|
|
21
21
|
};
|
|
22
22
|
/** The sides whose chrome the page runs under instead of below. */
|
|
23
23
|
export type PageOverlayConfig = boolean | "top" | "bottom";
|
|
24
|
+
|
|
25
|
+
/** How a page's navbar moves when it transitions; see `PageConfig.navbarMotion`. */
|
|
26
|
+
export type NavbarMotion = "crossfade" | "page";
|
|
24
27
|
/** `"stream"` flushes the shell (`Loading` included) then streams; a redirect in suspended content becomes a client one.
|
|
25
28
|
* `"block"` buffers the whole document, so an error in slow content can still render a clean error page. */
|
|
26
29
|
export type SsrRenderMode = "stream" | "block";
|
|
@@ -42,6 +45,13 @@ export interface PageConfig {
|
|
|
42
45
|
* and an overlaid side's safe area defaults to transparent.
|
|
43
46
|
*/
|
|
44
47
|
overlay?: PageOverlayConfig;
|
|
48
|
+
/**
|
|
49
|
+
* How the navbar (`Layout.Navbar`'s top inset and its back button) moves when this page transitions.
|
|
50
|
+
* `"crossfade"`, the default, keeps one bar in place and crossfades the two pages' bars, as UIKit's does; between a
|
|
51
|
+
* page with a bar and one without, the bar's height folds away. `"page"` moves each bar with its page, as a part of
|
|
52
|
+
* the page, for a bar that is the page's own surface (translucent, or with no fill of its own).
|
|
53
|
+
*/
|
|
54
|
+
navbarMotion?: NavbarMotion;
|
|
45
55
|
gesture?: boolean;
|
|
46
56
|
cache?: boolean;
|
|
47
57
|
/** Initial full-document SSR strategy. Defaults to `"stream"`. */
|
|
@@ -55,6 +65,10 @@ export interface PageConfig {
|
|
|
55
65
|
/** `false` answers a `Link` prefetch of the page (on a layout, of every page under it) without rendering it, for a
|
|
56
66
|
* render with a side effect such as counting a view; the click renders it as usual. */
|
|
57
67
|
prefetch?: boolean;
|
|
68
|
+
/** `false` keys the page in the RSC and HTML result caches on its query exactly as requested (on a layout, every
|
|
69
|
+
* page under it), for a page whose output follows parameter order or a tracking parameter it reads without declaring
|
|
70
|
+
* it with `.search()`. By default the key sorts the query and leaves out `AKAN_ROUTE_CACHE_TRACKING_PARAMS`. */
|
|
71
|
+
canonicalQuery?: boolean;
|
|
58
72
|
topSafeAreaColor?: string;
|
|
59
73
|
bottomSafeAreaColor?: string;
|
|
60
74
|
/** Keeps the route (on a `_layout`, its whole directory) out of `akan build` while `akan start` serves it. Write a
|
|
@@ -73,6 +87,8 @@ export interface CsrState {
|
|
|
73
87
|
/** Web only: the sides whose safe area `env(safe-area-inset-*)` measures, since a browser tells script nothing. */
|
|
74
88
|
safeAreaEnv?: { top: boolean; bottom: boolean };
|
|
75
89
|
overlay?: { top: boolean; bottom: boolean };
|
|
90
|
+
/** Set when the page declares one; left out, the navbar crossfades. */
|
|
91
|
+
navbarMotion?: NavbarMotion;
|
|
76
92
|
gesture: boolean;
|
|
77
93
|
cache: boolean;
|
|
78
94
|
ssr: SsrRenderMode;
|
|
@@ -162,6 +178,8 @@ export interface RouteRender {
|
|
|
162
178
|
getLayoutManifest?: () => PromiseOrObject<WebAppManifest | undefined>;
|
|
163
179
|
/** The `page()` chain behind a page render, when it was declared as one — what a page prompt is read off. */
|
|
164
180
|
getRouteDefinition?: () => PromiseOrObject<RouteDefinition | undefined>;
|
|
181
|
+
/** The query names the level reads; `undefined` for a legacy module, which receives every one. */
|
|
182
|
+
getSearchNames?: () => PromiseOrObject<string[] | undefined>;
|
|
165
183
|
}
|
|
166
184
|
export interface RouteViewport {
|
|
167
185
|
/** `viewport-fit=cover`: the page runs under the notch and home indicator, and `env(safe-area-inset-*)` measures them. */
|
package/client/device.ts
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { parseAkanI18nEnv } from "akanjs/common";
|
|
2
3
|
import type { RefObject } from "react";
|
|
3
4
|
import { csrLocation } from "./csrLocation";
|
|
4
5
|
import { readCssSafeAreaInsets } from "./frameConfig";
|
|
5
6
|
import type { DeviceInfo } from "./native";
|
|
6
7
|
|
|
7
8
|
type NativeModule = typeof import("./native");
|
|
9
|
+
type KeyboardRideClass = typeof import("./keyboardRide").KeyboardRide;
|
|
8
10
|
type NativeControls = Pick<NativeModule, "haptics" | "keyboard">;
|
|
9
11
|
type ProcessEnvLike = { env?: Record<string, string | undefined> };
|
|
10
12
|
type DebugPayload = Record<string, unknown>;
|
|
11
13
|
|
|
12
14
|
const globalWithProcess = globalThis as typeof globalThis & { process?: ProcessEnvLike };
|
|
13
15
|
|
|
16
|
+
/** Whether the shell left the keyboard to the page; an older shell still pans to the field, so the page must not. */
|
|
17
|
+
export const isPageKeyboardAvoidance = () =>
|
|
18
|
+
(globalThis as { __AKAN_NATIVE__?: { keyboardAvoidance?: string } }).__AKAN_NATIVE__?.keyboardAvoidance === "page";
|
|
19
|
+
|
|
20
|
+
export const IOS_KEYBOARD_ANIMATION_EASING = "cubic-bezier(0.38, 0.7, 0.125, 1)";
|
|
21
|
+
|
|
22
|
+
export const ANDROID_KEYBOARD_ANIMATION_EASING = "cubic-bezier(0.2, 0, 0, 1)";
|
|
23
|
+
export const nativeKeyboardEasing = () =>
|
|
24
|
+
(globalThis as { __AKAN_NATIVE__?: { platform?: string } }).__AKAN_NATIVE__?.platform === "android"
|
|
25
|
+
? ANDROID_KEYBOARD_ANIMATION_EASING
|
|
26
|
+
: IOS_KEYBOARD_ANIMATION_EASING;
|
|
27
|
+
|
|
14
28
|
const debugSessionId = crypto.getRandomValues(new Uint32Array(1))[0].toString(36);
|
|
15
29
|
let debugSeq = 0;
|
|
16
30
|
|
|
@@ -92,6 +106,12 @@ const langInPath = (pathname: string, supportLanguages: string[] | readonly stri
|
|
|
92
106
|
return supportLanguages.find((language) => language === predefinedLangPath);
|
|
93
107
|
};
|
|
94
108
|
|
|
109
|
+
const supportedLang = (code: string, supportLanguages: string[] | readonly string[]) => {
|
|
110
|
+
if (supportLanguages.length === 0 || supportLanguages.includes(code)) return code;
|
|
111
|
+
const { defaultLocale } = parseAkanI18nEnv();
|
|
112
|
+
return supportLanguages.includes(defaultLocale) ? defaultLocale : (supportLanguages[0] ?? code);
|
|
113
|
+
};
|
|
114
|
+
|
|
95
115
|
const createWebDevice = ({
|
|
96
116
|
lang,
|
|
97
117
|
supportLanguages,
|
|
@@ -101,7 +121,7 @@ const createWebDevice = ({
|
|
|
101
121
|
}) => {
|
|
102
122
|
const pathname = typeof window === "undefined" ? "" : csrLocation.pathname;
|
|
103
123
|
return new Device({
|
|
104
|
-
lang: lang ?? langInPath(pathname, supportLanguages) ?? getBrowserLanguage(),
|
|
124
|
+
lang: lang ?? langInPath(pathname, supportLanguages) ?? supportedLang(getBrowserLanguage(), supportLanguages),
|
|
105
125
|
info: webDeviceInfo,
|
|
106
126
|
topSafeArea: 0,
|
|
107
127
|
bottomSafeArea: 0,
|
|
@@ -133,7 +153,8 @@ export class Device {
|
|
|
133
153
|
|
|
134
154
|
const { top: topSafeArea, bottom: bottomSafeArea } = readCssSafeAreaInsets();
|
|
135
155
|
Device.instance = new Device({
|
|
136
|
-
lang:
|
|
156
|
+
lang:
|
|
157
|
+
lang ?? langInPath(window.location.pathname, supportLanguages) ?? supportedLang(languageCode, supportLanguages),
|
|
137
158
|
info,
|
|
138
159
|
topSafeArea,
|
|
139
160
|
bottomSafeArea,
|
|
@@ -171,9 +192,16 @@ export class Device {
|
|
|
171
192
|
async hideKeyboard() {
|
|
172
193
|
await this.#native?.keyboard.hide();
|
|
173
194
|
}
|
|
195
|
+
|
|
196
|
+
static #keyboardRide: KeyboardRideClass | null = null;
|
|
174
197
|
listenKeyboardChanged(onKeyboardChanged: (height: number) => void) {
|
|
175
198
|
const keyboard = this.#native?.keyboard;
|
|
176
199
|
if (!keyboard) return;
|
|
200
|
+
if (isPageKeyboardAvoidance())
|
|
201
|
+
void import("./keyboardRide").then(({ KeyboardRide }) => {
|
|
202
|
+
Device.#keyboardRide = KeyboardRide;
|
|
203
|
+
KeyboardRide.watchFocus();
|
|
204
|
+
});
|
|
177
205
|
let currentHeight = 0;
|
|
178
206
|
const emitKeyboardHeight = (event: string, height: number) => {
|
|
179
207
|
debugFrame("keyboard.event", { event, height, previousHeight: currentHeight });
|
|
@@ -187,6 +215,7 @@ export class Device {
|
|
|
187
215
|
...(["willShow", "didShow", "willHide", "didHide"] as const).map((event) =>
|
|
188
216
|
keyboard.listen(event, ({ height, duration }) => {
|
|
189
217
|
if (duration > 0) this.keyboardAnimationMs = duration;
|
|
218
|
+
Device.#keyboardRide?.move(height, this.keyboardAnimationMs);
|
|
190
219
|
emitKeyboardHeight(event, height);
|
|
191
220
|
}),
|
|
192
221
|
),
|
|
@@ -1,32 +1,110 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type DictionaryModule, importDictionaryModule } from "./dictionaryModule";
|
|
2
|
+
import { DictionaryPart } from "./dictionaryPart";
|
|
3
|
+
import { TranslatorState } from "./translatorState";
|
|
2
4
|
|
|
3
|
-
interface
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
interface DictionaryAssetState {
|
|
6
|
+
loads: Map<string, Promise<DictionaryModule>>;
|
|
7
|
+
appliedSeqByLang: Map<string, number>;
|
|
8
|
+
seq: number;
|
|
9
|
+
|
|
10
|
+
wholes: WeakSet<object>;
|
|
11
|
+
|
|
12
|
+
groupsBySnapshot: WeakMap<object, Set<string>>;
|
|
6
13
|
}
|
|
7
14
|
|
|
15
|
+
const dictionaryAssetStateKey = "__AKAN_DICTIONARY_ASSET__";
|
|
16
|
+
|
|
8
17
|
export class DictionaryAsset {
|
|
9
|
-
static
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
static #state(): DictionaryAssetState {
|
|
19
|
+
const globalScope = globalThis as typeof globalThis & { [dictionaryAssetStateKey]?: DictionaryAssetState };
|
|
20
|
+
globalScope[dictionaryAssetStateKey] ??= {
|
|
21
|
+
loads: new Map(),
|
|
22
|
+
appliedSeqByLang: new Map(),
|
|
23
|
+
seq: 0,
|
|
24
|
+
wholes: new WeakSet(),
|
|
25
|
+
groupsBySnapshot: new WeakMap(),
|
|
26
|
+
};
|
|
27
|
+
return globalScope[dictionaryAssetStateKey];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static async load(urls: string | readonly string[] | null | undefined): Promise<void> {
|
|
31
|
+
const list = (typeof urls === "string" ? urls.split(",") : (urls ?? [])).filter(Boolean);
|
|
32
|
+
if (!list.length) return;
|
|
33
|
+
const state = DictionaryAsset.#state();
|
|
34
|
+
const seq = ++state.seq;
|
|
35
|
+
TranslatorState.get().loadSeq = seq;
|
|
36
|
+
const loaded = await Promise.allSettled(list.map((url) => DictionaryAsset.#loading(url)));
|
|
37
|
+
loaded.forEach((result, idx) => {
|
|
38
|
+
const url = list[idx];
|
|
39
|
+
if (result.status === "fulfilled" && url) DictionaryAsset.#apply(url, result.value, seq);
|
|
40
|
+
});
|
|
41
|
+
const failed = loaded.find((result) => result.status === "rejected");
|
|
42
|
+
if (failed) throw failed.reason;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static async add(url: string): Promise<boolean> {
|
|
46
|
+
const dictionaryModule = await DictionaryAsset.#loading(url);
|
|
47
|
+
return DictionaryAsset.#apply(url, dictionaryModule, null);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static holdsEveryGroup(lang: string): boolean {
|
|
51
|
+
const replaced = TranslatorState.get().replacedByLang.get(lang);
|
|
52
|
+
return !!replaced && DictionaryAsset.#state().wholes.has(replaced);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static holdsGroup(lang: string, group: string): boolean {
|
|
56
|
+
const replaced = TranslatorState.get().replacedByLang.get(lang);
|
|
57
|
+
return !!replaced && !!DictionaryAsset.#state().groupsBySnapshot.get(replaced)?.has(group);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static #markGroups(snapshot: object, groups: readonly string[]) {
|
|
61
|
+
const { groupsBySnapshot } = DictionaryAsset.#state();
|
|
62
|
+
const marked = groupsBySnapshot.get(snapshot) ?? new Set<string>();
|
|
63
|
+
for (const group of groups) marked.add(group);
|
|
64
|
+
groupsBySnapshot.set(snapshot, marked);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static #apply(
|
|
68
|
+
url: string,
|
|
69
|
+
{ lang, default: dictionary, parts, table, groups, part }: DictionaryModule,
|
|
70
|
+
seq: number | null,
|
|
71
|
+
) {
|
|
72
|
+
const state = DictionaryAsset.#state();
|
|
73
|
+
const translator = TranslatorState.get();
|
|
74
|
+
const replaced = translator.replacedByLang.get(lang);
|
|
75
|
+
if (part)
|
|
76
|
+
return (
|
|
77
|
+
!!replaced && DictionaryPart.urlOf(lang, part) === url && DictionaryPart.merge(lang, url, dictionary, replaced)
|
|
78
|
+
);
|
|
79
|
+
const sameBuild = !!table && !!replaced && translator.tableByLang.get(lang) === table;
|
|
80
|
+
if (groups && sameBuild) {
|
|
81
|
+
if (!state.wholes.has(replaced) && DictionaryPart.merge(lang, url, dictionary, replaced))
|
|
82
|
+
DictionaryAsset.#markGroups(replaced, groups);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
if (seq === null || (state.appliedSeqByLang.get(lang) ?? 0) > seq) return false;
|
|
86
|
+
state.appliedSeqByLang.set(lang, seq);
|
|
87
|
+
if (!groups) {
|
|
88
|
+
state.wholes.add(dictionary);
|
|
89
|
+
TranslatorState.replace(lang, dictionary, parts, table);
|
|
90
|
+
return true;
|
|
30
91
|
}
|
|
92
|
+
const base = {};
|
|
93
|
+
TranslatorState.replace(lang, base, parts, table);
|
|
94
|
+
const merged = DictionaryPart.merge(lang, url, dictionary, base);
|
|
95
|
+
if (merged) DictionaryAsset.#markGroups(base, groups);
|
|
96
|
+
return merged;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static #loading(url: string): Promise<DictionaryModule> {
|
|
100
|
+
const { loads } = DictionaryAsset.#state();
|
|
101
|
+
const known = loads.get(url);
|
|
102
|
+
if (known) return known;
|
|
103
|
+
const loading = importDictionaryModule(url).catch((error: unknown) => {
|
|
104
|
+
loads.delete(url);
|
|
105
|
+
throw error;
|
|
106
|
+
});
|
|
107
|
+
loads.set(url, loading);
|
|
108
|
+
return loading;
|
|
31
109
|
}
|
|
32
110
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { DictionaryAsset } from "./dictionaryAsset";
|
|
2
|
+
import { importDictionaryModule } from "./dictionaryModule";
|
|
3
|
+
import { TranslatorState } from "./translatorState";
|
|
4
|
+
|
|
5
|
+
interface GroupTable {
|
|
6
|
+
files: string[];
|
|
7
|
+
default: Record<string, number>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface GroupWait {
|
|
11
|
+
load: Promise<boolean>;
|
|
12
|
+
|
|
13
|
+
rendered: boolean;
|
|
14
|
+
failedAt?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface DictionaryGroupsState {
|
|
18
|
+
tables: Map<string, Promise<GroupTable>>;
|
|
19
|
+
waits: Map<string, GroupWait>;
|
|
20
|
+
reported: Set<string>;
|
|
21
|
+
listeners: Set<() => void>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const dictionaryGroupsStateKey = "__AKAN_DICTIONARY_GROUPS__";
|
|
25
|
+
|
|
26
|
+
export class DictionaryGroups {
|
|
27
|
+
static #state(): DictionaryGroupsState {
|
|
28
|
+
const globalScope = globalThis as typeof globalThis & { [dictionaryGroupsStateKey]?: DictionaryGroupsState };
|
|
29
|
+
globalScope[dictionaryGroupsStateKey] ??= {
|
|
30
|
+
tables: new Map(),
|
|
31
|
+
waits: new Map(),
|
|
32
|
+
reported: new Set(),
|
|
33
|
+
listeners: new Set(),
|
|
34
|
+
};
|
|
35
|
+
return globalScope[dictionaryGroupsStateKey];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static install(): void {
|
|
39
|
+
TranslatorState.get().groups ??= { pending: DictionaryGroups.pending, missed: DictionaryGroups.missed };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static pending(lang: string, key: string): Promise<boolean> | null {
|
|
43
|
+
return DictionaryGroups.#wait(lang, key)?.load ?? null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static missed(lang: string, key: string): void {
|
|
47
|
+
if (typeof window === "undefined") return;
|
|
48
|
+
const wait = DictionaryGroups.#wait(lang, key);
|
|
49
|
+
if (!wait) return;
|
|
50
|
+
wait.rendered = true;
|
|
51
|
+
if (process.env.NODE_ENV === "production") return;
|
|
52
|
+
const group = key.slice(0, key.indexOf("."));
|
|
53
|
+
const { reported } = DictionaryGroups.#state();
|
|
54
|
+
if (reported.has(group)) return;
|
|
55
|
+
reported.add(group);
|
|
56
|
+
const fault = new Error(
|
|
57
|
+
`[dictionary] "${key}" was shown on a route whose dictionary files leave out "${group}": its file loads late. The group was not counted for this route in its last build: a key of it added to a client file since is counted when the route builds again, and a key the build can read names the group.`,
|
|
58
|
+
);
|
|
59
|
+
void wait.load.then((merged) => merged && console.error(fault));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static onMerged(listener: () => void): () => void {
|
|
63
|
+
const { listeners } = DictionaryGroups.#state();
|
|
64
|
+
listeners.add(listener);
|
|
65
|
+
return () => listeners.delete(listener);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static #wait(lang: string, key: string): GroupWait | null {
|
|
69
|
+
const dot = key.indexOf(".");
|
|
70
|
+
const group = dot > 0 ? key.slice(0, dot) : "";
|
|
71
|
+
const translator = TranslatorState.get();
|
|
72
|
+
const table = translator.tableByLang.get(lang);
|
|
73
|
+
if (!group || !table || DictionaryAsset.holdsGroup(lang, group) || DictionaryAsset.holdsEveryGroup(lang))
|
|
74
|
+
return null;
|
|
75
|
+
const { waits } = DictionaryGroups.#state();
|
|
76
|
+
const id = `${table} ${group}`;
|
|
77
|
+
const known = waits.get(id);
|
|
78
|
+
if (known && (known.failedAt === undefined || known.failedAt === translator.loadSeq)) return known;
|
|
79
|
+
const wait: GroupWait = { load: Promise.resolve(false), rendered: false };
|
|
80
|
+
wait.load = DictionaryGroups.#load(table, group).then(
|
|
81
|
+
(merged) => {
|
|
82
|
+
if (merged && wait.rendered) for (const listener of DictionaryGroups.#state().listeners) listener();
|
|
83
|
+
return merged;
|
|
84
|
+
},
|
|
85
|
+
(error: unknown) => {
|
|
86
|
+
wait.failedAt = TranslatorState.get().loadSeq;
|
|
87
|
+
console.error(`[DictionaryGroups] "${group}" failed to load: ${String(error)}`);
|
|
88
|
+
return false;
|
|
89
|
+
},
|
|
90
|
+
);
|
|
91
|
+
waits.set(id, wait);
|
|
92
|
+
return wait;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static async #load(table: string, group: string): Promise<boolean> {
|
|
96
|
+
const { files, default: fileOf } = await DictionaryGroups.#table(table);
|
|
97
|
+
const idx = fileOf[group];
|
|
98
|
+
const url = idx === undefined ? undefined : files[idx];
|
|
99
|
+
return url ? DictionaryAsset.add(url) : false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static #table(url: string): Promise<GroupTable> {
|
|
103
|
+
const { tables } = DictionaryGroups.#state();
|
|
104
|
+
const known = tables.get(url);
|
|
105
|
+
if (known) return known;
|
|
106
|
+
const loading = importDictionaryModule<GroupTable>(url).catch((error: unknown) => {
|
|
107
|
+
tables.delete(url);
|
|
108
|
+
throw error;
|
|
109
|
+
});
|
|
110
|
+
tables.set(url, loading);
|
|
111
|
+
return loading;
|
|
112
|
+
}
|
|
113
|
+
}
|