veryfront 0.1.128 → 0.1.129
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/esm/cli/router.d.ts +0 -5
- package/esm/cli/router.d.ts.map +1 -1
- package/esm/cli/router.js +30 -2
- package/esm/cli/shared/update-check.d.ts +4 -0
- package/esm/cli/shared/update-check.d.ts.map +1 -0
- package/esm/cli/shared/update-check.js +97 -0
- package/esm/deno.d.ts +5 -0
- package/esm/deno.js +13 -8
- package/esm/src/channels/control-plane.d.ts.map +1 -1
- package/esm/src/channels/control-plane.js +5 -5
- package/esm/src/channels/invoke.d.ts +1 -1
- package/esm/src/channels/invoke.d.ts.map +1 -1
- package/esm/src/channels/invoke.js +6 -6
- package/esm/src/chat/index.d.ts +12 -24
- package/esm/src/chat/index.d.ts.map +1 -1
- package/esm/src/chat/index.js +5 -25
- package/esm/src/config/env.d.ts.map +1 -1
- package/esm/src/config/env.js +18 -10
- package/esm/src/data/static-data-fetcher.d.ts +3 -0
- package/esm/src/data/static-data-fetcher.d.ts.map +1 -1
- package/esm/src/data/static-data-fetcher.js +29 -25
- package/esm/src/data/static-paths-fetcher.d.ts.map +1 -1
- package/esm/src/data/static-paths-fetcher.js +3 -2
- package/esm/src/errors/logging.d.ts.map +1 -1
- package/esm/src/errors/logging.js +16 -7
- package/esm/src/errors/user-friendly/error-formatter.d.ts.map +1 -1
- package/esm/src/errors/user-friendly/error-formatter.js +9 -25
- package/esm/src/fs/index.d.ts +11 -12
- package/esm/src/fs/index.d.ts.map +1 -1
- package/esm/src/fs/index.js +11 -24
- package/esm/src/html/dev-scripts.d.ts.map +1 -1
- package/esm/src/html/dev-scripts.js +5 -8
- package/esm/src/html/html-escape.d.ts +1 -0
- package/esm/src/html/html-escape.d.ts.map +1 -1
- package/esm/src/html/html-escape.js +3 -0
- package/esm/src/html/html-injection.js +2 -2
- package/esm/src/html/html-shell-generator.d.ts +5 -2
- package/esm/src/html/html-shell-generator.d.ts.map +1 -1
- package/esm/src/html/html-shell-generator.js +41 -30
- package/esm/src/html/hydration-script-builder/dev-client-renderer.js +2 -2
- package/esm/src/html/hydration-script-builder/dev-component-manifest.js +2 -2
- package/esm/src/html/hydration-script-builder/dev-error-logger.d.ts.map +1 -1
- package/esm/src/html/hydration-script-builder/dev-error-logger.js +2 -6
- package/esm/src/html/hydration-script-builder/dev-scripts.js +2 -2
- package/esm/src/html/hydration-script-builder/hydration-data-generator.d.ts +3 -1
- package/esm/src/html/hydration-script-builder/hydration-data-generator.d.ts.map +1 -1
- package/esm/src/html/hydration-script-builder/hydration-data-generator.js +2 -2
- package/esm/src/html/hydration-script-builder/index.d.ts +1 -1
- package/esm/src/html/hydration-script-builder/index.d.ts.map +1 -1
- package/esm/src/html/hydration-script-builder/index.js +1 -1
- package/esm/src/html/hydration-script-builder/prod-hydration.js +2 -2
- package/esm/src/html/hydration-script-builder/prod-scripts.d.ts +2 -0
- package/esm/src/html/hydration-script-builder/prod-scripts.d.ts.map +1 -1
- package/esm/src/html/hydration-script-builder/prod-scripts.js +14 -14
- package/esm/src/html/schemas/html.schema.d.ts +2 -0
- package/esm/src/html/schemas/html.schema.d.ts.map +1 -1
- package/esm/src/html/schemas/html.schema.js +2 -0
- package/esm/src/html/styles-builder/css-pregeneration.d.ts +17 -1
- package/esm/src/html/styles-builder/css-pregeneration.d.ts.map +1 -1
- package/esm/src/html/styles-builder/css-pregeneration.js +103 -1
- package/esm/src/html/styles-builder/dev-styles.js +2 -2
- package/esm/src/html/utils.d.ts +2 -0
- package/esm/src/html/utils.d.ts.map +1 -1
- package/esm/src/html/utils.js +49 -28
- package/esm/src/integrations/remote-tools.d.ts.map +1 -1
- package/esm/src/integrations/remote-tools.js +32 -39
- package/esm/src/internal-agents/ag-ui-sse.d.ts +0 -1
- package/esm/src/internal-agents/ag-ui-sse.d.ts.map +1 -1
- package/esm/src/internal-agents/ag-ui-sse.js +2 -16
- package/esm/src/internal-agents/control-plane-auth.d.ts.map +1 -1
- package/esm/src/internal-agents/control-plane-auth.js +5 -3
- package/esm/src/internal-agents/request-body.d.ts.map +1 -1
- package/esm/src/internal-agents/request-body.js +6 -3
- package/esm/src/internal-agents/session-manager.d.ts +1 -0
- package/esm/src/internal-agents/session-manager.d.ts.map +1 -1
- package/esm/src/internal-agents/session-manager.js +12 -18
- package/esm/src/issues/core.d.ts.map +1 -1
- package/esm/src/issues/core.js +24 -23
- package/esm/src/issues/schemas/issue.schema.d.ts.map +1 -1
- package/esm/src/issues/schemas/issue.schema.js +2 -1
- package/esm/src/jobs/runtime-env.d.ts.map +1 -1
- package/esm/src/jobs/runtime-env.js +21 -44
- package/esm/src/markdown/index.d.ts +1 -2
- package/esm/src/markdown/index.d.ts.map +1 -1
- package/esm/src/markdown/index.js +1 -6
- package/esm/src/mcp/server.d.ts +0 -1
- package/esm/src/mcp/server.d.ts.map +1 -1
- package/esm/src/mcp/server.js +40 -41
- package/esm/src/mdx/index.d.ts +3 -2
- package/esm/src/mdx/index.d.ts.map +1 -1
- package/esm/src/mdx/index.js +3 -5
- package/esm/src/middleware/builtin/logger.d.ts.map +1 -1
- package/esm/src/middleware/builtin/logger.js +31 -28
- package/esm/src/middleware/builtin/security/rate-limit.d.ts.map +1 -1
- package/esm/src/middleware/builtin/security/rate-limit.js +17 -12
- package/esm/src/middleware/builtin/timeout.d.ts.map +1 -1
- package/esm/src/middleware/builtin/timeout.js +17 -10
- package/esm/src/modules/import-map/default-import-map.d.ts.map +1 -1
- package/esm/src/modules/import-map/default-import-map.js +4 -3
- package/esm/src/oauth/handlers/callback-handler.d.ts +0 -5
- package/esm/src/oauth/handlers/callback-handler.d.ts.map +1 -1
- package/esm/src/oauth/handlers/callback-handler.js +9 -14
- package/esm/src/oauth/handlers/index.d.ts +1 -1
- package/esm/src/oauth/handlers/index.js +1 -1
- package/esm/src/oauth/handlers/init-handler.d.ts.map +1 -1
- package/esm/src/oauth/handlers/init-handler.js +32 -20
- package/esm/src/oauth/providers/index.d.ts +1 -1
- package/esm/src/oauth/providers/index.js +1 -1
- package/esm/src/oauth/schemas/index.d.ts +1 -1
- package/esm/src/oauth/schemas/index.js +1 -1
- package/esm/src/oauth/token-store/index.d.ts +1 -1
- package/esm/src/oauth/token-store/index.js +1 -1
- package/esm/src/oauth/token-store/memory.d.ts +1 -1
- package/esm/src/oauth/token-store/memory.d.ts.map +1 -1
- package/esm/src/oauth/token-store/memory.js +8 -8
- package/esm/src/observability/request-profiler.d.ts +31 -0
- package/esm/src/observability/request-profiler.d.ts.map +1 -0
- package/esm/src/observability/request-profiler.js +94 -0
- package/esm/src/observability/tracing/otlp-setup.d.ts.map +1 -1
- package/esm/src/observability/tracing/otlp-setup.js +16 -21
- package/esm/src/prompt/factory.d.ts.map +1 -1
- package/esm/src/prompt/factory.js +10 -12
- package/esm/src/prompt/registry.d.ts.map +1 -1
- package/esm/src/prompt/registry.js +12 -10
- package/esm/src/prompt/schemas/prompt.schema.d.ts.map +1 -1
- package/esm/src/prompt/schemas/prompt.schema.js +0 -2
- package/esm/src/prompt/types.d.ts +1 -1
- package/esm/src/prompt/types.d.ts.map +1 -1
- package/esm/src/provider/local/ai-sdk-adapter.d.ts.map +1 -1
- package/esm/src/provider/local/ai-sdk-adapter.js +3 -8
- package/esm/src/provider/local/env.d.ts +4 -6
- package/esm/src/provider/local/env.d.ts.map +1 -1
- package/esm/src/provider/local/env.js +14 -1
- package/esm/src/provider/local/local-engine.d.ts.map +1 -1
- package/esm/src/provider/local/local-engine.js +2 -7
- package/esm/src/provider/model-registry.d.ts.map +1 -1
- package/esm/src/provider/model-registry.js +2 -7
- package/esm/src/provider/veryfront-cloud/provider.d.ts.map +1 -1
- package/esm/src/provider/veryfront-cloud/provider.js +1 -7
- package/esm/src/provider/veryfront-cloud/shared.d.ts.map +1 -1
- package/esm/src/provider/veryfront-cloud/shared.js +9 -11
- package/esm/src/proxy/handler.d.ts.map +1 -1
- package/esm/src/proxy/handler.js +56 -57
- package/esm/src/react/compat/hooks-adapter.d.ts +1 -7
- package/esm/src/react/compat/hooks-adapter.d.ts.map +1 -1
- package/esm/src/react/compat/hooks-adapter.js +35 -40
- package/esm/src/react/components/Head.d.ts +1 -26
- package/esm/src/react/components/Head.d.ts.map +1 -1
- package/esm/src/react/components/Head.js +1 -172
- package/esm/src/react/context/index.d.ts +2 -46
- package/esm/src/react/context/index.d.ts.map +1 -1
- package/esm/src/react/context/index.js +1 -44
- package/esm/src/react/head-collector.d.ts +1 -10
- package/esm/src/react/head-collector.d.ts.map +1 -1
- package/esm/src/react/head-collector.js +4 -0
- package/esm/src/react/router/index.d.ts +2 -45
- package/esm/src/react/router/index.d.ts.map +1 -1
- package/esm/src/react/router/index.js +1 -49
- package/esm/src/react/runtime/core.d.ts +49 -0
- package/esm/src/react/runtime/core.d.ts.map +1 -0
- package/esm/src/react/runtime/core.js +200 -0
- package/esm/src/rendering/orchestrator/html.d.ts +2 -0
- package/esm/src/rendering/orchestrator/html.d.ts.map +1 -1
- package/esm/src/rendering/orchestrator/html.js +69 -12
- package/esm/src/rendering/orchestrator/ssr-orchestrator.d.ts.map +1 -1
- package/esm/src/rendering/orchestrator/ssr-orchestrator.js +4 -0
- package/esm/src/rendering/orchestrator/types.d.ts +4 -0
- package/esm/src/rendering/orchestrator/types.d.ts.map +1 -1
- package/esm/src/repositories/types.d.ts.map +1 -1
- package/esm/src/resource/factory.d.ts.map +1 -1
- package/esm/src/resource/factory.js +12 -9
- package/esm/src/resource/registry.d.ts +3 -3
- package/esm/src/resource/registry.d.ts.map +1 -1
- package/esm/src/resource/registry.js +7 -7
- package/esm/src/schemas/common.d.ts.map +1 -1
- package/esm/src/schemas/common.js +7 -4
- package/esm/src/security/http/config.d.ts +0 -1
- package/esm/src/security/http/config.d.ts.map +1 -1
- package/esm/src/security/http/config.js +3 -16
- package/esm/src/security/http/response/security-handler.d.ts +1 -0
- package/esm/src/security/http/response/security-handler.d.ts.map +1 -1
- package/esm/src/security/http/response/security-handler.js +17 -12
- package/esm/src/security/index.d.ts +4 -2
- package/esm/src/security/index.d.ts.map +1 -1
- package/esm/src/security/index.js +3 -1
- package/esm/src/server/handlers/dev/styles-css.handler.d.ts.map +1 -1
- package/esm/src/server/handlers/dev/styles-css.handler.js +8 -7
- package/esm/src/server/handlers/monitoring/metrics.handler.d.ts.map +1 -1
- package/esm/src/server/handlers/monitoring/metrics.handler.js +3 -1
- package/esm/src/server/handlers/request/module/module-server-handler.d.ts.map +1 -1
- package/esm/src/server/handlers/request/module/module-server-handler.js +18 -15
- package/esm/src/server/handlers/request/prod-hydration-module.handler.d.ts +8 -0
- package/esm/src/server/handlers/request/prod-hydration-module.handler.d.ts.map +1 -0
- package/esm/src/server/handlers/request/prod-hydration-module.handler.js +41 -0
- package/esm/src/server/handlers/request/ssr/ssr.handler.d.ts.map +1 -1
- package/esm/src/server/handlers/request/ssr/ssr.handler.js +3 -0
- package/esm/src/server/production-server.d.ts.map +1 -1
- package/esm/src/server/production-server.js +65 -0
- package/esm/src/server/runtime-handler/handler-context-builder.d.ts +1 -1
- package/esm/src/server/runtime-handler/handler-context-builder.d.ts.map +1 -1
- package/esm/src/server/runtime-handler/index.d.ts +1 -1
- package/esm/src/server/runtime-handler/index.d.ts.map +1 -1
- package/esm/src/server/runtime-handler/index.js +36 -11
- package/esm/src/server/runtime-handler/request-utils.d.ts +7 -0
- package/esm/src/server/runtime-handler/request-utils.d.ts.map +1 -1
- package/esm/src/server/runtime-handler/request-utils.js +10 -0
- package/esm/src/server/services/rendering/ssr.service.d.ts +1 -0
- package/esm/src/server/services/rendering/ssr.service.d.ts.map +1 -1
- package/esm/src/server/services/rendering/ssr.service.js +12 -5
- package/esm/src/server/services/rsc/endpoints/rsc-bundles.generated.js +1 -1
- package/esm/src/skill/allowed-tools.d.ts +3 -8
- package/esm/src/skill/allowed-tools.d.ts.map +1 -1
- package/esm/src/skill/executor.js +2 -2
- package/esm/src/skill/parser.d.ts.map +1 -1
- package/esm/src/skill/parser.js +12 -12
- package/esm/src/skill/path-safety.js +1 -1
- package/esm/src/skill/tools.d.ts.map +1 -1
- package/esm/src/skill/tools.js +18 -11
- package/esm/src/studio/bridge/bridge-bundle.generated.d.ts.map +1 -1
- package/esm/src/studio/bridge/bridge-bundle.generated.js +1 -1
- package/esm/src/task/discovery.d.ts.map +1 -1
- package/esm/src/task/discovery.js +73 -95
- package/esm/src/tool/executor.d.ts.map +1 -1
- package/esm/src/tool/executor.js +8 -7
- package/esm/src/tool/factory.d.ts.map +1 -1
- package/esm/src/tool/factory.js +13 -16
- package/esm/src/transforms/esm/package-registry.d.ts +4 -0
- package/esm/src/transforms/esm/package-registry.d.ts.map +1 -1
- package/esm/src/transforms/esm/package-registry.js +34 -17
- package/esm/src/transforms/import-rewriter/strategies/veryfront-strategy.d.ts.map +1 -1
- package/esm/src/transforms/import-rewriter/strategies/veryfront-strategy.js +2 -1
- package/esm/src/transforms/mdx/esm-module-loader/cache-format.d.ts.map +1 -1
- package/esm/src/transforms/mdx/esm-module-loader/cache-format.js +26 -1
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/index.d.ts +1 -1
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/index.d.ts.map +1 -1
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/index.js +1 -1
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/render-sessions.d.ts +1 -0
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/render-sessions.d.ts.map +1 -1
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/render-sessions.js +3 -0
- package/esm/src/transforms/pipeline/stages/ssr-vf-modules/index.d.ts +1 -1
- package/esm/src/transforms/pipeline/stages/ssr-vf-modules/index.js +1 -1
- package/esm/src/transforms/veryfront-module-urls.d.ts.map +1 -1
- package/esm/src/transforms/veryfront-module-urls.js +7 -3
- package/esm/src/types/entities/getEntityInfo.d.ts.map +1 -1
- package/esm/src/types/entities/getEntityInfo.js +79 -127
- package/esm/src/utils/path-utils.d.ts +1 -1
- package/esm/src/utils/path-utils.d.ts.map +1 -1
- package/esm/src/utils/path-utils.js +16 -7
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/esm/src/utils/version.d.ts.map +1 -1
- package/esm/src/utils/version.js +0 -1
- package/esm/src/workflow/worker/dynamic-job-entrypoint.d.ts.map +1 -1
- package/esm/src/workflow/worker/dynamic-job-entrypoint.js +5 -72
- package/esm/src/workflow/worker/job-entrypoint.d.ts.map +1 -1
- package/esm/src/workflow/worker/job-entrypoint.js +5 -72
- package/esm/src/workflow/worker/shared.d.ts +18 -0
- package/esm/src/workflow/worker/shared.d.ts.map +1 -0
- package/esm/src/workflow/worker/shared.js +77 -0
- package/package.json +1 -1
- package/src/cli/router.ts +41 -2
- package/src/cli/shared/update-check.ts +110 -0
- package/src/deno.js +13 -8
- package/src/src/channels/control-plane.ts +6 -10
- package/src/src/channels/invoke.ts +7 -7
- package/src/src/chat/index.ts +96 -132
- package/src/src/config/env.ts +24 -11
- package/src/src/data/static-data-fetcher.ts +59 -34
- package/src/src/data/static-paths-fetcher.ts +4 -2
- package/src/src/errors/logging.ts +21 -7
- package/src/src/errors/user-friendly/error-formatter.ts +14 -29
- package/src/src/fs/index.ts +21 -30
- package/src/src/html/dev-scripts.ts +5 -9
- package/src/src/html/html-escape.ts +4 -0
- package/src/src/html/html-injection.ts +2 -2
- package/src/src/html/html-shell-generator.ts +60 -26
- package/src/src/html/hydration-script-builder/dev-client-renderer.ts +2 -2
- package/src/src/html/hydration-script-builder/dev-component-manifest.ts +2 -2
- package/src/src/html/hydration-script-builder/dev-error-logger.ts +2 -8
- package/src/src/html/hydration-script-builder/dev-scripts.ts +2 -2
- package/src/src/html/hydration-script-builder/hydration-data-generator.ts +2 -1
- package/src/src/html/hydration-script-builder/index.ts +5 -1
- package/src/src/html/hydration-script-builder/prod-hydration.ts +2 -2
- package/src/src/html/hydration-script-builder/prod-scripts.ts +16 -15
- package/src/src/html/schemas/html.schema.ts +2 -0
- package/src/src/html/styles-builder/css-pregeneration.ts +133 -1
- package/src/src/html/styles-builder/dev-styles.ts +2 -2
- package/src/src/html/utils.ts +62 -29
- package/src/src/integrations/remote-tools.ts +39 -37
- package/src/src/internal-agents/ag-ui-sse.ts +2 -17
- package/src/src/internal-agents/control-plane-auth.ts +8 -6
- package/src/src/internal-agents/request-body.ts +7 -5
- package/src/src/internal-agents/session-manager.ts +16 -20
- package/src/src/issues/core.ts +24 -27
- package/src/src/issues/schemas/issue.schema.ts +3 -1
- package/src/src/jobs/runtime-env.ts +24 -50
- package/src/src/markdown/index.ts +5 -8
- package/src/src/mcp/server.ts +50 -53
- package/src/src/mdx/index.ts +7 -8
- package/src/src/middleware/builtin/logger.ts +44 -29
- package/src/src/middleware/builtin/security/rate-limit.ts +20 -11
- package/src/src/middleware/builtin/timeout.ts +22 -13
- package/src/src/modules/import-map/default-import-map.ts +4 -3
- package/src/src/oauth/handlers/callback-handler.ts +9 -16
- package/src/src/oauth/handlers/index.ts +1 -1
- package/src/src/oauth/handlers/init-handler.ts +56 -27
- package/src/src/oauth/providers/index.ts +1 -1
- package/src/src/oauth/schemas/index.ts +1 -1
- package/src/src/oauth/token-store/index.ts +1 -1
- package/src/src/oauth/token-store/memory.ts +8 -8
- package/src/src/observability/request-profiler.ts +140 -0
- package/src/src/observability/tracing/otlp-setup.ts +16 -22
- package/src/src/prompt/factory.ts +16 -14
- package/src/src/prompt/registry.ts +14 -13
- package/src/src/prompt/schemas/prompt.schema.ts +0 -4
- package/src/src/prompt/types.ts +1 -2
- package/src/src/provider/local/ai-sdk-adapter.ts +3 -10
- package/src/src/provider/local/env.ts +22 -2
- package/src/src/provider/local/local-engine.ts +2 -9
- package/src/src/provider/model-registry.ts +2 -9
- package/src/src/provider/veryfront-cloud/provider.ts +1 -8
- package/src/src/provider/veryfront-cloud/shared.ts +12 -15
- package/src/src/proxy/handler.ts +90 -74
- package/src/src/react/compat/hooks-adapter.ts +43 -44
- package/src/src/react/components/Head.tsx +1 -181
- package/src/src/react/context/index.tsx +2 -83
- package/src/src/react/head-collector.ts +9 -0
- package/src/src/react/router/index.tsx +2 -100
- package/src/src/react/runtime/core.ts +303 -0
- package/src/src/rendering/orchestrator/html.ts +122 -18
- package/src/src/rendering/orchestrator/ssr-orchestrator.ts +8 -0
- package/src/src/rendering/orchestrator/types.ts +4 -0
- package/src/src/repositories/types.ts +0 -4
- package/src/src/resource/factory.ts +15 -11
- package/src/src/resource/registry.ts +7 -7
- package/src/src/schemas/common.ts +8 -5
- package/src/src/security/http/config.ts +3 -19
- package/src/src/security/http/response/security-handler.ts +22 -13
- package/src/src/security/index.ts +4 -7
- package/src/src/server/handlers/dev/styles-css.handler.ts +32 -14
- package/src/src/server/handlers/monitoring/metrics.handler.ts +3 -1
- package/src/src/server/handlers/request/module/module-server-handler.ts +24 -17
- package/src/src/server/handlers/request/prod-hydration-module.handler.ts +61 -0
- package/src/src/server/handlers/request/ssr/ssr.handler.ts +3 -0
- package/src/src/server/production-server.ts +84 -0
- package/src/src/server/runtime-handler/handler-context-builder.ts +1 -1
- package/src/src/server/runtime-handler/index.ts +44 -13
- package/src/src/server/runtime-handler/request-utils.ts +11 -0
- package/src/src/server/services/rendering/ssr.service.ts +31 -18
- package/src/src/server/services/rsc/endpoints/rsc-bundles.generated.ts +1 -1
- package/src/src/skill/allowed-tools.ts +1 -8
- package/src/src/skill/executor.ts +2 -2
- package/src/src/skill/parser.ts +13 -20
- package/src/src/skill/path-safety.ts +1 -1
- package/src/src/skill/tools.ts +27 -20
- package/src/src/studio/bridge/bridge-bundle.generated.ts +1 -1
- package/src/src/task/discovery.ts +97 -97
- package/src/src/tool/executor.ts +10 -8
- package/src/src/tool/factory.ts +21 -22
- package/src/src/tool/types.ts +0 -17
- package/src/src/transforms/esm/package-registry.ts +52 -20
- package/src/src/transforms/import-rewriter/strategies/veryfront-strategy.ts +2 -1
- package/src/src/transforms/mdx/esm-module-loader/cache-format.ts +34 -1
- package/src/src/transforms/mdx/esm-module-loader/module-fetcher/index.ts +1 -1
- package/src/src/transforms/mdx/esm-module-loader/module-fetcher/render-sessions.ts +4 -0
- package/src/src/transforms/pipeline/stages/ssr-vf-modules/index.ts +1 -1
- package/src/src/transforms/veryfront-module-urls.ts +6 -2
- package/src/src/types/entities/getEntityInfo.ts +131 -152
- package/src/src/utils/path-utils.ts +16 -7
- package/src/src/utils/version-constant.ts +1 -1
- package/src/src/utils/version.ts +0 -1
- package/src/src/workflow/worker/dynamic-job-entrypoint.ts +18 -84
- package/src/src/workflow/worker/job-entrypoint.ts +18 -85
- package/src/src/workflow/worker/shared.ts +127 -0
- package/esm/src/prompt/schemas/index.d.ts +0 -7
- package/esm/src/prompt/schemas/index.d.ts.map +0 -1
- package/esm/src/prompt/schemas/index.js +0 -6
- package/esm/src/security/http/handlers-index.d.ts +0 -5
- package/esm/src/security/http/handlers-index.d.ts.map +0 -1
- package/esm/src/security/http/handlers-index.js +0 -3
- package/src/src/prompt/schemas/index.ts +0 -7
- package/src/src/security/http/handlers-index.ts +0 -4
|
@@ -1,182 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Declarative `<head>` metadata management.
|
|
3
|
-
*
|
|
4
|
-
* @module head
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```tsx
|
|
8
|
-
* import { Head } from "veryfront/head";
|
|
9
|
-
*
|
|
10
|
-
* export default function Page() {
|
|
11
|
-
* return (
|
|
12
|
-
* <>
|
|
13
|
-
* <Head>
|
|
14
|
-
* <title>My Page</title>
|
|
15
|
-
* <meta name="description" content="Page description" />
|
|
16
|
-
* </Head>
|
|
17
|
-
* <main>Content</main>
|
|
18
|
-
* </>
|
|
19
|
-
* );
|
|
20
|
-
* }
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
1
|
import "../../../_dnt.polyfills.js";
|
|
24
|
-
|
|
25
|
-
import React, { useEffect, useRef } from "react";
|
|
26
|
-
import { collectHead } from "../head-collector.js";
|
|
27
|
-
import { isServerEnvironment } from "../../platform/compat/runtime.js";
|
|
28
|
-
import { getDocumentNonce } from "./ai/csp-nonce.js";
|
|
29
|
-
|
|
30
|
-
export function Head({ children }: { children: React.ReactNode }): React.ReactElement {
|
|
31
|
-
const mountedRef = useRef(false);
|
|
32
|
-
const isSSR = isServerEnvironment();
|
|
33
|
-
|
|
34
|
-
if (isSSR && children) {
|
|
35
|
-
React.Children.forEach(children, (child) => {
|
|
36
|
-
if (!React.isValidElement(child)) return;
|
|
37
|
-
|
|
38
|
-
const { type } = child;
|
|
39
|
-
// Cast props to Record for React 19 compatibility (props is unknown in R19 types)
|
|
40
|
-
const props = child.props as Record<string, unknown>;
|
|
41
|
-
if (typeof type !== "string" || type === "body") return;
|
|
42
|
-
|
|
43
|
-
if (type === "title") {
|
|
44
|
-
collectHead({ title: String(props.children ?? "") });
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (type === "meta") {
|
|
49
|
-
collectHead({
|
|
50
|
-
metas: [
|
|
51
|
-
{
|
|
52
|
-
name: props.name as string | undefined,
|
|
53
|
-
property: props.property as string | undefined,
|
|
54
|
-
content: String(props.content ?? ""),
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
});
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (type === "link") {
|
|
62
|
-
const link: Record<string, string> = {};
|
|
63
|
-
for (const [key, value] of Object.entries(props)) {
|
|
64
|
-
if (value != null) link[key] = String(value);
|
|
65
|
-
}
|
|
66
|
-
collectHead({ links: [link] });
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (type === "style") {
|
|
71
|
-
collectHead({ styles: [String(props.children ?? "")] });
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (type === "script") {
|
|
76
|
-
const script: Record<string, string | undefined> = {};
|
|
77
|
-
for (const [key, value] of Object.entries(props)) {
|
|
78
|
-
if (key === "children" || key === "dangerouslySetInnerHTML") continue;
|
|
79
|
-
if (value != null) script[key] = String(value);
|
|
80
|
-
}
|
|
81
|
-
// Handle inline script content
|
|
82
|
-
if (props.dangerouslySetInnerHTML) {
|
|
83
|
-
const html = props.dangerouslySetInnerHTML as { __html?: string };
|
|
84
|
-
if (html.__html) script.content = html.__html;
|
|
85
|
-
} else if (typeof props.children === "string") {
|
|
86
|
-
script.content = props.children;
|
|
87
|
-
}
|
|
88
|
-
collectHead({ scripts: [script] });
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
useEffect(() => {
|
|
94
|
-
mountedRef.current = true;
|
|
95
|
-
if (!children) return;
|
|
96
|
-
|
|
97
|
-
const addedElements: Element[] = [];
|
|
98
|
-
const nonce = getDocumentNonce();
|
|
99
|
-
|
|
100
|
-
React.Children.forEach(children, (child) => {
|
|
101
|
-
if (!React.isValidElement(child)) return;
|
|
102
|
-
|
|
103
|
-
const { type } = child;
|
|
104
|
-
// Cast props to Record for React 19 compatibility (props is unknown in R19 types)
|
|
105
|
-
const props = child.props as Record<string, unknown>;
|
|
106
|
-
if (typeof type !== "string" || type === "body") return;
|
|
107
|
-
|
|
108
|
-
if (type === "title") {
|
|
109
|
-
document.title = String(props.children ?? "");
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const element = document.createElement(type);
|
|
114
|
-
if ((type === "style" || type === "script") && !props.nonce && nonce) {
|
|
115
|
-
element.setAttribute("nonce", nonce);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// For scripts, check if already SSR'd via <Head> to avoid double execution
|
|
119
|
-
if (type === "script") {
|
|
120
|
-
const src = props.src as string | undefined;
|
|
121
|
-
const id = props.id as string | undefined;
|
|
122
|
-
|
|
123
|
-
// Check by id (look for SSR'd script with data-vf-head marker)
|
|
124
|
-
if (id && document.querySelector(`script[data-vf-head][id="${id}"]`)) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
// Check by src for external scripts
|
|
128
|
-
if (src && document.querySelector(`script[data-vf-head][src="${src}"]`)) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
// For inline scripts without id, check by content hash
|
|
132
|
-
const content = typeof props.children === "string"
|
|
133
|
-
? props.children
|
|
134
|
-
: (props.dangerouslySetInnerHTML as { __html?: string })?.__html;
|
|
135
|
-
if (content && !id) {
|
|
136
|
-
let sum = 0;
|
|
137
|
-
for (let i = 0; i < Math.min(content.length, 200); i++) {
|
|
138
|
-
sum = ((sum << 5) - sum + content.charCodeAt(i)) | 0;
|
|
139
|
-
}
|
|
140
|
-
const hash = "vf" + Math.abs(sum).toString(36);
|
|
141
|
-
if (document.querySelector(`script[data-vf-head][data-vf-hash="${hash}"]`)) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
element.setAttribute("data-vf-hash", hash);
|
|
145
|
-
}
|
|
146
|
-
element.setAttribute("data-vf-head", "true");
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
for (const [key, value] of Object.entries(props)) {
|
|
150
|
-
if (key === "children") continue;
|
|
151
|
-
|
|
152
|
-
let attrName = key;
|
|
153
|
-
if (key === "className") attrName = "class";
|
|
154
|
-
else if (key === "htmlFor") attrName = "for";
|
|
155
|
-
|
|
156
|
-
if (typeof value === "boolean") {
|
|
157
|
-
if (value) element.setAttribute(attrName, "");
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (value != null) element.setAttribute(attrName, String(value));
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (typeof props.children === "string") {
|
|
165
|
-
element.textContent = props.children;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
element.setAttribute("data-veryfront-managed", "1");
|
|
169
|
-
document.head.appendChild(element);
|
|
170
|
-
addedElements.push(element);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
return () => {
|
|
174
|
-
for (const el of addedElements) el.remove();
|
|
175
|
-
};
|
|
176
|
-
}, [children]);
|
|
177
|
-
|
|
178
|
-
return React.createElement("div", {
|
|
179
|
-
"data-veryfront-head": "1",
|
|
180
|
-
style: { display: "none" },
|
|
181
|
-
});
|
|
182
|
-
}
|
|
2
|
+
export { Head } from "../runtime/core.js";
|
|
@@ -1,84 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Access route params, page data, and MDX frontmatter.
|
|
3
|
-
*
|
|
4
|
-
* @module context
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```tsx
|
|
8
|
-
* import { usePageContext } from "veryfront/context";
|
|
9
|
-
*
|
|
10
|
-
* function TableOfContents() {
|
|
11
|
-
* const { headings, frontmatter } = usePageContext();
|
|
12
|
-
* return (
|
|
13
|
-
* <ul>
|
|
14
|
-
* {headings.map((h) => (
|
|
15
|
-
* <li key={h.id}>
|
|
16
|
-
* <a href={`#${h.id}`}>{h.text}</a>
|
|
17
|
-
* </li>
|
|
18
|
-
* ))}
|
|
19
|
-
* </ul>
|
|
20
|
-
* );
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
1
|
import "../../../_dnt.polyfills.js";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
import React from "react";
|
|
29
|
-
|
|
30
|
-
export interface MdxHeading {
|
|
31
|
-
text: string;
|
|
32
|
-
id: string;
|
|
33
|
-
level: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface PageContextValue {
|
|
37
|
-
slug: string;
|
|
38
|
-
path: string;
|
|
39
|
-
params: Record<string, string>;
|
|
40
|
-
query: Record<string, string>;
|
|
41
|
-
frontmatter: Record<string, unknown>;
|
|
42
|
-
/** Headings extracted from MDX content for table of contents/sidebar navigation */
|
|
43
|
-
headings: MdxHeading[];
|
|
44
|
-
/** @deprecated Use `headings` instead. Alias for backwards compatibility. */
|
|
45
|
-
mdxHeadings: MdxHeading[];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const defaultPageContext: PageContextValue = {
|
|
49
|
-
slug: "/",
|
|
50
|
-
path: "/",
|
|
51
|
-
params: {},
|
|
52
|
-
query: {},
|
|
53
|
-
frontmatter: {},
|
|
54
|
-
headings: [],
|
|
55
|
-
mdxHeadings: [],
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const PAGE_CONTEXT_SYMBOL = Symbol.for("veryfront.react.page-context");
|
|
59
|
-
const globalPageContext = dntShim.dntGlobalThis as typeof dntShim.dntGlobalThis & {
|
|
60
|
-
[PAGE_CONTEXT_SYMBOL]?: React.Context<PageContextValue>;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const PageContextContext = globalPageContext[PAGE_CONTEXT_SYMBOL] ??
|
|
64
|
-
(globalPageContext[PAGE_CONTEXT_SYMBOL] = React.createContext(defaultPageContext));
|
|
65
|
-
|
|
66
|
-
export interface PageContextProviderProps {
|
|
67
|
-
children: React.ReactNode;
|
|
68
|
-
pageContext?: PageContextValue;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function PageContextProvider({
|
|
72
|
-
children,
|
|
73
|
-
pageContext,
|
|
74
|
-
}: PageContextProviderProps): React.ReactElement {
|
|
75
|
-
return (
|
|
76
|
-
<PageContextContext.Provider value={pageContext ?? defaultPageContext}>
|
|
77
|
-
{children}
|
|
78
|
-
</PageContextContext.Provider>
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function usePageContext(): PageContextValue {
|
|
83
|
-
return React.useContext(PageContextContext);
|
|
84
|
-
}
|
|
2
|
+
export { PageContextProvider, usePageContext } from "../runtime/core.js";
|
|
3
|
+
export type { MdxHeading, PageContextProviderProps, PageContextValue } from "../runtime/core.js";
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* const { result, head } = await runWithHeadCollector(() => renderToString(element));
|
|
9
9
|
* // head.title, head.description, head.metas are now available
|
|
10
10
|
*/
|
|
11
|
+
import * as dntShim from "../../_dnt.shims.js";
|
|
12
|
+
|
|
11
13
|
|
|
12
14
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
13
15
|
|
|
@@ -44,11 +46,16 @@ export interface CollectedHead {
|
|
|
44
46
|
scripts: HeadScript[];
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
export const HEAD_COLLECTOR_SYMBOL = Symbol.for("veryfront.react.collect-head");
|
|
50
|
+
|
|
47
51
|
function createEmpty(): CollectedHead {
|
|
48
52
|
return { metas: [], links: [], styles: [], scripts: [] };
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
const headStorage = new AsyncLocalStorage<CollectedHead>();
|
|
56
|
+
const globalHeadCollector = dntShim.dntGlobalThis as typeof dntShim.dntGlobalThis & {
|
|
57
|
+
[HEAD_COLLECTOR_SYMBOL]?: typeof collectHead;
|
|
58
|
+
};
|
|
52
59
|
|
|
53
60
|
export async function runWithHeadCollector<T>(
|
|
54
61
|
fn: () => T | Promise<T>,
|
|
@@ -88,6 +95,8 @@ export function collectHead(data: Partial<CollectedHead>): void {
|
|
|
88
95
|
}
|
|
89
96
|
}
|
|
90
97
|
|
|
98
|
+
globalHeadCollector[HEAD_COLLECTOR_SYMBOL] = collectHead;
|
|
99
|
+
|
|
91
100
|
export function hasCollectedHead(): boolean {
|
|
92
101
|
const collected = headStorage.getStore();
|
|
93
102
|
if (!collected) return false;
|
|
@@ -1,101 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client-side routing, navigation, and links.
|
|
3
|
-
*
|
|
4
|
-
* @module router
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```tsx
|
|
8
|
-
* import { useRouter, Link } from "veryfront/router";
|
|
9
|
-
*
|
|
10
|
-
* function Nav() {
|
|
11
|
-
* const router = useRouter();
|
|
12
|
-
* return (
|
|
13
|
-
* <nav>
|
|
14
|
-
* <Link href="/about">About</Link>
|
|
15
|
-
* <p>Current path: {router.pathname}</p>
|
|
16
|
-
* </nav>
|
|
17
|
-
* );
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
1
|
import "../../../_dnt.polyfills.js";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
import React from "react";
|
|
26
|
-
|
|
27
|
-
export interface RouterValue {
|
|
28
|
-
domain: string;
|
|
29
|
-
path: string;
|
|
30
|
-
pathname: string;
|
|
31
|
-
params: Record<string, string>;
|
|
32
|
-
query: Record<string, string>;
|
|
33
|
-
isPreview: boolean;
|
|
34
|
-
isMounted: boolean;
|
|
35
|
-
navigate: (url: string) => Promise<void>;
|
|
36
|
-
push: (url: string) => Promise<void>;
|
|
37
|
-
replace: (url: string) => Promise<void>;
|
|
38
|
-
reload: () => Promise<void>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const defaultRouter: RouterValue = {
|
|
42
|
-
domain: "",
|
|
43
|
-
path: "/",
|
|
44
|
-
pathname: "/",
|
|
45
|
-
params: {},
|
|
46
|
-
query: {},
|
|
47
|
-
isPreview: false,
|
|
48
|
-
isMounted: false,
|
|
49
|
-
navigate: async () => {},
|
|
50
|
-
push: async () => {},
|
|
51
|
-
replace: async () => {},
|
|
52
|
-
reload: async () => {},
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const ROUTER_CONTEXT_SYMBOL = Symbol.for("veryfront.react.router-context");
|
|
56
|
-
const globalRouterContext = dntShim.dntGlobalThis as typeof dntShim.dntGlobalThis & {
|
|
57
|
-
[ROUTER_CONTEXT_SYMBOL]?: React.Context<RouterValue>;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const RouterContext = globalRouterContext[ROUTER_CONTEXT_SYMBOL] ??
|
|
61
|
-
(globalRouterContext[ROUTER_CONTEXT_SYMBOL] = React.createContext<RouterValue>(defaultRouter));
|
|
62
|
-
|
|
63
|
-
export interface RouterProviderProps {
|
|
64
|
-
children: React.ReactNode;
|
|
65
|
-
router?: RouterValue;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function RouterProvider({
|
|
69
|
-
children,
|
|
70
|
-
router,
|
|
71
|
-
}: RouterProviderProps): React.ReactElement {
|
|
72
|
-
return (
|
|
73
|
-
<RouterContext.Provider value={router ?? defaultRouter}>
|
|
74
|
-
{children}
|
|
75
|
-
</RouterContext.Provider>
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function useRouter(): RouterValue {
|
|
80
|
-
return React.useContext(RouterContext);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export { RouterProvider as Router };
|
|
84
|
-
|
|
85
|
-
// Link is defined here (not re-exported from components/Link.tsx) to avoid
|
|
86
|
-
// relative imports in embedded framework sources, which break compiled binary SSR.
|
|
87
|
-
export type LinkProps = React.AnchorHTMLAttributes<HTMLAnchorElement> & {
|
|
88
|
-
prefetch?: boolean;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export function Link({
|
|
92
|
-
prefetch = true,
|
|
93
|
-
children,
|
|
94
|
-
...rest
|
|
95
|
-
}: LinkProps): React.ReactElement {
|
|
96
|
-
return (
|
|
97
|
-
<a {...rest} data-prefetch={prefetch ? "true" : undefined}>
|
|
98
|
-
{children}
|
|
99
|
-
</a>
|
|
100
|
-
);
|
|
101
|
-
}
|
|
2
|
+
export { Link, Router, RouterProvider, useRouter } from "../runtime/core.js";
|
|
3
|
+
export type { LinkProps, RouterProviderProps, RouterValue } from "../runtime/core.js";
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import * as dntShim from "../../../_dnt.shims.js";
|
|
2
|
+
import React, { useEffect } from "react";
|
|
3
|
+
|
|
4
|
+
export interface RouterValue {
|
|
5
|
+
domain: string;
|
|
6
|
+
path: string;
|
|
7
|
+
pathname: string;
|
|
8
|
+
params: Record<string, string>;
|
|
9
|
+
query: Record<string, string>;
|
|
10
|
+
isPreview: boolean;
|
|
11
|
+
isMounted: boolean;
|
|
12
|
+
navigate: (url: string) => Promise<void>;
|
|
13
|
+
push: (url: string) => Promise<void>;
|
|
14
|
+
replace: (url: string) => Promise<void>;
|
|
15
|
+
reload: () => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type LinkProps = React.AnchorHTMLAttributes<HTMLAnchorElement> & {
|
|
19
|
+
prefetch?: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export interface RouterProviderProps {
|
|
23
|
+
children: React.ReactNode;
|
|
24
|
+
router?: RouterValue;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface MdxHeading {
|
|
28
|
+
text: string;
|
|
29
|
+
id: string;
|
|
30
|
+
level: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface PageContextValue {
|
|
34
|
+
slug: string;
|
|
35
|
+
path: string;
|
|
36
|
+
params: Record<string, string>;
|
|
37
|
+
query: Record<string, string>;
|
|
38
|
+
frontmatter: Record<string, unknown>;
|
|
39
|
+
headings: MdxHeading[];
|
|
40
|
+
mdxHeadings: MdxHeading[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface PageContextProviderProps {
|
|
44
|
+
children: React.ReactNode;
|
|
45
|
+
pageContext?: PageContextValue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const defaultRouter: RouterValue = {
|
|
49
|
+
domain: "",
|
|
50
|
+
path: "/",
|
|
51
|
+
pathname: "/",
|
|
52
|
+
params: {},
|
|
53
|
+
query: {},
|
|
54
|
+
isPreview: false,
|
|
55
|
+
isMounted: false,
|
|
56
|
+
navigate: async () => {},
|
|
57
|
+
push: async () => {},
|
|
58
|
+
replace: async () => {},
|
|
59
|
+
reload: async () => {},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const defaultPageContext: PageContextValue = {
|
|
63
|
+
slug: "/",
|
|
64
|
+
path: "/",
|
|
65
|
+
params: {},
|
|
66
|
+
query: {},
|
|
67
|
+
frontmatter: {},
|
|
68
|
+
headings: [],
|
|
69
|
+
mdxHeadings: [],
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const ROUTER_CONTEXT_SYMBOL = Symbol.for("veryfront.react.router-context");
|
|
73
|
+
const PAGE_CONTEXT_SYMBOL = Symbol.for("veryfront.react.page-context");
|
|
74
|
+
const HEAD_COLLECTOR_SYMBOL = Symbol.for("veryfront.react.collect-head");
|
|
75
|
+
|
|
76
|
+
const globalRouterContext = dntShim.dntGlobalThis as typeof dntShim.dntGlobalThis & {
|
|
77
|
+
[ROUTER_CONTEXT_SYMBOL]?: React.Context<RouterValue>;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const globalPageContext = dntShim.dntGlobalThis as typeof dntShim.dntGlobalThis & {
|
|
81
|
+
[PAGE_CONTEXT_SYMBOL]?: React.Context<PageContextValue>;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
type CollectHeadFn = (data: {
|
|
85
|
+
title?: string;
|
|
86
|
+
description?: string;
|
|
87
|
+
metas?: Array<{ name?: string; property?: string; content: string }>;
|
|
88
|
+
links?: Array<Record<string, string>>;
|
|
89
|
+
styles?: string[];
|
|
90
|
+
scripts?: Array<Record<string, string | undefined>>;
|
|
91
|
+
}) => void;
|
|
92
|
+
|
|
93
|
+
const RouterContext = globalRouterContext[ROUTER_CONTEXT_SYMBOL] ??
|
|
94
|
+
(globalRouterContext[ROUTER_CONTEXT_SYMBOL] = React.createContext<RouterValue>(defaultRouter));
|
|
95
|
+
|
|
96
|
+
const PageContextContext = globalPageContext[PAGE_CONTEXT_SYMBOL] ??
|
|
97
|
+
(globalPageContext[PAGE_CONTEXT_SYMBOL] = React.createContext(defaultPageContext));
|
|
98
|
+
|
|
99
|
+
function isServerEnvironment(): boolean {
|
|
100
|
+
const ssrFlag = (dntShim.dntGlobalThis as Record<string, unknown>).__VERYFRONT_SSR__;
|
|
101
|
+
if (ssrFlag === true) return true;
|
|
102
|
+
return typeof dntShim.dntGlobalThis === "undefined";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function getDocumentNonce(): string | undefined {
|
|
106
|
+
if (typeof document === "undefined") return undefined;
|
|
107
|
+
|
|
108
|
+
const element = document.querySelector<HTMLElement>("script[nonce], style[nonce], link[nonce]");
|
|
109
|
+
if (!element) return undefined;
|
|
110
|
+
|
|
111
|
+
const nonce = element.nonce || element.getAttribute("nonce") || "";
|
|
112
|
+
return nonce || undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function collectHead(data: Parameters<CollectHeadFn>[0]): void {
|
|
116
|
+
const collector = (dntShim.dntGlobalThis as typeof dntShim.dntGlobalThis & {
|
|
117
|
+
[HEAD_COLLECTOR_SYMBOL]?: CollectHeadFn;
|
|
118
|
+
})[HEAD_COLLECTOR_SYMBOL];
|
|
119
|
+
|
|
120
|
+
collector?.(data);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function RouterProvider({
|
|
124
|
+
children,
|
|
125
|
+
router,
|
|
126
|
+
}: RouterProviderProps): React.ReactElement {
|
|
127
|
+
return React.createElement(
|
|
128
|
+
RouterContext.Provider,
|
|
129
|
+
{ value: router ?? defaultRouter },
|
|
130
|
+
children,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function useRouter(): RouterValue {
|
|
135
|
+
return React.useContext(RouterContext);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function Link({
|
|
139
|
+
prefetch = true,
|
|
140
|
+
children,
|
|
141
|
+
...rest
|
|
142
|
+
}: LinkProps): React.ReactElement {
|
|
143
|
+
return React.createElement(
|
|
144
|
+
"a",
|
|
145
|
+
{ ...rest, "data-prefetch": prefetch ? "true" : undefined },
|
|
146
|
+
children,
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function PageContextProvider({
|
|
151
|
+
children,
|
|
152
|
+
pageContext,
|
|
153
|
+
}: PageContextProviderProps): React.ReactElement {
|
|
154
|
+
return React.createElement(
|
|
155
|
+
PageContextContext.Provider,
|
|
156
|
+
{ value: pageContext ?? defaultPageContext },
|
|
157
|
+
children,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function usePageContext(): PageContextValue {
|
|
162
|
+
return React.useContext(PageContextContext);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function Head({ children }: { children: React.ReactNode }): React.ReactElement {
|
|
166
|
+
const isSSR = isServerEnvironment();
|
|
167
|
+
|
|
168
|
+
if (isSSR && children) {
|
|
169
|
+
React.Children.forEach(children, (child) => {
|
|
170
|
+
if (!React.isValidElement(child)) return;
|
|
171
|
+
|
|
172
|
+
const { type } = child;
|
|
173
|
+
const props = child.props as Record<string, unknown>;
|
|
174
|
+
if (typeof type !== "string" || type === "body") return;
|
|
175
|
+
|
|
176
|
+
if (type === "title") {
|
|
177
|
+
collectHead({ title: String(props.children ?? "") });
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (type === "meta") {
|
|
182
|
+
collectHead({
|
|
183
|
+
metas: [{
|
|
184
|
+
name: props.name as string | undefined,
|
|
185
|
+
property: props.property as string | undefined,
|
|
186
|
+
content: String(props.content ?? ""),
|
|
187
|
+
}],
|
|
188
|
+
});
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (type === "link") {
|
|
193
|
+
const link: Record<string, string> = {};
|
|
194
|
+
for (const [key, value] of Object.entries(props)) {
|
|
195
|
+
if (value != null) link[key] = String(value);
|
|
196
|
+
}
|
|
197
|
+
collectHead({ links: [link] });
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (type === "style") {
|
|
202
|
+
collectHead({ styles: [String(props.children ?? "")] });
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (type === "script") {
|
|
207
|
+
const script: Record<string, string | undefined> = {};
|
|
208
|
+
for (const [key, value] of Object.entries(props)) {
|
|
209
|
+
if (key === "children" || key === "dangerouslySetInnerHTML") continue;
|
|
210
|
+
if (value != null) script[key] = String(value);
|
|
211
|
+
}
|
|
212
|
+
if (props.dangerouslySetInnerHTML) {
|
|
213
|
+
const html = props.dangerouslySetInnerHTML as { __html?: string };
|
|
214
|
+
if (html.__html) script.content = html.__html;
|
|
215
|
+
} else if (typeof props.children === "string") {
|
|
216
|
+
script.content = props.children;
|
|
217
|
+
}
|
|
218
|
+
collectHead({ scripts: [script] });
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
useEffect(() => {
|
|
224
|
+
if (!children) return;
|
|
225
|
+
|
|
226
|
+
const addedElements: Element[] = [];
|
|
227
|
+
const nonce = getDocumentNonce();
|
|
228
|
+
|
|
229
|
+
React.Children.forEach(children, (child) => {
|
|
230
|
+
if (!React.isValidElement(child)) return;
|
|
231
|
+
|
|
232
|
+
const { type } = child;
|
|
233
|
+
const props = child.props as Record<string, unknown>;
|
|
234
|
+
if (typeof type !== "string" || type === "body") return;
|
|
235
|
+
|
|
236
|
+
if (type === "title") {
|
|
237
|
+
document.title = String(props.children ?? "");
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const element = document.createElement(type);
|
|
242
|
+
if ((type === "style" || type === "script") && !props.nonce && nonce) {
|
|
243
|
+
element.setAttribute("nonce", nonce);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (type === "script") {
|
|
247
|
+
const src = props.src as string | undefined;
|
|
248
|
+
const id = props.id as string | undefined;
|
|
249
|
+
|
|
250
|
+
if (id && document.querySelector(`script[data-vf-head][id="${id}"]`)) return;
|
|
251
|
+
if (src && document.querySelector(`script[data-vf-head][src="${src}"]`)) return;
|
|
252
|
+
|
|
253
|
+
const content = typeof props.children === "string"
|
|
254
|
+
? props.children
|
|
255
|
+
: (props.dangerouslySetInnerHTML as { __html?: string })?.__html;
|
|
256
|
+
if (content && !id) {
|
|
257
|
+
let sum = 0;
|
|
258
|
+
for (let i = 0; i < Math.min(content.length, 200); i++) {
|
|
259
|
+
sum = ((sum << 5) - sum + content.charCodeAt(i)) | 0;
|
|
260
|
+
}
|
|
261
|
+
const hash = `vf${Math.abs(sum).toString(36)}`;
|
|
262
|
+
if (document.querySelector(`script[data-vf-head][data-vf-hash="${hash}"]`)) return;
|
|
263
|
+
element.setAttribute("data-vf-hash", hash);
|
|
264
|
+
}
|
|
265
|
+
element.setAttribute("data-vf-head", "true");
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
for (const [key, value] of Object.entries(props)) {
|
|
269
|
+
if (key === "children") continue;
|
|
270
|
+
|
|
271
|
+
let attrName = key;
|
|
272
|
+
if (key === "className") attrName = "class";
|
|
273
|
+
else if (key === "htmlFor") attrName = "for";
|
|
274
|
+
|
|
275
|
+
if (typeof value === "boolean") {
|
|
276
|
+
if (value) element.setAttribute(attrName, "");
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (value != null) element.setAttribute(attrName, String(value));
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (typeof props.children === "string") {
|
|
284
|
+
element.textContent = props.children;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
element.setAttribute("data-veryfront-managed", "1");
|
|
288
|
+
document.head.appendChild(element);
|
|
289
|
+
addedElements.push(element);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
return () => {
|
|
293
|
+
for (const el of addedElements) el.remove();
|
|
294
|
+
};
|
|
295
|
+
}, [children]);
|
|
296
|
+
|
|
297
|
+
return React.createElement("div", {
|
|
298
|
+
"data-veryfront-head": "1",
|
|
299
|
+
style: { display: "none" },
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export { RouterProvider as Router };
|