@fiscalisto/react 0.1.81 → 0.1.83
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 +2 -0
- package/dist/index.d.ts +25 -2
- package/dist/index.js +75 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,6 +48,8 @@ export function BotonFacturar({ url }: { url: string }) {
|
|
|
48
48
|
|
|
49
49
|
`FiscalistoDialog` hace lo mismo controlado con `open` y `onClose`.
|
|
50
50
|
|
|
51
|
+
La ventana se acomoda a la pantalla: en un teléfono ocupa toda la pantalla; en una computadora es una caja tan alta como el paso (nunca más que la ventana del navegador), con la factura junto al formulario si la pantalla es ancha. El botón principal se queda abajo, a la vista.
|
|
52
|
+
|
|
51
53
|
## Datos fiscales de un cliente
|
|
52
54
|
|
|
53
55
|
Con `customer_data_request.url` (POST /v1/customer_data_requests) el mismo componente muestra el
|
package/dist/index.d.ts
CHANGED
|
@@ -46,9 +46,12 @@ export interface FiscalistoEmbedProps {
|
|
|
46
46
|
style?: CSSProperties;
|
|
47
47
|
}
|
|
48
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">
|
|
49
|
+
export declare function embedUrl(url: string, options?: Pick<FiscalistoEmbedProps, "appearance" | "preview" | "code" | "total"> & {
|
|
50
|
+
/** Opened in FiscalistoDialog: the dialog sizes the frame and the page fills it. */
|
|
51
|
+
frame?: "dialog";
|
|
52
|
+
}): URL;
|
|
50
53
|
/** The page inside yours, as tall as its content. */
|
|
51
|
-
export declare function FiscalistoEmbed(
|
|
54
|
+
export declare function FiscalistoEmbed(props: FiscalistoEmbedProps): import("react").JSX.Element;
|
|
52
55
|
export interface FiscalistoDialogProps extends Omit<FiscalistoEmbedProps, "className" | "style"> {
|
|
53
56
|
open: boolean;
|
|
54
57
|
/** The ×, Esc or a click outside. */
|
|
@@ -61,6 +64,26 @@ export interface FiscalistoDialogProps extends Omit<FiscalistoEmbedProps, "class
|
|
|
61
64
|
* buyer finishes, so they can download their PDF and XML; close it from `onComplete` if you want.
|
|
62
65
|
*/
|
|
63
66
|
export declare function FiscalistoDialog({ open, onClose, heading, title, ...embed }: FiscalistoDialogProps): import("react").JSX.Element | null;
|
|
67
|
+
/**
|
|
68
|
+
* The dialog's box for the screen (the same rules as fiscalisto.js). A phone, or a window too
|
|
69
|
+
* small for a box, gets the whole screen, the page scrolling inside with its button at the
|
|
70
|
+
* bottom. A computer gets a box as tall as the step (up to the window): 520 px wide, or up to
|
|
71
|
+
* 960 with the invoice beside the form when the window is wide enough and the page has it.
|
|
72
|
+
*/
|
|
73
|
+
export declare function dialogBox(screen: {
|
|
74
|
+
width: number;
|
|
75
|
+
height: number;
|
|
76
|
+
}, content?: {
|
|
77
|
+
height?: number;
|
|
78
|
+
wide?: boolean;
|
|
79
|
+
heading?: boolean;
|
|
80
|
+
}): {
|
|
81
|
+
full: true;
|
|
82
|
+
} | {
|
|
83
|
+
full: false;
|
|
84
|
+
width: number;
|
|
85
|
+
height: number;
|
|
86
|
+
};
|
|
64
87
|
/** `const { open, dialog } = useFiscalistoDialog()`: `open(url)` from a button, `{dialog}` in your tree. */
|
|
65
88
|
export declare function useFiscalistoDialog(options?: Omit<FiscalistoDialogProps, "open" | "onClose" | "url"> & {
|
|
66
89
|
onClose?: () => void;
|
package/dist/index.js
CHANGED
|
@@ -33,17 +33,32 @@ export function embedUrl(url, options = {}) {
|
|
|
33
33
|
u.searchParams.set("c", options.code);
|
|
34
34
|
if (options.total)
|
|
35
35
|
u.searchParams.set("t", String(options.total));
|
|
36
|
+
if (options.frame === "dialog")
|
|
37
|
+
u.searchParams.set("frame", "dialog");
|
|
36
38
|
return u;
|
|
37
39
|
}
|
|
38
40
|
/** The page inside yours, as tall as its content. */
|
|
39
|
-
export function FiscalistoEmbed(
|
|
41
|
+
export function FiscalistoEmbed(props) {
|
|
42
|
+
return _jsx(Frame, { ...props });
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The frame. In FiscalistoDialog (`sized`) the dialog chooses its height and hears the content's
|
|
46
|
+
* own (`onSize`, with whether the invoice can sit beside the form); elsewhere it grows with it.
|
|
47
|
+
*/
|
|
48
|
+
function Frame({ url, appearance, preview, code, total, onComplete, onReady, initialHeight = 560, title = "Facturación", className, style, sized, }) {
|
|
40
49
|
const ref = useRef(null);
|
|
41
50
|
const [height, setHeight] = useState(initialHeight);
|
|
42
|
-
const src = embedUrl(url, {
|
|
51
|
+
const src = embedUrl(url, {
|
|
52
|
+
appearance,
|
|
53
|
+
preview,
|
|
54
|
+
code,
|
|
55
|
+
total,
|
|
56
|
+
frame: sized ? "dialog" : undefined,
|
|
57
|
+
});
|
|
43
58
|
const origin = src.origin;
|
|
44
59
|
// The latest callbacks, without listening again on every render.
|
|
45
|
-
const handlers = useRef({ onComplete, onReady });
|
|
46
|
-
handlers.current = { onComplete, onReady };
|
|
60
|
+
const handlers = useRef({ onComplete, onReady, onSize: sized?.onSize });
|
|
61
|
+
handlers.current = { onComplete, onReady, onSize: sized?.onSize };
|
|
47
62
|
useEffect(() => {
|
|
48
63
|
function onMessage(e) {
|
|
49
64
|
if (e.source !== ref.current?.contentWindow || e.origin !== origin)
|
|
@@ -53,8 +68,10 @@ export function FiscalistoEmbed({ url, appearance, preview, code, total, onCompl
|
|
|
53
68
|
return;
|
|
54
69
|
if (data.event === "ready")
|
|
55
70
|
handlers.current.onReady?.();
|
|
56
|
-
else if (data.event === "resize")
|
|
71
|
+
else if (data.event === "resize") {
|
|
57
72
|
setHeight(Math.max(200, data.height));
|
|
73
|
+
handlers.current.onSize?.(data.height, data.wide);
|
|
74
|
+
}
|
|
58
75
|
else if (data.event === "completed")
|
|
59
76
|
handlers.current.onComplete?.(data.kind === "ticket"
|
|
60
77
|
? { kind: "ticket", uuid: data.uuid ?? null }
|
|
@@ -68,7 +85,7 @@ export function FiscalistoEmbed({ url, appearance, preview, code, total, onCompl
|
|
|
68
85
|
width: "100%",
|
|
69
86
|
border: 0,
|
|
70
87
|
background: "transparent",
|
|
71
|
-
height,
|
|
88
|
+
height: sized ? sized.height : height,
|
|
72
89
|
transition: "height .15s ease",
|
|
73
90
|
...style,
|
|
74
91
|
} }));
|
|
@@ -79,6 +96,8 @@ export function FiscalistoEmbed({ url, appearance, preview, code, total, onCompl
|
|
|
79
96
|
*/
|
|
80
97
|
export function FiscalistoDialog({ open, onClose, heading, title = "Facturación", ...embed }) {
|
|
81
98
|
const close = useRef(null);
|
|
99
|
+
const screen = useScreen(open);
|
|
100
|
+
const [content, setContent] = useState(null);
|
|
82
101
|
useEffect(() => {
|
|
83
102
|
if (!open)
|
|
84
103
|
return;
|
|
@@ -97,12 +116,18 @@ export function FiscalistoDialog({ open, onClose, heading, title = "Facturación
|
|
|
97
116
|
previous?.focus?.();
|
|
98
117
|
};
|
|
99
118
|
}, [open, onClose]);
|
|
119
|
+
const onSize = useCallback((height, wide) => setContent({ height, wide }), []);
|
|
100
120
|
if (!open)
|
|
101
121
|
return null;
|
|
102
122
|
const dark = embed.appearance?.theme === "dark" ||
|
|
103
123
|
(embed.appearance?.theme !== "light" &&
|
|
104
124
|
typeof window !== "undefined" &&
|
|
105
125
|
!!window.matchMedia?.("(prefers-color-scheme: dark)").matches);
|
|
126
|
+
const box = dialogBox(screen, {
|
|
127
|
+
height: content?.height,
|
|
128
|
+
wide: embed.preview === false ? false : (content?.wide ?? true),
|
|
129
|
+
heading: !!heading,
|
|
130
|
+
});
|
|
106
131
|
return (_jsx("div", { role: "dialog", "aria-modal": "true", "aria-label": title, onClick: (e) => {
|
|
107
132
|
if (e.target === e.currentTarget)
|
|
108
133
|
onClose();
|
|
@@ -111,26 +136,26 @@ export function FiscalistoDialog({ open, onClose, heading, title = "Facturación
|
|
|
111
136
|
inset: 0,
|
|
112
137
|
zIndex: 2147483000,
|
|
113
138
|
display: "flex",
|
|
114
|
-
alignItems: "
|
|
139
|
+
alignItems: box.full ? "stretch" : "center",
|
|
115
140
|
justifyContent: "center",
|
|
116
|
-
|
|
117
|
-
padding: "24px 12px",
|
|
141
|
+
padding: box.full ? 0 : 24,
|
|
118
142
|
background: "rgba(17,17,17,.45)",
|
|
119
143
|
}, children: _jsxs("div", { style: {
|
|
120
144
|
position: "relative",
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
maxWidth:
|
|
125
|
-
|
|
126
|
-
borderRadius: 16,
|
|
145
|
+
display: "flex",
|
|
146
|
+
flexDirection: "column",
|
|
147
|
+
width: box.full ? "100%" : box.width,
|
|
148
|
+
maxWidth: "100%",
|
|
149
|
+
height: box.full ? "100dvh" : undefined,
|
|
150
|
+
borderRadius: box.full ? 0 : 16,
|
|
127
151
|
overflow: "hidden",
|
|
128
152
|
background: dark ? "#071615" : "#fbfcfc",
|
|
129
|
-
boxShadow: "0 24px 60px rgba(0,0,0,.25)",
|
|
153
|
+
boxShadow: box.full ? "none" : "0 24px 60px rgba(0,0,0,.25)",
|
|
154
|
+
transition: "width .15s ease",
|
|
130
155
|
}, children: [_jsx("button", { ref: close, type: "button", "aria-label": "Cerrar", onClick: onClose, style: {
|
|
131
156
|
position: "absolute",
|
|
132
|
-
top:
|
|
133
|
-
right:
|
|
157
|
+
top: 10,
|
|
158
|
+
right: 10,
|
|
134
159
|
zIndex: 1,
|
|
135
160
|
width: 32,
|
|
136
161
|
height: 32,
|
|
@@ -141,10 +166,41 @@ export function FiscalistoDialog({ open, onClose, heading, title = "Facturación
|
|
|
141
166
|
font: "20px/32px system-ui, sans-serif",
|
|
142
167
|
cursor: "pointer",
|
|
143
168
|
}, children: "\u00D7" }), heading && (_jsx("div", { style: {
|
|
169
|
+
flex: "none",
|
|
144
170
|
padding: "16px 48px 0 20px",
|
|
145
171
|
font: "600 16px system-ui, sans-serif",
|
|
146
172
|
color: dark ? "#e6efee" : "#111",
|
|
147
|
-
}, children: heading })), _jsx(
|
|
173
|
+
}, children: heading })), _jsx(Frame, { title: title, ...embed, style: box.full ? { flex: 1, minHeight: 0 } : undefined, sized: { height: box.full ? "auto" : box.height, onSize } })] }) }));
|
|
174
|
+
}
|
|
175
|
+
/** The window's size while the dialog is open, kept current when it turns or resizes. */
|
|
176
|
+
function useScreen(open) {
|
|
177
|
+
const read = () => typeof window === "undefined"
|
|
178
|
+
? { width: 1280, height: 800 }
|
|
179
|
+
: { width: window.innerWidth, height: window.innerHeight };
|
|
180
|
+
const [screen, setScreen] = useState(read);
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
if (!open)
|
|
183
|
+
return;
|
|
184
|
+
const update = () => setScreen(read());
|
|
185
|
+
update();
|
|
186
|
+
window.addEventListener("resize", update);
|
|
187
|
+
return () => window.removeEventListener("resize", update);
|
|
188
|
+
}, [open]);
|
|
189
|
+
return screen;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The dialog's box for the screen (the same rules as fiscalisto.js). A phone, or a window too
|
|
193
|
+
* small for a box, gets the whole screen, the page scrolling inside with its button at the
|
|
194
|
+
* bottom. A computer gets a box as tall as the step (up to the window): 520 px wide, or up to
|
|
195
|
+
* 960 with the invoice beside the form when the window is wide enough and the page has it.
|
|
196
|
+
*/
|
|
197
|
+
export function dialogBox(screen, content = {}) {
|
|
198
|
+
if (screen.width < 640 || screen.height < 520)
|
|
199
|
+
return { full: true };
|
|
200
|
+
const side = content.wide !== false && screen.width >= 1024;
|
|
201
|
+
const room = screen.height - 48 - (content.heading ? 40 : 0);
|
|
202
|
+
const height = Math.min(room, side ? 760 : 820, Math.max(360, content.height ?? 640));
|
|
203
|
+
return { full: false, width: side ? Math.min(960, screen.width - 48) : 520, height };
|
|
148
204
|
}
|
|
149
205
|
/** `const { open, dialog } = useFiscalistoDialog()`: `open(url)` from a button, `{dialog}` in your tree. */
|
|
150
206
|
export function useFiscalistoDialog(options = {}) {
|
package/package.json
CHANGED