@unabridged/midwest 0.24.0 → 0.24.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.
Files changed (41) hide show
  1. package/app/assets/javascript/midwest/index.ts +10 -0
  2. package/app/assets/javascript/midwest/map_providers.ts +61 -0
  3. package/app/assets/javascript/midwest/viewport_observer.ts +49 -0
  4. package/app/assets/javascript/midwest.js +1056 -70
  5. package/app/assets/javascript/midwest.js.map +1 -1
  6. package/app/assets/stylesheets/midwest.css +1 -1
  7. package/app/assets/stylesheets/midwest.tailwind.css +7 -1
  8. package/dist/css/midwest.css +1 -1
  9. package/dist/javascript/collection/app/assets/javascript/midwest/index.js +10 -0
  10. package/dist/javascript/collection/app/assets/javascript/midwest/index.js.map +1 -1
  11. package/dist/javascript/collection/app/assets/javascript/midwest/map_providers.js +56 -0
  12. package/dist/javascript/collection/app/assets/javascript/midwest/map_providers.js.map +1 -0
  13. package/dist/javascript/collection/app/assets/javascript/midwest/viewport_observer.js +22 -0
  14. package/dist/javascript/collection/app/assets/javascript/midwest/viewport_observer.js.map +1 -0
  15. package/dist/javascript/collection/app/components/midwest/carousel_component/carousel_component_controller.js +4 -7
  16. package/dist/javascript/collection/app/components/midwest/carousel_component/carousel_component_controller.js.map +1 -1
  17. package/dist/javascript/collection/app/components/midwest/dropdown_component/dropdown_component_controller.js +0 -6
  18. package/dist/javascript/collection/app/components/midwest/dropdown_component/dropdown_component_controller.js.map +1 -1
  19. package/dist/javascript/collection/app/components/midwest/form/address_component/address_component_controller.js +441 -0
  20. package/dist/javascript/collection/app/components/midwest/form/address_component/address_component_controller.js.map +1 -0
  21. package/dist/javascript/collection/app/components/midwest/form/live_summary_component/live_summary_component_controller.js +55 -1
  22. package/dist/javascript/collection/app/components/midwest/form/live_summary_component/live_summary_component_controller.js.map +1 -1
  23. package/dist/javascript/collection/app/components/midwest/intersection_observer_component/intersection_observer_component_controller.js +20 -25
  24. package/dist/javascript/collection/app/components/midwest/intersection_observer_component/intersection_observer_component_controller.js.map +1 -1
  25. package/dist/javascript/collection/app/components/midwest/map_component/map_component_controller.js +297 -0
  26. package/dist/javascript/collection/app/components/midwest/map_component/map_component_controller.js.map +1 -0
  27. package/dist/javascript/collection/app/components/midwest/motion_component/motion_component_controller.js +32 -0
  28. package/dist/javascript/collection/app/components/midwest/motion_component/motion_component_controller.js.map +1 -0
  29. package/dist/javascript/collection/app/components/midwest/notification_component/notification_component_controller.js +4 -12
  30. package/dist/javascript/collection/app/components/midwest/notification_component/notification_component_controller.js.map +1 -1
  31. package/dist/javascript/collection/app/components/midwest/onboarding_component/onboarding_component_controller.js +34 -5
  32. package/dist/javascript/collection/app/components/midwest/onboarding_component/onboarding_component_controller.js.map +1 -1
  33. package/dist/javascript/collection/app/components/midwest/page_transition_component/page_transition_component_controller.js +38 -0
  34. package/dist/javascript/collection/app/components/midwest/page_transition_component/page_transition_component_controller.js.map +1 -0
  35. package/dist/javascript/collection/app/components/midwest/popover_component/popover_component_controller.js +67 -0
  36. package/dist/javascript/collection/app/components/midwest/popover_component/popover_component_controller.js.map +1 -0
  37. package/dist/javascript/collection/app/components/midwest/table_component/load_more_controller.js +10 -14
  38. package/dist/javascript/collection/app/components/midwest/table_component/load_more_controller.js.map +1 -1
  39. package/dist/javascript/midwest.js +1056 -70
  40. package/dist/javascript/midwest.js.map +1 -1
  41. package/package.json +1 -1
@@ -38,6 +38,11 @@ import Onboarding from '../../../components/midwest/onboarding_component/onboard
38
38
  import ThemeSwitch from '../../../components/midwest/form/switch_component/theme_switch_controller'
39
39
  import Panorama from '../../../components/midwest/panorama_component/panorama_component_controller'
40
40
  import Playlist from '../../../components/midwest/playlist_component/playlist_component_controller'
41
+ import Motion from '../../../components/midwest/motion_component/motion_component_controller'
42
+ import PageTransition from '../../../components/midwest/page_transition_component/page_transition_component_controller'
43
+ import Map from '../../../components/midwest/map_component/map_component_controller'
44
+ import Address from '../../../components/midwest/form/address_component/address_component_controller'
45
+ import Popover from '../../../components/midwest/popover_component/popover_component_controller'
41
46
  /* IMPORTS */
42
47
 
43
48
  export { Card, Banner, CountdownTimer, Chart }
@@ -83,5 +88,10 @@ export function registerMidwestControllers (application: any) {
83
88
  application.register('midwest-theme-switch', ThemeSwitch)
84
89
  application.register('midwest-panorama', Panorama)
85
90
  application.register('midwest-playlist', Playlist)
91
+ application.register('midwest-motion', Motion)
92
+ application.register('midwest-page-transition', PageTransition)
93
+ application.register('midwest-map', Map)
94
+ application.register('midwest-address', Address)
95
+ application.register('midwest-popover', Popover)
86
96
  /* EXPORTS */
87
97
  }
@@ -0,0 +1,61 @@
1
+ // Shared map provider script loaders. Module-level promises ensure the CDN
2
+ // script is only injected once even when MapComponent and AddressComponent both
3
+ // mount on the same page simultaneously.
4
+
5
+ let mapkitScriptPromise: Promise<void> | null = null
6
+ let googleMapsScriptPromise: Promise<void> | null = null
7
+ let leafletScriptPromise: Promise<void> | null = null
8
+
9
+ export function loadMapKitScript (): Promise<void> {
10
+ if ((window as any).mapkit) return Promise.resolve()
11
+ if (mapkitScriptPromise) return mapkitScriptPromise
12
+
13
+ mapkitScriptPromise = new Promise<void>((resolve, reject) => {
14
+ const script = document.createElement('script')
15
+ script.src = 'https://cdn.apple-mapkit.com/mk/5.x.x/mapkit.js'
16
+ script.crossOrigin = 'anonymous'
17
+ script.addEventListener('load', () => resolve())
18
+ script.addEventListener('error', () => reject(new Error('Failed to load MapKit JS')))
19
+ document.head.appendChild(script)
20
+ })
21
+ return mapkitScriptPromise
22
+ }
23
+
24
+ // Leaflet: injects the CSS link then the JS. Both are deduplicated.
25
+ export function loadLeafletScript (): Promise<void> {
26
+ if ((window as any).L) return Promise.resolve()
27
+ if (leafletScriptPromise) return leafletScriptPromise
28
+
29
+ leafletScriptPromise = new Promise<void>((resolve, reject) => {
30
+ if (!document.querySelector('link[data-midwest-leaflet]')) {
31
+ const link = document.createElement('link')
32
+ link.rel = 'stylesheet'
33
+ link.href = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css'
34
+ link.dataset.midwestLeaflet = ''
35
+ document.head.appendChild(link)
36
+ }
37
+
38
+ const script = document.createElement('script')
39
+ script.src = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js'
40
+ script.addEventListener('load', () => resolve())
41
+ script.addEventListener('error', () => reject(new Error('Failed to load Leaflet')))
42
+ document.head.appendChild(script)
43
+ })
44
+ return leafletScriptPromise
45
+ }
46
+
47
+ // Always includes &libraries=places so that AddressComponent autocomplete works
48
+ // whether or not a MapComponent also loads Google Maps on the same page.
49
+ export function loadGoogleMapsScript (apiKey: string): Promise<void> {
50
+ if ((window as any).google?.maps) return Promise.resolve()
51
+ if (googleMapsScriptPromise) return googleMapsScriptPromise
52
+
53
+ googleMapsScriptPromise = new Promise<void>((resolve, reject) => {
54
+ ;(window as any).__midwestGoogleMapsReady = resolve
55
+ const script = document.createElement('script')
56
+ script.src = `https://maps.googleapis.com/maps/api/js?key=${encodeURIComponent(apiKey)}&callback=__midwestGoogleMapsReady&loading=async&libraries=places`
57
+ script.addEventListener('error', () => reject(new Error('Failed to load Google Maps')))
58
+ document.head.appendChild(script)
59
+ })
60
+ return googleMapsScriptPromise
61
+ }
@@ -0,0 +1,49 @@
1
+ // Shared viewport-detection helper for components that react to scrolling into
2
+ // and out of view (IntersectionObserverComponent, MotionComponent, …).
3
+ //
4
+ // Wraps the IntersectionObserver API so controllers only describe *what* to do
5
+ // on enter/leave, not the observer plumbing. Components own the reaction (toggle
6
+ // a class, dispatch an event, reveal an animation); this module owns creating,
7
+ // observing, and tearing down the observer so the behavior stays consistent.
8
+
9
+ export interface ViewportObserverOptions {
10
+ // Fraction(s) of the element that must be visible to count as intersecting.
11
+ threshold?: number | number[]
12
+ // Margin around the viewport root (CSS shorthand string).
13
+ rootMargin?: string
14
+ // Stop observing after the first time the element enters the viewport.
15
+ once?: boolean
16
+ // Called each time the element enters the viewport.
17
+ onEnter?: (entry: IntersectionObserverEntry) => void
18
+ // Called each time the element leaves the viewport. Never called after the
19
+ // first enter when `once` is true (the observer has disconnected by then).
20
+ onLeave?: (entry: IntersectionObserverEntry) => void
21
+ }
22
+
23
+ // Observe `element` crossing the viewport threshold, invoking the callbacks as
24
+ // it enters and leaves. Returns a teardown function that disconnects the
25
+ // observer; callers should invoke it from their controller's `disconnect()`.
26
+ export function observeViewport (
27
+ element: Element,
28
+ options: ViewportObserverOptions = {}
29
+ ): () => void {
30
+ const { threshold = 0, rootMargin = '0px', once = false, onEnter, onLeave } = options
31
+
32
+ const observer = new IntersectionObserver(
33
+ (entries) => {
34
+ for (const entry of entries) {
35
+ if (entry.isIntersecting) {
36
+ onEnter?.(entry)
37
+ if (once) observer.disconnect()
38
+ } else {
39
+ onLeave?.(entry)
40
+ }
41
+ }
42
+ },
43
+ { threshold, rootMargin }
44
+ )
45
+
46
+ observer.observe(element)
47
+
48
+ return () => observer.disconnect()
49
+ }