@link-foundation/ui-components 0.0.0-stage → 0.1.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,151 @@
1
+ /**
2
+ * `tab-group`: panels shown one at a time behind a tab strip (WAI-ARIA APG
3
+ * tabs pattern, automatic activation).
4
+ *
5
+ * (inspector: tab-group (label Inspector) (active styles)
6
+ * (styles: panel (title Styles) ...)
7
+ * (events: panel (title Events) (closable true) ...))
8
+ *
9
+ * The strip is described in `tab-strip.js`. Selecting, closing and
10
+ * reordering tabs change the rendered group and send the events
11
+ * `tab-change` (`detail.active`), `tab-close` (`detail.panel`) and
12
+ * `tab-reorder` (`detail.order`); the application may write them back to
13
+ * its store.
14
+ */
15
+
16
+ import { defineKind } from '@link-foundation/ui-dom';
17
+ import {
18
+ atomOf,
19
+ controllerOf,
20
+ dropController,
21
+ emit,
22
+ findController,
23
+ idOf,
24
+ isLive,
25
+ linkId,
26
+ renderedChildren,
27
+ titleOf,
28
+ watchChildren,
29
+ } from './dom.js';
30
+ import { createTabStrip } from './tab-strip.js';
31
+
32
+ /** Mark a panel as the tab panel of a tab. */
33
+ export function showPanel(panel, tabId, shown) {
34
+ panel.setAttribute('role', 'tabpanel');
35
+ if (tabId !== null) {
36
+ panel.setAttribute('aria-labelledby', tabId);
37
+ }
38
+ panel.tabIndex = 0;
39
+ panel.toggleAttribute('hidden', !shown);
40
+ }
41
+
42
+ /** The tab of a rendered panel. */
43
+ export const tabOf = (panel) => ({
44
+ id: linkId(panel),
45
+ title: titleOf(panel),
46
+ panel: idOf(panel, 'ui-tab-panel'),
47
+ closable: panel.getAttribute('data-closable') === 'true',
48
+ });
49
+
50
+ function createTabGroup(node, ctx, el) {
51
+ const state = { el, active: null, order: [], closed: new Set() };
52
+
53
+ const panels = () =>
54
+ renderedChildren(node).filter((p) => !state.closed.has(linkId(p)));
55
+
56
+ const sorted = () => {
57
+ const all = panels();
58
+ const rank = (p) => {
59
+ const i = state.order.indexOf(linkId(p));
60
+ return i < 0 ? state.order.length + all.indexOf(p) : i;
61
+ };
62
+ return [...all].sort((a, b) => rank(a) - rank(b));
63
+ };
64
+
65
+ const refresh = () => {
66
+ const list = sorted();
67
+ const ids = list.map(linkId);
68
+ if (!ids.includes(state.active)) {
69
+ const wanted = atomOf(state.el, 'active');
70
+ state.active = ids.includes(wanted) ? wanted : (ids[0] ?? null);
71
+ }
72
+ strip.render(list.map(tabOf), state.active);
73
+ for (const panel of renderedChildren(node)) {
74
+ const id = linkId(panel);
75
+ showPanel(panel, strip.tabId(id), id === state.active);
76
+ }
77
+ };
78
+
79
+ const strip = createTabStrip(ctx.document, {
80
+ get label() {
81
+ return atomOf(state.el, 'label') ?? 'Tabs';
82
+ },
83
+ get reorderable() {
84
+ return atomOf(state.el, 'reorderable') !== 'false';
85
+ },
86
+ select(id) {
87
+ if (id !== state.active) {
88
+ state.active = id;
89
+ refresh();
90
+ emit(node, 'tab-change', { active: id });
91
+ }
92
+ },
93
+ close(id) {
94
+ const ids = sorted().map(linkId);
95
+ const at = ids.indexOf(id);
96
+ state.closed.add(id);
97
+ if (state.active === id) {
98
+ state.active = ids[at + 1] ?? ids[at - 1] ?? null;
99
+ }
100
+ refresh();
101
+ if (state.active !== null) {
102
+ strip.focusTab(state.active);
103
+ }
104
+ emit(node, 'tab-close', { panel: id });
105
+ },
106
+ reorder(order) {
107
+ state.order = order;
108
+ refresh();
109
+ emit(node, 'tab-reorder', { order: [...order] });
110
+ },
111
+ });
112
+ node.prepend(strip.element);
113
+
114
+ const observer = watchChildren(node, refresh, [
115
+ 'data-title',
116
+ 'data-closable',
117
+ ]);
118
+ return {
119
+ state,
120
+ strip,
121
+ update(el, changed) {
122
+ state.el = el;
123
+ if (changed.includes('active')) {
124
+ state.active = atomOf(el, 'active') ?? state.active;
125
+ }
126
+ refresh();
127
+ observer.takeRecords();
128
+ },
129
+ disconnect() {
130
+ observer.disconnect();
131
+ strip.disconnect();
132
+ },
133
+ };
134
+ }
135
+
136
+ defineKind('tab-group', {
137
+ tag: 'ui-tab-group',
138
+ create: (el, ctx) => ctx.document.createElement('ui-tab-group'),
139
+ update(node, el, changed, ctx) {
140
+ if (isLive(ctx)) {
141
+ controllerOf(node, () => createTabGroup(node, ctx, el)).update(
142
+ el,
143
+ changed
144
+ );
145
+ }
146
+ },
147
+ destroy: (node) => dropController(node),
148
+ });
149
+
150
+ /** The selected panel id of a rendered tab group (for tests and tools). */
151
+ export const activeTab = (node) => findController(node)?.state.active ?? null;
@@ -0,0 +1,277 @@
1
+ /**
2
+ * The tab strip of a tab group and of a dock region (WAI-ARIA APG tabs
3
+ * pattern, automatic activation).
4
+ *
5
+ * - Left and Right move between the tabs and select them, Home and End
6
+ * go to the first and the last tab; one tab is in the tab order.
7
+ * - Delete closes a closable tab.
8
+ * - Ctrl+Shift+Left and Ctrl+Shift+Right move the tab (reorder); so does
9
+ * dragging it to another place in the strip.
10
+ * - A tab can be dragged to another strip (another dock region).
11
+ * - When the tabs do not fit, the "More tabs" menu lists them all.
12
+ * - An optional "Panel actions" menu acts on the selected tab.
13
+ */
14
+
15
+ import { bindKeys } from '../a11y/keys.js';
16
+ import { make, uid } from './dom.js';
17
+ import { menuButton } from './menu.js';
18
+
19
+ /** The panel id of the tab dragged right now (shared by all strips). */
20
+ let dragging = null;
21
+
22
+ /**
23
+ * @typedef {object} Tab
24
+ * @property {string} id the panel id
25
+ * @property {string} title
26
+ * @property {string} panel the DOM id of the tab panel
27
+ * @property {boolean} closable
28
+ *
29
+ * @typedef {object} StripHandlers
30
+ * @property {(id: string) => void} select
31
+ * @property {(id: string) => void} [close]
32
+ * @property {(order: string[]) => void} [reorder]
33
+ * @property {(id: string, index: number) => void} [receive] a tab of
34
+ * another strip was dropped here
35
+ * @property {(id: string) => {label: string, run: () => void}[]} [actions]
36
+ */
37
+
38
+ const order = (strip) => strip.tabs.map((t) => t.id);
39
+ const focusTab = (strip, id) => strip.buttons.get(id)?.focus();
40
+
41
+ /** Move tab `id` to index `to` and keep the focus on it. */
42
+ function reorder(strip, id, to) {
43
+ const ids = order(strip).filter((t) => t !== id);
44
+ ids.splice(Math.max(0, Math.min(to, ids.length)), 0, id);
45
+ strip.spec.reorder?.(ids);
46
+ focusTab(strip, id);
47
+ }
48
+
49
+ function selectAndFocus(strip, id) {
50
+ strip.spec.select(id);
51
+ focusTab(strip, id);
52
+ }
53
+
54
+ /** Select the tab `move` places after tab `id` (around the ends). */
55
+ function step(strip, id, move) {
56
+ const ids = order(strip);
57
+ const at = ids.indexOf(id);
58
+ selectAndFocus(strip, ids[(at + move + ids.length) % ids.length]);
59
+ }
60
+
61
+ /** The keys of the tab of panel `id()`. */
62
+ function tabKeys(strip, id) {
63
+ const { spec } = strip;
64
+ const move = (by) => () => {
65
+ if (spec.reorderable !== false) {
66
+ reorder(strip, id(), order(strip).indexOf(id()) + by);
67
+ }
68
+ };
69
+ return {
70
+ ArrowLeft: () => step(strip, id(), -1),
71
+ ArrowRight: () => step(strip, id(), 1),
72
+ Home: () => selectAndFocus(strip, order(strip)[0]),
73
+ End: () => selectAndFocus(strip, order(strip).at(-1)),
74
+ 'Ctrl+Shift+ArrowLeft': move(-1),
75
+ 'Ctrl+Shift+ArrowRight': move(1),
76
+ Delete: () => {
77
+ const tab = strip.tabs.find((t) => t.id === id());
78
+ if (!tab?.closable || !spec.close) {
79
+ return false;
80
+ }
81
+ spec.close(tab.id);
82
+ },
83
+ };
84
+ }
85
+
86
+ /** A dragged tab dropped before tab `before` (`null`: at the end). */
87
+ function onDrop(strip, event, before) {
88
+ if (dragging === null) {
89
+ return;
90
+ }
91
+ event.preventDefault();
92
+ const { id } = dragging;
93
+ dragging = null;
94
+ const ids = order(strip);
95
+ const target = before === null ? ids.length : ids.indexOf(before);
96
+ if (ids.includes(id)) {
97
+ if (strip.spec.reorderable !== false) {
98
+ const from = ids.indexOf(id);
99
+ reorder(strip, id, from < target ? target - 1 : target);
100
+ }
101
+ } else {
102
+ strip.spec.receive?.(id, target);
103
+ }
104
+ }
105
+
106
+ function listenDrag(strip, button) {
107
+ button.addEventListener('dragstart', (event) => {
108
+ dragging = { id: button.dataset.panel };
109
+ event.dataTransfer?.setData('text/plain', button.dataset.panel);
110
+ if (event.dataTransfer) {
111
+ event.dataTransfer.effectAllowed = 'move';
112
+ }
113
+ });
114
+ button.addEventListener('dragend', () => {
115
+ dragging = null;
116
+ });
117
+ button.addEventListener('dragover', (event) => event.preventDefault());
118
+ button.addEventListener('drop', (event) => {
119
+ event.stopPropagation();
120
+ onDrop(strip, event, button.dataset.panel);
121
+ });
122
+ }
123
+
124
+ function makeTab(strip) {
125
+ const button = make(strip.document, 'button', {
126
+ type: 'button',
127
+ role: 'tab',
128
+ id: uid('ui-tab'),
129
+ draggable: 'true',
130
+ });
131
+ button.append(make(strip.document, 'span', { class: 'ui-tab-title' }));
132
+ button.addEventListener('click', (event) => {
133
+ if (event.target.closest?.('.ui-tab-close')) {
134
+ strip.spec.close?.(button.dataset.panel);
135
+ return;
136
+ }
137
+ strip.spec.select(button.dataset.panel);
138
+ });
139
+ bindKeys(
140
+ button,
141
+ tabKeys(strip, () => button.dataset.panel)
142
+ );
143
+ listenDrag(strip, button);
144
+ return button;
145
+ }
146
+
147
+ /** Write a tab: its title, its selection and its close mark. */
148
+ function drawTab(strip, button, tab, selected) {
149
+ button.dataset.panel = tab.id;
150
+ button.firstChild.textContent = tab.title;
151
+ const on = tab.id === selected;
152
+ button.setAttribute('aria-selected', String(on));
153
+ button.setAttribute('aria-controls', tab.panel);
154
+ button.tabIndex = on ? 0 : -1;
155
+ let close = button.querySelector('.ui-tab-close');
156
+ if (tab.closable && close === null) {
157
+ // Not a button: a tab cannot hold another control. Delete closes the
158
+ // tab from the keyboard.
159
+ close = make(
160
+ strip.document,
161
+ 'span',
162
+ {
163
+ class: 'ui-tab-close',
164
+ 'aria-hidden': 'true',
165
+ title: `Close ${tab.title}`,
166
+ },
167
+ '×'
168
+ );
169
+ button.append(close);
170
+ } else if (!tab.closable) {
171
+ close?.remove();
172
+ }
173
+ }
174
+
175
+ /** The "More tabs" menu (shown when the tabs overflow) and the actions. */
176
+ function makeMenus(strip) {
177
+ const { document, spec, element } = strip;
178
+ strip.overflow = menuButton(document, {
179
+ label: `More tabs of ${spec.label}`,
180
+ text: '⋯',
181
+ className: 'ui-tab-overflow',
182
+ items: () =>
183
+ strip.tabs.map((tab) => ({
184
+ label: tab.title,
185
+ run: () => selectAndFocus(strip, tab.id),
186
+ })),
187
+ });
188
+ strip.overflow.hidden = true;
189
+ element.append(strip.overflow);
190
+ strip.actions = null;
191
+ if (spec.actions) {
192
+ strip.actions = menuButton(document, {
193
+ label: `Panel actions of ${spec.label}`,
194
+ text: '⋮',
195
+ className: 'ui-tab-actions',
196
+ items: () => (strip.active === null ? [] : spec.actions(strip.active)),
197
+ });
198
+ element.append(strip.actions);
199
+ }
200
+ }
201
+
202
+ /** Show the "More tabs" menu only when the tabs do not fit. */
203
+ function checkOverflow(strip) {
204
+ strip.overflow.hidden = !(
205
+ strip.list.scrollWidth >
206
+ strip.list.clientWidth + 1
207
+ );
208
+ }
209
+
210
+ /** Draw the tabs; `selected` is the selected panel id. */
211
+ function renderStrip(strip, tabs, selected) {
212
+ const { buttons, list } = strip;
213
+ strip.tabs = tabs;
214
+ strip.active = selected;
215
+ for (const [id, button] of buttons) {
216
+ if (!tabs.some((t) => t.id === id)) {
217
+ button.remove();
218
+ buttons.delete(id);
219
+ }
220
+ }
221
+ tabs.forEach((tab, i) => {
222
+ let button = buttons.get(tab.id);
223
+ if (button === undefined) {
224
+ button = makeTab(strip);
225
+ buttons.set(tab.id, button);
226
+ }
227
+ drawTab(strip, button, tab, selected);
228
+ if (list.children[i] !== button) {
229
+ list.insertBefore(button, list.children[i] ?? null);
230
+ }
231
+ });
232
+ if (strip.actions !== null) {
233
+ strip.actions.hidden = selected === null;
234
+ }
235
+ checkOverflow(strip);
236
+ }
237
+
238
+ /**
239
+ * Make a tab strip.
240
+ * @param {Document} document
241
+ * @param {{label: string, reorderable?: boolean} & StripHandlers} spec
242
+ */
243
+ export function createTabStrip(document, spec) {
244
+ const element = make(document, 'div', { class: 'ui-tab-strip' });
245
+ const list = make(document, 'div', {
246
+ role: 'tablist',
247
+ 'aria-label': spec.label,
248
+ });
249
+ element.append(list);
250
+ /** @type {{tabs: Tab[]} & Record<string, any>} */
251
+ const strip = {
252
+ document,
253
+ spec,
254
+ element,
255
+ list,
256
+ tabs: [],
257
+ active: null,
258
+ buttons: new Map(),
259
+ };
260
+ list.addEventListener('dragover', (event) => event.preventDefault());
261
+ list.addEventListener('drop', (event) => onDrop(strip, event, null));
262
+ makeMenus(strip);
263
+ const win = document.defaultView;
264
+ const resizeObserver =
265
+ typeof win?.ResizeObserver === 'function'
266
+ ? new win.ResizeObserver(() => checkOverflow(strip))
267
+ : null;
268
+ resizeObserver?.observe(list);
269
+ return {
270
+ element,
271
+ render: (tabs, selected) => renderStrip(strip, tabs, selected),
272
+ focusTab: (id) => focusTab(strip, id),
273
+ /** The DOM id of the tab of a panel. */
274
+ tabId: (id) => strip.buttons.get(id)?.id ?? null,
275
+ disconnect: () => resizeObserver?.disconnect(),
276
+ };
277
+ }
@@ -0,0 +1,229 @@
1
+ /**
2
+ * The vocabulary of the layout elements, in the shape of
3
+ * docs/spec/vocabulary.lino, and the ui-core vocabulary extended with it.
4
+ * Parse layout documents with `{ vocabulary: layoutVocabulary() }`: then
5
+ * their properties are checked, and none is reported as unknown.
6
+ */
7
+
8
+ import { defaultVocabulary, loadVocabulary } from '@link-foundation/ui-core';
9
+
10
+ /** The layout kinds as Links Notation. */
11
+ export const LAYOUT_VOCABULARY_TEXT = `stack: kind
12
+ description 'Lays its children out in one direction (CSS flexbox).'
13
+ property direction
14
+ enum vertical horizontal row column row-reverse column-reverse
15
+ property gap dimension
16
+ property padding dimension
17
+ property align
18
+ enum start center end stretch baseline
19
+ property justify
20
+ enum start center end space-between space-around space-evenly
21
+ property wrap
22
+ enum true false reverse
23
+ property style element-ref
24
+ children any
25
+
26
+ grid: kind
27
+ description 'Lays its children out in rows and columns (CSS grid).'
28
+ property columns any
29
+ property rows any
30
+ property areas any
31
+ property gap dimension
32
+ property padding dimension
33
+ property style element-ref
34
+ children any
35
+
36
+ split: kind
37
+ description 'Two or more panes with draggable dividers.'
38
+ property direction
39
+ enum row column horizontal vertical
40
+ property sizes any
41
+ property min any
42
+ property max any
43
+ property collapsible any
44
+ property collapsed any
45
+ property resizable
46
+ enum true false
47
+ property remember-size string
48
+ property children any
49
+ property label string
50
+ children any
51
+
52
+ tab-group: kind
53
+ description 'Panels shown one at a time behind a tab strip.'
54
+ property active element-ref
55
+ property label string
56
+ property reorderable
57
+ enum true false
58
+ children any
59
+
60
+ panel: kind
61
+ description 'A titled panel: a tab of a tab group or a dock panel.'
62
+ property title string
63
+ property closable
64
+ enum true false
65
+ children any
66
+
67
+ dock: kind
68
+ description 'Docked panels in the regions left, right, top, bottom and center.'
69
+ property persist string
70
+ property float any multi
71
+ property closed any multi
72
+ property label string
73
+ children any
74
+
75
+ region: kind
76
+ description 'A region of a dock and the panels it shows as tabs.'
77
+ property side
78
+ enum left right top bottom center
79
+ property size dimension
80
+ property collapsed
81
+ enum true false
82
+ property panels any
83
+ property active element-ref
84
+ children none
85
+
86
+ window: kind
87
+ description 'A floating, movable and resizable surface.'
88
+ property title string
89
+ property open
90
+ enum true false
91
+ property x number
92
+ property y number
93
+ property width number
94
+ property height number
95
+ property closable
96
+ enum true false
97
+ children any
98
+
99
+ app-shell: kind
100
+ description 'Navigation as a bottom bar, a rail or a drawer, by viewport width.'
101
+ property breakpoints any
102
+ property bottom-bar element-ref
103
+ property rail element-ref
104
+ property drawer element-ref
105
+ property label string
106
+ children any
107
+
108
+ container: kind
109
+ description 'Centers its content up to a maximum inline size, with gutters.'
110
+ property size
111
+ enum extra-small small medium large extra-large full
112
+ property gutters boolean
113
+ property style element-ref
114
+ children any
115
+
116
+ paper: kind
117
+ description 'A plain surface: elevated from 0 to 5, or outlined.'
118
+ property elevation number
119
+ property variant
120
+ enum elevated outlined
121
+ property square boolean
122
+ property style element-ref
123
+ children any
124
+
125
+ card: kind
126
+ description 'A surface for one subject: an optional title and subtitle, then any content.'
127
+ positional title
128
+ property title string
129
+ property subtitle string
130
+ property variant
131
+ enum elevated filled outlined
132
+ property style element-ref
133
+ children any
134
+
135
+ app-bar: kind
136
+ description 'The bar at the top of a page or a section: a title, then any content.'
137
+ positional title
138
+ property title string
139
+ property position
140
+ enum static sticky fixed
141
+ property tone
142
+ enum surface primary
143
+ property style element-ref
144
+ children any
145
+ nav-strip: kind
146
+ property label string
147
+ property active string
148
+ property wrap-below dimension
149
+ children any
150
+
151
+ section-nav: kind
152
+ property label string
153
+ property active string
154
+ property wrap-below dimension
155
+ property back-to-top string
156
+ property back-label string
157
+ children any
158
+
159
+ nav-link: kind
160
+ positional label
161
+ property label string
162
+ property href string
163
+ property external boolean
164
+ children none
165
+
166
+ link-cards: kind
167
+ property min dimension
168
+ children any
169
+
170
+ link-card: kind
171
+ positional title
172
+ property title string
173
+ property label string
174
+ property summary string
175
+ property glyph string
176
+ property icon string
177
+ property href string
178
+ property external boolean
179
+ children none
180
+
181
+ titled-section: kind
182
+ positional title
183
+ property title string
184
+ property kicker string
185
+ property level number
186
+ children any
187
+
188
+ pref-switches: kind
189
+ children none
190
+
191
+ `;
192
+
193
+ /** The common properties of the dialect (`note`), declared on every kind. */
194
+ function withCommon(kinds, base) {
195
+ const common = [...(base.kinds.get('document')?.properties ?? [])].filter(
196
+ ([name]) => name === 'note'
197
+ );
198
+ for (const kind of kinds.values()) {
199
+ for (const [name, spec] of common) {
200
+ if (!kind.properties.has(name)) {
201
+ kind.properties.set(name, spec);
202
+ }
203
+ }
204
+ }
205
+ return kinds;
206
+ }
207
+
208
+ let cached = null;
209
+
210
+ /**
211
+ * The ui-dialect vocabulary with the layout kinds (cached). `stack` of the
212
+ * layout vocabulary replaces the basic one: it accepts every value the
213
+ * basic one does, and more.
214
+ * @returns {import('@link-foundation/ui-core').Vocabulary}
215
+ */
216
+ export function layoutVocabulary() {
217
+ if (cached === null) {
218
+ const base = defaultVocabulary();
219
+ const layout = withCommon(
220
+ loadVocabulary(LAYOUT_VOCABULARY_TEXT).kinds,
221
+ base
222
+ );
223
+ cached = Object.freeze({
224
+ ...base,
225
+ kinds: new Map([...base.kinds, ...layout]),
226
+ });
227
+ }
228
+ return cached;
229
+ }