@gramlot/gramlot 0.3.41 → 0.5.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 (358) hide show
  1. package/assets/icons/align-center.svg +4 -0
  2. package/assets/icons/align-justify.svg +4 -0
  3. package/assets/icons/align-left.svg +4 -0
  4. package/assets/icons/align-right.svg +4 -0
  5. package/assets/icons/applications.svg +4 -0
  6. package/assets/icons/archive.svg +4 -0
  7. package/assets/icons/attachment.svg +4 -0
  8. package/assets/icons/bold.svg +4 -0
  9. package/assets/icons/book.svg +4 -0
  10. package/assets/icons/bookmark.svg +4 -0
  11. package/assets/icons/calendar.svg +4 -0
  12. package/assets/icons/cancel.svg +4 -0
  13. package/assets/icons/chart.svg +4 -1
  14. package/assets/icons/chat.svg +4 -0
  15. package/assets/icons/clock.svg +4 -0
  16. package/assets/icons/code.svg +4 -0
  17. package/assets/icons/collapse.svg +4 -0
  18. package/assets/icons/columns.svg +4 -0
  19. package/assets/icons/confirm.svg +4 -0
  20. package/assets/icons/copy.svg +4 -0
  21. package/assets/icons/cut.svg +4 -0
  22. package/assets/icons/database.svg +4 -0
  23. package/assets/icons/delete.svg +4 -0
  24. package/assets/icons/detach.svg +4 -0
  25. package/assets/icons/document.svg +4 -0
  26. package/assets/icons/download.svg +4 -0
  27. package/assets/icons/duplicate.svg +4 -0
  28. package/assets/icons/edit.svg +4 -0
  29. package/assets/icons/eraser.svg +4 -0
  30. package/assets/icons/expand.svg +4 -0
  31. package/assets/icons/export.svg +4 -0
  32. package/assets/icons/eye.svg +4 -0
  33. package/assets/icons/filter.svg +4 -0
  34. package/assets/icons/first.svg +4 -0
  35. package/assets/icons/folder.svg +4 -0
  36. package/assets/icons/group.svg +4 -0
  37. package/assets/icons/help.svg +4 -0
  38. package/assets/icons/home.svg +4 -0
  39. package/assets/icons/horizontal-rule.svg +4 -0
  40. package/assets/icons/image.svg +4 -0
  41. package/assets/icons/import.svg +4 -0
  42. package/assets/icons/indent.svg +4 -0
  43. package/assets/icons/info.svg +4 -0
  44. package/assets/icons/inspector.svg +4 -0
  45. package/assets/icons/italic.svg +4 -0
  46. package/assets/icons/last.svg +4 -0
  47. package/assets/icons/layers.svg +4 -0
  48. package/assets/icons/link.svg +4 -0
  49. package/assets/icons/list-bulleted.svg +4 -0
  50. package/assets/icons/list-numbered.svg +4 -0
  51. package/assets/icons/list.svg +4 -0
  52. package/assets/icons/lock.svg +4 -0
  53. package/assets/icons/logout.svg +4 -0
  54. package/assets/icons/navigation.svg +4 -0
  55. package/assets/icons/new.svg +4 -0
  56. package/assets/icons/next.svg +4 -0
  57. package/assets/icons/open.svg +4 -0
  58. package/assets/icons/outdent.svg +4 -0
  59. package/assets/icons/palette.svg +4 -0
  60. package/assets/icons/panel-bottom.svg +4 -0
  61. package/assets/icons/panel-left.svg +4 -0
  62. package/assets/icons/panel-right.svg +4 -0
  63. package/assets/icons/panel-top.svg +4 -0
  64. package/assets/icons/paragraph.svg +4 -0
  65. package/assets/icons/paste.svg +4 -0
  66. package/assets/icons/pause.svg +4 -0
  67. package/assets/icons/pin.svg +4 -0
  68. package/assets/icons/play.svg +4 -0
  69. package/assets/icons/previous.svg +4 -0
  70. package/assets/icons/print.svg +4 -0
  71. package/assets/icons/redo.svg +4 -0
  72. package/assets/icons/refresh.svg +4 -0
  73. package/assets/icons/save.svg +4 -0
  74. package/assets/icons/search.svg +4 -0
  75. package/assets/icons/select-all.svg +4 -0
  76. package/assets/icons/send.svg +4 -0
  77. package/assets/icons/settings.svg +4 -0
  78. package/assets/icons/sort-ascending.svg +4 -0
  79. package/assets/icons/sort-descending.svg +4 -0
  80. package/assets/icons/stop.svg +4 -0
  81. package/assets/icons/strikethrough.svg +4 -0
  82. package/assets/icons/table.svg +4 -0
  83. package/assets/icons/tree.svg +4 -0
  84. package/assets/icons/underline.svg +4 -0
  85. package/assets/icons/undo.svg +4 -0
  86. package/assets/icons/unlock.svg +4 -0
  87. package/assets/icons/upload.svg +4 -0
  88. package/assets/icons/user.svg +4 -0
  89. package/assets/icons/warning.svg +4 -0
  90. package/assets/icons/zoom-in.svg +4 -0
  91. package/assets/icons/zoom-out.svg +4 -0
  92. package/dist/components/charts/__init__.py +1 -1
  93. package/dist/components/charts/assets/index.js +1 -1
  94. package/dist/components/charts/assets/libraries/vega.js +11 -11
  95. package/dist/components/charts/grammar.json +2032 -72
  96. package/dist/components/editors/__init__.py +1 -1
  97. package/dist/components/editors/assets/collection.js +1 -1
  98. package/dist/components/editors/assets/index.js +1 -1
  99. package/dist/components/editors/assets/libraries/codemirror.js +30 -31
  100. package/dist/components/editors/assets/libraries/jodit.js +453 -447
  101. package/dist/components/editors/commands.json +113 -1
  102. package/dist/components/editors/grammar.json +12 -5
  103. package/dist/components/grid/__init__.py +1 -1
  104. package/dist/components/grid/assets/index.js +1 -1
  105. package/dist/components/grid/commands.json +4 -6
  106. package/dist/components/grid/grammar.json +112 -0
  107. package/dist/components/inputs/__init__.py +1 -1
  108. package/dist/components/inputs/assets/index.js +1 -1
  109. package/dist/components/inputs/grammar.json +5165 -359
  110. package/dist/components/layout/__init__.py +1 -1
  111. package/dist/components/layout/assets/collection.js +1 -0
  112. package/dist/components/layout/assets/index.js +1 -1
  113. package/dist/components/layout/grammar.json +433 -4
  114. package/dist/components/tree/__init__.py +1 -1
  115. package/dist/components/tree/assets/index.js +1 -1
  116. package/dist/components/tree/grammar.json +51 -0
  117. package/dist/components/typst/__init__.py +1 -1
  118. package/dist/components/typst/assets/collection.js +6 -6
  119. package/dist/components/typst/assets/index.js +1 -1
  120. package/dist/components/uploads/__init__.py +1 -1
  121. package/dist/components/uploads/assets/index.js +1 -1
  122. package/dist/components/uploads/grammar.json +66 -0
  123. package/dist/declared-collections.js +1 -1
  124. package/dist/gramlot.js +5486 -2029
  125. package/dist/gramlot.min.js +361 -138
  126. package/dist/libraries.json +6 -4
  127. package/dist/standard-collections.js +1 -1
  128. package/dist/standard-grammar.js +1 -1
  129. package/package.json +6 -2
  130. package/src/binding/ask-dialog.js +17 -3
  131. package/src/binding/providers.js +3 -2
  132. package/src/binding/remote.js +41 -6
  133. package/src/binding/runtime.js +30 -3
  134. package/src/builder/gramlot-builder.d.ts +3 -1
  135. package/src/builder/gramlot-builder.js +77 -26
  136. package/src/builder/source.js +78 -15
  137. package/src/builder/xml-recipe.js +144 -0
  138. package/src/chat-file-types.js +13 -0
  139. package/src/chat.d.ts +1 -0
  140. package/src/chat.js +35 -25
  141. package/src/commands.d.ts +1 -1
  142. package/src/commands.js +1 -1
  143. package/src/components/border-container.js +64 -6
  144. package/src/components/buttons.js +26 -31
  145. package/src/components/chart-bar3d-options.js +0 -1
  146. package/src/components/chart-boxplot-options.js +1 -1
  147. package/src/components/chart-candlestick-options.js +1 -1
  148. package/src/components/chart-engines/echarts-options.js +6 -5
  149. package/src/components/chart-engines/echarts.js +27 -10
  150. package/src/components/chart-engines/plotly-map.js +1 -1
  151. package/src/components/chart-engines/plotly.js +21 -14
  152. package/src/components/chart-engines/uplot.js +17 -11
  153. package/src/components/chart-engines/vega.js +17 -11
  154. package/src/components/chart-funnel-options.js +1 -1
  155. package/src/components/chart-geographic-options.js +2 -2
  156. package/src/components/chart-heatmap-options.js +1 -1
  157. package/src/components/chart-map-bar3d-options.js +2 -2
  158. package/src/components/chart-map-options.js +2 -2
  159. package/src/components/chart-pane.js +5 -5
  160. package/src/components/chart-parallel-options.js +1 -1
  161. package/src/components/chart-radar-options.js +1 -1
  162. package/src/components/chart-renderer.js +6 -1
  163. package/src/components/chart-sankey-options.js +1 -1
  164. package/src/components/chart-spatial-options.js +6 -2
  165. package/src/components/chart-sunburst-options.js +13 -1
  166. package/src/components/chart-theme.js +14 -0
  167. package/src/components/chart-treemap-options.js +1 -1
  168. package/src/components/chart-type-data.js +24 -4
  169. package/src/components/charts.js +7 -6
  170. package/src/components/check-box-text-editor.js +1 -0
  171. package/src/components/check-box-text.js +2 -0
  172. package/src/components/check-box-tree.js +1 -1
  173. package/src/components/choice-editor.js +5 -4
  174. package/src/components/choice-field-styles.js +9 -1
  175. package/src/components/code-mirror-engine.js +19 -5
  176. package/src/components/code-mirror-gramlot.js +85 -0
  177. package/src/components/code-mirror.js +3 -2
  178. package/src/components/drawing.js +43 -14
  179. package/src/components/editor-commands.js +69 -0
  180. package/src/components/editor-options.js +1 -1
  181. package/src/components/editors.js +5 -3
  182. package/src/components/form-tray-pane.js +18 -0
  183. package/src/components/graphical-ranges.js +190 -0
  184. package/src/components/grid-check-sets.js +39 -3
  185. package/src/components/grid-footer.js +6 -1
  186. package/src/components/grid-header-interaction.js +3 -3
  187. package/src/components/grid-styles.js +30 -5
  188. package/src/components/grid-tools.js +15 -7
  189. package/src/components/grid.js +109 -15
  190. package/src/components/html-editor-commands.js +61 -0
  191. package/src/components/html-editor.js +18 -3
  192. package/src/components/inputs.js +94 -23
  193. package/src/components/jodit-engine.js +110 -7
  194. package/src/components/layout.js +3 -2
  195. package/src/components/menus.js +89 -26
  196. package/src/components/numeric-range.js +39 -0
  197. package/src/components/selected-container.js +123 -64
  198. package/src/components/tab-bar.js +389 -0
  199. package/src/components/toolbar-icon-style.js +22 -0
  200. package/src/components/toolbar-overflow.js +74 -12
  201. package/src/components/tray-base.js +528 -0
  202. package/src/components/tray-pane.js +41 -518
  203. package/src/components/tree.js +56 -4
  204. package/src/components/typed-editor.js +5 -2
  205. package/src/components/typst-preview.js +3 -3
  206. package/src/components/upload-blocks.js +88 -0
  207. package/src/components/upload-engine.js +21 -31
  208. package/src/components/uploader.js +168 -47
  209. package/src/editing-session.js +2 -1
  210. package/src/gramlot.js +6 -3
  211. package/src/handlers/dom-handler.d.ts +2 -0
  212. package/src/handlers/dom-handler.js +9 -0
  213. package/src/handlers/rpc-handler.d.ts +1 -1
  214. package/src/handlers/rpc-handler.js +2 -0
  215. package/src/handlers/source-handler.d.ts +5 -3
  216. package/src/handlers/source-handler.js +31 -13
  217. package/src/icons.js +84 -0
  218. package/src/ide-runtime.js +3 -1
  219. package/src/index-page-runtime.js +20 -5
  220. package/src/index-page-styles.js +1 -1
  221. package/src/index-theme.js +210 -3
  222. package/src/index.d.ts +7 -2
  223. package/src/index.js +7 -2
  224. package/src/libraries.js +4 -4
  225. package/src/object-extract.d.ts +7 -0
  226. package/src/object-extract.js +31 -0
  227. package/src/renderer/attributes.js +1 -1
  228. package/src/renderer/gramlot-renderer.d.ts +2 -2
  229. package/src/renderer/gramlot-renderer.js +4 -1
  230. package/src/server/chat-attachments.js +139 -0
  231. package/src/server/chat.d.ts +33 -0
  232. package/src/server/chat.js +168 -0
  233. package/src/server/database-selectors.d.ts +6 -0
  234. package/src/server/database-selectors.js +13 -0
  235. package/src/server/gramlot-file-server.js +6 -1
  236. package/src/server/gramlot-server.d.ts +19 -3
  237. package/src/server/gramlot-server.js +149 -19
  238. package/src/server/index-page.d.ts +10 -0
  239. package/src/server/index-page.js +92 -8
  240. package/src/server/index.d.ts +1 -1
  241. package/src/server/index.js +1 -1
  242. package/src/server/page-base.js +4 -0
  243. package/src/server/page-store.d.ts +21 -0
  244. package/src/server/page-store.js +219 -0
  245. package/src/server/page.d.ts +6 -1
  246. package/src/server/page.js +5 -1
  247. package/src/server/store-recipe.js +102 -0
  248. package/src/server/toolbar-icon-name.d.ts +93 -0
  249. package/src/server/upload.d.ts +2 -0
  250. package/src/server/upload.js +36 -18
  251. package/src/server/visual-editor.js +4 -2
  252. package/src/tree-store.d.ts +5 -1
  253. package/src/tree-store.js +11 -2
  254. package/src/view/choice-focus.js +17 -0
  255. package/src/view/html.js +21 -1
  256. package/src/view/labelbox.js +6 -1
  257. package/src/view/menu.js +9 -3
  258. package/src/visual-editor.d.ts +1 -0
  259. package/src/visual-editor.js +10 -5
  260. package/themes/gramlot-base/theme.css +60 -28
  261. package/themes/gramlot-compact/theme.css +2 -0
  262. package/themes/gramlot-index/icons/align-center.svg +4 -0
  263. package/themes/gramlot-index/icons/align-justify.svg +4 -0
  264. package/themes/gramlot-index/icons/align-left.svg +4 -0
  265. package/themes/gramlot-index/icons/align-right.svg +4 -0
  266. package/themes/gramlot-index/icons/applications.svg +4 -0
  267. package/themes/gramlot-index/icons/archive.svg +4 -0
  268. package/themes/gramlot-index/icons/attachment.svg +4 -0
  269. package/themes/gramlot-index/icons/bold.svg +4 -0
  270. package/themes/gramlot-index/icons/book.svg +4 -0
  271. package/themes/gramlot-index/icons/bookmark.svg +4 -0
  272. package/themes/gramlot-index/icons/calendar.svg +4 -0
  273. package/themes/gramlot-index/icons/cancel.svg +4 -0
  274. package/themes/gramlot-index/icons/chart.svg +4 -0
  275. package/themes/gramlot-index/icons/chat.svg +4 -0
  276. package/themes/gramlot-index/icons/clock.svg +4 -0
  277. package/themes/gramlot-index/icons/code.svg +4 -0
  278. package/themes/gramlot-index/icons/collapse.svg +4 -0
  279. package/themes/gramlot-index/icons/columns.svg +4 -0
  280. package/themes/gramlot-index/icons/confirm.svg +4 -0
  281. package/themes/gramlot-index/icons/copy.svg +4 -0
  282. package/themes/gramlot-index/icons/cut.svg +4 -0
  283. package/themes/gramlot-index/icons/database.svg +4 -0
  284. package/themes/gramlot-index/icons/delete.svg +4 -0
  285. package/themes/gramlot-index/icons/detach.svg +4 -0
  286. package/themes/gramlot-index/icons/document.svg +4 -0
  287. package/themes/gramlot-index/icons/download.svg +4 -0
  288. package/themes/gramlot-index/icons/duplicate.svg +4 -0
  289. package/themes/gramlot-index/icons/edit.svg +4 -0
  290. package/themes/gramlot-index/icons/eraser.svg +4 -0
  291. package/themes/gramlot-index/icons/expand.svg +4 -0
  292. package/themes/gramlot-index/icons/export.svg +4 -0
  293. package/themes/gramlot-index/icons/eye.svg +4 -0
  294. package/themes/gramlot-index/icons/filter.svg +4 -0
  295. package/themes/gramlot-index/icons/first.svg +4 -0
  296. package/themes/gramlot-index/icons/folder.svg +4 -0
  297. package/themes/gramlot-index/icons/group.svg +4 -0
  298. package/themes/gramlot-index/icons/help.svg +4 -0
  299. package/themes/gramlot-index/icons/home.svg +4 -0
  300. package/themes/gramlot-index/icons/horizontal-rule.svg +4 -0
  301. package/themes/gramlot-index/icons/image.svg +4 -0
  302. package/themes/gramlot-index/icons/import.svg +4 -0
  303. package/themes/gramlot-index/icons/indent.svg +4 -0
  304. package/themes/gramlot-index/icons/info.svg +4 -0
  305. package/themes/gramlot-index/icons/inspector.svg +4 -0
  306. package/themes/gramlot-index/icons/italic.svg +4 -0
  307. package/themes/gramlot-index/icons/last.svg +4 -0
  308. package/themes/gramlot-index/icons/layers.svg +4 -0
  309. package/themes/gramlot-index/icons/link.svg +4 -0
  310. package/themes/gramlot-index/icons/list-bulleted.svg +4 -0
  311. package/themes/gramlot-index/icons/list-numbered.svg +4 -0
  312. package/themes/gramlot-index/icons/list.svg +4 -0
  313. package/themes/gramlot-index/icons/lock.svg +4 -0
  314. package/themes/gramlot-index/icons/logout.svg +4 -0
  315. package/themes/gramlot-index/icons/navigation.svg +4 -0
  316. package/themes/gramlot-index/icons/new.svg +4 -0
  317. package/themes/gramlot-index/icons/next.svg +4 -0
  318. package/themes/gramlot-index/icons/open.svg +4 -0
  319. package/themes/gramlot-index/icons/outdent.svg +4 -0
  320. package/themes/gramlot-index/icons/palette.svg +4 -0
  321. package/themes/gramlot-index/icons/panel-bottom.svg +4 -0
  322. package/themes/gramlot-index/icons/panel-left.svg +4 -0
  323. package/themes/gramlot-index/icons/panel-right.svg +4 -0
  324. package/themes/gramlot-index/icons/panel-top.svg +4 -0
  325. package/themes/gramlot-index/icons/paragraph.svg +4 -0
  326. package/themes/gramlot-index/icons/paste.svg +4 -0
  327. package/themes/gramlot-index/icons/pause.svg +4 -0
  328. package/themes/gramlot-index/icons/pin.svg +4 -0
  329. package/themes/gramlot-index/icons/play.svg +4 -0
  330. package/themes/gramlot-index/icons/previous.svg +4 -0
  331. package/themes/gramlot-index/icons/print.svg +4 -0
  332. package/themes/gramlot-index/icons/redo.svg +4 -0
  333. package/themes/gramlot-index/icons/refresh.svg +4 -0
  334. package/themes/gramlot-index/icons/save.svg +4 -0
  335. package/themes/gramlot-index/icons/search.svg +4 -0
  336. package/themes/gramlot-index/icons/select-all.svg +4 -0
  337. package/themes/gramlot-index/icons/send.svg +4 -0
  338. package/themes/gramlot-index/icons/settings.svg +4 -0
  339. package/themes/gramlot-index/icons/sort-ascending.svg +4 -0
  340. package/themes/gramlot-index/icons/sort-descending.svg +4 -0
  341. package/themes/gramlot-index/icons/stop.svg +4 -0
  342. package/themes/gramlot-index/icons/strikethrough.svg +4 -0
  343. package/themes/gramlot-index/icons/table.svg +4 -0
  344. package/themes/gramlot-index/icons/tree.svg +4 -0
  345. package/themes/gramlot-index/icons/underline.svg +4 -0
  346. package/themes/gramlot-index/icons/undo.svg +4 -0
  347. package/themes/gramlot-index/icons/unlock.svg +4 -0
  348. package/themes/gramlot-index/icons/upload.svg +4 -0
  349. package/themes/gramlot-index/icons/user.svg +4 -0
  350. package/themes/gramlot-index/icons/warning.svg +4 -0
  351. package/themes/gramlot-index/icons/zoom-in.svg +4 -0
  352. package/themes/gramlot-index/icons/zoom-out.svg +4 -0
  353. package/themes/gramlot-index/icons.json +93 -0
  354. package/themes/gramlot-index/theme.css +24 -0
  355. package/themes/joanna/theme.css +2 -0
  356. package/themes/mela/theme.css +2 -0
  357. package/themes/mimi/theme.css +2 -0
  358. package/tools/gramlot-tools-inspector.js +11 -3
@@ -0,0 +1,144 @@
1
+ import {fromTytx, fromTytxIter} from '@genrojs/tytx';
2
+ import {Bag} from '@genrojs/bag';
3
+ import {SourceBagNode, sourceTarget} from '@genrojs/builders';
4
+ import {GramlotBuilderBag} from './source.js';
5
+
6
+ // Decode a scalar using the registered TYTX suffix, preserving unsuffixed XML text.
7
+ function scalar(text) {
8
+ const [value] = fromTytxIter([text]);
9
+ return value;
10
+ }
11
+
12
+ function isCompound(value) {
13
+ if (Array.isArray(value)) return true;
14
+ if (!value || typeof value !== 'object') return false;
15
+ const prototype = Object.getPrototypeOf(value);
16
+ return prototype === Object.prototype || prototype === null;
17
+ }
18
+
19
+ function attributeValue(text) {
20
+ if (!text.endsWith('::JS')) return scalar(text);
21
+ const value = fromTytx(text);
22
+ if (!isCompound(value)) throw new TypeError('A ::JS recipe attribute requires a JSON object or array');
23
+ return value;
24
+ }
25
+
26
+ /** The element children of `element`; text other than whitespace is an error. */
27
+ function elementChildren(element, where) {
28
+ const children = [];
29
+ for (const child of element.childNodes) {
30
+ if (child.nodeType === 1) children.push(child);
31
+ else if ((child.nodeType === 3 || child.nodeType === 4) && child.data.trim()) {
32
+ throw new TypeError(`Unexpected text inside ${where}`);
33
+ }
34
+ }
35
+ return children;
36
+ }
37
+
38
+ /**
39
+ * A builder container (a method that writes Source, such as frameGrid) runs on `parent` with the
40
+ * attributes, as `parent.frameGrid(attrs)` does in JS. Each child element names an accessor of the
41
+ * returned node (`grid`, `top`, `bottom`, `toolbar`); its own children go into that node.
42
+ */
43
+ function appendContainer(element, method, attrs, parent, builder) {
44
+ const name = element.tagName;
45
+ const result = builder[method](builder.wrapSource(parent), attrs);
46
+ for (const accessor of elementChildren(element, `<${name}>`)) {
47
+ if (accessor.namespaceURI || accessor.attributes.length) {
48
+ throw new TypeError(`<${accessor.tagName}> inside <${name}> names an accessor and takes no attributes`);
49
+ }
50
+ if (result === undefined) throw new TypeError(`<${name}> does not accept accessors`);
51
+ const target = sourceTarget(result[accessor.tagName]);
52
+ if (!(target instanceof SourceBagNode)) {
53
+ throw new TypeError(`<${name}> has no accessor <${accessor.tagName}>`);
54
+ }
55
+ for (const child of elementChildren(accessor, `<${name}><${accessor.tagName}>`)) {
56
+ appendElement(child, target, target.builder);
57
+ }
58
+ }
59
+ }
60
+
61
+ function appendElement(element, parent, builder) {
62
+ if (element.namespaceURI) throw new TypeError(`Unknown recipe element <${element.tagName}>`);
63
+ const tag = builder.schemaTag(element.tagName);
64
+ const attrs = Object.fromEntries(Array.from(element.attributes, attr => [attr.name, attributeValue(attr.value)]));
65
+ if (!tag) {
66
+ const method = builder.containerMethod(element.tagName);
67
+ if (!method) throw new TypeError(`Unknown recipe element <${element.tagName}>`);
68
+ appendContainer(element, method, attrs, parent, builder);
69
+ return;
70
+ }
71
+ const children = [];
72
+ let text = '';
73
+ for (const child of element.childNodes) {
74
+ if (child.nodeType === 1) children.push(child);
75
+ else if (child.nodeType === 3 || child.nodeType === 4) {
76
+ if (!children.length) text += child.data;
77
+ else if (child.data.trim()) throw new TypeError(`Unexpected text after a child of <${tag}>`);
78
+ }
79
+ }
80
+ // Builder preserves a scalar prefix when the first child promotes its parent to a branch.
81
+ const value = text.length && (!children.length || text.trim()) ? scalar(text) : null;
82
+ const node = parent instanceof GramlotBuilderBag
83
+ ? builder.bagCall(parent, tag, value, attrs)
84
+ : builder.commandOnNode(parent, tag, value, attrs);
85
+ for (const child of children) appendElement(child, node, node.builder);
86
+ }
87
+
88
+ function recipeSections(xml, DOMParser) {
89
+ if (typeof xml !== 'string') throw new TypeError('XML Source requires a document string');
90
+ const document = new DOMParser().parseFromString(xml, 'application/xml');
91
+ const root = document.documentElement;
92
+ if (document.doctype || root.namespaceURI || root.tagName !== 'gramlot' ||
93
+ document.getElementsByTagNameNS('*', 'parsererror').length) {
94
+ throw new TypeError('Expected a well-formed Gramlot XML Recipe with a <gramlot> root');
95
+ }
96
+ const sections = name => Array.from(root.children).filter(child => !child.namespaceURI && child.tagName === name);
97
+ const mains = sections('main'), data = sections('data');
98
+ if (mains.length !== 1) throw new TypeError('Gramlot XML Recipe requires one direct <main> section');
99
+ if (data.length > 1) throw new TypeError('Gramlot XML Recipe accepts one direct <data> section');
100
+ return {main:mains[0], data:data[0]};
101
+ }
102
+
103
+ function readSource(main, builder) {
104
+ const source = new GramlotBuilderBag(null, builder);
105
+ source.setBackref();
106
+ for (const child of main.childNodes) {
107
+ if (child.nodeType === 1) appendElement(child, source, builder);
108
+ else if ((child.nodeType === 3 || child.nodeType === 4) && child.data.trim()) {
109
+ throw new TypeError('Expected Source elements inside <main>');
110
+ }
111
+ }
112
+ return source;
113
+ }
114
+
115
+ /** A remote fragment contributes only Source. Initial Data belongs to the page document. */
116
+ export function readXmlRecipe(xml, builder, DOMParser) {
117
+ return readSource(recipeSections(xml, DOMParser).main, builder);
118
+ }
119
+
120
+ function readData(element) {
121
+ // Use Bag's XML label, attribute and nested Bag conventions. Recipe leaf values
122
+ // and scalar attributes use the same TYTX suffixes as Source attributes.
123
+ const bag = Bag.fromXml(element.outerHTML);
124
+ function decode(branch) {
125
+ for (const node of branch.getNodes()) {
126
+ const attrs = Object.fromEntries(Object.entries(node.attr ?? {}).map(([key, value]) =>
127
+ [key, typeof value === 'string' ? scalar(value) : value]));
128
+ node.setAttr(attrs, false, false, false);
129
+ if (node.staticValue instanceof Bag) decode(node.staticValue);
130
+ else if (typeof node.staticValue === 'string') node.setValue(scalar(node.staticValue), false);
131
+ }
132
+ }
133
+ decode(bag);
134
+ return bag;
135
+ }
136
+
137
+ /** Decode a complete startup or editor document before applying any page state. */
138
+ export function readXmlRecipeDocument(xml, builder, DOMParser) {
139
+ const {main, data} = recipeSections(xml, DOMParser);
140
+ return {
141
+ source:readSource(main, builder),
142
+ data:data ? readData(data) : null,
143
+ };
144
+ }
@@ -0,0 +1,13 @@
1
+ const textExtensions = [
2
+ 'txt', 'md', 'csv', 'json', 'py', 'js', 'ts', 'jsx', 'tsx', 'html', 'css',
3
+ 'sql', 'yaml', 'yml', 'xml', 'sh', 'toml', 'log',
4
+ ];
5
+
6
+ export const fileTypes = {
7
+ png: 'image/png',
8
+ jpg: 'image/jpeg',
9
+ jpeg: 'image/jpeg',
10
+ webp: 'image/webp',
11
+ pdf: 'application/pdf',
12
+ ...Object.fromEntries(textExtensions.map(extension => [extension, 'text/plain'])),
13
+ };
package/src/chat.d.ts CHANGED
@@ -3,6 +3,7 @@ import type {SourceBagNode} from '@genrojs/builders';
3
3
  import type {Bag} from '@genrojs/bag';
4
4
  export function chatRender(page: Gramlot, node: SourceBagNode, params: {messages: Bag}): void;
5
5
  export function chatSend(page: Gramlot, node: SourceBagNode): void;
6
+ export function chatDraftKey(page: Gramlot, node: SourceBagNode, event: KeyboardEvent): void;
6
7
  export function chatReset(page: Gramlot, node: SourceBagNode): void;
7
8
  export function chatCompleted(page: Gramlot, node: SourceBagNode, params: {response: Bag | null}): void;
8
9
 
package/src/chat.js CHANGED
@@ -1,15 +1,19 @@
1
+ import {fileTypes} from './chat-file-types.js';
1
2
  /** Shared chat behavior. Pages delegate their named Logic methods here. */
2
3
  import {Bag} from '@genrojs/bag';
3
4
  import {SourceBag, sourceTarget} from '@genrojs/builders';
4
5
  import {GramlotBuilderBag} from './builder/source.js';
5
6
  import {GramlotBuilder} from './builder/gramlot-builder.js';
6
7
  import {fromTytx, toTytx} from '@genrojs/tytx';
8
+ import {sendUploadBlocks} from './components/upload-blocks.js';
7
9
  import {randomId} from './random-id.js';
8
10
 
9
11
  const LABEL = /^m_[a-f0-9]+$/;
10
12
 
11
13
  /** Reconcile message Source, preserving older fragments and their interactive Data. */
12
14
  export function chatRender(page, node, {messages}) {
15
+ // A suspended binder removes its local snapshot until the page reconnects.
16
+ if (messages == null && page._pageStore?.reconnecting) return;
13
17
  if (!(messages instanceof Bag) || messages instanceof SourceBag) throw new TypeError('Chat messages require a Data Bag');
14
18
  const target = node.parentNode;
15
19
  const viewport = page.dom.getDomNode(target);
@@ -79,13 +83,29 @@ function send(node, action, text=null) {
79
83
  const id=randomId();
80
84
  node.SET('.requestId',id); node.SET('.pending',true); node.SET('.error','');
81
85
  // One atomic Data write; the normal binder carries it to the PageStore recipe.
82
- node.SET('.conversation.request',new Bag({id,action,text,attachments:fromTytx(toTytx(node.getRelativeData('.attachments')))}));
86
+ const attachments=new Bag();
87
+ if(action === 'send') for(const file of node.getRelativeData('.attachments').getNodes()) {
88
+ attachments.setItem(file.label,new Bag({ref:file.staticValue.getItem('ref')}));
89
+ }
90
+ const model=node.getRelativeData('.model') ?? null;
91
+ node.SET('.conversation.request',new Bag({id,action,text,attachments,model}));
83
92
  }
84
93
  export function chatSend(page,node) {
85
94
  const text=node.getRelativeData('.draft');
86
95
  if(typeof text !== 'string' || (!text.trim() && !node.getRelativeData('.attachments').length)) return;
87
96
  send(node,'send',text);
88
97
  }
98
+ /**
99
+ * Composer keydown: Enter without modifiers runs the page Logic `chatSend`, so the send button
100
+ * conditions apply (a refused send inserts no newline); Shift+Enter and the other keys keep their
101
+ * default. Enter during an IME composition confirms the composition and never sends.
102
+ */
103
+ export function chatDraftKey(page,node,event) {
104
+ if(event.key!=='Enter' || event.isComposing || event.shiftKey || event.ctrlKey || event.altKey || event.metaKey) return;
105
+ event.preventDefault();
106
+ const {group,method}=page.src.logicRegistry.resolve('chatSend',node);
107
+ method.call(group,node);
108
+ }
89
109
  export function chatReset(page,node) {send(node,'reset');}
90
110
  export function chatCompleted(page,node,{response}) {
91
111
  if(response === null) return;
@@ -133,16 +153,6 @@ export function chatResize(page,node) {
133
153
  layout.schedule();
134
154
  }
135
155
 
136
- const textExtensions=['txt','md','csv','json','py','js','ts','jsx','tsx','html','css','sql','yaml','yml','xml','sh','toml','log'];
137
- const fileTypes={png:'image/png',jpg:'image/jpeg',jpeg:'image/jpeg',webp:'image/webp',pdf:'application/pdf',...Object.fromEntries(textExtensions.map(ext=>[ext,'text/plain']))};
138
- function readFile(file,win) {
139
- return new Promise((resolve,reject)=>{
140
- const reader=new win.FileReader();
141
- reader.onload=()=>resolve(reader.result.slice(reader.result.indexOf(',')+1));
142
- reader.onerror=()=>reject(new Error('Could not read the selected file.'));
143
- reader.readAsDataURL(file);
144
- });
145
- }
146
156
  export async function chatPickAttachments(page,node) {
147
157
  if(node.getRelativeData('.pending')||node.getRelativeData('.picking'))return;
148
158
  const doc=page.dom.getDomNode(node.parentNode).ownerDocument;
@@ -150,7 +160,8 @@ export async function chatPickAttachments(page,node) {
150
160
  input.accept=Object.keys(fileTypes).map(ext=>'.'+ext).join(',');
151
161
  input.style.display='none';doc.body.append(input);
152
162
  let active=true,finish;
153
- const release=page.src.renderer.onDispose(node.parentNode,()=>{active=false;input.remove();finish([]);});
163
+ const controller=new AbortController();
164
+ const release=page.src.renderer.onDispose(node.parentNode,()=>{active=false;controller.abort();input.remove();finish([]);});
154
165
  node.SET('.picking',true);node.SET('.error','');
155
166
  try {
156
167
  const files=await new Promise(resolve=>{
@@ -162,20 +173,19 @@ export async function chatPickAttachments(page,node) {
162
173
  if(!active||!files.length)return;
163
174
  const attachments=fromTytx(toTytx(node.getRelativeData('.attachments')));
164
175
  if(attachments.length+files.length>5)throw new Error('Choose at most 5 files.');
165
- let total=attachments.getNodes().reduce((n,file)=>n+file.staticValue.getItem('size'),0);
166
176
  for(const file of files) {
167
177
  const mediaType=fileTypes[file.name.split('.').pop().toLowerCase()];
168
- if(!mediaType)throw new Error('Supported files: PNG, JPEG, WebP, PDF and UTF-8 text/code.');
169
- const limit=mediaType==='text/plain'?1024*1024:2*1024*1024;
170
- total+=file.size;
171
- if(!file.size||file.size>limit||total>4*1024*1024)throw new Error('Limits: 2 MiB per file, 1 MiB for text, 4 MiB total.');
172
- const data=await readFile(file,doc.defaultView);
173
- if(mediaType==='text/plain') {
174
- const bytes=Uint8Array.from(atob(data),c=>c.charCodeAt(0));
175
- new TextDecoder('utf-8',{fatal:true}).decode(bytes);
176
- if(bytes.includes(0))throw new Error('The selected file is not UTF-8 text.');
178
+ if(!mediaType || !file.size)throw new Error('Choose a nonempty PNG, JPEG, WebP, PDF or UTF-8 text file.');
179
+ const grant=await page.rpc.call('upload','prepare',{operation:'chat_files.receive',
180
+ metadata:{name:file.name,mediaType,size:file.size,fields:{},context:{}}});
181
+ try {
182
+ const outcome=await sendUploadBlocks(page,file,grant,{window:doc.defaultView,signal:controller.signal});
183
+ if(outcome.state !== 'completed')throw new Error('Could not save the attachment.');
184
+ attachments.setItem('a_'+randomId(),new Bag(outcome.result));
185
+ } catch(error) {
186
+ await page.rpc.call('upload','cancel',{transferId:grant.transferId});
187
+ throw error;
177
188
  }
178
- attachments.setItem('a_'+randomId(),new Bag({name:file.name,mediaType,size:file.size,data}));
179
189
  }
180
190
  if(active)node.SET('.attachments',attachments);
181
191
  } catch(error) {if(active)node.SET('.error',error.message);}
@@ -192,10 +202,10 @@ export function chatRenderAttachments(page,node,{attachments}) {
192
202
  const file=attachment.staticValue;
193
203
  const item=builder.root.div({node_label:attachment.label,display:'flex',align_items:'center',gap:'6px',
194
204
  padding:'4px 8px',border:'1px solid var(--gramlot-border-control,#aaa)',border_radius:'10px',flex_shrink:0});
195
- if(file.getItem('mediaType').startsWith('image/')) item.img({src:'data:'+file.getItem('mediaType')+';base64,'+file.getItem('data'),
205
+ if(file.getItem('mediaType').startsWith('image/')) item.img({src:file.getItem('url'),
196
206
  alt:'Attachment preview',width:'36px',height:'36px',object_fit:'cover',border_radius:'6px'});
197
207
  item.span('=='+JSON.stringify(file.getItem('name')),{font_size:'12px',max_width:'180px',overflow:'hidden',text_overflow:'ellipsis',white_space:'nowrap'});
198
- item.button({icon:'×','aria-label':'Remove '+file.getItem('name'),disabled:'^.pending',class:'button--quiet'})
208
+ item.button({icon:'cancel','aria-label':'Remove '+file.getItem('name'),disabled:'^.pending',class:'button--quiet'})
199
209
  .dataController({func:'chatRemoveAttachment',attachment_id:attachment.label});
200
210
  }
201
211
  const prepared=page.src.prepareSource(builder.source);
package/src/commands.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Command metadata authored by a collection and isolated per page instance. */
2
- export interface CommandDefinition {label:string; publish:string; icon?:string; iconSrc?:string; tooltip?:string;}
2
+ export interface CommandDefinition {label:string; publish:string; icon?:string; tooltip?:string;}
3
3
  export interface CommandGroupMetadata {author?:string; description?:string;}
4
4
  export class CommandRegistry {
5
5
  registerGroup(namespace:string, metadata?:CommandGroupMetadata): Readonly<{register(name:string,definition:CommandDefinition):void}>;
package/src/commands.js CHANGED
@@ -17,7 +17,7 @@ export class CommandRegistry {
17
17
  if (commands.has(name)) throw new Error(`Duplicate command: ${namespace}:${name}`);
18
18
  if (!definition || typeof definition !== 'object' || Array.isArray(definition) ||
19
19
  !Object.hasOwn(definition, 'label') || !Object.hasOwn(definition, 'publish') ||
20
- Object.keys(definition).some(key => !['label', 'publish', 'icon', 'iconSrc', 'tooltip'].includes(key)) ||
20
+ Object.keys(definition).some(key => !['label', 'publish', 'icon', 'tooltip'].includes(key)) ||
21
21
  Object.values(definition).some(value => typeof value !== 'string')) {
22
22
  throw new TypeError(`Invalid command definition: ${namespace}:${name}`);
23
23
  }
@@ -1,4 +1,7 @@
1
+ import {renderIcon} from '../icons.js';
1
2
  /** Parent-owned regions. Layout changes never move or recreate slotted content. */
3
+ import {labelboxContent} from '../view/labelbox.js';
4
+ import {toolbarIconParameters, projectToolbarIconStyle} from './toolbar-icon-style.js';
2
5
  import {defineComponent} from './registry.js';
3
6
  import {Container} from './container.js';
4
7
  import {WindowSurface} from './window-surface.js';
@@ -194,8 +197,6 @@ export const BorderContainer = defineComponent({
194
197
  max-height var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),
195
198
  margin var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out)}
196
199
  .drawer:hover,.drawer:focus-visible{opacity:var(--gramlot-drawer-active-opacity,1)}
197
- [data-axis=x]>.drawer[data-resizable]{cursor:col-resize}
198
- [data-axis=y]>.drawer[data-resizable]{cursor:row-resize}
199
200
  @media (hover:hover){
200
201
  [data-axis=x]>.drawer:hover{transform:scale(var(--gramlot-drawer-hover-cross-scale,1.75),var(--gramlot-drawer-hover-length-scale,1.12))}
201
202
  [data-axis=y]>.drawer:hover{transform:scale(var(--gramlot-drawer-hover-length-scale,1.12),var(--gramlot-drawer-hover-cross-scale,1.75))}
@@ -281,7 +282,7 @@ export const BorderContainer = defineComponent({
281
282
  separator.setAttribute('aria-controls', viewport.id);
282
283
  const drawer = doc.createElement('button'); drawer.type = 'button'; drawer.className = 'drawer';
283
284
  drawer.setAttribute('aria-controls', viewport.id);
284
- const drawerIcon = doc.createElement('span'); drawerIcon.className = 'drawer-icon'; drawerIcon.setAttribute('aria-hidden', 'true');
285
+ const drawerIcon = doc.createElement('span'); drawerIcon.className = 'drawer-icon'; drawerIcon.setAttribute('iconslot', ''); drawerIcon.setAttribute('aria-hidden', 'true');
285
286
  const drawerLabel = doc.createElement('span'); drawerLabel.className = 'drawer-label';
286
287
  const drawerContent = doc.createElement('span'); drawerContent.className = 'drawer-content';
287
288
  const drawerViewport = doc.createElement('span'); drawerViewport.className = 'drawer-viewport';
@@ -376,7 +377,7 @@ export const BorderContainer = defineComponent({
376
377
  USE_PROFILES: {html: true}, FORBID_TAGS: ['style', 'form', 'input', 'button', 'select', 'textarea'],
377
378
  RETURN_DOM_FRAGMENT: true,
378
379
  }));
379
- state.drawerIcon.textContent = config.icon ?? '';
380
+ renderIcon(this, state.drawerIcon, config.icon);
380
381
  state.drawerIcon.hidden = !config.icon;
381
382
  state.drawer.toggleAttribute('data-icon', !!config.icon);
382
383
  state.drawer.toggleAttribute('data-labelled', !!config.label);
@@ -545,6 +546,63 @@ export const BorderContainer = defineComponent({
545
546
  /** Five-region command frame; the existing border engine owns layout. */
546
547
  export const FramePane = defineComponent({
547
548
  name: 'framePane', tag: 'gramlot-frame-pane', base: BorderContainer.base,
548
- parameters: BorderContainer.parameters, childParameters: BorderContainer.childParameters,
549
- subTags: 'contentPane', implementation: BorderContainer.implementation
549
+ parameters: {...BorderContainer.parameters, ...toolbarIconParameters},
550
+ childParameters: {...BorderContainer.childParameters, region:{required:true, enum:REGIONS, binding:'read'}},
551
+ subTags: 'contentPane,menu',
552
+ implementation: Base => class extends BorderContainer.implementation(Base) {
553
+ static projectChild(element, attrs, context) {
554
+ if (labelboxContent(element).localName !== 'gramlot-menu') return super.projectChild(element, attrs, context);
555
+ const {region, ...rest} = attrs;
556
+ if (rest.presentation !== 'bar' || !REGIONS.includes(region)) {
557
+ throw new TypeError('A direct framePane menu requires presentation="bar" and a frame region');
558
+ }
559
+ return {...rest, slot:'bars-' + region, orientation:['left','right'].includes(region) ? 'vertical' : 'horizontal'};
560
+ }
561
+ constructor() {
562
+ super();
563
+ const doc = this.ownerDocument;
564
+ const style = doc.createElement('style');
565
+ style.textContent = `
566
+ .frame-bars{display:flex;min-width:0;min-height:0;flex-direction:column;overflow:hidden}
567
+ .frame-bars[data-side=left],.frame-bars[data-side=right]{flex-direction:row}
568
+ ::slotted(:nth-child(n+2 of [slot=bars-top]:not([hidden]))),
569
+ ::slotted(:nth-child(n+2 of [slot=bars-bottom]:not([hidden]))){
570
+ border-block-start:1px solid color-mix(in srgb,var(--gramlot-border) 45%,transparent)}
571
+ ::slotted(:nth-child(n+2 of [slot=bars-left]:not([hidden]))),
572
+ ::slotted(:nth-child(n+2 of [slot=bars-right]:not([hidden]))){
573
+ border-inline-start:1px solid color-mix(in srgb,var(--gramlot-border) 45%,transparent)}
574
+ .control-box.has-bars{
575
+ grid-template-columns:var(--left,0px) auto minmax(0,1fr) auto var(--right,0px);
576
+ grid-template-rows:var(--top,0px) auto auto minmax(0,1fr) auto var(--bottom,0px);
577
+ grid-template-areas:'top top top top top' 'bars-top bars-top bars-top bars-top bars-top'
578
+ 'left bars-left bars-center bars-right right' 'left bars-left center bars-right right'
579
+ 'bars-bottom bars-bottom bars-bottom bars-bottom bars-bottom' 'bottom bottom bottom bottom bottom'}
580
+ .control-box.has-bars[data-design=sidebar]{
581
+ grid-template-areas:'left bars-left top bars-right right' 'left bars-left bars-top bars-right right'
582
+ 'left bars-left bars-center bars-right right' 'left bars-left center bars-right right'
583
+ 'left bars-left bars-bottom bars-right right' 'left bars-left bottom bars-right right'}
584
+ `;
585
+ this.shadowRoot.append(style);
586
+ const slots = [];
587
+ for (const side of REGIONS) {
588
+ const strip = doc.createElement('div'), slot = doc.createElement('slot');
589
+ strip.className = 'frame-bars';
590
+ strip.dataset.side = side;
591
+ slot.name = 'bars-' + side;
592
+ strip.style.gridArea = slot.name;
593
+ strip.hidden = true;
594
+ slots.push(slot);
595
+ slot.addEventListener('slotchange', () => {
596
+ strip.hidden = !slot.assignedElements().length;
597
+ this.control.classList.toggle('has-bars', slots.some(s => !s.parentElement.hidden));
598
+ });
599
+ strip.append(slot);
600
+ this.control.append(strip);
601
+ }
602
+ style.textContent += '.frame-bars[hidden]{display:none}';
603
+ }
604
+ projectAttributes(attrs, adapt) {
605
+ return projectToolbarIconStyle(this, super.projectAttributes(attrs, adapt));
606
+ }
607
+ }
550
608
  });
@@ -1,9 +1,11 @@
1
+ import {renderIcon, iconSource} from '../icons.js';
1
2
  import {labelboxContent} from '../view/labelbox.js';
2
3
  import {choiceFieldStyles} from './choice-field-styles.js';
3
4
  /** Built-in command surfaces. Execution stays in ButtonBinding, state in ControlAdapter. */
4
5
  import {defineComponent, defineCollection} from './registry.js';
5
6
  import {controlElement} from './bases.js';
6
7
  import {projectParameters} from './parameters.js';
8
+ import {toolbarIconParameters} from './toolbar-icon-style.js';
7
9
  import {MenuContainer, menuLine} from './menus.js';
8
10
 
9
11
  function Command(HTMLElement) {
@@ -17,26 +19,26 @@ function Command(HTMLElement) {
17
19
  this.control.type = 'button';
18
20
  this.control.id = 'control';
19
21
  this.icon = doc.createElement('span');
20
- this.icon.className = 'icon';
22
+ this.icon.className = 'icon'; this.icon.setAttribute('iconslot', '');
21
23
  this.icon.setAttribute('aria-hidden', 'true');
22
24
  this.caption = doc.createElement('slot');
23
25
  this.control.append(this.icon, this.caption);
24
26
  this.controlBox.append(this.control);
25
27
  const style = doc.createElement('style');
26
28
  style.textContent = `:host{vertical-align:middle} :host([hidden]){display:none} .control-box{display:flex;align-items:stretch}
27
- button{display:inline-flex;align-items:center;justify-content:center;gap:var(--gramlot-button-gap,.35em);font:inherit;
28
- color:var(--gramlot-button-color,var(--gramlot-ink,CanvasText));background:var(--gramlot-button-background,var(--gramlot-field-background,Canvas));
29
- border:1px solid var(--gramlot-border-control,#888);border-radius:var(--gramlot-radius-sm,4px);
30
- min-height:max(var(--gramlot-field-height,28px),var(--gramlot-touch-target,0px));
31
- padding:var(--gramlot-button-padding,.25em .65em);cursor:pointer}
32
- button:hover:not(:disabled){background:var(--gramlot-button-hover,var(--gramlot-field-readonly-background,#eee))}
29
+ button{display:inline-flex;align-items:center;justify-content:center;gap:var(--gramlot-button-gap,.35em);font:inherit;font-size:var(--gramlot-field-font-size,inherit);line-height:1.25;box-sizing:border-box;
30
+ color:var(--gramlot-button-color,var(--gramlot-ink,CanvasText));background:var(--gramlot-button-background,color-mix(in srgb,var(--gramlot-surface,Canvas) 84%,currentColor));
31
+ border:0;border-radius:var(--gramlot-radius-sm,4px);
32
+ min-block-size:max(var(--gramlot-button-height,24px),var(--gramlot-touch-target,0px));min-inline-size:var(--gramlot-touch-target,0px);
33
+ padding:var(--gramlot-button-padding,2px 8px);cursor:pointer}
34
+ button:hover:not(:disabled){background:var(--gramlot-button-hover,color-mix(in srgb,var(--gramlot-surface,Canvas) 74%,currentColor))}
33
35
  :host(.button--secondary) button{background:var(--gramlot-selected,Highlight);color:var(--gramlot-action,CanvasText);border-color:transparent}
34
36
  :host(.button--secondary) button:hover:not(:disabled){background:var(--gramlot-selected,Highlight);color:var(--gramlot-action-hover,CanvasText);border-color:var(--gramlot-action,CanvasText)}
35
37
  button:active:not(:disabled){filter:brightness(.9)}
36
38
  @media(prefers-contrast:more){button{border:2px solid currentColor}}
37
39
  :host(.button--quiet) button{background:transparent;color:var(--gramlot-action,CanvasText);border-color:transparent}
38
40
  :host(.button--quiet) button:hover:not(:disabled){background:var(--gramlot-selected,Highlight);color:var(--gramlot-action-hover,CanvasText);border-color:transparent}
39
- button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:2px}
41
+ button:focus-visible{outline:1px solid var(--gramlot-focus-ring,Highlight);outline-offset:-1px}
40
42
  button:disabled{opacity:.55;cursor:not-allowed} .icon:empty{display:none} .icon img{display:block;width:100%;height:100%;object-fit:contain} .icon:has(img){width:1em;height:1em}
41
43
  .led{display:inline-block;width:.6em;height:.6em;border-radius:50%;background:var(--gramlot-button-led-off,#888)}
42
44
  [aria-pressed=true] .led{background:var(--gramlot-button-led-on,#2b9a46)}
@@ -46,10 +48,10 @@ function Command(HTMLElement) {
46
48
  max-width:var(--gramlot-popup-available-width);max-height:var(--gramlot-popup-available-height);
47
49
  border:1px solid var(--gramlot-border-control,#888);border-radius:var(--gramlot-radius-sm,4px);
48
50
  color:var(--gramlot-ink,CanvasText);background:var(--gramlot-field-background,Canvas);box-shadow:0 3px 12px #0003}
49
- :host(:is([role=menuitem],[role=menuitemcheckbox])){display:block} :host(:is([role=menuitem],[role=menuitemcheckbox])) button{width:100%;justify-content:start;border:0;background:transparent}
51
+ :host(:is([role=menuitem],[role=menuitemcheckbox])){display:block} :host(:is([role=menuitem],[role=menuitemcheckbox])) button:not(.standard-button){width:100%;justify-content:start;border:0;background:transparent}
50
52
  :host([role=separator]){display:block;border-top:1px solid var(--gramlot-border-control,#888);margin:.25em}
51
53
  :host([role=separator]) button{display:none}
52
- @media(forced-colors:active){button,:host(.button--secondary) button,:host(.button--quiet) button{background:ButtonFace;color:ButtonText;border-color:ButtonText;filter:none}}
54
+ @media(forced-colors:active){button,:host(.button--secondary) button,:host(.button--quiet) button{background:ButtonFace;color:ButtonText;border:1px solid ButtonText;filter:none}}
53
55
  `;
54
56
  style.textContent += `
55
57
  #control.icon-only{gap:0;padding:var(--gramlot-button-icon-padding,5px);
@@ -95,29 +97,19 @@ function Command(HTMLElement) {
95
97
  const rest = super.projectAttributes(attrs, adapt);
96
98
  this.control.disabled = Boolean(this.parameters.disabled);
97
99
  this.control.readOnly = Boolean(this.parameters.readonly);
98
- this.renderIcon(this.parameters.icon, this.parameters.iconSrc);
100
+ this.renderIcon(this.parameters.icon);
99
101
  if (attrs['aria-label'] != null) this.control.setAttribute('aria-label', attrs['aria-label']);
100
102
  else this.control.removeAttribute('aria-label');
101
103
  if (this.#actionPresentation) this.setActionPresentation(this.#actionPresentation);
102
104
  return rest;
103
105
  }
104
- renderIcon(icon, iconSrc) {
105
- if (!iconSrc) { this.icon.textContent = icon ?? ''; this.refreshIconOnly(); return; }
106
- let image = this.icon.firstElementChild;
107
- if (!image) {
108
- image = this.ownerDocument.createElement('img');
109
- image.alt = ''; image.draggable = false;
110
- this.icon.replaceChildren(image);
111
- }
112
- if (image.getAttribute('src') !== iconSrc) image.setAttribute('src', iconSrc);
113
- this.refreshIconOnly();
114
- }
106
+ renderIcon(icon) { renderIcon(this, this.icon, icon); this.refreshIconOnly(); }
115
107
  get entryIcon() { return this.parameters.icon; }
116
- get entryIconSrc() { return this.parameters.iconSrc; }
108
+ get entryIconSrc() { return iconSource(this, this.entryIcon); }
117
109
  setActionPresentation(presentation) {
118
110
  this.#actionPresentation = presentation;
119
111
  this.hidden = presentation.hidden;
120
- this.icon.textContent = presentation.icon;
112
+ this.renderIcon(presentation.icon);
121
113
  this.title = presentation.title;
122
114
  this.control.setAttribute('aria-label', presentation.title);
123
115
  this.refreshIconOnly();
@@ -131,8 +123,7 @@ function Command(HTMLElement) {
131
123
  Command.parameters = {
132
124
  action: {dtype: 'T', nullable: true},
133
125
  disabled: {dtype: 'B', default: false, binding: 'read'},
134
- icon: {dtype: 'T', default: '', binding: 'read'},
135
- iconSrc: {dtype: 'T', default: '', binding: 'read'}
126
+ icon: {dtype: 'T', default: '', binding: 'read'}
136
127
  };
137
128
  export const Button = defineComponent({name: 'button', tag: 'gramlot-button', base: Command,
138
129
  command: true, subTags: '*', implementation: Base => class extends Base {}});
@@ -165,18 +156,22 @@ export const ToggleButton = defineComponent({name: 'toggleButton', tag: 'gramlot
165
156
 
166
157
  export const Menu = defineComponent({name:'menu',tag:'gramlot-menu',base:MenuContainer,
167
158
  subTags:'menuline,spacer,contentPane',parameters:{
159
+ ...toolbarIconParameters,
160
+ showTooltip:{dtype:'B',nullable:true,binding:'read'},
168
161
  presentation:{dtype:'T',default:'popup',enum:['popup','bar']},
169
162
  orientation:{dtype:'T',default:'horizontal',enum:['horizontal','vertical']},
170
163
  modifiers:{dtype:'T',nullable:true},
171
- labelPosition:{dtype:'T',binding:'read',default:'beside',enum:['beside','below','tooltip']},iconSize:{dtype:'R',binding:'read',default:24},
164
+ labelPosition:{dtype:'T',binding:'read',default:'beside',enum:['beside','below','tooltip']},icon_size:{dtype:'R',binding:'read',default:24},
172
165
  resolver:{dtype:'T',nullable:true},cacheTime:{dtype:'R',default:-1},sync:{dtype:'B',default:false}
173
166
  },implementation:Base=>class extends Base {}});
174
167
  export const MenuLine = defineComponent({name:'menuline',tag:'gramlot-menu-line',base:Command,
175
168
  command:true,subTags:'*',parameters:{
176
- command:{dtype:'T',nullable:true},caption:{dtype:'T',nullable:true},code:{dtype:'T',nullable:true},
177
- checked:{dtype:'B',nullable:true,binding:'read'},tooltip:{dtype:'T',nullable:true},
178
- labelPosition:{dtype:'T',binding:'read',nullable:true,enum:['beside','below','tooltip']},iconSize:{dtype:'R',binding:'read',nullable:true},
179
- group:{dtype:'B',default:false},
169
+ command:{dtype:'T',nullable:true},caption:{dtype:'T',nullable:true,binding:'read'},code:{dtype:'T',nullable:true},
170
+ checked:{dtype:'B',nullable:true,binding:'read'},tooltip:{dtype:'T',nullable:true,binding:'read'},
171
+ labelPosition:{dtype:'T',binding:'read',nullable:true,enum:['beside','below','tooltip']},icon_size:{dtype:'R',binding:'read',nullable:true},
172
+ ...toolbarIconParameters,
173
+ badge:{dtype:['T','L','R'],nullable:true,binding:'read'},badge_color:{dtype:'T',nullable:true,binding:'read'},
174
+ expandInBar:{dtype:'R',nullable:true},group:{dtype:'B',default:false},
180
175
  parameters:{annotation:{kind:'type',module:'builtins',name:'dict'},nullable:true},favorite:{dtype:'B',default:false}
181
176
  },implementation:menuLine});
182
177
  export const Spacer = defineComponent({name:'spacer',tag:'gramlot-spacer',base:HTMLElement=>class extends HTMLElement {
@@ -7,7 +7,6 @@ export function chartBar3DOptions(view, first, second, fields, settings, domains
7
7
  const count=fields.length, span=0.72, step=count ? span/count : 0;
8
8
  const boxWidth=100,boxDepth=80;
9
9
  return {
10
- backgroundColor:'#ffffff',
11
10
  legend:{show:true,type:'scroll',left:12,right:12,bottom:10,height:24,data:fields},
12
11
  tooltip:{renderMode:'richText',formatter:params=>{
13
12
  const [x,y,value]=params.value;
@@ -14,7 +14,7 @@ export function chartBoxplotOptions({view,category,fields,seriesOptions}) {
14
14
  names.push(name);
15
15
  data.push(values);
16
16
  }
17
- return {backgroundColor:'#ffffff',tooltip:{trigger:'item'},
17
+ return {tooltip:{trigger:'item'},
18
18
  grid:{left:60,right:30,top:30,bottom:50},
19
19
  xAxis:{type:'category',data:names,name:category,boundaryGap:true},
20
20
  yAxis:{type:'value',scale:true},
@@ -18,7 +18,7 @@ export function chartCandlestickOptions({view,category,fields,seriesOptions}) {
18
18
  const itemStyle={};
19
19
  if(up){itemStyle.color=up;itemStyle.borderColor=up;}
20
20
  if(down){itemStyle.color0=down;itemStyle.borderColor0=down;}
21
- return {backgroundColor:'#ffffff',tooltip:{trigger:'axis',axisPointer:{type:'cross'}},
21
+ return {tooltip:{trigger:'axis',axisPointer:{type:'cross'}},
22
22
  grid:{left:60,right:30,top:30,bottom:70},
23
23
  xAxis:{type:'category',data:names,name:category,boundaryGap:true},
24
24
  yAxis:{type:'value',scale:true},
@@ -1,8 +1,9 @@
1
1
  import {chartPalette,chartLabel} from '../chart-domains.js';
2
2
  import {chartData} from '../chart-data.js';
3
+ import {chartCaption} from '../chart-type-data.js';
3
4
 
4
5
  /** Shared 2D layout; each type declares its presentation capabilities. */
5
- export function cartesianOptions({view,category,fields,settings,domains}, {seriesType,radial=false,horizontal=false,stacked=false,scatter=false,area=false,donut=false}) {
6
+ export function cartesianOptions({view,category,fields,settings,seriesOptions,domains}, {seriesType,radial=false,horizontal=false,stacked=false,scatter=false,area=false,donut=false}) {
6
7
  const {source,kind} = chartData(view,category,fields,domains?.dimension);
7
8
  if (stacked && new Set(settings.map(option => option.axis)).size > 1) throw new TypeError('Stacked series need the same scale. Assign all selected measures to the same axis.');
8
9
  if (scatter && !['value','time'].includes(kind)) throw new TypeError('Scatter needs a numeric or date dimension. Choose another column.');
@@ -10,14 +11,14 @@ export function cartesianOptions({view,category,fields,settings,domains}, {serie
10
11
  const numericAxes = ['left','right'].map((side,index) => ({type:'value',
11
12
  position:horizontal ? ['bottom','top'][index] : side,
12
13
  show:settings.some(options => options.axis === side),
13
- name:fields.filter((field,i) => settings[i].axis === side).join(', '),
14
+ name:fields.filter((field,i) => settings[i].axis === side).map(field => chartCaption(seriesOptions,field)).join(', '),
14
15
  ...(domains?{min:domains.axes[side][0],max:domains.axes[side][1]}:{}),splitLine:{show:index === 0}}));
15
- const option = {backgroundColor:'#ffffff',useUTC:true,legend:{show:true},
16
+ const option = {useUTC:true,legend:{show:true},
16
17
  tooltip:{trigger:radial || scatter ? 'item' : 'axis'},
17
18
  grid:{left:80,right:75,top:65,bottom:65}};
18
19
  if (radial) {
19
20
  option.legend = {show:true,type:'scroll',orient:'horizontal',left:12,right:12,bottom:10,height:24};
20
- option.series = fields.map(field => ({id:field,name:field,type:'pie',top:12,bottom:64,left:12,right:12,
21
+ option.series = fields.map(field => ({id:field,name:chartCaption(seriesOptions,field),type:'pie',top:12,bottom:64,left:12,right:12,
21
22
  label:{alignTo:'edge',edgeDistance:10,overflow:'truncate'},labelLayout:{hideOverlap:true},
22
23
  radius:donut ? ['35%','65%'] : '65%',
23
24
  data:source.map(row => ({name:kind === 'time' ? new Date(row[0]).toISOString().slice(0,10) : String(row[0]),value:row[1],...(domains?{itemStyle:{color:chartPalette[domains.labels.indexOf(chartLabel(row[0],kind))%chartPalette.length]}}:{})}))}));
@@ -37,7 +38,7 @@ export function cartesianOptions({view,category,fields,settings,domains}, {serie
37
38
  }
38
39
  option.xAxis = horizontal ? numericAxes : dimension;
39
40
  option.yAxis = horizontal ? dimension : numericAxes;
40
- option.series = fields.map((field,index) => ({id:field,name:field,
41
+ option.series = fields.map((field,index) => ({id:field,name:chartCaption(seriesOptions,field),
41
42
  type:seriesType,
42
43
  ...(seriesType==='line' ? {showSymbol:source.length===1} : {}),
43
44
  ...(horizontal ? {xAxisIndex:settings[index].axis === 'right' ? 1 : 0} : {yAxisIndex:settings[index].axis === 'right' ? 1 : 0}),