@tamagui/focusable 1.0.1-beta.106 → 1.0.1-beta.109

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.
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/focusable.ts"],
4
4
  "sourcesContent": ["export type Focusable = { focus: Function; focusAndSelect?: Function }\n"],
5
- "mappings": ";;;;;;;;;;;;;AAAA;AAAA;",
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -1,26 +1,10 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
6
  var __getProtoOf = Object.getPrototypeOf;
9
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
8
  var __export = (target, all) => {
25
9
  for (var name in all)
26
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -54,16 +38,17 @@ function focusableInputHOC(Component) {
54
38
  return;
55
39
  if (!input)
56
40
  return;
57
- (0, import_registerFocusable.registerFocusable)(props.id, __spreadValues({
58
- focus: input.focus
59
- }, isInput && {
60
- focusAndSelect() {
61
- input.focus();
62
- if (input.setSelection && typeof inputValue.current === "string") {
63
- input.setSelection(0, inputValue.current.length);
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);
48
+ }
64
49
  }
65
50
  }
66
- }));
51
+ });
67
52
  }, [props.id]);
68
53
  const combinedRefs = (0, import_compose_refs.composeRefs)(ref, inputRef);
69
54
  (0, import_react2.useEffect)(() => {
@@ -73,16 +58,18 @@ function focusableInputHOC(Component) {
73
58
  (0, import_registerFocusable.unregisterFocusable)(props.id);
74
59
  };
75
60
  }, [props.id]);
76
- const finalProps = isInput ? __spreadProps(__spreadValues({}, props), {
61
+ const finalProps = isInput ? {
62
+ ...props,
77
63
  onChangeText(value) {
78
64
  var _a;
79
65
  inputValue.current = value;
80
66
  (_a = props.onChangeText) == null ? void 0 : _a.call(props, value);
81
67
  }
82
- }) : props;
83
- return /* @__PURE__ */ import_react.default.createElement(Component, __spreadValues({
84
- ref: combinedRefs
85
- }, finalProps));
68
+ } : props;
69
+ return /* @__PURE__ */ import_react.default.createElement(Component, {
70
+ ref: combinedRefs,
71
+ ...finalProps
72
+ });
86
73
  });
87
74
  }
88
75
  // Annotate the CommonJS export names for ESM import in node:
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/focusableInputHOC.tsx"],
4
4
  "sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { isTamaguiComponent } 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 [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 finalProps = isInput\n ? {\n ...props,\n onChangeText(value) {\n inputValue.current = value\n props.onChangeText?.(value)\n },\n }\n : props\n\n return <Component ref={combinedRefs} {...finalProps} />\n }\n ) as any\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA4B;AAC5B,kBAAmC;AACnC,mBAA8B;AAC9B,oBAAmD;AAEnD,+BAAuD;AAEhD,2BAA+C,WAAiB;AACrE,SAAO,8BACL,CACE,OAMA,QACG;AACH,UAAM,UAAU,oCAAmB,SAAS,KAAK,UAAU,aAAa;AACxE,UAAM,aAAa,yBAAO,MAAM,SAAS,MAAM,gBAAgB,EAAE;AAEjE,UAAM,WAAW,+BACf,CAAC,UAAU;AACT,UAAI,CAAC,MAAM;AAAI;AACf,UAAI,CAAC;AAAO;AACZ,sDAAkB,MAAM,IAAI;AAAA,QAC1B,OAAO,MAAM;AAAA,SAET,WAAW;AAAA,QAEb,iBAAiB;AACf,gBAAM,MAAM;AACZ,cAAI,MAAM,gBAAg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AC,MAAM,EAAE,CACX;AAEA,UAAM,eAAe,qCAAY,KAAK,QAAQ;AAE9C,iCAAU,MAAM;AACd,UAAI,CAAC,MAAM;AAAI;AACf,aAAO,MAAM;AACX,0DAAoB,MAAM,EAAG;AAAA,MAC/B;AAAA,IACF,GAAG,CAAC,MAAM,EAAE,CAAC;AAEb,UAAM,aAAa,UACf;AAAA,MACE,GAAG;AAAA,MACH,aAAa,OAAO;AAtDhC;AAuDc,mBAAW,UAAU;AACrB,oBAAM,iBAAN,+BAAqB;AAAA,MACvB;AAAA,IACF,IACA;AAEJ,WAAO,mDAAC;AAAA,MAAU,KAAK;AAAA,MAAe,GAAG;AAAA,KAAY;AAAA,EACvD,CACF;AACF;",
6
6
  "names": []
7
7
  }
package/dist/cjs/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
4
  "sourcesContent": ["export * from './registerFocusable'\nexport * from './focusableInputHOC'\nexport * from './focusable'\n"],
5
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,gCAAd;AACA,wBAAc,gCADd;AAEA,wBAAc,wBAFd;",
5
+ "mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,gCAAd;AACA,wBAAc,gCADd;AAEA,wBAAc,wBAFd;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/registerFocusable.ts"],
4
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": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,oBAAoB,CAAC,IAAY,UAAqB;AAEnE;AAEO,MAAM,sBAAsB,CAAC,OAAe;AAEnD;AAEO,MAAM,iBAAiB,CAAC,OAAe;AAE9C;",
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,oBAAoB,CAAC,IAAY,UAAqB;AAEnE;AAEO,MAAM,sBAAsB,CAAC,OAAe;AAEnD;AAEO,MAAM,iBAAiB,CAAC,OAAe;AAE9C;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/registerFocusable.native.ts"],
4
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 !== 'production') {\n if (InputsMap.has(id)) {\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 !== 'production') {\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
-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AAU,IAAI,EAAE;AAC9B,MAAI,CAAC,OAAO;AACV,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,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
6
  "names": []
7
7
  }
@@ -1,22 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
1
  import { composeRefs } from "@tamagui/compose-refs";
21
2
  import { isTamaguiComponent } from "@tamagui/core";
22
3
  import React, { useRef } from "react";
@@ -31,16 +12,17 @@ function focusableInputHOC(Component) {
31
12
  return;
32
13
  if (!input)
33
14
  return;
34
- registerFocusable(props.id, __spreadValues({
35
- focus: input.focus
36
- }, isInput && {
37
- focusAndSelect() {
38
- input.focus();
39
- if (input.setSelection && typeof inputValue.current === "string") {
40
- input.setSelection(0, inputValue.current.length);
15
+ registerFocusable(props.id, {
16
+ focus: input.focus,
17
+ ...isInput && {
18
+ focusAndSelect() {
19
+ input.focus();
20
+ if (input.setSelection && typeof inputValue.current === "string") {
21
+ input.setSelection(0, inputValue.current.length);
22
+ }
41
23
  }
42
24
  }
43
- }));
25
+ });
44
26
  }, [props.id]);
45
27
  const combinedRefs = composeRefs(ref, inputRef);
46
28
  useEffect(() => {
@@ -50,16 +32,18 @@ function focusableInputHOC(Component) {
50
32
  unregisterFocusable(props.id);
51
33
  };
52
34
  }, [props.id]);
53
- const finalProps = isInput ? __spreadProps(__spreadValues({}, props), {
35
+ const finalProps = isInput ? {
36
+ ...props,
54
37
  onChangeText(value) {
55
38
  var _a;
56
39
  inputValue.current = value;
57
40
  (_a = props.onChangeText) == null ? void 0 : _a.call(props, value);
58
41
  }
59
- }) : props;
60
- return /* @__PURE__ */ React.createElement(Component, __spreadValues({
61
- ref: combinedRefs
62
- }, finalProps));
42
+ } : props;
43
+ return /* @__PURE__ */ React.createElement(Component, {
44
+ ref: combinedRefs,
45
+ ...finalProps
46
+ });
63
47
  });
64
48
  }
65
49
  export {
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/focusableInputHOC.tsx"],
4
4
  "sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { isTamaguiComponent } 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 [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 finalProps = isInput\n ? {\n ...props,\n onChangeText(value) {\n inputValue.current = value\n props.onChangeText?.(value)\n },\n }\n : props\n\n return <Component ref={combinedRefs} {...finalProps} />\n }\n ) as any\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AAEA;AAEO,2BAA+C,WAAiB;AACrE,SAAO,WACL,CACE,OAMA,QACG;AACH,UAAM,UAAU,mBAAmB,SAAS,KAAK,UAAU,aAAa;AACxE,UAAM,aAAa,OAAO,MAAM,SAAS,MAAM,gBAAgB,EAAE;AAEjE,UAAM,WAAW,YACf,CAAC,UAAU;AACT,UAAI,CAAC,MAAM;AAAI;AACf,UAAI,CAAC;AAAO;AACZ,wBAAkB,MAAM,IAAI;AAAA,QAC1B,OAAO,MAAM;AAAA,SAET,WAAW;AAAA,QAEb,iBAAiB;AACf,gBAAM,MAAM;AACZ,cAAI,MAAM,gBAAgB,OAAO,WAAW,YAAY,UAAU;AAChE,kBAAM,aAAa,GAAG,WAAW,QAAQ,MAAM;AAAA,UACjD;AAAA,QACF;AAAA,MACF,EACD;AAAA,IACH,GACA,CAAC,MAAM,EAAE,CACX;AAEA,UAAM,eAAe,YAAY,KAAK,QAAQ;AAE9C,cAAU,MAAM;AACd,UAAI,CAAC,MAAM;AAAI;AACf,aAAO,MAAM;AACX,4BAAoB,MAAM,EAAG;AAAA,MAC/B;AAAA,IACF,GAAG,CAAC,MAAM,EAAE,CAAC;AAEb,UAAM,aAAa,UACf,iCACK,QADL;AAAA,MAEE,aAAa,OAAO;AAtDhC;AAuDc,mBAAW,UAAU;AACrB,oBAAM,iBAAN,+BAAqB;AAAA,MACvB;AAAA,IACF,KACA;AAEJ,WAAO,oCAAC;AAAA,MAAU,KAAK;AAAA,OAAkB,WAAY;AAAA,EACvD,CACF;AACF;",
5
+ "mappings": "AAAA;AACA;AACA;AACA;AAEA;AAEO,2BAA+C,WAAiB;AACrE,SAAO,WACL,CACE,OAMA,QACG;AACH,UAAM,UAAU,mBAAmB,SAAS,KAAK,UAAU,aAAa;AACxE,UAAM,aAAa,OAAO,MAAM,SAAS,MAAM,gBAAgB,EAAE;AAEjE,UAAM,WAAW,YACf,CAAC,UAAU;AACT,UAAI,CAAC,MAAM;AAAI;AACf,UAAI,CAAC;AAAO;AACZ,wBAAkB,MAAM,IAAI;AAAA,QAC1B,OAAO,MAAM;AAAA,QAEb,GAAI,WAAW;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,GACA,CAAC,MAAM,EAAE,CACX;AAEA,UAAM,eAAe,YAAY,KAAK,QAAQ;AAE9C,cAAU,MAAM;AACd,UAAI,CAAC,MAAM;AAAI;AACf,aAAO,MAAM;AACX,4BAAoB,MAAM,EAAG;AAAA,MAC/B;AAAA,IACF,GAAG,CAAC,MAAM,EAAE,CAAC;AAEb,UAAM,aAAa,UACf;AAAA,MACE,GAAG;AAAA,MACH,aAAa,OAAO;AAtDhC;AAuDc,mBAAW,UAAU;AACrB,oBAAM,iBAAN,+BAAqB;AAAA,MACvB;AAAA,IACF,IACA;AAEJ,WAAO,oCAAC;AAAA,MAAU,KAAK;AAAA,MAAe,GAAG;AAAA,KAAY;AAAA,EACvD,CACF;AACF;",
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.106",
3
+ "version": "1.0.1-beta.109",
4
4
  "sideEffects": false,
5
5
  "source": "src/index.ts",
6
6
  "types": "./types/index.d.ts",
@@ -20,15 +20,15 @@
20
20
  "clean:build": "tamagui-build clean:build"
21
21
  },
22
22
  "dependencies": {
23
- "@tamagui/compose-refs": "^1.0.1-beta.106",
24
- "@tamagui/core": "^1.0.1-beta.106"
23
+ "@tamagui/compose-refs": "^1.0.1-beta.109",
24
+ "@tamagui/core": "^1.0.1-beta.109"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "react": "*",
28
28
  "react-dom": "*"
29
29
  },
30
30
  "devDependencies": {
31
- "@tamagui/build": "^1.0.1-beta.106",
31
+ "@tamagui/build": "^1.0.1-beta.109",
32
32
  "react": "*",
33
33
  "react-dom": "*"
34
34
  },
@@ -1,67 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var useControllableState_exports = {};
19
- __export(useControllableState_exports, {
20
- useControllableState: () => useControllableState
21
- });
22
- module.exports = __toCommonJS(useControllableState_exports);
23
- var import_use_event = require("@tamagui/use-event");
24
- var import_react = require("react");
25
- function useControllableState({
26
- prop,
27
- defaultProp,
28
- onChange,
29
- strategy = "prop-wins",
30
- preventUpdate
31
- }) {
32
- const currentProp = (0, import_react.useRef)(prop);
33
- const [val, setVal] = (0, import_react.useState)(prop ?? defaultProp);
34
- const propWins = strategy === "prop-wins";
35
- if (currentProp.current !== prop && !preventUpdate) {
36
- currentProp.current = prop;
37
- setVal((prev) => {
38
- return getNextStateWithCallback(prev, prop, onChange);
39
- });
40
- }
41
- return [
42
- val,
43
- (0, import_use_event.useEvent)((next) => {
44
- if (preventUpdate)
45
- return;
46
- if (propWins && currentProp.current !== void 0) {
47
- onChange == null ? void 0 : onChange(next);
48
- return;
49
- }
50
- setVal((prev) => {
51
- return getNextStateWithCallback(prev, typeof next === "function" ? next(prev) : next, onChange);
52
- });
53
- })
54
- ];
55
- }
56
- const getNextStateWithCallback = (prev, next, handleChange) => {
57
- if (prev === next || next === void 0) {
58
- return prev;
59
- }
60
- handleChange == null ? void 0 : handleChange(next);
61
- return next;
62
- };
63
- // Annotate the CommonJS export names for ESM import in node:
64
- 0 && (module.exports = {
65
- useControllableState
66
- });
67
- //# sourceMappingURL=useControllableState.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/useControllableState.ts"],
4
- "sourcesContent": ["import { useEvent } from '@tamagui/use-event'\nimport React, { useEffect, useRef, useState } from 'react'\n\n// can configure to allow most-recent-wins or prop-wins\n// defaults to prop-wins\n\ntype ChangeCb<T> = ((next: T) => void) | React.Dispatch<React.SetStateAction<T>>\n\nexport function useControllableState<T>({\n prop,\n defaultProp,\n onChange,\n strategy = 'prop-wins',\n preventUpdate,\n}: {\n prop?: T | undefined\n defaultProp: T\n onChange?: ChangeCb<T>\n strategy?: 'prop-wins' | 'most-recent-wins'\n preventUpdate?: boolean\n}): [T, React.Dispatch<React.SetStateAction<T>>] {\n const currentProp = useRef(prop)\n const [val, setVal] = useState(prop ?? defaultProp)\n const propWins = strategy === 'prop-wins'\n\n // TODO can try no useEffect here right? just if()\n if (currentProp.current !== prop && !preventUpdate) {\n currentProp.current = prop\n setVal((prev) => {\n return getNextStateWithCallback(prev, prop, onChange)\n })\n }\n\n return [\n val,\n useEvent((next: unknown) => {\n if (preventUpdate) return\n if (propWins && currentProp.current !== undefined) {\n onChange?.(next as T)\n return\n }\n setVal((prev) => {\n return getNextStateWithCallback(\n prev,\n typeof next === 'function' ? next(prev) : next,\n onChange\n )\n })\n }),\n ]\n}\n\nconst getNextStateWithCallback = (prev: any, next: any, handleChange?: ChangeCb<any>) => {\n if (prev === next || next === undefined) {\n return prev\n }\n handleChange?.(next)\n return next\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAyB;AACzB,mBAAmD;AAO5C,8BAAiC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,GAO+C;AAC/C,QAAM,cAAc,yBAAO,IAAI;AAC/B,QAAM,CAAC,KAAK,UAAU,2BAAS,QAAQ,WAAW;AAClD,QAAM,WAAW,aAAa;AAG9B,MAAI,YAAY,YAAY,QAAQ,CAAC,eAAe;AAClD,gBAAY,UAAU;AACtB,WAAO,CAAC,SAAS;AACf,aAAO,yBAAyB,MAAM,MAAM,QAAQ;AAAA,IACtD,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL;AAAA,IACA,+BAAS,CAAC,SAAkB;AAC1B,UAAI;AAAe;AACnB,UAAI,YAAY,YAAY,YAAY,QAAW;AACjD,6CAAW;AACX;AAAA,MACF;AACA,aAAO,CAAC,SAAS;AACf,eAAO,yBACL,MACA,OAAO,SAAS,aAAa,KAAK,IAAI,IAAI,MAC1C,QACF;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;AAEA,MAAM,2BAA2B,CAAC,MAAW,MAAW,iBAAiC;AACvF,MAAI,SAAS,QAAQ,SAAS,QAAW;AACvC,WAAO;AAAA,EACT;AACA,+CAAe;AACf,SAAO;AACT;",
6
- "names": []
7
- }
@@ -1,44 +0,0 @@
1
- import { useEvent } from "@tamagui/use-event";
2
- import { useRef, useState } from "react";
3
- function useControllableState({
4
- prop,
5
- defaultProp,
6
- onChange,
7
- strategy = "prop-wins",
8
- preventUpdate
9
- }) {
10
- const currentProp = useRef(prop);
11
- const [val, setVal] = useState(prop ?? defaultProp);
12
- const propWins = strategy === "prop-wins";
13
- if (currentProp.current !== prop && !preventUpdate) {
14
- currentProp.current = prop;
15
- setVal((prev) => {
16
- return getNextStateWithCallback(prev, prop, onChange);
17
- });
18
- }
19
- return [
20
- val,
21
- useEvent((next) => {
22
- if (preventUpdate)
23
- return;
24
- if (propWins && currentProp.current !== void 0) {
25
- onChange == null ? void 0 : onChange(next);
26
- return;
27
- }
28
- setVal((prev) => {
29
- return getNextStateWithCallback(prev, typeof next === "function" ? next(prev) : next, onChange);
30
- });
31
- })
32
- ];
33
- }
34
- const getNextStateWithCallback = (prev, next, handleChange) => {
35
- if (prev === next || next === void 0) {
36
- return prev;
37
- }
38
- handleChange == null ? void 0 : handleChange(next);
39
- return next;
40
- };
41
- export {
42
- useControllableState
43
- };
44
- //# sourceMappingURL=useControllableState.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/useControllableState.ts"],
4
- "sourcesContent": ["import { useEvent } from '@tamagui/use-event'\nimport React, { useEffect, useRef, useState } from 'react'\n\n// can configure to allow most-recent-wins or prop-wins\n// defaults to prop-wins\n\ntype ChangeCb<T> = ((next: T) => void) | React.Dispatch<React.SetStateAction<T>>\n\nexport function useControllableState<T>({\n prop,\n defaultProp,\n onChange,\n strategy = 'prop-wins',\n preventUpdate,\n}: {\n prop?: T | undefined\n defaultProp: T\n onChange?: ChangeCb<T>\n strategy?: 'prop-wins' | 'most-recent-wins'\n preventUpdate?: boolean\n}): [T, React.Dispatch<React.SetStateAction<T>>] {\n const currentProp = useRef(prop)\n const [val, setVal] = useState(prop ?? defaultProp)\n const propWins = strategy === 'prop-wins'\n\n // TODO can try no useEffect here right? just if()\n if (currentProp.current !== prop && !preventUpdate) {\n currentProp.current = prop\n setVal((prev) => {\n return getNextStateWithCallback(prev, prop, onChange)\n })\n }\n\n return [\n val,\n useEvent((next: unknown) => {\n if (preventUpdate) return\n if (propWins && currentProp.current !== undefined) {\n onChange?.(next as T)\n return\n }\n setVal((prev) => {\n return getNextStateWithCallback(\n prev,\n typeof next === 'function' ? next(prev) : next,\n onChange\n )\n })\n }),\n ]\n}\n\nconst getNextStateWithCallback = (prev: any, next: any, handleChange?: ChangeCb<any>) => {\n if (prev === next || next === undefined) {\n return prev\n }\n handleChange?.(next)\n return next\n}\n"],
5
- "mappings": "AAAA;AACA;AAOO,8BAAiC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,GAO+C;AAC/C,QAAM,cAAc,OAAO,IAAI;AAC/B,QAAM,CAAC,KAAK,UAAU,SAAS,QAAQ,WAAW;AAClD,QAAM,WAAW,aAAa;AAG9B,MAAI,YAAY,YAAY,QAAQ,CAAC,eAAe;AAClD,gBAAY,UAAU;AACtB,WAAO,CAAC,SAAS;AACf,aAAO,yBAAyB,MAAM,MAAM,QAAQ;AAAA,IACtD,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL;AAAA,IACA,SAAS,CAAC,SAAkB;AAC1B,UAAI;AAAe;AACnB,UAAI,YAAY,YAAY,YAAY,QAAW;AACjD,6CAAW;AACX;AAAA,MACF;AACA,aAAO,CAAC,SAAS;AACf,eAAO,yBACL,MACA,OAAO,SAAS,aAAa,KAAK,IAAI,IAAI,MAC1C,QACF;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;AAEA,MAAM,2BAA2B,CAAC,MAAW,MAAW,iBAAiC;AACvF,MAAI,SAAS,QAAQ,SAAS,QAAW;AACvC,WAAO;AAAA,EACT;AACA,+CAAe;AACf,SAAO;AACT;",
6
- "names": []
7
- }
@@ -1,44 +0,0 @@
1
- import { useEvent } from "@tamagui/use-event";
2
- import { useRef, useState } from "react";
3
- function useControllableState({
4
- prop,
5
- defaultProp,
6
- onChange,
7
- strategy = "prop-wins",
8
- preventUpdate
9
- }) {
10
- const currentProp = useRef(prop);
11
- const [val, setVal] = useState(prop != null ? prop : defaultProp);
12
- const propWins = strategy === "prop-wins";
13
- if (currentProp.current !== prop && !preventUpdate) {
14
- currentProp.current = prop;
15
- setVal((prev) => {
16
- return getNextStateWithCallback(prev, prop, onChange);
17
- });
18
- }
19
- return [
20
- val,
21
- useEvent((next) => {
22
- if (preventUpdate)
23
- return;
24
- if (propWins && currentProp.current !== void 0) {
25
- onChange == null ? void 0 : onChange(next);
26
- return;
27
- }
28
- setVal((prev) => {
29
- return getNextStateWithCallback(prev, typeof next === "function" ? next(prev) : next, onChange);
30
- });
31
- })
32
- ];
33
- }
34
- const getNextStateWithCallback = (prev, next, handleChange) => {
35
- if (prev === next || next === void 0) {
36
- return prev;
37
- }
38
- handleChange == null ? void 0 : handleChange(next);
39
- return next;
40
- };
41
- export {
42
- useControllableState
43
- };
44
- //# sourceMappingURL=useControllableState.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/useControllableState.ts"],
4
- "sourcesContent": ["import { useEvent } from '@tamagui/use-event'\nimport React, { useEffect, useRef, useState } from 'react'\n\n// can configure to allow most-recent-wins or prop-wins\n// defaults to prop-wins\n\ntype ChangeCb<T> = ((next: T) => void) | React.Dispatch<React.SetStateAction<T>>\n\nexport function useControllableState<T>({\n prop,\n defaultProp,\n onChange,\n strategy = 'prop-wins',\n preventUpdate,\n}: {\n prop?: T | undefined\n defaultProp: T\n onChange?: ChangeCb<T>\n strategy?: 'prop-wins' | 'most-recent-wins'\n preventUpdate?: boolean\n}): [T, React.Dispatch<React.SetStateAction<T>>] {\n const currentProp = useRef(prop)\n const [val, setVal] = useState(prop ?? defaultProp)\n const propWins = strategy === 'prop-wins'\n\n // TODO can try no useEffect here right? just if()\n if (currentProp.current !== prop && !preventUpdate) {\n currentProp.current = prop\n setVal((prev) => {\n return getNextStateWithCallback(prev, prop, onChange)\n })\n }\n\n return [\n val,\n useEvent((next: unknown) => {\n if (preventUpdate) return\n if (propWins && currentProp.current !== undefined) {\n onChange?.(next as T)\n return\n }\n setVal((prev) => {\n return getNextStateWithCallback(\n prev,\n typeof next === 'function' ? next(prev) : next,\n onChange\n )\n })\n }),\n ]\n}\n\nconst getNextStateWithCallback = (prev: any, next: any, handleChange?: ChangeCb<any>) => {\n if (prev === next || next === undefined) {\n return prev\n }\n handleChange?.(next)\n return next\n}\n"],
5
- "mappings": "AAAA;AACA;AAOO,8BAAiC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,GAO+C;AAC/C,QAAM,cAAc,OAAO,IAAI;AAC/B,QAAM,CAAC,KAAK,UAAU,SAAS,sBAAQ,WAAW;AAClD,QAAM,WAAW,aAAa;AAG9B,MAAI,YAAY,YAAY,QAAQ,CAAC,eAAe;AAClD,gBAAY,UAAU;AACtB,WAAO,CAAC,SAAS;AACf,aAAO,yBAAyB,MAAM,MAAM,QAAQ;AAAA,IACtD,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL;AAAA,IACA,SAAS,CAAC,SAAkB;AAC1B,UAAI;AAAe;AACnB,UAAI,YAAY,YAAY,YAAY,QAAW;AACjD,6CAAW;AACX;AAAA,MACF;AACA,aAAO,CAAC,SAAS;AACf,eAAO,yBACL,MACA,OAAO,SAAS,aAAa,KAAK,IAAI,IAAI,MAC1C,QACF;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;AAEA,MAAM,2BAA2B,CAAC,MAAW,MAAW,iBAAiC;AACvF,MAAI,SAAS,QAAQ,SAAS,QAAW;AACvC,WAAO;AAAA,EACT;AACA,+CAAe;AACf,SAAO;AACT;",
6
- "names": []
7
- }
@@ -1,11 +0,0 @@
1
- import React from 'react';
2
- declare type ChangeCb<T> = ((next: T) => void) | React.Dispatch<React.SetStateAction<T>>;
3
- export declare function useControllableState<T>({ prop, defaultProp, onChange, strategy, preventUpdate, }: {
4
- prop?: T | undefined;
5
- defaultProp: T;
6
- onChange?: ChangeCb<T>;
7
- strategy?: 'prop-wins' | 'most-recent-wins';
8
- preventUpdate?: boolean;
9
- }): [T, React.Dispatch<React.SetStateAction<T>>];
10
- export {};
11
- //# sourceMappingURL=useControllableState.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useControllableState.d.ts","sourceRoot":"","sources":["../src/useControllableState.ts"],"names":[],"mappings":"AACA,OAAO,KAAsC,MAAM,OAAO,CAAA;AAK1D,aAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;AAEhF,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,EACtC,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,QAAsB,EACtB,aAAa,GACd,EAAE;IACD,IAAI,CAAC,EAAE,CAAC,GAAG,SAAS,CAAA;IACpB,WAAW,EAAE,CAAC,CAAA;IACd,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;IACtB,QAAQ,CAAC,EAAE,WAAW,GAAG,kBAAkB,CAAA;IAC3C,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CA8B/C"}