react-cosmos-ui 6.0.0-alpha.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 (377) hide show
  1. package/LICENSE +21 -0
  2. package/dist/components/BaseSvg.d.ts +9 -0
  3. package/dist/components/BaseSvg.js +8 -0
  4. package/dist/components/Icon.d.ts +7 -0
  5. package/dist/components/Icon.js +5 -0
  6. package/dist/components/Illustration.d.ts +8 -0
  7. package/dist/components/Illustration.js +5 -0
  8. package/dist/components/KeyBox.d.ts +9 -0
  9. package/dist/components/KeyBox.js +28 -0
  10. package/dist/components/SidePanel.d.ts +10 -0
  11. package/dist/components/SidePanel.js +52 -0
  12. package/dist/components/Space.d.ts +7 -0
  13. package/dist/components/Space.js +8 -0
  14. package/dist/components/TreeView.d.ts +19 -0
  15. package/dist/components/TreeView.js +26 -0
  16. package/dist/components/ValueInputTree/ExpandCollapseValues.d.ts +9 -0
  17. package/dist/components/ValueInputTree/ExpandCollapseValues.js +11 -0
  18. package/dist/components/ValueInputTree/ValueInput/BooleanValueInput.d.ts +8 -0
  19. package/dist/components/ValueInputTree/ValueInput/BooleanValueInput.js +32 -0
  20. package/dist/components/ValueInputTree/ValueInput/NullValueInput.d.ts +5 -0
  21. package/dist/components/ValueInputTree/ValueInput/NullValueInput.js +9 -0
  22. package/dist/components/ValueInputTree/ValueInput/NumberValueInput.d.ts +8 -0
  23. package/dist/components/ValueInputTree/ValueInput/NumberValueInput.js +14 -0
  24. package/dist/components/ValueInputTree/ValueInput/StringValueInput.d.ts +8 -0
  25. package/dist/components/ValueInputTree/ValueInput/StringValueInput.js +18 -0
  26. package/dist/components/ValueInputTree/ValueInput/UndefinedValueInput.d.ts +5 -0
  27. package/dist/components/ValueInputTree/ValueInput/UndefinedValueInput.js +9 -0
  28. package/dist/components/ValueInputTree/ValueInput/UnserializableValueInput.d.ts +6 -0
  29. package/dist/components/ValueInputTree/ValueInput/UnserializableValueInput.js +11 -0
  30. package/dist/components/ValueInputTree/ValueInput/ValueInput.d.ts +11 -0
  31. package/dist/components/ValueInputTree/ValueInput/ValueInput.js +30 -0
  32. package/dist/components/ValueInputTree/ValueInput/shared.d.ts +6 -0
  33. package/dist/components/ValueInputTree/ValueInput/shared.js +41 -0
  34. package/dist/components/ValueInputTree/ValueInputDir.d.ts +9 -0
  35. package/dist/components/ValueInputTree/ValueInputDir.js +68 -0
  36. package/dist/components/ValueInputTree/ValueInputTree.d.ts +12 -0
  37. package/dist/components/ValueInputTree/ValueInputTree.js +32 -0
  38. package/dist/components/ValueInputTree/index.d.ts +4 -0
  39. package/dist/components/ValueInputTree/index.js +4 -0
  40. package/dist/components/ValueInputTree/shared.d.ts +16 -0
  41. package/dist/components/ValueInputTree/shared.js +15 -0
  42. package/dist/components/ValueInputTree/valueGroups.d.ts +8 -0
  43. package/dist/components/ValueInputTree/valueGroups.js +10 -0
  44. package/dist/components/ValueInputTree/valueTree.d.ts +3 -0
  45. package/dist/components/ValueInputTree/valueTree.js +20 -0
  46. package/dist/components/ValueInputTree/valueTreeExpansion.d.ts +7 -0
  47. package/dist/components/ValueInputTree/valueTreeExpansion.js +16 -0
  48. package/dist/components/buttons/Button32.d.ts +11 -0
  49. package/dist/components/buttons/Button32.js +8 -0
  50. package/dist/components/buttons/Button8.d.ts +11 -0
  51. package/dist/components/buttons/Button8.js +8 -0
  52. package/dist/components/buttons/IconButton32.d.ts +10 -0
  53. package/dist/components/buttons/IconButton32.js +7 -0
  54. package/dist/components/buttons/IconButton8.d.ts +10 -0
  55. package/dist/components/buttons/IconButton8.js +7 -0
  56. package/dist/components/buttons/index.d.ts +4 -0
  57. package/dist/components/buttons/index.js +4 -0
  58. package/dist/components/buttons/shared.d.ts +15 -0
  59. package/dist/components/buttons/shared.js +52 -0
  60. package/dist/components/icons/index.d.ts +33 -0
  61. package/dist/components/icons/index.js +107 -0
  62. package/dist/components/illustrations/ArtificialIntelligence.d.ts +3 -0
  63. package/dist/components/illustrations/ArtificialIntelligence.js +123 -0
  64. package/dist/components/illustrations/Astronaut.d.ts +3 -0
  65. package/dist/components/illustrations/Astronaut.js +72 -0
  66. package/dist/components/illustrations/BlankCanvas.d.ts +3 -0
  67. package/dist/components/illustrations/BlankCanvas.js +75 -0
  68. package/dist/components/inputs/NumberInput.d.ts +15 -0
  69. package/dist/components/inputs/NumberInput.js +79 -0
  70. package/dist/components/inputs/Select.d.ts +16 -0
  71. package/dist/components/inputs/Select.js +69 -0
  72. package/dist/components/inputs/shared.d.ts +14 -0
  73. package/dist/components/inputs/shared.js +43 -0
  74. package/dist/cosmos.decorator.d.ts +5 -0
  75. package/dist/cosmos.decorator.js +6 -0
  76. package/dist/cosmos.loadPlugins.d.ts +1 -0
  77. package/dist/cosmos.loadPlugins.js +17 -0
  78. package/dist/hooks/useDrag.d.ts +14 -0
  79. package/dist/hooks/useDrag.js +58 -0
  80. package/dist/hooks/useFocus.d.ts +5 -0
  81. package/dist/hooks/useFocus.js +7 -0
  82. package/dist/index.d.ts +36 -0
  83. package/dist/index.js +36 -0
  84. package/dist/playground.bundle.js +1358 -0
  85. package/dist/playground.bundle.js.LICENSE.txt +64 -0
  86. package/dist/playground.bundle.js.map +1 -0
  87. package/dist/playground.d.ts +11 -0
  88. package/dist/playground.js +36 -0
  89. package/dist/playgroundConfig.d.ts +10 -0
  90. package/dist/playgroundConfig.js +1 -0
  91. package/dist/plugins/BuildNotifications/index.d.ts +2 -0
  92. package/dist/plugins/BuildNotifications/index.js +35 -0
  93. package/dist/plugins/BuildNotifications/spec.d.ts +3 -0
  94. package/dist/plugins/BuildNotifications/spec.js +1 -0
  95. package/dist/plugins/ClassStatePanel/ClassStatePanel/ComponentClassState.d.ts +10 -0
  96. package/dist/plugins/ClassStatePanel/ClassStatePanel/ComponentClassState.js +36 -0
  97. package/dist/plugins/ClassStatePanel/ClassStatePanel/index.d.ts +11 -0
  98. package/dist/plugins/ClassStatePanel/ClassStatePanel/index.js +13 -0
  99. package/dist/plugins/ClassStatePanel/ClassStatePanel/shared.d.ts +2 -0
  100. package/dist/plugins/ClassStatePanel/ClassStatePanel/shared.js +16 -0
  101. package/dist/plugins/ClassStatePanel/index.d.ts +2 -0
  102. package/dist/plugins/ClassStatePanel/index.js +30 -0
  103. package/dist/plugins/ClassStatePanel/shared.d.ts +1 -0
  104. package/dist/plugins/ClassStatePanel/shared.js +1 -0
  105. package/dist/plugins/ClassStatePanel/spec.d.ts +3 -0
  106. package/dist/plugins/ClassStatePanel/spec.js +1 -0
  107. package/dist/plugins/ContentOverlay/ContentOverlay.d.ts +13 -0
  108. package/dist/plugins/ContentOverlay/ContentOverlay.js +34 -0
  109. package/dist/plugins/ContentOverlay/KeyShortcut.d.ts +6 -0
  110. package/dist/plugins/ContentOverlay/KeyShortcut.js +30 -0
  111. package/dist/plugins/ContentOverlay/NoFixtureSelected.d.ts +5 -0
  112. package/dist/plugins/ContentOverlay/NoFixtureSelected.js +34 -0
  113. package/dist/plugins/ContentOverlay/RendererNotResponding.d.ts +1 -0
  114. package/dist/plugins/ContentOverlay/RendererNotResponding.js +109 -0
  115. package/dist/plugins/ContentOverlay/WelcomeCosmos.d.ts +5 -0
  116. package/dist/plugins/ContentOverlay/WelcomeCosmos.js +158 -0
  117. package/dist/plugins/ContentOverlay/cosmos.decorator.d.ts +5 -0
  118. package/dist/plugins/ContentOverlay/cosmos.decorator.js +13 -0
  119. package/dist/plugins/ContentOverlay/index.d.ts +2 -0
  120. package/dist/plugins/ContentOverlay/index.js +19 -0
  121. package/dist/plugins/ContentOverlay/shared.d.ts +9 -0
  122. package/dist/plugins/ContentOverlay/shared.js +75 -0
  123. package/dist/plugins/ContentOverlay/spec.d.ts +3 -0
  124. package/dist/plugins/ContentOverlay/spec.js +1 -0
  125. package/dist/plugins/ContentOverlay/welcomeDismiss.d.ts +7 -0
  126. package/dist/plugins/ContentOverlay/welcomeDismiss.js +17 -0
  127. package/dist/plugins/ControlPanel/ControlPanel.d.ts +8 -0
  128. package/dist/plugins/ControlPanel/ControlPanel.js +37 -0
  129. package/dist/plugins/ControlPanel/index.d.ts +2 -0
  130. package/dist/plugins/ControlPanel/index.js +17 -0
  131. package/dist/plugins/ControlPanel/spec.d.ts +6 -0
  132. package/dist/plugins/ControlPanel/spec.js +1 -0
  133. package/dist/plugins/ControlSelect/SelectValueInput.d.ts +8 -0
  134. package/dist/plugins/ControlSelect/SelectValueInput.js +15 -0
  135. package/dist/plugins/ControlSelect/index.d.ts +2 -0
  136. package/dist/plugins/ControlSelect/index.js +22 -0
  137. package/dist/plugins/ControlSelect/spec.d.ts +3 -0
  138. package/dist/plugins/ControlSelect/spec.js +1 -0
  139. package/dist/plugins/Core/index.d.ts +2 -0
  140. package/dist/plugins/Core/index.js +68 -0
  141. package/dist/plugins/Core/spec.d.ts +25 -0
  142. package/dist/plugins/Core/spec.js +1 -0
  143. package/dist/plugins/FixtureBookmark/BookmarkFixtureButton.d.ts +6 -0
  144. package/dist/plugins/FixtureBookmark/BookmarkFixtureButton.js +6 -0
  145. package/dist/plugins/FixtureBookmark/FixtureBookmarks.d.ts +10 -0
  146. package/dist/plugins/FixtureBookmark/FixtureBookmarks.js +123 -0
  147. package/dist/plugins/FixtureBookmark/index.d.ts +2 -0
  148. package/dist/plugins/FixtureBookmark/index.js +46 -0
  149. package/dist/plugins/FixtureBookmark/spec.d.ts +3 -0
  150. package/dist/plugins/FixtureBookmark/spec.js +1 -0
  151. package/dist/plugins/FixtureSearch/FixtureSearchHeader.d.ts +7 -0
  152. package/dist/plugins/FixtureSearch/FixtureSearchHeader.js +66 -0
  153. package/dist/plugins/FixtureSearch/FixtureSearchOverlay.d.ts +13 -0
  154. package/dist/plugins/FixtureSearch/FixtureSearchOverlay.js +312 -0
  155. package/dist/plugins/FixtureSearch/FixtureSearchResult.d.ts +9 -0
  156. package/dist/plugins/FixtureSearch/FixtureSearchResult.js +48 -0
  157. package/dist/plugins/FixtureSearch/FixtureSearchShortcuts.d.ts +1 -0
  158. package/dist/plugins/FixtureSearch/FixtureSearchShortcuts.js +60 -0
  159. package/dist/plugins/FixtureSearch/index.d.ts +2 -0
  160. package/dist/plugins/FixtureSearch/index.js +72 -0
  161. package/dist/plugins/FixtureSearch/spec.d.ts +7 -0
  162. package/dist/plugins/FixtureSearch/spec.js +1 -0
  163. package/dist/plugins/FixtureTree/BlankState.d.ts +8 -0
  164. package/dist/plugins/FixtureTree/BlankState.js +75 -0
  165. package/dist/plugins/FixtureTree/FixtureTree/FixtureButton.d.ts +12 -0
  166. package/dist/plugins/FixtureTree/FixtureTree/FixtureButton.js +16 -0
  167. package/dist/plugins/FixtureTree/FixtureTree/FixtureDir.d.ts +9 -0
  168. package/dist/plugins/FixtureTree/FixtureTree/FixtureDir.js +46 -0
  169. package/dist/plugins/FixtureTree/FixtureTree/FixtureLink.d.ts +9 -0
  170. package/dist/plugins/FixtureTree/FixtureTree/FixtureLink.js +34 -0
  171. package/dist/plugins/FixtureTree/FixtureTree/FixtureTree.d.ts +13 -0
  172. package/dist/plugins/FixtureTree/FixtureTree/FixtureTree.js +37 -0
  173. package/dist/plugins/FixtureTree/FixtureTree/FixtureTreeItem.d.ts +6 -0
  174. package/dist/plugins/FixtureTree/FixtureTree/FixtureTreeItem.js +24 -0
  175. package/dist/plugins/FixtureTree/FixtureTree/MultiFixtureButton.d.ts +13 -0
  176. package/dist/plugins/FixtureTree/FixtureTree/MultiFixtureButton.js +46 -0
  177. package/dist/plugins/FixtureTree/FixtureTree/MultiFixtureChildButton.d.ts +12 -0
  178. package/dist/plugins/FixtureTree/FixtureTree/MultiFixtureChildButton.js +26 -0
  179. package/dist/plugins/FixtureTree/FixtureTreeContainer.d.ts +14 -0
  180. package/dist/plugins/FixtureTree/FixtureTreeContainer.js +28 -0
  181. package/dist/plugins/FixtureTree/FixtureTreeHeader.d.ts +11 -0
  182. package/dist/plugins/FixtureTree/FixtureTreeHeader.js +33 -0
  183. package/dist/plugins/FixtureTree/index.d.ts +2 -0
  184. package/dist/plugins/FixtureTree/index.js +25 -0
  185. package/dist/plugins/FixtureTree/revealFixture.d.ts +3 -0
  186. package/dist/plugins/FixtureTree/revealFixture.js +48 -0
  187. package/dist/plugins/FixtureTree/shared.d.ts +7 -0
  188. package/dist/plugins/FixtureTree/shared.js +8 -0
  189. package/dist/plugins/FixtureTree/spec.d.ts +7 -0
  190. package/dist/plugins/FixtureTree/spec.js +1 -0
  191. package/dist/plugins/FixtureTree/useScrollToSelected.d.ts +6 -0
  192. package/dist/plugins/FixtureTree/useScrollToSelected.js +18 -0
  193. package/dist/plugins/FullScreenButton/FullScreenButton.d.ts +5 -0
  194. package/dist/plugins/FullScreenButton/FullScreenButton.js +6 -0
  195. package/dist/plugins/FullScreenButton/index.d.ts +2 -0
  196. package/dist/plugins/FullScreenButton/index.js +25 -0
  197. package/dist/plugins/FullScreenButton/spec.d.ts +3 -0
  198. package/dist/plugins/FullScreenButton/spec.js +1 -0
  199. package/dist/plugins/MessageHandler/index.d.ts +2 -0
  200. package/dist/plugins/MessageHandler/index.js +12 -0
  201. package/dist/plugins/MessageHandler/shared.d.ts +3 -0
  202. package/dist/plugins/MessageHandler/shared.js +1 -0
  203. package/dist/plugins/MessageHandler/socket.d.ts +4 -0
  204. package/dist/plugins/MessageHandler/socket.js +45 -0
  205. package/dist/plugins/MessageHandler/spec.d.ts +11 -0
  206. package/dist/plugins/MessageHandler/spec.js +1 -0
  207. package/dist/plugins/Notifications/Notifications.d.ts +6 -0
  208. package/dist/plugins/Notifications/Notifications.js +75 -0
  209. package/dist/plugins/Notifications/index.d.ts +2 -0
  210. package/dist/plugins/Notifications/index.js +36 -0
  211. package/dist/plugins/Notifications/pushNotification.d.ts +6 -0
  212. package/dist/plugins/Notifications/pushNotification.js +40 -0
  213. package/dist/plugins/Notifications/shared.d.ts +3 -0
  214. package/dist/plugins/Notifications/shared.js +1 -0
  215. package/dist/plugins/Notifications/spec.d.ts +22 -0
  216. package/dist/plugins/Notifications/spec.js +1 -0
  217. package/dist/plugins/PluginList/PluginList.d.ts +10 -0
  218. package/dist/plugins/PluginList/PluginList.js +38 -0
  219. package/dist/plugins/PluginList/index.d.ts +2 -0
  220. package/dist/plugins/PluginList/index.js +12 -0
  221. package/dist/plugins/PluginList/spec.d.ts +3 -0
  222. package/dist/plugins/PluginList/spec.js +1 -0
  223. package/dist/plugins/PropsPanel/BlankState.d.ts +3 -0
  224. package/dist/plugins/PropsPanel/BlankState.js +47 -0
  225. package/dist/plugins/PropsPanel/PropsPanel/ComponentProps.d.ts +10 -0
  226. package/dist/plugins/PropsPanel/PropsPanel/ComponentProps.js +40 -0
  227. package/dist/plugins/PropsPanel/PropsPanel/index.d.ts +11 -0
  228. package/dist/plugins/PropsPanel/PropsPanel/index.js +13 -0
  229. package/dist/plugins/PropsPanel/PropsPanel/shared.d.ts +2 -0
  230. package/dist/plugins/PropsPanel/PropsPanel/shared.js +16 -0
  231. package/dist/plugins/PropsPanel/index.d.ts +2 -0
  232. package/dist/plugins/PropsPanel/index.js +55 -0
  233. package/dist/plugins/PropsPanel/shared.d.ts +1 -0
  234. package/dist/plugins/PropsPanel/shared.js +1 -0
  235. package/dist/plugins/PropsPanel/spec.d.ts +3 -0
  236. package/dist/plugins/PropsPanel/spec.js +1 -0
  237. package/dist/plugins/RemoteRenderer/RemoteButton/copyToClipboard.d.ts +1 -0
  238. package/dist/plugins/RemoteRenderer/RemoteButton/copyToClipboard.js +24 -0
  239. package/dist/plugins/RemoteRenderer/RemoteButton/index.d.ts +8 -0
  240. package/dist/plugins/RemoteRenderer/RemoteButton/index.js +37 -0
  241. package/dist/plugins/RemoteRenderer/index.d.ts +2 -0
  242. package/dist/plugins/RemoteRenderer/index.js +36 -0
  243. package/dist/plugins/RemoteRenderer/shared.d.ts +3 -0
  244. package/dist/plugins/RemoteRenderer/shared.js +1 -0
  245. package/dist/plugins/RemoteRenderer/spec.d.ts +3 -0
  246. package/dist/plugins/RemoteRenderer/spec.js +1 -0
  247. package/dist/plugins/RendererCore/index.d.ts +2 -0
  248. package/dist/plugins/RendererCore/index.js +47 -0
  249. package/dist/plugins/RendererCore/isValidFixtureSelected.d.ts +2 -0
  250. package/dist/plugins/RendererCore/isValidFixtureSelected.js +16 -0
  251. package/dist/plugins/RendererCore/onRouterFixtureChange.d.ts +3 -0
  252. package/dist/plugins/RendererCore/onRouterFixtureChange.js +18 -0
  253. package/dist/plugins/RendererCore/receiveResponse/fixtureListUpdate.d.ts +3 -0
  254. package/dist/plugins/RendererCore/receiveResponse/fixtureListUpdate.js +11 -0
  255. package/dist/plugins/RendererCore/receiveResponse/fixtureStateChange.d.ts +3 -0
  256. package/dist/plugins/RendererCore/receiveResponse/fixtureStateChange.js +30 -0
  257. package/dist/plugins/RendererCore/receiveResponse/index.d.ts +3 -0
  258. package/dist/plugins/RendererCore/receiveResponse/index.js +20 -0
  259. package/dist/plugins/RendererCore/receiveResponse/playgroundCommand.d.ts +3 -0
  260. package/dist/plugins/RendererCore/receiveResponse/playgroundCommand.js +5 -0
  261. package/dist/plugins/RendererCore/receiveResponse/rendererReady.d.ts +3 -0
  262. package/dist/plugins/RendererCore/receiveResponse/rendererReady.js +49 -0
  263. package/dist/plugins/RendererCore/setFixtureState.d.ts +3 -0
  264. package/dist/plugins/RendererCore/setFixtureState.js +22 -0
  265. package/dist/plugins/RendererCore/shared/index.d.ts +4 -0
  266. package/dist/plugins/RendererCore/shared/index.js +1 -0
  267. package/dist/plugins/RendererCore/shared/postRequest.d.ts +5 -0
  268. package/dist/plugins/RendererCore/shared/postRequest.js +31 -0
  269. package/dist/plugins/RendererCore/shared/router.d.ts +2 -0
  270. package/dist/plugins/RendererCore/shared/router.js +3 -0
  271. package/dist/plugins/RendererCore/spec.d.ts +25 -0
  272. package/dist/plugins/RendererCore/spec.js +1 -0
  273. package/dist/plugins/RendererPreview/RendererPreview.d.ts +8 -0
  274. package/dist/plugins/RendererPreview/RendererPreview.js +25 -0
  275. package/dist/plugins/RendererPreview/checkRendererStatus.d.ts +2 -0
  276. package/dist/plugins/RendererPreview/checkRendererStatus.js +31 -0
  277. package/dist/plugins/RendererPreview/handleRendererRequests.d.ts +6 -0
  278. package/dist/plugins/RendererPreview/handleRendererRequests.js +76 -0
  279. package/dist/plugins/RendererPreview/handleWindowMessages.d.ts +2 -0
  280. package/dist/plugins/RendererPreview/handleWindowMessages.js +56 -0
  281. package/dist/plugins/RendererPreview/index.d.ts +2 -0
  282. package/dist/plugins/RendererPreview/index.js +49 -0
  283. package/dist/plugins/RendererPreview/shared.d.ts +9 -0
  284. package/dist/plugins/RendererPreview/shared.js +1 -0
  285. package/dist/plugins/RendererPreview/spec.d.ts +13 -0
  286. package/dist/plugins/RendererPreview/spec.js +1 -0
  287. package/dist/plugins/RendererSelect/index.d.ts +2 -0
  288. package/dist/plugins/RendererSelect/index.js +27 -0
  289. package/dist/plugins/RendererSelect/spec.d.ts +3 -0
  290. package/dist/plugins/RendererSelect/spec.js +1 -0
  291. package/dist/plugins/ResponsivePreview/ResponsivePreview/Header.d.ts +13 -0
  292. package/dist/plugins/ResponsivePreview/ResponsivePreview/Header.js +97 -0
  293. package/dist/plugins/ResponsivePreview/ResponsivePreview/ResponsivePreview.d.ts +14 -0
  294. package/dist/plugins/ResponsivePreview/ResponsivePreview/ResponsivePreview.js +152 -0
  295. package/dist/plugins/ResponsivePreview/ResponsivePreview/style.d.ts +45 -0
  296. package/dist/plugins/ResponsivePreview/ResponsivePreview/style.js +79 -0
  297. package/dist/plugins/ResponsivePreview/ToggleButton/index.d.ts +6 -0
  298. package/dist/plugins/ResponsivePreview/ToggleButton/index.js +6 -0
  299. package/dist/plugins/ResponsivePreview/index.d.ts +2 -0
  300. package/dist/plugins/ResponsivePreview/index.js +79 -0
  301. package/dist/plugins/ResponsivePreview/shared.d.ts +21 -0
  302. package/dist/plugins/ResponsivePreview/shared.js +19 -0
  303. package/dist/plugins/ResponsivePreview/spec.d.ts +13 -0
  304. package/dist/plugins/ResponsivePreview/spec.js +1 -0
  305. package/dist/plugins/Root/GlobalHeader.d.ts +9 -0
  306. package/dist/plugins/Root/GlobalHeader.js +59 -0
  307. package/dist/plugins/Root/RendererHeader.d.ts +16 -0
  308. package/dist/plugins/Root/RendererHeader.js +79 -0
  309. package/dist/plugins/Root/Root.d.ts +28 -0
  310. package/dist/plugins/Root/Root.js +120 -0
  311. package/dist/plugins/Root/SidePanel.d.ts +10 -0
  312. package/dist/plugins/Root/SidePanel.js +26 -0
  313. package/dist/plugins/Root/ToggleNavButton.d.ts +7 -0
  314. package/dist/plugins/Root/ToggleNavButton.js +6 -0
  315. package/dist/plugins/Root/index.d.ts +2 -0
  316. package/dist/plugins/Root/index.js +73 -0
  317. package/dist/plugins/Root/navOpen.d.ts +4 -0
  318. package/dist/plugins/Root/navOpen.js +11 -0
  319. package/dist/plugins/Root/navWidth.d.ts +5 -0
  320. package/dist/plugins/Root/navWidth.js +14 -0
  321. package/dist/plugins/Root/panelOpen.d.ts +4 -0
  322. package/dist/plugins/Root/panelOpen.js +16 -0
  323. package/dist/plugins/Root/panelWidth.d.ts +5 -0
  324. package/dist/plugins/Root/panelWidth.js +14 -0
  325. package/dist/plugins/Root/shared.d.ts +3 -0
  326. package/dist/plugins/Root/shared.js +1 -0
  327. package/dist/plugins/Root/spec.d.ts +14 -0
  328. package/dist/plugins/Root/spec.js +1 -0
  329. package/dist/plugins/Router/index.d.ts +2 -0
  330. package/dist/plugins/Router/index.js +56 -0
  331. package/dist/plugins/Router/spec.d.ts +15 -0
  332. package/dist/plugins/Router/spec.js +1 -0
  333. package/dist/plugins/StandardControl/index.d.ts +2 -0
  334. package/dist/plugins/StandardControl/index.js +43 -0
  335. package/dist/plugins/StandardControl/spec.d.ts +3 -0
  336. package/dist/plugins/StandardControl/spec.js +1 -0
  337. package/dist/plugins/StandardControl/storage.d.ts +7 -0
  338. package/dist/plugins/StandardControl/storage.js +10 -0
  339. package/dist/plugins/Storage/index.d.ts +2 -0
  340. package/dist/plugins/Storage/index.js +40 -0
  341. package/dist/plugins/Storage/spec.d.ts +18 -0
  342. package/dist/plugins/Storage/spec.js +1 -0
  343. package/dist/plugins/pluginEntry.d.ts +23 -0
  344. package/dist/plugins/pluginEntry.js +29 -0
  345. package/dist/shared/defaultPluginConfig.d.ts +13 -0
  346. package/dist/shared/defaultPluginConfig.js +13 -0
  347. package/dist/shared/fixtureTree.d.ts +3 -0
  348. package/dist/shared/fixtureTree.js +12 -0
  349. package/dist/shared/treeExpansion.d.ts +7 -0
  350. package/dist/shared/treeExpansion.js +24 -0
  351. package/dist/shared/url.d.ts +5 -0
  352. package/dist/shared/url.js +33 -0
  353. package/dist/slots/ControlActionSlot.d.ts +10 -0
  354. package/dist/slots/ControlActionSlot.js +5 -0
  355. package/dist/slots/ControlSlot.d.ts +11 -0
  356. package/dist/slots/ControlSlot.js +5 -0
  357. package/dist/slots/FixtureActionSlot.d.ts +10 -0
  358. package/dist/slots/FixtureActionSlot.js +5 -0
  359. package/dist/slots/NavRowSlot.d.ts +9 -0
  360. package/dist/slots/NavRowSlot.js +5 -0
  361. package/dist/slots/RendererActionSlot.d.ts +10 -0
  362. package/dist/slots/RendererActionSlot.js +5 -0
  363. package/dist/slots/SidePanelRowSlot.d.ts +12 -0
  364. package/dist/slots/SidePanelRowSlot.js +5 -0
  365. package/dist/slots/ValueInputSlot.d.ts +16 -0
  366. package/dist/slots/ValueInputSlot.js +5 -0
  367. package/dist/style/colors.d.ts +37 -0
  368. package/dist/style/colors.js +43 -0
  369. package/dist/style/globalStyle.d.ts +2 -0
  370. package/dist/style/globalStyle.js +49 -0
  371. package/dist/style/vars.d.ts +2 -0
  372. package/dist/style/vars.js +2 -0
  373. package/dist/testHelpers/pluginHelpers.d.ts +5 -0
  374. package/dist/testHelpers/pluginHelpers.js +25 -0
  375. package/dist/testHelpers/pluginMocks.d.ts +116 -0
  376. package/dist/testHelpers/pluginMocks.js +139 -0
  377. package/package.json +24 -0
@@ -0,0 +1,25 @@
1
+ import { FixtureList, FixtureState, MessageType, RendererId, StateUpdater } from 'react-cosmos-core';
2
+ export type RendererCoreSpec = {
3
+ name: 'rendererCore';
4
+ state: {
5
+ connectedRendererIds: RendererId[];
6
+ primaryRendererId: null | RendererId;
7
+ fixtures: FixtureList;
8
+ fixtureState: FixtureState;
9
+ };
10
+ methods: {
11
+ getConnectedRendererIds(): RendererId[];
12
+ getPrimaryRendererId(): null | RendererId;
13
+ getFixtures(): FixtureList;
14
+ getFixtureState(): FixtureState;
15
+ isRendererConnected(): boolean;
16
+ isValidFixtureSelected(): boolean;
17
+ setFixtureState(stateUpdater: StateUpdater<FixtureState>): void;
18
+ selectPrimaryRenderer(primaryRendererId: RendererId): void;
19
+ receiveResponse(msg: MessageType): void;
20
+ };
21
+ events: {
22
+ request(msg: MessageType): void;
23
+ response(msg: MessageType): void;
24
+ };
25
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ export type OnIframeRef = (elRef: null | HTMLIFrameElement) => void;
3
+ type Props = {
4
+ rendererUrl: null | string;
5
+ onIframeRef: OnIframeRef;
6
+ };
7
+ export declare const RendererPreview: React.NamedExoticComponent<Props>;
8
+ export {};
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { Slot } from 'react-plugin';
3
+ import styled from 'styled-components';
4
+ export const RendererPreview = React.memo(function RendererPreview({ rendererUrl, onIframeRef, }) {
5
+ if (!rendererUrl) {
6
+ return null;
7
+ }
8
+ return (React.createElement(Slot, { name: "rendererPreviewOuter" },
9
+ React.createElement(Container, null,
10
+ React.createElement(Iframe, { "data-testid": "previewIframe", ref: onIframeRef, src: rendererUrl, frameBorder: 0, allow: "clipboard-write *" }))));
11
+ });
12
+ const Container = styled.div `
13
+ width: 100%;
14
+ height: 100%;
15
+ background-color: #fff;
16
+ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'%3E%3Cg fill-rule='evenodd'%3E%3Cg fill='%23f1f1f1' fill-opacity='0.4'%3E%3Cpath opacity='.5' d='M96 95h4v1h-4v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9zm-1 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-9-10h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm9-10v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-9-10h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm9-10v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-9-10h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm9-10v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-9-10h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9z'/%3E%3Cpath d='M6 5V0H5v5H0v1h5v94h1V6h94V5H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
17
+ `;
18
+ const Iframe = styled.iframe `
19
+ display: block;
20
+ width: 100%;
21
+ height: 100%;
22
+ margin: 0;
23
+ padding: 0;
24
+ border: none;
25
+ `;
@@ -0,0 +1,2 @@
1
+ import { RendererPreviewContext } from './shared.js';
2
+ export declare function checkRendererStatus(context: RendererPreviewContext, rendererUrl: string): (() => void) | undefined;
@@ -0,0 +1,31 @@
1
+ export function checkRendererStatus(context, rendererUrl) {
2
+ // We can't do fetch requests when Cosmos exports are opened without a
3
+ // web server (ie. via file:/// protocol) so we're left to _assume_ the
4
+ // renderer iframe loads alright.
5
+ if (location.protocol === 'file:') {
6
+ return;
7
+ }
8
+ // The plugin might unmount before the fetch call returns a status, in which
9
+ // case we no longer want to update the (unmounted) plugin state
10
+ let unmounted = false;
11
+ fetch(rendererUrl, { credentials: 'include' })
12
+ .then(({ status }) => {
13
+ if (!unmounted) {
14
+ context.setState(state => ({
15
+ ...state,
16
+ urlStatus: status === 200 ? 'ok' : 'error',
17
+ }));
18
+ }
19
+ })
20
+ .catch(err => {
21
+ if (!unmounted) {
22
+ context.setState(state => ({
23
+ ...state,
24
+ urlStatus: 'error',
25
+ }));
26
+ }
27
+ });
28
+ return () => {
29
+ unmounted = true;
30
+ };
31
+ }
@@ -0,0 +1,6 @@
1
+ import { MessageType } from 'react-cosmos-core';
2
+ import { RendererPreviewContext } from './shared.js';
3
+ export declare function createRendererRequestHandler(): {
4
+ postRendererRequest: (pluginContext: RendererPreviewContext, msg: MessageType) => void;
5
+ setIframeRef: (pluginContext: RendererPreviewContext, iframeRef: null | HTMLIFrameElement) => void;
6
+ };
@@ -0,0 +1,76 @@
1
+ const notificationId = 'renderer-location-change';
2
+ export function createRendererRequestHandler() {
3
+ let state = null;
4
+ function postRendererRequest(pluginContext, msg) {
5
+ if (!state)
6
+ return;
7
+ const { iframeRef } = state;
8
+ if (iframeRef.contentWindow) {
9
+ const iframeWindow = iframeRef.contentWindow;
10
+ if (msg.type === 'selectFixture' &&
11
+ iframeLocationChanged(iframeWindow, iframeRef.src)) {
12
+ const notifications = getNotificationMethods(pluginContext);
13
+ notifications.removeStickyNotification(notificationId);
14
+ iframeWindow.location.replace(iframeRef.src);
15
+ }
16
+ else {
17
+ iframeWindow.postMessage(msg, '*');
18
+ }
19
+ }
20
+ }
21
+ function setIframeRef(pluginContext, iframeRef) {
22
+ if (state)
23
+ state.iframeRef.removeEventListener('load', state.onIframeLoad);
24
+ if (iframeRef) {
25
+ state = {
26
+ iframeRef,
27
+ onIframeLoad(e) {
28
+ const iframe = e.target;
29
+ const iframeWindow = iframe.contentWindow;
30
+ if (iframeWindow) {
31
+ const notifications = getNotificationMethods(pluginContext);
32
+ if (iframeLocationChanged(iframeWindow, iframe.src)) {
33
+ notifications.pushStickyNotification({
34
+ id: notificationId,
35
+ type: 'info',
36
+ title: 'Renderer iframe location changed',
37
+ info: `Reload or select another fixture to reset your preview.`,
38
+ });
39
+ }
40
+ else {
41
+ notifications.removeStickyNotification(notificationId);
42
+ }
43
+ }
44
+ },
45
+ };
46
+ iframeRef.addEventListener('load', state.onIframeLoad);
47
+ }
48
+ else {
49
+ state = null;
50
+ }
51
+ }
52
+ return { postRendererRequest, setIframeRef };
53
+ }
54
+ function iframeLocationChanged(iframeWindow, iframeSrc) {
55
+ // We cannot read the iframe location when the iframe doesn't have the same
56
+ // origin as the main frame, due to cross-origin browser security. In this
57
+ // case we return false to avoid entering an infinite loop.
58
+ if (iframeSrc.indexOf('http') === 0 && !iframeSrc.match(origin))
59
+ return false;
60
+ try {
61
+ const { href } = iframeWindow.location;
62
+ const locationWithoutHash = href.split('#')[0];
63
+ return (locationWithoutHash !== iframeSrc &&
64
+ // Some static servers strip .html extensions automatically
65
+ // https://github.com/zeit/serve-handler/tree/ce35fcd4e1c67356348f4735eed88fb084af9b43#cleanurls-booleanarray
66
+ locationWithoutHash !== iframeSrc.replace(/\.html$/, ''));
67
+ }
68
+ catch (err) {
69
+ // An exception is thrown when trying to access the location of a
70
+ // cross-origin frame, which signals that the iframe location host changed.
71
+ return true;
72
+ }
73
+ }
74
+ function getNotificationMethods(pluginContext) {
75
+ return pluginContext.getMethodsOf('notifications');
76
+ }
@@ -0,0 +1,2 @@
1
+ import { RendererPreviewContext } from './shared.js';
2
+ export declare function handleWindowMessages(context: RendererPreviewContext): () => void;
@@ -0,0 +1,56 @@
1
+ export function handleWindowMessages(context) {
2
+ const handler = createMessageHandler(context);
3
+ window.addEventListener('message', handler, false);
4
+ return () => {
5
+ window.removeEventListener('message', handler, false);
6
+ };
7
+ }
8
+ function createMessageHandler(context) {
9
+ return (msg) => {
10
+ if (!isValidResponse(msg)) {
11
+ return;
12
+ }
13
+ const rendererCore = context.getMethodsOf('rendererCore');
14
+ const response = msg.data;
15
+ rendererCore.receiveResponse(response);
16
+ updateRuntimeStatus(context, response);
17
+ if (response.type === 'rendererReady') {
18
+ rendererCore.selectPrimaryRenderer(response.payload.rendererId);
19
+ }
20
+ };
21
+ }
22
+ function isValidResponse(msg) {
23
+ return (
24
+ // TODO: Create convention to filter out alien messages reliably (eg.
25
+ // maybe tag msgs with source: "cosmos")
26
+ // https://github.com/facebook/react-devtools/issues/812#issuecomment-308827334
27
+ !msg.data.source &&
28
+ // TODO: Improve message validation
29
+ msg.data.type &&
30
+ msg.data.payload);
31
+ }
32
+ function updateRuntimeStatus({ getState, setState }, response) {
33
+ const { runtimeStatus } = getState();
34
+ // Errors are not of interest anymore after renderer connectivity has been
35
+ // established. Errors that occur after renderer is connected are likely
36
+ // errors related to specific fixtures that the user can navigate away from.
37
+ if (runtimeStatus === 'connected') {
38
+ return;
39
+ }
40
+ switch (response.type) {
41
+ case 'rendererReady': {
42
+ return setState(prevState => ({
43
+ ...prevState,
44
+ runtimeStatus: 'connected',
45
+ }));
46
+ }
47
+ case 'rendererError': {
48
+ return setState(prevState => ({
49
+ ...prevState,
50
+ runtimeStatus: 'error',
51
+ }));
52
+ }
53
+ default:
54
+ // The rest of the responses are handled by the renderer core plugin
55
+ }
56
+ }
@@ -0,0 +1,2 @@
1
+ declare const register: () => void;
2
+ export { register };
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import { createPlugin } from 'react-plugin';
3
+ import { checkRendererStatus } from './checkRendererStatus.js';
4
+ import { createRendererRequestHandler } from './handleRendererRequests.js';
5
+ import { handleWindowMessages } from './handleWindowMessages.js';
6
+ import { RendererPreview } from './RendererPreview.js';
7
+ const { postRendererRequest, setIframeRef } = createRendererRequestHandler();
8
+ const { onLoad, on, plug, register } = createPlugin({
9
+ name: 'rendererPreview',
10
+ initialState: {
11
+ urlStatus: 'unknown',
12
+ runtimeStatus: 'pending',
13
+ },
14
+ methods: {
15
+ getUrlStatus,
16
+ getRuntimeStatus,
17
+ },
18
+ });
19
+ on('rendererCore', {
20
+ request: postRendererRequest,
21
+ });
22
+ onLoad((context) => {
23
+ const rendererUrl = getRendererUrl(context);
24
+ if (!rendererUrl) {
25
+ return null;
26
+ }
27
+ return [
28
+ checkRendererStatus(context, rendererUrl),
29
+ handleWindowMessages(context),
30
+ ];
31
+ });
32
+ plug('rendererPreview', ({ pluginContext }) => {
33
+ function handleIframeRef(ref) {
34
+ setIframeRef(pluginContext, ref);
35
+ }
36
+ return (React.createElement(RendererPreview, { rendererUrl: getRendererUrl(pluginContext), onIframeRef: handleIframeRef }));
37
+ });
38
+ export { register };
39
+ if (process.env.NODE_ENV !== 'test')
40
+ register();
41
+ function getUrlStatus({ getState }) {
42
+ return getState().urlStatus;
43
+ }
44
+ function getRuntimeStatus({ getState }) {
45
+ return getState().runtimeStatus;
46
+ }
47
+ function getRendererUrl({ getMethodsOf }) {
48
+ return getMethodsOf('core').getWebRendererUrl();
49
+ }
@@ -0,0 +1,9 @@
1
+ import { PluginContext } from 'react-plugin';
2
+ import { RendererPreviewSpec } from './spec.js';
3
+ export type UrlStatus = 'unknown' | 'ok' | 'error';
4
+ export type RuntimeStatus = 'pending' | 'connected' | 'error';
5
+ export type State = {
6
+ urlStatus: UrlStatus;
7
+ runtimeStatus: RuntimeStatus;
8
+ };
9
+ export type RendererPreviewContext = PluginContext<RendererPreviewSpec>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ export type UrlStatus = 'unknown' | 'ok' | 'error';
2
+ export type RuntimeStatus = 'pending' | 'connected' | 'error';
3
+ export type RendererPreviewSpec = {
4
+ name: 'rendererPreview';
5
+ state: {
6
+ urlStatus: UrlStatus;
7
+ runtimeStatus: RuntimeStatus;
8
+ };
9
+ methods: {
10
+ getUrlStatus(): UrlStatus;
11
+ getRuntimeStatus(): RuntimeStatus;
12
+ };
13
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const register: () => void;
2
+ export { register };
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import { createPlugin } from 'react-plugin';
3
+ import styled from 'styled-components';
4
+ const { plug, register } = createPlugin({
5
+ name: 'rendererSelect',
6
+ });
7
+ plug('sidePanelRow', ({ pluginContext }) => {
8
+ const { getMethodsOf } = pluginContext;
9
+ const rendererCore = getMethodsOf('rendererCore');
10
+ const primaryRendererId = rendererCore.getPrimaryRendererId();
11
+ const connectedRendererIds = rendererCore.getConnectedRendererIds();
12
+ if (!primaryRendererId) {
13
+ return null;
14
+ }
15
+ return (React.createElement(Container, null, connectedRendererIds.map(rendererId => (React.createElement("li", { key: rendererId },
16
+ React.createElement("small", { onClick: () => rendererCore.selectPrimaryRenderer(rendererId), style: {
17
+ cursor: 'pointer',
18
+ fontWeight: rendererId === primaryRendererId ? 'bold' : 'normal',
19
+ } }, rendererId))))));
20
+ });
21
+ export { register };
22
+ if (process.env.NODE_ENV !== 'test')
23
+ register();
24
+ const Container = styled.ul `
25
+ padding: 8px 12px;
26
+ list-style: none;
27
+ `;
@@ -0,0 +1,3 @@
1
+ export type RendererSelectSpec = {
2
+ name: 'rendererSelect';
3
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { ResponsiveDevice, ResponsiveViewport } from '../spec.js';
3
+ type Props = {
4
+ devices: ResponsiveDevice[];
5
+ selectedViewport: ResponsiveViewport;
6
+ scaleFactor: number;
7
+ scaled: boolean;
8
+ selectViewport: (viewport: ResponsiveViewport) => unknown;
9
+ toggleScale: () => unknown;
10
+ };
11
+ export declare const Header: React.NamedExoticComponent<Props>;
12
+ export declare const RotateButton: import("styled-components").StyledComponent<"button", any, {}, never>;
13
+ export {};
@@ -0,0 +1,97 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { Button8 } from '../../../components/buttons/index.js';
4
+ import { Minimize2Icon, RefreshCcwIcon, } from '../../../components/icons/index.js';
5
+ import { NumberInput } from '../../../components/inputs/NumberInput.js';
6
+ import { Select } from '../../../components/inputs/Select.js';
7
+ import { Space } from '../../../components/Space.js';
8
+ import { blue, grey128, grey144, grey216, grey248, grey8, } from '../../../style/colors.js';
9
+ import { quick } from '../../../style/vars.js';
10
+ const numberInputStypes = {
11
+ focusedColor: grey248,
12
+ focusedBg: grey8,
13
+ focusedBoxShadow: `0 0 0.5px 1px ${blue}`,
14
+ };
15
+ export const Header = React.memo(function Header({ devices, selectedViewport, scaleFactor, scaled, selectViewport, toggleScale, }) {
16
+ const options = React.useMemo(() => devices.map(({ width, height, label }) => {
17
+ const value = stringifyViewport({ width, height });
18
+ return { value, label, width, height };
19
+ }), [devices]);
20
+ const canScale = scaleFactor < 1;
21
+ return (React.createElement(Container, { "data-testid": "responsiveHeader" },
22
+ React.createElement(Left, null,
23
+ React.createElement(Select, { testId: "viewportSelect", options: options, value: stringifyViewport(selectedViewport), color: grey248, height: 32, padding: 8, onChange: option => selectViewport({ width: option.width, height: option.height }) })),
24
+ React.createElement(Space, { width: 4 }),
25
+ React.createElement(Center, null,
26
+ React.createElement(NumberInput, { value: selectedViewport.width, minValue: 0, maxValue: 5120, styles: numberInputStypes, onChange: width => selectViewport({ ...selectedViewport, width }) }),
27
+ React.createElement(ViewportX, null, "\u00D7"),
28
+ React.createElement(NumberInput, { value: selectedViewport.height, minValue: 0, maxValue: 5120, styles: numberInputStypes, onChange: height => selectViewport({ ...selectedViewport, height }) }),
29
+ React.createElement(RotateButton, { title: "Rotate", onClick: () => selectViewport({
30
+ width: selectedViewport.height,
31
+ height: selectedViewport.width,
32
+ }) },
33
+ React.createElement(RefreshCcwIcon, { size: 14 }))),
34
+ React.createElement(Space, { width: 4 }),
35
+ React.createElement(Right, null, canScale ? (React.createElement(Button8, { icon: React.createElement(Minimize2Icon, null), label: getScalePercent(scaleFactor), title: "Toggle fit to scale", disabled: false, selected: scaled, onClick: toggleScale })) : (React.createElement(Button8, { icon: React.createElement(Minimize2Icon, null), label: "100%", title: "Toggle fit to scale", disabled: true, selected: false, onClick: () => { } })))));
36
+ });
37
+ function stringifyViewport({ width, height }) {
38
+ return `${width}x${height}`;
39
+ }
40
+ function getScalePercent(scaleFactor) {
41
+ return `${Math.floor(scaleFactor * 100)}%`;
42
+ }
43
+ const Container = styled.div `
44
+ flex-shrink: 0;
45
+ display: flex;
46
+ flex-direction: row;
47
+ align-items: center;
48
+ padding: 4px;
49
+ background: ${grey8};
50
+ white-space: nowrap;
51
+ overflow-x: auto;
52
+ `;
53
+ const Left = styled.div `
54
+ flex: 1;
55
+ display: flex;
56
+ flex-direction: row;
57
+ justify-content: flex-start;
58
+ align-items: center;
59
+ `;
60
+ const Right = styled.div `
61
+ flex: 1;
62
+ display: flex;
63
+ flex-direction: row;
64
+ justify-content: flex-end;
65
+ align-items: center;
66
+ `;
67
+ const Center = styled.div `
68
+ display: flex;
69
+ flex-direction: row;
70
+ align-items: center;
71
+ `;
72
+ const ViewportX = styled.div `
73
+ padding: 0 1px;
74
+ line-height: 32px;
75
+ color: ${grey128};
76
+ `;
77
+ export const RotateButton = styled.button `
78
+ display: flex;
79
+ align-items: center;
80
+ justify-content: center;
81
+ width: 24px;
82
+ height: 24px;
83
+ border: 0;
84
+ background: transparent;
85
+ color: ${grey144};
86
+ outline: none;
87
+ transition: color ${quick}s;
88
+
89
+ :hover,
90
+ :focus {
91
+ color: ${grey216};
92
+ }
93
+
94
+ ::-moz-focus-inner {
95
+ border: 0;
96
+ }
97
+ `;
@@ -0,0 +1,14 @@
1
+ import { Dispatch, ReactNode, SetStateAction } from 'react';
2
+ import { ResponsiveDevice, ResponsiveViewport } from '../spec.js';
3
+ type Props = {
4
+ children?: ReactNode;
5
+ devices: ResponsiveDevice[];
6
+ enabled: boolean;
7
+ viewport: ResponsiveViewport;
8
+ scaled: boolean;
9
+ validFixtureSelected: boolean;
10
+ setViewport: Dispatch<SetStateAction<ResponsiveViewport>>;
11
+ setScaled: (scaled: boolean) => unknown;
12
+ };
13
+ export declare function ResponsivePreview({ children, devices, enabled, viewport, scaled, validFixtureSelected, setViewport, setScaled, }: Props): JSX.Element;
14
+ export {};
@@ -0,0 +1,152 @@
1
+ import { isEqual } from 'lodash-es';
2
+ import React, { useCallback, useEffect, useRef, useState, } from 'react';
3
+ import styled, { css } from 'styled-components';
4
+ import { useDrag } from '../../../hooks/useDrag.js';
5
+ import { grey64, grey8 } from '../../../style/colors.js';
6
+ import { Header } from './Header.js';
7
+ import { getStyles, getViewportScaleFactor, responsivePreviewBorderWidth, responsivePreviewPadding, stretchStyle, } from './style.js';
8
+ export function ResponsivePreview({ children, devices, enabled, viewport, scaled, validFixtureSelected, setViewport, setScaled, }) {
9
+ const [container, setContainer] = useState(null);
10
+ const onWidthChange = useCallback((width) => setViewport(prevViewport => ({ ...prevViewport, width })), [setViewport]);
11
+ const onHeightChange = useCallback((height) => setViewport(prevViewport => ({ ...prevViewport, height })), [setViewport]);
12
+ const leftDrag = useDrag({
13
+ value: viewport.width,
14
+ direction: 'horizontal',
15
+ double: true,
16
+ reverse: true,
17
+ min: 32,
18
+ onChange: onWidthChange,
19
+ });
20
+ const rightDrag = useDrag({
21
+ value: viewport.width,
22
+ direction: 'horizontal',
23
+ double: true,
24
+ min: 32,
25
+ onChange: onWidthChange,
26
+ });
27
+ const bottomDrag = useDrag({
28
+ value: viewport.height,
29
+ direction: 'vertical',
30
+ double: true,
31
+ min: 32,
32
+ onChange: onHeightChange,
33
+ });
34
+ const containerRef = useRef(null);
35
+ const updateContainerSize = useCallback(() => {
36
+ const currentContainer = getContainerSize(containerRef.current);
37
+ if (!isEqual(currentContainer, container))
38
+ setContainer(currentContainer);
39
+ }, [container]);
40
+ useEffect(() => {
41
+ updateContainerSize();
42
+ window.addEventListener('resize', updateContainerSize);
43
+ return () => {
44
+ window.removeEventListener('resize', updateContainerSize);
45
+ };
46
+ }, [updateContainerSize]);
47
+ function handleContainerRef(el) {
48
+ containerRef.current = el;
49
+ if (el)
50
+ updateContainerSize();
51
+ }
52
+ // We don't simply do `return children` because it would cause a flicker
53
+ // whenever switching between responsive and non responsive mode. By
54
+ // returning the same element nesting between states for Preview the
55
+ // component instances are preserved and the transition is seamless.
56
+ if (!validFixtureSelected || !enabled || !container) {
57
+ return (React.createElement(Container, null,
58
+ React.createElement("div", { key: "preview", ref: handleContainerRef, style: stretchStyle },
59
+ React.createElement("div", { style: stretchStyle },
60
+ React.createElement("div", { key: "container", style: stretchStyle },
61
+ React.createElement("div", { style: stretchStyle }, children))))));
62
+ }
63
+ const scaleFactor = getViewportScaleFactor(viewport, container);
64
+ const { maskContainerStyle, padContainerStyle, alignContainerStyle, scaleContainerStyle, } = getStyles({ container, viewport, scaled });
65
+ return (React.createElement(Container, null,
66
+ React.createElement(Header, { devices: devices, selectedViewport: viewport, scaleFactor: scaleFactor, scaled: scaled, selectViewport: setViewport, toggleScale: () => setScaled(!scaled) }),
67
+ React.createElement("div", { key: "preview", ref: handleContainerRef, style: maskContainerStyle },
68
+ React.createElement("div", { style: padContainerStyle },
69
+ React.createElement("div", { key: "container", style: alignContainerStyle },
70
+ React.createElement("div", { style: scaleContainerStyle }, children)),
71
+ React.createElement(LeftDragHandle, { ref: leftDrag.dragElRef },
72
+ React.createElement(VerticalDragIndicator, null)),
73
+ React.createElement(RightDragHandle, { ref: rightDrag.dragElRef },
74
+ React.createElement(VerticalDragIndicator, null)),
75
+ React.createElement(BottomDragHandle, { ref: bottomDrag.dragElRef },
76
+ React.createElement(HorizontalDragIndicator, null)),
77
+ (leftDrag.dragging || rightDrag.dragging || bottomDrag.dragging) && (React.createElement(DragOverlay, { style: {
78
+ width: alignContainerStyle.width,
79
+ height: alignContainerStyle.height,
80
+ } }))))));
81
+ }
82
+ function getContainerSize(containerEl) {
83
+ if (!containerEl)
84
+ return null;
85
+ const { width, height } = containerEl.getBoundingClientRect();
86
+ return { width, height };
87
+ }
88
+ const Container = styled.div.attrs({ 'data-testid': 'responsivePreview' }) `
89
+ flex: 1;
90
+ display: flex;
91
+ flex-direction: column;
92
+ overflow-x: hidden;
93
+ background: ${grey8};
94
+ `;
95
+ const commonDragHandleStyles = css `
96
+ position: absolute;
97
+ user-select: none;
98
+ display: flex;
99
+ justify-content: center;
100
+ align-items: center;
101
+ `;
102
+ const LeftDragHandle = styled.div `
103
+ ${commonDragHandleStyles};
104
+ top: ${responsivePreviewPadding.top}px;
105
+ bottom: ${responsivePreviewPadding.bottom}px;
106
+ left: 0;
107
+ width: ${responsivePreviewPadding.left}px;
108
+ cursor: col-resize;
109
+ flex-direction: column;
110
+ align-items: flex-end;
111
+ `;
112
+ const RightDragHandle = styled.div `
113
+ ${commonDragHandleStyles};
114
+ top: ${responsivePreviewPadding.top}px;
115
+ bottom: ${responsivePreviewPadding.bottom}px;
116
+ right: 0;
117
+ width: ${responsivePreviewPadding.left}px;
118
+ cursor: col-resize;
119
+ flex-direction: column;
120
+ align-items: flex-start;
121
+ `;
122
+ const BottomDragHandle = styled.div `
123
+ ${commonDragHandleStyles};
124
+ bottom: 0;
125
+ left: ${responsivePreviewPadding.left}px;
126
+ right: ${responsivePreviewPadding.right}px;
127
+ height: ${responsivePreviewPadding.bottom}px;
128
+ cursor: row-resize;
129
+ flex-direction: row;
130
+ align-items: flex-start;
131
+ `;
132
+ const VerticalDragIndicator = styled.div `
133
+ margin: 0 8px;
134
+ width: 5px;
135
+ height: 64px;
136
+ border-radius: 3px;
137
+ background: ${grey64};
138
+ `;
139
+ const HorizontalDragIndicator = styled.div `
140
+ margin: 8px 0;
141
+ width: 64px;
142
+ height: 5px;
143
+ border-radius: 3px;
144
+ background: ${grey64};
145
+ `;
146
+ // The purpose of DragOverlay is to cover the renderer iframe while dragging,
147
+ // because otherwise the iframe steaps the mousemove events and stops the drag.
148
+ const DragOverlay = styled.div `
149
+ position: absolute;
150
+ top: ${responsivePreviewPadding.top + responsivePreviewBorderWidth}px;
151
+ left: ${responsivePreviewPadding.left + responsivePreviewBorderWidth}px;
152
+ `;