decord/beta/source/modules/polls/native/useFocusHelper.tsx

194 lines
5.7 KiB
TypeScript
Raw Permalink Normal View History

2026-10-12 16:32:48 +00:00
// Module ID: 11918
// Function ID: 11919
// Name: useFocusHelper
2026-10-12 16:32:48 +00:00
// Dependencies: [19, 38, 6170, 2]
// Exports: default
2026-10-12 16:32:48 +00:00
// Module 11918 (useFocusHelper)
import _modDef38 from "module_38" /* 38 */;
2026-10-01 14:13:23 +00:00
import react from "react" /* 19 */;
import size from "module_2" /* 2 */;
2026-10-01 14:13:23 +00:00
function FocusHelperState() {
const merged = Object.assign({ refsByKey: null, keyOrder: null });
merged[0] = {};
merged[1] = [];
return merged;
2026-10-01 14:13:23 +00:00
}
class FocusHelperImpl {
constructor() {
2026-10-01 14:13:23 +00:00
const obj = Object.create(new.target.prototype);
if (typeof FocusHelperState === "function") {
const merged = Object.assign({ refsByKey: null, keyOrder: null });
merged[0] = {};
merged[1] = [];
obj.validState = merged;
obj.focusNext = function focusNext() {
2026-10-01 14:13:23 +00:00
let keyOrder;
let refsByKey;
({ refsByKey, keyOrder } = obj.validState);
let tmp2;
const keys = Object.keys();
if (keys !== undefined) {
while (keys[tmp] !== undefined) {
let tmp12 = refsByKey[tmp4];
let isFocusedResult;
if (tmp12 != null) {
let current = tmp12.current;
if (current != null) {
isFocusedResult = current.isFocused();
}
}
tmp2 = tmp4;
if (true === isFocusedResult) {
break;
}
}
}
if (null != tmp2) {
const index = keyOrder.indexOf(tmp2);
if (-1 !== index) {
if (index < keyOrder.length - 1) {
if (refsByKey[obj.validState.keyOrder[index + 1]] != null) {
const current2 = tmp8.current;
if (current2 != null) {
current2.focus();
}
}
}
}
onAddAnswer = obj.onAddAnswer;
if (onAddAnswer != null) {
onAddAnswer();
}
}
};
obj.focus = function focus(arg0) {
if (obj.validState.refsByKey[arg0] != null) {
const current = tmp.current;
if (current != null) {
current.focus();
}
}
};
return obj;
} else {
throw new TypeError("Trying to call a non-function");
}
}
2026-10-01 14:13:23 +00:00
restartState() {
if (typeof FocusHelperState === "function") {
const self = this;
const merged = Object.assign({ refsByKey: null, keyOrder: null });
merged[0] = {};
merged[1] = [];
this.pendingState = merged;
} else {
throw new TypeError("Trying to call a non-function");
}
}
2026-10-01 14:13:23 +00:00
commitState() {
const self = this;
const pendingState = this.pendingState;
if (null != pendingState) {
self.validState = pendingState;
}
self.pendingState = undefined;
}
2026-10-01 14:13:23 +00:00
refWithKey(question) {
const pendingState = this.pendingState;
_modDef38(null != pendingState, "Called refWithKey without a valid state");
const keyOrder = pendingState.keyOrder;
keyOrder.push(question);
if (null != pendingState.refsByKey[question]) {
return pendingState.refsByKey[question];
} else {
const ref = react.createRef();
pendingState.refsByKey[question] = ref;
return ref;
}
}
2026-10-01 14:13:23 +00:00
}
const prototype = FocusHelperImpl.prototype;
const result = size.fileFinishedImporting("modules/polls/native/useFocusHelper.tsx");
export default function useFocusHelper() {
let obj = arg0;
if (arg0 === undefined) {
obj = {};
}
let onAddAnswer = obj.onAddAnswer;
let obj2;
2026-10-01 14:13:23 +00:00
obj2 = onAddAnswer(obj2[2])(function() {
if (typeof FocusHelperImpl === "function") {
const obj = Object.create(FocusHelperImpl.prototype);
2026-10-01 14:13:23 +00:00
const self = this;
if (typeof FocusHelperState === "function") {
const merged = Object.assign({ refsByKey: null, keyOrder: null });
merged[0] = {};
merged[1] = [];
obj.validState = merged;
obj.focusNext = function focusNext() {
2026-10-01 14:13:23 +00:00
let keyOrder;
let refsByKey;
({ refsByKey, keyOrder } = obj.validState);
let tmp2;
const keys = Object.keys();
if (keys !== undefined) {
while (keys[tmp] !== undefined) {
let tmp12 = refsByKey[tmp4];
let isFocusedResult;
if (tmp12 != null) {
let current = tmp12.current;
if (current != null) {
isFocusedResult = current.isFocused();
}
}
tmp2 = tmp4;
if (true === isFocusedResult) {
break;
}
}
}
if (null != tmp2) {
const index = keyOrder.indexOf(tmp2);
if (-1 !== index) {
if (index < keyOrder.length - 1) {
if (refsByKey[obj.validState.keyOrder[index + 1]] != null) {
const current2 = tmp8.current;
if (current2 != null) {
current2.focus();
}
}
}
}
onAddAnswer = obj.onAddAnswer;
if (onAddAnswer != null) {
onAddAnswer();
}
}
};
obj.focus = function focus(arg0) {
if (obj.validState.refsByKey[arg0] != null) {
const current = tmp.current;
if (current != null) {
current.focus();
}
}
};
return obj;
} else {
throw new TypeError("Trying to call a non-function");
}
} else {
throw new TypeError("Trying to call a non-function");
}
});
obj2.restartState();
2026-10-01 14:13:23 +00:00
const effect = react.useEffect(() => {
obj2.onAddAnswer = onAddAnswer;
obj2.commitState();
});
return obj2;
};