@tamagui/focusable 1.2.9 → 1.2.10
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/esm/focusable.mjs +1 -0
- package/dist/esm/focusable.mjs.map +7 -0
- package/dist/esm/focusableInputHOC.mjs +61 -0
- package/dist/esm/focusableInputHOC.mjs.map +7 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/index.mjs.map +7 -0
- package/dist/esm/registerFocusable.mjs +12 -0
- package/dist/esm/registerFocusable.mjs.map +7 -0
- package/dist/esm/registerFocusable.native.mjs +35 -0
- package/dist/esm/registerFocusable.native.mjs.map +7 -0
- package/dist/jsx/focusable.mjs +1 -0
- package/dist/jsx/focusable.mjs.map +7 -0
- package/dist/jsx/focusableInputHOC.mjs +57 -0
- package/dist/jsx/focusableInputHOC.mjs.map +7 -0
- package/dist/jsx/index.mjs +4 -0
- package/dist/jsx/index.mjs.map +7 -0
- package/dist/jsx/registerFocusable.mjs +12 -0
- package/dist/jsx/registerFocusable.mjs.map +7 -0
- package/dist/jsx/registerFocusable.native.mjs +35 -0
- package/dist/jsx/registerFocusable.native.mjs.map +7 -0
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=focusable.mjs.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { composeRefs } from "@tamagui/compose-refs";
|
|
3
|
+
import { isTamaguiComponent, useEvent } from "@tamagui/core";
|
|
4
|
+
import { forwardRef, useCallback, useEffect, useRef } from "react";
|
|
5
|
+
import { registerFocusable } from "./registerFocusable";
|
|
6
|
+
function focusableInputHOC(Component) {
|
|
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 unregisterFocusable = useRef();
|
|
13
|
+
const inputRef = useCallback(
|
|
14
|
+
(input) => {
|
|
15
|
+
var _a;
|
|
16
|
+
if (!props.id)
|
|
17
|
+
return;
|
|
18
|
+
if (!input)
|
|
19
|
+
return;
|
|
20
|
+
(_a = unregisterFocusable.current) == null ? void 0 : _a.call(unregisterFocusable);
|
|
21
|
+
unregisterFocusable.current = registerFocusable(props.id, {
|
|
22
|
+
focus: input.focus,
|
|
23
|
+
...isInput && {
|
|
24
|
+
// react-native doesn't support programmatic .select()
|
|
25
|
+
focusAndSelect() {
|
|
26
|
+
input.focus();
|
|
27
|
+
if (input.setSelection && typeof inputValue.current === "string") {
|
|
28
|
+
input.setSelection(0, inputValue.current.length);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
[isInput, props.id]
|
|
35
|
+
);
|
|
36
|
+
const combinedRefs = composeRefs(ref, inputRef);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
return () => {
|
|
39
|
+
var _a;
|
|
40
|
+
(_a = unregisterFocusable.current) == null ? void 0 : _a.call(unregisterFocusable);
|
|
41
|
+
};
|
|
42
|
+
}, []);
|
|
43
|
+
const onChangeText = useEvent((value) => {
|
|
44
|
+
var _a;
|
|
45
|
+
inputValue.current = value;
|
|
46
|
+
(_a = props.onChangeText) == null ? void 0 : _a.call(props, value);
|
|
47
|
+
});
|
|
48
|
+
const finalProps = isInput ? {
|
|
49
|
+
...props,
|
|
50
|
+
onChangeText
|
|
51
|
+
} : props;
|
|
52
|
+
return /* @__PURE__ */ jsx(Component, { ref: combinedRefs, ...finalProps });
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
);
|
|
56
|
+
return component;
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
focusableInputHOC
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=focusableInputHOC.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/focusableInputHOC.tsx"],
|
|
4
|
+
"sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { TamaguiComponent, isTamaguiComponent, useEvent } from '@tamagui/core'\nimport { forwardRef, useCallback, useEffect, useRef } from 'react'\n\nimport { registerFocusable } 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 const unregisterFocusable = useRef<() => void | undefined>()\n\n const inputRef = useCallback(\n (input) => {\n if (!props.id) return\n if (!input) return\n unregisterFocusable.current?.()\n unregisterFocusable.current = 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 return () => {\n unregisterFocusable.current?.()\n }\n }, [])\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,SAAS,YAAY,aAAa,WAAW,cAAc;AAE3D,SAAS,yBAAyB;AAE3B,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;AACjE,cAAM,sBAAsB,OAA+B;AAE3D,cAAM,WAAW;AAAA,UACf,CAAC,UAAU;AAvBrB;AAwBY,gBAAI,CAAC,MAAM;AAAI;AACf,gBAAI,CAAC;AAAO;AACZ,sCAAoB,YAApB;AACA,gCAAoB,UAAU,kBAAkB,MAAM,IAAI;AAAA,cACxD,OAAO,MAAM;AAAA,cAEb,GAAI,WAAW;AAAA;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,iBAAO,MAAM;AA/CvB;AAgDY,sCAAoB,YAApB;AAAA,UACF;AAAA,QACF,GAAG,CAAC,CAAC;AAEL,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,aAAU,KAAK,cAAe,GAAG,YAAY;AAAA,MACvD;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const registerFocusable = (id, input) => () => {
|
|
2
|
+
};
|
|
3
|
+
const unregisterFocusable = (id) => {
|
|
4
|
+
};
|
|
5
|
+
const focusFocusable = (id) => {
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
focusFocusable,
|
|
9
|
+
registerFocusable,
|
|
10
|
+
unregisterFocusable
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=registerFocusable.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/registerFocusable.ts"],
|
|
4
|
+
"sourcesContent": ["import { Focusable } from './focusable'\n\nexport const registerFocusable = (id: string, input: Focusable) => () => {\n // noop focus is handed natively\n}\n\nexport const unregisterFocusable = (id: string) => {\n // noop focus is handed natively\n}\n\nexport const focusFocusable = (id: string) => {\n // noop focus is handed natively\n}\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,oBAAoB,CAAC,IAAY,UAAqB,MAAM;AAEzE;AAEO,MAAM,sBAAsB,CAAC,OAAe;AAEnD;AAEO,MAAM,iBAAiB,CAAC,OAAe;AAE9C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const InputsMap = /* @__PURE__ */ new Map();
|
|
2
|
+
const registerFocusable = (id, input) => {
|
|
3
|
+
if (process.env.NODE_ENV === "development") {
|
|
4
|
+
if (InputsMap.has(id)) {
|
|
5
|
+
console.warn(`Warning, duplicate ID for input: ${id}`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
InputsMap.set(id, input);
|
|
9
|
+
return () => {
|
|
10
|
+
InputsMap.delete(id);
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
const unregisterFocusable = (id) => {
|
|
14
|
+
InputsMap.delete(id);
|
|
15
|
+
};
|
|
16
|
+
const focusFocusable = (id, select = false) => {
|
|
17
|
+
const input = InputsMap.get(id);
|
|
18
|
+
if (!input) {
|
|
19
|
+
if (process.env.NODE_ENV === "development") {
|
|
20
|
+
console.warn("No input found for id", id);
|
|
21
|
+
}
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (select || !input.focusAndSelect) {
|
|
25
|
+
input.focus();
|
|
26
|
+
} else {
|
|
27
|
+
input.focusAndSelect();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
focusFocusable,
|
|
32
|
+
registerFocusable,
|
|
33
|
+
unregisterFocusable
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=registerFocusable.native.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/registerFocusable.native.ts"],
|
|
4
|
+
"sourcesContent": ["// used for focusing on native\n\nimport { Focusable } from './focusable'\n\nconst InputsMap = new Map<string, Focusable>()\n\nexport const registerFocusable = (id: string, input: Focusable) => {\n if (process.env.NODE_ENV === 'development') {\n if (InputsMap.has(id)) {\n // eslint-disable-next-line no-console\n console.warn(`Warning, duplicate ID for input: ${id}`)\n }\n }\n InputsMap.set(id, input)\n return () => {\n InputsMap.delete(id)\n }\n}\n\nexport const unregisterFocusable = (id: string) => {\n InputsMap.delete(id)\n}\n\nexport const focusFocusable = (id: string, select = false) => {\n const input = InputsMap.get(id)\n if (!input) {\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn('No input found for id', id)\n }\n return\n }\n if (select || !input.focusAndSelect) {\n input.focus()\n } else {\n input.focusAndSelect()\n }\n}\n"],
|
|
5
|
+
"mappings": "AAIA,MAAM,YAAY,oBAAI,IAAuB;AAEtC,MAAM,oBAAoB,CAAC,IAAY,UAAqB;AACjE,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,UAAU,IAAI,EAAE,GAAG;AAErB,cAAQ,KAAK,oCAAoC,IAAI;AAAA,IACvD;AAAA,EACF;AACA,YAAU,IAAI,IAAI,KAAK;AACvB,SAAO,MAAM;AACX,cAAU,OAAO,EAAE;AAAA,EACrB;AACF;AAEO,MAAM,sBAAsB,CAAC,OAAe;AACjD,YAAU,OAAO,EAAE;AACrB;AAEO,MAAM,iBAAiB,CAAC,IAAY,SAAS,UAAU;AAC5D,QAAM,QAAQ,UAAU,IAAI,EAAE;AAC9B,MAAI,CAAC,OAAO;AACV,QAAI,QAAQ,IAAI,aAAa,eAAe;AAE1C,cAAQ,KAAK,yBAAyB,EAAE;AAAA,IAC1C;AACA;AAAA,EACF;AACA,MAAI,UAAU,CAAC,MAAM,gBAAgB;AACnC,UAAM,MAAM;AAAA,EACd,OAAO;AACL,UAAM,eAAe;AAAA,EACvB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=focusable.mjs.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { composeRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { isTamaguiComponent, useEvent } from "@tamagui/core";
|
|
3
|
+
import { forwardRef, useCallback, useEffect, useRef } from "react";
|
|
4
|
+
import { registerFocusable } from "./registerFocusable";
|
|
5
|
+
function focusableInputHOC(Component) {
|
|
6
|
+
const component = Component.extractable(
|
|
7
|
+
forwardRef(
|
|
8
|
+
(props, ref) => {
|
|
9
|
+
const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput;
|
|
10
|
+
const inputValue = useRef(props.value || props.defaultValue || "");
|
|
11
|
+
const unregisterFocusable = useRef();
|
|
12
|
+
const inputRef = useCallback(
|
|
13
|
+
(input) => {
|
|
14
|
+
if (!props.id)
|
|
15
|
+
return;
|
|
16
|
+
if (!input)
|
|
17
|
+
return;
|
|
18
|
+
unregisterFocusable.current?.();
|
|
19
|
+
unregisterFocusable.current = registerFocusable(props.id, {
|
|
20
|
+
focus: input.focus,
|
|
21
|
+
...isInput && {
|
|
22
|
+
// react-native doesn't support programmatic .select()
|
|
23
|
+
focusAndSelect() {
|
|
24
|
+
input.focus();
|
|
25
|
+
if (input.setSelection && typeof inputValue.current === "string") {
|
|
26
|
+
input.setSelection(0, inputValue.current.length);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
[isInput, props.id]
|
|
33
|
+
);
|
|
34
|
+
const combinedRefs = composeRefs(ref, inputRef);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
return () => {
|
|
37
|
+
unregisterFocusable.current?.();
|
|
38
|
+
};
|
|
39
|
+
}, []);
|
|
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
|
+
)
|
|
51
|
+
);
|
|
52
|
+
return component;
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
focusableInputHOC
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=focusableInputHOC.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/focusableInputHOC.tsx"],
|
|
4
|
+
"sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { TamaguiComponent, isTamaguiComponent, useEvent } from '@tamagui/core'\nimport { forwardRef, useCallback, useEffect, useRef } from 'react'\n\nimport { registerFocusable } 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 const unregisterFocusable = useRef<() => void | undefined>()\n\n const inputRef = useCallback(\n (input) => {\n if (!props.id) return\n if (!input) return\n unregisterFocusable.current?.()\n unregisterFocusable.current = 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 return () => {\n unregisterFocusable.current?.()\n }\n }, [])\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,SAAS,YAAY,aAAa,WAAW,cAAc;AAE3D,SAAS,yBAAyB;AAE3B,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;AACjE,cAAM,sBAAsB,OAA+B;AAE3D,cAAM,WAAW;AAAA,UACf,CAAC,UAAU;AACT,gBAAI,CAAC,MAAM;AAAI;AACf,gBAAI,CAAC;AAAO;AACZ,gCAAoB,UAAU;AAC9B,gCAAoB,UAAU,kBAAkB,MAAM,IAAI;AAAA,cACxD,OAAO,MAAM;AAAA,cAEb,GAAI,WAAW;AAAA;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,iBAAO,MAAM;AACX,gCAAoB,UAAU;AAAA,UAChC;AAAA,QACF,GAAG,CAAC,CAAC;AAEL,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
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const registerFocusable = (id, input) => () => {
|
|
2
|
+
};
|
|
3
|
+
const unregisterFocusable = (id) => {
|
|
4
|
+
};
|
|
5
|
+
const focusFocusable = (id) => {
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
focusFocusable,
|
|
9
|
+
registerFocusable,
|
|
10
|
+
unregisterFocusable
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=registerFocusable.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/registerFocusable.ts"],
|
|
4
|
+
"sourcesContent": ["import { Focusable } from './focusable'\n\nexport const registerFocusable = (id: string, input: Focusable) => () => {\n // noop focus is handed natively\n}\n\nexport const unregisterFocusable = (id: string) => {\n // noop focus is handed natively\n}\n\nexport const focusFocusable = (id: string) => {\n // noop focus is handed natively\n}\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,oBAAoB,CAAC,IAAY,UAAqB,MAAM;AAEzE;AAEO,MAAM,sBAAsB,CAAC,OAAe;AAEnD;AAEO,MAAM,iBAAiB,CAAC,OAAe;AAE9C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const InputsMap = /* @__PURE__ */ new Map();
|
|
2
|
+
const registerFocusable = (id, input) => {
|
|
3
|
+
if (process.env.NODE_ENV === "development") {
|
|
4
|
+
if (InputsMap.has(id)) {
|
|
5
|
+
console.warn(`Warning, duplicate ID for input: ${id}`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
InputsMap.set(id, input);
|
|
9
|
+
return () => {
|
|
10
|
+
InputsMap.delete(id);
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
const unregisterFocusable = (id) => {
|
|
14
|
+
InputsMap.delete(id);
|
|
15
|
+
};
|
|
16
|
+
const focusFocusable = (id, select = false) => {
|
|
17
|
+
const input = InputsMap.get(id);
|
|
18
|
+
if (!input) {
|
|
19
|
+
if (process.env.NODE_ENV === "development") {
|
|
20
|
+
console.warn("No input found for id", id);
|
|
21
|
+
}
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (select || !input.focusAndSelect) {
|
|
25
|
+
input.focus();
|
|
26
|
+
} else {
|
|
27
|
+
input.focusAndSelect();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
focusFocusable,
|
|
32
|
+
registerFocusable,
|
|
33
|
+
unregisterFocusable
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=registerFocusable.native.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/registerFocusable.native.ts"],
|
|
4
|
+
"sourcesContent": ["// used for focusing on native\n\nimport { Focusable } from './focusable'\n\nconst InputsMap = new Map<string, Focusable>()\n\nexport const registerFocusable = (id: string, input: Focusable) => {\n if (process.env.NODE_ENV === 'development') {\n if (InputsMap.has(id)) {\n // eslint-disable-next-line no-console\n console.warn(`Warning, duplicate ID for input: ${id}`)\n }\n }\n InputsMap.set(id, input)\n return () => {\n InputsMap.delete(id)\n }\n}\n\nexport const unregisterFocusable = (id: string) => {\n InputsMap.delete(id)\n}\n\nexport const focusFocusable = (id: string, select = false) => {\n const input = InputsMap.get(id)\n if (!input) {\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn('No input found for id', id)\n }\n return\n }\n if (select || !input.focusAndSelect) {\n input.focus()\n } else {\n input.focusAndSelect()\n }\n}\n"],
|
|
5
|
+
"mappings": "AAIA,MAAM,YAAY,oBAAI,IAAuB;AAEtC,MAAM,oBAAoB,CAAC,IAAY,UAAqB;AACjE,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,UAAU,IAAI,EAAE,GAAG;AAErB,cAAQ,KAAK,oCAAoC,IAAI;AAAA,IACvD;AAAA,EACF;AACA,YAAU,IAAI,IAAI,KAAK;AACvB,SAAO,MAAM;AACX,cAAU,OAAO,EAAE;AAAA,EACrB;AACF;AAEO,MAAM,sBAAsB,CAAC,OAAe;AACjD,YAAU,OAAO,EAAE;AACrB;AAEO,MAAM,iBAAiB,CAAC,IAAY,SAAS,UAAU;AAC5D,QAAM,QAAQ,UAAU,IAAI,EAAE;AAC9B,MAAI,CAAC,OAAO;AACV,QAAI,QAAQ,IAAI,aAAa,eAAe;AAE1C,cAAQ,KAAK,yBAAyB,EAAE;AAAA,IAC1C;AACA;AAAA,EACF;AACA,MAAI,UAAU,CAAC,MAAM,gBAAgB;AACnC,UAAM,MAAM;AAAA,EACd,OAAO;AACL,UAAM,eAAe;AAAA,EACvB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/focusable",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.10",
|
|
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.2.
|
|
26
|
-
"@tamagui/core": "^1.2.
|
|
25
|
+
"@tamagui/compose-refs": "^1.2.10",
|
|
26
|
+
"@tamagui/core": "^1.2.10"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "*",
|
|
30
30
|
"react-dom": "*"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@tamagui/build": "^1.2.
|
|
33
|
+
"@tamagui/build": "^1.2.10",
|
|
34
34
|
"react": "^18.2.0",
|
|
35
35
|
"react-dom": "^18.2.0"
|
|
36
36
|
},
|