@lolyjs/core 0.1.0-alpha.5 → 0.1.0-alpha.8

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/runtime.cjs CHANGED
@@ -33,7 +33,8 @@ var APP_CONTAINER_ID = "__app";
33
33
 
34
34
  // modules/runtime/client/window-data.ts
35
35
  function getWindowData() {
36
- return window[WINDOW_DATA_KEY] ?? null;
36
+ var _a;
37
+ return (_a = window[WINDOW_DATA_KEY]) != null ? _a : null;
37
38
  }
38
39
  function setWindowData(data) {
39
40
  window[WINDOW_DATA_KEY] = data;
@@ -46,7 +47,8 @@ function setWindowData(data) {
46
47
  }
47
48
  }
48
49
  function getCurrentTheme() {
49
- return getWindowData()?.theme ?? null;
50
+ var _a, _b;
51
+ return (_b = (_a = getWindowData()) == null ? void 0 : _a.theme) != null ? _b : null;
50
52
  }
51
53
 
52
54
  // modules/runtime/client/route-matcher.ts
@@ -114,6 +116,11 @@ var import_react = require("react");
114
116
  // modules/runtime/client/RouterView.tsx
115
117
  var import_jsx_runtime = require("react/jsx-runtime");
116
118
  function RouterView({ state }) {
119
+ console.log("[loly:RouterView] Rendering", {
120
+ url: state.url,
121
+ hasRoute: !!state.route,
122
+ hasComponents: !!state.components
123
+ });
117
124
  if (!state.route) {
118
125
  if (state.components === null) {
119
126
  return null;
@@ -125,6 +132,11 @@ function RouterView({ state }) {
125
132
  }
126
133
  const { Page, layouts } = state.components;
127
134
  const { params, props } = state;
135
+ console.log("[loly:RouterView] Creating page element", {
136
+ hasPage: !!Page,
137
+ layoutsCount: layouts.length,
138
+ paramsKeys: Object.keys(params)
139
+ });
128
140
  let element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Page, { params, ...props });
129
141
  const layoutChain = layouts.slice().reverse();
130
142
  for (const Layout of layoutChain) {
@@ -193,7 +205,7 @@ function evictOldest() {
193
205
  }
194
206
  function setCacheEntry(key, entry) {
195
207
  const existingEntry = dataCache.get(key);
196
- const wasFulfilled = existingEntry?.status === "fulfilled";
208
+ const wasFulfilled = (existingEntry == null ? void 0 : existingEntry.status) === "fulfilled";
197
209
  dataCache.set(key, entry);
198
210
  if (entry.status === "fulfilled") {
199
211
  if (!wasFulfilled) {
@@ -247,7 +259,7 @@ async function fetchRouteDataOnce(url) {
247
259
  }
248
260
  async function getRouteData(url, options) {
249
261
  const key = buildDataUrl(url);
250
- if (options?.revalidate) {
262
+ if (options == null ? void 0 : options.revalidate) {
251
263
  deleteCacheEntry(key);
252
264
  }
253
265
  const entry = dataCache.get(key);
@@ -274,6 +286,7 @@ async function getRouteData(url, options) {
274
286
 
275
287
  // modules/runtime/client/navigation.ts
276
288
  async function handleErrorRoute(nextUrl, json, errorRoute, setState) {
289
+ var _a;
277
290
  try {
278
291
  const components = await errorRoute.load();
279
292
  let theme = "light";
@@ -300,7 +313,7 @@ async function handleErrorRoute(nextUrl, json, errorRoute, setState) {
300
313
  pathname: nextUrl,
301
314
  params: json.params || {},
302
315
  props: errorProps,
303
- metadata: json.metadata ?? null,
316
+ metadata: (_a = json.metadata) != null ? _a : null,
304
317
  theme,
305
318
  notFound: false,
306
319
  error: true
@@ -324,6 +337,7 @@ async function handleErrorRoute(nextUrl, json, errorRoute, setState) {
324
337
  }
325
338
  }
326
339
  async function handleNotFoundRoute(nextUrl, json, notFoundRoute, setState) {
340
+ var _a, _b;
327
341
  let theme = "light";
328
342
  if (typeof document !== "undefined") {
329
343
  const cookieMatch = document.cookie.match(/theme=([^;]+)/);
@@ -339,14 +353,14 @@ async function handleNotFoundRoute(nextUrl, json, notFoundRoute, setState) {
339
353
  theme = json.theme;
340
354
  }
341
355
  const notFoundProps = {
342
- ...json.props ?? {},
356
+ ...(_a = json.props) != null ? _a : {},
343
357
  theme
344
358
  };
345
359
  const windowData = {
346
360
  pathname: nextUrl,
347
361
  params: {},
348
362
  props: notFoundProps,
349
- metadata: json.metadata ?? null,
363
+ metadata: (_b = json.metadata) != null ? _b : null,
350
364
  theme,
351
365
  notFound: true,
352
366
  error: false
@@ -372,7 +386,8 @@ async function handleNotFoundRoute(nextUrl, json, notFoundRoute, setState) {
372
386
  }
373
387
  }
374
388
  async function handleNormalRoute(nextUrl, json, routes, setState) {
375
- applyMetadata(json.metadata ?? null);
389
+ var _a, _b, _c;
390
+ applyMetadata((_a = json.metadata) != null ? _a : null);
376
391
  let theme = "light";
377
392
  if (typeof document !== "undefined") {
378
393
  const cookieMatch = document.cookie.match(/theme=([^;]+)/);
@@ -390,7 +405,7 @@ async function handleNormalRoute(nextUrl, json, routes, setState) {
390
405
  theme = json.theme;
391
406
  }
392
407
  const newProps = {
393
- ...json.props ?? {},
408
+ ...(_b = json.props) != null ? _b : {},
394
409
  theme
395
410
  // Always include theme
396
411
  };
@@ -403,7 +418,7 @@ async function handleNormalRoute(nextUrl, json, routes, setState) {
403
418
  pathname: nextUrl,
404
419
  params: matched.params,
405
420
  props: newProps,
406
- metadata: json.metadata ?? null,
421
+ metadata: (_c = json.metadata) != null ? _c : null,
407
422
  theme,
408
423
  notFound: false,
409
424
  error: false
@@ -427,7 +442,7 @@ async function navigate(nextUrl, handlers, options) {
427
442
  const { setState, routes, notFoundRoute, errorRoute } = handlers;
428
443
  try {
429
444
  const { ok, json } = await getRouteData(nextUrl, {
430
- revalidate: options?.revalidate
445
+ revalidate: options == null ? void 0 : options.revalidate
431
446
  });
432
447
  if (json && json.error) {
433
448
  console.log("[client] Error detected in response:", json);
@@ -472,24 +487,50 @@ async function navigate(nextUrl, handlers, options) {
472
487
  }
473
488
  function createClickHandler(navigate2) {
474
489
  return function handleClick(ev) {
490
+ const target = ev.target;
491
+ const tagName = (target == null ? void 0 : target.tagName.toLowerCase()) || "unknown";
492
+ console.log("[loly:click] Click event received", {
493
+ type: ev.type,
494
+ tagName,
495
+ target: target == null ? void 0 : target.tagName,
496
+ defaultPrevented: ev.defaultPrevented,
497
+ button: ev.button,
498
+ clientX: ev.clientX,
499
+ clientY: ev.clientY
500
+ });
475
501
  try {
476
- if (ev.defaultPrevented) return;
477
- if (ev.type !== "click") return;
478
- if (ev.button !== 0) return;
479
- if (ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey) return;
502
+ if (ev.defaultPrevented) {
503
+ console.log("[loly:click] Event already prevented, skipping");
504
+ return;
505
+ }
506
+ if (ev.type !== "click") {
507
+ console.log("[loly:click] Not a click event, skipping", { type: ev.type });
508
+ return;
509
+ }
510
+ if (ev.button !== 0) {
511
+ console.log("[loly:click] Not left button, skipping", { button: ev.button });
512
+ return;
513
+ }
514
+ if (ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey) {
515
+ console.log("[loly:click] Modifier keys pressed, skipping");
516
+ return;
517
+ }
480
518
  if (ev.clientX === 0 && ev.clientY === 0 && ev.detail === 0) {
481
- const target2 = ev.target;
482
- if (target2) {
483
- const tagName2 = target2.tagName.toLowerCase();
484
- if (tagName2 === "input" || tagName2 === "textarea" || tagName2 === "button" || tagName2 === "select") {
519
+ if (target) {
520
+ const tagName3 = target.tagName.toLowerCase();
521
+ if (tagName3 === "input" || tagName3 === "textarea" || tagName3 === "button" || tagName3 === "select") {
522
+ console.log("[loly:click] Synthetic event on interactive element, skipping", { tagName: tagName3 });
485
523
  return;
486
524
  }
487
525
  }
488
526
  }
489
- const target = ev.target;
490
- if (!target) return;
491
- const tagName = target.tagName.toLowerCase();
492
- if (tagName === "input" || tagName === "textarea" || tagName === "button" || tagName === "select" || target.isContentEditable || target.getAttribute("contenteditable") === "true") {
527
+ if (!target) {
528
+ console.log("[loly:click] No target, skipping");
529
+ return;
530
+ }
531
+ const tagName2 = target.tagName.toLowerCase();
532
+ if (tagName2 === "input" || tagName2 === "textarea" || tagName2 === "button" || tagName2 === "select" || target.isContentEditable || target.getAttribute("contenteditable") === "true") {
533
+ console.log("[loly:click] Target is interactive element, skipping", { tagName: tagName2 });
493
534
  return;
494
535
  }
495
536
  const interactiveParent = target.closest("input, textarea, button, select, [contenteditable], label");
@@ -497,29 +538,60 @@ function createClickHandler(navigate2) {
497
538
  if (interactiveParent.tagName.toLowerCase() === "label") {
498
539
  const label = interactiveParent;
499
540
  if (label.control) {
541
+ console.log("[loly:click] Inside label with control, skipping");
500
542
  return;
501
543
  }
502
544
  } else {
545
+ console.log("[loly:click] Inside interactive parent, skipping", {
546
+ parentTag: interactiveParent.tagName.toLowerCase()
547
+ });
503
548
  return;
504
549
  }
505
550
  }
506
551
  const anchor = target.closest("a[href]");
507
- if (!anchor) return;
552
+ if (!anchor) {
553
+ console.log("[loly:click] No anchor found, skipping");
554
+ return;
555
+ }
556
+ console.log("[loly:click] Anchor found, processing navigation", {
557
+ href: anchor.getAttribute("href")
558
+ });
508
559
  const href = anchor.getAttribute("href");
509
- if (!href) return;
510
- if (href.startsWith("#")) return;
560
+ if (!href) {
561
+ console.log("[loly:click] No href attribute, skipping");
562
+ return;
563
+ }
564
+ if (href.startsWith("#")) {
565
+ console.log("[loly:click] Hash link, skipping");
566
+ return;
567
+ }
511
568
  const url = new URL(href, window.location.href);
512
- if (url.origin !== window.location.origin) return;
513
- if (anchor.target && anchor.target !== "_self") return;
569
+ if (url.origin !== window.location.origin) {
570
+ console.log("[loly:click] External link, skipping", { origin: url.origin });
571
+ return;
572
+ }
573
+ if (anchor.target && anchor.target !== "_self") {
574
+ console.log("[loly:click] Link has target, skipping", { target: anchor.target });
575
+ return;
576
+ }
514
577
  ev.preventDefault();
578
+ console.log("[loly:click] Prevented default, navigating");
515
579
  const nextUrl = url.pathname + url.search;
516
580
  const currentUrl = window.location.pathname + window.location.search;
517
- if (nextUrl === currentUrl) return;
581
+ if (nextUrl === currentUrl) {
582
+ console.log("[loly:click] Same URL, skipping", { nextUrl });
583
+ return;
584
+ }
518
585
  const shouldRevalidate = anchor.hasAttribute("data-revalidate") && anchor.getAttribute("data-revalidate") !== "false";
586
+ console.log("[loly:click] Pushing state and navigating", {
587
+ nextUrl,
588
+ currentUrl,
589
+ shouldRevalidate
590
+ });
519
591
  window.history.pushState({}, "", nextUrl);
520
592
  navigate2(nextUrl, shouldRevalidate ? { revalidate: true } : void 0);
521
593
  } catch (error) {
522
- console.error("[navigation] Error in click handler:", error);
594
+ console.error("[loly:click] Error in click handler:", error);
523
595
  }
524
596
  };
525
597
  }
@@ -538,6 +610,10 @@ function AppShell({
538
610
  notFoundRoute,
539
611
  errorRoute
540
612
  }) {
613
+ console.log("[loly:AppShell] Component rendering", {
614
+ url: initialState.url,
615
+ hasRoute: !!initialState.route
616
+ });
541
617
  const [state, setState] = (0, import_react.useState)(initialState);
542
618
  const handlersRef = (0, import_react.useRef)({
543
619
  setState,
@@ -546,6 +622,11 @@ function AppShell({
546
622
  errorRoute
547
623
  });
548
624
  (0, import_react.useEffect)(() => {
625
+ console.log("[loly:AppShell] Updating handlersRef", {
626
+ routesCount: routes.length,
627
+ hasNotFound: !!notFoundRoute,
628
+ hasError: !!errorRoute
629
+ });
549
630
  handlersRef.current = {
550
631
  setState,
551
632
  routes,
@@ -554,16 +635,34 @@ function AppShell({
554
635
  };
555
636
  }, [routes, notFoundRoute, errorRoute]);
556
637
  (0, import_react.useEffect)(() => {
638
+ const effectId = Math.random().toString(36).substring(7);
639
+ console.log("[loly:AppShell] Setting up event listeners", { effectId });
557
640
  let isMounted = true;
641
+ let listenerCount = 0;
558
642
  async function handleNavigate(nextUrl, options) {
559
- if (!isMounted) return;
643
+ if (!isMounted) {
644
+ console.warn("[loly:AppShell] navigate called but component is unmounted");
645
+ return;
646
+ }
647
+ console.log("[loly:AppShell] Navigating to", nextUrl, options);
560
648
  await navigate(nextUrl, handlersRef.current, options);
561
649
  }
562
650
  const handleClick = createClickHandler(handleNavigate);
563
651
  const handlePopState = createPopStateHandler(handleNavigate);
564
652
  window.addEventListener("click", handleClick, false);
565
653
  window.addEventListener("popstate", handlePopState, false);
654
+ listenerCount = 2;
655
+ console.log("[loly:AppShell] Event listeners added", {
656
+ clickListener: true,
657
+ popStateListener: true,
658
+ totalListeners: listenerCount
659
+ });
566
660
  return () => {
661
+ console.log("[loly:AppShell] Cleaning up event listeners", {
662
+ effectId,
663
+ wasMounted: isMounted,
664
+ listenersToRemove: listenerCount
665
+ });
567
666
  isMounted = false;
568
667
  window.removeEventListener("click", handleClick, false);
569
668
  window.removeEventListener("popstate", handlePopState, false);
@@ -579,14 +678,15 @@ function AppShell({
579
678
  // modules/runtime/client/bootstrap.tsx
580
679
  var import_jsx_runtime3 = require("react/jsx-runtime");
581
680
  async function loadInitialRoute(initialUrl, initialData, routes, notFoundRoute, errorRoute) {
582
- const isInitialNotFound = initialData?.notFound === true;
583
- const isInitialError = initialData?.error === true;
681
+ var _a, _b;
682
+ const isInitialNotFound = (initialData == null ? void 0 : initialData.notFound) === true;
683
+ const isInitialError = (initialData == null ? void 0 : initialData.error) === true;
584
684
  let initialRoute = null;
585
685
  let initialParams = {};
586
686
  let initialComponents = null;
587
687
  if (isInitialError && errorRoute) {
588
688
  initialRoute = errorRoute;
589
- initialParams = initialData?.params ?? {};
689
+ initialParams = (_a = initialData == null ? void 0 : initialData.params) != null ? _a : {};
590
690
  initialComponents = await errorRoute.load();
591
691
  } else if (isInitialNotFound && notFoundRoute) {
592
692
  initialRoute = notFoundRoute;
@@ -614,18 +714,29 @@ async function loadInitialRoute(initialUrl, initialData, routes, notFoundRoute,
614
714
  route: initialRoute,
615
715
  params: initialParams,
616
716
  components: initialComponents,
617
- props: initialData?.props ?? {}
717
+ props: (_b = initialData == null ? void 0 : initialData.props) != null ? _b : {}
618
718
  };
619
719
  }
620
720
  function bootstrapClient(routes, notFoundRoute, errorRoute = null) {
721
+ console.log("[loly:runtime] bootstrapClient called", {
722
+ routesCount: routes.length,
723
+ hasNotFound: !!notFoundRoute,
724
+ hasError: !!errorRoute
725
+ });
621
726
  (async function bootstrap() {
622
727
  const container = document.getElementById(APP_CONTAINER_ID);
623
728
  const initialData = getWindowData();
729
+ console.log("[loly:runtime] bootstrap starting", {
730
+ hasContainer: !!container,
731
+ containerId: APP_CONTAINER_ID,
732
+ hasInitialData: !!initialData
733
+ });
624
734
  if (!container) {
625
- console.error(`Container #${APP_CONTAINER_ID} not found for hydration`);
735
+ console.error(`[loly:runtime] Container #${APP_CONTAINER_ID} not found for hydration`);
626
736
  return;
627
737
  }
628
738
  const initialUrl = window.location.pathname + window.location.search;
739
+ console.log("[loly:runtime] Loading initial route", { initialUrl });
629
740
  try {
630
741
  const initialState = await loadInitialRoute(
631
742
  initialUrl,
@@ -634,9 +745,15 @@ function bootstrapClient(routes, notFoundRoute, errorRoute = null) {
634
745
  notFoundRoute,
635
746
  errorRoute
636
747
  );
637
- if (initialData?.metadata) {
748
+ console.log("[loly:runtime] Initial route loaded", {
749
+ url: initialState.url,
750
+ hasRoute: !!initialState.route,
751
+ hasComponents: !!initialState.components
752
+ });
753
+ if (initialData == null ? void 0 : initialData.metadata) {
638
754
  applyMetadata(initialData.metadata);
639
755
  }
756
+ console.log("[loly:runtime] Hydrating React app");
640
757
  (0, import_client.hydrateRoot)(
641
758
  container,
642
759
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
@@ -649,9 +766,10 @@ function bootstrapClient(routes, notFoundRoute, errorRoute = null) {
649
766
  }
650
767
  )
651
768
  );
769
+ console.log("[loly:runtime] React app hydrated successfully");
652
770
  } catch (error) {
653
771
  console.error(
654
- "[client] Error loading initial route components for",
772
+ "[loly:runtime] Error loading initial route components for",
655
773
  initialUrl,
656
774
  error
657
775
  );
@@ -659,8 +777,4 @@ function bootstrapClient(routes, notFoundRoute, errorRoute = null) {
659
777
  }
660
778
  })();
661
779
  }
662
- // Annotate the CommonJS export names for ESM import in node:
663
- 0 && (module.exports = {
664
- bootstrapClient
665
- });
666
780
  //# sourceMappingURL=runtime.cjs.map