dtwo 3.2.0 → 3.2.1

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2022 - Dtwo Team
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 - Dtwo Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/app.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './dist/app'
1
+ export * from './dist/app'
package/bin/dtwo.mjs CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env node
2
- import 'dtwc/cli'
1
+ #!/usr/bin/env node
2
+ import 'dtwc/cli'
package/config.cjs CHANGED
@@ -1,7 +1,7 @@
1
- function defineDtwoConfig (config) {
2
- return config
3
- }
4
-
5
- module.exports = {
6
- defineDtwoConfig
7
- }
1
+ function defineDtwoConfig (config) {
2
+ return config
3
+ }
4
+
5
+ module.exports = {
6
+ defineDtwoConfig
7
+ }
package/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { DtwoConfig } from '@dtwo/schema'
2
- export { DtwoConfig } from '@dtwo/schema'
1
+ import type { DtwoConfig } from 'dtwo/schema'
2
+ export { DtwoConfig } from 'dtwo/schema'
3
3
 
4
4
  export declare function defineDtwoConfig(config: DtwoConfig): DtwoConfig
package/config.mjs CHANGED
@@ -1,5 +1,5 @@
1
- function defineDtwoConfig (config) {
2
- return config
3
- }
4
-
5
- export { defineDtwoConfig }
1
+ function defineDtwoConfig (config) {
2
+ return config
3
+ }
4
+
5
+ export { defineDtwoConfig }
@@ -1,75 +1,75 @@
1
- import { ref, onMounted, defineComponent, createElementBlock, h, createElementKNode } from 'kdu'
2
-
3
- export default defineComponent({
4
- name: 'ClientOnly',
5
- inheritAttrs: false,
6
- // eslint-disable-next-line kdu/require-prop-types
7
- props: ['fallback', 'placeholder', 'placeholderTag', 'fallbackTag'],
8
- setup (_, { slots, attrs }) {
9
- const mounted = ref(false)
10
- onMounted(() => { mounted.value = true })
11
- return (props) => {
12
- if (mounted.value) { return slots.default?.() }
13
- const slot = slots.fallback || slots.placeholder
14
- if (slot) { return slot() }
15
- const fallbackStr = props.fallback || props.placeholder || ''
16
- const fallbackTag = props.fallbackTag || props.placeholderTag || 'span'
17
- return createElementBlock(fallbackTag, attrs, fallbackStr)
18
- }
19
- }
20
- })
21
-
22
- const cache = new WeakMap()
23
-
24
- export function createClientOnly (component) {
25
- if (cache.has(component)) {
26
- return cache.get(component)
27
- }
28
-
29
- const clone = { ...component }
30
-
31
- if (clone.render) {
32
- // override the component render (non script setup component)
33
- clone.render = (ctx, ...args) => {
34
- if (ctx.mounted$) {
35
- const res = component.render(ctx, ...args)
36
- return (res.children === null || typeof res.children === 'string')
37
- ? createElementKNode(res.type, res.props, res.children, res.patchFlag, res.dynamicProps, res.shapeFlag)
38
- : h(res)
39
- } else {
40
- return h('div', ctx.$attrs ?? ctx._.attrs)
41
- }
42
- }
43
- } else if (clone.template) {
44
- // handle runtime-compiler template
45
- clone.template = `
46
- <template k-if="mounted$">${component.template}</template>
47
- <template k-else><div></div></template>
48
- `
49
- }
50
-
51
- clone.setup = (props, ctx) => {
52
- const mounted$ = ref(false)
53
- onMounted(() => { mounted$.value = true })
54
-
55
- return Promise.resolve(component.setup?.(props, ctx) || {})
56
- .then((setupState) => {
57
- return typeof setupState !== 'function'
58
- ? { ...setupState, mounted$ }
59
- : (...args) => {
60
- if (mounted$.value) {
61
- const res = setupState(...args)
62
- return (res.children === null || typeof res.children === 'string')
63
- ? createElementKNode(res.type, res.props, res.children, res.patchFlag, res.dynamicProps, res.shapeFlag)
64
- : h(res)
65
- } else {
66
- return h('div', ctx.attrs)
67
- }
68
- }
69
- })
70
- }
71
-
72
- cache.set(component, clone)
73
-
74
- return clone
75
- }
1
+ import { ref, onMounted, defineComponent, createElementBlock, h, createElementKNode } from 'kdu'
2
+
3
+ export default defineComponent({
4
+ name: 'ClientOnly',
5
+ inheritAttrs: false,
6
+ // eslint-disable-next-line kdu/require-prop-types
7
+ props: ['fallback', 'placeholder', 'placeholderTag', 'fallbackTag'],
8
+ setup (_, { slots, attrs }) {
9
+ const mounted = ref(false)
10
+ onMounted(() => { mounted.value = true })
11
+ return (props) => {
12
+ if (mounted.value) { return slots.default?.() }
13
+ const slot = slots.fallback || slots.placeholder
14
+ if (slot) { return slot() }
15
+ const fallbackStr = props.fallback || props.placeholder || ''
16
+ const fallbackTag = props.fallbackTag || props.placeholderTag || 'span'
17
+ return createElementBlock(fallbackTag, attrs, fallbackStr)
18
+ }
19
+ }
20
+ })
21
+
22
+ const cache = new WeakMap()
23
+
24
+ export function createClientOnly (component) {
25
+ if (cache.has(component)) {
26
+ return cache.get(component)
27
+ }
28
+
29
+ const clone = { ...component }
30
+
31
+ if (clone.render) {
32
+ // override the component render (non script setup component)
33
+ clone.render = (ctx, ...args) => {
34
+ if (ctx.mounted$) {
35
+ const res = component.render(ctx, ...args)
36
+ return (res.children === null || typeof res.children === 'string')
37
+ ? createElementKNode(res.type, res.props, res.children, res.patchFlag, res.dynamicProps, res.shapeFlag)
38
+ : h(res)
39
+ } else {
40
+ return h('div', ctx.$attrs ?? ctx._.attrs)
41
+ }
42
+ }
43
+ } else if (clone.template) {
44
+ // handle runtime-compiler template
45
+ clone.template = `
46
+ <template k-if="mounted$">${component.template}</template>
47
+ <template k-else><div></div></template>
48
+ `
49
+ }
50
+
51
+ clone.setup = (props, ctx) => {
52
+ const mounted$ = ref(false)
53
+ onMounted(() => { mounted$.value = true })
54
+
55
+ return Promise.resolve(component.setup?.(props, ctx) || {})
56
+ .then((setupState) => {
57
+ return typeof setupState !== 'function'
58
+ ? { ...setupState, mounted$ }
59
+ : (...args) => {
60
+ if (mounted$.value) {
61
+ const res = setupState(...args)
62
+ return (res.children === null || typeof res.children === 'string')
63
+ ? createElementKNode(res.type, res.props, res.children, res.patchFlag, res.dynamicProps, res.shapeFlag)
64
+ : h(res)
65
+ } else {
66
+ return h('div', ctx.attrs)
67
+ }
68
+ }
69
+ })
70
+ }
71
+
72
+ cache.set(component, clone)
73
+
74
+ return clone
75
+ }
@@ -1,11 +1,11 @@
1
- import { defineComponent } from 'kdu'
2
-
3
- export default defineComponent({
4
- name: 'DevOnly',
5
- setup (_, props) {
6
- if (process.dev) {
7
- return () => props.slots.default?.()
8
- }
9
- return () => null
10
- }
11
- })
1
+ import { defineComponent } from 'kdu'
2
+
3
+ export default defineComponent({
4
+ name: 'DevOnly',
5
+ setup (_, props) {
6
+ if (process.dev) {
7
+ return () => props.slots.default?.()
8
+ }
9
+ return () => null
10
+ }
11
+ })
@@ -1,46 +1,46 @@
1
- <template>
2
- <ErrorTemplate k-bind="{ statusCode, statusMessage, description, stack }" />
3
- </template>
4
-
5
- <script setup>
6
- import { defineAsyncComponent } from 'kdu'
7
-
8
- // Deliberately prevent reactive update when error is cleared
9
- // eslint-disable-next-line kdu/no-setup-props-destructure
10
- const { error } = defineProps({
11
- error: Object
12
- })
13
-
14
- // TODO: extract to a separate utility
15
- const stacktrace = (error.stack || '')
16
- .split('\n')
17
- .splice(1)
18
- .map((line) => {
19
- const text = line
20
- .replace('webpack:/', '')
21
- .replace('.kdu', '.js') // TODO: Support sourcemap
22
- .trim()
23
- return {
24
- text,
25
- internal: (line.includes('node_modules') && !line.includes('.cache')) ||
26
- line.includes('internal') ||
27
- line.includes('new Promise')
28
- }
29
- }).map(i => `<span class="stack${i.internal ? ' internal' : ''}">${i.text}</span>`).join('\n')
30
-
31
- // Error page props
32
- const statusCode = Number(error.statusCode || 500)
33
- const is404 = statusCode === 404
34
-
35
- const statusMessage = error.statusMessage ?? (is404 ? 'Page Not Found' : 'Internal Server Error')
36
- const description = error.message || error.toString()
37
- const stack = process.dev && !is404 ? error.description || `<pre>${stacktrace}</pre>` : undefined
38
-
39
- // TODO: Investigate side-effect issue with imports
40
- const _Error404 = defineAsyncComponent(() => import('@dtwo/ui-templates/templates/error-404.kdu').then(r => r.default || r))
41
- const _Error = process.dev
42
- ? defineAsyncComponent(() => import('@dtwo/ui-templates/templates/error-dev.kdu').then(r => r.default || r))
43
- : defineAsyncComponent(() => import('@dtwo/ui-templates/templates/error-500.kdu').then(r => r.default || r))
44
-
45
- const ErrorTemplate = is404 ? _Error404 : _Error
46
- </script>
1
+ <template>
2
+ <ErrorTemplate k-bind="{ statusCode, statusMessage, description, stack }" />
3
+ </template>
4
+
5
+ <script setup>
6
+ import { defineAsyncComponent } from 'kdu'
7
+
8
+ // Deliberately prevent reactive update when error is cleared
9
+ // eslint-disable-next-line kdu/no-setup-props-destructure
10
+ const { error } = defineProps({
11
+ error: Object
12
+ })
13
+
14
+ // TODO: extract to a separate utility
15
+ const stacktrace = (error.stack || '')
16
+ .split('\n')
17
+ .splice(1)
18
+ .map((line) => {
19
+ const text = line
20
+ .replace('webpack:/', '')
21
+ .replace('.kdu', '.js') // TODO: Support sourcemap
22
+ .trim()
23
+ return {
24
+ text,
25
+ internal: (line.includes('node_modules') && !line.includes('.cache')) ||
26
+ line.includes('internal') ||
27
+ line.includes('new Promise')
28
+ }
29
+ }).map(i => `<span class="stack${i.internal ? ' internal' : ''}">${i.text}</span>`).join('\n')
30
+
31
+ // Error page props
32
+ const statusCode = Number(error.statusCode || 500)
33
+ const is404 = statusCode === 404
34
+
35
+ const statusMessage = error.statusMessage ?? (is404 ? 'Page Not Found' : 'Internal Server Error')
36
+ const description = error.message || error.toString()
37
+ const stack = process.dev && !is404 ? error.description || `<pre>${stacktrace}</pre>` : undefined
38
+
39
+ // TODO: Investigate side-effect issue with imports
40
+ const _Error404 = defineAsyncComponent(() => import('@dtwo/ui-templates/templates/error-404.kdu').then(r => r.default || r))
41
+ const _Error = process.dev
42
+ ? defineAsyncComponent(() => import('@dtwo/ui-templates/templates/error-dev.kdu').then(r => r.default || r))
43
+ : defineAsyncComponent(() => import('@dtwo/ui-templates/templates/error-500.kdu').then(r => r.default || r))
44
+
45
+ const ErrorTemplate = is404 ? _Error404 : _Error
46
+ </script>
@@ -37,12 +37,14 @@ export default defineComponent({
37
37
  right: 0,
38
38
  left: 0,
39
39
  pointerEvents: "none",
40
- width: `${indicator.progress.value}%`,
40
+ width: "auto",
41
41
  height: `${props.height}px`,
42
42
  opacity: indicator.isLoading.value ? 1 : 0,
43
43
  background: props.color || void 0,
44
44
  backgroundSize: `${100 / indicator.progress.value * 100}% auto`,
45
- transition: "width 0.1s, height 0.4s, opacity 0.4s",
45
+ transform: `scaleX(${indicator.progress.value}%)`,
46
+ transformOrigin: "left",
47
+ transition: "transform 0.1s, height 0.4s, opacity 0.4s",
46
48
  zIndex: 999999
47
49
  }
48
50
  }, slots);
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <Suspense @resolve="onResolve">
3
3
  <ErrorComponent k-if="error" :error="error" />
4
- <IslandRendererer k-else-if="islandContext" :context="islandContext" />
4
+ <IslandRenderer k-else-if="islandContext" :context="islandContext" />
5
5
  <AppComponent k-else />
6
6
  </Suspense>
7
7
  </template>
@@ -14,7 +14,7 @@ import { useRoute } from '#app/composables/router'
14
14
  import AppComponent from '#build/app-component.mjs'
15
15
 
16
16
  const ErrorComponent = defineAsyncComponent(() => import('#build/error-component.mjs').then(r => r.default || r))
17
- const IslandRendererer = process.server
17
+ const IslandRenderer = process.server
18
18
  ? defineAsyncComponent(() => import('./island-renderer').then(r => r.default || r))
19
19
  : () => null
20
20
 
@@ -1,7 +1,7 @@
1
1
  import type { H3Error } from 'h3';
2
2
  export declare const useError: () => import("kdu").Ref<Error | {
3
3
  url: string;
4
- statusCode: string;
4
+ statusCode: number;
5
5
  statusMessage: string;
6
6
  message: string;
7
7
  description: string;
@@ -1,4 +1,4 @@
1
- import { joinURL } from "ufo";
1
+ import { joinURL, hasProtocol } from "ufo";
2
2
  import { useDtwoApp, useRuntimeConfig } from "../dtwo.mjs";
3
3
  import { useHead } from "./head.mjs";
4
4
  export function loadPayload(url, opts = {}) {
@@ -33,8 +33,8 @@ function _getPayloadURL(url, opts = {}) {
33
33
  if (u.search) {
34
34
  throw new Error("Payload URL cannot contain search params: " + url);
35
35
  }
36
- if (u.host !== "localhost") {
37
- throw new Error("Payload URL cannot contain host: " + url);
36
+ if (u.host !== "localhost" || hasProtocol(u.pathname, true)) {
37
+ throw new Error("Payload URL must not include hostname: " + url);
38
38
  }
39
39
  const hash = opts.hash || (opts.fresh ? Date.now() : "");
40
40
  return joinURL(useRuntimeConfig().app.baseURL, u.pathname, hash ? `_payload.${hash}.js` : "_payload.js");
@@ -45,7 +45,7 @@ async function _importPayload(payloadURL) {
45
45
  }
46
46
  const res = await import(
47
47
  /* webpackIgnore: true */
48
- /* @wite-ignore */
48
+ /* @lahm-ignore */
49
49
  payloadURL
50
50
  ).catch((err) => {
51
51
  console.warn("[dtwo] Cannot load payload ", payloadURL, err);
@@ -53,7 +53,7 @@ export const navigateTo = (to, options) => {
53
53
  const toPath = typeof to === "string" ? to : to.path || "/";
54
54
  const isExternal = hasProtocol(toPath, true);
55
55
  if (isExternal && !options?.external) {
56
- throw new Error("Navigating to external URL is not allowed by default. Use `nagivateTo (url, { external: true })`.");
56
+ throw new Error("Navigating to external URL is not allowed by default. Use `navigateTo (url, { external: true })`.");
57
57
  }
58
58
  if (isExternal && parseURL(toPath).protocol === "script:") {
59
59
  throw new Error("Cannot navigate to an URL with script protocol.");
@@ -1,4 +1,4 @@
1
- import type { AppConfig } from '@dtwo/schema';
1
+ import type { AppConfig } from 'dtwo/schema';
2
2
  type DeepPartial<T> = T extends Function ? T : T extends Record<string, any> ? {
3
3
  [P in keyof T]?: DeepPartial<T[P]>;
4
4
  } : T;
@@ -1,9 +1,9 @@
1
1
  import type { App, onErrorCaptured, KNode, Ref } from 'kdu';
2
2
  import type { Hookable } from 'hookable';
3
- import type { RuntimeConfig, AppConfigInput } from '@dtwo/schema';
4
3
  import type { SSRContext } from 'kdu-bundle-renderer/runtime';
5
4
  import type { H3Event } from 'h3';
6
5
  import type { DtwoIslandContext } from '../core/runtime/hole/renderer';
6
+ import type { RuntimeConfig, AppConfigInput } from 'dtwo/schema';
7
7
  type DtwoMeta = {
8
8
  htmlAttrs?: string;
9
9
  headAttrs?: string;
@@ -27,6 +27,9 @@ export interface RuntimeDtwoHooks {
27
27
  'app:error:cleared': (options: {
28
28
  redirect?: string;
29
29
  }) => HookResult;
30
+ 'app:chunkError': (options: {
31
+ error: any;
32
+ }) => HookResult;
30
33
  'app:data:refresh': (keys?: string[]) => HookResult;
31
34
  'link:prefetch': (link: string) => HookResult;
32
35
  'page:start': (Component?: KNode) => HookResult;
@@ -72,7 +75,7 @@ interface _DtwoApp {
72
75
  rendered?: Function;
73
76
  error?: Error | {
74
77
  url: string;
75
- statusCode: string;
78
+ statusCode: number;
76
79
  statusMessage: string;
77
80
  message: string;
78
81
  description: string;
package/dist/app/dtwo.mjs CHANGED
@@ -65,6 +65,11 @@ export function createDtwoApp(options) {
65
65
  app: options.ssrContext.runtimeConfig.app
66
66
  };
67
67
  }
68
+ if (process.client) {
69
+ window.addEventListener("dtwo.preloadError", (event) => {
70
+ dtwoApp.callHook("app:chunkError", { error: event.payload });
71
+ });
72
+ }
68
73
  const runtimeConfig = process.server ? options.ssrContext.runtimeConfig : reactive(dtwoApp.payload.config);
69
74
  const compatibilityConfig = new Proxy(runtimeConfig, {
70
75
  get(target, prop) {
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,26 @@
1
+ import { defineDtwoPlugin } from "#app/dtwo";
2
+ import { useRouter } from "#app/composables/router";
3
+ export default defineDtwoPlugin((dtwoApp) => {
4
+ const router = useRouter();
5
+ const chunkErrors = /* @__PURE__ */ new Set();
6
+ router.beforeEach(() => {
7
+ chunkErrors.clear();
8
+ });
9
+ dtwoApp.hook("app:chunkError", ({ error }) => {
10
+ chunkErrors.add(error);
11
+ });
12
+ router.onError((error, to) => {
13
+ if (!chunkErrors.has(error)) {
14
+ return;
15
+ }
16
+ let handledPath = {};
17
+ try {
18
+ handledPath = JSON.parse(localStorage.getItem("dtwo:reload") || "{}");
19
+ } catch {
20
+ }
21
+ if (handledPath?.path !== to.fullPath || handledPath?.expires < Date.now()) {
22
+ localStorage.setItem("dtwo:reload", JSON.stringify({ path: to.fullPath, expires: Date.now() + 1e4 }));
23
+ window.location.href = to.fullPath;
24
+ }
25
+ });
26
+ });
@@ -1,12 +1,11 @@
1
1
  import { reactive, h, isReadonly } from "kdu";
2
2
  import { parseURL, stringifyParsedURL, parseQuery, stringifyQuery, withoutBase, isEqual, joinURL } from "ufo";
3
3
  import { createError } from "h3";
4
- import { defineDtwoPlugin, useRuntimeConfig } from "../dtwo.mjs";
4
+ import { callWithDtwo, defineDtwoPlugin, useRuntimeConfig } from "../dtwo.mjs";
5
5
  import { clearError, showError } from "../composables/error.mjs";
6
6
  import { navigateTo } from "../composables/router.mjs";
7
7
  import { useState } from "../composables/state.mjs";
8
8
  import { useRequestEvent } from "../composables/ssr.mjs";
9
- import { callWithDtwo } from "../dtwo.mjs";
10
9
  import { globalMiddleware } from "#build/middleware";
11
10
  function getRouteFromPath(fullPath) {
12
11
  if (typeof fullPath === "object") {
@@ -1,28 +1,28 @@
1
- import type { DtwoApp } from '../dtwo'
2
-
3
- declare global {
4
- namespace NodeJS {
5
- interface Process {
6
- browser: boolean
7
- client: boolean
8
- dev: boolean
9
- mode: 'spa' | 'universal'
10
- server: boolean
11
- static: boolean
12
- }
13
- }
14
-
15
- interface Window {
16
- __DTWO__?: Record<string, any>
17
- }
18
- }
19
-
20
- declare module 'kdu' {
21
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
- interface App<HostElement> {
23
- $dtwo: DtwoApp
24
- }
25
- interface ComponentInternalInstance {
26
- _dtwoOnBeforeMountCbs: Function[]
27
- }
28
- }
1
+ import type { DtwoApp } from '../dtwo'
2
+
3
+ declare global {
4
+ namespace NodeJS {
5
+ interface Process {
6
+ browser: boolean
7
+ client: boolean
8
+ dev: boolean
9
+ mode: 'spa' | 'universal'
10
+ server: boolean
11
+ static: boolean
12
+ }
13
+ }
14
+
15
+ interface Window {
16
+ __DTWO__?: Record<string, any>
17
+ }
18
+ }
19
+
20
+ declare module 'kdu' {
21
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
+ interface App<HostElement> {
23
+ $dtwo: DtwoApp
24
+ }
25
+ interface ComponentInternalInstance {
26
+ _dtwoOnBeforeMountCbs: Function[]
27
+ }
28
+ }
@@ -4,8 +4,9 @@ import devalue from "@d2js/devalue";
4
4
  import destr from "destr";
5
5
  import { joinURL } from "ufo";
6
6
  import { renderToString as _renderToString } from "kdu/server-renderer";
7
- import { useRuntimeConfig, useHoleApp, defineRenderHandler, getRouteRules } from "#internal/hole";
7
+ import { useRuntimeConfig, defineRenderHandler, getRouteRules } from "#internal/hole";
8
8
  import { hash } from "ohash";
9
+ import { useHoleApp } from "#internal/hole/app";
9
10
  import { appRootId, appRootTag } from "#internal/dtwo.config.mjs";
10
11
  import { buildAssetsURL, publicAssetsURL } from "#paths";
11
12
  globalThis.__buildAssetsURL = buildAssetsURL;
@@ -31,7 +32,7 @@ const getSSRRenderer = lazyCachedFunction(async () => {
31
32
  const renderer = createRenderer(createSSRApp, options);
32
33
  async function renderToString(input, context) {
33
34
  const html = await _renderToString(input, context);
34
- if (process.dev && process.env.DTWO_WITE_NODE_OPTIONS) {
35
+ if (process.dev && process.env.DTWO_LAHM_NODE_OPTIONS) {
35
36
  renderer.rendererContext.updateManifest(await getClientManifest());
36
37
  }
37
38
  return `<${appRootTag} id="${appRootId}">${html}</${appRootTag}>`;
@@ -86,6 +87,9 @@ const PRERENDER_NO_SSR_ROUTES = /* @__PURE__ */ new Set(["/index.html", "/200.ht
86
87
  export default defineRenderHandler(async (event) => {
87
88
  const holeApp = useHoleApp();
88
89
  const ssrError = event.node.req.url?.startsWith("/__dtwo_error") ? getQuery(event) : null;
90
+ if (ssrError && ssrError.statusCode) {
91
+ ssrError.statusCode = parseInt(ssrError.statusCode);
92
+ }
89
93
  if (ssrError && event.node.req.socket.readyState !== "readOnly") {
90
94
  throw createError("Cannot directly render error page!");
91
95
  }
@@ -1,6 +1,6 @@
1
1
  import type { HeadEntryOptions, UseHeadInput, ActiveHeadEntry } from '@kduse/head';
2
- import type { HeadAugmentations } from '@dtwo/schema';
3
2
  import { useSeoMeta as _useSeoMeta } from '@kduse/head';
3
+ import type { HeadAugmentations } from 'dtwo/schema';
4
4
  /**
5
5
  * You can pass in a meta object, which has keys corresponding to meta tags:
6
6
  * `title`, `base`, `script`, `style`, `meta` and `link`, as well as `htmlAttrs` and `bodyAttrs`.
@@ -1,4 +1,4 @@
1
1
  import type { UseHeadInput } from '@kduse/head';
2
- import type { HeadAugmentations } from '@dtwo/schema';
2
+ import type { HeadAugmentations } from 'dtwo/schema';
3
3
  export * from './composables';
4
4
  export type MetaObject = UseHeadInput<HeadAugmentations>;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { DtwoOptions, Dtwo } from '@dtwo/schema';
2
1
  import { LoadDtwoOptions } from '@dtwo/kit';
2
+ import { DtwoOptions, Dtwo } from 'dtwo/schema';
3
3
 
4
4
  declare function createDtwo(options: DtwoOptions): Dtwo;
5
5
  declare function loadDtwo(opts: LoadDtwoOptions): Promise<Dtwo>;