@qontinui/ui-bridge 0.1.1 → 0.3.0
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/ai/index.d.mts +893 -0
- package/dist/ai/index.d.ts +893 -0
- package/dist/ai/index.js +3897 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/index.mjs +3839 -0
- package/dist/ai/index.mjs.map +1 -0
- package/dist/babel-plugin/index.js +515 -0
- package/dist/babel-plugin/index.js.map +1 -0
- package/dist/babel-plugin/index.mjs +499 -0
- package/dist/babel-plugin/index.mjs.map +1 -0
- package/dist/control/index.d.mts +5 -4
- package/dist/control/index.d.ts +5 -4
- package/dist/core/index.d.mts +115 -42
- package/dist/core/index.d.ts +115 -42
- package/dist/core/index.js +0 -983
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +1 -972
- package/dist/core/index.mjs.map +1 -1
- package/dist/debug/index.d.mts +3 -3
- package/dist/debug/index.d.ts +3 -3
- package/dist/index.d.mts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +8249 -4163
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8193 -4152
- package/dist/index.mjs.map +1 -1
- package/dist/{metrics-QCnK0EFw.d.ts → metrics-BfiT_rhZ.d.ts} +2 -2
- package/dist/{metrics-BCG7z7Aq.d.mts → metrics-DTA2bwG7.d.mts} +2 -2
- package/dist/native/control/index.js +453 -0
- package/dist/native/control/index.js.map +1 -0
- package/dist/native/control/index.mjs +450 -0
- package/dist/native/control/index.mjs.map +1 -0
- package/dist/native/core/index.js +486 -0
- package/dist/native/core/index.js.map +1 -0
- package/dist/native/core/index.mjs +475 -0
- package/dist/native/core/index.mjs.map +1 -0
- package/dist/native/debug/index.js +451 -0
- package/dist/native/debug/index.js.map +1 -0
- package/dist/native/debug/index.mjs +449 -0
- package/dist/native/debug/index.mjs.map +1 -0
- package/dist/native/index.js +2274 -0
- package/dist/native/index.js.map +1 -0
- package/dist/native/index.mjs +2246 -0
- package/dist/native/index.mjs.map +1 -0
- package/dist/native/react/index.js +1401 -0
- package/dist/native/react/index.js.map +1 -0
- package/dist/native/react/index.mjs +1389 -0
- package/dist/native/react/index.mjs.map +1 -0
- package/dist/native/server/index.js +415 -0
- package/dist/native/server/index.js.map +1 -0
- package/dist/native/server/index.mjs +410 -0
- package/dist/native/server/index.mjs.map +1 -0
- package/dist/react/index.d.mts +20 -6
- package/dist/react/index.d.ts +20 -6
- package/dist/react/index.js +629 -14
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +629 -14
- package/dist/react/index.mjs.map +1 -1
- package/dist/{registry-CT6BVVKr.d.mts → registry-BKLEm-yk.d.ts} +29 -14
- package/dist/{registry-D4mQ01B3.d.ts → registry-BmZgyCz8.d.mts} +29 -14
- package/dist/render-log/index.d.mts +1 -1
- package/dist/render-log/index.d.ts +1 -1
- package/dist/server/express.d.mts +36 -0
- package/dist/server/express.d.ts +36 -0
- package/dist/server/express.js +196 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.mjs +192 -0
- package/dist/server/express.mjs.map +1 -0
- package/dist/server/handlers.d.mts +93 -0
- package/dist/server/handlers.d.ts +93 -0
- package/dist/server/handlers.js +4278 -0
- package/dist/server/handlers.js.map +1 -0
- package/dist/server/handlers.mjs +4275 -0
- package/dist/server/handlers.mjs.map +1 -0
- package/dist/server/index.d.mts +10 -0
- package/dist/server/index.d.ts +10 -0
- package/dist/server/index.js +5352 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +5337 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/server/nextjs.d.mts +126 -0
- package/dist/server/nextjs.d.ts +126 -0
- package/dist/server/nextjs.js +287 -0
- package/dist/server/nextjs.js.map +1 -0
- package/dist/server/nextjs.mjs +282 -0
- package/dist/server/nextjs.mjs.map +1 -0
- package/dist/server/standalone.d.mts +6 -0
- package/dist/server/standalone.d.ts +6 -0
- package/dist/server/standalone.js +719 -0
- package/dist/server/standalone.js.map +1 -0
- package/dist/server/standalone.mjs +715 -0
- package/dist/server/standalone.mjs.map +1 -0
- package/dist/standalone-BURj8J3G.d.ts +212 -0
- package/dist/standalone-Dwmel29d.d.mts +212 -0
- package/dist/swc-plugin/index.d.mts +79 -0
- package/dist/swc-plugin/index.d.ts +79 -0
- package/dist/swc-plugin/index.js +15 -0
- package/dist/swc-plugin/index.js.map +1 -0
- package/dist/swc-plugin/index.mjs +9 -0
- package/dist/swc-plugin/index.mjs.map +1 -0
- package/dist/types-B5Q0GVo0.d.mts +646 -0
- package/dist/{types-DdJD9yw5.d.mts → types-B7J7noLK.d.mts} +1 -1
- package/dist/{types-BDkXy5si.d.ts → types-BkNRILUa.d.ts} +1 -1
- package/dist/types-CEQLnFMv.d.mts +156 -0
- package/dist/types-CHnlwiTK.d.ts +156 -0
- package/dist/types-DfPqwU-i.d.ts +646 -0
- package/dist/{types-BpvpStn3.d.mts → types-jKVgTI6_.d.mts} +364 -160
- package/dist/{types-BpvpStn3.d.ts → types-jKVgTI6_.d.ts} +364 -160
- package/package.json +111 -3
- package/swc-plugin-wasm/ui_bridge_swc_plugin.wasm +0 -0
- package/dist/websocket-client-B2LC9CYc.d.mts +0 -124
- package/dist/websocket-client-DupH0X7B.d.ts +0 -124
|
@@ -0,0 +1,1401 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
|
|
6
|
+
// src/native/react/UIBridgeNativeProvider.tsx
|
|
7
|
+
|
|
8
|
+
// src/native/core/registry.ts
|
|
9
|
+
function inferActions(type) {
|
|
10
|
+
const baseActions = ["focus", "blur"];
|
|
11
|
+
switch (type) {
|
|
12
|
+
case "button":
|
|
13
|
+
case "touchable":
|
|
14
|
+
case "pressable":
|
|
15
|
+
return [...baseActions, "press", "longPress", "doubleTap"];
|
|
16
|
+
case "input":
|
|
17
|
+
return [...baseActions, "press", "type", "clear"];
|
|
18
|
+
case "text":
|
|
19
|
+
return [...baseActions, "press", "longPress"];
|
|
20
|
+
case "view":
|
|
21
|
+
return [...baseActions, "press"];
|
|
22
|
+
case "scroll":
|
|
23
|
+
return [...baseActions, "scroll", "swipe"];
|
|
24
|
+
case "list":
|
|
25
|
+
return [...baseActions, "scroll", "swipe"];
|
|
26
|
+
case "listItem":
|
|
27
|
+
return [...baseActions, "press", "longPress", "swipe"];
|
|
28
|
+
case "switch":
|
|
29
|
+
case "checkbox":
|
|
30
|
+
return [...baseActions, "press", "toggle"];
|
|
31
|
+
case "radio":
|
|
32
|
+
return [...baseActions, "press"];
|
|
33
|
+
case "image":
|
|
34
|
+
return [...baseActions, "press", "longPress"];
|
|
35
|
+
case "modal":
|
|
36
|
+
return ["focus", "blur"];
|
|
37
|
+
case "custom":
|
|
38
|
+
default:
|
|
39
|
+
return [...baseActions, "press"];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
var NativeUIBridgeRegistry = class {
|
|
43
|
+
constructor(config = {}) {
|
|
44
|
+
this.elements = /* @__PURE__ */ new Map();
|
|
45
|
+
this.components = /* @__PURE__ */ new Map();
|
|
46
|
+
this.workflows = /* @__PURE__ */ new Map();
|
|
47
|
+
this.eventListeners = /* @__PURE__ */ new Map();
|
|
48
|
+
this.config = config;
|
|
49
|
+
}
|
|
50
|
+
// ============================================================================
|
|
51
|
+
// Element Management
|
|
52
|
+
// ============================================================================
|
|
53
|
+
/**
|
|
54
|
+
* Register a native element
|
|
55
|
+
*/
|
|
56
|
+
registerElement(id, ref, options = {}) {
|
|
57
|
+
const {
|
|
58
|
+
type = "custom",
|
|
59
|
+
label,
|
|
60
|
+
actions = inferActions(type),
|
|
61
|
+
customActions,
|
|
62
|
+
props,
|
|
63
|
+
treePath = id,
|
|
64
|
+
testId,
|
|
65
|
+
accessibilityLabel
|
|
66
|
+
} = options;
|
|
67
|
+
const getState = () => {
|
|
68
|
+
const element = ref.current;
|
|
69
|
+
if (!element) {
|
|
70
|
+
return {
|
|
71
|
+
mounted: false,
|
|
72
|
+
visible: false,
|
|
73
|
+
enabled: false,
|
|
74
|
+
focused: false,
|
|
75
|
+
layout: null
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const stored = this.elements.get(id);
|
|
79
|
+
if (stored && stored.getState !== getState) {
|
|
80
|
+
return stored.getState();
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
mounted: true,
|
|
84
|
+
visible: true,
|
|
85
|
+
enabled: true,
|
|
86
|
+
focused: false,
|
|
87
|
+
layout: null
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
const getIdentifier = () => ({
|
|
91
|
+
uiId: id,
|
|
92
|
+
testId: testId || id,
|
|
93
|
+
accessibilityLabel,
|
|
94
|
+
treePath
|
|
95
|
+
});
|
|
96
|
+
const registered = {
|
|
97
|
+
id,
|
|
98
|
+
ref,
|
|
99
|
+
type,
|
|
100
|
+
label,
|
|
101
|
+
actions,
|
|
102
|
+
customActions,
|
|
103
|
+
props,
|
|
104
|
+
getState,
|
|
105
|
+
getIdentifier,
|
|
106
|
+
registeredAt: Date.now(),
|
|
107
|
+
mounted: true
|
|
108
|
+
};
|
|
109
|
+
this.elements.set(id, registered);
|
|
110
|
+
this.emit("element:registered", { id, type, label });
|
|
111
|
+
if (this.config.verbose) {
|
|
112
|
+
console.log(`[ui-bridge-native] Registered element: ${id} (${type})`);
|
|
113
|
+
}
|
|
114
|
+
return registered;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Unregister an element
|
|
118
|
+
*/
|
|
119
|
+
unregisterElement(id) {
|
|
120
|
+
const element = this.elements.get(id);
|
|
121
|
+
if (element) {
|
|
122
|
+
this.elements.delete(id);
|
|
123
|
+
this.emit("element:unregistered", { id });
|
|
124
|
+
if (this.config.verbose) {
|
|
125
|
+
console.log(`[ui-bridge-native] Unregistered element: ${id}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get a registered element
|
|
131
|
+
*/
|
|
132
|
+
getElement(id) {
|
|
133
|
+
return this.elements.get(id);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get all registered elements
|
|
137
|
+
*/
|
|
138
|
+
getAllElements() {
|
|
139
|
+
return Array.from(this.elements.values());
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Update element state
|
|
143
|
+
*/
|
|
144
|
+
updateElementState(id, state) {
|
|
145
|
+
const element = this.elements.get(id);
|
|
146
|
+
if (element) {
|
|
147
|
+
const currentState = element.getState();
|
|
148
|
+
const newState = { ...currentState, ...state };
|
|
149
|
+
const updated = {
|
|
150
|
+
...element,
|
|
151
|
+
getState: () => newState
|
|
152
|
+
};
|
|
153
|
+
this.elements.set(id, updated);
|
|
154
|
+
this.emit("element:stateChanged", { id, state: newState });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Update element props (for action execution)
|
|
159
|
+
*/
|
|
160
|
+
updateElementProps(id, props) {
|
|
161
|
+
const element = this.elements.get(id);
|
|
162
|
+
if (element) {
|
|
163
|
+
const updated = {
|
|
164
|
+
...element,
|
|
165
|
+
props: { ...element.props, ...props }
|
|
166
|
+
};
|
|
167
|
+
this.elements.set(id, updated);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Find element by testID
|
|
172
|
+
*/
|
|
173
|
+
findByTestId(testId) {
|
|
174
|
+
for (const element of this.elements.values()) {
|
|
175
|
+
const identifier = element.getIdentifier();
|
|
176
|
+
if (identifier.testId === testId) {
|
|
177
|
+
return element;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return void 0;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Find elements by type
|
|
184
|
+
*/
|
|
185
|
+
findByType(type) {
|
|
186
|
+
return Array.from(this.elements.values()).filter((e) => e.type === type);
|
|
187
|
+
}
|
|
188
|
+
// ============================================================================
|
|
189
|
+
// Component Management
|
|
190
|
+
// ============================================================================
|
|
191
|
+
/**
|
|
192
|
+
* Register a component
|
|
193
|
+
*/
|
|
194
|
+
registerComponent(id, options) {
|
|
195
|
+
const { name, description, actions = [], elementIds } = options;
|
|
196
|
+
const registered = {
|
|
197
|
+
id,
|
|
198
|
+
name,
|
|
199
|
+
description,
|
|
200
|
+
actions: actions.map((a) => ({
|
|
201
|
+
id: a.id,
|
|
202
|
+
label: a.label,
|
|
203
|
+
description: a.description,
|
|
204
|
+
handler: a.handler
|
|
205
|
+
})),
|
|
206
|
+
elementIds,
|
|
207
|
+
registeredAt: Date.now(),
|
|
208
|
+
mounted: true
|
|
209
|
+
};
|
|
210
|
+
this.components.set(id, registered);
|
|
211
|
+
this.emit("component:registered", { id, name });
|
|
212
|
+
if (this.config.verbose) {
|
|
213
|
+
console.log(`[ui-bridge-native] Registered component: ${id} (${name})`);
|
|
214
|
+
}
|
|
215
|
+
return registered;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Unregister a component
|
|
219
|
+
*/
|
|
220
|
+
unregisterComponent(id) {
|
|
221
|
+
const component = this.components.get(id);
|
|
222
|
+
if (component) {
|
|
223
|
+
this.components.delete(id);
|
|
224
|
+
this.emit("component:unregistered", { id });
|
|
225
|
+
if (this.config.verbose) {
|
|
226
|
+
console.log(`[ui-bridge-native] Unregistered component: ${id}`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get a registered component
|
|
232
|
+
*/
|
|
233
|
+
getComponent(id) {
|
|
234
|
+
return this.components.get(id);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get all registered components
|
|
238
|
+
*/
|
|
239
|
+
getAllComponents() {
|
|
240
|
+
return Array.from(this.components.values());
|
|
241
|
+
}
|
|
242
|
+
// ============================================================================
|
|
243
|
+
// Workflow Management
|
|
244
|
+
// ============================================================================
|
|
245
|
+
/**
|
|
246
|
+
* Register a workflow
|
|
247
|
+
*/
|
|
248
|
+
registerWorkflow(workflow) {
|
|
249
|
+
this.workflows.set(workflow.id, workflow);
|
|
250
|
+
if (this.config.verbose) {
|
|
251
|
+
console.log(`[ui-bridge-native] Registered workflow: ${workflow.id}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Unregister a workflow
|
|
256
|
+
*/
|
|
257
|
+
unregisterWorkflow(id) {
|
|
258
|
+
this.workflows.delete(id);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Get a workflow
|
|
262
|
+
*/
|
|
263
|
+
getWorkflow(id) {
|
|
264
|
+
return this.workflows.get(id);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Get all workflows
|
|
268
|
+
*/
|
|
269
|
+
getAllWorkflows() {
|
|
270
|
+
return Array.from(this.workflows.values());
|
|
271
|
+
}
|
|
272
|
+
// ============================================================================
|
|
273
|
+
// Event System
|
|
274
|
+
// ============================================================================
|
|
275
|
+
/**
|
|
276
|
+
* Subscribe to events
|
|
277
|
+
*/
|
|
278
|
+
on(type, listener) {
|
|
279
|
+
if (!this.eventListeners.has(type)) {
|
|
280
|
+
this.eventListeners.set(type, /* @__PURE__ */ new Set());
|
|
281
|
+
}
|
|
282
|
+
this.eventListeners.get(type).add(listener);
|
|
283
|
+
return () => this.off(type, listener);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Unsubscribe from events
|
|
287
|
+
*/
|
|
288
|
+
off(type, listener) {
|
|
289
|
+
this.eventListeners.get(type)?.delete(listener);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Emit an event
|
|
293
|
+
*/
|
|
294
|
+
emit(type, data) {
|
|
295
|
+
const event = {
|
|
296
|
+
type,
|
|
297
|
+
timestamp: Date.now(),
|
|
298
|
+
data
|
|
299
|
+
};
|
|
300
|
+
const listeners = this.eventListeners.get(type);
|
|
301
|
+
if (listeners) {
|
|
302
|
+
for (const listener of listeners) {
|
|
303
|
+
try {
|
|
304
|
+
listener(event);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
console.error(`[ui-bridge-native] Event listener error:`, error);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (this.config.onEvent) {
|
|
311
|
+
try {
|
|
312
|
+
this.config.onEvent(event);
|
|
313
|
+
} catch (error) {
|
|
314
|
+
console.error(`[ui-bridge-native] Global event handler error:`, error);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
// ============================================================================
|
|
319
|
+
// Snapshots
|
|
320
|
+
// ============================================================================
|
|
321
|
+
/**
|
|
322
|
+
* Create a snapshot of the current state
|
|
323
|
+
*/
|
|
324
|
+
createSnapshot() {
|
|
325
|
+
return {
|
|
326
|
+
timestamp: Date.now(),
|
|
327
|
+
elements: this.getAllElements().map((e) => ({
|
|
328
|
+
id: e.id,
|
|
329
|
+
type: e.type,
|
|
330
|
+
label: e.label,
|
|
331
|
+
identifier: e.getIdentifier(),
|
|
332
|
+
state: e.getState(),
|
|
333
|
+
actions: e.actions,
|
|
334
|
+
customActions: e.customActions ? Object.keys(e.customActions) : void 0
|
|
335
|
+
})),
|
|
336
|
+
components: this.getAllComponents().map((c) => ({
|
|
337
|
+
id: c.id,
|
|
338
|
+
name: c.name,
|
|
339
|
+
description: c.description,
|
|
340
|
+
actions: c.actions.map((a) => a.id),
|
|
341
|
+
elementIds: c.elementIds
|
|
342
|
+
})),
|
|
343
|
+
workflows: this.getAllWorkflows().map((w) => ({
|
|
344
|
+
id: w.id,
|
|
345
|
+
name: w.name,
|
|
346
|
+
description: w.description,
|
|
347
|
+
stepCount: w.steps.length
|
|
348
|
+
}))
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Get registry statistics
|
|
353
|
+
*/
|
|
354
|
+
getStats() {
|
|
355
|
+
return {
|
|
356
|
+
elements: this.elements.size,
|
|
357
|
+
components: this.components.size,
|
|
358
|
+
workflows: this.workflows.size
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Clear all registrations
|
|
363
|
+
*/
|
|
364
|
+
clear() {
|
|
365
|
+
this.elements.clear();
|
|
366
|
+
this.components.clear();
|
|
367
|
+
this.workflows.clear();
|
|
368
|
+
if (this.config.verbose) {
|
|
369
|
+
console.log(`[ui-bridge-native] Registry cleared`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
var globalRegistry = null;
|
|
374
|
+
function setGlobalRegistry(registry) {
|
|
375
|
+
globalRegistry = registry;
|
|
376
|
+
}
|
|
377
|
+
function getGlobalRegistry() {
|
|
378
|
+
return globalRegistry;
|
|
379
|
+
}
|
|
380
|
+
function resetGlobalRegistry() {
|
|
381
|
+
globalRegistry?.clear();
|
|
382
|
+
globalRegistry = null;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// src/native/core/element-identifier.ts
|
|
386
|
+
function findElementByIdentifier(identifier) {
|
|
387
|
+
const registry = getGlobalRegistry();
|
|
388
|
+
if (!registry) return null;
|
|
389
|
+
if (typeof identifier === "string") {
|
|
390
|
+
const byId = registry.getElement(identifier);
|
|
391
|
+
if (byId) return byId;
|
|
392
|
+
const byTestId = registry.findByTestId(identifier);
|
|
393
|
+
if (byTestId) return byTestId;
|
|
394
|
+
return findByPattern(registry, identifier);
|
|
395
|
+
}
|
|
396
|
+
if (identifier.uiId) {
|
|
397
|
+
const byId = registry.getElement(identifier.uiId);
|
|
398
|
+
if (byId) return byId;
|
|
399
|
+
}
|
|
400
|
+
if (identifier.testId) {
|
|
401
|
+
const byTestId = registry.findByTestId(identifier.testId);
|
|
402
|
+
if (byTestId) return byTestId;
|
|
403
|
+
}
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
function findByPattern(registry, pattern) {
|
|
407
|
+
if (!registry) return null;
|
|
408
|
+
const regexPattern = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
409
|
+
const regex = new RegExp(`^${regexPattern}$`, "i");
|
|
410
|
+
for (const element of registry.getAllElements()) {
|
|
411
|
+
const identifier = element.getIdentifier();
|
|
412
|
+
if (identifier.testId && regex.test(identifier.testId)) {
|
|
413
|
+
return element;
|
|
414
|
+
}
|
|
415
|
+
if (identifier.uiId && regex.test(identifier.uiId)) {
|
|
416
|
+
return element;
|
|
417
|
+
}
|
|
418
|
+
if (identifier.treePath && regex.test(identifier.treePath)) {
|
|
419
|
+
return element;
|
|
420
|
+
}
|
|
421
|
+
if (identifier.accessibilityLabel && regex.test(identifier.accessibilityLabel)) {
|
|
422
|
+
return element;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// src/native/control/action-executor.ts
|
|
429
|
+
var DEFAULT_WAIT_OPTIONS = {
|
|
430
|
+
visible: true,
|
|
431
|
+
enabled: true,
|
|
432
|
+
focused: false,
|
|
433
|
+
state: {},
|
|
434
|
+
timeout: 1e4,
|
|
435
|
+
interval: 100
|
|
436
|
+
};
|
|
437
|
+
function sleep(ms) {
|
|
438
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
439
|
+
}
|
|
440
|
+
var DefaultNativeActionExecutor = class {
|
|
441
|
+
constructor(registry) {
|
|
442
|
+
this.registry = registry;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Execute an action on an element
|
|
446
|
+
*/
|
|
447
|
+
async executeAction(elementId, request) {
|
|
448
|
+
const startTime = Date.now();
|
|
449
|
+
let waitDurationMs = 0;
|
|
450
|
+
try {
|
|
451
|
+
let registered = this.registry.getElement(elementId);
|
|
452
|
+
if (!registered) {
|
|
453
|
+
registered = findElementByIdentifier(elementId) ?? void 0;
|
|
454
|
+
}
|
|
455
|
+
if (!registered) {
|
|
456
|
+
return {
|
|
457
|
+
success: false,
|
|
458
|
+
error: `Element not found: ${elementId}`,
|
|
459
|
+
durationMs: Date.now() - startTime,
|
|
460
|
+
timestamp: Date.now(),
|
|
461
|
+
requestId: request.requestId
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
if (request.waitOptions) {
|
|
465
|
+
const waitResult = await this.waitForElementInternal(
|
|
466
|
+
registered.id,
|
|
467
|
+
request.waitOptions
|
|
468
|
+
);
|
|
469
|
+
waitDurationMs = waitResult.waitedMs;
|
|
470
|
+
if (!waitResult.met) {
|
|
471
|
+
return {
|
|
472
|
+
success: false,
|
|
473
|
+
error: waitResult.error || "Wait condition not met",
|
|
474
|
+
durationMs: Date.now() - startTime,
|
|
475
|
+
timestamp: Date.now(),
|
|
476
|
+
requestId: request.requestId,
|
|
477
|
+
waitDurationMs
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
const result = await this.performAction(registered, request.action, request.params);
|
|
482
|
+
return {
|
|
483
|
+
success: true,
|
|
484
|
+
elementState: registered.getState(),
|
|
485
|
+
result,
|
|
486
|
+
durationMs: Date.now() - startTime,
|
|
487
|
+
timestamp: Date.now(),
|
|
488
|
+
requestId: request.requestId,
|
|
489
|
+
waitDurationMs
|
|
490
|
+
};
|
|
491
|
+
} catch (error) {
|
|
492
|
+
return {
|
|
493
|
+
success: false,
|
|
494
|
+
error: error instanceof Error ? error.message : String(error),
|
|
495
|
+
stack: error instanceof Error ? error.stack : void 0,
|
|
496
|
+
durationMs: Date.now() - startTime,
|
|
497
|
+
timestamp: Date.now(),
|
|
498
|
+
requestId: request.requestId,
|
|
499
|
+
waitDurationMs
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Perform an action on an element
|
|
505
|
+
*/
|
|
506
|
+
async performAction(element, action, params) {
|
|
507
|
+
if (!element) {
|
|
508
|
+
throw new Error("Element not found");
|
|
509
|
+
}
|
|
510
|
+
const props = element.props || {};
|
|
511
|
+
if (element.customActions && action in element.customActions) {
|
|
512
|
+
return element.customActions[action].handler(params);
|
|
513
|
+
}
|
|
514
|
+
switch (action) {
|
|
515
|
+
case "press":
|
|
516
|
+
return this.performPress(props, params);
|
|
517
|
+
case "longPress":
|
|
518
|
+
return this.performLongPress(props, params);
|
|
519
|
+
case "doubleTap":
|
|
520
|
+
return this.performDoubleTap(props);
|
|
521
|
+
case "type":
|
|
522
|
+
return this.performType(element, props, params);
|
|
523
|
+
case "clear":
|
|
524
|
+
return this.performClear(element, props);
|
|
525
|
+
case "focus":
|
|
526
|
+
return this.performFocus(element);
|
|
527
|
+
case "blur":
|
|
528
|
+
return this.performBlur(element);
|
|
529
|
+
case "scroll":
|
|
530
|
+
return this.performScroll(props, params);
|
|
531
|
+
case "swipe":
|
|
532
|
+
return this.performSwipe(props, params);
|
|
533
|
+
case "toggle":
|
|
534
|
+
return this.performToggle(props);
|
|
535
|
+
default:
|
|
536
|
+
throw new Error(`Unknown action: ${action}`);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Perform press action
|
|
541
|
+
*/
|
|
542
|
+
async performPress(props, params) {
|
|
543
|
+
const handlers = ["onPress", "onPressIn", "onResponderRelease"];
|
|
544
|
+
for (const handler of handlers) {
|
|
545
|
+
if (typeof props[handler] === "function") {
|
|
546
|
+
const event = this.createPressEvent(params);
|
|
547
|
+
props[handler](event);
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
throw new Error("No press handler found on element");
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Perform long press action
|
|
555
|
+
*/
|
|
556
|
+
async performLongPress(props, params) {
|
|
557
|
+
if (typeof props.onLongPress === "function") {
|
|
558
|
+
const event = this.createPressEvent(params);
|
|
559
|
+
props.onLongPress(event);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
throw new Error("No long press handler found on element");
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Perform double tap action
|
|
566
|
+
*/
|
|
567
|
+
async performDoubleTap(props) {
|
|
568
|
+
if (typeof props.onDoubleTap === "function") {
|
|
569
|
+
props.onDoubleTap();
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
if (typeof props.onPress === "function") {
|
|
573
|
+
const event = this.createPressEvent();
|
|
574
|
+
props.onPress(event);
|
|
575
|
+
await sleep(50);
|
|
576
|
+
props.onPress(event);
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
throw new Error("No press handler found for double tap");
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Perform type action
|
|
583
|
+
*/
|
|
584
|
+
async performType(element, props, params) {
|
|
585
|
+
if (!params?.text) {
|
|
586
|
+
throw new Error("Type action requires text parameter");
|
|
587
|
+
}
|
|
588
|
+
if (params.clearFirst) {
|
|
589
|
+
await this.performClear(element, props);
|
|
590
|
+
}
|
|
591
|
+
if (params.delay && params.delay > 0) {
|
|
592
|
+
const currentValue = element?.getState().value || "";
|
|
593
|
+
for (const char of params.text) {
|
|
594
|
+
const newValue = currentValue + char;
|
|
595
|
+
if (typeof props.onChangeText === "function") {
|
|
596
|
+
props.onChangeText(newValue);
|
|
597
|
+
}
|
|
598
|
+
await sleep(params.delay);
|
|
599
|
+
}
|
|
600
|
+
} else {
|
|
601
|
+
if (typeof props.onChangeText === "function") {
|
|
602
|
+
props.onChangeText(params.text);
|
|
603
|
+
} else if (typeof props.onChange === "function") {
|
|
604
|
+
props.onChange({
|
|
605
|
+
nativeEvent: { text: params.text }
|
|
606
|
+
});
|
|
607
|
+
} else {
|
|
608
|
+
throw new Error("No text change handler found on element");
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
if (element) {
|
|
612
|
+
this.registry.updateElementState(element.id, { value: params.text });
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Perform clear action
|
|
617
|
+
*/
|
|
618
|
+
async performClear(element, props) {
|
|
619
|
+
if (typeof props.onChangeText === "function") {
|
|
620
|
+
props.onChangeText("");
|
|
621
|
+
} else if (typeof props.onChange === "function") {
|
|
622
|
+
props.onChange({
|
|
623
|
+
nativeEvent: { text: "" }
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
if (element) {
|
|
627
|
+
this.registry.updateElementState(element.id, { value: "" });
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Perform focus action
|
|
632
|
+
*/
|
|
633
|
+
async performFocus(element) {
|
|
634
|
+
if (element?.ref.current && "focus" in element.ref.current) {
|
|
635
|
+
element.ref.current.focus();
|
|
636
|
+
}
|
|
637
|
+
if (element) {
|
|
638
|
+
this.registry.updateElementState(element.id, { focused: true });
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Perform blur action
|
|
643
|
+
*/
|
|
644
|
+
async performBlur(element) {
|
|
645
|
+
if (element?.ref.current && "blur" in element.ref.current) {
|
|
646
|
+
element.ref.current.blur();
|
|
647
|
+
}
|
|
648
|
+
if (element) {
|
|
649
|
+
this.registry.updateElementState(element.id, { focused: false });
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Perform scroll action
|
|
654
|
+
*/
|
|
655
|
+
async performScroll(props, params) {
|
|
656
|
+
if (typeof props.onScroll === "function") {
|
|
657
|
+
const event = {
|
|
658
|
+
nativeEvent: {
|
|
659
|
+
contentOffset: params?.offset || { x: 0, y: 0 }
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
props.onScroll(event);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Perform swipe action
|
|
667
|
+
*/
|
|
668
|
+
async performSwipe(props, params) {
|
|
669
|
+
if (!params?.direction) {
|
|
670
|
+
throw new Error("Swipe action requires direction parameter");
|
|
671
|
+
}
|
|
672
|
+
const handlerMap = {
|
|
673
|
+
left: "onSwipeLeft",
|
|
674
|
+
right: "onSwipeRight",
|
|
675
|
+
up: "onSwipeUp",
|
|
676
|
+
down: "onSwipeDown"
|
|
677
|
+
};
|
|
678
|
+
const handler = handlerMap[params.direction];
|
|
679
|
+
if (handler && typeof props[handler] === "function") {
|
|
680
|
+
props[handler]();
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
if (typeof props.onSwipe === "function") {
|
|
684
|
+
props.onSwipe(params.direction);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Perform toggle action
|
|
689
|
+
*/
|
|
690
|
+
async performToggle(props) {
|
|
691
|
+
if (typeof props.onValueChange === "function") {
|
|
692
|
+
const currentValue = props.value;
|
|
693
|
+
props.onValueChange(!currentValue);
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
if (typeof props.onPress === "function") {
|
|
697
|
+
props.onPress();
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
throw new Error("No toggle handler found on element");
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Create a synthetic press event
|
|
704
|
+
*/
|
|
705
|
+
createPressEvent(params) {
|
|
706
|
+
return {
|
|
707
|
+
nativeEvent: {
|
|
708
|
+
locationX: params?.position?.x ?? 0,
|
|
709
|
+
locationY: params?.position?.y ?? 0,
|
|
710
|
+
timestamp: Date.now()
|
|
711
|
+
},
|
|
712
|
+
persist: () => {
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Execute a component action
|
|
718
|
+
*/
|
|
719
|
+
async executeComponentAction(componentId, request) {
|
|
720
|
+
const startTime = Date.now();
|
|
721
|
+
try {
|
|
722
|
+
const component = this.registry.getComponent(componentId);
|
|
723
|
+
if (!component) {
|
|
724
|
+
return {
|
|
725
|
+
success: false,
|
|
726
|
+
error: `Component not found: ${componentId}`,
|
|
727
|
+
durationMs: Date.now() - startTime,
|
|
728
|
+
timestamp: Date.now(),
|
|
729
|
+
requestId: request.requestId
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
const action = component.actions.find((a) => a.id === request.action);
|
|
733
|
+
if (!action) {
|
|
734
|
+
return {
|
|
735
|
+
success: false,
|
|
736
|
+
error: `Action not found: ${request.action}`,
|
|
737
|
+
durationMs: Date.now() - startTime,
|
|
738
|
+
timestamp: Date.now(),
|
|
739
|
+
requestId: request.requestId
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
const result = await action.handler(request.params);
|
|
743
|
+
return {
|
|
744
|
+
success: true,
|
|
745
|
+
result,
|
|
746
|
+
durationMs: Date.now() - startTime,
|
|
747
|
+
timestamp: Date.now(),
|
|
748
|
+
requestId: request.requestId
|
|
749
|
+
};
|
|
750
|
+
} catch (error) {
|
|
751
|
+
return {
|
|
752
|
+
success: false,
|
|
753
|
+
error: error instanceof Error ? error.message : String(error),
|
|
754
|
+
stack: error instanceof Error ? error.stack : void 0,
|
|
755
|
+
durationMs: Date.now() - startTime,
|
|
756
|
+
timestamp: Date.now(),
|
|
757
|
+
requestId: request.requestId
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Find elements
|
|
763
|
+
*/
|
|
764
|
+
async find(request) {
|
|
765
|
+
const startTime = Date.now();
|
|
766
|
+
const allElements = this.registry.getAllElements();
|
|
767
|
+
let filtered = allElements;
|
|
768
|
+
if (request.types && request.types.length > 0) {
|
|
769
|
+
filtered = filtered.filter((e) => request.types.includes(e.type));
|
|
770
|
+
}
|
|
771
|
+
if (request.testIdPattern) {
|
|
772
|
+
const regex = new RegExp(
|
|
773
|
+
request.testIdPattern.replace(/\*/g, ".*").replace(/\?/g, ".")
|
|
774
|
+
);
|
|
775
|
+
filtered = filtered.filter((e) => {
|
|
776
|
+
const identifier = e.getIdentifier();
|
|
777
|
+
return identifier.testId && regex.test(identifier.testId);
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
if (request.accessibilityLabelPattern) {
|
|
781
|
+
const regex = new RegExp(
|
|
782
|
+
request.accessibilityLabelPattern.replace(/\*/g, ".*").replace(/\?/g, ".")
|
|
783
|
+
);
|
|
784
|
+
filtered = filtered.filter((e) => {
|
|
785
|
+
const identifier = e.getIdentifier();
|
|
786
|
+
return identifier.accessibilityLabel && regex.test(identifier.accessibilityLabel);
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
if (request.visibleOnly) {
|
|
790
|
+
filtered = filtered.filter((e) => e.getState().visible);
|
|
791
|
+
}
|
|
792
|
+
if (request.limit && request.limit > 0) {
|
|
793
|
+
filtered = filtered.slice(0, request.limit);
|
|
794
|
+
}
|
|
795
|
+
const elements = filtered.map((e) => ({
|
|
796
|
+
id: e.id,
|
|
797
|
+
type: e.type,
|
|
798
|
+
identifier: e.getIdentifier(),
|
|
799
|
+
state: e.getState(),
|
|
800
|
+
actions: e.actions,
|
|
801
|
+
label: e.label
|
|
802
|
+
}));
|
|
803
|
+
return {
|
|
804
|
+
elements,
|
|
805
|
+
total: elements.length,
|
|
806
|
+
durationMs: Date.now() - startTime,
|
|
807
|
+
timestamp: Date.now()
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Wait for element conditions
|
|
812
|
+
*/
|
|
813
|
+
async waitForElement(elementId, options) {
|
|
814
|
+
return this.waitForElementInternal(elementId, options);
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Internal wait implementation
|
|
818
|
+
*/
|
|
819
|
+
async waitForElementInternal(elementId, options) {
|
|
820
|
+
const opts = { ...DEFAULT_WAIT_OPTIONS, ...options };
|
|
821
|
+
const startTime = Date.now();
|
|
822
|
+
while (Date.now() - startTime < opts.timeout) {
|
|
823
|
+
const element = this.registry.getElement(elementId);
|
|
824
|
+
if (!element) {
|
|
825
|
+
await sleep(opts.interval);
|
|
826
|
+
continue;
|
|
827
|
+
}
|
|
828
|
+
const state = element.getState();
|
|
829
|
+
let conditionsMet = true;
|
|
830
|
+
if (opts.visible && !state.visible) {
|
|
831
|
+
conditionsMet = false;
|
|
832
|
+
}
|
|
833
|
+
if (opts.enabled && !state.enabled) {
|
|
834
|
+
conditionsMet = false;
|
|
835
|
+
}
|
|
836
|
+
if (opts.focused && !state.focused) {
|
|
837
|
+
conditionsMet = false;
|
|
838
|
+
}
|
|
839
|
+
if (opts.state && Object.keys(opts.state).length > 0) {
|
|
840
|
+
const stateRecord = state;
|
|
841
|
+
for (const [key, value] of Object.entries(opts.state)) {
|
|
842
|
+
if (stateRecord[key] !== value) {
|
|
843
|
+
conditionsMet = false;
|
|
844
|
+
break;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
if (conditionsMet) {
|
|
849
|
+
return {
|
|
850
|
+
met: true,
|
|
851
|
+
waitedMs: Date.now() - startTime,
|
|
852
|
+
state
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
await sleep(opts.interval);
|
|
856
|
+
}
|
|
857
|
+
return {
|
|
858
|
+
met: false,
|
|
859
|
+
waitedMs: Date.now() - startTime,
|
|
860
|
+
error: `Timeout waiting for conditions on element: ${elementId}`
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
function createNativeActionExecutor(registry) {
|
|
865
|
+
return new DefaultNativeActionExecutor(registry);
|
|
866
|
+
}
|
|
867
|
+
var UIBridgeNativeContext = react.createContext(null);
|
|
868
|
+
function UIBridgeNativeProvider({
|
|
869
|
+
children,
|
|
870
|
+
features = {},
|
|
871
|
+
config = {},
|
|
872
|
+
onEvent
|
|
873
|
+
}) {
|
|
874
|
+
const registryRef = react.useRef(null);
|
|
875
|
+
const executorRef = react.useRef(null);
|
|
876
|
+
const [serverRunning, setServerRunning] = react.useState(false);
|
|
877
|
+
if (!registryRef.current) {
|
|
878
|
+
registryRef.current = new NativeUIBridgeRegistry({
|
|
879
|
+
verbose: config.verbose,
|
|
880
|
+
onEvent
|
|
881
|
+
});
|
|
882
|
+
setGlobalRegistry(registryRef.current);
|
|
883
|
+
}
|
|
884
|
+
const registry = registryRef.current;
|
|
885
|
+
if (!executorRef.current) {
|
|
886
|
+
executorRef.current = createNativeActionExecutor(registry);
|
|
887
|
+
}
|
|
888
|
+
const executor = executorRef.current;
|
|
889
|
+
const startServer = react.useCallback(async () => {
|
|
890
|
+
if (!features.server) {
|
|
891
|
+
console.warn("[ui-bridge-native] Server feature not enabled");
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
console.log(
|
|
895
|
+
`[ui-bridge-native] Would start HTTP server on port ${config.serverPort || 9876}`
|
|
896
|
+
);
|
|
897
|
+
setServerRunning(true);
|
|
898
|
+
}, [features.server, config.serverPort]);
|
|
899
|
+
const stopServer = react.useCallback(() => {
|
|
900
|
+
console.log("[ui-bridge-native] Would stop HTTP server");
|
|
901
|
+
setServerRunning(false);
|
|
902
|
+
}, []);
|
|
903
|
+
react.useEffect(() => {
|
|
904
|
+
if (features.server) {
|
|
905
|
+
startServer();
|
|
906
|
+
return () => stopServer();
|
|
907
|
+
}
|
|
908
|
+
}, [features.server, startServer, stopServer]);
|
|
909
|
+
react.useEffect(() => {
|
|
910
|
+
return () => {
|
|
911
|
+
stopServer();
|
|
912
|
+
resetGlobalRegistry();
|
|
913
|
+
};
|
|
914
|
+
}, [stopServer]);
|
|
915
|
+
const getElements = react.useCallback(() => registry.getAllElements(), [registry]);
|
|
916
|
+
const getComponents = react.useCallback(() => registry.getAllComponents(), [registry]);
|
|
917
|
+
const createSnapshot = react.useCallback(() => registry.createSnapshot(), [registry]);
|
|
918
|
+
const on = react.useCallback(
|
|
919
|
+
(type, listener) => registry.on(type, listener),
|
|
920
|
+
[registry]
|
|
921
|
+
);
|
|
922
|
+
const off = react.useCallback(
|
|
923
|
+
(type, listener) => registry.off(type, listener),
|
|
924
|
+
[registry]
|
|
925
|
+
);
|
|
926
|
+
const contextValue = react.useMemo(
|
|
927
|
+
() => ({
|
|
928
|
+
features,
|
|
929
|
+
config,
|
|
930
|
+
registry,
|
|
931
|
+
executor,
|
|
932
|
+
getElements,
|
|
933
|
+
getComponents,
|
|
934
|
+
createSnapshot,
|
|
935
|
+
on,
|
|
936
|
+
off,
|
|
937
|
+
initialized: true,
|
|
938
|
+
serverRunning,
|
|
939
|
+
startServer,
|
|
940
|
+
stopServer
|
|
941
|
+
}),
|
|
942
|
+
[
|
|
943
|
+
features,
|
|
944
|
+
config,
|
|
945
|
+
registry,
|
|
946
|
+
executor,
|
|
947
|
+
getElements,
|
|
948
|
+
getComponents,
|
|
949
|
+
createSnapshot,
|
|
950
|
+
on,
|
|
951
|
+
off,
|
|
952
|
+
serverRunning,
|
|
953
|
+
startServer,
|
|
954
|
+
stopServer
|
|
955
|
+
]
|
|
956
|
+
);
|
|
957
|
+
return /* @__PURE__ */ jsxRuntime.jsx(UIBridgeNativeContext.Provider, { value: contextValue, children });
|
|
958
|
+
}
|
|
959
|
+
function useUIBridgeNative() {
|
|
960
|
+
const context = react.useContext(UIBridgeNativeContext);
|
|
961
|
+
if (!context) {
|
|
962
|
+
throw new Error("useUIBridgeNative must be used within a UIBridgeNativeProvider");
|
|
963
|
+
}
|
|
964
|
+
return context;
|
|
965
|
+
}
|
|
966
|
+
function useUIBridgeNativeOptional() {
|
|
967
|
+
return react.useContext(UIBridgeNativeContext);
|
|
968
|
+
}
|
|
969
|
+
var useUIBridgeNativeRequired = useUIBridgeNative;
|
|
970
|
+
function useUIElement(options) {
|
|
971
|
+
const bridge = useUIBridgeNativeOptional();
|
|
972
|
+
const ref = react.useRef(null);
|
|
973
|
+
const [registered, setRegistered] = react.useState(false);
|
|
974
|
+
const [_layout, setLayout] = react.useState(null);
|
|
975
|
+
const propsRef = react.useRef({});
|
|
976
|
+
const {
|
|
977
|
+
id,
|
|
978
|
+
type = "custom",
|
|
979
|
+
label,
|
|
980
|
+
actions,
|
|
981
|
+
customActions,
|
|
982
|
+
autoRegister = true,
|
|
983
|
+
onStateChange,
|
|
984
|
+
parentPath
|
|
985
|
+
} = options;
|
|
986
|
+
const treePath = parentPath ? `${parentPath}/${id}` : id;
|
|
987
|
+
const bridgeProps = react.useMemo(
|
|
988
|
+
() => ({
|
|
989
|
+
testID: id,
|
|
990
|
+
accessibilityLabel: label
|
|
991
|
+
}),
|
|
992
|
+
[id, label]
|
|
993
|
+
);
|
|
994
|
+
const register = react.useCallback(() => {
|
|
995
|
+
if (!bridge || registered) return;
|
|
996
|
+
bridge.registry.registerElement(id, ref, {
|
|
997
|
+
type,
|
|
998
|
+
label,
|
|
999
|
+
actions,
|
|
1000
|
+
customActions,
|
|
1001
|
+
treePath,
|
|
1002
|
+
testId: id,
|
|
1003
|
+
accessibilityLabel: label
|
|
1004
|
+
});
|
|
1005
|
+
setRegistered(true);
|
|
1006
|
+
}, [bridge, registered, id, type, label, actions, customActions, treePath]);
|
|
1007
|
+
const unregister = react.useCallback(() => {
|
|
1008
|
+
if (!bridge || !registered) return;
|
|
1009
|
+
bridge.registry.unregisterElement(id);
|
|
1010
|
+
setRegistered(false);
|
|
1011
|
+
}, [bridge, registered, id]);
|
|
1012
|
+
const onLayout = react.useCallback(
|
|
1013
|
+
(event) => {
|
|
1014
|
+
const { x, y, width, height } = event.nativeEvent.layout;
|
|
1015
|
+
if (ref.current && "measureInWindow" in ref.current) {
|
|
1016
|
+
ref.current.measureInWindow(
|
|
1017
|
+
(pageX, pageY) => {
|
|
1018
|
+
const newLayout = {
|
|
1019
|
+
x,
|
|
1020
|
+
y,
|
|
1021
|
+
width,
|
|
1022
|
+
height,
|
|
1023
|
+
pageX,
|
|
1024
|
+
pageY
|
|
1025
|
+
};
|
|
1026
|
+
setLayout(newLayout);
|
|
1027
|
+
if (bridge && registered) {
|
|
1028
|
+
const newState = {
|
|
1029
|
+
mounted: true,
|
|
1030
|
+
visible: width > 0 && height > 0,
|
|
1031
|
+
enabled: true,
|
|
1032
|
+
focused: false,
|
|
1033
|
+
layout: newLayout
|
|
1034
|
+
};
|
|
1035
|
+
bridge.registry.updateElementState(id, newState);
|
|
1036
|
+
onStateChange?.(newState);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
);
|
|
1040
|
+
} else {
|
|
1041
|
+
const newLayout = {
|
|
1042
|
+
x,
|
|
1043
|
+
y,
|
|
1044
|
+
width,
|
|
1045
|
+
height,
|
|
1046
|
+
pageX: x,
|
|
1047
|
+
pageY: y
|
|
1048
|
+
};
|
|
1049
|
+
setLayout(newLayout);
|
|
1050
|
+
if (bridge && registered) {
|
|
1051
|
+
const newState = {
|
|
1052
|
+
mounted: true,
|
|
1053
|
+
visible: width > 0 && height > 0,
|
|
1054
|
+
enabled: true,
|
|
1055
|
+
focused: false,
|
|
1056
|
+
layout: newLayout
|
|
1057
|
+
};
|
|
1058
|
+
bridge.registry.updateElementState(id, newState);
|
|
1059
|
+
onStateChange?.(newState);
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
},
|
|
1063
|
+
[bridge, registered, id, onStateChange]
|
|
1064
|
+
);
|
|
1065
|
+
react.useEffect(() => {
|
|
1066
|
+
if (autoRegister) {
|
|
1067
|
+
register();
|
|
1068
|
+
}
|
|
1069
|
+
return () => {
|
|
1070
|
+
unregister();
|
|
1071
|
+
};
|
|
1072
|
+
}, [autoRegister, register, unregister]);
|
|
1073
|
+
react.useCallback(
|
|
1074
|
+
(props) => {
|
|
1075
|
+
propsRef.current = { ...propsRef.current, ...props };
|
|
1076
|
+
if (bridge && registered) {
|
|
1077
|
+
bridge.registry.updateElementProps(id, props);
|
|
1078
|
+
}
|
|
1079
|
+
},
|
|
1080
|
+
[bridge, registered, id]
|
|
1081
|
+
);
|
|
1082
|
+
const getState = react.useCallback(() => {
|
|
1083
|
+
if (!bridge) return null;
|
|
1084
|
+
const element = bridge.registry.getElement(id);
|
|
1085
|
+
return element?.getState() || null;
|
|
1086
|
+
}, [bridge, id]);
|
|
1087
|
+
const getIdentifier = react.useCallback(() => {
|
|
1088
|
+
if (!bridge) return null;
|
|
1089
|
+
const element = bridge.registry.getElement(id);
|
|
1090
|
+
return element?.getIdentifier() || null;
|
|
1091
|
+
}, [bridge, id]);
|
|
1092
|
+
const trigger = react.useCallback(
|
|
1093
|
+
async (action, params) => {
|
|
1094
|
+
if (!bridge) {
|
|
1095
|
+
throw new Error("UI Bridge Native not available");
|
|
1096
|
+
}
|
|
1097
|
+
const response = await bridge.executor.executeAction(id, {
|
|
1098
|
+
action,
|
|
1099
|
+
params
|
|
1100
|
+
});
|
|
1101
|
+
if (!response.success) {
|
|
1102
|
+
throw new Error(response.error || "Action failed");
|
|
1103
|
+
}
|
|
1104
|
+
},
|
|
1105
|
+
[bridge, id]
|
|
1106
|
+
);
|
|
1107
|
+
const registeredElement = react.useMemo(() => {
|
|
1108
|
+
if (!bridge) return null;
|
|
1109
|
+
return bridge.registry.getElement(id) || null;
|
|
1110
|
+
}, [bridge, id, registered]);
|
|
1111
|
+
return {
|
|
1112
|
+
ref,
|
|
1113
|
+
onLayout,
|
|
1114
|
+
bridgeProps,
|
|
1115
|
+
registered,
|
|
1116
|
+
getState,
|
|
1117
|
+
getIdentifier,
|
|
1118
|
+
trigger,
|
|
1119
|
+
register,
|
|
1120
|
+
unregister,
|
|
1121
|
+
registeredElement
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
function useUIElementWithProps(options) {
|
|
1125
|
+
const elementReturn = useUIElement(options);
|
|
1126
|
+
const bridge = useUIBridgeNativeOptional();
|
|
1127
|
+
const captureProps = react.useCallback(
|
|
1128
|
+
(props) => {
|
|
1129
|
+
if (bridge && elementReturn.registered) {
|
|
1130
|
+
bridge.registry.updateElementProps(options.id, props);
|
|
1131
|
+
}
|
|
1132
|
+
},
|
|
1133
|
+
[bridge, elementReturn.registered, options.id]
|
|
1134
|
+
);
|
|
1135
|
+
return {
|
|
1136
|
+
...elementReturn,
|
|
1137
|
+
captureProps
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
function useUIComponent(options) {
|
|
1141
|
+
const bridge = useUIBridgeNativeOptional();
|
|
1142
|
+
const registeredRef = react.useRef(false);
|
|
1143
|
+
const actionsRef = react.useRef(options.actions || []);
|
|
1144
|
+
const elementIdsRef = react.useRef(options.elementIds || []);
|
|
1145
|
+
const { id, name, description, autoRegister = true } = options;
|
|
1146
|
+
react.useEffect(() => {
|
|
1147
|
+
actionsRef.current = options.actions || [];
|
|
1148
|
+
elementIdsRef.current = options.elementIds || [];
|
|
1149
|
+
}, [options.actions, options.elementIds]);
|
|
1150
|
+
const register = react.useCallback(() => {
|
|
1151
|
+
if (!bridge || registeredRef.current) return;
|
|
1152
|
+
bridge.registry.registerComponent(id, {
|
|
1153
|
+
name,
|
|
1154
|
+
description,
|
|
1155
|
+
actions: actionsRef.current.map((a) => ({
|
|
1156
|
+
id: a.id,
|
|
1157
|
+
label: a.label,
|
|
1158
|
+
description: a.description,
|
|
1159
|
+
handler: a.handler
|
|
1160
|
+
})),
|
|
1161
|
+
elementIds: elementIdsRef.current
|
|
1162
|
+
});
|
|
1163
|
+
registeredRef.current = true;
|
|
1164
|
+
}, [bridge, id, name, description]);
|
|
1165
|
+
const unregister = react.useCallback(() => {
|
|
1166
|
+
if (!bridge || !registeredRef.current) return;
|
|
1167
|
+
bridge.registry.unregisterComponent(id);
|
|
1168
|
+
registeredRef.current = false;
|
|
1169
|
+
}, [bridge, id]);
|
|
1170
|
+
const executeAction = react.useCallback(
|
|
1171
|
+
async (actionId, params) => {
|
|
1172
|
+
if (!bridge) {
|
|
1173
|
+
throw new Error("UI Bridge Native not available");
|
|
1174
|
+
}
|
|
1175
|
+
const response = await bridge.executor.executeComponentAction(id, {
|
|
1176
|
+
action: actionId,
|
|
1177
|
+
params
|
|
1178
|
+
});
|
|
1179
|
+
if (!response.success) {
|
|
1180
|
+
throw new Error(response.error || "Action failed");
|
|
1181
|
+
}
|
|
1182
|
+
return response.result;
|
|
1183
|
+
},
|
|
1184
|
+
[bridge, id]
|
|
1185
|
+
);
|
|
1186
|
+
const updateActions = react.useCallback(
|
|
1187
|
+
(actions) => {
|
|
1188
|
+
actionsRef.current = actions;
|
|
1189
|
+
if (registeredRef.current && bridge) {
|
|
1190
|
+
bridge.registry.unregisterComponent(id);
|
|
1191
|
+
registeredRef.current = false;
|
|
1192
|
+
register();
|
|
1193
|
+
}
|
|
1194
|
+
},
|
|
1195
|
+
[bridge, id, register]
|
|
1196
|
+
);
|
|
1197
|
+
const addElement = react.useCallback((elementId) => {
|
|
1198
|
+
if (!elementIdsRef.current.includes(elementId)) {
|
|
1199
|
+
elementIdsRef.current = [...elementIdsRef.current, elementId];
|
|
1200
|
+
}
|
|
1201
|
+
}, []);
|
|
1202
|
+
const removeElement = react.useCallback((elementId) => {
|
|
1203
|
+
elementIdsRef.current = elementIdsRef.current.filter((eid) => eid !== elementId);
|
|
1204
|
+
}, []);
|
|
1205
|
+
react.useEffect(() => {
|
|
1206
|
+
if (autoRegister) {
|
|
1207
|
+
register();
|
|
1208
|
+
}
|
|
1209
|
+
return () => {
|
|
1210
|
+
unregister();
|
|
1211
|
+
};
|
|
1212
|
+
}, [autoRegister, register, unregister]);
|
|
1213
|
+
const registeredComponent = react.useMemo(() => {
|
|
1214
|
+
if (!bridge) return null;
|
|
1215
|
+
return bridge.registry.getComponent(id) || null;
|
|
1216
|
+
}, [bridge, id, registeredRef.current]);
|
|
1217
|
+
return {
|
|
1218
|
+
registered: registeredRef.current,
|
|
1219
|
+
executeAction,
|
|
1220
|
+
register,
|
|
1221
|
+
unregister,
|
|
1222
|
+
updateActions,
|
|
1223
|
+
addElement,
|
|
1224
|
+
removeElement,
|
|
1225
|
+
registeredComponent
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
function useUIComponentAction(handler, deps) {
|
|
1229
|
+
return react.useCallback(handler, deps);
|
|
1230
|
+
}
|
|
1231
|
+
function useUIBridge() {
|
|
1232
|
+
const bridge = useUIBridgeNativeOptional();
|
|
1233
|
+
const available = bridge !== null;
|
|
1234
|
+
const initialized = bridge?.initialized ?? false;
|
|
1235
|
+
const elements = react.useMemo(
|
|
1236
|
+
() => bridge ? bridge.getElements() : [],
|
|
1237
|
+
[bridge]
|
|
1238
|
+
);
|
|
1239
|
+
const components = react.useMemo(
|
|
1240
|
+
() => bridge ? bridge.getComponents() : [],
|
|
1241
|
+
[bridge]
|
|
1242
|
+
);
|
|
1243
|
+
const workflows = react.useMemo(
|
|
1244
|
+
() => bridge ? bridge.registry.getAllWorkflows() : [],
|
|
1245
|
+
[bridge]
|
|
1246
|
+
);
|
|
1247
|
+
const createSnapshot = react.useCallback(() => {
|
|
1248
|
+
if (!bridge) {
|
|
1249
|
+
return {
|
|
1250
|
+
timestamp: Date.now(),
|
|
1251
|
+
elements: [],
|
|
1252
|
+
components: [],
|
|
1253
|
+
workflows: []
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
return bridge.createSnapshot();
|
|
1257
|
+
}, [bridge]);
|
|
1258
|
+
const executeAction = react.useCallback(
|
|
1259
|
+
async (elementId, request) => {
|
|
1260
|
+
if (!bridge) {
|
|
1261
|
+
return {
|
|
1262
|
+
success: false,
|
|
1263
|
+
error: "UI Bridge not available",
|
|
1264
|
+
durationMs: 0,
|
|
1265
|
+
timestamp: Date.now()
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
return bridge.executor.executeAction(elementId, request);
|
|
1269
|
+
},
|
|
1270
|
+
[bridge]
|
|
1271
|
+
);
|
|
1272
|
+
const executeComponentAction = react.useCallback(
|
|
1273
|
+
async (componentId, request) => {
|
|
1274
|
+
if (!bridge) {
|
|
1275
|
+
return {
|
|
1276
|
+
success: false,
|
|
1277
|
+
error: "UI Bridge not available",
|
|
1278
|
+
durationMs: 0,
|
|
1279
|
+
timestamp: Date.now()
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
return bridge.executor.executeComponentAction(componentId, request);
|
|
1283
|
+
},
|
|
1284
|
+
[bridge]
|
|
1285
|
+
);
|
|
1286
|
+
const find = react.useCallback(
|
|
1287
|
+
async (request) => {
|
|
1288
|
+
if (!bridge) {
|
|
1289
|
+
return {
|
|
1290
|
+
elements: [],
|
|
1291
|
+
total: 0,
|
|
1292
|
+
durationMs: 0,
|
|
1293
|
+
timestamp: Date.now()
|
|
1294
|
+
};
|
|
1295
|
+
}
|
|
1296
|
+
return bridge.executor.find(request || {});
|
|
1297
|
+
},
|
|
1298
|
+
[bridge]
|
|
1299
|
+
);
|
|
1300
|
+
const getElement = react.useCallback(
|
|
1301
|
+
(id) => bridge?.registry.getElement(id),
|
|
1302
|
+
[bridge]
|
|
1303
|
+
);
|
|
1304
|
+
const getComponent = react.useCallback(
|
|
1305
|
+
(id) => bridge?.registry.getComponent(id),
|
|
1306
|
+
[bridge]
|
|
1307
|
+
);
|
|
1308
|
+
const getElementState = react.useCallback(
|
|
1309
|
+
(id) => {
|
|
1310
|
+
const element = bridge?.registry.getElement(id);
|
|
1311
|
+
return element?.getState() ?? null;
|
|
1312
|
+
},
|
|
1313
|
+
[bridge]
|
|
1314
|
+
);
|
|
1315
|
+
const registerWorkflow = react.useCallback(
|
|
1316
|
+
(workflow) => {
|
|
1317
|
+
bridge?.registry.registerWorkflow(workflow);
|
|
1318
|
+
},
|
|
1319
|
+
[bridge]
|
|
1320
|
+
);
|
|
1321
|
+
const unregisterWorkflow = react.useCallback(
|
|
1322
|
+
(id) => {
|
|
1323
|
+
bridge?.registry.unregisterWorkflow(id);
|
|
1324
|
+
},
|
|
1325
|
+
[bridge]
|
|
1326
|
+
);
|
|
1327
|
+
return {
|
|
1328
|
+
available,
|
|
1329
|
+
initialized,
|
|
1330
|
+
elements,
|
|
1331
|
+
components,
|
|
1332
|
+
workflows,
|
|
1333
|
+
createSnapshot,
|
|
1334
|
+
executeAction,
|
|
1335
|
+
executeComponentAction,
|
|
1336
|
+
find,
|
|
1337
|
+
getElement,
|
|
1338
|
+
getComponent,
|
|
1339
|
+
getElementState,
|
|
1340
|
+
registerWorkflow,
|
|
1341
|
+
unregisterWorkflow
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
function useUIBridgeRequired() {
|
|
1345
|
+
const result = useUIBridge();
|
|
1346
|
+
if (!result.available) {
|
|
1347
|
+
throw new Error("useUIBridgeRequired must be used within a UIBridgeNativeProvider");
|
|
1348
|
+
}
|
|
1349
|
+
return result;
|
|
1350
|
+
}
|
|
1351
|
+
function useAutoRegister(options = {}) {
|
|
1352
|
+
const { enabled = false, onRegister, onUnregister } = options;
|
|
1353
|
+
const bridge = useUIBridgeNativeOptional();
|
|
1354
|
+
const registeredIdsRef = react.useRef(/* @__PURE__ */ new Set());
|
|
1355
|
+
const register = react.useCallback(
|
|
1356
|
+
(id, ref, elementOptions) => {
|
|
1357
|
+
if (!enabled || !bridge?.registry) return;
|
|
1358
|
+
if (registeredIdsRef.current.has(id)) return;
|
|
1359
|
+
bridge.registry.registerElement(id, ref, elementOptions);
|
|
1360
|
+
registeredIdsRef.current.add(id);
|
|
1361
|
+
onRegister?.(id);
|
|
1362
|
+
},
|
|
1363
|
+
[enabled, bridge, onRegister]
|
|
1364
|
+
);
|
|
1365
|
+
const unregister = react.useCallback(
|
|
1366
|
+
(id) => {
|
|
1367
|
+
if (!bridge?.registry) return;
|
|
1368
|
+
bridge.registry.unregisterElement(id);
|
|
1369
|
+
registeredIdsRef.current.delete(id);
|
|
1370
|
+
onUnregister?.(id);
|
|
1371
|
+
},
|
|
1372
|
+
[bridge, onUnregister]
|
|
1373
|
+
);
|
|
1374
|
+
react.useEffect(() => {
|
|
1375
|
+
return () => {
|
|
1376
|
+
registeredIdsRef.current.forEach((id) => {
|
|
1377
|
+
bridge?.registry.unregisterElement(id);
|
|
1378
|
+
});
|
|
1379
|
+
registeredIdsRef.current.clear();
|
|
1380
|
+
};
|
|
1381
|
+
}, [bridge]);
|
|
1382
|
+
return {
|
|
1383
|
+
register,
|
|
1384
|
+
unregister,
|
|
1385
|
+
isEnabled: enabled && !!bridge?.registry
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
exports.UIBridgeNativeProvider = UIBridgeNativeProvider;
|
|
1390
|
+
exports.useAutoRegister = useAutoRegister;
|
|
1391
|
+
exports.useUIBridge = useUIBridge;
|
|
1392
|
+
exports.useUIBridgeNative = useUIBridgeNative;
|
|
1393
|
+
exports.useUIBridgeNativeOptional = useUIBridgeNativeOptional;
|
|
1394
|
+
exports.useUIBridgeNativeRequired = useUIBridgeNativeRequired;
|
|
1395
|
+
exports.useUIBridgeRequired = useUIBridgeRequired;
|
|
1396
|
+
exports.useUIComponent = useUIComponent;
|
|
1397
|
+
exports.useUIComponentAction = useUIComponentAction;
|
|
1398
|
+
exports.useUIElement = useUIElement;
|
|
1399
|
+
exports.useUIElementWithProps = useUIElementWithProps;
|
|
1400
|
+
//# sourceMappingURL=index.js.map
|
|
1401
|
+
//# sourceMappingURL=index.js.map
|