@lolyjs/core 0.1.0-alpha.3 → 0.1.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/index.cjs CHANGED
@@ -5499,14 +5499,19 @@ async function navigate(nextUrl, handlers, options) {
5499
5499
  }
5500
5500
  function createClickHandler(navigate2) {
5501
5501
  return function handleClick(ev) {
5502
+ const path25 = ev.composedPath();
5503
+ for (const element of path25) {
5504
+ if (!(element instanceof HTMLElement)) continue;
5505
+ const tagName = element.tagName.toLowerCase();
5506
+ if (tagName === "input" || tagName === "textarea" || tagName === "button" || tagName === "select" || element.isContentEditable || tagName === "label" && element.control) {
5507
+ return;
5508
+ }
5509
+ }
5510
+ const target = ev.target;
5511
+ if (!target) return;
5502
5512
  if (ev.defaultPrevented) return;
5503
5513
  if (ev.button !== 0) return;
5504
5514
  if (ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey) return;
5505
- const target = ev.target;
5506
- if (!target) return;
5507
- const tagName = target.tagName.toLowerCase();
5508
- const isInteractiveElement = tagName === "input" || tagName === "textarea" || tagName === "button" || tagName === "select" || target.isContentEditable || target.closest("input, textarea, button, select, [contenteditable]");
5509
- if (isInteractiveElement) return;
5510
5515
  const anchor = target.closest("a[href]");
5511
5516
  if (!anchor) return;
5512
5517
  const href = anchor.getAttribute("href");
@@ -5540,25 +5545,33 @@ function AppShell({
5540
5545
  errorRoute
5541
5546
  }) {
5542
5547
  const [state, setState] = (0, import_react2.useState)(initialState);
5548
+ const handlersRef = (0, import_react2.useRef)({
5549
+ setState,
5550
+ routes,
5551
+ notFoundRoute,
5552
+ errorRoute
5553
+ });
5543
5554
  (0, import_react2.useEffect)(() => {
5544
- const handlers = {
5555
+ handlersRef.current = {
5545
5556
  setState,
5546
5557
  routes,
5547
5558
  notFoundRoute,
5548
5559
  errorRoute
5549
5560
  };
5561
+ }, [routes, notFoundRoute, errorRoute]);
5562
+ (0, import_react2.useEffect)(() => {
5550
5563
  async function handleNavigate(nextUrl, options) {
5551
- await navigate(nextUrl, handlers, options);
5564
+ await navigate(nextUrl, handlersRef.current, options);
5552
5565
  }
5553
5566
  const handleClick = createClickHandler(handleNavigate);
5554
5567
  const handlePopState = createPopStateHandler(handleNavigate);
5555
- window.addEventListener("click", handleClick);
5556
- window.addEventListener("popstate", handlePopState);
5568
+ window.addEventListener("click", handleClick, { capture: false });
5569
+ window.addEventListener("popstate", handlePopState, { capture: false });
5557
5570
  return () => {
5558
- window.removeEventListener("click", handleClick);
5559
- window.removeEventListener("popstate", handlePopState);
5571
+ window.removeEventListener("click", handleClick, { capture: false });
5572
+ window.removeEventListener("popstate", handlePopState, { capture: false });
5560
5573
  };
5561
- }, [routes, notFoundRoute, errorRoute]);
5574
+ }, []);
5562
5575
  const isError = state.route === errorRoute;
5563
5576
  const isNotFound = state.route === notFoundRoute;
5564
5577
  const routeType = isError ? "error" : isNotFound ? "notfound" : "normal";