@lolyjs/core 0.1.0-alpha.1 → 0.1.0-alpha.11

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/index.cjs CHANGED
@@ -3508,7 +3508,7 @@ function createLogger(options = {}) {
3508
3508
  const baseConfig = {
3509
3509
  level,
3510
3510
  base: {
3511
- name: "@loly/core",
3511
+ name: "@lolyjs/core",
3512
3512
  env: process.env.NODE_ENV || "development"
3513
3513
  },
3514
3514
  timestamp: import_pino.default.stdTimeFunctions.isoTime,
@@ -4868,7 +4868,7 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params)
4868
4868
  initialData,
4869
4869
  meta: loaderResult.metadata,
4870
4870
  titleFallback: "My Framework Dev",
4871
- descriptionFallback: "Static page generated by @loly/core.",
4871
+ descriptionFallback: "Static page generated by @lolyjs/core.",
4872
4872
  chunkHref,
4873
4873
  clientJsPath,
4874
4874
  clientCssPath
@@ -5457,7 +5457,6 @@ async function navigate(nextUrl, handlers, options) {
5457
5457
  revalidate: options?.revalidate
5458
5458
  });
5459
5459
  if (json && json.error) {
5460
- console.log("[client] Error detected in response:", json);
5461
5460
  if (errorRoute) {
5462
5461
  const handled = await handleErrorRoute(
5463
5462
  nextUrl,
@@ -5499,26 +5498,54 @@ async function navigate(nextUrl, handlers, options) {
5499
5498
  }
5500
5499
  function createClickHandler(navigate2) {
5501
5500
  return function handleClick(ev) {
5502
- if (ev.defaultPrevented) return;
5503
- if (ev.button !== 0) return;
5504
- if (ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey) return;
5505
- const target = ev.target;
5506
- if (!target) return;
5507
- const anchor = target.closest("a[href]");
5508
- if (!anchor) return;
5509
- const href = anchor.getAttribute("href");
5510
- if (!href) return;
5511
- if (href.startsWith("#")) return;
5512
- const url = new URL(href, window.location.href);
5513
- if (url.origin !== window.location.origin) return;
5514
- if (anchor.target && anchor.target !== "_self") return;
5515
- ev.preventDefault();
5516
- const nextUrl = url.pathname + url.search;
5517
- const currentUrl = window.location.pathname + window.location.search;
5518
- if (nextUrl === currentUrl) return;
5519
- const shouldRevalidate = anchor.hasAttribute("data-revalidate") && anchor.getAttribute("data-revalidate") !== "false";
5520
- window.history.pushState({}, "", nextUrl);
5521
- navigate2(nextUrl, shouldRevalidate ? { revalidate: true } : void 0);
5501
+ try {
5502
+ if (ev.defaultPrevented) return;
5503
+ if (ev.type !== "click") return;
5504
+ if (ev.button !== 0) return;
5505
+ if (ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey) return;
5506
+ const target = ev.target;
5507
+ if (ev.clientX === 0 && ev.clientY === 0 && ev.detail === 0) {
5508
+ if (target) {
5509
+ const tagName2 = target.tagName.toLowerCase();
5510
+ if (tagName2 === "input" || tagName2 === "textarea" || tagName2 === "button" || tagName2 === "select") {
5511
+ return;
5512
+ }
5513
+ }
5514
+ }
5515
+ if (!target) return;
5516
+ const tagName = target.tagName.toLowerCase();
5517
+ if (tagName === "input" || tagName === "textarea" || tagName === "button" || tagName === "select" || target.isContentEditable || target.getAttribute("contenteditable") === "true") {
5518
+ return;
5519
+ }
5520
+ const interactiveParent = target.closest("input, textarea, button, select, [contenteditable], label");
5521
+ if (interactiveParent) {
5522
+ if (interactiveParent.tagName.toLowerCase() === "label") {
5523
+ const label = interactiveParent;
5524
+ if (label.control) {
5525
+ return;
5526
+ }
5527
+ } else {
5528
+ return;
5529
+ }
5530
+ }
5531
+ const anchor = target.closest("a[href]");
5532
+ if (!anchor) return;
5533
+ const href = anchor.getAttribute("href");
5534
+ if (!href) return;
5535
+ if (href.startsWith("#")) return;
5536
+ const url = new URL(href, window.location.href);
5537
+ if (url.origin !== window.location.origin) return;
5538
+ if (anchor.target && anchor.target !== "_self") return;
5539
+ ev.preventDefault();
5540
+ const nextUrl = url.pathname + url.search;
5541
+ const currentUrl = window.location.pathname + window.location.search;
5542
+ if (nextUrl === currentUrl) return;
5543
+ const shouldRevalidate = anchor.hasAttribute("data-revalidate") && anchor.getAttribute("data-revalidate") !== "false";
5544
+ window.history.pushState({}, "", nextUrl);
5545
+ navigate2(nextUrl, shouldRevalidate ? { revalidate: true } : void 0);
5546
+ } catch (error) {
5547
+ console.error("[navigation] Error in click handler:", error);
5548
+ }
5522
5549
  };
5523
5550
  }
5524
5551
  function createPopStateHandler(navigate2) {
@@ -5537,25 +5564,36 @@ function AppShell({
5537
5564
  errorRoute
5538
5565
  }) {
5539
5566
  const [state, setState] = (0, import_react2.useState)(initialState);
5567
+ const handlersRef = (0, import_react2.useRef)({
5568
+ setState,
5569
+ routes,
5570
+ notFoundRoute,
5571
+ errorRoute
5572
+ });
5540
5573
  (0, import_react2.useEffect)(() => {
5541
- const handlers = {
5574
+ handlersRef.current = {
5542
5575
  setState,
5543
5576
  routes,
5544
5577
  notFoundRoute,
5545
5578
  errorRoute
5546
5579
  };
5580
+ }, [routes, notFoundRoute, errorRoute]);
5581
+ (0, import_react2.useEffect)(() => {
5582
+ let isMounted = true;
5547
5583
  async function handleNavigate(nextUrl, options) {
5548
- await navigate(nextUrl, handlers, options);
5584
+ if (!isMounted) return;
5585
+ await navigate(nextUrl, handlersRef.current, options);
5549
5586
  }
5550
5587
  const handleClick = createClickHandler(handleNavigate);
5551
5588
  const handlePopState = createPopStateHandler(handleNavigate);
5552
- window.addEventListener("click", handleClick);
5553
- window.addEventListener("popstate", handlePopState);
5589
+ window.addEventListener("click", handleClick, false);
5590
+ window.addEventListener("popstate", handlePopState, false);
5554
5591
  return () => {
5555
- window.removeEventListener("click", handleClick);
5556
- window.removeEventListener("popstate", handlePopState);
5592
+ isMounted = false;
5593
+ window.removeEventListener("click", handleClick, false);
5594
+ window.removeEventListener("popstate", handlePopState, false);
5557
5595
  };
5558
- }, [routes, notFoundRoute, errorRoute]);
5596
+ }, []);
5559
5597
  const isError = state.route === errorRoute;
5560
5598
  const isNotFound = state.route === notFoundRoute;
5561
5599
  const routeType = isError ? "error" : isNotFound ? "notfound" : "normal";