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.
- package/LICENSE +21 -21
- package/app.d.ts +1 -1
- package/bin/dtwo.mjs +2 -2
- package/config.cjs +7 -7
- package/config.d.ts +2 -2
- package/config.mjs +5 -5
- package/dist/app/components/client-only.mjs +75 -75
- package/dist/app/components/dev-only.mjs +11 -11
- package/dist/app/components/dtwo-error-boundary.mjs +1 -1
- package/dist/app/components/dtwo-error-page.kdu +46 -46
- package/dist/app/components/dtwo-island.mjs +3 -1
- package/dist/app/components/dtwo-loading-indicator.mjs +5 -3
- package/dist/app/components/dtwo-root.kdu +5 -3
- 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/error.d.ts +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 +6 -6
- package/dist/app/composables/preload.mjs +1 -1
- package/dist/app/composables/router.mjs +1 -1
- package/dist/app/composables/ssr.d.ts +1 -0
- package/dist/app/composables/ssr.mjs +7 -0
- package/dist/app/config.d.ts +1 -1
- package/dist/app/dtwo.d.ts +5 -2
- package/dist/app/dtwo.mjs +5 -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/chunk-reload.client.d.ts +2 -0
- package/dist/app/plugins/chunk-reload.client.mjs +26 -0
- 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 -2
- package/dist/app/types/augments.d.ts +28 -28
- package/dist/components/runtime/server-component.mjs +4 -1
- package/dist/core/runtime/hole/renderer.mjs +6 -2
- package/dist/head/runtime/composables.d.ts +1 -1
- package/dist/head/runtime/composables.mjs +1 -1
- package/dist/head/runtime/index.d.ts +1 -1
- package/dist/head/runtime/lib/kduse-head.plugin.mjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +9173 -271
- package/dist/pages/runtime/app.kdu +5 -5
- 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 +6 -2
- package/dist/pages/runtime/router.options.mjs +1 -1
- package/dist/pages/runtime/validate.mjs +23 -2
- package/package.json +31 -27
- package/schema.d.ts +1 -0
- package/schema.mjs +1 -0
- package/types.d.ts +1 -1
- package/README.md +0 -7
package/dist/app/dtwo.d.ts
CHANGED
|
@@ -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:
|
|
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) {
|
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
|
@@ -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,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,8 +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 {
|
|
5
|
-
import {
|
|
4
|
+
import { callWithDtwo, 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";
|
|
6
9
|
import { globalMiddleware } from "#build/middleware";
|
|
7
10
|
function getRouteFromPath(fullPath) {
|
|
8
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
|
+
}
|
|
@@ -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({
|
|
@@ -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,
|
|
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.
|
|
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,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.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>;
|