@supernal/interface-nextjs 1.0.24 → 1.0.25

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.js CHANGED
@@ -4144,8 +4144,15 @@ var import_browser6 = require("@supernal/interface/browser");
4144
4144
 
4145
4145
  // src/hooks/useLocationTracking.ts
4146
4146
  var import_react14 = require("react");
4147
- var import_router = require("next/router");
4148
4147
  var import_browser4 = require("@supernal/interface/browser");
4148
+ var usePathname;
4149
+ var useSearchParams;
4150
+ try {
4151
+ const navigation = require("next/navigation");
4152
+ usePathname = navigation.usePathname;
4153
+ useSearchParams = navigation.useSearchParams;
4154
+ } catch {
4155
+ }
4149
4156
  function getVisibleElements() {
4150
4157
  if (typeof document === "undefined") return [];
4151
4158
  const elements = document.querySelectorAll("[data-testid]");
@@ -4157,77 +4164,126 @@ function arraysEqual(a, b) {
4157
4164
  const sortedB = [...b].sort();
4158
4165
  return sortedA.every((val, idx) => val === sortedB[idx]);
4159
4166
  }
4167
+ function getCurrentLocation() {
4168
+ if (typeof window === "undefined") {
4169
+ return { pathname: "/", search: "", asPath: "/" };
4170
+ }
4171
+ return {
4172
+ pathname: window.location.pathname,
4173
+ search: window.location.search,
4174
+ asPath: window.location.pathname + window.location.search
4175
+ };
4176
+ }
4160
4177
  function useLocationTracking() {
4161
- const router = (0, import_router.useRouter)();
4162
4178
  const lastLocationRef = (0, import_react14.useRef)("");
4163
4179
  const lastElementsRef = (0, import_react14.useRef)([]);
4180
+ let pathname = null;
4181
+ let searchParams = null;
4182
+ try {
4183
+ if (usePathname) {
4184
+ pathname = usePathname();
4185
+ }
4186
+ if (useSearchParams) {
4187
+ searchParams = useSearchParams();
4188
+ }
4189
+ } catch {
4190
+ }
4164
4191
  (0, import_react14.useEffect)(() => {
4165
4192
  const updateLocation = () => {
4193
+ const location = pathname !== null ? { pathname, search: searchParams?.toString() || "", asPath: pathname + (searchParams?.toString() ? `?${searchParams.toString()}` : "") } : getCurrentLocation();
4166
4194
  const visibleElements = getVisibleElements();
4167
- const locationChanged = lastLocationRef.current !== router.pathname;
4195
+ const locationChanged = lastLocationRef.current !== location.pathname;
4168
4196
  const elementsChanged = !arraysEqual(lastElementsRef.current, visibleElements);
4169
4197
  if (locationChanged || elementsChanged) {
4170
4198
  import_browser4.LocationContext.setCurrent({
4171
- page: router.pathname,
4172
- route: router.route,
4199
+ page: location.pathname,
4200
+ route: location.pathname,
4173
4201
  elements: visibleElements,
4174
4202
  metadata: {
4175
- query: router.query,
4176
- asPath: router.asPath
4203
+ search: location.search,
4204
+ asPath: location.asPath
4177
4205
  }
4178
4206
  });
4179
4207
  if (locationChanged) {
4180
- console.log(`[LocationTracking] Updated location: ${router.pathname}`);
4208
+ console.log(`[LocationTracking] Updated location: ${location.pathname}`);
4181
4209
  }
4182
4210
  if (elementsChanged) {
4183
4211
  console.log(`[LocationTracking] Visible elements changed: ${visibleElements.length} elements`);
4184
4212
  }
4185
- lastLocationRef.current = router.pathname;
4213
+ lastLocationRef.current = location.pathname;
4186
4214
  lastElementsRef.current = visibleElements;
4187
4215
  }
4188
4216
  };
4189
4217
  const initialTimer = setTimeout(updateLocation, 100);
4190
4218
  const intervalId = setInterval(updateLocation, 1e3);
4191
- const handleRouteChange = () => {
4219
+ const handleNavigation = () => {
4192
4220
  setTimeout(updateLocation, 100);
4193
4221
  };
4194
- router.events.on("routeChangeComplete", handleRouteChange);
4222
+ window.addEventListener("popstate", handleNavigation);
4195
4223
  return () => {
4196
4224
  clearTimeout(initialTimer);
4197
4225
  clearInterval(intervalId);
4198
- router.events.off("routeChangeComplete", handleRouteChange);
4226
+ window.removeEventListener("popstate", handleNavigation);
4199
4227
  };
4200
- }, [router.pathname, router.route, router.asPath]);
4228
+ }, [pathname, searchParams]);
4201
4229
  }
4202
4230
 
4203
4231
  // src/hooks/useNavigationGraphSetup.ts
4204
4232
  var import_react15 = require("react");
4205
- var import_router2 = require("next/router");
4233
+ var useAppRouter;
4234
+ var usePathname2;
4235
+ try {
4236
+ const navigation = require("next/navigation");
4237
+ useAppRouter = navigation.useRouter;
4238
+ usePathname2 = navigation.usePathname;
4239
+ } catch {
4240
+ }
4206
4241
  function useNavigationGraphSetup() {
4207
- const router = (0, import_router2.useRouter)();
4208
4242
  const [isInitialized, setIsInitialized] = (0, import_react15.useState)(false);
4243
+ let router = null;
4244
+ let pathname = null;
4245
+ try {
4246
+ if (useAppRouter) {
4247
+ router = useAppRouter();
4248
+ }
4249
+ if (usePathname2) {
4250
+ pathname = usePathname2();
4251
+ }
4252
+ } catch {
4253
+ }
4254
+ const navigate = (0, import_react15.useCallback)((path) => {
4255
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
4256
+ if (router?.push) {
4257
+ router.push(normalizedPath);
4258
+ } else if (typeof window !== "undefined") {
4259
+ window.location.href = normalizedPath;
4260
+ }
4261
+ }, [router]);
4262
+ const currentPath = pathname ?? (typeof window !== "undefined" ? window.location.pathname + window.location.search : "/");
4209
4263
  (0, import_react15.useEffect)(() => {
4210
4264
  import("@supernal/interface/browser").then(({ NavigationGraph: NavigationGraph2 }) => {
4211
4265
  const graph = NavigationGraph2.getInstance();
4212
- const handler = (path) => {
4213
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
4214
- router.push(normalizedPath);
4266
+ graph.setNavigationHandler(navigate);
4267
+ const browserRouter = {
4268
+ push: navigate,
4269
+ back: () => router?.back?.() ?? window.history.back(),
4270
+ forward: () => router?.forward?.() ?? window.history.forward(),
4271
+ refresh: () => router?.refresh?.() ?? window.location.reload()
4215
4272
  };
4216
- graph.setNavigationHandler(handler);
4217
- graph.setRouter(router);
4218
- graph.setCurrentContext(router.asPath);
4273
+ graph.setRouter(browserRouter);
4274
+ graph.setCurrentContext(currentPath);
4219
4275
  setIsInitialized(true);
4220
4276
  console.log("[NavigationGraphSetup] Auto-configured with Next.js router");
4221
4277
  });
4222
- }, [router]);
4278
+ }, [navigate, currentPath]);
4223
4279
  (0, import_react15.useEffect)(() => {
4224
4280
  if (!isInitialized) return;
4225
4281
  import("@supernal/interface/browser").then(({ NavigationGraph: NavigationGraph2 }) => {
4226
4282
  const graph = NavigationGraph2.getInstance();
4227
- graph.setCurrentContext(router.asPath);
4228
- console.log(`[NavigationGraphSetup] Context updated: ${router.asPath}`);
4283
+ graph.setCurrentContext(currentPath);
4284
+ console.log(`[NavigationGraphSetup] Context updated: ${currentPath}`);
4229
4285
  });
4230
- }, [router.asPath, isInitialized]);
4286
+ }, [currentPath, isInitialized]);
4231
4287
  }
4232
4288
 
4233
4289
  // src/components/ToolMenuPopup/ToolMenuPopup.tsx
package/dist/index.mjs CHANGED
@@ -4090,8 +4090,15 @@ import { ExposureCollector, ToolRegistry as ToolRegistry3 } from "@supernal/inte
4090
4090
 
4091
4091
  // src/hooks/useLocationTracking.ts
4092
4092
  import { useEffect as useEffect10, useRef as useRef9 } from "react";
4093
- import { useRouter } from "next/router";
4094
4093
  import { LocationContext } from "@supernal/interface/browser";
4094
+ var usePathname;
4095
+ var useSearchParams;
4096
+ try {
4097
+ const navigation = __require("next/navigation");
4098
+ usePathname = navigation.usePathname;
4099
+ useSearchParams = navigation.useSearchParams;
4100
+ } catch {
4101
+ }
4095
4102
  function getVisibleElements() {
4096
4103
  if (typeof document === "undefined") return [];
4097
4104
  const elements = document.querySelectorAll("[data-testid]");
@@ -4103,77 +4110,126 @@ function arraysEqual(a, b) {
4103
4110
  const sortedB = [...b].sort();
4104
4111
  return sortedA.every((val, idx) => val === sortedB[idx]);
4105
4112
  }
4113
+ function getCurrentLocation() {
4114
+ if (typeof window === "undefined") {
4115
+ return { pathname: "/", search: "", asPath: "/" };
4116
+ }
4117
+ return {
4118
+ pathname: window.location.pathname,
4119
+ search: window.location.search,
4120
+ asPath: window.location.pathname + window.location.search
4121
+ };
4122
+ }
4106
4123
  function useLocationTracking() {
4107
- const router = useRouter();
4108
4124
  const lastLocationRef = useRef9("");
4109
4125
  const lastElementsRef = useRef9([]);
4126
+ let pathname = null;
4127
+ let searchParams = null;
4128
+ try {
4129
+ if (usePathname) {
4130
+ pathname = usePathname();
4131
+ }
4132
+ if (useSearchParams) {
4133
+ searchParams = useSearchParams();
4134
+ }
4135
+ } catch {
4136
+ }
4110
4137
  useEffect10(() => {
4111
4138
  const updateLocation = () => {
4139
+ const location = pathname !== null ? { pathname, search: searchParams?.toString() || "", asPath: pathname + (searchParams?.toString() ? `?${searchParams.toString()}` : "") } : getCurrentLocation();
4112
4140
  const visibleElements = getVisibleElements();
4113
- const locationChanged = lastLocationRef.current !== router.pathname;
4141
+ const locationChanged = lastLocationRef.current !== location.pathname;
4114
4142
  const elementsChanged = !arraysEqual(lastElementsRef.current, visibleElements);
4115
4143
  if (locationChanged || elementsChanged) {
4116
4144
  LocationContext.setCurrent({
4117
- page: router.pathname,
4118
- route: router.route,
4145
+ page: location.pathname,
4146
+ route: location.pathname,
4119
4147
  elements: visibleElements,
4120
4148
  metadata: {
4121
- query: router.query,
4122
- asPath: router.asPath
4149
+ search: location.search,
4150
+ asPath: location.asPath
4123
4151
  }
4124
4152
  });
4125
4153
  if (locationChanged) {
4126
- console.log(`[LocationTracking] Updated location: ${router.pathname}`);
4154
+ console.log(`[LocationTracking] Updated location: ${location.pathname}`);
4127
4155
  }
4128
4156
  if (elementsChanged) {
4129
4157
  console.log(`[LocationTracking] Visible elements changed: ${visibleElements.length} elements`);
4130
4158
  }
4131
- lastLocationRef.current = router.pathname;
4159
+ lastLocationRef.current = location.pathname;
4132
4160
  lastElementsRef.current = visibleElements;
4133
4161
  }
4134
4162
  };
4135
4163
  const initialTimer = setTimeout(updateLocation, 100);
4136
4164
  const intervalId = setInterval(updateLocation, 1e3);
4137
- const handleRouteChange = () => {
4165
+ const handleNavigation = () => {
4138
4166
  setTimeout(updateLocation, 100);
4139
4167
  };
4140
- router.events.on("routeChangeComplete", handleRouteChange);
4168
+ window.addEventListener("popstate", handleNavigation);
4141
4169
  return () => {
4142
4170
  clearTimeout(initialTimer);
4143
4171
  clearInterval(intervalId);
4144
- router.events.off("routeChangeComplete", handleRouteChange);
4172
+ window.removeEventListener("popstate", handleNavigation);
4145
4173
  };
4146
- }, [router.pathname, router.route, router.asPath]);
4174
+ }, [pathname, searchParams]);
4147
4175
  }
4148
4176
 
4149
4177
  // src/hooks/useNavigationGraphSetup.ts
4150
- import { useEffect as useEffect11, useState as useState11 } from "react";
4151
- import { useRouter as useRouter2 } from "next/router";
4178
+ import { useEffect as useEffect11, useState as useState11, useCallback as useCallback7 } from "react";
4179
+ var useAppRouter;
4180
+ var usePathname2;
4181
+ try {
4182
+ const navigation = __require("next/navigation");
4183
+ useAppRouter = navigation.useRouter;
4184
+ usePathname2 = navigation.usePathname;
4185
+ } catch {
4186
+ }
4152
4187
  function useNavigationGraphSetup() {
4153
- const router = useRouter2();
4154
4188
  const [isInitialized, setIsInitialized] = useState11(false);
4189
+ let router = null;
4190
+ let pathname = null;
4191
+ try {
4192
+ if (useAppRouter) {
4193
+ router = useAppRouter();
4194
+ }
4195
+ if (usePathname2) {
4196
+ pathname = usePathname2();
4197
+ }
4198
+ } catch {
4199
+ }
4200
+ const navigate = useCallback7((path) => {
4201
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
4202
+ if (router?.push) {
4203
+ router.push(normalizedPath);
4204
+ } else if (typeof window !== "undefined") {
4205
+ window.location.href = normalizedPath;
4206
+ }
4207
+ }, [router]);
4208
+ const currentPath = pathname ?? (typeof window !== "undefined" ? window.location.pathname + window.location.search : "/");
4155
4209
  useEffect11(() => {
4156
4210
  import("@supernal/interface/browser").then(({ NavigationGraph: NavigationGraph2 }) => {
4157
4211
  const graph = NavigationGraph2.getInstance();
4158
- const handler = (path) => {
4159
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
4160
- router.push(normalizedPath);
4212
+ graph.setNavigationHandler(navigate);
4213
+ const browserRouter = {
4214
+ push: navigate,
4215
+ back: () => router?.back?.() ?? window.history.back(),
4216
+ forward: () => router?.forward?.() ?? window.history.forward(),
4217
+ refresh: () => router?.refresh?.() ?? window.location.reload()
4161
4218
  };
4162
- graph.setNavigationHandler(handler);
4163
- graph.setRouter(router);
4164
- graph.setCurrentContext(router.asPath);
4219
+ graph.setRouter(browserRouter);
4220
+ graph.setCurrentContext(currentPath);
4165
4221
  setIsInitialized(true);
4166
4222
  console.log("[NavigationGraphSetup] Auto-configured with Next.js router");
4167
4223
  });
4168
- }, [router]);
4224
+ }, [navigate, currentPath]);
4169
4225
  useEffect11(() => {
4170
4226
  if (!isInitialized) return;
4171
4227
  import("@supernal/interface/browser").then(({ NavigationGraph: NavigationGraph2 }) => {
4172
4228
  const graph = NavigationGraph2.getInstance();
4173
- graph.setCurrentContext(router.asPath);
4174
- console.log(`[NavigationGraphSetup] Context updated: ${router.asPath}`);
4229
+ graph.setCurrentContext(currentPath);
4230
+ console.log(`[NavigationGraphSetup] Context updated: ${currentPath}`);
4175
4231
  });
4176
- }, [router.asPath, isInitialized]);
4232
+ }, [currentPath, isInitialized]);
4177
4233
  }
4178
4234
 
4179
4235
  // src/components/ToolMenuPopup/ToolMenuPopup.tsx
@@ -4405,7 +4461,7 @@ var ToolMenuPopup = ({
4405
4461
  import { useEffect as useEffect13 } from "react";
4406
4462
 
4407
4463
  // src/components/ToolMenuPopup/useToolMenu.ts
4408
- import { useState as useState13, useMemo as useMemo4, useCallback as useCallback7 } from "react";
4464
+ import { useState as useState13, useMemo as useMemo4, useCallback as useCallback8 } from "react";
4409
4465
  import { ToolRegistry as ToolRegistry2 } from "@supernal/interface/browser";
4410
4466
  var CATEGORY_DISPLAY = {
4411
4467
  navigation: "Navigation",
@@ -4427,9 +4483,9 @@ var CATEGORY_DISPLAY = {
4427
4483
  };
4428
4484
  function useToolMenu() {
4429
4485
  const [isOpen, setIsOpen] = useState13(false);
4430
- const open = useCallback7(() => setIsOpen(true), []);
4431
- const close = useCallback7(() => setIsOpen(false), []);
4432
- const toggle = useCallback7(() => setIsOpen((prev) => !prev), []);
4486
+ const open = useCallback8(() => setIsOpen(true), []);
4487
+ const close = useCallback8(() => setIsOpen(false), []);
4488
+ const toggle = useCallback8(() => setIsOpen((prev) => !prev), []);
4433
4489
  const { categories, totalTools, contextLabel } = useMemo4(() => {
4434
4490
  if (!isOpen) {
4435
4491
  return { categories: [], totalTools: 0, contextLabel: "" };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supernal/interface-nextjs",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "Next.js integration for Supernal Intelligence Interface - enables agentic UX with one line of code",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",