@r5n/otp-react-native 0.0.0-stage → 8.0.0

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.
Files changed (114) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/LICENSE +21 -0
  3. package/README.md +227 -2
  4. package/lib/commonjs/Cell.js +140 -0
  5. package/lib/commonjs/Cell.js.map +1 -0
  6. package/lib/commonjs/OtpInput.js +129 -0
  7. package/lib/commonjs/OtpInput.js.map +1 -0
  8. package/lib/commonjs/accessibility.js +90 -0
  9. package/lib/commonjs/accessibility.js.map +1 -0
  10. package/lib/commonjs/clipboard.js +197 -0
  11. package/lib/commonjs/clipboard.js.map +1 -0
  12. package/lib/commonjs/dev.js +63 -0
  13. package/lib/commonjs/dev.js.map +1 -0
  14. package/lib/commonjs/hiddenInput.js +95 -0
  15. package/lib/commonjs/hiddenInput.js.map +1 -0
  16. package/lib/commonjs/index.js +53 -0
  17. package/lib/commonjs/index.js.map +1 -0
  18. package/lib/commonjs/legacy.js +217 -0
  19. package/lib/commonjs/legacy.js.map +1 -0
  20. package/lib/commonjs/managedProps.js +73 -0
  21. package/lib/commonjs/managedProps.js.map +1 -0
  22. package/lib/commonjs/package.json +1 -0
  23. package/lib/commonjs/types.js +45 -0
  24. package/lib/commonjs/types.js.map +1 -0
  25. package/lib/commonjs/useOtpController.js +70 -0
  26. package/lib/commonjs/useOtpController.js.map +1 -0
  27. package/lib/commonjs/useOtpInput.js +251 -0
  28. package/lib/commonjs/useOtpInput.js.map +1 -0
  29. package/lib/module/Cell.js +103 -0
  30. package/lib/module/Cell.js.map +1 -0
  31. package/lib/module/OtpInput.js +94 -0
  32. package/lib/module/OtpInput.js.map +1 -0
  33. package/lib/module/accessibility.js +49 -0
  34. package/lib/module/accessibility.js.map +1 -0
  35. package/lib/module/clipboard.js +156 -0
  36. package/lib/module/clipboard.js.map +1 -0
  37. package/lib/module/dev.js +22 -0
  38. package/lib/module/dev.js.map +1 -0
  39. package/lib/module/hiddenInput.js +54 -0
  40. package/lib/module/hiddenInput.js.map +1 -0
  41. package/lib/module/index.js +14 -0
  42. package/lib/module/index.js.map +1 -0
  43. package/lib/module/legacy.js +187 -0
  44. package/lib/module/legacy.js.map +1 -0
  45. package/lib/module/managedProps.js +32 -0
  46. package/lib/module/managedProps.js.map +1 -0
  47. package/lib/module/types.js +3 -0
  48. package/lib/module/types.js.map +1 -0
  49. package/lib/module/useOtpController.js +29 -0
  50. package/lib/module/useOtpController.js.map +1 -0
  51. package/lib/module/useOtpInput.js +216 -0
  52. package/lib/module/useOtpInput.js.map +1 -0
  53. package/lib/typescript/commonjs/package.json +1 -0
  54. package/lib/typescript/commonjs/src/Cell.d.ts +39 -0
  55. package/lib/typescript/commonjs/src/Cell.d.ts.map +1 -0
  56. package/lib/typescript/commonjs/src/OtpInput.d.ts +12 -0
  57. package/lib/typescript/commonjs/src/OtpInput.d.ts.map +1 -0
  58. package/lib/typescript/commonjs/src/accessibility.d.ts +39 -0
  59. package/lib/typescript/commonjs/src/accessibility.d.ts.map +1 -0
  60. package/lib/typescript/commonjs/src/clipboard.d.ts +9 -0
  61. package/lib/typescript/commonjs/src/clipboard.d.ts.map +1 -0
  62. package/lib/typescript/commonjs/src/dev.d.ts +13 -0
  63. package/lib/typescript/commonjs/src/dev.d.ts.map +1 -0
  64. package/lib/typescript/commonjs/src/hiddenInput.d.ts +31 -0
  65. package/lib/typescript/commonjs/src/hiddenInput.d.ts.map +1 -0
  66. package/lib/typescript/commonjs/src/index.d.ts +11 -0
  67. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  68. package/lib/typescript/commonjs/src/legacy.d.ts +78 -0
  69. package/lib/typescript/commonjs/src/legacy.d.ts.map +1 -0
  70. package/lib/typescript/commonjs/src/managedProps.d.ts +5 -0
  71. package/lib/typescript/commonjs/src/managedProps.d.ts.map +1 -0
  72. package/lib/typescript/commonjs/src/types.d.ts +262 -0
  73. package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
  74. package/lib/typescript/commonjs/src/useOtpController.d.ts +28 -0
  75. package/lib/typescript/commonjs/src/useOtpController.d.ts.map +1 -0
  76. package/lib/typescript/commonjs/src/useOtpInput.d.ts +22 -0
  77. package/lib/typescript/commonjs/src/useOtpInput.d.ts.map +1 -0
  78. package/lib/typescript/module/src/Cell.d.ts +39 -0
  79. package/lib/typescript/module/src/Cell.d.ts.map +1 -0
  80. package/lib/typescript/module/src/OtpInput.d.ts +12 -0
  81. package/lib/typescript/module/src/OtpInput.d.ts.map +1 -0
  82. package/lib/typescript/module/src/accessibility.d.ts +39 -0
  83. package/lib/typescript/module/src/accessibility.d.ts.map +1 -0
  84. package/lib/typescript/module/src/clipboard.d.ts +9 -0
  85. package/lib/typescript/module/src/clipboard.d.ts.map +1 -0
  86. package/lib/typescript/module/src/dev.d.ts +13 -0
  87. package/lib/typescript/module/src/dev.d.ts.map +1 -0
  88. package/lib/typescript/module/src/hiddenInput.d.ts +31 -0
  89. package/lib/typescript/module/src/hiddenInput.d.ts.map +1 -0
  90. package/lib/typescript/module/src/index.d.ts +11 -0
  91. package/lib/typescript/module/src/index.d.ts.map +1 -0
  92. package/lib/typescript/module/src/legacy.d.ts +78 -0
  93. package/lib/typescript/module/src/legacy.d.ts.map +1 -0
  94. package/lib/typescript/module/src/managedProps.d.ts +5 -0
  95. package/lib/typescript/module/src/managedProps.d.ts.map +1 -0
  96. package/lib/typescript/module/src/types.d.ts +262 -0
  97. package/lib/typescript/module/src/types.d.ts.map +1 -0
  98. package/lib/typescript/module/src/useOtpController.d.ts +28 -0
  99. package/lib/typescript/module/src/useOtpController.d.ts.map +1 -0
  100. package/lib/typescript/module/src/useOtpInput.d.ts +22 -0
  101. package/lib/typescript/module/src/useOtpInput.d.ts.map +1 -0
  102. package/package.json +102 -4
  103. package/src/Cell.tsx +146 -0
  104. package/src/OtpInput.tsx +120 -0
  105. package/src/accessibility.ts +86 -0
  106. package/src/clipboard.ts +232 -0
  107. package/src/dev.ts +33 -0
  108. package/src/hiddenInput.ts +80 -0
  109. package/src/index.ts +38 -0
  110. package/src/legacy.tsx +317 -0
  111. package/src/managedProps.ts +29 -0
  112. package/src/types.ts +299 -0
  113. package/src/useOtpController.ts +58 -0
  114. package/src/useOtpInput.ts +313 -0
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ function __accessProp(key) {
7
+ return this[key];
8
+ }
9
+ var __toCommonJS = (from) => {
10
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
11
+ if (entry)
12
+ return entry;
13
+ entry = __defProp({}, "__esModule", { value: true });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (var key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(entry, key))
17
+ __defProp(entry, key, {
18
+ get: __accessProp.bind(from, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ __moduleCache.set(from, entry);
23
+ return entry;
24
+ };
25
+ var __moduleCache;
26
+ var __returnValue = (v) => v;
27
+ function __exportSetter(name, newValue) {
28
+ this[name] = __returnValue.bind(null, newValue);
29
+ }
30
+ var __export = (target, all) => {
31
+ for (var name in all)
32
+ __defProp(target, name, {
33
+ get: all[name],
34
+ enumerable: true,
35
+ configurable: true,
36
+ set: __exportSetter.bind(all, name)
37
+ });
38
+ };
39
+
40
+ // src/legacy.tsx
41
+ var exports_legacy = {};
42
+ __export(exports_legacy, {
43
+ OtpInputs: () => OtpInputs
44
+ });
45
+ module.exports = __toCommonJS(exports_legacy);
46
+ var import_otp_core = require("@r5n/otp-core");
47
+ var import_react = require("react");
48
+ var import_react_native = require("react-native");
49
+ var import_Cell = require("./Cell.js");
50
+ var import_dev = require("./dev.js");
51
+ var import_OtpInput = require("./OtpInput.js");
52
+ var jsx_runtime = require("react/jsx-runtime");
53
+ var IGNORED = [
54
+ "selectTextOnFocus",
55
+ "clearTextOnFocus",
56
+ "caretHidden",
57
+ "contextMenuHidden",
58
+ "maxLength",
59
+ "value",
60
+ "selection",
61
+ "pointerEvents",
62
+ "inputMode"
63
+ ];
64
+ var styles = import_react_native.StyleSheet.create({
65
+ container: {
66
+ alignItems: "center",
67
+ flex: 1,
68
+ flexDirection: "row",
69
+ justifyContent: "space-between"
70
+ }
71
+ });
72
+ var dismissKeyboard = () => import_react_native.Keyboard.dismiss();
73
+ var checkNumberOfInputs = (numberOfInputs) => {
74
+ try {
75
+ import_otp_core.resolveOptions({ length: numberOfInputs });
76
+ } catch (error) {
77
+ const reason = error instanceof Error ? error.message : String(error);
78
+ throw new RangeError(`@r5n/otp-react-native: invalid \`numberOfInputs\` (${String(numberOfInputs)}), which v8 ` + `passes to OtpInput as \`length\`: ${reason}`);
79
+ }
80
+ };
81
+ var toProvider = (clipboard, intervalMs) => ({
82
+ getString: clipboard.getString.bind(clipboard),
83
+ hasString: clipboard.hasString?.bind(clipboard),
84
+ intervalMs
85
+ });
86
+ var OtpInputs = import_react.forwardRef(function OtpInputs2({
87
+ numberOfInputs = 4,
88
+ handleChange,
89
+ defaultValue,
90
+ autofillFromClipboard,
91
+ autofillListenerIntervalMS,
92
+ clipboard,
93
+ keyboardType = "phone-pad",
94
+ style,
95
+ focusStyles,
96
+ inputContainerStyles,
97
+ inputStyles,
98
+ isRTL = false,
99
+ testIDPrefix = "otpInput",
100
+ autoFocus,
101
+ placeholder,
102
+ secureTextEntry,
103
+ editable,
104
+ readOnly,
105
+ onFocus,
106
+ onBlur,
107
+ accessibilityLabel,
108
+ accessibilityHint,
109
+ autoComplete,
110
+ testID,
111
+ placeholderTextColor,
112
+ maxFontSizeMultiplier,
113
+ allowFontScaling,
114
+ selectTextOnFocus,
115
+ clearTextOnFocus,
116
+ caretHidden,
117
+ contextMenuHidden,
118
+ maxLength,
119
+ value,
120
+ selection,
121
+ pointerEvents,
122
+ inputMode,
123
+ ...textInputProps
124
+ }, ref) {
125
+ checkNumberOfInputs(numberOfInputs);
126
+ const inner = import_react.useRef(null);
127
+ const onChange = import_react.useRef(handleChange);
128
+ import_react.useLayoutEffect(() => {
129
+ onChange.current = handleChange;
130
+ });
131
+ import_react.useImperativeHandle(ref, () => ({
132
+ reset: () => {
133
+ const input = inner.current;
134
+ if (input?.getValue() === "")
135
+ onChange.current?.("");
136
+ else
137
+ input?.clear();
138
+ },
139
+ focus: () => inner.current?.focus()
140
+ }), []);
141
+ const appliedDefault = import_react.useRef(null);
142
+ import_react.useEffect(() => {
143
+ const previous = appliedDefault.current;
144
+ appliedDefault.current = defaultValue ?? "";
145
+ if (!defaultValue || defaultValue === previous)
146
+ return;
147
+ if (previous === null)
148
+ onChange.current?.(inner.current?.getValue() ?? "");
149
+ else
150
+ inner.current?.setValue(defaultValue);
151
+ }, [defaultValue]);
152
+ const passed = {
153
+ selectTextOnFocus,
154
+ clearTextOnFocus,
155
+ caretHidden,
156
+ contextMenuHidden,
157
+ maxLength,
158
+ value,
159
+ selection,
160
+ pointerEvents,
161
+ inputMode
162
+ };
163
+ const v7Styled = inputContainerStyles !== undefined || inputStyles !== undefined || focusStyles !== undefined;
164
+ const ignored = IGNORED.filter((name) => passed[name] !== undefined).join(", ");
165
+ const secureAndroid = secureTextEntry === true && import_react_native.Platform.OS === "android";
166
+ const wantsClipboard = autofillFromClipboard === true || autofillListenerIntervalMS !== undefined;
167
+ const missingClipboard = wantsClipboard && clipboard === undefined;
168
+ import_react.useEffect(() => {
169
+ if (!__DEV__)
170
+ return;
171
+ import_dev.warnOnce("deprecated", "the default export (the v7 API) is deprecated and will be removed in the next major version. " + "Use `import { OtpInput } from '@r5n/otp-react-native'`; see the migration guide. " + "Clipboard autofill is now off unless you pass a `clipboard` provider.");
172
+ }, []);
173
+ import_react.useEffect(() => {
174
+ if (!__DEV__ || ignored === "")
175
+ return;
176
+ import_dev.warnOnce(`ignored:${ignored}`, `ignored v7 props (no effect in v8): ${ignored}.`);
177
+ }, [ignored]);
178
+ import_react.useEffect(() => {
179
+ if (!__DEV__ || !missingClipboard)
180
+ return;
181
+ import_dev.warnOnce("clipboard", "autofillFromClipboard needs a clipboard provider since v8, which has no native dependencies. " + "Pass `clipboard={Clipboard}` (from @react-native-clipboard/clipboard) or " + "`clipboard={{ getString: Clipboard.getStringAsync, hasString: Clipboard.hasStringAsync }}` (expo-clipboard).");
182
+ }, [missingClipboard]);
183
+ return /* @__PURE__ */ jsx_runtime.jsx(import_Cell.CellAppearance.Provider, {
184
+ value: v7Styled ? "none" : "default",
185
+ children: /* @__PURE__ */ jsx_runtime.jsx(import_OtpInput.OtpInput, {
186
+ ref: inner,
187
+ length: numberOfInputs,
188
+ charset: "any",
189
+ defaultValue,
190
+ onChange: handleChange,
191
+ onComplete: dismissKeyboard,
192
+ autoFocus,
193
+ disabled: editable === false || readOnly === true,
194
+ mask: secureTextEntry === true,
195
+ placeholder,
196
+ keyboardType: secureAndroid && keyboardType === "phone-pad" ? "number-pad" : keyboardType,
197
+ autoComplete: autoComplete === "off" ? "off" : "auto",
198
+ direction: isRTL === true !== import_react_native.I18nManager.isRTL ? "rtl" : "ltr",
199
+ clipboardAutofill: autofillFromClipboard === false || clipboard === undefined ? false : toProvider(clipboard, autofillListenerIntervalMS),
200
+ onFocus,
201
+ onBlur,
202
+ accessibilityLabel,
203
+ accessibilityHint,
204
+ textInputProps: secureAndroid ? { ...textInputProps, secureTextEntry: true } : textInputProps,
205
+ testID: testID ?? testIDPrefix,
206
+ style: style ?? styles.container,
207
+ cellStyle: inputContainerStyles,
208
+ focusedCellStyle: focusStyles,
209
+ cellTextStyle: inputStyles,
210
+ placeholderTextColor,
211
+ maxFontSizeMultiplier: allowFontScaling === false ? 1 : maxFontSizeMultiplier
212
+ })
213
+ });
214
+ });
215
+
216
+ //# debugId=3EE3C6E7329076D864756E2164756E21
217
+ //# sourceMappingURL=legacy.js.map
@@ -0,0 +1 @@
1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;AAAA,MAClB,eAAe;AAAA,MACf;AAAA,MAGA,uBACE,qBAAqB,QAAQ,IAAK;AAAA,KAEtC;AAAA,GACA;AAAA,CAEL;","debugId":"3EE3C6E7329076D864756E2164756E21","names":[]}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ function __accessProp(key) {
7
+ return this[key];
8
+ }
9
+ var __toCommonJS = (from) => {
10
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
11
+ if (entry)
12
+ return entry;
13
+ entry = __defProp({}, "__esModule", { value: true });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (var key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(entry, key))
17
+ __defProp(entry, key, {
18
+ get: __accessProp.bind(from, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ __moduleCache.set(from, entry);
23
+ return entry;
24
+ };
25
+ var __moduleCache;
26
+ var __returnValue = (v) => v;
27
+ function __exportSetter(name, newValue) {
28
+ this[name] = __returnValue.bind(null, newValue);
29
+ }
30
+ var __export = (target, all) => {
31
+ for (var name in all)
32
+ __defProp(target, name, {
33
+ get: all[name],
34
+ enumerable: true,
35
+ configurable: true,
36
+ set: __exportSetter.bind(all, name)
37
+ });
38
+ };
39
+
40
+ // src/managedProps.ts
41
+ var exports_managedProps = {};
42
+ __export(exports_managedProps, {
43
+ CELL_MANAGED_PROPS: () => CELL_MANAGED_PROPS,
44
+ TEXT_INPUT_MANAGED_PROPS: () => TEXT_INPUT_MANAGED_PROPS
45
+ });
46
+ module.exports = __toCommonJS(exports_managedProps);
47
+ var TEXT_INPUT_MANAGED_PROPS = [
48
+ "value",
49
+ "defaultValue",
50
+ "maxLength",
51
+ "selection",
52
+ "editable",
53
+ "readOnly",
54
+ "caretHidden",
55
+ "contextMenuHidden",
56
+ "pointerEvents",
57
+ "selectTextOnFocus",
58
+ "clearTextOnFocus",
59
+ "inputMode"
60
+ ];
61
+ var CELL_MANAGED_PROPS = [
62
+ "children",
63
+ "style",
64
+ "testID",
65
+ "pointerEvents",
66
+ "aria-hidden",
67
+ "accessible",
68
+ "accessibilityElementsHidden",
69
+ "importantForAccessibility"
70
+ ];
71
+
72
+ //# debugId=416352E46FC7038364756E2164756E21
73
+ //# sourceMappingURL=managedProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/managedProps.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,2BAA2B;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGO,IAAM,qBAAqB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","debugId":"416352E46FC7038364756E2164756E21","names":[]}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ function __accessProp(key) {
7
+ return this[key];
8
+ }
9
+ var __toCommonJS = (from) => {
10
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
11
+ if (entry)
12
+ return entry;
13
+ entry = __defProp({}, "__esModule", { value: true });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (var key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(entry, key))
17
+ __defProp(entry, key, {
18
+ get: __accessProp.bind(from, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ __moduleCache.set(from, entry);
23
+ return entry;
24
+ };
25
+ var __moduleCache;
26
+ var __returnValue = (v) => v;
27
+ function __exportSetter(name, newValue) {
28
+ this[name] = __returnValue.bind(null, newValue);
29
+ }
30
+ var __export = (target, all) => {
31
+ for (var name in all)
32
+ __defProp(target, name, {
33
+ get: all[name],
34
+ enumerable: true,
35
+ configurable: true,
36
+ set: __exportSetter.bind(all, name)
37
+ });
38
+ };
39
+
40
+ // src/types.ts
41
+ var exports_types = {};
42
+ module.exports = __toCommonJS(exports_types);
43
+
44
+ //# debugId=61E0101AD0A6EDEA64756E2164756E21
45
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"mappings":"","debugId":"61E0101AD0A6EDEA64756E2164756E21","names":[]}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ function __accessProp(key) {
7
+ return this[key];
8
+ }
9
+ var __toCommonJS = (from) => {
10
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
11
+ if (entry)
12
+ return entry;
13
+ entry = __defProp({}, "__esModule", { value: true });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (var key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(entry, key))
17
+ __defProp(entry, key, {
18
+ get: __accessProp.bind(from, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ __moduleCache.set(from, entry);
23
+ return entry;
24
+ };
25
+ var __moduleCache;
26
+ var __returnValue = (v) => v;
27
+ function __exportSetter(name, newValue) {
28
+ this[name] = __returnValue.bind(null, newValue);
29
+ }
30
+ var __export = (target, all) => {
31
+ for (var name in all)
32
+ __defProp(target, name, {
33
+ get: all[name],
34
+ enumerable: true,
35
+ configurable: true,
36
+ set: __exportSetter.bind(all, name)
37
+ });
38
+ };
39
+
40
+ // src/useOtpController.ts
41
+ var exports_useOtpController = {};
42
+ __export(exports_useOtpController, {
43
+ isDestroyed: () => isDestroyed,
44
+ useOtpController: () => useOtpController
45
+ });
46
+ module.exports = __toCommonJS(exports_useOtpController);
47
+ var import_react = require("react");
48
+ var destroyed = new WeakSet;
49
+ var isDestroyed = (controller) => destroyed.has(controller);
50
+ var useOtpController = (create, reconcile) => {
51
+ const [controller, setController] = import_react.useState(() => create());
52
+ import_react.useEffect(() => {
53
+ if (isDestroyed(controller)) {
54
+ setController(create(controller.getSnapshot()));
55
+ return;
56
+ }
57
+ return () => {
58
+ destroyed.add(controller);
59
+ controller.destroy();
60
+ };
61
+ }, [controller, create]);
62
+ import_react.useLayoutEffect(() => {
63
+ controller.update(reconcile);
64
+ });
65
+ const snapshot = import_react.useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot);
66
+ return { controller, snapshot };
67
+ };
68
+
69
+ //# debugId=9BF3E168762697FF64756E2164756E21
70
+ //# sourceMappingURL=useOtpController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/useOtpController.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAC2E,IAA3E;AAGA,IAAM,YAAY,IAAI;AAGf,IAAM,cAAc,CAAC,eAAuC,UAAU,IAAI,UAAU;AA0BpF,IAAM,mBAAmB,CAC9B,QACA,cACsB;AAAA,EACtB,OAAO,YAAY,iBAAiB,sBAAwB,MAAM,OAAO,CAAC;AAAA,EAC1E,uBAAU,MAAM;AAAA,IACd,IAAI,YAAY,UAAU,GAAG;AAAA,MAC3B,cAAc,OAAO,WAAW,YAAY,CAAC,CAAC;AAAA,MAC9C;AAAA,IACF;AAAA,IACA,OAAO,MAAM;AAAA,MACX,UAAU,IAAI,UAAU;AAAA,MACxB,WAAW,QAAQ;AAAA;AAAA,KAEpB,CAAC,YAAY,MAAM,CAAC;AAAA,EACvB,6BAAgB,MAAM;AAAA,IACpB,WAAW,OAAO,SAAS;AAAA,GAC5B;AAAA,EACD,MAAM,WAAW,kCACf,WAAW,WACX,WAAW,aACX,WAAW,WACb;AAAA,EACA,OAAO,EAAE,YAAY,SAAS;AAAA;","debugId":"9BF3E168762697FF64756E2164756E21","names":[]}
@@ -0,0 +1,251 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ function __accessProp(key) {
7
+ return this[key];
8
+ }
9
+ var __toCommonJS = (from) => {
10
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
11
+ if (entry)
12
+ return entry;
13
+ entry = __defProp({}, "__esModule", { value: true });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (var key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(entry, key))
17
+ __defProp(entry, key, {
18
+ get: __accessProp.bind(from, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ __moduleCache.set(from, entry);
23
+ return entry;
24
+ };
25
+ var __moduleCache;
26
+ var __returnValue = (v) => v;
27
+ function __exportSetter(name, newValue) {
28
+ this[name] = __returnValue.bind(null, newValue);
29
+ }
30
+ var __export = (target, all) => {
31
+ for (var name in all)
32
+ __defProp(target, name, {
33
+ get: all[name],
34
+ enumerable: true,
35
+ configurable: true,
36
+ set: __exportSetter.bind(all, name)
37
+ });
38
+ };
39
+
40
+ // src/useOtpInput.ts
41
+ var exports_useOtpInput = {};
42
+ __export(exports_useOtpInput, {
43
+ useOtpInput: () => useOtpInput
44
+ });
45
+ module.exports = __toCommonJS(exports_useOtpInput);
46
+ var import_otp_core = require("@r5n/otp-core");
47
+ var import_react = require("react");
48
+ var import_react_native = require("react-native");
49
+ var import_accessibility = require("./accessibility.js");
50
+ var import_Cell = require("./Cell.js");
51
+ var import_clipboard = require("./clipboard.js");
52
+ var import_dev = require("./dev.js");
53
+ var import_hiddenInput = require("./hiddenInput.js");
54
+ var import_managedProps = require("./managedProps.js");
55
+ var import_useOtpController = require("./useOtpController.js");
56
+ var MASK_GLYPH = "•";
57
+ var toCodePoints = (text, offset) => Array.from(text.slice(0, offset)).length;
58
+ var followSelection = (controller, input, { start, end }) => {
59
+ const { value } = controller.getSnapshot();
60
+ if (start !== end) {
61
+ controller.setSelection({ start: toCodePoints(value, start), end: toCodePoints(value, end) });
62
+ return;
63
+ }
64
+ if (end < value.length)
65
+ input.current?.setSelection?.(value.length, value.length);
66
+ const caret = Array.from(value).length;
67
+ controller.setSelection({ start: caret, end: caret });
68
+ };
69
+ function useOtpInput(options) {
70
+ const latest = import_react.useRef(options);
71
+ import_react.useLayoutEffect(() => {
72
+ latest.current = options;
73
+ });
74
+ const inputRef = import_react.useRef(null);
75
+ const create = import_react.useCallback((seed) => {
76
+ const { length, charset, casing, groups, value, defaultValue } = latest.current;
77
+ const controller = import_otp_core.createOtpController({
78
+ length,
79
+ charset,
80
+ casing,
81
+ groups,
82
+ value,
83
+ defaultValue: seed ? seed.value : defaultValue,
84
+ onChange: (next) => latest.current.onChange?.(next),
85
+ onComplete: (next) => {
86
+ const current = latest.current;
87
+ current.onComplete?.(next);
88
+ import_accessibility.announce(import_accessibility.announcementText(current.accessibilityTexts?.complete, "complete"));
89
+ if (current.blurOnComplete)
90
+ inputRef.current?.blur();
91
+ }
92
+ });
93
+ if (seed !== undefined && inputRef.current?.isFocused?.() === true)
94
+ controller.setFocused(true);
95
+ return controller;
96
+ }, []);
97
+ const {
98
+ length,
99
+ charset,
100
+ casing,
101
+ groups,
102
+ value,
103
+ autoFocus,
104
+ disabled,
105
+ error,
106
+ mask,
107
+ placeholder,
108
+ direction,
109
+ autoComplete = "auto",
110
+ keyboardType,
111
+ accessibilityLabel,
112
+ accessibilityHint,
113
+ accessibilityTexts,
114
+ textInputProps,
115
+ testID
116
+ } = options;
117
+ const { controller, snapshot } = import_useOtpController.useOtpController(create, {
118
+ length,
119
+ charset,
120
+ casing,
121
+ groups,
122
+ value
123
+ });
124
+ import_react.useEffect(() => {
125
+ if (!autoFocus)
126
+ return;
127
+ const frame = requestAnimationFrame(() => {
128
+ if (!latest.current.disabled)
129
+ inputRef.current?.focus();
130
+ });
131
+ return () => cancelAnimationFrame(frame);
132
+ }, [autoFocus]);
133
+ import_clipboard.useClipboardAutofill(controller, options.clipboardAutofill);
134
+ const blockedInputProps = import_dev.forbiddenKeys(textInputProps, import_managedProps.TEXT_INPUT_MANAGED_PROPS);
135
+ const blocked = blockedInputProps.join(", ");
136
+ import_react.useEffect(() => {
137
+ if (!__DEV__ || blocked === "")
138
+ return;
139
+ import_dev.warnOnce(`textInputProps:${blocked}`, `${blocked.split(", ").map((key) => `textInputProps.${key}`).join(", ")} ignored: the ` + "component manages these props, or they break paste, autofill or screen readers on the " + "hidden input (C:S3-6).");
140
+ }, [blocked]);
141
+ const controlled = value !== undefined;
142
+ const wasControlled = import_react.useRef(controlled);
143
+ const readOnlyValue = controlled && options.onChange === undefined && disabled !== true;
144
+ import_react.useEffect(() => {
145
+ if (!__DEV__)
146
+ return;
147
+ if (readOnlyValue) {
148
+ import_dev.warnOnce("value-without-onChange", "`value` was passed without `onChange`, so every edit is reverted. Pass `onChange`, " + "use `defaultValue` for an uncontrolled input, or set `disabled` (W:#21).");
149
+ }
150
+ if (controlled !== wasControlled.current) {
151
+ import_dev.warnOnce("controlled-switch", `an input switched from ${wasControlled.current ? "controlled" : "uncontrolled"} to ` + `${controlled ? "controlled" : "uncontrolled"}. Keep \`value\` either always defined or ` + "always undefined for the lifetime of the input (W:#21).");
152
+ }
153
+ wasControlled.current = controlled;
154
+ }, [readOnlyValue, controlled]);
155
+ const errorText = import_accessibility.announcementText(accessibilityTexts?.error, "error");
156
+ import_accessibility.useAnnounceOnRise(error === true, errorText);
157
+ const actions = import_react.useMemo(() => ({
158
+ focus: () => {
159
+ if (!latest.current.disabled)
160
+ inputRef.current?.focus();
161
+ },
162
+ blur: () => inputRef.current?.blur(),
163
+ clear: () => controller.clear(),
164
+ setValue: (next) => controller.setValue(next),
165
+ getValue: () => controller.getSnapshot().value,
166
+ isFocused: () => controller.getSnapshot().isFocused
167
+ }), [controller]);
168
+ const handlers = import_react.useMemo(() => ({
169
+ onChangeText: (text) => {
170
+ controller.input(text);
171
+ latest.current.textInputProps?.onChangeText?.(text);
172
+ },
173
+ onSelectionChange: (event) => {
174
+ followSelection(controller, inputRef, event.nativeEvent.selection);
175
+ latest.current.textInputProps?.onSelectionChange?.(event);
176
+ },
177
+ onFocus: (event) => {
178
+ controller.setFocused(true);
179
+ latest.current.onFocus?.(event);
180
+ latest.current.textInputProps?.onFocus?.(event);
181
+ },
182
+ onBlur: (event) => {
183
+ controller.setFocused(false);
184
+ latest.current.onBlur?.(event);
185
+ latest.current.textInputProps?.onBlur?.(event);
186
+ }
187
+ }), [controller]);
188
+ const glyph = mask === true ? MASK_GLYPH : typeof mask === "string" && mask !== "" ? mask : undefined;
189
+ const isError = error === true;
190
+ const isDisabled = disabled === true;
191
+ const { slots, options: resolved } = snapshot;
192
+ const cells = import_react.useMemo(() => {
193
+ const hints = Array.from(placeholder ?? "");
194
+ const perCell = hints.length === resolved.length;
195
+ return slots.map((slot) => {
196
+ const hint = perCell ? hints[slot.index] ?? "" : placeholder ?? "";
197
+ return Object.freeze({
198
+ index: slot.index,
199
+ char: slot.char,
200
+ displayChar: slot.isFilled ? glyph ?? slot.char : hint,
201
+ isFilled: slot.isFilled,
202
+ isActive: slot.isActive,
203
+ isPlaceholder: !slot.isFilled && hint !== "",
204
+ isMasked: glyph !== undefined,
205
+ isError,
206
+ isDisabled,
207
+ groupIndex: slot.groupIndex,
208
+ isFirstInGroup: slot.isFirstInGroup,
209
+ isLastInGroup: slot.isLastInGroup
210
+ });
211
+ });
212
+ }, [slots, resolved.length, placeholder, glyph, isError, isDisabled]);
213
+ const rtl = direction === "rtl" || direction === "auto" && import_react_native.I18nManager.isRTL;
214
+ const rowStyle = import_react.useMemo(() => ({ flexDirection: "row", direction: rtl ? "rtl" : "ltr" }), [rtl]);
215
+ const extraInputProps = import_dev.withoutKeys(textInputProps, blockedInputProps);
216
+ const inputProps = {
217
+ ...import_hiddenInput.hiddenInputProps({ options: resolved, autoComplete, keyboardType }),
218
+ ...extraInputProps,
219
+ ...handlers,
220
+ ref: inputRef,
221
+ value: snapshot.value,
222
+ editable: !isDisabled,
223
+ style: [textInputProps?.style, import_hiddenInput.HIDDEN_INPUT_STYLE],
224
+ accessibilityLabel: accessibilityLabel ?? textInputProps?.accessibilityLabel ?? import_accessibility.defaultLabel(resolved),
225
+ accessibilityHint: accessibilityHint ?? textInputProps?.accessibilityHint,
226
+ accessibilityState: { ...textInputProps?.accessibilityState, disabled: isDisabled },
227
+ accessibilityValue: import_accessibility.accessibilityValue(snapshot.value, resolved.length, glyph !== undefined, isError ? errorText : "", accessibilityTexts),
228
+ testID: testID ?? textInputProps?.testID
229
+ };
230
+ return {
231
+ focus: actions.focus,
232
+ blur: actions.blur,
233
+ clear: actions.clear,
234
+ setValue: actions.setValue,
235
+ getValue: actions.getValue,
236
+ isFocused: actions.isFocused,
237
+ get input() {
238
+ return inputRef.current;
239
+ },
240
+ snapshot,
241
+ cells,
242
+ decorationProps: import_Cell.DECORATION_PROPS,
243
+ inputProps,
244
+ rowStyle,
245
+ pressableProps: { onPress: actions.focus, disabled: isDisabled, accessible: false },
246
+ controller
247
+ };
248
+ }
249
+
250
+ //# debugId=75BBF98CC2760BDC64756E2164756E21
251
+ //# sourceMappingURL=useOtpInput.js.map