@ozura/elements 1.3.1-next.70 → 1.3.1-next.72
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/react/index.cjs.js +38 -13
- package/dist/react/index.cjs.js.map +1 -1
- package/dist/react/index.esm.js +38 -13
- package/dist/react/index.esm.js.map +1 -1
- package/dist/react/react/index.d.ts +20 -0
- package/dist/react/vue/index.d.ts +20 -0
- package/dist/server/vue/index.d.ts +20 -0
- package/dist/types/vue/index.d.ts +20 -0
- package/dist/vue/index.cjs.js +36 -10
- package/dist/vue/index.cjs.js.map +1 -1
- package/dist/vue/index.esm.js +36 -10
- package/dist/vue/index.esm.js.map +1 -1
- package/dist/vue/vue/index.d.ts +20 -0
- package/package.json +1 -1
package/dist/react/index.cjs.js
CHANGED
|
@@ -2275,9 +2275,11 @@ const OzContext = react.createContext({
|
|
|
2275
2275
|
notifyUnmount: () => { },
|
|
2276
2276
|
notifyMount: () => { },
|
|
2277
2277
|
notifyTokenize: () => { },
|
|
2278
|
+
notifyChange: () => { },
|
|
2278
2279
|
mountedCount: 0,
|
|
2279
2280
|
readyCount: 0,
|
|
2280
2281
|
tokenizeCount: 0,
|
|
2282
|
+
changeTick: 0,
|
|
2281
2283
|
});
|
|
2282
2284
|
/**
|
|
2283
2285
|
* Creates and owns an OzVault instance for the lifetime of this component.
|
|
@@ -2290,6 +2292,7 @@ function OzElements({ sessionUrl, getSessionKey, fetchWaxKey, pubKey, frameBaseU
|
|
|
2290
2292
|
const [mountedCount, setMountedCount] = react.useState(0);
|
|
2291
2293
|
const [readyCount, setReadyCount] = react.useState(0);
|
|
2292
2294
|
const [tokenizeCount, setTokenizeCount] = react.useState(0);
|
|
2295
|
+
const [changeTick, setChangeTick] = react.useState(0);
|
|
2293
2296
|
const onLoadErrorRef = react.useRef(onLoadError);
|
|
2294
2297
|
onLoadErrorRef.current = onLoadError;
|
|
2295
2298
|
const onWaxRefreshRef = react.useRef(onSessionRefresh !== null && onSessionRefresh !== void 0 ? onSessionRefresh : onWaxRefresh);
|
|
@@ -2412,7 +2415,8 @@ function OzElements({ sessionUrl, getSessionKey, fetchWaxKey, pubKey, frameBaseU
|
|
|
2412
2415
|
setReadyCount(n => Math.max(0, n - 1));
|
|
2413
2416
|
}, []);
|
|
2414
2417
|
const notifyTokenize = react.useCallback(() => setTokenizeCount(n => n + 1), []);
|
|
2415
|
-
const
|
|
2418
|
+
const notifyChange = react.useCallback(() => setChangeTick(n => n + 1), []);
|
|
2419
|
+
const value = react.useMemo(() => ({ vault, initError, notifyMount, notifyReady, notifyUnmount, notifyTokenize, notifyChange, mountedCount, readyCount, tokenizeCount, changeTick }), [vault, initError, notifyMount, notifyReady, notifyUnmount, notifyTokenize, notifyChange, mountedCount, readyCount, tokenizeCount, changeTick]);
|
|
2416
2420
|
return jsxRuntime.jsx(OzContext.Provider, { value: value, children: children });
|
|
2417
2421
|
}
|
|
2418
2422
|
/**
|
|
@@ -2420,28 +2424,49 @@ function OzElements({ sessionUrl, getSessionKey, fetchWaxKey, pubKey, frameBaseU
|
|
|
2420
2424
|
* an `<OzElements>` provider tree.
|
|
2421
2425
|
*/
|
|
2422
2426
|
function useOzElements() {
|
|
2423
|
-
|
|
2427
|
+
var _a, _b;
|
|
2428
|
+
const { vault, initError, mountedCount, readyCount, notifyTokenize, notifyChange, tokenizeCount } = react.useContext(OzContext);
|
|
2424
2429
|
const createToken = react.useCallback(async (options) => {
|
|
2425
2430
|
if (!vault) {
|
|
2426
2431
|
return Promise.reject(new OzError('useOzElements must be called inside an <OzElements> provider.'));
|
|
2427
2432
|
}
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2433
|
+
// Start the call so vault._tokenizing flips synchronously, then notify so
|
|
2434
|
+
// `isTokenizing` re-renders as `true`. Notify again on settle so it returns
|
|
2435
|
+
// to `false`. (vault.isTokenizing is a plain getter — nothing else would
|
|
2436
|
+
// trigger a render while the call is in flight.)
|
|
2437
|
+
const promise = vault.createToken(options);
|
|
2438
|
+
notifyChange();
|
|
2439
|
+
try {
|
|
2440
|
+
const result = await promise;
|
|
2441
|
+
notifyTokenize();
|
|
2442
|
+
return result;
|
|
2443
|
+
}
|
|
2444
|
+
finally {
|
|
2445
|
+
notifyChange();
|
|
2446
|
+
}
|
|
2447
|
+
}, [vault, notifyTokenize, notifyChange]);
|
|
2432
2448
|
const createBankToken = react.useCallback(async (options) => {
|
|
2433
2449
|
if (!vault) {
|
|
2434
2450
|
return Promise.reject(new OzError('useOzElements must be called inside an <OzElements> provider.'));
|
|
2435
2451
|
}
|
|
2436
|
-
const
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2452
|
+
const promise = vault.createBankToken(options);
|
|
2453
|
+
notifyChange();
|
|
2454
|
+
try {
|
|
2455
|
+
const result = await promise;
|
|
2456
|
+
notifyTokenize();
|
|
2457
|
+
return result;
|
|
2458
|
+
}
|
|
2459
|
+
finally {
|
|
2460
|
+
notifyChange();
|
|
2461
|
+
}
|
|
2462
|
+
}, [vault, notifyTokenize, notifyChange]);
|
|
2440
2463
|
const reset = react.useCallback(() => {
|
|
2441
2464
|
vault === null || vault === void 0 ? void 0 : vault.reset();
|
|
2442
2465
|
}, [vault]);
|
|
2443
2466
|
const ready = vault !== null && vault.isReady && mountedCount > 0 && readyCount >= mountedCount;
|
|
2444
|
-
|
|
2467
|
+
const isComplete = (_a = vault === null || vault === void 0 ? void 0 : vault.isComplete) !== null && _a !== void 0 ? _a : false;
|
|
2468
|
+
const isTokenizing = (_b = vault === null || vault === void 0 ? void 0 : vault.isTokenizing) !== null && _b !== void 0 ? _b : false;
|
|
2469
|
+
return { createToken, createBankToken, reset, ready, initError, tokenizeCount, isComplete, isTokenizing };
|
|
2445
2470
|
}
|
|
2446
2471
|
const SKELETON_STYLE = {
|
|
2447
2472
|
height: 46,
|
|
@@ -2476,7 +2501,7 @@ function OzFieldBase({ type, variant, style, placeholder, disabled, loadTimeoutM
|
|
|
2476
2501
|
const elementRef = react.useRef(null);
|
|
2477
2502
|
const [loaded, setLoaded] = react.useState(false);
|
|
2478
2503
|
const [loadError, setLoadError] = react.useState(null);
|
|
2479
|
-
const { vault, notifyMount, notifyReady, notifyUnmount } = react.useContext(OzContext);
|
|
2504
|
+
const { vault, notifyMount, notifyReady, notifyUnmount, notifyChange } = react.useContext(OzContext);
|
|
2480
2505
|
const onChangeRef = react.useRef(onChange);
|
|
2481
2506
|
const onFocusRef = react.useRef(onFocus);
|
|
2482
2507
|
const onBlurRef = react.useRef(onBlur);
|
|
@@ -2508,7 +2533,7 @@ function OzFieldBase({ type, variant, style, placeholder, disabled, loadTimeoutM
|
|
|
2508
2533
|
notifyReady();
|
|
2509
2534
|
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
2510
2535
|
});
|
|
2511
|
-
element.on('change', (e) => { var _a;
|
|
2536
|
+
element.on('change', (e) => { var _a; (_a = onChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onChangeRef, e); notifyChange(); });
|
|
2512
2537
|
element.on('focus', () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef); });
|
|
2513
2538
|
element.on('blur', () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef); });
|
|
2514
2539
|
element.on('loaderror', (e) => {
|