@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
@@ -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
+ `;
@@ -0,0 +1,22 @@
1
+ /** The toolbar, frame and individual occurrence share the same inherited icon paint. */
2
+ export const toolbarIconParameters = {
3
+ icon_color: {dtype:'T', nullable:true, binding:'read'},
4
+ icon_opacity: {dtype:'R', nullable:true, binding:'read'},
5
+ };
6
+
7
+ export function projectToolbarIconStyle(element, rest) {
8
+ const {icon_color, icon_opacity} = element.parameters;
9
+ if (icon_color == null && icon_opacity == null) return rest;
10
+ const style = element.ownerDocument.createElement('span').style;
11
+ style.cssText = rest.style ?? '';
12
+ if (icon_color) {
13
+ style.setProperty('--gramlot-toolbar-icon-color', icon_color);
14
+ style.setProperty('--gramlot-toolbar-original-icon', 'hidden');
15
+ }
16
+ if (icon_opacity != null) {
17
+ if (!Number.isFinite(icon_opacity) || icon_opacity < 0 || icon_opacity > 1)
18
+ throw new RangeError('icon_opacity must be between 0 and 1');
19
+ style.setProperty('--gramlot-toolbar-icon-opacity', String(icon_opacity));
20
+ }
21
+ return {...rest, style:style.cssText};
22
+ }
@@ -40,11 +40,12 @@ export class ToolbarOverflow {
40
40
  :host([role=toolbar]){min-width:0;min-height:0;max-width:100%;width:100%;flex-shrink:1;gap:0}
41
41
  :host([role=toolbar][aria-orientation=vertical]){width:auto;height:100%;max-height:100%}
42
42
  .toolbar-viewport{display:contents}
43
- :host([role=toolbar]) .toolbar-viewport{display:flex;align-items:center;gap:var(--gramlot-toolbar-gap,4px);flex:1 1 0%;min-width:0;min-height:0;overflow-x:auto;overflow-y:hidden}
44
- :host([role=toolbar][aria-orientation=vertical]) .toolbar-viewport{flex-direction:column;align-items:stretch;overflow-x:hidden;overflow-y:auto;width:100%}
43
+ :host([role=toolbar]) .toolbar-viewport{display:flex;align-items:center;gap:var(--gramlot-toolbar-gap,4px);flex:1 1 0%;min-width:0;min-height:0;overflow:clip}
44
+ :host([role=toolbar][aria-orientation=vertical]) .toolbar-viewport{flex-direction:column;align-items:stretch;overflow:clip;width:100%}
45
45
  :host([role=toolbar]) ::slotted(*){flex-shrink:0}
46
46
  :host([role=toolbar]) .toolbar-viewport[data-measuring]{flex:none;width:max-content;height:max-content;overflow:visible}
47
47
  .toolbar-more{flex:0 0 auto;width:max(var(--gramlot-field-height,32px),var(--gramlot-touch-target,0px));height:max(var(--gramlot-field-height,32px),var(--gramlot-touch-target,0px));padding:0;border:0;border-radius:4px;background:transparent;color:inherit;font:inherit;display:grid;place-items:center}
48
+ :host([aria-orientation=horizontal]) .toolbar-more{height:max(calc(var(--gramlot-toolbar-icon-size) + 8px),var(--gramlot-touch-target,0px))}
48
49
  .toolbar-more svg{display:block;width:18px;height:18px;pointer-events:none}
49
50
  .toolbar-more:hover,.toolbar-more:focus-visible{background:var(--gramlot-selected,Highlight)}
50
51
  :host([role=toolbar][aria-orientation=vertical]) .toolbar-more{width:100%}
@@ -76,8 +77,13 @@ export class ToolbarOverflow {
76
77
  disconnect(){
77
78
  this.close(false); this.#resize?.disconnect();this.#resize=null;this.#events?.abort();
78
79
  if(this.#frame!==null)this.#menu.ownerDocument.defaultView.cancelAnimationFrame(this.#frame);
80
+ for (const unit of this.#units) this.#resetInline(unit);
79
81
  this.#frame=null;this.#units=[];
80
82
  }
83
+ #resetInline(unit) {
84
+ const line = labelboxContent(unit);
85
+ if (line.hasAttribute('data-menu-expanded')) line.showInBar(false);
86
+ }
81
87
  schedule(){
82
88
  if(!this.#menu.isConnected)return;
83
89
  if(!this.#menu.permanent){
@@ -93,14 +99,22 @@ export class ToolbarOverflow {
93
99
  const menu=this.#menu,win=menu.ownerDocument.defaultView;
94
100
  if(!menu.permanent || !menu.isConnected)return;
95
101
  const vertical=menu.parameters.orientation==='vertical',axis=vertical?'height':'width';
102
+ this.#button.style.setProperty('--gramlot-toolbar-icon-size', menu.parameters.icon_size + 'px');
96
103
  const style=win.getComputedStyle(menu);
97
- const available=(vertical?menu.clientHeight:menu.clientWidth)-parseFloat(style[vertical?'paddingTop':'paddingLeft']||0)-parseFloat(style[vertical?'paddingBottom':'paddingRight']||0);
104
+ // clientWidth rounds fractional CSS pixels. Use the content box to avoid
105
+ // fitting an extra command at fractional zoom or with a toolbar border.
106
+ const edges = vertical ? ['Top','Bottom'] : ['Left','Right'];
107
+ const outer = menu.getBoundingClientRect()[axis];
108
+ const available = outer > 0
109
+ ? outer - edges.reduce((sum, edge) => sum + parseFloat(style['padding' + edge] || 0)
110
+ + parseFloat(style['border' + edge + 'Width'] || 0), 0)
111
+ : (vertical ? menu.clientHeight : menu.clientWidth) - edges.reduce((sum, edge) => sum + parseFloat(style['padding' + edge] || 0), 0);
98
112
  if(available<=0)return;
99
113
  let active=menu.ownerDocument.activeElement;
100
114
  while(active?.shadowRoot?.activeElement)active=active.shadowRoot.activeElement;
101
115
  const units=[...menu.children].filter(unit=>!unit.hidden && (labelboxContent(unit).localName!=='gramlot-menu' || labelboxContent(unit).permanent));
102
116
  for(const unit of this.#units)if(!units.includes(unit)){
103
- this.#resize.unobserve(unit);unit.removeAttribute('slot');unit.removeAttribute('data-menu-overflow');
117
+ this.#resetInline(unit);this.#resize.unobserve(unit);unit.removeAttribute('slot');unit.removeAttribute('data-menu-overflow');
104
118
  }
105
119
  for(const unit of units)if(!this.#units.includes(unit))this.#resize.observe(unit);
106
120
  this.#units=units;
@@ -108,18 +122,28 @@ export class ToolbarOverflow {
108
122
  // slots synchronously before paint. No clones or Source changes are made.
109
123
  for(const unit of units){unit.removeAttribute('slot');unit.removeAttribute('data-menu-overflow');}
110
124
  this.#overflow.clear();
111
- menu.refreshItems();
112
- for(const item of menu.items)item.refreshAvailability();
125
+ const candidates = [];
126
+ for (const unit of units) {
127
+ const line = labelboxContent(unit);
128
+ this.#resetInline(unit);
129
+ if (line.parameters?.expandInBar != null && line.submenu && !line.submenu.permanent &&
130
+ !line.submenu.hidden && line.submenu.visibleItems.length && !['error','loading'].includes(line.submenu.status)) {
131
+ candidates.push(unit);
132
+ }
133
+ }
134
+ for (const line of menu.querySelectorAll('gramlot-menu-line')) {
135
+ if (line.menuOwner === menu) line.refreshAvailability();
136
+ }
113
137
  // Auto margins distribute spare space; they are not intrinsic content.
114
138
  // Measure synchronously without flex allocation, then restore before paint.
115
139
  this.#viewport.setAttribute('data-measuring','');
116
140
  const gap=parseFloat(win.getComputedStyle(this.#viewport).gap)||0;
117
- const lengths=new Map(units.map(unit=>{
141
+ const measure = unit => {
118
142
  const css=win.getComputedStyle(unit);
119
143
  const length=labelboxContent(unit).localName==='gramlot-spacer'?(labelboxContent(unit).parameters.size??0):unit.getBoundingClientRect()[axis];
120
- return [unit,length+(parseFloat(css[vertical?'marginTop':'marginLeft'])||0)+(parseFloat(css[vertical?'marginBottom':'marginRight'])||0)];
121
- }));
122
- this.#viewport.removeAttribute('data-measuring');
144
+ return length+(parseFloat(css[vertical?'marginTop':'marginLeft'])||0)+(parseFloat(css[vertical?'marginBottom':'marginRight'])||0);
145
+ };
146
+ const lengths = new Map(units.map(unit => [unit, measure(unit)]));
123
147
  const separator=unit=>labelboxContent(unit).getAttribute('role')==='separator';
124
148
  const tidy=list=>list.filter((unit,index)=>!separator(unit) ||
125
149
  list.slice(0,index).some(item=>labelboxContent(item).localName!=='gramlot-spacer'&&!separator(item)) &&
@@ -127,9 +151,36 @@ export class ToolbarOverflow {
127
151
  !separator(list.slice(index+1).find(item=>labelboxContent(item).localName!=='gramlot-spacer')));
128
152
  const required=remaining=>remaining.reduce((sum,unit)=>sum+lengths.get(unit),0)+Math.max(0,remaining.length-1)*gap;
129
153
  let remaining=tidy(units);
154
+ // Measure both presentations at their intrinsic sizes with the original controls.
155
+ const compact = new Map();
156
+ for (const unit of candidates) {
157
+ const line = labelboxContent(unit);
158
+ compact.set(unit, lengths.get(unit));
159
+ line.showInBar(true, menu.parameters.orientation);
160
+ lengths.set(unit, Math.max(measure(unit), line.submenu.getBoundingClientRect()[axis]));
161
+ }
162
+ // Stable sort after reversal makes the later submenu close first on a tie.
163
+ candidates.reverse().sort((a,b) => labelboxContent(a).parameters.expandInBar - labelboxContent(b).parameters.expandInBar);
164
+ for (const unit of candidates) {
165
+ if (required(remaining) <= available) break;
166
+ labelboxContent(unit).showInBar(false);
167
+ lengths.set(unit, compact.get(unit));
168
+ }
169
+ this.#viewport.removeAttribute('data-measuring');
170
+ for (const unit of candidates) {
171
+ const line = labelboxContent(unit);
172
+ if (line.hasAttribute('data-menu-expanded')) {
173
+ if (line.submenu.opened) line.submenu.close(false);
174
+ } else {
175
+ line.submenu.refreshItems();
176
+ if (!line.submenu.opened) line.submenu.close(false);
177
+ }
178
+ }
130
179
  if(required(remaining)>available){
180
+ this.#button.hidden = false;
181
+ const capacity = available - this.#button.getBoundingClientRect()[axis];
131
182
  let cut=units.length;
132
- while(cut>0 && required(remaining)>available-32) {
183
+ while(cut>0 && required(remaining)>capacity) {
133
184
  cut--;
134
185
  remaining=tidy(units.slice(0,cut));
135
186
  }
@@ -149,7 +200,18 @@ export class ToolbarOverflow {
149
200
  if(this.#overflow.size===0)this.close(false);
150
201
  else if(activeUnit && this.#overflow.has(activeUnit))this.open(false);
151
202
  else if(this.#opened)this.#place();
152
- if(activeUnit && active?.isConnected)active.focus({preventScroll:true});
203
+ if (activeUnit && active?.isConnected) {
204
+ const line = labelboxContent(activeUnit);
205
+ let target = active;
206
+ if (line.submenu && line.parameters.expandInBar != null) {
207
+ if (line.hasAttribute('data-menu-expanded') && active === line.control) {
208
+ target = menu.usableItems.find(item => line.contains(item))?.control ?? menu;
209
+ } else if (!line.hasAttribute('data-menu-expanded') && !line.submenu.opened) {
210
+ target = line.control;
211
+ }
212
+ }
213
+ target.focus({preventScroll:true});
214
+ }
153
215
  menu.refreshItems();
154
216
  }
155
217
  #place(){positionPopup(this.#panel,this.#button,{placement:this.#menu.parameters.orientation==='vertical'?'side':'bottom'});}
@@ -1,3 +1,4 @@
1
+ import {iconSource} from '../icons.js';
1
2
  /** Bag hierarchy, lazy branch expansion, captions and path selection. */
2
3
  import {Bag} from '@genrojs/bag';
3
4
  import createDOMPurify from 'dompurify';
@@ -64,6 +65,7 @@ export const Tree = defineComponent({
64
65
  getLabel: {dtype: 'T', nullable: true, default: null},
65
66
  labelState: {dtype: 'X', nullable: true, default: null, binding: 'read'},
66
67
  getLabelClass: {dtype: 'T', nullable: true, default: null},
68
+ icon: {dtype:'T', default:'', binding:'read'},
67
69
  getIconClass: {dtype: 'T', nullable: true, default: null},
68
70
  selectedLabelClass: {dtype: 'T', default: '', binding: 'read'},
69
71
  searchText: {dtype: 'T', default: '', binding: 'read'},
@@ -148,7 +150,7 @@ export const Tree = defineComponent({
148
150
  height:16px;padding:0 3px;border-radius:3px;font-size:10px;line-height:1;
149
151
  background:var(--gramlot-tree-badge-background,#e7eaf0);color:var(--gramlot-tree-badge-color,#394452)}
150
152
  .badge[data-colored]{color:var(--gramlot-tree-colored-badge-color,white)}
151
- .icon{width:16px;height:16px;flex:none;background:currentColor;opacity:.7;mask:center/contain no-repeat;
153
+ .icon{width:var(--gramlot-icon-size,16px);height:var(--gramlot-icon-size,16px);flex:none;background:var(--gramlot-icon-color,currentColor);opacity:var(--gramlot-icon-opacity,.7);mask:center/contain no-repeat;
152
154
  mask-image:url("data:image/svg+xml,%3Csvg xmlns='${SVG_NS}' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='black' stroke-width='1.7' d='M5 3h9l5 5v13H5zM14 3v6h5M8 13h8M8 17h8'/%3E%3C/svg%3E")}
153
155
  .branch-icon{mask-image:url("data:image/svg+xml,%3Csvg xmlns='${SVG_NS}' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='black' stroke-width='1.7' d='M3 7V4h7l3 3h8v13H3z'/%3E%3C/svg%3E")}
154
156
  .opened-icon{mask-image:url("data:image/svg+xml,%3Csvg xmlns='${SVG_NS}' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='black' stroke-width='1.7' d='M3 19V4h7l3 3h8v3M3 20l3-9h16l-3 9z'/%3E%3C/svg%3E")}
@@ -360,6 +362,7 @@ export const Tree = defineComponent({
360
362
  const scalar = children === null && !this.parameters.hideValues && (node.resolver === null || !node.resolver.expired);
361
363
  const branch = children !== null ? children.length > 0
362
364
  : scalar || (node.resolver !== null && this.parameters.resolveLazy && node.attr.child_count !== 0);
365
+ const section = branch && node.attr.section === true;
363
366
  const entry = this.ownerDocument.createElement('li');
364
367
  entry.className = `node ${branch ? 'branch' : 'leaf'}`;
365
368
  entry.setAttribute('part', `node ${branch ? 'branch' : 'leaf'}`);
@@ -401,6 +404,7 @@ export const Tree = defineComponent({
401
404
  caption.setAttribute('part', 'caption');
402
405
  const icon = this.ownerDocument.createElement('span');
403
406
  icon.className = `icon ${branch ? 'branch-icon' : 'leaf-icon'}`;
407
+ icon.setAttribute('iconslot', 'row');
404
408
  icon.setAttribute('aria-hidden', 'true');
405
409
  icon.setAttribute('part', `icon ${branch ? 'branch-icon' : 'leaf-icon'}`);
406
410
 
@@ -419,7 +423,10 @@ export const Tree = defineComponent({
419
423
  this.#toggleCheck(path);
420
424
  });
421
425
  }
422
- row.append(expander, check || icon, badge, caption); entry.append(row);
426
+ row.append(expander);
427
+ if (check) row.append(check);
428
+ else if (!section) row.append(icon);
429
+ row.append(badge, caption); entry.append(row);
423
430
  const group = branch ? (children ? build(children, path, entry) : this.ownerDocument.createElement('ul')) : null;
424
431
  if (group) { group.className = 'group'; group.setAttribute('role', 'group'); group.setAttribute('part', 'group'); }
425
432
  if (group) entry.append(group);
@@ -486,7 +493,9 @@ export const Tree = defineComponent({
486
493
  : [branch ? 'branch-icon' : 'leaf-icon', ...(branch ? [opened ? 'opened-icon' : 'closed-icon'] : [])];
487
494
  icon.className = ['icon', ...iconClasses].join(' ');
488
495
  icon.setAttribute('part', ['icon', ...iconClasses].join(' '));
489
- icon.hidden = customIcon && iconClasses.length === 0;
496
+ const asset = iconSource(this, node.attr.icon ?? this.parameters.icon);
497
+ icon.style.maskImage = asset ? 'url(' + JSON.stringify(asset) + ')' : '';
498
+ icon.hidden = !asset && customIcon && iconClasses.length === 0;
490
499
  if (check) {
491
500
  const value = checks.get(path);
492
501
  check.checked = value === true || value === 'disabled:on';
@@ -16,9 +16,9 @@ function PreviewElement(HTMLElement){
16
16
  const style=doc.createElement('style');
17
17
  style.textContent=`:host{display:block;height:100%;min-height:0;color:var(--gramlot-ink,CanvasText)}
18
18
  .preview{display:flex;flex-direction:column;height:100%;background:var(--gramlot-surface-subtle,Canvas)}
19
- .tools{display:flex;gap:16px;align-items:center;padding:8px 12px;font:inherit}
20
- a{color:var(--gramlot-brand-blue,LinkText);border-radius:var(--gramlot-radius-sm,4px);padding:4px 8px;text-decoration:none;white-space:nowrap}
21
- a:hover{background:var(--gramlot-selected-background,Highlight)}
19
+ .tools{display:flex;gap:16px;align-items:center;padding:8px 12px;font:inherit;background:var(--gramlot-surface,Canvas)}
20
+ a{color:var(--gramlot-action,LinkText);border-radius:var(--gramlot-radius-sm,4px);padding:4px 8px;text-decoration:underline;white-space:nowrap}
21
+ a[href]:hover{color:var(--gramlot-action-hover,LinkText);background:var(--gramlot-selected,Canvas)}
22
22
  a:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight)}
23
23
  a[aria-disabled=true]{opacity:.45;pointer-events:none}
24
24
  .status{white-space:pre-wrap;font-size:.9em;overflow:auto;max-height:8em}