@lolyjs/core 0.2.0-alpha.3 → 0.2.0-alpha.4
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/{bootstrap-BiCQmSkx.d.mts → bootstrap-DgvWWDim.d.mts} +7 -0
- package/dist/{bootstrap-BiCQmSkx.d.ts → bootstrap-DgvWWDim.d.ts} +7 -0
- package/dist/cli.cjs +29 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +29 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +86 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +86 -1
- package/dist/index.js.map +1 -1
- package/dist/react/hooks.cjs +98 -22
- package/dist/react/hooks.cjs.map +1 -1
- package/dist/react/hooks.d.mts +5 -0
- package/dist/react/hooks.d.ts +5 -0
- package/dist/react/hooks.js +99 -23
- package/dist/react/hooks.js.map +1 -1
- package/dist/runtime.cjs +57 -0
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.d.mts +2 -2
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.js +57 -0
- package/dist/runtime.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -47,17 +47,19 @@ __export(globals_exports, {
|
|
|
47
47
|
NOT_FOUND_FILE_PREFIX: () => NOT_FOUND_FILE_PREFIX,
|
|
48
48
|
NOT_FOUND_PATTERN: () => NOT_FOUND_PATTERN,
|
|
49
49
|
PAGE_FILE_NAME: () => PAGE_FILE_NAME,
|
|
50
|
+
ROUTER_DATA_KEY: () => ROUTER_DATA_KEY,
|
|
50
51
|
STATIC_PATH: () => STATIC_PATH,
|
|
51
52
|
STYLE_FILE_NAME: () => STYLE_FILE_NAME,
|
|
52
53
|
WINDOW_DATA_KEY: () => WINDOW_DATA_KEY
|
|
53
54
|
});
|
|
54
|
-
var BUILD_FOLDER_NAME, STYLE_FILE_NAME, WINDOW_DATA_KEY, APP_CONTAINER_ID, STATIC_PATH, NOT_FOUND_PATTERN, ERROR_PATTERN, NOT_FOUND_CHUNK_KEY, ERROR_CHUNK_KEY, NOT_FOUND_FILE_PREFIX, ERROR_FILE_PREFIX, PAGE_FILE_NAME, LAYOUT_FILE_NAME, FAVICON_PATH, CLIENT_CSS_PATH, CLIENT_JS_PATH, ASSETS_BASE_DIR;
|
|
55
|
+
var BUILD_FOLDER_NAME, STYLE_FILE_NAME, WINDOW_DATA_KEY, ROUTER_DATA_KEY, APP_CONTAINER_ID, STATIC_PATH, NOT_FOUND_PATTERN, ERROR_PATTERN, NOT_FOUND_CHUNK_KEY, ERROR_CHUNK_KEY, NOT_FOUND_FILE_PREFIX, ERROR_FILE_PREFIX, PAGE_FILE_NAME, LAYOUT_FILE_NAME, FAVICON_PATH, CLIENT_CSS_PATH, CLIENT_JS_PATH, ASSETS_BASE_DIR;
|
|
55
56
|
var init_globals = __esm({
|
|
56
57
|
"constants/globals.ts"() {
|
|
57
58
|
"use strict";
|
|
58
59
|
BUILD_FOLDER_NAME = ".loly";
|
|
59
60
|
STYLE_FILE_NAME = "styles.css";
|
|
60
61
|
WINDOW_DATA_KEY = "__FW_DATA__";
|
|
62
|
+
ROUTER_DATA_KEY = "__LOLY_ROUTER_DATA__";
|
|
61
63
|
APP_CONTAINER_ID = "__app";
|
|
62
64
|
STATIC_PATH = "/static";
|
|
63
65
|
NOT_FOUND_PATTERN = "/not-found";
|
|
@@ -3877,6 +3879,7 @@ function createDocumentTree(options) {
|
|
|
3877
3879
|
const {
|
|
3878
3880
|
appTree,
|
|
3879
3881
|
initialData,
|
|
3882
|
+
routerData,
|
|
3880
3883
|
meta,
|
|
3881
3884
|
titleFallback,
|
|
3882
3885
|
descriptionFallback,
|
|
@@ -3914,6 +3917,9 @@ function createDocumentTree(options) {
|
|
|
3914
3917
|
...initialData,
|
|
3915
3918
|
theme
|
|
3916
3919
|
});
|
|
3920
|
+
const routerSerialized = JSON.stringify({
|
|
3921
|
+
...routerData
|
|
3922
|
+
});
|
|
3917
3923
|
const documentTree = import_react.default.createElement(
|
|
3918
3924
|
"html",
|
|
3919
3925
|
{ lang },
|
|
@@ -3961,6 +3967,12 @@ function createDocumentTree(options) {
|
|
|
3961
3967
|
dangerouslySetInnerHTML: {
|
|
3962
3968
|
__html: `window.${WINDOW_DATA_KEY} = ${serialized};`
|
|
3963
3969
|
}
|
|
3970
|
+
}),
|
|
3971
|
+
import_react.default.createElement("script", {
|
|
3972
|
+
nonce,
|
|
3973
|
+
dangerouslySetInnerHTML: {
|
|
3974
|
+
__html: `window.${ROUTER_DATA_KEY} = ${routerSerialized};`
|
|
3975
|
+
}
|
|
3964
3976
|
})
|
|
3965
3977
|
);
|
|
3966
3978
|
return documentTree;
|
|
@@ -3983,6 +3995,15 @@ function buildInitialData(urlPath, params, loaderResult) {
|
|
|
3983
3995
|
};
|
|
3984
3996
|
}
|
|
3985
3997
|
|
|
3998
|
+
// modules/rendering/routerData/index.ts
|
|
3999
|
+
var buildRouterData = (req) => {
|
|
4000
|
+
return {
|
|
4001
|
+
pathname: req.path,
|
|
4002
|
+
params: req.params,
|
|
4003
|
+
searchParams: req.query
|
|
4004
|
+
};
|
|
4005
|
+
};
|
|
4006
|
+
|
|
3986
4007
|
// modules/server/handlers/middleware.ts
|
|
3987
4008
|
async function runRouteMiddlewares(route, ctx) {
|
|
3988
4009
|
for (const mw of route.middlewares) {
|
|
@@ -4144,6 +4165,7 @@ async function handlePageRequestInternal(options) {
|
|
|
4144
4165
|
}
|
|
4145
4166
|
}
|
|
4146
4167
|
const matched = matchRoute(routes, urlPath);
|
|
4168
|
+
const routerData = buildRouterData(req);
|
|
4147
4169
|
if (!matched) {
|
|
4148
4170
|
if (notFoundPage) {
|
|
4149
4171
|
const ctx2 = {
|
|
@@ -4164,6 +4186,7 @@ async function handlePageRequestInternal(options) {
|
|
|
4164
4186
|
const documentTree2 = createDocumentTree({
|
|
4165
4187
|
appTree: appTree2,
|
|
4166
4188
|
initialData: initialData2,
|
|
4189
|
+
routerData,
|
|
4167
4190
|
meta: loaderResult2.metadata ?? null,
|
|
4168
4191
|
titleFallback: "Not found",
|
|
4169
4192
|
descriptionFallback: "Loly demo",
|
|
@@ -4271,6 +4294,7 @@ async function handlePageRequestInternal(options) {
|
|
|
4271
4294
|
const documentTree = createDocumentTree({
|
|
4272
4295
|
appTree,
|
|
4273
4296
|
initialData,
|
|
4297
|
+
routerData,
|
|
4274
4298
|
meta: loaderResult.metadata,
|
|
4275
4299
|
titleFallback: "Loly framework",
|
|
4276
4300
|
descriptionFallback: "Loly demo",
|
|
@@ -4328,6 +4352,7 @@ async function renderErrorPageWithStream(errorPage, req, res, error, routeChunks
|
|
|
4328
4352
|
loaderResult.theme = theme;
|
|
4329
4353
|
}
|
|
4330
4354
|
const initialData = buildInitialData(req.path, { error: String(error) }, loaderResult);
|
|
4355
|
+
const routerData = buildRouterData(req);
|
|
4331
4356
|
initialData.error = true;
|
|
4332
4357
|
if (isDataReq) {
|
|
4333
4358
|
res.statusCode = 500;
|
|
@@ -4358,6 +4383,7 @@ async function renderErrorPageWithStream(errorPage, req, res, error, routeChunks
|
|
|
4358
4383
|
const documentTree = createDocumentTree({
|
|
4359
4384
|
appTree,
|
|
4360
4385
|
initialData,
|
|
4386
|
+
routerData,
|
|
4361
4387
|
meta: loaderResult.metadata ?? null,
|
|
4362
4388
|
titleFallback: "Error",
|
|
4363
4389
|
descriptionFallback: "An error occurred",
|
|
@@ -4940,10 +4966,12 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params)
|
|
|
4940
4966
|
return;
|
|
4941
4967
|
}
|
|
4942
4968
|
const initialData = buildInitialData(urlPath, params, loaderResult);
|
|
4969
|
+
const routerData = buildRouterData(req);
|
|
4943
4970
|
const appTree = buildAppTree(route, params, initialData.props);
|
|
4944
4971
|
const documentTree = createDocumentTree({
|
|
4945
4972
|
appTree,
|
|
4946
4973
|
initialData,
|
|
4974
|
+
routerData,
|
|
4947
4975
|
meta: loaderResult.metadata,
|
|
4948
4976
|
titleFallback: "My Framework Dev",
|
|
4949
4977
|
descriptionFallback: "Static page generated by @lolyjs/core.",
|
|
@@ -5134,7 +5162,9 @@ var import_client5 = require("react-dom/client");
|
|
|
5134
5162
|
|
|
5135
5163
|
// modules/runtime/client/constants.ts
|
|
5136
5164
|
var WINDOW_DATA_KEY2 = "__FW_DATA__";
|
|
5165
|
+
var ROUTER_DATA_KEY2 = "__LOLY_ROUTER_DATA__";
|
|
5137
5166
|
var APP_CONTAINER_ID2 = "__app";
|
|
5167
|
+
var ROUTER_NAVIGATE_KEY = "__LOLY_ROUTER_NAVIGATE__";
|
|
5138
5168
|
|
|
5139
5169
|
// modules/runtime/client/window-data.ts
|
|
5140
5170
|
function getWindowData() {
|
|
@@ -5143,6 +5173,12 @@ function getWindowData() {
|
|
|
5143
5173
|
}
|
|
5144
5174
|
return window[WINDOW_DATA_KEY2] ?? null;
|
|
5145
5175
|
}
|
|
5176
|
+
function getRouterData() {
|
|
5177
|
+
if (typeof window === "undefined") {
|
|
5178
|
+
return null;
|
|
5179
|
+
}
|
|
5180
|
+
return window[ROUTER_DATA_KEY2] ?? null;
|
|
5181
|
+
}
|
|
5146
5182
|
function setWindowData(data) {
|
|
5147
5183
|
window[WINDOW_DATA_KEY2] = data;
|
|
5148
5184
|
if (typeof window !== "undefined") {
|
|
@@ -5153,6 +5189,16 @@ function setWindowData(data) {
|
|
|
5153
5189
|
);
|
|
5154
5190
|
}
|
|
5155
5191
|
}
|
|
5192
|
+
function setRouterData(data) {
|
|
5193
|
+
window[ROUTER_DATA_KEY2] = data;
|
|
5194
|
+
if (typeof window !== "undefined") {
|
|
5195
|
+
window.dispatchEvent(
|
|
5196
|
+
new CustomEvent("fw-router-data-refresh", {
|
|
5197
|
+
detail: { data }
|
|
5198
|
+
})
|
|
5199
|
+
);
|
|
5200
|
+
}
|
|
5201
|
+
}
|
|
5156
5202
|
function getCurrentTheme() {
|
|
5157
5203
|
return getWindowData()?.theme ?? null;
|
|
5158
5204
|
}
|
|
@@ -5414,6 +5460,13 @@ async function handleErrorRoute(nextUrl, json, errorRoute, setState) {
|
|
|
5414
5460
|
error: true
|
|
5415
5461
|
};
|
|
5416
5462
|
setWindowData(windowData);
|
|
5463
|
+
const url = new URL(nextUrl, typeof window !== "undefined" ? window.location.origin : "http://localhost");
|
|
5464
|
+
const routerData = {
|
|
5465
|
+
pathname: url.pathname,
|
|
5466
|
+
params: json.params || {},
|
|
5467
|
+
searchParams: Object.fromEntries(url.searchParams.entries())
|
|
5468
|
+
};
|
|
5469
|
+
setRouterData(routerData);
|
|
5417
5470
|
setState({
|
|
5418
5471
|
url: nextUrl,
|
|
5419
5472
|
route: errorRoute,
|
|
@@ -5460,6 +5513,13 @@ async function handleNotFoundRoute(nextUrl, json, notFoundRoute, setState) {
|
|
|
5460
5513
|
error: false
|
|
5461
5514
|
};
|
|
5462
5515
|
setWindowData(windowData);
|
|
5516
|
+
const url = new URL(nextUrl, typeof window !== "undefined" ? window.location.origin : "http://localhost");
|
|
5517
|
+
const routerData = {
|
|
5518
|
+
pathname: url.pathname,
|
|
5519
|
+
params: {},
|
|
5520
|
+
searchParams: Object.fromEntries(url.searchParams.entries())
|
|
5521
|
+
};
|
|
5522
|
+
setRouterData(routerData);
|
|
5463
5523
|
if (notFoundRoute) {
|
|
5464
5524
|
const components = await notFoundRoute.load();
|
|
5465
5525
|
setState({
|
|
@@ -5517,6 +5577,13 @@ async function handleNormalRoute(nextUrl, json, routes, setState) {
|
|
|
5517
5577
|
error: false
|
|
5518
5578
|
};
|
|
5519
5579
|
setWindowData(windowData);
|
|
5580
|
+
const url = new URL(nextUrl, typeof window !== "undefined" ? window.location.origin : "http://localhost");
|
|
5581
|
+
const routerData = {
|
|
5582
|
+
pathname: url.pathname,
|
|
5583
|
+
params: matched.params,
|
|
5584
|
+
searchParams: Object.fromEntries(url.searchParams.entries())
|
|
5585
|
+
};
|
|
5586
|
+
setRouterData(routerData);
|
|
5520
5587
|
const components = await matched.route.load();
|
|
5521
5588
|
window.scrollTo({
|
|
5522
5589
|
top: 0,
|
|
@@ -5671,6 +5738,14 @@ function AppShell({
|
|
|
5671
5738
|
},
|
|
5672
5739
|
[]
|
|
5673
5740
|
);
|
|
5741
|
+
(0, import_react3.useEffect)(() => {
|
|
5742
|
+
if (typeof window !== "undefined") {
|
|
5743
|
+
window[ROUTER_NAVIGATE_KEY] = handleNavigate;
|
|
5744
|
+
return () => {
|
|
5745
|
+
delete window[ROUTER_NAVIGATE_KEY];
|
|
5746
|
+
};
|
|
5747
|
+
}
|
|
5748
|
+
}, [handleNavigate]);
|
|
5674
5749
|
(0, import_react3.useEffect)(() => {
|
|
5675
5750
|
let isMounted = true;
|
|
5676
5751
|
async function handleNavigateInternal(nextUrl, options) {
|
|
@@ -5791,6 +5866,16 @@ function bootstrapClient(routes, notFoundRoute, errorRoute = null) {
|
|
|
5791
5866
|
return;
|
|
5792
5867
|
}
|
|
5793
5868
|
const initialUrl = window.location.pathname + window.location.search;
|
|
5869
|
+
let routerData = getRouterData();
|
|
5870
|
+
if (!routerData) {
|
|
5871
|
+
const url = new URL(initialUrl, window.location.origin);
|
|
5872
|
+
routerData = {
|
|
5873
|
+
pathname: url.pathname,
|
|
5874
|
+
params: initialData?.params || {},
|
|
5875
|
+
searchParams: Object.fromEntries(url.searchParams.entries())
|
|
5876
|
+
};
|
|
5877
|
+
setRouterData(routerData);
|
|
5878
|
+
}
|
|
5794
5879
|
try {
|
|
5795
5880
|
const initialState = await loadInitialRoute(
|
|
5796
5881
|
initialUrl,
|