@unabridged/midwest 0.25.0 → 0.27.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 (28) hide show
  1. package/README.md +1 -1
  2. package/app/assets/javascript/midwest/async_runtime.ts +90 -0
  3. package/app/assets/javascript/midwest/index.ts +6 -0
  4. package/app/assets/javascript/midwest.js +605 -21
  5. package/app/assets/javascript/midwest.js.map +1 -1
  6. package/app/assets/stylesheets/midwest/tailwind.css +39 -69
  7. package/app/assets/stylesheets/midwest/tailwind.theme.css +68 -0
  8. package/app/assets/stylesheets/midwest.css +1 -1
  9. package/app/assets/stylesheets/midwest.tailwind.css +20 -1
  10. package/dist/css/midwest.css +1 -1
  11. package/dist/javascript/collection/app/assets/javascript/midwest/index.js +6 -0
  12. package/dist/javascript/collection/app/assets/javascript/midwest/index.js.map +1 -1
  13. package/dist/javascript/collection/app/components/midwest/assets_component/assets_component_controller.js +47 -0
  14. package/dist/javascript/collection/app/components/midwest/assets_component/assets_component_controller.js.map +1 -0
  15. package/dist/javascript/collection/app/components/midwest/chart_component/chart_component_controller.js +122 -2
  16. package/dist/javascript/collection/app/components/midwest/chart_component/chart_component_controller.js.map +1 -1
  17. package/dist/javascript/collection/app/components/midwest/context_menu_component/context_menu_component_controller.js +71 -0
  18. package/dist/javascript/collection/app/components/midwest/context_menu_component/context_menu_component_controller.js.map +1 -0
  19. package/dist/javascript/collection/app/components/midwest/dialog_component/dialog_component_controller.js +33 -1
  20. package/dist/javascript/collection/app/components/midwest/dialog_component/dialog_component_controller.js.map +1 -1
  21. package/dist/javascript/collection/app/components/midwest/split_view_component/split_view_component_controller.js +99 -0
  22. package/dist/javascript/collection/app/components/midwest/split_view_component/split_view_component_controller.js.map +1 -0
  23. package/dist/javascript/collection/app/components/midwest/table_component/table_component_controller.js +239 -15
  24. package/dist/javascript/collection/app/components/midwest/table_component/table_component_controller.js.map +1 -1
  25. package/dist/javascript/midwest.d.ts +16 -1
  26. package/dist/javascript/midwest.js +605 -21
  27. package/dist/javascript/midwest.js.map +1 -1
  28. package/package.json +3 -2
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Rails Tests](https://github.com/unabridged/midwest/actions/workflows/rails-tests.yml/badge.svg?branch=main)](https://github.com/unabridged/midwest/actions/workflows/rails-tests.yml)
4
4
  [![Bridgetown Tests](https://github.com/unabridged/midwest/actions/workflows/bridgetown-tests.yml/badge.svg?branch=main)](https://github.com/unabridged/midwest/actions/workflows/bridgetown-tests.yml)
5
5
  [![Ruby](https://img.shields.io/badge/Ruby-3.3_%7C_3.4-CC342D?logo=ruby&logoColor=white)](https://github.com/unabridged/midwest/actions/workflows/ci.yml)
6
- [![Coverage](https://img.shields.io/badge/coverage-95%25-brightgreen)](https://github.com/unabridged/midwest/actions/workflows/ci.yml)
6
+ [![Coverage](https://img.shields.io/badge/coverage-94%25-brightgreen)](https://github.com/unabridged/midwest/actions/workflows/ci.yml)
7
7
 
8
8
  Midwest Component Library is an implementation of the Midwest Design System using [ViewComponent](https://github.com/github/view_component).
9
9
 
@@ -0,0 +1,90 @@
1
+ // Shared runtime for the async (per-component) JS build.
2
+ //
3
+ // In bundled mode every controller is registered up front by
4
+ // `registerMidwestControllers(application)`. In async mode each component's
5
+ // module is fetched on its own, whenever that component first appears on a
6
+ // page — which may be long before or long after the host application calls
7
+ // `Application.start()`. So registration cannot assume an application exists
8
+ // yet: anything that arrives early is queued and flushed once one does.
9
+ //
10
+ // Wiring, for a host app that follows the Rails convention of exposing its
11
+ // instance as `window.Stimulus`, is nothing — the runtime adopts it. Otherwise:
12
+ //
13
+ // import { Application } from '@hotwired/stimulus'
14
+ // const application = Application.start()
15
+ // window.Midwest.useApplication(application)
16
+ //
17
+ // See ASYNC_ASSETS.md §6.2.
18
+
19
+ type ControllerConstructor = unknown
20
+
21
+ interface StimulusApplication {
22
+ register: (identifier: string, controllerConstructor: ControllerConstructor) => void
23
+ }
24
+
25
+ interface MidwestRuntime {
26
+ register: (identifier: string, controllerConstructor: ControllerConstructor) => void
27
+ useApplication: (application: StimulusApplication) => void
28
+ }
29
+
30
+ declare global {
31
+ interface Window {
32
+ Stimulus?: StimulusApplication
33
+ Midwest?: MidwestRuntime
34
+ }
35
+ }
36
+
37
+ const pending: [string, ControllerConstructor][] = []
38
+ const registered = new Set<string>()
39
+ let application: StimulusApplication | null = null
40
+
41
+ // Idempotent by identifier: a component's module can legitimately be requested
42
+ // twice (a Turbo Frame carrying a component the page already had), and while
43
+ // the browser's module map means it only *executes* once per URL, a rebuilt
44
+ // file with a new hash is a different URL and would execute again.
45
+ export function register (identifier: string, controllerConstructor: ControllerConstructor): void {
46
+ if (registered.has(identifier)) return
47
+ registered.add(identifier)
48
+
49
+ if (application) {
50
+ application.register(identifier, controllerConstructor)
51
+ } else {
52
+ pending.push([identifier, controllerConstructor])
53
+ }
54
+ }
55
+
56
+ export function useApplication (app: StimulusApplication): void {
57
+ application = app
58
+ while (pending.length > 0) {
59
+ const [identifier, controllerConstructor] = pending.shift() as [string, ControllerConstructor]
60
+ app.register(identifier, controllerConstructor)
61
+ }
62
+ }
63
+
64
+ // Adoption has to cope with either order, and the common one is the awkward
65
+ // one: `midwest_asset_tags` sits in <head>, so Midwest's modules are usually
66
+ // parsed — and executed — BEFORE the application's own Stimulus boot. Checking
67
+ // `window.Stimulus` once at load time therefore finds nothing, queues every
68
+ // controller, and never flushes. Nothing errors; the page is simply inert.
69
+ //
70
+ // So when there is no application yet, watch the property for one being
71
+ // assigned. Rails' convention of `window.Stimulus = Application.start()` then
72
+ // wires everything up on its own, whichever script happens to run first.
73
+ if (typeof window !== 'undefined') {
74
+ window.Midwest = { register, useApplication }
75
+
76
+ if (window.Stimulus) {
77
+ useApplication(window.Stimulus)
78
+ } else {
79
+ let assigned: StimulusApplication | undefined
80
+ Object.defineProperty(window, 'Stimulus', {
81
+ configurable: true,
82
+ enumerable: true,
83
+ get: () => assigned,
84
+ set (value: StimulusApplication) {
85
+ assigned = value
86
+ if (value) useApplication(value)
87
+ }
88
+ })
89
+ }
90
+ }
@@ -43,6 +43,9 @@ import PageTransition from '../../../components/midwest/page_transition_componen
43
43
  import Map from '../../../components/midwest/map_component/map_component_controller'
44
44
  import Address from '../../../components/midwest/form/address_component/address_component_controller'
45
45
  import Popover from '../../../components/midwest/popover_component/popover_component_controller'
46
+ import ContextMenu from '../../../components/midwest/context_menu_component/context_menu_component_controller'
47
+ import SplitView from '../../../components/midwest/split_view_component/split_view_component_controller'
48
+ import Assets from '../../../components/midwest/assets_component/assets_component_controller'
46
49
  /* IMPORTS */
47
50
 
48
51
  export { Card, Banner, CountdownTimer, Chart }
@@ -93,5 +96,8 @@ export function registerMidwestControllers (application: any) {
93
96
  application.register('midwest-map', Map)
94
97
  application.register('midwest-address', Address)
95
98
  application.register('midwest-popover', Popover)
99
+ application.register('midwest-context-menu', ContextMenu)
100
+ application.register('midwest-split-view', SplitView)
101
+ application.register('midwest-assets', Assets)
96
102
  /* EXPORTS */
97
103
  }