@netlib/widerrufsbutton 2.1.1 → 2.1.3

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.es.js CHANGED
@@ -1,11 +1,11 @@
1
- import { jsx as a, jsxs as c, Fragment as L } from "react/jsx-runtime";
2
- import { useState as w, useRef as q, useEffect as C } from "react";
3
- import { createPortal as F } from "react-dom";
4
- async function O(e, r) {
5
- const t = {
1
+ import { jsx as a, jsxs as c, Fragment as q } from "react/jsx-runtime";
2
+ import { useState as w, useRef as F, useEffect as C } from "react";
3
+ import { createPortal as O } from "react-dom";
4
+ async function L(e, r) {
5
+ const l = {
6
6
  "Content-Type": "application/json"
7
7
  };
8
- e.authToken && (t.Authorization = `Bearer ${e.authToken}`);
8
+ e.authToken && (l.Authorization = `Bearer ${e.authToken}`);
9
9
  const o = {
10
10
  action: e.action,
11
11
  payload: {
@@ -13,26 +13,26 @@ async function O(e, r) {
13
13
  ...e.companyName ? { companyName: e.companyName } : {},
14
14
  ...e.senderEmail ? { senderEmail: e.senderEmail } : {}
15
15
  }
16
- }, l = await fetch(e.apiUrl, {
16
+ }, n = await fetch(e.apiUrl, {
17
17
  method: "PATCH",
18
- headers: t,
18
+ headers: l,
19
19
  body: JSON.stringify(o)
20
20
  });
21
21
  let d;
22
22
  try {
23
- d = await l.json();
23
+ d = await n.json();
24
24
  } catch {
25
- if (!l.ok) throw new Error(`Server antwortete mit Status ${l.status}`);
25
+ if (!n.ok) throw new Error(`Server antwortete mit Status ${n.status}`);
26
26
  return;
27
27
  }
28
28
  if (d !== null && typeof d == "object" && "ok" in d && d.ok === !1) {
29
29
  const s = d.message;
30
- throw new Error(typeof s == "string" && s ? s : `Server antwortete mit Status ${l.status}`);
30
+ throw new Error(typeof s == "string" && s ? s : `Server antwortete mit Status ${n.status}`);
31
31
  }
32
- if (!l.ok)
33
- throw new Error(`Server antwortete mit Status ${l.status}`);
32
+ if (!n.ok)
33
+ throw new Error(`Server antwortete mit Status ${n.status}`);
34
34
  }
35
- const I = {
35
+ const U = {
36
36
  firstName: "",
37
37
  lastName: "",
38
38
  email: "",
@@ -44,41 +44,41 @@ function k(e) {
44
44
  const r = {};
45
45
  return e.firstName.trim() || (r.firstName = "Bitte geben Sie Ihren Vornamen an."), e.lastName.trim() || (r.lastName = "Bitte geben Sie Ihren Nachnamen an."), e.email.trim() ? /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.email) || (r.email = "Bitte geben Sie eine gültige E-Mail-Adresse an.") : r.email = "Bitte geben Sie Ihre E-Mail-Adresse an.", e.orderNumber.trim() || (r.orderNumber = "Bitte geben Sie die Bestellnummer oder Vertragsnummer an."), r;
46
46
  }
47
- function U({ config: e, onClose: r }) {
48
- const [t, o] = w(I), [l, d] = w({}), [s, S] = w({}), [h, N] = w("idle"), [E, z] = w(""), W = q(null);
47
+ function I({ config: e, onClose: r }) {
48
+ const [l, o] = w(U), [n, d] = w({}), [s, S] = w({}), [h, N] = w("idle"), [E, z] = w(""), W = F(null);
49
49
  C(() => {
50
50
  var u;
51
51
  (u = W.current) == null || u.focus();
52
- const n = (b) => b.key === "Escape" && r();
53
- return document.addEventListener("keydown", n), () => document.removeEventListener("keydown", n);
52
+ const t = (b) => b.key === "Escape" && r();
53
+ return document.addEventListener("keydown", t), () => document.removeEventListener("keydown", t);
54
54
  }, [r]);
55
- function m(n, u) {
56
- const b = { ...t, [n]: u };
57
- if (o(b), s[n]) {
58
- const g = k(b);
59
- d((x) => ({ ...x, [n]: g[n] }));
55
+ function m(t, u) {
56
+ const b = { ...l, [t]: u };
57
+ if (o(b), s[t]) {
58
+ const x = k(b);
59
+ d((g) => ({ ...g, [t]: x[t] }));
60
60
  }
61
61
  }
62
- function f(n) {
63
- S((b) => ({ ...b, [n]: !0 }));
64
- const u = k(t);
65
- d((b) => ({ ...b, [n]: u[n] }));
62
+ function f(t) {
63
+ S((b) => ({ ...b, [t]: !0 }));
64
+ const u = k(l);
65
+ d((b) => ({ ...b, [t]: u[t] }));
66
66
  }
67
- async function T(n) {
68
- var g, x;
69
- n.preventDefault();
67
+ async function T(t) {
68
+ var x, g;
69
+ t.preventDefault();
70
70
  const u = Object.fromEntries(
71
- Object.keys(t).map((v) => [v, !0])
71
+ Object.keys(l).map((v) => [v, !0])
72
72
  );
73
73
  S(u);
74
- const b = k(t);
74
+ const b = k(l);
75
75
  if (d(b), !(Object.keys(b).length > 0)) {
76
76
  N("loading"), z("");
77
77
  try {
78
- await O(e, t), N("success"), (g = e.onSuccess) == null || g.call(e);
78
+ await L(e, l), N("success"), (x = e.onSuccess) == null || x.call(e);
79
79
  } catch (v) {
80
80
  const B = v instanceof Error ? v : new Error("Ein unbekannter Fehler ist aufgetreten.");
81
- z(B.message), N("error"), (x = e.onError) == null || x.call(e, B);
81
+ z(B.message), N("error"), (g = e.onError) == null || g.call(e, B);
82
82
  }
83
83
  }
84
84
  }
@@ -90,7 +90,7 @@ function U({ config: e, onClose: r }) {
90
90
  role: "dialog",
91
91
  "aria-modal": "true",
92
92
  "aria-labelledby": "wrb-title",
93
- onClick: (n) => n.target === n.currentTarget && r(),
93
+ onClick: (t) => t.target === t.currentTarget && r(),
94
94
  children: /* @__PURE__ */ c("div", { className: "wrb-modal", children: [
95
95
  /* @__PURE__ */ c("div", { className: "wrb-modal-header", children: [
96
96
  /* @__PURE__ */ a("h2", { className: "wrb-modal-title", id: "wrb-title", children: j }),
@@ -111,11 +111,11 @@ function U({ config: e, onClose: r }) {
111
111
  /* @__PURE__ */ a("h3", { children: "Widerruf eingegangen" }),
112
112
  /* @__PURE__ */ c("p", { children: [
113
113
  "Ihr Widerruf wurde erfolgreich übermittelt. Sie erhalten in Kürze eine Bestätigung an ",
114
- /* @__PURE__ */ a("strong", { children: t.email }),
114
+ /* @__PURE__ */ a("strong", { children: l.email }),
115
115
  "."
116
116
  ] })
117
117
  ] }),
118
- /* @__PURE__ */ a(A, { links: e.legalLinks })
118
+ /* @__PURE__ */ a(A, { config: e })
119
119
  ] }) : /* @__PURE__ */ c("div", { className: "wrb-modal-body", children: [
120
120
  e.introText && /* @__PURE__ */ a("p", { className: "wrb-intro", children: e.introText }),
121
121
  h === "error" && E && /* @__PURE__ */ a("div", { className: "wrb-alert wrb-alert-error", role: "alert", children: E }),
@@ -125,16 +125,16 @@ function U({ config: e, onClose: r }) {
125
125
  {
126
126
  label: "Vorname",
127
127
  required: !0,
128
- error: s.firstName ? l.firstName : void 0,
128
+ error: s.firstName ? n.firstName : void 0,
129
129
  children: /* @__PURE__ */ a(
130
130
  "input",
131
131
  {
132
132
  ref: W,
133
- className: `wrb-input${s.firstName && l.firstName ? " wrb-error" : ""}`,
133
+ className: `wrb-input${s.firstName && n.firstName ? " wrb-error" : ""}`,
134
134
  type: "text",
135
135
  autoComplete: "given-name",
136
- value: t.firstName,
137
- onChange: (n) => m("firstName", n.target.value),
136
+ value: l.firstName,
137
+ onChange: (t) => m("firstName", t.target.value),
138
138
  onBlur: () => f("firstName"),
139
139
  placeholder: "Max"
140
140
  }
@@ -146,15 +146,15 @@ function U({ config: e, onClose: r }) {
146
146
  {
147
147
  label: "Nachname",
148
148
  required: !0,
149
- error: s.lastName ? l.lastName : void 0,
149
+ error: s.lastName ? n.lastName : void 0,
150
150
  children: /* @__PURE__ */ a(
151
151
  "input",
152
152
  {
153
- className: `wrb-input${s.lastName && l.lastName ? " wrb-error" : ""}`,
153
+ className: `wrb-input${s.lastName && n.lastName ? " wrb-error" : ""}`,
154
154
  type: "text",
155
155
  autoComplete: "family-name",
156
- value: t.lastName,
157
- onChange: (n) => m("lastName", n.target.value),
156
+ value: l.lastName,
157
+ onChange: (t) => m("lastName", t.target.value),
158
158
  onBlur: () => f("lastName"),
159
159
  placeholder: "Mustermann"
160
160
  }
@@ -167,15 +167,15 @@ function U({ config: e, onClose: r }) {
167
167
  label: "E-Mail-Adresse",
168
168
  required: !0,
169
169
  hint: "Hierüber erhalten Sie die Eingangsbestätigung.",
170
- error: s.email ? l.email : void 0,
170
+ error: s.email ? n.email : void 0,
171
171
  children: /* @__PURE__ */ a(
172
172
  "input",
173
173
  {
174
- className: `wrb-input${s.email && l.email ? " wrb-error" : ""}`,
174
+ className: `wrb-input${s.email && n.email ? " wrb-error" : ""}`,
175
175
  type: "email",
176
176
  autoComplete: "email",
177
- value: t.email,
178
- onChange: (n) => m("email", n.target.value),
177
+ value: l.email,
178
+ onChange: (t) => m("email", t.target.value),
179
179
  onBlur: () => f("email"),
180
180
  placeholder: "name@beispiel.de"
181
181
  }
@@ -188,14 +188,14 @@ function U({ config: e, onClose: r }) {
188
188
  label: "Bestell- / Auftrags- / Vertragsnummer",
189
189
  required: !0,
190
190
  hint: "Zu finden in Ihrer Bestellbestätigung.",
191
- error: s.orderNumber ? l.orderNumber : void 0,
191
+ error: s.orderNumber ? n.orderNumber : void 0,
192
192
  children: /* @__PURE__ */ a(
193
193
  "input",
194
194
  {
195
- className: `wrb-input${s.orderNumber && l.orderNumber ? " wrb-error" : ""}`,
195
+ className: `wrb-input${s.orderNumber && n.orderNumber ? " wrb-error" : ""}`,
196
196
  type: "text",
197
- value: t.orderNumber,
198
- onChange: (n) => m("orderNumber", n.target.value),
197
+ value: l.orderNumber,
198
+ onChange: (t) => m("orderNumber", t.target.value),
199
199
  onBlur: () => f("orderNumber"),
200
200
  placeholder: "z.B. 10045678"
201
201
  }
@@ -211,8 +211,8 @@ function U({ config: e, onClose: r }) {
211
211
  "textarea",
212
212
  {
213
213
  className: "wrb-textarea",
214
- value: t.reason,
215
- onChange: (n) => m("reason", n.target.value),
214
+ value: l.reason,
215
+ onChange: (t) => m("reason", t.target.value),
216
216
  placeholder: "Optional",
217
217
  rows: 2
218
218
  }
@@ -223,8 +223,8 @@ function U({ config: e, onClose: r }) {
223
223
  "textarea",
224
224
  {
225
225
  className: "wrb-textarea",
226
- value: t.userMessage,
227
- onChange: (n) => m("userMessage", n.target.value),
226
+ value: l.userMessage,
227
+ onChange: (t) => m("userMessage", t.target.value),
228
228
  placeholder: "Optional",
229
229
  rows: 3
230
230
  }
@@ -250,35 +250,34 @@ function U({ config: e, onClose: r }) {
250
250
  )
251
251
  ] })
252
252
  ] }),
253
- /* @__PURE__ */ a(A, { links: e.legalLinks })
253
+ /* @__PURE__ */ a(A, { config: e })
254
254
  ] })
255
255
  ] })
256
256
  }
257
257
  );
258
258
  }
259
- function p({ label: e, required: r, hint: t, error: o, children: l }) {
259
+ function p({ label: e, required: r, hint: l, error: o, children: n }) {
260
260
  return /* @__PURE__ */ c("div", { className: "wrb-field", children: [
261
261
  /* @__PURE__ */ c("label", { className: "wrb-label", children: [
262
262
  e,
263
263
  r && /* @__PURE__ */ a("span", { className: "wrb-required", "aria-hidden": "true", children: "*" })
264
264
  ] }),
265
- l,
266
- t && !o && /* @__PURE__ */ a("p", { className: "wrb-hint", children: t }),
265
+ n,
266
+ l && !o && /* @__PURE__ */ a("p", { className: "wrb-hint", children: l }),
267
267
  o && /* @__PURE__ */ a("p", { className: "wrb-field-error", role: "alert", children: o })
268
268
  ] });
269
269
  }
270
- function A({ links: e }) {
271
- return e != null && e.length ? /* @__PURE__ */ a("div", { className: "wrb-legal-links", children: e.map((r) => /* @__PURE__ */ a(
270
+ function A({ config: e }) {
271
+ return e.privacyUrl ? /* @__PURE__ */ a("div", { className: "wrb-legal-links", children: /* @__PURE__ */ a(
272
272
  "a",
273
273
  {
274
- href: r.href,
274
+ href: e.privacyUrl,
275
275
  className: "wrb-legal-link",
276
276
  target: "_blank",
277
277
  rel: "noopener noreferrer",
278
- children: r.name
279
- },
280
- r.href
281
- )) }) : null;
278
+ children: e.privacyLabel ?? "Datenschutz"
279
+ }
280
+ ) }) : null;
282
281
  }
283
282
  const $ = `
284
283
  /* Widerrufsbutton widget — prefix: wrb- */
@@ -510,28 +509,28 @@ const $ = `
510
509
  text-decoration: underline;
511
510
  }
512
511
  `;
513
- function V() {
512
+ function P() {
514
513
  const e = "wrb-styles";
515
514
  if (document.getElementById(e)) return;
516
515
  const r = document.createElement("style");
517
516
  r.id = e, r.textContent = $, document.head.appendChild(r);
518
517
  }
519
- function K({ config: e }) {
520
- const [r, t] = w(!1);
518
+ function R({ config: e }) {
519
+ const [r, l] = w(!1);
521
520
  return C(() => {
522
- V();
523
- }, []), /* @__PURE__ */ c(L, { children: [
521
+ P();
522
+ }, []), /* @__PURE__ */ c(q, { children: [
524
523
  /* @__PURE__ */ a(
525
524
  "button",
526
525
  {
527
526
  type: "button",
528
527
  className: `wrb-btn${e.buttonClass ? ` ${e.buttonClass}` : ""}`,
529
- onClick: () => t(!0),
528
+ onClick: () => l(!0),
530
529
  children: e.buttonLabel ?? "Vertrag widerrufen"
531
530
  }
532
531
  ),
533
- r && F(
534
- /* @__PURE__ */ a(U, { config: e, onClose: () => t(!1) }),
532
+ r && O(
533
+ /* @__PURE__ */ a(I, { config: e, onClose: () => l(!1) }),
535
534
  document.body
536
535
  )
537
536
  ] });
@@ -540,15 +539,15 @@ function i(e) {
540
539
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
541
540
  }
542
541
  function y(e) {
543
- var r;
544
- return (r = e.legalLinks) != null && r.length ? `
542
+ if (!e.privacyUrl) return "";
543
+ const r = i(e.privacyLabel ?? "Datenschutz");
544
+ return `
545
545
  <div class="wrb-legal-links">
546
- ${e.legalLinks.map((t) => `<a href="${i(t.href)}" class="wrb-legal-link" rel="noopener noreferrer">${i(t.name)}</a>`).join(`
547
- `)}
548
- </div>` : "";
546
+ <a href="${i(e.privacyUrl)}" class="wrb-legal-link" rel="noopener noreferrer">${r}</a>
547
+ </div>`;
549
548
  }
550
- function M(e, r = "", t = "") {
551
- const o = i(e.successUrl ?? r), l = i(e.errorUrl ?? t);
549
+ function M(e, r = "", l = "") {
550
+ const o = i(e.successUrl ?? r), n = i(e.errorUrl ?? l);
552
551
  return `
553
552
  <div class="wrb-field">
554
553
  <label class="wrb-label">
@@ -594,10 +593,10 @@ function M(e, r = "", t = "") {
594
593
  </div>
595
594
  <input type="hidden" name="action" value="${i(e.action)}">
596
595
  ${o ? `<input type="hidden" name="successUrl" value="${o}">` : ""}
597
- ${l ? `<input type="hidden" name="errorUrl" value="${l}">` : ""}`;
596
+ ${n ? `<input type="hidden" name="errorUrl" value="${n}">` : ""}`;
598
597
  }
599
- function Y(e) {
600
- const r = e.companyName ? `Widerruf – ${i(e.companyName)}` : "Widerrufsformular", t = i(e.formAction ?? e.apiUrl ?? "/rest/v1/apiCancellation");
598
+ function K(e) {
599
+ const r = e.companyName ? `Widerruf – ${i(e.companyName)}` : "Widerrufsformular", l = i(e.formAction ?? e.apiUrl ?? "/rest/v1/apiCancellation");
601
600
  return `<!DOCTYPE html>
602
601
  <html lang="de">
603
602
  <head>
@@ -627,7 +626,7 @@ function Y(e) {
627
626
  </div>
628
627
  <div class="wrb-modal-body">
629
628
  ${e.introText ? `<p class="wrb-intro">${i(e.introText)}</p>` : ""}
630
- <form method="POST" action="${t}" novalidate>
629
+ <form method="POST" action="${l}" novalidate>
631
630
  ${M(e)}
632
631
  <div class="wrb-actions">
633
632
  <button type="submit" class="wrb-submit-btn">
@@ -642,18 +641,18 @@ function Y(e) {
642
641
  </body>
643
642
  </html>`;
644
643
  }
645
- function _(e, { inlineStyles: r = !0 } = {}) {
646
- const t = e.companyName ? `Widerruf – ${i(e.companyName)}` : "Widerrufsformular", o = i(e.formAction ?? e.apiUrl ?? "/rest/v1/apiCancellation"), l = `
644
+ function Y(e, { inlineStyles: r = !0 } = {}) {
645
+ const l = e.companyName ? `Widerruf – ${i(e.companyName)}` : "Widerrufsformular", o = i(e.formAction ?? e.apiUrl ?? "/rest/v1/apiCancellation"), n = `
647
646
  #wrb-modal, #wrb-success, #wrb-error { display: none; }
648
647
  #wrb-modal:target, #wrb-success:target, #wrb-error:target { display: flex; }`;
649
- return `${r ? `<style>${l}
650
- ${$}</style>` : `<style>${l}</style>`}
648
+ return `${r ? `<style>${n}
649
+ ${$}</style>` : `<style>${n}</style>`}
651
650
 
652
651
  <!-- Widerruf: Form-Modal -->
653
652
  <div id="wrb-modal" class="wrb-overlay" role="dialog" aria-modal="true" aria-labelledby="wrb-modal-title">
654
653
  <div class="wrb-modal">
655
654
  <div class="wrb-modal-header">
656
- <h2 class="wrb-modal-title" id="wrb-modal-title">${t}</h2>
655
+ <h2 class="wrb-modal-title" id="wrb-modal-title">${l}</h2>
657
656
  <a href="#" class="wrb-close-btn" aria-label="Schließen">✕</a>
658
657
  </div>
659
658
  <div class="wrb-modal-body">
@@ -715,8 +714,8 @@ ${$}</style>` : `<style>${l}</style>`}
715
714
  </div>`;
716
715
  }
717
716
  export {
718
- U as WiderrufsModal,
719
- K as WiderrufsWidget,
720
- Y as generateFallbackHtml,
721
- _ as generateModalHtml
717
+ I as WiderrufsModal,
718
+ R as WiderrufsWidget,
719
+ K as generateFallbackHtml,
720
+ Y as generateModalHtml
722
721
  };
package/dist/types.d.ts CHANGED
@@ -1,7 +1,3 @@
1
- export interface LegalLink {
2
- name: string;
3
- href: string;
4
- }
5
1
  export interface WiderrufsConfig {
6
2
  /** PATCH endpoint, e.g. /rest/v1/systemLog */
7
3
  apiUrl: string;
@@ -23,8 +19,10 @@ export interface WiderrufsConfig {
23
19
  cancelLabel?: string;
24
20
  /** Label for the submit button (default: "Absenden") */
25
21
  submitLabel?: string;
26
- /** Legal navigation links shown in modal footer and static fallback page */
27
- legalLinks?: LegalLink[];
22
+ /** Label for the privacy policy link shown in the modal footer */
23
+ privacyLabel?: string;
24
+ /** URL for the privacy policy link shown in the modal footer */
25
+ privacyUrl?: string;
28
26
  /** POST action URL for the static HTML fallback form (defaults to apiUrl) */
29
27
  formAction?: string;
30
28
  /** Redirect URL after successful form submit (static fallback / no-JS modal) */