foldkit 0.111.0 → 0.112.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 (222) hide show
  1. package/README.md +2 -2
  2. package/dist/devTools/host.d.ts +6 -0
  3. package/dist/devTools/host.d.ts.map +1 -0
  4. package/dist/devTools/host.js +4 -0
  5. package/dist/dom/dom.d.ts +6 -1
  6. package/dist/dom/dom.d.ts.map +1 -1
  7. package/dist/dom/dom.js +24 -1
  8. package/dist/html/index.d.ts +4 -3
  9. package/dist/html/index.d.ts.map +1 -1
  10. package/dist/html/index.js +4 -3
  11. package/dist/html/submodel.d.ts +2 -2
  12. package/dist/html/submodel.d.ts.map +1 -1
  13. package/dist/index.d.ts +0 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +0 -1
  16. package/dist/runtime/public.d.ts +1 -1
  17. package/dist/runtime/public.d.ts.map +1 -1
  18. package/dist/runtime/runtime.d.ts +14 -1
  19. package/dist/runtime/runtime.d.ts.map +1 -1
  20. package/dist/runtime/runtime.js +7 -4
  21. package/dist/runtime/subscription.d.ts +1 -1
  22. package/dist/subscription/public.d.ts +1 -1
  23. package/dist/subscription/public.d.ts.map +1 -1
  24. package/package.json +12 -93
  25. package/dist/devTools/overlay-styles.d.ts +0 -3
  26. package/dist/devTools/overlay-styles.d.ts.map +0 -1
  27. package/dist/devTools/overlay-styles.js +0 -706
  28. package/dist/devTools/overlay.d.ts +0 -63
  29. package/dist/devTools/overlay.d.ts.map +0 -1
  30. package/dist/devTools/overlay.js +0 -1244
  31. package/dist/test/apps/disabledButton.d.ts +0 -38
  32. package/dist/test/apps/disabledButton.d.ts.map +0 -1
  33. package/dist/test/apps/disabledButton.js +0 -71
  34. package/dist/ui/anchor.d.ts +0 -38
  35. package/dist/ui/anchor.d.ts.map +0 -1
  36. package/dist/ui/anchor.js +0 -142
  37. package/dist/ui/animation/index.d.ts +0 -49
  38. package/dist/ui/animation/index.d.ts.map +0 -1
  39. package/dist/ui/animation/index.js +0 -74
  40. package/dist/ui/animation/public.d.ts +0 -3
  41. package/dist/ui/animation/public.d.ts.map +0 -1
  42. package/dist/ui/animation/public.js +0 -1
  43. package/dist/ui/animation/schema.d.ts +0 -43
  44. package/dist/ui/animation/schema.d.ts.map +0 -1
  45. package/dist/ui/animation/schema.js +0 -41
  46. package/dist/ui/animation/update.d.ts +0 -24
  47. package/dist/ui/animation/update.d.ts.map +0 -1
  48. package/dist/ui/animation/update.js +0 -67
  49. package/dist/ui/button/index.d.ts +0 -17
  50. package/dist/ui/button/index.d.ts.map +0 -1
  51. package/dist/ui/button/index.js +0 -22
  52. package/dist/ui/button/public.d.ts +0 -3
  53. package/dist/ui/button/public.d.ts.map +0 -1
  54. package/dist/ui/button/public.js +0 -1
  55. package/dist/ui/calendar/index.d.ts +0 -462
  56. package/dist/ui/calendar/index.d.ts.map +0 -1
  57. package/dist/ui/calendar/index.js +0 -824
  58. package/dist/ui/calendar/public.d.ts +0 -3
  59. package/dist/ui/calendar/public.d.ts.map +0 -1
  60. package/dist/ui/calendar/public.js +0 -1
  61. package/dist/ui/checkbox/index.d.ts +0 -119
  62. package/dist/ui/checkbox/index.d.ts.map +0 -1
  63. package/dist/ui/checkbox/index.js +0 -110
  64. package/dist/ui/checkbox/public.d.ts +0 -3
  65. package/dist/ui/checkbox/public.d.ts.map +0 -1
  66. package/dist/ui/checkbox/public.js +0 -1
  67. package/dist/ui/combobox/multi.d.ts +0 -184
  68. package/dist/ui/combobox/multi.d.ts.map +0 -1
  69. package/dist/ui/combobox/multi.js +0 -81
  70. package/dist/ui/combobox/multiPublic.d.ts +0 -3
  71. package/dist/ui/combobox/multiPublic.d.ts.map +0 -1
  72. package/dist/ui/combobox/multiPublic.js +0 -1
  73. package/dist/ui/combobox/public.d.ts +0 -7
  74. package/dist/ui/combobox/public.d.ts.map +0 -1
  75. package/dist/ui/combobox/public.js +0 -3
  76. package/dist/ui/combobox/shared.d.ts +0 -422
  77. package/dist/ui/combobox/shared.d.ts.map +0 -1
  78. package/dist/ui/combobox/shared.js +0 -707
  79. package/dist/ui/combobox/single.d.ts +0 -199
  80. package/dist/ui/combobox/single.d.ts.map +0 -1
  81. package/dist/ui/combobox/single.js +0 -106
  82. package/dist/ui/datePicker/index.d.ts +0 -457
  83. package/dist/ui/datePicker/index.d.ts.map +0 -1
  84. package/dist/ui/datePicker/index.js +0 -317
  85. package/dist/ui/datePicker/public.d.ts +0 -3
  86. package/dist/ui/datePicker/public.d.ts.map +0 -1
  87. package/dist/ui/datePicker/public.js +0 -1
  88. package/dist/ui/dialog/index.d.ts +0 -155
  89. package/dist/ui/dialog/index.d.ts.map +0 -1
  90. package/dist/ui/dialog/index.js +0 -208
  91. package/dist/ui/dialog/public.d.ts +0 -3
  92. package/dist/ui/dialog/public.d.ts.map +0 -1
  93. package/dist/ui/dialog/public.js +0 -1
  94. package/dist/ui/disclosure/index.d.ts +0 -110
  95. package/dist/ui/disclosure/index.d.ts.map +0 -1
  96. package/dist/ui/disclosure/index.js +0 -110
  97. package/dist/ui/disclosure/public.d.ts +0 -3
  98. package/dist/ui/disclosure/public.d.ts.map +0 -1
  99. package/dist/ui/disclosure/public.js +0 -1
  100. package/dist/ui/dragAndDrop/index.d.ts +0 -540
  101. package/dist/ui/dragAndDrop/index.d.ts.map +0 -1
  102. package/dist/ui/dragAndDrop/index.js +0 -535
  103. package/dist/ui/dragAndDrop/public.d.ts +0 -3
  104. package/dist/ui/dragAndDrop/public.d.ts.map +0 -1
  105. package/dist/ui/dragAndDrop/public.js +0 -1
  106. package/dist/ui/fieldset/index.d.ts +0 -21
  107. package/dist/ui/fieldset/index.d.ts.map +0 -1
  108. package/dist/ui/fieldset/index.js +0 -25
  109. package/dist/ui/fieldset/public.d.ts +0 -3
  110. package/dist/ui/fieldset/public.d.ts.map +0 -1
  111. package/dist/ui/fieldset/public.js +0 -1
  112. package/dist/ui/fileDrop/index.d.ts +0 -109
  113. package/dist/ui/fileDrop/index.d.ts.map +0 -1
  114. package/dist/ui/fileDrop/index.js +0 -126
  115. package/dist/ui/fileDrop/public.d.ts +0 -3
  116. package/dist/ui/fileDrop/public.d.ts.map +0 -1
  117. package/dist/ui/fileDrop/public.js +0 -1
  118. package/dist/ui/group.d.ts +0 -8
  119. package/dist/ui/group.d.ts.map +0 -1
  120. package/dist/ui/group.js +0 -13
  121. package/dist/ui/index.d.ts +0 -25
  122. package/dist/ui/index.d.ts.map +0 -1
  123. package/dist/ui/index.js +0 -24
  124. package/dist/ui/input/index.d.ts +0 -26
  125. package/dist/ui/input/index.d.ts.map +0 -1
  126. package/dist/ui/input/index.js +0 -43
  127. package/dist/ui/input/public.d.ts +0 -3
  128. package/dist/ui/input/public.d.ts.map +0 -1
  129. package/dist/ui/input/public.js +0 -1
  130. package/dist/ui/keyboard.d.ts +0 -6
  131. package/dist/ui/keyboard.d.ts.map +0 -1
  132. package/dist/ui/keyboard.js +0 -9
  133. package/dist/ui/listbox/multi.d.ts +0 -190
  134. package/dist/ui/listbox/multi.d.ts.map +0 -1
  135. package/dist/ui/listbox/multi.js +0 -65
  136. package/dist/ui/listbox/multiPublic.d.ts +0 -3
  137. package/dist/ui/listbox/multiPublic.d.ts.map +0 -1
  138. package/dist/ui/listbox/multiPublic.js +0 -1
  139. package/dist/ui/listbox/public.d.ts +0 -7
  140. package/dist/ui/listbox/public.d.ts.map +0 -1
  141. package/dist/ui/listbox/public.js +0 -3
  142. package/dist/ui/listbox/shared.d.ts +0 -431
  143. package/dist/ui/listbox/shared.d.ts.map +0 -1
  144. package/dist/ui/listbox/shared.js +0 -669
  145. package/dist/ui/listbox/single.d.ts +0 -208
  146. package/dist/ui/listbox/single.d.ts.map +0 -1
  147. package/dist/ui/listbox/single.js +0 -73
  148. package/dist/ui/menu/index.d.ts +0 -367
  149. package/dist/ui/menu/index.d.ts.map +0 -1
  150. package/dist/ui/menu/index.js +0 -681
  151. package/dist/ui/menu/public.d.ts +0 -4
  152. package/dist/ui/menu/public.d.ts.map +0 -1
  153. package/dist/ui/menu/public.js +0 -1
  154. package/dist/ui/popover/index.d.ts +0 -267
  155. package/dist/ui/popover/index.d.ts.map +0 -1
  156. package/dist/ui/popover/index.js +0 -345
  157. package/dist/ui/popover/public.d.ts +0 -4
  158. package/dist/ui/popover/public.d.ts.map +0 -1
  159. package/dist/ui/popover/public.js +0 -1
  160. package/dist/ui/radioGroup/index.d.ts +0 -169
  161. package/dist/ui/radioGroup/index.d.ts.map +0 -1
  162. package/dist/ui/radioGroup/index.js +0 -196
  163. package/dist/ui/radioGroup/public.d.ts +0 -3
  164. package/dist/ui/radioGroup/public.d.ts.map +0 -1
  165. package/dist/ui/radioGroup/public.js +0 -1
  166. package/dist/ui/select/index.d.ts +0 -24
  167. package/dist/ui/select/index.d.ts.map +0 -1
  168. package/dist/ui/select/index.js +0 -40
  169. package/dist/ui/select/public.d.ts +0 -3
  170. package/dist/ui/select/public.d.ts.map +0 -1
  171. package/dist/ui/select/public.js +0 -1
  172. package/dist/ui/slider/index.d.ts +0 -318
  173. package/dist/ui/slider/index.d.ts.map +0 -1
  174. package/dist/ui/slider/index.js +0 -336
  175. package/dist/ui/slider/public.d.ts +0 -3
  176. package/dist/ui/slider/public.d.ts.map +0 -1
  177. package/dist/ui/slider/public.js +0 -1
  178. package/dist/ui/switch/index.d.ts +0 -99
  179. package/dist/ui/switch/index.d.ts.map +0 -1
  180. package/dist/ui/switch/index.js +0 -106
  181. package/dist/ui/switch/public.d.ts +0 -3
  182. package/dist/ui/switch/public.d.ts.map +0 -1
  183. package/dist/ui/switch/public.js +0 -1
  184. package/dist/ui/tabs/index.d.ts +0 -155
  185. package/dist/ui/tabs/index.d.ts.map +0 -1
  186. package/dist/ui/tabs/index.js +0 -184
  187. package/dist/ui/tabs/public.d.ts +0 -3
  188. package/dist/ui/tabs/public.d.ts.map +0 -1
  189. package/dist/ui/tabs/public.js +0 -1
  190. package/dist/ui/textarea/index.d.ts +0 -26
  191. package/dist/ui/textarea/index.d.ts.map +0 -1
  192. package/dist/ui/textarea/index.js +0 -44
  193. package/dist/ui/textarea/public.d.ts +0 -3
  194. package/dist/ui/textarea/public.d.ts.map +0 -1
  195. package/dist/ui/textarea/public.js +0 -1
  196. package/dist/ui/toast/index.d.ts +0 -608
  197. package/dist/ui/toast/index.d.ts.map +0 -1
  198. package/dist/ui/toast/index.js +0 -145
  199. package/dist/ui/toast/public.d.ts +0 -4
  200. package/dist/ui/toast/public.d.ts.map +0 -1
  201. package/dist/ui/toast/public.js +0 -1
  202. package/dist/ui/toast/schema.d.ts +0 -154
  203. package/dist/ui/toast/schema.d.ts.map +0 -1
  204. package/dist/ui/toast/schema.js +0 -93
  205. package/dist/ui/toast/update.d.ts +0 -510
  206. package/dist/ui/toast/update.d.ts.map +0 -1
  207. package/dist/ui/toast/update.js +0 -225
  208. package/dist/ui/tooltip/index.d.ts +0 -170
  209. package/dist/ui/tooltip/index.d.ts.map +0 -1
  210. package/dist/ui/tooltip/index.js +0 -252
  211. package/dist/ui/tooltip/public.d.ts +0 -4
  212. package/dist/ui/tooltip/public.d.ts.map +0 -1
  213. package/dist/ui/tooltip/public.js +0 -1
  214. package/dist/ui/typeahead.d.ts +0 -4
  215. package/dist/ui/typeahead.d.ts.map +0 -1
  216. package/dist/ui/typeahead.js +0 -14
  217. package/dist/ui/virtualList/index.d.ts +0 -202
  218. package/dist/ui/virtualList/index.d.ts.map +0 -1
  219. package/dist/ui/virtualList/index.js +0 -391
  220. package/dist/ui/virtualList/public.d.ts +0 -3
  221. package/dist/ui/virtualList/public.d.ts.map +0 -1
  222. package/dist/ui/virtualList/public.js +0 -1
@@ -1,1244 +0,0 @@
1
- import { clsx } from 'clsx';
2
- import { Array as Array_, Context, Effect, Equal, Function, HashSet, Match as M, Number as Number_, Option, Order, Predicate, Queue, Record, Schema as S, Stream, String as String_, SubscriptionRef, pipe, } from 'effect';
3
- import * as Command from '../command/index.js';
4
- import { lockScroll, unlockScroll } from '../dom/scrollLock.js';
5
- import { OptionExt } from '../effectExtensions/index.js';
6
- import { DEVTOOLS_HOST_ID, childAttributes, createKeyedLazy, createLazy, html, } from '../html/index.js';
7
- import { m } from '../message/index.js';
8
- import { makeElement } from '../runtime/runtime.js';
9
- import * as Subscription from '../runtime/subscription.js';
10
- import { evo } from '../struct/index.js';
11
- import * as Listbox from '../ui/listbox/public.js';
12
- import * as Slider from '../ui/slider/public.js';
13
- import * as Tabs from '../ui/tabs/public.js';
14
- import { overlayStyles } from './overlay-styles.js';
15
- import { toInspectableValue } from './serialize.js';
16
- import { INIT_INDEX, latestEntryIndex, } from './store.js';
17
- import { GOT_MESSAGE_PATTERN, extractSubmodelInfo, isTagged, } from './submodelPath.js';
18
- const SubmodelFilterListbox = Listbox.create();
19
- // MODEL
20
- const DisplayCommand = S.Struct({
21
- name: S.String,
22
- args: S.Option(S.Record(S.String, S.Unknown)),
23
- });
24
- const DisplayMount = S.Struct({
25
- name: S.String,
26
- args: S.Option(S.Record(S.String, S.Unknown)),
27
- });
28
- const DisplayEntry = S.Struct({
29
- tag: S.String,
30
- submodelPath: S.Array(S.String),
31
- maybeLeafTag: S.Option(S.String),
32
- commands: S.Array(DisplayCommand),
33
- mountStarts: S.Array(DisplayMount),
34
- mountEnds: S.Array(DisplayMount),
35
- timestamp: S.Number,
36
- isModelChanged: S.Boolean,
37
- });
38
- const INSPECTOR_TABS_ID = 'dt-inspector';
39
- const SUBMODEL_FILTER_ID = 'dt-submodel-filter';
40
- const SCRUBBER_SLIDER_ID = 'dt-scrubber';
41
- const InspectorTabsModel = S.Struct({
42
- id: S.String,
43
- activeIndex: S.Number,
44
- focusedIndex: S.Number,
45
- activationMode: S.Literals(['Automatic', 'Manual']),
46
- });
47
- const INSPECTOR_TABS = [
48
- 'Model',
49
- 'Message',
50
- 'Commands',
51
- 'Mounts',
52
- ];
53
- const InspectorTabs = Tabs.create();
54
- /**
55
- * `S.Unknown` whose equivalence is reference equality. Effect 4's default
56
- * equivalence for `S.Unknown` is `Equal.equals`, which walks the value
57
- * structurally (hash + compareRecords) instead of falling back to `===` like
58
- * Effect 3. The DevTools overlay holds whole user Model and Message snapshots
59
- * in fields typed as `S.Unknown`, so the runtime's per-dispatch
60
- * `modelEquivalence` check would otherwise walk the entire payload three
61
- * times every time the user dispatches a Message. The snapshots are
62
- * through-traffic (different reference per frame iff different content),
63
- * which makes reference equality the correct comparison.
64
- */
65
- const UnknownByReference = S.Unknown.pipe(S.overrideToEquivalence(() => (a, b) => a === b));
66
- const Model = S.Struct({
67
- isOpen: S.Boolean,
68
- isMobile: S.Boolean,
69
- entries: S.Array(DisplayEntry),
70
- initCommands: S.Array(DisplayCommand),
71
- initMountStarts: S.Array(DisplayMount),
72
- startIndex: S.Number,
73
- isPaused: S.Boolean,
74
- pausedAtIndex: S.Number,
75
- selectedIndex: S.Number,
76
- isFollowingLatest: S.Boolean,
77
- isFollowingTop: S.Boolean,
78
- maybeInspectedModel: S.Option(UnknownByReference),
79
- maybeInspectedMessage: S.Option(UnknownByReference),
80
- submodelTags: S.Array(S.String),
81
- maybeSubmodelFilter: S.Option(S.String),
82
- submodelFilterListbox: Listbox.Model,
83
- expandedPaths: S.HashSet(S.String),
84
- changedPaths: S.HashSet(S.String),
85
- affectedPaths: S.HashSet(S.String),
86
- inspectorTabs: InspectorTabsModel,
87
- // NOTE: empirically, inlining `Slider.Model` here throws
88
- // "Cannot read properties of undefined (reading 'ast')" when running slider
89
- // tests, because slider imports html → runtime → overlay, and overlay
90
- // references Slider.Model mid-cycle. S.suspend defers the read until after
91
- // the cycle resolves. Inlining Listbox.Model works in practice but goes
92
- // through the same import chain; the exact cause of the asymmetry isn't
93
- // pinned down. Suspend is the conservative fix until the runtime ↔ overlay
94
- // cycle is broken at the source.
95
- scrubberSlider: S.suspend(() => Slider.Model),
96
- });
97
- const Flags = S.Struct({
98
- isMobile: S.Boolean,
99
- entries: S.Array(DisplayEntry),
100
- initCommands: S.Array(DisplayCommand),
101
- initMountStarts: S.Array(DisplayMount),
102
- startIndex: S.Number,
103
- isPaused: S.Boolean,
104
- pausedAtIndex: S.Number,
105
- });
106
- // MESSAGE
107
- const ClickedToggle = m('ClickedToggle');
108
- const ClickedRow = m('ClickedRow', { index: S.Number });
109
- const ClickedResume = m('ClickedResume');
110
- const ClickedClear = m('ClickedClear');
111
- const CompletedJump = m('CompletedJump');
112
- const CompletedResume = m('CompletedResume');
113
- const ClickedFollowLatest = m('ClickedFollowLatest');
114
- const ClickedScrollToTopPill = m('ClickedScrollToTopPill');
115
- const ScrolledMessageList = m('ScrolledMessageList', { scrollTop: S.Number });
116
- const CompletedClear = m('CompletedClear');
117
- const LockedScroll = m('LockedScroll');
118
- const UnlockedScroll = m('UnlockedScroll');
119
- const ScrolledToTop = m('ScrolledToTop');
120
- const CrossedMobileBreakpoint = m('CrossedMobileBreakpoint', {
121
- isMobile: S.Boolean,
122
- });
123
- const ReceivedInspectedState = m('ReceivedInspectedState', {
124
- model: S.Unknown,
125
- maybeMessage: S.Option(S.Unknown),
126
- changedPaths: S.HashSet(S.String),
127
- affectedPaths: S.HashSet(S.String),
128
- });
129
- const ToggledTreeNode = m('ToggledTreeNode', { path: S.String });
130
- const GotInspectorTabsMessage = m('GotInspectorTabsMessage', {
131
- message: S.Unknown,
132
- });
133
- const ReceivedStoreUpdate = m('ReceivedStoreUpdate', {
134
- entries: S.Array(DisplayEntry),
135
- initCommands: S.Array(DisplayCommand),
136
- initMountStarts: S.Array(DisplayMount),
137
- startIndex: S.Number,
138
- isPaused: S.Boolean,
139
- pausedAtIndex: S.Number,
140
- });
141
- const GotSubmodelFilterMessage = m('GotSubmodelFilterMessage', {
142
- message: Listbox.Message,
143
- });
144
- // NOTE: suspend for the same init-order reason as scrubberSlider above.
145
- const GotScrubberSliderMessage = m('GotScrubberSliderMessage', {
146
- message: S.suspend(() => Slider.Message),
147
- });
148
- const Message = S.Union([
149
- ClickedToggle,
150
- ClickedRow,
151
- ClickedResume,
152
- ClickedClear,
153
- ClickedFollowLatest,
154
- ClickedScrollToTopPill,
155
- ScrolledMessageList,
156
- CompletedJump,
157
- CompletedResume,
158
- CompletedClear,
159
- LockedScroll,
160
- UnlockedScroll,
161
- ScrolledToTop,
162
- CrossedMobileBreakpoint,
163
- ReceivedInspectedState,
164
- ToggledTreeNode,
165
- GotInspectorTabsMessage,
166
- ReceivedStoreUpdate,
167
- GotSubmodelFilterMessage,
168
- GotScrubberSliderMessage,
169
- ]);
170
- // HELPERS
171
- const MILLIS_PER_SECOND = 1000;
172
- const MOBILE_BREAKPOINT = 767;
173
- const MOBILE_BREAKPOINT_QUERY = `(max-width: ${MOBILE_BREAKPOINT}px)`;
174
- const TREE_INDENT_PX = 12;
175
- const MAX_PREVIEW_KEYS = 3;
176
- const ALL_MESSAGES_VALUE = '';
177
- const NO_COMMANDS = [];
178
- const NO_MOUNTS = [];
179
- const formatTimeDelta = (deltaMs) => M.value(deltaMs).pipe(M.when(0, () => '0ms'), M.when(Number_.isLessThan(MILLIS_PER_SECOND), ms => `+${Math.round(ms)}ms`), M.orElse(ms => `+${(ms / MILLIS_PER_SECOND).toFixed(1)}s`));
180
- const MESSAGE_LIST_SELECTOR = '.message-list';
181
- // NOTE: scrubber slider value space is independent of the store's host
182
- // indices. Slider value 0 represents init; 1..entries.length represents
183
- // positions after each buffered message. Passing pausedAtIndex (a host
184
- // index) straight into setValue, or treating ChangedValue.value as a host
185
- // index in jumpTo, will silently produce wrong navigation. Translate at
186
- // the boundaries via the helpers below.
187
- const hostIndexToSliderValue = (hostIndex, startIndex) => (hostIndex === INIT_INDEX ? 0 : hostIndex - startIndex + 1);
188
- const sliderValueToHostIndex = (sliderValue, startIndex) => (sliderValue === 0 ? INIT_INDEX : startIndex + sliderValue - 1);
189
- const SCROLL_FOLLOW_THRESHOLD_PX = 8;
190
- const computeSubmodelTags = (entries) => pipe(entries, Array_.flatMap(({ submodelPath }) => submodelPath), Array_.dedupe, Array_.sort(Order.String));
191
- const toDisplayCommand = (command) => ({
192
- name: command.name,
193
- args: Option.fromNullishOr(command.args),
194
- });
195
- const toDisplayMount = (mount) => ({
196
- name: mount.name,
197
- args: Option.fromNullishOr(mount.args),
198
- });
199
- const toDisplayEntries = ({ entries }) => Array_.map(entries, entry => {
200
- const { submodelPath, maybeLeafTag } = extractSubmodelInfo(entry.tag, entry.message);
201
- return {
202
- tag: entry.tag,
203
- submodelPath,
204
- maybeLeafTag,
205
- commands: Array_.map(entry.commands, toDisplayCommand),
206
- mountStarts: Array_.map(entry.mountStarts, toDisplayMount),
207
- mountEnds: Array_.map(entry.mountEnds, toDisplayMount),
208
- timestamp: entry.timestamp,
209
- isModelChanged: entry.isModelChanged,
210
- };
211
- });
212
- const toDisplayState = (state) => ({
213
- entries: toDisplayEntries(state),
214
- initCommands: Array_.map(state.initCommands, toDisplayCommand),
215
- initMountStarts: Array_.map(state.initMountStarts, toDisplayMount),
216
- startIndex: state.startIndex,
217
- isPaused: state.isPaused,
218
- pausedAtIndex: state.pausedAtIndex,
219
- });
220
- const isExpandable = Predicate.isObjectOrArray;
221
- const objectPreview = (value) => pipe(value, Record.keys, Array_.filter(key => key !== '_tag'), Array_.match({
222
- onEmpty: () => '{}',
223
- onNonEmpty: keys => {
224
- const preview = pipe(keys, Array_.take(MAX_PREVIEW_KEYS), Array_.join(', '));
225
- return Array_.length(keys) > MAX_PREVIEW_KEYS
226
- ? `{ ${preview}, … }`
227
- : `{ ${preview} }`;
228
- },
229
- }));
230
- const collapsedPreview = (value) => M.value(value).pipe(M.when(Array.isArray, array => `(${array.length})`), M.when(Predicate.isObject, objectPreview), M.orElse(() => ''));
231
- class StoreService extends Context.Service()('foldkit/DevToolsStore') {
232
- }
233
- class ShadowRootService extends Context.Service()('foldkit/DevToolsShadowRoot') {
234
- }
235
- export const LockScroll = Command.define('LockScroll', LockedScroll)(lockScroll.pipe(Effect.as(LockedScroll())));
236
- export const UnlockScroll = Command.define('UnlockScroll', UnlockedScroll)(unlockScroll.pipe(Effect.as(UnlockedScroll())));
237
- const buildInspectionEffect = (index) => Effect.gen(function* () {
238
- const store = yield* StoreService;
239
- const model = yield* store.getModelAtIndex(index);
240
- const maybeMessage = yield* store.getMessageAtIndex(index);
241
- const diff = yield* store.getDiffAtIndex(index);
242
- return ReceivedInspectedState({ model, maybeMessage, ...diff });
243
- });
244
- export const JumpTo = Command.define('JumpTo', { index: S.Number }, CompletedJump)(({ index }) => Effect.gen(function* () {
245
- const store = yield* StoreService;
246
- yield* store.jumpTo(index);
247
- return CompletedJump();
248
- }));
249
- export const InspectState = Command.define('InspectState', { index: S.Number }, ReceivedInspectedState)(({ index }) => buildInspectionEffect(index));
250
- export const InspectLatest = Command.define('InspectLatest', ReceivedInspectedState)(Effect.gen(function* () {
251
- const store = yield* StoreService;
252
- const state = yield* SubscriptionRef.get(store.stateRef);
253
- return yield* buildInspectionEffect(latestEntryIndex(state));
254
- }));
255
- export const Resume = Command.define('Resume', CompletedResume)(Effect.gen(function* () {
256
- const store = yield* StoreService;
257
- yield* store.resume;
258
- return CompletedResume();
259
- }));
260
- export const Clear = Command.define('Clear', CompletedClear)(Effect.gen(function* () {
261
- const store = yield* StoreService;
262
- yield* store.clear;
263
- return CompletedClear();
264
- }));
265
- export const ScrollToTop = Command.define('ScrollToTop', ScrolledToTop)(Effect.gen(function* () {
266
- const shadow = yield* ShadowRootService;
267
- const messageList = shadow.querySelector(MESSAGE_LIST_SELECTOR);
268
- if (messageList instanceof HTMLElement) {
269
- messageList.scrollTop = 0;
270
- }
271
- return ScrolledToTop();
272
- }));
273
- const makeUpdate = (store, shadow, mode) => {
274
- const provideContext = (effect) => effect.pipe(Effect.provideService(StoreService, store), Effect.provideService(ShadowRootService, shadow));
275
- const inspectLatest = Command.mapEffect(InspectLatest(), provideContext);
276
- const resume = Command.mapEffect(Resume(), provideContext);
277
- const clear = Command.mapEffect(Clear(), provideContext);
278
- const scrollToTop = Command.mapEffect(ScrollToTop(), provideContext);
279
- const jumpTo = (index) => Command.mapEffect(JumpTo({ index }), provideContext);
280
- const inspectState = (index) => Command.mapEffect(InspectState({ index }), provideContext);
281
- const toggleScrollLock = (shouldLock) => shouldLock ? LockScroll() : UnlockScroll();
282
- return (model, message) => M.value(message).pipe(M.withReturnType(), M.tags({
283
- ClickedToggle: () => {
284
- const nextIsOpen = !model.isOpen;
285
- return [
286
- evo(model, { isOpen: () => nextIsOpen }),
287
- OptionExt.when(model.isMobile, toggleScrollLock(nextIsOpen)).pipe(Option.toArray),
288
- ];
289
- },
290
- CrossedMobileBreakpoint: ({ isMobile }) => [
291
- evo(model, { isMobile: () => isMobile }),
292
- OptionExt.when(model.isOpen, toggleScrollLock(isMobile)).pipe(Option.toArray),
293
- ],
294
- ClickedRow: ({ index }) => M.value(mode).pipe(M.withReturnType(), M.when('TimeTravel', () => [
295
- model,
296
- [jumpTo(index), inspectState(index)],
297
- ]), M.when('Inspect', () => [
298
- evo(model, {
299
- selectedIndex: () => index,
300
- isFollowingLatest: () => false,
301
- }),
302
- [inspectState(index)],
303
- ]), M.exhaustive),
304
- ClickedResume: () => [
305
- evo(model, {
306
- isFollowingTop: () => true,
307
- expandedPaths: () => HashSet.empty(),
308
- changedPaths: () => HashSet.empty(),
309
- affectedPaths: () => HashSet.empty(),
310
- }),
311
- [resume, inspectLatest, scrollToTop],
312
- ],
313
- ClickedClear: () => [
314
- evo(model, {
315
- selectedIndex: () => INIT_INDEX,
316
- isFollowingLatest: () => true,
317
- isFollowingTop: () => true,
318
- maybeSubmodelFilter: () => Option.none(),
319
- expandedPaths: () => HashSet.empty(),
320
- changedPaths: () => HashSet.empty(),
321
- affectedPaths: () => HashSet.empty(),
322
- }),
323
- [clear, inspectLatest, scrollToTop],
324
- ],
325
- ClickedFollowLatest: () => {
326
- const latestIndex = Array_.match(model.entries, {
327
- onEmpty: () => INIT_INDEX,
328
- onNonEmpty: () => model.startIndex + model.entries.length - 1,
329
- });
330
- return [
331
- evo(model, {
332
- selectedIndex: () => latestIndex,
333
- isFollowingLatest: () => true,
334
- isFollowingTop: () => true,
335
- expandedPaths: () => HashSet.empty(),
336
- changedPaths: () => HashSet.empty(),
337
- affectedPaths: () => HashSet.empty(),
338
- }),
339
- [inspectLatest, scrollToTop],
340
- ];
341
- },
342
- ClickedScrollToTopPill: () => [
343
- evo(model, {
344
- isFollowingTop: () => true,
345
- }),
346
- [scrollToTop],
347
- ],
348
- ScrolledMessageList: ({ scrollTop }) => {
349
- const isAtTop = scrollTop <= SCROLL_FOLLOW_THRESHOLD_PX;
350
- return isAtTop === model.isFollowingTop
351
- ? [model, []]
352
- : [evo(model, { isFollowingTop: () => isAtTop }), []];
353
- },
354
- ReceivedInspectedState: ({ model: inspectedModel, maybeMessage, changedPaths, affectedPaths, }) => [
355
- evo(model, {
356
- maybeInspectedModel: () => Option.some(inspectedModel),
357
- maybeInspectedMessage: () => maybeMessage,
358
- changedPaths: () => changedPaths,
359
- affectedPaths: () => affectedPaths,
360
- }),
361
- [],
362
- ],
363
- GotInspectorTabsMessage: ({ message: tabsMessage }) => {
364
- const [nextTabsModel, tabsCommands] = InspectorTabs.update(model.inspectorTabs,
365
- /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions */
366
- tabsMessage);
367
- return [
368
- evo(model, {
369
- inspectorTabs: () => nextTabsModel,
370
- }),
371
- Command.mapMessages(tabsCommands, innerMessage => GotInspectorTabsMessage({ message: innerMessage })),
372
- ];
373
- },
374
- ToggledTreeNode: ({ path }) => [
375
- evo(model, {
376
- expandedPaths: paths => HashSet.has(paths, path)
377
- ? HashSet.remove(paths, path)
378
- : HashSet.add(paths, path),
379
- }),
380
- [],
381
- ],
382
- ReceivedStoreUpdate: ({ entries, initCommands, initMountStarts, startIndex, isPaused, pausedAtIndex, }) => {
383
- const shouldFollowSelection = M.value(mode).pipe(M.when('TimeTravel', () => !isPaused), M.when('Inspect', () => model.isFollowingLatest), M.exhaustive);
384
- const shouldFollowScroll = M.value(mode).pipe(M.when('TimeTravel', () => !isPaused && model.isFollowingTop), M.when('Inspect', () => model.isFollowingTop), M.exhaustive);
385
- const latestIndex = Array_.match(entries, {
386
- onEmpty: () => INIT_INDEX,
387
- onNonEmpty: () => startIndex + entries.length - 1,
388
- });
389
- const nextSubmodelTags = computeSubmodelTags(entries);
390
- const isFilterStale = Option.exists(model.maybeSubmodelFilter, filterTag => !Array_.contains(nextSubmodelTags, filterTag));
391
- return [
392
- evo(model, {
393
- entries: () => entries,
394
- initCommands: () => initCommands,
395
- initMountStarts: () => initMountStarts,
396
- startIndex: () => startIndex,
397
- isPaused: () => isPaused,
398
- pausedAtIndex: () => pausedAtIndex,
399
- submodelTags: () => nextSubmodelTags,
400
- maybeSubmodelFilter: current => isFilterStale ? Option.none() : current,
401
- submodelFilterListbox: current => isFilterStale
402
- ? evo(current, {
403
- maybeSelectedItem: () => Option.some(ALL_MESSAGES_VALUE),
404
- })
405
- : current,
406
- selectedIndex: current => shouldFollowSelection ? latestIndex : current,
407
- scrubberSlider: current => {
408
- const sliderMax = entries.length;
409
- const targetSliderValue = isPaused
410
- ? hostIndexToSliderValue(pausedAtIndex, startIndex)
411
- : sliderMax;
412
- return Slider.reflectValue(Slider.reflectRange(current, { min: 0, max: sliderMax }), targetSliderValue);
413
- },
414
- }),
415
- [
416
- ...(shouldFollowSelection ? [inspectLatest] : []),
417
- ...(shouldFollowScroll ? [scrollToTop] : []),
418
- ],
419
- ];
420
- },
421
- GotSubmodelFilterMessage: ({ message: listboxMessage }) => {
422
- const [nextListboxModel, listboxCommands, maybeOutMessage] = SubmodelFilterListbox.update(model.submodelFilterListbox, listboxMessage);
423
- const mappedCommands = Command.mapMessages(listboxCommands, innerMessage => GotSubmodelFilterMessage({ message: innerMessage }));
424
- return Option.match(maybeOutMessage, {
425
- onNone: () => [
426
- evo(model, { submodelFilterListbox: () => nextListboxModel }),
427
- mappedCommands,
428
- ],
429
- onSome: M.type().pipe(M.withReturnType(), M.tagsExhaustive({
430
- Selected: ({ value }) => [
431
- evo(model, {
432
- maybeSubmodelFilter: () => Option.liftPredicate(value, String_.isNonEmpty),
433
- submodelFilterListbox: () => nextListboxModel,
434
- }),
435
- mappedCommands,
436
- ],
437
- })),
438
- });
439
- },
440
- GotScrubberSliderMessage: ({ message: sliderMessage }) => {
441
- const [nextSlider, sliderCommands, maybeOutMessage] = Slider.update(model.scrubberSlider, sliderMessage);
442
- const mappedSliderCommands = Command.mapMessages(sliderCommands, innerMessage => GotScrubberSliderMessage({ message: innerMessage }));
443
- const additionalCommands = Option.match(maybeOutMessage, {
444
- onNone: () => [],
445
- onSome: outMessage => M.value(outMessage).pipe(M.tagsExhaustive({
446
- ChangedValue: ({ value }) => {
447
- const hostIndex = sliderValueToHostIndex(value, model.startIndex);
448
- return [jumpTo(hostIndex), inspectState(hostIndex)];
449
- },
450
- })),
451
- });
452
- return [
453
- evo(model, { scrubberSlider: () => nextSlider }),
454
- [...mappedSliderCommands, ...additionalCommands],
455
- ];
456
- },
457
- }), M.tag('CompletedJump', 'CompletedResume', 'CompletedClear', 'LockedScroll', 'UnlockedScroll', 'ScrolledToTop', () => [model, []]), M.exhaustive);
458
- };
459
- // SUBSCRIPTION
460
- const makeOverlaySubscriptions = (store, shadow) => {
461
- const sliderSubscriptions = Slider.subscriptionsForRoot(() => shadow);
462
- const scrubberSubscriptions = Subscription.lift({
463
- scrubberPointer: sliderSubscriptions.dragPointer,
464
- scrubberEscape: sliderSubscriptions.dragEscape,
465
- })({
466
- toChildModel: model => model.scrubberSlider,
467
- toParentMessage: message => GotScrubberSliderMessage({ message }),
468
- });
469
- const ownSubscriptions = Subscription.make()(_entry => ({
470
- storeUpdates: Subscription.persistent(Stream.concat(Stream.fromEffect(SubscriptionRef.get(store.stateRef).pipe(Effect.map(state => ReceivedStoreUpdate(toDisplayState(state))))), Stream.map(SubscriptionRef.changes(store.stateRef), state => ReceivedStoreUpdate(toDisplayState(state))))),
471
- mobileBreakpoint: Subscription.persistent(Stream.callback(queue => Effect.acquireRelease(Effect.sync(() => {
472
- const mediaQuery = window.matchMedia(MOBILE_BREAKPOINT_QUERY);
473
- const handler = (event) => {
474
- Queue.offerUnsafe(queue, CrossedMobileBreakpoint({ isMobile: event.matches }));
475
- };
476
- mediaQuery.addEventListener('change', handler);
477
- return { mediaQuery, handler };
478
- }), ({ mediaQuery, handler }) => Effect.sync(() => mediaQuery.removeEventListener('change', handler))).pipe(Effect.flatMap(() => Effect.never)))),
479
- }));
480
- return Subscription.aggregate()(ownSubscriptions, scrubberSubscriptions);
481
- };
482
- // VIEW
483
- const indexClass = 'text-2xs text-dt-muted font-mono min-w-5';
484
- const headerButtonClass = 'dt-header-button bg-transparent border-none text-dt-muted cursor-pointer text-base font-mono transition-colors';
485
- const ROW_BASE = 'dt-row flex items-center py-1 px-1 cursor-pointer gap-1.5 transition-colors border-b';
486
- const BADGE_POSITION_CLASS = {
487
- BottomRight: 'dt-pos-br',
488
- BottomLeft: 'dt-pos-bl',
489
- TopRight: 'dt-pos-tr',
490
- TopLeft: 'dt-pos-tl',
491
- };
492
- const PANEL_POSITION_CLASS = {
493
- BottomRight: 'dt-panel-br',
494
- BottomLeft: 'dt-panel-bl',
495
- TopRight: 'dt-panel-tr',
496
- TopLeft: 'dt-panel-tl',
497
- };
498
- const makeView = (position, mode, shadow, maybeBanner) => {
499
- const h = html();
500
- const lazyTreeNode = createKeyedLazy();
501
- const lazyMessageRow = createKeyedLazy();
502
- const lazyTabContent = createKeyedLazy();
503
- const lazyMessageList = createLazy();
504
- // JSON TREE
505
- const leafValueView = (value) => M.value(value).pipe(M.when(Predicate.isNull, () => h.span([h.Key('value'), h.Class('json-null italic')], ['null'])), M.when(Predicate.isUndefined, () => h.span([h.Key('value'), h.Class('json-null italic')], ['undefined'])), M.when(Predicate.isString, stringValue => h.span([h.Key('value'), h.Class('json-string')], [`"${stringValue}"`])), M.when(Predicate.isNumber, numberValue => h.span([h.Key('value'), h.Class('json-number')], [String(numberValue)])), M.when(Predicate.isBoolean, booleanValue => h.span([h.Key('value'), h.Class('json-boolean')], [String(booleanValue)])), M.orElse(unknownValue => h.span([h.Key('value'), h.Class('json-null')], [String(unknownValue)])));
506
- // NOTE: each row-child view declares an explicit key. snabbdom's
507
- // `sameVnode` only checks `key + sel`, and foldkit element vnodes carry
508
- // `sel = tagName` with classes stored in `data.class`. Without per-role
509
- // keys, two unkeyed spans with different classes (e.g. `.json-key` and
510
- // `.diff-dot`) are sameVnode to snabbdom, so a single DOM span gets
511
- // recycled across roles as rows transition shape \u2014 and the text-node
512
- // children from the old role can leak into the new role's element.
513
- // Keying by role pins each slot to its own DOM element.
514
- const keyView = (key) => h.span([h.Key('key'), h.Class('json-key')], [`${key}:\u00a0`]);
515
- const CHEVRON_RIGHT = 'M8.25 4.5l7.5 7.5-7.5 7.5';
516
- const CHEVRON_DOWN = 'M19.5 8.25l-7.5 7.5-7.5-7.5';
517
- const arrowView = (isExpanded) => h.svg([
518
- h.Key('arrow'),
519
- h.AriaHidden(true),
520
- h.Class('json-arrow shrink-0'),
521
- h.Xmlns('http://www.w3.org/2000/svg'),
522
- h.Fill('none'),
523
- h.ViewBox('0 0 24 24'),
524
- h.StrokeWidth('2'),
525
- h.Stroke('currentColor'),
526
- ], [
527
- h.path([
528
- h.StrokeLinecap('round'),
529
- h.StrokeLinejoin('round'),
530
- h.D(isExpanded ? CHEVRON_DOWN : CHEVRON_RIGHT),
531
- ], []),
532
- ]);
533
- const tagLabelView = (tag) => h.span([h.Key('tag'), h.Class('json-tag')], [tag]);
534
- const diffDotView = h.span([h.Key('diffdot'), h.Class('diff-dot')], []);
535
- const inlineDiffDotView = h.span([h.Class('diff-dot-inline')], []);
536
- const flattenTree = ({ value, treePath, depth, key, ...shared }) => {
537
- const { rootPath, expandedPaths, changedPaths, affectedPaths, accumulator, indentRootChildren, } = shared;
538
- const isRoot = treePath === rootPath;
539
- const nodeIsExpandable = isExpandable(value);
540
- const isExpanded = nodeIsExpandable && (isRoot || HashSet.has(expandedPaths, treePath));
541
- const tag = isTagged(value) ? value._tag : '';
542
- accumulator.push({
543
- value,
544
- treePath,
545
- depth,
546
- key,
547
- isExpandable: nodeIsExpandable,
548
- isExpanded,
549
- isChanged: HashSet.has(changedPaths, treePath),
550
- isAffected: HashSet.has(affectedPaths, treePath),
551
- isRoot,
552
- tag,
553
- });
554
- if (!isExpanded) {
555
- return;
556
- }
557
- const childDepth = isRoot && !indentRootChildren ? depth : depth + 1;
558
- if (Array.isArray(value)) {
559
- value.forEach((item, arrayIndex) => flattenTree({
560
- ...shared,
561
- value: item,
562
- treePath: `${treePath}.${arrayIndex}`,
563
- depth: childDepth,
564
- key: String(arrayIndex),
565
- }));
566
- }
567
- else if (Predicate.isObject(value)) {
568
- pipe(value, Record.toEntries, Array_.filter(([entryKey]) => entryKey !== '_tag'), Array_.forEach(([entryKey, childValue]) => flattenTree({
569
- ...shared,
570
- value: childValue,
571
- treePath: `${treePath}.${entryKey}`,
572
- depth: childDepth,
573
- key: entryKey,
574
- })));
575
- }
576
- };
577
- const flatNodeView = (value, treePath, depth, key, nodeIsExpandable, isExpanded, isChanged, isAffected, isRoot, tag) => {
578
- const indent = h.Style({ paddingLeft: `${depth * TREE_INDENT_PX}px` });
579
- const hasDiffDot = isChanged || isAffected;
580
- if (!nodeIsExpandable) {
581
- return h.div([
582
- h.Key(treePath),
583
- h.Class(clsx('tree-row flex items-center gap-px font-mono text-2xs', {
584
- 'diff-changed': isChanged,
585
- })),
586
- indent,
587
- ], [
588
- ...(hasDiffDot ? [diffDotView] : []),
589
- ...(String_.isNonEmpty(key) ? [keyView(key)] : []),
590
- leafValueView(value),
591
- ]);
592
- }
593
- const preview = isExpanded
594
- ? Array.isArray(value)
595
- ? `(${value.length})`
596
- : ''
597
- : collapsedPreview(value);
598
- return h.div([
599
- h.Key(treePath),
600
- h.Class(clsx('tree-row flex items-center gap-px font-mono text-2xs', {
601
- 'tree-row-expandable cursor-pointer': !isRoot,
602
- 'diff-changed': isChanged,
603
- })),
604
- indent,
605
- ...(isRoot ? [] : [h.OnClick(ToggledTreeNode({ path: treePath }))]),
606
- ], [
607
- ...(isRoot ? [] : [arrowView(isExpanded)]),
608
- ...(!isRoot && hasDiffDot ? [diffDotView] : []),
609
- ...(String_.isNonEmpty(key) ? [keyView(key)] : []),
610
- ...(String_.isNonEmpty(tag) ? [tagLabelView(tag)] : []),
611
- h.span([h.Key('value'), h.Class('json-preview')], [preview]),
612
- ]);
613
- };
614
- const renderFlatNode = (node) => lazyTreeNode(node.treePath, flatNodeView, [
615
- node.value,
616
- node.treePath,
617
- node.depth,
618
- node.key,
619
- node.isExpandable,
620
- node.isExpanded,
621
- node.isChanged,
622
- node.isAffected,
623
- node.isRoot,
624
- node.tag,
625
- ]);
626
- const treeView = (value, rootPath, expandedPaths, changedPaths, affectedPaths, maybeRootLabel, indentRootChildren) => {
627
- const nodes = [];
628
- flattenTree({
629
- value: toInspectableValue(value),
630
- treePath: rootPath,
631
- rootPath,
632
- expandedPaths,
633
- changedPaths,
634
- affectedPaths,
635
- depth: 0,
636
- key: Option.getOrElse(maybeRootLabel, () => ''),
637
- accumulator: nodes,
638
- indentRootChildren,
639
- });
640
- return h.div([
641
- h.Class('inspector-tree flex-1 overflow-auto min-h-0 min-w-0 overscroll-none'),
642
- ], nodes.map(renderFlatNode));
643
- };
644
- const inspectedTimestamp = (model) => {
645
- const selectedIndex = selectedHistoryIndex(model);
646
- if (selectedIndex === INIT_INDEX) {
647
- return '0ms';
648
- }
649
- const baseTimestamp = pipe(model.entries, Array_.head, Option.match({
650
- onNone: () => 0,
651
- onSome: ({ timestamp }) => timestamp,
652
- }));
653
- return pipe(Array_.get(model.entries, selectedIndex - model.startIndex), Option.map(entry => {
654
- const delta = entry.timestamp - baseTimestamp;
655
- const seconds = Math.floor(delta / MILLIS_PER_SECOND);
656
- const remainingMs = delta % MILLIS_PER_SECOND;
657
- return seconds > 0
658
- ? `+${seconds}s ${remainingMs.toFixed(1)}ms`
659
- : `+${remainingMs.toFixed(1)}ms`;
660
- }), Option.getOrElse(() => ''));
661
- };
662
- const emptyInspectorView = h.div([
663
- h.Class('flex-1 flex items-center justify-center text-dt-muted text-2xs font-mono min-w-0'),
664
- ], ['Click a message to inspect']);
665
- const noMessageView = h.div([
666
- h.Class('flex-1 flex items-center justify-center text-dt-muted text-2xs font-mono min-w-0'),
667
- ], ['init: no Message']);
668
- const modelTabContent = (inspectedModel, expandedPaths, changedPaths, affectedPaths) => treeView(inspectedModel, 'root', expandedPaths, changedPaths, affectedPaths, Option.none(), true);
669
- const unwrapIfFiltered = (message, maybeSubmodelFilter) => {
670
- if (Option.isNone(maybeSubmodelFilter)) {
671
- return message;
672
- }
673
- const { value: filterTag } = maybeSubmodelFilter;
674
- let current = message;
675
- let matched = false;
676
- while (isTagged(current) && GOT_MESSAGE_PATTERN.test(current._tag)) {
677
- if (current._tag === filterTag) {
678
- matched = true;
679
- }
680
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
681
- const inner = current?.['message'];
682
- if (inner === undefined) {
683
- break;
684
- }
685
- current = inner;
686
- if (matched) {
687
- break;
688
- }
689
- }
690
- return current;
691
- };
692
- const messageTabContent = (maybeInspectedMessage, maybeSubmodelFilter, expandedPaths, timestamp) => Option.match(maybeInspectedMessage, {
693
- onNone: () => noMessageView,
694
- onSome: rawMessage => {
695
- const message = unwrapIfFiltered(rawMessage, maybeSubmodelFilter);
696
- return h.div([h.Class('flex flex-col flex-1 min-h-0 min-w-0')], [
697
- h.div([
698
- h.Class('px-2 py-1 border-b text-2xs text-dt-muted font-mono shrink-0'),
699
- ], [timestamp]),
700
- h.div([h.Class('flex flex-col flex-1 min-h-0 min-w-0 pt-1 pl-1')], [
701
- treeView(message, 'root', expandedPaths, HashSet.empty(), HashSet.empty(), Option.none(), false),
702
- ]),
703
- ]);
704
- },
705
- });
706
- const selectedHistoryIndex = (model) => {
707
- const lastIndex = Array_.match(model.entries, {
708
- onEmpty: () => INIT_INDEX,
709
- onNonEmpty: () => model.startIndex + model.entries.length - 1,
710
- });
711
- return M.value(mode).pipe(M.when('TimeTravel', () => model.isPaused ? model.pausedAtIndex : lastIndex), M.when('Inspect', () => model.selectedIndex), M.exhaustive);
712
- };
713
- const selectedCommands = (model) => {
714
- const selectedIndex = selectedHistoryIndex(model);
715
- if (selectedIndex === INIT_INDEX) {
716
- return model.initCommands;
717
- }
718
- else {
719
- return pipe(model.entries, Array_.get(selectedIndex - model.startIndex), Option.map(entry => entry.commands), Option.getOrElse(() => NO_COMMANDS));
720
- }
721
- };
722
- const flattenCommand = (command, index, expandedPaths) => {
723
- const taggedValue = Option.match(command.args, {
724
- onNone: () => ({ _tag: command.name }),
725
- onSome: argsValue => ({ ...argsValue, _tag: command.name }),
726
- });
727
- const rootPath = `command-${index}`;
728
- const nodes = [];
729
- flattenTree({
730
- value: toInspectableValue(taggedValue),
731
- treePath: rootPath,
732
- rootPath,
733
- expandedPaths,
734
- changedPaths: HashSet.empty(),
735
- affectedPaths: HashSet.empty(),
736
- depth: 0,
737
- key: '',
738
- accumulator: nodes,
739
- indentRootChildren: false,
740
- });
741
- return nodes;
742
- };
743
- const commandsTabContent = (commands, expandedPaths) => Array_.match(commands, {
744
- onEmpty: () => h.div([
745
- h.Class('flex-1 flex items-center justify-center text-dt-muted text-2xs font-mono min-w-0'),
746
- ], ['No Commands returned']),
747
- onNonEmpty: commandList => h.div([
748
- h.Class('flex flex-col flex-1 min-h-0 min-w-0 overflow-auto overscroll-none'),
749
- ], Array_.map(commandList, (command, index) => h.div([h.Class('flex items-start px-2 py-1 border-b gap-1.5')], [
750
- h.span([h.Class(indexClass)], [String(index + 1)]),
751
- h.div([h.Class('flex flex-col flex-1 min-w-0')], Array_.map(flattenCommand(command, index, expandedPaths), renderFlatNode)),
752
- ]))),
753
- });
754
- const selectedMountActivity = (model) => {
755
- const selectedIndex = selectedHistoryIndex(model);
756
- if (selectedIndex === INIT_INDEX) {
757
- return { starts: model.initMountStarts, ends: NO_MOUNTS };
758
- }
759
- else {
760
- return pipe(model.entries, Array_.get(selectedIndex - model.startIndex), Option.match({
761
- onNone: () => ({ starts: NO_MOUNTS, ends: NO_MOUNTS }),
762
- onSome: entry => ({
763
- starts: entry.mountStarts,
764
- ends: entry.mountEnds,
765
- }),
766
- }));
767
- }
768
- };
769
- const flattenMount = (mount, sectionLabel, index, expandedPaths) => {
770
- const taggedValue = Option.match(mount.args, {
771
- onNone: () => ({ _tag: mount.name }),
772
- onSome: argsValue => ({ ...argsValue, _tag: mount.name }),
773
- });
774
- const rootPath = `mount-${sectionLabel}-${index}`;
775
- const nodes = [];
776
- flattenTree({
777
- value: toInspectableValue(taggedValue),
778
- treePath: rootPath,
779
- rootPath,
780
- expandedPaths,
781
- changedPaths: HashSet.empty(),
782
- affectedPaths: HashSet.empty(),
783
- depth: 0,
784
- key: '',
785
- accumulator: nodes,
786
- indentRootChildren: false,
787
- });
788
- return nodes;
789
- };
790
- const mountListSection = (label, mounts, expandedPaths) => h.div([h.Class('flex flex-col shrink-0')], [
791
- h.div([
792
- h.Class('px-2 py-1 border-b text-2xs text-dt-muted font-mono shrink-0'),
793
- ], [label]),
794
- ...Array_.map(mounts, (mount, index) => h.div([h.Class('flex items-start px-2 py-1 border-b gap-1.5')], [
795
- h.span([h.Class(indexClass)], [String(index + 1)]),
796
- h.div([h.Class('flex flex-col flex-1 min-w-0')], Array_.map(flattenMount(mount, label, index, expandedPaths), renderFlatNode)),
797
- ])),
798
- ]);
799
- const mountsTabContent = (starts, ends, expandedPaths) => {
800
- const hasAny = Array_.isReadonlyArrayNonEmpty(starts) ||
801
- Array_.isReadonlyArrayNonEmpty(ends);
802
- if (!hasAny) {
803
- return h.div([
804
- h.Class('flex-1 flex items-center justify-center text-dt-muted text-2xs font-mono min-w-0'),
805
- ], ['No Mounts during this render']);
806
- }
807
- return h.div([
808
- h.Class('flex flex-col flex-1 min-h-0 min-w-0 overflow-auto overscroll-none'),
809
- ], [
810
- ...(Array_.isReadonlyArrayNonEmpty(starts)
811
- ? [mountListSection('Started', starts, expandedPaths)]
812
- : []),
813
- ...(Array_.isReadonlyArrayNonEmpty(ends)
814
- ? [mountListSection('Ended', ends, expandedPaths)]
815
- : []),
816
- ]);
817
- };
818
- const inspectorTabContent = (model, tab, inspectedModel) => M.value(tab).pipe(M.when('Model', () => lazyTabContent('Model', modelTabContent, [
819
- inspectedModel,
820
- model.expandedPaths,
821
- model.changedPaths,
822
- model.affectedPaths,
823
- ])), M.when('Message', () => lazyTabContent('Message', messageTabContent, [
824
- model.maybeInspectedMessage,
825
- model.maybeSubmodelFilter,
826
- model.expandedPaths,
827
- inspectedTimestamp(model),
828
- ])), M.when('Commands', () => lazyTabContent('Commands', commandsTabContent, [
829
- selectedCommands(model),
830
- model.expandedPaths,
831
- ])), M.when('Mounts', () => {
832
- const { starts, ends } = selectedMountActivity(model);
833
- return lazyTabContent('Mounts', mountsTabContent, [
834
- starts,
835
- ends,
836
- model.expandedPaths,
837
- ]);
838
- }), M.exhaustive);
839
- const inspectorPaneView = (model) => h.div([
840
- h.Class('flex flex-col border-l min-w-0 min-h-0 flex-1 dt-inspector-pane'),
841
- ], [
842
- h.submodel({
843
- slotId: model.inspectorTabs.id,
844
- model: model.inspectorTabs,
845
- view: InspectorTabs.view,
846
- viewInputs: {
847
- tabs: INSPECTOR_TABS,
848
- ariaLabel: 'Inspector tabs',
849
- toView: ({ tablist, tabs, activeIndex }) => h.div([h.Class('flex flex-col flex-1 min-h-0')], [
850
- h.div([...tablist, h.Class('flex border-b shrink-0')], tabs.map(tab => h.button([
851
- ...tab.tab,
852
- h.Class(clsx('dt-tab-button cursor-pointer text-base font-mono px-3 py-1', tab.isActive
853
- ? 'text-dt dt-tab-active'
854
- : 'text-dt-muted')),
855
- ], [h.span([], [tab.value])]))),
856
- ...tabs.map(tab => h.div([
857
- ...tab.panel,
858
- h.Class('flex flex-col flex-1 min-h-0 min-w-0'),
859
- h.Hidden(tab.index !== activeIndex),
860
- ...(tab.index === activeIndex
861
- ? []
862
- : [h.Style({ display: 'none' })]),
863
- ], [
864
- Option.match(model.maybeInspectedModel, {
865
- onNone: () => emptyInspectorView,
866
- onSome: inspectedModel => inspectorTabContent(model, tab.value, inspectedModel),
867
- }),
868
- ])),
869
- ]),
870
- },
871
- toParentMessage: message => GotInspectorTabsMessage({ message }),
872
- }),
873
- ]);
874
- // MESSAGE LIST
875
- const badgeView = (model) => h.button([
876
- h.Class(clsx('fixed bg-dt-bg text-dt cursor-pointer flex flex-col items-center justify-center font-mono outline-none dt-badge', BADGE_POSITION_CLASS[position], model.isPaused ? 'dt-badge-paused' : 'dt-badge-accent')),
877
- h.Style({ width: '22px', height: '56px', fontSize: '10px' }),
878
- h.OnClick(ClickedToggle()),
879
- ], [
880
- model.isOpen
881
- ? h.svg([
882
- h.AriaHidden(true),
883
- h.Xmlns('http://www.w3.org/2000/svg'),
884
- h.Fill('none'),
885
- h.ViewBox('0 0 24 24'),
886
- h.StrokeWidth('1.5'),
887
- h.Stroke('currentColor'),
888
- h.Style({ width: '12px', height: '12px' }),
889
- ], [
890
- h.path([
891
- h.StrokeLinecap('round'),
892
- h.StrokeLinejoin('round'),
893
- h.D('M6 18L18 6M6 6l12 12'),
894
- ], []),
895
- ])
896
- : h.div([
897
- h.Class(clsx('flex flex-col items-center gap-0.5 font-semibold tracking-wider leading-none', model.isPaused ? 'text-dt-bg' : 'text-dt-muted')),
898
- ], [h.span([], ['D']), h.span([], ['E']), h.span([], ['V'])]),
899
- ]);
900
- const headerClass = 'flex items-center justify-between px-3 py-1.5 border-b shrink-0';
901
- const actionButtonClass = 'dt-resume-button bg-transparent border-none text-dt-live cursor-pointer text-base font-mono font-medium';
902
- const statusClass = 'text-base font-mono';
903
- const clearHistoryButton = h.button([h.Class(headerButtonClass), h.OnClick(ClickedClear())], ['Clear history']);
904
- const submodelLabel = (tag) => pipe(tag, String_.replace(/^Got/, ''), String_.replace(/Message$/, ''));
905
- const CHECK_ICON = 'M4.5 12.75l6 6 9-13.5';
906
- const checkIconView = h.svg([
907
- h.AriaHidden(true),
908
- h.Class('dt-filter-check shrink-0'),
909
- h.Xmlns('http://www.w3.org/2000/svg'),
910
- h.Fill('none'),
911
- h.ViewBox('0 0 24 24'),
912
- h.StrokeWidth('2'),
913
- h.Stroke('currentColor'),
914
- ], [
915
- h.path([h.D(CHECK_ICON), h.StrokeLinecap('round'), h.StrokeLinejoin('round')], []),
916
- ]);
917
- const filterItemLabel = (item) => String_.isNonEmpty(item) ? submodelLabel(item) : 'All Messages';
918
- const ARROW_UP = 'M4.5 10.5L12 3m0 0l7.5 7.5M12 3v18';
919
- const arrowUpIconView = h.svg([
920
- h.AriaHidden(true),
921
- h.Class('dt-scroll-pill-icon shrink-0'),
922
- h.Xmlns('http://www.w3.org/2000/svg'),
923
- h.Fill('none'),
924
- h.ViewBox('0 0 24 24'),
925
- h.StrokeWidth('2'),
926
- h.Stroke('currentColor'),
927
- ], [
928
- h.path([h.D(ARROW_UP), h.StrokeLinecap('round'), h.StrokeLinejoin('round')], []),
929
- ]);
930
- const scrollToTopPillView = h.button([
931
- h.Key('scroll-pill'),
932
- h.Class('dt-scroll-pill'),
933
- h.OnClick(ClickedScrollToTopPill()),
934
- ], [
935
- arrowUpIconView,
936
- h.span([h.Class('dt-scroll-pill-text')], ['Jump to top']),
937
- ]);
938
- const submodelFilterView = (model) => {
939
- const buttonLabel = Option.match(model.maybeSubmodelFilter, {
940
- onNone: () => 'All Messages',
941
- onSome: submodelLabel,
942
- });
943
- return h.submodel({
944
- slotId: 'submodel-filter',
945
- model: model.submodelFilterListbox,
946
- view: SubmodelFilterListbox.view,
947
- viewInputs: {
948
- items: [ALL_MESSAGES_VALUE, ...model.submodelTags],
949
- itemToConfig: item => ({
950
- className: 'dt-filter-item',
951
- content: h.div([h.Class('flex items-center gap-2')], [checkIconView, h.span([], [filterItemLabel(item)])]),
952
- }),
953
- buttonContent: h.span([h.Class('flex flex-1 items-center justify-between')], [
954
- h.span([], [buttonLabel]),
955
- h.svg([
956
- h.AriaHidden(true),
957
- h.Class('json-arrow shrink-0'),
958
- h.Xmlns('http://www.w3.org/2000/svg'),
959
- h.Fill('none'),
960
- h.ViewBox('0 0 24 24'),
961
- h.StrokeWidth('2'),
962
- h.Stroke('currentColor'),
963
- ], [
964
- h.path([
965
- h.D(CHEVRON_DOWN),
966
- h.StrokeLinecap('round'),
967
- h.StrokeLinejoin('round'),
968
- ], []),
969
- ]),
970
- ]),
971
- buttonClassName: 'dt-filter-button',
972
- itemsClassName: 'dt-filter-items',
973
- className: 'dt-filter-wrapper',
974
- attributes: childAttributes([h.Key('submodel-filter')]),
975
- backdropClassName: 'dt-filter-backdrop',
976
- },
977
- toParentMessage: message => GotSubmodelFilterMessage({ message }),
978
- });
979
- };
980
- const headerView = (model) => {
981
- const { status, maybeAction } = M.value(mode).pipe(M.withReturnType(), M.when('TimeTravel', () => model.isPaused
982
- ? {
983
- status: h.span([h.Class(`${statusClass} text-dt-paused`)], [
984
- model.pausedAtIndex === INIT_INDEX
985
- ? 'Paused (init)'
986
- : `Paused (${model.pausedAtIndex + 1})`,
987
- ]),
988
- maybeAction: Option.some(h.button([h.Class(actionButtonClass), h.OnClick(ClickedResume())], ['Resume →'])),
989
- }
990
- : {
991
- status: h.span([h.Class(`${statusClass} text-dt-live font-medium`)], ['Live']),
992
- maybeAction: Option.none(),
993
- }), M.when('Inspect', () => ({
994
- status: h.span([h.Class(`${statusClass} text-dt-accent`)], [
995
- model.selectedIndex === INIT_INDEX
996
- ? 'Inspecting (init)'
997
- : `Inspecting (${model.selectedIndex + 1})`,
998
- ]),
999
- maybeAction: OptionExt.when(!model.isFollowingLatest, h.button([h.Class(actionButtonClass), h.OnClick(ClickedFollowLatest())], ['Follow Latest →'])),
1000
- })), M.exhaustive);
1001
- const maybeClearHistoryButton = OptionExt.when(!model.isPaused, clearHistoryButton);
1002
- return h.header([h.Class(headerClass)], [
1003
- status,
1004
- ...Option.toArray(maybeAction),
1005
- ...Option.toArray(maybeClearHistoryButton),
1006
- ]);
1007
- };
1008
- const initRowView = (isSelected, isPausedHere) => h.keyed('li')('init', [
1009
- h.Class(clsx(ROW_BASE, { selected: isSelected })),
1010
- h.OnClick(ClickedRow({ index: INIT_INDEX })),
1011
- ], [
1012
- ...OptionExt.when(mode === 'TimeTravel', h.span([h.Class('pause-column')], isPausedHere ? [pauseIconView] : [])).pipe(Option.toArray),
1013
- h.span([h.Class('dot-column')], []),
1014
- h.span([h.Class(indexClass)], []),
1015
- h.span([h.Class('text-base text-dt-muted font-mono')], ['init']),
1016
- ]);
1017
- const pauseIconView = h.svg([
1018
- h.AriaHidden(true),
1019
- h.Class('dt-pause-icon'),
1020
- h.Xmlns('http://www.w3.org/2000/svg'),
1021
- h.Fill('none'),
1022
- h.ViewBox('0 0 24 24'),
1023
- h.StrokeWidth('2.5'),
1024
- h.Stroke('currentColor'),
1025
- ], [
1026
- h.path([
1027
- h.StrokeLinecap('round'),
1028
- h.StrokeLinejoin('round'),
1029
- h.D('M5.75 3v18M18.25 3v18'),
1030
- ], []),
1031
- ]);
1032
- const messageRowView = (tag, absoluteIndex, isSelected, isPausedHere, timeDelta, isModelChanged) => h.keyed('li')(String(absoluteIndex), [
1033
- h.Class(clsx(ROW_BASE, { selected: isSelected })),
1034
- h.OnClick(ClickedRow({ index: absoluteIndex })),
1035
- ], [
1036
- ...OptionExt.when(mode === 'TimeTravel', h.span([h.Class('pause-column')], isPausedHere ? [pauseIconView] : [])).pipe(Option.toArray),
1037
- h.span([h.Class('dot-column')], isModelChanged ? [inlineDiffDotView] : []),
1038
- h.span([h.Class(indexClass)], [String(absoluteIndex + 1)]),
1039
- h.span([h.Class('text-base text-dt font-mono flex-1 truncate')], [tag]),
1040
- h.span([
1041
- h.Class('text-2xs text-dt-muted font-mono shrink-0 text-right min-w-5'),
1042
- ], [formatTimeDelta(timeDelta)]),
1043
- ]);
1044
- const messageListBody = (entries, startIndex, selectedIndex, isPaused, pausedAtIndex, maybeFilterTag) => {
1045
- const baseTimestamp = pipe(entries, Array_.head, Option.match({
1046
- onNone: () => 0,
1047
- onSome: ({ timestamp }) => timestamp,
1048
- }));
1049
- const isInitSelected = selectedIndex === INIT_INDEX;
1050
- const isFiltered = Option.isSome(maybeFilterTag);
1051
- const indexedEntries = pipe(entries, Array_.map((entry, arrayIndex) => ({
1052
- entry,
1053
- absoluteIndex: startIndex + arrayIndex,
1054
- })), isFiltered
1055
- ? Array_.filter(({ entry }) => Array_.contains(entry.submodelPath, maybeFilterTag.value))
1056
- : Function.identity);
1057
- const messageRows = pipe(indexedEntries, Array_.map(({ entry, absoluteIndex }) => {
1058
- const isSelected = selectedIndex === absoluteIndex;
1059
- const isPausedHere = isPaused && pausedAtIndex === absoluteIndex;
1060
- const displayTag = isFiltered
1061
- ? pipe(entry.submodelPath, Array_.findFirstIndex(Equal.equals(maybeFilterTag.value)), Option.flatMap(filterIndex => Array_.get(entry.submodelPath, Number_.increment(filterIndex))), Option.orElse(() => entry.maybeLeafTag), Option.getOrElse(() => entry.tag))
1062
- : entry.tag;
1063
- return lazyMessageRow(String(absoluteIndex), messageRowView, [
1064
- displayTag,
1065
- absoluteIndex,
1066
- isSelected,
1067
- isPausedHere,
1068
- entry.timestamp - baseTimestamp,
1069
- entry.isModelChanged,
1070
- ]);
1071
- }), Array_.reverse);
1072
- return h.ul([
1073
- h.Key('message-list'),
1074
- h.Class('message-list flex-1 overflow-y-auto min-h-0 overscroll-none'),
1075
- h.OnScroll(scrollTop => ScrolledMessageList({ scrollTop })),
1076
- ], isFiltered
1077
- ? messageRows
1078
- : [
1079
- ...messageRows,
1080
- initRowView(isInitSelected, isPaused && pausedAtIndex === INIT_INDEX),
1081
- ]);
1082
- };
1083
- const messageListView = (model) => {
1084
- const selectedIndex = selectedHistoryIndex(model);
1085
- return lazyMessageList(messageListBody, [
1086
- model.entries,
1087
- model.startIndex,
1088
- selectedIndex,
1089
- model.isPaused,
1090
- model.pausedAtIndex,
1091
- model.maybeSubmodelFilter,
1092
- ]);
1093
- };
1094
- // SCRUBBER
1095
- const scrubberPositionLabel = (model) => {
1096
- const total = String(model.entries.length).padStart(3, '0');
1097
- const current = String(model.scrubberSlider.value).padStart(3, '0');
1098
- return `${current} / ${total}`;
1099
- };
1100
- const scrubberView = (model) => h.submodel({
1101
- slotId: model.scrubberSlider.id,
1102
- model: model.scrubberSlider,
1103
- view: Slider.view,
1104
- viewInputs: {
1105
- ariaLabel: 'Session scrubber',
1106
- getTrackRoot: () => shadow,
1107
- formatValue: value => value === 0 ? 'init' : `Message ${String(value)}`,
1108
- toView: attributes => h.div([
1109
- h.Class('dt-scrubber-row flex items-center gap-3 px-3 py-2 border-t shrink-0'),
1110
- ], [
1111
- h.div([
1112
- ...attributes.root,
1113
- h.Class('dt-scrubber-control flex-1 flex items-center'),
1114
- ], [
1115
- h.div([...attributes.track, h.Class('dt-scrubber-track')], [
1116
- h.div([
1117
- ...attributes.filledTrack,
1118
- h.Class('dt-scrubber-fill'),
1119
- ], []),
1120
- h.div([...attributes.thumb, h.Class('dt-scrubber-thumb')], []),
1121
- ]),
1122
- ]),
1123
- h.span([
1124
- h.Class('dt-scrubber-position text-2xs text-dt-muted font-mono shrink-0 tabular-nums'),
1125
- ], [scrubberPositionLabel(model)]),
1126
- ]),
1127
- },
1128
- toParentMessage: message => GotScrubberSliderMessage({ message }),
1129
- });
1130
- // PANEL
1131
- const isScrubberVisible = mode === 'TimeTravel';
1132
- const panelView = (model) => h.keyed('div')('dt-panel', [
1133
- h.Class(clsx('fixed dt-panel dt-panel-wide bg-dt-bg border rounded-lg flex flex-col overflow-hidden font-mono text-dt', PANEL_POSITION_CLASS[position])),
1134
- ], [
1135
- ...Option.map(maybeBanner, banner => h.div([
1136
- h.Class('px-3 py-2 border-b text-sm text-dt-muted font-mono shrink-0 leading-snug'),
1137
- ], [banner])).pipe(Option.toArray),
1138
- headerView(model),
1139
- h.div([h.Class('flex flex-1 min-h-0 dt-content')], [
1140
- h.div([h.Class('flex flex-col min-h-0 dt-message-pane')], [
1141
- ...Array_.match(model.submodelTags, {
1142
- onEmpty: () => [],
1143
- onNonEmpty: () => [submodelFilterView(model)],
1144
- }),
1145
- ...OptionExt.when(!model.isFollowingTop, scrollToTopPillView).pipe(Option.toArray),
1146
- messageListView(model),
1147
- ]),
1148
- inspectorPaneView(model),
1149
- ]),
1150
- ...OptionExt.when(isScrubberVisible, scrubberView(model)).pipe(Option.toArray),
1151
- ]);
1152
- const interactionBlocker = h.div([h.Class('dt-interaction-blocker')], []);
1153
- return (model) => h.div([], [
1154
- ...OptionExt.when(model.isPaused && mode === 'TimeTravel', interactionBlocker).pipe(Option.toArray),
1155
- ...OptionExt.when(model.isOpen, panelView(model)).pipe(Option.toArray),
1156
- badgeView(model),
1157
- ]);
1158
- };
1159
- // CREATE
1160
- const createShadowContainer = () => {
1161
- const existingHost = document.getElementById(DEVTOOLS_HOST_ID);
1162
- if (existingHost) {
1163
- existingHost.remove();
1164
- }
1165
- const host = document.createElement('div');
1166
- host.id = DEVTOOLS_HOST_ID;
1167
- host.addEventListener('pointerdown', event => {
1168
- const activeElement = document.activeElement;
1169
- if (activeElement !== null &&
1170
- activeElement !== host &&
1171
- activeElement !== document.body) {
1172
- event.preventDefault();
1173
- }
1174
- }, { capture: true });
1175
- document.body.appendChild(host);
1176
- const shadow = host.attachShadow({ mode: 'open' });
1177
- const styleElement = document.createElement('style');
1178
- styleElement.textContent = overlayStyles;
1179
- shadow.appendChild(styleElement);
1180
- const container = document.createElement('div');
1181
- shadow.appendChild(container);
1182
- return { container, shadow };
1183
- };
1184
- export const createOverlay = (store, position, mode, maybeBanner) => Effect.gen(function* () {
1185
- const { container, shadow } = yield* Effect.acquireRelease(Effect.sync(() => createShadowContainer()), createdShadowContainer => Effect.sync(() => {
1186
- createdShadowContainer.shadow.host.remove();
1187
- }));
1188
- container.id = '__foldkit_devtools_overlay__';
1189
- const flags = Effect.gen(function* () {
1190
- const storeState = yield* SubscriptionRef.get(store.stateRef);
1191
- return {
1192
- isMobile: window.matchMedia(MOBILE_BREAKPOINT_QUERY).matches,
1193
- ...toDisplayState(storeState),
1194
- };
1195
- });
1196
- const init = (flags) => {
1197
- const sliderMax = flags.entries.length;
1198
- const initialSliderValue = flags.isPaused
1199
- ? hostIndexToSliderValue(flags.pausedAtIndex, flags.startIndex)
1200
- : sliderMax;
1201
- return [
1202
- {
1203
- isOpen: false,
1204
- ...flags,
1205
- selectedIndex: INIT_INDEX,
1206
- isFollowingLatest: true,
1207
- isFollowingTop: true,
1208
- submodelTags: computeSubmodelTags(flags.entries),
1209
- maybeSubmodelFilter: Option.none(),
1210
- submodelFilterListbox: Listbox.init({
1211
- id: SUBMODEL_FILTER_ID,
1212
- selectedItem: ALL_MESSAGES_VALUE,
1213
- }),
1214
- maybeInspectedModel: Option.none(),
1215
- maybeInspectedMessage: Option.none(),
1216
- expandedPaths: HashSet.empty(),
1217
- changedPaths: HashSet.empty(),
1218
- affectedPaths: HashSet.empty(),
1219
- inspectorTabs: Tabs.init({ id: INSPECTOR_TABS_ID }),
1220
- scrubberSlider: Slider.init({
1221
- id: SCRUBBER_SLIDER_ID,
1222
- min: 0,
1223
- max: sliderMax,
1224
- step: 1,
1225
- initialValue: initialSliderValue,
1226
- }),
1227
- },
1228
- [],
1229
- ];
1230
- };
1231
- const overlayRuntime = makeElement({
1232
- Model,
1233
- Flags,
1234
- flags,
1235
- init,
1236
- update: makeUpdate(store, shadow, mode),
1237
- view: makeView(position, mode, shadow, maybeBanner),
1238
- container,
1239
- subscriptions: makeOverlaySubscriptions(store, shadow),
1240
- devTools: false,
1241
- freezeModel: false,
1242
- });
1243
- yield* Effect.forkScoped(overlayRuntime.start());
1244
- });