@netlib/widerrufsbutton 2.1.1 → 2.1.4

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,6 +1,6 @@
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";
1
+ import { jsx as a, jsxs as c, Fragment as q } from "react/jsx-runtime";
2
+ import { useState as m, useRef as F, useEffect as C } from "react";
3
+ import { createPortal as L } from "react-dom";
4
4
  async function O(e, r) {
5
5
  const t = {
6
6
  "Content-Type": "application/json"
@@ -13,50 +13,49 @@ 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
+ }, i = await fetch(e.apiUrl, {
17
17
  method: "PATCH",
18
18
  headers: t,
19
19
  body: JSON.stringify(o)
20
20
  });
21
21
  let d;
22
22
  try {
23
- d = await l.json();
23
+ d = await i.json();
24
24
  } catch {
25
- if (!l.ok) throw new Error(`Server antwortete mit Status ${l.status}`);
25
+ if (!i.ok) throw new Error(`Server antwortete mit Status ${i.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 ${i.status}`);
31
31
  }
32
- if (!l.ok)
33
- throw new Error(`Server antwortete mit Status ${l.status}`);
32
+ if (!i.ok)
33
+ throw new Error(`Server antwortete mit Status ${i.status}`);
34
34
  }
35
- const I = {
35
+ const U = {
36
36
  firstName: "",
37
37
  lastName: "",
38
38
  email: "",
39
39
  orderNumber: "",
40
- reason: "",
41
- userMessage: ""
40
+ reason: ""
42
41
  };
43
42
  function k(e) {
44
43
  const r = {};
45
44
  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
45
  }
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);
46
+ function I({ config: e, onClose: r }) {
47
+ const [t, o] = m(U), [i, d] = m({}), [s, S] = m({}), [h, N] = m("idle"), [E, z] = m(""), W = F(null);
49
48
  C(() => {
50
49
  var u;
51
50
  (u = W.current) == null || u.focus();
52
51
  const n = (b) => b.key === "Escape" && r();
53
52
  return document.addEventListener("keydown", n), () => document.removeEventListener("keydown", n);
54
53
  }, [r]);
55
- function m(n, u) {
54
+ function p(n, u) {
56
55
  const b = { ...t, [n]: u };
57
56
  if (o(b), s[n]) {
58
- const g = k(b);
59
- d((x) => ({ ...x, [n]: g[n] }));
57
+ const x = k(b);
58
+ d((g) => ({ ...g, [n]: x[n] }));
60
59
  }
61
60
  }
62
61
  function f(n) {
@@ -64,8 +63,8 @@ function U({ config: e, onClose: r }) {
64
63
  const u = k(t);
65
64
  d((b) => ({ ...b, [n]: u[n] }));
66
65
  }
67
- async function T(n) {
68
- var g, x;
66
+ async function M(n) {
67
+ var x, g;
69
68
  n.preventDefault();
70
69
  const u = Object.fromEntries(
71
70
  Object.keys(t).map((v) => [v, !0])
@@ -75,10 +74,10 @@ function U({ config: e, onClose: r }) {
75
74
  if (d(b), !(Object.keys(b).length > 0)) {
76
75
  N("loading"), z("");
77
76
  try {
78
- await O(e, t), N("success"), (g = e.onSuccess) == null || g.call(e);
77
+ await O(e, t), N("success"), (x = e.onSuccess) == null || x.call(e);
79
78
  } catch (v) {
80
79
  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);
80
+ z(B.message), N("error"), (g = e.onError) == null || g.call(e, B);
82
81
  }
83
82
  }
84
83
  }
@@ -115,26 +114,26 @@ function U({ config: e, onClose: r }) {
115
114
  "."
116
115
  ] })
117
116
  ] }),
118
- /* @__PURE__ */ a(A, { links: e.legalLinks })
117
+ /* @__PURE__ */ a(A, { config: e })
119
118
  ] }) : /* @__PURE__ */ c("div", { className: "wrb-modal-body", children: [
120
119
  e.introText && /* @__PURE__ */ a("p", { className: "wrb-intro", children: e.introText }),
121
120
  h === "error" && E && /* @__PURE__ */ a("div", { className: "wrb-alert wrb-alert-error", role: "alert", children: E }),
122
- /* @__PURE__ */ c("form", { onSubmit: T, noValidate: !0, children: [
121
+ /* @__PURE__ */ c("form", { onSubmit: M, noValidate: !0, children: [
123
122
  /* @__PURE__ */ a(
124
- p,
123
+ w,
125
124
  {
126
125
  label: "Vorname",
127
126
  required: !0,
128
- error: s.firstName ? l.firstName : void 0,
127
+ error: s.firstName ? i.firstName : void 0,
129
128
  children: /* @__PURE__ */ a(
130
129
  "input",
131
130
  {
132
131
  ref: W,
133
- className: `wrb-input${s.firstName && l.firstName ? " wrb-error" : ""}`,
132
+ className: `wrb-input${s.firstName && i.firstName ? " wrb-error" : ""}`,
134
133
  type: "text",
135
134
  autoComplete: "given-name",
136
135
  value: t.firstName,
137
- onChange: (n) => m("firstName", n.target.value),
136
+ onChange: (n) => p("firstName", n.target.value),
138
137
  onBlur: () => f("firstName"),
139
138
  placeholder: "Max"
140
139
  }
@@ -142,19 +141,19 @@ function U({ config: e, onClose: r }) {
142
141
  }
143
142
  ),
144
143
  /* @__PURE__ */ a(
145
- p,
144
+ w,
146
145
  {
147
146
  label: "Nachname",
148
147
  required: !0,
149
- error: s.lastName ? l.lastName : void 0,
148
+ error: s.lastName ? i.lastName : void 0,
150
149
  children: /* @__PURE__ */ a(
151
150
  "input",
152
151
  {
153
- className: `wrb-input${s.lastName && l.lastName ? " wrb-error" : ""}`,
152
+ className: `wrb-input${s.lastName && i.lastName ? " wrb-error" : ""}`,
154
153
  type: "text",
155
154
  autoComplete: "family-name",
156
155
  value: t.lastName,
157
- onChange: (n) => m("lastName", n.target.value),
156
+ onChange: (n) => p("lastName", n.target.value),
158
157
  onBlur: () => f("lastName"),
159
158
  placeholder: "Mustermann"
160
159
  }
@@ -162,20 +161,20 @@ function U({ config: e, onClose: r }) {
162
161
  }
163
162
  ),
164
163
  /* @__PURE__ */ a(
165
- p,
164
+ w,
166
165
  {
167
166
  label: "E-Mail-Adresse",
168
167
  required: !0,
169
168
  hint: "Hierüber erhalten Sie die Eingangsbestätigung.",
170
- error: s.email ? l.email : void 0,
169
+ error: s.email ? i.email : void 0,
171
170
  children: /* @__PURE__ */ a(
172
171
  "input",
173
172
  {
174
- className: `wrb-input${s.email && l.email ? " wrb-error" : ""}`,
173
+ className: `wrb-input${s.email && i.email ? " wrb-error" : ""}`,
175
174
  type: "email",
176
175
  autoComplete: "email",
177
176
  value: t.email,
178
- onChange: (n) => m("email", n.target.value),
177
+ onChange: (n) => p("email", n.target.value),
179
178
  onBlur: () => f("email"),
180
179
  placeholder: "name@beispiel.de"
181
180
  }
@@ -183,19 +182,19 @@ function U({ config: e, onClose: r }) {
183
182
  }
184
183
  ),
185
184
  /* @__PURE__ */ a(
186
- p,
185
+ w,
187
186
  {
188
187
  label: "Bestell- / Auftrags- / Vertragsnummer",
189
188
  required: !0,
190
189
  hint: "Zu finden in Ihrer Bestellbestätigung.",
191
- error: s.orderNumber ? l.orderNumber : void 0,
190
+ error: s.orderNumber ? i.orderNumber : void 0,
192
191
  children: /* @__PURE__ */ a(
193
192
  "input",
194
193
  {
195
- className: `wrb-input${s.orderNumber && l.orderNumber ? " wrb-error" : ""}`,
194
+ className: `wrb-input${s.orderNumber && i.orderNumber ? " wrb-error" : ""}`,
196
195
  type: "text",
197
196
  value: t.orderNumber,
198
- onChange: (n) => m("orderNumber", n.target.value),
197
+ onChange: (n) => p("orderNumber", n.target.value),
199
198
  onBlur: () => f("orderNumber"),
200
199
  placeholder: "z.B. 10045678"
201
200
  }
@@ -203,7 +202,7 @@ function U({ config: e, onClose: r }) {
203
202
  }
204
203
  ),
205
204
  /* @__PURE__ */ a(
206
- p,
205
+ w,
207
206
  {
208
207
  label: "Widerrufsgrund",
209
208
  hint: "Freiwillige Angabe – ein Widerruf ist ohne Angabe von Gründen möglich.",
@@ -212,23 +211,13 @@ function U({ config: e, onClose: r }) {
212
211
  {
213
212
  className: "wrb-textarea",
214
213
  value: t.reason,
215
- onChange: (n) => m("reason", n.target.value),
214
+ onChange: (n) => p("reason", n.target.value),
216
215
  placeholder: "Optional",
217
216
  rows: 2
218
217
  }
219
218
  )
220
219
  }
221
220
  ),
222
- /* @__PURE__ */ a(p, { label: "Nachricht", children: /* @__PURE__ */ a(
223
- "textarea",
224
- {
225
- className: "wrb-textarea",
226
- value: t.userMessage,
227
- onChange: (n) => m("userMessage", n.target.value),
228
- placeholder: "Optional",
229
- rows: 3
230
- }
231
- ) }),
232
221
  /* @__PURE__ */ c("div", { className: "wrb-actions", children: [
233
222
  /* @__PURE__ */ a(
234
223
  "button",
@@ -250,35 +239,34 @@ function U({ config: e, onClose: r }) {
250
239
  )
251
240
  ] })
252
241
  ] }),
253
- /* @__PURE__ */ a(A, { links: e.legalLinks })
242
+ /* @__PURE__ */ a(A, { config: e })
254
243
  ] })
255
244
  ] })
256
245
  }
257
246
  );
258
247
  }
259
- function p({ label: e, required: r, hint: t, error: o, children: l }) {
248
+ function w({ label: e, required: r, hint: t, error: o, children: i }) {
260
249
  return /* @__PURE__ */ c("div", { className: "wrb-field", children: [
261
250
  /* @__PURE__ */ c("label", { className: "wrb-label", children: [
262
251
  e,
263
252
  r && /* @__PURE__ */ a("span", { className: "wrb-required", "aria-hidden": "true", children: "*" })
264
253
  ] }),
265
- l,
254
+ i,
266
255
  t && !o && /* @__PURE__ */ a("p", { className: "wrb-hint", children: t }),
267
256
  o && /* @__PURE__ */ a("p", { className: "wrb-field-error", role: "alert", children: o })
268
257
  ] });
269
258
  }
270
- function A({ links: e }) {
271
- return e != null && e.length ? /* @__PURE__ */ a("div", { className: "wrb-legal-links", children: e.map((r) => /* @__PURE__ */ a(
259
+ function A({ config: e }) {
260
+ return e.privacyUrl ? /* @__PURE__ */ a("div", { className: "wrb-legal-links", children: /* @__PURE__ */ a(
272
261
  "a",
273
262
  {
274
- href: r.href,
263
+ href: e.privacyUrl,
275
264
  className: "wrb-legal-link",
276
265
  target: "_blank",
277
266
  rel: "noopener noreferrer",
278
- children: r.name
279
- },
280
- r.href
281
- )) }) : null;
267
+ children: e.privacyLabel ?? "Datenschutz"
268
+ }
269
+ ) }) : null;
282
270
  }
283
271
  const $ = `
284
272
  /* Widerrufsbutton widget — prefix: wrb- */
@@ -510,17 +498,17 @@ const $ = `
510
498
  text-decoration: underline;
511
499
  }
512
500
  `;
513
- function V() {
501
+ function P() {
514
502
  const e = "wrb-styles";
515
503
  if (document.getElementById(e)) return;
516
504
  const r = document.createElement("style");
517
505
  r.id = e, r.textContent = $, document.head.appendChild(r);
518
506
  }
519
- function K({ config: e }) {
520
- const [r, t] = w(!1);
507
+ function R({ config: e }) {
508
+ const [r, t] = m(!1);
521
509
  return C(() => {
522
- V();
523
- }, []), /* @__PURE__ */ c(L, { children: [
510
+ P();
511
+ }, []), /* @__PURE__ */ c(q, { children: [
524
512
  /* @__PURE__ */ a(
525
513
  "button",
526
514
  {
@@ -530,25 +518,25 @@ function K({ config: e }) {
530
518
  children: e.buttonLabel ?? "Vertrag widerrufen"
531
519
  }
532
520
  ),
533
- r && F(
534
- /* @__PURE__ */ a(U, { config: e, onClose: () => t(!1) }),
521
+ r && L(
522
+ /* @__PURE__ */ a(I, { config: e, onClose: () => t(!1) }),
535
523
  document.body
536
524
  )
537
525
  ] });
538
526
  }
539
- function i(e) {
527
+ function l(e) {
540
528
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
541
529
  }
542
530
  function y(e) {
543
- var r;
544
- return (r = e.legalLinks) != null && r.length ? `
531
+ if (!e.privacyUrl) return "";
532
+ const r = l(e.privacyLabel ?? "Datenschutz");
533
+ return `
545
534
  <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>` : "";
535
+ <a href="${l(e.privacyUrl)}" class="wrb-legal-link" rel="noopener noreferrer">${r}</a>
536
+ </div>`;
549
537
  }
550
- function M(e, r = "", t = "") {
551
- const o = i(e.successUrl ?? r), l = i(e.errorUrl ?? t);
538
+ function T(e, r = "", t = "") {
539
+ const o = l(e.successUrl ?? r), i = l(e.errorUrl ?? t);
552
540
  return `
553
541
  <div class="wrb-field">
554
542
  <label class="wrb-label">
@@ -588,16 +576,12 @@ function M(e, r = "", t = "") {
588
576
  Freiwillige Angabe – ein Widerruf ist ohne Angabe von Gründen möglich.
589
577
  </p>
590
578
  </div>
591
- <div class="wrb-field">
592
- <label class="wrb-label">Nachricht</label>
593
- <textarea class="wrb-textarea" name="userMessage" placeholder="Optional" rows="3"></textarea>
594
- </div>
595
- <input type="hidden" name="action" value="${i(e.action)}">
579
+ <input type="hidden" name="action" value="${l(e.action)}">
596
580
  ${o ? `<input type="hidden" name="successUrl" value="${o}">` : ""}
597
- ${l ? `<input type="hidden" name="errorUrl" value="${l}">` : ""}`;
581
+ ${i ? `<input type="hidden" name="errorUrl" value="${i}">` : ""}`;
598
582
  }
599
- function Y(e) {
600
- const r = e.companyName ? `Widerruf – ${i(e.companyName)}` : "Widerrufsformular", t = i(e.formAction ?? e.apiUrl ?? "/rest/v1/apiCancellation");
583
+ function K(e) {
584
+ const r = e.companyName ? `Widerruf – ${l(e.companyName)}` : "Widerrufsformular", t = l(e.formAction ?? e.apiUrl ?? "/rest/v1/apiCancellation");
601
585
  return `<!DOCTYPE html>
602
586
  <html lang="de">
603
587
  <head>
@@ -626,12 +610,12 @@ function Y(e) {
626
610
  <h1 class="wrb-modal-title">${r}</h1>
627
611
  </div>
628
612
  <div class="wrb-modal-body">
629
- ${e.introText ? `<p class="wrb-intro">${i(e.introText)}</p>` : ""}
613
+ ${e.introText ? `<p class="wrb-intro">${l(e.introText)}</p>` : ""}
630
614
  <form method="POST" action="${t}" novalidate>
631
- ${M(e)}
615
+ ${T(e)}
632
616
  <div class="wrb-actions">
633
617
  <button type="submit" class="wrb-submit-btn">
634
- ${i(e.submitLabel ?? "Absenden")}
618
+ ${l(e.submitLabel ?? "Absenden")}
635
619
  </button>
636
620
  </div>
637
621
  </form>
@@ -642,12 +626,12 @@ function Y(e) {
642
626
  </body>
643
627
  </html>`;
644
628
  }
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 = `
629
+ function Y(e, { inlineStyles: r = !0 } = {}) {
630
+ const t = e.companyName ? `Widerruf – ${l(e.companyName)}` : "Widerrufsformular", o = l(e.formAction ?? e.apiUrl ?? "/rest/v1/apiCancellation"), i = `
647
631
  #wrb-modal, #wrb-success, #wrb-error { display: none; }
648
632
  #wrb-modal:target, #wrb-success:target, #wrb-error:target { display: flex; }`;
649
- return `${r ? `<style>${l}
650
- ${$}</style>` : `<style>${l}</style>`}
633
+ return `${r ? `<style>${i}
634
+ ${$}</style>` : `<style>${i}</style>`}
651
635
 
652
636
  <!-- Widerruf: Form-Modal -->
653
637
  <div id="wrb-modal" class="wrb-overlay" role="dialog" aria-modal="true" aria-labelledby="wrb-modal-title">
@@ -657,13 +641,13 @@ ${$}</style>` : `<style>${l}</style>`}
657
641
  <a href="#" class="wrb-close-btn" aria-label="Schließen">✕</a>
658
642
  </div>
659
643
  <div class="wrb-modal-body">
660
- ${e.introText ? `<p class="wrb-intro">${i(e.introText)}</p>` : ""}
644
+ ${e.introText ? `<p class="wrb-intro">${l(e.introText)}</p>` : ""}
661
645
  <form method="POST" action="${o}" novalidate>
662
- ${M(e, "#wrb-success", "#wrb-error")}
646
+ ${T(e, "#wrb-success", "#wrb-error")}
663
647
  <div class="wrb-actions">
664
- <a href="#" class="wrb-cancel-btn">${i(e.cancelLabel ?? "Abbrechen")}</a>
648
+ <a href="#" class="wrb-cancel-btn">${l(e.cancelLabel ?? "Abbrechen")}</a>
665
649
  <button type="submit" class="wrb-submit-btn">
666
- ${i(e.submitLabel ?? "Absenden")}
650
+ ${l(e.submitLabel ?? "Absenden")}
667
651
  </button>
668
652
  </div>
669
653
  </form>
@@ -715,8 +699,8 @@ ${$}</style>` : `<style>${l}</style>`}
715
699
  </div>`;
716
700
  }
717
701
  export {
718
- U as WiderrufsModal,
719
- K as WiderrufsWidget,
720
- Y as generateFallbackHtml,
721
- _ as generateModalHtml
702
+ I as WiderrufsModal,
703
+ R as WiderrufsWidget,
704
+ K as generateFallbackHtml,
705
+ Y as generateModalHtml
722
706
  };
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) */
@@ -42,6 +40,5 @@ export interface WiderrufsFormData {
42
40
  email: string;
43
41
  orderNumber: string;
44
42
  reason: string;
45
- userMessage: string;
46
43
  }
47
44
  export type SubmitStatus = 'idle' | 'loading' | 'success' | 'error';
@@ -296,10 +296,6 @@
296
296
  Freiwillige Angabe – ein Widerruf ist ohne Angabe von Gründen möglich.
297
297
  </p>
298
298
  </div>
299
- <div class="wrb-field">
300
- <label class="wrb-label">Nachricht</label>
301
- <textarea class="wrb-textarea" name="userMessage" placeholder="Optional" rows="3"></textarea>
302
- </div>
303
299
  <input type="hidden" name="action" value="widerruf_submit">
304
300
 
305
301