@ozura/elements 1.3.1-next.77 → 1.3.1-next.78

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/README.md CHANGED
@@ -28,6 +28,7 @@ Card data is collected inside Ozura-hosted iframes so raw numbers never touch yo
28
28
  - [vault.createBankToken()](#vaultcreatebanktokenoptions)
29
29
  - [vault.reset()](#vaultreset)
30
30
  - [vault.destroy()](#vaultdestroy)
31
+ - [vault.getFieldStates()](#vaultgetfieldstates)
31
32
  - [vault.debugState()](#vaultdebugstate)
32
33
  - [OzElement events](#ozelement-events)
33
34
  - [React API](#react-api)
@@ -36,6 +37,7 @@ Card data is collected inside Ozura-hosted iframes so raw numbers never touch yo
36
37
  - [Individual field components](#individual-field-components)
37
38
  - [OzBankCard](#ozbankcard)
38
39
  - [useOzElements()](#useozelements)
40
+ - [useFieldStates()](#usefieldstates)
39
41
  - [Styling](#styling)
40
42
  - [Per-element styles](#per-element-styles)
41
43
  - [Global appearance](#global-appearance)
@@ -595,6 +597,29 @@ try {
595
597
 
596
598
  ---
597
599
 
600
+ ### vault.getFieldStates()
601
+
602
+ ```ts
603
+ vault.getFieldStates(): FieldStatesSnapshot
604
+ ```
605
+
606
+ Returns a snapshot of every created field's current state, keyed by element type. Each entry is `{ empty, complete, valid, error?, cardBrand? }`. Call it whenever you need the latest state — typically from an `OzElement` `change` listener — to gate the submit button, show per-field errors, or display the card brand, without wiring bookkeeping per field.
607
+
608
+ ```ts
609
+ cardNumber.on('change', () => {
610
+ const s = vault.getFieldStates();
611
+ // {
612
+ // cardNumber: { empty: false, complete: true, valid: true, cardBrand: 'visa' },
613
+ // cvv: { empty: false, complete: false, valid: false, error: 'Invalid CVV' },
614
+ // }
615
+ payBtn.disabled = !(s.cardNumber?.valid && s.expirationDate?.valid && s.cvv?.valid);
616
+ });
617
+ ```
618
+
619
+ Keys exist only for fields you have created (card and bank fields are combined), so access with `?.`. The result is a set of shallow copies — mutating it does not affect the vault. In React/Vue, prefer the reactive [`useFieldStates()`](#usefieldstates) instead of calling this on every change.
620
+
621
+ ---
622
+
598
623
  ### vault.debugState()
599
624
 
600
625
  ```ts
@@ -803,6 +828,33 @@ Must be called from inside an `<OzElements>` provider tree.
803
828
 
804
829
  ---
805
830
 
831
+ ### useFieldStates()
832
+
833
+ ```ts
834
+ const fields = useFieldStates();
835
+ ```
836
+
837
+ Reactive snapshot of every created field's state, keyed by element type — `{ empty, complete, valid, error?, cardBrand? }` per field. Recomputes on every field change. It is a **standalone hook** (not part of `useOzElements()`), so only the components that need per-field state re-render on input. Must be called inside an `<OzElements>` provider; returns `{}` otherwise.
838
+
839
+ ```tsx
840
+ import { useFieldStates } from '@ozura/elements/react';
841
+
842
+ function CardErrors() {
843
+ const fields = useFieldStates();
844
+ return (
845
+ <>
846
+ {fields.cardNumber?.error && <span className="err">{fields.cardNumber.error}</span>}
847
+ {fields.cvv?.error && <span className="err">{fields.cvv.error}</span>}
848
+ {fields.cardNumber?.cardBrand && <BrandIcon brand={fields.cardNumber.cardBrand} />}
849
+ </>
850
+ );
851
+ }
852
+ ```
853
+
854
+ Keys exist only for fields you have created (card and bank combined), so access with `?.`.
855
+
856
+ ---
857
+
806
858
  ## Vue API
807
859
 
808
860
  > 📖 Vue 3 integration using the Composition API. Requires `vue >= 3.3`. No `.vue` SFC files needed in your setup — components work with `<script setup>` or the Options API.
@@ -886,6 +938,28 @@ Must be called from inside an `<OzElements>` provider tree.
886
938
  | `tokenizeCount` | `Ref<number>` | Successful tokenizations in the current session. Resets on session refresh. |
887
939
  | `reset` | `() => void` | Clear all fields without destroying the vault. Call after a declined payment. |
888
940
 
941
+ ### useFieldStates()
942
+
943
+ ```ts
944
+ const fields = useFieldStates(); // ComputedRef<FieldStatesSnapshot>
945
+ ```
946
+
947
+ Reactive snapshot of every created field's state, keyed by element type — `{ empty, complete, valid, error?, cardBrand? }` per field. Returns a `ComputedRef` that recomputes on every field change. Must be called from inside an `<OzElements>` provider tree (throws otherwise).
948
+
949
+ ```vue
950
+ <script setup>
951
+ import { useFieldStates } from '@ozura/elements/vue';
952
+ const fields = useFieldStates();
953
+ </script>
954
+
955
+ <template>
956
+ <span v-if="fields.cvv?.error" class="err">{{ fields.cvv.error }}</span>
957
+ <BrandIcon v-if="fields.cardNumber?.cardBrand" :brand="fields.cardNumber.cardBrand" />
958
+ </template>
959
+ ```
960
+
961
+ Keys exist only for fields you have created (card and bank combined); access with `?.`.
962
+
889
963
  ### Field props and events
890
964
 
891
965
  All five field components share the same props and emits:
@@ -86,7 +86,7 @@ export interface ElementChangeEvent {
86
86
  complete: boolean;
87
87
  valid: boolean;
88
88
  /** Card brand — only present on cardNumber elements */
89
- cardBrand?: string;
89
+ cardBrand?: CardBrand;
90
90
  /** Parsed month (01-12) — only present on expirationDate elements */
91
91
  month?: string;
92
92
  /** Parsed 2-digit year — only present on expirationDate elements */
@@ -86,7 +86,7 @@ export interface ElementChangeEvent {
86
86
  complete: boolean;
87
87
  valid: boolean;
88
88
  /** Card brand — only present on cardNumber elements */
89
- cardBrand?: string;
89
+ cardBrand?: CardBrand;
90
90
  /** Parsed month (01-12) — only present on expirationDate elements */
91
91
  month?: string;
92
92
  /** Parsed 2-digit year — only present on expirationDate elements */
@@ -86,7 +86,7 @@ export interface ElementChangeEvent {
86
86
  complete: boolean;
87
87
  valid: boolean;
88
88
  /** Card brand — only present on cardNumber elements */
89
- cardBrand?: string;
89
+ cardBrand?: CardBrand;
90
90
  /** Parsed month (01-12) — only present on expirationDate elements */
91
91
  month?: string;
92
92
  /** Parsed 2-digit year — only present on expirationDate elements */
@@ -86,7 +86,7 @@ export interface ElementChangeEvent {
86
86
  complete: boolean;
87
87
  valid: boolean;
88
88
  /** Card brand — only present on cardNumber elements */
89
- cardBrand?: string;
89
+ cardBrand?: CardBrand;
90
90
  /** Parsed month (01-12) — only present on expirationDate elements */
91
91
  month?: string;
92
92
  /** Parsed 2-digit year — only present on expirationDate elements */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ozura/elements",
3
- "version": "1.3.1-next.77",
3
+ "version": "1.3.1-next.78",
4
4
  "description": "PCI-compliant card tokenization SDK for the Ozura Vault — collect card data in iframe-isolated fields and tokenize without PCI scope",
5
5
  "main": "dist/oz-elements.umd.js",
6
6
  "module": "dist/oz-elements.esm.js",