@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.
@@ -1,4 +1,5 @@
1
1
  declare const WINDOW_DATA_KEY = "__FW_DATA__";
2
+ declare const ROUTER_DATA_KEY = "__LOLY_ROUTER_DATA__";
2
3
 
3
4
  type InitialData = {
4
5
  pathname: string;
@@ -12,9 +13,15 @@ type InitialData = {
12
13
  error?: boolean;
13
14
  theme?: string;
14
15
  };
16
+ type RouterData = {
17
+ pathname: string;
18
+ params: Record<string, string>;
19
+ searchParams: Record<string, unknown>;
20
+ };
15
21
  declare global {
16
22
  interface Window {
17
23
  [WINDOW_DATA_KEY]?: InitialData;
24
+ [ROUTER_DATA_KEY]?: RouterData;
18
25
  }
19
26
  }
20
27
  type ClientLoadedComponents = {
@@ -1,4 +1,5 @@
1
1
  declare const WINDOW_DATA_KEY = "__FW_DATA__";
2
+ declare const ROUTER_DATA_KEY = "__LOLY_ROUTER_DATA__";
2
3
 
3
4
  type InitialData = {
4
5
  pathname: string;
@@ -12,9 +13,15 @@ type InitialData = {
12
13
  error?: boolean;
13
14
  theme?: string;
14
15
  };
16
+ type RouterData = {
17
+ pathname: string;
18
+ params: Record<string, string>;
19
+ searchParams: Record<string, unknown>;
20
+ };
15
21
  declare global {
16
22
  interface Window {
17
23
  [WINDOW_DATA_KEY]?: InitialData;
24
+ [ROUTER_DATA_KEY]?: RouterData;
18
25
  }
19
26
  }
20
27
  type ClientLoadedComponents = {
package/dist/cli.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";
@@ -1490,6 +1492,7 @@ function createDocumentTree(options) {
1490
1492
  const {
1491
1493
  appTree,
1492
1494
  initialData,
1495
+ routerData,
1493
1496
  meta,
1494
1497
  titleFallback,
1495
1498
  descriptionFallback,
@@ -1527,6 +1530,9 @@ function createDocumentTree(options) {
1527
1530
  ...initialData,
1528
1531
  theme
1529
1532
  });
1533
+ const routerSerialized = JSON.stringify({
1534
+ ...routerData
1535
+ });
1530
1536
  const documentTree = import_react.default.createElement(
1531
1537
  "html",
1532
1538
  { lang },
@@ -1574,6 +1580,12 @@ function createDocumentTree(options) {
1574
1580
  dangerouslySetInnerHTML: {
1575
1581
  __html: `window.${WINDOW_DATA_KEY} = ${serialized};`
1576
1582
  }
1583
+ }),
1584
+ import_react.default.createElement("script", {
1585
+ nonce,
1586
+ dangerouslySetInnerHTML: {
1587
+ __html: `window.${ROUTER_DATA_KEY} = ${routerSerialized};`
1588
+ }
1577
1589
  })
1578
1590
  );
1579
1591
  return documentTree;
@@ -1596,6 +1608,15 @@ function buildInitialData(urlPath, params, loaderResult) {
1596
1608
  };
1597
1609
  }
1598
1610
 
1611
+ // modules/rendering/routerData/index.ts
1612
+ var buildRouterData = (req) => {
1613
+ return {
1614
+ pathname: req.path,
1615
+ params: req.params,
1616
+ searchParams: req.query
1617
+ };
1618
+ };
1619
+
1599
1620
  // modules/build/ssg/renderer.ts
1600
1621
  init_globals();
1601
1622
  async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params) {
@@ -1649,10 +1670,12 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params)
1649
1670
  return;
1650
1671
  }
1651
1672
  const initialData = buildInitialData(urlPath, params, loaderResult);
1673
+ const routerData = buildRouterData(req);
1652
1674
  const appTree = buildAppTree(route, params, initialData.props);
1653
1675
  const documentTree = createDocumentTree({
1654
1676
  appTree,
1655
1677
  initialData,
1678
+ routerData,
1656
1679
  meta: loaderResult.metadata,
1657
1680
  titleFallback: "My Framework Dev",
1658
1681
  descriptionFallback: "Static page generated by @lolyjs/core.",
@@ -4454,6 +4477,7 @@ async function handlePageRequestInternal(options) {
4454
4477
  }
4455
4478
  }
4456
4479
  const matched = matchRoute(routes, urlPath);
4480
+ const routerData = buildRouterData(req);
4457
4481
  if (!matched) {
4458
4482
  if (notFoundPage) {
4459
4483
  const ctx2 = {
@@ -4474,6 +4498,7 @@ async function handlePageRequestInternal(options) {
4474
4498
  const documentTree2 = createDocumentTree({
4475
4499
  appTree: appTree2,
4476
4500
  initialData: initialData2,
4501
+ routerData,
4477
4502
  meta: loaderResult2.metadata ?? null,
4478
4503
  titleFallback: "Not found",
4479
4504
  descriptionFallback: "Loly demo",
@@ -4581,6 +4606,7 @@ async function handlePageRequestInternal(options) {
4581
4606
  const documentTree = createDocumentTree({
4582
4607
  appTree,
4583
4608
  initialData,
4609
+ routerData,
4584
4610
  meta: loaderResult.metadata,
4585
4611
  titleFallback: "Loly framework",
4586
4612
  descriptionFallback: "Loly demo",
@@ -4638,6 +4664,7 @@ async function renderErrorPageWithStream(errorPage, req, res, error, routeChunks
4638
4664
  loaderResult.theme = theme;
4639
4665
  }
4640
4666
  const initialData = buildInitialData(req.path, { error: String(error) }, loaderResult);
4667
+ const routerData = buildRouterData(req);
4641
4668
  initialData.error = true;
4642
4669
  if (isDataReq) {
4643
4670
  res.statusCode = 500;
@@ -4668,6 +4695,7 @@ async function renderErrorPageWithStream(errorPage, req, res, error, routeChunks
4668
4695
  const documentTree = createDocumentTree({
4669
4696
  appTree,
4670
4697
  initialData,
4698
+ routerData,
4671
4699
  meta: loaderResult.metadata ?? null,
4672
4700
  titleFallback: "Error",
4673
4701
  descriptionFallback: "An error occurred",