@mapvx/website-component 0.8.0 → 0.9.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/README.md +201 -1
- package/dist/browser/main.js +278 -123
- package/dist/browser/styles.css +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -253,7 +253,7 @@ The web component accepts the following input properties to customize its behavi
|
|
|
253
253
|
#### Required Properties Only
|
|
254
254
|
|
|
255
255
|
```html
|
|
256
|
-
<mapvx-website api-key="your-api-key-here"></mapvx-website>
|
|
256
|
+
<mapvx-website api-key="your-api-key-here" institution-id="institution-123"></mapvx-website>
|
|
257
257
|
```
|
|
258
258
|
|
|
259
259
|
#### With Optional Configuration
|
|
@@ -270,6 +270,206 @@ The web component accepts the following input properties to customize its behavi
|
|
|
270
270
|
</mapvx-website>
|
|
271
271
|
```
|
|
272
272
|
|
|
273
|
+
## 📤 Output Events
|
|
274
|
+
|
|
275
|
+
The web component emits custom events that you can listen to for user interactions:
|
|
276
|
+
|
|
277
|
+
| Event Name | Type | Description |
|
|
278
|
+
| -------------- | -------- | --------------------------------------------------------------- |
|
|
279
|
+
| `cardSelected` | `string` | Emitted when a location card is selected. Contains the card ID. |
|
|
280
|
+
|
|
281
|
+
### Output Usage Examples
|
|
282
|
+
|
|
283
|
+
#### Vanilla JavaScript
|
|
284
|
+
|
|
285
|
+
```javascript
|
|
286
|
+
// Wait for the web component to be registered
|
|
287
|
+
function setupCardSelectedListener() {
|
|
288
|
+
const element = document.querySelector('mapvx-website')
|
|
289
|
+
if (element) {
|
|
290
|
+
element.addEventListener('cardSelected', (event) => {
|
|
291
|
+
if (event instanceof CustomEvent) {
|
|
292
|
+
const cardId = event.detail
|
|
293
|
+
console.log('Card selected:', cardId)
|
|
294
|
+
// Handle card selection
|
|
295
|
+
}
|
|
296
|
+
})
|
|
297
|
+
} else {
|
|
298
|
+
// Retry if element is not yet available
|
|
299
|
+
setTimeout(setupCardSelectedListener, 100)
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Check if web component is already registered
|
|
304
|
+
if (customElements.get('mapvx-website')) {
|
|
305
|
+
setupCardSelectedListener()
|
|
306
|
+
} else {
|
|
307
|
+
// Wait for registration
|
|
308
|
+
const checkInterval = setInterval(() => {
|
|
309
|
+
if (customElements.get('mapvx-website')) {
|
|
310
|
+
setupCardSelectedListener()
|
|
311
|
+
clearInterval(checkInterval)
|
|
312
|
+
}
|
|
313
|
+
}, 100)
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
#### Update Browser URL with `history.pushState`
|
|
318
|
+
|
|
319
|
+
You can also react to the `cardSelected` event to change the browser URL without a full page reload, which is especially useful in SSR apps looking to keep client-side navigation in sync with the selected place. Add this script to your HTML page after the web component:s
|
|
320
|
+
|
|
321
|
+
```html
|
|
322
|
+
<script>
|
|
323
|
+
// Wait for the web component to be registered
|
|
324
|
+
function setupUrlUpdater() {
|
|
325
|
+
const element = document.querySelector('mapvx-website')
|
|
326
|
+
if (!element) {
|
|
327
|
+
setTimeout(setupUrlUpdater, 100)
|
|
328
|
+
return
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const handleCardSelected = (event) => {
|
|
332
|
+
if (event instanceof CustomEvent) {
|
|
333
|
+
const cardId = event.detail
|
|
334
|
+
// Update URL using history.pushState
|
|
335
|
+
history.pushState(
|
|
336
|
+
{ page: 'profile', id: cardId },
|
|
337
|
+
'',
|
|
338
|
+
`${location.pathname}?tenant=${cardId}`,
|
|
339
|
+
)
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
element.addEventListener('cardSelected', handleCardSelected)
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Check if web component is already registered
|
|
347
|
+
if (customElements.get('mapvx-website')) {
|
|
348
|
+
setupUrlUpdater()
|
|
349
|
+
} else {
|
|
350
|
+
// Wait for registration
|
|
351
|
+
const waitForRegistration = setInterval(() => {
|
|
352
|
+
if (customElements.get('mapvx-website')) {
|
|
353
|
+
clearInterval(waitForRegistration)
|
|
354
|
+
setupUrlUpdater()
|
|
355
|
+
}
|
|
356
|
+
}, 100)
|
|
357
|
+
}
|
|
358
|
+
</script>
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
#### React
|
|
362
|
+
|
|
363
|
+
```jsx
|
|
364
|
+
import { useEffect, useRef } from 'react'
|
|
365
|
+
|
|
366
|
+
function App() {
|
|
367
|
+
const webComponentRef = useRef(null)
|
|
368
|
+
|
|
369
|
+
useEffect(() => {
|
|
370
|
+
const element = webComponentRef.current
|
|
371
|
+
if (!element) return
|
|
372
|
+
|
|
373
|
+
const handleCardSelected = (event) => {
|
|
374
|
+
if (event instanceof CustomEvent) {
|
|
375
|
+
const cardId = event.detail
|
|
376
|
+
console.log('Card selected:', cardId)
|
|
377
|
+
// Handle card selection
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
element.addEventListener('cardSelected', handleCardSelected)
|
|
382
|
+
|
|
383
|
+
return () => {
|
|
384
|
+
element.removeEventListener('cardSelected', handleCardSelected)
|
|
385
|
+
}
|
|
386
|
+
}, [])
|
|
387
|
+
|
|
388
|
+
return <mapvx-website ref={webComponentRef} api-key="your-api-key-here" />
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
#### Vue
|
|
393
|
+
|
|
394
|
+
```vue
|
|
395
|
+
<template>
|
|
396
|
+
<mapvx-website ref="webComponent" api-key="your-api-key-here" />
|
|
397
|
+
</template>
|
|
398
|
+
|
|
399
|
+
<script setup>
|
|
400
|
+
import { ref, onMounted, onUnmounted } from 'vue'
|
|
401
|
+
|
|
402
|
+
const webComponent = ref(null)
|
|
403
|
+
|
|
404
|
+
const handleCardSelected = (event) => {
|
|
405
|
+
if (event instanceof CustomEvent) {
|
|
406
|
+
const cardId = event.detail
|
|
407
|
+
console.log('Card selected:', cardId)
|
|
408
|
+
// Handle card selection
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
onMounted(() => {
|
|
413
|
+
if (webComponent.value) {
|
|
414
|
+
webComponent.value.addEventListener('cardSelected', handleCardSelected)
|
|
415
|
+
}
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
onUnmounted(() => {
|
|
419
|
+
if (webComponent.value) {
|
|
420
|
+
webComponent.value.removeEventListener('cardSelected', handleCardSelected)
|
|
421
|
+
}
|
|
422
|
+
})
|
|
423
|
+
</script>
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
#### Angular
|
|
427
|
+
|
|
428
|
+
```typescript
|
|
429
|
+
import { Component, ElementRef, OnInit, OnDestroy, ViewChild, AfterViewInit } from '@angular/core'
|
|
430
|
+
|
|
431
|
+
@Component({
|
|
432
|
+
selector: 'app-mapvx',
|
|
433
|
+
template: ` <mapvx-website #webComponent [attr.api-key]="apiKey" /> `,
|
|
434
|
+
})
|
|
435
|
+
export class MapvxComponent implements AfterViewInit, OnDestroy {
|
|
436
|
+
@ViewChild('webComponent', { static: false }) webComponentRef!: ElementRef<HTMLElement>
|
|
437
|
+
|
|
438
|
+
apiKey = 'your-api-key-here'
|
|
439
|
+
private cardSelectedListener?: (event: Event) => void
|
|
440
|
+
|
|
441
|
+
ngAfterViewInit() {
|
|
442
|
+
this.setupCardSelectedListener()
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
private setupCardSelectedListener() {
|
|
446
|
+
const element = this.webComponentRef?.nativeElement
|
|
447
|
+
if (!element) {
|
|
448
|
+
// Retry if element is not yet available
|
|
449
|
+
setTimeout(() => this.setupCardSelectedListener(), 100)
|
|
450
|
+
return
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
this.cardSelectedListener = (event: Event) => {
|
|
454
|
+
if (event instanceof CustomEvent) {
|
|
455
|
+
const cardId = event.detail as string
|
|
456
|
+
console.log('Card selected:', cardId)
|
|
457
|
+
// Handle card selection
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
element.addEventListener('cardSelected', this.cardSelectedListener)
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
ngOnDestroy() {
|
|
465
|
+
const element = this.webComponentRef?.nativeElement
|
|
466
|
+
if (element && this.cardSelectedListener) {
|
|
467
|
+
element.removeEventListener('cardSelected', this.cardSelectedListener)
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
```
|
|
472
|
+
|
|
273
473
|
## 🔧 Server-Side Rendering (SSR) Support
|
|
274
474
|
|
|
275
475
|
For applications using Server-Side Rendering (SSR) where you need to preload initial data on the server before sending it to the browser:
|