@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.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
2
|
import { Request, Response } from 'express';
|
|
3
3
|
import { Socket, Server } from 'socket.io';
|
|
4
|
-
export { c as bootstrapClient } from './bootstrap-
|
|
4
|
+
export { c as bootstrapClient } from './bootstrap-DgvWWDim.mjs';
|
|
5
5
|
import { ZodSchema, z } from 'zod';
|
|
6
6
|
import * as express_rate_limit from 'express-rate-limit';
|
|
7
7
|
import pino, { Logger as Logger$1 } from 'pino';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
2
|
import { Request, Response } from 'express';
|
|
3
3
|
import { Socket, Server } from 'socket.io';
|
|
4
|
-
export { c as bootstrapClient } from './bootstrap-
|
|
4
|
+
export { c as bootstrapClient } from './bootstrap-DgvWWDim.js';
|
|
5
5
|
import { ZodSchema, z } from 'zod';
|
|
6
6
|
import * as express_rate_limit from 'express-rate-limit';
|
|
7
7
|
import pino, { Logger as Logger$1 } from 'pino';
|
package/dist/index.js
CHANGED
|
@@ -42,17 +42,19 @@ __export(globals_exports, {
|
|
|
42
42
|
NOT_FOUND_FILE_PREFIX: () => NOT_FOUND_FILE_PREFIX,
|
|
43
43
|
NOT_FOUND_PATTERN: () => NOT_FOUND_PATTERN,
|
|
44
44
|
PAGE_FILE_NAME: () => PAGE_FILE_NAME,
|
|
45
|
+
ROUTER_DATA_KEY: () => ROUTER_DATA_KEY,
|
|
45
46
|
STATIC_PATH: () => STATIC_PATH,
|
|
46
47
|
STYLE_FILE_NAME: () => STYLE_FILE_NAME,
|
|
47
48
|
WINDOW_DATA_KEY: () => WINDOW_DATA_KEY
|
|
48
49
|
});
|
|
49
|
-
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;
|
|
50
|
+
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;
|
|
50
51
|
var init_globals = __esm({
|
|
51
52
|
"constants/globals.ts"() {
|
|
52
53
|
"use strict";
|
|
53
54
|
BUILD_FOLDER_NAME = ".loly";
|
|
54
55
|
STYLE_FILE_NAME = "styles.css";
|
|
55
56
|
WINDOW_DATA_KEY = "__FW_DATA__";
|
|
57
|
+
ROUTER_DATA_KEY = "__LOLY_ROUTER_DATA__";
|
|
56
58
|
APP_CONTAINER_ID = "__app";
|
|
57
59
|
STATIC_PATH = "/static";
|
|
58
60
|
NOT_FOUND_PATTERN = "/not-found";
|
|
@@ -3835,6 +3837,7 @@ function createDocumentTree(options) {
|
|
|
3835
3837
|
const {
|
|
3836
3838
|
appTree,
|
|
3837
3839
|
initialData,
|
|
3840
|
+
routerData,
|
|
3838
3841
|
meta,
|
|
3839
3842
|
titleFallback,
|
|
3840
3843
|
descriptionFallback,
|
|
@@ -3872,6 +3875,9 @@ function createDocumentTree(options) {
|
|
|
3872
3875
|
...initialData,
|
|
3873
3876
|
theme
|
|
3874
3877
|
});
|
|
3878
|
+
const routerSerialized = JSON.stringify({
|
|
3879
|
+
...routerData
|
|
3880
|
+
});
|
|
3875
3881
|
const documentTree = React.createElement(
|
|
3876
3882
|
"html",
|
|
3877
3883
|
{ lang },
|
|
@@ -3919,6 +3925,12 @@ function createDocumentTree(options) {
|
|
|
3919
3925
|
dangerouslySetInnerHTML: {
|
|
3920
3926
|
__html: `window.${WINDOW_DATA_KEY} = ${serialized};`
|
|
3921
3927
|
}
|
|
3928
|
+
}),
|
|
3929
|
+
React.createElement("script", {
|
|
3930
|
+
nonce,
|
|
3931
|
+
dangerouslySetInnerHTML: {
|
|
3932
|
+
__html: `window.${ROUTER_DATA_KEY} = ${routerSerialized};`
|
|
3933
|
+
}
|
|
3922
3934
|
})
|
|
3923
3935
|
);
|
|
3924
3936
|
return documentTree;
|
|
@@ -3941,6 +3953,15 @@ function buildInitialData(urlPath, params, loaderResult) {
|
|
|
3941
3953
|
};
|
|
3942
3954
|
}
|
|
3943
3955
|
|
|
3956
|
+
// modules/rendering/routerData/index.ts
|
|
3957
|
+
var buildRouterData = (req) => {
|
|
3958
|
+
return {
|
|
3959
|
+
pathname: req.path,
|
|
3960
|
+
params: req.params,
|
|
3961
|
+
searchParams: req.query
|
|
3962
|
+
};
|
|
3963
|
+
};
|
|
3964
|
+
|
|
3944
3965
|
// modules/server/handlers/middleware.ts
|
|
3945
3966
|
async function runRouteMiddlewares(route, ctx) {
|
|
3946
3967
|
for (const mw of route.middlewares) {
|
|
@@ -4102,6 +4123,7 @@ async function handlePageRequestInternal(options) {
|
|
|
4102
4123
|
}
|
|
4103
4124
|
}
|
|
4104
4125
|
const matched = matchRoute(routes, urlPath);
|
|
4126
|
+
const routerData = buildRouterData(req);
|
|
4105
4127
|
if (!matched) {
|
|
4106
4128
|
if (notFoundPage) {
|
|
4107
4129
|
const ctx2 = {
|
|
@@ -4122,6 +4144,7 @@ async function handlePageRequestInternal(options) {
|
|
|
4122
4144
|
const documentTree2 = createDocumentTree({
|
|
4123
4145
|
appTree: appTree2,
|
|
4124
4146
|
initialData: initialData2,
|
|
4147
|
+
routerData,
|
|
4125
4148
|
meta: loaderResult2.metadata ?? null,
|
|
4126
4149
|
titleFallback: "Not found",
|
|
4127
4150
|
descriptionFallback: "Loly demo",
|
|
@@ -4229,6 +4252,7 @@ async function handlePageRequestInternal(options) {
|
|
|
4229
4252
|
const documentTree = createDocumentTree({
|
|
4230
4253
|
appTree,
|
|
4231
4254
|
initialData,
|
|
4255
|
+
routerData,
|
|
4232
4256
|
meta: loaderResult.metadata,
|
|
4233
4257
|
titleFallback: "Loly framework",
|
|
4234
4258
|
descriptionFallback: "Loly demo",
|
|
@@ -4286,6 +4310,7 @@ async function renderErrorPageWithStream(errorPage, req, res, error, routeChunks
|
|
|
4286
4310
|
loaderResult.theme = theme;
|
|
4287
4311
|
}
|
|
4288
4312
|
const initialData = buildInitialData(req.path, { error: String(error) }, loaderResult);
|
|
4313
|
+
const routerData = buildRouterData(req);
|
|
4289
4314
|
initialData.error = true;
|
|
4290
4315
|
if (isDataReq) {
|
|
4291
4316
|
res.statusCode = 500;
|
|
@@ -4316,6 +4341,7 @@ async function renderErrorPageWithStream(errorPage, req, res, error, routeChunks
|
|
|
4316
4341
|
const documentTree = createDocumentTree({
|
|
4317
4342
|
appTree,
|
|
4318
4343
|
initialData,
|
|
4344
|
+
routerData,
|
|
4319
4345
|
meta: loaderResult.metadata ?? null,
|
|
4320
4346
|
titleFallback: "Error",
|
|
4321
4347
|
descriptionFallback: "An error occurred",
|
|
@@ -4898,10 +4924,12 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params)
|
|
|
4898
4924
|
return;
|
|
4899
4925
|
}
|
|
4900
4926
|
const initialData = buildInitialData(urlPath, params, loaderResult);
|
|
4927
|
+
const routerData = buildRouterData(req);
|
|
4901
4928
|
const appTree = buildAppTree(route, params, initialData.props);
|
|
4902
4929
|
const documentTree = createDocumentTree({
|
|
4903
4930
|
appTree,
|
|
4904
4931
|
initialData,
|
|
4932
|
+
routerData,
|
|
4905
4933
|
meta: loaderResult.metadata,
|
|
4906
4934
|
titleFallback: "My Framework Dev",
|
|
4907
4935
|
descriptionFallback: "Static page generated by @lolyjs/core.",
|
|
@@ -5092,7 +5120,9 @@ import { hydrateRoot } from "react-dom/client";
|
|
|
5092
5120
|
|
|
5093
5121
|
// modules/runtime/client/constants.ts
|
|
5094
5122
|
var WINDOW_DATA_KEY2 = "__FW_DATA__";
|
|
5123
|
+
var ROUTER_DATA_KEY2 = "__LOLY_ROUTER_DATA__";
|
|
5095
5124
|
var APP_CONTAINER_ID2 = "__app";
|
|
5125
|
+
var ROUTER_NAVIGATE_KEY = "__LOLY_ROUTER_NAVIGATE__";
|
|
5096
5126
|
|
|
5097
5127
|
// modules/runtime/client/window-data.ts
|
|
5098
5128
|
function getWindowData() {
|
|
@@ -5101,6 +5131,12 @@ function getWindowData() {
|
|
|
5101
5131
|
}
|
|
5102
5132
|
return window[WINDOW_DATA_KEY2] ?? null;
|
|
5103
5133
|
}
|
|
5134
|
+
function getRouterData() {
|
|
5135
|
+
if (typeof window === "undefined") {
|
|
5136
|
+
return null;
|
|
5137
|
+
}
|
|
5138
|
+
return window[ROUTER_DATA_KEY2] ?? null;
|
|
5139
|
+
}
|
|
5104
5140
|
function setWindowData(data) {
|
|
5105
5141
|
window[WINDOW_DATA_KEY2] = data;
|
|
5106
5142
|
if (typeof window !== "undefined") {
|
|
@@ -5111,6 +5147,16 @@ function setWindowData(data) {
|
|
|
5111
5147
|
);
|
|
5112
5148
|
}
|
|
5113
5149
|
}
|
|
5150
|
+
function setRouterData(data) {
|
|
5151
|
+
window[ROUTER_DATA_KEY2] = data;
|
|
5152
|
+
if (typeof window !== "undefined") {
|
|
5153
|
+
window.dispatchEvent(
|
|
5154
|
+
new CustomEvent("fw-router-data-refresh", {
|
|
5155
|
+
detail: { data }
|
|
5156
|
+
})
|
|
5157
|
+
);
|
|
5158
|
+
}
|
|
5159
|
+
}
|
|
5114
5160
|
function getCurrentTheme() {
|
|
5115
5161
|
return getWindowData()?.theme ?? null;
|
|
5116
5162
|
}
|
|
@@ -5372,6 +5418,13 @@ async function handleErrorRoute(nextUrl, json, errorRoute, setState) {
|
|
|
5372
5418
|
error: true
|
|
5373
5419
|
};
|
|
5374
5420
|
setWindowData(windowData);
|
|
5421
|
+
const url = new URL(nextUrl, typeof window !== "undefined" ? window.location.origin : "http://localhost");
|
|
5422
|
+
const routerData = {
|
|
5423
|
+
pathname: url.pathname,
|
|
5424
|
+
params: json.params || {},
|
|
5425
|
+
searchParams: Object.fromEntries(url.searchParams.entries())
|
|
5426
|
+
};
|
|
5427
|
+
setRouterData(routerData);
|
|
5375
5428
|
setState({
|
|
5376
5429
|
url: nextUrl,
|
|
5377
5430
|
route: errorRoute,
|
|
@@ -5418,6 +5471,13 @@ async function handleNotFoundRoute(nextUrl, json, notFoundRoute, setState) {
|
|
|
5418
5471
|
error: false
|
|
5419
5472
|
};
|
|
5420
5473
|
setWindowData(windowData);
|
|
5474
|
+
const url = new URL(nextUrl, typeof window !== "undefined" ? window.location.origin : "http://localhost");
|
|
5475
|
+
const routerData = {
|
|
5476
|
+
pathname: url.pathname,
|
|
5477
|
+
params: {},
|
|
5478
|
+
searchParams: Object.fromEntries(url.searchParams.entries())
|
|
5479
|
+
};
|
|
5480
|
+
setRouterData(routerData);
|
|
5421
5481
|
if (notFoundRoute) {
|
|
5422
5482
|
const components = await notFoundRoute.load();
|
|
5423
5483
|
setState({
|
|
@@ -5475,6 +5535,13 @@ async function handleNormalRoute(nextUrl, json, routes, setState) {
|
|
|
5475
5535
|
error: false
|
|
5476
5536
|
};
|
|
5477
5537
|
setWindowData(windowData);
|
|
5538
|
+
const url = new URL(nextUrl, typeof window !== "undefined" ? window.location.origin : "http://localhost");
|
|
5539
|
+
const routerData = {
|
|
5540
|
+
pathname: url.pathname,
|
|
5541
|
+
params: matched.params,
|
|
5542
|
+
searchParams: Object.fromEntries(url.searchParams.entries())
|
|
5543
|
+
};
|
|
5544
|
+
setRouterData(routerData);
|
|
5478
5545
|
const components = await matched.route.load();
|
|
5479
5546
|
window.scrollTo({
|
|
5480
5547
|
top: 0,
|
|
@@ -5629,6 +5696,14 @@ function AppShell({
|
|
|
5629
5696
|
},
|
|
5630
5697
|
[]
|
|
5631
5698
|
);
|
|
5699
|
+
useEffect(() => {
|
|
5700
|
+
if (typeof window !== "undefined") {
|
|
5701
|
+
window[ROUTER_NAVIGATE_KEY] = handleNavigate;
|
|
5702
|
+
return () => {
|
|
5703
|
+
delete window[ROUTER_NAVIGATE_KEY];
|
|
5704
|
+
};
|
|
5705
|
+
}
|
|
5706
|
+
}, [handleNavigate]);
|
|
5632
5707
|
useEffect(() => {
|
|
5633
5708
|
let isMounted = true;
|
|
5634
5709
|
async function handleNavigateInternal(nextUrl, options) {
|
|
@@ -5749,6 +5824,16 @@ function bootstrapClient(routes, notFoundRoute, errorRoute = null) {
|
|
|
5749
5824
|
return;
|
|
5750
5825
|
}
|
|
5751
5826
|
const initialUrl = window.location.pathname + window.location.search;
|
|
5827
|
+
let routerData = getRouterData();
|
|
5828
|
+
if (!routerData) {
|
|
5829
|
+
const url = new URL(initialUrl, window.location.origin);
|
|
5830
|
+
routerData = {
|
|
5831
|
+
pathname: url.pathname,
|
|
5832
|
+
params: initialData?.params || {},
|
|
5833
|
+
searchParams: Object.fromEntries(url.searchParams.entries())
|
|
5834
|
+
};
|
|
5835
|
+
setRouterData(routerData);
|
|
5836
|
+
}
|
|
5752
5837
|
try {
|
|
5753
5838
|
const initialState = await loadInitialRoute(
|
|
5754
5839
|
initialUrl,
|