@qontinui/ui-bridge-native 0.6.7 → 0.6.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/index.js CHANGED
@@ -2097,6 +2097,35 @@ function diagnosePageHealth(elements, viewport) {
2097
2097
  }
2098
2098
 
2099
2099
  // src/server/handlers.ts
2100
+ function matchElementsByText(registry, text, opts) {
2101
+ const needle = text.toLowerCase();
2102
+ const contains = (v) => typeof v === "string" && v.toLowerCase().includes(needle);
2103
+ let all = registry.getAllElements();
2104
+ if (opts?.visibleOnly) {
2105
+ all = all.filter((e) => e.getState().visible);
2106
+ }
2107
+ const scored = [];
2108
+ for (const e of all) {
2109
+ let rank = Number.POSITIVE_INFINITY;
2110
+ if (contains(e.label)) rank = Math.min(rank, 0);
2111
+ const ident = e.getIdentifier();
2112
+ if (ident) {
2113
+ if (contains(ident.testId)) rank = Math.min(rank, 1);
2114
+ if (contains(ident.accessibilityLabel)) rank = Math.min(rank, 1);
2115
+ if (contains(ident.treePath)) rank = Math.min(rank, 1);
2116
+ if (contains(ident.uiId)) rank = Math.min(rank, 1);
2117
+ }
2118
+ if (rank === Number.POSITIVE_INFINITY) {
2119
+ const handlers = extractHandlerNames(e.props);
2120
+ if (handlers.some((h) => h.toLowerCase().includes(needle))) rank = 2;
2121
+ }
2122
+ if (rank !== Number.POSITIVE_INFINITY) {
2123
+ scored.push({ rank, element: { id: e.id, type: e.type, label: e.label } });
2124
+ }
2125
+ }
2126
+ scored.sort((a, b) => a.rank - b.rank);
2127
+ return scored.map((s) => s.element);
2128
+ }
2100
2129
  async function executeWorkflowStep(step, registry, executor) {
2101
2130
  const startTime = Date.now();
2102
2131
  try {
@@ -2693,6 +2722,89 @@ function createServerHandlers(registry, executor, config) {
2693
2722
  const failedCount = results.length - succeededCount;
2694
2723
  return success2({ results, succeededCount, failedCount });
2695
2724
  },
2725
+ // ========================================================================
2726
+ // App-agnostic interaction parity (cross-platform `/control/page/*`)
2727
+ //
2728
+ // Mirrors the web/runner convenience endpoints so the SAME contract drives
2729
+ // mobile. Text/label interactions compose `executor.find` (registry-based
2730
+ // discovery) + `executor.executeAction` (press/type). Selector-only
2731
+ // variants have no React-Native analog and return NOT_SUPPORTED — the
2732
+ // mobile bridge's snapshot + `/control/find` (testID / accessibilityLabel)
2733
+ // cover what a selector would on web.
2734
+ // ========================================================================
2735
+ clickByText: async (ctx) => {
2736
+ const body = ctx.body;
2737
+ const text = typeof body?.text === "string" ? body.text.trim() : "";
2738
+ if (!text) {
2739
+ return error2("text is required and must not be empty", "INVALID_REQUEST");
2740
+ }
2741
+ const match = matchElementsByText(registry, text, { visibleOnly: body?.visibleOnly })[0];
2742
+ if (!match) {
2743
+ return error2(`No element found with text "${text}"`, "ELEMENT_NOT_FOUND");
2744
+ }
2745
+ const response = await executor.executeAction(match.id, { action: "press" });
2746
+ if (!response.success) {
2747
+ return error2(response.error || "Press failed", "ACTION_FAILED");
2748
+ }
2749
+ return success2({
2750
+ clicked: true,
2751
+ element: { id: match.id, type: match.type, label: match.label }
2752
+ });
2753
+ },
2754
+ clickBySelector: async () => {
2755
+ return error2(
2756
+ "clickBySelector is not supported on native platform \u2014 React Native has no CSS-selector DOM. Use clickByText, or /control/find with testIdPattern/accessibilityLabelPattern then /control/element/:id/action.",
2757
+ "NOT_SUPPORTED"
2758
+ );
2759
+ },
2760
+ typeInto: async (ctx) => {
2761
+ const body = ctx.body;
2762
+ const label = typeof body?.label === "string" ? body.label.trim() : "";
2763
+ if (!label) {
2764
+ return error2(
2765
+ "label is required on native (selector-based typeInto is web-only)",
2766
+ "INVALID_REQUEST"
2767
+ );
2768
+ }
2769
+ const text = typeof body?.text === "string" ? body.text : "";
2770
+ const match = matchElementsByText(registry, label, { visibleOnly: body?.visibleOnly })[0];
2771
+ if (!match) {
2772
+ return error2(`No input found for label "${label}"`, "ELEMENT_NOT_FOUND");
2773
+ }
2774
+ const response = await executor.executeAction(match.id, {
2775
+ action: "type",
2776
+ params: { text, clear: body?.clear === true }
2777
+ });
2778
+ if (!response.success) {
2779
+ return error2(response.error || "Type failed", "ACTION_FAILED");
2780
+ }
2781
+ return success2({
2782
+ typed: true,
2783
+ element: { id: match.id, type: match.type, label: match.label }
2784
+ });
2785
+ },
2786
+ readValue: async () => {
2787
+ return error2(
2788
+ "readValue is not supported on native platform \u2014 React Native has no CSS-selector DOM. Use /control/element/:id/state to read an element value.",
2789
+ "NOT_SUPPORTED"
2790
+ );
2791
+ },
2792
+ findByText: async (ctx) => {
2793
+ const body = ctx.body;
2794
+ const text = typeof body?.text === "string" ? body.text.trim() : "";
2795
+ if (!text) {
2796
+ return error2("text is required and must not be empty", "INVALID_REQUEST");
2797
+ }
2798
+ const matches = matchElementsByText(registry, text, { visibleOnly: body?.visibleOnly });
2799
+ return success2(
2800
+ matches.map((el, index) => ({
2801
+ index,
2802
+ id: el.id,
2803
+ type: el.type,
2804
+ label: el.label
2805
+ }))
2806
+ );
2807
+ },
2696
2808
  // Coord-based tap
2697
2809
  //
2698
2810
  // Synthesizes a press at the given screen coordinates by scanning the
@@ -3299,6 +3411,17 @@ var WS_ROUTES = [
3299
3411
  // Coord-based tap — synthesizes a press at the given screen coords by
3300
3412
  // matching against registered elements' layout rects.
3301
3413
  { pattern: "control/tap", handler: "tapAt", httpMethods: ["POST"] },
3414
+ // App-agnostic interaction parity — mirrors the web/runner convenience
3415
+ // endpoints (`/control/page/click-by-text` etc.) so the SAME cross-platform
3416
+ // contract drives mobile. Text/label-based interactions compose
3417
+ // `executor.find` + `executor.executeAction` over the registry; the
3418
+ // DOM-selector-only variants (`click-by-selector`, `read-value`) have no RN
3419
+ // analog and return a structured NOT_SUPPORTED envelope.
3420
+ { pattern: "control/page/click-by-text", handler: "clickByText", httpMethods: ["POST"] },
3421
+ { pattern: "control/page/click-by-selector", handler: "clickBySelector", httpMethods: ["POST"] },
3422
+ { pattern: "control/page/type-into", handler: "typeInto", httpMethods: ["POST"] },
3423
+ { pattern: "control/page/read-value", handler: "readValue", httpMethods: ["POST"] },
3424
+ { pattern: "control/page/find-by-text", handler: "findByText", httpMethods: ["POST"] },
3302
3425
  // Test hooks — gated behind `features.testHooks`. Let external runners
3303
3426
  // drive the ModalDetector over HTTP so tests can flip `snapshot.modalStack`
3304
3427
  // without mounting React components.
@@ -3374,6 +3497,11 @@ var HANDLER_DESCRIPTIONS = {
3374
3497
  aiChangeBufferEnable: "STUB \u2014 runner-only; mobile returns NOT_SUPPORTED. Use WS event subscriptions for change notifications.",
3375
3498
  aiWaitForElement: "STUB \u2014 runner-only; mobile returns NOT_SUPPORTED. Use the WS waitForElement / waitForCondition JSON-RPC methods.",
3376
3499
  tapAt: "Synthesize a press at given screen coords by matching registered element layout rects: body { x, y, action? }",
3500
+ clickByText: "App-agnostic: press the first element matching free-text (label/accessibilityLabel/testID): body { text, visibleOnly? }",
3501
+ clickBySelector: "STUB \u2014 selector-based; NOT_SUPPORTED on native (no DOM). Use clickByText or /control/find + /control/element/:id/action.",
3502
+ typeInto: "App-agnostic: type into the input matching a label: body { label, text, clear?, visibleOnly? }. (selector form is web-only)",
3503
+ readValue: "STUB \u2014 selector-based; NOT_SUPPORTED on native (no DOM). Use /control/element/:id/state to read a value.",
3504
+ findByText: "App-agnostic: list elements matching free-text (no press): body { text, visibleOnly? }",
3377
3505
  getConsoleErrors: "TEST HOOK \u2014 last-N console.error/console.warn entries; ?since=<ms>&limit=<n>",
3378
3506
  getNetworkRequests: "TEST HOOK \u2014 last-N fetch/XHR entries with status + duration; ?since=<ms>&limit=<n>",
3379
3507
  pushModal: "TEST HOOK \u2014 push a modal onto the snapshot.modalStack via the registry ModalDetector",