vike 0.4.144-commit-6aef8a6 → 0.4.144-commit-7f5e99a
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/cjs/__internal/index.js +6 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +2 -2
- package/dist/cjs/node/plugin/plugins/commonConfig.js +0 -3
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +29 -42
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +14 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/cjs/node/plugin/plugins/previewConfig.js +11 -2
- package/dist/cjs/node/prerender/runPrerender.js +16 -17
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +20 -6
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
- package/dist/cjs/node/runtime/renderPage.js +2 -2
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/node/shared/getClientEntryFilePath.js +2 -2
- package/dist/cjs/shared/addUrlComputedProps.js +24 -12
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +4 -6
- package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
- package/dist/cjs/shared/hooks/getHook.js +1 -1
- package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +43 -0
- package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +44 -0
- package/dist/cjs/shared/page-configs/helpers.js +33 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +6 -8
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +2 -2
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +11 -13
- package/dist/cjs/shared/route/index.js +3 -3
- package/dist/cjs/shared/route/loadPageRoutes.js +11 -10
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -1
- package/dist/cjs/shared/utils.js +1 -1
- package/dist/cjs/utils/{hasPropertyGetter.js → isPropertyGetter.js} +3 -3
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/__internal/index.d.ts +6 -3
- package/dist/esm/__internal/index.js +8 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.js +3 -3
- package/dist/esm/client/client-routing-runtime/entry.js +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/getPageContext.js +4 -7
- package/dist/esm/client/client-routing-runtime/getPageId.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/getPageId.js +4 -7
- package/dist/esm/client/client-routing-runtime/history.d.ts +3 -1
- package/dist/esm/client/client-routing-runtime/history.js +26 -8
- package/dist/esm/client/client-routing-runtime/installClientRouter.d.ts +21 -0
- package/dist/esm/client/client-routing-runtime/{useClientRouter.js → installClientRouter.js} +248 -242
- package/dist/esm/client/client-routing-runtime/isClientSideRoutable.d.ts +8 -0
- package/dist/esm/client/client-routing-runtime/isClientSideRoutable.js +15 -0
- package/dist/esm/client/client-routing-runtime/navigate.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/navigate.js +10 -8
- package/dist/esm/client/client-routing-runtime/prefetch.js +12 -5
- package/dist/esm/client/client-routing-runtime/skipLink.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/skipLink.js +1 -2
- package/dist/esm/client/shared/executeOnRenderClientHook.js +6 -5
- package/dist/esm/client/shared/getPageContextProxyForUser.js +13 -7
- package/dist/esm/node/plugin/plugins/buildConfig.js +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +0 -3
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +29 -42
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +15 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/esm/node/plugin/plugins/previewConfig.js +11 -2
- package/dist/esm/node/prerender/runPrerender.js +11 -12
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +21 -7
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
- package/dist/esm/node/runtime/renderPage.js +2 -2
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/node/shared/getClientEntryFilePath.js +1 -1
- package/dist/esm/shared/addUrlComputedProps.d.ts +1 -0
- package/dist/esm/shared/addUrlComputedProps.js +25 -13
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +2 -4
- package/dist/esm/shared/getPageFiles/getExports.js +2 -2
- package/dist/esm/shared/hooks/getHook.js +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +4 -12
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +7 -0
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +37 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.d.ts +14 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.js +38 -0
- package/dist/esm/shared/page-configs/helpers.d.ts +13 -0
- package/dist/esm/shared/page-configs/helpers.js +27 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +6 -8
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +2 -2
- package/dist/esm/shared/route/executeOnBeforeRouteHook.d.ts +1 -1
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +11 -13
- package/dist/esm/shared/route/index.d.ts +11 -9
- package/dist/esm/shared/route/index.js +3 -3
- package/dist/esm/shared/route/loadPageRoutes.js +7 -6
- package/dist/esm/shared/route/resolveRouteFunction.js +1 -1
- package/dist/esm/shared/utils.d.ts +1 -1
- package/dist/esm/shared/utils.js +1 -1
- package/dist/esm/utils/isPropertyGetter.d.ts +1 -0
- package/dist/esm/utils/{hasPropertyGetter.js → isPropertyGetter.js} +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/shared/page-configs/utils.js +0 -96
- package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.js +0 -15
- package/dist/esm/client/client-routing-runtime/useClientRouter.d.ts +0 -6
- package/dist/esm/shared/page-configs/utils.d.ts +0 -35
- package/dist/esm/shared/page-configs/utils.js +0 -90
- package/dist/esm/utils/hasPropertyGetter.d.ts +0 -1
|
@@ -14,20 +14,18 @@ import { preparePageContextForUserConsumptionClientSide } from '../shared/prepar
|
|
|
14
14
|
import { loadPageFilesClientSide } from '../shared/loadPageFilesClientSide.js';
|
|
15
15
|
import { removeBuiltInOverrides } from './getPageContext/removeBuiltInOverrides.js';
|
|
16
16
|
import { getPageContextRequestUrl } from '../../shared/getPageContextRequestUrl.js';
|
|
17
|
-
import { getConfigValue, getPageConfig } from '../../shared/page-configs/
|
|
17
|
+
import { getConfigValue, getPageConfig } from '../../shared/page-configs/helpers.js';
|
|
18
18
|
import { assertOnBeforeRenderHookReturn } from '../../shared/assertOnBeforeRenderHookReturn.js';
|
|
19
19
|
import { executeGuardHook } from '../../shared/route/executeGuardHook.js';
|
|
20
20
|
import { AbortRender, isAbortPageContext } from '../../shared/route/abort.js';
|
|
21
21
|
const globalObject = getGlobalObject('router/getPageContext.ts', {});
|
|
22
22
|
async function getPageContext(pageContext) {
|
|
23
23
|
if (pageContext._isFirstRenderAttempt && navigationState.isFirstUrl(pageContext.urlOriginal)) {
|
|
24
|
-
assert(hasProp(pageContext, '_isFirstRenderAttempt', 'true'));
|
|
25
24
|
const pageContextAddendum = await getPageContextFirstRender(pageContext);
|
|
26
25
|
setPageContextInitHasClientData(pageContextAddendum);
|
|
27
26
|
return pageContextAddendum;
|
|
28
27
|
}
|
|
29
28
|
else {
|
|
30
|
-
assert(hasProp(pageContext, '_isFirstRenderAttempt', 'false'));
|
|
31
29
|
const pageContextAddendum = await getPageContextUponNavigation(pageContext);
|
|
32
30
|
setPageContextInitHasClientData(pageContextAddendum);
|
|
33
31
|
return pageContextAddendum;
|
|
@@ -185,8 +183,8 @@ async function onBeforeRenderClientOnlyExists(pageContext) {
|
|
|
185
183
|
}
|
|
186
184
|
}
|
|
187
185
|
async function getPageContextFromRoute(pageContext) {
|
|
188
|
-
const
|
|
189
|
-
|
|
186
|
+
const pageContextFromRoute = await route(pageContext);
|
|
187
|
+
// We'll be able to remove this once async route functions are deprecated (because we'll be able to skip link hijacking if a link doesn't match a route (because whether to call event.preventDefault() needs to be determined synchronously))
|
|
190
188
|
if (!pageContextFromRoute._pageId) {
|
|
191
189
|
const err = new Error('No routing match');
|
|
192
190
|
markIs404(err);
|
|
@@ -202,8 +200,7 @@ function checkIf404(err) {
|
|
|
202
200
|
return isObject(err) && err._is404 === true;
|
|
203
201
|
}
|
|
204
202
|
async function fetchPageContextFromServer(pageContext) {
|
|
205
|
-
const
|
|
206
|
-
const pageContextUrl = getPageContextRequestUrl(urlLogical);
|
|
203
|
+
const pageContextUrl = getPageContextRequestUrl(pageContext._urlRewrite ?? pageContext.urlOriginal);
|
|
207
204
|
const response = await fetch(pageContextUrl);
|
|
208
205
|
{
|
|
209
206
|
const contentType = response.headers.get('content-type');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getPageId };
|
|
2
|
-
declare function getPageId(
|
|
2
|
+
declare function getPageId(urlOriginal: string): Promise<{
|
|
3
3
|
pageId: null;
|
|
4
4
|
pageFilesAll: import("../../shared/getPageFiles/getPageFileObject.js").PageFile[];
|
|
5
5
|
pageConfigs: import("../../shared/page-configs/PageConfig.js").PageConfigRuntime[];
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
export { getPageId };
|
|
2
2
|
import { route } from '../../shared/route/index.js';
|
|
3
3
|
import { createPageContext } from './createPageContext.js';
|
|
4
|
-
async function getPageId(
|
|
5
|
-
const pageContext = await createPageContext(
|
|
6
|
-
const routeContext = await route(pageContext);
|
|
4
|
+
async function getPageId(urlOriginal) {
|
|
5
|
+
const pageContext = await createPageContext(urlOriginal);
|
|
7
6
|
const pageFilesAll = pageContext._pageFilesAll;
|
|
8
7
|
const pageConfigs = pageContext._pageConfigs;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
const pageId = routeContext.pageContextAddendum._pageId;
|
|
8
|
+
const pageContextFromRoute = await route(pageContext);
|
|
9
|
+
const pageId = pageContextFromRoute._pageId;
|
|
13
10
|
if (!pageId) {
|
|
14
11
|
return { pageId: null, pageFilesAll, pageConfigs };
|
|
15
12
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { initHistoryState, getHistoryState, pushHistory, ScrollPosition, saveScrollPosition };
|
|
1
|
+
export { initHistoryState, getHistoryState, pushHistory, ScrollPosition, saveScrollPosition, monkeyPatchHistoryPushState };
|
|
2
2
|
type HistoryState = {
|
|
3
3
|
timestamp?: number;
|
|
4
4
|
scrollPosition?: null | ScrollPosition;
|
|
5
|
+
triggedBy?: 'user' | 'vike' | 'browser';
|
|
5
6
|
};
|
|
6
7
|
type ScrollPosition = {
|
|
7
8
|
x: number;
|
|
@@ -11,3 +12,4 @@ declare function initHistoryState(): void;
|
|
|
11
12
|
declare function getHistoryState(): HistoryState;
|
|
12
13
|
declare function saveScrollPosition(): void;
|
|
13
14
|
declare function pushHistory(url: string, overwriteLastHistoryEntry: boolean): void;
|
|
15
|
+
declare function monkeyPatchHistoryPushState(): void;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export { initHistoryState, getHistoryState, pushHistory, saveScrollPosition };
|
|
2
|
-
import { assert, hasProp, isObject } from './utils.js';
|
|
3
|
-
// Fill missing state information
|
|
4
|
-
// -
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
1
|
+
export { initHistoryState, getHistoryState, pushHistory, saveScrollPosition, monkeyPatchHistoryPushState };
|
|
2
|
+
import { assert, assertUsage, hasProp, isObject } from './utils.js';
|
|
3
|
+
// Fill missing state information:
|
|
4
|
+
// - `history.state` can uninitialized (i.e. `null`):
|
|
5
|
+
// - The very first render
|
|
6
|
+
// - The user's code runs `location.hash = '#section'`
|
|
7
|
+
// - The user clicks on an anchor link `<a href="#section">Section</a>` (Vike's `onLinkClick()` handler skips hash links).
|
|
8
|
+
// - State information may be incomplete if `history.state` is set by an old Vike version. (E.g. `state.timestamp` was introduced for `pageContext.isBackwardNavigation` in `0.4.19`.)
|
|
8
9
|
function initHistoryState() {
|
|
9
10
|
let state = window.history.state;
|
|
10
11
|
if (!state) {
|
|
@@ -19,6 +20,9 @@ function initHistoryState() {
|
|
|
19
20
|
hasModifications = true;
|
|
20
21
|
state.scrollPosition = getScrollPosition();
|
|
21
22
|
}
|
|
23
|
+
if (!('triggedBy' in state)) {
|
|
24
|
+
state.triggedBy = 'browser';
|
|
25
|
+
}
|
|
22
26
|
assertState(state);
|
|
23
27
|
if (hasModifications) {
|
|
24
28
|
replaceHistoryState(state);
|
|
@@ -44,7 +48,7 @@ function saveScrollPosition() {
|
|
|
44
48
|
function pushHistory(url, overwriteLastHistoryEntry) {
|
|
45
49
|
if (!overwriteLastHistoryEntry) {
|
|
46
50
|
const timestamp = getTimestamp();
|
|
47
|
-
pushHistoryState({ timestamp, scrollPosition: null }, url);
|
|
51
|
+
pushHistoryState({ timestamp, scrollPosition: null, triggedBy: 'vike' }, url);
|
|
48
52
|
}
|
|
49
53
|
else {
|
|
50
54
|
replaceHistoryState(getHistoryState(), url);
|
|
@@ -69,3 +73,17 @@ function replaceHistoryState(state, url) {
|
|
|
69
73
|
function pushHistoryState(state, url) {
|
|
70
74
|
window.history.pushState(state, '', url);
|
|
71
75
|
}
|
|
76
|
+
function monkeyPatchHistoryPushState() {
|
|
77
|
+
const pushStateOriginal = history.pushState;
|
|
78
|
+
history.pushState = (stateFromUser = {}, ...rest) => {
|
|
79
|
+
assertUsage(null === stateFromUser || undefined === stateFromUser || isObject(stateFromUser), 'history.pushState(state) argument state must be an object');
|
|
80
|
+
const state = {
|
|
81
|
+
scrollPosition: getScrollPosition(),
|
|
82
|
+
timestamp: getTimestamp(),
|
|
83
|
+
...stateFromUser,
|
|
84
|
+
// Don't allow user to overwrite triggedBy as it would break Vike's handling of the 'popstate' event
|
|
85
|
+
triggedBy: 'user'
|
|
86
|
+
};
|
|
87
|
+
return pushStateOriginal.apply(history, [state, ...rest]);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { installClientRouter };
|
|
2
|
+
export { disableClientRouting };
|
|
3
|
+
export { isDisableAutomaticLinkInterception };
|
|
4
|
+
export { renderPageClientSide };
|
|
5
|
+
import { ScrollPosition } from './history.js';
|
|
6
|
+
import { PageContextFromRewrite } from '../../shared/route/abort.js';
|
|
7
|
+
declare function installClientRouter(): void;
|
|
8
|
+
type RenderArgs = {
|
|
9
|
+
scrollTarget: ScrollTarget;
|
|
10
|
+
isBackwardNavigation: boolean | null;
|
|
11
|
+
urlOriginal?: string;
|
|
12
|
+
overwriteLastHistoryEntry?: boolean;
|
|
13
|
+
checkIfClientSideRenderable?: boolean;
|
|
14
|
+
pageContextsFromRewrite?: PageContextFromRewrite[];
|
|
15
|
+
redirectCount?: number;
|
|
16
|
+
isUserLandNavigation?: boolean;
|
|
17
|
+
};
|
|
18
|
+
declare function renderPageClientSide(renderArgs: RenderArgs): Promise<void>;
|
|
19
|
+
type ScrollTarget = ScrollPosition | 'scroll-to-top-or-hash' | 'preserve-scroll';
|
|
20
|
+
declare function isDisableAutomaticLinkInterception(): boolean;
|
|
21
|
+
declare function disableClientRouting(err: unknown, log: boolean): void;
|