@dxos/app-framework 0.8.4-main.9be5663bfe → 0.8.4-main.abd8ff62ef

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 (278) hide show
  1. package/dist/lib/browser/{capability-BBBBAPDI.mjs → capability-Q5XRXRD2.mjs} +10 -10
  2. package/dist/lib/browser/{capability-OP63CD5N.mjs → capability-V7LR4LQN.mjs} +11 -11
  3. package/dist/lib/browser/capability-V7LR4LQN.mjs.map +7 -0
  4. package/dist/lib/browser/{chunk-T3Y4AEKX.mjs → chunk-23D4SJUE.mjs} +3 -3
  5. package/dist/lib/browser/{chunk-T3Y4AEKX.mjs.map → chunk-23D4SJUE.mjs.map} +1 -1
  6. package/dist/lib/browser/{chunk-2CKCJ6PN.mjs → chunk-3JWJXGLK.mjs} +1 -1
  7. package/dist/lib/browser/{chunk-2CKCJ6PN.mjs.map → chunk-3JWJXGLK.mjs.map} +1 -1
  8. package/dist/lib/browser/{chunk-GX4TUNM6.mjs → chunk-3ZS2A3DN.mjs} +170 -226
  9. package/dist/lib/browser/chunk-3ZS2A3DN.mjs.map +7 -0
  10. package/dist/lib/browser/{chunk-I34GF4NG.mjs → chunk-45CHLTBV.mjs} +2 -2
  11. package/dist/lib/browser/chunk-5LAIGWLU.mjs +467 -0
  12. package/dist/lib/browser/chunk-5LAIGWLU.mjs.map +7 -0
  13. package/dist/lib/browser/{chunk-QSXYHXCE.mjs → chunk-66IXTIVK.mjs} +1 -1
  14. package/dist/lib/browser/{chunk-QSXYHXCE.mjs.map → chunk-66IXTIVK.mjs.map} +2 -2
  15. package/dist/lib/browser/{chunk-TGX63LTL.mjs → chunk-FJ4765WW.mjs} +1 -1
  16. package/dist/lib/browser/{chunk-TGX63LTL.mjs.map → chunk-FJ4765WW.mjs.map} +2 -2
  17. package/dist/lib/browser/chunk-G7SDBRKH.mjs +1 -0
  18. package/dist/lib/browser/chunk-JXCBZSBJ.mjs +372 -0
  19. package/dist/lib/browser/chunk-JXCBZSBJ.mjs.map +7 -0
  20. package/dist/lib/browser/chunk-MX5DKEJH.mjs +584 -0
  21. package/dist/lib/browser/chunk-MX5DKEJH.mjs.map +7 -0
  22. package/dist/lib/browser/{chunk-JKWMHZP6.mjs → chunk-WBHCSOBW.mjs} +2 -2
  23. package/dist/lib/browser/chunk-WBHCSOBW.mjs.map +7 -0
  24. package/dist/lib/browser/{chunk-FU4GAFUQ.mjs → chunk-Z55LVAGN.mjs} +80 -15
  25. package/dist/lib/browser/chunk-Z55LVAGN.mjs.map +7 -0
  26. package/dist/lib/browser/{chunk-F7FW2RK2.mjs → chunk-ZGJAZSNE.mjs} +7 -32
  27. package/dist/lib/browser/chunk-ZGJAZSNE.mjs.map +7 -0
  28. package/dist/lib/browser/cli/index.mjs +11 -27
  29. package/dist/lib/browser/cli/index.mjs.map +2 -2
  30. package/dist/lib/browser/common/activation-events.mjs +7 -7
  31. package/dist/lib/browser/common/capabilities.mjs +7 -7
  32. package/dist/lib/browser/core/activation-event.mjs +1 -1
  33. package/dist/lib/browser/core/capability.mjs +1 -1
  34. package/dist/lib/browser/core/plugin-manager.mjs +6 -4
  35. package/dist/lib/browser/core/plugin.mjs +10 -2
  36. package/dist/lib/browser/core/url-loader.mjs +13 -5
  37. package/dist/lib/browser/index.mjs +22 -18
  38. package/dist/lib/browser/index.mjs.map +3 -3
  39. package/dist/lib/browser/{invoker-capability-H5PPENOC.mjs → invoker-capability-LNX4CGIV.mjs} +12 -11
  40. package/dist/lib/browser/invoker-capability-LNX4CGIV.mjs.map +7 -0
  41. package/dist/lib/browser/meta.json +1 -1
  42. package/dist/lib/browser/testing/index.mjs +144 -27
  43. package/dist/lib/browser/testing/index.mjs.map +4 -4
  44. package/dist/lib/browser/testing/react.mjs +78 -0
  45. package/dist/lib/browser/testing/react.mjs.map +7 -0
  46. package/dist/lib/browser/ui/index.mjs +18 -14
  47. package/dist/lib/node-esm/{capability-AWBEMRYR.mjs → capability-EW5GJCI6.mjs} +10 -10
  48. package/dist/lib/node-esm/{capability-WFEG6CIZ.mjs → capability-YKBMMD53.mjs} +11 -11
  49. package/dist/lib/node-esm/capability-YKBMMD53.mjs.map +7 -0
  50. package/dist/lib/node-esm/{chunk-FKE4Z3D6.mjs → chunk-37Z53PXZ.mjs} +1 -1
  51. package/dist/lib/node-esm/{chunk-FKE4Z3D6.mjs.map → chunk-37Z53PXZ.mjs.map} +2 -2
  52. package/dist/lib/node-esm/{chunk-WZCSOX5Q.mjs → chunk-6XW6LET6.mjs} +2 -2
  53. package/dist/lib/node-esm/{chunk-URWHJQT2.mjs → chunk-D347W3KO.mjs} +7 -32
  54. package/dist/lib/node-esm/chunk-D347W3KO.mjs.map +7 -0
  55. package/dist/lib/node-esm/chunk-D5PO2WXX.mjs +373 -0
  56. package/dist/lib/node-esm/chunk-D5PO2WXX.mjs.map +7 -0
  57. package/dist/lib/node-esm/{chunk-ULUEXB7Q.mjs → chunk-HTBJU5FX.mjs} +80 -15
  58. package/dist/lib/node-esm/chunk-HTBJU5FX.mjs.map +7 -0
  59. package/dist/lib/node-esm/chunk-KM2F6GH6.mjs +468 -0
  60. package/dist/lib/node-esm/chunk-KM2F6GH6.mjs.map +7 -0
  61. package/dist/lib/node-esm/{chunk-EL3R25OQ.mjs → chunk-OZ7DZA5Z.mjs} +1 -1
  62. package/dist/lib/node-esm/{chunk-BCEOLX47.mjs → chunk-Q7XBFII4.mjs} +170 -226
  63. package/dist/lib/node-esm/chunk-Q7XBFII4.mjs.map +7 -0
  64. package/dist/lib/node-esm/{chunk-VKHGNEDB.mjs → chunk-SBS2YMPT.mjs} +3 -3
  65. package/dist/lib/node-esm/{chunk-VKHGNEDB.mjs.map → chunk-SBS2YMPT.mjs.map} +1 -1
  66. package/dist/lib/node-esm/{chunk-42KBWDE4.mjs → chunk-SDJ4B2LU.mjs} +1 -1
  67. package/dist/lib/node-esm/{chunk-42KBWDE4.mjs.map → chunk-SDJ4B2LU.mjs.map} +1 -1
  68. package/dist/lib/node-esm/{chunk-G3RTFSNG.mjs → chunk-WFSRZKBP.mjs} +2 -2
  69. package/dist/lib/node-esm/chunk-WFSRZKBP.mjs.map +7 -0
  70. package/dist/lib/node-esm/chunk-WKTLE7MG.mjs +585 -0
  71. package/dist/lib/node-esm/chunk-WKTLE7MG.mjs.map +7 -0
  72. package/dist/lib/node-esm/{chunk-ZZ7CKK6W.mjs → chunk-XOCUANHO.mjs} +1 -1
  73. package/dist/lib/node-esm/{chunk-ZZ7CKK6W.mjs.map → chunk-XOCUANHO.mjs.map} +2 -2
  74. package/dist/lib/node-esm/cli/index.mjs +11 -27
  75. package/dist/lib/node-esm/cli/index.mjs.map +2 -2
  76. package/dist/lib/node-esm/common/activation-events.mjs +7 -7
  77. package/dist/lib/node-esm/common/capabilities.mjs +7 -7
  78. package/dist/lib/node-esm/core/activation-event.mjs +1 -1
  79. package/dist/lib/node-esm/core/capability.mjs +1 -1
  80. package/dist/lib/node-esm/core/plugin-manager.mjs +6 -4
  81. package/dist/lib/node-esm/core/plugin.mjs +10 -2
  82. package/dist/lib/node-esm/core/url-loader.mjs +13 -5
  83. package/dist/lib/node-esm/index.mjs +22 -18
  84. package/dist/lib/node-esm/index.mjs.map +3 -3
  85. package/dist/lib/node-esm/{invoker-capability-S3ZA527J.mjs → invoker-capability-O4T5PHLA.mjs} +12 -11
  86. package/dist/lib/node-esm/invoker-capability-O4T5PHLA.mjs.map +7 -0
  87. package/dist/lib/node-esm/meta.json +1 -1
  88. package/dist/lib/node-esm/testing/index.mjs +144 -27
  89. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  90. package/dist/lib/node-esm/testing/react.mjs +79 -0
  91. package/dist/lib/node-esm/testing/react.mjs.map +7 -0
  92. package/dist/lib/node-esm/ui/index.mjs +18 -14
  93. package/dist/plugin/node-esm/index.mjs +480 -32
  94. package/dist/plugin/node-esm/index.mjs.map +4 -4
  95. package/dist/plugin/node-esm/meta.json +1 -1
  96. package/dist/types/src/common/capabilities.d.ts +2 -1
  97. package/dist/types/src/common/capabilities.d.ts.map +1 -1
  98. package/dist/types/src/common/operations.d.ts +1 -1
  99. package/dist/types/src/common/operations.d.ts.map +1 -1
  100. package/dist/types/src/core/activation-event.d.ts +4 -4
  101. package/dist/types/src/core/activation-event.d.ts.map +1 -1
  102. package/dist/types/src/core/capability-manager.d.ts.map +1 -1
  103. package/dist/types/src/core/capability.d.ts +2 -2
  104. package/dist/types/src/core/capability.d.ts.map +1 -1
  105. package/dist/types/src/core/index.d.ts +2 -0
  106. package/dist/types/src/core/index.d.ts.map +1 -1
  107. package/dist/types/src/core/plugin-asset-cache.d.ts +71 -0
  108. package/dist/types/src/core/plugin-asset-cache.d.ts.map +1 -0
  109. package/dist/types/src/core/plugin-manager.d.ts +51 -2
  110. package/dist/types/src/core/plugin-manager.d.ts.map +1 -1
  111. package/dist/types/src/core/plugin-manifest.d.ts +76 -0
  112. package/dist/types/src/core/plugin-manifest.d.ts.map +1 -0
  113. package/dist/types/src/core/plugin-manifest.test.d.ts +2 -0
  114. package/dist/types/src/core/plugin-manifest.test.d.ts.map +1 -0
  115. package/dist/types/src/core/plugin.d.ts +107 -6
  116. package/dist/types/src/core/plugin.d.ts.map +1 -1
  117. package/dist/types/src/core/url-loader.d.ts +90 -3
  118. package/dist/types/src/core/url-loader.d.ts.map +1 -1
  119. package/dist/types/src/helpers.d.ts.map +1 -1
  120. package/dist/types/src/plugin-operation/history/capability.d.ts.map +1 -1
  121. package/dist/types/src/plugin-operation/history/errors.d.ts +6 -6
  122. package/dist/types/src/plugin-operation/history/errors.d.ts.map +1 -1
  123. package/dist/types/src/plugin-operation/history/history-tracker.d.ts +1 -1
  124. package/dist/types/src/plugin-operation/history/history-tracker.d.ts.map +1 -1
  125. package/dist/types/src/plugin-operation/history/types.d.ts +1 -1
  126. package/dist/types/src/plugin-operation/history/types.d.ts.map +1 -1
  127. package/dist/types/src/plugin-operation/history/undo-mapping.d.ts +1 -1
  128. package/dist/types/src/plugin-operation/history/undo-mapping.d.ts.map +1 -1
  129. package/dist/types/src/plugin-operation/history/undo-registry.d.ts +1 -1
  130. package/dist/types/src/plugin-operation/history/undo-registry.d.ts.map +1 -1
  131. package/dist/types/src/plugin-operation/invoker-capability.d.ts +1 -1
  132. package/dist/types/src/plugin-operation/invoker-capability.d.ts.map +1 -1
  133. package/dist/types/src/plugin-operation/testing.d.ts +2 -1
  134. package/dist/types/src/plugin-operation/testing.d.ts.map +1 -1
  135. package/dist/types/src/plugin-runtime/capability.d.ts +1 -1
  136. package/dist/types/src/plugin-runtime/capability.d.ts.map +1 -1
  137. package/dist/types/src/testing/harness.d.ts +67 -0
  138. package/dist/types/src/testing/harness.d.ts.map +1 -0
  139. package/dist/types/src/testing/index.d.ts +1 -0
  140. package/dist/types/src/testing/index.d.ts.map +1 -1
  141. package/dist/types/src/testing/react.d.ts +27 -0
  142. package/dist/types/src/testing/react.d.ts.map +1 -0
  143. package/dist/types/src/testing/react.test.d.ts +2 -0
  144. package/dist/types/src/testing/react.test.d.ts.map +1 -0
  145. package/dist/types/src/testing/service.d.ts.map +1 -1
  146. package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
  147. package/dist/types/src/testing/withPluginManager.stories.d.ts.map +1 -1
  148. package/dist/types/src/ui/components/App/App.d.ts.map +1 -1
  149. package/dist/types/src/ui/components/App/App.stories.d.ts.map +1 -1
  150. package/dist/types/src/ui/components/Placeholder/Placeholder.d.ts +64 -0
  151. package/dist/types/src/ui/components/Placeholder/Placeholder.d.ts.map +1 -0
  152. package/dist/types/src/ui/components/Placeholder/Placeholder.stories.d.ts +19 -0
  153. package/dist/types/src/ui/components/Placeholder/Placeholder.stories.d.ts.map +1 -0
  154. package/dist/types/src/ui/components/Placeholder/index.d.ts +2 -0
  155. package/dist/types/src/ui/components/Placeholder/index.d.ts.map +1 -0
  156. package/dist/types/src/ui/components/PluginManager/PluginManagerContext.stories.d.ts.map +1 -1
  157. package/dist/types/src/ui/components/Surface/SurfaceComponent.d.ts +16 -4
  158. package/dist/types/src/ui/components/Surface/SurfaceComponent.d.ts.map +1 -1
  159. package/dist/types/src/ui/components/Surface/SurfaceComponent.stories.d.ts.map +1 -1
  160. package/dist/types/src/ui/components/Surface/SurfaceProfilerContext.d.ts.map +1 -1
  161. package/dist/types/src/ui/components/Surface/index.d.ts +16 -6
  162. package/dist/types/src/ui/components/Surface/index.d.ts.map +1 -1
  163. package/dist/types/src/ui/components/Surface/types.d.ts +110 -9
  164. package/dist/types/src/ui/components/Surface/types.d.ts.map +1 -1
  165. package/dist/types/src/ui/components/Surface/types.test.d.ts +2 -0
  166. package/dist/types/src/ui/components/Surface/types.test.d.ts.map +1 -0
  167. package/dist/types/src/ui/components/index.d.ts +1 -0
  168. package/dist/types/src/ui/components/index.d.ts.map +1 -1
  169. package/dist/types/src/ui/hooks/useApp.d.ts +29 -3
  170. package/dist/types/src/ui/hooks/useApp.d.ts.map +1 -1
  171. package/dist/types/src/ui/hooks/useCapabilities.d.ts.map +1 -1
  172. package/dist/types/src/ui/hooks/useLoading.d.ts.map +1 -1
  173. package/dist/types/src/ui/hooks/useSettingsState.d.ts.map +1 -1
  174. package/dist/types/src/vite-plugin/boot-loader/BootLoader.stories.d.ts +34 -0
  175. package/dist/types/src/vite-plugin/boot-loader/BootLoader.stories.d.ts.map +1 -0
  176. package/dist/types/src/vite-plugin/boot-loader/index.d.ts +52 -0
  177. package/dist/types/src/vite-plugin/boot-loader/index.d.ts.map +1 -0
  178. package/dist/types/src/vite-plugin/composer/index.d.ts +34 -0
  179. package/dist/types/src/vite-plugin/composer/index.d.ts.map +1 -0
  180. package/dist/types/src/vite-plugin/import-map/index.d.ts +28 -0
  181. package/dist/types/src/vite-plugin/import-map/index.d.ts.map +1 -0
  182. package/dist/types/src/vite-plugin/index.d.ts +4 -2
  183. package/dist/types/src/vite-plugin/index.d.ts.map +1 -1
  184. package/dist/types/src/vite-plugin/manifest.d.ts +37 -0
  185. package/dist/types/src/vite-plugin/manifest.d.ts.map +1 -0
  186. package/dist/types/src/vite-plugin/manifest.test.d.ts +2 -0
  187. package/dist/types/src/vite-plugin/manifest.test.d.ts.map +1 -0
  188. package/dist/types/src/vite-plugin/packages.d.ts +10 -4
  189. package/dist/types/src/vite-plugin/packages.d.ts.map +1 -1
  190. package/dist/types/tsconfig.tsbuildinfo +1 -1
  191. package/moon.yml +1 -0
  192. package/package.json +33 -59
  193. package/src/common/capabilities.ts +2 -1
  194. package/src/common/operations.ts +1 -1
  195. package/src/core/capability.ts +1 -1
  196. package/src/core/index.ts +2 -0
  197. package/src/core/plugin-asset-cache.ts +60 -0
  198. package/src/core/plugin-manager.test.ts +246 -5
  199. package/src/core/plugin-manager.ts +167 -25
  200. package/src/core/plugin-manifest.test.ts +48 -0
  201. package/src/core/plugin-manifest.ts +102 -0
  202. package/src/core/plugin.ts +135 -10
  203. package/src/core/url-loader.test.ts +104 -5
  204. package/src/core/url-loader.ts +226 -37
  205. package/src/plugin-operation/OperationPlugin.ts +2 -2
  206. package/src/plugin-operation/history/capability.ts +1 -1
  207. package/src/plugin-operation/history/history-tracker.test.ts +2 -1
  208. package/src/plugin-operation/history/history-tracker.ts +1 -1
  209. package/src/plugin-operation/history/types.ts +1 -1
  210. package/src/plugin-operation/history/undo-mapping.ts +1 -1
  211. package/src/plugin-operation/history/undo-registry.ts +1 -1
  212. package/src/plugin-operation/invoker-capability.ts +2 -1
  213. package/src/plugin-operation/testing.ts +2 -1
  214. package/src/plugin-runtime/RuntimePlugin.ts +2 -2
  215. package/src/testing/harness.ts +229 -0
  216. package/src/testing/index.ts +1 -0
  217. package/src/testing/react.test.tsx +48 -0
  218. package/src/testing/react.tsx +113 -0
  219. package/src/testing/withPluginManager.stories.tsx +1 -1
  220. package/src/ui/components/App/App.stories.tsx +1 -1
  221. package/src/ui/components/App/App.tsx +25 -2
  222. package/src/ui/components/Placeholder/Placeholder.stories.tsx +77 -0
  223. package/src/ui/components/Placeholder/Placeholder.tsx +155 -0
  224. package/src/ui/components/Placeholder/index.ts +5 -0
  225. package/src/ui/components/PluginManager/PluginManagerContext.stories.tsx +4 -2
  226. package/src/ui/components/Surface/SurfaceComponent.stories.tsx +1 -1
  227. package/src/ui/components/Surface/SurfaceComponent.tsx +83 -46
  228. package/src/ui/components/Surface/index.ts +20 -1
  229. package/src/ui/components/Surface/types.test.ts +126 -0
  230. package/src/ui/components/Surface/types.ts +164 -12
  231. package/src/ui/components/index.ts +1 -0
  232. package/src/ui/hooks/useApp.tsx +165 -41
  233. package/src/ui/hooks/useLoading.tsx +14 -6
  234. package/src/vite-plugin/boot-loader/BootLoader.stories.tsx +263 -0
  235. package/src/vite-plugin/boot-loader/boot-loader.css +294 -0
  236. package/src/vite-plugin/boot-loader/boot-loader.js +274 -0
  237. package/src/vite-plugin/boot-loader/index.ts +112 -0
  238. package/src/vite-plugin/composer/index.ts +277 -0
  239. package/src/vite-plugin/import-map/index.ts +524 -0
  240. package/src/vite-plugin/index.ts +6 -2
  241. package/src/vite-plugin/manifest.test.ts +24 -0
  242. package/src/vite-plugin/manifest.ts +50 -0
  243. package/src/vite-plugin/packages.ts +169 -10
  244. package/tsconfig.json +9 -0
  245. package/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
  246. package/dist/lib/browser/capability-OP63CD5N.mjs.map +0 -7
  247. package/dist/lib/browser/chunk-F7FW2RK2.mjs.map +0 -7
  248. package/dist/lib/browser/chunk-FU4GAFUQ.mjs.map +0 -7
  249. package/dist/lib/browser/chunk-GX4TUNM6.mjs.map +0 -7
  250. package/dist/lib/browser/chunk-JKWMHZP6.mjs.map +0 -7
  251. package/dist/lib/browser/chunk-LVJW5EFU.mjs +0 -157
  252. package/dist/lib/browser/chunk-LVJW5EFU.mjs.map +0 -7
  253. package/dist/lib/browser/chunk-RFSO3JRG.mjs +0 -1
  254. package/dist/lib/browser/chunk-WPE6AL7I.mjs +0 -905
  255. package/dist/lib/browser/chunk-WPE6AL7I.mjs.map +0 -7
  256. package/dist/lib/browser/invoker-capability-H5PPENOC.mjs.map +0 -7
  257. package/dist/lib/node-esm/capability-WFEG6CIZ.mjs.map +0 -7
  258. package/dist/lib/node-esm/chunk-4A3ZCMI3.mjs +0 -158
  259. package/dist/lib/node-esm/chunk-4A3ZCMI3.mjs.map +0 -7
  260. package/dist/lib/node-esm/chunk-BCEOLX47.mjs.map +0 -7
  261. package/dist/lib/node-esm/chunk-G3RTFSNG.mjs.map +0 -7
  262. package/dist/lib/node-esm/chunk-LQKOTNJW.mjs +0 -906
  263. package/dist/lib/node-esm/chunk-LQKOTNJW.mjs.map +0 -7
  264. package/dist/lib/node-esm/chunk-ULUEXB7Q.mjs.map +0 -7
  265. package/dist/lib/node-esm/chunk-URWHJQT2.mjs.map +0 -7
  266. package/dist/lib/node-esm/invoker-capability-S3ZA527J.mjs.map +0 -7
  267. package/dist/types/src/vite-plugin/composer-plugin.d.ts +0 -18
  268. package/dist/types/src/vite-plugin/composer-plugin.d.ts.map +0 -1
  269. package/dist/types/src/vite-plugin/import-map-plugin.d.ts +0 -16
  270. package/dist/types/src/vite-plugin/import-map-plugin.d.ts.map +0 -1
  271. package/src/vite-plugin/composer-plugin.ts +0 -128
  272. package/src/vite-plugin/import-map-plugin.ts +0 -314
  273. /package/dist/lib/browser/{capability-BBBBAPDI.mjs.map → capability-Q5XRXRD2.mjs.map} +0 -0
  274. /package/dist/lib/browser/{chunk-I34GF4NG.mjs.map → chunk-45CHLTBV.mjs.map} +0 -0
  275. /package/dist/lib/browser/{chunk-RFSO3JRG.mjs.map → chunk-G7SDBRKH.mjs.map} +0 -0
  276. /package/dist/lib/node-esm/{capability-AWBEMRYR.mjs.map → capability-EW5GJCI6.mjs.map} +0 -0
  277. /package/dist/lib/node-esm/{chunk-WZCSOX5Q.mjs.map → chunk-6XW6LET6.mjs.map} +0 -0
  278. /package/dist/lib/node-esm/{chunk-EL3R25OQ.mjs.map → chunk-OZ7DZA5Z.mjs.map} +0 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/core/plugin-manager.ts", "../../../src/core/capability-manager.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Atom, Registry } from '@effect-atom/atom-react';\nimport * as Array from 'effect/Array';\nimport * as Cause from 'effect/Cause';\nimport * as Deferred from 'effect/Deferred';\nimport * as Duration from 'effect/Duration';\nimport * as Effect from 'effect/Effect';\nimport * as Fiber from 'effect/Fiber';\nimport * as Function from 'effect/Function';\nimport * as HashSet from 'effect/HashSet';\nimport * as PubSub from 'effect/PubSub';\nimport * as Ref from 'effect/Ref';\n\nimport { runAndForwardErrors } from '@dxos/effect';\nimport { Performance } from '@dxos/effect';\nimport { BaseError } from '@dxos/errors';\nimport { log } from '@dxos/log';\n\nimport * as ActivationEvent from './activation-event';\nimport * as Capability from './capability';\nimport * as CapabilityManager from './capability-manager';\nimport * as Plugin from './plugin';\n\n/**\n * Tagged error for failures during the constructor-launched core/enabled\n * `enable()` chain. Surfaces via {@link PluginManager.activate}'s wait on\n * `_initialization` so a caller blocked on initialization gets a typed\n * failure (with the original error preserved as `cause`) instead of an\n * untyped `Error`.\n */\nexport class PluginInitializationError extends BaseError.extend(\n 'PluginInitializationError',\n 'Plugin manager initialization failed',\n) {}\n\n/**\n * Identifier denoting a Manager.\n */\nexport const ManagerTypeId: unique symbol = Symbol.for('@dxos/app-framework/Manager');\nexport type ManagerTypeId = typeof ManagerTypeId;\n\nexport type ManagerOptions = {\n pluginLoader: (id: string) => Effect.Effect<Plugin.Plugin, Error>;\n plugins?: Plugin.Plugin[];\n core?: string[];\n enabled?: string[];\n registry?: Registry.Registry;\n /**\n * Hook called when a plugin is removed via {@link PluginManager.remove}. Used by the\n * host app to clean up persisted state (e.g. evict offline-cached plugin assets).\n * Failures are logged and swallowed; removal still succeeds even if the hook fails.\n */\n onRemove?: (id: string) => Effect.Effect<void, unknown>;\n};\n\nexport type ActivationMessage = {\n event: string;\n state: 'activating' | 'activated' | 'error';\n /** Module ID when the message pertains to a specific module activation. */\n module?: string;\n error?: Error;\n};\n\n/**\n * Interface for the Plugin Manager.\n */\nexport interface PluginManager {\n readonly [ManagerTypeId]: ManagerTypeId;\n readonly activation: PubSub.PubSub<ActivationMessage>;\n readonly capabilities: CapabilityManager.CapabilityManager;\n readonly registry: Registry.Registry;\n\n readonly plugins: Atom.Atom<readonly Plugin.Plugin[]>;\n readonly core: Atom.Atom<readonly string[]>;\n readonly enabled: Atom.Atom<readonly string[]>;\n readonly modules: Atom.Atom<readonly Plugin.PluginModule[]>;\n readonly active: Atom.Atom<readonly string[]>;\n readonly eventsFired: Atom.Atom<readonly string[]>;\n readonly pendingReset: Atom.Atom<readonly string[]>;\n\n getPlugins(): readonly Plugin.Plugin[];\n getCore(): readonly string[];\n getEnabled(): readonly string[];\n getModules(): readonly Plugin.PluginModule[];\n getActive(): readonly string[];\n getEventsFired(): readonly string[];\n getPendingReset(): readonly string[];\n\n /**\n * Loads a plugin via the plugin loader and registers it without enabling it.\n * Returns the loaded plugin so callers can enable it by its canonical id\n * (which may differ from the locator used to load it, e.g. URL loaders).\n */\n add(id: string): Effect.Effect<Plugin.Plugin, Error>;\n enable(id: string): Effect.Effect<boolean, Error>;\n remove(id: string): Effect.Effect<boolean, Error>;\n disable(id: string): Effect.Effect<boolean, Error>;\n // TODO(wittjosiah): Improve error typing.\n activate(\n event: ActivationEvent.ActivationEvent | string,\n params?: { before?: string; after?: string },\n ): Effect.Effect<boolean, Error>;\n deactivate(id: string): Effect.Effect<boolean, Error>;\n reset(event: ActivationEvent.ActivationEvent | string): Effect.Effect<boolean, Error>;\n\n /**\n * Shuts down the manager by deactivating all active modules in reverse activation order,\n * clearing all capabilities, and resetting lifecycle bookkeeping.\n * Plugins, core, enabled, and modules remain intact so the manager can be reused.\n */\n shutdown(): Effect.Effect<boolean, Error>;\n}\n\n/**\n * Type guard to check if a value is a PluginManager.\n */\nexport const isManager = (value: unknown): value is PluginManager => {\n return typeof value === 'object' && value !== null && ManagerTypeId in value;\n};\n\n/**\n * Internal implementation of PluginManager.\n */\nclass ManagerImpl implements PluginManager {\n readonly [ManagerTypeId]: ManagerTypeId = ManagerTypeId;\n readonly activation = Effect.runSync(PubSub.unbounded<ActivationMessage>());\n readonly capabilities: CapabilityManager.CapabilityManager;\n readonly registry: Registry.Registry;\n\n private readonly _pluginsAtom: Atom.Writable<Plugin.Plugin[]>;\n private readonly _coreAtom: Atom.Writable<string[]>;\n private readonly _enabledAtom: Atom.Writable<string[]>;\n private readonly _modulesAtom: Atom.Writable<Plugin.PluginModule[]>;\n private readonly _activeAtom: Atom.Writable<string[]>;\n private readonly _eventsFiredAtom: Atom.Writable<string[]>;\n private readonly _pendingResetAtom: Atom.Writable<string[]>;\n private readonly _pluginLoader: ManagerOptions['pluginLoader'];\n private readonly _onRemove: ManagerOptions['onRemove'];\n private readonly _capabilities = new Map<string, Capability.Any[]>();\n private readonly _moduleMemoMap = new Map<Plugin.PluginModule['id'], Deferred.Deferred<Capability.Any[], Error>>();\n private readonly _moduleSemaphores = new Map<Plugin.PluginModule['id'], Effect.Semaphore>();\n // Coalesces concurrent `_resolveLazyPlugin` calls per plugin id. Without\n // this, two callers entering `enable(id)` before the swap completes would\n // each invoke `mod.default(options)` and produce distinct module objects,\n // defeating `_addModule`'s reference-equality dedupe and racing the\n // `_pluginsAtom` swap.\n private readonly _resolvingPlugins = new Map<string, Deferred.Deferred<Plugin.Plugin, Plugin.LazyPluginError>>();\n private readonly _activatingEvents = Effect.runSync(Ref.make<string[]>([]));\n private readonly _activatingModules = Effect.runSync(Ref.make<string[]>([]));\n private readonly _inFlightFibers = Effect.runSync(Ref.make<Array<Fiber.Fiber<unknown, unknown>>>([]));\n private readonly _shutdownSemaphore = Effect.runSync(Effect.makeSemaphore(1));\n private readonly _shuttingDown = Effect.runSync(Ref.make(false));\n // Tracks the constructor-launched core/enabled `enable()` calls so that\n // `activate` can wait for module registration before dispatching events.\n // Lazy plugins make `enable` asynchronous (a dynamic `import()` happens\n // inside it), so without this synchronization an `activate` triggered\n // immediately after `make` could fire on an empty module set. Failures\n // are wrapped in `PluginInitializationError` so awaiters get a tagged\n // error rather than the wide `Error` produced by the underlying chain.\n private readonly _initialization = Effect.runSync(Deferred.make<void, PluginInitializationError>());\n\n constructor({\n pluginLoader,\n plugins = [],\n core = plugins.map(({ meta }) => meta.id),\n enabled = [],\n registry,\n onRemove,\n }: ManagerOptions) {\n this.registry = registry ?? Registry.make();\n this.capabilities = CapabilityManager.make({\n registry: this.registry,\n });\n\n this._pluginLoader = pluginLoader;\n this._onRemove = onRemove;\n this._pluginsAtom = Atom.make(plugins).pipe(Atom.keepAlive);\n this._coreAtom = Atom.make(core).pipe(Atom.keepAlive);\n this._enabledAtom = Atom.make(enabled).pipe(Atom.keepAlive);\n this._modulesAtom = Atom.make<Plugin.PluginModule[]>([]).pipe(Atom.keepAlive);\n this._activeAtom = Atom.make<string[]>([]).pipe(Atom.keepAlive);\n this._eventsFiredAtom = Atom.make<string[]>([]).pipe(Atom.keepAlive);\n this._pendingResetAtom = Atom.make<string[]>([]).pipe(Atom.keepAlive);\n plugins.forEach((plugin) => this._addPlugin(plugin));\n // Dedupe before mapping to `enable` — `core` and `enabled` may overlap (an\n // app-supplied plugin can be in both), and concurrent `enable(id)` calls\n // for the same id are not idempotent (each would re-run the lazy resolve\n // and double-register modules). `new Set([...])` preserves first-seen\n // order which matches the natural core-before-enabled precedence.\n const initialIds = [...new Set([...core, ...enabled])];\n void Effect.all(initialIds.map((id) => this.enable(id)))\n .pipe(\n Effect.mapError((cause) => new PluginInitializationError({ cause })),\n Effect.tap(() => Deferred.succeed(this._initialization, undefined)),\n Effect.tapErrorCause((cause) => Deferred.failCause(this._initialization, cause)),\n )\n .pipe(runAndForwardErrors);\n }\n\n get plugins(): Atom.Atom<readonly Plugin.Plugin[]> {\n return this._pluginsAtom;\n }\n\n get core(): Atom.Atom<readonly string[]> {\n return this._coreAtom;\n }\n\n /**\n * Ids of plugins that are currently enabled.\n */\n get enabled(): Atom.Atom<readonly string[]> {\n return this._enabledAtom;\n }\n\n /**\n * Modules of plugins which are currently enabled.\n */\n get modules(): Atom.Atom<readonly Plugin.PluginModule[]> {\n return this._modulesAtom;\n }\n\n /**\n * Ids of modules which are currently active.\n */\n get active(): Atom.Atom<readonly string[]> {\n return this._activeAtom;\n }\n\n /**\n * Ids of events which have been fired.\n */\n get eventsFired(): Atom.Atom<readonly string[]> {\n return this._eventsFiredAtom;\n }\n\n /**\n * Ids of modules which are pending reset.\n */\n get pendingReset(): Atom.Atom<readonly string[]> {\n return this._pendingResetAtom;\n }\n\n getPlugins(): readonly Plugin.Plugin[] {\n return this._get(this._pluginsAtom);\n }\n\n getCore(): readonly string[] {\n return this._get(this._coreAtom);\n }\n\n getEnabled(): readonly string[] {\n return this._get(this._enabledAtom);\n }\n\n getModules(): readonly Plugin.PluginModule[] {\n return this._get(this._modulesAtom);\n }\n\n getActive(): readonly string[] {\n return this._get(this._activeAtom);\n }\n\n getEventsFired(): readonly string[] {\n return this._get(this._eventsFiredAtom);\n }\n\n getPendingReset(): readonly string[] {\n return this._get(this._pendingResetAtom);\n }\n\n /**\n * Adds a plugin to the manager via the plugin loader.\n * The plugin is registered but not enabled; call `enable` separately to activate it.\n * @param id The id of the plugin.\n */\n add(id: string): Effect.Effect<Plugin.Plugin, Error> {\n return Effect.gen(this, function* () {\n log('add plugin', { id });\n const plugin = yield* this._pluginLoader(id);\n this._addPlugin(plugin);\n return plugin;\n });\n }\n\n /**\n * Enables a plugin.\n * @param id The id of the plugin.\n */\n enable(id: string): Effect.Effect<boolean, Error> {\n return Effect.gen(this, function* () {\n log('enable plugin', { id });\n const stub = this._getPlugin(id);\n if (!stub) {\n return false;\n }\n\n const plugin = yield* this._resolveLazyPlugin(stub);\n\n this._update(this._enabledAtom, (enabled) => (enabled.includes(id) ? enabled : [...enabled, id]));\n\n plugin.modules.forEach((module) => {\n this._addModule(module);\n this._setPendingResetByModule(module);\n });\n\n log('pending reset', { events: [...this.getPendingReset()] });\n yield* Effect.all(\n this.getPendingReset().map((event) => this.activate(event)),\n { concurrency: 'unbounded' },\n );\n\n return true;\n });\n }\n\n /**\n * Resolves a lazy plugin stub (returned by {@link Plugin.lazy}) to its\n * loaded form and swaps it into `_pluginsAtom`. Returns the input unchanged\n * when the plugin is already resolved, so callers can `yield*` this\n * unconditionally. The lazy stub carries `meta` synchronously but its\n * `modules` list is empty until the loader resolves; the swap ensures\n * subsequent enable/disable operations see the resolved plugin.\n *\n * Concurrent calls for the same id are coalesced via `_resolvingPlugins`:\n * the first caller starts the resolution, every subsequent caller awaits\n * the same `Deferred`. On failure we publish a `lazy:<id>` error message\n * and skip the atom swap so the failure is observable to the activation\n * subscriber and a retry can be attempted.\n */\n private _resolveLazyPlugin(plugin: Plugin.Plugin): Effect.Effect<Plugin.Plugin, Plugin.LazyPluginError> {\n return Effect.gen(this, function* () {\n if (!Plugin.isLazy(plugin)) {\n return plugin;\n }\n const id = plugin.meta.id;\n\n const existing = this._resolvingPlugins.get(id);\n if (existing) {\n return yield* Deferred.await(existing);\n }\n const deferred = yield* Deferred.make<Plugin.Plugin, Plugin.LazyPluginError>();\n this._resolvingPlugins.set(id, deferred);\n\n return yield* Effect.gen(this, function* () {\n log('resolving lazy plugin', { id });\n yield* PubSub.publish(this.activation, { event: '', state: 'activating', module: `lazy:${id}` });\n const resolvedPlugin = yield* Plugin.resolveLazy(plugin);\n this._update(this._pluginsAtom, (plugins) => plugins.map((p) => (p.meta.id === id ? resolvedPlugin : p)));\n yield* PubSub.publish(this.activation, { event: '', state: 'activated', module: `lazy:${id}` });\n return resolvedPlugin;\n }).pipe(\n Effect.tapError((error) =>\n PubSub.publish(this.activation, { event: '', state: 'error', module: `lazy:${id}`, error }),\n ),\n Effect.tap((value) => Deferred.succeed(deferred, value)),\n Effect.tapErrorCause((cause) => Deferred.failCause(deferred, cause)),\n Effect.ensuring(Effect.sync(() => this._resolvingPlugins.delete(id))),\n );\n });\n }\n\n /**\n * Removes a plugin from the manager.\n * @param id The id of the plugin.\n */\n remove(id: string): Effect.Effect<boolean, Error> {\n return Effect.gen(this, function* () {\n log('remove plugin', { id });\n const disabled = yield* this.disable(id);\n if (!disabled) {\n return false;\n }\n\n this._removePlugin(id);\n if (this._onRemove) {\n this._runForkedFiber(\n this._onRemove(id).pipe(\n Effect.tapError((error) => Effect.sync(() => log.warn('plugin remove hook failed', { id, error }))),\n Effect.ignore,\n ),\n );\n }\n return true;\n });\n }\n\n /**\n * Disables a plugin.\n * @param id The id of the plugin.\n */\n disable(id: string): Effect.Effect<boolean, Error> {\n return Effect.gen(this, function* () {\n log('disable plugin', { id });\n if (this._get(this._coreAtom).includes(id)) {\n return false;\n }\n\n const plugin = this._getPlugin(id);\n if (!plugin) {\n return false;\n }\n\n const enabledIndex = this._get(this._enabledAtom).findIndex((enabled) => enabled === id);\n if (enabledIndex !== -1) {\n this._update(this._enabledAtom, (enabled) => enabled.filter((item) => item !== id));\n yield* this.deactivate(id);\n\n plugin.modules.forEach((module) => {\n this._removeModule(module.id);\n });\n }\n\n return true;\n });\n }\n\n /**\n * Activates plugins based on the activation event.\n * @param event The activation event.\n * @returns Whether the activation was successful.\n */\n activate(\n event: ActivationEvent.ActivationEvent | string,\n params?: { before?: string; after?: string },\n ): Effect.Effect<boolean, Error> {\n const key = typeof event === 'string' ? event : ActivationEvent.eventKey(event);\n return Effect.gen(this, function* () {\n if (yield* this._isShuttingDown()) {\n log('skipping activation during shutdown', { key, ...params });\n return false;\n }\n\n // Wait for the constructor's core/enabled `enable()` chain — including\n // any async dynamic imports for lazy plugins — to finish registering\n // modules. Without this, dispatching to an empty module set is the\n // observable symptom of the race.\n yield* Deferred.await(this._initialization);\n\n return yield* Effect.withFiberRuntime<boolean, Error>((fiber) =>\n this._activateEvent(key, params, fiber).pipe(\n together(\n Effect.sleep(Duration.seconds(15)).pipe(\n Effect.andThen(Effect.sync(() => log.warn('event activation is taking a long time', { event: key }))),\n ),\n ),\n Performance.addTrackEntry({\n name: typeof event === 'string' ? event : ActivationEvent.eventKey(event),\n devtools: {\n dataType: 'track-entry',\n track: 'Event Activation',\n trackGroup: 'Composer',\n color: 'primary',\n },\n }),\n ),\n );\n });\n }\n\n /**\n * Deactivates all of the modules for a plugin.\n * @param id The id of the plugin.\n * @returns Whether the deactivation was successful.\n */\n deactivate(id: string): Effect.Effect<boolean, Error> {\n return Effect.gen(this, function* () {\n const plugin = this._getPlugin(id);\n if (!plugin) {\n return false;\n }\n\n const modules = plugin.modules;\n const results = yield* Effect.all(\n modules.map((module) => this._deactivateModule(module)),\n { concurrency: 'unbounded' },\n );\n return results.every((result) => result);\n });\n }\n\n /**\n * Re-activates the modules that were activated by the event.\n * @param event The activation event.\n * @returns Whether the reset was successful.\n */\n reset(event: ActivationEvent.ActivationEvent | string): Effect.Effect<boolean, Error> {\n return Effect.gen(this, function* () {\n const key = typeof event === 'string' ? event : ActivationEvent.eventKey(event);\n log('reset', { key });\n const modules = this._getActiveModulesByEvent(key);\n const results = yield* Effect.all(\n modules.map((module) => this._deactivateModule(module)),\n { concurrency: 'unbounded' },\n );\n\n if (results.every((result) => result)) {\n return yield* this.activate(key);\n } else {\n return false;\n }\n });\n }\n\n shutdown(): Effect.Effect<boolean, Error> {\n return this._shutdownSemaphore.withPermits(1)(\n Effect.gen(this, function* () {\n yield* Ref.set(this._shuttingDown, true);\n log('shutdown');\n\n yield* this._interruptInFlightActivations();\n\n const activeIds = [...this._get(this._activeAtom)].reverse();\n const allModules = this._get(this._modulesAtom);\n const modulesToDeactivate = activeIds\n .map((id) => allModules.find((module) => module.id === id))\n .filter((module): module is Plugin.PluginModule => module != null);\n\n for (const module of modulesToDeactivate) {\n yield* this._deactivateModule(module);\n }\n\n this._set(this._eventsFiredAtom, []);\n this._set(this._pendingResetAtom, []);\n this._moduleMemoMap.clear();\n yield* Ref.set(this._activatingEvents, []);\n yield* Ref.set(this._activatingModules, []);\n\n log('shutdown complete');\n return true;\n }).pipe(Effect.ensuring(Ref.set(this._shuttingDown, false))),\n );\n }\n\n //\n // State helpers\n //\n\n private _get<T>(atom: Atom.Atom<T>): T {\n return this.registry.get(atom);\n }\n\n private _set<T>(atom: Atom.Writable<T>, value: T): void {\n this.registry.set(atom, value);\n }\n\n private _update<T>(atom: Atom.Writable<T>, updater: (current: T) => T): void {\n this._set(atom, updater(this._get(atom)));\n }\n\n private _isShuttingDown(): Effect.Effect<boolean> {\n return Ref.get(this._shuttingDown);\n }\n\n private _getPlugin(id: string): Plugin.Plugin | undefined {\n return this._get(this._pluginsAtom).find((plugin) => plugin.meta.id === id);\n }\n\n private _getActiveModules(): Plugin.PluginModule[] {\n const active = this._get(this._activeAtom);\n return this._get(this._modulesAtom).filter((module) => active.includes(module.id));\n }\n\n private _getInactiveModules(): Plugin.PluginModule[] {\n const active = this._get(this._activeAtom);\n return this._get(this._modulesAtom).filter((module) => !active.includes(module.id));\n }\n\n private _getActiveModulesByEvent(key: string): Plugin.PluginModule[] {\n return this._getActiveModules().filter((module) =>\n ActivationEvent.getEvents(module.activatesOn).map(ActivationEvent.eventKey).includes(key),\n );\n }\n\n private _getInactiveModulesByEvent(key: string): Plugin.PluginModule[] {\n return this._getInactiveModules().filter((module) =>\n ActivationEvent.getEvents(module.activatesOn).map(ActivationEvent.eventKey).includes(key),\n );\n }\n\n private _setPendingResetByModule(module: Plugin.PluginModule): void {\n const activationEvents = ActivationEvent.getEvents(module.activatesOn)\n .map(ActivationEvent.eventKey)\n .filter((key) => this._get(this._eventsFiredAtom).includes(key));\n\n const pendingReset = Array.fromIterable(new Set(activationEvents)).filter((event) => {\n const pending = this._get(this._pendingResetAtom);\n return !pending.includes(event);\n });\n if (pendingReset.length > 0) {\n log('pending reset', { events: pendingReset });\n this._update(this._pendingResetAtom, (current) => [...current, ...pendingReset]);\n }\n }\n\n private _clearPendingReset(key: string): void {\n const pendingIndex = this._get(this._pendingResetAtom).findIndex((event) => event === key);\n if (pendingIndex !== -1) {\n this._update(this._pendingResetAtom, (pending) => pending.filter((event) => event !== key));\n }\n }\n\n //\n // Fiber helpers\n //\n\n private _interruptInFlightActivations(): Effect.Effect<void> {\n return Effect.gen(this, function* () {\n const inFlightFibers = yield* Ref.get(this._inFlightFibers);\n yield* Effect.forEach(inFlightFibers, (fiber) => Fiber.interrupt(fiber), {\n concurrency: 'unbounded',\n });\n });\n }\n\n private _trackFiber(\n ref: Ref.Ref<Array<Fiber.Fiber<unknown, unknown>>>,\n fiber: Fiber.Fiber<unknown, unknown>,\n ): Effect.Effect<void> {\n return Ref.update(ref, (fibers) => [...fibers, fiber]);\n }\n\n private _untrackFiber(\n ref: Ref.Ref<Array<Fiber.Fiber<unknown, unknown>>>,\n fiber: Fiber.Fiber<unknown, unknown>,\n ): Effect.Effect<void> {\n return Ref.update(ref, (fibers) => fibers.filter((trackedFiber) => trackedFiber !== fiber));\n }\n\n /**\n * Spawns an effect on the default runtime and registers the resulting fiber in\n * `_inFlightFibers` so {@link shutdown} can interrupt it. Used from sync entry\n * points like {@link remove} where there is no enclosing Effect to fork from;\n * inside an Effect chain prefer the existing track/await/untrack pattern.\n */\n private _runForkedFiber<E>(effect: Effect.Effect<void, E>): void {\n const fiber = Effect.runFork(effect);\n Effect.runSync(this._trackFiber(this._inFlightFibers, fiber));\n Effect.runFork(Fiber.await(fiber).pipe(Effect.andThen(() => this._untrackFiber(this._inFlightFibers, fiber))));\n }\n\n //\n // Registration helpers\n //\n\n private _addPlugin(plugin: Plugin.Plugin): void {\n log('add plugin', { id: plugin.meta.id });\n // TODO(wittjosiah): Find a way to add a warning for duplicate plugins that doesn't cause log spam.\n this._update(this._pluginsAtom, (plugins) => (plugins.includes(plugin) ? plugins : [...plugins, plugin]));\n }\n\n private _removePlugin(id: string): void {\n log('remove plugin', { id });\n this._update(this._pluginsAtom, (plugins) => plugins.filter((plugin) => plugin.meta.id !== id));\n }\n\n private _addModule(module: Plugin.PluginModule): void {\n log('add module', { id: module.id });\n // TODO(wittjosiah): Find a way to add a warning for duplicate modules that doesn't cause log spam.\n this._update(this._modulesAtom, (modules) => (modules.includes(module) ? modules : [...modules, module]));\n }\n\n private _removeModule(id: string): void {\n log('remove module', { id });\n this._update(this._modulesAtom, (modules) => modules.filter((module) => module.id !== id));\n }\n\n //\n // Activation helpers\n //\n\n private _activateEvent(\n key: string,\n params: { before?: string; after?: string } | undefined,\n fiber: Fiber.Fiber<unknown, unknown>,\n ): Effect.Effect<boolean, Error> {\n return Effect.gen(this, function* () {\n yield* this._trackFiber(this._inFlightFibers, fiber);\n log('activating', { key, ...params });\n yield* Ref.update(this._activatingEvents, (activating) => Array.append(activating, key));\n this._clearPendingReset(key);\n\n const activatingEvents = yield* this._activatingEvents;\n const activatingModules = yield* this._activatingModules;\n const modules = this._getModulesForActivation(key, activatingEvents, activatingModules);\n if (modules.length === 0) {\n log('no modules to activate', { key });\n if (!this._get(this._eventsFiredAtom).includes(key)) {\n this._update(this._eventsFiredAtom, (events) => [...events, key]);\n }\n return false;\n }\n\n return yield* this._activateModulesForEvent(key, modules, activatingEvents);\n }).pipe(\n Effect.ensuring(\n Effect.all([\n this._untrackFiber(this._inFlightFibers, fiber),\n Ref.update(this._activatingEvents, (activating) => Array.filter(activating, (event) => event !== key)),\n ]),\n ),\n );\n }\n\n private _activateModulesForEvent(\n key: string,\n modules: Plugin.PluginModule[],\n activatingEvents: string[],\n ): Effect.Effect<boolean, Error> {\n const activatingModuleIds = modules.map((module) => module.id);\n return Effect.gen(this, function* () {\n yield* Ref.update(this._activatingModules, (activating) => Array.appendAll(activating, activatingModuleIds));\n\n log('activating modules', { key, modules: activatingModuleIds });\n performance.mark(`event:${key}:start`);\n yield* PubSub.publish(this.activation, { event: key, state: 'activating' });\n\n yield* this._activateRelatedEvents(key, this._getBeforeEvents(modules, activatingEvents), 'before');\n\n const capabilities = yield* this._loadCapabilitiesForModules(key, modules);\n yield* this._contributeCapabilitiesForModules(modules, capabilities);\n\n yield* this._activateRelatedEvents(key, this._getAfterEvents(modules, activatingEvents), 'after');\n\n if (!this._get(this._eventsFiredAtom).includes(key)) {\n this._update(this._eventsFiredAtom, (events) => [...events, key]);\n }\n\n performance.mark(`event:${key}:end`);\n performance.measure(`event:${key}`, `event:${key}:start`, `event:${key}:end`);\n yield* PubSub.publish(this.activation, { event: key, state: 'activated' });\n log('activated', { key });\n\n return true;\n }).pipe(\n Effect.ensuring(\n Ref.update(this._activatingModules, (activating) =>\n Array.filter(activating, (module) => !activatingModuleIds.includes(module)),\n ),\n ),\n );\n }\n\n private _getModulesForActivation(\n key: string,\n activatingEvents: string[],\n activatingModules: string[],\n ): Plugin.PluginModule[] {\n return this._getInactiveModulesByEvent(key).filter((module) => {\n const allOf = ActivationEvent.isAllOf(module.activatesOn);\n if (!allOf) {\n return true;\n }\n\n // Check to see if all of the events in the `allOf` have been fired.\n // An event can be considered \"fired\" if it is in the `eventsFired` list or if it is currently being activated.\n const events = ActivationEvent.getEvents(module.activatesOn).filter(\n (event) => ActivationEvent.eventKey(event) !== key,\n );\n return (\n events.every(\n (event) =>\n this._get(this._eventsFiredAtom).includes(ActivationEvent.eventKey(event)) ||\n activatingEvents.includes(ActivationEvent.eventKey(event)),\n ) && !activatingModules.includes(module.id)\n );\n });\n }\n\n private _getBeforeEvents(\n modules: Plugin.PluginModule[],\n activatingEvents: string[],\n ): ActivationEvent.ActivationEvent[] {\n return Function.pipe(\n modules,\n Array.flatMap((module) => module.firesBeforeActivation ?? []),\n HashSet.fromIterable,\n HashSet.toValues,\n Array.filter((event) => !activatingEvents.includes(ActivationEvent.eventKey(event))),\n );\n }\n\n private _getAfterEvents(\n modules: Plugin.PluginModule[],\n activatingEvents: string[],\n ): ActivationEvent.ActivationEvent[] {\n return Function.pipe(\n modules,\n Array.flatMap((module) => module.firesAfterActivation ?? []),\n HashSet.fromIterable,\n HashSet.toValues,\n Array.filter((event) => !activatingEvents.includes(ActivationEvent.eventKey(event))),\n );\n }\n\n private _activateRelatedEvents(\n key: string,\n events: ActivationEvent.ActivationEvent[],\n phase: 'before' | 'after',\n ): Effect.Effect<void, Error> {\n const logLabel = phase === 'before' ? 'firesBeforeActivation' : 'firesAfterActivation';\n const eventKey = phase === 'before' ? 'beforeEvents' : 'afterEvents';\n return Function.pipe(\n events,\n Array.map((event) => this.activate(event, phase === 'before' ? { before: key } : { after: key })),\n Effect.allWith({ concurrency: 'unbounded' }),\n together(\n Effect.sleep(Duration.seconds(10)).pipe(\n Effect.andThen(\n Effect.sync(() =>\n log.warn(`${logLabel} is taking a long time`, {\n event: key,\n [eventKey]: events.map(ActivationEvent.eventKey),\n }),\n ),\n ),\n ),\n ),\n Effect.asVoid,\n );\n }\n\n //\n // Module lifecycle helpers\n //\n\n private _loadCapabilitiesForModules(\n key: string,\n modules: Plugin.PluginModule[],\n ): Effect.Effect<Capability.Any[][], Error> {\n return Function.pipe(\n modules,\n Array.map((mod) => this._loadModule(mod, key)),\n Effect.allWith({ concurrency: 'unbounded' }),\n Effect.catchAll((error) => {\n return Effect.gen(this, function* () {\n yield* PubSub.publish(this.activation, { event: key, state: 'error', error });\n return yield* Effect.fail(error);\n });\n }),\n );\n }\n\n private _contributeCapabilitiesForModules(\n modules: Plugin.PluginModule[],\n capabilities: Capability.Any[][],\n ): Effect.Effect<void, Error> {\n return Function.pipe(\n modules,\n Array.zip(capabilities),\n Array.map(([module, capabilitySet]) => this._contributeCapabilities(module, capabilitySet)),\n // TODO(wittjosiah): This currently can't be run in parallel, and inserting\n // any yield between contributions (`Effect.yieldNow()`, `Effect.sleep(0)`)\n // races the `allOf` activation-event resolver — observed as a System\n // Error dialog on warm reloads. Contributions must stay strictly\n // synchronous within an event; React paint slots have to be found at\n // event boundaries higher up the call chain.\n Effect.all,\n Effect.asVoid,\n );\n }\n\n private _getModuleSemaphore(moduleId: Plugin.PluginModule['id']): Effect.Semaphore {\n let semaphore = this._moduleSemaphores.get(moduleId);\n if (!semaphore) {\n semaphore = Effect.runSync(Effect.makeSemaphore(1));\n this._moduleSemaphores.set(moduleId, semaphore);\n }\n return semaphore;\n }\n\n // `parentEvent` is the activation event that first triggered this module\n // load — included in `activating`/`activated` PubSub messages so subscribers\n // (e.g. the boot loader's status listener) can associate a module with its\n // triggering event in the trace. The same module may be referenced by\n // multiple events, but module loads are memoized via `_moduleMemoMap`, so\n // only the first event to need it will appear here; later events await the\n // cached deferred without re-publishing.\n private _loadModule = (module: Plugin.PluginModule, parentEvent: string): Effect.Effect<Capability.Any[], Error> =>\n Effect.gen(this, function* () {\n const semaphore = this._getModuleSemaphore(module.id);\n\n // Atomically check-and-set under per-module semaphore to prevent race conditions.\n const deferredToAwait = yield* Effect.gen(this, function* () {\n const existing = this._moduleMemoMap.get(module.id);\n if (existing) {\n return existing;\n }\n\n // First caller - create deferred, store it, and start loading in background.\n const deferred = yield* Deferred.make<Capability.Any[], Error>();\n this._moduleMemoMap.set(module.id, deferred);\n\n const loadEffect = Effect.gen(this, function* () {\n log('loading module', { module: module.id, parentEvent });\n performance.mark(`module:${module.id}:start`);\n yield* PubSub.publish(this.activation, { event: parentEvent, state: 'activating', module: module.id });\n const [duration, capabilities] = yield* module\n .activate()\n .pipe(\n Effect.provideService(Capability.Service, this.capabilities),\n Effect.provideService(Plugin.Service, this),\n Effect.timed,\n );\n const normalized = capabilities == null ? [] : Array.isArray(capabilities) ? capabilities : [capabilities];\n const elapsed = Duration.toMillis(duration);\n performance.mark(`module:${module.id}:end`);\n performance.measure(`module:${module.id}`, `module:${module.id}:start`, `module:${module.id}:end`);\n yield* PubSub.publish(this.activation, { event: parentEvent, state: 'activated', module: module.id });\n log('loaded module', {\n module: module.id,\n parentEvent,\n elapsed,\n failed: false,\n });\n return normalized as Capability.Any[];\n }).pipe(\n Effect.withSpan('PluginManager._loadModule'),\n together(\n Effect.sleep(Duration.seconds(10)).pipe(\n Effect.andThen(\n Effect.sync(() => log.warn(`module is taking a long time to activate`, { module: module.id })),\n ),\n ),\n ),\n Performance.addTrackEntry({\n name: module.id,\n devtools: {\n dataType: 'track-entry',\n track: 'Module Activation',\n trackGroup: 'Composer',\n color: 'primary',\n },\n }),\n );\n\n // Fork the load to run in background, completing the deferred when done.\n const fiber = yield* Effect.forkDaemon(\n loadEffect.pipe(\n Effect.tap((result) => Deferred.succeed(deferred, result)),\n Effect.catchAllCause((cause) => {\n const error = Cause.squash(cause);\n log.error('module failed to activate', {\n module: module.id,\n error: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n isDefect: !Cause.isFailure(cause),\n });\n return Deferred.fail(deferred, error instanceof Error ? error : new Error(String(error)));\n }),\n ),\n );\n yield* this._trackFiber(this._inFlightFibers, fiber);\n yield* Effect.forkDaemon(\n Fiber.await(fiber).pipe(Effect.andThen(() => this._untrackFiber(this._inFlightFibers, fiber))),\n );\n\n return deferred;\n }).pipe(semaphore.withPermits(1));\n\n // Wait for result outside the semaphore so multiple waiters can proceed concurrently.\n return yield* Deferred.await(deferredToAwait);\n });\n\n private _contributeCapabilities(\n module: Plugin.PluginModule,\n capabilities: Capability.Any[],\n ): Effect.Effect<void, Error> {\n return Effect.gen(this, function* () {\n capabilities.forEach((capability) => {\n this.capabilities.contribute({ module: module.id, ...capability });\n });\n this._update(this._activeAtom, (active) => [...active, module.id]);\n this._capabilities.set(module.id, capabilities);\n });\n }\n\n private _deactivateModule(module: Plugin.PluginModule): Effect.Effect<boolean, Error> {\n return Effect.gen(this, function* () {\n const id = module.id;\n log('deactivating', { id });\n this._moduleMemoMap.delete(id);\n\n const capabilities = this._capabilities.get(id);\n if (capabilities) {\n for (const capability of capabilities) {\n this.capabilities.remove(capability.interface, capability.implementation);\n const program = capability.deactivate?.() ?? Effect.succeed(undefined);\n yield* program;\n }\n this._capabilities.delete(id);\n }\n\n const activeIndex = this._get(this._activeAtom).findIndex((event) => event === id);\n if (activeIndex !== -1) {\n this._update(this._activeAtom, (active) => active.filter((event) => event !== id));\n }\n\n log('deactivated', { id });\n return true;\n });\n }\n}\n\n/**\n * Creates a new Plugin Manager instance.\n */\nexport const make = (options: ManagerOptions): PluginManager => new ManagerImpl(options);\n\n/**\n * Runs an effect concurrently with another effect.\n * If the first effect completes, the second effect is interrupted.\n */\n// TODO(dmaretskyi): Effect.race > Effect.asVoid\nconst together =\n <R1>(togetherEffect: Effect.Effect<void, never, R1>) =>\n <A, E, R2>(effect: Effect.Effect<A, E, R2>): Effect.Effect<A, E, R1 | R2> =>\n Effect.gen(function* () {\n const togetherFiber = yield* Effect.fork(togetherEffect);\n const result = yield* effect;\n yield* Fiber.interrupt(togetherFiber);\n return result;\n });\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Atom, type Registry } from '@effect-atom/atom-react';\nimport * as Deferred from 'effect/Deferred';\nimport * as Effect from 'effect/Effect';\n\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport type * as Capability from './capability';\n\ntype CapabilityEntry<T> = {\n moduleId: string;\n implementation: T;\n};\n\n/**\n * Options for creating a capability manager.\n * @internal\n */\nexport type CapabilityManagerOptions = {\n registry: Registry.Registry;\n};\n\n/**\n * Interface for the Capability Manager.\n * Provides methods for contributing, removing, and accessing capabilities.\n */\nexport interface CapabilityManager {\n contribute<T>(args: { module: string; interface: Capability.InterfaceDef<T>; implementation: T }): void;\n\n remove<T>(interfaceDef: Capability.InterfaceDef<T>, implementation: T): void;\n\n /**\n * Get the Atom reference to the available capabilities for a given interface.\n * Primarily useful for deriving other Atom values based on the capabilities or\n * for subscribing to changes in the capabilities.\n * @returns An atom reference to the available capabilities.\n */\n atom<T>(interfaceDef: Capability.InterfaceDef<T>): Atom.Atom<T[]>;\n\n /**\n * Get capabilities from the capability manager.\n * @returns An array of capabilities.\n */\n getAll<T>(interfaceDef: Capability.InterfaceDef<T>): T[];\n\n /**\n * Requests a single capability from the capability manager.\n * @returns The capability.\n * @throws If no capability is found.\n */\n get<T>(interfaceDef: Capability.InterfaceDef<T>): T;\n\n /**\n * Waits for a capability to be available.\n * @returns The capability.\n */\n waitFor<T>(interfaceDef: Capability.InterfaceDef<T>): Effect.Effect<T, Error>;\n\n /**\n * Get capabilities grouped by the module that contributed them.\n * @returns An atom containing a record from module ID to capability implementations.\n */\n atomByModule<T>(interfaceDef: Capability.InterfaceDef<T>): Atom.Atom<Record<string, T[]>>;\n}\n\n/**\n * Internal implementation of CapabilityManager.\n */\nclass CapabilityManagerImpl implements CapabilityManager {\n private readonly _registry: Registry.Registry;\n\n private readonly _capabilityEntries = Atom.family<string, Atom.Writable<CapabilityEntry<unknown>[]>>(() => {\n return Atom.make<CapabilityEntry<unknown>[]>([]).pipe(Atom.keepAlive);\n });\n\n readonly _capabilities = Atom.family<string, Atom.Atom<unknown[]>>((id: string) => {\n return Atom.make((get) => {\n const current = get(this._capabilityEntries(id));\n return current.map((c) => c.implementation);\n }).pipe(Atom.keepAlive);\n });\n\n readonly _capabilitiesByModule = Atom.family<string, Atom.Atom<Record<string, unknown[]>>>((id: string) => {\n return Atom.make((get) => {\n const entries = get(this._capabilityEntries(id));\n const result: Record<string, unknown[]> = {};\n for (const entry of entries) {\n (result[entry.moduleId] ??= []).push(entry.implementation);\n }\n return result;\n }).pipe(Atom.keepAlive);\n });\n\n readonly _capability = Atom.family<string, Atom.Atom<unknown>>((id: string) => {\n return Atom.make((get) => {\n const current = get(this._capabilities(id));\n invariant(current.length > 0, `No capability found for ${id}`);\n return current[0];\n });\n });\n\n constructor({ registry }: CapabilityManagerOptions) {\n this._registry = registry;\n }\n\n contribute<T>({\n module: moduleId,\n interface: interfaceDef,\n implementation,\n }: {\n module: string;\n interface: Capability.InterfaceDef<T>;\n implementation: T;\n }): void {\n const current = this._registry.get(this._capabilityEntries(interfaceDef.identifier));\n const isDuplicate = current.some((c) => c.moduleId === moduleId && c.implementation === implementation);\n if (isDuplicate) {\n log('capability already contributed, skipping', { id: interfaceDef.identifier, moduleId });\n return;\n }\n\n const entry: CapabilityEntry<T> = { moduleId, implementation };\n this._registry.set(this._capabilityEntries(interfaceDef.identifier), [...current, entry]);\n log('capability contributed', {\n id: interfaceDef.identifier,\n moduleId,\n count: current.length,\n });\n }\n\n remove<T>(interfaceDef: Capability.InterfaceDef<T>, implementation: T): void {\n const current = this._registry.get(this._capabilityEntries(interfaceDef.identifier));\n if (current.length === 0) {\n return;\n }\n\n const next = current.filter((c) => c.implementation !== implementation);\n if (next.length !== current.length) {\n this._registry.set(this._capabilityEntries(interfaceDef.identifier), next);\n log('capability removed', { id: interfaceDef.identifier, count: current.length });\n } else {\n log.warn('capability not removed', { id: interfaceDef.identifier });\n }\n }\n\n atom<T>(interfaceDef: Capability.InterfaceDef<T>): Atom.Atom<T[]> {\n // NOTE: This the type-checking for capabilities is done at the time of contribution.\n return this._capabilities(interfaceDef.identifier) as Atom.Atom<T[]>;\n }\n\n getAll<T>(interfaceDef: Capability.InterfaceDef<T>): T[] {\n return this._registry.get(this.atom(interfaceDef));\n }\n\n get<T>(interfaceDef: Capability.InterfaceDef<T>): T {\n const capabilities = this.getAll(interfaceDef);\n invariant(capabilities.length > 0, `No capability found for ${interfaceDef.identifier}`);\n return capabilities[0];\n }\n\n waitFor<T>(interfaceDef: Capability.InterfaceDef<T>): Effect.Effect<T, Error> {\n return Effect.gen(this, function* () {\n const [capability] = this.getAll(interfaceDef);\n if (capability) {\n return capability;\n }\n\n const deferred = yield* Deferred.make<T, Error>();\n const cancel = this._registry.subscribe(this.atom(interfaceDef), (capabilities) => {\n if (capabilities.length > 0) {\n Effect.runSync(Deferred.succeed(deferred, capabilities[0]));\n }\n });\n const result = yield* Deferred.await(deferred);\n cancel();\n return result;\n });\n }\n\n atomByModule<T>(interfaceDef: Capability.InterfaceDef<T>): Atom.Atom<Record<string, T[]>> {\n return this._capabilitiesByModule(interfaceDef.identifier) as Atom.Atom<Record<string, T[]>>;\n }\n}\n\n/**\n * Creates a new Capability Manager instance.\n */\nexport const make = (options: CapabilityManagerOptions): CapabilityManager => new CapabilityManagerImpl(options);\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;cAAAA;;AAIA,SAASC,QAAAA,OAAM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,eAAA,aAAOkG,OAAAA,WAAAA,WAAAA,WAAAA,cAAAA;AACT,gBAAA,UAAA,WAAA,aAAA,KAAA,gBAAA,MAAA;AACI,iBAACvJ;QACP;AAEA,aAAMwJ,cAAc,OAAU,EAAA;MAC9B;YACE,cAAa,KAAK7J,KAAAA,KAAa,WAAY8J,EAAAA,UAAa,CAAC,UAAC7G,UAAUA,EAAUT;AAChF,UAAA,gBAAA,IAAA;AAEI,aAAA,QAAA,KAAe,aAAA,CAAA,WAAA,OAAA,OAAA,CAAA,UAAA,UAAA,EAAA,CAAA;;AAAK,MAAAD,KAAA,eAAA;QACxB;MACF,GAAA,EAAA,YAAA,YAAA,GAAAhD,eAAA,GAAA,KAAA,GAAA,KAAA,CAAA;AACF,aAAA;IACF,CAAA;EAEA;;;eAeM,CAAMwK,mBAAgBC,CAAAA,WAAAA,YAAAA,aAAAA;AACtB,QAAA,gBAAsB,OAACC,aAAAA,cAAAA;AACvB,QAAA,SAAOF,OAAAA;AACT,SAAA,gBAAA,aAAA;;;",
6
+ "names": ["make", "Atom", "Registry", "Array", "Cause", "Deferred", "Duration", "Effect", "Fiber", "Function", "HashSet", "PubSub", "Ref", "runAndForwardErrors", "Performance", "BaseError", "log", "make", "Atom", "Deferred", "Effect", "invariant", "log", "_capabilityEntries", "family", "_capabilities", "id", "current", "c", "pipe", "keepAlive", "_capabilitiesByModule", "get", "result", "entry", "entries", "_capability", "length", "contribute", "moduleId", "isDuplicate", "implementation", "interfaceDef", "count", "remove", "_registry", "set", "identifier", "atom", "getAll", "capabilities", "waitFor", "capability", "deferred", "runSync", "cancel", "atomByModule", "__dxlog_file", "activation", "Effect", "capabilities", "registry", "_pluginsAtom", "_coreAtom", "_enabledAtom", "_modulesAtom", "_activeAtom", "_eventsFiredAtom", "_pendingResetAtom", "_pluginLoader", "_onRemove", "_capabilities", "_moduleMemoMap", "_moduleSemaphores", "Map", "_activatingModules", "runSync", "_inFlightFibers", "make", "_shutdownSemaphore", "makeSemaphore", "_shuttingDown", "CapabilityManager", "Atom", "enabled", "pipe", "keepAlive", "plugins", "plugin", "_addPlugin", "core", "tap", "Deferred", "succeed", "_initialization", "undefined", "tapErrorCause", "failCause", "getPlugins", "getCore", "getEnabled", "getModules", "getActive", "getEventsFired", "getPendingReset", "log", "id", "modules", "_setPendingResetByModule", "concurrency", "isLazy", "existing", "deferred", "module", "resolvedPlugin", "event", "error", "value", "disabled", "_removePlugin", "_runForkedFiber", "enabledIndex", "filter", "item", "deactivate", "forEach", "_removeModule", "gen", "_isShuttingDown", "key", "Performance", "addTrackEntry", "name", "devtools", "dataType", "track", "trackGroup", "color", "every", "results", "map", "shutdown", "_interruptInFlightActivations", "activeIds", "_get", "reverse", "allModules", "modulesToDeactivate", "_deactivateModule", "Ref", "_activatingEvents", "set", "_set", "_update", "atom", "updater", "_getPlugin", "_getActiveModules", "_getInactiveModules", "_getActiveModulesByEvent", "_getInactiveModulesByEvent", "Array", "fromIterable", "includes", "pendingReset", "length", "current", "_clearPendingReset", "pendingIndex", "pending", "inFlightFibers", "_trackFiber", "fibers", "fiber", "_untrackFiber", "await", "meta", "_addModule", "activatingEvents", "activatingModules", "_getModulesForActivation", "events", "_activateModulesForEvent", "activating", "activatingModuleIds", "performance", "mark", "publish", "_contributeCapabilitiesForModules", "_activateRelatedEvents", "PubSub", "ensuring", "update", "ActivationEvent", "allOf", "_getBeforeEvents", "_getAfterEvents", "phase", "after", "together", "sleep", "eventKey", "catchAll", "_getModuleSemaphore", "moduleId", "semaphore", "deferredToAwait", "loadEffect", "parentEvent", "duration", "elapsed", "failed", "normalized", "withSpan", "stack", "isDefect", "isFailure", "cause", "withPermits", "_contributeCapabilities", "capability", "get", "program", "activeIndex", "active", "result", "effect", "togetherFiber"]
7
+ }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  activation_event_exports
3
- } from "./chunk-QSXYHXCE.mjs";
3
+ } from "./chunk-66IXTIVK.mjs";
4
4
  import {
5
5
  __export
6
6
  } from "./chunk-J5LGTIGS.mjs";
@@ -31,4 +31,4 @@ export {
31
31
  ManagedRuntimeReady,
32
32
  activation_events_exports
33
33
  };
34
- //# sourceMappingURL=chunk-I34GF4NG.mjs.map
34
+ //# sourceMappingURL=chunk-45CHLTBV.mjs.map
@@ -0,0 +1,467 @@
1
+ import {
2
+ PluginManagerProvider,
3
+ topologicalSort,
4
+ usePluginManager
5
+ } from "./chunk-MX5DKEJH.mjs";
6
+ import {
7
+ PluginManagerContext
8
+ } from "./chunk-FJ4765WW.mjs";
9
+ import {
10
+ capabilities_exports
11
+ } from "./chunk-WBHCSOBW.mjs";
12
+ import {
13
+ activation_events_exports
14
+ } from "./chunk-45CHLTBV.mjs";
15
+ import {
16
+ plugin_manager_exports
17
+ } from "./chunk-3ZS2A3DN.mjs";
18
+
19
+ // src/ui/components/App/App.tsx
20
+ import React2, { useEffect as useEffect3 } from "react";
21
+
22
+ // src/ui/hooks/useApp.tsx
23
+ import { RegistryContext } from "@effect-atom/atom-react";
24
+ import * as Effect from "effect/Effect";
25
+ import * as Fiber from "effect/Fiber";
26
+ import * as PubSub from "effect/PubSub";
27
+ import * as Queue from "effect/Queue";
28
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
29
+ import { runAndForwardErrors } from "@dxos/effect";
30
+ import { invariant } from "@dxos/invariant";
31
+ import { log } from "@dxos/log";
32
+ import { ErrorBoundary, ErrorFallback } from "@dxos/react-error-boundary";
33
+ import { useAsyncEffect, useDefaultValue } from "@dxos/react-hooks";
34
+ import { ContextProtocolProvider } from "@dxos/web-context-react";
35
+ var __dxlog_file = "/__w/dxos/dxos/packages/sdk/app-framework/src/ui/hooks/useApp.tsx";
36
+ var ENABLED_KEY = "org.dxos.app-framework.enabled";
37
+ var useApp = ({ pluginManager, pluginLoader: pluginLoaderProp, onPluginRemove, plugins: pluginsProp, core: coreProp, defaults: defaultsProp, setupEvents: setupEventsProp, placeholder, fallback = ErrorFallback, cacheEnabled = false, safeMode = false, debounce = 0, timeout = 3e4 }) => {
38
+ const plugins = useDefaultValue(pluginsProp, () => []);
39
+ const core = useDefaultValue(coreProp, () => plugins.map(({ meta }) => meta.id));
40
+ const defaults = useDefaultValue(defaultsProp, () => []);
41
+ const setupEvents = useDefaultValue(setupEventsProp, () => []);
42
+ const pluginLoader = useMemo(() => pluginLoaderProp ?? ((id) => Effect.sync(() => {
43
+ const plugin = plugins.find((plugin2) => plugin2.meta.id === id);
44
+ invariant(plugin, `Plugin not found: ${id}`, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 52, S: void 0, A: ["plugin", "`Plugin not found: ${id}`"] });
45
+ return plugin;
46
+ })), [
47
+ pluginLoaderProp,
48
+ plugins
49
+ ]);
50
+ const readyRef = useRef(false);
51
+ const [ready, setReady] = useState(false);
52
+ const errorRef = useRef(null);
53
+ const [error, setError] = useState(null);
54
+ const [startupProgress, setStartupProgress] = useState({
55
+ activated: 0,
56
+ total: 0,
57
+ progress: 0
58
+ });
59
+ const cached = useMemo(() => JSON.parse(localStorage.getItem(ENABLED_KEY) ?? "[]"), []);
60
+ const enabled = useMemo(() => safeMode ? [] : cacheEnabled && cached.length > 0 ? cached : defaults, [
61
+ safeMode,
62
+ cacheEnabled,
63
+ cached,
64
+ defaults
65
+ ]);
66
+ const isExternalManager = !!pluginManager;
67
+ const manager = useMemo(() => {
68
+ const mgr = pluginManager ?? plugin_manager_exports.make({
69
+ pluginLoader,
70
+ plugins,
71
+ core,
72
+ enabled,
73
+ onRemove: onPluginRemove
74
+ });
75
+ log("useApp: useMemo created/reused manager", {
76
+ provided: !!pluginManager
77
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 84, S: void 0 });
78
+ return mgr;
79
+ }, [
80
+ pluginManager,
81
+ pluginLoader,
82
+ plugins,
83
+ core,
84
+ enabled,
85
+ onPluginRemove
86
+ ]);
87
+ useEffect(() => {
88
+ if (!cacheEnabled) {
89
+ return;
90
+ }
91
+ return manager.registry.subscribe(manager.enabled, (value) => {
92
+ localStorage.setItem(ENABLED_KEY, JSON.stringify(value));
93
+ });
94
+ }, [
95
+ cacheEnabled,
96
+ manager
97
+ ]);
98
+ useEffect(() => {
99
+ setupDevtools(manager);
100
+ }, [
101
+ manager
102
+ ]);
103
+ useAsyncEffect(async () => {
104
+ log("useApp: effect mount", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 113, S: void 0 });
105
+ manager.capabilities.contribute({
106
+ interface: capabilities_exports.PluginManager,
107
+ implementation: manager,
108
+ module: "org.dxos.app-framework.plugin-manager"
109
+ });
110
+ manager.capabilities.contribute({
111
+ interface: capabilities_exports.AtomRegistry,
112
+ implementation: manager.registry,
113
+ module: "org.dxos.app-framework.atom-registry"
114
+ });
115
+ const fiber = Effect.gen(function* () {
116
+ const queue = yield* PubSub.subscribe(manager.activation);
117
+ const listener = yield* Effect.forkDaemon(Queue.take(queue).pipe(Effect.tap(({ event, state, module, error: error$ }) => Effect.sync(() => {
118
+ if (event === activation_events_exports.Startup.id && state === "activated" && !module) {
119
+ clearTimeout(timeoutId);
120
+ setReady(true);
121
+ readyRef.current = true;
122
+ globalThis.composer?.profiler?.dump();
123
+ if (typeof window !== "undefined") {
124
+ window.dispatchEvent(new CustomEvent("app-framework:startup-activated"));
125
+ }
126
+ return;
127
+ }
128
+ if (module && state === "activating" && !readyRef.current) {
129
+ setStartupProgress((current) => ({
130
+ ...current,
131
+ // `event` here is the activation event that first
132
+ // triggered this module load (plumbed through
133
+ // `_loadCapabilitiesForModules` → `_loadModule`).
134
+ // Falsy/empty falls back to undefined so consumers can
135
+ // tell "no parent context" from "parent context: <X>".
136
+ event: event || void 0,
137
+ module,
138
+ humanizedName: humanizeModuleId(module)
139
+ }));
140
+ }
141
+ if (module && state === "activated" && !readyRef.current) {
142
+ const active = manager.getActive();
143
+ const total = manager.getModules().length;
144
+ setStartupProgress((current) => ({
145
+ ...current,
146
+ activated: active.length,
147
+ total,
148
+ progress: total > 0 ? active.length / total : 0
149
+ }));
150
+ }
151
+ if (event && !module && state === "activating" && !readyRef.current) {
152
+ setStartupProgress((current) => ({
153
+ ...current,
154
+ event,
155
+ module: void 0,
156
+ humanizedName: humanizeEventKey(event)
157
+ }));
158
+ }
159
+ if (error$ && !readyRef.current) {
160
+ setError(error$);
161
+ errorRef.current = error$;
162
+ }
163
+ })), Effect.forever));
164
+ yield* Effect.all([
165
+ ...setupEvents.map((event) => manager.activate(event)),
166
+ manager.activate(activation_events_exports.SetupReactSurface),
167
+ manager.activate(activation_events_exports.Startup)
168
+ ]);
169
+ return yield* Fiber.join(listener);
170
+ }).pipe(Effect.scoped, Effect.runFork);
171
+ const timeoutId = setTimeout(() => {
172
+ if (!readyRef.current && !errorRef.current) {
173
+ log.warn("startup timeout diagnostic", {
174
+ eventsFired: manager.getEventsFired(),
175
+ activeModules: manager.getActive(),
176
+ pendingReset: manager.getPendingReset()
177
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 220, S: void 0 });
178
+ void runAndForwardErrors(Fiber.interrupt(fiber));
179
+ setError(new Error(`Startup timed out after ${timeout}ms`));
180
+ }
181
+ }, timeout);
182
+ return () => {
183
+ log("useApp: effect cleanup", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 230, S: void 0 });
184
+ clearTimeout(timeoutId);
185
+ void runAndForwardErrors(Fiber.interrupt(fiber));
186
+ if (!isExternalManager) {
187
+ void runAndForwardErrors(manager.shutdown());
188
+ }
189
+ };
190
+ }, [
191
+ manager
192
+ ]);
193
+ const progressRef = useRef(startupProgress);
194
+ progressRef.current = startupProgress;
195
+ return useCallback(() => /* @__PURE__ */ React.createElement(ErrorBoundary, {
196
+ name: "app",
197
+ FallbackComponent: fallback
198
+ }, /* @__PURE__ */ React.createElement(PluginManagerProvider, {
199
+ value: manager
200
+ }, /* @__PURE__ */ React.createElement(ContextProtocolProvider, {
201
+ value: manager,
202
+ context: PluginManagerContext
203
+ }, /* @__PURE__ */ React.createElement(RegistryContext.Provider, {
204
+ value: manager.registry
205
+ }, /* @__PURE__ */ React.createElement(App, {
206
+ placeholder,
207
+ ready,
208
+ error,
209
+ debounce,
210
+ progress: progressRef.current
211
+ }))))), [
212
+ fallback,
213
+ manager,
214
+ placeholder,
215
+ ready,
216
+ error
217
+ ]);
218
+ };
219
+ var setupDevtools = (manager) => {
220
+ globalThis.composer ??= {};
221
+ globalThis.composer.manager = manager;
222
+ };
223
+ var humanizeModuleId = (moduleId) => {
224
+ const match = moduleId.match(/\.plugin\.([^.]+)\.module\.(.+)$/);
225
+ if (!match) {
226
+ const parts = moduleId.split(".");
227
+ return parts[parts.length - 1];
228
+ }
229
+ const [, pluginSlug, moduleName] = match;
230
+ const pluginLabel = pluginSlug.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
231
+ const moduleLabel = moduleName.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").toLowerCase();
232
+ if (moduleLabel === pluginSlug) {
233
+ return pluginLabel;
234
+ }
235
+ return `${pluginLabel}: ${moduleLabel}`;
236
+ };
237
+ var humanizeEventKey = (eventKey) => {
238
+ const id = eventKey.split(":")[0];
239
+ const match = id.match(/\.event\.(.+)$/);
240
+ const slug = match ? match[1] : id.split(".").pop() ?? id;
241
+ return slug.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
242
+ };
243
+
244
+ // src/ui/hooks/useCapabilities.ts
245
+ import { useAtomValue } from "@effect-atom/atom-react";
246
+ import { useCallback as useCallback2 } from "react";
247
+ import { invariant as invariant2 } from "@dxos/invariant";
248
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/sdk/app-framework/src/ui/hooks/useCapabilities.ts";
249
+ var useCapabilities = (interfaceDef) => {
250
+ const manager = usePluginManager();
251
+ return useAtomValue(manager.capabilities.atom(interfaceDef));
252
+ };
253
+ var useCapability = (interfaceDef) => {
254
+ const capabilities = useCapabilities(interfaceDef);
255
+ invariant2(capabilities.length > 0, `No capability found for ${interfaceDef.identifier}`, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 22, S: void 0, A: ["capabilities.length > 0", "`No capability found for ${interfaceDef.identifier}`"] });
256
+ return capabilities[0];
257
+ };
258
+ var useAtomCapability = (atomCapability) => {
259
+ const atom = useCapability(atomCapability);
260
+ return useAtomValue(atom);
261
+ };
262
+ var useAtomCapabilityState = (atomCapability) => {
263
+ const registry = useCapability(capabilities_exports.AtomRegistry);
264
+ const atom = useCapability(atomCapability);
265
+ const value = useAtomValue(atom);
266
+ const update = useCallback2((fn) => {
267
+ registry.set(atom, fn(registry.get(atom)));
268
+ }, [
269
+ registry,
270
+ atom
271
+ ]);
272
+ return [
273
+ value,
274
+ update
275
+ ];
276
+ };
277
+ var useOperationInvoker = () => useCapability(capabilities_exports.OperationInvoker);
278
+
279
+ // src/ui/hooks/useLoading.tsx
280
+ import { useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
281
+ var LoadingState = /* @__PURE__ */ (function(LoadingState2) {
282
+ LoadingState2[LoadingState2["Loading"] = 0] = "Loading";
283
+ LoadingState2[LoadingState2["FadeIn"] = 1] = "FadeIn";
284
+ LoadingState2[LoadingState2["FadeOut"] = 2] = "FadeOut";
285
+ LoadingState2[LoadingState2["Done"] = 3] = "Done";
286
+ return LoadingState2;
287
+ })({});
288
+ var useLoading = (ready, debounce = 0) => {
289
+ const [stage, setStage] = useState2(0);
290
+ const readyRef = useRef2(ready);
291
+ readyRef.current = ready;
292
+ useEffect2(() => {
293
+ if (!debounce) {
294
+ return;
295
+ }
296
+ const i = setInterval(() => {
297
+ setStage((stage2) => {
298
+ const isReady = readyRef.current;
299
+ switch (stage2) {
300
+ case 0: {
301
+ if (!isReady) {
302
+ return 1;
303
+ }
304
+ clearInterval(i);
305
+ return 3;
306
+ }
307
+ case 1: {
308
+ if (isReady) {
309
+ return 2;
310
+ }
311
+ break;
312
+ }
313
+ case 2: {
314
+ clearInterval(i);
315
+ return 3;
316
+ }
317
+ }
318
+ return stage2;
319
+ });
320
+ }, debounce);
321
+ return () => clearInterval(i);
322
+ }, [
323
+ debounce
324
+ ]);
325
+ if (!debounce) {
326
+ return ready ? 3 : 0;
327
+ }
328
+ return stage;
329
+ };
330
+
331
+ // src/ui/hooks/useSettingsState.ts
332
+ import { RegistryContext as RegistryContext2, useAtomValue as useAtomValue2 } from "@effect-atom/atom-react";
333
+ import { useCallback as useCallback3, useContext } from "react";
334
+ var useSettingsState = (atom) => {
335
+ const registry = useContext(RegistryContext2);
336
+ const settings = useAtomValue2(atom);
337
+ const updateSettings = useCallback3((fn) => {
338
+ registry.set(atom, fn(registry.get(atom)));
339
+ }, [
340
+ registry,
341
+ atom
342
+ ]);
343
+ return {
344
+ settings,
345
+ updateSettings
346
+ };
347
+ };
348
+
349
+ // src/ui/components/App/App.tsx
350
+ var FIRST_INTERACTIVE_MARK = "app-framework:first-interactive";
351
+ var App = ({ placeholder: Placeholder2, ready, error, debounce, progress }) => {
352
+ const reactContexts = useCapabilities(capabilities_exports.ReactContext);
353
+ const reactRoots = useCapabilities(capabilities_exports.ReactRoot);
354
+ const stage = useLoading(ready, debounce);
355
+ const placeholderDismissed = stage >= LoadingState.Done;
356
+ useEffect3(() => {
357
+ if (!placeholderDismissed) {
358
+ return;
359
+ }
360
+ if (performance.getEntriesByName(FIRST_INTERACTIVE_MARK).length === 0) {
361
+ performance.mark(FIRST_INTERACTIVE_MARK);
362
+ }
363
+ window.__bootLoader?.dismiss?.();
364
+ }, [
365
+ placeholderDismissed
366
+ ]);
367
+ if (error) {
368
+ throw error;
369
+ }
370
+ if (!placeholderDismissed) {
371
+ if (!Placeholder2) {
372
+ return null;
373
+ }
374
+ return /* @__PURE__ */ React2.createElement(Placeholder2, {
375
+ stage,
376
+ progress
377
+ });
378
+ }
379
+ const ComposedContext = composeContexts(reactContexts);
380
+ return /* @__PURE__ */ React2.createElement(ComposedContext, null, reactRoots.map(({ id, root: Component }) => /* @__PURE__ */ React2.createElement(Component, {
381
+ key: id
382
+ })));
383
+ };
384
+ var composeContexts = (contexts) => {
385
+ if (contexts.length === 0) {
386
+ return ({ children }) => /* @__PURE__ */ React2.createElement(React2.Fragment, null, children);
387
+ }
388
+ return topologicalSort(contexts).map(({ context }) => context).reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ React2.createElement(Acc, null, /* @__PURE__ */ React2.createElement(Next, null, children)));
389
+ };
390
+
391
+ // src/ui/components/Placeholder/Placeholder.tsx
392
+ import React3, { useEffect as useEffect4, useLayoutEffect, useRef as useRef3 } from "react";
393
+ import { ThemeProvider } from "@dxos/react-ui";
394
+ import { defaultTx, mx } from "@dxos/ui-theme";
395
+ var Placeholder = ({ stage = 1, progress, logo }) => {
396
+ if (location.search === "?throw") {
397
+ throw new Error("Test error");
398
+ }
399
+ useEffect4(() => {
400
+ if (stage >= 2) {
401
+ return;
402
+ }
403
+ const fraction = progress?.progress ?? 0;
404
+ window.__bootLoader?.progress(0.5 + fraction * 0.5);
405
+ if (progress?.humanizedName) {
406
+ window.__bootLoader?.status({
407
+ event: progress.event,
408
+ module: progress.module,
409
+ humanized: `Activating ${progress.humanizedName}`
410
+ });
411
+ }
412
+ }, [
413
+ stage,
414
+ progress?.progress,
415
+ progress?.event,
416
+ progress?.module,
417
+ progress?.humanizedName
418
+ ]);
419
+ useLayoutEffect(() => {
420
+ if (stage >= 2) {
421
+ window.__bootLoader?.dismiss();
422
+ }
423
+ }, [
424
+ stage
425
+ ]);
426
+ const stageRef = useRef3(stage);
427
+ stageRef.current = stage;
428
+ useEffect4(() => {
429
+ return () => {
430
+ if (stageRef.current >= 3) {
431
+ window.__bootLoader?.dismiss();
432
+ }
433
+ };
434
+ }, []);
435
+ if (stage < 2) {
436
+ return null;
437
+ }
438
+ const logoClassName = mx("h-[300px] w-[300px] scale-600 transition-all duration-500 ease-in-out filter grayscale opacity-0", stage >= 1 && "scale-100 grayscale-0 opacity-70", stage >= 2 && "scale-50 opacity-0");
439
+ return /* @__PURE__ */ React3.createElement(ThemeProvider, {
440
+ tx: defaultTx
441
+ }, /* @__PURE__ */ React3.createElement("div", {
442
+ role: "none",
443
+ className: "relative dx-container h-dvh flex flex-col"
444
+ }, /* @__PURE__ */ React3.createElement("div", {
445
+ role: "none",
446
+ className: "flex flex-col grow justify-center items-center"
447
+ }, typeof logo === "function" ? logo({
448
+ className: logoClassName
449
+ }) : logo ? /* @__PURE__ */ React3.createElement("div", {
450
+ className: logoClassName
451
+ }, logo) : null)));
452
+ };
453
+
454
+ export {
455
+ useApp,
456
+ useCapabilities,
457
+ useCapability,
458
+ useAtomCapability,
459
+ useAtomCapabilityState,
460
+ useOperationInvoker,
461
+ LoadingState,
462
+ useLoading,
463
+ useSettingsState,
464
+ App,
465
+ Placeholder
466
+ };
467
+ //# sourceMappingURL=chunk-5LAIGWLU.mjs.map