@tamagui/focusable 1.29.6 → 1.30.0-1685833167060
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/cjs/focusableInputHOC.js +62 -48
- package/dist/cjs/focusableInputHOC.js.map +2 -2
- package/dist/esm/focusableInputHOC.js +61 -48
- package/dist/esm/focusableInputHOC.js.map +2 -2
- package/dist/jsx/focusableInputHOC.js +58 -45
- package/dist/jsx/focusableInputHOC.js.map +2 -2
- package/dist/jsx/focusableInputHOC.mjs +58 -45
- package/dist/jsx/focusableInputHOC.mjs.map +2 -2
- package/package.json +4 -4
- package/src/focusableInputHOC.tsx +71 -57
- package/types/focusable.d.ts.map +1 -0
- package/types/focusableInputHOC.d.ts +16 -0
- package/types/focusableInputHOC.d.ts.map +1 -0
- package/types/index.d.ts.map +1 -0
- package/types/registerFocusable.d.ts.map +1 -0
- package/types/registerFocusable.native.d.ts.map +1 -0
|
@@ -18,7 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var focusableInputHOC_exports = {};
|
|
20
20
|
__export(focusableInputHOC_exports, {
|
|
21
|
-
focusableInputHOC: () => focusableInputHOC
|
|
21
|
+
focusableInputHOC: () => focusableInputHOC,
|
|
22
|
+
useFocusable: () => useFocusable
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(focusableInputHOC_exports);
|
|
24
25
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -26,58 +27,71 @@ var import_compose_refs = require("@tamagui/compose-refs");
|
|
|
26
27
|
var import_web = require("@tamagui/web");
|
|
27
28
|
var import_react = require("react");
|
|
28
29
|
var import_registerFocusable = require("./registerFocusable");
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
30
|
+
function useFocusable({
|
|
31
|
+
isInput,
|
|
32
|
+
props,
|
|
33
|
+
ref
|
|
34
|
+
}) {
|
|
35
|
+
const { id, onChangeText, value, defaultValue } = props;
|
|
36
|
+
const inputValue = (0, import_react.useRef)(value || defaultValue || "");
|
|
37
|
+
const unregisterFocusable = (0, import_react.useRef)();
|
|
38
|
+
const inputRef = (0, import_react.useCallback)(
|
|
39
|
+
(input) => {
|
|
40
|
+
var _a;
|
|
41
|
+
if (!id)
|
|
42
|
+
return;
|
|
43
|
+
if (!input)
|
|
44
|
+
return;
|
|
45
|
+
(_a = unregisterFocusable.current) == null ? void 0 : _a.call(unregisterFocusable);
|
|
46
|
+
unregisterFocusable.current = (0, import_registerFocusable.registerFocusable)(id, {
|
|
47
|
+
focus: input.focus,
|
|
48
|
+
...isInput && {
|
|
49
|
+
// react-native doesn't support programmatic .select()
|
|
50
|
+
focusAndSelect() {
|
|
51
|
+
input.focus();
|
|
52
|
+
if (input.setSelection && typeof inputValue.current === "string") {
|
|
53
|
+
input.setSelection(0, inputValue.current.length);
|
|
53
54
|
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
[isInput, props.id]
|
|
57
|
-
);
|
|
58
|
-
const combinedRefs = (0, import_compose_refs.composeRefs)(ref, inputRef);
|
|
59
|
-
(0, import_react.useEffect)(() => {
|
|
60
|
-
return () => {
|
|
61
|
-
var _a;
|
|
62
|
-
(_a = unregisterFocusable.current) == null ? void 0 : _a.call(unregisterFocusable);
|
|
63
|
-
};
|
|
64
|
-
}, []);
|
|
65
|
-
const onChangeText = (0, import_web.useEvent)((value) => {
|
|
66
|
-
var _a;
|
|
67
|
-
inputValue.current = value;
|
|
68
|
-
(_a = props.onChangeText) == null ? void 0 : _a.call(props, value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
69
57
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
onChangeText
|
|
73
|
-
} : props;
|
|
74
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ref: combinedRefs, ...finalProps });
|
|
75
|
-
}
|
|
58
|
+
},
|
|
59
|
+
[isInput, id]
|
|
76
60
|
);
|
|
77
|
-
|
|
61
|
+
const combinedRefs = (0, import_compose_refs.composeRefs)(ref, inputRef);
|
|
62
|
+
(0, import_react.useEffect)(() => {
|
|
63
|
+
return () => {
|
|
64
|
+
var _a;
|
|
65
|
+
(_a = unregisterFocusable.current) == null ? void 0 : _a.call(unregisterFocusable);
|
|
66
|
+
};
|
|
67
|
+
}, []);
|
|
68
|
+
return {
|
|
69
|
+
ref: combinedRefs,
|
|
70
|
+
onChangeText: (0, import_web.useEvent)((value2) => {
|
|
71
|
+
inputValue.current = value2;
|
|
72
|
+
onChangeText == null ? void 0 : onChangeText(value2);
|
|
73
|
+
})
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function focusableInputHOC(Component) {
|
|
77
|
+
return Component.styleable((props, ref) => {
|
|
78
|
+
var _a;
|
|
79
|
+
const isInput = (_a = Component.staticConfig) == null ? void 0 : _a.isInput;
|
|
80
|
+
const { ref: combinedRef, onChangeText } = useFocusable({
|
|
81
|
+
ref,
|
|
82
|
+
props,
|
|
83
|
+
isInput
|
|
84
|
+
});
|
|
85
|
+
const finalProps = isInput ? {
|
|
86
|
+
...props,
|
|
87
|
+
onChangeText
|
|
88
|
+
} : props;
|
|
89
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ref: combinedRef, ...finalProps });
|
|
90
|
+
});
|
|
78
91
|
}
|
|
79
92
|
// Annotate the CommonJS export names for ESM import in node:
|
|
80
93
|
0 && (module.exports = {
|
|
81
|
-
focusableInputHOC
|
|
94
|
+
focusableInputHOC,
|
|
95
|
+
useFocusable
|
|
82
96
|
});
|
|
83
97
|
//# sourceMappingURL=focusableInputHOC.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/focusableInputHOC.tsx"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
5
|
-
"names": []
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiFW;AAjFX,0BAA4B;AAC5B,iBAA2C;AAC3C,mBAAsD;AAEtD,+BAAkC;AAS3B,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,QAAM,EAAE,IAAI,cAAc,OAAO,aAAa,IAAI;AAClD,QAAM,iBAAa,qBAAO,SAAS,gBAAgB,EAAE;AACrD,QAAM,0BAAsB,qBAA+B;AAE3D,QAAM,eAAW;AAAA,IACf,CAAC,UAAU;AA3Bf;AA4BM,UAAI,CAAC;AAAI;AACT,UAAI,CAAC;AAAO;AACZ,gCAAoB,YAApB;AACA,0BAAoB,cAAU,4CAAkB,IAAI;AAAA,QAClD,OAAO,MAAM;AAAA,QAEb,GAAI,WAAW;AAAA;AAAA,UAEb,iBAAiB;AACf,kBAAM,MAAM;AACZ,gBAAI,MAAM,gBAAgB,OAAO,WAAW,YAAY,UAAU;AAChE,oBAAM,aAAa,GAAG,WAAW,QAAQ,MAAM;AAAA,YACjD;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IACA,CAAC,SAAS,EAAE;AAAA,EACd;AAEA,QAAM,mBAAe,iCAAY,KAAK,QAAQ;AAE9C,8BAAU,MAAM;AACd,WAAO,MAAM;AAnDjB;AAoDM,gCAAoB,YAApB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AAAA,IACL,KAAK;AAAA,IACL,kBAAc,qBAAS,CAACA,WAAU;AAChC,iBAAW,UAAUA;AACrB,mDAAeA;AAAA,IACjB,CAAC;AAAA,EACH;AACF;AAEO,SAAS,kBAA8C,WAAiB;AAC7E,SAAO,UAAU,UAAU,CAAC,OAAuB,QAAQ;AAlE7D;AAmEI,UAAM,WAAU,eAAU,iBAAV,mBAAwB;AACxC,UAAM,EAAE,KAAK,aAAa,aAAa,IAAI,aAAa;AAAA,MACtD;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AACD,UAAM,aAAa,UACf;AAAA,MACE,GAAG;AAAA,MACH;AAAA,IACF,IACA;AAGJ,WAAO,4CAAC,aAAU,KAAK,aAAc,GAAG,YAAY;AAAA,EACtD,CAAC;AACH;",
|
|
5
|
+
"names": ["value"]
|
|
6
6
|
}
|
|
@@ -1,59 +1,72 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { composeRefs } from "@tamagui/compose-refs";
|
|
3
|
-
import {
|
|
3
|
+
import { useEvent } from "@tamagui/web";
|
|
4
4
|
import { useCallback, useEffect, useRef } from "react";
|
|
5
5
|
import { registerFocusable } from "./registerFocusable";
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
6
|
+
function useFocusable({
|
|
7
|
+
isInput,
|
|
8
|
+
props,
|
|
9
|
+
ref
|
|
10
|
+
}) {
|
|
11
|
+
const { id, onChangeText, value, defaultValue } = props;
|
|
12
|
+
const inputValue = useRef(value || defaultValue || "");
|
|
13
|
+
const unregisterFocusable = useRef();
|
|
14
|
+
const inputRef = useCallback(
|
|
15
|
+
(input) => {
|
|
16
|
+
var _a;
|
|
17
|
+
if (!id)
|
|
18
|
+
return;
|
|
19
|
+
if (!input)
|
|
20
|
+
return;
|
|
21
|
+
(_a = unregisterFocusable.current) == null ? void 0 : _a.call(unregisterFocusable);
|
|
22
|
+
unregisterFocusable.current = registerFocusable(id, {
|
|
23
|
+
focus: input.focus,
|
|
24
|
+
...isInput && {
|
|
25
|
+
// react-native doesn't support programmatic .select()
|
|
26
|
+
focusAndSelect() {
|
|
27
|
+
input.focus();
|
|
28
|
+
if (input.setSelection && typeof inputValue.current === "string") {
|
|
29
|
+
input.setSelection(0, inputValue.current.length);
|
|
30
30
|
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
[isInput, props.id]
|
|
34
|
-
);
|
|
35
|
-
const combinedRefs = composeRefs(ref, inputRef);
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
return () => {
|
|
38
|
-
var _a;
|
|
39
|
-
(_a = unregisterFocusable.current) == null ? void 0 : _a.call(unregisterFocusable);
|
|
40
|
-
};
|
|
41
|
-
}, []);
|
|
42
|
-
const onChangeText = useEvent((value) => {
|
|
43
|
-
var _a;
|
|
44
|
-
inputValue.current = value;
|
|
45
|
-
(_a = props.onChangeText) == null ? void 0 : _a.call(props, value);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
46
33
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
onChangeText
|
|
50
|
-
} : props;
|
|
51
|
-
return /* @__PURE__ */ jsx(Component, { ref: combinedRefs, ...finalProps });
|
|
52
|
-
}
|
|
34
|
+
},
|
|
35
|
+
[isInput, id]
|
|
53
36
|
);
|
|
54
|
-
|
|
37
|
+
const combinedRefs = composeRefs(ref, inputRef);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
return () => {
|
|
40
|
+
var _a;
|
|
41
|
+
(_a = unregisterFocusable.current) == null ? void 0 : _a.call(unregisterFocusable);
|
|
42
|
+
};
|
|
43
|
+
}, []);
|
|
44
|
+
return {
|
|
45
|
+
ref: combinedRefs,
|
|
46
|
+
onChangeText: useEvent((value2) => {
|
|
47
|
+
inputValue.current = value2;
|
|
48
|
+
onChangeText == null ? void 0 : onChangeText(value2);
|
|
49
|
+
})
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function focusableInputHOC(Component) {
|
|
53
|
+
return Component.styleable((props, ref) => {
|
|
54
|
+
var _a;
|
|
55
|
+
const isInput = (_a = Component.staticConfig) == null ? void 0 : _a.isInput;
|
|
56
|
+
const { ref: combinedRef, onChangeText } = useFocusable({
|
|
57
|
+
ref,
|
|
58
|
+
props,
|
|
59
|
+
isInput
|
|
60
|
+
});
|
|
61
|
+
const finalProps = isInput ? {
|
|
62
|
+
...props,
|
|
63
|
+
onChangeText
|
|
64
|
+
} : props;
|
|
65
|
+
return /* @__PURE__ */ jsx(Component, { ref: combinedRef, ...finalProps });
|
|
66
|
+
});
|
|
55
67
|
}
|
|
56
68
|
export {
|
|
57
|
-
focusableInputHOC
|
|
69
|
+
focusableInputHOC,
|
|
70
|
+
useFocusable
|
|
58
71
|
};
|
|
59
72
|
//# sourceMappingURL=focusableInputHOC.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/focusableInputHOC.tsx"],
|
|
4
|
-
"mappings": "
|
|
5
|
-
"names": []
|
|
4
|
+
"mappings": "AAiFW;AAjFX,SAAS,mBAAmB;AAC5B,SAA2B,gBAAgB;AAC3C,SAAgB,aAAa,WAAW,cAAc;AAEtD,SAAS,yBAAyB;AAS3B,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,QAAM,EAAE,IAAI,cAAc,OAAO,aAAa,IAAI;AAClD,QAAM,aAAa,OAAO,SAAS,gBAAgB,EAAE;AACrD,QAAM,sBAAsB,OAA+B;AAE3D,QAAM,WAAW;AAAA,IACf,CAAC,UAAU;AA3Bf;AA4BM,UAAI,CAAC;AAAI;AACT,UAAI,CAAC;AAAO;AACZ,gCAAoB,YAApB;AACA,0BAAoB,UAAU,kBAAkB,IAAI;AAAA,QAClD,OAAO,MAAM;AAAA,QAEb,GAAI,WAAW;AAAA;AAAA,UAEb,iBAAiB;AACf,kBAAM,MAAM;AACZ,gBAAI,MAAM,gBAAgB,OAAO,WAAW,YAAY,UAAU;AAChE,oBAAM,aAAa,GAAG,WAAW,QAAQ,MAAM;AAAA,YACjD;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IACA,CAAC,SAAS,EAAE;AAAA,EACd;AAEA,QAAM,eAAe,YAAY,KAAK,QAAQ;AAE9C,YAAU,MAAM;AACd,WAAO,MAAM;AAnDjB;AAoDM,gCAAoB,YAApB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AAAA,IACL,KAAK;AAAA,IACL,cAAc,SAAS,CAACA,WAAU;AAChC,iBAAW,UAAUA;AACrB,mDAAeA;AAAA,IACjB,CAAC;AAAA,EACH;AACF;AAEO,SAAS,kBAA8C,WAAiB;AAC7E,SAAO,UAAU,UAAU,CAAC,OAAuB,QAAQ;AAlE7D;AAmEI,UAAM,WAAU,eAAU,iBAAV,mBAAwB;AACxC,UAAM,EAAE,KAAK,aAAa,aAAa,IAAI,aAAa;AAAA,MACtD;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AACD,UAAM,aAAa,UACf;AAAA,MACE,GAAG;AAAA,MACH;AAAA,IACF,IACA;AAGJ,WAAO,oBAAC,aAAU,KAAK,aAAc,GAAG,YAAY;AAAA,EACtD,CAAC;AACH;",
|
|
5
|
+
"names": ["value"]
|
|
6
6
|
}
|
|
@@ -1,55 +1,68 @@
|
|
|
1
1
|
import { composeRefs } from "@tamagui/compose-refs";
|
|
2
|
-
import {
|
|
2
|
+
import { useEvent } from "@tamagui/web";
|
|
3
3
|
import { useCallback, useEffect, useRef } from "react";
|
|
4
4
|
import { registerFocusable } from "./registerFocusable";
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
function useFocusable({
|
|
6
|
+
isInput,
|
|
7
|
+
props,
|
|
8
|
+
ref
|
|
9
|
+
}) {
|
|
10
|
+
const { id, onChangeText, value, defaultValue } = props;
|
|
11
|
+
const inputValue = useRef(value || defaultValue || "");
|
|
12
|
+
const unregisterFocusable = useRef();
|
|
13
|
+
const inputRef = useCallback(
|
|
14
|
+
(input) => {
|
|
15
|
+
if (!id)
|
|
16
|
+
return;
|
|
17
|
+
if (!input)
|
|
18
|
+
return;
|
|
19
|
+
unregisterFocusable.current?.();
|
|
20
|
+
unregisterFocusable.current = registerFocusable(id, {
|
|
21
|
+
focus: input.focus,
|
|
22
|
+
...isInput && {
|
|
23
|
+
// react-native doesn't support programmatic .select()
|
|
24
|
+
focusAndSelect() {
|
|
25
|
+
input.focus();
|
|
26
|
+
if (input.setSelection && typeof inputValue.current === "string") {
|
|
27
|
+
input.setSelection(0, inputValue.current.length);
|
|
28
28
|
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
[isInput, props.id]
|
|
32
|
-
);
|
|
33
|
-
const combinedRefs = composeRefs(ref, inputRef);
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
return () => {
|
|
36
|
-
unregisterFocusable.current?.();
|
|
37
|
-
};
|
|
38
|
-
}, []);
|
|
39
|
-
const onChangeText = useEvent((value) => {
|
|
40
|
-
inputValue.current = value;
|
|
41
|
-
props.onChangeText?.(value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
42
31
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
onChangeText
|
|
46
|
-
} : props;
|
|
47
|
-
return <Component ref={combinedRefs} {...finalProps} />;
|
|
48
|
-
}
|
|
32
|
+
},
|
|
33
|
+
[isInput, id]
|
|
49
34
|
);
|
|
50
|
-
|
|
35
|
+
const combinedRefs = composeRefs(ref, inputRef);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
return () => {
|
|
38
|
+
unregisterFocusable.current?.();
|
|
39
|
+
};
|
|
40
|
+
}, []);
|
|
41
|
+
return {
|
|
42
|
+
ref: combinedRefs,
|
|
43
|
+
onChangeText: useEvent((value2) => {
|
|
44
|
+
inputValue.current = value2;
|
|
45
|
+
onChangeText?.(value2);
|
|
46
|
+
})
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function focusableInputHOC(Component) {
|
|
50
|
+
return Component.styleable((props, ref) => {
|
|
51
|
+
const isInput = Component.staticConfig?.isInput;
|
|
52
|
+
const { ref: combinedRef, onChangeText } = useFocusable({
|
|
53
|
+
ref,
|
|
54
|
+
props,
|
|
55
|
+
isInput
|
|
56
|
+
});
|
|
57
|
+
const finalProps = isInput ? {
|
|
58
|
+
...props,
|
|
59
|
+
onChangeText
|
|
60
|
+
} : props;
|
|
61
|
+
return <Component ref={combinedRef} {...finalProps} />;
|
|
62
|
+
});
|
|
51
63
|
}
|
|
52
64
|
export {
|
|
53
|
-
focusableInputHOC
|
|
65
|
+
focusableInputHOC,
|
|
66
|
+
useFocusable
|
|
54
67
|
};
|
|
55
68
|
//# sourceMappingURL=focusableInputHOC.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/focusableInputHOC.tsx"],
|
|
4
|
-
"mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAA2B,
|
|
5
|
-
"names": []
|
|
4
|
+
"mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAA2B,gBAAgB;AAC3C,SAAgB,aAAa,WAAW,cA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A,EACtD,CAAC;AACH;",
|
|
5
|
+
"names": ["value"]
|
|
6
6
|
}
|
|
@@ -1,55 +1,68 @@
|
|
|
1
1
|
import { composeRefs } from "@tamagui/compose-refs";
|
|
2
|
-
import {
|
|
2
|
+
import { useEvent } from "@tamagui/web";
|
|
3
3
|
import { useCallback, useEffect, useRef } from "react";
|
|
4
4
|
import { registerFocusable } from "./registerFocusable";
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
function useFocusable({
|
|
6
|
+
isInput,
|
|
7
|
+
props,
|
|
8
|
+
ref
|
|
9
|
+
}) {
|
|
10
|
+
const { id, onChangeText, value, defaultValue } = props;
|
|
11
|
+
const inputValue = useRef(value || defaultValue || "");
|
|
12
|
+
const unregisterFocusable = useRef();
|
|
13
|
+
const inputRef = useCallback(
|
|
14
|
+
(input) => {
|
|
15
|
+
if (!id)
|
|
16
|
+
return;
|
|
17
|
+
if (!input)
|
|
18
|
+
return;
|
|
19
|
+
unregisterFocusable.current?.();
|
|
20
|
+
unregisterFocusable.current = registerFocusable(id, {
|
|
21
|
+
focus: input.focus,
|
|
22
|
+
...isInput && {
|
|
23
|
+
// react-native doesn't support programmatic .select()
|
|
24
|
+
focusAndSelect() {
|
|
25
|
+
input.focus();
|
|
26
|
+
if (input.setSelection && typeof inputValue.current === "string") {
|
|
27
|
+
input.setSelection(0, inputValue.current.length);
|
|
28
28
|
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
[isInput, props.id]
|
|
32
|
-
);
|
|
33
|
-
const combinedRefs = composeRefs(ref, inputRef);
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
return () => {
|
|
36
|
-
unregisterFocusable.current?.();
|
|
37
|
-
};
|
|
38
|
-
}, []);
|
|
39
|
-
const onChangeText = useEvent((value) => {
|
|
40
|
-
inputValue.current = value;
|
|
41
|
-
props.onChangeText?.(value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
42
31
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
onChangeText
|
|
46
|
-
} : props;
|
|
47
|
-
return <Component ref={combinedRefs} {...finalProps} />;
|
|
48
|
-
}
|
|
32
|
+
},
|
|
33
|
+
[isInput, id]
|
|
49
34
|
);
|
|
50
|
-
|
|
35
|
+
const combinedRefs = composeRefs(ref, inputRef);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
return () => {
|
|
38
|
+
unregisterFocusable.current?.();
|
|
39
|
+
};
|
|
40
|
+
}, []);
|
|
41
|
+
return {
|
|
42
|
+
ref: combinedRefs,
|
|
43
|
+
onChangeText: useEvent((value2) => {
|
|
44
|
+
inputValue.current = value2;
|
|
45
|
+
onChangeText?.(value2);
|
|
46
|
+
})
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function focusableInputHOC(Component) {
|
|
50
|
+
return Component.styleable((props, ref) => {
|
|
51
|
+
const isInput = Component.staticConfig?.isInput;
|
|
52
|
+
const { ref: combinedRef, onChangeText } = useFocusable({
|
|
53
|
+
ref,
|
|
54
|
+
props,
|
|
55
|
+
isInput
|
|
56
|
+
});
|
|
57
|
+
const finalProps = isInput ? {
|
|
58
|
+
...props,
|
|
59
|
+
onChangeText
|
|
60
|
+
} : props;
|
|
61
|
+
return <Component ref={combinedRef} {...finalProps} />;
|
|
62
|
+
});
|
|
51
63
|
}
|
|
52
64
|
export {
|
|
53
|
-
focusableInputHOC
|
|
65
|
+
focusableInputHOC,
|
|
66
|
+
useFocusable
|
|
54
67
|
};
|
|
55
68
|
//# sourceMappingURL=focusableInputHOC.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
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UAAM,UAAU,UAAU,cAAc;AACxC,UAAM,EAAE,KAAK,aAAa,aAAa,IAAI,aAAa;AAAA,MACtD;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AACD,UAAM,aAAa,UACf;AAAA,MACE,GAAG;AAAA,MACH;AAAA,IACF,IACA;AAGJ,WAAO,CAAC,UAAU,KAAK,iBAAiB,YAAY;AAAA,EACtD,CAAC;AACH;",
|
|
5
|
+
"names": ["value"]
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/focusable",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.0-1685833167060",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"clean:build": "tamagui-build clean:build"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@tamagui/compose-refs": "1.
|
|
26
|
-
"@tamagui/web": "1.
|
|
25
|
+
"@tamagui/compose-refs": "1.30.0-1685833167060",
|
|
26
|
+
"@tamagui/web": "1.30.0-1685833167060"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "*"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tamagui/build": "1.
|
|
32
|
+
"@tamagui/build": "1.30.0-1685833167060",
|
|
33
33
|
"react": "^18.2.0"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
@@ -1,70 +1,84 @@
|
|
|
1
1
|
import { composeRefs } from '@tamagui/compose-refs'
|
|
2
|
-
import { TamaguiComponent,
|
|
3
|
-
import { useCallback, useEffect, useRef } from 'react'
|
|
2
|
+
import { TamaguiComponent, useEvent } from '@tamagui/web'
|
|
3
|
+
import React, { useCallback, useEffect, useRef } from 'react'
|
|
4
4
|
|
|
5
5
|
import { registerFocusable } from './registerFocusable'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
value?: string
|
|
14
|
-
defaultValue?: string
|
|
15
|
-
},
|
|
16
|
-
ref
|
|
17
|
-
) => {
|
|
18
|
-
const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput
|
|
19
|
-
const inputValue = useRef(props.value || props.defaultValue || '')
|
|
20
|
-
const unregisterFocusable = useRef<() => void | undefined>()
|
|
21
|
-
|
|
22
|
-
const inputRef = useCallback(
|
|
23
|
-
(input) => {
|
|
24
|
-
if (!props.id) return
|
|
25
|
-
if (!input) return
|
|
26
|
-
unregisterFocusable.current?.()
|
|
27
|
-
unregisterFocusable.current = registerFocusable(props.id, {
|
|
28
|
-
focus: input.focus,
|
|
29
|
-
|
|
30
|
-
...(isInput && {
|
|
31
|
-
// react-native doesn't support programmatic .select()
|
|
32
|
-
focusAndSelect() {
|
|
33
|
-
input.focus()
|
|
34
|
-
if (input.setSelection && typeof inputValue.current === 'string') {
|
|
35
|
-
input.setSelection(0, inputValue.current.length)
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
}),
|
|
39
|
-
})
|
|
40
|
-
},
|
|
41
|
-
[isInput, props.id]
|
|
42
|
-
)
|
|
7
|
+
type FocusableProps = {
|
|
8
|
+
id?: string
|
|
9
|
+
onChangeText?: (val: string) => void
|
|
10
|
+
value?: string
|
|
11
|
+
defaultValue?: string
|
|
12
|
+
}
|
|
43
13
|
|
|
44
|
-
|
|
14
|
+
export function useFocusable({
|
|
15
|
+
isInput,
|
|
16
|
+
props,
|
|
17
|
+
ref,
|
|
18
|
+
}: {
|
|
19
|
+
isInput?: boolean
|
|
20
|
+
props: FocusableProps
|
|
21
|
+
ref?: React.MutableRefObject<any>
|
|
22
|
+
}) {
|
|
23
|
+
const { id, onChangeText, value, defaultValue } = props
|
|
24
|
+
const inputValue = useRef(value || defaultValue || '')
|
|
25
|
+
const unregisterFocusable = useRef<() => void | undefined>()
|
|
45
26
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
27
|
+
const inputRef = useCallback(
|
|
28
|
+
(input) => {
|
|
29
|
+
if (!id) return
|
|
30
|
+
if (!input) return
|
|
31
|
+
unregisterFocusable.current?.()
|
|
32
|
+
unregisterFocusable.current = registerFocusable(id, {
|
|
33
|
+
focus: input.focus,
|
|
51
34
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
35
|
+
...(isInput && {
|
|
36
|
+
// react-native doesn't support programmatic .select()
|
|
37
|
+
focusAndSelect() {
|
|
38
|
+
input.focus()
|
|
39
|
+
if (input.setSelection && typeof inputValue.current === 'string') {
|
|
40
|
+
input.setSelection(0, inputValue.current.length)
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
55
44
|
})
|
|
45
|
+
},
|
|
46
|
+
[isInput, id]
|
|
47
|
+
)
|
|
56
48
|
|
|
57
|
-
|
|
58
|
-
? {
|
|
59
|
-
...props,
|
|
60
|
-
onChangeText,
|
|
61
|
-
}
|
|
62
|
-
: props
|
|
49
|
+
const combinedRefs = composeRefs(ref, inputRef)
|
|
63
50
|
|
|
64
|
-
|
|
65
|
-
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
return () => {
|
|
53
|
+
unregisterFocusable.current?.()
|
|
66
54
|
}
|
|
67
|
-
)
|
|
55
|
+
}, [])
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
ref: combinedRefs,
|
|
59
|
+
onChangeText: useEvent((value) => {
|
|
60
|
+
inputValue.current = value
|
|
61
|
+
onChangeText?.(value)
|
|
62
|
+
}),
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function focusableInputHOC<A extends TamaguiComponent>(Component: A): A {
|
|
67
|
+
return Component.styleable((props: FocusableProps, ref) => {
|
|
68
|
+
const isInput = Component.staticConfig?.isInput
|
|
69
|
+
const { ref: combinedRef, onChangeText } = useFocusable({
|
|
70
|
+
ref,
|
|
71
|
+
props,
|
|
72
|
+
isInput,
|
|
73
|
+
})
|
|
74
|
+
const finalProps = isInput
|
|
75
|
+
? {
|
|
76
|
+
...props,
|
|
77
|
+
onChangeText,
|
|
78
|
+
}
|
|
79
|
+
: props
|
|
68
80
|
|
|
69
|
-
|
|
81
|
+
// @ts-expect-error
|
|
82
|
+
return <Component ref={combinedRef} {...finalProps} />
|
|
83
|
+
}) as any
|
|
70
84
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"focusable.d.ts","sourceRoot":"","sources":["../src/focusable.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,cAAc,CAAC,EAAE,QAAQ,CAAA;CAAE,CAAA"}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
import { TamaguiComponent } from '@tamagui/web';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
type FocusableProps = {
|
|
4
|
+
id?: string;
|
|
5
|
+
onChangeText?: (val: string) => void;
|
|
6
|
+
value?: string;
|
|
7
|
+
defaultValue?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function useFocusable({ isInput, props, ref, }: {
|
|
10
|
+
isInput?: boolean;
|
|
11
|
+
props: FocusableProps;
|
|
12
|
+
ref?: React.MutableRefObject<any>;
|
|
13
|
+
}): {
|
|
14
|
+
ref: (node: any) => void;
|
|
15
|
+
onChangeText: (value: any) => void;
|
|
16
|
+
};
|
|
2
17
|
export declare function focusableInputHOC<A extends TamaguiComponent>(Component: A): A;
|
|
18
|
+
export {};
|
|
3
19
|
//# sourceMappingURL=focusableInputHOC.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"focusableInputHOC.d.ts","sourceRoot":"","sources":["../src/focusableInputHOC.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAY,MAAM,cAAc,CAAA;AACzD,OAAO,KAAyC,MAAM,OAAO,CAAA;AAI7D,KAAK,cAAc,GAAG;IACpB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IACpC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,KAAK,EACL,GAAG,GACJ,EAAE;IACD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,cAAc,CAAA;IACrB,GAAG,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAA;CAClC;;;EA0CA;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,gBAAgB,EAAE,SAAS,EAAE,CAAC,GAAG,CAAC,CAkB7E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerFocusable.d.ts","sourceRoot":"","sources":["../src/registerFocusable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,eAAO,MAAM,iBAAiB,OAAQ,MAAM,SAAS,SAAS,eAE7D,CAAA;AAED,eAAO,MAAM,mBAAmB,OAAQ,MAAM,SAE7C,CAAA;AAED,eAAO,MAAM,cAAc,OAAQ,MAAM,SAExC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerFocusable.native.d.ts","sourceRoot":"","sources":["../src/registerFocusable.native.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAIvC,eAAO,MAAM,iBAAiB,OAAQ,MAAM,SAAS,SAAS,eAU7D,CAAA;AAED,eAAO,MAAM,mBAAmB,OAAQ,MAAM,SAE7C,CAAA;AAED,eAAO,MAAM,cAAc,OAAQ,MAAM,2BAaxC,CAAA"}
|