@code-collective/booking-widget 1.0.0

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.
Files changed (45) hide show
  1. package/README.md +266 -0
  2. package/dist/booking-widget.css +2 -0
  3. package/dist/booking-widget.js +4359 -0
  4. package/dist/booking-widget.umd.cjs +2 -0
  5. package/package.json +48 -0
  6. package/src/lib/AvailabilityCalendar.svelte +222 -0
  7. package/src/lib/CartBar.svelte +32 -0
  8. package/src/lib/CartBarView.svelte +60 -0
  9. package/src/lib/CartOverview.svelte +20 -0
  10. package/src/lib/CartOverviewButton.svelte +120 -0
  11. package/src/lib/Checkout.svelte +55 -0
  12. package/src/lib/CheckoutModal.svelte +510 -0
  13. package/src/lib/ConsentSection.svelte +45 -0
  14. package/src/lib/ContactForm.svelte +67 -0
  15. package/src/lib/CountdownTimer.svelte +30 -0
  16. package/src/lib/EditBookingView.svelte +73 -0
  17. package/src/lib/OptionCard.svelte +41 -0
  18. package/src/lib/PaymentPage.svelte +155 -0
  19. package/src/lib/PickupPointPicker.svelte +76 -0
  20. package/src/lib/ResultView.svelte +84 -0
  21. package/src/lib/SelectableCard.svelte +71 -0
  22. package/src/lib/TicketConfigurator.svelte +78 -0
  23. package/src/lib/TimeSlotPicker.svelte +45 -0
  24. package/src/lib/UnitCounter.svelte +91 -0
  25. package/src/lib/WizardPage.svelte +561 -0
  26. package/src/lib/api.ts +204 -0
  27. package/src/lib/app.css +246 -0
  28. package/src/lib/cart-manager.ts +76 -0
  29. package/src/lib/client-types.ts +52 -0
  30. package/src/lib/config.ts +92 -0
  31. package/src/lib/currency.ts +18 -0
  32. package/src/lib/elements/bw-cart.svelte +44 -0
  33. package/src/lib/elements/bw-checkout.svelte +99 -0
  34. package/src/lib/elements/bw-configurator.svelte +66 -0
  35. package/src/lib/elements/env.ts +11 -0
  36. package/src/lib/elements/register.ts +149 -0
  37. package/src/lib/elements/shared.ts +14 -0
  38. package/src/lib/elements/theme.css +193 -0
  39. package/src/lib/fake-api.ts +282 -0
  40. package/src/lib/generated-types.ts +828 -0
  41. package/src/lib/index.ts +189 -0
  42. package/src/lib/messages.ts +3 -0
  43. package/src/lib/mock-data.ts +241 -0
  44. package/src/lib/session-manager.ts +75 -0
  45. package/src/lib/utils.ts +25 -0
@@ -0,0 +1,78 @@
1
+ <script lang="ts">
2
+ import type { BookingApi } from './api';
3
+ import type { WizardPages } from './config';
4
+ import type { CartItem, CheckoutProductDto } from './client-types';
5
+ import { CartManager } from './cart-manager';
6
+ import { postMessage } from './messages';
7
+ import { expandUnitItems } from './utils';
8
+ import { formatCurrency } from './currency';
9
+ import WizardPage from './WizardPage.svelte';
10
+
11
+ interface Props {
12
+ api: BookingApi;
13
+ cartManager: CartManager;
14
+ productId: string;
15
+ wizardPages: WizardPages;
16
+ autoSelectSingleTimeSlot?: boolean;
17
+ onCancel?: () => void;
18
+ }
19
+ let { api, cartManager, productId, wizardPages, autoSelectSingleTimeSlot = false, onCancel }: Props = $props();
20
+
21
+ let product = $state<CheckoutProductDto | null>(null);
22
+ let isLoading = $state(true);
23
+ let isAddingToCart = $state(false);
24
+
25
+ async function load() {
26
+ product = await api.getProduct(productId);
27
+ isLoading = false;
28
+ }
29
+
30
+ load();
31
+
32
+ async function onAddToCart(item: CartItem) {
33
+ isAddingToCart = true;
34
+
35
+ try {
36
+ await cartManager.ensureCart();
37
+
38
+ const unitItems = expandUnitItems(item.units);
39
+ const added = await api.addCartItem({
40
+ productId: item.productId,
41
+ optionId: item.optionId,
42
+ unitItems,
43
+ availabilityId: item.availabilityId,
44
+ localDate: item.localDate,
45
+ pickupPointId: item.pickupPointId,
46
+ amount: item.totalPrice,
47
+ currencyCode: item.currency,
48
+ currencyPrecision: item.currencyPrecision,
49
+ });
50
+
51
+ const total = formatCurrency(item.totalPrice, item.currency, item.currencyPrecision, 2);
52
+ postMessage({
53
+ type: 'cart:change',
54
+ itemCount: unitItems.length,
55
+ cartItemId: added.id,
56
+ totalFormatted: total,
57
+ openCheckout: true,
58
+ });
59
+ } finally {
60
+ isAddingToCart = false;
61
+ }
62
+ }
63
+ </script>
64
+
65
+ {#if isLoading || isAddingToCart}
66
+ <div class="loading-center" style="height:100vh">
67
+ <div class="spinner"></div>
68
+ </div>
69
+ {:else if product}
70
+ <WizardPage
71
+ {product}
72
+ {api}
73
+ {wizardPages}
74
+ {autoSelectSingleTimeSlot}
75
+ {onCancel}
76
+ onComplete={onAddToCart}
77
+ />
78
+ {/if}
@@ -0,0 +1,45 @@
1
+ <script lang="ts">
2
+ import type { CheckoutAvailabilityDto } from './client-types';
3
+ import { formatTime } from './utils';
4
+ import SelectableCard from './SelectableCard.svelte';
5
+
6
+ interface Props {
7
+ timeSlots: CheckoutAvailabilityDto[];
8
+ selectedTime: string | null;
9
+ loading: boolean;
10
+ onTimeSelected: (time: string) => void;
11
+ }
12
+ let { timeSlots, selectedTime, loading, onTimeSelected }: Props = $props();
13
+ </script>
14
+
15
+ {#if loading}
16
+ <div class="loading-center"><div class="spinner"></div></div>
17
+ {:else if timeSlots.length === 1 && timeSlots[0].allDay}
18
+ <p class="hint">All-day availability</p>
19
+ {:else if timeSlots.length > 0}
20
+ <div class="slots">
21
+ {#each timeSlots as slot}
22
+ {@const time = formatTime(slot.localDateTimeStart)}
23
+ <SelectableCard
24
+ selected={selectedTime === time}
25
+ onSelect={() => onTimeSelected(time)}
26
+ heading={time}
27
+ body={slot.vacancies != null ? `${slot.vacancies} left` : undefined}
28
+ />
29
+ {/each}
30
+ </div>
31
+ {/if}
32
+
33
+ <style>
34
+ .hint {
35
+ text-align: center;
36
+ padding: 12px;
37
+ color: var(--bw-color-text-secondary);
38
+ font-size: 14px;
39
+ }
40
+ .slots {
41
+ display: flex;
42
+ flex-direction: column;
43
+ gap: 10px;
44
+ }
45
+ </style>
@@ -0,0 +1,91 @@
1
+ <script lang="ts">
2
+ import type { CheckoutUnitDto } from './client-types';
3
+ import { formatCurrency } from './currency';
4
+
5
+ interface Props {
6
+ unit: CheckoutUnitDto;
7
+ quantity: number;
8
+ onChange: (qty: number) => void;
9
+ }
10
+ let { unit, quantity, onChange }: Props = $props();
11
+
12
+ let priceLabel = $derived(() => {
13
+ if (!unit.pricing || unit.pricing.length === 0) return '';
14
+ const p = unit.pricing[0];
15
+ return `from ${formatCurrency(p.retail, p.currency, p.currencyPrecision)}`;
16
+ });
17
+
18
+ function decrement() { if (quantity > 0) onChange(quantity - 1); }
19
+
20
+ function increment() {
21
+ onChange(quantity + 1);
22
+ }
23
+ </script>
24
+
25
+ <div class="card row">
26
+ <div class="info">
27
+ <span class="name">{unit.title ?? unit.id}</span>
28
+ {#if priceLabel()}
29
+ <span class="price">{priceLabel()}</span>
30
+ {/if}
31
+ </div>
32
+ <div class="stepper">
33
+ <button class="step-btn" onclick={decrement} disabled={quantity === 0} aria-label="Decrease">&minus;</button>
34
+ <span class="qty">{quantity}</span>
35
+ <button class="step-btn" onclick={increment} aria-label="Increase">+</button>
36
+ </div>
37
+ </div>
38
+
39
+ <style>
40
+ .row {
41
+ display: flex;
42
+ align-items: center;
43
+ }
44
+ .info {
45
+ flex: 1;
46
+ display: flex;
47
+ flex-direction: column;
48
+ gap: 2px;
49
+ }
50
+ .name {
51
+ font-size: 15px;
52
+ font-weight: 700;
53
+ }
54
+ .price {
55
+ font-size: 13px;
56
+ color: var(--bw-color-text-secondary);
57
+ }
58
+ .stepper {
59
+ display: flex;
60
+ align-items: center;
61
+ gap: 4px;
62
+ }
63
+ .step-btn {
64
+ width: 40px;
65
+ height: 40px;
66
+ border-radius: 50%;
67
+ background: transparent;
68
+ border: 1.5px solid var(--bw-color-border);
69
+ color: var(--bw-color-primary);
70
+ font-size: 20px;
71
+ display: flex;
72
+ align-items: center;
73
+ justify-content: center;
74
+ transition: background var(--bw-transition), color var(--bw-transition), border-color var(--bw-transition);
75
+ }
76
+ .step-btn:hover:not(:disabled) {
77
+ background: var(--bw-color-primary);
78
+ color: white;
79
+ }
80
+ .step-btn:disabled {
81
+ opacity: 0.3;
82
+ cursor: default;
83
+ }
84
+ .qty {
85
+ font-size: 17px;
86
+ font-weight: 700;
87
+ min-width: 32px;
88
+ text-align: center;
89
+ font-variant-numeric: tabular-nums;
90
+ }
91
+ </style>