@tamagui/focusable 1.0.1-beta.206 → 1.0.1-beta.208

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.
@@ -28,53 +28,56 @@ var import_react = require("react");
28
28
  var import_react2 = require("react");
29
29
  var import_registerFocusable = require("./registerFocusable");
30
30
  function focusableInputHOC(Component) {
31
- return (0, import_react2.forwardRef)(
32
- (props, ref) => {
33
- const isInput = (0, import_core.isTamaguiComponent)(Component) && Component.staticConfig.isInput;
34
- const inputValue = (0, import_react.useRef)(props.value || props.defaultValue || "");
35
- const inputRef = (0, import_react2.useCallback)(
36
- (input) => {
37
- if (!props.id)
38
- return;
39
- if (!input)
40
- return;
41
- (0, import_registerFocusable.registerFocusable)(props.id, {
42
- focus: input.focus,
43
- ...isInput && {
44
- focusAndSelect() {
45
- input.focus();
46
- if (input.setSelection && typeof inputValue.current === "string") {
47
- input.setSelection(0, inputValue.current.length);
31
+ const component = Component.extractable(
32
+ (0, import_react2.forwardRef)(
33
+ (props, ref) => {
34
+ const isInput = (0, import_core.isTamaguiComponent)(Component) && Component.staticConfig.isInput;
35
+ const inputValue = (0, import_react.useRef)(props.value || props.defaultValue || "");
36
+ const inputRef = (0, import_react2.useCallback)(
37
+ (input) => {
38
+ if (!props.id)
39
+ return;
40
+ if (!input)
41
+ return;
42
+ (0, import_registerFocusable.registerFocusable)(props.id, {
43
+ focus: input.focus,
44
+ ...isInput && {
45
+ focusAndSelect() {
46
+ input.focus();
47
+ if (input.setSelection && typeof inputValue.current === "string") {
48
+ input.setSelection(0, inputValue.current.length);
49
+ }
48
50
  }
49
51
  }
50
- }
51
- });
52
- },
53
- [isInput, props.id]
54
- );
55
- const combinedRefs = (0, import_compose_refs.composeRefs)(ref, inputRef);
56
- (0, import_react2.useEffect)(() => {
57
- if (!props.id)
58
- return;
59
- return () => {
60
- (0, import_registerFocusable.unregisterFocusable)(props.id);
61
- };
62
- }, [props.id]);
63
- const onChangeText = (0, import_core.useEvent)((value) => {
64
- var _a;
65
- inputValue.current = value;
66
- (_a = props.onChangeText) == null ? void 0 : _a.call(props, value);
67
- });
68
- const finalProps = isInput ? {
69
- ...props,
70
- onChangeText
71
- } : props;
72
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {
73
- ref: combinedRefs,
74
- ...finalProps
75
- });
76
- }
52
+ });
53
+ },
54
+ [isInput, props.id]
55
+ );
56
+ const combinedRefs = (0, import_compose_refs.composeRefs)(ref, inputRef);
57
+ (0, import_react2.useEffect)(() => {
58
+ if (!props.id)
59
+ return;
60
+ return () => {
61
+ (0, import_registerFocusable.unregisterFocusable)(props.id);
62
+ };
63
+ }, [props.id]);
64
+ const onChangeText = (0, import_core.useEvent)((value) => {
65
+ var _a;
66
+ inputValue.current = value;
67
+ (_a = props.onChangeText) == null ? void 0 : _a.call(props, value);
68
+ });
69
+ const finalProps = isInput ? {
70
+ ...props,
71
+ onChangeText
72
+ } : props;
73
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {
74
+ ref: combinedRefs,
75
+ ...finalProps
76
+ });
77
+ }
78
+ )
77
79
  );
80
+ return component;
78
81
  }
79
82
  // Annotate the CommonJS export names for ESM import in node:
80
83
  0 && (module.exports = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/focusableInputHOC.tsx"],
4
- "sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { isTamaguiComponent, useEvent } from '@tamagui/core'\nimport React, { useRef } from 'react'\nimport { forwardRef, useCallback, useEffect } from 'react'\n\nimport { registerFocusable, unregisterFocusable } from './registerFocusable'\n\nexport function focusableInputHOC<A extends Function>(Component: A): A {\n return forwardRef(\n (\n props: {\n id?: string\n onChangeText?: (val: string) => void\n value?: string\n defaultValue?: string\n },\n ref\n ) => {\n const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput\n const inputValue = useRef(props.value || props.defaultValue || '')\n\n const inputRef = useCallback(\n (input) => {\n if (!props.id) return\n if (!input) return\n registerFocusable(props.id, {\n focus: input.focus,\n\n ...(isInput && {\n // react-native doesn't support programmatic .select()\n focusAndSelect() {\n input.focus()\n if (input.setSelection && typeof inputValue.current === 'string') {\n input.setSelection(0, inputValue.current.length)\n }\n },\n }),\n })\n },\n [isInput, props.id]\n )\n\n const combinedRefs = composeRefs(ref, inputRef)\n\n useEffect(() => {\n if (!props.id) return\n return () => {\n unregisterFocusable(props.id!)\n }\n }, [props.id])\n\n const onChangeText = useEvent((value) => {\n inputValue.current = value\n props.onChangeText?.(value)\n })\n\n const finalProps = isInput\n ? {\n ...props,\n onChangeText,\n }\n : props\n\n return <Component ref={combinedRefs} {...finalProps} />\n }\n ) as any\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+Da;AA/Db,0BAA4B;AAC5B,kBAA6C;AAC7C,mBAA8B;AAC9B,IAAAA,gBAAmD;AAEnD,+BAAuD;AAEhD,SAAS,kBAAsC,WAAiB;AACrE,aAAO;AAAA,IACL,CACE,OAMA,QACG;AACH,YAAM,cAAU,gCAAmB,SAAS,KAAK,UAAU,aAAa;AACxE,YAAM,iBAAa,qBAAO,MAAM,SAAS,MAAM,gBAAgB,EAAE;AAEjE,YAAM,eAAW;AAAA,QACf,CAAC,UAAU;AACT,cAAI,CAAC,MAAM;AAAI;AACf,cAAI,CAAC;AAAO;AACZ,0DAAkB,MAAM,IAAI;AAAA,YAC1B,OAAO,MAAM;AAAA,YAEb,GAAI,WAAW;AAAA,cAEb,iBAAiB;AACf,sBAAM,MAAM;AACZ,oBAAI,MAAM,gBAAgB,OAAO,WAAW,YAAY,UAAU;AAChE,wBAAM,aAAa,GAAG,WAAW,QAAQ,MAAM;AAAA,gBACjD;AAAA,cACF;AAAA,YACF;AAAA,UACF,CAAC;AAAA,QACH;AAAA,QACA,CAAC,SAAS,MAAM,EAAE;AAAA,MACpB;AAEA,YAAM,mBAAe,iCAAY,KAAK,QAAQ;AAE9C,mCAAU,MAAM;AACd,YAAI,CAAC,MAAM;AAAI;AACf,eAAO,MAAM;AACX,4DAAoB,MAAM,EAAG;AAAA,QAC/B;AAAA,MACF,GAAG,CAAC,MAAM,EAAE,CAAC;AAEb,YAAM,mBAAe,sBAAS,CAAC,UAAU;AAnD/C;AAoDQ,mBAAW,UAAU;AACrB,oBAAM,iBAAN,+BAAqB;AAAA,MACvB,CAAC;AAED,YAAM,aAAa,UACf;AAAA,QACE,GAAG;AAAA,QACH;AAAA,MACF,IACA;AAEJ,aAAO,4CAAC;AAAA,QAAU,KAAK;AAAA,QAAe,GAAG;AAAA,OAAY;AAAA,IACvD;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { TamaguiComponent, isTamaguiComponent, useEvent } from '@tamagui/core'\nimport React, { useRef } from 'react'\nimport { forwardRef, useCallback, useEffect } from 'react'\n\nimport { registerFocusable, unregisterFocusable } from './registerFocusable'\n\nexport function focusableInputHOC<A extends TamaguiComponent>(Component: A): A {\n const component = Component.extractable(\n forwardRef(\n (\n props: {\n id?: string\n onChangeText?: (val: string) => void\n value?: string\n defaultValue?: string\n },\n ref\n ) => {\n const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput\n const inputValue = useRef(props.value || props.defaultValue || '')\n\n const inputRef = useCallback(\n (input) => {\n if (!props.id) return\n if (!input) return\n registerFocusable(props.id, {\n focus: input.focus,\n\n ...(isInput && {\n // react-native doesn't support programmatic .select()\n focusAndSelect() {\n input.focus()\n if (input.setSelection && typeof inputValue.current === 'string') {\n input.setSelection(0, inputValue.current.length)\n }\n },\n }),\n })\n },\n [isInput, props.id]\n )\n\n const combinedRefs = composeRefs(ref, inputRef)\n\n useEffect(() => {\n if (!props.id) return\n return () => {\n unregisterFocusable(props.id!)\n }\n }, [props.id])\n\n const onChangeText = useEvent((value) => {\n inputValue.current = value\n props.onChangeText?.(value)\n })\n\n const finalProps = isInput\n ? {\n ...props,\n onChangeText,\n }\n : props\n\n // @ts-expect-error\n return <Component ref={combinedRefs} {...finalProps} />\n }\n )\n ) as any\n\n return component\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiEe;AAjEf,0BAA4B;AAC5B,kBAA+D;AAC/D,mBAA8B;AAC9B,IAAAA,gBAAmD;AAEnD,+BAAuD;AAEhD,SAAS,kBAA8C,WAAiB;AAC7E,QAAM,YAAY,UAAU;AAAA,QAC1B;AAAA,MACE,CACE,OAMA,QACG;AACH,cAAM,cAAU,gCAAmB,SAAS,KAAK,UAAU,aAAa;AACxE,cAAM,iBAAa,qBAAO,MAAM,SAAS,MAAM,gBAAgB,EAAE;AAEjE,cAAM,eAAW;AAAA,UACf,CAAC,UAAU;AACT,gBAAI,CAAC,MAAM;AAAI;AACf,gBAAI,CAAC;AAAO;AACZ,4DAAkB,MAAM,IAAI;AAAA,cAC1B,OAAO,MAAM;AAAA,cAEb,GAAI,WAAW;AAAA,gBAEb,iBAAiB;AACf,wBAAM,MAAM;AACZ,sBAAI,MAAM,gBAAgB,OAAO,WAAW,YAAY,UAAU;AAChE,0BAAM,aAAa,GAAG,WAAW,QAAQ,MAAM;AAAA,kBACjD;AAAA,gBACF;AAAA,cACF;AAAA,YACF,CAAC;AAAA,UACH;AAAA,UACA,CAAC,SAAS,MAAM,EAAE;AAAA,QACpB;AAEA,cAAM,mBAAe,iCAAY,KAAK,QAAQ;AAE9C,qCAAU,MAAM;AACd,cAAI,CAAC,MAAM;AAAI;AACf,iBAAO,MAAM;AACX,8DAAoB,MAAM,EAAG;AAAA,UAC/B;AAAA,QACF,GAAG,CAAC,MAAM,EAAE,CAAC;AAEb,cAAM,mBAAe,sBAAS,CAAC,UAAU;AApDjD;AAqDU,qBAAW,UAAU;AACrB,sBAAM,iBAAN,+BAAqB;AAAA,QACvB,CAAC;AAED,cAAM,aAAa,UACf;AAAA,UACE,GAAG;AAAA,UACH;AAAA,QACF,IACA;AAGJ,eAAO,4CAAC;AAAA,UAAU,KAAK;AAAA,UAAe,GAAG;AAAA,SAAY;AAAA,MACvD;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
6
6
  "names": ["import_react"]
7
7
  }
@@ -5,53 +5,56 @@ import { useRef } from "react";
5
5
  import { forwardRef, useCallback, useEffect } from "react";
6
6
  import { registerFocusable, unregisterFocusable } from "./registerFocusable";
7
7
  function focusableInputHOC(Component) {
8
- return forwardRef(
9
- (props, ref) => {
10
- const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput;
11
- const inputValue = useRef(props.value || props.defaultValue || "");
12
- const inputRef = useCallback(
13
- (input) => {
14
- if (!props.id)
15
- return;
16
- if (!input)
17
- return;
18
- registerFocusable(props.id, {
19
- focus: input.focus,
20
- ...isInput && {
21
- focusAndSelect() {
22
- input.focus();
23
- if (input.setSelection && typeof inputValue.current === "string") {
24
- input.setSelection(0, inputValue.current.length);
8
+ const component = Component.extractable(
9
+ forwardRef(
10
+ (props, ref) => {
11
+ const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput;
12
+ const inputValue = useRef(props.value || props.defaultValue || "");
13
+ const inputRef = useCallback(
14
+ (input) => {
15
+ if (!props.id)
16
+ return;
17
+ if (!input)
18
+ return;
19
+ registerFocusable(props.id, {
20
+ focus: input.focus,
21
+ ...isInput && {
22
+ focusAndSelect() {
23
+ input.focus();
24
+ if (input.setSelection && typeof inputValue.current === "string") {
25
+ input.setSelection(0, inputValue.current.length);
26
+ }
25
27
  }
26
28
  }
27
- }
28
- });
29
- },
30
- [isInput, props.id]
31
- );
32
- const combinedRefs = composeRefs(ref, inputRef);
33
- useEffect(() => {
34
- if (!props.id)
35
- return;
36
- return () => {
37
- unregisterFocusable(props.id);
38
- };
39
- }, [props.id]);
40
- const onChangeText = useEvent((value) => {
41
- var _a;
42
- inputValue.current = value;
43
- (_a = props.onChangeText) == null ? void 0 : _a.call(props, value);
44
- });
45
- const finalProps = isInput ? {
46
- ...props,
47
- onChangeText
48
- } : props;
49
- return /* @__PURE__ */ jsx(Component, {
50
- ref: combinedRefs,
51
- ...finalProps
52
- });
53
- }
29
+ });
30
+ },
31
+ [isInput, props.id]
32
+ );
33
+ const combinedRefs = composeRefs(ref, inputRef);
34
+ useEffect(() => {
35
+ if (!props.id)
36
+ return;
37
+ return () => {
38
+ unregisterFocusable(props.id);
39
+ };
40
+ }, [props.id]);
41
+ const onChangeText = useEvent((value) => {
42
+ var _a;
43
+ inputValue.current = value;
44
+ (_a = props.onChangeText) == null ? void 0 : _a.call(props, value);
45
+ });
46
+ const finalProps = isInput ? {
47
+ ...props,
48
+ onChangeText
49
+ } : props;
50
+ return /* @__PURE__ */ jsx(Component, {
51
+ ref: combinedRefs,
52
+ ...finalProps
53
+ });
54
+ }
55
+ )
54
56
  );
57
+ return component;
55
58
  }
56
59
  export {
57
60
  focusableInputHOC
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/focusableInputHOC.tsx"],
4
- "sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { isTamaguiComponent, useEvent } from '@tamagui/core'\nimport React, { useRef } from 'react'\nimport { forwardRef, useCallback, useEffect } from 'react'\n\nimport { registerFocusable, unregisterFocusable } from './registerFocusable'\n\nexport function focusableInputHOC<A extends Function>(Component: A): A {\n return forwardRef(\n (\n props: {\n id?: string\n onChangeText?: (val: string) => void\n value?: string\n defaultValue?: string\n },\n ref\n ) => {\n const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput\n const inputValue = useRef(props.value || props.defaultValue || '')\n\n const inputRef = useCallback(\n (input) => {\n if (!props.id) return\n if (!input) return\n registerFocusable(props.id, {\n focus: input.focus,\n\n ...(isInput && {\n // react-native doesn't support programmatic .select()\n focusAndSelect() {\n input.focus()\n if (input.setSelection && typeof inputValue.current === 'string') {\n input.setSelection(0, inputValue.current.length)\n }\n },\n }),\n })\n },\n [isInput, props.id]\n )\n\n const combinedRefs = composeRefs(ref, inputRef)\n\n useEffect(() => {\n if (!props.id) return\n return () => {\n unregisterFocusable(props.id!)\n }\n }, [props.id])\n\n const onChangeText = useEvent((value) => {\n inputValue.current = value\n props.onChangeText?.(value)\n })\n\n const finalProps = isInput\n ? {\n ...props,\n onChangeText,\n }\n : props\n\n return <Component ref={combinedRefs} {...finalProps} />\n }\n ) as any\n}\n"],
5
- "mappings": "AA+Da;AA/Db,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB,gBAAgB;AAC7C,SAAgB,cAAc;AAC9B,SAAS,YAAY,aAAa,iBAAiB;AAEnD,SAAS,mBAAmB,2BAA2B;AAEhD,SAAS,kBAAsC,WAAiB;AACrE,SAAO;AAAA,IACL,CACE,OAMA,QACG;AACH,YAAM,UAAU,mBAAmB,SAAS,KAAK,UAAU,aAAa;AACxE,YAAM,aAAa,OAAO,MAAM,SAAS,MAAM,gBAAgB,EAAE;AAEjE,YAAM,WAAW;AAAA,QACf,CAAC,UAAU;AACT,cAAI,CAAC,MAAM;AAAI;AACf,cAAI,CAAC;AAAO;AACZ,4BAAkB,MAAM,IAAI;AAAA,YAC1B,OAAO,MAAM;AAAA,YAEb,GAAI,WAAW;AAAA,cAEb,iBAAiB;AACf,sBAAM,MAAM;AACZ,oBAAI,MAAM,gBAAgB,OAAO,WAAW,YAAY,UAAU;AAChE,wBAAM,aAAa,GAAG,WAAW,QAAQ,MAAM;AAAA,gBACjD;AAAA,cACF;AAAA,YACF;AAAA,UACF,CAAC;AAAA,QACH;AAAA,QACA,CAAC,SAAS,MAAM,EAAE;AAAA,MACpB;AAEA,YAAM,eAAe,YAAY,KAAK,QAAQ;AAE9C,gBAAU,MAAM;AACd,YAAI,CAAC,MAAM;AAAI;AACf,eAAO,MAAM;AACX,8BAAoB,MAAM,EAAG;AAAA,QAC/B;AAAA,MACF,GAAG,CAAC,MAAM,EAAE,CAAC;AAEb,YAAM,eAAe,SAAS,CAAC,UAAU;AAnD/C;AAoDQ,mBAAW,UAAU;AACrB,oBAAM,iBAAN,+BAAqB;AAAA,MACvB,CAAC;AAED,YAAM,aAAa,UACf;AAAA,QACE,GAAG;AAAA,QACH;AAAA,MACF,IACA;AAEJ,aAAO,oBAAC;AAAA,QAAU,KAAK;AAAA,QAAe,GAAG;AAAA,OAAY;AAAA,IACvD;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { TamaguiComponent, isTamaguiComponent, useEvent } from '@tamagui/core'\nimport React, { useRef } from 'react'\nimport { forwardRef, useCallback, useEffect } from 'react'\n\nimport { registerFocusable, unregisterFocusable } from './registerFocusable'\n\nexport function focusableInputHOC<A extends TamaguiComponent>(Component: A): A {\n const component = Component.extractable(\n forwardRef(\n (\n props: {\n id?: string\n onChangeText?: (val: string) => void\n value?: string\n defaultValue?: string\n },\n ref\n ) => {\n const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput\n const inputValue = useRef(props.value || props.defaultValue || '')\n\n const inputRef = useCallback(\n (input) => {\n if (!props.id) return\n if (!input) return\n registerFocusable(props.id, {\n focus: input.focus,\n\n ...(isInput && {\n // react-native doesn't support programmatic .select()\n focusAndSelect() {\n input.focus()\n if (input.setSelection && typeof inputValue.current === 'string') {\n input.setSelection(0, inputValue.current.length)\n }\n },\n }),\n })\n },\n [isInput, props.id]\n )\n\n const combinedRefs = composeRefs(ref, inputRef)\n\n useEffect(() => {\n if (!props.id) return\n return () => {\n unregisterFocusable(props.id!)\n }\n }, [props.id])\n\n const onChangeText = useEvent((value) => {\n inputValue.current = value\n props.onChangeText?.(value)\n })\n\n const finalProps = isInput\n ? {\n ...props,\n onChangeText,\n }\n : props\n\n // @ts-expect-error\n return <Component ref={combinedRefs} {...finalProps} />\n }\n )\n ) as any\n\n return component\n}\n"],
5
+ "mappings": "AAiEe;AAjEf,SAAS,mBAAmB;AAC5B,SAA2B,oBAAoB,gBAAgB;AAC/D,SAAgB,cAAc;AAC9B,SAAS,YAAY,aAAa,iBAAiB;AAEnD,SAAS,mBAAmB,2BAA2B;AAEhD,SAAS,kBAA8C,WAAiB;AAC7E,QAAM,YAAY,UAAU;AAAA,IAC1B;AAAA,MACE,CACE,OAMA,QACG;AACH,cAAM,UAAU,mBAAmB,SAAS,KAAK,UAAU,aAAa;AACxE,cAAM,aAAa,OAAO,MAAM,SAAS,MAAM,gBAAgB,EAAE;AAEjE,cAAM,WAAW;AAAA,UACf,CAAC,UAAU;AACT,gBAAI,CAAC,MAAM;AAAI;AACf,gBAAI,CAAC;AAAO;AACZ,8BAAkB,MAAM,IAAI;AAAA,cAC1B,OAAO,MAAM;AAAA,cAEb,GAAI,WAAW;AAAA,gBAEb,iBAAiB;AACf,wBAAM,MAAM;AACZ,sBAAI,MAAM,gBAAgB,OAAO,WAAW,YAAY,UAAU;AAChE,0BAAM,aAAa,GAAG,WAAW,QAAQ,MAAM;AAAA,kBACjD;AAAA,gBACF;AAAA,cACF;AAAA,YACF,CAAC;AAAA,UACH;AAAA,UACA,CAAC,SAAS,MAAM,EAAE;AAAA,QACpB;AAEA,cAAM,eAAe,YAAY,KAAK,QAAQ;AAE9C,kBAAU,MAAM;AACd,cAAI,CAAC,MAAM;AAAI;AACf,iBAAO,MAAM;AACX,gCAAoB,MAAM,EAAG;AAAA,UAC/B;AAAA,QACF,GAAG,CAAC,MAAM,EAAE,CAAC;AAEb,cAAM,eAAe,SAAS,CAAC,UAAU;AApDjD;AAqDU,qBAAW,UAAU;AACrB,sBAAM,iBAAN,+BAAqB;AAAA,QACvB,CAAC;AAED,cAAM,aAAa,UACf;AAAA,UACE,GAAG;AAAA,UACH;AAAA,QACF,IACA;AAGJ,eAAO,oBAAC;AAAA,UAAU,KAAK;AAAA,UAAe,GAAG;AAAA,SAAY;AAAA,MACvD;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -4,49 +4,52 @@ import { useRef } from "react";
4
4
  import { forwardRef, useCallback, useEffect } from "react";
5
5
  import { registerFocusable, unregisterFocusable } from "./registerFocusable";
6
6
  function focusableInputHOC(Component) {
7
- return forwardRef(
8
- (props, ref) => {
9
- const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput;
10
- const inputValue = useRef(props.value || props.defaultValue || "");
11
- const inputRef = useCallback(
12
- (input) => {
13
- if (!props.id)
14
- return;
15
- if (!input)
16
- return;
17
- registerFocusable(props.id, {
18
- focus: input.focus,
19
- ...isInput && {
20
- focusAndSelect() {
21
- input.focus();
22
- if (input.setSelection && typeof inputValue.current === "string") {
23
- input.setSelection(0, inputValue.current.length);
7
+ const component = Component.extractable(
8
+ forwardRef(
9
+ (props, ref) => {
10
+ const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput;
11
+ const inputValue = useRef(props.value || props.defaultValue || "");
12
+ const inputRef = useCallback(
13
+ (input) => {
14
+ if (!props.id)
15
+ return;
16
+ if (!input)
17
+ return;
18
+ registerFocusable(props.id, {
19
+ focus: input.focus,
20
+ ...isInput && {
21
+ focusAndSelect() {
22
+ input.focus();
23
+ if (input.setSelection && typeof inputValue.current === "string") {
24
+ input.setSelection(0, inputValue.current.length);
25
+ }
24
26
  }
25
27
  }
26
- }
27
- });
28
- },
29
- [isInput, props.id]
30
- );
31
- const combinedRefs = composeRefs(ref, inputRef);
32
- useEffect(() => {
33
- if (!props.id)
34
- return;
35
- return () => {
36
- unregisterFocusable(props.id);
37
- };
38
- }, [props.id]);
39
- const onChangeText = useEvent((value) => {
40
- inputValue.current = value;
41
- props.onChangeText?.(value);
42
- });
43
- const finalProps = isInput ? {
44
- ...props,
45
- onChangeText
46
- } : props;
47
- return <Component ref={combinedRefs} {...finalProps} />;
48
- }
28
+ });
29
+ },
30
+ [isInput, props.id]
31
+ );
32
+ const combinedRefs = composeRefs(ref, inputRef);
33
+ useEffect(() => {
34
+ if (!props.id)
35
+ return;
36
+ return () => {
37
+ unregisterFocusable(props.id);
38
+ };
39
+ }, [props.id]);
40
+ const onChangeText = useEvent((value) => {
41
+ inputValue.current = value;
42
+ props.onChangeText?.(value);
43
+ });
44
+ const finalProps = isInput ? {
45
+ ...props,
46
+ onChangeText
47
+ } : props;
48
+ return <Component ref={combinedRefs} {...finalProps} />;
49
+ }
50
+ )
49
51
  );
52
+ return component;
50
53
  }
51
54
  export {
52
55
  focusableInputHOC
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/focusableInputHOC.tsx"],
4
- "sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { isTamaguiComponent, useEvent } from '@tamagui/core'\nimport React, { useRef } from 'react'\nimport { forwardRef, useCallback, useEffect } from 'react'\n\nimport { registerFocusable, unregisterFocusable } from './registerFocusable'\n\nexport function focusableInputHOC<A extends Function>(Component: A): A {\n return forwardRef(\n (\n props: {\n id?: string\n onChangeText?: (val: string) => void\n value?: string\n defaultValue?: string\n },\n ref\n ) => {\n const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput\n const inputValue = useRef(props.value || props.defaultValue || '')\n\n const inputRef = useCallback(\n (input) => {\n if (!props.id) return\n if (!input) return\n registerFocusable(props.id, {\n focus: input.focus,\n\n ...(isInput && {\n // react-native doesn't support programmatic .select()\n focusAndSelect() {\n input.focus()\n if (input.setSelection && typeof inputValue.current === 'string') {\n input.setSelection(0, inputValue.current.length)\n }\n },\n }),\n })\n },\n [isInput, props.id]\n )\n\n const combinedRefs = composeRefs(ref, inputRef)\n\n useEffect(() => {\n if (!props.id) return\n return () => {\n unregisterFocusable(props.id!)\n }\n }, [props.id])\n\n const onChangeText = useEvent((value) => {\n inputValue.current = value\n props.onChangeText?.(value)\n })\n\n const finalProps = isInput\n ? {\n ...props,\n onChangeText,\n }\n : props\n\n return <Component ref={combinedRefs} {...finalProps} />\n }\n ) as any\n}\n"],
5
- "mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB,gBAAgB;AAC7C,SAAgB,cAAc;AAC9B,SAAS,YAAY,aAAa,iBAAiB;AAEnD,SAAS,mBAAmB,2BAA2B;AAEhD,SAAS,kBAAsC,WAAiB;AACrE,SAAO;AAAA,IACL,CACE,OAMA,QACG;AACH,YAAM,UAAU,mBAAmB,SAAS,KAAK,UAAU,aAAa;AACxE,YAAM,aAAa,OAAO,MAAM,SAAS,MAAM,gBAAgB,EAAE;AAEjE,YAAM,WAAW;AAAA,QACf,CAAC,UAAU;AACT,cAAI,CAAC,MAAM;AAAI;AACf,cAAI,CAAC;AAAO;AACZ,4BAAkB,MAAM,IAAI;AAAA,YAC1B,OAAO,MAAM;AAAA,YAEb,GAAI,WAAW;AAAA,cAEb,iBAAiB;AACf,sBAAM,MAAM;AACZ,oBAAI,MAAM,gBAAgB,OAAO,WAAW,YAAY,UAAU;AAChE,wBAAM,aAAa,GAAG,WAAW,QAAQ,MAAM;AAAA,gBACjD;AAAA,cACF;AAAA,YACF;AAAA,UACF,CAAC;AAAA,QACH;AAAA,QACA,CAAC,SAAS,MAAM,EAAE;AAAA,MACpB;AAEA,YAAM,eAAe,YAAY,KAAK,QAAQ;AAE9C,gBAAU,MAAM;AACd,YAAI,CAAC,MAAM;AAAI;AACf,eAAO,MAAM;AACX,8BAAoB,MAAM,EAAG;AAAA,QAC/B;AAAA,MACF,GAAG,CAAC,MAAM,EAAE,CAAC;AAEb,YAAM,eAAe,SAAS,CAAC,UAAU;AACvC,mBAAW,UAAU;AACrB,cAAM,eAAe,KAAK;AAAA,MAC5B,CAAC;AAED,YAAM,aAAa,UACf;AAAA,QACE,GAAG;AAAA,QACH;AAAA,MACF,IACA;AAEJ,aAAO,CAAC,UAAU,KAAK,kBAAkB,YAAY;AAAA,IACvD;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { TamaguiComponent, isTamaguiComponent, useEvent } from '@tamagui/core'\nimport React, { useRef } from 'react'\nimport { forwardRef, useCallback, useEffect } from 'react'\n\nimport { registerFocusable, unregisterFocusable } from './registerFocusable'\n\nexport function focusableInputHOC<A extends TamaguiComponent>(Component: A): A {\n const component = Component.extractable(\n forwardRef(\n (\n props: {\n id?: string\n onChangeText?: (val: string) => void\n value?: string\n defaultValue?: string\n },\n ref\n ) => {\n const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput\n const inputValue = useRef(props.value || props.defaultValue || '')\n\n const inputRef = useCallback(\n (input) => {\n if (!props.id) return\n if (!input) return\n registerFocusable(props.id, {\n focus: input.focus,\n\n ...(isInput && {\n // react-native doesn't support programmatic .select()\n focusAndSelect() {\n input.focus()\n if (input.setSelection && typeof inputValue.current === 'string') {\n input.setSelection(0, inputValue.current.length)\n }\n },\n }),\n })\n },\n [isInput, props.id]\n )\n\n const combinedRefs = composeRefs(ref, inputRef)\n\n useEffect(() => {\n if (!props.id) return\n return () => {\n unregisterFocusable(props.id!)\n }\n }, [props.id])\n\n const onChangeText = useEvent((value) => {\n inputValue.current = value\n props.onChangeText?.(value)\n })\n\n const finalProps = isInput\n ? {\n ...props,\n onChangeText,\n }\n : props\n\n // @ts-expect-error\n return <Component ref={combinedRefs} {...finalProps} />\n }\n )\n ) as any\n\n return component\n}\n"],
5
+ "mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAA2B,oBAAoB,gBAAgB;AAC/D,SAAgB,cAAc;AAC9B,SAAS,YAAY,aAAa,iBAAiB;AAEnD,SAAS,mBAAmB,2BAA2B;AAEhD,SAAS,kBAA8C,WAAiB;AAC7E,QAAM,YAAY,UAAU;AAAA,IAC1B;AAAA,MACE,CACE,OAMA,QACG;AACH,cAAM,UAAU,mBAAmB,SAAS,KAAK,UAAU,aAAa;AACxE,cAAM,aAAa,OAAO,MAAM,SAAS,MAAM,gBAAgB,EAAE;AAEjE,cAAM,WAAW;AAAA,UACf,CAAC,UAAU;AACT,gBAAI,CAAC,MAAM;AAAI;AACf,gBAAI,CAAC;AAAO;AACZ,8BAAkB,MAAM,IAAI;AAAA,cAC1B,OAAO,MAAM;AAAA,cAEb,GAAI,WAAW;AAAA,gBAEb,iBAAiB;AACf,wBAAM,MAAM;AACZ,sBAAI,MAAM,gBAAgB,OAAO,WAAW,YAAY,UAAU;AAChE,0BAAM,aAAa,GAAG,WAAW,QAAQ,MAAM;AAAA,kBACjD;AAAA,gBACF;AAAA,cACF;AAAA,YACF,CAAC;AAAA,UACH;AAAA,UACA,CAAC,SAAS,MAAM,EAAE;AAAA,QACpB;AAEA,cAAM,eAAe,YAAY,KAAK,QAAQ;AAE9C,kBAAU,MAAM;AACd,cAAI,CAAC,MAAM;AAAI;AACf,iBAAO,MAAM;AACX,gCAAoB,MAAM,EAAG;AAAA,UAC/B;AAAA,QACF,GAAG,CAAC,MAAM,EAAE,CAAC;AAEb,cAAM,eAAe,SAAS,CAAC,UAAU;AACvC,qBAAW,UAAU;AACrB,gBAAM,eAAe,KAAK;AAAA,QAC5B,CAAC;AAED,cAAM,aAAa,UACf;AAAA,UACE,GAAG;AAAA,UACH;AAAA,QACF,IACA;AAGJ,eAAO,CAAC,UAAU,KAAK,kBAAkB,YAAY;AAAA,MACvD;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/focusable",
3
- "version": "1.0.1-beta.206",
3
+ "version": "1.0.1-beta.208",
4
4
  "sideEffects": false,
5
5
  "source": "src/index.ts",
6
6
  "types": "./types/index.d.ts",
@@ -22,15 +22,15 @@
22
22
  "clean:build": "tamagui-build clean:build"
23
23
  },
24
24
  "dependencies": {
25
- "@tamagui/compose-refs": "^1.0.1-beta.206",
26
- "@tamagui/core": "^1.0.1-beta.206"
25
+ "@tamagui/compose-refs": "^1.0.1-beta.208",
26
+ "@tamagui/core": "^1.0.1-beta.208"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "react": "*",
30
30
  "react-dom": "*"
31
31
  },
32
32
  "devDependencies": {
33
- "@tamagui/build": "^1.0.1-beta.206",
33
+ "@tamagui/build": "^1.0.1-beta.208",
34
34
  "react": "*",
35
35
  "react-dom": "*"
36
36
  },
@@ -1,67 +1,72 @@
1
1
  import { composeRefs } from '@tamagui/compose-refs'
2
- import { isTamaguiComponent, useEvent } from '@tamagui/core'
2
+ import { TamaguiComponent, isTamaguiComponent, useEvent } from '@tamagui/core'
3
3
  import React, { useRef } from 'react'
4
4
  import { forwardRef, useCallback, useEffect } from 'react'
5
5
 
6
6
  import { registerFocusable, unregisterFocusable } from './registerFocusable'
7
7
 
8
- export function focusableInputHOC<A extends Function>(Component: A): A {
9
- return forwardRef(
10
- (
11
- props: {
12
- id?: string
13
- onChangeText?: (val: string) => void
14
- value?: string
15
- defaultValue?: string
16
- },
17
- ref
18
- ) => {
19
- const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput
20
- const inputValue = useRef(props.value || props.defaultValue || '')
21
-
22
- const inputRef = useCallback(
23
- (input) => {
24
- if (!props.id) return
25
- if (!input) return
26
- registerFocusable(props.id, {
27
- focus: input.focus,
28
-
29
- ...(isInput && {
30
- // react-native doesn't support programmatic .select()
31
- focusAndSelect() {
32
- input.focus()
33
- if (input.setSelection && typeof inputValue.current === 'string') {
34
- input.setSelection(0, inputValue.current.length)
35
- }
36
- },
37
- }),
38
- })
8
+ export function focusableInputHOC<A extends TamaguiComponent>(Component: A): A {
9
+ const component = Component.extractable(
10
+ forwardRef(
11
+ (
12
+ props: {
13
+ id?: string
14
+ onChangeText?: (val: string) => void
15
+ value?: string
16
+ defaultValue?: string
39
17
  },
40
- [isInput, props.id]
41
- )
18
+ ref
19
+ ) => {
20
+ const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput
21
+ const inputValue = useRef(props.value || props.defaultValue || '')
42
22
 
43
- const combinedRefs = composeRefs(ref, inputRef)
23
+ const inputRef = useCallback(
24
+ (input) => {
25
+ if (!props.id) return
26
+ if (!input) return
27
+ registerFocusable(props.id, {
28
+ focus: input.focus,
44
29
 
45
- useEffect(() => {
46
- if (!props.id) return
47
- return () => {
48
- unregisterFocusable(props.id!)
49
- }
50
- }, [props.id])
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
+ )
51
43
 
52
- const onChangeText = useEvent((value) => {
53
- inputValue.current = value
54
- props.onChangeText?.(value)
55
- })
44
+ const combinedRefs = composeRefs(ref, inputRef)
56
45
 
57
- const finalProps = isInput
58
- ? {
59
- ...props,
60
- onChangeText,
46
+ useEffect(() => {
47
+ if (!props.id) return
48
+ return () => {
49
+ unregisterFocusable(props.id!)
61
50
  }
62
- : props
51
+ }, [props.id])
63
52
 
64
- return <Component ref={combinedRefs} {...finalProps} />
65
- }
53
+ const onChangeText = useEvent((value) => {
54
+ inputValue.current = value
55
+ props.onChangeText?.(value)
56
+ })
57
+
58
+ const finalProps = isInput
59
+ ? {
60
+ ...props,
61
+ onChangeText,
62
+ }
63
+ : props
64
+
65
+ // @ts-expect-error
66
+ return <Component ref={combinedRefs} {...finalProps} />
67
+ }
68
+ )
66
69
  ) as any
70
+
71
+ return component
67
72
  }
@@ -1,2 +1,3 @@
1
- export declare function focusableInputHOC<A extends Function>(Component: A): A;
1
+ import { TamaguiComponent } from '@tamagui/core';
2
+ export declare function focusableInputHOC<A extends TamaguiComponent>(Component: A): A;
2
3
  //# sourceMappingURL=focusableInputHOC.d.ts.map