@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.
@@ -912,6 +912,35 @@ function diagnosePageHealth(elements, viewport) {
912
912
  }
913
913
 
914
914
  // src/server/handlers.ts
915
+ function matchElementsByText(registry, text, opts) {
916
+ const needle = text.toLowerCase();
917
+ const contains = (v) => typeof v === "string" && v.toLowerCase().includes(needle);
918
+ let all = registry.getAllElements();
919
+ if (opts?.visibleOnly) {
920
+ all = all.filter((e) => e.getState().visible);
921
+ }
922
+ const scored = [];
923
+ for (const e of all) {
924
+ let rank = Number.POSITIVE_INFINITY;
925
+ if (contains(e.label)) rank = Math.min(rank, 0);
926
+ const ident = e.getIdentifier();
927
+ if (ident) {
928
+ if (contains(ident.testId)) rank = Math.min(rank, 1);
929
+ if (contains(ident.accessibilityLabel)) rank = Math.min(rank, 1);
930
+ if (contains(ident.treePath)) rank = Math.min(rank, 1);
931
+ if (contains(ident.uiId)) rank = Math.min(rank, 1);
932
+ }
933
+ if (rank === Number.POSITIVE_INFINITY) {
934
+ const handlers = extractHandlerNames(e.props);
935
+ if (handlers.some((h) => h.toLowerCase().includes(needle))) rank = 2;
936
+ }
937
+ if (rank !== Number.POSITIVE_INFINITY) {
938
+ scored.push({ rank, element: { id: e.id, type: e.type, label: e.label } });
939
+ }
940
+ }
941
+ scored.sort((a, b) => a.rank - b.rank);
942
+ return scored.map((s) => s.element);
943
+ }
915
944
  async function executeWorkflowStep(step, registry, executor) {
916
945
  const startTime = Date.now();
917
946
  try {
@@ -1508,6 +1537,89 @@ function createServerHandlers(registry, executor, config) {
1508
1537
  const failedCount = results.length - succeededCount;
1509
1538
  return success2({ results, succeededCount, failedCount });
1510
1539
  },
1540
+ // ========================================================================
1541
+ // App-agnostic interaction parity (cross-platform `/control/page/*`)
1542
+ //
1543
+ // Mirrors the web/runner convenience endpoints so the SAME contract drives
1544
+ // mobile. Text/label interactions compose `executor.find` (registry-based
1545
+ // discovery) + `executor.executeAction` (press/type). Selector-only
1546
+ // variants have no React-Native analog and return NOT_SUPPORTED — the
1547
+ // mobile bridge's snapshot + `/control/find` (testID / accessibilityLabel)
1548
+ // cover what a selector would on web.
1549
+ // ========================================================================
1550
+ clickByText: async (ctx) => {
1551
+ const body = ctx.body;
1552
+ const text = typeof body?.text === "string" ? body.text.trim() : "";
1553
+ if (!text) {
1554
+ return error2("text is required and must not be empty", "INVALID_REQUEST");
1555
+ }
1556
+ const match = matchElementsByText(registry, text, { visibleOnly: body?.visibleOnly })[0];
1557
+ if (!match) {
1558
+ return error2(`No element found with text "${text}"`, "ELEMENT_NOT_FOUND");
1559
+ }
1560
+ const response = await executor.executeAction(match.id, { action: "press" });
1561
+ if (!response.success) {
1562
+ return error2(response.error || "Press failed", "ACTION_FAILED");
1563
+ }
1564
+ return success2({
1565
+ clicked: true,
1566
+ element: { id: match.id, type: match.type, label: match.label }
1567
+ });
1568
+ },
1569
+ clickBySelector: async () => {
1570
+ return error2(
1571
+ "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.",
1572
+ "NOT_SUPPORTED"
1573
+ );
1574
+ },
1575
+ typeInto: async (ctx) => {
1576
+ const body = ctx.body;
1577
+ const label = typeof body?.label === "string" ? body.label.trim() : "";
1578
+ if (!label) {
1579
+ return error2(
1580
+ "label is required on native (selector-based typeInto is web-only)",
1581
+ "INVALID_REQUEST"
1582
+ );
1583
+ }
1584
+ const text = typeof body?.text === "string" ? body.text : "";
1585
+ const match = matchElementsByText(registry, label, { visibleOnly: body?.visibleOnly })[0];
1586
+ if (!match) {
1587
+ return error2(`No input found for label "${label}"`, "ELEMENT_NOT_FOUND");
1588
+ }
1589
+ const response = await executor.executeAction(match.id, {
1590
+ action: "type",
1591
+ params: { text, clear: body?.clear === true }
1592
+ });
1593
+ if (!response.success) {
1594
+ return error2(response.error || "Type failed", "ACTION_FAILED");
1595
+ }
1596
+ return success2({
1597
+ typed: true,
1598
+ element: { id: match.id, type: match.type, label: match.label }
1599
+ });
1600
+ },
1601
+ readValue: async () => {
1602
+ return error2(
1603
+ "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.",
1604
+ "NOT_SUPPORTED"
1605
+ );
1606
+ },
1607
+ findByText: async (ctx) => {
1608
+ const body = ctx.body;
1609
+ const text = typeof body?.text === "string" ? body.text.trim() : "";
1610
+ if (!text) {
1611
+ return error2("text is required and must not be empty", "INVALID_REQUEST");
1612
+ }
1613
+ const matches = matchElementsByText(registry, text, { visibleOnly: body?.visibleOnly });
1614
+ return success2(
1615
+ matches.map((el, index) => ({
1616
+ index,
1617
+ id: el.id,
1618
+ type: el.type,
1619
+ label: el.label
1620
+ }))
1621
+ );
1622
+ },
1511
1623
  // Coord-based tap
1512
1624
  //
1513
1625
  // Synthesizes a press at the given screen coordinates by scanning the
@@ -2114,6 +2226,17 @@ var WS_ROUTES = [
2114
2226
  // Coord-based tap — synthesizes a press at the given screen coords by
2115
2227
  // matching against registered elements' layout rects.
2116
2228
  { pattern: "control/tap", handler: "tapAt", httpMethods: ["POST"] },
2229
+ // App-agnostic interaction parity — mirrors the web/runner convenience
2230
+ // endpoints (`/control/page/click-by-text` etc.) so the SAME cross-platform
2231
+ // contract drives mobile. Text/label-based interactions compose
2232
+ // `executor.find` + `executor.executeAction` over the registry; the
2233
+ // DOM-selector-only variants (`click-by-selector`, `read-value`) have no RN
2234
+ // analog and return a structured NOT_SUPPORTED envelope.
2235
+ { pattern: "control/page/click-by-text", handler: "clickByText", httpMethods: ["POST"] },
2236
+ { pattern: "control/page/click-by-selector", handler: "clickBySelector", httpMethods: ["POST"] },
2237
+ { pattern: "control/page/type-into", handler: "typeInto", httpMethods: ["POST"] },
2238
+ { pattern: "control/page/read-value", handler: "readValue", httpMethods: ["POST"] },
2239
+ { pattern: "control/page/find-by-text", handler: "findByText", httpMethods: ["POST"] },
2117
2240
  // Test hooks — gated behind `features.testHooks`. Let external runners
2118
2241
  // drive the ModalDetector over HTTP so tests can flip `snapshot.modalStack`
2119
2242
  // without mounting React components.
@@ -2189,6 +2312,11 @@ var HANDLER_DESCRIPTIONS = {
2189
2312
  aiChangeBufferEnable: "STUB \u2014 runner-only; mobile returns NOT_SUPPORTED. Use WS event subscriptions for change notifications.",
2190
2313
  aiWaitForElement: "STUB \u2014 runner-only; mobile returns NOT_SUPPORTED. Use the WS waitForElement / waitForCondition JSON-RPC methods.",
2191
2314
  tapAt: "Synthesize a press at given screen coords by matching registered element layout rects: body { x, y, action? }",
2315
+ clickByText: "App-agnostic: press the first element matching free-text (label/accessibilityLabel/testID): body { text, visibleOnly? }",
2316
+ clickBySelector: "STUB \u2014 selector-based; NOT_SUPPORTED on native (no DOM). Use clickByText or /control/find + /control/element/:id/action.",
2317
+ typeInto: "App-agnostic: type into the input matching a label: body { label, text, clear?, visibleOnly? }. (selector form is web-only)",
2318
+ readValue: "STUB \u2014 selector-based; NOT_SUPPORTED on native (no DOM). Use /control/element/:id/state to read a value.",
2319
+ findByText: "App-agnostic: list elements matching free-text (no press): body { text, visibleOnly? }",
2192
2320
  getConsoleErrors: "TEST HOOK \u2014 last-N console.error/console.warn entries; ?since=<ms>&limit=<n>",
2193
2321
  getNetworkRequests: "TEST HOOK \u2014 last-N fetch/XHR entries with status + duration; ?since=<ms>&limit=<n>",
2194
2322
  pushModal: "TEST HOOK \u2014 push a modal onto the snapshot.modalStack via the registry ModalDetector",