@link-foundation/ui-components 0.0.0-stage → 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (402) hide show
  1. package/CONFIGURATIONS.md +74 -0
  2. package/ICONS.md +76 -0
  3. package/LICENSE +24 -0
  4. package/README.md +1499 -2
  5. package/bin/lino-network.mjs +71 -0
  6. package/dist/icons/ATTRIBUTION.md +602 -0
  7. package/dist/icons/NOTICE.lino +1261 -0
  8. package/dist/icons/brand.js +31 -0
  9. package/dist/icons/brand.svg +3 -0
  10. package/dist/icons/licenses/brand/DISCLAIMER.md +51 -0
  11. package/dist/icons/licenses/brand/LICENSE.md +30 -0
  12. package/dist/icons/licenses/lucide/LICENSE +43 -0
  13. package/dist/icons/licenses/material-symbols/LICENSE +202 -0
  14. package/dist/icons/licenses/material-symbols/NOTICE +12 -0
  15. package/dist/icons/licenses/tabler/LICENSE +21 -0
  16. package/dist/icons/lucide.js +681 -0
  17. package/dist/icons/lucide.svg +34 -0
  18. package/dist/icons/material-symbols.js +681 -0
  19. package/dist/icons/material-symbols.svg +34 -0
  20. package/dist/icons/own.js +521 -0
  21. package/dist/icons/own.svg +34 -0
  22. package/dist/icons/tabler.js +681 -0
  23. package/dist/icons/tabler.svg +34 -0
  24. package/dist/network-layout-NOTICE.md +6 -0
  25. package/dist/network-layout-d3-dispatch-LICENSE.txt +13 -0
  26. package/dist/network-layout-d3-force-LICENSE.txt +13 -0
  27. package/dist/network-layout-d3-quadtree-LICENSE.txt +13 -0
  28. package/dist/network-layout-d3-timer-LICENSE.txt +13 -0
  29. package/dist/network-layout-dagre-LICENSE.txt +19 -0
  30. package/dist/network-layout.worker.mjs +2 -0
  31. package/package.json +246 -4
  32. package/src/a11y/announce.js +88 -0
  33. package/src/a11y/bind-machine.js +181 -0
  34. package/src/a11y/focus.js +169 -0
  35. package/src/a11y/index.d.ts +89 -0
  36. package/src/a11y/index.js +19 -0
  37. package/src/a11y/keys.js +182 -0
  38. package/src/a11y/roving.js +167 -0
  39. package/src/a11y/typeahead.js +82 -0
  40. package/src/behavior/actions.js +235 -0
  41. package/src/behavior/diagnostics.js +73 -0
  42. package/src/behavior/dom.d.ts +38 -0
  43. package/src/behavior/dom.js +420 -0
  44. package/src/behavior/index.d.ts +211 -0
  45. package/src/behavior/index.js +29 -0
  46. package/src/behavior/interpret.js +454 -0
  47. package/src/behavior/machines/disclosure.lino +46 -0
  48. package/src/behavior/machines/index.js +91 -0
  49. package/src/behavior/machines/toggle.lino +25 -0
  50. package/src/behavior/parse-machine.js +367 -0
  51. package/src/charts/README.md +78 -0
  52. package/src/charts/activity-layout.js +350 -0
  53. package/src/charts/activity-model.js +130 -0
  54. package/src/charts/activity-validation.js +31 -0
  55. package/src/charts/chart-model.js +667 -0
  56. package/src/charts/chart.js +518 -0
  57. package/src/charts/echarts-adapter.d.ts +23 -0
  58. package/src/charts/echarts-adapter.js +240 -0
  59. package/src/charts/element.js +330 -0
  60. package/src/charts/errors.js +62 -0
  61. package/src/charts/gauge.js +27 -0
  62. package/src/charts/index.d.ts +344 -0
  63. package/src/charts/index.js +59 -0
  64. package/src/charts/layout.js +542 -0
  65. package/src/charts/lino.js +158 -0
  66. package/src/charts/mark-options.js +78 -0
  67. package/src/charts/read.js +101 -0
  68. package/src/charts/renderer-features.js +8 -0
  69. package/src/charts/scales.js +223 -0
  70. package/src/charts/small-model.js +223 -0
  71. package/src/charts/small-svg.js +269 -0
  72. package/src/charts/sparkline.js +27 -0
  73. package/src/charts/stat-tile.js +37 -0
  74. package/src/charts/summary.js +193 -0
  75. package/src/charts/svg-renderer.js +226 -0
  76. package/src/charts/svg.js +69 -0
  77. package/src/charts/tag-cloud.js +129 -0
  78. package/src/charts/tokens.js +171 -0
  79. package/src/charts/tooltip.js +47 -0
  80. package/src/charts/values.js +146 -0
  81. package/src/chat/README.md +142 -0
  82. package/src/chat/actions.js +75 -0
  83. package/src/chat/chat-contract.js +95 -0
  84. package/src/chat/chat-list.js +42 -0
  85. package/src/chat/chat-model.js +125 -0
  86. package/src/chat/chat.css +228 -0
  87. package/src/chat/composer.js +131 -0
  88. package/src/chat/day-separator.js +12 -0
  89. package/src/chat/dom.js +33 -0
  90. package/src/chat/follow.js +49 -0
  91. package/src/chat/index.d.ts +142 -0
  92. package/src/chat/index.js +13 -0
  93. package/src/chat/message-bubble.js +191 -0
  94. package/src/chat/message-stream.js +331 -0
  95. package/src/chat/reasoning-trace.js +70 -0
  96. package/src/chat/selection.js +39 -0
  97. package/src/chat/skins/bubbles.lino +2 -0
  98. package/src/chat/skins/cards.lino +4 -0
  99. package/src/chat/skins/compact.lino +4 -0
  100. package/src/chat/skins/signal.lino +25 -0
  101. package/src/chat/skins/t3.lino +25 -0
  102. package/src/chat/skins/telegram.lino +31 -0
  103. package/src/chat/skins/whatsapp.lino +25 -0
  104. package/src/chat/stream-keys.js +57 -0
  105. package/src/chat/stream-window.js +159 -0
  106. package/src/chat/vocabulary.js +19 -0
  107. package/src/controls/accordion.js +160 -0
  108. package/src/controls/avatar.js +80 -0
  109. package/src/controls/badge.js +48 -0
  110. package/src/controls/button-template.js +32 -0
  111. package/src/controls/button.js +97 -0
  112. package/src/controls/catalog.lino +84 -0
  113. package/src/controls/checkbox.js +112 -0
  114. package/src/controls/chip.js +140 -0
  115. package/src/controls/choices.js +45 -0
  116. package/src/controls/color-field.js +217 -0
  117. package/src/controls/color-popover.js +135 -0
  118. package/src/controls/color-rgb.js +80 -0
  119. package/src/controls/color.js +67 -0
  120. package/src/controls/combobox.js +192 -0
  121. package/src/controls/dom.js +261 -0
  122. package/src/controls/icon-button.js +33 -0
  123. package/src/controls/index.d.ts +163 -0
  124. package/src/controls/index.js +182 -0
  125. package/src/controls/kinds-text.js +358 -0
  126. package/src/controls/kinds.lino +350 -0
  127. package/src/controls/label.js +52 -0
  128. package/src/controls/link.js +101 -0
  129. package/src/controls/listbox.js +144 -0
  130. package/src/controls/machines/button.lino +20 -0
  131. package/src/controls/machines/checkbox.lino +17 -0
  132. package/src/controls/machines/chip.lino +20 -0
  133. package/src/controls/machines/color-field.lino +23 -0
  134. package/src/controls/machines/combobox.lino +82 -0
  135. package/src/controls/machines/icon-button.lino +20 -0
  136. package/src/controls/machines/index.js +586 -0
  137. package/src/controls/machines/number-field.lino +71 -0
  138. package/src/controls/machines/radio-group.lino +17 -0
  139. package/src/controls/machines/select.lino +122 -0
  140. package/src/controls/machines/slider.lino +99 -0
  141. package/src/controls/machines/switch.lino +19 -0
  142. package/src/controls/machines/text-area.lino +26 -0
  143. package/src/controls/machines/text-field.lino +26 -0
  144. package/src/controls/number-field.js +239 -0
  145. package/src/controls/numeric-keys.js +125 -0
  146. package/src/controls/option.js +54 -0
  147. package/src/controls/progress.js +76 -0
  148. package/src/controls/radio-group.js +234 -0
  149. package/src/controls/select.js +229 -0
  150. package/src/controls/slider.js +234 -0
  151. package/src/controls/stories.js +172 -0
  152. package/src/controls/styles.css +1060 -0
  153. package/src/controls/switch.js +95 -0
  154. package/src/controls/text-area.js +39 -0
  155. package/src/controls/text-field.js +131 -0
  156. package/src/controls/vocabulary.js +164 -0
  157. package/src/data/data.css +95 -0
  158. package/src/data/index.d.ts +83 -0
  159. package/src/data/index.js +10 -0
  160. package/src/data/keyboard.js +189 -0
  161. package/src/data/list.js +215 -0
  162. package/src/data/render-data.js +116 -0
  163. package/src/data/selection-dom.js +39 -0
  164. package/src/data/selection-model.js +43 -0
  165. package/src/data/sort-model.js +42 -0
  166. package/src/data/source.js +45 -0
  167. package/src/data/table.js +160 -0
  168. package/src/data/tree-model.js +41 -0
  169. package/src/data/tree.js +55 -0
  170. package/src/data/viewport.js +216 -0
  171. package/src/data/virtual-range.js +92 -0
  172. package/src/data/vocabulary.js +67 -0
  173. package/src/diagrams/diagram-model.js +511 -0
  174. package/src/diagrams/diagram.js +204 -0
  175. package/src/diagrams/index.d.ts +225 -0
  176. package/src/diagrams/index.js +48 -0
  177. package/src/diagrams/layout-dagre.js +164 -0
  178. package/src/diagrams/layout-plugins.js +131 -0
  179. package/src/diagrams/mermaid-export.js +232 -0
  180. package/src/diagrams/mermaid-view.js +229 -0
  181. package/src/diagrams/svg-diagram.js +215 -0
  182. package/src/editor/code-editor.js +206 -0
  183. package/src/editor/documents-model.js +170 -0
  184. package/src/editor/documents-persistence.js +85 -0
  185. package/src/editor/editor-engine.js +22 -0
  186. package/src/editor/editor-ui.js +203 -0
  187. package/src/editor/editor.css +106 -0
  188. package/src/editor/engines/codemirror.js +227 -0
  189. package/src/editor/engines/monaco.js +219 -0
  190. package/src/editor/index.d.ts +111 -0
  191. package/src/editor/index.js +14 -0
  192. package/src/editor/lino-highlight.js +106 -0
  193. package/src/editor/lino-structure.js +85 -0
  194. package/src/editor/validate-lino.js +43 -0
  195. package/src/embed/README.md +161 -0
  196. package/src/embed/controller.js +223 -0
  197. package/src/embed/element.js +141 -0
  198. package/src/embed/index.d.ts +75 -0
  199. package/src/embed/index.js +9 -0
  200. package/src/embed/providers/telegram.d.ts +3 -0
  201. package/src/embed/providers/telegram.js +38 -0
  202. package/src/embed/providers/vk.d.ts +3 -0
  203. package/src/embed/providers/vk.js +42 -0
  204. package/src/embed/providers/x.d.ts +3 -0
  205. package/src/embed/providers/x.js +31 -0
  206. package/src/embed/registry.js +35 -0
  207. package/src/embed/script.js +73 -0
  208. package/src/embed/view.js +122 -0
  209. package/src/icons/adapters/lucide.d.ts +15 -0
  210. package/src/icons/adapters/lucide.js +142 -0
  211. package/src/icons/adapters/material-symbols.d.ts +13 -0
  212. package/src/icons/adapters/material-symbols.js +113 -0
  213. package/src/icons/adapters/shared.d.ts +38 -0
  214. package/src/icons/adapters/shared.js +157 -0
  215. package/src/icons/adapters/simple-icons.d.ts +9 -0
  216. package/src/icons/adapters/simple-icons.js +38 -0
  217. package/src/icons/adapters/tabler.d.ts +9 -0
  218. package/src/icons/adapters/tabler.js +86 -0
  219. package/src/icons/icon-registry.js +215 -0
  220. package/src/icons/icon.js +356 -0
  221. package/src/icons/index.d.ts +123 -0
  222. package/src/icons/index.js +30 -0
  223. package/src/icons/names.js +51 -0
  224. package/src/icons/own-icons.js +521 -0
  225. package/src/icons/presentation.js +55 -0
  226. package/src/icons/svg.js +136 -0
  227. package/src/index.d.ts +14 -0
  228. package/src/index.js +40 -0
  229. package/src/layout/README.md +102 -0
  230. package/src/layout/app-shell.js +150 -0
  231. package/src/layout/catalog.lino +27 -0
  232. package/src/layout/dock-model.js +576 -0
  233. package/src/layout/dock-view.js +312 -0
  234. package/src/layout/dock.js +352 -0
  235. package/src/layout/dom.js +312 -0
  236. package/src/layout/grid.js +192 -0
  237. package/src/layout/index.d.ts +267 -0
  238. package/src/layout/index.js +60 -0
  239. package/src/layout/layer-manager.js +120 -0
  240. package/src/layout/layout.css +760 -0
  241. package/src/layout/menu.js +141 -0
  242. package/src/layout/nav-strip.js +174 -0
  243. package/src/layout/page-links.js +166 -0
  244. package/src/layout/panel.js +26 -0
  245. package/src/layout/pref-switches.js +209 -0
  246. package/src/layout/split-model.js +270 -0
  247. package/src/layout/split.js +430 -0
  248. package/src/layout/stack.js +86 -0
  249. package/src/layout/surfaces.js +119 -0
  250. package/src/layout/tab-group.js +151 -0
  251. package/src/layout/tab-strip.js +277 -0
  252. package/src/layout/vocabulary.js +229 -0
  253. package/src/layout/window-frame.js +222 -0
  254. package/src/layout/window.js +146 -0
  255. package/src/links-view/animator.js +144 -0
  256. package/src/links-view/configuration-classes.js +150 -0
  257. package/src/links-view/configuration-model.js +191 -0
  258. package/src/links-view/configuration-notations.js +230 -0
  259. package/src/links-view/configurations.d.ts +73 -0
  260. package/src/links-view/configurations.js +33 -0
  261. package/src/links-view/create-layout-runner.js +79 -0
  262. package/src/links-view/doublet-curves.js +239 -0
  263. package/src/links-view/doublet-layout.js +148 -0
  264. package/src/links-view/doublet-markers.js +109 -0
  265. package/src/links-view/doublet-options.js +369 -0
  266. package/src/links-view/doublet-svg.js +156 -0
  267. package/src/links-view/doublet.js +230 -0
  268. package/src/links-view/export.js +146 -0
  269. package/src/links-view/geometry.js +409 -0
  270. package/src/links-view/index.d.ts +1029 -0
  271. package/src/links-view/index.js +140 -0
  272. package/src/links-view/labels.js +28 -0
  273. package/src/links-view/layout-worker-entry.mjs +2 -0
  274. package/src/links-view/layout-worker.js +28 -0
  275. package/src/links-view/layouts/circle.js +7 -0
  276. package/src/links-view/layouts/force.js +76 -0
  277. package/src/links-view/layouts/grid.js +7 -0
  278. package/src/links-view/layouts/hex.js +8 -0
  279. package/src/links-view/layouts/index.js +15 -0
  280. package/src/links-view/layouts/layered.js +29 -0
  281. package/src/links-view/layouts/regular.js +27 -0
  282. package/src/links-view/layouts/spiral.js +10 -0
  283. package/src/links-view/link-view.js +494 -0
  284. package/src/links-view/links-gallery.js +306 -0
  285. package/src/links-view/links-network.js +496 -0
  286. package/src/links-view/lino-network-source.js +122 -0
  287. package/src/links-view/lino-network.js +233 -0
  288. package/src/links-view/lino-to-network.js +252 -0
  289. package/src/links-view/markers.js +192 -0
  290. package/src/links-view/model.js +233 -0
  291. package/src/links-view/network-editor/dom.js +36 -0
  292. package/src/links-view/network-editor/editor.js +202 -0
  293. package/src/links-view/network-editor/model.js +163 -0
  294. package/src/links-view/network-editor/options.js +265 -0
  295. package/src/links-view/network-editor/panels.js +423 -0
  296. package/src/links-view/network-editor/presets.js +76 -0
  297. package/src/links-view/network-editor/provider.js +93 -0
  298. package/src/links-view/network-editor/remap.js +45 -0
  299. package/src/links-view/network-editor/schema.js +224 -0
  300. package/src/links-view/network-editor/share.js +232 -0
  301. package/src/links-view/network-editor/styles.js +19 -0
  302. package/src/links-view/network-editor/url-sync.js +131 -0
  303. package/src/links-view/network-interaction.js +228 -0
  304. package/src/links-view/network-model.js +85 -0
  305. package/src/links-view/network-renderer.js +259 -0
  306. package/src/links-view/network-scene.js +245 -0
  307. package/src/links-view/network-source.js +82 -0
  308. package/src/links-view/network-vocabulary.js +18 -0
  309. package/src/links-view/presentation.js +199 -0
  310. package/src/links-view/render-canvas.js +102 -0
  311. package/src/links-view/render-svg.js +118 -0
  312. package/src/links-view/scene.js +233 -0
  313. package/src/links-view/solver-job.js +106 -0
  314. package/src/links-view/tokens.js +114 -0
  315. package/src/links-view/zoom-pan.js +203 -0
  316. package/src/overlays/catalog.lino +89 -0
  317. package/src/overlays/context-menu.js +110 -0
  318. package/src/overlays/dialog.js +117 -0
  319. package/src/overlays/dom.js +168 -0
  320. package/src/overlays/drawer.js +8 -0
  321. package/src/overlays/index.d.ts +80 -0
  322. package/src/overlays/index.js +25 -0
  323. package/src/overlays/kinds.lino +137 -0
  324. package/src/overlays/list-popover.js +129 -0
  325. package/src/overlays/machines/index.js +71 -0
  326. package/src/overlays/machines/surface.lino +11 -0
  327. package/src/overlays/machines/tabs.lino +7 -0
  328. package/src/overlays/machines/toast.lino +16 -0
  329. package/src/overlays/machines/tooltip.lino +29 -0
  330. package/src/overlays/menu.js +240 -0
  331. package/src/overlays/popover.js +194 -0
  332. package/src/overlays/position.js +84 -0
  333. package/src/overlays/radial-geometry.js +38 -0
  334. package/src/overlays/radial-menu.js +50 -0
  335. package/src/overlays/styles.css +155 -0
  336. package/src/overlays/tabs.js +125 -0
  337. package/src/overlays/toast-queue.js +105 -0
  338. package/src/overlays/toast.js +163 -0
  339. package/src/overlays/tooltip.js +110 -0
  340. package/src/overlays/vocabulary.js +3 -0
  341. package/src/settings/conditions.js +44 -0
  342. package/src/settings/control-for.js +62 -0
  343. package/src/settings/field-control.js +201 -0
  344. package/src/settings/index.d.ts +201 -0
  345. package/src/settings/index.js +3 -0
  346. package/src/settings/messages.js +112 -0
  347. package/src/settings/miniature.js +26 -0
  348. package/src/settings/panel-actions.js +234 -0
  349. package/src/settings/panel-model.js +49 -0
  350. package/src/settings/panel-refresh.js +56 -0
  351. package/src/settings/panel-rows.js +200 -0
  352. package/src/settings/preset-cards.js +43 -0
  353. package/src/settings/saved-looks.js +227 -0
  354. package/src/settings/section-layout.js +95 -0
  355. package/src/settings/section-tabs.js +175 -0
  356. package/src/settings/settings-panel.js +192 -0
  357. package/src/settings/settings.css +178 -0
  358. package/stories/accordion.lino +14 -0
  359. package/stories/alert-dialog.lino +4 -0
  360. package/stories/app-bar.lino +10 -0
  361. package/stories/avatar.lino +7 -0
  362. package/stories/badge.lino +12 -0
  363. package/stories/button.lino +17 -0
  364. package/stories/card.lino +10 -0
  365. package/stories/checkbox.lino +14 -0
  366. package/stories/chip.lino +19 -0
  367. package/stories/color-field.lino +9 -0
  368. package/stories/combobox.lino +10 -0
  369. package/stories/container.lino +11 -0
  370. package/stories/context-menu.lino +15 -0
  371. package/stories/dialog.lino +16 -0
  372. package/stories/drawer.lino +12 -0
  373. package/stories/icon-button.lino +13 -0
  374. package/stories/label.lino +7 -0
  375. package/stories/link-cards.lino +9 -0
  376. package/stories/link.lino +9 -0
  377. package/stories/menu-item.lino +6 -0
  378. package/stories/menu-separator.lino +7 -0
  379. package/stories/menu.lino +30 -0
  380. package/stories/nav-strip.lino +11 -0
  381. package/stories/number-field.lino +16 -0
  382. package/stories/option.lino +10 -0
  383. package/stories/paper.lino +11 -0
  384. package/stories/popover.lino +4 -0
  385. package/stories/pref-switches.lino +4 -0
  386. package/stories/progress.lino +14 -0
  387. package/stories/radial-menu.lino +19 -0
  388. package/stories/radio-group.lino +22 -0
  389. package/stories/radio.lino +10 -0
  390. package/stories/section-nav.lino +9 -0
  391. package/stories/select.lino +16 -0
  392. package/stories/slider.lino +14 -0
  393. package/stories/switch.lino +10 -0
  394. package/stories/tab-panel.lino +7 -0
  395. package/stories/tab.lino +7 -0
  396. package/stories/tabs.lino +25 -0
  397. package/stories/text-area.lino +12 -0
  398. package/stories/text-field.lino +23 -0
  399. package/stories/titled-section.lino +7 -0
  400. package/stories/toast.lino +3 -0
  401. package/stories/toaster.lino +2 -0
  402. package/stories/tooltip.lino +3 -0
@@ -0,0 +1,312 @@
1
+ /**
2
+ * The drawing of a dock (see `dock.js`): one box with a tab strip per
3
+ * region, one window frame per floating panel, and the closed panels kept
4
+ * hidden. Every function takes the dock context `dock`:
5
+ *
6
+ * { node, document, layers, holder, floatLayer, restore, state, change }
7
+ *
8
+ * where `state.layout` is the dock layout and `state.panels` maps panel ids
9
+ * to their rendered nodes.
10
+ */
11
+
12
+ import {
13
+ activatePanel,
14
+ closePanel,
15
+ findPanel,
16
+ floatPanel,
17
+ movePanel,
18
+ SIDES,
19
+ updateRegion,
20
+ } from './dock-model.js';
21
+ import { idOf, make, titleOf } from './dom.js';
22
+ import { isTrackAtom } from './grid.js';
23
+ import { showPanel } from './tab-group.js';
24
+ import { createTabStrip } from './tab-strip.js';
25
+ import { createWindowFrame } from './window-frame.js';
26
+
27
+ const SIDE_NAMES = {
28
+ left: 'Left',
29
+ right: 'Right',
30
+ top: 'Top',
31
+ bottom: 'Bottom',
32
+ center: 'Center',
33
+ };
34
+
35
+ /** Whether a dock panel may be closed (all but `(closable false)`). */
36
+ export const isClosable = (panel) =>
37
+ panel?.getAttribute('data-closable') !== 'false';
38
+
39
+ const panelNode = (dock, id) => dock.state.panels.get(id);
40
+
41
+ /** The id of the region on a side; the side itself when there is none. */
42
+ const regionOn = (layout, side) =>
43
+ layout.regions.find((r) => r.side === side)?.id ?? side;
44
+
45
+ /** Focus the tab or the floating window of a panel, else "Restore". */
46
+ export function focusPanel(dock, id) {
47
+ const found = findPanel(dock.state.layout, id);
48
+ if (found?.place === 'region') {
49
+ dock.state.regions.get(found.region.id)?.strip.focusTab(id);
50
+ } else if (found?.place === 'floating') {
51
+ dock.state.floats.get(id)?.frame.root.focus();
52
+ } else {
53
+ dock.restore.focus();
54
+ }
55
+ }
56
+
57
+ /** Close a panel of a region; the focus goes to the tab shown after it. */
58
+ function closeInRegion(dock, id, regionId) {
59
+ const layout = closePanel(dock.state.layout, id);
60
+ const next = layout.regions.find((r) => r.id === regionId)?.active;
61
+ dock.change(layout, next ?? id);
62
+ }
63
+
64
+ /** The "Panel actions" menu items of the shown panel of a region. */
65
+ function regionActions(dock, regionId, id) {
66
+ const layout = dock.state.layout;
67
+ const region = layout.regions.find((r) => r.id === regionId);
68
+ if (region === undefined) {
69
+ return [];
70
+ }
71
+ const moves = SIDES.filter((side) => side !== region.side).map((side) => ({
72
+ label: `Move to ${SIDE_NAMES[side].toLowerCase()}`,
73
+ run: () =>
74
+ dock.change(
75
+ movePanel(dock.state.layout, id, {
76
+ region: regionOn(dock.state.layout, side),
77
+ activate: true,
78
+ }),
79
+ id
80
+ ),
81
+ }));
82
+ return [
83
+ ...moves,
84
+ {
85
+ label: 'Float',
86
+ run: () => dock.change(floatPanel(dock.state.layout, id), id),
87
+ },
88
+ {
89
+ label: 'Close',
90
+ disabled: !isClosable(panelNode(dock, id)),
91
+ run: () => closeInRegion(dock, id, regionId),
92
+ },
93
+ {
94
+ label: region.collapsed ? 'Expand region' : 'Collapse region',
95
+ run: () =>
96
+ dock.change(
97
+ updateRegion(dock.state.layout, regionId, {
98
+ collapsed: !region.collapsed,
99
+ }),
100
+ id
101
+ ),
102
+ },
103
+ ];
104
+ }
105
+
106
+ /** The layout with the panels of a region in a new order. */
107
+ function reordered(layout, regionId, order) {
108
+ return {
109
+ ...layout,
110
+ regions: layout.regions.map((r) =>
111
+ r.id === regionId
112
+ ? {
113
+ ...r,
114
+ panels: [...order, ...r.panels.filter((p) => !order.includes(p))],
115
+ }
116
+ : r
117
+ ),
118
+ };
119
+ }
120
+
121
+ function makeRegion(dock, region) {
122
+ const label = `${SIDE_NAMES[region.side]} panels`;
123
+ const box = make(dock.document, 'div', {
124
+ class: 'ui-dock-region',
125
+ role: 'group',
126
+ 'data-side': region.side,
127
+ 'aria-label': label,
128
+ });
129
+ const strip = createTabStrip(dock.document, {
130
+ label,
131
+ select: (id) => dock.change(activatePanel(dock.state.layout, id)),
132
+ close: (id) => closeInRegion(dock, id, region.id),
133
+ reorder: (order) =>
134
+ dock.change(reordered(dock.state.layout, region.id, order)),
135
+ receive: (id, index) =>
136
+ dock.change(
137
+ movePanel(dock.state.layout, id, {
138
+ region: region.id,
139
+ index,
140
+ activate: true,
141
+ }),
142
+ id
143
+ ),
144
+ actions: (id) => regionActions(dock, region.id, id),
145
+ });
146
+ box.append(strip.element);
147
+ dock.node.insertBefore(box, dock.floatLayer);
148
+ return { box, strip, side: region.side };
149
+ }
150
+
151
+ /** Draw a region: its tabs and its panels; `shown` gets it when it has any. */
152
+ function renderRegion(dock, region, shown) {
153
+ const { state } = dock;
154
+ let entry = state.regions.get(region.id);
155
+ if (entry === undefined || entry.side !== region.side) {
156
+ dropRegion(dock, region.id);
157
+ entry = makeRegion(dock, region);
158
+ state.regions.set(region.id, entry);
159
+ }
160
+ const ids = region.panels.filter((id) => panelNode(dock, id) !== undefined);
161
+ const active = ids.includes(region.active) ? region.active : ids[0];
162
+ entry.strip.render(
163
+ ids.map((id) => ({
164
+ id,
165
+ title: titleOf(panelNode(dock, id)),
166
+ panel: idOf(panelNode(dock, id), 'ui-dock-panel'),
167
+ closable: isClosable(panelNode(dock, id)),
168
+ })),
169
+ active ?? null
170
+ );
171
+ for (const id of ids) {
172
+ const panel = panelNode(dock, id);
173
+ if (panel.parentNode !== entry.box) {
174
+ entry.box.append(panel);
175
+ }
176
+ showPanel(panel, entry.strip.tabId(id), id === active && !region.collapsed);
177
+ }
178
+ entry.box.hidden = ids.length === 0;
179
+ entry.box.style.setProperty('grid-area', region.side);
180
+ entry.box.toggleAttribute('data-collapsed', region.collapsed);
181
+ if (ids.length > 0) {
182
+ shown.add(region.id);
183
+ }
184
+ }
185
+
186
+ function dropRegion(dock, id) {
187
+ const entry = dock.state.regions.get(id);
188
+ entry?.box.remove();
189
+ entry?.strip.disconnect();
190
+ dock.state.regions.delete(id);
191
+ }
192
+
193
+ /** Put a floating panel back in the region it came from (or the center). */
194
+ function dockBack(dock, id) {
195
+ const layout = dock.state.layout;
196
+ const from = layout.floating.find((f) => f.panel === id)?.region;
197
+ dock.change(
198
+ movePanel(layout, id, {
199
+ region: from ?? regionOn(layout, 'center'),
200
+ activate: true,
201
+ }),
202
+ id
203
+ );
204
+ }
205
+
206
+ function makeFloat(dock, id) {
207
+ const root = make(dock.document, 'div', { class: 'ui-dock-float' });
208
+ dock.floatLayer.append(root);
209
+ const dockButton = make(
210
+ dock.document,
211
+ 'button',
212
+ { type: 'button', class: 'ui-window-tool' },
213
+ '⇲'
214
+ );
215
+ dockButton.addEventListener('click', () => dockBack(dock, id));
216
+ const frame = createWindowFrame(root, {
217
+ title: '',
218
+ layers: dock.layers,
219
+ onClose: () => dock.change(closePanel(dock.state.layout, id), id),
220
+ onChange: (rect) => dock.change(floatPanel(dock.state.layout, id, rect)),
221
+ tools: [dockButton],
222
+ });
223
+ frame.raise();
224
+ return { root, frame, dockButton };
225
+ }
226
+
227
+ function renderFloat(dock, f) {
228
+ let entry = dock.state.floats.get(f.panel);
229
+ if (entry === undefined) {
230
+ entry = makeFloat(dock, f.panel);
231
+ dock.state.floats.set(f.panel, entry);
232
+ }
233
+ const panel = panelNode(dock, f.panel);
234
+ const title = titleOf(panel);
235
+ entry.frame.setTitle(title);
236
+ entry.frame.setClosable(isClosable(panel));
237
+ entry.dockButton.setAttribute('aria-label', `Dock ${title}`);
238
+ entry.frame.setRect(
239
+ { x: f.x, y: f.y, width: f.width, height: f.height },
240
+ false
241
+ );
242
+ if (panel.parentNode !== entry.frame.body) {
243
+ entry.frame.body.append(panel);
244
+ }
245
+ panel.hidden = false;
246
+ panel.removeAttribute('role');
247
+ panel.removeAttribute('aria-labelledby');
248
+ panel.removeAttribute('tabindex');
249
+ }
250
+
251
+ /**
252
+ * The center column keeps a usable width (`--ui-dock-center-min-width`);
253
+ * when the regions do not fit, the dock scrolls (they never overlap).
254
+ */
255
+ const CENTER_COLUMN = 'minmax(var(--ui-dock-center-min-width, 12rem), 1fr)';
256
+
257
+ /** The size track of a side of the dock. */
258
+ function track(layout, side, shown) {
259
+ const region = layout.regions.find((r) => r.side === side && shown.has(r.id));
260
+ if (region === undefined || region.collapsed || region.size === null) {
261
+ return 'auto';
262
+ }
263
+ return isTrackAtom(region.size) ? region.size : 'auto';
264
+ }
265
+
266
+ /** Draw the layout: regions, floating panels, closed panels, the grid. */
267
+ export function renderDock(dock) {
268
+ const { state, node } = dock;
269
+ const layout = state.layout;
270
+ const shown = new Set();
271
+ layout.regions.forEach((region) => renderRegion(dock, region, shown));
272
+ const floating = layout.floating.filter((f) => panelNode(dock, f.panel));
273
+ floating.forEach((f) => renderFloat(dock, f));
274
+ for (const c of layout.closed) {
275
+ const panel = panelNode(dock, c.panel);
276
+ if (panel !== undefined) {
277
+ panel.hidden = true;
278
+ dock.holder.append(panel);
279
+ }
280
+ }
281
+ for (const id of state.regions.keys()) {
282
+ if (!layout.regions.some((r) => r.id === id)) {
283
+ dropRegion(dock, id);
284
+ }
285
+ }
286
+ for (const [id, entry] of state.floats) {
287
+ if (!floating.some((f) => f.panel === id)) {
288
+ entry.frame.disconnect();
289
+ entry.root.remove();
290
+ state.floats.delete(id);
291
+ }
292
+ }
293
+ dock.restore.hidden = !layout.closed.some((c) => panelNode(dock, c.panel));
294
+ node.style.setProperty(
295
+ 'grid-template-columns',
296
+ `${track(layout, 'left', shown)} ${CENTER_COLUMN} ${track(layout, 'right', shown)}`
297
+ );
298
+ node.style.setProperty(
299
+ 'grid-template-rows',
300
+ `auto ${track(layout, 'top', shown)} minmax(0, 1fr) ${track(layout, 'bottom', shown)}`
301
+ );
302
+ }
303
+
304
+ /** Disconnect the strips and the frames of a dock. */
305
+ export function disconnectDock(dock) {
306
+ for (const entry of dock.state.regions.values()) {
307
+ entry.strip.disconnect();
308
+ }
309
+ for (const entry of dock.state.floats.values()) {
310
+ entry.frame.disconnect();
311
+ }
312
+ }
@@ -0,0 +1,352 @@
1
+ /**
2
+ * `dock`: panels docked in the regions left, right, top, bottom and center,
3
+ * each region showing its panels as tabs.
4
+ *
5
+ * designer-shell: dock
6
+ * label Designer
7
+ * persist designer.layout
8
+ * left: region
9
+ * size 16rem
10
+ * panels toolbox outline
11
+ * right: region
12
+ * size 20rem
13
+ * panels properties
14
+ * center: region
15
+ * panels canvas
16
+ * toolbox: panel
17
+ * title Toolbox
18
+ * ...
19
+ * outline: panel
20
+ * title Outline
21
+ * ...
22
+ * properties: panel
23
+ * title Properties
24
+ * ...
25
+ * canvas: panel
26
+ * title Canvas
27
+ * closable false
28
+ * ...
29
+ *
30
+ * The layout is the model of `dock-model.js`, read from the `region`
31
+ * children and the `float` and `closed` properties. A panel that no region
32
+ * lists goes to the center.
33
+ *
34
+ * - The tab strip of a region selects, reorders and closes its panels
35
+ * (`tab-strip.js`); a tab dragged to another region moves its panel.
36
+ * - The "Panel actions" menu of a region moves the shown panel to another
37
+ * region, floats it, closes it, and collapses or expands the region.
38
+ * - A floating panel is a window (`window-frame.js`); its "Dock" button
39
+ * puts it back in its region.
40
+ * - "Restore panel" lists the closed panels.
41
+ * - Ctrl+F6 and Ctrl+Shift+F6 move to the next and the previous open panel.
42
+ *
43
+ * Every change sends `dock-change` with `detail.layout` and `detail.lino`
44
+ * (`dockLayoutToLino`), and is saved under the `persist` key of the
45
+ * render's storage (`options.layout.storage`); a saved layout is used when
46
+ * the dock is rendered again.
47
+ */
48
+
49
+ import { defineKind } from '@link-foundation/ui-dom';
50
+ import { bindKeys } from '../a11y/keys.js';
51
+ import {
52
+ activatePanel,
53
+ dockLayoutFromLinks,
54
+ dockLayoutFromNode,
55
+ dockLayoutToLino,
56
+ findPanel,
57
+ movePanel,
58
+ openPanelIds,
59
+ restorePanel,
60
+ } from './dock-model.js';
61
+ import { disconnectDock, focusPanel, renderDock } from './dock-view.js';
62
+ import {
63
+ controllerOf,
64
+ dropController,
65
+ emit,
66
+ findController,
67
+ isLive,
68
+ labelGroup,
69
+ layersOf,
70
+ linkId,
71
+ make,
72
+ readStored,
73
+ renderedChildren,
74
+ storageOf,
75
+ titleOf,
76
+ writeStored,
77
+ } from './dom.js';
78
+ import { menuButton } from './menu.js';
79
+
80
+ const holders = new WeakMap();
81
+ const regionEls = new WeakMap();
82
+
83
+ /** The layout with every rendered panel in it (new ones in the center). */
84
+ function withPanels(layout, ids) {
85
+ let next = layout;
86
+ for (const id of ids) {
87
+ if (findPanel(next, id) === null) {
88
+ const center =
89
+ next.regions.find((r) => r.side === 'center')?.id ?? 'center';
90
+ next = movePanel(
91
+ { ...next, closed: [...next.closed, { panel: id, region: null }] },
92
+ id,
93
+ center
94
+ );
95
+ }
96
+ }
97
+ return next;
98
+ }
99
+
100
+ /** A saved layout, or `null` when there is none or it does not parse. */
101
+ function storedLayout(storage, key) {
102
+ const text = key === null ? null : readStored(storage, key);
103
+ if (text === null) {
104
+ return null;
105
+ }
106
+ try {
107
+ return dockLayoutFromLinks(text);
108
+ } catch {
109
+ return null;
110
+ }
111
+ }
112
+
113
+ /** Apply a new layout: draw it, save it, focus a panel, tell the app. */
114
+ function change(dock, layout, focusId) {
115
+ dock.state.layout = layout;
116
+ render(dock);
117
+ const lino = dockLayoutToLino(layout);
118
+ if (layout.persist !== null) {
119
+ writeStored(dock.storage, layout.persist, lino);
120
+ }
121
+ if (focusId !== undefined) {
122
+ focusPanel(dock, focusId);
123
+ }
124
+ emit(dock.node, 'dock-change', { layout, lino });
125
+ }
126
+
127
+ function render(dock) {
128
+ renderDock(dock);
129
+ dock.observer.takeRecords();
130
+ }
131
+
132
+ /** The panels of the dock: its rendered children that are not regions. */
133
+ function collectPanels(dock) {
134
+ const panels = new Map();
135
+ for (const panel of dock.state.panels.values()) {
136
+ if (dock.node.contains(panel) && linkId(panel) !== null) {
137
+ panels.set(linkId(panel), panel);
138
+ }
139
+ }
140
+ for (const child of renderedChildren(dock.holder)) {
141
+ if (child.localName !== 'ui-region') {
142
+ panels.set(linkId(child), child);
143
+ }
144
+ }
145
+ dock.state.panels = panels;
146
+ }
147
+
148
+ /** The layout written in the store: the dock and its regions. */
149
+ function sourceLayout(dock) {
150
+ const regions = renderedChildren(dock.holder)
151
+ .filter((child) => regionEls.has(child))
152
+ .map((child) => regionEls.get(child));
153
+ return dockLayoutFromNode({
154
+ id: dock.state.el.name ?? null,
155
+ properties: dock.state.el.properties,
156
+ children: regions.map((r) => ({
157
+ id: r.name,
158
+ kind: 'region',
159
+ properties: r.properties,
160
+ })),
161
+ });
162
+ }
163
+
164
+ /** Read the layout again; a saved one wins on the first read. */
165
+ function reload(dock) {
166
+ const { state } = dock;
167
+ state.scheduled = false;
168
+ collectPanels(dock);
169
+ const source = sourceLayout(dock);
170
+ const text = dockLayoutToLino(source);
171
+ if (text !== state.sourceText) {
172
+ const first = state.sourceText === null;
173
+ state.sourceText = text;
174
+ state.layout =
175
+ (first ? storedLayout(dock.storage, source.persist) : null) ?? source;
176
+ }
177
+ state.layout = withPanels(state.layout, [...state.panels.keys()]);
178
+ render(dock);
179
+ }
180
+
181
+ /** Reload once, after the current task (a render inserts many nodes). */
182
+ function schedule(dock) {
183
+ if (!dock.state.scheduled) {
184
+ dock.state.scheduled = true;
185
+ dock.document.defaultView.queueMicrotask(() => reload(dock));
186
+ }
187
+ }
188
+
189
+ /** The index in `ids` of the panel holding the focus, else -1. */
190
+ function focusedIndex(dock, ids) {
191
+ const active = dock.document.activeElement;
192
+ const inside = ids.findIndex((id) =>
193
+ [dock.state.panels.get(id), dock.state.floats.get(id)?.root].some((n) =>
194
+ n?.contains(active)
195
+ )
196
+ );
197
+ if (inside >= 0) {
198
+ return inside;
199
+ }
200
+ const tab = active?.closest?.('[role=tab]');
201
+ return ids.findIndex((id) => tab?.dataset.panel === id);
202
+ }
203
+
204
+ /**
205
+ * Focus the next (`step` 1) or the previous (-1) open panel; false when
206
+ * there is none, so the key is left alone.
207
+ */
208
+ function cyclePanels(dock, step) {
209
+ const { state } = dock;
210
+ if (state.layout === null) {
211
+ return false;
212
+ }
213
+ const ids = openPanelIds(state.layout).filter((id) => state.panels.get(id));
214
+ if (ids.length === 0) {
215
+ return false;
216
+ }
217
+ const at = focusedIndex(dock, ids);
218
+ const next = ids[(at + step + ids.length) % ids.length] ?? ids[0];
219
+ if (findPanel(state.layout, next).place === 'region') {
220
+ change(dock, activatePanel(state.layout, next), next);
221
+ } else {
222
+ focusPanel(dock, next);
223
+ }
224
+ }
225
+
226
+ /** The "Restore panel" button: a menu of the closed panels. */
227
+ function restoreButton(dock) {
228
+ return menuButton(dock.document, {
229
+ label: 'Restore panel',
230
+ text: 'Restore panel',
231
+ className: 'ui-dock-restore',
232
+ items: () =>
233
+ dock.state.layout.closed
234
+ .filter((c) => dock.state.panels.get(c.panel) !== undefined)
235
+ .map((c) => ({
236
+ label: titleOf(dock.state.panels.get(c.panel)),
237
+ run: () =>
238
+ dock.change(restorePanel(dock.state.layout, c.panel), c.panel),
239
+ })),
240
+ });
241
+ }
242
+
243
+ function observe(dock) {
244
+ const { holder, node, state } = dock;
245
+ const observer = new dock.document.defaultView.MutationObserver((records) => {
246
+ const relevant = records.some((r) =>
247
+ r.type === 'childList'
248
+ ? r.target === holder
249
+ : state.panels.get(linkId(r.target)) === r.target
250
+ );
251
+ if (relevant) {
252
+ schedule(dock);
253
+ }
254
+ });
255
+ observer.observe(holder, { childList: true });
256
+ observer.observe(node, {
257
+ subtree: true,
258
+ attributes: true,
259
+ attributeFilter: ['data-title', 'data-closable'],
260
+ });
261
+ return observer;
262
+ }
263
+
264
+ function createDock(node, ctx) {
265
+ const document = ctx.document;
266
+ const dock = {
267
+ node,
268
+ document,
269
+ storage: storageOf(ctx),
270
+ layers: layersOf(ctx),
271
+ holder: holders.get(node),
272
+ state: {
273
+ el: null,
274
+ layout: null,
275
+ sourceText: null,
276
+ panels: new Map(),
277
+ regions: new Map(),
278
+ floats: new Map(),
279
+ scheduled: false,
280
+ },
281
+ };
282
+ dock.change = (layout, focusId) => change(dock, layout, focusId);
283
+ dock.restore = restoreButton(dock);
284
+ const tools = make(document, 'div', { class: 'ui-dock-tools' });
285
+ tools.append(dock.restore);
286
+ dock.floatLayer = make(document, 'div', { class: 'ui-dock-floating' });
287
+ node.prepend(tools);
288
+ node.append(dock.floatLayer);
289
+ dock.observer = observe(dock);
290
+ // Ctrl+F6 and Ctrl+Shift+F6: the next and the previous open panel.
291
+ bindKeys(node, {
292
+ 'Ctrl+F6': () => cyclePanels(dock, 1),
293
+ 'Ctrl+Shift+F6': () => cyclePanels(dock, -1),
294
+ });
295
+ return {
296
+ state: dock.state,
297
+ schedule: () => schedule(dock),
298
+ update(el) {
299
+ dock.state.el = el;
300
+ schedule(dock);
301
+ },
302
+ disconnect() {
303
+ dock.observer.disconnect();
304
+ disconnectDock(dock);
305
+ },
306
+ };
307
+ }
308
+
309
+ defineKind('dock', {
310
+ tag: 'ui-dock',
311
+ childrenSlot: (node) => holders.get(node) ?? node,
312
+ create(el, ctx) {
313
+ const node = ctx.document.createElement('ui-dock');
314
+ if (isLive(ctx)) {
315
+ const holder = ctx.document.createElement('div');
316
+ holder.className = 'ui-dock-holder';
317
+ holder.hidden = true;
318
+ node.appendChild(holder);
319
+ holders.set(node, holder);
320
+ }
321
+ return node;
322
+ },
323
+ update(node, el, changed, ctx) {
324
+ if (changed.includes('label')) {
325
+ labelGroup(node, el);
326
+ }
327
+ if (isLive(ctx)) {
328
+ controllerOf(node, () => createDock(node, ctx)).update(el);
329
+ }
330
+ },
331
+ destroy: (node) => dropController(node),
332
+ });
333
+
334
+ defineKind('region', {
335
+ tag: 'ui-region',
336
+ childrenSlot: null,
337
+ create(el, ctx) {
338
+ const node = ctx.document.createElement('ui-region');
339
+ node.setAttribute('hidden', '');
340
+ return node;
341
+ },
342
+ update(node, el) {
343
+ regionEls.set(node, el);
344
+ const dock = node.parentNode?.parentNode;
345
+ if (dock) {
346
+ findController(dock)?.schedule?.();
347
+ }
348
+ },
349
+ });
350
+
351
+ /** The current layout of a rendered dock (for tests and tools). */
352
+ export const dockLayout = (node) => findController(node)?.state.layout ?? null;