@qontinui/ui-bridge-native 0.6.15 → 0.6.16

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.mjs CHANGED
@@ -311,6 +311,13 @@ function computeVisibility(state, clip) {
311
311
  const onScreen = spansOverlap(rect.left, rect.right, clip.left, clip.right) && spansOverlap(rect.top, rect.bottom, clip.top, clip.bottom);
312
312
  return onScreen ? { visibility: "visible" } : { visibility: "hidden", visibilityReason: "off-screen" };
313
313
  }
314
+ function copyRouteInfo(info) {
315
+ const copy = { ...info };
316
+ if (info.params) copy.params = { ...info.params };
317
+ if (info.queryParams) copy.queryParams = { ...info.queryParams };
318
+ if (info.routeStack) copy.routeStack = [...info.routeStack];
319
+ return copy;
320
+ }
314
321
  function inferActions(type, scrollAncestorId) {
315
322
  const baseActions = scrollAncestorId ? ["focus", "blur", "scrollIntoView"] : ["focus", "blur"];
316
323
  switch (type) {
@@ -375,6 +382,16 @@ var NativeUIBridgeRegistry = class {
375
382
  * already installs.
376
383
  */
377
384
  this.routeProvider = null;
385
+ /**
386
+ * The route TEMPLATE the app last reported through `useRouteAwareness`
387
+ * (via {@link setRouteInfo}), emitted on every snapshot as `page.route`.
388
+ *
389
+ * Deliberately NOT named `routeInfo`: `createSnapshot`'s parameter of that
390
+ * name is the CONCRETE `{currentRoute, segments, activeTab}` read from the
391
+ * route provider. The two must never be confused — the concrete path is
392
+ * user input, and this slot is the router-asserted template.
393
+ */
394
+ this.reportedRoute = void 0;
378
395
  /**
379
396
  * Device pixel ratio used to project `state.layout` (logical dp) into the
380
397
  * physical-pixel `bbox` emitted on each snapshot element. Defaults to `1`
@@ -433,6 +450,22 @@ var NativeUIBridgeRegistry = class {
433
450
  getRouteProvider() {
434
451
  return this.routeProvider;
435
452
  }
453
+ /**
454
+ * Set the route info emitted as `page.route` on every snapshot — the
455
+ * router-asserted TEMPLATE, normally reported by `useRouteAwareness`.
456
+ * Pass `undefined` to clear it (the hook does so on unmount), after which
457
+ * snapshots omit `page` again.
458
+ *
459
+ * The value is copied, so a later mutation by the caller cannot alter what
460
+ * is stored or what an already-emitted snapshot holds.
461
+ */
462
+ setRouteInfo(info) {
463
+ this.reportedRoute = info ? copyRouteInfo(info) : void 0;
464
+ }
465
+ /** Read-only accessor for the reported route info, if any (a copy). */
466
+ getRouteInfo() {
467
+ return this.reportedRoute ? copyRouteInfo(this.reportedRoute) : void 0;
468
+ }
436
469
  /**
437
470
  * Resolve the snapshot's `activeTab`: an explicit `getActiveTab()` on the
438
471
  * route provider wins, otherwise derive it from the Expo Router segments the
@@ -1273,6 +1306,12 @@ var NativeUIBridgeRegistry = class {
1273
1306
  // hosts that wire no route provider.
1274
1307
  ...resolvedRoute.currentRoute ? { route: resolvedRoute.currentRoute } : {},
1275
1308
  ...resolvedRoute.activeTab ? { activeTab: resolvedRoute.activeTab } : {},
1309
+ // The router-asserted route TEMPLATE, spelled as the web SDK's
1310
+ // `snapshot.page.route`. Emitted on the ONE assembly point both route
1311
+ // branches above share (the explicit-`routeInfo` branch the server's
1312
+ // `getSnapshot` override uses, and the provider fallback). Omitted, not
1313
+ // nulled, when unset — the same convention as the aliases above.
1314
+ ...this.reportedRoute ? { page: { route: copyRouteInfo(this.reportedRoute) } } : {},
1276
1315
  registration: this.getRegistrationCoverage()
1277
1316
  };
1278
1317
  if (this.appInfo) {
@@ -1319,6 +1358,9 @@ var NativeUIBridgeRegistry = class {
1319
1358
  }
1320
1359
  }
1321
1360
  }
1361
+ if (this.reportedRoute) {
1362
+ snapshot.page = { route: copyRouteInfo(this.reportedRoute) };
1363
+ }
1322
1364
  }
1323
1365
  return snapshot;
1324
1366
  }
@@ -4394,7 +4436,7 @@ function createServerHandlers(registry, executor, config) {
4394
4436
  };
4395
4437
  if (config?.appInfo) {
4396
4438
  response.uiBridge = {
4397
- version: "0.6.15",
4439
+ version: "0.6.16",
4398
4440
  ...config.appInfo,
4399
4441
  capabilities: ["elements", "components", "actions", "design"],
4400
4442
  elementCount: stats.elements,
@@ -7891,6 +7933,74 @@ function useUIBridgeModal(opts) {
7891
7933
  };
7892
7934
  }, [modalDetector, id, title, type, blocking, dismissible]);
7893
7935
  }
7936
+ function effectiveInfo(info, unmatched) {
7937
+ return unmatched ? { ...info, pattern: null, params: void 0 } : info;
7938
+ }
7939
+ function useRouteAwareness(info, options = {}) {
7940
+ const bridge = useUIBridgeNativeOptional();
7941
+ const unmatched = options.unmatched === true;
7942
+ const infoRef = useRef(info);
7943
+ infoRef.current = info;
7944
+ const pattern = info.pattern;
7945
+ const patternSource = info.patternSource;
7946
+ const paramsKey = info.params ? JSON.stringify(info.params) : "";
7947
+ const queryParamsKey = info.queryParams ? JSON.stringify(info.queryParams) : "";
7948
+ const routeStackKey = info.routeStack?.join(",");
7949
+ useEffect(() => {
7950
+ if (!bridge) return;
7951
+ const registry = bridge.registry;
7952
+ registry.setRouteInfo(effectiveInfo(infoRef.current, unmatched));
7953
+ return () => {
7954
+ registry.setRouteInfo(void 0);
7955
+ };
7956
+ }, [bridge, unmatched, pattern, patternSource, paramsKey, queryParamsKey, routeStackKey]);
7957
+ }
7958
+
7959
+ // src/react/routePattern.ts
7960
+ function focusedIndex(state, routeCount) {
7961
+ if (state.index !== void 0) return state.index;
7962
+ return typeof state.type === "string" && state.type !== "stack" ? 0 : routeCount - 1;
7963
+ }
7964
+ function isRouteIdentifier(value) {
7965
+ return typeof value === "string" && value.length > 0 && !value.includes("/") && !value.includes("?") && !value.includes("#");
7966
+ }
7967
+ function isExpoRouterUnmatched(segments) {
7968
+ return segments.some((s) => typeof s === "string" && s.startsWith("+"));
7969
+ }
7970
+ function expoRouterPattern(segments) {
7971
+ if (!Array.isArray(segments)) return null;
7972
+ for (const segment of segments) {
7973
+ if (!isRouteIdentifier(segment)) return null;
7974
+ if (segment.startsWith("+")) return null;
7975
+ }
7976
+ return "/" + segments.join("/");
7977
+ }
7978
+ function expoRouterRouteStack(segments) {
7979
+ if (expoRouterPattern(segments) === null) return void 0;
7980
+ const stack = ["/"];
7981
+ for (let depth = 1; depth <= segments.length; depth++) {
7982
+ stack.push("/" + segments.slice(0, depth).join("/"));
7983
+ }
7984
+ return stack;
7985
+ }
7986
+ function reactNavigationPattern(state, options = {}) {
7987
+ const names = [];
7988
+ let level = state ?? void 0;
7989
+ while (level) {
7990
+ const routes = level.routes;
7991
+ if (!Array.isArray(routes) || routes.length === 0) return null;
7992
+ const index = focusedIndex(level, routes.length);
7993
+ if (!Number.isInteger(index) || index < 0 || index >= routes.length) return null;
7994
+ const route = routes[index];
7995
+ if (!route || !isRouteIdentifier(route.name)) return null;
7996
+ names.push(route.name);
7997
+ level = route.state;
7998
+ }
7999
+ if (names.length === 0) return null;
8000
+ const leaf = names[names.length - 1];
8001
+ if (options.notFoundRouteNames?.includes(leaf)) return null;
8002
+ return "/" + names.join("/");
8003
+ }
7894
8004
  function useUIBridgeToast(opts) {
7895
8005
  const { toastCapture } = useUIBridgeNative();
7896
8006
  const { id, message, level } = opts;
@@ -9053,6 +9163,6 @@ var styles = StyleSheet.create({
9053
9163
  }
9054
9164
  });
9055
9165
 
9056
- export { CloudRelayClient, DEFAULT_PARAM_VALIDATION_MODE, DefaultNativeActionExecutor, DeviceAnnouncer, MAX_ACTION_TIMEOUT_MS, ModalDetector, NATIVE_STANDARD_ACTION_EFFECTS, NativeActionError, NativeUIBridgeRegistry, NativeUIBridgeServer, State, ToastCapture, TransitionTo, UIBridgeInspector, UIBridgeNativeProvider, UI_BRIDGE_NATIVE_ROUTES, UndoTracker, WebSocketConnection, WebSocketEventBridge, bindWithRetry, buildTreePath, buildUpgradeResponse, captureNativeResponsiveSnapshot, captureNativeStateVariations, computeAcceptKey, computeVisibility, createDesignHandlers, createNativeActionExecutor, createNativeElementIdentifier, createNativeServer, createServerHandlers, deriveInteractable, deriveText, extractHandlerNames, findAllByPattern, findElementByIdentifier, formatParamValidationFailure, getDefaultParamValidationMode, getGlobalRegistry, getNativeElementDesignData, httpStatusForResponse, inertAbortSignal, intersectRects, isAddrInUseError, isEmptyRect, mapNativeStyleToExtended, matchesIdentifier, nativeStandardActionEffect, normalizeActionTimeoutMs, pageRectOf, parseColorToRgb, parseFontSizePx, parseTreePath, projectVisionFields, resetDefaultParamValidationMode, resetGlobalRegistry, resolveActionEffect, roleForType, runAbortable, setDefaultParamValidationMode, setGlobalRegistry, useToastRecorder, useUIBridge, useUIBridgeModal, useUIBridgeNative, useUIBridgeNativeOptional, useUIBridgeNativeRequired, useUIBridgeRequired, useUIBridgeToast, useUIComponent, useUIComponentAction, useUIElement, useUIElementWithProps, validateActionParams };
9166
+ export { CloudRelayClient, DEFAULT_PARAM_VALIDATION_MODE, DefaultNativeActionExecutor, DeviceAnnouncer, MAX_ACTION_TIMEOUT_MS, ModalDetector, NATIVE_STANDARD_ACTION_EFFECTS, NativeActionError, NativeUIBridgeRegistry, NativeUIBridgeServer, State, ToastCapture, TransitionTo, UIBridgeInspector, UIBridgeNativeProvider, UI_BRIDGE_NATIVE_ROUTES, UndoTracker, WebSocketConnection, WebSocketEventBridge, bindWithRetry, buildTreePath, buildUpgradeResponse, captureNativeResponsiveSnapshot, captureNativeStateVariations, computeAcceptKey, computeVisibility, createDesignHandlers, createNativeActionExecutor, createNativeElementIdentifier, createNativeServer, createServerHandlers, deriveInteractable, deriveText, expoRouterPattern, expoRouterRouteStack, extractHandlerNames, findAllByPattern, findElementByIdentifier, formatParamValidationFailure, getDefaultParamValidationMode, getGlobalRegistry, getNativeElementDesignData, httpStatusForResponse, inertAbortSignal, intersectRects, isAddrInUseError, isEmptyRect, isExpoRouterUnmatched, mapNativeStyleToExtended, matchesIdentifier, nativeStandardActionEffect, normalizeActionTimeoutMs, pageRectOf, parseColorToRgb, parseFontSizePx, parseTreePath, projectVisionFields, reactNavigationPattern, resetDefaultParamValidationMode, resetGlobalRegistry, resolveActionEffect, roleForType, runAbortable, setDefaultParamValidationMode, setGlobalRegistry, useRouteAwareness, useToastRecorder, useUIBridge, useUIBridgeModal, useUIBridgeNative, useUIBridgeNativeOptional, useUIBridgeNativeRequired, useUIBridgeRequired, useUIBridgeToast, useUIComponent, useUIComponentAction, useUIElement, useUIElementWithProps, validateActionParams };
9057
9167
  //# sourceMappingURL=index.mjs.map
9058
9168
  //# sourceMappingURL=index.mjs.map