@fiscalisto/react 0.1.19 → 0.1.21
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/index.d.ts +25 -8
- package/dist/index.js +40 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type CSSProperties, type ReactNode } from "react";
|
|
2
2
|
/**
|
|
3
|
-
* @fiscalisto/react: Fiscalisto's hosted pages inside your React app.
|
|
4
|
-
* portal (`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* @fiscalisto/react: Fiscalisto's hosted pages inside your React app. Your business's
|
|
4
|
+
* autofactura portal (`portal_url` from GET /v1/issuers/{id}/self_invoicing, with the invoice
|
|
5
|
+
* filling in beside the form like a checkout), a ticket's (`ticket.url` from POST /v1/tickets) or
|
|
6
|
+
* a customer data request (`customer_data_request.url`), in a frame that grows with its content,
|
|
7
|
+
* or on top of your page. The same as fiscalisto.js (https://fiscalisto.com/js/fiscalisto.js),
|
|
8
|
+
* without a script tag.
|
|
7
9
|
*
|
|
8
10
|
* The buyer's fiscal data never reaches your page: when they finish, `onComplete` says so (with
|
|
9
11
|
* the stamped invoice's UUID for a ticket); read the rest with the API or your webhook.
|
|
@@ -14,9 +16,24 @@ export type FiscalistoCompletion = {
|
|
|
14
16
|
} | {
|
|
15
17
|
kind: "customer_data";
|
|
16
18
|
};
|
|
19
|
+
/** How the page looks inside yours (like Stripe Elements' `appearance`). */
|
|
20
|
+
export interface FiscalistoAppearance {
|
|
21
|
+
/** "auto" (the default) follows the buyer's device. */
|
|
22
|
+
theme?: "light" | "dark" | "auto";
|
|
23
|
+
/** The button and focus color, "#rrggbb". */
|
|
24
|
+
accent?: string;
|
|
25
|
+
/** Corner radius in pixels, 0 to 24. */
|
|
26
|
+
radius?: number;
|
|
27
|
+
}
|
|
17
28
|
export interface FiscalistoEmbedProps {
|
|
18
|
-
/** `ticket.url` or `customer_data_request.url`, as the API answered it. */
|
|
29
|
+
/** `portal_url`, `ticket.url` or `customer_data_request.url`, as the API answered it. */
|
|
19
30
|
url: string;
|
|
31
|
+
appearance?: FiscalistoAppearance;
|
|
32
|
+
/** false hides the live invoice beside the form. */
|
|
33
|
+
preview?: boolean;
|
|
34
|
+
/** The ticket's code and total: the portal finds it by itself. */
|
|
35
|
+
code?: string;
|
|
36
|
+
total?: number;
|
|
20
37
|
/** The invoice was stamped, or the data was sent. */
|
|
21
38
|
onComplete?: (e: FiscalistoCompletion) => void;
|
|
22
39
|
/** The page finished loading. */
|
|
@@ -28,10 +45,10 @@ export interface FiscalistoEmbedProps {
|
|
|
28
45
|
className?: string;
|
|
29
46
|
style?: CSSProperties;
|
|
30
47
|
}
|
|
31
|
-
/** The link with ?embed=1; only autofactura and data request links are shown. */
|
|
32
|
-
export declare function embedUrl(url: string): URL;
|
|
48
|
+
/** The link with ?embed=1 and its look; only autofactura and data request links are shown. */
|
|
49
|
+
export declare function embedUrl(url: string, options?: Pick<FiscalistoEmbedProps, "appearance" | "preview" | "code" | "total">): URL;
|
|
33
50
|
/** The page inside yours, as tall as its content. */
|
|
34
|
-
export declare function FiscalistoEmbed({ url, onComplete, onReady, initialHeight, title, className, style, }: FiscalistoEmbedProps): import("react").JSX.Element;
|
|
51
|
+
export declare function FiscalistoEmbed({ url, appearance, preview, code, total, onComplete, onReady, initialHeight, title, className, style, }: FiscalistoEmbedProps): import("react").JSX.Element;
|
|
35
52
|
export interface FiscalistoDialogProps extends Omit<FiscalistoEmbedProps, "className" | "style"> {
|
|
36
53
|
open: boolean;
|
|
37
54
|
/** The ×, Esc or a click outside. */
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,45 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useRef, useState, } from "react";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const hex = (value) => {
|
|
4
|
+
const h = (value ?? "").trim().replace(/^#/, "").toLowerCase();
|
|
5
|
+
if (/^[0-9a-f]{6}$/.test(h))
|
|
6
|
+
return h;
|
|
7
|
+
if (/^[0-9a-f]{3}$/.test(h))
|
|
8
|
+
return h
|
|
9
|
+
.split("")
|
|
10
|
+
.map((c) => c + c)
|
|
11
|
+
.join("");
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
14
|
+
/** The link with ?embed=1 and its look; only autofactura and data request links are shown. */
|
|
15
|
+
export function embedUrl(url, options = {}) {
|
|
5
16
|
const u = new URL(url);
|
|
6
17
|
if (u.protocol !== "https:" && u.hostname !== "localhost")
|
|
7
18
|
throw new Error("Fiscalisto: la liga debe ser https.");
|
|
8
19
|
if (!/^\/(autofactura|datos)\//.test(u.pathname))
|
|
9
20
|
throw new Error("Fiscalisto: solo se muestran ligas de autofactura o de datos fiscales.");
|
|
10
21
|
u.searchParams.set("embed", "1");
|
|
22
|
+
const a = options.appearance ?? {};
|
|
23
|
+
if (a.theme === "light" || a.theme === "dark")
|
|
24
|
+
u.searchParams.set("theme", a.theme);
|
|
25
|
+
const accent = hex(a.accent);
|
|
26
|
+
if (accent)
|
|
27
|
+
u.searchParams.set("accent", accent);
|
|
28
|
+
if (typeof a.radius === "number" && Number.isFinite(a.radius))
|
|
29
|
+
u.searchParams.set("radius", String(Math.min(24, Math.max(0, Math.round(a.radius)))));
|
|
30
|
+
if (options.preview === false)
|
|
31
|
+
u.searchParams.set("preview", "0");
|
|
32
|
+
if (options.code)
|
|
33
|
+
u.searchParams.set("c", options.code);
|
|
34
|
+
if (options.total)
|
|
35
|
+
u.searchParams.set("t", String(options.total));
|
|
11
36
|
return u;
|
|
12
37
|
}
|
|
13
38
|
/** The page inside yours, as tall as its content. */
|
|
14
|
-
export function FiscalistoEmbed({ url, onComplete, onReady, initialHeight = 560, title = "Facturación", className, style, }) {
|
|
39
|
+
export function FiscalistoEmbed({ url, appearance, preview, code, total, onComplete, onReady, initialHeight = 560, title = "Facturación", className, style, }) {
|
|
15
40
|
const ref = useRef(null);
|
|
16
41
|
const [height, setHeight] = useState(initialHeight);
|
|
17
|
-
const src = embedUrl(url);
|
|
42
|
+
const src = embedUrl(url, { appearance, preview, code, total });
|
|
18
43
|
const origin = src.origin;
|
|
19
44
|
// The latest callbacks, without listening again on every render.
|
|
20
45
|
const handlers = useRef({ onComplete, onReady });
|
|
@@ -74,6 +99,12 @@ export function FiscalistoDialog({ open, onClose, heading, title = "Facturación
|
|
|
74
99
|
}, [open, onClose]);
|
|
75
100
|
if (!open)
|
|
76
101
|
return null;
|
|
102
|
+
// With the live invoice, wide enough for it beside the form (folded on a phone).
|
|
103
|
+
const wide = embed.preview !== false && /\/autofactura\//.test(embed.url);
|
|
104
|
+
const dark = embed.appearance?.theme === "dark" ||
|
|
105
|
+
(embed.appearance?.theme !== "light" &&
|
|
106
|
+
typeof window !== "undefined" &&
|
|
107
|
+
!!window.matchMedia?.("(prefers-color-scheme: dark)").matches);
|
|
77
108
|
return (_jsx("div", { role: "dialog", "aria-modal": "true", "aria-label": title, onClick: (e) => {
|
|
78
109
|
if (e.target === e.currentTarget)
|
|
79
110
|
onClose();
|
|
@@ -90,11 +121,11 @@ export function FiscalistoDialog({ open, onClose, heading, title = "Facturación
|
|
|
90
121
|
}, children: _jsxs("div", { style: {
|
|
91
122
|
position: "relative",
|
|
92
123
|
width: "100%",
|
|
93
|
-
maxWidth: 480,
|
|
124
|
+
maxWidth: wide ? 960 : 480,
|
|
94
125
|
margin: "auto 0",
|
|
95
126
|
borderRadius: 16,
|
|
96
127
|
overflow: "hidden",
|
|
97
|
-
background: "#
|
|
128
|
+
background: dark ? "#071615" : "#fbfcfc",
|
|
98
129
|
boxShadow: "0 24px 60px rgba(0,0,0,.25)",
|
|
99
130
|
}, children: [_jsx("button", { ref: close, type: "button", "aria-label": "Cerrar", onClick: onClose, style: {
|
|
100
131
|
position: "absolute",
|
|
@@ -105,13 +136,14 @@ export function FiscalistoDialog({ open, onClose, heading, title = "Facturación
|
|
|
105
136
|
height: 32,
|
|
106
137
|
border: 0,
|
|
107
138
|
borderRadius: 999,
|
|
108
|
-
background: "rgba(0,0,0,.06)",
|
|
109
|
-
color: "#333",
|
|
139
|
+
background: dark ? "rgba(255,255,255,.1)" : "rgba(0,0,0,.06)",
|
|
140
|
+
color: dark ? "#e6efee" : "#333",
|
|
110
141
|
font: "20px/32px system-ui, sans-serif",
|
|
111
142
|
cursor: "pointer",
|
|
112
143
|
}, children: "\u00D7" }), heading && (_jsx("div", { style: {
|
|
113
144
|
padding: "16px 48px 0 20px",
|
|
114
145
|
font: "600 16px system-ui, sans-serif",
|
|
146
|
+
color: dark ? "#e6efee" : "#111",
|
|
115
147
|
}, children: heading })), _jsx(FiscalistoEmbed, { title: title, ...embed })] }) }));
|
|
116
148
|
}
|
|
117
149
|
/** `const { open, dialog } = useFiscalistoDialog()`: `open(url)` from a button, `{dialog}` in your tree. */
|
package/package.json
CHANGED