@gramlot/gramlot 0.3.40 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/assets/icons/applications.svg +4 -0
  2. package/assets/icons/archive.svg +4 -0
  3. package/assets/icons/attachment.svg +4 -0
  4. package/assets/icons/book.svg +4 -0
  5. package/assets/icons/bookmark.svg +4 -0
  6. package/assets/icons/calendar.svg +4 -0
  7. package/assets/icons/cancel.svg +4 -0
  8. package/assets/icons/chart.svg +4 -1
  9. package/assets/icons/chat.svg +4 -0
  10. package/assets/icons/clock.svg +4 -0
  11. package/assets/icons/code.svg +4 -0
  12. package/assets/icons/collapse.svg +4 -0
  13. package/assets/icons/columns.svg +4 -0
  14. package/assets/icons/confirm.svg +4 -0
  15. package/assets/icons/copy.svg +4 -0
  16. package/assets/icons/cut.svg +4 -0
  17. package/assets/icons/database.svg +4 -0
  18. package/assets/icons/delete.svg +4 -0
  19. package/assets/icons/detach.svg +4 -0
  20. package/assets/icons/document.svg +4 -0
  21. package/assets/icons/download.svg +4 -0
  22. package/assets/icons/duplicate.svg +4 -0
  23. package/assets/icons/edit.svg +4 -0
  24. package/assets/icons/expand.svg +4 -0
  25. package/assets/icons/export.svg +4 -0
  26. package/assets/icons/eye.svg +4 -0
  27. package/assets/icons/filter.svg +4 -0
  28. package/assets/icons/first.svg +4 -0
  29. package/assets/icons/folder.svg +4 -0
  30. package/assets/icons/group.svg +4 -0
  31. package/assets/icons/help.svg +4 -0
  32. package/assets/icons/home.svg +4 -0
  33. package/assets/icons/import.svg +4 -0
  34. package/assets/icons/info.svg +4 -0
  35. package/assets/icons/inspector.svg +4 -0
  36. package/assets/icons/last.svg +4 -0
  37. package/assets/icons/layers.svg +4 -0
  38. package/assets/icons/link.svg +4 -0
  39. package/assets/icons/list.svg +4 -0
  40. package/assets/icons/lock.svg +4 -0
  41. package/assets/icons/logout.svg +4 -0
  42. package/assets/icons/navigation.svg +4 -0
  43. package/assets/icons/new.svg +4 -0
  44. package/assets/icons/next.svg +4 -0
  45. package/assets/icons/open.svg +4 -0
  46. package/assets/icons/palette.svg +4 -0
  47. package/assets/icons/panel-bottom.svg +4 -0
  48. package/assets/icons/panel-left.svg +4 -0
  49. package/assets/icons/panel-right.svg +4 -0
  50. package/assets/icons/panel-top.svg +4 -0
  51. package/assets/icons/paste.svg +4 -0
  52. package/assets/icons/pause.svg +4 -0
  53. package/assets/icons/pin.svg +4 -0
  54. package/assets/icons/play.svg +4 -0
  55. package/assets/icons/previous.svg +4 -0
  56. package/assets/icons/print.svg +4 -0
  57. package/assets/icons/redo.svg +4 -0
  58. package/assets/icons/refresh.svg +4 -0
  59. package/assets/icons/save.svg +4 -0
  60. package/assets/icons/search.svg +4 -0
  61. package/assets/icons/send.svg +4 -0
  62. package/assets/icons/settings.svg +4 -0
  63. package/assets/icons/sort-ascending.svg +4 -0
  64. package/assets/icons/sort-descending.svg +4 -0
  65. package/assets/icons/stop.svg +4 -0
  66. package/assets/icons/table.svg +4 -0
  67. package/assets/icons/tree.svg +4 -0
  68. package/assets/icons/undo.svg +4 -0
  69. package/assets/icons/unlock.svg +4 -0
  70. package/assets/icons/upload.svg +4 -0
  71. package/assets/icons/user.svg +4 -0
  72. package/assets/icons/warning.svg +4 -0
  73. package/assets/icons/zoom-in.svg +4 -0
  74. package/assets/icons/zoom-out.svg +4 -0
  75. package/dist/components/charts/__init__.py +1 -1
  76. package/dist/components/charts/assets/index.js +1 -1
  77. package/dist/components/charts/assets/libraries/vega.js +11 -11
  78. package/dist/components/editors/__init__.py +1 -1
  79. package/dist/components/editors/assets/index.js +1 -1
  80. package/dist/components/editors/assets/libraries/codemirror.js +30 -31
  81. package/dist/components/editors/assets/libraries/jodit.js +3 -1
  82. package/dist/components/editors/assets/libraries/prosemirror.js +1 -1
  83. package/dist/components/editors/grammar.json +6 -1
  84. package/dist/components/grid/__init__.py +1 -1
  85. package/dist/components/grid/assets/index.js +1 -1
  86. package/dist/components/grid/commands.json +4 -6
  87. package/dist/components/grid/grammar.json +51 -0
  88. package/dist/components/inputs/__init__.py +1 -1
  89. package/dist/components/inputs/assets/index.js +1 -1
  90. package/dist/components/inputs/grammar.json +4987 -216
  91. package/dist/components/layout/__init__.py +1 -1
  92. package/dist/components/layout/assets/index.js +1 -1
  93. package/dist/components/layout/grammar.json +69 -4
  94. package/dist/components/tree/__init__.py +1 -1
  95. package/dist/components/tree/assets/index.js +1 -1
  96. package/dist/components/tree/grammar.json +16 -0
  97. package/dist/components/typst/__init__.py +1 -1
  98. package/dist/components/typst/assets/collection.js +6 -6
  99. package/dist/components/typst/assets/index.js +1 -1
  100. package/dist/components/uploads/__init__.py +1 -1
  101. package/dist/components/uploads/assets/index.js +1 -1
  102. package/dist/components/uploads/grammar.json +66 -0
  103. package/dist/declared-collections.js +1 -1
  104. package/dist/gramlot.js +4007 -1256
  105. package/dist/gramlot.min.js +329 -131
  106. package/dist/libraries.json +1 -0
  107. package/dist/standard-collections.js +1 -1
  108. package/dist/standard-grammar.js +1 -1
  109. package/package.json +3 -1
  110. package/src/binding/ask-dialog.js +17 -3
  111. package/src/binding/data-binder.js +5 -0
  112. package/src/binding/providers.js +1 -1
  113. package/src/binding/runtime.js +6 -3
  114. package/src/builder/chart-icon.js +2 -0
  115. package/src/builder/gramlot-builder.d.ts +3 -1
  116. package/src/builder/gramlot-builder.js +26 -9
  117. package/src/builder/source.js +12 -3
  118. package/src/builder/xml-recipe.js +144 -0
  119. package/src/chat-file-types.js +13 -0
  120. package/src/chat.js +23 -25
  121. package/src/commands.d.ts +1 -1
  122. package/src/commands.js +1 -1
  123. package/src/components/border-container.js +64 -6
  124. package/src/components/buttons.js +26 -31
  125. package/src/components/chart-geographic-options.js +1 -1
  126. package/src/components/chart-pane.js +5 -5
  127. package/src/components/chart-spatial-options.js +5 -1
  128. package/src/components/check-box-text-editor.js +1 -0
  129. package/src/components/check-box-text.js +2 -0
  130. package/src/components/choice-editor.js +3 -2
  131. package/src/components/choice-field-styles.js +9 -1
  132. package/src/components/code-mirror-engine.js +18 -5
  133. package/src/components/code-mirror-gramlot.js +85 -0
  134. package/src/components/code-mirror.js +3 -2
  135. package/src/components/drawing.js +43 -14
  136. package/src/components/editor-options.js +1 -1
  137. package/src/components/graphical-ranges.js +177 -0
  138. package/src/components/grid-footer.js +6 -1
  139. package/src/components/grid-styles.js +11 -2
  140. package/src/components/grid-tools.js +15 -7
  141. package/src/components/grid.js +69 -8
  142. package/src/components/inputs.js +93 -23
  143. package/src/components/jodit-engine.js +3 -1
  144. package/src/components/menus.js +83 -25
  145. package/src/components/numeric-range.js +39 -0
  146. package/src/components/selected-container.js +109 -63
  147. package/src/components/tab-bar.js +371 -0
  148. package/src/components/toolbar-icon-style.js +22 -0
  149. package/src/components/toolbar-overflow.js +74 -12
  150. package/src/components/tree.js +12 -3
  151. package/src/components/typst-preview.js +3 -3
  152. package/src/components/upload-blocks.js +88 -0
  153. package/src/components/upload-engine.js +21 -31
  154. package/src/components/uploader.js +168 -47
  155. package/src/gramlot.js +6 -3
  156. package/src/handlers/dom-handler.d.ts +2 -0
  157. package/src/handlers/dom-handler.js +9 -0
  158. package/src/handlers/rpc-handler.d.ts +1 -1
  159. package/src/handlers/rpc-handler.js +2 -0
  160. package/src/handlers/source-handler.d.ts +5 -3
  161. package/src/handlers/source-handler.js +31 -13
  162. package/src/icons.js +84 -0
  163. package/src/index-page-runtime.js +9 -2
  164. package/src/index-page-styles.js +1 -1
  165. package/src/index-theme.js +210 -3
  166. package/src/index.d.ts +5 -1
  167. package/src/index.js +5 -1
  168. package/src/libraries.js +1 -1
  169. package/src/page-store-connection.js +44 -7
  170. package/src/renderer/gramlot-renderer.js +4 -1
  171. package/src/server/chat-attachments.js +139 -0
  172. package/src/server/chat.d.ts +31 -0
  173. package/src/server/chat.js +157 -0
  174. package/src/server/database-selectors.d.ts +6 -0
  175. package/src/server/database-selectors.js +13 -0
  176. package/src/server/gramlot-file-server.js +6 -1
  177. package/src/server/gramlot-server.d.ts +19 -3
  178. package/src/server/gramlot-server.js +144 -18
  179. package/src/server/index-page.d.ts +10 -0
  180. package/src/server/index-page.js +73 -8
  181. package/src/server/index.d.ts +1 -1
  182. package/src/server/index.js +1 -1
  183. package/src/server/page-base.js +4 -0
  184. package/src/server/page-store.d.ts +21 -0
  185. package/src/server/page-store.js +219 -0
  186. package/src/server/page.d.ts +6 -1
  187. package/src/server/page.js +5 -1
  188. package/src/server/store-recipe.js +102 -0
  189. package/src/server/toolbar-icon-name.d.ts +76 -0
  190. package/src/server/upload.d.ts +2 -0
  191. package/src/server/upload.js +36 -18
  192. package/src/server/visual-editor.js +4 -2
  193. package/src/tree-store.d.ts +5 -1
  194. package/src/tree-store.js +11 -2
  195. package/src/view/choice-focus.js +17 -0
  196. package/src/view/html.js +21 -1
  197. package/src/view/menu.js +9 -3
  198. package/src/visual-editor.js +6 -2
  199. package/themes/gramlot-base/theme.css +53 -28
  200. package/themes/gramlot-compact/theme.css +2 -0
  201. package/themes/gramlot-index/icons/applications.svg +4 -0
  202. package/themes/gramlot-index/icons/archive.svg +4 -0
  203. package/themes/gramlot-index/icons/attachment.svg +4 -0
  204. package/themes/gramlot-index/icons/book.svg +4 -0
  205. package/themes/gramlot-index/icons/bookmark.svg +4 -0
  206. package/themes/gramlot-index/icons/calendar.svg +4 -0
  207. package/themes/gramlot-index/icons/cancel.svg +4 -0
  208. package/themes/gramlot-index/icons/chart.svg +4 -0
  209. package/themes/gramlot-index/icons/chat.svg +4 -0
  210. package/themes/gramlot-index/icons/clock.svg +4 -0
  211. package/themes/gramlot-index/icons/code.svg +4 -0
  212. package/themes/gramlot-index/icons/collapse.svg +4 -0
  213. package/themes/gramlot-index/icons/columns.svg +4 -0
  214. package/themes/gramlot-index/icons/confirm.svg +4 -0
  215. package/themes/gramlot-index/icons/copy.svg +4 -0
  216. package/themes/gramlot-index/icons/cut.svg +4 -0
  217. package/themes/gramlot-index/icons/database.svg +4 -0
  218. package/themes/gramlot-index/icons/delete.svg +4 -0
  219. package/themes/gramlot-index/icons/detach.svg +4 -0
  220. package/themes/gramlot-index/icons/document.svg +4 -0
  221. package/themes/gramlot-index/icons/download.svg +4 -0
  222. package/themes/gramlot-index/icons/duplicate.svg +4 -0
  223. package/themes/gramlot-index/icons/edit.svg +4 -0
  224. package/themes/gramlot-index/icons/expand.svg +4 -0
  225. package/themes/gramlot-index/icons/export.svg +4 -0
  226. package/themes/gramlot-index/icons/eye.svg +4 -0
  227. package/themes/gramlot-index/icons/filter.svg +4 -0
  228. package/themes/gramlot-index/icons/first.svg +4 -0
  229. package/themes/gramlot-index/icons/folder.svg +4 -0
  230. package/themes/gramlot-index/icons/group.svg +4 -0
  231. package/themes/gramlot-index/icons/help.svg +4 -0
  232. package/themes/gramlot-index/icons/home.svg +4 -0
  233. package/themes/gramlot-index/icons/import.svg +4 -0
  234. package/themes/gramlot-index/icons/info.svg +4 -0
  235. package/themes/gramlot-index/icons/inspector.svg +4 -0
  236. package/themes/gramlot-index/icons/last.svg +4 -0
  237. package/themes/gramlot-index/icons/layers.svg +4 -0
  238. package/themes/gramlot-index/icons/link.svg +4 -0
  239. package/themes/gramlot-index/icons/list.svg +4 -0
  240. package/themes/gramlot-index/icons/lock.svg +4 -0
  241. package/themes/gramlot-index/icons/logout.svg +4 -0
  242. package/themes/gramlot-index/icons/navigation.svg +4 -0
  243. package/themes/gramlot-index/icons/new.svg +4 -0
  244. package/themes/gramlot-index/icons/next.svg +4 -0
  245. package/themes/gramlot-index/icons/open.svg +4 -0
  246. package/themes/gramlot-index/icons/palette.svg +4 -0
  247. package/themes/gramlot-index/icons/panel-bottom.svg +4 -0
  248. package/themes/gramlot-index/icons/panel-left.svg +4 -0
  249. package/themes/gramlot-index/icons/panel-right.svg +4 -0
  250. package/themes/gramlot-index/icons/panel-top.svg +4 -0
  251. package/themes/gramlot-index/icons/paste.svg +4 -0
  252. package/themes/gramlot-index/icons/pause.svg +4 -0
  253. package/themes/gramlot-index/icons/pin.svg +4 -0
  254. package/themes/gramlot-index/icons/play.svg +4 -0
  255. package/themes/gramlot-index/icons/previous.svg +4 -0
  256. package/themes/gramlot-index/icons/print.svg +4 -0
  257. package/themes/gramlot-index/icons/redo.svg +4 -0
  258. package/themes/gramlot-index/icons/refresh.svg +4 -0
  259. package/themes/gramlot-index/icons/save.svg +4 -0
  260. package/themes/gramlot-index/icons/search.svg +4 -0
  261. package/themes/gramlot-index/icons/send.svg +4 -0
  262. package/themes/gramlot-index/icons/settings.svg +4 -0
  263. package/themes/gramlot-index/icons/sort-ascending.svg +4 -0
  264. package/themes/gramlot-index/icons/sort-descending.svg +4 -0
  265. package/themes/gramlot-index/icons/stop.svg +4 -0
  266. package/themes/gramlot-index/icons/table.svg +4 -0
  267. package/themes/gramlot-index/icons/tree.svg +4 -0
  268. package/themes/gramlot-index/icons/undo.svg +4 -0
  269. package/themes/gramlot-index/icons/unlock.svg +4 -0
  270. package/themes/gramlot-index/icons/upload.svg +4 -0
  271. package/themes/gramlot-index/icons/user.svg +4 -0
  272. package/themes/gramlot-index/icons/warning.svg +4 -0
  273. package/themes/gramlot-index/icons/zoom-in.svg +4 -0
  274. package/themes/gramlot-index/icons/zoom-out.svg +4 -0
  275. package/themes/gramlot-index/icons.json +76 -0
  276. package/themes/gramlot-index/theme.css +21 -0
  277. package/themes/joanna/theme.css +2 -0
  278. package/themes/mela/theme.css +2 -0
  279. package/themes/mimi/theme.css +2 -0
@@ -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}
@@ -0,0 +1,88 @@
1
+ import {fromTytx} from '@genrojs/tytx';
2
+
3
+ const blockSize = 256 * 1024;
4
+
5
+ function waitForRetry(signal, delay) {
6
+ signal?.throwIfAborted();
7
+ return new Promise((resolve, reject) => {
8
+ const abort = () => { clearTimeout(timer); reject(signal.reason); };
9
+ const timer = setTimeout(() => {
10
+ signal?.removeEventListener('abort', abort);
11
+ resolve();
12
+ }, delay);
13
+ signal?.addEventListener('abort', abort, {once:true});
14
+ });
15
+ }
16
+
17
+ function postBlock(window, url, headers, block, signal) {
18
+ return new Promise((resolve, reject) => {
19
+ const xhr = new window.XMLHttpRequest();
20
+ xhr.open('POST', url);
21
+ xhr.setRequestHeader('Content-Type', 'application/octet-stream');
22
+ for (const [name, value] of Object.entries(headers)) xhr.setRequestHeader(name, value);
23
+ const abort = () => xhr.abort();
24
+ const finish = fn => () => { signal?.removeEventListener('abort', abort); fn(); };
25
+ xhr.addEventListener('load', finish(() => {
26
+ try {
27
+ if (xhr.status !== 200) throw new Error(`Upload HTTP ${xhr.status}`);
28
+ resolve(fromTytx(xhr.responseText));
29
+ } catch (error) { reject(error); }
30
+ }));
31
+ xhr.addEventListener('error', finish(() => reject(new TypeError('Upload connection failed'))));
32
+ xhr.addEventListener('abort', finish(() => reject(new Error('Upload cancelled'))));
33
+ signal?.addEventListener('abort', abort, {once:true});
34
+ xhr.send(block);
35
+ });
36
+ }
37
+
38
+ function readBlock(window, blob) {
39
+ return new Promise((resolve, reject) => {
40
+ const reader = new window.FileReader();
41
+ reader.onload = () => resolve(new Uint8Array(reader.result));
42
+ reader.onerror = () => reject(reader.error);
43
+ reader.readAsArrayBuffer(blob);
44
+ });
45
+ }
46
+
47
+ /** One checkpoint per complete block. A lost response is reconciled before another write. */
48
+ export async function sendUploadBlocks(page, file, grant, {window, offset = 0, signal, progress = () => {}}) {
49
+ const {pageId, rpc, uploadUrl} = page;
50
+ const {transferId, authorization} = grant;
51
+ let delay = 250;
52
+ for (;;) {
53
+ signal?.throwIfAborted();
54
+ const end = Math.min(offset + blockSize, file.size);
55
+ const block = file.slice(offset, end);
56
+ let outcome;
57
+ try {
58
+ outcome = uploadUrl ? await postBlock(window, uploadUrl, {
59
+ 'X-Gramlot-Page-Id':pageId, 'X-Gramlot-Transfer-Id':transferId,
60
+ 'X-Gramlot-Upload-Token':authorization, 'X-Gramlot-Upload-Offset':String(offset),
61
+ }, block, signal) : await rpc.transport.upload({pageId, transferId, authorization, offset, block:await readBlock(window, block)}, progress, signal);
62
+ } catch (error) {
63
+ for (;;) {
64
+ signal?.throwIfAborted();
65
+ try {
66
+ outcome = await rpc.call('upload', 'status', {transferId}, {signal});
67
+ break;
68
+ } catch (statusError) {
69
+ if (statusError.name !== 'TypeError' && !page._pageStore?.reconnecting) throw statusError;
70
+ await waitForRetry(signal, delay);
71
+ delay = Math.min(delay * 2, 5000);
72
+ }
73
+ }
74
+ if (outcome.state === 'pending' && outcome.offset === offset) {
75
+ if (!(error instanceof TypeError)) throw error;
76
+ await waitForRetry(signal, delay);
77
+ delay = Math.min(delay * 2, 5000);
78
+ continue;
79
+ }
80
+ }
81
+ if (outcome.state === 'completed') progress(file.size);
82
+ if (outcome.state !== 'pending' || outcome.offset === undefined) return outcome;
83
+ if (outcome.offset !== end || end === offset || end === file.size) throw new Error('Invalid upload checkpoint');
84
+ offset = end;
85
+ progress(offset);
86
+ delay = 250;
87
+ }
88
+ }
@@ -1,6 +1,6 @@
1
1
  /** One browser queue, independent of its presentation. Files and grants stay private. */
2
2
  import {Bag} from '@genrojs/bag';
3
- import {fromTytx} from '@genrojs/tytx';
3
+ import {sendUploadBlocks} from './upload-blocks.js';
4
4
  import {randomId} from '../random-id.js';
5
5
 
6
6
  /** Read the optional shared context at preparation time, independently of file fields. */
@@ -53,7 +53,7 @@ export class UploadEngine {
53
53
  if (!this.gramlot.capabilities.includes('upload')) {
54
54
  this.#update(id, {status:'failed', error:'Upload is unavailable in this environment'}); return;
55
55
  }
56
- const state = {xhr:null, controller:new AbortController(), transferId:null, cancelled:false};
56
+ const state = {controller:new AbortController(), transferId:null, cancelled:false};
57
57
  this.#active.set(id, state);
58
58
  this.#update(id, {status:'preparing', error:null});
59
59
  try {
@@ -61,13 +61,13 @@ export class UploadEngine {
61
61
  metadata:{name:file.name, size:file.size, mediaType:file.type || '',
62
62
  fields:row.getItem('metadata').asDict(false, false, true), context:this.getContext()}});
63
63
  state.transferId = grant.transferId;
64
- this.#transfers.set(id, grant.transferId);
64
+ this.#transfers.set(id, grant);
65
65
  if (state.cancelled || this.#closed) {
66
66
  const outcome = await this.gramlot.rpc.call('upload', 'cancel', {transferId:state.transferId});
67
67
  await this.#apply(id, outcome, true); return;
68
68
  }
69
69
  this.#update(id, {status:'uploading'});
70
- const result = await this.#send(file, state, grant.authorization, id);
70
+ const result = await sendUploadBlocks(this.gramlot, file, grant, {window:this.window, signal:state.controller.signal, progress:loaded => this.#update(id, {loaded})});
71
71
  await this.#apply(id, result, state.cancelled);
72
72
  } catch (error) {
73
73
  if (state.transferId) {
@@ -83,28 +83,6 @@ export class UploadEngine {
83
83
  this.#active.delete(id);
84
84
  }
85
85
  }
86
- #send(file, state, token, id) {
87
- if (!this.gramlot.uploadUrl) {
88
- return this.gramlot.rpc.transport.upload({pageId:this.gramlot.pageId, transferId:state.transferId,
89
- authorization:token, file}, loaded => this.#update(id, {loaded}), state.controller.signal);
90
- }
91
- return new Promise((resolve, reject) => {
92
- const request = state.xhr = new this.window.XMLHttpRequest();
93
- request.open('POST', this.gramlot.uploadUrl, true);
94
- request.setRequestHeader('Content-Type', 'application/octet-stream');
95
- request.setRequestHeader('X-Gramlot-Page-Id', this.gramlot.pageId);
96
- request.setRequestHeader('X-Gramlot-Transfer-Id', state.transferId);
97
- request.setRequestHeader('X-Gramlot-Upload-Token', token);
98
- request.upload.addEventListener('progress', event => this.#update(id, {loaded:event.loaded}));
99
- request.addEventListener('load', () => {
100
- if (request.status !== 200) { reject(new Error(`Upload HTTP ${request.status}`)); return; }
101
- try { resolve(fromTytx(request.responseText)); } catch (error) { reject(error); }
102
- }, {once:true});
103
- request.addEventListener('error', () => reject(new Error('Upload connection failed')), {once:true});
104
- request.addEventListener('abort', () => reject(new Error('Upload cancelled')), {once:true});
105
- request.send(file);
106
- });
107
- }
108
86
  async #apply(id, outcome, cancelled = false) {
109
87
  if (outcome.state === 'completed') {
110
88
  this.#update(id, {status:'completed', result:outcome.result, error:null});
@@ -132,15 +110,28 @@ export class UploadEngine {
132
110
  return true;
133
111
  }
134
112
  async reconcile(id) {
135
- const transferId = this.#transfers.get(id);
136
- if (!transferId || this.#closed || this.#active.has(id) || this.#checking.has(id)) return;
113
+ const grant = this.#transfers.get(id);
114
+ if (!grant || this.#closed || this.#active.has(id) || this.#checking.has(id)) return;
137
115
  this.#checking.add(id);
116
+ const state = {transferId:grant.transferId, controller:new AbortController(), cancelled:false};
138
117
  try {
139
- const outcome = await this.gramlot.rpc.call('upload', 'status', {transferId});
118
+ this.#active.set(id, state);
119
+ let outcome = await this.gramlot.rpc.call('upload', 'status', {transferId:grant.transferId});
120
+ if (outcome.state === 'pending' && Number.isSafeInteger(outcome.offset)) {
121
+ outcome = await sendUploadBlocks(this.gramlot, this.#files.get(id), grant, {
122
+ window:this.window, offset:outcome.offset, signal:state.controller.signal, progress:loaded => this.#update(id, {loaded}),
123
+ });
124
+ }
140
125
  await this.#apply(id, outcome);
141
126
  } catch (error) {
142
- this.#update(id, {status:'uncertain', error:error.message});
127
+ if (state.cancelled) {
128
+ try {
129
+ const outcome = await this.gramlot.rpc.call('upload', 'cancel', {transferId:grant.transferId});
130
+ await this.#apply(id, outcome, true);
131
+ } catch (recoveryError) { this.#update(id, {status:'uncertain', error:recoveryError.message}); }
132
+ } else this.#update(id, {status:'uncertain', error:error.message});
143
133
  } finally {
134
+ this.#active.delete(id);
144
135
  this.#checking.delete(id);
145
136
  }
146
137
  }
@@ -154,7 +145,6 @@ export class UploadEngine {
154
145
  if (!state) return;
155
146
  state.cancelled = true;
156
147
  state.controller.abort();
157
- state.xhr?.abort();
158
148
  }
159
149
  dispose() {
160
150
  this.#closed = true;