dtwo 3.1.2 → 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.
Files changed (64) hide show
  1. package/LICENSE +21 -21
  2. package/app.d.ts +1 -1
  3. package/bin/dtwo.mjs +2 -2
  4. package/config.cjs +7 -7
  5. package/config.d.ts +2 -2
  6. package/config.mjs +5 -5
  7. package/dist/app/components/client-only.mjs +75 -75
  8. package/dist/app/components/dev-only.mjs +11 -11
  9. package/dist/app/components/dtwo-error-boundary.mjs +1 -1
  10. package/dist/app/components/dtwo-error-page.kdu +46 -46
  11. package/dist/app/components/dtwo-island.mjs +3 -1
  12. package/dist/app/components/dtwo-loading-indicator.mjs +5 -3
  13. package/dist/app/components/dtwo-root.kdu +5 -3
  14. package/dist/app/components/island-renderer.mjs +1 -1
  15. package/dist/app/components/layout.mjs +1 -1
  16. package/dist/app/composables/component.mjs +1 -1
  17. package/dist/app/composables/error.d.ts +1 -1
  18. package/dist/app/composables/fetch.d.ts +7 -6
  19. package/dist/app/composables/fetch.mjs +7 -1
  20. package/dist/app/composables/head.d.ts +2 -0
  21. package/dist/app/composables/head.mjs +1 -0
  22. package/dist/app/composables/index.d.ts +3 -1
  23. package/dist/app/composables/index.mjs +2 -1
  24. package/dist/app/composables/payload.mjs +6 -6
  25. package/dist/app/composables/preload.mjs +1 -1
  26. package/dist/app/composables/router.mjs +1 -1
  27. package/dist/app/composables/ssr.d.ts +1 -0
  28. package/dist/app/composables/ssr.mjs +7 -0
  29. package/dist/app/config.d.ts +1 -1
  30. package/dist/app/dtwo.d.ts +5 -2
  31. package/dist/app/dtwo.mjs +5 -0
  32. package/dist/app/entry-spa.d.ts +2 -0
  33. package/dist/app/entry-spa.mjs +2 -0
  34. package/dist/app/entry.mjs +1 -1
  35. package/dist/app/index.d.ts +0 -2
  36. package/dist/app/index.mjs +0 -1
  37. package/dist/app/plugins/chunk-reload.client.d.ts +2 -0
  38. package/dist/app/plugins/chunk-reload.client.mjs +26 -0
  39. package/dist/app/plugins/cross-origin-prefetch.client.mjs +2 -1
  40. package/dist/app/plugins/debug.mjs +1 -1
  41. package/dist/app/plugins/payload.client.mjs +3 -1
  42. package/dist/app/plugins/preload.server.mjs +1 -1
  43. package/dist/app/plugins/router.d.ts +1 -1
  44. package/dist/app/plugins/router.mjs +5 -2
  45. package/dist/app/types/augments.d.ts +28 -28
  46. package/dist/components/runtime/server-component.mjs +4 -1
  47. package/dist/core/runtime/hole/renderer.mjs +6 -2
  48. package/dist/head/runtime/composables.d.ts +1 -1
  49. package/dist/head/runtime/composables.mjs +1 -1
  50. package/dist/head/runtime/index.d.ts +1 -1
  51. package/dist/head/runtime/lib/kduse-head.plugin.mjs +1 -1
  52. package/dist/index.d.ts +1 -1
  53. package/dist/index.mjs +9173 -271
  54. package/dist/pages/runtime/app.kdu +5 -5
  55. package/dist/pages/runtime/page.mjs +1 -1
  56. package/dist/pages/runtime/plugins/prefetch.client.mjs +2 -1
  57. package/dist/pages/runtime/plugins/router.mjs +6 -2
  58. package/dist/pages/runtime/router.options.mjs +1 -1
  59. package/dist/pages/runtime/validate.mjs +23 -2
  60. package/package.json +31 -27
  61. package/schema.d.ts +1 -0
  62. package/schema.mjs +1 -0
  63. package/types.d.ts +1 -1
  64. package/README.md +0 -7
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,5 +1,5 @@
1
1
  import { defineComponent, ref, onErrorCaptured } from "kdu";
2
- import { useDtwoApp } from "#app";
2
+ import { useDtwoApp } from "#app/dtwo";
3
3
  export default defineComponent({
4
4
  emits: {
5
5
  error(_error) {
@@ -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>
@@ -2,7 +2,9 @@ import { defineComponent, createStaticKNode, computed, ref, watch } from "kdu";
2
2
  import { debounce } from "perfect-debounce";
3
3
  import { hash } from "ohash";
4
4
  import { appendHeader } from "h3";
5
- import { useHead, useDtwoApp, useRequestEvent } from "#app";
5
+ import { useDtwoApp } from "#app/dtwo";
6
+ import { useRequestEvent } from "#app/composables/ssr";
7
+ import { useHead } from "#app/composables/head";
6
8
  const pKey = "_islandPromises";
7
9
  export default defineComponent({
8
10
  name: "DtwoIsland",
@@ -1,5 +1,5 @@
1
1
  import { computed, defineComponent, h, onBeforeUnmount, ref } from "kdu";
2
- import { useDtwoApp } from "#app";
2
+ import { useDtwoApp } from "#app/dtwo";
3
3
  export default defineComponent({
4
4
  name: "DtwoLoadingIndicator",
5
5
  props: {
@@ -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,18 +1,20 @@
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>
8
8
 
9
9
  <script setup>
10
10
  import { defineAsyncComponent, onErrorCaptured, onServerPrefetch, provide } from 'kdu'
11
- import { callWithDtwo, isDtwoError, showError, useError, useRoute, useDtwoApp } from '#app'
11
+ import { callWithDtwo, useDtwoApp } from '#app/dtwo'
12
+ import { isDtwoError, showError, useError } from '#app/composables/error'
13
+ import { useRoute } from '#app/composables/router'
12
14
  import AppComponent from '#build/app-component.mjs'
13
15
 
14
16
  const ErrorComponent = defineAsyncComponent(() => import('#build/error-component.mjs').then(r => r.default || r))
15
- const IslandRendererer = process.server
17
+ const IslandRenderer = process.server
16
18
  ? defineAsyncComponent(() => import('./island-renderer').then(r => r.default || r))
17
19
  : () => null
18
20
 
@@ -1,6 +1,6 @@
1
1
  import { createBlock, defineComponent, h, Teleport } from "kdu";
2
2
  import * as islandComponents from "#build/components.islands.mjs";
3
- import { createError } from "#app";
3
+ import { createError } from "#app/composables/error";
4
4
  export default defineComponent({
5
5
  props: {
6
6
  context: {
@@ -1,6 +1,6 @@
1
1
  import { computed, defineComponent, h, inject, nextTick, onMounted, Transition, unref } from "kdu";
2
2
  import { _wrapIf } from "./utils.mjs";
3
- import { useRoute } from "#app";
3
+ import { useRoute } from "#app/composables/router";
4
4
  import { useRoute as useKduRouterRoute } from "#build/pages";
5
5
  import layouts from "#build/layouts";
6
6
  import { appLayoutTransition as defaultLayoutTransition } from "#build/dtwo.config.mjs";
@@ -2,7 +2,7 @@ import { getCurrentInstance, reactive, toRefs } from "kdu";
2
2
  import { useDtwoApp } from "../dtwo.mjs";
3
3
  import { useAsyncData } from "./asyncData.mjs";
4
4
  import { useRoute } from "./router.mjs";
5
- import { useHead } from "#head";
5
+ import { useHead } from "./head.mjs";
6
6
  export const DtwoComponentIndicator = "__dtwo_component";
7
7
  async function runLegacyAsyncData(res, fn) {
8
8
  const dtwo = useDtwoApp();
@@ -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,15 +1,16 @@
1
1
  import type { FetchError } from 'ofetch';
2
- import type { TypedInternalResponse, HoleFetchOptions, HoleFetchRequest } from 'holepack';
2
+ import type { TypedInternalResponse, HoleFetchOptions, HoleFetchRequest, AvailableRouterMethod } from 'holepack';
3
3
  import type { Ref } from 'kdu';
4
4
  import type { AsyncDataOptions, _Transform, KeyOfRes, AsyncData, PickFrom } from './asyncData';
5
- export type FetchResult<ReqT extends HoleFetchRequest> = TypedInternalResponse<ReqT, unknown>;
5
+ export type FetchResult<ReqT extends HoleFetchRequest, M extends AvailableRouterMethod<ReqT>> = TypedInternalResponse<ReqT, unknown, M>;
6
6
  type ComputedOptions<T extends Record<string, any>> = {
7
7
  [K in keyof T]: T[K] extends Function ? T[K] : T[K] extends Record<string, any> ? ComputedOptions<T[K]> | Ref<T[K]> | T[K] : Ref<T[K]> | T[K];
8
8
  };
9
- type ComputedFetchOptions<R extends HoleFetchRequest> = ComputedOptions<HoleFetchOptions<R>>;
10
- export interface UseFetchOptions<DataT, Transform extends _Transform<DataT, any> = _Transform<DataT, DataT>, PickKeys extends KeyOfRes<Transform> = KeyOfRes<Transform>, R extends HoleFetchRequest = string & {}> extends AsyncDataOptions<DataT, Transform, PickKeys>, ComputedFetchOptions<R> {
9
+ type ComputedFetchOptions<R extends HoleFetchRequest, M extends AvailableRouterMethod<R>> = ComputedOptions<HoleFetchOptions<R, M>>;
10
+ export interface UseFetchOptions<DataT, Transform extends _Transform<DataT, any> = _Transform<DataT, DataT>, PickKeys extends KeyOfRes<Transform> = KeyOfRes<Transform>, R extends HoleFetchRequest = string & {}, M extends AvailableRouterMethod<R> = AvailableRouterMethod<R>> extends AsyncDataOptions<DataT, Transform, PickKeys>, ComputedFetchOptions<R, M> {
11
11
  key?: string;
12
+ $fetch?: typeof globalThis.$fetch;
12
13
  }
13
- export declare function useFetch<ResT = void, ErrorT = FetchError, ReqT extends HoleFetchRequest = HoleFetchRequest, _ResT = ResT extends void ? FetchResult<ReqT> : ResT, Transform extends (res: _ResT) => any = (res: _ResT) => _ResT, PickKeys extends KeyOfRes<Transform> = KeyOfRes<Transform>>(request: Ref<ReqT> | ReqT | (() => ReqT), opts?: UseFetchOptions<_ResT, Transform, PickKeys, ReqT>): AsyncData<PickFrom<ReturnType<Transform>, PickKeys>, ErrorT | null>;
14
- export declare function useLazyFetch<ResT = void, ErrorT = FetchError, ReqT extends HoleFetchRequest = HoleFetchRequest, _ResT = ResT extends void ? FetchResult<ReqT> : ResT, Transform extends (res: _ResT) => any = (res: _ResT) => _ResT, PickKeys extends KeyOfRes<Transform> = KeyOfRes<Transform>>(request: Ref<ReqT> | ReqT | (() => ReqT), opts?: Omit<UseFetchOptions<_ResT, Transform, PickKeys>, 'lazy'>): AsyncData<PickFrom<ReturnType<Transform>, PickKeys>, ErrorT | null>;
14
+ export declare function useFetch<ResT = void, ErrorT = FetchError, ReqT extends HoleFetchRequest = HoleFetchRequest, Method extends AvailableRouterMethod<ReqT> = 'get' extends AvailableRouterMethod<ReqT> ? 'get' : AvailableRouterMethod<ReqT>, _ResT = ResT extends void ? FetchResult<ReqT, Method> : ResT, Transform extends (res: _ResT) => any = (res: _ResT) => _ResT, PickKeys extends KeyOfRes<Transform> = KeyOfRes<Transform>>(request: Ref<ReqT> | ReqT | (() => ReqT), opts?: UseFetchOptions<_ResT, Transform, PickKeys, ReqT, Method>): AsyncData<PickFrom<ReturnType<Transform>, PickKeys>, ErrorT | null>;
15
+ export declare function useLazyFetch<ResT = void, ErrorT = FetchError, ReqT extends HoleFetchRequest = HoleFetchRequest, Method extends AvailableRouterMethod<ReqT> = 'get' extends AvailableRouterMethod<ReqT> ? 'get' : AvailableRouterMethod<ReqT>, _ResT = ResT extends void ? FetchResult<ReqT, Method> : ResT, Transform extends (res: _ResT) => any = (res: _ResT) => _ResT, PickKeys extends KeyOfRes<Transform> = KeyOfRes<Transform>>(request: Ref<ReqT> | ReqT | (() => ReqT), opts?: Omit<UseFetchOptions<_ResT, Transform, PickKeys, Method>, 'lazy'>): AsyncData<PickFrom<ReturnType<Transform>, PickKeys>, ErrorT | null>;
15
16
  export {};
@@ -1,5 +1,6 @@
1
1
  import { computed, unref, reactive } from "kdu";
2
2
  import { hash } from "ohash";
3
+ import { useRequestFetch } from "./ssr.mjs";
3
4
  import { useAsyncData } from "./asyncData.mjs";
4
5
  export function useFetch(request, arg1, arg2) {
5
6
  const [opts = {}, autoKey] = typeof arg1 === "string" ? [{}, arg1] : [arg1, arg2];
@@ -49,7 +50,12 @@ export function useFetch(request, arg1, arg2) {
49
50
  const asyncData = useAsyncData(key, () => {
50
51
  controller?.abort?.();
51
52
  controller = typeof AbortController !== "undefined" ? new AbortController() : {};
52
- return $fetch(_request.value, { signal: controller.signal, ..._fetchOptions });
53
+ const isLocalFetch = typeof _request.value === "string" && _request.value.startsWith("/");
54
+ let _$fetch = opts.$fetch || globalThis.$fetch;
55
+ if (process.server && !opts.$fetch && isLocalFetch) {
56
+ _$fetch = useRequestFetch();
57
+ }
58
+ return _$fetch(_request.value, { signal: controller.signal, ..._fetchOptions });
53
59
  }, _asyncDataOptions);
54
60
  return asyncData;
55
61
  }
@@ -0,0 +1,2 @@
1
+ export type { MetaObject } from '#head';
2
+ export { useHead, useSeoMeta, useServerSeoMeta } from '#head';
@@ -0,0 +1 @@
1
+ export { useHead, useSeoMeta, useServerSeoMeta } from "#head";
@@ -9,9 +9,11 @@ export { useFetch, useLazyFetch } from './fetch';
9
9
  export type { FetchResult, UseFetchOptions } from './fetch';
10
10
  export { useCookie } from './cookie';
11
11
  export type { CookieOptions, CookieRef } from './cookie';
12
- export { useRequestHeaders, useRequestEvent, setResponseStatus } from './ssr';
12
+ export { useRequestHeaders, useRequestEvent, useRequestFetch, setResponseStatus } from './ssr';
13
13
  export { onDtwoReady } from './ready';
14
14
  export { abortNavigation, addRouteMiddleware, defineDtwoRouteMiddleware, onBeforeRouteLeave, onBeforeRouteUpdate, setPageLayout, navigateTo, useRoute, useRouter } from './router';
15
15
  export type { AddRouteMiddlewareOptions, RouteMiddleware } from './router';
16
16
  export { preloadComponents, prefetchComponents, preloadRouteComponents } from './preload';
17
17
  export { isPrerendered, loadPayload, preloadPayload } from './payload';
18
+ export type { MetaObject } from './head';
19
+ export { useHead, useSeoMeta, useServerSeoMeta } from './head';
@@ -5,8 +5,9 @@ export { useState } from "./state.mjs";
5
5
  export { clearError, createError, isDtwoError, showError, useError } from "./error.mjs";
6
6
  export { useFetch, useLazyFetch } from "./fetch.mjs";
7
7
  export { useCookie } from "./cookie.mjs";
8
- export { useRequestHeaders, useRequestEvent, setResponseStatus } from "./ssr.mjs";
8
+ export { useRequestHeaders, useRequestEvent, useRequestFetch, setResponseStatus } from "./ssr.mjs";
9
9
  export { onDtwoReady } from "./ready.mjs";
10
10
  export { abortNavigation, addRouteMiddleware, defineDtwoRouteMiddleware, onBeforeRouteLeave, onBeforeRouteUpdate, setPageLayout, navigateTo, useRoute, useRouter } from "./router.mjs";
11
11
  export { preloadComponents, prefetchComponents, preloadRouteComponents } from "./preload.mjs";
12
12
  export { isPrerendered, loadPayload, preloadPayload } from "./payload.mjs";
13
+ export { useHead, useSeoMeta, useServerSeoMeta } from "./head.mjs";
@@ -1,6 +1,6 @@
1
- import { joinURL } from "ufo";
2
- import { useDtwoApp } from "../dtwo.mjs";
3
- import { useHead, useRuntimeConfig } from "../index.mjs";
1
+ import { joinURL, hasProtocol } from "ufo";
2
+ import { useDtwoApp, useRuntimeConfig } from "../dtwo.mjs";
3
+ import { useHead } from "./head.mjs";
4
4
  export function loadPayload(url, opts = {}) {
5
5
  if (process.server) {
6
6
  return null;
@@ -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);
@@ -26,11 +26,11 @@ export async function preloadRouteComponents(to, router = useRouter()) {
26
26
  if (router._routePreloaded.has(to)) {
27
27
  return;
28
28
  }
29
- router._routePreloaded.add(to);
30
29
  const promises = router._preloadPromises = router._preloadPromises || [];
31
30
  if (promises.length > 4) {
32
31
  return Promise.all(promises).then(() => preloadRouteComponents(to, router));
33
32
  }
33
+ router._routePreloaded.add(to);
34
34
  const components = router.resolve(to).matched.map((component) => component.components?.default).filter((component) => typeof component === "function");
35
35
  for (const component of components) {
36
36
  const promise = Promise.resolve(component()).catch(() => {
@@ -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.");
@@ -3,4 +3,5 @@ import type { DtwoApp } from '../dtwo';
3
3
  export declare function useRequestHeaders<K extends string = string>(include: K[]): Record<Lowercase<K>, string | undefined>;
4
4
  export declare function useRequestHeaders(): Readonly<Record<string, string | undefined>>;
5
5
  export declare function useRequestEvent(dtwoApp?: DtwoApp): H3Event;
6
+ export declare function useRequestFetch(): typeof global.$fetch;
6
7
  export declare function setResponseStatus(code: number, message?: string): void;
@@ -12,6 +12,13 @@ export function useRequestHeaders(include) {
12
12
  export function useRequestEvent(dtwoApp = useDtwoApp()) {
13
13
  return dtwoApp.ssrContext?.event;
14
14
  }
15
+ export function useRequestFetch() {
16
+ if (process.client) {
17
+ return globalThis.$fetch;
18
+ }
19
+ const event = useDtwoApp().ssrContext?.event;
20
+ return event?.$fetch || globalThis.$fetch;
21
+ }
15
22
  export function setResponseStatus(code, message) {
16
23
  const event = process.server && useRequestEvent();
17
24
  if (event) {
@@ -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;