@ozura/elements 1.0.1-next.7 → 1.0.2-next.8
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/frame/element-frame.js +31 -4
- package/dist/frame/element-frame.js.map +1 -1
- package/dist/frame/tokenizer-frame.js +14 -1
- package/dist/frame/tokenizer-frame.js.map +1 -1
- package/dist/oz-elements.esm.js +24 -0
- package/dist/oz-elements.esm.js.map +1 -1
- package/dist/oz-elements.umd.js +24 -0
- package/dist/oz-elements.umd.js.map +1 -1
- package/dist/react/frame/elementFrame.d.ts +59 -1
- package/dist/react/frame/protocol.d.ts +12 -0
- package/dist/react/index.cjs.js +117 -104
- package/dist/react/index.cjs.js.map +1 -1
- package/dist/react/index.esm.js +118 -105
- package/dist/react/index.esm.js.map +1 -1
- package/dist/react/types/index.d.ts +2 -0
- package/dist/server/frame/elementFrame.d.ts +59 -1
- package/dist/server/frame/protocol.d.ts +12 -0
- package/dist/server/types/index.d.ts +2 -0
- package/dist/types/frame/elementFrame.d.ts +59 -1
- package/dist/types/frame/protocol.d.ts +12 -0
- package/dist/types/types/index.d.ts +2 -0
- package/package.json +1 -1
package/dist/react/index.cjs.js
CHANGED
|
@@ -821,6 +821,19 @@ function validateBilling(billing) {
|
|
|
821
821
|
return { valid: errors.length === 0, errors, normalized };
|
|
822
822
|
}
|
|
823
823
|
|
|
824
|
+
/**
|
|
825
|
+
* Shared postMessage protocol constants.
|
|
826
|
+
*
|
|
827
|
+
* PROTOCOL_VERSION must be incremented any time a breaking change is made to
|
|
828
|
+
* the postMessage message shape (new required fields, renamed types, removed
|
|
829
|
+
* fields, changed semantics). The SDK reads this value from OZ_FRAME_READY
|
|
830
|
+
* messages and warns when the frame and SDK are out of sync.
|
|
831
|
+
*
|
|
832
|
+
* Non-breaking additions (new optional fields, new message types that old
|
|
833
|
+
* frames can safely ignore) do NOT require a version bump.
|
|
834
|
+
*/
|
|
835
|
+
const PROTOCOL_VERSION = 1;
|
|
836
|
+
|
|
824
837
|
function isCardMetadata(v) {
|
|
825
838
|
return !!v && typeof v === 'object' && typeof v.last4 === 'string';
|
|
826
839
|
}
|
|
@@ -1393,6 +1406,11 @@ class OzVault {
|
|
|
1393
1406
|
// the previous session and justCompleted never fires, breaking auto-advance.
|
|
1394
1407
|
if (msg.type === 'OZ_FRAME_READY') {
|
|
1395
1408
|
this.completionState.set(frameId, false);
|
|
1409
|
+
if (msg.__ozVersion !== PROTOCOL_VERSION) {
|
|
1410
|
+
console.warn(`[OzVault] Protocol version mismatch on element frame "${frameId}" — ` +
|
|
1411
|
+
`SDK expects v${PROTOCOL_VERSION}, frame reported v${typeof msg.__ozVersion === 'number' ? msg.__ozVersion : '(none)'}. ` +
|
|
1412
|
+
'Deploy the matching frame assets to elements.ozura.com and purge the Azure CDN cache.');
|
|
1413
|
+
}
|
|
1396
1414
|
}
|
|
1397
1415
|
// Intercept OZ_CHANGE before forwarding — handle auto-advance and CVV sync
|
|
1398
1416
|
if (msg.type === 'OZ_CHANGE') {
|
|
@@ -1438,6 +1456,12 @@ class OzVault {
|
|
|
1438
1456
|
var _a, _b, _c;
|
|
1439
1457
|
switch (msg.type) {
|
|
1440
1458
|
case 'OZ_FRAME_READY':
|
|
1459
|
+
if (msg.__ozVersion !== PROTOCOL_VERSION) {
|
|
1460
|
+
console.warn(`[OzVault] Protocol version mismatch — SDK expects v${PROTOCOL_VERSION}, ` +
|
|
1461
|
+
`tokenizer frame reported v${typeof msg.__ozVersion === 'number' ? msg.__ozVersion : '(none)'}. ` +
|
|
1462
|
+
'This usually means the deployed frame files are stale. ' +
|
|
1463
|
+
'Deploy the matching frame assets to elements.ozura.com and purge the Azure CDN cache.');
|
|
1464
|
+
}
|
|
1441
1465
|
this.tokenizerReady = true;
|
|
1442
1466
|
if (this.loadErrorTimeoutId != null) {
|
|
1443
1467
|
clearTimeout(this.loadErrorTimeoutId);
|
|
@@ -2020,6 +2044,71 @@ const OzCardNumber = (props) => jsxRuntime.jsx(OzFieldBase, Object.assign({ type
|
|
|
2020
2044
|
const OzExpiry = (props) => jsxRuntime.jsx(OzFieldBase, Object.assign({ type: "expirationDate", variant: "card" }, props));
|
|
2021
2045
|
/** Renders a PCI-isolated CVV input inside an Ozura iframe. */
|
|
2022
2046
|
const OzCvv = (props) => jsxRuntime.jsx(OzFieldBase, Object.assign({ type: "cvv", variant: "card" }, props));
|
|
2047
|
+
// ─── Shared composite-component hook ─────────────────────────────────────────
|
|
2048
|
+
/**
|
|
2049
|
+
* Shared plumbing for OzCard and OzBankCard.
|
|
2050
|
+
*
|
|
2051
|
+
* Manages:
|
|
2052
|
+
* - Callback refs (onChange, onReady, onFocus, onBlur) kept in sync on every render
|
|
2053
|
+
* - Vault-change detection: resets `readyFieldTypes` and `onReadyFiredRef` when the
|
|
2054
|
+
* vault instance is replaced (e.g. after fetchWaxKey changes or the provider remounts)
|
|
2055
|
+
* - Per-field ready tracking: creates one stable handler per named field; fires the
|
|
2056
|
+
* `onReady` callback once all `fieldNames.length` fields have reported ready
|
|
2057
|
+
* - Error state
|
|
2058
|
+
* - Layout helpers: `gapStr`, `resolvedLabelStyle`, `renderLabel`
|
|
2059
|
+
*
|
|
2060
|
+
* @internal — not exported; used only by OzCard and OzBankCard.
|
|
2061
|
+
*/
|
|
2062
|
+
function useCardBase({ vault, fieldNames, onChange, onReady, onFocus, onBlur, gap = 8, labelStyle, labelClassName, }) {
|
|
2063
|
+
const totalFields = fieldNames.length;
|
|
2064
|
+
const readyFieldTypes = react.useRef(new Set());
|
|
2065
|
+
const onReadyFiredRef = react.useRef(false);
|
|
2066
|
+
const vaultRef = react.useRef(vault);
|
|
2067
|
+
const onChangeRef = react.useRef(onChange);
|
|
2068
|
+
const onReadyRef = react.useRef(onReady);
|
|
2069
|
+
const onFocusRef = react.useRef(onFocus);
|
|
2070
|
+
const onBlurRef = react.useRef(onBlur);
|
|
2071
|
+
react.useEffect(() => { onChangeRef.current = onChange; }, [onChange]);
|
|
2072
|
+
react.useEffect(() => { onReadyRef.current = onReady; }, [onReady]);
|
|
2073
|
+
react.useEffect(() => { onFocusRef.current = onFocus; }, [onFocus]);
|
|
2074
|
+
react.useEffect(() => { onBlurRef.current = onBlur; }, [onBlur]);
|
|
2075
|
+
react.useEffect(() => {
|
|
2076
|
+
if (vault !== vaultRef.current) {
|
|
2077
|
+
vaultRef.current = vault;
|
|
2078
|
+
readyFieldTypes.current = new Set();
|
|
2079
|
+
onReadyFiredRef.current = false;
|
|
2080
|
+
}
|
|
2081
|
+
return () => {
|
|
2082
|
+
readyFieldTypes.current = new Set();
|
|
2083
|
+
onReadyFiredRef.current = false;
|
|
2084
|
+
};
|
|
2085
|
+
}, [vault]);
|
|
2086
|
+
// One stable handler per named field — recreated only when total field count changes.
|
|
2087
|
+
// Field names are static (card = 3 fields, bank = 2 fields) so `totalFields` alone
|
|
2088
|
+
// is a sufficient dependency; a JSON dep would create a new map on every render.
|
|
2089
|
+
// CONTRACT: `fieldNames` must be a static literal — callers must not pass a dynamic
|
|
2090
|
+
// array that changes length without also changing field count.
|
|
2091
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2092
|
+
const readyHandlers = react.useMemo(() => {
|
|
2093
|
+
const handlers = {};
|
|
2094
|
+
for (const name of fieldNames) {
|
|
2095
|
+
handlers[name] = () => {
|
|
2096
|
+
var _a;
|
|
2097
|
+
readyFieldTypes.current.add(name);
|
|
2098
|
+
if (readyFieldTypes.current.size >= totalFields && !onReadyFiredRef.current) {
|
|
2099
|
+
onReadyFiredRef.current = true;
|
|
2100
|
+
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
2101
|
+
}
|
|
2102
|
+
};
|
|
2103
|
+
}
|
|
2104
|
+
return handlers;
|
|
2105
|
+
}, [totalFields]); // totalFields captures fieldNames.length; field names are static
|
|
2106
|
+
const [error, setError] = react.useState();
|
|
2107
|
+
const gapStr = typeof gap === 'string' ? gap : `${gap}px`;
|
|
2108
|
+
const resolvedLabelStyle = react.useMemo(() => (labelStyle ? Object.assign(Object.assign({}, DEFAULT_LABEL_STYLE), labelStyle) : DEFAULT_LABEL_STYLE), [labelStyle]);
|
|
2109
|
+
const renderLabel = react.useCallback((text) => renderFieldLabel(text, labelClassName, resolvedLabelStyle), [labelClassName, resolvedLabelStyle]);
|
|
2110
|
+
return { onChangeRef, onFocusRef, onBlurRef, readyHandlers, error, setError, gapStr, resolvedLabelStyle, renderLabel };
|
|
2111
|
+
}
|
|
2023
2112
|
const DEFAULT_ERROR_STYLE = {
|
|
2024
2113
|
color: '#dc2626',
|
|
2025
2114
|
fontSize: 13,
|
|
@@ -2062,62 +2151,22 @@ function mergeStyles(base, override) {
|
|
|
2062
2151
|
function OzCard({ style, styles, classNames, labels, labelStyle, labelClassName, layout = 'default', gap = 8, hideErrors = false, errorStyle, errorClassName, renderError, onChange, onReady, onFocus, onBlur, disabled, className, placeholders, }) {
|
|
2063
2152
|
var _a, _b, _c;
|
|
2064
2153
|
const { vault } = react.useContext(OzContext);
|
|
2154
|
+
const { onChangeRef, onFocusRef, onBlurRef, readyHandlers, error, setError, gapStr, renderLabel, } = useCardBase({
|
|
2155
|
+
vault,
|
|
2156
|
+
fieldNames: ['cardNumber', 'expiry', 'cvv'],
|
|
2157
|
+
onChange,
|
|
2158
|
+
onReady,
|
|
2159
|
+
onFocus,
|
|
2160
|
+
onBlur,
|
|
2161
|
+
gap,
|
|
2162
|
+
labelStyle,
|
|
2163
|
+
labelClassName,
|
|
2164
|
+
});
|
|
2065
2165
|
const fieldState = react.useRef({
|
|
2066
2166
|
cardNumber: null,
|
|
2067
2167
|
expiry: null,
|
|
2068
2168
|
cvv: null,
|
|
2069
2169
|
});
|
|
2070
|
-
const readyFieldTypes = react.useRef(new Set());
|
|
2071
|
-
const onReadyFiredRef = react.useRef(false);
|
|
2072
|
-
const vaultRef = react.useRef(vault);
|
|
2073
|
-
const onChangeRef = react.useRef(onChange);
|
|
2074
|
-
const onReadyRef = react.useRef(onReady);
|
|
2075
|
-
const onFocusRef = react.useRef(onFocus);
|
|
2076
|
-
const onBlurRef = react.useRef(onBlur);
|
|
2077
|
-
react.useEffect(() => { onChangeRef.current = onChange; }, [onChange]);
|
|
2078
|
-
react.useEffect(() => { onReadyRef.current = onReady; }, [onReady]);
|
|
2079
|
-
react.useEffect(() => { onFocusRef.current = onFocus; }, [onFocus]);
|
|
2080
|
-
react.useEffect(() => { onBlurRef.current = onBlur; }, [onBlur]);
|
|
2081
|
-
// When the vault is recreated (e.g. appearance/fonts props change on OzElements),
|
|
2082
|
-
// context readyCount is reset but this ref is not. Reset so onReady fires once when all 3 are ready.
|
|
2083
|
-
// The cleanup resets readyFieldTypes when the component unmounts (covers React StrictMode double-invoke
|
|
2084
|
-
// and SPA scenarios where the parent re-mounts this component).
|
|
2085
|
-
react.useEffect(() => {
|
|
2086
|
-
if (vault !== vaultRef.current) {
|
|
2087
|
-
vaultRef.current = vault;
|
|
2088
|
-
readyFieldTypes.current = new Set();
|
|
2089
|
-
onReadyFiredRef.current = false;
|
|
2090
|
-
}
|
|
2091
|
-
return () => {
|
|
2092
|
-
readyFieldTypes.current = new Set();
|
|
2093
|
-
onReadyFiredRef.current = false;
|
|
2094
|
-
};
|
|
2095
|
-
}, [vault]);
|
|
2096
|
-
const [error, setError] = react.useState();
|
|
2097
|
-
const handleCardNumberReady = react.useCallback(() => {
|
|
2098
|
-
var _a;
|
|
2099
|
-
readyFieldTypes.current.add('cardNumber');
|
|
2100
|
-
if (readyFieldTypes.current.size >= 3 && !onReadyFiredRef.current) {
|
|
2101
|
-
onReadyFiredRef.current = true;
|
|
2102
|
-
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
2103
|
-
}
|
|
2104
|
-
}, []);
|
|
2105
|
-
const handleExpiryReady = react.useCallback(() => {
|
|
2106
|
-
var _a;
|
|
2107
|
-
readyFieldTypes.current.add('expiry');
|
|
2108
|
-
if (readyFieldTypes.current.size >= 3 && !onReadyFiredRef.current) {
|
|
2109
|
-
onReadyFiredRef.current = true;
|
|
2110
|
-
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
2111
|
-
}
|
|
2112
|
-
}, []);
|
|
2113
|
-
const handleCvvReady = react.useCallback(() => {
|
|
2114
|
-
var _a;
|
|
2115
|
-
readyFieldTypes.current.add('cvv');
|
|
2116
|
-
if (readyFieldTypes.current.size >= 3 && !onReadyFiredRef.current) {
|
|
2117
|
-
onReadyFiredRef.current = true;
|
|
2118
|
-
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
2119
|
-
}
|
|
2120
|
-
}, []);
|
|
2121
2170
|
const emitChange = react.useCallback(() => {
|
|
2122
2171
|
var _a;
|
|
2123
2172
|
const { cardNumber, expiry, cvv } = fieldState.current;
|
|
@@ -2132,20 +2181,16 @@ function OzCard({ style, styles, classNames, labels, labelStyle, labelClassName,
|
|
|
2132
2181
|
error: err,
|
|
2133
2182
|
fields: Object.assign({}, fieldState.current),
|
|
2134
2183
|
});
|
|
2135
|
-
}, []);
|
|
2136
|
-
const gapStr = typeof gap === 'string' ? gap : `${gap}px`;
|
|
2137
|
-
const resolvedLabelStyle = labelStyle
|
|
2138
|
-
? Object.assign(Object.assign({}, DEFAULT_LABEL_STYLE), labelStyle) : DEFAULT_LABEL_STYLE;
|
|
2139
|
-
const renderLabel = (text) => renderFieldLabel(text, labelClassName, resolvedLabelStyle);
|
|
2184
|
+
}, [setError, onChangeRef]);
|
|
2140
2185
|
const showError = !hideErrors && error;
|
|
2141
2186
|
const errorNode = showError
|
|
2142
2187
|
? renderError
|
|
2143
2188
|
? renderError(error)
|
|
2144
2189
|
: (jsxRuntime.jsx("div", { role: "alert", className: errorClassName, style: errorStyle ? Object.assign(Object.assign({}, DEFAULT_ERROR_STYLE), errorStyle) : DEFAULT_ERROR_STYLE, children: error }))
|
|
2145
2190
|
: null;
|
|
2146
|
-
const cardNumberField = (jsxRuntime.jsxs("div", { children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.cardNumber), jsxRuntime.jsx(OzCardNumber, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.cardNumber), className: classNames === null || classNames === void 0 ? void 0 : classNames.cardNumber, placeholder: (_a = placeholders === null || placeholders === void 0 ? void 0 : placeholders.cardNumber) !== null && _a !== void 0 ? _a : 'Card number', disabled: disabled, onChange: (e) => { fieldState.current.cardNumber = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'cardNumber'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'cardNumber'); }, onReady:
|
|
2147
|
-
const expiryField = (jsxRuntime.jsxs("div", { style: layout === 'default' ? { flex: 1 } : undefined, children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.expiry), jsxRuntime.jsx(OzExpiry, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.expiry), className: classNames === null || classNames === void 0 ? void 0 : classNames.expiry, placeholder: (_b = placeholders === null || placeholders === void 0 ? void 0 : placeholders.expiry) !== null && _b !== void 0 ? _b : 'MM / YY', disabled: disabled, onChange: (e) => { fieldState.current.expiry = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'expiry'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'expiry'); }, onReady:
|
|
2148
|
-
const cvvField = (jsxRuntime.jsxs("div", { style: layout === 'default' ? { flex: 1 } : undefined, children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.cvv), jsxRuntime.jsx(OzCvv, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.cvv), className: classNames === null || classNames === void 0 ? void 0 : classNames.cvv, placeholder: (_c = placeholders === null || placeholders === void 0 ? void 0 : placeholders.cvv) !== null && _c !== void 0 ? _c : 'CVV', disabled: disabled, onChange: (e) => { fieldState.current.cvv = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'cvv'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'cvv'); }, onReady:
|
|
2191
|
+
const cardNumberField = (jsxRuntime.jsxs("div", { children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.cardNumber), jsxRuntime.jsx(OzCardNumber, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.cardNumber), className: classNames === null || classNames === void 0 ? void 0 : classNames.cardNumber, placeholder: (_a = placeholders === null || placeholders === void 0 ? void 0 : placeholders.cardNumber) !== null && _a !== void 0 ? _a : 'Card number', disabled: disabled, onChange: (e) => { fieldState.current.cardNumber = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'cardNumber'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'cardNumber'); }, onReady: readyHandlers['cardNumber'] })] }));
|
|
2192
|
+
const expiryField = (jsxRuntime.jsxs("div", { style: layout === 'default' ? { flex: 1 } : undefined, children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.expiry), jsxRuntime.jsx(OzExpiry, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.expiry), className: classNames === null || classNames === void 0 ? void 0 : classNames.expiry, placeholder: (_b = placeholders === null || placeholders === void 0 ? void 0 : placeholders.expiry) !== null && _b !== void 0 ? _b : 'MM / YY', disabled: disabled, onChange: (e) => { fieldState.current.expiry = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'expiry'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'expiry'); }, onReady: readyHandlers['expiry'] })] }));
|
|
2193
|
+
const cvvField = (jsxRuntime.jsxs("div", { style: layout === 'default' ? { flex: 1 } : undefined, children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.cvv), jsxRuntime.jsx(OzCvv, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.cvv), className: classNames === null || classNames === void 0 ? void 0 : classNames.cvv, placeholder: (_c = placeholders === null || placeholders === void 0 ? void 0 : placeholders.cvv) !== null && _c !== void 0 ? _c : 'CVV', disabled: disabled, onChange: (e) => { fieldState.current.cvv = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'cvv'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'cvv'); }, onReady: readyHandlers['cvv'] })] }));
|
|
2149
2194
|
if (layout === 'rows') {
|
|
2150
2195
|
return (jsxRuntime.jsxs("div", { className: className, style: { width: '100%', display: 'flex', flexDirection: 'column', gap: gapStr }, children: [cardNumberField, expiryField, cvvField, errorNode] }));
|
|
2151
2196
|
}
|
|
@@ -2166,49 +2211,21 @@ const OzBankRoutingNumber = (props) => jsxRuntime.jsx(OzFieldBase, Object.assign
|
|
|
2166
2211
|
function OzBankCard({ style, styles, classNames, labels, labelStyle, labelClassName, gap = 8, hideErrors = false, errorStyle, errorClassName, renderError, onChange, onReady, onFocus, onBlur, disabled, className, placeholders, }) {
|
|
2167
2212
|
var _a, _b;
|
|
2168
2213
|
const { vault } = react.useContext(OzContext);
|
|
2214
|
+
const { onChangeRef, onFocusRef, onBlurRef, readyHandlers, error, setError, gapStr, renderLabel, } = useCardBase({
|
|
2215
|
+
vault,
|
|
2216
|
+
fieldNames: ['accountNumber', 'routingNumber'],
|
|
2217
|
+
onChange,
|
|
2218
|
+
onReady,
|
|
2219
|
+
onFocus,
|
|
2220
|
+
onBlur,
|
|
2221
|
+
gap,
|
|
2222
|
+
labelStyle,
|
|
2223
|
+
labelClassName,
|
|
2224
|
+
});
|
|
2169
2225
|
const fieldState = react.useRef({
|
|
2170
2226
|
accountNumber: null,
|
|
2171
2227
|
routingNumber: null,
|
|
2172
2228
|
});
|
|
2173
|
-
const readyFieldTypes = react.useRef(new Set());
|
|
2174
|
-
const onReadyFiredRef = react.useRef(false);
|
|
2175
|
-
const vaultRef = react.useRef(vault);
|
|
2176
|
-
const onChangeRef = react.useRef(onChange);
|
|
2177
|
-
const onReadyRef = react.useRef(onReady);
|
|
2178
|
-
const onFocusRef = react.useRef(onFocus);
|
|
2179
|
-
const onBlurRef = react.useRef(onBlur);
|
|
2180
|
-
react.useEffect(() => { onChangeRef.current = onChange; }, [onChange]);
|
|
2181
|
-
react.useEffect(() => { onReadyRef.current = onReady; }, [onReady]);
|
|
2182
|
-
react.useEffect(() => { onFocusRef.current = onFocus; }, [onFocus]);
|
|
2183
|
-
react.useEffect(() => { onBlurRef.current = onBlur; }, [onBlur]);
|
|
2184
|
-
react.useEffect(() => {
|
|
2185
|
-
if (vault !== vaultRef.current) {
|
|
2186
|
-
vaultRef.current = vault;
|
|
2187
|
-
readyFieldTypes.current = new Set();
|
|
2188
|
-
onReadyFiredRef.current = false;
|
|
2189
|
-
}
|
|
2190
|
-
return () => {
|
|
2191
|
-
readyFieldTypes.current = new Set();
|
|
2192
|
-
onReadyFiredRef.current = false;
|
|
2193
|
-
};
|
|
2194
|
-
}, [vault]);
|
|
2195
|
-
const [error, setError] = react.useState();
|
|
2196
|
-
const handleAccountReady = react.useCallback(() => {
|
|
2197
|
-
var _a;
|
|
2198
|
-
readyFieldTypes.current.add('accountNumber');
|
|
2199
|
-
if (readyFieldTypes.current.size >= 2 && !onReadyFiredRef.current) {
|
|
2200
|
-
onReadyFiredRef.current = true;
|
|
2201
|
-
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
2202
|
-
}
|
|
2203
|
-
}, []);
|
|
2204
|
-
const handleRoutingReady = react.useCallback(() => {
|
|
2205
|
-
var _a;
|
|
2206
|
-
readyFieldTypes.current.add('routingNumber');
|
|
2207
|
-
if (readyFieldTypes.current.size >= 2 && !onReadyFiredRef.current) {
|
|
2208
|
-
onReadyFiredRef.current = true;
|
|
2209
|
-
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
2210
|
-
}
|
|
2211
|
-
}, []);
|
|
2212
2229
|
const emitChange = react.useCallback(() => {
|
|
2213
2230
|
var _a;
|
|
2214
2231
|
const { accountNumber, routingNumber } = fieldState.current;
|
|
@@ -2221,18 +2238,14 @@ function OzBankCard({ style, styles, classNames, labels, labelStyle, labelClassN
|
|
|
2221
2238
|
error: err,
|
|
2222
2239
|
fields: Object.assign({}, fieldState.current),
|
|
2223
2240
|
});
|
|
2224
|
-
}, []);
|
|
2225
|
-
const gapStr = typeof gap === 'string' ? gap : `${gap}px`;
|
|
2226
|
-
const resolvedLabelStyle = labelStyle
|
|
2227
|
-
? Object.assign(Object.assign({}, DEFAULT_LABEL_STYLE), labelStyle) : DEFAULT_LABEL_STYLE;
|
|
2228
|
-
const renderLabel = (text) => renderFieldLabel(text, labelClassName, resolvedLabelStyle);
|
|
2241
|
+
}, [setError, onChangeRef]);
|
|
2229
2242
|
const showError = !hideErrors && error;
|
|
2230
2243
|
const errorNode = showError
|
|
2231
2244
|
? renderError
|
|
2232
2245
|
? renderError(error)
|
|
2233
2246
|
: (jsxRuntime.jsx("div", { role: "alert", className: errorClassName, style: errorStyle ? Object.assign(Object.assign({}, DEFAULT_ERROR_STYLE), errorStyle) : DEFAULT_ERROR_STYLE, children: error }))
|
|
2234
2247
|
: null;
|
|
2235
|
-
return (jsxRuntime.jsxs("div", { className: className, style: { width: '100%', display: 'flex', flexDirection: 'column', gap: gapStr }, children: [jsxRuntime.jsxs("div", { children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.accountNumber), jsxRuntime.jsx(OzBankAccountNumber, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.accountNumber), className: classNames === null || classNames === void 0 ? void 0 : classNames.accountNumber, placeholder: (_a = placeholders === null || placeholders === void 0 ? void 0 : placeholders.accountNumber) !== null && _a !== void 0 ? _a : 'Account number', disabled: disabled, onChange: (e) => { fieldState.current.accountNumber = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'accountNumber'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'accountNumber'); }, onReady:
|
|
2248
|
+
return (jsxRuntime.jsxs("div", { className: className, style: { width: '100%', display: 'flex', flexDirection: 'column', gap: gapStr }, children: [jsxRuntime.jsxs("div", { children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.accountNumber), jsxRuntime.jsx(OzBankAccountNumber, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.accountNumber), className: classNames === null || classNames === void 0 ? void 0 : classNames.accountNumber, placeholder: (_a = placeholders === null || placeholders === void 0 ? void 0 : placeholders.accountNumber) !== null && _a !== void 0 ? _a : 'Account number', disabled: disabled, onChange: (e) => { fieldState.current.accountNumber = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'accountNumber'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'accountNumber'); }, onReady: readyHandlers['accountNumber'] })] }), jsxRuntime.jsxs("div", { children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.routingNumber), jsxRuntime.jsx(OzBankRoutingNumber, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.routingNumber), className: classNames === null || classNames === void 0 ? void 0 : classNames.routingNumber, placeholder: (_b = placeholders === null || placeholders === void 0 ? void 0 : placeholders.routingNumber) !== null && _b !== void 0 ? _b : 'Routing number', disabled: disabled, onChange: (e) => { fieldState.current.routingNumber = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'routingNumber'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'routingNumber'); }, onReady: readyHandlers['routingNumber'] })] }), errorNode] }));
|
|
2236
2249
|
}
|
|
2237
2250
|
|
|
2238
2251
|
exports.OzBankAccountNumber = OzBankAccountNumber;
|