dtwo 3.1.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/compat/idle-callback.mjs +4 -2
- package/dist/app/components/dtwo-error-boundary.mjs +1 -1
- package/dist/app/components/dtwo-island.mjs +3 -1
- package/dist/app/components/dtwo-loading-indicator.mjs +1 -1
- package/dist/app/components/dtwo-root.kdu +3 -1
- package/dist/app/components/island-renderer.mjs +1 -1
- package/dist/app/components/layout.mjs +1 -1
- package/dist/app/composables/component.mjs +1 -1
- package/dist/app/composables/fetch.d.ts +7 -6
- package/dist/app/composables/fetch.mjs +7 -1
- package/dist/app/composables/head.d.ts +2 -0
- package/dist/app/composables/head.mjs +1 -0
- package/dist/app/composables/index.d.ts +3 -1
- package/dist/app/composables/index.mjs +2 -1
- package/dist/app/composables/payload.mjs +2 -2
- package/dist/app/composables/preload.mjs +1 -1
- package/dist/app/composables/ready.mjs +3 -0
- package/dist/app/composables/ssr.d.ts +1 -0
- package/dist/app/composables/ssr.mjs +7 -0
- package/dist/app/entry-spa.d.ts +2 -0
- package/dist/app/entry-spa.mjs +2 -0
- package/dist/app/entry.mjs +1 -1
- package/dist/app/index.d.ts +0 -2
- package/dist/app/index.mjs +0 -1
- package/dist/app/plugins/cross-origin-prefetch.client.mjs +2 -1
- package/dist/app/plugins/debug.mjs +1 -1
- package/dist/app/plugins/payload.client.mjs +3 -1
- package/dist/app/plugins/preload.server.mjs +1 -1
- package/dist/app/plugins/router.d.ts +1 -1
- package/dist/app/plugins/router.mjs +5 -1
- package/dist/components/runtime/server-component.mjs +4 -1
- package/dist/core/runtime/hole/renderer.mjs +1 -1
- package/dist/head/runtime/components.d.ts +8 -8
- package/dist/head/runtime/composables.mjs +1 -1
- package/dist/head/runtime/lib/kduse-head.plugin.mjs +1 -1
- package/dist/index.mjs +181 -63
- package/dist/pages/runtime/page.mjs +1 -1
- package/dist/pages/runtime/plugins/prefetch.client.mjs +2 -1
- package/dist/pages/runtime/plugins/router.mjs +5 -1
- package/dist/pages/runtime/router.options.mjs +1 -1
- package/dist/pages/runtime/validate.mjs +1 -1
- package/package.json +21 -22
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export const requestIdleCallback = process.server ?
|
|
1
|
+
export const requestIdleCallback = process.server ? () => {
|
|
2
|
+
} : globalThis.requestIdleCallback || ((cb) => {
|
|
2
3
|
const start = Date.now();
|
|
3
4
|
const idleDeadline = {
|
|
4
5
|
didTimeout: false,
|
|
@@ -8,6 +9,7 @@ export const requestIdleCallback = process.server ? void 0 : globalThis.requestI
|
|
|
8
9
|
cb(idleDeadline);
|
|
9
10
|
}, 1);
|
|
10
11
|
});
|
|
11
|
-
export const cancelIdleCallback = process.server ?
|
|
12
|
+
export const cancelIdleCallback = process.server ? () => {
|
|
13
|
+
} : globalThis.cancelIdleCallback || ((id) => {
|
|
12
14
|
clearTimeout(id);
|
|
13
15
|
});
|
|
@@ -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 {
|
|
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",
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
<script setup>
|
|
10
10
|
import { defineAsyncComponent, onErrorCaptured, onServerPrefetch, provide } from 'kdu'
|
|
11
|
-
import { callWithDtwo,
|
|
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))
|
|
@@ -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 "
|
|
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,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
|
|
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
|
|
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
|
-
|
|
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 @@
|
|
|
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
1
|
import { joinURL } from "ufo";
|
|
2
|
-
import { useDtwoApp } from "../dtwo.mjs";
|
|
3
|
-
import { useHead
|
|
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;
|
|
@@ -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(() => {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { useDtwoApp } from "../dtwo.mjs";
|
|
2
2
|
import { requestIdleCallback } from "../compat/idle-callback.mjs";
|
|
3
3
|
export const onDtwoReady = (callback) => {
|
|
4
|
+
if (process.server) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
4
7
|
const dtwoApp = useDtwoApp();
|
|
5
8
|
if (dtwoApp.isHydrating) {
|
|
6
9
|
dtwoApp.hooks.hookOnce("app:suspense:resolve", () => {
|
|
@@ -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) {
|
package/dist/app/entry.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createSSRApp, createApp, nextTick } from "kdu";
|
|
2
2
|
import { $fetch } from "ofetch";
|
|
3
3
|
import { baseURL } from "#build/paths.mjs";
|
|
4
|
-
import { createDtwoApp, applyPlugins, normalizePlugins } from "#app";
|
|
4
|
+
import { createDtwoApp, applyPlugins, normalizePlugins } from "#app/dtwo";
|
|
5
5
|
import "#build/css";
|
|
6
6
|
import _plugins from "#build/plugins";
|
|
7
7
|
import RootComponent from "#build/root-component.mjs";
|
package/dist/app/index.d.ts
CHANGED
|
@@ -4,7 +4,5 @@ export * from './composables';
|
|
|
4
4
|
export * from './components';
|
|
5
5
|
export * from './config';
|
|
6
6
|
export type { PageMeta } from '../pages/runtime';
|
|
7
|
-
export type { MetaObject } from '../head/runtime';
|
|
8
|
-
export { useHead } from '#head';
|
|
9
7
|
export declare const isKdu2 = false;
|
|
10
8
|
export declare const isKdu3 = true;
|
package/dist/app/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ref } from "kdu";
|
|
2
2
|
import { parseURL } from "ufo";
|
|
3
|
-
import { defineDtwoPlugin
|
|
3
|
+
import { defineDtwoPlugin } from "#app/dtwo";
|
|
4
|
+
import { useHead } from "#app/composables/head";
|
|
4
5
|
export default defineDtwoPlugin((dtwoApp) => {
|
|
5
6
|
const externalURLs = ref(/* @__PURE__ */ new Set());
|
|
6
7
|
function generateRules() {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { parseURL } from "ufo";
|
|
2
|
-
import { defineDtwoPlugin
|
|
2
|
+
import { defineDtwoPlugin } from "#app/dtwo";
|
|
3
|
+
import { loadPayload, isPrerendered } from "#app/composables/payload";
|
|
4
|
+
import { useRouter } from "#app/composables/router";
|
|
3
5
|
export default defineDtwoPlugin((dtwoApp) => {
|
|
4
6
|
if (!isPrerendered()) {
|
|
5
7
|
return;
|
|
@@ -1,7 +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,
|
|
4
|
+
import { defineDtwoPlugin, useRuntimeConfig } from "../dtwo.mjs";
|
|
5
|
+
import { clearError, showError } from "../composables/error.mjs";
|
|
6
|
+
import { navigateTo } from "../composables/router.mjs";
|
|
7
|
+
import { useState } from "../composables/state.mjs";
|
|
8
|
+
import { useRequestEvent } from "../composables/ssr.mjs";
|
|
5
9
|
import { callWithDtwo } from "../dtwo.mjs";
|
|
6
10
|
import { globalMiddleware } from "#build/middleware";
|
|
7
11
|
function getRouteFromPath(fullPath) {
|
|
@@ -2,7 +2,10 @@ import { defineComponent, createStaticKNode, computed, h, watch } from "kdu";
|
|
|
2
2
|
import { debounce } from "perfect-debounce";
|
|
3
3
|
import { hash } from "ohash";
|
|
4
4
|
import { appendHeader } from "h3";
|
|
5
|
-
import {
|
|
5
|
+
import { useDtwoApp } from "#app/dtwo";
|
|
6
|
+
import { useRequestEvent } from "#app/composables/ssr";
|
|
7
|
+
import { useAsyncData } from "#app/composables/asyncData";
|
|
8
|
+
import { useHead } from "#app/composables/head";
|
|
6
9
|
const pKey = "_islandPromises";
|
|
7
10
|
export const createServerComponent = (name) => {
|
|
8
11
|
return defineComponent({
|
|
@@ -13,7 +13,7 @@ globalThis.__publicAssetsURL = publicAssetsURL;
|
|
|
13
13
|
const getClientManifest = () => import("#build/dist/server/client.manifest.mjs").then((r) => r.default || r).then((r) => typeof r === "function" ? r() : r);
|
|
14
14
|
const getStaticRenderedHead = () => import("#head-static").then((r) => r.default || r);
|
|
15
15
|
const getServerEntry = () => import("#build/dist/server/server.mjs").then((r) => r.default || r);
|
|
16
|
-
const getSSRStyles = () => import("#build/dist/server/styles.mjs").then((r) => r.default || r);
|
|
16
|
+
const getSSRStyles = lazyCachedFunction(() => import("#build/dist/server/styles.mjs").then((r) => r.default || r));
|
|
17
17
|
const getSSRRenderer = lazyCachedFunction(async () => {
|
|
18
18
|
const manifest = await getClientManifest();
|
|
19
19
|
if (!manifest) {
|
|
@@ -48,7 +48,7 @@ export declare const NoScript: import("kdu").DefineComponent<{
|
|
|
48
48
|
translate: StringConstructor;
|
|
49
49
|
}, () => import("kdu").KNode<import("kdu").RendererNode, import("kdu").RendererElement, {
|
|
50
50
|
[key: string]: any;
|
|
51
|
-
}>[] | null | undefined, unknown, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin,
|
|
51
|
+
}>[] | null | undefined, unknown, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin, {}, string, import("kdu").KNodeProps & import("kdu").AllowedComponentProps & import("kdu").ComponentCustomProps, Readonly<import("kdu").ExtractPropTypes<{
|
|
52
52
|
title: StringConstructor;
|
|
53
53
|
body: BooleanConstructor;
|
|
54
54
|
renderPriority: (StringConstructor | NumberConstructor)[];
|
|
@@ -172,7 +172,7 @@ export declare const Link: import("kdu").DefineComponent<{
|
|
|
172
172
|
translate: StringConstructor;
|
|
173
173
|
}, () => import("kdu").KNode<import("kdu").RendererNode, import("kdu").RendererElement, {
|
|
174
174
|
[key: string]: any;
|
|
175
|
-
}>[] | null | undefined, unknown, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin,
|
|
175
|
+
}>[] | null | undefined, unknown, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin, {}, string, import("kdu").KNodeProps & import("kdu").AllowedComponentProps & import("kdu").ComponentCustomProps, Readonly<import("kdu").ExtractPropTypes<{
|
|
176
176
|
as: StringConstructor;
|
|
177
177
|
crossorigin: PropType<CrossOrigin>;
|
|
178
178
|
disabled: BooleanConstructor;
|
|
@@ -298,7 +298,7 @@ export declare const Base: import("kdu").DefineComponent<{
|
|
|
298
298
|
translate: StringConstructor;
|
|
299
299
|
}, () => import("kdu").KNode<import("kdu").RendererNode, import("kdu").RendererElement, {
|
|
300
300
|
[key: string]: any;
|
|
301
|
-
}>[] | null | undefined, unknown, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin,
|
|
301
|
+
}>[] | null | undefined, unknown, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin, {}, string, import("kdu").KNodeProps & import("kdu").AllowedComponentProps & import("kdu").ComponentCustomProps, Readonly<import("kdu").ExtractPropTypes<{
|
|
302
302
|
href: StringConstructor;
|
|
303
303
|
target: PropType<Target>;
|
|
304
304
|
accesskey: StringConstructor;
|
|
@@ -355,7 +355,7 @@ export declare const Title: import("kdu").DefineComponent<{
|
|
|
355
355
|
[x: string]: any;
|
|
356
356
|
}, () => import("kdu").KNode<import("kdu").RendererNode, import("kdu").RendererElement, {
|
|
357
357
|
[key: string]: any;
|
|
358
|
-
}>[] | null | undefined, {}, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin,
|
|
358
|
+
}>[] | null | undefined, {}, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin, {}, string, import("kdu").KNodeProps & import("kdu").AllowedComponentProps & import("kdu").ComponentCustomProps, Readonly<import("kdu").ExtractPropTypes<{
|
|
359
359
|
[x: string]: any;
|
|
360
360
|
}>>, {
|
|
361
361
|
[x: string]: any;
|
|
@@ -412,7 +412,7 @@ export declare const Meta: import("kdu").DefineComponent<{
|
|
|
412
412
|
translate: StringConstructor;
|
|
413
413
|
}, () => import("kdu").KNode<import("kdu").RendererNode, import("kdu").RendererElement, {
|
|
414
414
|
[key: string]: any;
|
|
415
|
-
}>[] | null | undefined, unknown, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin,
|
|
415
|
+
}>[] | null | undefined, unknown, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin, {}, string, import("kdu").KNodeProps & import("kdu").AllowedComponentProps & import("kdu").ComponentCustomProps, Readonly<import("kdu").ExtractPropTypes<{
|
|
416
416
|
charset: StringConstructor;
|
|
417
417
|
content: StringConstructor;
|
|
418
418
|
httpEquiv: PropType<HTTPEquiv>;
|
|
@@ -525,7 +525,7 @@ export declare const Style: import("kdu").DefineComponent<{
|
|
|
525
525
|
translate: StringConstructor;
|
|
526
526
|
}, () => import("kdu").KNode<import("kdu").RendererNode, import("kdu").RendererElement, {
|
|
527
527
|
[key: string]: any;
|
|
528
|
-
}>[] | null | undefined, unknown, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin,
|
|
528
|
+
}>[] | null | undefined, unknown, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin, {}, string, import("kdu").KNodeProps & import("kdu").AllowedComponentProps & import("kdu").ComponentCustomProps, Readonly<import("kdu").ExtractPropTypes<{
|
|
529
529
|
type: StringConstructor;
|
|
530
530
|
media: StringConstructor;
|
|
531
531
|
nonce: StringConstructor;
|
|
@@ -640,7 +640,7 @@ export declare const Html: import("kdu").DefineComponent<{
|
|
|
640
640
|
translate: StringConstructor;
|
|
641
641
|
}, () => import("kdu").KNode<import("kdu").RendererNode, import("kdu").RendererElement, {
|
|
642
642
|
[key: string]: any;
|
|
643
|
-
}>[] | null | undefined, unknown, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin,
|
|
643
|
+
}>[] | null | undefined, unknown, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin, {}, string, import("kdu").KNodeProps & import("kdu").AllowedComponentProps & import("kdu").ComponentCustomProps, Readonly<import("kdu").ExtractPropTypes<{
|
|
644
644
|
manifest: StringConstructor;
|
|
645
645
|
version: StringConstructor;
|
|
646
646
|
xmlns: StringConstructor;
|
|
@@ -742,7 +742,7 @@ export declare const Body: import("kdu").DefineComponent<{
|
|
|
742
742
|
translate: StringConstructor;
|
|
743
743
|
}, () => import("kdu").KNode<import("kdu").RendererNode, import("kdu").RendererElement, {
|
|
744
744
|
[key: string]: any;
|
|
745
|
-
}>[] | null | undefined, unknown, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin,
|
|
745
|
+
}>[] | null | undefined, unknown, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin, {}, string, import("kdu").KNodeProps & import("kdu").AllowedComponentProps & import("kdu").ComponentCustomProps, Readonly<import("kdu").ExtractPropTypes<{
|
|
746
746
|
renderPriority: (StringConstructor | NumberConstructor)[];
|
|
747
747
|
accesskey: StringConstructor;
|
|
748
748
|
autocapitalize: StringConstructor;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHead, useHead } from "@kduse/head";
|
|
2
2
|
import { renderSSRHead } from "@kdhead/ssr";
|
|
3
|
-
import { defineDtwoPlugin } from "#app";
|
|
3
|
+
import { defineDtwoPlugin } from "#app/dtwo";
|
|
4
4
|
import { appHead } from "#build/dtwo.config.mjs";
|
|
5
5
|
export default defineDtwoPlugin((dtwoApp) => {
|
|
6
6
|
const head = createHead();
|
package/dist/index.mjs
CHANGED
|
@@ -7,6 +7,8 @@ import { encodePath, parseURL, stringifyQuery, parseQuery, joinURL, withTrailing
|
|
|
7
7
|
import { existsSync, readdirSync, statSync, promises } from 'node:fs';
|
|
8
8
|
import { genArrayFromRaw, genSafeVariableName, genImport, genDynamicImport, genObjectFromRawEntries, genString, genExport } from 'knitwork';
|
|
9
9
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
10
|
+
import { filename } from 'pathe/utils';
|
|
11
|
+
import { hash } from 'ohash';
|
|
10
12
|
import { kebabCase, splitByCase, pascalCase, camelCase } from 'scule';
|
|
11
13
|
import { createUnplugin } from '@dtwo/unplugin';
|
|
12
14
|
import { findStaticImports, findExports, parseStaticImport, resolvePath as resolvePath$1 } from 'mlly';
|
|
@@ -14,13 +16,12 @@ import { walk } from 'estree-walker';
|
|
|
14
16
|
import MagicString from 'magic-string';
|
|
15
17
|
import { globby } from 'globby';
|
|
16
18
|
import { hyphenate } from '@kdujs/shared';
|
|
17
|
-
import { parse, walk as walk$1, ELEMENT_NODE } from 'ultrahtml';
|
|
18
19
|
import { defineKdimportPreset, createKdimport, scanDirExports } from 'kdimport';
|
|
19
20
|
import { createRequire } from 'node:module';
|
|
20
21
|
import { createTransformer } from 'unctx/transform';
|
|
21
22
|
import { stripLiteral } from 'strip-literal';
|
|
22
23
|
import { createHole, scanHandlers, writeTypes, build as build$1, prepare, copyPublicAssets, prerender, createDevServer } from 'holepack';
|
|
23
|
-
import
|
|
24
|
+
import { defu } from 'defu';
|
|
24
25
|
import { dynamicEventHandler } from 'h3';
|
|
25
26
|
import { createHeadCore } from 'kdhead';
|
|
26
27
|
import { renderSSRHead } from '@kdhead/ssr';
|
|
@@ -30,7 +31,6 @@ import { debounce } from 'perfect-debounce';
|
|
|
30
31
|
import { resolveSchema, generateMarkdown, generateTypes } from 'untyped';
|
|
31
32
|
import untypedPlugin from 'untyped/babel-plugin';
|
|
32
33
|
import jiti from 'jiti';
|
|
33
|
-
import { hash } from 'ohash';
|
|
34
34
|
|
|
35
35
|
let _distDir = dirname(fileURLToPath(import.meta.url));
|
|
36
36
|
if (_distDir.match(/(chunks|shared)$/)) {
|
|
@@ -195,12 +195,11 @@ function prepareRoutes(routes, parent) {
|
|
|
195
195
|
return routes;
|
|
196
196
|
}
|
|
197
197
|
function normalizeRoutes(routes, metaImports = /* @__PURE__ */ new Set()) {
|
|
198
|
-
const dtwo = useDtwo();
|
|
199
198
|
return {
|
|
200
199
|
imports: metaImports,
|
|
201
200
|
routes: genArrayFromRaw(routes.map((page) => {
|
|
202
201
|
const file = normalize(page.file);
|
|
203
|
-
const metaImportName = genSafeVariableName(
|
|
202
|
+
const metaImportName = genSafeVariableName(filename(file) + hash(file)) + "Meta";
|
|
204
203
|
metaImports.add(genImport(`${file}?macro=true`, [{ name: "default", as: metaImportName }]));
|
|
205
204
|
let aliasCode = `${metaImportName}?.alias || []`;
|
|
206
205
|
if (Array.isArray(page.alias) && page.alias.length) {
|
|
@@ -538,6 +537,9 @@ const pagesModule = defineDtwoModule({
|
|
|
538
537
|
dtwo.options.wite.optimizeDeps = dtwo.options.wite.optimizeDeps || {};
|
|
539
538
|
dtwo.options.wite.optimizeDeps.include = dtwo.options.wite.optimizeDeps.include || [];
|
|
540
539
|
dtwo.options.wite.optimizeDeps.include.push("kdu-router");
|
|
540
|
+
dtwo.options.wite.resolve = dtwo.options.wite.resolve || {};
|
|
541
|
+
dtwo.options.wite.resolve.dedupe = dtwo.options.wite.resolve.dedupe || [];
|
|
542
|
+
dtwo.options.wite.resolve.dedupe.push("kdu-router");
|
|
541
543
|
addTemplate({
|
|
542
544
|
filename: "router.options.mjs",
|
|
543
545
|
getContents: async () => {
|
|
@@ -635,7 +637,7 @@ const componentsPluginTemplate = {
|
|
|
635
637
|
getContents({ options }) {
|
|
636
638
|
const globalComponents = options.getComponents().filter((c) => c.global === true);
|
|
637
639
|
return `import { defineAsyncComponent } from 'kdu'
|
|
638
|
-
import { defineDtwoPlugin } from '#app'
|
|
640
|
+
import { defineDtwoPlugin } from '#app/dtwo'
|
|
639
641
|
|
|
640
642
|
const components = ${genObjectFromRawEntries(globalComponents.map((c) => {
|
|
641
643
|
const exp = c.export === "default" ? "c.default || c" : `c['${c.export}']`;
|
|
@@ -897,44 +899,99 @@ function findComponent(components, name, mode) {
|
|
|
897
899
|
return otherModeComponent;
|
|
898
900
|
}
|
|
899
901
|
|
|
900
|
-
const
|
|
902
|
+
const SSR_RENDER_RE = /ssrRenderComponent/;
|
|
903
|
+
const PLACEHOLDER_EXACT_RE = /^(fallback|placeholder)$/;
|
|
901
904
|
const TreeShakeTemplatePlugin = createUnplugin((options) => {
|
|
902
905
|
const regexpMap = /* @__PURE__ */ new WeakMap();
|
|
903
906
|
return {
|
|
904
907
|
name: "dtwo:tree-shake-template",
|
|
905
|
-
enforce: "
|
|
908
|
+
enforce: "post",
|
|
906
909
|
transformInclude(id) {
|
|
907
910
|
const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href));
|
|
908
911
|
return pathname.endsWith(".kdu");
|
|
909
912
|
},
|
|
910
|
-
|
|
911
|
-
const template = code.match(/<template>([\s\S]*)<\/template>/);
|
|
912
|
-
if (!template) {
|
|
913
|
-
return;
|
|
914
|
-
}
|
|
913
|
+
transform(code, id) {
|
|
915
914
|
const components = options.getComponents();
|
|
916
915
|
if (!regexpMap.has(components)) {
|
|
917
|
-
const
|
|
918
|
-
|
|
919
|
-
regexpMap.set(components, [new RegExp(`(${tags.join("|")})`, "g"), clientOnlyComponents2]);
|
|
916
|
+
const clientOnlyComponents = components.filter((c) => c.mode === "client" && !components.some((other) => other.mode !== "client" && other.pascalName === c.pascalName && other.filePath !== resolve(distDir, "app/components/server-placeholder"))).flatMap((c) => [c.pascalName, c.kebabName.replaceAll("-", "_")]).concat(["ClientOnly", "client_only"]);
|
|
917
|
+
regexpMap.set(components, [new RegExp(`(${clientOnlyComponents.join("|")})`), new RegExp(`^(${clientOnlyComponents.map((c) => `(?:(?:_unref\\()?(?:_component_)?(?:Lazy|lazy_)?${c}\\)?)`).join("|")})$`), clientOnlyComponents]);
|
|
920
918
|
}
|
|
921
|
-
const
|
|
919
|
+
const s = new MagicString(code);
|
|
920
|
+
const importDeclarations = [];
|
|
921
|
+
const [COMPONENTS_RE, COMPONENTS_IDENTIFIERS_RE] = regexpMap.get(components);
|
|
922
922
|
if (!COMPONENTS_RE.test(code)) {
|
|
923
923
|
return;
|
|
924
924
|
}
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
925
|
+
walk(this.parse(code, { sourceType: "module", ecmaVersion: "latest" }), {
|
|
926
|
+
enter: (_node) => {
|
|
927
|
+
const node = _node;
|
|
928
|
+
if (node.type === "ImportDeclaration") {
|
|
929
|
+
importDeclarations.push(node);
|
|
930
|
+
} else if (node.type === "CallExpression" && node.callee.type === "Identifier" && SSR_RENDER_RE.test(node.callee.name)) {
|
|
931
|
+
const [componentCall, _, children] = node.arguments;
|
|
932
|
+
if (componentCall.type === "Identifier" || componentCall.type === "MemberExpression" || componentCall.type === "CallExpression") {
|
|
933
|
+
const componentName = getComponentName(node);
|
|
934
|
+
const isClientComponent = COMPONENTS_IDENTIFIERS_RE.test(componentName);
|
|
935
|
+
const isClientOnlyComponent = /^(?:_unref\()?(?:_component_)?(?:Lazy|lazy_)?(?:client_only|ClientOnly\)?)$/.test(componentName);
|
|
936
|
+
if (isClientComponent && children?.type === "ObjectExpression") {
|
|
937
|
+
const slotsToRemove = isClientOnlyComponent ? children.properties.filter((prop) => prop.type === "Property" && prop.key.type === "Identifier" && !PLACEHOLDER_EXACT_RE.test(prop.key.name)) : children.properties;
|
|
938
|
+
for (const slot of slotsToRemove) {
|
|
939
|
+
const componentsSet = /* @__PURE__ */ new Set();
|
|
940
|
+
s.remove(slot.start, slot.end + 1);
|
|
941
|
+
const removedCode = `({${code.slice(slot.start, slot.end + 1)}})`;
|
|
942
|
+
const currentCode = s.toString();
|
|
943
|
+
walk(this.parse(removedCode, { sourceType: "module", ecmaVersion: "latest" }), {
|
|
944
|
+
enter: (_node2) => {
|
|
945
|
+
const node2 = _node2;
|
|
946
|
+
if (node2.type === "CallExpression" && node2.callee.type === "Identifier" && SSR_RENDER_RE.test(node2.callee.name)) {
|
|
947
|
+
const componentNode = node2.arguments[0];
|
|
948
|
+
if (componentNode.type === "CallExpression") {
|
|
949
|
+
const identifier = componentNode.arguments[0];
|
|
950
|
+
if (!isRenderedInCode(currentCode, removedCode.slice(componentNode.start, componentNode.end))) {
|
|
951
|
+
componentsSet.add(identifier.name);
|
|
952
|
+
}
|
|
953
|
+
} else if (componentNode.type === "Identifier" && !isRenderedInCode(currentCode, componentNode.name)) {
|
|
954
|
+
componentsSet.add(componentNode.name);
|
|
955
|
+
} else if (componentNode.type === "MemberExpression") {
|
|
956
|
+
const { start, end } = componentNode;
|
|
957
|
+
if (!isRenderedInCode(currentCode, removedCode.slice(start, end))) {
|
|
958
|
+
componentsSet.add(componentNode.property.value);
|
|
959
|
+
walk(this.parse(code, { sourceType: "module", ecmaVersion: "latest" }), {
|
|
960
|
+
enter: (node3) => {
|
|
961
|
+
removeFromSetupReturnStatement(s, node3, componentNode.property.value);
|
|
962
|
+
}
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
const componentsToRemove = [...componentsSet];
|
|
970
|
+
for (const componentName2 of componentsToRemove) {
|
|
971
|
+
let removed = false;
|
|
972
|
+
const VAR_RE = new RegExp(`(?:const|let|var) ${componentName2} = ([^;\\n]*);?`);
|
|
973
|
+
s.replace(VAR_RE, () => {
|
|
974
|
+
removed = true;
|
|
975
|
+
return "";
|
|
976
|
+
});
|
|
977
|
+
if (!removed) {
|
|
978
|
+
const declaration = findImportDeclaration(importDeclarations, componentName2);
|
|
979
|
+
if (declaration) {
|
|
980
|
+
if (declaration.specifiers.length > 1) {
|
|
981
|
+
const componentSpecifier = declaration.specifiers.find((s2) => s2.local.name === componentName2);
|
|
982
|
+
if (componentSpecifier) {
|
|
983
|
+
s.remove(componentSpecifier.start, componentSpecifier.end + 1);
|
|
984
|
+
}
|
|
985
|
+
} else {
|
|
986
|
+
s.remove(declaration.start, declaration.end);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}
|
|
938
995
|
}
|
|
939
996
|
});
|
|
940
997
|
if (s.hasChanged()) {
|
|
@@ -946,6 +1003,46 @@ const TreeShakeTemplatePlugin = createUnplugin((options) => {
|
|
|
946
1003
|
}
|
|
947
1004
|
};
|
|
948
1005
|
});
|
|
1006
|
+
function findImportDeclaration(declarations, importName) {
|
|
1007
|
+
const declaration = declarations.find((d) => {
|
|
1008
|
+
const specifier = d.specifiers.find((s) => s.local.name === importName);
|
|
1009
|
+
if (specifier) {
|
|
1010
|
+
return true;
|
|
1011
|
+
}
|
|
1012
|
+
return false;
|
|
1013
|
+
});
|
|
1014
|
+
return declaration;
|
|
1015
|
+
}
|
|
1016
|
+
function isRenderedInCode(code, name) {
|
|
1017
|
+
return new RegExp(`ssrRenderComponent\\(${escapeRE(name)}`).test(code);
|
|
1018
|
+
}
|
|
1019
|
+
function getComponentName(ssrRenderNode) {
|
|
1020
|
+
const componentCall = ssrRenderNode.arguments[0];
|
|
1021
|
+
if (componentCall.type === "Identifier") {
|
|
1022
|
+
return componentCall.name;
|
|
1023
|
+
} else if (componentCall.type === "MemberExpression") {
|
|
1024
|
+
return componentCall.property.value;
|
|
1025
|
+
}
|
|
1026
|
+
return componentCall.arguments[0].name;
|
|
1027
|
+
}
|
|
1028
|
+
function removeFromSetupReturnStatement(s, node, name) {
|
|
1029
|
+
if (node.type === "Property" && node.key.type === "Identifier" && node.key.name === "setup" && node.value.type === "FunctionExpression") {
|
|
1030
|
+
const returnStatement = node.value.body.body.find((n) => n.type === "ReturnStatement");
|
|
1031
|
+
if (returnStatement?.argument?.type === "Identifier") {
|
|
1032
|
+
const returnIdentifier = returnStatement.argument.name;
|
|
1033
|
+
const returnedDeclaration = node.value.body.body.find((n) => n.type === "VariableDeclaration" && n.declarations[0].id.name === returnIdentifier);
|
|
1034
|
+
const componentProperty = returnedDeclaration?.declarations[0].init?.properties.find((p) => p.key.name === name);
|
|
1035
|
+
if (componentProperty) {
|
|
1036
|
+
s.remove(componentProperty.start, componentProperty.end + 1);
|
|
1037
|
+
}
|
|
1038
|
+
} else if (returnStatement?.argument?.type === "ObjectExpression") {
|
|
1039
|
+
const componentProperty = returnStatement.argument?.properties.find((p) => p.key.name === name);
|
|
1040
|
+
if (componentProperty) {
|
|
1041
|
+
s.remove(componentProperty.start, componentProperty.end + 1);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
949
1046
|
|
|
950
1047
|
const isPureObjectOrString = (val) => !Array.isArray(val) && typeof val === "object" || typeof val === "string";
|
|
951
1048
|
const isDirectory = (p) => {
|
|
@@ -1101,35 +1198,35 @@ const componentsModule = defineDtwoModule({
|
|
|
1101
1198
|
dtwo.hook("wite:extendConfig", (config, { isClient, isServer }) => {
|
|
1102
1199
|
const mode = isClient ? "client" : "server";
|
|
1103
1200
|
config.plugins = config.plugins || [];
|
|
1104
|
-
config.plugins.push(loaderPlugin.wite({
|
|
1105
|
-
sourcemap: dtwo.options.sourcemap[mode],
|
|
1106
|
-
getComponents,
|
|
1107
|
-
mode,
|
|
1108
|
-
experimentalComponentIslands: dtwo.options.experimental.componentIslands
|
|
1109
|
-
}));
|
|
1110
1201
|
if (dtwo.options.experimental.treeshakeClientOnly && isServer) {
|
|
1111
1202
|
config.plugins.push(TreeShakeTemplatePlugin.wite({
|
|
1112
1203
|
sourcemap: dtwo.options.sourcemap[mode],
|
|
1113
1204
|
getComponents
|
|
1114
1205
|
}));
|
|
1115
1206
|
}
|
|
1207
|
+
config.plugins.push(loaderPlugin.wite({
|
|
1208
|
+
sourcemap: dtwo.options.sourcemap[mode],
|
|
1209
|
+
getComponents,
|
|
1210
|
+
mode,
|
|
1211
|
+
experimentalComponentIslands: dtwo.options.experimental.componentIslands
|
|
1212
|
+
}));
|
|
1116
1213
|
});
|
|
1117
1214
|
dtwo.hook("webpack:config", (configs) => {
|
|
1118
1215
|
configs.forEach((config) => {
|
|
1119
1216
|
const mode = config.name === "client" ? "client" : "server";
|
|
1120
1217
|
config.plugins = config.plugins || [];
|
|
1121
|
-
config.plugins.push(loaderPlugin.webpack({
|
|
1122
|
-
sourcemap: dtwo.options.sourcemap[mode],
|
|
1123
|
-
getComponents,
|
|
1124
|
-
mode,
|
|
1125
|
-
experimentalComponentIslands: dtwo.options.experimental.componentIslands
|
|
1126
|
-
}));
|
|
1127
1218
|
if (dtwo.options.experimental.treeshakeClientOnly && mode === "server") {
|
|
1128
1219
|
config.plugins.push(TreeShakeTemplatePlugin.webpack({
|
|
1129
1220
|
sourcemap: dtwo.options.sourcemap[mode],
|
|
1130
1221
|
getComponents
|
|
1131
1222
|
}));
|
|
1132
1223
|
}
|
|
1224
|
+
config.plugins.push(loaderPlugin.webpack({
|
|
1225
|
+
sourcemap: dtwo.options.sourcemap[mode],
|
|
1226
|
+
getComponents,
|
|
1227
|
+
mode,
|
|
1228
|
+
experimentalComponentIslands: dtwo.options.experimental.componentIslands
|
|
1229
|
+
}));
|
|
1133
1230
|
});
|
|
1134
1231
|
});
|
|
1135
1232
|
}
|
|
@@ -1173,15 +1270,6 @@ const TransformPlugin = createUnplugin(({ ctx, options, sourcemap }) => {
|
|
|
1173
1270
|
});
|
|
1174
1271
|
|
|
1175
1272
|
const commonPresets = [
|
|
1176
|
-
// #head
|
|
1177
|
-
defineKdimportPreset({
|
|
1178
|
-
from: "#head",
|
|
1179
|
-
imports: [
|
|
1180
|
-
"useHead",
|
|
1181
|
-
"useSeoMeta",
|
|
1182
|
-
"useServerSeoMeta"
|
|
1183
|
-
]
|
|
1184
|
-
}),
|
|
1185
1273
|
// kdu-demi (mocked)
|
|
1186
1274
|
defineKdimportPreset({
|
|
1187
1275
|
from: "kdu-demi",
|
|
@@ -1194,6 +1282,9 @@ const commonPresets = [
|
|
|
1194
1282
|
const appPreset = defineKdimportPreset({
|
|
1195
1283
|
from: "#app",
|
|
1196
1284
|
imports: [
|
|
1285
|
+
"useHead",
|
|
1286
|
+
"useSeoMeta",
|
|
1287
|
+
"useServerSeoMeta",
|
|
1197
1288
|
"useAsyncData",
|
|
1198
1289
|
"useLazyAsyncData",
|
|
1199
1290
|
"useDtwoData",
|
|
@@ -1209,6 +1300,7 @@ const appPreset = defineKdimportPreset({
|
|
|
1209
1300
|
"useCookie",
|
|
1210
1301
|
"useRequestHeaders",
|
|
1211
1302
|
"useRequestEvent",
|
|
1303
|
+
"useRequestFetch",
|
|
1212
1304
|
"setResponseStatus",
|
|
1213
1305
|
"setPageLayout",
|
|
1214
1306
|
"onDtwoReady",
|
|
@@ -1309,11 +1401,25 @@ const kduPreset = defineKdimportPreset({
|
|
|
1309
1401
|
"useTransitionState"
|
|
1310
1402
|
]
|
|
1311
1403
|
});
|
|
1404
|
+
const kduTypesPreset = defineKdimportPreset({
|
|
1405
|
+
from: "kdu",
|
|
1406
|
+
type: true,
|
|
1407
|
+
imports: [
|
|
1408
|
+
"Component",
|
|
1409
|
+
"ComponentPublicInstance",
|
|
1410
|
+
"ComputedRef",
|
|
1411
|
+
"InjectionKey",
|
|
1412
|
+
"PropType",
|
|
1413
|
+
"Ref",
|
|
1414
|
+
"KNode"
|
|
1415
|
+
]
|
|
1416
|
+
});
|
|
1312
1417
|
const defaultPresets = [
|
|
1313
1418
|
...commonPresets,
|
|
1314
1419
|
appPreset,
|
|
1315
1420
|
routerPreset,
|
|
1316
|
-
kduPreset
|
|
1421
|
+
kduPreset,
|
|
1422
|
+
kduTypesPreset
|
|
1317
1423
|
];
|
|
1318
1424
|
|
|
1319
1425
|
const importsModule = defineDtwoModule({
|
|
@@ -1427,7 +1533,7 @@ function addDeclarationTemplates(ctx, options) {
|
|
|
1427
1533
|
});
|
|
1428
1534
|
}
|
|
1429
1535
|
|
|
1430
|
-
const version = "3.
|
|
1536
|
+
const version = "3.2.0";
|
|
1431
1537
|
|
|
1432
1538
|
const _require = createRequire(import.meta.url);
|
|
1433
1539
|
const kduAppPatterns = (dtwo) => [
|
|
@@ -1597,6 +1703,11 @@ const addModuleTranspiles = (opts = {}) => {
|
|
|
1597
1703
|
|
|
1598
1704
|
async function initHole(dtwo) {
|
|
1599
1705
|
const _holeConfig = dtwo.options.hole || {};
|
|
1706
|
+
const excludePaths = dtwo.options._layers.flatMap((l) => [
|
|
1707
|
+
l.cwd.match(/(?<=\/)node_modules\/(.+)$/)?.[1],
|
|
1708
|
+
l.cwd.match(/\.pnpm\/.+\/node_modules\/(.+)$/)?.[1]
|
|
1709
|
+
]).filter((dir) => Boolean(dir)).map((dir) => escapeRE(dir));
|
|
1710
|
+
const excludePattern = excludePaths.length ? [new RegExp(`node_modules\\/(?!${excludePaths.join("|")})`)] : [/node_modules/];
|
|
1600
1711
|
const holeConfig = defu(_holeConfig, {
|
|
1601
1712
|
debug: dtwo.options.debug,
|
|
1602
1713
|
rootDir: dtwo.options.rootDir,
|
|
@@ -1616,14 +1727,11 @@ async function initHole(dtwo) {
|
|
|
1616
1727
|
name: "publicAssetsURL",
|
|
1617
1728
|
from: resolve(distDir, "core/runtime/hole/paths")
|
|
1618
1729
|
}
|
|
1619
|
-
]
|
|
1730
|
+
],
|
|
1731
|
+
exclude: [...excludePattern, /[\\/]\.git[\\/]/]
|
|
1620
1732
|
},
|
|
1621
1733
|
esbuild: {
|
|
1622
|
-
options: {
|
|
1623
|
-
exclude: [
|
|
1624
|
-
new RegExp(`node_modules\\/(?!${dtwo.options._layers.map((l) => l.cwd.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean).map((dir) => escapeRE(dir)).join("|")})`)
|
|
1625
|
-
]
|
|
1626
|
-
}
|
|
1734
|
+
options: { exclude: excludePattern }
|
|
1627
1735
|
},
|
|
1628
1736
|
analyze: dtwo.options.build.analyze && {
|
|
1629
1737
|
template: "treemap",
|
|
@@ -1654,7 +1762,11 @@ async function initHole(dtwo) {
|
|
|
1654
1762
|
generateTsConfig: false
|
|
1655
1763
|
},
|
|
1656
1764
|
publicAssets: [
|
|
1657
|
-
{ dir: resolve(dtwo.options.buildDir, "dist/client") }
|
|
1765
|
+
dtwo.options.dev ? { dir: resolve(dtwo.options.buildDir, "dist/client") } : {
|
|
1766
|
+
dir: join(dtwo.options.buildDir, "dist/client", dtwo.options.app.buildAssetsDir),
|
|
1767
|
+
maxAge: 30 * 24 * 60 * 60,
|
|
1768
|
+
baseURL: dtwo.options.app.buildAssetsDir
|
|
1769
|
+
},
|
|
1658
1770
|
...dtwo.options._layers.map((layer) => join(layer.config.srcDir, layer.config.dir?.public || "public")).filter((dir) => existsSync(dir)).map((dir) => ({ dir }))
|
|
1659
1771
|
],
|
|
1660
1772
|
prerender: {
|
|
@@ -1714,9 +1826,15 @@ async function initHole(dtwo) {
|
|
|
1714
1826
|
holeConfig.virtual["#head-static"] = `export default ${JSON.stringify(headChunk)}`;
|
|
1715
1827
|
if (!dtwo.options.ssr) {
|
|
1716
1828
|
holeConfig.virtual["#build/dist/server/server.mjs"] = "export default () => {}";
|
|
1829
|
+
if (process.platform === "win32") {
|
|
1830
|
+
holeConfig.virtual["#build/dist/server/server.mjs".replace(/\//g, "\\")] = "export default () => {}";
|
|
1831
|
+
}
|
|
1717
1832
|
}
|
|
1718
1833
|
if (!dtwo.options.experimental.inlineSSRStyles) {
|
|
1719
1834
|
holeConfig.virtual["#build/dist/server/styles.mjs"] = "export default {}";
|
|
1835
|
+
if (process.platform === "win32") {
|
|
1836
|
+
holeConfig.virtual["#build/dist/server/styles.mjs".replace(/\//g, "\\")] = "export default {}";
|
|
1837
|
+
}
|
|
1720
1838
|
}
|
|
1721
1839
|
holeConfig.rollupConfig.plugins = await holeConfig.rollupConfig.plugins || [];
|
|
1722
1840
|
holeConfig.rollupConfig.plugins = Array.isArray(holeConfig.rollupConfig.plugins) ? holeConfig.rollupConfig.plugins : [holeConfig.rollupConfig.plugins];
|
|
@@ -1867,7 +1985,7 @@ const schemaModule = defineDtwoModule({
|
|
|
1867
1985
|
const schemas = await Promise.all(
|
|
1868
1986
|
schemaDefs.map((schemaDef) => resolveSchema(schemaDef))
|
|
1869
1987
|
);
|
|
1870
|
-
const schema2 = defu
|
|
1988
|
+
const schema2 = defu(...schemas);
|
|
1871
1989
|
await dtwo.hooks.callHook("schema:resolved", schema2);
|
|
1872
1990
|
return schema2;
|
|
1873
1991
|
}
|
|
@@ -2113,7 +2231,7 @@ const clientPluginTemplate = {
|
|
|
2113
2231
|
const imports = [];
|
|
2114
2232
|
for (const plugin of clientPlugins) {
|
|
2115
2233
|
const path = relative(ctx.dtwo.options.rootDir, plugin.src);
|
|
2116
|
-
const variable = genSafeVariableName(
|
|
2234
|
+
const variable = genSafeVariableName(filename(plugin.src)).replace(/_(45|46|47)/g, "_") + "_" + hash(path);
|
|
2117
2235
|
exports.push(variable);
|
|
2118
2236
|
imports.push(genImport(plugin.src, variable));
|
|
2119
2237
|
}
|
|
@@ -2131,7 +2249,7 @@ const serverPluginTemplate = {
|
|
|
2131
2249
|
const imports = [];
|
|
2132
2250
|
for (const plugin of serverPlugins) {
|
|
2133
2251
|
const path = relative(ctx.dtwo.options.rootDir, plugin.src);
|
|
2134
|
-
const variable = genSafeVariableName(path).replace(/_(45|46|47)/g, "_") + "_" + hash(path);
|
|
2252
|
+
const variable = genSafeVariableName(filename(path)).replace(/_(45|46|47)/g, "_") + "_" + hash(path);
|
|
2135
2253
|
exports.push(variable);
|
|
2136
2254
|
imports.push(genImport(plugin.src, variable));
|
|
2137
2255
|
}
|
|
@@ -2,7 +2,7 @@ import { computed, defineComponent, h, provide, reactive, onMounted, nextTick, S
|
|
|
2
2
|
import { RouterView } from "kdu-router";
|
|
3
3
|
import { defu } from "defu";
|
|
4
4
|
import { generateRouteKey, wrapInKeepAlive } from "./utils.mjs";
|
|
5
|
-
import { useDtwoApp } from "#app";
|
|
5
|
+
import { useDtwoApp } from "#app/dtwo";
|
|
6
6
|
import { _wrapIf } from "#app/components/utils";
|
|
7
7
|
import { appPageTransition as defaultPageTransition, appKeepalive as defaultKeepaliveConfig } from "#build/dtwo.config.mjs";
|
|
8
8
|
export default defineComponent({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { hasProtocol } from "ufo";
|
|
2
|
-
import { defineDtwoPlugin, useDtwoApp
|
|
2
|
+
import { defineDtwoPlugin, useDtwoApp } from "#app/dtwo";
|
|
3
|
+
import { useRouter } from "#app/composables/router";
|
|
3
4
|
import layouts from "#build/layouts";
|
|
4
5
|
import { namedMiddleware } from "#build/middleware";
|
|
5
6
|
export default defineDtwoPlugin(() => {
|
|
@@ -7,7 +7,11 @@ import {
|
|
|
7
7
|
} from "kdu-router";
|
|
8
8
|
import { createError } from "h3";
|
|
9
9
|
import { withoutBase, isEqual } from "ufo";
|
|
10
|
-
import { callWithDtwo, defineDtwoPlugin, useRuntimeConfig
|
|
10
|
+
import { callWithDtwo, defineDtwoPlugin, useRuntimeConfig } from "#app/dtwo";
|
|
11
|
+
import { showError, clearError, useError } from "#app/composables/error";
|
|
12
|
+
import { useRequestEvent } from "#app/composables/ssr";
|
|
13
|
+
import { useState } from "#app/composables/state";
|
|
14
|
+
import { navigateTo } from "#app/composables/router";
|
|
11
15
|
import _routes from "#build/routes";
|
|
12
16
|
import routerOptions from "#build/router.options";
|
|
13
17
|
import { globalMiddleware, namedMiddleware } from "#build/middleware";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dtwo",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"repository": "d2js/dtwo",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
"exports": {
|
|
14
14
|
".": "./dist/index.mjs",
|
|
15
15
|
"./config": {
|
|
16
|
+
"types": "./config.d.ts",
|
|
16
17
|
"import": "./config.mjs",
|
|
17
|
-
"require": "./config.cjs"
|
|
18
|
-
"types": "./config.d.ts"
|
|
18
|
+
"require": "./config.cjs"
|
|
19
19
|
},
|
|
20
20
|
"./app": "./dist/app/index.mjs",
|
|
21
21
|
"./package.json": "./package.json"
|
|
@@ -34,34 +34,34 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@d2js/devalue": "2.0.2",
|
|
37
|
-
"@dtwo/kit": "3.
|
|
38
|
-
"@dtwo/schema": "3.
|
|
37
|
+
"@dtwo/kit": "3.2.0",
|
|
38
|
+
"@dtwo/schema": "3.2.0",
|
|
39
39
|
"@dtwo/telemetry": "2.1.8",
|
|
40
|
-
"@dtwo/ui-templates": "1.1.
|
|
40
|
+
"@dtwo/ui-templates": "1.1.1",
|
|
41
41
|
"@dtwo/unplugin": "1.0.0",
|
|
42
|
-
"@dtwo/wite-builder": "3.
|
|
43
|
-
"@kdhead/ssr": "1.0.
|
|
44
|
-
"@kdujs/reactivity": "3.2.
|
|
45
|
-
"@kdujs/shared": "3.2.
|
|
46
|
-
"@kduse/head": "1.0.
|
|
42
|
+
"@dtwo/wite-builder": "3.2.0",
|
|
43
|
+
"@kdhead/ssr": "1.0.21",
|
|
44
|
+
"@kdujs/reactivity": "3.2.48",
|
|
45
|
+
"@kdujs/shared": "3.2.48",
|
|
46
|
+
"@kduse/head": "1.0.25",
|
|
47
47
|
"chokidar": "3.5.3",
|
|
48
48
|
"cookie-es": "0.5.0",
|
|
49
49
|
"defu": "6.1.2",
|
|
50
50
|
"destr": "1.2.2",
|
|
51
|
-
"dtwc": "3.
|
|
51
|
+
"dtwc": "3.2.0",
|
|
52
52
|
"escape-string-regexp": "5.0.0",
|
|
53
53
|
"estree-walker": "3.0.3",
|
|
54
54
|
"fs-extra": "11.1.0",
|
|
55
55
|
"globby": "13.1.3",
|
|
56
|
-
"h3": "1.0
|
|
56
|
+
"h3": "1.4.0",
|
|
57
57
|
"hash-sum": "2.0.0",
|
|
58
|
-
"holepack": "2.
|
|
58
|
+
"holepack": "2.2.1",
|
|
59
59
|
"hookable": "5.4.2",
|
|
60
|
-
"jiti": "1.
|
|
61
|
-
"kdhead": "1.0.
|
|
62
|
-
"kdimport": "2.
|
|
63
|
-
"kdu": "3.2.
|
|
64
|
-
"kdu-bundle-renderer": "1.0.
|
|
60
|
+
"jiti": "1.17.0",
|
|
61
|
+
"kdhead": "1.0.21",
|
|
62
|
+
"kdimport": "2.2.4",
|
|
63
|
+
"kdu": "3.2.48",
|
|
64
|
+
"kdu-bundle-renderer": "1.0.1",
|
|
65
65
|
"kdu-devtools-stub": "0.1.0",
|
|
66
66
|
"kdu-router": "4.1.6",
|
|
67
67
|
"knitwork": "1.0.0",
|
|
@@ -72,11 +72,10 @@
|
|
|
72
72
|
"pathe": "1.1.0",
|
|
73
73
|
"perfect-debounce": "0.1.3",
|
|
74
74
|
"scule": "1.0.0",
|
|
75
|
-
"strip-literal": "1.0.
|
|
75
|
+
"strip-literal": "1.0.1",
|
|
76
76
|
"ufo": "1.0.1",
|
|
77
|
-
"ultrahtml": "1.2.0",
|
|
78
77
|
"unctx": "2.1.1",
|
|
79
|
-
"unenv": "1.
|
|
78
|
+
"unenv": "1.1.1",
|
|
80
79
|
"untyped": "1.2.2"
|
|
81
80
|
},
|
|
82
81
|
"devDependencies": {
|