@lifestreamdynamics/booking-widget 0.1.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.
- package/LICENSE +21 -0
- package/README.md +122 -0
- package/dist/index.d.ts +44 -0
- package/dist/lsv-booking.js +784 -0
- package/dist/lsv-booking.umd.cjs +393 -0
- package/package.json +53 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
(function(m,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(m=typeof globalThis<"u"?globalThis:m||self,d(m.LsvBooking={}))})(this,(function(m){"use strict";var k=Object.defineProperty;var C=(m,d,h)=>d in m?k(m,d,{enumerable:!0,configurable:!0,writable:!0,value:h}):m[d]=h;var u=(m,d,h)=>C(m,typeof d!="symbol"?d+"":d,h);const d=`
|
|
2
|
+
:host {
|
|
3
|
+
display: block;
|
|
4
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
5
|
+
--lsv-primary-color: #06b6d4;
|
|
6
|
+
--lsv-border-radius: 0.5rem;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
:host([theme="light"]) {
|
|
10
|
+
--lsv-bg-color: #ffffff;
|
|
11
|
+
--lsv-text-color: #1e293b;
|
|
12
|
+
--lsv-surface-color: #f8fafc;
|
|
13
|
+
--lsv-border-color: #e2e8f0;
|
|
14
|
+
--lsv-muted-color: #64748b;
|
|
15
|
+
--lsv-input-bg: #ffffff;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
:host([theme="dark"]), :host {
|
|
19
|
+
--lsv-bg-color: #0f172a;
|
|
20
|
+
--lsv-text-color: #e2e8f0;
|
|
21
|
+
--lsv-surface-color: #1e293b;
|
|
22
|
+
--lsv-border-color: #334155;
|
|
23
|
+
--lsv-muted-color: #94a3b8;
|
|
24
|
+
--lsv-input-bg: #0f172a;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@media (prefers-color-scheme: light) {
|
|
28
|
+
:host([theme="auto"]) {
|
|
29
|
+
--lsv-bg-color: #ffffff;
|
|
30
|
+
--lsv-text-color: #1e293b;
|
|
31
|
+
--lsv-surface-color: #f8fafc;
|
|
32
|
+
--lsv-border-color: #e2e8f0;
|
|
33
|
+
--lsv-muted-color: #64748b;
|
|
34
|
+
--lsv-input-bg: #ffffff;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@media (prefers-color-scheme: dark) {
|
|
39
|
+
:host([theme="auto"]) {
|
|
40
|
+
--lsv-bg-color: #0f172a;
|
|
41
|
+
--lsv-text-color: #e2e8f0;
|
|
42
|
+
--lsv-surface-color: #1e293b;
|
|
43
|
+
--lsv-border-color: #334155;
|
|
44
|
+
--lsv-muted-color: #94a3b8;
|
|
45
|
+
--lsv-input-bg: #0f172a;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
* { box-sizing: border-box; }
|
|
50
|
+
|
|
51
|
+
.widget {
|
|
52
|
+
background: var(--lsv-bg-color);
|
|
53
|
+
color: var(--lsv-text-color);
|
|
54
|
+
border: 1px solid var(--lsv-border-color);
|
|
55
|
+
border-radius: var(--lsv-border-radius);
|
|
56
|
+
padding: 1.5rem;
|
|
57
|
+
max-width: 480px;
|
|
58
|
+
margin: 0 auto;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.widget-title {
|
|
62
|
+
font-size: 1.125rem;
|
|
63
|
+
font-weight: 600;
|
|
64
|
+
margin: 0 0 1rem;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.step-indicator {
|
|
68
|
+
display: flex;
|
|
69
|
+
gap: 0.5rem;
|
|
70
|
+
margin-bottom: 1.25rem;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.step-dot {
|
|
74
|
+
width: 8px;
|
|
75
|
+
height: 8px;
|
|
76
|
+
border-radius: 50%;
|
|
77
|
+
background: var(--lsv-border-color);
|
|
78
|
+
transition: background 0.2s;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.step-dot.active {
|
|
82
|
+
background: var(--lsv-primary-color);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.step-dot.done {
|
|
86
|
+
background: var(--lsv-primary-color);
|
|
87
|
+
opacity: 0.5;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* Loading */
|
|
91
|
+
.loading {
|
|
92
|
+
display: flex;
|
|
93
|
+
align-items: center;
|
|
94
|
+
justify-content: center;
|
|
95
|
+
gap: 0.5rem;
|
|
96
|
+
padding: 2rem 0;
|
|
97
|
+
color: var(--lsv-muted-color);
|
|
98
|
+
font-size: 0.875rem;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.spinner {
|
|
102
|
+
width: 20px;
|
|
103
|
+
height: 20px;
|
|
104
|
+
border: 2px solid var(--lsv-border-color);
|
|
105
|
+
border-top-color: var(--lsv-primary-color);
|
|
106
|
+
border-radius: 50%;
|
|
107
|
+
animation: spin 0.8s linear infinite;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@keyframes spin {
|
|
111
|
+
to { transform: rotate(360deg); }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* Error */
|
|
115
|
+
.error-box {
|
|
116
|
+
background: rgba(239, 68, 68, 0.1);
|
|
117
|
+
border: 1px solid rgba(239, 68, 68, 0.4);
|
|
118
|
+
border-radius: var(--lsv-border-radius);
|
|
119
|
+
padding: 0.875rem 1rem;
|
|
120
|
+
font-size: 0.875rem;
|
|
121
|
+
color: #f87171;
|
|
122
|
+
margin-bottom: 0.75rem;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.btn-retry {
|
|
126
|
+
display: inline-block;
|
|
127
|
+
margin-top: 0.75rem;
|
|
128
|
+
padding: 0.5rem 1rem;
|
|
129
|
+
background: var(--lsv-surface-color);
|
|
130
|
+
border: 1px solid var(--lsv-border-color);
|
|
131
|
+
border-radius: var(--lsv-border-radius);
|
|
132
|
+
color: var(--lsv-text-color);
|
|
133
|
+
font-size: 0.8125rem;
|
|
134
|
+
cursor: pointer;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.btn-retry:hover { opacity: 0.8; }
|
|
138
|
+
|
|
139
|
+
/* Slot cards */
|
|
140
|
+
.slot-list {
|
|
141
|
+
display: flex;
|
|
142
|
+
flex-direction: column;
|
|
143
|
+
gap: 0.625rem;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.slot-card {
|
|
147
|
+
background: var(--lsv-surface-color);
|
|
148
|
+
border: 1px solid var(--lsv-border-color);
|
|
149
|
+
border-radius: var(--lsv-border-radius);
|
|
150
|
+
padding: 0.875rem 1rem;
|
|
151
|
+
cursor: pointer;
|
|
152
|
+
transition: border-color 0.15s;
|
|
153
|
+
text-align: left;
|
|
154
|
+
width: 100%;
|
|
155
|
+
color: var(--lsv-text-color);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.slot-card:hover {
|
|
159
|
+
border-color: var(--lsv-primary-color);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.slot-card-title {
|
|
163
|
+
font-weight: 500;
|
|
164
|
+
font-size: 0.9375rem;
|
|
165
|
+
margin: 0 0 0.25rem;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.slot-card-meta {
|
|
169
|
+
font-size: 0.8125rem;
|
|
170
|
+
color: var(--lsv-muted-color);
|
|
171
|
+
margin: 0;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/* Date picker */
|
|
175
|
+
.date-grid {
|
|
176
|
+
display: grid;
|
|
177
|
+
grid-template-columns: repeat(7, 1fr);
|
|
178
|
+
gap: 0.25rem;
|
|
179
|
+
margin-bottom: 0.75rem;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.date-header {
|
|
183
|
+
font-size: 0.6875rem;
|
|
184
|
+
font-weight: 600;
|
|
185
|
+
text-align: center;
|
|
186
|
+
color: var(--lsv-muted-color);
|
|
187
|
+
padding: 0.25rem 0;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.date-cell {
|
|
191
|
+
aspect-ratio: 1;
|
|
192
|
+
display: flex;
|
|
193
|
+
align-items: center;
|
|
194
|
+
justify-content: center;
|
|
195
|
+
border-radius: calc(var(--lsv-border-radius) * 0.5);
|
|
196
|
+
font-size: 0.8125rem;
|
|
197
|
+
cursor: pointer;
|
|
198
|
+
border: 1px solid transparent;
|
|
199
|
+
background: transparent;
|
|
200
|
+
color: var(--lsv-text-color);
|
|
201
|
+
transition: background 0.15s, border-color 0.15s;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.date-cell:hover:not(.disabled) {
|
|
205
|
+
background: var(--lsv-surface-color);
|
|
206
|
+
border-color: var(--lsv-border-color);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.date-cell.selected {
|
|
210
|
+
background: var(--lsv-primary-color);
|
|
211
|
+
color: #0f172a;
|
|
212
|
+
font-weight: 600;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.date-cell.disabled {
|
|
216
|
+
opacity: 0.3;
|
|
217
|
+
cursor: not-allowed;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.date-cell.empty {
|
|
221
|
+
cursor: default;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/* Time slots */
|
|
225
|
+
.time-grid {
|
|
226
|
+
display: grid;
|
|
227
|
+
grid-template-columns: repeat(3, 1fr);
|
|
228
|
+
gap: 0.5rem;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.time-btn {
|
|
232
|
+
padding: 0.5rem 0.25rem;
|
|
233
|
+
border: 1px solid var(--lsv-border-color);
|
|
234
|
+
border-radius: var(--lsv-border-radius);
|
|
235
|
+
background: var(--lsv-surface-color);
|
|
236
|
+
color: var(--lsv-text-color);
|
|
237
|
+
font-size: 0.8125rem;
|
|
238
|
+
cursor: pointer;
|
|
239
|
+
transition: border-color 0.15s, background 0.15s;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
.time-btn:hover {
|
|
243
|
+
border-color: var(--lsv-primary-color);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.time-btn.selected {
|
|
247
|
+
background: var(--lsv-primary-color);
|
|
248
|
+
border-color: var(--lsv-primary-color);
|
|
249
|
+
color: #0f172a;
|
|
250
|
+
font-weight: 600;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/* Form */
|
|
254
|
+
.form-group {
|
|
255
|
+
margin-bottom: 0.875rem;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.form-label {
|
|
259
|
+
display: block;
|
|
260
|
+
font-size: 0.8125rem;
|
|
261
|
+
font-weight: 500;
|
|
262
|
+
margin-bottom: 0.375rem;
|
|
263
|
+
color: var(--lsv-text-color);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.form-input, .form-textarea {
|
|
267
|
+
width: 100%;
|
|
268
|
+
padding: 0.5rem 0.75rem;
|
|
269
|
+
background: var(--lsv-input-bg);
|
|
270
|
+
border: 1px solid var(--lsv-border-color);
|
|
271
|
+
border-radius: var(--lsv-border-radius);
|
|
272
|
+
color: var(--lsv-text-color);
|
|
273
|
+
font-size: 0.875rem;
|
|
274
|
+
font-family: inherit;
|
|
275
|
+
transition: border-color 0.15s;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.form-input:focus, .form-textarea:focus {
|
|
279
|
+
outline: none;
|
|
280
|
+
border-color: var(--lsv-primary-color);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.form-textarea {
|
|
284
|
+
resize: vertical;
|
|
285
|
+
min-height: 80px;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/* Buttons */
|
|
289
|
+
.btn-primary {
|
|
290
|
+
display: block;
|
|
291
|
+
width: 100%;
|
|
292
|
+
padding: 0.625rem 1rem;
|
|
293
|
+
background: var(--lsv-primary-color);
|
|
294
|
+
border: none;
|
|
295
|
+
border-radius: var(--lsv-border-radius);
|
|
296
|
+
color: #0f172a;
|
|
297
|
+
font-size: 0.9375rem;
|
|
298
|
+
font-weight: 600;
|
|
299
|
+
cursor: pointer;
|
|
300
|
+
transition: opacity 0.15s;
|
|
301
|
+
font-family: inherit;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.btn-primary:hover:not(:disabled) { opacity: 0.85; }
|
|
305
|
+
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
306
|
+
|
|
307
|
+
.btn-back {
|
|
308
|
+
display: inline-flex;
|
|
309
|
+
align-items: center;
|
|
310
|
+
gap: 0.25rem;
|
|
311
|
+
padding: 0.375rem 0;
|
|
312
|
+
background: transparent;
|
|
313
|
+
border: none;
|
|
314
|
+
color: var(--lsv-muted-color);
|
|
315
|
+
font-size: 0.8125rem;
|
|
316
|
+
cursor: pointer;
|
|
317
|
+
margin-bottom: 0.75rem;
|
|
318
|
+
font-family: inherit;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
.btn-back:hover { color: var(--lsv-text-color); }
|
|
322
|
+
|
|
323
|
+
/* Summary */
|
|
324
|
+
.booking-summary {
|
|
325
|
+
background: var(--lsv-surface-color);
|
|
326
|
+
border: 1px solid var(--lsv-border-color);
|
|
327
|
+
border-radius: var(--lsv-border-radius);
|
|
328
|
+
padding: 0.75rem 1rem;
|
|
329
|
+
margin-bottom: 1rem;
|
|
330
|
+
font-size: 0.8125rem;
|
|
331
|
+
color: var(--lsv-muted-color);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.booking-summary strong {
|
|
335
|
+
color: var(--lsv-text-color);
|
|
336
|
+
display: block;
|
|
337
|
+
font-size: 0.9375rem;
|
|
338
|
+
margin-bottom: 0.25rem;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/* Success */
|
|
342
|
+
.success-view {
|
|
343
|
+
text-align: center;
|
|
344
|
+
padding: 1.5rem 0;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
.success-icon {
|
|
348
|
+
width: 48px;
|
|
349
|
+
height: 48px;
|
|
350
|
+
border-radius: 50%;
|
|
351
|
+
background: rgba(6, 182, 212, 0.15);
|
|
352
|
+
display: flex;
|
|
353
|
+
align-items: center;
|
|
354
|
+
justify-content: center;
|
|
355
|
+
margin: 0 auto 1rem;
|
|
356
|
+
font-size: 1.5rem;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
.success-title {
|
|
360
|
+
font-size: 1.125rem;
|
|
361
|
+
font-weight: 600;
|
|
362
|
+
margin: 0 0 0.5rem;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
.success-msg {
|
|
366
|
+
font-size: 0.875rem;
|
|
367
|
+
color: var(--lsv-muted-color);
|
|
368
|
+
margin: 0;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
.section-title {
|
|
372
|
+
font-size: 0.875rem;
|
|
373
|
+
font-weight: 600;
|
|
374
|
+
color: var(--lsv-muted-color);
|
|
375
|
+
margin: 0 0 0.75rem;
|
|
376
|
+
text-transform: uppercase;
|
|
377
|
+
letter-spacing: 0.05em;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
.empty-msg {
|
|
381
|
+
padding: 1.5rem 0;
|
|
382
|
+
text-align: center;
|
|
383
|
+
color: var(--lsv-muted-color);
|
|
384
|
+
font-size: 0.875rem;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
.actions {
|
|
388
|
+
display: flex;
|
|
389
|
+
flex-direction: column;
|
|
390
|
+
gap: 0.5rem;
|
|
391
|
+
margin-top: 1rem;
|
|
392
|
+
}
|
|
393
|
+
`,h=["sun","mon","tue","wed","thu","fri","sat"],y=["Su","Mo","Tu","We","Th","Fr","Sa"];class f extends HTMLElement{constructor(){super();u(this,"root");u(this,"step","slots");u(this,"slots",[]);u(this,"selectedSlot",null);u(this,"selectedDate","");u(this,"selectedTime","");u(this,"availableTimes",[]);u(this,"isLoading",!1);u(this,"errorMsg","");this.root=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.loadSlots()}attributeChangedCallback(e,t,r){t!==r&&(e==="theme"?this.render():this.isConnected&&this.reset())}get apiUrl(){return(this.getAttribute("api-url")??"").replace(/\/$/,"")}get profileSlug(){return this.getAttribute("profile-slug")??""}get vaultSlug(){return this.getAttribute("vault-slug")??""}get baseApiPath(){return`${this.apiUrl}/api/v1/public/vaults/${this.profileSlug}/${this.vaultSlug}`}reset(){this.step="slots",this.slots=[],this.selectedSlot=null,this.selectedDate="",this.selectedTime="",this.availableTimes=[],this.isLoading=!1,this.errorMsg="",this.render(),this.loadSlots()}setLoading(e){this.isLoading=e,this.render()}setError(e){this.errorMsg=e,this.isLoading=!1,this.render()}async loadSlots(){this.setLoading(!0);try{const e=await fetch(`${this.baseApiPath}/booking-slots`);if(!e.ok)throw new Error(`HTTP ${e.status}`);const t=await e.json();this.slots=t.slots,this.errorMsg=""}catch{this.setError("Failed to load booking slots. Please try again.");return}this.isLoading=!1,this.render()}async loadTimes(e,t){this.setLoading(!0);try{const r=await fetch(`${this.baseApiPath}/booking-slots/${e}/availability?date=${t}`);if(!r.ok)throw new Error(`HTTP ${r.status}`);const o=await r.json();this.availableTimes=o.times,this.errorMsg=""}catch{this.setError("Failed to load available times. Please try again.");return}this.isLoading=!1,this.step="time",this.render()}async submitBooking(e,t,r,o){if(!this.selectedSlot||!this.selectedDate||!this.selectedTime)return;this.setLoading(!0);const s=new Date(`${this.selectedDate}T${this.selectedTime}`).toISOString(),a=this.selectedSlot.id,n={guestName:e,guestEmail:t,startAt:s};r&&(n.guestPhone=r),o&&(n.notes=o);try{const c=await fetch(`${this.baseApiPath}/booking-slots/${a}/book`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!c.ok){const l=await c.json().catch(()=>({}));throw new Error(l.error??l.message??`HTTP ${c.status}`)}const i=await c.json();this.isLoading=!1,this.step="success",this.render(),this.dispatchEvent(new CustomEvent("lsv-booking-submitted",{bubbles:!0,composed:!0,detail:{bookingId:"",startAt:i.startAt,endAt:"",slotTitle:this.selectedSlot.title}}))}catch(c){const i=c instanceof Error?c.message:"Booking failed. Please try again.";this.dispatchEvent(new CustomEvent("lsv-booking-error",{bubbles:!0,composed:!0,detail:{message:i,step:"form"}})),this.setError(i)}}getNextDates(){const e=[],t=new Date;t.setHours(0,0,0,0);for(let r=0;r<14;r++){const o=new Date(t);o.setDate(t.getDate()+r);const s=o.toISOString().split("T")[0],a=o.toLocaleDateString("en-US",{month:"short",day:"numeric"});e.push({date:s,label:a,dayOfWeek:o.getDay()})}return e}isDateAllowed(e){if(!this.selectedSlot)return!1;const t=h[e];return this.selectedSlot.daysOfWeek.includes(t)}formatTime(e){try{if(e.includes("T"))return new Date(e).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0});const[t,r]=e.split(":").map(Number),o=new Date;return o.setHours(t,r,0,0),o.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0})}catch{return e}}formatDate(e){try{return new Date(`${e}T12:00:00`).toLocaleDateString("en-US",{weekday:"short",month:"short",day:"numeric"})}catch{return e}}render(){const e=document.createElement("style");e.textContent=d;const t=document.createElement("div");if(t.className="widget",this.step==="success")t.appendChild(this.renderSuccess());else if(t.appendChild(this.renderStepIndicator()),this.isLoading)t.appendChild(this.renderLoading());else if(this.errorMsg)t.appendChild(this.renderError());else switch(this.step){case"slots":t.appendChild(this.renderSlots());break;case"date":t.appendChild(this.renderDate());break;case"time":t.appendChild(this.renderTime());break;case"form":t.appendChild(this.renderForm());break}this.root.replaceChildren(e,t),this.attachEvents()}renderStepIndicator(){const e=["slots","date","time","form"],t=e.indexOf(this.step),r=document.createElement("div");return r.className="step-indicator",e.forEach((o,s)=>{const a=document.createElement("div");a.className=`step-dot${s===t?" active":s<t?" done":""}`,r.appendChild(a)}),r}renderLoading(){const e=document.createElement("div");e.className="loading";const t=document.createElement("div");t.className="spinner";const r=document.createElement("span");return r.textContent="Loading…",e.appendChild(t),e.appendChild(r),e}renderError(){const e=document.createDocumentFragment(),t=document.createElement("div");t.className="error-box",t.textContent=this.errorMsg,e.appendChild(t);const r=document.createElement("button");r.className="btn-retry",r.dataset.action="retry",r.textContent="Try again",e.appendChild(r);const o=document.createElement("div");return o.appendChild(e),o}renderSlots(){const e=document.createDocumentFragment(),t=document.createElement("p");if(t.className="section-title",t.textContent="Choose a booking type",e.appendChild(t),this.slots.length===0){const o=document.createElement("p");o.className="empty-msg",o.textContent="No booking slots available.",e.appendChild(o)}else{const o=document.createElement("div");o.className="slot-list",this.slots.forEach(s=>{const a=document.createElement("button");a.className="slot-card",a.dataset.action="select-slot",a.dataset.slotId=s.id;const n=document.createElement("p");n.className="slot-card-title",n.textContent=s.title;const c=document.createElement("p");c.className="slot-card-meta";const i=this.formatDayList(s.daysOfWeek);if(c.textContent=`${s.durationMin} min · ${i} · ${s.startTime}–${s.endTime}`,a.appendChild(n),s.description){const l=document.createElement("p");l.className="slot-card-meta",l.style.marginTop="0.25rem",l.textContent=s.description,a.appendChild(l)}a.appendChild(c),o.appendChild(a)}),e.appendChild(o)}const r=document.createElement("div");return r.appendChild(e),r}formatDayList(e){if(e.length===7)return"Every day";if(e.length===5&&!e.includes("sat")&&!e.includes("sun"))return"Weekdays";if(e.length===2&&e.includes("sat")&&e.includes("sun"))return"Weekends";const t={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"};return e.map(r=>t[r]??r).join(", ")}renderDate(){var c;const e=document.createDocumentFragment(),t=document.createElement("button");t.className="btn-back",t.dataset.action="back-to-slots",t.textContent="← Back",e.appendChild(t);const r=document.createElement("p");r.className="section-title",r.textContent="Select a date",e.appendChild(r);const o=this.getNextDates(),s=document.createElement("div");s.className="date-grid",y.forEach(i=>{const l=document.createElement("div");l.className="date-header",l.textContent=i,s.appendChild(l)});const a=((c=o[0])==null?void 0:c.dayOfWeek)??0;for(let i=0;i<a;i++){const l=document.createElement("div");l.className="date-cell empty",s.appendChild(l)}o.forEach(({date:i,label:l,dayOfWeek:g})=>{const p=document.createElement("button"),b=this.isDateAllowed(g);p.className=`date-cell${b?"":" disabled"}${i===this.selectedDate?" selected":""}`,p.textContent=new Date(`${i}T12:00:00`).getDate().toString(),p.title=l,b?(p.dataset.action="select-date",p.dataset.date=i):p.disabled=!0,s.appendChild(p)}),e.appendChild(s);const n=document.createElement("div");return n.appendChild(e),n}renderTime(){const e=document.createDocumentFragment(),t=document.createElement("button");t.className="btn-back",t.dataset.action="back-to-date",t.textContent="← Back",e.appendChild(t);const r=document.createElement("p");if(r.className="section-title",r.textContent=`Available times · ${this.formatDate(this.selectedDate)}`,e.appendChild(r),this.availableTimes.length===0){const s=document.createElement("p");s.className="empty-msg",s.textContent="No times available on this date. Try another day.",e.appendChild(s)}else{const s=document.createElement("div");s.className="time-grid",this.availableTimes.forEach(a=>{const n=document.createElement("button");n.className=`time-btn${a===this.selectedTime?" selected":""}`,n.dataset.action="select-time",n.dataset.time=a,n.textContent=this.formatTime(a),s.appendChild(n)}),e.appendChild(s)}if(this.selectedTime){const s=document.createElement("div");s.className="actions";const a=document.createElement("button");a.className="btn-primary",a.dataset.action="go-to-form",a.textContent="Continue",s.appendChild(a),e.appendChild(s)}const o=document.createElement("div");return o.appendChild(e),o}renderForm(){var b,v;const e=document.createDocumentFragment(),t=document.createElement("button");t.className="btn-back",t.dataset.action="back-to-time",t.textContent="← Back",e.appendChild(t);const r=document.createElement("div");r.className="booking-summary";const o=document.createElement("strong");o.textContent=((b=this.selectedSlot)==null?void 0:b.title)??"",r.appendChild(o);const s=document.createElement("span");s.textContent=`${this.formatDate(this.selectedDate)} at ${this.formatTime(this.selectedTime)}`,r.appendChild(s),e.appendChild(r);const a=document.createElement("form");a.id="lsv-booking-form",a.appendChild(this.makeField("guestName","Full name","text",!0)),a.appendChild(this.makeField("guestEmail","Email address","email",!0)),(v=this.selectedSlot)!=null&&v.requirePhone&&a.appendChild(this.makeField("guestPhone","Phone number","tel",!0));const n=document.createElement("div");n.className="form-group";const c=document.createElement("label");c.className="form-label",c.setAttribute("for","lsv-notes"),c.textContent="Notes (optional)";const i=document.createElement("textarea");i.className="form-textarea",i.id="lsv-notes",i.name="notes",i.rows=3,i.placeholder="Anything you'd like to share…",n.appendChild(c),n.appendChild(i),a.appendChild(n);const l=document.createElement("div");l.className="actions";const g=document.createElement("button");g.type="submit",g.className="btn-primary",g.textContent="Confirm Booking",l.appendChild(g),a.appendChild(l),e.appendChild(a);const p=document.createElement("div");return p.appendChild(e),p}makeField(e,t,r,o){const s=document.createElement("div");s.className="form-group";const a=document.createElement("label");a.className="form-label",a.setAttribute("for",`lsv-${e}`),a.textContent=o?`${t} *`:t;const n=document.createElement("input");return n.className="form-input",n.type=r,n.id=`lsv-${e}`,n.name=e,n.required=o,n.autocomplete=e==="guestName"?"name":e==="guestEmail"?"email":e==="guestPhone"?"tel":"off",s.appendChild(a),s.appendChild(n),s}renderSuccess(){const e=document.createElement("div");e.className="success-view";const t=document.createElement("div");t.className="success-icon",t.textContent="✓";const r=document.createElement("p");r.className="success-title",r.textContent="Booking requested!";const o=document.createElement("p");return o.className="success-msg",o.textContent="Check your email to confirm your booking.",e.appendChild(t),e.appendChild(r),e.appendChild(o),e}attachEvents(){this.root.addEventListener("click",t=>{const o=t.target.closest("[data-action]");o&&this.handleAction(o.dataset.action??"",o)});const e=this.root.querySelector("#lsv-booking-form");e&&e.addEventListener("submit",t=>{t.preventDefault();const r=new FormData(e),o=(r.get("guestName")??"").trim(),s=(r.get("guestEmail")??"").trim(),a=(r.get("guestPhone")??"").trim(),n=(r.get("notes")??"").trim();!o||!s||this.submitBooking(o,s,a,n)})}handleAction(e,t){switch(e){case"retry":this.errorMsg="",this.step==="slots"?this.loadSlots():this.step==="time"&&this.selectedSlot?this.loadTimes(this.selectedSlot.id,this.selectedDate):this.render();break;case"select-slot":{const r=t.dataset.slotId,o=this.slots.find(s=>s.id===r);if(!o)return;this.selectedSlot=o,this.step="date",this.render();break}case"back-to-slots":this.selectedSlot=null,this.selectedDate="",this.selectedTime="",this.step="slots",this.render();break;case"select-date":{const r=t.dataset.date;if(!r||!this.selectedSlot)return;this.selectedDate=r,this.selectedTime="",this.loadTimes(this.selectedSlot.id,r);break}case"back-to-date":this.selectedTime="",this.step="date",this.render();break;case"select-time":{const r=t.dataset.time;if(!r)return;this.selectedTime=r,this.render();break}case"go-to-form":this.selectedTime&&(this.step="form",this.render());break;case"back-to-time":this.step="time",this.render();break}}}u(f,"observedAttributes",["api-url","profile-slug","vault-slug","theme"]),customElements.get("lsv-booking")||customElements.define("lsv-booking",f),m.LsvBooking=f,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lifestreamdynamics/booking-widget",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Embeddable booking widget Web Component for Lifestream Vault",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/lsv-booking.umd.cjs",
|
|
7
|
+
"module": "dist/lsv-booking.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/lsv-booking.js",
|
|
13
|
+
"require": "./dist/lsv-booking.umd.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": true,
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"keywords": [
|
|
22
|
+
"lifestream",
|
|
23
|
+
"vault",
|
|
24
|
+
"booking",
|
|
25
|
+
"widget",
|
|
26
|
+
"web-component",
|
|
27
|
+
"custom-element"
|
|
28
|
+
],
|
|
29
|
+
"author": "Lifestream Dynamics <eric@lifestreamdynamics.com>",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/lifestreamdynamics/lifestream-vault-booking-widget.git"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/lifestreamdynamics/lifestream-vault-booking-widget/issues"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/lifestreamdynamics/lifestream-vault-booking-widget#readme",
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "vite build",
|
|
41
|
+
"dev": "vite build --watch",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"test:watch": "vitest",
|
|
44
|
+
"prepublishOnly": "npm run build && npm test"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"jsdom": "^28.1.0",
|
|
48
|
+
"typescript": "^5.7.3",
|
|
49
|
+
"vite": "^6.1.0",
|
|
50
|
+
"vite-plugin-dts": "^4.5.0",
|
|
51
|
+
"vitest": "^3.0.5"
|
|
52
|
+
}
|
|
53
|
+
}
|