@gramlot/gramlot 0.3.40 → 0.4.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 (279) hide show
  1. package/assets/icons/applications.svg +4 -0
  2. package/assets/icons/archive.svg +4 -0
  3. package/assets/icons/attachment.svg +4 -0
  4. package/assets/icons/book.svg +4 -0
  5. package/assets/icons/bookmark.svg +4 -0
  6. package/assets/icons/calendar.svg +4 -0
  7. package/assets/icons/cancel.svg +4 -0
  8. package/assets/icons/chart.svg +4 -1
  9. package/assets/icons/chat.svg +4 -0
  10. package/assets/icons/clock.svg +4 -0
  11. package/assets/icons/code.svg +4 -0
  12. package/assets/icons/collapse.svg +4 -0
  13. package/assets/icons/columns.svg +4 -0
  14. package/assets/icons/confirm.svg +4 -0
  15. package/assets/icons/copy.svg +4 -0
  16. package/assets/icons/cut.svg +4 -0
  17. package/assets/icons/database.svg +4 -0
  18. package/assets/icons/delete.svg +4 -0
  19. package/assets/icons/detach.svg +4 -0
  20. package/assets/icons/document.svg +4 -0
  21. package/assets/icons/download.svg +4 -0
  22. package/assets/icons/duplicate.svg +4 -0
  23. package/assets/icons/edit.svg +4 -0
  24. package/assets/icons/expand.svg +4 -0
  25. package/assets/icons/export.svg +4 -0
  26. package/assets/icons/eye.svg +4 -0
  27. package/assets/icons/filter.svg +4 -0
  28. package/assets/icons/first.svg +4 -0
  29. package/assets/icons/folder.svg +4 -0
  30. package/assets/icons/group.svg +4 -0
  31. package/assets/icons/help.svg +4 -0
  32. package/assets/icons/home.svg +4 -0
  33. package/assets/icons/import.svg +4 -0
  34. package/assets/icons/info.svg +4 -0
  35. package/assets/icons/inspector.svg +4 -0
  36. package/assets/icons/last.svg +4 -0
  37. package/assets/icons/layers.svg +4 -0
  38. package/assets/icons/link.svg +4 -0
  39. package/assets/icons/list.svg +4 -0
  40. package/assets/icons/lock.svg +4 -0
  41. package/assets/icons/logout.svg +4 -0
  42. package/assets/icons/navigation.svg +4 -0
  43. package/assets/icons/new.svg +4 -0
  44. package/assets/icons/next.svg +4 -0
  45. package/assets/icons/open.svg +4 -0
  46. package/assets/icons/palette.svg +4 -0
  47. package/assets/icons/panel-bottom.svg +4 -0
  48. package/assets/icons/panel-left.svg +4 -0
  49. package/assets/icons/panel-right.svg +4 -0
  50. package/assets/icons/panel-top.svg +4 -0
  51. package/assets/icons/paste.svg +4 -0
  52. package/assets/icons/pause.svg +4 -0
  53. package/assets/icons/pin.svg +4 -0
  54. package/assets/icons/play.svg +4 -0
  55. package/assets/icons/previous.svg +4 -0
  56. package/assets/icons/print.svg +4 -0
  57. package/assets/icons/redo.svg +4 -0
  58. package/assets/icons/refresh.svg +4 -0
  59. package/assets/icons/save.svg +4 -0
  60. package/assets/icons/search.svg +4 -0
  61. package/assets/icons/send.svg +4 -0
  62. package/assets/icons/settings.svg +4 -0
  63. package/assets/icons/sort-ascending.svg +4 -0
  64. package/assets/icons/sort-descending.svg +4 -0
  65. package/assets/icons/stop.svg +4 -0
  66. package/assets/icons/table.svg +4 -0
  67. package/assets/icons/tree.svg +4 -0
  68. package/assets/icons/undo.svg +4 -0
  69. package/assets/icons/unlock.svg +4 -0
  70. package/assets/icons/upload.svg +4 -0
  71. package/assets/icons/user.svg +4 -0
  72. package/assets/icons/warning.svg +4 -0
  73. package/assets/icons/zoom-in.svg +4 -0
  74. package/assets/icons/zoom-out.svg +4 -0
  75. package/dist/components/charts/__init__.py +1 -1
  76. package/dist/components/charts/assets/index.js +1 -1
  77. package/dist/components/charts/assets/libraries/vega.js +11 -11
  78. package/dist/components/editors/__init__.py +1 -1
  79. package/dist/components/editors/assets/index.js +1 -1
  80. package/dist/components/editors/assets/libraries/codemirror.js +30 -31
  81. package/dist/components/editors/assets/libraries/jodit.js +3 -1
  82. package/dist/components/editors/assets/libraries/prosemirror.js +1 -1
  83. package/dist/components/editors/grammar.json +6 -1
  84. package/dist/components/grid/__init__.py +1 -1
  85. package/dist/components/grid/assets/index.js +1 -1
  86. package/dist/components/grid/commands.json +4 -6
  87. package/dist/components/grid/grammar.json +51 -0
  88. package/dist/components/inputs/__init__.py +1 -1
  89. package/dist/components/inputs/assets/index.js +1 -1
  90. package/dist/components/inputs/grammar.json +4987 -216
  91. package/dist/components/layout/__init__.py +1 -1
  92. package/dist/components/layout/assets/index.js +1 -1
  93. package/dist/components/layout/grammar.json +69 -4
  94. package/dist/components/tree/__init__.py +1 -1
  95. package/dist/components/tree/assets/index.js +1 -1
  96. package/dist/components/tree/grammar.json +16 -0
  97. package/dist/components/typst/__init__.py +1 -1
  98. package/dist/components/typst/assets/collection.js +6 -6
  99. package/dist/components/typst/assets/index.js +1 -1
  100. package/dist/components/uploads/__init__.py +1 -1
  101. package/dist/components/uploads/assets/index.js +1 -1
  102. package/dist/components/uploads/grammar.json +66 -0
  103. package/dist/declared-collections.js +1 -1
  104. package/dist/gramlot.js +4007 -1256
  105. package/dist/gramlot.min.js +329 -131
  106. package/dist/libraries.json +1 -0
  107. package/dist/standard-collections.js +1 -1
  108. package/dist/standard-grammar.js +1 -1
  109. package/package.json +3 -1
  110. package/src/binding/ask-dialog.js +17 -3
  111. package/src/binding/data-binder.js +5 -0
  112. package/src/binding/providers.js +1 -1
  113. package/src/binding/runtime.js +6 -3
  114. package/src/builder/chart-icon.js +2 -0
  115. package/src/builder/gramlot-builder.d.ts +3 -1
  116. package/src/builder/gramlot-builder.js +26 -9
  117. package/src/builder/source.js +12 -3
  118. package/src/builder/xml-recipe.js +144 -0
  119. package/src/chat-file-types.js +13 -0
  120. package/src/chat.js +23 -25
  121. package/src/commands.d.ts +1 -1
  122. package/src/commands.js +1 -1
  123. package/src/components/border-container.js +64 -6
  124. package/src/components/buttons.js +26 -31
  125. package/src/components/chart-geographic-options.js +1 -1
  126. package/src/components/chart-pane.js +5 -5
  127. package/src/components/chart-spatial-options.js +5 -1
  128. package/src/components/check-box-text-editor.js +1 -0
  129. package/src/components/check-box-text.js +2 -0
  130. package/src/components/choice-editor.js +3 -2
  131. package/src/components/choice-field-styles.js +9 -1
  132. package/src/components/code-mirror-engine.js +18 -5
  133. package/src/components/code-mirror-gramlot.js +85 -0
  134. package/src/components/code-mirror.js +3 -2
  135. package/src/components/drawing.js +43 -14
  136. package/src/components/editor-options.js +1 -1
  137. package/src/components/graphical-ranges.js +177 -0
  138. package/src/components/grid-footer.js +6 -1
  139. package/src/components/grid-styles.js +11 -2
  140. package/src/components/grid-tools.js +15 -7
  141. package/src/components/grid.js +69 -8
  142. package/src/components/inputs.js +93 -23
  143. package/src/components/jodit-engine.js +3 -1
  144. package/src/components/menus.js +83 -25
  145. package/src/components/numeric-range.js +39 -0
  146. package/src/components/selected-container.js +109 -63
  147. package/src/components/tab-bar.js +371 -0
  148. package/src/components/toolbar-icon-style.js +22 -0
  149. package/src/components/toolbar-overflow.js +74 -12
  150. package/src/components/tree.js +12 -3
  151. package/src/components/typst-preview.js +3 -3
  152. package/src/components/upload-blocks.js +88 -0
  153. package/src/components/upload-engine.js +21 -31
  154. package/src/components/uploader.js +168 -47
  155. package/src/gramlot.js +6 -3
  156. package/src/handlers/dom-handler.d.ts +2 -0
  157. package/src/handlers/dom-handler.js +9 -0
  158. package/src/handlers/rpc-handler.d.ts +1 -1
  159. package/src/handlers/rpc-handler.js +2 -0
  160. package/src/handlers/source-handler.d.ts +5 -3
  161. package/src/handlers/source-handler.js +31 -13
  162. package/src/icons.js +84 -0
  163. package/src/index-page-runtime.js +9 -2
  164. package/src/index-page-styles.js +1 -1
  165. package/src/index-theme.js +210 -3
  166. package/src/index.d.ts +5 -1
  167. package/src/index.js +5 -1
  168. package/src/libraries.js +1 -1
  169. package/src/page-store-connection.js +44 -7
  170. package/src/renderer/gramlot-renderer.js +4 -1
  171. package/src/server/chat-attachments.js +139 -0
  172. package/src/server/chat.d.ts +31 -0
  173. package/src/server/chat.js +157 -0
  174. package/src/server/database-selectors.d.ts +6 -0
  175. package/src/server/database-selectors.js +13 -0
  176. package/src/server/gramlot-file-server.js +6 -1
  177. package/src/server/gramlot-server.d.ts +19 -3
  178. package/src/server/gramlot-server.js +144 -18
  179. package/src/server/index-page.d.ts +10 -0
  180. package/src/server/index-page.js +73 -8
  181. package/src/server/index.d.ts +1 -1
  182. package/src/server/index.js +1 -1
  183. package/src/server/page-base.js +4 -0
  184. package/src/server/page-store.d.ts +21 -0
  185. package/src/server/page-store.js +219 -0
  186. package/src/server/page.d.ts +6 -1
  187. package/src/server/page.js +5 -1
  188. package/src/server/store-recipe.js +102 -0
  189. package/src/server/toolbar-icon-name.d.ts +76 -0
  190. package/src/server/upload.d.ts +2 -0
  191. package/src/server/upload.js +36 -18
  192. package/src/server/visual-editor.js +4 -2
  193. package/src/tree-store.d.ts +5 -1
  194. package/src/tree-store.js +11 -2
  195. package/src/view/choice-focus.js +17 -0
  196. package/src/view/html.js +21 -1
  197. package/src/view/menu.js +9 -3
  198. package/src/visual-editor.js +6 -2
  199. package/themes/gramlot-base/theme.css +53 -28
  200. package/themes/gramlot-compact/theme.css +2 -0
  201. package/themes/gramlot-index/icons/applications.svg +4 -0
  202. package/themes/gramlot-index/icons/archive.svg +4 -0
  203. package/themes/gramlot-index/icons/attachment.svg +4 -0
  204. package/themes/gramlot-index/icons/book.svg +4 -0
  205. package/themes/gramlot-index/icons/bookmark.svg +4 -0
  206. package/themes/gramlot-index/icons/calendar.svg +4 -0
  207. package/themes/gramlot-index/icons/cancel.svg +4 -0
  208. package/themes/gramlot-index/icons/chart.svg +4 -0
  209. package/themes/gramlot-index/icons/chat.svg +4 -0
  210. package/themes/gramlot-index/icons/clock.svg +4 -0
  211. package/themes/gramlot-index/icons/code.svg +4 -0
  212. package/themes/gramlot-index/icons/collapse.svg +4 -0
  213. package/themes/gramlot-index/icons/columns.svg +4 -0
  214. package/themes/gramlot-index/icons/confirm.svg +4 -0
  215. package/themes/gramlot-index/icons/copy.svg +4 -0
  216. package/themes/gramlot-index/icons/cut.svg +4 -0
  217. package/themes/gramlot-index/icons/database.svg +4 -0
  218. package/themes/gramlot-index/icons/delete.svg +4 -0
  219. package/themes/gramlot-index/icons/detach.svg +4 -0
  220. package/themes/gramlot-index/icons/document.svg +4 -0
  221. package/themes/gramlot-index/icons/download.svg +4 -0
  222. package/themes/gramlot-index/icons/duplicate.svg +4 -0
  223. package/themes/gramlot-index/icons/edit.svg +4 -0
  224. package/themes/gramlot-index/icons/expand.svg +4 -0
  225. package/themes/gramlot-index/icons/export.svg +4 -0
  226. package/themes/gramlot-index/icons/eye.svg +4 -0
  227. package/themes/gramlot-index/icons/filter.svg +4 -0
  228. package/themes/gramlot-index/icons/first.svg +4 -0
  229. package/themes/gramlot-index/icons/folder.svg +4 -0
  230. package/themes/gramlot-index/icons/group.svg +4 -0
  231. package/themes/gramlot-index/icons/help.svg +4 -0
  232. package/themes/gramlot-index/icons/home.svg +4 -0
  233. package/themes/gramlot-index/icons/import.svg +4 -0
  234. package/themes/gramlot-index/icons/info.svg +4 -0
  235. package/themes/gramlot-index/icons/inspector.svg +4 -0
  236. package/themes/gramlot-index/icons/last.svg +4 -0
  237. package/themes/gramlot-index/icons/layers.svg +4 -0
  238. package/themes/gramlot-index/icons/link.svg +4 -0
  239. package/themes/gramlot-index/icons/list.svg +4 -0
  240. package/themes/gramlot-index/icons/lock.svg +4 -0
  241. package/themes/gramlot-index/icons/logout.svg +4 -0
  242. package/themes/gramlot-index/icons/navigation.svg +4 -0
  243. package/themes/gramlot-index/icons/new.svg +4 -0
  244. package/themes/gramlot-index/icons/next.svg +4 -0
  245. package/themes/gramlot-index/icons/open.svg +4 -0
  246. package/themes/gramlot-index/icons/palette.svg +4 -0
  247. package/themes/gramlot-index/icons/panel-bottom.svg +4 -0
  248. package/themes/gramlot-index/icons/panel-left.svg +4 -0
  249. package/themes/gramlot-index/icons/panel-right.svg +4 -0
  250. package/themes/gramlot-index/icons/panel-top.svg +4 -0
  251. package/themes/gramlot-index/icons/paste.svg +4 -0
  252. package/themes/gramlot-index/icons/pause.svg +4 -0
  253. package/themes/gramlot-index/icons/pin.svg +4 -0
  254. package/themes/gramlot-index/icons/play.svg +4 -0
  255. package/themes/gramlot-index/icons/previous.svg +4 -0
  256. package/themes/gramlot-index/icons/print.svg +4 -0
  257. package/themes/gramlot-index/icons/redo.svg +4 -0
  258. package/themes/gramlot-index/icons/refresh.svg +4 -0
  259. package/themes/gramlot-index/icons/save.svg +4 -0
  260. package/themes/gramlot-index/icons/search.svg +4 -0
  261. package/themes/gramlot-index/icons/send.svg +4 -0
  262. package/themes/gramlot-index/icons/settings.svg +4 -0
  263. package/themes/gramlot-index/icons/sort-ascending.svg +4 -0
  264. package/themes/gramlot-index/icons/sort-descending.svg +4 -0
  265. package/themes/gramlot-index/icons/stop.svg +4 -0
  266. package/themes/gramlot-index/icons/table.svg +4 -0
  267. package/themes/gramlot-index/icons/tree.svg +4 -0
  268. package/themes/gramlot-index/icons/undo.svg +4 -0
  269. package/themes/gramlot-index/icons/unlock.svg +4 -0
  270. package/themes/gramlot-index/icons/upload.svg +4 -0
  271. package/themes/gramlot-index/icons/user.svg +4 -0
  272. package/themes/gramlot-index/icons/warning.svg +4 -0
  273. package/themes/gramlot-index/icons/zoom-in.svg +4 -0
  274. package/themes/gramlot-index/icons/zoom-out.svg +4 -0
  275. package/themes/gramlot-index/icons.json +76 -0
  276. package/themes/gramlot-index/theme.css +21 -0
  277. package/themes/joanna/theme.css +2 -0
  278. package/themes/mela/theme.css +2 -0
  279. package/themes/mimi/theme.css +2 -0
@@ -1,8 +1,9 @@
1
+ import {renderIcon, projectIconAttributes} from '../icons.js';
1
2
  /** Shared selection keeps panel Source and light DOM mounted until explicit closing. */
2
3
  import {defineComponent} from './registry.js';
3
4
  import {Container} from './container.js';
5
+ import {createTabBar, outsideTabStrip, tabBarStyles} from './tab-bar.js';
4
6
  import {WindowSurface} from './window-surface.js';
5
- import {SVG_NS} from '../renderer/attributes.js';
6
7
 
7
8
  function SelectedContainer(HTMLElement) {
8
9
  // Named as its factory: inside the body `SelectedContainer` is this class, owner of the static state.
@@ -12,13 +13,13 @@ function SelectedContainer(HTMLElement) {
12
13
  static #selectionPanels = new WeakMap();
13
14
  static #panelSequence = 0;
14
15
  static projectChild(element, attrs, actions) {
15
- const {pageName = null, title = '', icon = '', badge = null, badge_color = '', closable = false, detachable = false, onClose, hidden = false, disabled = false, ...rest} = attrs;
16
+ const {pageName = null, title = '', icon = '', icon_size = null, icon_color = null, icon_opacity = null, badge = null, badge_color = '', closable = false, detachable = false, onClose, hidden = false, disabled = false, ...rest} = attrs;
16
17
  if (pageName !== null && typeof pageName !== 'string') throw new TypeError('pageName must be a string');
17
18
  if (typeof closable !== 'boolean') throw new TypeError('closable must be a boolean');
18
19
  if (typeof detachable !== 'boolean') throw new TypeError('detachable must be a boolean');
19
20
  const panels = SelectedContainer.#selectionPanels;
20
21
  const slot = panels.get(element)?.slot ?? `panel-${++SelectedContainer.#panelSequence}`;
21
- panels.set(element, {pageName, title, icon, badge, badge_color, closable, detachable, hidden, disabled, slot,
22
+ panels.set(element, {pageName, title, icon, icon_size, icon_color, icon_opacity, badge, badge_color, closable, detachable, hidden, disabled, slot,
22
23
  remove: actions.remove, allowClose: () => onClose == null ? true : actions.invoke('onClose', onClose, {})});
23
24
  rest.slot = slot;
24
25
  if (element.parentElement) element.parentElement.scheduleSelection();
@@ -215,12 +216,13 @@ export const TabContainer = defineComponent({
215
216
  name:'tabContainer', tag:'gramlot-tab-container', base:SelectedContainer, subTags:'*',
216
217
  sourceContext: true, childParameters: {...selectionChildParameters, title:{...selectionChildParameters.title, required:true}, detachable:{dtype:'B'}},
217
218
  parameters: {
218
- tabMode: {dtype:'T', default:'tabs', binding:'read', enum:['tabs','underline']},
219
+ tabMode: {dtype:'T', default:'tabs', binding:'read', enum:['tabs','underline','tabBar']},
219
220
  tabPosition: {dtype:'T', default:'top', binding:'read', enum:['top','bottom','left','right']},
220
221
  tabAlign: {dtype:'T', default:'start', binding:'read', enum:['start','center','end']},
221
222
  },
222
223
  implementation: Base => class extends Base {
223
224
  #tabs = new Map();
225
+ #tabBar;
224
226
  constructor() {
225
227
  super();
226
228
  const doc = this.ownerDocument;
@@ -251,17 +253,7 @@ export const TabContainer = defineComponent({
251
253
  @media(hover:hover){.tabs button:not(:disabled):hover{background:var(--gramlot-tab-hover-background,var(--gramlot-selected,#e8f1fc))}}
252
254
  .tabs button:disabled{opacity:.5;cursor:default}
253
255
  .tabs button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-3px}
254
- .panel:has(>.panel-tools:not([hidden])){display:flex;flex-direction:column;overflow:hidden}
255
- .panel:has(>.panel-tools:not([hidden]))>slot{display:block;flex:1;min-height:0;overflow:auto}
256
- .panel-tools{display:flex;flex:none;justify-content:flex-end;padding:2px 4px;
257
- background:var(--gramlot-surface-subtle,var(--gramlot-surface,#fff));border-bottom:1px solid var(--tab-border)}
258
- .detach{display:flex;align-items:center;justify-content:center;touch-action:none;cursor:grab;
259
- font:inherit;color:inherit;border:0;border-radius:var(--gramlot-radius-sm,4px);background:transparent;
260
- padding:var(--gramlot-group-action-padding,.2em .4em);min-width:var(--gramlot-touch-target,var(--gramlot-group-action-size,24px));min-height:var(--gramlot-touch-target,var(--gramlot-group-action-size,24px))}
261
- @media(hover:hover){.detach:hover{background:var(--gramlot-field-readonly-background,#ddd)}}
262
- .detach:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-2px}
263
- .detach svg{width:1.25em;height:1.25em;flex:none;pointer-events:none}
264
- .detach[data-dragging]{cursor:grabbing;background:var(--gramlot-selected,#e8f1fc)}
256
+ .tab-entry[data-detachable] [role=tab]{touch-action:none;user-select:none;cursor:grab}
265
257
  .close{align-self:center;flex:none;min-height:var(--gramlot-touch-target,20px);min-width:var(--gramlot-touch-target,20px);
266
258
  padding:0;margin-inline-end:3px;border-radius:var(--tab-radius);font-size:1.15em}
267
259
  [hidden]{display:none!important}
@@ -285,23 +277,59 @@ export const TabContainer = defineComponent({
285
277
  [data-mode=underline]:is([data-position=left],[data-position=right]) .tab-entry::after{height:auto;width:var(--gramlot-tab-indicator-size,2px);top:0;bottom:0}
286
278
  [data-mode=underline][data-position=left] .tab-entry::after{left:auto;right:0}
287
279
  [data-mode=underline][data-position=right] .tab-entry::after{left:0;right:auto}`;
280
+ style.textContent += tabBarStyles;
288
281
  this.shadowRoot.append(style);
289
282
  }
290
283
  projectAttributes(attrs, adapt) {
291
284
  const rest = super.projectAttributes(attrs, adapt);
292
285
  const {tabMode, tabPosition, tabAlign} = this.parameters;
293
- if (!['tabs','underline'].includes(tabMode)) throw new TypeError('Invalid tabMode');
286
+ if (!['tabs','underline','tabBar'].includes(tabMode)) throw new TypeError('Invalid tabMode');
294
287
  if (!['top','bottom','left','right'].includes(tabPosition)) throw new TypeError('Invalid tabPosition');
295
288
  if (!['start','center','end'].includes(tabAlign)) throw new TypeError('Invalid tabAlign');
296
289
  this.control.dataset.mode = tabMode; this.control.dataset.position = tabPosition;
297
290
  this.control.dataset.align = tabAlign;
298
- this.tabStrip.setAttribute('aria-orientation', ['left','right'].includes(tabPosition) ? 'vertical' : 'horizontal');
291
+ if (tabMode === 'tabBar' && !this.#tabBar) {
292
+ this.#tabBar = createTabBar(this.ownerDocument);
293
+ this.#tabBar.detachTab = (root, position) => {
294
+ for (const [record, entry] of this.#tabs) {
295
+ if (entry.root === root) { this.detachPanel(record, position); break; }
296
+ }
297
+ };
298
+ this.tabStrip.replaceWith(this.#tabBar);
299
+ this.#tabBar.append(this.tabStrip);
300
+ } else if (tabMode !== 'tabBar' && this.#tabBar) {
301
+ for (const entry of this.tabStrip.querySelectorAll('[data-overflow]')) entry.removeAttribute('data-overflow');
302
+ this.#tabBar.replaceWith(this.tabStrip);
303
+ this.#tabBar = null;
304
+ }
305
+ const orientation = ['left','right'].includes(tabPosition) ? 'vertical' : 'horizontal';
306
+ this.tabStrip.setAttribute('aria-orientation', orientation);
307
+ if (this.#tabBar) this.#tabBar.dataset.position = orientation;
299
308
  return rest;
300
309
  }
310
+ #focusAfterClose() {
311
+ const active = this.tabStrip.querySelector('[aria-selected=true]');
312
+ if (!active) return;
313
+ if (this.#tabBar?.hasAttribute('inert')) {
314
+ const panel = this.shadowRoot.getElementById(active.getAttribute('aria-controls'));
315
+ panel.tabIndex = -1;
316
+ panel.focus();
317
+ } else active.focus();
318
+ }
301
319
  renderTabs(records, selected) {
302
320
  for (const [record, entry] of this.#tabs) {
303
- if (!records.includes(record)) { entry.root.remove(); this.#tabs.delete(record); }
321
+ if (records.includes(record)) continue;
322
+ if (this.#tabBar && !entry.root.hidden && !entry.root.hasAttribute('data-overflow') && !this.#tabBar.hasAttribute('inert')) {
323
+ const spacer = this.ownerDocument.createElement('div');
324
+ spacer.className = 'tab-entry closing';
325
+ spacer.inert = true;
326
+ spacer.setAttribute('aria-hidden', 'true');
327
+ entry.root.replaceWith(spacer);
328
+ this.ownerDocument.defaultView.setTimeout(() => spacer.remove(), 200);
329
+ } else entry.root.remove();
330
+ this.#tabs.delete(record);
304
331
  }
332
+ let visibleCount = 0;
305
333
  for (const [index, record] of records.entries()) {
306
334
  let entry = this.#tabs.get(record);
307
335
  if (!entry) {
@@ -311,62 +339,83 @@ export const TabContainer = defineComponent({
311
339
  record.viewport.setAttribute('role', 'tabpanel');
312
340
  record.viewport.setAttribute('aria-labelledby', button.id);
313
341
  const icon = doc.createElement('span'), caption = doc.createElement('span'), badge = doc.createElement('span');
314
- icon.className = 'icon'; icon.setAttribute('aria-hidden', 'true'); caption.className = 'caption'; badge.className = 'badge';
342
+ icon.className = 'icon'; icon.setAttribute('iconslot', ''); icon.setAttribute('aria-hidden', 'true'); caption.className = 'caption'; badge.className = 'badge';
315
343
  button.append(icon, caption, badge);
316
344
  close.className = 'close'; close.textContent = '×';
317
- button.addEventListener('click', () => this.selectPanel(record));
345
+ let pointerId = null;
346
+ let suppressClick = false;
347
+ // tabBar owns its preview and reorder gesture. Plain strips only detach.
348
+ button.addEventListener('pointerdown', event => {
349
+ suppressClick = false;
350
+ if (this.#tabBar || !root.hasAttribute('data-detachable') || button.disabled ||
351
+ event.button !== 0 || !event.isPrimary) return;
352
+ pointerId = event.pointerId;
353
+ button.setPointerCapture(pointerId);
354
+ });
355
+ button.addEventListener('pointerup', event => {
356
+ if (event.pointerId !== pointerId) return;
357
+ pointerId = null;
358
+ const vertical = this.tabStrip.getAttribute('aria-orientation') === 'vertical';
359
+ if (!this.#tabBar && outsideTabStrip(this.tabStrip, vertical, event)) {
360
+ suppressClick = true;
361
+ this.detachPanel(record, {left:event.clientX-12, top:event.clientY-12});
362
+ }
363
+ });
364
+ for (const type of ['pointercancel','lostpointercapture']) {
365
+ button.addEventListener(type, event => {
366
+ if (event.pointerId === pointerId) pointerId = null;
367
+ });
368
+ }
369
+ button.addEventListener('click', event => {
370
+ if (!suppressClick || !event.detail) this.selectPanel(record);
371
+ suppressClick = false;
372
+ });
318
373
  close.addEventListener('click', () => {
319
374
  this.closePanel(record);
320
- if (!close.isConnected) this.tabStrip.querySelector('[aria-selected=true]')?.focus();
375
+ if (!close.isConnected) this.#focusAfterClose();
321
376
  });
322
377
  button.addEventListener('keydown', event => {
323
- if (event.key === 'Delete') { event.preventDefault(); this.closePanel(record); this.tabStrip.querySelector('[aria-selected=true]')?.focus(); return; }
378
+ if (event.key === 'Escape' && pointerId !== null) {
379
+ button.releasePointerCapture(pointerId);
380
+ pointerId = null;
381
+ return;
382
+ }
383
+ if (event.key === 'Enter' && event.shiftKey && root.hasAttribute('data-detachable')) {
384
+ event.preventDefault();
385
+ this.detachPanel(record);
386
+ return;
387
+ }
388
+ if (event.key === 'Delete') { event.preventDefault(); this.closePanel(record); this.#focusAfterClose(); return; }
324
389
  const vertical = ['left','right'].includes(this.parameters.tabPosition);
325
390
  const previous = vertical ? 'ArrowUp' : 'ArrowLeft', nextKey = vertical ? 'ArrowDown' : 'ArrowRight';
326
391
  if (![previous,nextKey,'Home','End'].includes(event.key)) return;
327
392
  event.preventDefault();
328
- const available = [...this.#tabs].filter(([r]) => !r.config.hidden && !r.config.disabled)
329
- .sort(([a], [b]) => a.index - b.index);
330
- let index = available.findIndex(([r]) => r === record);
393
+ const available = [...this.tabStrip.querySelectorAll('.tab-entry:not([hidden]):not([data-overflow]) [role=tab]:not(:disabled)')];
394
+ let index = available.indexOf(button);
331
395
  index = event.key === 'Home' ? 0 : event.key === 'End' ? available.length - 1
332
396
  : (index + (event.key === nextKey ? 1 : -1) + available.length) % available.length;
333
- const [next, tab] = available[index]; this.selectPanel(next); tab.button.focus();
334
- tab.button.scrollIntoView({block:'nearest',inline:'nearest'});
397
+ const next = available[index];
398
+ if (!this.#tabBar) next.click();
399
+ next.focus();
400
+ next.scrollIntoView({block:'nearest',inline:'nearest'});
335
401
  });
336
- const detach = doc.createElement('button'); detach.type = 'button'; detach.className = 'detach';
337
- const symbol = doc.createElementNS(SVG_NS, 'svg'); symbol.setAttribute('viewBox','0 0 20 20'); symbol.setAttribute('aria-hidden','true');
338
- const path = doc.createElementNS(SVG_NS, 'path'); path.setAttribute('d','M11 3h6v6M17 3l-8 8M8 4H4v12h12v-4');
339
- path.setAttribute('fill','none'); path.setAttribute('stroke','currentColor'); path.setAttribute('stroke-width','1.8');
340
- path.setAttribute('stroke-linecap','round'); path.setAttribute('stroke-linejoin','round'); symbol.append(path); detach.append(symbol);
341
- let gesture = null, dragged = false;
342
- detach.addEventListener('pointerdown', event => {
343
- if (event.button !== 0) return;
344
- gesture = {id:event.pointerId,x:event.clientX,y:event.clientY}; dragged = false;
345
- detach.setPointerCapture(event.pointerId); detach.setAttribute('data-dragging','');
346
- });
347
- detach.addEventListener('pointerup', event => {
348
- if (!gesture || gesture.id !== event.pointerId) return;
349
- const start = gesture; gesture = null; detach.removeAttribute('data-dragging');
350
- if (detach.hasPointerCapture(event.pointerId)) detach.releasePointerCapture(event.pointerId);
351
- dragged = Math.hypot(event.clientX-start.x,event.clientY-start.y) >= 8;
352
- if (dragged) this.detachPanel(record,{left:event.clientX-12,top:event.clientY-12});
353
- });
354
- for (const type of ['pointercancel','lostpointercapture']) detach.addEventListener(type, () => {
355
- gesture = null; detach.removeAttribute('data-dragging');
356
- });
357
- detach.addEventListener('click', () => {
358
- if (dragged) { dragged = false; return; }
359
- this.detachPanel(record);
360
- });
361
- const tools = doc.createElement('div'); tools.className = 'panel-tools'; tools.append(detach);
362
- record.viewport.prepend(tools);
363
- root.append(button, close); this.tabStrip.append(root); entry = {root,button,close,icon,caption,badge,detach,tools}; this.#tabs.set(record, entry);
402
+ root.append(button, close); this.tabStrip.append(root); entry = {root,button,close,icon,caption,badge}; this.#tabs.set(record, entry);
364
403
  }
365
- if (this.tabStrip.children[index] !== entry.root) this.tabStrip.insertBefore(entry.root, this.tabStrip.children[index] ?? null);
366
- entry.root.hidden = !!record.config.hidden;
404
+ if (!this.#tabBar && this.tabStrip.children[index] !== entry.root) this.tabStrip.insertBefore(entry.root, this.tabStrip.children[index] ?? null);
405
+ entry.root.hidden = !!record.config.hidden || !!(this.#tabBar && record.surface);
406
+ if (!entry.root.hidden) visibleCount++;
407
+ entry.root.toggleAttribute('data-detachable', record.config.detachable && !record.surface);
367
408
  const caption = record.config.title || record.config.pageName || String(record.index + 1);
368
- entry.caption.textContent = caption; entry.button.title = caption;
369
- entry.icon.textContent = record.config.icon;
409
+ entry.caption.textContent = caption;
410
+ if (entry.root.hasAttribute('data-detachable')) {
411
+ entry.button.title = `${caption} · Drag out or press Shift+Enter to detach`;
412
+ entry.button.setAttribute('aria-keyshortcuts', 'Shift+Enter');
413
+ } else {
414
+ entry.button.title = caption;
415
+ entry.button.removeAttribute('aria-keyshortcuts');
416
+ }
417
+ renderIcon(this, entry.icon, record.config.icon);
418
+ entry.icon.style.cssText = projectIconAttributes(record.config, {style:entry.icon.style.cssText}, this.ownerDocument).style;
370
419
  entry.badge.textContent = record.config.badge ?? '';
371
420
  entry.badge.hidden = record.config.badge == null || record.config.badge === '';
372
421
  entry.badge.style.backgroundColor = record.config.badge_color;
@@ -374,14 +423,11 @@ export const TabContainer = defineComponent({
374
423
  entry.button.disabled = !!record.config.disabled;
375
424
  entry.button.setAttribute('aria-selected', String(record === selected));
376
425
  entry.button.tabIndex = record === selected ? 0 : -1;
377
- entry.tools.hidden = !record.config.detachable || record !== selected || !!record.surface;
378
- entry.detach.disabled = !!record.config.disabled;
379
- entry.detach.setAttribute('aria-label', `Detach ${caption}`);
380
- entry.detach.title = `Drag or click to detach ${caption}`;
381
426
  entry.close.hidden = !record.config.closable;
382
427
  entry.close.disabled = !!record.config.disabled;
383
428
  entry.close.setAttribute('aria-label', `Close ${caption}`);
384
429
  }
430
+ this.#tabBar?.update(visibleCount, this.#tabs.get(selected)?.root);
385
431
  }
386
432
  },
387
433
  });
@@ -0,0 +1,371 @@
1
+ import {positionPopup} from './popup.js';
2
+
3
+ const minimumTabWidth = 80;
4
+
5
+ /** A sideways drop along a strip stays within the tab order. */
6
+ export function outsideTabStrip(strip, vertical, event) {
7
+ const bounds = strip.getBoundingClientRect();
8
+ return vertical ? Math.max(bounds.left-event.clientX, event.clientX-bounds.right) > 24
9
+ : Math.max(bounds.top-event.clientY, event.clientY-bounds.bottom) > 24;
10
+ }
11
+
12
+ /** Presentation for the existing TabContainer buttons. Panels never move during a drag. */
13
+ export function createTabBar(document) {
14
+ const window = document.defaultView;
15
+ if (!window.customElements.get('gramlot-tab-bar')) {
16
+ window.customElements.define('gramlot-tab-bar', TabBar(window.HTMLElement));
17
+ }
18
+ return document.createElement('gramlot-tab-bar');
19
+ }
20
+
21
+ function TabBar(HTMLElement) {
22
+ return class extends HTMLElement {
23
+ #observer;
24
+ #frame = null;
25
+ #slot;
26
+ #more;
27
+ #menu;
28
+ #selected;
29
+ #drag;
30
+ #suppressClick = false;
31
+ constructor() {
32
+ super();
33
+ const shadow = this.attachShadow({mode: 'open'});
34
+ const style = this.ownerDocument.createElement('style');
35
+ style.textContent = `
36
+ :host{display:var(--gramlot-tab-strip-display,grid);flex:none;min-width:0;min-height:0;
37
+ grid-template-rows:1fr;opacity:1;transition:grid-template-rows 200ms ease-out,opacity 200ms ease-out}
38
+ :host([inert]){grid-template-rows:0fr;opacity:0}
39
+ .clip{overflow:hidden;min-height:0;min-width:0}
40
+ .scroll{box-sizing:border-box;padding:4px 8px;overflow:auto;scrollbar-width:none;overscroll-behavior:contain}
41
+ :host([data-position=vertical]){grid-template-rows:1fr;grid-template-columns:1fr;
42
+ transition:grid-template-columns 200ms ease-out,opacity 200ms ease-out}
43
+ :host([data-position=vertical][inert]){grid-template-columns:0fr}
44
+ :host([data-position=vertical]) .scroll{height:100%}
45
+ :host([data-position=horizontal]) .scroll{display:flex;align-items:stretch;overflow:hidden}
46
+ :host([data-position=horizontal]) slot{display:block;min-width:0;flex:1;overflow:clip}
47
+ .more{flex:none;width:max(30px,var(--gramlot-touch-target,0px));min-height:max(24px,var(--gramlot-touch-target,0px));font:bold 17px system-ui;
48
+ color:inherit;background:transparent;border:0;border-radius:5px;cursor:pointer}
49
+ .more:hover,.more:focus-visible,[role=menuitem]:is(:hover,:focus-visible){background:var(--gramlot-selected,ButtonFace)}
50
+ [role=menu]{position:fixed;inset:auto;margin:0;padding:4px;box-sizing:border-box;
51
+ min-width:min(10rem,var(--gramlot-popup-available-width));max-width:var(--gramlot-popup-available-width);
52
+ max-height:var(--gramlot-popup-available-height);overflow:auto;border:1px solid var(--gramlot-border,#999);
53
+ border-radius:8px;background:var(--gramlot-surface,Canvas);color:var(--gramlot-ink,CanvasText);
54
+ box-shadow:0 3px 14px #0003}
55
+ [role=menuitem]{box-sizing:border-box;display:flex;align-items:center;gap:.75em;width:100%;padding:5px 8px;
56
+ min-height:var(--gramlot-touch-target,24px);border:0;border-radius:4px;background:transparent;color:inherit;
57
+ text-align:start;font:inherit;cursor:pointer}
58
+ .caption{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
59
+ .badge{border-radius:999px;padding:0 .4em;background:var(--gramlot-tab-badge-background,#3766b5);
60
+ color:var(--gramlot-tab-badge-color,white);font-size:.85em}
61
+ .drag-preview{position:fixed;inset:auto;left:0;top:0;margin:0;box-sizing:border-box;
62
+ padding:0 10px;pointer-events:none;user-select:none;border:1px solid var(--gramlot-border,#bbb);
63
+ border-radius:7px;background:var(--gramlot-surface,Canvas);color:var(--tabs-text,var(--gramlot-ink,CanvasText));
64
+ box-shadow:0 4px 12px #0003;font:12px system-ui;overflow:visible;will-change:transform}
65
+ .drag-preview:popover-open{display:flex;align-items:center;justify-content:center;gap:.4em}
66
+ .drag-preview .caption{flex:0 1 auto}
67
+ .drag-preview[data-detach]{outline:2px solid var(--gramlot-action,Highlight);box-shadow:0 7px 18px #0004}
68
+ .drag-preview[data-detach]::after{content:'↗';position:absolute;right:-6px;top:-7px;
69
+ border-radius:50%;padding:1px 4px;background:var(--gramlot-action,Highlight);color:var(--gramlot-surface,Canvas);font-weight:bold}
70
+ @media(prefers-reduced-motion:reduce){:host{transition:none!important}}`;
71
+ const clip = this.ownerDocument.createElement('div');
72
+ const scroll = this.ownerDocument.createElement('div');
73
+ clip.className = 'clip';
74
+ scroll.className = 'scroll';
75
+ this.#slot = this.ownerDocument.createElement('slot');
76
+ this.#more = this.ownerDocument.createElement('button');
77
+ this.#more.className = 'more';
78
+ this.#more.type = 'button';
79
+ this.#more.hidden = true;
80
+ this.#more.textContent = '»';
81
+ this.#more.title = 'More tabs';
82
+ this.#more.setAttribute('aria-label', 'More tabs');
83
+ this.#more.setAttribute('aria-haspopup', 'menu');
84
+ this.#more.setAttribute('aria-expanded', 'false');
85
+ this.#menu = this.ownerDocument.createElement('div');
86
+ this.#menu.id = 'more-tabs';
87
+ this.#menu.setAttribute('role','menu');
88
+ this.#menu.setAttribute('aria-label','More tabs');
89
+ this.#menu.setAttribute('popover','auto');
90
+ this.#more.popoverTargetElement = this.#menu;
91
+ this.#more.setAttribute('aria-controls', this.#menu.id);
92
+ this.#menu.addEventListener('beforetoggle', event => {
93
+ this.#more.setAttribute('aria-expanded', String(event.newState === 'open'));
94
+ if (event.newState === 'open') this.#refreshMenu();
95
+ });
96
+ this.#menu.addEventListener('toggle', () => {
97
+ if (!this.#menu.matches(':popover-open')) return;
98
+ positionPopup(this.#menu, this.#more, {align:'end'});
99
+ });
100
+ this.#more.addEventListener('keydown', event => {
101
+ if (event.key === 'ArrowDown') { event.preventDefault(); this.#more.click(); }
102
+ });
103
+ this.#menu.addEventListener('keydown', event => {
104
+ const items = [...this.#menu.querySelectorAll('button:not(:disabled)')];
105
+ const index = items.indexOf(event.target);
106
+ if (!items.length || !['Home','End','ArrowDown','ArrowUp'].includes(event.key)) return;
107
+ event.preventDefault();
108
+ const next = event.key === 'Home' ? 0 : event.key === 'End' ? items.length-1
109
+ : (index + (event.key === 'ArrowDown' ? 1 : -1) + items.length) % items.length;
110
+ items[next].focus();
111
+ });
112
+ scroll.append(this.#slot, this.#more);
113
+ clip.append(scroll);
114
+ shadow.append(style, clip, this.#menu);
115
+ const view = this.ownerDocument.defaultView;
116
+ this.#observer = new view.ResizeObserver(() => {
117
+ if (this.#frame !== null) return;
118
+ this.#frame = view.requestAnimationFrame(() => {
119
+ this.#frame = null;
120
+ this.#layout();
121
+ });
122
+ });
123
+ this.addEventListener('pointerdown', event => {
124
+ const button = event.target.closest('[role=tab]');
125
+ if (this.#drag || !button || button.disabled || event.button !== 0 || !event.isPrimary) return;
126
+ this.#suppressClick = false;
127
+ this.#drag = {entry:button.parentElement, strip:button.parentElement.parentElement, id:event.pointerId, x:event.clientX, y:event.clientY};
128
+ button.setPointerCapture(event.pointerId);
129
+ });
130
+ this.addEventListener('pointermove', event => {
131
+ const drag = this.#drag;
132
+ if (drag?.id !== event.pointerId) return;
133
+ if (!drag.preview) {
134
+ if (Math.hypot(event.clientX - drag.x, event.clientY - drag.y) < 4) return;
135
+ this.#suppressClick = true;
136
+ this.#lift(drag);
137
+ }
138
+ const drop = this.#dropPosition(event);
139
+ drag.preview.style.transform = 'translate(' + (event.clientX - drag.gripX) + 'px,' + (event.clientY - drag.gripY) + 'px)';
140
+ drag.preview.toggleAttribute('data-detach', drop.outside && drag.entry.hasAttribute('data-detachable'));
141
+ this.#showGap(drop);
142
+ });
143
+ this.addEventListener('pointerup', event => {
144
+ const drag = this.#drag;
145
+ if (drag?.id !== event.pointerId) return;
146
+ const drop = drag.preview && this.#dropPosition(event);
147
+ this.#endDrag();
148
+ if (!drop) return;
149
+ if (drop.outside) {
150
+ this.detachTab(drag.entry, {left:event.clientX-12, top:event.clientY-12});
151
+ return;
152
+ }
153
+ const strip = drag.entry.parentElement;
154
+ const focused = strip.getRootNode().activeElement;
155
+ strip.insertBefore(drag.entry, drop.before);
156
+ if (drag.entry.contains(focused)) focused.focus({preventScroll:true});
157
+ this.#layout();
158
+ });
159
+ for (const type of ['pointercancel','lostpointercapture']) {
160
+ this.addEventListener(type, event => {
161
+ if (this.#drag?.id === event.pointerId) this.#endDrag();
162
+ });
163
+ }
164
+ this.addEventListener('keydown', event => {
165
+ if (event.key === 'Escape' && this.#drag) {
166
+ event.preventDefault();
167
+ this.#endDrag();
168
+ }
169
+ });
170
+ this.addEventListener('click', event => {
171
+ if (event.detail && this.#suppressClick) {
172
+ event.stopPropagation();
173
+ this.#suppressClick = false;
174
+ }
175
+ }, true);
176
+ this.addEventListener('auxclick', event => {
177
+ const button = event.target.closest('[role=tab]');
178
+ if (event.button !== 1 || !button || button.disabled) return;
179
+ event.preventDefault();
180
+ const close = button.parentElement.querySelector('.close');
181
+ if (!close.hidden) close.click();
182
+ });
183
+ this.addEventListener('transitionend', () => this.#position());
184
+ }
185
+ #lift(drag) {
186
+ const rect = drag.entry.getBoundingClientRect();
187
+ drag.gripX = drag.x - rect.left;
188
+ drag.gripY = drag.y - rect.top;
189
+ const preview = this.ownerDocument.createElement('div');
190
+ preview.className = 'drag-preview';
191
+ preview.setAttribute('popover','manual');
192
+ preview.setAttribute('aria-hidden','true');
193
+ preview.inert = true;
194
+ preview.style.width = rect.width + 'px';
195
+ preview.style.height = rect.height + 'px';
196
+ for (const part of drag.entry.querySelector('[role=tab]').children) {
197
+ if (!part.hidden && part.textContent) preview.append(part.cloneNode(true));
198
+ }
199
+ this.shadowRoot.append(preview);
200
+ preview.showPopover();
201
+ drag.preview = preview;
202
+ drag.entry.setAttribute('data-dragging','');
203
+ }
204
+ #dropPosition(event) {
205
+ const entry = this.#drag.entry, strip = entry.parentElement;
206
+ const vertical = this.dataset.position === 'vertical';
207
+ const outside = outsideTabStrip(this, vertical, event);
208
+ const rect = strip.getBoundingClientRect();
209
+ const point = vertical ? event.clientY - rect.top : event.clientX - rect.left;
210
+ const tabs = [...strip.children].filter(tab => !tab.hidden && !tab.inert && !tab.hasAttribute('data-overflow'));
211
+ // Offsets describe the committed slots even while their contents slide into the proposed order.
212
+ const before = tabs.find(tab => tab !== entry && point < (vertical
213
+ ? tab.offsetTop + tab.offsetHeight / 2 : tab.offsetLeft + tab.offsetWidth / 2));
214
+ return {outside, vertical, tabs, before:before ?? tabs.at(-1)?.nextElementSibling ?? null};
215
+ }
216
+ #showGap({outside, vertical, tabs, before}) {
217
+ const {entry} = this.#drag;
218
+ const strip = entry.parentElement;
219
+ const from = tabs.indexOf(entry);
220
+ const others = tabs.filter(tab => tab !== entry);
221
+ const beforeIndex = others.indexOf(before);
222
+ const to = outside ? from : beforeIndex < 0 ? others.length : beforeIndex;
223
+ const size = vertical ? entry.offsetHeight : entry.offsetWidth;
224
+ tabs.forEach((tab, index) => {
225
+ let shift = 0;
226
+ if (index > from && index <= to) shift = -size;
227
+ if (index < from && index >= to) shift = size;
228
+ tab.style.translate = shift ? (vertical ? '0 ' + shift + 'px' : shift + 'px 0') : '';
229
+ if (tab === this.#selected) strip.style.setProperty('--capsule-shift', tab.style.translate || 'none');
230
+ });
231
+ }
232
+ #endDrag() {
233
+ const drag = this.#drag;
234
+ this.#drag = null;
235
+ if (!drag) return;
236
+ if (drag.preview) {
237
+ drag.preview.remove();
238
+ drag.entry.removeAttribute('data-dragging');
239
+ for (const tab of drag.strip.children) tab.style.removeProperty('translate');
240
+ drag.strip.style.removeProperty('--capsule-shift');
241
+ }
242
+ const button = drag.entry.querySelector('[role=tab]');
243
+ if (button.hasPointerCapture(drag.id)) button.releasePointerCapture(drag.id);
244
+ }
245
+ connectedCallback() {
246
+ this.#observer.observe(this);
247
+ if (this.#selected) this.#observer.observe(this.#selected);
248
+ }
249
+ disconnectedCallback() {
250
+ this.#observer.disconnect();
251
+ if (this.#frame !== null) this.ownerDocument.defaultView.cancelAnimationFrame(this.#frame);
252
+ this.#frame = null;
253
+ this.#endDrag();
254
+ }
255
+ update(count, selected) {
256
+ const collapsed = count === 0 || (count === 1 && !this.querySelector('.tab-entry[data-detachable]:not([hidden])'));
257
+ const reveal = this.hasAttribute('inert') && !collapsed;
258
+ this.toggleAttribute('inert', collapsed);
259
+ this.setAttribute('aria-hidden', String(collapsed));
260
+ const changed = selected !== this.#selected;
261
+ if (changed) {
262
+ if (this.#selected) this.#observer.unobserve(this.#selected);
263
+ this.#selected = selected;
264
+ if (selected) this.#observer.observe(selected);
265
+ }
266
+ this.#layout();
267
+ if (this.dataset.position === 'vertical' && selected && !collapsed && (changed || reveal)) {
268
+ const scroller = this.shadowRoot.querySelector('.scroll');
269
+ const target = selected.getBoundingClientRect(), bounds = scroller.getBoundingClientRect();
270
+ if (target.left < bounds.left) scroller.scrollLeft += target.left - bounds.left;
271
+ if (target.right > bounds.right) scroller.scrollLeft += target.right - bounds.right;
272
+ if (target.top < bounds.top) scroller.scrollTop += target.top - bounds.top;
273
+ if (target.bottom > bounds.bottom) scroller.scrollTop += target.bottom - bounds.bottom;
274
+ }
275
+ }
276
+ #refreshMenu() {
277
+ const focused = this.shadowRoot.activeElement?.dataset.tab;
278
+ const items = [...this.querySelectorAll('.tab-entry[data-overflow]:not([hidden]) [role=tab]')].map(tab => {
279
+ const item = this.ownerDocument.createElement('button');
280
+ item.type = 'button';
281
+ item.setAttribute('role','menuitem');
282
+ item.tabIndex = -1;
283
+ item.dataset.tab = tab.id;
284
+ item.disabled = tab.disabled;
285
+ item.append(tab.querySelector('.caption').cloneNode(true));
286
+ const badge = tab.querySelector('.badge');
287
+ if (!badge.hidden) item.append(badge.cloneNode(true));
288
+ item.addEventListener('click', () => {
289
+ this.#menu.hidePopover();
290
+ tab.click();
291
+ if (tab.offsetWidth) tab.focus();
292
+ else this.#more.focus();
293
+ });
294
+ return item;
295
+ });
296
+ const first = items.find(item => !item.disabled);
297
+ if (first) first.autofocus = true;
298
+ this.#menu.replaceChildren(...items);
299
+ if (focused) (items.find(item => item.dataset.tab === focused) ?? items.find(item => !item.disabled))?.focus();
300
+ }
301
+ #layout() {
302
+ const tabs = [...this.querySelectorAll('.tab-entry:not([hidden]):not(.closing)')];
303
+ const horizontal = this.dataset.position === 'horizontal';
304
+ const width = this.#slot.clientWidth + this.#more.offsetWidth;
305
+ const overflow = horizontal && width > 0 && tabs.length > 1 && tabs.length * minimumTabWidth > width;
306
+ this.#more.hidden = !overflow;
307
+ const capacity = overflow ? Math.max(0, Math.floor((width-this.#more.offsetWidth)/minimumTabWidth)) : tabs.length;
308
+ const visible = tabs.slice(0,capacity);
309
+ if (capacity && this.#selected && !visible.includes(this.#selected)) visible[capacity-1] = this.#selected;
310
+ for (const tab of tabs) tab.toggleAttribute('data-overflow', !visible.includes(tab));
311
+ if (this.#more.getAttribute('aria-expanded') === 'true') {
312
+ if (overflow) {
313
+ this.#refreshMenu();
314
+ positionPopup(this.#menu, this.#more, {align:'end'});
315
+ } else this.#menu.hidePopover();
316
+ }
317
+ if (this.#drag && (!visible.includes(this.#drag.entry) || this.inert || this.#drag.entry.querySelector('[role=tab]').disabled)) this.#endDrag();
318
+ this.#position();
319
+ }
320
+ #position() {
321
+ const tab = this.#selected;
322
+ if (!tab) return;
323
+ const style = tab.parentElement.style;
324
+ style.setProperty('--capsule-x', tab.offsetLeft + 'px');
325
+ style.setProperty('--capsule-y', tab.offsetTop + 'px');
326
+ style.setProperty('--capsule-width', tab.offsetWidth + 'px');
327
+ style.setProperty('--capsule-height', tab.offsetHeight + 'px');
328
+ }
329
+ };
330
+ }
331
+
332
+ /** Entries stay in the container's shadow tree alongside the panels they label. */
333
+ export const tabBarStyles = `
334
+ gramlot-tab-bar .tabs.tabs{position:relative;box-sizing:border-box;display:flex;align-items:stretch;
335
+ min-width:min-content;width:100%;padding:0;border:0;gap:0;overflow:visible;border-radius:8px;
336
+ background:var(--tabs-track,light-dark(rgb(0 0 0 / .06),rgb(255 255 255 / .08)))}
337
+ gramlot-tab-bar .tabs:has([aria-selected=true])::before{content:"";position:absolute;top:0;left:0;
338
+ pointer-events:none;border-radius:6px;width:var(--capsule-width);height:var(--capsule-height);
339
+ transform:translate(var(--capsule-x),var(--capsule-y));translate:var(--capsule-shift,none);transition:transform 180ms ease-out,translate 120ms ease-out;
340
+ background:var(--tabs-active,light-dark(white,rgb(255 255 255 / .18)));
341
+ box-shadow:0 0 0 .5px rgb(0 0 0 / .12),0 1px 2px rgb(0 0 0 / .12)}
342
+ gramlot-tab-bar .tabs .tab-entry{box-sizing:border-box;min-width:${minimumTabWidth}px;flex:1 1 0;overflow:hidden;
343
+ height:max(24px,var(--gramlot-touch-target,0px));border:0;border-radius:6px;
344
+ background:transparent;color:var(--tabs-text,var(--gramlot-ink,CanvasText));
345
+ transition:flex-grow 200ms ease-out,min-width 200ms ease-out}
346
+ gramlot-tab-bar .tabs:has([data-dragging]) .tab-entry{transition:translate 120ms ease-out}
347
+ gramlot-tab-bar .tab-entry[data-dragging]{opacity:.25}
348
+ gramlot-tab-bar .tabs:has([data-dragging] [aria-selected=true])::before{opacity:.25}
349
+ gramlot-tab-bar[data-position=horizontal] .tab-entry{max-width:200px;contain:inline-size}
350
+ gramlot-tab-bar .tab-entry[data-overflow]{display:none}
351
+ @starting-style{gramlot-tab-bar .tabs .tab-entry{flex-grow:0;min-width:0}}
352
+ gramlot-tab-bar .tabs .tab-entry button{padding:0 20px;min-height:0;font:12px system-ui}
353
+ gramlot-tab-bar .tabs .tab-entry [role=tab]{width:100%;color:inherit;justify-content:center;
354
+ touch-action:none;user-select:none;cursor:grab;opacity:.55}
355
+ gramlot-tab-bar .tabs .tab-entry[data-dragging] [role=tab]{cursor:grabbing}
356
+ gramlot-tab-bar .tabs .tab-entry [aria-selected=true]{opacity:1}
357
+ gramlot-tab-bar .tabs .tab-entry .close{position:absolute;inset-inline-start:0;top:0;height:100%;
358
+ margin:0;padding:0;width:20px;min-width:0;font:14px system-ui;opacity:0}
359
+ gramlot-tab-bar .tabs .tab-entry:is(:hover,:focus-within) .close{opacity:1}
360
+ @media(hover:hover){gramlot-tab-bar .tabs .tab-entry button:hover{background:transparent}
361
+ gramlot-tab-bar .tabs .tab-entry:hover:not(:has([aria-selected=true])){background:rgb(0 0 0 / .05)}}
362
+ @media(pointer:coarse){gramlot-tab-bar .tabs .tab-entry{height:max(44px,var(--gramlot-touch-target,0px))}
363
+ gramlot-tab-bar .tabs .tab-entry .close{opacity:1;width:36px}
364
+ gramlot-tab-bar .tabs .tab-entry [role=tab]{padding-inline:36px}}
365
+ gramlot-tab-bar[data-position=vertical] .tabs.tabs{height:100%;max-width:none;width:100%}
366
+ gramlot-tab-bar[data-position=vertical] .tabs .tab-entry{min-height:24px}
367
+ gramlot-tab-bar .tabs .closing{animation:tab-bar-close 200ms ease-out forwards;pointer-events:none}
368
+ @keyframes tab-bar-close{to{min-width:0;min-height:0;flex-grow:0}}
369
+ @media(prefers-reduced-motion:reduce){gramlot-tab-bar .tabs .closing{animation:none;display:none}
370
+ gramlot-tab-bar .tabs::before,gramlot-tab-bar .tabs .tab-entry{transition:none!important}}
371
+ `;