@gramlot/gramlot 0.3.41 → 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 (276) 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/grammar.json +6 -1
  83. package/dist/components/grid/__init__.py +1 -1
  84. package/dist/components/grid/assets/index.js +1 -1
  85. package/dist/components/grid/commands.json +4 -6
  86. package/dist/components/grid/grammar.json +51 -0
  87. package/dist/components/inputs/__init__.py +1 -1
  88. package/dist/components/inputs/assets/index.js +1 -1
  89. package/dist/components/inputs/grammar.json +4987 -216
  90. package/dist/components/layout/__init__.py +1 -1
  91. package/dist/components/layout/assets/index.js +1 -1
  92. package/dist/components/layout/grammar.json +69 -4
  93. package/dist/components/tree/__init__.py +1 -1
  94. package/dist/components/tree/assets/index.js +1 -1
  95. package/dist/components/tree/grammar.json +16 -0
  96. package/dist/components/typst/__init__.py +1 -1
  97. package/dist/components/typst/assets/collection.js +6 -6
  98. package/dist/components/typst/assets/index.js +1 -1
  99. package/dist/components/uploads/__init__.py +1 -1
  100. package/dist/components/uploads/assets/index.js +1 -1
  101. package/dist/components/uploads/grammar.json +66 -0
  102. package/dist/declared-collections.js +1 -1
  103. package/dist/gramlot.js +3961 -1249
  104. package/dist/gramlot.min.js +329 -131
  105. package/dist/libraries.json +1 -0
  106. package/dist/standard-collections.js +1 -1
  107. package/dist/standard-grammar.js +1 -1
  108. package/package.json +3 -1
  109. package/src/binding/ask-dialog.js +17 -3
  110. package/src/binding/providers.js +1 -1
  111. package/src/binding/runtime.js +6 -3
  112. package/src/builder/chart-icon.js +2 -0
  113. package/src/builder/gramlot-builder.d.ts +3 -1
  114. package/src/builder/gramlot-builder.js +26 -9
  115. package/src/builder/source.js +12 -3
  116. package/src/builder/xml-recipe.js +144 -0
  117. package/src/chat-file-types.js +13 -0
  118. package/src/chat.js +23 -25
  119. package/src/commands.d.ts +1 -1
  120. package/src/commands.js +1 -1
  121. package/src/components/border-container.js +64 -6
  122. package/src/components/buttons.js +26 -31
  123. package/src/components/chart-geographic-options.js +1 -1
  124. package/src/components/chart-pane.js +5 -5
  125. package/src/components/chart-spatial-options.js +5 -1
  126. package/src/components/check-box-text-editor.js +1 -0
  127. package/src/components/check-box-text.js +2 -0
  128. package/src/components/choice-editor.js +3 -2
  129. package/src/components/choice-field-styles.js +9 -1
  130. package/src/components/code-mirror-engine.js +18 -5
  131. package/src/components/code-mirror-gramlot.js +85 -0
  132. package/src/components/code-mirror.js +3 -2
  133. package/src/components/drawing.js +43 -14
  134. package/src/components/editor-options.js +1 -1
  135. package/src/components/graphical-ranges.js +177 -0
  136. package/src/components/grid-footer.js +6 -1
  137. package/src/components/grid-styles.js +11 -2
  138. package/src/components/grid-tools.js +15 -7
  139. package/src/components/grid.js +69 -8
  140. package/src/components/inputs.js +93 -23
  141. package/src/components/jodit-engine.js +3 -1
  142. package/src/components/menus.js +83 -25
  143. package/src/components/numeric-range.js +39 -0
  144. package/src/components/selected-container.js +109 -63
  145. package/src/components/tab-bar.js +371 -0
  146. package/src/components/toolbar-icon-style.js +22 -0
  147. package/src/components/toolbar-overflow.js +74 -12
  148. package/src/components/tree.js +12 -3
  149. package/src/components/typst-preview.js +3 -3
  150. package/src/components/upload-blocks.js +88 -0
  151. package/src/components/upload-engine.js +21 -31
  152. package/src/components/uploader.js +168 -47
  153. package/src/gramlot.js +6 -3
  154. package/src/handlers/dom-handler.d.ts +2 -0
  155. package/src/handlers/dom-handler.js +9 -0
  156. package/src/handlers/rpc-handler.d.ts +1 -1
  157. package/src/handlers/rpc-handler.js +2 -0
  158. package/src/handlers/source-handler.d.ts +5 -3
  159. package/src/handlers/source-handler.js +31 -13
  160. package/src/icons.js +84 -0
  161. package/src/index-page-runtime.js +9 -2
  162. package/src/index-page-styles.js +1 -1
  163. package/src/index-theme.js +210 -3
  164. package/src/index.d.ts +5 -1
  165. package/src/index.js +5 -1
  166. package/src/libraries.js +1 -1
  167. package/src/renderer/gramlot-renderer.js +4 -1
  168. package/src/server/chat-attachments.js +139 -0
  169. package/src/server/chat.d.ts +31 -0
  170. package/src/server/chat.js +157 -0
  171. package/src/server/database-selectors.d.ts +6 -0
  172. package/src/server/database-selectors.js +13 -0
  173. package/src/server/gramlot-file-server.js +6 -1
  174. package/src/server/gramlot-server.d.ts +19 -3
  175. package/src/server/gramlot-server.js +144 -18
  176. package/src/server/index-page.d.ts +10 -0
  177. package/src/server/index-page.js +73 -8
  178. package/src/server/index.d.ts +1 -1
  179. package/src/server/index.js +1 -1
  180. package/src/server/page-base.js +4 -0
  181. package/src/server/page-store.d.ts +21 -0
  182. package/src/server/page-store.js +219 -0
  183. package/src/server/page.d.ts +6 -1
  184. package/src/server/page.js +5 -1
  185. package/src/server/store-recipe.js +102 -0
  186. package/src/server/toolbar-icon-name.d.ts +76 -0
  187. package/src/server/upload.d.ts +2 -0
  188. package/src/server/upload.js +36 -18
  189. package/src/server/visual-editor.js +4 -2
  190. package/src/tree-store.d.ts +5 -1
  191. package/src/tree-store.js +11 -2
  192. package/src/view/choice-focus.js +17 -0
  193. package/src/view/html.js +21 -1
  194. package/src/view/menu.js +9 -3
  195. package/src/visual-editor.js +6 -2
  196. package/themes/gramlot-base/theme.css +53 -28
  197. package/themes/gramlot-compact/theme.css +2 -0
  198. package/themes/gramlot-index/icons/applications.svg +4 -0
  199. package/themes/gramlot-index/icons/archive.svg +4 -0
  200. package/themes/gramlot-index/icons/attachment.svg +4 -0
  201. package/themes/gramlot-index/icons/book.svg +4 -0
  202. package/themes/gramlot-index/icons/bookmark.svg +4 -0
  203. package/themes/gramlot-index/icons/calendar.svg +4 -0
  204. package/themes/gramlot-index/icons/cancel.svg +4 -0
  205. package/themes/gramlot-index/icons/chart.svg +4 -0
  206. package/themes/gramlot-index/icons/chat.svg +4 -0
  207. package/themes/gramlot-index/icons/clock.svg +4 -0
  208. package/themes/gramlot-index/icons/code.svg +4 -0
  209. package/themes/gramlot-index/icons/collapse.svg +4 -0
  210. package/themes/gramlot-index/icons/columns.svg +4 -0
  211. package/themes/gramlot-index/icons/confirm.svg +4 -0
  212. package/themes/gramlot-index/icons/copy.svg +4 -0
  213. package/themes/gramlot-index/icons/cut.svg +4 -0
  214. package/themes/gramlot-index/icons/database.svg +4 -0
  215. package/themes/gramlot-index/icons/delete.svg +4 -0
  216. package/themes/gramlot-index/icons/detach.svg +4 -0
  217. package/themes/gramlot-index/icons/document.svg +4 -0
  218. package/themes/gramlot-index/icons/download.svg +4 -0
  219. package/themes/gramlot-index/icons/duplicate.svg +4 -0
  220. package/themes/gramlot-index/icons/edit.svg +4 -0
  221. package/themes/gramlot-index/icons/expand.svg +4 -0
  222. package/themes/gramlot-index/icons/export.svg +4 -0
  223. package/themes/gramlot-index/icons/eye.svg +4 -0
  224. package/themes/gramlot-index/icons/filter.svg +4 -0
  225. package/themes/gramlot-index/icons/first.svg +4 -0
  226. package/themes/gramlot-index/icons/folder.svg +4 -0
  227. package/themes/gramlot-index/icons/group.svg +4 -0
  228. package/themes/gramlot-index/icons/help.svg +4 -0
  229. package/themes/gramlot-index/icons/home.svg +4 -0
  230. package/themes/gramlot-index/icons/import.svg +4 -0
  231. package/themes/gramlot-index/icons/info.svg +4 -0
  232. package/themes/gramlot-index/icons/inspector.svg +4 -0
  233. package/themes/gramlot-index/icons/last.svg +4 -0
  234. package/themes/gramlot-index/icons/layers.svg +4 -0
  235. package/themes/gramlot-index/icons/link.svg +4 -0
  236. package/themes/gramlot-index/icons/list.svg +4 -0
  237. package/themes/gramlot-index/icons/lock.svg +4 -0
  238. package/themes/gramlot-index/icons/logout.svg +4 -0
  239. package/themes/gramlot-index/icons/navigation.svg +4 -0
  240. package/themes/gramlot-index/icons/new.svg +4 -0
  241. package/themes/gramlot-index/icons/next.svg +4 -0
  242. package/themes/gramlot-index/icons/open.svg +4 -0
  243. package/themes/gramlot-index/icons/palette.svg +4 -0
  244. package/themes/gramlot-index/icons/panel-bottom.svg +4 -0
  245. package/themes/gramlot-index/icons/panel-left.svg +4 -0
  246. package/themes/gramlot-index/icons/panel-right.svg +4 -0
  247. package/themes/gramlot-index/icons/panel-top.svg +4 -0
  248. package/themes/gramlot-index/icons/paste.svg +4 -0
  249. package/themes/gramlot-index/icons/pause.svg +4 -0
  250. package/themes/gramlot-index/icons/pin.svg +4 -0
  251. package/themes/gramlot-index/icons/play.svg +4 -0
  252. package/themes/gramlot-index/icons/previous.svg +4 -0
  253. package/themes/gramlot-index/icons/print.svg +4 -0
  254. package/themes/gramlot-index/icons/redo.svg +4 -0
  255. package/themes/gramlot-index/icons/refresh.svg +4 -0
  256. package/themes/gramlot-index/icons/save.svg +4 -0
  257. package/themes/gramlot-index/icons/search.svg +4 -0
  258. package/themes/gramlot-index/icons/send.svg +4 -0
  259. package/themes/gramlot-index/icons/settings.svg +4 -0
  260. package/themes/gramlot-index/icons/sort-ascending.svg +4 -0
  261. package/themes/gramlot-index/icons/sort-descending.svg +4 -0
  262. package/themes/gramlot-index/icons/stop.svg +4 -0
  263. package/themes/gramlot-index/icons/table.svg +4 -0
  264. package/themes/gramlot-index/icons/tree.svg +4 -0
  265. package/themes/gramlot-index/icons/undo.svg +4 -0
  266. package/themes/gramlot-index/icons/unlock.svg +4 -0
  267. package/themes/gramlot-index/icons/upload.svg +4 -0
  268. package/themes/gramlot-index/icons/user.svg +4 -0
  269. package/themes/gramlot-index/icons/warning.svg +4 -0
  270. package/themes/gramlot-index/icons/zoom-in.svg +4 -0
  271. package/themes/gramlot-index/icons/zoom-out.svg +4 -0
  272. package/themes/gramlot-index/icons.json +76 -0
  273. package/themes/gramlot-index/theme.css +21 -0
  274. package/themes/joanna/theme.css +2 -0
  275. package/themes/mela/theme.css +2 -0
  276. package/themes/mimi/theme.css +2 -0
@@ -1,9 +1,17 @@
1
1
  /** Shared popup/permanent menu presentation. Source and execution stay in bindings. */
2
2
  import {labelboxContent, labelboxPresentation} from '../view/labelbox.js';
3
+ import {projectToolbarIconStyle} from './toolbar-icon-style.js';
3
4
  import {projectParameters} from './parameters.js';
4
5
  import {positionPopup} from './popup.js';
5
6
  import {ToolbarOverflow} from './toolbar-overflow.js';
6
7
 
8
+ // Keyboard navigation and presentation follow the visible bar. Command binding
9
+ // and Source ownership continue to follow the original menu hierarchy.
10
+ function containingMenu(element) {
11
+ const menu = element.parentElement?.closest('gramlot-menu');
12
+ return menu?.hasAttribute('data-menu-inline') ? menu.parentMenu : menu ?? null;
13
+ }
14
+
7
15
  export function MenuContainer(HTMLElement) {
8
16
  return class extends HTMLElement {
9
17
  #events; #observer; #active = null; #previous = []; #opener = null;
@@ -20,6 +28,10 @@ export function MenuContainer(HTMLElement) {
20
28
  :host([role=toolbar]){display:flex;gap:var(--gramlot-toolbar-gap,4px);align-items:center}
21
29
  :host([role=menu]) ::slotted([role=separator]){margin:5px 7px 5px 2.5rem;border-top:1px solid var(--gramlot-border-control,#888)}
22
30
  :host([role=toolbar][aria-orientation=horizontal]) ::slotted([role=separator]){border-top:0;border-left:1px solid var(--gramlot-border-control,#888);align-self:stretch;margin:4px}
31
+ :host([role=toolbar][aria-orientation=vertical]) ::slotted([role=separator]){border-left:0;border-top:1px solid var(--gramlot-border-control,#888);align-self:stretch;margin:4px}
32
+ :host([data-menu-inline]){display:inline-flex;position:static;inset:auto;align-items:center;gap:var(--gramlot-toolbar-gap,4px);margin:0;padding:0;border:0;box-shadow:none;background:transparent;width:max-content;max-width:none;max-height:none;overflow:visible}
33
+ :host([data-menu-inline=vertical]){flex-direction:column}
34
+ :host([data-menu-inline]) ::slotted(*){flex-shrink:0}
23
35
  :host([hidden]){display:none!important} slot{display:contents} .status{padding:.4em;opacity:.75}
24
36
  .status:empty{display:none} button{font:inherit}`;
25
37
  this.#slot = doc.createElement('slot');
@@ -36,12 +48,12 @@ export function MenuContainer(HTMLElement) {
36
48
  }
37
49
  get permanent() { return this.parameters.presentation === 'bar'; }
38
50
  get opened() { return this.permanent || this.#opened; }
39
- get items() { return [...this.querySelectorAll('gramlot-menu-line')].filter(item => item.menuOwner===this && !item.parameters.group); }
51
+ get items() { return [...this.querySelectorAll('gramlot-menu-line')].filter(item => item.menuOwner===this && !item.parameters.group && !item.hasAttribute('data-menu-expanded')); }
40
52
  get overflow() { return this.#overflow; }
41
53
  isOverflowed(item) { return this.#overflow.contains(item); }
42
54
  get visibleItems() { return this.items.filter(item => labelboxPresentation(item).slot!=='suppressed' && !item.hidden && !item.closest('[hidden]') && item.getAttribute('role') !== 'separator'); }
43
55
  get usableItems() { return this.visibleItems.filter(item => !item.disabled); }
44
- get parentMenu() { return this.parentElement?.closest('gramlot-menu') ?? null; }
56
+ get parentMenu() { return containingMenu(this); }
45
57
  connectedCallback() {
46
58
  this.#observer = new this.ownerDocument.defaultView.MutationObserver(() => {this.refreshItems();this.#overflow.schedule();});
47
59
  this.#observer.observe(this, {childList:true, subtree:true, characterData:true, attributes:true, attributeFilter:['hidden','disabled']});
@@ -54,7 +66,7 @@ export function MenuContainer(HTMLElement) {
54
66
  projectAttributes(attrs) {
55
67
  const rest = projectParameters(this, attrs);
56
68
  this.#modifierKeys();
57
- if(!Number.isFinite(this.parameters.iconSize)||this.parameters.iconSize<=0)throw new TypeError('menu iconSize must be positive');
69
+ if(!Number.isFinite(this.parameters.icon_size)||this.parameters.icon_size<=0)throw new TypeError('menu icon_size must be positive');
58
70
  this.setAttribute('role', this.permanent ? 'toolbar' : 'menu');
59
71
  this.setAttribute('aria-orientation', this.permanent ? this.parameters.orientation : 'vertical');
60
72
  this.tabIndex = -1;
@@ -62,7 +74,7 @@ export function MenuContainer(HTMLElement) {
62
74
  else this.setAttribute('popover','manual');
63
75
  this.refreshItems();
64
76
  this.#overflow.schedule();
65
- return rest;
77
+ return projectToolbarIconStyle(this, rest);
66
78
  }
67
79
  #modifierKeys() {
68
80
  const value=this.parameters.modifiers;
@@ -112,6 +124,7 @@ export function MenuContainer(HTMLElement) {
112
124
  this.refreshItems();
113
125
  }
114
126
  refreshItems() {
127
+ if (this.hasAttribute('data-menu-inline')) return;
115
128
  for(const group of this.querySelectorAll('gramlot-menu-line'))if(group.menuOwner===this && group.parameters.group)group.refreshAvailability();
116
129
  for(const item of this.items)item.refreshAvailability();
117
130
  const usable = this.usableItems;
@@ -126,7 +139,7 @@ export function MenuContainer(HTMLElement) {
126
139
  const next = this.#previous.slice(index+1).find(item => usable.includes(item))
127
140
  ?? this.#previous.slice(0,index).reverse().find(item => usable.includes(item));
128
141
  this.#active = next ?? null;
129
- if (this.opened && this.status !== 'loading') {
142
+ if (this.opened && this.contains(this.ownerDocument.activeElement) && this.status !== 'loading') {
130
143
  if (next) next.focus();
131
144
  else if (this.permanent) this.focus(); else this.close();
132
145
  }
@@ -159,7 +172,8 @@ export function MenuContainer(HTMLElement) {
159
172
  focusEntry(last = false) {
160
173
  const usable = this.usableItems;
161
174
  const target = usable[last ? usable.length-1 : 0];
162
- if (target) { this.#active=target; target.focus(); } else this.focus();
175
+ if (target) { this.#active=target; target.focus(); }
176
+ else (this.querySelector('[autofocus]') ?? this).focus();
163
177
  }
164
178
  close(restore = true) {
165
179
  for (const child of this.querySelectorAll('gramlot-menu')) if (!child.permanent) child.close(false);
@@ -177,10 +191,10 @@ export function MenuContainer(HTMLElement) {
177
191
  else if (restore && this.#opener?.isConnected) this.#opener.focus();
178
192
  }
179
193
  #key(event) {
180
- if (event.defaultPrevented || event.composedPath().find(node => node.localName === 'gramlot-menu') !== this) return;
194
+ if (event.defaultPrevented || event.composedPath().find(node => node.localName === 'gramlot-menu' && !node.hasAttribute('data-menu-inline')) !== this) return;
181
195
  const item = event.composedPath().find(node => this.items.includes(node));
182
196
  // Embedded editors retain their editing and Tab behavior.
183
- if (!item && event.target !== this) return;
197
+ if (!item && event.target !== this && (event.key !== 'Escape' || this.permanent)) return;
184
198
  const inOverflow=item && this.isOverflowed(item);
185
199
  const items=this.usableItems.filter(entry=>this.isOverflowed(entry)===Boolean(inOverflow)), index=items.indexOf(item);
186
200
  const nextKey=this.permanent && !inOverflow && this.parameters.orientation==='horizontal' ? 'ArrowRight':'ArrowDown';
@@ -230,21 +244,33 @@ export function menuLine(Base) {
230
244
  background:transparent;cursor:pointer;line-height:1.2;white-space:nowrap}
231
245
  :host button.toolbar-button .icon{display:inline-flex;align-items:center;justify-content:center;
232
246
  width:var(--gramlot-toolbar-icon-size);height:var(--gramlot-toolbar-icon-size);font-size:var(--gramlot-toolbar-icon-size);line-height:1}
233
- #control.toolbar-button.icon-only{--gramlot-button-icon-size:var(--gramlot-toolbar-icon-size)}
247
+ #control.toolbar-button.icon-only{--gramlot-button-icon-size:var(--gramlot-toolbar-icon-size);border:0;background:transparent}
248
+ :host(:not([data-menu-group-rows])) #control.toolbar-button.icon-only{
249
+ min-height:max(calc(var(--gramlot-toolbar-icon-size) + 8px),var(--gramlot-touch-target,0px));padding-block:3px}
250
+ #control.toolbar-button.icon-only:hover:not(:disabled){background:color-mix(in srgb,currentColor 17%,transparent)}
251
+ #control.toolbar-button.icon-only:is([aria-checked=true],[aria-expanded=true]){background:var(--gramlot-selected,Highlight)}
252
+ @media(forced-colors:active){#control.toolbar-button.icon-only{background:ButtonFace;border:1px solid ButtonText}#control.toolbar-button.icon-only[aria-checked=true]{background:Highlight;color:HighlightText}}
253
+ :host button.toolbar-button:not([aria-checked=true]):not([aria-expanded=true]) .icon img{color-scheme:var(--gramlot-toolbar-icon-scheme,inherit)}
254
+ .icon{position:relative;color:var(--gramlot-toolbar-icon-color,inherit)}
255
+ .menu-caption{opacity:var(--gramlot-icon-opacity,1)}
256
+ .icon[data-badge]::after{content:attr(data-badge);position:absolute;inset-block-start:-.3em;inset-inline-end:-.6em;
257
+ min-width:1.3em;padding:0 .22em;box-sizing:border-box;border-radius:1em;text-align:center;font:600 10px/1.3 system-ui;
258
+ background:var(--gramlot-icon-badge-background,var(--gramlot-tab-badge-background,var(--gramlot-brand-blue,#3766b5)));color:var(--gramlot-tab-badge-color,white);pointer-events:none}
234
259
  :host button.toolbar-button .icon:empty{display:none}
235
260
  :host button.toolbar-button:hover:not(:disabled){background:color-mix(in srgb,currentColor 10%,transparent)}
236
- :host button.toolbar-button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-2px}
261
+ :host button.toolbar-button:focus-visible{outline:1px solid var(--gramlot-focus-ring,Highlight);outline-offset:-1px}
237
262
  :host button.toolbar-button[aria-checked=true],:host button.toolbar-button[aria-expanded=true]{background:var(--gramlot-selected,color-mix(in srgb,currentColor 14%,transparent))}
238
263
  :host button.toolbar-button:disabled{opacity:.45;cursor:default}
239
264
  :host button.toolbar-below{flex-direction:column;gap:3px;min-width:54px}
240
265
  :host button.toolbar-below .menu-caption{font-size:11px;line-height:1.2}
241
266
  :host button.toolbar-tooltip .menu-caption{display:none}
242
267
  :host button.toolbar-button .menu-check{display:none}
243
- :host button.toolbar-tooltip .menu-arrow{position:static;flex:0 0 8px;margin-inline-start:2px;font-size:12px;line-height:1}
244
- :host button.toolbar-below .menu-arrow{position:absolute;inset:4px 3px auto auto;font-size:12px}`;
268
+ :host button.toolbar-button .icon > .menu-arrow{position:absolute;right:0;bottom:1px;
269
+ width:0;height:0;border-inline:4px solid transparent;border-top:5px solid currentColor;
270
+ filter:drop-shadow(0 0 1px var(--gramlot-field-background,Canvas));font-size:0;pointer-events:none}`;
245
271
  style.textContent+=`
246
272
  :host([role=group]){display:block;min-width:0}
247
- :host([role=group]) .control-box{display:none}
273
+ :host([role=group]) .control-box,:host([role=separator]) .control-box,:host([data-menu-expanded]) .control-box{display:none}
248
274
  .menu-group{display:flex;align-items:center;gap:var(--gramlot-toolbar-gap,4px);flex-wrap:nowrap}
249
275
  .menu-group ::slotted(*){flex-shrink:0}
250
276
  .menu-group[hidden]{display:none}
@@ -270,11 +296,10 @@ export function menuLine(Base) {
270
296
  });
271
297
  this.addEventListener('pointerleave',()=>clearTimeout(this.#hover));
272
298
  }
273
- get menuOwner() { return this.parentElement?.closest('gramlot-menu') ?? null; }
299
+ get menuOwner() { return containingMenu(this); }
274
300
  get submenu() { return [...this.children].map(labelboxContent).find(child=>child?.localName==='gramlot-menu') ?? null; }
275
301
  get entryCaption() { return this.parameters.caption ?? this.#registry?.label ?? ''; }
276
- get entryIcon() { return this.parameters.icon || this.parameters.iconSrc ? this.parameters.icon : this.#registry?.icon; }
277
- get entryIconSrc() { return this.parameters.icon || this.parameters.iconSrc ? this.parameters.iconSrc : this.#registry?.iconSrc; }
302
+ get entryIcon() { return this.parameters.icon || this.#registry?.icon; }
278
303
  get occurrence() { return this.parameters.code ?? this.sourceLabel; }
279
304
  setCommandDefinition(definition, sourceLabel) {
280
305
  this.#registry=definition; this.sourceLabel=sourceLabel; this.#render();
@@ -282,14 +307,18 @@ export function menuLine(Base) {
282
307
  projectAttributes(attrs,adapt) {
283
308
  const rest=super.projectAttributes(attrs,adapt);
284
309
  this.#accessibleLabel=attrs['aria-label'];
285
- if(this.parameters.iconSize!=null&&(!Number.isFinite(this.parameters.iconSize)||this.parameters.iconSize<=0))throw new TypeError('menuline iconSize must be positive');
310
+ if(this.parameters.icon_size!=null&&(!Number.isFinite(this.parameters.icon_size)||this.parameters.icon_size<=0))throw new TypeError('menuline icon_size must be positive');
311
+ if (this.parameters.expandInBar != null && !Number.isFinite(this.parameters.expandInBar)) throw new TypeError('menuline expandInBar must be finite');
286
312
  this.#authoredDisabled=Boolean(this.parameters.disabled);
287
- this.#render(); this.menuOwner?.refreshItems(); this.menuOwner?.overflow.schedule(); return rest;
313
+ this.#render(); this.menuOwner?.refreshItems(); const owner = this.menuOwner;
314
+ owner?.overflow.schedule();
315
+ if (owner && !owner.permanent) owner.parentMenu?.overflow.schedule();
316
+ return projectToolbarIconStyle(this, rest);
288
317
  }
289
318
  #render() {
290
319
  const separator=[...this.childNodes].filter(node=>node.nodeType===3)
291
320
  .map(node=>node.textContent).join('').trim()==='-' && !this.parameters.command;
292
- this.setAttribute('role',this.parameters.group?'group':separator?'separator':this.parameters.checked==null?'menuitem':'menuitemcheckbox');
321
+ this.setAttribute('role',this.hasAttribute('data-menu-expanded')?'presentation':this.parameters.group?'group':separator?'separator':this.parameters.checked==null?'menuitem':'menuitemcheckbox');
293
322
  this.#group.hidden=!this.parameters.group;
294
323
  this.setAttribute('aria-disabled',String(this.#authoredDisabled));
295
324
  if (this.parameters.checked!=null) {
@@ -299,10 +328,14 @@ export function menuLine(Base) {
299
328
  this.#check.textContent=this.parameters.checked ? '✓':'';
300
329
  this.#caption.textContent=this.parameters.command && !this.#registry ? '???':this.entryCaption;
301
330
  this.caption.hidden=true;
302
- this.renderIcon(this.entryIcon, this.entryIconSrc);
331
+ this.renderIcon(this.entryIcon);
332
+ const badge = this.parameters.badge;
333
+ if (badge == null || badge === '') this.icon.removeAttribute('data-badge');
334
+ else this.icon.dataset.badge = String(badge);
335
+ this.icon.style.setProperty('--gramlot-icon-badge-background', this.parameters.badge_color ?? '');
303
336
  const tooltip=this.parameters.tooltip ?? this.#registry?.tooltip ?? this.entryCaption;
304
- this.control.title=tooltip;
305
- this.control.setAttribute('aria-label',this.#accessibleLabel ?? (this.entryCaption || tooltip));
337
+ const label = this.#accessibleLabel ?? (this.entryCaption || tooltip);
338
+ this.control.setAttribute('aria-label', this.icon.hasAttribute('data-badge') ? label + ' ' + badge : label);
306
339
  if (this.submenu) this.control.setAttribute('aria-haspopup','menu');
307
340
  else this.control.removeAttribute('aria-haspopup');
308
341
  this.refreshAvailability();
@@ -316,18 +349,26 @@ export function menuLine(Base) {
316
349
  }
317
350
  return owner?.parameters[name];
318
351
  };
352
+ const tooltipOwner = this.closest('gramlot-menu')?.closest('gramlot-menu[role=toolbar]');
353
+ const showTooltip = owner?.parameters.showTooltip ?? tooltipOwner?.parameters.showTooltip ?? true;
354
+ this.control.title = showTooltip ? (this.parameters.tooltip ?? this.#registry?.tooltip ?? this.entryCaption) : '';
319
355
  const toolbar=Boolean(owner?.permanent && !popup);
320
356
  const labelPosition=inherited('labelPosition');
321
- this.control.classList.toggle('toolbar-button',toolbar);
357
+ const standardButton = toolbar && this.classList.contains('button--standard');
358
+ this.control.classList.toggle('standard-button', standardButton);
359
+ this.control.classList.toggle('toolbar-button',toolbar && !standardButton);
322
360
  this.control.classList.toggle('toolbar-below',toolbar && labelPosition==='below');
323
361
  this.control.classList.toggle('toolbar-tooltip',toolbar && labelPosition==='tooltip');
324
- if(toolbar)this.control.style.setProperty('--gramlot-toolbar-icon-size',`${inherited('iconSize')}px`);
362
+ if(toolbar)this.control.style.setProperty('--gramlot-toolbar-icon-size',`${inherited('icon_size')}px`);
325
363
  else this.control.style.removeProperty('--gramlot-toolbar-icon-size');
326
364
  this.toggleAttribute('data-menu-group-rows',Boolean(popup || owner?.parameters.orientation==='vertical'));
327
365
  this.control.classList.toggle('menu-row', popup);
328
- this.#arrow.textContent = this.submenu ? (toolbar && labelPosition==='tooltip' ? '⌄' : popup || owner?.parameters.orientation==='vertical' ? '›' : '▾') : '';
366
+ this.#arrow.textContent = this.submenu ? (popup ? '›' : '▾') : '';
367
+ const arrowParent = toolbar && this.submenu && (this.entryIcon || this.entryIconSrc) ? this.icon : this.control;
368
+ if (this.#arrow.parentNode !== arrowParent) arrowParent.append(this.#arrow);
329
369
  const disabled=this.#authoredDisabled || this.getAttribute('role')==='separator'
330
370
  || Boolean(this.parameters.command && !this.#registry)
371
+ || Boolean(this.parentElement?.closest('gramlot-menu-line[data-menu-expanded]')?.disabled)
331
372
  || ['loading','error'].includes(owner?.status)
332
373
  || Boolean(this.closest('gramlot-drop-down-button')?.parameters.disabled);
333
374
  if(this.control.disabled!==disabled)this.control.disabled=disabled;
@@ -336,6 +377,23 @@ export function menuLine(Base) {
336
377
  get disabled() {
337
378
  for(let p=this.parentElement;p && p!==this.menuOwner;p=p.parentElement)if(p.localName==='gramlot-menu-line' && p.parameters.disabled)return true;
338
379
  return this.control.disabled || Boolean(this.closest('gramlot-drop-down-button')?.parameters.disabled); }
380
+ showInBar(expanded, orientation) {
381
+ const submenu = this.submenu;
382
+ this.toggleAttribute('data-menu-expanded', expanded);
383
+ if (expanded) {
384
+ submenu.setAttribute('data-menu-inline', orientation);
385
+ this.setAttribute('role', 'presentation');
386
+ submenu.setAttribute('role', 'group');
387
+ } else {
388
+ submenu?.removeAttribute('data-menu-inline');
389
+ submenu?.setAttribute('role', 'menu');
390
+ this.setAttribute('role', this.parameters.checked == null ? 'menuitem' : 'menuitemcheckbox');
391
+ }
392
+ const owner = expanded ? this.menuOwner : submenu;
393
+ for (const child of submenu?.querySelectorAll('gramlot-menu-line') ?? []) {
394
+ if (child.menuOwner === owner) child.refreshAvailability();
395
+ }
396
+ }
339
397
  set disabled(value) { this.control.disabled=Boolean(value); }
340
398
  attachCommand() { this.#render(); }
341
399
  releaseCommand() { clearTimeout(this.#hover); this.submenu?.close(false); }
@@ -0,0 +1,39 @@
1
+ export const numericRangeParameters = {
2
+ value: {dtype: 'R', default: 0, binding: 'twoWay'},
3
+ min: {dtype: 'R', default: 0, binding: 'read', target: 'control'},
4
+ max: {dtype: 'R', default: 100, binding: 'read', target: 'control'},
5
+ step: {dtype: 'R', default: 1, binding: 'read', target: 'control'}
6
+ };
7
+
8
+ // The native range owns step rounding, clamping and keyboard interaction.
9
+ export function numericRange(Base) {
10
+ return class extends Base {
11
+ #sourceContext;
12
+ #correcting = false;
13
+
14
+ setSourceContext(context) { this.#sourceContext = context; }
15
+ createControl() {
16
+ const control = this.ownerDocument.createElement('input');
17
+ control.type = 'range';
18
+ return control;
19
+ }
20
+ readControlValue() { return this.control.valueAsNumber; }
21
+ writeControlValue(value) {
22
+ this.control.value = String(value);
23
+ const corrected = this.control.valueAsNumber;
24
+ if (!this.#correcting && Number.isFinite(value) && corrected !== value) {
25
+ this.#correcting = true;
26
+ try { this.#sourceContext.writeParameter('value', corrected); }
27
+ finally { this.#correcting = false; }
28
+ }
29
+ }
30
+ projectAttributes(attrs, adapt) {
31
+ const previous = this.parameters;
32
+ const rest = super.projectAttributes(attrs, adapt);
33
+ if (previous && ['min', 'max', 'step'].some(name => previous[name] !== this.parameters[name])) {
34
+ this.writeControlValue(this.parameters.value);
35
+ }
36
+ return rest;
37
+ }
38
+ };
39
+ }
@@ -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
  });