dockview-core 1.8.4 → 1.8.5

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 (334) hide show
  1. package/README.md +51 -51
  2. package/dist/cjs/api/component.api.d.ts +455 -152
  3. package/dist/cjs/api/component.api.d.ts.map +1 -1
  4. package/dist/cjs/api/component.api.js +895 -592
  5. package/dist/cjs/api/component.api.js.map +1 -1
  6. package/dist/cjs/api/dockviewGroupPanelApi.d.ts +29 -29
  7. package/dist/cjs/api/dockviewGroupPanelApi.js +53 -53
  8. package/dist/cjs/api/dockviewPanelApi.d.ts +47 -47
  9. package/dist/cjs/api/dockviewPanelApi.js +88 -88
  10. package/dist/cjs/api/gridviewPanelApi.d.ts +37 -37
  11. package/dist/cjs/api/gridviewPanelApi.js +47 -47
  12. package/dist/cjs/api/panelApi.d.ts +88 -88
  13. package/dist/cjs/api/panelApi.js +135 -135
  14. package/dist/cjs/api/paneviewPanelApi.d.ts +26 -26
  15. package/dist/cjs/api/paneviewPanelApi.js +57 -57
  16. package/dist/cjs/api/splitviewPanelApi.d.ts +32 -32
  17. package/dist/cjs/api/splitviewPanelApi.js +47 -47
  18. package/dist/cjs/array.d.ts +13 -13
  19. package/dist/cjs/array.js +67 -67
  20. package/dist/cjs/dnd/abstractDragHandler.d.ts +12 -12
  21. package/dist/cjs/dnd/abstractDragHandler.js +141 -141
  22. package/dist/cjs/dnd/dataTransfer.d.ts +30 -31
  23. package/dist/cjs/dnd/dataTransfer.d.ts.map +1 -1
  24. package/dist/cjs/dnd/dataTransfer.js +99 -100
  25. package/dist/cjs/dnd/dataTransfer.js.map +1 -1
  26. package/dist/cjs/dnd/dnd.d.ts +27 -27
  27. package/dist/cjs/dnd/dnd.js +59 -59
  28. package/dist/cjs/dnd/droptarget.d.ts +53 -53
  29. package/dist/cjs/dnd/droptarget.js +304 -304
  30. package/dist/cjs/dnd/droptarget.js.map +1 -1
  31. package/dist/cjs/dnd/ghost.d.ts +1 -1
  32. package/dist/cjs/dnd/ghost.js +15 -15
  33. package/dist/cjs/dnd/groupDragHandler.d.ts +12 -12
  34. package/dist/cjs/dnd/groupDragHandler.js +77 -77
  35. package/dist/cjs/dnd/overlay.d.ts +43 -43
  36. package/dist/cjs/dnd/overlay.d.ts.map +1 -1
  37. package/dist/cjs/dnd/overlay.js +412 -412
  38. package/dist/cjs/dnd/overlay.js.map +1 -1
  39. package/dist/cjs/dockview/components/panel/content.d.ts +30 -30
  40. package/dist/cjs/dockview/components/panel/content.js +100 -100
  41. package/dist/cjs/dockview/components/tab/defaultTab.d.ts +21 -21
  42. package/dist/cjs/dockview/components/tab/defaultTab.js +105 -105
  43. package/dist/cjs/dockview/components/tab/tab.d.ts +34 -34
  44. package/dist/cjs/dockview/components/tab/tab.js +120 -120
  45. package/dist/cjs/dockview/components/titlebar/tabsContainer.d.ts +81 -81
  46. package/dist/cjs/dockview/components/titlebar/tabsContainer.js +325 -325
  47. package/dist/cjs/dockview/components/titlebar/voidContainer.d.ts +17 -17
  48. package/dist/cjs/dockview/components/titlebar/voidContainer.js +77 -77
  49. package/dist/cjs/dockview/components/watermark/watermark.d.ts +18 -18
  50. package/dist/cjs/dockview/components/watermark/watermark.js +87 -87
  51. package/dist/cjs/dockview/deserializer.d.ts +12 -12
  52. package/dist/cjs/dockview/deserializer.js +33 -33
  53. package/dist/cjs/dockview/deserializer.js.map +1 -1
  54. package/dist/cjs/dockview/dockviewComponent.d.ts +159 -159
  55. package/dist/cjs/dockview/dockviewComponent.d.ts.map +1 -1
  56. package/dist/cjs/dockview/dockviewComponent.js +1170 -1156
  57. package/dist/cjs/dockview/dockviewComponent.js.map +1 -1
  58. package/dist/cjs/dockview/dockviewFloatingGroupPanel.d.ts +23 -23
  59. package/dist/cjs/dockview/dockviewFloatingGroupPanel.js +34 -34
  60. package/dist/cjs/dockview/dockviewGroupPanel.d.ts +30 -30
  61. package/dist/cjs/dockview/dockviewGroupPanel.js +97 -97
  62. package/dist/cjs/dockview/dockviewGroupPanelModel.d.ts +185 -185
  63. package/dist/cjs/dockview/dockviewGroupPanelModel.js +632 -631
  64. package/dist/cjs/dockview/dockviewGroupPanelModel.js.map +1 -1
  65. package/dist/cjs/dockview/dockviewPanel.d.ts +41 -41
  66. package/dist/cjs/dockview/dockviewPanel.js +172 -171
  67. package/dist/cjs/dockview/dockviewPanel.js.map +1 -1
  68. package/dist/cjs/dockview/dockviewPanelModel.d.ts +35 -35
  69. package/dist/cjs/dockview/dockviewPanelModel.js +98 -98
  70. package/dist/cjs/dockview/dockviewPanelModel.js.map +1 -1
  71. package/dist/cjs/dockview/options.d.ts +133 -136
  72. package/dist/cjs/dockview/options.d.ts.map +1 -1
  73. package/dist/cjs/dockview/options.js +31 -31
  74. package/dist/cjs/dockview/types.d.ts +63 -63
  75. package/dist/cjs/dockview/types.js +10 -10
  76. package/dist/cjs/dockview/types.js.map +1 -1
  77. package/dist/cjs/dom.d.ts +16 -16
  78. package/dist/cjs/dom.js +197 -197
  79. package/dist/cjs/events.d.ts +47 -47
  80. package/dist/cjs/events.js +216 -216
  81. package/dist/cjs/events.js.map +1 -1
  82. package/dist/cjs/gridview/baseComponentGridview.d.ts +88 -87
  83. package/dist/cjs/gridview/baseComponentGridview.d.ts.map +1 -1
  84. package/dist/cjs/gridview/baseComponentGridview.js +270 -270
  85. package/dist/cjs/gridview/baseComponentGridview.js.map +1 -1
  86. package/dist/cjs/gridview/basePanelView.d.ts +40 -40
  87. package/dist/cjs/gridview/basePanelView.js +156 -156
  88. package/dist/cjs/gridview/branchNode.d.ts +49 -49
  89. package/dist/cjs/gridview/branchNode.js +343 -343
  90. package/dist/cjs/gridview/gridview.d.ts +133 -133
  91. package/dist/cjs/gridview/gridview.js +547 -547
  92. package/dist/cjs/gridview/gridviewComponent.d.ts +80 -80
  93. package/dist/cjs/gridview/gridviewComponent.d.ts.map +1 -1
  94. package/dist/cjs/gridview/gridviewComponent.js +362 -360
  95. package/dist/cjs/gridview/gridviewComponent.js.map +1 -1
  96. package/dist/cjs/gridview/gridviewPanel.d.ts +65 -65
  97. package/dist/cjs/gridview/gridviewPanel.js +214 -214
  98. package/dist/cjs/gridview/leafNode.d.ts +34 -34
  99. package/dist/cjs/gridview/leafNode.js +170 -170
  100. package/dist/cjs/gridview/leafNode.js.map +1 -1
  101. package/dist/cjs/gridview/options.d.ts +17 -18
  102. package/dist/cjs/gridview/options.d.ts.map +1 -1
  103. package/dist/cjs/gridview/options.js +2 -2
  104. package/dist/cjs/gridview/types.d.ts +3 -3
  105. package/dist/cjs/gridview/types.js +2 -2
  106. package/dist/cjs/index.d.ts +42 -42
  107. package/dist/cjs/index.js +61 -61
  108. package/dist/cjs/lifecycle.d.ts +23 -23
  109. package/dist/cjs/lifecycle.js +65 -65
  110. package/dist/cjs/lifecycle.js.map +1 -1
  111. package/dist/cjs/math.d.ts +5 -5
  112. package/dist/cjs/math.js +34 -34
  113. package/dist/cjs/panel/componentFactory.d.ts +11 -10
  114. package/dist/cjs/panel/componentFactory.d.ts.map +1 -1
  115. package/dist/cjs/panel/componentFactory.js +30 -30
  116. package/dist/cjs/panel/componentFactory.js.map +1 -1
  117. package/dist/cjs/panel/types.d.ts +33 -33
  118. package/dist/cjs/panel/types.js +2 -2
  119. package/dist/cjs/paneview/defaultPaneviewHeader.d.ts +21 -21
  120. package/dist/cjs/paneview/defaultPaneviewHeader.js +90 -90
  121. package/dist/cjs/paneview/draggablePaneviewPanel.d.ts +21 -21
  122. package/dist/cjs/paneview/draggablePaneviewPanel.js +131 -131
  123. package/dist/cjs/paneview/options.d.ts +25 -28
  124. package/dist/cjs/paneview/options.d.ts.map +1 -1
  125. package/dist/cjs/paneview/options.js +2 -2
  126. package/dist/cjs/paneview/paneview.d.ts +40 -40
  127. package/dist/cjs/paneview/paneview.d.ts.map +1 -1
  128. package/dist/cjs/paneview/paneview.js +200 -201
  129. package/dist/cjs/paneview/paneview.js.map +1 -1
  130. package/dist/cjs/paneview/paneviewComponent.d.ts +128 -128
  131. package/dist/cjs/paneview/paneviewComponent.js +400 -397
  132. package/dist/cjs/paneview/paneviewComponent.js.map +1 -1
  133. package/dist/cjs/paneview/paneviewPanel.d.ts +92 -92
  134. package/dist/cjs/paneview/paneviewPanel.d.ts.map +1 -1
  135. package/dist/cjs/paneview/paneviewPanel.js +275 -275
  136. package/dist/cjs/resizable.d.ts +10 -7
  137. package/dist/cjs/resizable.d.ts.map +1 -1
  138. package/dist/cjs/resizable.js +79 -64
  139. package/dist/cjs/resizable.js.map +1 -1
  140. package/dist/cjs/splitview/options.d.ts +26 -27
  141. package/dist/cjs/splitview/options.d.ts.map +1 -1
  142. package/dist/cjs/splitview/options.js +2 -2
  143. package/dist/cjs/splitview/splitview.d.ts +128 -128
  144. package/dist/cjs/splitview/splitview.js +936 -936
  145. package/dist/cjs/splitview/splitview.js.map +1 -1
  146. package/dist/cjs/splitview/splitviewComponent.d.ts +101 -101
  147. package/dist/cjs/splitview/splitviewComponent.js +395 -392
  148. package/dist/cjs/splitview/splitviewComponent.js.map +1 -1
  149. package/dist/cjs/splitview/splitviewPanel.d.ts +45 -45
  150. package/dist/cjs/splitview/splitviewPanel.d.ts.map +1 -1
  151. package/dist/cjs/splitview/splitviewPanel.js +179 -179
  152. package/dist/cjs/splitview/splitviewPanel.js.map +1 -1
  153. package/dist/cjs/splitview/viewItem.d.ts +25 -25
  154. package/dist/cjs/splitview/viewItem.js +119 -119
  155. package/dist/cjs/svg.d.ts +3 -3
  156. package/dist/cjs/svg.js +43 -43
  157. package/dist/cjs/types.d.ts +2 -2
  158. package/dist/cjs/types.js +2 -2
  159. package/dist/dockview-core.amd.js +7650 -7316
  160. package/dist/dockview-core.amd.js.map +1 -1
  161. package/dist/dockview-core.amd.min.js +2 -2
  162. package/dist/dockview-core.amd.min.js.map +1 -1
  163. package/dist/dockview-core.amd.min.noStyle.js +2 -2
  164. package/dist/dockview-core.amd.min.noStyle.js.map +1 -1
  165. package/dist/dockview-core.amd.noStyle.js +7601 -7267
  166. package/dist/dockview-core.amd.noStyle.js.map +1 -1
  167. package/dist/dockview-core.cjs.js +7650 -7316
  168. package/dist/dockview-core.cjs.js.map +1 -1
  169. package/dist/dockview-core.esm.js +7650 -7316
  170. package/dist/dockview-core.esm.js.map +1 -1
  171. package/dist/dockview-core.esm.min.js +2 -2
  172. package/dist/dockview-core.esm.min.js.map +1 -1
  173. package/dist/dockview-core.js +7650 -7316
  174. package/dist/dockview-core.js.map +1 -1
  175. package/dist/dockview-core.min.js +2 -2
  176. package/dist/dockview-core.min.js.map +1 -1
  177. package/dist/dockview-core.min.noStyle.js +2 -2
  178. package/dist/dockview-core.min.noStyle.js.map +1 -1
  179. package/dist/dockview-core.noStyle.js +7601 -7267
  180. package/dist/dockview-core.noStyle.js.map +1 -1
  181. package/dist/esm/api/component.api.d.ts +455 -152
  182. package/dist/esm/api/component.api.d.ts.map +1 -1
  183. package/dist/esm/api/component.api.js +638 -335
  184. package/dist/esm/api/component.api.js.map +1 -1
  185. package/dist/esm/api/dockviewGroupPanelApi.d.ts +29 -29
  186. package/dist/esm/api/dockviewGroupPanelApi.js +27 -27
  187. package/dist/esm/api/dockviewPanelApi.d.ts +47 -47
  188. package/dist/esm/api/dockviewPanelApi.js +53 -53
  189. package/dist/esm/api/gridviewPanelApi.d.ts +37 -37
  190. package/dist/esm/api/gridviewPanelApi.js +25 -25
  191. package/dist/esm/api/panelApi.d.ts +88 -88
  192. package/dist/esm/api/panelApi.js +93 -93
  193. package/dist/esm/api/paneviewPanelApi.d.ts +26 -26
  194. package/dist/esm/api/paneviewPanelApi.js +27 -27
  195. package/dist/esm/api/splitviewPanelApi.d.ts +32 -32
  196. package/dist/esm/api/splitviewPanelApi.js +25 -25
  197. package/dist/esm/array.d.ts +13 -13
  198. package/dist/esm/array.js +57 -57
  199. package/dist/esm/dnd/abstractDragHandler.d.ts +12 -12
  200. package/dist/esm/dnd/abstractDragHandler.js +63 -63
  201. package/dist/esm/dnd/dataTransfer.d.ts +30 -31
  202. package/dist/esm/dnd/dataTransfer.d.ts.map +1 -1
  203. package/dist/esm/dnd/dataTransfer.js +66 -69
  204. package/dist/esm/dnd/dataTransfer.js.map +1 -1
  205. package/dist/esm/dnd/dnd.d.ts +27 -27
  206. package/dist/esm/dnd/dnd.js +36 -36
  207. package/dist/esm/dnd/droptarget.d.ts +53 -53
  208. package/dist/esm/dnd/droptarget.js +274 -274
  209. package/dist/esm/dnd/droptarget.js.map +1 -1
  210. package/dist/esm/dnd/ghost.d.ts +1 -1
  211. package/dist/esm/dnd/ghost.js +11 -11
  212. package/dist/esm/dnd/groupDragHandler.d.ts +12 -12
  213. package/dist/esm/dnd/groupDragHandler.js +54 -54
  214. package/dist/esm/dnd/overlay.d.ts +43 -43
  215. package/dist/esm/dnd/overlay.d.ts.map +1 -1
  216. package/dist/esm/dnd/overlay.js +304 -304
  217. package/dist/esm/dnd/overlay.js.map +1 -1
  218. package/dist/esm/dockview/components/panel/content.d.ts +30 -30
  219. package/dist/esm/dockview/components/panel/content.js +73 -73
  220. package/dist/esm/dockview/components/tab/defaultTab.d.ts +21 -21
  221. package/dist/esm/dockview/components/tab/defaultTab.js +67 -67
  222. package/dist/esm/dockview/components/tab/tab.d.ts +34 -34
  223. package/dist/esm/dockview/components/tab/tab.js +90 -90
  224. package/dist/esm/dockview/components/titlebar/tabsContainer.d.ts +81 -81
  225. package/dist/esm/dockview/components/titlebar/tabsContainer.js +239 -239
  226. package/dist/esm/dockview/components/titlebar/voidContainer.d.ts +17 -17
  227. package/dist/esm/dockview/components/titlebar/voidContainer.js +51 -51
  228. package/dist/esm/dockview/components/watermark/watermark.d.ts +18 -18
  229. package/dist/esm/dockview/components/watermark/watermark.js +61 -61
  230. package/dist/esm/dockview/deserializer.d.ts +12 -12
  231. package/dist/esm/dockview/deserializer.js +28 -28
  232. package/dist/esm/dockview/deserializer.js.map +1 -1
  233. package/dist/esm/dockview/dockviewComponent.d.ts +159 -159
  234. package/dist/esm/dockview/dockviewComponent.d.ts.map +1 -1
  235. package/dist/esm/dockview/dockviewComponent.js +932 -918
  236. package/dist/esm/dockview/dockviewComponent.js.map +1 -1
  237. package/dist/esm/dockview/dockviewFloatingGroupPanel.d.ts +23 -23
  238. package/dist/esm/dockview/dockviewFloatingGroupPanel.js +12 -12
  239. package/dist/esm/dockview/dockviewGroupPanel.d.ts +30 -30
  240. package/dist/esm/dockview/dockviewGroupPanel.js +51 -51
  241. package/dist/esm/dockview/dockviewGroupPanelModel.d.ts +185 -185
  242. package/dist/esm/dockview/dockviewGroupPanelModel.js +499 -498
  243. package/dist/esm/dockview/dockviewGroupPanelModel.js.map +1 -1
  244. package/dist/esm/dockview/dockviewPanel.d.ts +41 -41
  245. package/dist/esm/dockview/dockviewPanel.js +105 -104
  246. package/dist/esm/dockview/dockviewPanel.js.map +1 -1
  247. package/dist/esm/dockview/dockviewPanelModel.d.ts +35 -35
  248. package/dist/esm/dockview/dockviewPanelModel.js +74 -74
  249. package/dist/esm/dockview/dockviewPanelModel.js.map +1 -1
  250. package/dist/esm/dockview/options.d.ts +133 -136
  251. package/dist/esm/dockview/options.d.ts.map +1 -1
  252. package/dist/esm/dockview/options.js +24 -24
  253. package/dist/esm/dockview/types.d.ts +63 -63
  254. package/dist/esm/dockview/types.js +7 -7
  255. package/dist/esm/dom.d.ts +16 -16
  256. package/dist/esm/dom.js +126 -126
  257. package/dist/esm/events.d.ts +47 -47
  258. package/dist/esm/events.js +156 -156
  259. package/dist/esm/events.js.map +1 -1
  260. package/dist/esm/gridview/baseComponentGridview.d.ts +88 -87
  261. package/dist/esm/gridview/baseComponentGridview.d.ts.map +1 -1
  262. package/dist/esm/gridview/baseComponentGridview.js +184 -184
  263. package/dist/esm/gridview/baseComponentGridview.js.map +1 -1
  264. package/dist/esm/gridview/basePanelView.d.ts +40 -40
  265. package/dist/esm/gridview/basePanelView.js +85 -85
  266. package/dist/esm/gridview/branchNode.d.ts +49 -49
  267. package/dist/esm/gridview/branchNode.js +219 -219
  268. package/dist/esm/gridview/gridview.d.ts +133 -133
  269. package/dist/esm/gridview/gridview.js +461 -461
  270. package/dist/esm/gridview/gridviewComponent.d.ts +80 -80
  271. package/dist/esm/gridview/gridviewComponent.d.ts.map +1 -1
  272. package/dist/esm/gridview/gridviewComponent.js +264 -262
  273. package/dist/esm/gridview/gridviewComponent.js.map +1 -1
  274. package/dist/esm/gridview/gridviewPanel.d.ts +65 -65
  275. package/dist/esm/gridview/gridviewPanel.js +151 -151
  276. package/dist/esm/gridview/leafNode.d.ts +34 -34
  277. package/dist/esm/gridview/leafNode.js +103 -103
  278. package/dist/esm/gridview/options.d.ts +17 -18
  279. package/dist/esm/gridview/options.d.ts.map +1 -1
  280. package/dist/esm/gridview/options.js +1 -1
  281. package/dist/esm/gridview/types.d.ts +3 -3
  282. package/dist/esm/gridview/types.js +1 -1
  283. package/dist/esm/index.d.ts +42 -42
  284. package/dist/esm/index.js +34 -34
  285. package/dist/esm/lifecycle.d.ts +23 -23
  286. package/dist/esm/lifecycle.js +41 -41
  287. package/dist/esm/math.d.ts +5 -5
  288. package/dist/esm/math.js +28 -28
  289. package/dist/esm/panel/componentFactory.d.ts +11 -10
  290. package/dist/esm/panel/componentFactory.d.ts.map +1 -1
  291. package/dist/esm/panel/componentFactory.js +24 -24
  292. package/dist/esm/panel/componentFactory.js.map +1 -1
  293. package/dist/esm/panel/types.d.ts +33 -33
  294. package/dist/esm/panel/types.js +1 -1
  295. package/dist/esm/paneview/defaultPaneviewHeader.d.ts +21 -21
  296. package/dist/esm/paneview/defaultPaneviewHeader.js +63 -63
  297. package/dist/esm/paneview/draggablePaneviewPanel.d.ts +21 -21
  298. package/dist/esm/paneview/draggablePaneviewPanel.js +92 -92
  299. package/dist/esm/paneview/options.d.ts +25 -28
  300. package/dist/esm/paneview/options.d.ts.map +1 -1
  301. package/dist/esm/paneview/options.js +1 -1
  302. package/dist/esm/paneview/paneview.d.ts +40 -40
  303. package/dist/esm/paneview/paneview.d.ts.map +1 -1
  304. package/dist/esm/paneview/paneview.js +145 -145
  305. package/dist/esm/paneview/paneviewComponent.d.ts +128 -128
  306. package/dist/esm/paneview/paneviewComponent.js +276 -273
  307. package/dist/esm/paneview/paneviewComponent.js.map +1 -1
  308. package/dist/esm/paneview/paneviewPanel.d.ts +92 -92
  309. package/dist/esm/paneview/paneviewPanel.d.ts.map +1 -1
  310. package/dist/esm/paneview/paneviewPanel.js +192 -192
  311. package/dist/esm/resizable.d.ts +10 -7
  312. package/dist/esm/resizable.d.ts.map +1 -1
  313. package/dist/esm/resizable.js +48 -38
  314. package/dist/esm/resizable.js.map +1 -1
  315. package/dist/esm/splitview/options.d.ts +26 -27
  316. package/dist/esm/splitview/options.d.ts.map +1 -1
  317. package/dist/esm/splitview/options.js +1 -1
  318. package/dist/esm/splitview/splitview.d.ts +128 -128
  319. package/dist/esm/splitview/splitview.js +704 -704
  320. package/dist/esm/splitview/splitviewComponent.d.ts +101 -101
  321. package/dist/esm/splitview/splitviewComponent.js +261 -258
  322. package/dist/esm/splitview/splitviewComponent.js.map +1 -1
  323. package/dist/esm/splitview/splitviewPanel.d.ts +45 -45
  324. package/dist/esm/splitview/splitviewPanel.d.ts.map +1 -1
  325. package/dist/esm/splitview/splitviewPanel.js +108 -108
  326. package/dist/esm/splitview/splitviewPanel.js.map +1 -1
  327. package/dist/esm/splitview/viewItem.d.ts +25 -25
  328. package/dist/esm/splitview/viewItem.js +74 -74
  329. package/dist/esm/svg.d.ts +3 -3
  330. package/dist/esm/svg.js +31 -31
  331. package/dist/esm/types.d.ts +2 -2
  332. package/dist/esm/types.js +1 -1
  333. package/package.json +30 -42
  334. package/LICENSE +0 -21
@@ -1,919 +1,933 @@
1
- import { getRelativeLocation, getGridLocation, } from '../gridview/gridview';
2
- import { directionToPosition, Droptarget } from '../dnd/droptarget';
3
- import { tail, sequenceEquals, remove } from '../array';
4
- import { DockviewPanel } from './dockviewPanel';
5
- import { CompositeDisposable } from '../lifecycle';
6
- import { Event, Emitter } from '../events';
7
- import { Watermark } from './components/watermark/watermark';
8
- import { DockviewDropTargets, } from './types';
9
- import { sequentialNumberGenerator } from '../math';
10
- import { DefaultDockviewDeserialzier } from './deserializer';
11
- import { createComponent } from '../panel/componentFactory';
12
- import { isGroupOptionsWithGroup, isGroupOptionsWithPanel, isPanelOptionsWithGroup, isPanelOptionsWithPanel, } from './options';
13
- import { BaseGrid, toTarget, } from '../gridview/baseComponentGridview';
14
- import { DockviewApi } from '../api/component.api';
15
- import { Orientation, Sizing } from '../splitview/splitview';
16
- import { DockviewGroupPanel } from './dockviewGroupPanel';
17
- import { DockviewPanelModel } from './dockviewPanelModel';
18
- import { getPanelData } from '../dnd/dataTransfer';
19
- import { Overlay } from '../dnd/overlay';
20
- import { toggleClass, watchElementResize } from '../dom';
21
- import { DockviewFloatingGroupPanel, } from './dockviewFloatingGroupPanel';
22
- const DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE = 100;
23
- function typeValidate3(data, path) {
24
- if (typeof data.id !== 'string') {
25
- throw new Error(`${path}.id must be a string`);
26
- }
27
- if (typeof data.activeView !== 'string' ||
28
- typeof data.activeView !== 'undefined') {
29
- throw new Error(`${path}.activeView must be a string of undefined`);
30
- }
31
- }
32
- function typeValidate2(data, path) {
33
- if (typeof data.size !== 'number' && typeof data.size !== 'undefined') {
34
- throw new Error(`${path}.size must be a number or undefined`);
35
- }
36
- if (typeof data.visible !== 'boolean' &&
37
- typeof data.visible !== 'undefined') {
38
- throw new Error(`${path}.visible must be a boolean or undefined`);
39
- }
40
- if (data.type === 'leaf') {
41
- if (typeof data.data !== 'object' ||
42
- data.data === null ||
43
- Array.isArray(data.data)) {
44
- throw new Error('object must be a non-null object');
45
- }
46
- typeValidate3(data.data, `${path}.data`);
47
- }
48
- else if (data.type === 'branch') {
49
- if (!Array.isArray(data.data)) {
50
- throw new Error(`${path}.data must be an array`);
51
- }
52
- }
53
- else {
54
- throw new Error(`${path}.type must be onew of {'branch', 'leaf'}`);
55
- }
56
- }
57
- function typeValidate(data) {
58
- if (typeof data !== 'object' || data === null) {
59
- throw new Error('object must be a non-null object');
60
- }
61
- const { grid, panels, activeGroup, floatingGroups } = data;
62
- if (typeof grid !== 'object' || grid === null) {
63
- throw new Error("'.grid' must be a non-null object");
64
- }
65
- if (typeof grid.height !== 'number') {
66
- throw new Error("'.grid.height' must be a number");
67
- }
68
- if (typeof grid.width !== 'number') {
69
- throw new Error("'.grid.width' must be a number");
70
- }
71
- if (typeof grid.root !== 'object' || grid.root === null) {
72
- throw new Error("'.grid.root' must be a non-null object");
73
- }
74
- if (grid.root.type !== 'branch') {
75
- throw new Error(".grid.root.type must be of type 'branch'");
76
- }
77
- if (grid.orientation !== Orientation.HORIZONTAL &&
78
- grid.orientation !== Orientation.VERTICAL) {
79
- throw new Error(`'.grid.width' must be one of {${Orientation.HORIZONTAL}, ${Orientation.VERTICAL}}`);
80
- }
81
- typeValidate2(grid.root, '.grid.root');
82
- }
83
- export class DockviewComponent extends BaseGrid {
84
- get orientation() {
85
- return this.gridview.orientation;
86
- }
87
- get totalPanels() {
88
- return this.panels.length;
89
- }
90
- get panels() {
91
- return this.groups.flatMap((group) => group.panels);
92
- }
93
- get options() {
94
- return this._options;
95
- }
96
- get activePanel() {
97
- const activeGroup = this.activeGroup;
98
- if (!activeGroup) {
99
- return undefined;
100
- }
101
- return activeGroup.activePanel;
102
- }
103
- constructor(options) {
104
- super({
105
- proportionalLayout: true,
106
- orientation: options.orientation || Orientation.HORIZONTAL,
107
- styles: options.styles,
108
- parentElement: options.parentElement,
109
- });
110
- this.nextGroupId = sequentialNumberGenerator();
111
- this._deserializer = new DefaultDockviewDeserialzier(this);
112
- this.watermark = null;
113
- this._onWillDragPanel = new Emitter();
114
- this.onWillDragPanel = this._onWillDragPanel.event;
115
- this._onWillDragGroup = new Emitter();
116
- this.onWillDragGroup = this._onWillDragGroup.event;
117
- this._onDidDrop = new Emitter();
118
- this.onDidDrop = this._onDidDrop.event;
119
- this._onDidRemovePanel = new Emitter();
120
- this.onDidRemovePanel = this._onDidRemovePanel.event;
121
- this._onDidAddPanel = new Emitter();
122
- this.onDidAddPanel = this._onDidAddPanel.event;
123
- this._onDidLayoutFromJSON = new Emitter();
124
- this.onDidLayoutFromJSON = this._onDidLayoutFromJSON.event;
125
- this._onDidActivePanelChange = new Emitter();
126
- this.onDidActivePanelChange = this._onDidActivePanelChange.event;
127
- this.floatingGroups = [];
128
- toggleClass(this.gridview.element, 'dv-dockview', true);
129
- this.addDisposables(this._onWillDragPanel, this._onWillDragGroup, this._onDidActivePanelChange, this._onDidAddPanel, this._onDidRemovePanel, this._onDidLayoutFromJSON, this._onDidDrop, Event.any(this.onDidAddGroup, this.onDidRemoveGroup)(() => {
130
- this.updateWatermark();
131
- }), Event.any(this.onDidAddPanel, this.onDidRemovePanel, this.onDidActivePanelChange)(() => {
132
- this._bufferOnDidLayoutChange.fire();
133
- }));
134
- this._options = options;
135
- if (!this.options.components) {
136
- this.options.components = {};
137
- }
138
- if (!this.options.frameworkComponents) {
139
- this.options.frameworkComponents = {};
140
- }
141
- if (!this.options.frameworkTabComponents) {
142
- this.options.frameworkTabComponents = {};
143
- }
144
- if (!this.options.tabComponents) {
145
- this.options.tabComponents = {};
146
- }
147
- if (!this.options.watermarkComponent &&
148
- !this.options.watermarkFrameworkComponent) {
149
- this.options.watermarkComponent = Watermark;
150
- }
151
- const dropTarget = new Droptarget(this.element, {
152
- canDisplayOverlay: (event, position) => {
153
- const data = getPanelData();
154
- if (data) {
155
- if (data.viewId !== this.id) {
156
- return false;
157
- }
158
- if (position === 'center') {
159
- // center drop target is only allowed if there are no panels in the grid
160
- // floating panels are allowed
161
- return this.gridview.length === 0;
162
- }
163
- return true;
164
- }
165
- if (this.options.showDndOverlay) {
166
- if (position === 'center' && this.gridview.length !== 0) {
167
- /**
168
- * for external events only show the four-corner drag overlays, disable
169
- * the center position so that external drag events can fall through to the group
170
- * and panel drop target handlers
171
- */
172
- return false;
173
- }
174
- return this.options.showDndOverlay({
175
- nativeEvent: event,
176
- position: position,
177
- target: DockviewDropTargets.Edge,
178
- getData: getPanelData,
179
- });
180
- }
181
- return false;
182
- },
183
- acceptedTargetZones: ['top', 'bottom', 'left', 'right', 'center'],
184
- overlayModel: {
185
- activationSize: { type: 'pixels', value: 10 },
186
- size: { type: 'pixels', value: 20 },
187
- },
188
- });
189
- this.addDisposables(dropTarget.onDrop((event) => {
190
- const data = getPanelData();
191
- if (data) {
192
- this.moveGroupOrPanel(this.orthogonalize(event.position), data.groupId, data.panelId || undefined, 'center');
193
- }
194
- else {
195
- this._onDidDrop.fire(Object.assign(Object.assign({}, event), { api: this._api, group: null, getData: getPanelData }));
196
- }
197
- }), dropTarget);
198
- this._api = new DockviewApi(this);
199
- this.updateWatermark();
200
- }
201
- addFloatingGroup(item, coord, options) {
202
- var _a, _b, _c, _d, _e, _f;
203
- let group;
204
- if (item instanceof DockviewPanel) {
205
- group = this.createGroup();
206
- this.removePanel(item, {
207
- removeEmptyGroup: true,
208
- skipDispose: true,
209
- });
210
- group.model.openPanel(item);
211
- }
212
- else {
213
- group = item;
214
- const skip = typeof (options === null || options === void 0 ? void 0 : options.skipRemoveGroup) === 'boolean' &&
215
- options.skipRemoveGroup;
216
- if (!skip) {
217
- this.doRemoveGroup(item, { skipDispose: true });
218
- }
219
- }
220
- group.model.isFloating = true;
221
- const overlayLeft = typeof (coord === null || coord === void 0 ? void 0 : coord.x) === 'number' ? Math.max(coord.x, 0) : 100;
222
- const overlayTop = typeof (coord === null || coord === void 0 ? void 0 : coord.y) === 'number' ? Math.max(coord.y, 0) : 100;
223
- const overlay = new Overlay({
224
- container: this.gridview.element,
225
- content: group.element,
226
- height: (_a = coord === null || coord === void 0 ? void 0 : coord.height) !== null && _a !== void 0 ? _a : 300,
227
- width: (_b = coord === null || coord === void 0 ? void 0 : coord.width) !== null && _b !== void 0 ? _b : 300,
228
- left: overlayLeft,
229
- top: overlayTop,
230
- minimumInViewportWidth: this.options.floatingGroupBounds === 'boundedWithinViewport'
231
- ? undefined
232
- : (_d = (_c = this.options.floatingGroupBounds) === null || _c === void 0 ? void 0 : _c.minimumWidthWithinViewport) !== null && _d !== void 0 ? _d : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE,
233
- minimumInViewportHeight: this.options.floatingGroupBounds === 'boundedWithinViewport'
234
- ? undefined
235
- : (_f = (_e = this.options.floatingGroupBounds) === null || _e === void 0 ? void 0 : _e.minimumHeightWithinViewport) !== null && _f !== void 0 ? _f : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE,
236
- });
237
- const el = group.element.querySelector('.void-container');
238
- if (!el) {
239
- throw new Error('failed to find drag handle');
240
- }
241
- overlay.setupDrag(el, {
242
- inDragMode: typeof (options === null || options === void 0 ? void 0 : options.inDragMode) === 'boolean'
243
- ? options.inDragMode
244
- : false,
245
- });
246
- const floatingGroupPanel = new DockviewFloatingGroupPanel(group, overlay);
247
- const disposable = watchElementResize(group.element, (entry) => {
248
- const { width, height } = entry.contentRect;
249
- group.layout(width, height); // let the group know it's size is changing so it can fire events to the panel
250
- });
251
- floatingGroupPanel.addDisposables(overlay.onDidChange(() => {
252
- // this is either a resize or a move
253
- // to inform the panels .layout(...) the group with it's current size
254
- // don't care about resize since the above watcher handles that
255
- group.layout(group.height, group.width);
256
- }), overlay.onDidChangeEnd(() => {
257
- this._bufferOnDidLayoutChange.fire();
258
- }), group.onDidChange((event) => {
259
- overlay.setBounds({
260
- height: event === null || event === void 0 ? void 0 : event.height,
261
- width: event === null || event === void 0 ? void 0 : event.width,
262
- });
263
- }), {
264
- dispose: () => {
265
- disposable.dispose();
266
- group.model.isFloating = false;
267
- remove(this.floatingGroups, floatingGroupPanel);
268
- this.updateWatermark();
269
- },
270
- });
271
- this.floatingGroups.push(floatingGroupPanel);
272
- this.updateWatermark();
273
- }
274
- orthogonalize(position) {
275
- switch (position) {
276
- case 'top':
277
- case 'bottom':
278
- if (this.gridview.orientation === Orientation.HORIZONTAL) {
279
- // we need to add to a vertical splitview but the current root is a horizontal splitview.
280
- // insert a vertical splitview at the root level and add the existing view as a child
281
- this.gridview.insertOrthogonalSplitviewAtRoot();
282
- }
283
- break;
284
- case 'left':
285
- case 'right':
286
- if (this.gridview.orientation === Orientation.VERTICAL) {
287
- // we need to add to a horizontal splitview but the current root is a vertical splitview.
288
- // insert a horiziontal splitview at the root level and add the existing view as a child
289
- this.gridview.insertOrthogonalSplitviewAtRoot();
290
- }
291
- break;
292
- default:
293
- break;
294
- }
295
- switch (position) {
296
- case 'top':
297
- case 'left':
298
- case 'center':
299
- return this.createGroupAtLocation([0]); // insert into first position
300
- case 'bottom':
301
- case 'right':
302
- return this.createGroupAtLocation([this.gridview.length]); // insert into last position
303
- default:
304
- throw new Error(`unsupported position ${position}`);
305
- }
306
- }
307
- updateOptions(options) {
308
- var _a, _b;
309
- const hasOrientationChanged = typeof options.orientation === 'string' &&
310
- this.gridview.orientation !== options.orientation;
311
- const hasFloatingGroupOptionsChanged = options.floatingGroupBounds !== undefined &&
312
- options.floatingGroupBounds !== this.options.floatingGroupBounds;
313
- this._options = Object.assign(Object.assign({}, this.options), options);
314
- if (hasOrientationChanged) {
315
- this.gridview.orientation = options.orientation;
316
- }
317
- if (hasFloatingGroupOptionsChanged) {
318
- for (const group of this.floatingGroups) {
319
- switch (this.options.floatingGroupBounds) {
320
- case 'boundedWithinViewport':
321
- group.overlay.minimumInViewportHeight = undefined;
322
- group.overlay.minimumInViewportWidth = undefined;
323
- break;
324
- case undefined:
325
- group.overlay.minimumInViewportHeight =
326
- DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE;
327
- group.overlay.minimumInViewportWidth =
328
- DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE;
329
- break;
330
- default:
331
- group.overlay.minimumInViewportHeight =
332
- (_a = this.options.floatingGroupBounds) === null || _a === void 0 ? void 0 : _a.minimumHeightWithinViewport;
333
- group.overlay.minimumInViewportWidth =
334
- (_b = this.options.floatingGroupBounds) === null || _b === void 0 ? void 0 : _b.minimumWidthWithinViewport;
335
- }
336
- group.overlay.setBounds({});
337
- }
338
- }
339
- this.layout(this.gridview.width, this.gridview.height, true);
340
- }
341
- layout(width, height, forceResize) {
342
- super.layout(width, height, forceResize);
343
- if (this.floatingGroups) {
344
- for (const floating of this.floatingGroups) {
345
- // ensure floting groups stay within visible boundaries
346
- floating.overlay.setBounds();
347
- }
348
- }
349
- }
350
- focus() {
351
- var _a;
352
- (_a = this.activeGroup) === null || _a === void 0 ? void 0 : _a.focus();
353
- }
354
- getGroupPanel(id) {
355
- return this.panels.find((panel) => panel.id === id);
356
- }
357
- setActivePanel(panel) {
358
- this.doSetGroupActive(panel.group);
359
- panel.group.model.openPanel(panel);
360
- }
361
- moveToNext(options = {}) {
362
- var _a;
363
- if (!options.group) {
364
- if (!this.activeGroup) {
365
- return;
366
- }
367
- options.group = this.activeGroup;
368
- }
369
- if (options.includePanel && options.group) {
370
- if (options.group.activePanel !==
371
- options.group.panels[options.group.panels.length - 1]) {
372
- options.group.model.moveToNext({ suppressRoll: true });
373
- return;
374
- }
375
- }
376
- const location = getGridLocation(options.group.element);
377
- const next = (_a = this.gridview.next(location)) === null || _a === void 0 ? void 0 : _a.view;
378
- this.doSetGroupActive(next);
379
- }
380
- moveToPrevious(options = {}) {
381
- var _a;
382
- if (!options.group) {
383
- if (!this.activeGroup) {
384
- return;
385
- }
386
- options.group = this.activeGroup;
387
- }
388
- if (options.includePanel && options.group) {
389
- if (options.group.activePanel !== options.group.panels[0]) {
390
- options.group.model.moveToPrevious({ suppressRoll: true });
391
- return;
392
- }
393
- }
394
- const location = getGridLocation(options.group.element);
395
- const next = (_a = this.gridview.previous(location)) === null || _a === void 0 ? void 0 : _a.view;
396
- if (next) {
397
- this.doSetGroupActive(next);
398
- }
399
- }
400
- /**
401
- * Serialize the current state of the layout
402
- *
403
- * @returns A JSON respresentation of the layout
404
- */
405
- toJSON() {
406
- var _a;
407
- const data = this.gridview.serialize();
408
- const panels = this.panels.reduce((collection, panel) => {
409
- collection[panel.id] = panel.toJSON();
410
- return collection;
411
- }, {});
412
- const floats = this.floatingGroups.map((floatingGroup) => {
413
- return {
414
- data: floatingGroup.group.toJSON(),
415
- position: floatingGroup.overlay.toJSON(),
416
- };
417
- });
418
- const result = {
419
- grid: data,
420
- panels,
421
- activeGroup: (_a = this.activeGroup) === null || _a === void 0 ? void 0 : _a.id,
422
- };
423
- if (floats.length > 0) {
424
- result.floatingGroups = floats;
425
- }
426
- return result;
427
- }
428
- fromJSON(data) {
429
- var _a;
430
- this.clear();
431
- if (typeof data !== 'object' || data === null) {
432
- throw new Error('serialized layout must be a non-null object');
433
- }
434
- const { grid, panels, activeGroup } = data;
435
- if (grid.root.type !== 'branch' || !Array.isArray(grid.root.data)) {
436
- throw new Error('root must be of type branch');
437
- }
438
- try {
439
- // take note of the existing dimensions
440
- const width = this.width;
441
- const height = this.height;
442
- const createGroupFromSerializedState = (data) => {
443
- const { id, locked, hideHeader, views, activeView } = data;
444
- if (typeof id !== 'string') {
445
- throw new Error('group id must be of type string');
446
- }
447
- const group = this.createGroup({
448
- id,
449
- locked: !!locked,
450
- hideHeader: !!hideHeader,
451
- });
452
- const createdPanels = [];
453
- for (const child of views) {
454
- /**
455
- * Run the deserializer step seperately since this may fail to due corrupted external state.
456
- * In running this section first we avoid firing lots of 'add' events in the event of a failure
457
- * due to a corruption of input data.
458
- */
459
- const panel = this._deserializer.fromJSON(panels[child], group);
460
- createdPanels.push(panel);
461
- }
462
- this._onDidAddGroup.fire(group);
463
- for (let i = 0; i < views.length; i++) {
464
- const panel = createdPanels[i];
465
- const isActive = typeof activeView === 'string' &&
466
- activeView === panel.id;
467
- group.model.openPanel(panel, {
468
- skipSetPanelActive: !isActive,
469
- skipSetGroupActive: true,
470
- });
471
- }
472
- if (!group.activePanel && group.panels.length > 0) {
473
- group.model.openPanel(group.panels[group.panels.length - 1], {
474
- skipSetGroupActive: true,
475
- });
476
- }
477
- return group;
478
- };
479
- this.gridview.deserialize(grid, {
480
- fromJSON: (node) => {
481
- return createGroupFromSerializedState(node.data);
482
- },
483
- });
484
- this.layout(width, height, true);
485
- const serializedFloatingGroups = (_a = data.floatingGroups) !== null && _a !== void 0 ? _a : [];
486
- for (const serializedFloatingGroup of serializedFloatingGroups) {
487
- const { data, position } = serializedFloatingGroup;
488
- const group = createGroupFromSerializedState(data);
489
- this.addFloatingGroup(group, {
490
- x: position.left,
491
- y: position.top,
492
- height: position.height,
493
- width: position.width,
494
- }, { skipRemoveGroup: true, inDragMode: false });
495
- }
496
- for (const floatingGroup of this.floatingGroups) {
497
- floatingGroup.overlay.setBounds();
498
- }
499
- if (typeof activeGroup === 'string') {
500
- const panel = this.getPanel(activeGroup);
501
- if (panel) {
502
- this.doSetGroupActive(panel);
503
- }
504
- }
505
- }
506
- catch (err) {
507
- /**
508
- * Takes all the successfully created groups and remove all of their panels.
509
- */
510
- for (const group of this.groups) {
511
- for (const panel of group.panels) {
512
- this.removePanel(panel, {
513
- removeEmptyGroup: false,
514
- skipDispose: false,
515
- });
516
- }
517
- }
518
- /**
519
- * To remove a group we cannot call this.removeGroup(...) since this makes assumptions about
520
- * the underlying HTMLElement existing in the Gridview.
521
- */
522
- for (const group of this.groups) {
523
- group.dispose();
524
- this._groups.delete(group.id);
525
- this._onDidRemoveGroup.fire(group);
526
- }
527
- // iterate over a reassigned array since original array will be modified
528
- for (const floatingGroup of [...this.floatingGroups]) {
529
- floatingGroup.dispose();
530
- }
531
- // fires clean-up events and clears the underlying HTML gridview.
532
- this.clear();
533
- /**
534
- * even though we have cleaned-up we still want to inform the caller of their error
535
- * and we'll do this through re-throwing the original error since afterall you would
536
- * expect trying to load a corrupted layout to result in an error and not silently fail...
537
- */
538
- throw err;
539
- }
540
- this._onDidLayoutFromJSON.fire();
541
- }
542
- clear() {
543
- const groups = Array.from(this._groups.values()).map((_) => _.value);
544
- const hasActiveGroup = !!this.activeGroup;
545
- const hasActivePanel = !!this.activePanel;
546
- for (const group of groups) {
547
- // remove the group will automatically remove the panels
548
- this.removeGroup(group, { skipActive: true });
549
- }
550
- if (hasActiveGroup) {
551
- this.doSetGroupActive(undefined);
552
- }
553
- if (hasActivePanel) {
554
- this._onDidActivePanelChange.fire(undefined);
555
- }
556
- this.gridview.clear();
557
- }
558
- closeAllGroups() {
559
- for (const entry of this._groups.entries()) {
560
- const [_, group] = entry;
561
- group.value.model.closeAllPanels();
562
- }
563
- }
564
- addPanel(options) {
565
- var _a, _b;
566
- if (this.panels.find((_) => _.id === options.id)) {
567
- throw new Error(`panel with id ${options.id} already exists`);
568
- }
569
- let referenceGroup;
570
- if (options.position && options.floating) {
571
- throw new Error('you can only provide one of: position, floating as arguments to .addPanel(...)');
572
- }
573
- if (options.position) {
574
- if (isPanelOptionsWithPanel(options.position)) {
575
- const referencePanel = typeof options.position.referencePanel === 'string'
576
- ? this.getGroupPanel(options.position.referencePanel)
577
- : options.position.referencePanel;
578
- if (!referencePanel) {
579
- throw new Error(`referencePanel ${options.position.referencePanel} does not exist`);
580
- }
581
- referenceGroup = this.findGroup(referencePanel);
582
- }
583
- else if (isPanelOptionsWithGroup(options.position)) {
584
- referenceGroup =
585
- typeof options.position.referenceGroup === 'string'
586
- ? (_a = this._groups.get(options.position.referenceGroup)) === null || _a === void 0 ? void 0 : _a.value
587
- : options.position.referenceGroup;
588
- if (!referenceGroup) {
589
- throw new Error(`referencePanel ${options.position.referenceGroup} does not exist`);
590
- }
591
- }
592
- else {
593
- const group = this.orthogonalize(directionToPosition(options.position.direction));
594
- const panel = this.createPanel(options, group);
595
- group.model.openPanel(panel);
596
- return panel;
597
- }
598
- }
599
- else {
600
- referenceGroup = this.activeGroup;
601
- }
602
- let panel;
603
- if (referenceGroup) {
604
- const target = toTarget(((_b = options.position) === null || _b === void 0 ? void 0 : _b.direction) || 'within');
605
- if (options.floating) {
606
- const group = this.createGroup();
607
- panel = this.createPanel(options, group);
608
- group.model.openPanel(panel);
609
- const o = typeof options.floating === 'object' &&
610
- options.floating !== null
611
- ? options.floating
612
- : {};
613
- this.addFloatingGroup(group, o, {
614
- inDragMode: false,
615
- skipRemoveGroup: true,
616
- });
617
- }
618
- else if (referenceGroup.api.isFloating || target === 'center') {
619
- panel = this.createPanel(options, referenceGroup);
620
- referenceGroup.model.openPanel(panel);
621
- }
622
- else {
623
- const location = getGridLocation(referenceGroup.element);
624
- const relativeLocation = getRelativeLocation(this.gridview.orientation, location, target);
625
- const group = this.createGroupAtLocation(relativeLocation);
626
- panel = this.createPanel(options, group);
627
- group.model.openPanel(panel);
628
- }
629
- }
630
- else if (options.floating) {
631
- const group = this.createGroup();
632
- panel = this.createPanel(options, group);
633
- group.model.openPanel(panel);
634
- const o = typeof options.floating === 'object' &&
635
- options.floating !== null
636
- ? options.floating
637
- : {};
638
- this.addFloatingGroup(group, o, {
639
- inDragMode: false,
640
- skipRemoveGroup: true,
641
- });
642
- }
643
- else {
644
- const group = this.createGroupAtLocation();
645
- panel = this.createPanel(options, group);
646
- group.model.openPanel(panel);
647
- }
648
- return panel;
649
- }
650
- removePanel(panel, options = {
651
- removeEmptyGroup: true,
652
- skipDispose: false,
653
- }) {
654
- const group = panel.group;
655
- if (!group) {
656
- throw new Error(`cannot remove panel ${panel.id}. it's missing a group.`);
657
- }
658
- group.model.removePanel(panel);
659
- if (!options.skipDispose) {
660
- panel.dispose();
661
- }
662
- if (group.size === 0 && options.removeEmptyGroup) {
663
- this.removeGroup(group);
664
- }
665
- }
666
- createWatermarkComponent() {
667
- var _a;
668
- return createComponent('watermark-id', 'watermark-name', this.options.watermarkComponent
669
- ? { 'watermark-name': this.options.watermarkComponent }
670
- : {}, this.options.watermarkFrameworkComponent
671
- ? { 'watermark-name': this.options.watermarkFrameworkComponent }
672
- : {}, (_a = this.options.frameworkComponentFactory) === null || _a === void 0 ? void 0 : _a.watermark);
673
- }
674
- updateWatermark() {
675
- var _a, _b;
676
- if (this.groups.filter((x) => !x.api.isFloating).length === 0) {
677
- if (!this.watermark) {
678
- this.watermark = this.createWatermarkComponent();
679
- this.watermark.init({
680
- containerApi: new DockviewApi(this),
681
- });
682
- const watermarkContainer = document.createElement('div');
683
- watermarkContainer.className = 'dv-watermark-container';
684
- watermarkContainer.appendChild(this.watermark.element);
685
- this.gridview.element.appendChild(watermarkContainer);
686
- }
687
- }
688
- else if (this.watermark) {
689
- this.watermark.element.parentElement.remove();
690
- (_b = (_a = this.watermark).dispose) === null || _b === void 0 ? void 0 : _b.call(_a);
691
- this.watermark = null;
692
- }
693
- }
694
- addGroup(options) {
695
- var _a;
696
- const group = this.createGroup();
697
- if (options) {
698
- let referenceGroup;
699
- if (isGroupOptionsWithPanel(options)) {
700
- const referencePanel = typeof options.referencePanel === 'string'
701
- ? this.panels.find((panel) => panel.id === options.referencePanel)
702
- : options.referencePanel;
703
- if (!referencePanel) {
704
- throw new Error(`reference panel ${options.referencePanel} does not exist`);
705
- }
706
- referenceGroup = this.findGroup(referencePanel);
707
- if (!referenceGroup) {
708
- throw new Error(`reference group for reference panel ${options.referencePanel} does not exist`);
709
- }
710
- }
711
- else if (isGroupOptionsWithGroup(options)) {
712
- referenceGroup =
713
- typeof options.referenceGroup === 'string'
714
- ? (_a = this._groups.get(options.referenceGroup)) === null || _a === void 0 ? void 0 : _a.value
715
- : options.referenceGroup;
716
- if (!referenceGroup) {
717
- throw new Error(`reference group ${options.referenceGroup} does not exist`);
718
- }
719
- }
720
- else {
721
- const group = this.orthogonalize(directionToPosition(options.direction));
722
- return group;
723
- }
724
- const target = toTarget(options.direction || 'within');
725
- const location = getGridLocation(referenceGroup.element);
726
- const relativeLocation = getRelativeLocation(this.gridview.orientation, location, target);
727
- this.doAddGroup(group, relativeLocation);
728
- return group;
729
- }
730
- else {
731
- this.doAddGroup(group);
732
- return group;
733
- }
734
- }
735
- removeGroup(group, options) {
736
- var _a;
737
- const panels = [...group.panels]; // reassign since group panels will mutate
738
- for (const panel of panels) {
739
- this.removePanel(panel, {
740
- removeEmptyGroup: false,
741
- skipDispose: (_a = options === null || options === void 0 ? void 0 : options.skipDispose) !== null && _a !== void 0 ? _a : false,
742
- });
743
- }
744
- this.doRemoveGroup(group, options);
745
- }
746
- doRemoveGroup(group, options) {
747
- const floatingGroup = this.floatingGroups.find((_) => _.group === group);
748
- if (floatingGroup) {
749
- if (!(options === null || options === void 0 ? void 0 : options.skipDispose)) {
750
- floatingGroup.group.dispose();
751
- this._groups.delete(group.id);
752
- // TODO: fire group removed event?
753
- }
754
- floatingGroup.dispose();
755
- return floatingGroup.group;
756
- }
757
- return super.doRemoveGroup(group, options);
758
- }
759
- moveGroupOrPanel(destinationGroup, sourceGroupId, sourceItemId, destinationTarget, destinationIndex) {
760
- var _a;
761
- const sourceGroup = sourceGroupId
762
- ? (_a = this._groups.get(sourceGroupId)) === null || _a === void 0 ? void 0 : _a.value
763
- : undefined;
764
- if (sourceItemId === undefined) {
765
- if (sourceGroup) {
766
- this.moveGroup(sourceGroup, destinationGroup, destinationTarget);
767
- }
768
- return;
769
- }
770
- if (!destinationTarget || destinationTarget === 'center') {
771
- const groupItem = (sourceGroup === null || sourceGroup === void 0 ? void 0 : sourceGroup.model.removePanel(sourceItemId)) ||
772
- this.panels.find((panel) => panel.id === sourceItemId);
773
- if (!groupItem) {
774
- throw new Error(`No panel with id ${sourceItemId}`);
775
- }
776
- if ((sourceGroup === null || sourceGroup === void 0 ? void 0 : sourceGroup.model.size) === 0) {
777
- this.doRemoveGroup(sourceGroup);
778
- }
779
- destinationGroup.model.openPanel(groupItem, {
780
- index: destinationIndex,
781
- });
782
- }
783
- else {
784
- const referenceLocation = getGridLocation(destinationGroup.element);
785
- const targetLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, destinationTarget);
786
- if (sourceGroup && sourceGroup.size < 2) {
787
- const [targetParentLocation, to] = tail(targetLocation);
788
- const isFloating = this.floatingGroups.find((x) => x.group === sourceGroup);
789
- if (!isFloating) {
790
- const sourceLocation = getGridLocation(sourceGroup.element);
791
- const [sourceParentLocation, from] = tail(sourceLocation);
792
- if (sequenceEquals(sourceParentLocation, targetParentLocation)) {
793
- // special case when 'swapping' two views within same grid location
794
- // if a group has one tab - we are essentially moving the 'group'
795
- // which is equivalent to swapping two views in this case
796
- this.gridview.moveView(sourceParentLocation, from, to);
797
- }
798
- }
799
- // source group will become empty so delete the group
800
- const targetGroup = this.doRemoveGroup(sourceGroup, {
801
- skipActive: true,
802
- skipDispose: true,
803
- });
804
- // after deleting the group we need to re-evaulate the ref location
805
- const updatedReferenceLocation = getGridLocation(destinationGroup.element);
806
- const location = getRelativeLocation(this.gridview.orientation, updatedReferenceLocation, destinationTarget);
807
- this.doAddGroup(targetGroup, location);
808
- }
809
- else {
810
- const groupItem = (sourceGroup === null || sourceGroup === void 0 ? void 0 : sourceGroup.model.removePanel(sourceItemId)) ||
811
- this.panels.find((panel) => panel.id === sourceItemId);
812
- if (!groupItem) {
813
- throw new Error(`No panel with id ${sourceItemId}`);
814
- }
815
- const dropLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, destinationTarget);
816
- const group = this.createGroupAtLocation(dropLocation);
817
- group.model.openPanel(groupItem);
818
- }
819
- }
820
- }
821
- moveGroup(sourceGroup, referenceGroup, target) {
822
- if (sourceGroup) {
823
- if (!target || target === 'center') {
824
- const activePanel = sourceGroup.activePanel;
825
- const panels = [...sourceGroup.panels].map((p) => sourceGroup.model.removePanel(p.id));
826
- if ((sourceGroup === null || sourceGroup === void 0 ? void 0 : sourceGroup.model.size) === 0) {
827
- this.doRemoveGroup(sourceGroup);
828
- }
829
- for (const panel of panels) {
830
- referenceGroup.model.openPanel(panel, {
831
- skipSetPanelActive: panel !== activePanel,
832
- });
833
- }
834
- }
835
- else {
836
- const floatingGroup = this.floatingGroups.find((x) => x.group === sourceGroup);
837
- if (floatingGroup) {
838
- floatingGroup.dispose();
839
- }
840
- else {
841
- this.gridview.removeView(getGridLocation(sourceGroup.element));
842
- }
843
- const referenceLocation = getGridLocation(referenceGroup.element);
844
- const dropLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, target);
845
- this.gridview.addView(sourceGroup, Sizing.Distribute, dropLocation);
846
- }
847
- }
848
- }
849
- doSetGroupActive(group, skipFocus) {
850
- var _a, _b;
851
- const isGroupAlreadyFocused = this._activeGroup === group;
852
- super.doSetGroupActive(group, skipFocus);
853
- if (!isGroupAlreadyFocused && ((_a = this._activeGroup) === null || _a === void 0 ? void 0 : _a.activePanel)) {
854
- this._onDidActivePanelChange.fire((_b = this._activeGroup) === null || _b === void 0 ? void 0 : _b.activePanel);
855
- }
856
- }
857
- createGroup(options) {
858
- if (!options) {
859
- options = {};
860
- }
861
- let id = options === null || options === void 0 ? void 0 : options.id;
862
- if (id && this._groups.has(options.id)) {
863
- console.warn(`Duplicate group id ${options === null || options === void 0 ? void 0 : options.id}. reassigning group id to avoid errors`);
864
- id = undefined;
865
- }
866
- if (!id) {
867
- id = this.nextGroupId.next();
868
- while (this._groups.has(id)) {
869
- id = this.nextGroupId.next();
870
- }
871
- }
872
- const view = new DockviewGroupPanel(this, id, options);
873
- view.init({ params: {}, accessor: null }); // required to initialized .part and allow for correct disposal of group
874
- if (!this._groups.has(view.id)) {
875
- const disposable = new CompositeDisposable(view.model.onTabDragStart((event) => {
876
- this._onWillDragPanel.fire(event);
877
- }), view.model.onGroupDragStart((event) => {
878
- this._onWillDragGroup.fire(event);
879
- }), view.model.onMove((event) => {
880
- const { groupId, itemId, target, index } = event;
881
- this.moveGroupOrPanel(view, groupId, itemId, target, index);
882
- }), view.model.onDidDrop((event) => {
883
- this._onDidDrop.fire(Object.assign(Object.assign({}, event), { api: this._api, group: view }));
884
- }), view.model.onDidAddPanel((event) => {
885
- this._onDidAddPanel.fire(event.panel);
886
- }), view.model.onDidRemovePanel((event) => {
887
- this._onDidRemovePanel.fire(event.panel);
888
- }), view.model.onDidActivePanelChange((event) => {
889
- this._onDidActivePanelChange.fire(event.panel);
890
- }));
891
- this._groups.set(view.id, { value: view, disposable });
892
- }
893
- // TODO: must be called after the above listeners have been setup,
894
- // not an ideal pattern
895
- view.initialize();
896
- return view;
897
- }
898
- createPanel(options, group) {
899
- const contentComponent = options.component;
900
- const tabComponent = options.tabComponent || this.options.defaultTabComponent;
901
- const view = new DockviewPanelModel(this, options.id, contentComponent, tabComponent);
902
- const panel = new DockviewPanel(options.id, this, this._api, group, view);
903
- panel.init({
904
- title: options.title || options.id,
905
- params: (options === null || options === void 0 ? void 0 : options.params) || {},
906
- });
907
- return panel;
908
- }
909
- createGroupAtLocation(location = [0]) {
910
- const group = this.createGroup();
911
- this.doAddGroup(group, location);
912
- return group;
913
- }
914
- findGroup(panel) {
915
- var _a;
916
- return (_a = Array.from(this._groups.values()).find((group) => group.value.model.containsPanel(panel))) === null || _a === void 0 ? void 0 : _a.value;
917
- }
918
- }
1
+ import { getRelativeLocation, getGridLocation, } from '../gridview/gridview';
2
+ import { directionToPosition, Droptarget } from '../dnd/droptarget';
3
+ import { tail, sequenceEquals, remove } from '../array';
4
+ import { DockviewPanel } from './dockviewPanel';
5
+ import { CompositeDisposable } from '../lifecycle';
6
+ import { Event, Emitter } from '../events';
7
+ import { Watermark } from './components/watermark/watermark';
8
+ import { DockviewDropTargets, } from './types';
9
+ import { sequentialNumberGenerator } from '../math';
10
+ import { DefaultDockviewDeserialzier } from './deserializer';
11
+ import { createComponent } from '../panel/componentFactory';
12
+ import { isGroupOptionsWithGroup, isGroupOptionsWithPanel, isPanelOptionsWithGroup, isPanelOptionsWithPanel, } from './options';
13
+ import { BaseGrid, toTarget, } from '../gridview/baseComponentGridview';
14
+ import { DockviewApi } from '../api/component.api';
15
+ import { Orientation, Sizing } from '../splitview/splitview';
16
+ import { DockviewGroupPanel } from './dockviewGroupPanel';
17
+ import { DockviewPanelModel } from './dockviewPanelModel';
18
+ import { getPanelData } from '../dnd/dataTransfer';
19
+ import { Overlay } from '../dnd/overlay';
20
+ import { toggleClass, watchElementResize } from '../dom';
21
+ import { DockviewFloatingGroupPanel, } from './dockviewFloatingGroupPanel';
22
+ const DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE = 100;
23
+ function typeValidate3(data, path) {
24
+ if (typeof data.id !== 'string') {
25
+ throw new Error(`${path}.id must be a string`);
26
+ }
27
+ if (typeof data.activeView !== 'string' ||
28
+ typeof data.activeView !== 'undefined') {
29
+ throw new Error(`${path}.activeView must be a string of undefined`);
30
+ }
31
+ }
32
+ function typeValidate2(data, path) {
33
+ if (typeof data.size !== 'number' && typeof data.size !== 'undefined') {
34
+ throw new Error(`${path}.size must be a number or undefined`);
35
+ }
36
+ if (typeof data.visible !== 'boolean' &&
37
+ typeof data.visible !== 'undefined') {
38
+ throw new Error(`${path}.visible must be a boolean or undefined`);
39
+ }
40
+ if (data.type === 'leaf') {
41
+ if (typeof data.data !== 'object' ||
42
+ data.data === null ||
43
+ Array.isArray(data.data)) {
44
+ throw new Error('object must be a non-null object');
45
+ }
46
+ typeValidate3(data.data, `${path}.data`);
47
+ }
48
+ else if (data.type === 'branch') {
49
+ if (!Array.isArray(data.data)) {
50
+ throw new Error(`${path}.data must be an array`);
51
+ }
52
+ }
53
+ else {
54
+ throw new Error(`${path}.type must be onew of {'branch', 'leaf'}`);
55
+ }
56
+ }
57
+ function typeValidate(data) {
58
+ if (typeof data !== 'object' || data === null) {
59
+ throw new Error('object must be a non-null object');
60
+ }
61
+ const { grid, panels, activeGroup, floatingGroups } = data;
62
+ if (typeof grid !== 'object' || grid === null) {
63
+ throw new Error("'.grid' must be a non-null object");
64
+ }
65
+ if (typeof grid.height !== 'number') {
66
+ throw new Error("'.grid.height' must be a number");
67
+ }
68
+ if (typeof grid.width !== 'number') {
69
+ throw new Error("'.grid.width' must be a number");
70
+ }
71
+ if (typeof grid.root !== 'object' || grid.root === null) {
72
+ throw new Error("'.grid.root' must be a non-null object");
73
+ }
74
+ if (grid.root.type !== 'branch') {
75
+ throw new Error(".grid.root.type must be of type 'branch'");
76
+ }
77
+ if (grid.orientation !== Orientation.HORIZONTAL &&
78
+ grid.orientation !== Orientation.VERTICAL) {
79
+ throw new Error(`'.grid.width' must be one of {${Orientation.HORIZONTAL}, ${Orientation.VERTICAL}}`);
80
+ }
81
+ typeValidate2(grid.root, '.grid.root');
82
+ }
83
+ export class DockviewComponent extends BaseGrid {
84
+ get orientation() {
85
+ return this.gridview.orientation;
86
+ }
87
+ get totalPanels() {
88
+ return this.panels.length;
89
+ }
90
+ get panels() {
91
+ return this.groups.flatMap((group) => group.panels);
92
+ }
93
+ get options() {
94
+ return this._options;
95
+ }
96
+ get activePanel() {
97
+ const activeGroup = this.activeGroup;
98
+ if (!activeGroup) {
99
+ return undefined;
100
+ }
101
+ return activeGroup.activePanel;
102
+ }
103
+ constructor(options) {
104
+ var _a;
105
+ super({
106
+ proportionalLayout: true,
107
+ orientation: (_a = options.orientation) !== null && _a !== void 0 ? _a : Orientation.HORIZONTAL,
108
+ styles: options.styles,
109
+ parentElement: options.parentElement,
110
+ disableAutoResizing: options.disableAutoResizing,
111
+ });
112
+ this.nextGroupId = sequentialNumberGenerator();
113
+ this._deserializer = new DefaultDockviewDeserialzier(this);
114
+ this.watermark = null;
115
+ this._onWillDragPanel = new Emitter();
116
+ this.onWillDragPanel = this._onWillDragPanel.event;
117
+ this._onWillDragGroup = new Emitter();
118
+ this.onWillDragGroup = this._onWillDragGroup.event;
119
+ this._onDidDrop = new Emitter();
120
+ this.onDidDrop = this._onDidDrop.event;
121
+ this._onDidRemovePanel = new Emitter();
122
+ this.onDidRemovePanel = this._onDidRemovePanel.event;
123
+ this._onDidAddPanel = new Emitter();
124
+ this.onDidAddPanel = this._onDidAddPanel.event;
125
+ this._onDidLayoutFromJSON = new Emitter();
126
+ this.onDidLayoutFromJSON = this._onDidLayoutFromJSON.event;
127
+ this._onDidActivePanelChange = new Emitter();
128
+ this.onDidActivePanelChange = this._onDidActivePanelChange.event;
129
+ this.floatingGroups = [];
130
+ toggleClass(this.gridview.element, 'dv-dockview', true);
131
+ this.addDisposables(this._onWillDragPanel, this._onWillDragGroup, this._onDidActivePanelChange, this._onDidAddPanel, this._onDidRemovePanel, this._onDidLayoutFromJSON, this._onDidDrop, Event.any(this.onDidAddGroup, this.onDidRemoveGroup)(() => {
132
+ this.updateWatermark();
133
+ }), Event.any(this.onDidAddPanel, this.onDidRemovePanel, this.onDidActivePanelChange)(() => {
134
+ this._bufferOnDidLayoutChange.fire();
135
+ }));
136
+ this._options = options;
137
+ if (!this.options.components) {
138
+ this.options.components = {};
139
+ }
140
+ if (!this.options.frameworkComponents) {
141
+ this.options.frameworkComponents = {};
142
+ }
143
+ if (!this.options.frameworkTabComponents) {
144
+ this.options.frameworkTabComponents = {};
145
+ }
146
+ if (!this.options.tabComponents) {
147
+ this.options.tabComponents = {};
148
+ }
149
+ if (!this.options.watermarkComponent &&
150
+ !this.options.watermarkFrameworkComponent) {
151
+ this.options.watermarkComponent = Watermark;
152
+ }
153
+ const dropTarget = new Droptarget(this.element, {
154
+ canDisplayOverlay: (event, position) => {
155
+ const data = getPanelData();
156
+ if (data) {
157
+ if (data.viewId !== this.id) {
158
+ return false;
159
+ }
160
+ if (position === 'center') {
161
+ // center drop target is only allowed if there are no panels in the grid
162
+ // floating panels are allowed
163
+ return this.gridview.length === 0;
164
+ }
165
+ return true;
166
+ }
167
+ if (this.options.showDndOverlay) {
168
+ if (position === 'center' && this.gridview.length !== 0) {
169
+ /**
170
+ * for external events only show the four-corner drag overlays, disable
171
+ * the center position so that external drag events can fall through to the group
172
+ * and panel drop target handlers
173
+ */
174
+ return false;
175
+ }
176
+ return this.options.showDndOverlay({
177
+ nativeEvent: event,
178
+ position: position,
179
+ target: DockviewDropTargets.Edge,
180
+ getData: getPanelData,
181
+ });
182
+ }
183
+ return false;
184
+ },
185
+ acceptedTargetZones: ['top', 'bottom', 'left', 'right', 'center'],
186
+ overlayModel: {
187
+ activationSize: { type: 'pixels', value: 10 },
188
+ size: { type: 'pixels', value: 20 },
189
+ },
190
+ });
191
+ this.addDisposables(dropTarget.onDrop((event) => {
192
+ var _a;
193
+ const data = getPanelData();
194
+ if (data) {
195
+ this.moveGroupOrPanel(this.orthogonalize(event.position), data.groupId, (_a = data.panelId) !== null && _a !== void 0 ? _a : undefined, 'center');
196
+ }
197
+ else {
198
+ this._onDidDrop.fire(Object.assign(Object.assign({}, event), { api: this._api, group: null, getData: getPanelData }));
199
+ }
200
+ }), dropTarget);
201
+ this._api = new DockviewApi(this);
202
+ this.updateWatermark();
203
+ }
204
+ addFloatingGroup(item, coord, options) {
205
+ var _a, _b, _c, _d, _e, _f;
206
+ let group;
207
+ if (item instanceof DockviewPanel) {
208
+ group = this.createGroup();
209
+ this.removePanel(item, {
210
+ removeEmptyGroup: true,
211
+ skipDispose: true,
212
+ });
213
+ group.model.openPanel(item);
214
+ }
215
+ else {
216
+ group = item;
217
+ const skip = typeof (options === null || options === void 0 ? void 0 : options.skipRemoveGroup) === 'boolean' &&
218
+ options.skipRemoveGroup;
219
+ if (!skip) {
220
+ this.doRemoveGroup(item, { skipDispose: true });
221
+ }
222
+ }
223
+ group.model.isFloating = true;
224
+ const overlayLeft = typeof (coord === null || coord === void 0 ? void 0 : coord.x) === 'number' ? Math.max(coord.x, 0) : 100;
225
+ const overlayTop = typeof (coord === null || coord === void 0 ? void 0 : coord.y) === 'number' ? Math.max(coord.y, 0) : 100;
226
+ const overlay = new Overlay({
227
+ container: this.gridview.element,
228
+ content: group.element,
229
+ height: (_a = coord === null || coord === void 0 ? void 0 : coord.height) !== null && _a !== void 0 ? _a : 300,
230
+ width: (_b = coord === null || coord === void 0 ? void 0 : coord.width) !== null && _b !== void 0 ? _b : 300,
231
+ left: overlayLeft,
232
+ top: overlayTop,
233
+ minimumInViewportWidth: this.options.floatingGroupBounds === 'boundedWithinViewport'
234
+ ? undefined
235
+ : (_d = (_c = this.options.floatingGroupBounds) === null || _c === void 0 ? void 0 : _c.minimumWidthWithinViewport) !== null && _d !== void 0 ? _d : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE,
236
+ minimumInViewportHeight: this.options.floatingGroupBounds === 'boundedWithinViewport'
237
+ ? undefined
238
+ : (_f = (_e = this.options.floatingGroupBounds) === null || _e === void 0 ? void 0 : _e.minimumHeightWithinViewport) !== null && _f !== void 0 ? _f : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE,
239
+ });
240
+ const el = group.element.querySelector('.void-container');
241
+ if (!el) {
242
+ throw new Error('failed to find drag handle');
243
+ }
244
+ overlay.setupDrag(el, {
245
+ inDragMode: typeof (options === null || options === void 0 ? void 0 : options.inDragMode) === 'boolean'
246
+ ? options.inDragMode
247
+ : false,
248
+ });
249
+ const floatingGroupPanel = new DockviewFloatingGroupPanel(group, overlay);
250
+ const disposable = watchElementResize(group.element, (entry) => {
251
+ const { width, height } = entry.contentRect;
252
+ group.layout(width, height); // let the group know it's size is changing so it can fire events to the panel
253
+ });
254
+ floatingGroupPanel.addDisposables(overlay.onDidChange(() => {
255
+ // this is either a resize or a move
256
+ // to inform the panels .layout(...) the group with it's current size
257
+ // don't care about resize since the above watcher handles that
258
+ group.layout(group.height, group.width);
259
+ }), overlay.onDidChangeEnd(() => {
260
+ this._bufferOnDidLayoutChange.fire();
261
+ }), group.onDidChange((event) => {
262
+ overlay.setBounds({
263
+ height: event === null || event === void 0 ? void 0 : event.height,
264
+ width: event === null || event === void 0 ? void 0 : event.width,
265
+ });
266
+ }), {
267
+ dispose: () => {
268
+ disposable.dispose();
269
+ group.model.isFloating = false;
270
+ remove(this.floatingGroups, floatingGroupPanel);
271
+ this.updateWatermark();
272
+ },
273
+ });
274
+ this.floatingGroups.push(floatingGroupPanel);
275
+ this.updateWatermark();
276
+ }
277
+ orthogonalize(position) {
278
+ switch (position) {
279
+ case 'top':
280
+ case 'bottom':
281
+ if (this.gridview.orientation === Orientation.HORIZONTAL) {
282
+ // we need to add to a vertical splitview but the current root is a horizontal splitview.
283
+ // insert a vertical splitview at the root level and add the existing view as a child
284
+ this.gridview.insertOrthogonalSplitviewAtRoot();
285
+ }
286
+ break;
287
+ case 'left':
288
+ case 'right':
289
+ if (this.gridview.orientation === Orientation.VERTICAL) {
290
+ // we need to add to a horizontal splitview but the current root is a vertical splitview.
291
+ // insert a horiziontal splitview at the root level and add the existing view as a child
292
+ this.gridview.insertOrthogonalSplitviewAtRoot();
293
+ }
294
+ break;
295
+ default:
296
+ break;
297
+ }
298
+ switch (position) {
299
+ case 'top':
300
+ case 'left':
301
+ case 'center':
302
+ return this.createGroupAtLocation([0]); // insert into first position
303
+ case 'bottom':
304
+ case 'right':
305
+ return this.createGroupAtLocation([this.gridview.length]); // insert into last position
306
+ default:
307
+ throw new Error(`unsupported position ${position}`);
308
+ }
309
+ }
310
+ updateOptions(options) {
311
+ var _a, _b;
312
+ const hasOrientationChanged = typeof options.orientation === 'string' &&
313
+ this.gridview.orientation !== options.orientation;
314
+ const hasFloatingGroupOptionsChanged = options.floatingGroupBounds !== undefined &&
315
+ options.floatingGroupBounds !== this.options.floatingGroupBounds;
316
+ this._options = Object.assign(Object.assign({}, this.options), options);
317
+ if (hasOrientationChanged) {
318
+ this.gridview.orientation = options.orientation;
319
+ }
320
+ if (hasFloatingGroupOptionsChanged) {
321
+ for (const group of this.floatingGroups) {
322
+ switch (this.options.floatingGroupBounds) {
323
+ case 'boundedWithinViewport':
324
+ group.overlay.minimumInViewportHeight = undefined;
325
+ group.overlay.minimumInViewportWidth = undefined;
326
+ break;
327
+ case undefined:
328
+ group.overlay.minimumInViewportHeight =
329
+ DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE;
330
+ group.overlay.minimumInViewportWidth =
331
+ DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE;
332
+ break;
333
+ default:
334
+ group.overlay.minimumInViewportHeight =
335
+ (_a = this.options.floatingGroupBounds) === null || _a === void 0 ? void 0 : _a.minimumHeightWithinViewport;
336
+ group.overlay.minimumInViewportWidth =
337
+ (_b = this.options.floatingGroupBounds) === null || _b === void 0 ? void 0 : _b.minimumWidthWithinViewport;
338
+ }
339
+ group.overlay.setBounds({});
340
+ }
341
+ }
342
+ this.layout(this.gridview.width, this.gridview.height, true);
343
+ }
344
+ layout(width, height, forceResize) {
345
+ super.layout(width, height, forceResize);
346
+ if (this.floatingGroups) {
347
+ for (const floating of this.floatingGroups) {
348
+ // ensure floting groups stay within visible boundaries
349
+ floating.overlay.setBounds();
350
+ }
351
+ }
352
+ }
353
+ focus() {
354
+ var _a;
355
+ (_a = this.activeGroup) === null || _a === void 0 ? void 0 : _a.focus();
356
+ }
357
+ getGroupPanel(id) {
358
+ return this.panels.find((panel) => panel.id === id);
359
+ }
360
+ setActivePanel(panel) {
361
+ this.doSetGroupActive(panel.group);
362
+ panel.group.model.openPanel(panel);
363
+ }
364
+ moveToNext(options = {}) {
365
+ var _a;
366
+ if (!options.group) {
367
+ if (!this.activeGroup) {
368
+ return;
369
+ }
370
+ options.group = this.activeGroup;
371
+ }
372
+ if (options.includePanel && options.group) {
373
+ if (options.group.activePanel !==
374
+ options.group.panels[options.group.panels.length - 1]) {
375
+ options.group.model.moveToNext({ suppressRoll: true });
376
+ return;
377
+ }
378
+ }
379
+ const location = getGridLocation(options.group.element);
380
+ const next = (_a = this.gridview.next(location)) === null || _a === void 0 ? void 0 : _a.view;
381
+ this.doSetGroupAndPanelActive(next);
382
+ }
383
+ moveToPrevious(options = {}) {
384
+ var _a;
385
+ if (!options.group) {
386
+ if (!this.activeGroup) {
387
+ return;
388
+ }
389
+ options.group = this.activeGroup;
390
+ }
391
+ if (options.includePanel && options.group) {
392
+ if (options.group.activePanel !== options.group.panels[0]) {
393
+ options.group.model.moveToPrevious({ suppressRoll: true });
394
+ return;
395
+ }
396
+ }
397
+ const location = getGridLocation(options.group.element);
398
+ const next = (_a = this.gridview.previous(location)) === null || _a === void 0 ? void 0 : _a.view;
399
+ if (next) {
400
+ this.doSetGroupAndPanelActive(next);
401
+ }
402
+ }
403
+ /**
404
+ * Serialize the current state of the layout
405
+ *
406
+ * @returns A JSON respresentation of the layout
407
+ */
408
+ toJSON() {
409
+ var _a;
410
+ const data = this.gridview.serialize();
411
+ const panels = this.panels.reduce((collection, panel) => {
412
+ collection[panel.id] = panel.toJSON();
413
+ return collection;
414
+ }, {});
415
+ const floats = this.floatingGroups.map((floatingGroup) => {
416
+ return {
417
+ data: floatingGroup.group.toJSON(),
418
+ position: floatingGroup.overlay.toJSON(),
419
+ };
420
+ });
421
+ const result = {
422
+ grid: data,
423
+ panels,
424
+ activeGroup: (_a = this.activeGroup) === null || _a === void 0 ? void 0 : _a.id,
425
+ };
426
+ if (floats.length > 0) {
427
+ result.floatingGroups = floats;
428
+ }
429
+ return result;
430
+ }
431
+ fromJSON(data) {
432
+ var _a;
433
+ this.clear();
434
+ if (typeof data !== 'object' || data === null) {
435
+ throw new Error('serialized layout must be a non-null object');
436
+ }
437
+ const { grid, panels, activeGroup } = data;
438
+ if (grid.root.type !== 'branch' || !Array.isArray(grid.root.data)) {
439
+ throw new Error('root must be of type branch');
440
+ }
441
+ try {
442
+ // take note of the existing dimensions
443
+ const width = this.width;
444
+ const height = this.height;
445
+ const createGroupFromSerializedState = (data) => {
446
+ const { id, locked, hideHeader, views, activeView } = data;
447
+ if (typeof id !== 'string') {
448
+ throw new Error('group id must be of type string');
449
+ }
450
+ const group = this.createGroup({
451
+ id,
452
+ locked: !!locked,
453
+ hideHeader: !!hideHeader,
454
+ });
455
+ const createdPanels = [];
456
+ for (const child of views) {
457
+ /**
458
+ * Run the deserializer step seperately since this may fail to due corrupted external state.
459
+ * In running this section first we avoid firing lots of 'add' events in the event of a failure
460
+ * due to a corruption of input data.
461
+ */
462
+ const panel = this._deserializer.fromJSON(panels[child], group);
463
+ createdPanels.push(panel);
464
+ }
465
+ this._onDidAddGroup.fire(group);
466
+ for (let i = 0; i < views.length; i++) {
467
+ const panel = createdPanels[i];
468
+ const isActive = typeof activeView === 'string' &&
469
+ activeView === panel.id;
470
+ group.model.openPanel(panel, {
471
+ skipSetPanelActive: !isActive,
472
+ skipSetGroupActive: true,
473
+ });
474
+ }
475
+ if (!group.activePanel && group.panels.length > 0) {
476
+ group.model.openPanel(group.panels[group.panels.length - 1], {
477
+ skipSetGroupActive: true,
478
+ });
479
+ }
480
+ return group;
481
+ };
482
+ this.gridview.deserialize(grid, {
483
+ fromJSON: (node) => {
484
+ return createGroupFromSerializedState(node.data);
485
+ },
486
+ });
487
+ this.layout(width, height, true);
488
+ const serializedFloatingGroups = (_a = data.floatingGroups) !== null && _a !== void 0 ? _a : [];
489
+ for (const serializedFloatingGroup of serializedFloatingGroups) {
490
+ const { data, position } = serializedFloatingGroup;
491
+ const group = createGroupFromSerializedState(data);
492
+ this.addFloatingGroup(group, {
493
+ x: position.left,
494
+ y: position.top,
495
+ height: position.height,
496
+ width: position.width,
497
+ }, { skipRemoveGroup: true, inDragMode: false });
498
+ }
499
+ for (const floatingGroup of this.floatingGroups) {
500
+ floatingGroup.overlay.setBounds();
501
+ }
502
+ if (typeof activeGroup === 'string') {
503
+ const panel = this.getPanel(activeGroup);
504
+ if (panel) {
505
+ this.doSetGroupAndPanelActive(panel);
506
+ }
507
+ }
508
+ }
509
+ catch (err) {
510
+ /**
511
+ * Takes all the successfully created groups and remove all of their panels.
512
+ */
513
+ for (const group of this.groups) {
514
+ for (const panel of group.panels) {
515
+ this.removePanel(panel, {
516
+ removeEmptyGroup: false,
517
+ skipDispose: false,
518
+ });
519
+ }
520
+ }
521
+ /**
522
+ * To remove a group we cannot call this.removeGroup(...) since this makes assumptions about
523
+ * the underlying HTMLElement existing in the Gridview.
524
+ */
525
+ for (const group of this.groups) {
526
+ group.dispose();
527
+ this._groups.delete(group.id);
528
+ this._onDidRemoveGroup.fire(group);
529
+ }
530
+ // iterate over a reassigned array since original array will be modified
531
+ for (const floatingGroup of [...this.floatingGroups]) {
532
+ floatingGroup.dispose();
533
+ }
534
+ // fires clean-up events and clears the underlying HTML gridview.
535
+ this.clear();
536
+ /**
537
+ * even though we have cleaned-up we still want to inform the caller of their error
538
+ * and we'll do this through re-throwing the original error since afterall you would
539
+ * expect trying to load a corrupted layout to result in an error and not silently fail...
540
+ */
541
+ throw err;
542
+ }
543
+ this._onDidLayoutFromJSON.fire();
544
+ }
545
+ clear() {
546
+ const groups = Array.from(this._groups.values()).map((_) => _.value);
547
+ const hasActiveGroup = !!this.activeGroup;
548
+ const hasActivePanel = !!this.activePanel;
549
+ for (const group of groups) {
550
+ // remove the group will automatically remove the panels
551
+ this.removeGroup(group, { skipActive: true });
552
+ }
553
+ if (hasActiveGroup) {
554
+ this.doSetGroupAndPanelActive(undefined);
555
+ }
556
+ if (hasActivePanel) {
557
+ this._onDidActivePanelChange.fire(undefined);
558
+ }
559
+ this.gridview.clear();
560
+ }
561
+ closeAllGroups() {
562
+ for (const entry of this._groups.entries()) {
563
+ const [_, group] = entry;
564
+ group.value.model.closeAllPanels();
565
+ }
566
+ }
567
+ addPanel(options) {
568
+ var _a, _b;
569
+ if (this.panels.find((_) => _.id === options.id)) {
570
+ throw new Error(`panel with id ${options.id} already exists`);
571
+ }
572
+ let referenceGroup;
573
+ if (options.position && options.floating) {
574
+ throw new Error('you can only provide one of: position, floating as arguments to .addPanel(...)');
575
+ }
576
+ if (options.position) {
577
+ if (isPanelOptionsWithPanel(options.position)) {
578
+ const referencePanel = typeof options.position.referencePanel === 'string'
579
+ ? this.getGroupPanel(options.position.referencePanel)
580
+ : options.position.referencePanel;
581
+ if (!referencePanel) {
582
+ throw new Error(`referencePanel ${options.position.referencePanel} does not exist`);
583
+ }
584
+ referenceGroup = this.findGroup(referencePanel);
585
+ }
586
+ else if (isPanelOptionsWithGroup(options.position)) {
587
+ referenceGroup =
588
+ typeof options.position.referenceGroup === 'string'
589
+ ? (_a = this._groups.get(options.position.referenceGroup)) === null || _a === void 0 ? void 0 : _a.value
590
+ : options.position.referenceGroup;
591
+ if (!referenceGroup) {
592
+ throw new Error(`referencePanel ${options.position.referenceGroup} does not exist`);
593
+ }
594
+ }
595
+ else {
596
+ const group = this.orthogonalize(directionToPosition(options.position.direction));
597
+ const panel = this.createPanel(options, group);
598
+ group.model.openPanel(panel);
599
+ return panel;
600
+ }
601
+ }
602
+ else {
603
+ referenceGroup = this.activeGroup;
604
+ }
605
+ let panel;
606
+ if (referenceGroup) {
607
+ const target = toTarget(((_b = options.position) === null || _b === void 0 ? void 0 : _b.direction) || 'within');
608
+ if (options.floating) {
609
+ const group = this.createGroup();
610
+ const o = typeof options.floating === 'object' &&
611
+ options.floating !== null
612
+ ? options.floating
613
+ : {};
614
+ this.addFloatingGroup(group, o, {
615
+ inDragMode: false,
616
+ skipRemoveGroup: true,
617
+ });
618
+ this._onDidAddGroup.fire(group);
619
+ panel = this.createPanel(options, group);
620
+ group.model.openPanel(panel);
621
+ this.doSetGroupAndPanelActive(group);
622
+ }
623
+ else if (referenceGroup.api.isFloating || target === 'center') {
624
+ panel = this.createPanel(options, referenceGroup);
625
+ referenceGroup.model.openPanel(panel);
626
+ }
627
+ else {
628
+ const location = getGridLocation(referenceGroup.element);
629
+ const relativeLocation = getRelativeLocation(this.gridview.orientation, location, target);
630
+ const group = this.createGroupAtLocation(relativeLocation);
631
+ panel = this.createPanel(options, group);
632
+ group.model.openPanel(panel);
633
+ }
634
+ }
635
+ else if (options.floating) {
636
+ const group = this.createGroup();
637
+ const o = typeof options.floating === 'object' &&
638
+ options.floating !== null
639
+ ? options.floating
640
+ : {};
641
+ this.addFloatingGroup(group, o, {
642
+ inDragMode: false,
643
+ skipRemoveGroup: true,
644
+ });
645
+ this._onDidAddGroup.fire(group);
646
+ panel = this.createPanel(options, group);
647
+ group.model.openPanel(panel);
648
+ this.doSetGroupAndPanelActive(group);
649
+ }
650
+ else {
651
+ const group = this.createGroupAtLocation();
652
+ panel = this.createPanel(options, group);
653
+ group.model.openPanel(panel);
654
+ }
655
+ return panel;
656
+ }
657
+ removePanel(panel, options = {
658
+ removeEmptyGroup: true,
659
+ skipDispose: false,
660
+ }) {
661
+ const group = panel.group;
662
+ if (!group) {
663
+ throw new Error(`cannot remove panel ${panel.id}. it's missing a group.`);
664
+ }
665
+ group.model.removePanel(panel);
666
+ if (!options.skipDispose) {
667
+ panel.dispose();
668
+ }
669
+ if (group.size === 0 && options.removeEmptyGroup) {
670
+ this.removeGroup(group);
671
+ }
672
+ }
673
+ createWatermarkComponent() {
674
+ var _a;
675
+ return createComponent('watermark-id', 'watermark-name', this.options.watermarkComponent
676
+ ? { 'watermark-name': this.options.watermarkComponent }
677
+ : {}, this.options.watermarkFrameworkComponent
678
+ ? { 'watermark-name': this.options.watermarkFrameworkComponent }
679
+ : {}, (_a = this.options.frameworkComponentFactory) === null || _a === void 0 ? void 0 : _a.watermark);
680
+ }
681
+ updateWatermark() {
682
+ var _a, _b;
683
+ if (this.groups.filter((x) => !x.api.isFloating).length === 0) {
684
+ if (!this.watermark) {
685
+ this.watermark = this.createWatermarkComponent();
686
+ this.watermark.init({
687
+ containerApi: new DockviewApi(this),
688
+ });
689
+ const watermarkContainer = document.createElement('div');
690
+ watermarkContainer.className = 'dv-watermark-container';
691
+ watermarkContainer.appendChild(this.watermark.element);
692
+ this.gridview.element.appendChild(watermarkContainer);
693
+ }
694
+ }
695
+ else if (this.watermark) {
696
+ this.watermark.element.parentElement.remove();
697
+ (_b = (_a = this.watermark).dispose) === null || _b === void 0 ? void 0 : _b.call(_a);
698
+ this.watermark = null;
699
+ }
700
+ }
701
+ addGroup(options) {
702
+ var _a;
703
+ const group = this.createGroup();
704
+ if (options) {
705
+ let referenceGroup;
706
+ if (isGroupOptionsWithPanel(options)) {
707
+ const referencePanel = typeof options.referencePanel === 'string'
708
+ ? this.panels.find((panel) => panel.id === options.referencePanel)
709
+ : options.referencePanel;
710
+ if (!referencePanel) {
711
+ throw new Error(`reference panel ${options.referencePanel} does not exist`);
712
+ }
713
+ referenceGroup = this.findGroup(referencePanel);
714
+ if (!referenceGroup) {
715
+ throw new Error(`reference group for reference panel ${options.referencePanel} does not exist`);
716
+ }
717
+ }
718
+ else if (isGroupOptionsWithGroup(options)) {
719
+ referenceGroup =
720
+ typeof options.referenceGroup === 'string'
721
+ ? (_a = this._groups.get(options.referenceGroup)) === null || _a === void 0 ? void 0 : _a.value
722
+ : options.referenceGroup;
723
+ if (!referenceGroup) {
724
+ throw new Error(`reference group ${options.referenceGroup} does not exist`);
725
+ }
726
+ }
727
+ else {
728
+ const group = this.orthogonalize(directionToPosition(options.direction));
729
+ return group;
730
+ }
731
+ const target = toTarget(options.direction || 'within');
732
+ const location = getGridLocation(referenceGroup.element);
733
+ const relativeLocation = getRelativeLocation(this.gridview.orientation, location, target);
734
+ this.doAddGroup(group, relativeLocation);
735
+ return group;
736
+ }
737
+ else {
738
+ this.doAddGroup(group);
739
+ return group;
740
+ }
741
+ }
742
+ removeGroup(group, options) {
743
+ var _a;
744
+ const panels = [...group.panels]; // reassign since group panels will mutate
745
+ for (const panel of panels) {
746
+ this.removePanel(panel, {
747
+ removeEmptyGroup: false,
748
+ skipDispose: (_a = options === null || options === void 0 ? void 0 : options.skipDispose) !== null && _a !== void 0 ? _a : false,
749
+ });
750
+ }
751
+ const activePanel = this.activePanel;
752
+ this.doRemoveGroup(group, options);
753
+ if (this.activePanel !== activePanel) {
754
+ this._onDidActivePanelChange.fire(this.activePanel);
755
+ }
756
+ }
757
+ doRemoveGroup(group, options) {
758
+ const floatingGroup = this.floatingGroups.find((_) => _.group === group);
759
+ if (floatingGroup) {
760
+ if (!(options === null || options === void 0 ? void 0 : options.skipDispose)) {
761
+ floatingGroup.group.dispose();
762
+ this._groups.delete(group.id);
763
+ this._onDidRemoveGroup.fire(group);
764
+ }
765
+ floatingGroup.dispose();
766
+ if (!(options === null || options === void 0 ? void 0 : options.skipActive) && this._activeGroup === group) {
767
+ const groups = Array.from(this._groups.values());
768
+ this.doSetGroupActive(groups.length > 0 ? groups[0].value : undefined);
769
+ }
770
+ return floatingGroup.group;
771
+ }
772
+ return super.doRemoveGroup(group, options);
773
+ }
774
+ moveGroupOrPanel(destinationGroup, sourceGroupId, sourceItemId, destinationTarget, destinationIndex) {
775
+ var _a, _b, _c;
776
+ const sourceGroup = sourceGroupId
777
+ ? (_a = this._groups.get(sourceGroupId)) === null || _a === void 0 ? void 0 : _a.value
778
+ : undefined;
779
+ if (sourceItemId === undefined) {
780
+ if (sourceGroup) {
781
+ this.moveGroup(sourceGroup, destinationGroup, destinationTarget);
782
+ }
783
+ return;
784
+ }
785
+ if (!destinationTarget || destinationTarget === 'center') {
786
+ const groupItem = (_b = sourceGroup === null || sourceGroup === void 0 ? void 0 : sourceGroup.model.removePanel(sourceItemId)) !== null && _b !== void 0 ? _b : this.panels.find((panel) => panel.id === sourceItemId);
787
+ if (!groupItem) {
788
+ throw new Error(`No panel with id ${sourceItemId}`);
789
+ }
790
+ if ((sourceGroup === null || sourceGroup === void 0 ? void 0 : sourceGroup.model.size) === 0) {
791
+ this.doRemoveGroup(sourceGroup);
792
+ }
793
+ destinationGroup.model.openPanel(groupItem, {
794
+ index: destinationIndex,
795
+ });
796
+ }
797
+ else {
798
+ const referenceLocation = getGridLocation(destinationGroup.element);
799
+ const targetLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, destinationTarget);
800
+ if (sourceGroup && sourceGroup.size < 2) {
801
+ const [targetParentLocation, to] = tail(targetLocation);
802
+ const isFloating = this.floatingGroups.find((x) => x.group === sourceGroup);
803
+ if (!isFloating) {
804
+ const sourceLocation = getGridLocation(sourceGroup.element);
805
+ const [sourceParentLocation, from] = tail(sourceLocation);
806
+ if (sequenceEquals(sourceParentLocation, targetParentLocation)) {
807
+ // special case when 'swapping' two views within same grid location
808
+ // if a group has one tab - we are essentially moving the 'group'
809
+ // which is equivalent to swapping two views in this case
810
+ this.gridview.moveView(sourceParentLocation, from, to);
811
+ }
812
+ }
813
+ // source group will become empty so delete the group
814
+ const targetGroup = this.doRemoveGroup(sourceGroup, {
815
+ skipActive: true,
816
+ skipDispose: true,
817
+ });
818
+ // after deleting the group we need to re-evaulate the ref location
819
+ const updatedReferenceLocation = getGridLocation(destinationGroup.element);
820
+ const location = getRelativeLocation(this.gridview.orientation, updatedReferenceLocation, destinationTarget);
821
+ this.doAddGroup(targetGroup, location);
822
+ }
823
+ else {
824
+ const groupItem = (_c = sourceGroup === null || sourceGroup === void 0 ? void 0 : sourceGroup.model.removePanel(sourceItemId)) !== null && _c !== void 0 ? _c : this.panels.find((panel) => panel.id === sourceItemId);
825
+ if (!groupItem) {
826
+ throw new Error(`No panel with id ${sourceItemId}`);
827
+ }
828
+ const dropLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, destinationTarget);
829
+ const group = this.createGroupAtLocation(dropLocation);
830
+ group.model.openPanel(groupItem);
831
+ }
832
+ }
833
+ }
834
+ moveGroup(sourceGroup, referenceGroup, target) {
835
+ if (sourceGroup) {
836
+ if (!target || target === 'center') {
837
+ const activePanel = sourceGroup.activePanel;
838
+ const panels = [...sourceGroup.panels].map((p) => sourceGroup.model.removePanel(p.id));
839
+ if ((sourceGroup === null || sourceGroup === void 0 ? void 0 : sourceGroup.model.size) === 0) {
840
+ this.doRemoveGroup(sourceGroup);
841
+ }
842
+ for (const panel of panels) {
843
+ referenceGroup.model.openPanel(panel, {
844
+ skipSetPanelActive: panel !== activePanel,
845
+ });
846
+ }
847
+ }
848
+ else {
849
+ const floatingGroup = this.floatingGroups.find((x) => x.group === sourceGroup);
850
+ if (floatingGroup) {
851
+ floatingGroup.dispose();
852
+ }
853
+ else {
854
+ this.gridview.removeView(getGridLocation(sourceGroup.element));
855
+ }
856
+ const referenceLocation = getGridLocation(referenceGroup.element);
857
+ const dropLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, target);
858
+ this.gridview.addView(sourceGroup, Sizing.Distribute, dropLocation);
859
+ }
860
+ }
861
+ }
862
+ doSetGroupAndPanelActive(group, skipFocus) {
863
+ var _a, _b;
864
+ const activePanel = this.activePanel;
865
+ super.doSetGroupActive(group, skipFocus);
866
+ if (((_a = this._activeGroup) === null || _a === void 0 ? void 0 : _a.activePanel) !== activePanel) {
867
+ this._onDidActivePanelChange.fire((_b = this._activeGroup) === null || _b === void 0 ? void 0 : _b.activePanel);
868
+ }
869
+ }
870
+ createGroup(options) {
871
+ if (!options) {
872
+ options = {};
873
+ }
874
+ let id = options === null || options === void 0 ? void 0 : options.id;
875
+ if (id && this._groups.has(options.id)) {
876
+ console.warn(`Duplicate group id ${options === null || options === void 0 ? void 0 : options.id}. reassigning group id to avoid errors`);
877
+ id = undefined;
878
+ }
879
+ if (!id) {
880
+ id = this.nextGroupId.next();
881
+ while (this._groups.has(id)) {
882
+ id = this.nextGroupId.next();
883
+ }
884
+ }
885
+ const view = new DockviewGroupPanel(this, id, options);
886
+ view.init({ params: {}, accessor: null }); // required to initialized .part and allow for correct disposal of group
887
+ if (!this._groups.has(view.id)) {
888
+ const disposable = new CompositeDisposable(view.model.onTabDragStart((event) => {
889
+ this._onWillDragPanel.fire(event);
890
+ }), view.model.onGroupDragStart((event) => {
891
+ this._onWillDragGroup.fire(event);
892
+ }), view.model.onMove((event) => {
893
+ const { groupId, itemId, target, index } = event;
894
+ this.moveGroupOrPanel(view, groupId, itemId, target, index);
895
+ }), view.model.onDidDrop((event) => {
896
+ this._onDidDrop.fire(Object.assign(Object.assign({}, event), { api: this._api, group: view }));
897
+ }), view.model.onDidAddPanel((event) => {
898
+ this._onDidAddPanel.fire(event.panel);
899
+ }), view.model.onDidRemovePanel((event) => {
900
+ this._onDidRemovePanel.fire(event.panel);
901
+ }), view.model.onDidActivePanelChange((event) => {
902
+ this._onDidActivePanelChange.fire(event.panel);
903
+ }));
904
+ this._groups.set(view.id, { value: view, disposable });
905
+ }
906
+ // TODO: must be called after the above listeners have been setup,
907
+ // not an ideal pattern
908
+ view.initialize();
909
+ return view;
910
+ }
911
+ createPanel(options, group) {
912
+ var _a, _b, _c;
913
+ const contentComponent = options.component;
914
+ const tabComponent = (_a = options.tabComponent) !== null && _a !== void 0 ? _a : this.options.defaultTabComponent;
915
+ const view = new DockviewPanelModel(this, options.id, contentComponent, tabComponent);
916
+ const panel = new DockviewPanel(options.id, this, this._api, group, view);
917
+ panel.init({
918
+ title: (_b = options.title) !== null && _b !== void 0 ? _b : options.id,
919
+ params: (_c = options === null || options === void 0 ? void 0 : options.params) !== null && _c !== void 0 ? _c : {},
920
+ });
921
+ return panel;
922
+ }
923
+ createGroupAtLocation(location = [0]) {
924
+ const group = this.createGroup();
925
+ this.doAddGroup(group, location);
926
+ return group;
927
+ }
928
+ findGroup(panel) {
929
+ var _a;
930
+ return (_a = Array.from(this._groups.values()).find((group) => group.value.model.containsPanel(panel))) === null || _a === void 0 ? void 0 : _a.value;
931
+ }
932
+ }
919
933
  //# sourceMappingURL=dockviewComponent.js.map