@tranzakpackage/cards-react 0.0.0-stage → 2.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.
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
- # Temporary Holding Version
1
+ # Tranzak Cards - React / Next.js
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A `<TranzakCard />` component for React and Next.js (App Router and Pages Router).
4
+
5
+ ```bash
6
+ npm install @tranzakpackage/cards-react
7
+ ```
8
+
9
+ Full documentation and API reference: https://docs.tranzak.co (Cards section).
10
+
11
+ Proprietary software of Lomotec LLC. All rights reserved.
package/package.json CHANGED
@@ -1,6 +1,25 @@
1
1
  {
2
2
  "name": "@tranzakpackage/cards-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.0",
4
+ "description": "Tranzak Cards for React and Next.js (App Router and Pages Router).",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "module": "src/index.js",
8
+ "types": "src/index.d.ts",
9
+ "sideEffects": false,
10
+ "peerDependencies": {
11
+ "react": ">=17"
12
+ },
13
+ "dependencies": {
14
+ "@tranzakpackage/cards-core": "2.0.0"
15
+ },
16
+ "license": "UNLICENSED",
17
+ "files": [
18
+ "src",
19
+ "README.md"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "homepage": "https://docs.tranzak.co"
25
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import type { ComponentType, CSSProperties } from 'react';
2
+ import type { FramedWidget, InlineWidget, PublicCardState } from '@tranzakpackage/cards-core';
3
+
4
+ export interface TranzakCardProps {
5
+ /** The `widget` object returned by your server. A new object (a new session) re-mounts the card. */
6
+ widget?: InlineWidget | FramedWidget;
7
+ /** Older format: the URL of a single iframe. */
8
+ url?: string;
9
+ onReady?: () => void;
10
+ onFrozen?: () => void;
11
+ onUnfrozen?: () => void;
12
+ onResize?: (e: { height: number }) => void;
13
+ onStateChange?: (state: PublicCardState) => void;
14
+ onError?: (e: { code: string }) => void;
15
+ className?: string;
16
+ style?: CSSProperties;
17
+ }
18
+
19
+ export const TranzakCard: ComponentType<TranzakCardProps>;
20
+ export default TranzakCard;
package/src/index.js ADDED
@@ -0,0 +1,41 @@
1
+ 'use client';
2
+
3
+ import { createElement, useEffect, useRef } from 'react';
4
+ import { mount } from '@tranzakpackage/cards-core';
5
+
6
+ /**
7
+ * <TranzakCard widget={widget} onFrozen={...} /> : la carte s'affiche dans cette zone de votre page.
8
+ *
9
+ * `widget` est l'objet renvoyé par VOTRE serveur (voir @tranzakpackage/cards-server). Fonctionne avec Next.js (App Router et Pages
10
+ * Router) : le composant est « client », il ne touche à `window` qu'après le montage, donc le rendu serveur est sûr.
11
+ * Les fonctions de rappel peuvent changer sans remonter le widget ; un nouvel objet `widget` (nouvelle session) le remonte.
12
+ */
13
+ export function TranzakCard({ widget, url, onReady, onFrozen, onUnfrozen, onResize, onStateChange, onError, className, style }) {
14
+ const ref = useRef(null);
15
+ const handlers = useRef({});
16
+ handlers.current = { onReady, onFrozen, onUnfrozen, onResize, onStateChange, onError };
17
+
18
+ const key = widget ? JSON.stringify(widget) : url || '';
19
+
20
+ useEffect(() => {
21
+ if (!ref.current || !key) return undefined;
22
+ const call = (name) => (e) => { const f = handlers.current[name]; if (f) f(e); };
23
+ const mounted = mount({
24
+ container: ref.current,
25
+ widget,
26
+ url,
27
+ onReady: call('onReady'),
28
+ onFrozen: call('onFrozen'),
29
+ onUnfrozen: call('onUnfrozen'),
30
+ onResize: call('onResize'),
31
+ onStateChange: call('onStateChange'),
32
+ onError: call('onError'),
33
+ });
34
+ return () => mounted.destroy();
35
+ // eslint-disable-next-line react-hooks/exhaustive-deps
36
+ }, [key]);
37
+
38
+ return createElement('div', { ref, className, style, 'data-tranzak-card': '' });
39
+ }
40
+
41
+ export default TranzakCard;