@fiscalisto/react 0.1.82 → 0.1.84
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 +103 -34
- 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,31 @@ 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
|
+
});
|
|
131
|
+
const closeButton = (_jsx("button", { ref: close, type: "button", "aria-label": "Cerrar", onClick: onClose, style: {
|
|
132
|
+
...(heading
|
|
133
|
+
? { flex: "none" }
|
|
134
|
+
: { position: "absolute", top: 10, right: 10, zIndex: 1 }),
|
|
135
|
+
width: 32,
|
|
136
|
+
height: 32,
|
|
137
|
+
border: 0,
|
|
138
|
+
borderRadius: 999,
|
|
139
|
+
background: dark ? "rgba(255,255,255,.1)" : "rgba(0,0,0,.06)",
|
|
140
|
+
color: dark ? "#e6efee" : "#333",
|
|
141
|
+
font: "20px/32px system-ui, sans-serif",
|
|
142
|
+
cursor: "pointer",
|
|
143
|
+
}, children: "\u00D7" }));
|
|
106
144
|
return (_jsx("div", { role: "dialog", "aria-modal": "true", "aria-label": title, onClick: (e) => {
|
|
107
145
|
if (e.target === e.currentTarget)
|
|
108
146
|
onClose();
|
|
@@ -111,40 +149,71 @@ export function FiscalistoDialog({ open, onClose, heading, title = "Facturación
|
|
|
111
149
|
inset: 0,
|
|
112
150
|
zIndex: 2147483000,
|
|
113
151
|
display: "flex",
|
|
114
|
-
alignItems: "
|
|
152
|
+
alignItems: box.full ? "stretch" : "center",
|
|
115
153
|
justifyContent: "center",
|
|
116
|
-
|
|
117
|
-
padding: "24px 12px",
|
|
154
|
+
padding: box.full ? 0 : 24,
|
|
118
155
|
background: "rgba(17,17,17,.45)",
|
|
119
156
|
}, children: _jsxs("div", { style: {
|
|
120
157
|
position: "relative",
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
maxWidth:
|
|
125
|
-
|
|
126
|
-
borderRadius: 16,
|
|
158
|
+
display: "flex",
|
|
159
|
+
flexDirection: "column",
|
|
160
|
+
width: box.full ? "100%" : box.width,
|
|
161
|
+
maxWidth: "100%",
|
|
162
|
+
height: box.full ? "100dvh" : undefined,
|
|
163
|
+
borderRadius: box.full ? 0 : 16,
|
|
127
164
|
overflow: "hidden",
|
|
128
|
-
background
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
font: "
|
|
142
|
-
cursor: "pointer",
|
|
143
|
-
}, children: "\u00D7" }), heading && (_jsx("div", { style: {
|
|
144
|
-
padding: "16px 48px 0 20px",
|
|
145
|
-
font: "600 16px system-ui, sans-serif",
|
|
165
|
+
// The portal page's own background, so a heading bar and the page read as one.
|
|
166
|
+
background: dark ? "#0d0d0f" : "#ffffff",
|
|
167
|
+
boxShadow: box.full ? "none" : "0 24px 60px rgba(0,0,0,.25)",
|
|
168
|
+
transition: "width .15s ease",
|
|
169
|
+
}, children: [heading ? (_jsxs("div", { style: {
|
|
170
|
+
flex: "none",
|
|
171
|
+
display: "flex",
|
|
172
|
+
alignItems: "center",
|
|
173
|
+
gap: 12,
|
|
174
|
+
height: 56,
|
|
175
|
+
// The title lines up with the page's content: 16 px on a phone, 20 in a box.
|
|
176
|
+
padding: box.full ? "0 12px 0 16px" : "0 12px 0 20px",
|
|
177
|
+
borderBottom: `1px solid ${dark ? "rgba(255,255,255,.075)" : "rgba(13,43,41,.09)"}`,
|
|
178
|
+
font: "600 16px/1.3 system-ui, sans-serif",
|
|
146
179
|
color: dark ? "#e6efee" : "#111",
|
|
147
|
-
}, children:
|
|
180
|
+
}, children: [_jsx("div", { style: {
|
|
181
|
+
flex: 1,
|
|
182
|
+
minWidth: 0,
|
|
183
|
+
overflow: "hidden",
|
|
184
|
+
textOverflow: "ellipsis",
|
|
185
|
+
whiteSpace: "nowrap",
|
|
186
|
+
}, children: heading }), closeButton] })) : (closeButton), _jsx(Frame, { title: title, ...embed, style: box.full ? { flex: 1, minHeight: 0 } : undefined, sized: { height: box.full ? "auto" : box.height, onSize } })] }) }));
|
|
187
|
+
}
|
|
188
|
+
/** The window's size while the dialog is open, kept current when it turns or resizes. */
|
|
189
|
+
function useScreen(open) {
|
|
190
|
+
const read = () => typeof window === "undefined"
|
|
191
|
+
? { width: 1280, height: 800 }
|
|
192
|
+
: { width: window.innerWidth, height: window.innerHeight };
|
|
193
|
+
const [screen, setScreen] = useState(read);
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
if (!open)
|
|
196
|
+
return;
|
|
197
|
+
const update = () => setScreen(read());
|
|
198
|
+
update();
|
|
199
|
+
window.addEventListener("resize", update);
|
|
200
|
+
return () => window.removeEventListener("resize", update);
|
|
201
|
+
}, [open]);
|
|
202
|
+
return screen;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The dialog's box for the screen (the same rules as fiscalisto.js). A phone, or a window too
|
|
206
|
+
* small for a box, gets the whole screen, the page scrolling inside with its button at the
|
|
207
|
+
* bottom. A computer gets a box as tall as the step (up to the window): 520 px wide, or up to
|
|
208
|
+
* 960 with the invoice beside the form when the window is wide enough and the page has it.
|
|
209
|
+
*/
|
|
210
|
+
export function dialogBox(screen, content = {}) {
|
|
211
|
+
if (screen.width < 640 || screen.height < 520)
|
|
212
|
+
return { full: true };
|
|
213
|
+
const side = content.wide !== false && screen.width >= 1024;
|
|
214
|
+
const room = screen.height - 48 - (content.heading ? 56 : 0);
|
|
215
|
+
const height = Math.min(room, side ? 760 : 820, Math.max(360, content.height ?? 640));
|
|
216
|
+
return { full: false, width: side ? Math.min(960, screen.width - 48) : 520, height };
|
|
148
217
|
}
|
|
149
218
|
/** `const { open, dialog } = useFiscalistoDialog()`: `open(url)` from a button, `{dialog}` in your tree. */
|
|
150
219
|
export function useFiscalistoDialog(options = {}) {
|
package/package.json
CHANGED