@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
@@ -15,10 +15,11 @@ import {Gauge} from './chart-gauge.js';
15
15
  import {ChartNotice,CHART_NOTICE_STYLE,chartErrorSections,chartTypeSections} from './chart-notice.js';
16
16
  import {ChartSyntaxError} from './chart-syntax.js';
17
17
  import {chartTypes} from './chart-types/index.js';
18
+ import {chartTheme} from './chart-theme.js';
18
19
 
19
20
  const ChartView = defineComponent({
20
21
  name:'chartView', tag:'gramlot-chart-view', base:Container, sourceContext:true,
21
- parameters:{sampleMin:{dtype:'R',nullable:true,binding:'read'},sampleMax:{dtype:'R',nullable:true,binding:'read'},sampleStep:{dtype:'R',default:1,binding:'read'},sampleStart:{dtype:'R',default:0,binding:'read'},mapLabelMode:{dtype:'T',default:'value',binding:'read'},mapBarScale:{dtype:'T',default:'zero',binding:'read'},selectedTerritory:{dtype:'T',default:'',binding:'twoWay'},configpath:{dtype:'T'},timeEmpty:{dtype:'T',default:'previous',binding:'read'},timeField:{dtype:'T',default:'',binding:'read'},timeValue:{dtype:'X',nullable:true,binding:'read'},timeStep:{dtype:'T',default:'month',binding:'read'},engine:{dtype:'T',default:'echarts',binding:'read'},mapValueField:{dtype:'T',binding:'read'},mapLabelField:{dtype:'T',binding:'read'},geoJSON:{dtype:'X',nullable:true,binding:'read'},geometryField:{dtype:'T',binding:'read'},secondCaptionField:{dtype:'T',binding:'read'},seriesOptions:{dtype:'X',binding:'read'},storepath:{dtype:'T'}, rowMode:{dtype:'T'}, gridId:{dtype:'T'},
22
+ parameters:{sampleMin:{dtype:'R',nullable:true,binding:'read'},sampleMax:{dtype:'R',nullable:true,binding:'read'},sampleStep:{dtype:'R',default:1,binding:'read'},sampleStart:{dtype:'R',default:0,binding:'read'},mapLabelMode:{dtype:'T',default:'value',binding:'read'},mapBarScale:{dtype:'T',default:'zero',binding:'read'},selectedTerritory:{dtype:'T',default:'',binding:'twoWay'},configpath:{dtype:'T'},timeEmpty:{dtype:'T',default:'previous',binding:'read'},timeField:{dtype:'T',default:'',binding:'read'},timeValue:{dtype:'X',nullable:true,binding:'read'},timeStep:{dtype:'T',default:'month',binding:'read'},engine:{dtype:'T',default:'echarts',binding:'read'},legend:{dtype:'B',default:true,binding:'read'},axes:{dtype:'B',default:true,binding:'read'},mapValueField:{dtype:'T',binding:'read'},mapLabelField:{dtype:'T',binding:'read'},geoJSON:{dtype:'X',nullable:true,binding:'read'},geometryField:{dtype:'T',binding:'read'},secondCaptionField:{dtype:'T',binding:'read'},seriesOptions:{dtype:'X',binding:'read'},storepath:{dtype:'T'}, rowMode:{dtype:'T'}, gridId:{dtype:'T'},
22
23
  chartType:{dtype:'T',binding:'read'}, captionField:{dtype:'T',binding:'read'}, valueFields:{dtype:'T',nullable:true,binding:'read'}},
23
24
  implementation:Base => class extends Base {
24
25
  #sampleView; #timeView; #revision=0; #active=false; #notice; #context; #grid; #releaseGrid; #view; #releaseView; #renderer; #resize;
@@ -32,7 +33,7 @@ const ChartView = defineComponent({
32
33
  this.control = this.ownerDocument.createElement('div');
33
34
  this.controlBox.append(this.#notice.element, this.control);
34
35
  this.controlBox.style.backgroundColor = 'var(--gramlot-surface,#fff)';
35
- this.control.style.cssText = 'width:100%;height:100%;min-width:0;background:#fff';
36
+ this.control.style.cssText = 'width:100%;height:100%;min-width:0;background:var(--gramlot-surface,#fff)';
36
37
  this.#resize = new this.ownerDocument.defaultView.ResizeObserver(() => this.#renderer?.resize());
37
38
  }
38
39
  setSourceContext(context) { this.#context = context; }
@@ -60,7 +61,7 @@ const ChartView = defineComponent({
60
61
  this.#release();
61
62
  this.#sampleView = new ChartSampleView();
62
63
  this.#timeView = new ChartTimeView(this.#sampleView);
63
- this.#renderer = new ChartRenderer(this.control, this.#timeView, {renderer:'svg', domains:context=>this.#sampleView.domains(context,this.parameters.sampleMin,this.parameters.sampleMax)});
64
+ this.#renderer = new ChartRenderer(this.control, this.#timeView, {renderer:'svg', theme:()=>chartTheme(this.control), domains:context=>this.#sampleView.domains(context,this.parameters.sampleMin,this.parameters.sampleMax)});
64
65
  }
65
66
  return;
66
67
  }
@@ -72,7 +73,7 @@ const ChartView = defineComponent({
72
73
  // shows in the notice, and the Data change that brings them projects the chart again.
73
74
  this.#view = new ChartDataView(this.#context.sourceNode.rootBuilder.binding.collectionStore(path,rowMode));
74
75
  this.#timeView = new ChartTimeView(this.#view.view);
75
- this.#renderer = new ChartRenderer(this.control,this.#timeView,{renderer:'svg',domains:context=>this.#timeView.domains(context),onTerritorySelect:name=>this.#context.writeParameter('selectedTerritory',name)});
76
+ this.#renderer = new ChartRenderer(this.control,this.#timeView,{renderer:'svg',theme:()=>chartTheme(this.control),domains:context=>this.#timeView.domains(context),onTerritorySelect:name=>this.#context.writeParameter('selectedTerritory',name)});
76
77
  this.#releaseView = this.#view.view.subscribe(() => {this.#timeView.invalidateDomains();this.#render();});
77
78
  }
78
79
  this.#linkGrid();
@@ -112,7 +113,7 @@ const ChartView = defineComponent({
112
113
  this.#releaseView = this.#view = this.#renderer = this.#timeView = this.#sampleView = null;
113
114
  }
114
115
  async #render() {
115
- const {engine,chartType:typeId,captionField,valueFields,secondCaptionField,geometryField,geoJSON,mapValueField,mapLabelField,mapLabelMode,mapBarScale} = this.parameters;
116
+ const {engine,legend,axes,chartType:typeId,captionField,valueFields,secondCaptionField,geometryField,geoJSON,mapValueField,mapLabelField,mapLabelMode,mapBarScale} = this.parameters;
116
117
  const revision=++this.#revision;
117
118
  try {
118
119
  this.#connect();
@@ -136,7 +137,7 @@ const ChartView = defineComponent({
136
137
  await this.#renderer.prepare(engine,typeId);
137
138
  if(revision!==this.#revision || !this.#renderer)return;
138
139
  this.control.hidden = false;
139
- const structure=new Bag({engine,chartType:typeId,captionField,valueFields,secondCaptionField,geometryField,mapValueField,mapLabelField,mapLabelMode,mapBarScale});
140
+ const structure=new Bag({engine,legend,axes,chartType:typeId,captionField,valueFields,secondCaptionField,geometryField,mapValueField,mapLabelField,mapLabelMode,mapBarScale});
140
141
  structure.setItem('geoJSON',geoJSON);
141
142
  // The final read: the renderer reads seriesOptions at its address where it hands the values to the engine.
142
143
  await this.#renderer.update(structure, {data:this.#context.sourceNode.data, path:this.#context.attrDatapath('seriesOptions')});
@@ -13,6 +13,7 @@ export class CheckBoxTextEditor {
13
13
  this.toggle.className = 'choice-toggle'; this.toggle.setAttribute('aria-label', 'Show options');
14
14
  this.element = doc.createElement('div'); this.element.className = 'summary-row choice-field';
15
15
  this.element.append(this.input, this.toggle, this.list);
16
+ this.toggle.addEventListener('mousedown', event => event.preventDefault());
16
17
  this.toggle.addEventListener('click', () => owner.openChoices());
17
18
  this.input.addEventListener('input', event => {
18
19
  if (this.locked) return;
@@ -4,6 +4,7 @@ import {positionPopup} from './popup.js';
4
4
  import {CheckBoxTree} from './check-box-tree.js';
5
5
  import {CheckBoxTextEditor} from './check-box-text-editor.js';
6
6
  import {choiceFieldStyles} from './choice-field-styles.js';
7
+ import {trackChoiceFocus} from '../view/choice-focus.js';
7
8
 
8
9
  /** Multiple choices keep the existing group's commit and validation lifecycle. */
9
10
  export function checkBoxChoices(Base) {
@@ -22,6 +23,7 @@ export function checkBoxChoices(Base) {
22
23
  super();
23
24
  const doc = this.ownerDocument;
24
25
  this.#text = new CheckBoxTextEditor(this);
26
+ trackChoiceFocus(this.#text.element);
25
27
  this.summary = this.#text.input; this.summary.hidden = true;
26
28
  this.summary.className = 'summary';
27
29
  this.summary.setAttribute('aria-haspopup', 'dialog');
@@ -58,7 +58,7 @@ export class CheckBoxTree {
58
58
  this.element.inert = Boolean(p.disabled || p.readonly);
59
59
  this.element.setAttribute('aria-disabled', String(this.element.inert));
60
60
  const checks = p.identifier ? {[`checked_${p.identifier}`]:'value'} : {checkedPaths:value};
61
- this.element.projectAttributes({...checks, checkChildren:p.checkChildren,
61
+ this.element.projectAttributes({...checks, checkChildren:p.checkChildren, eagerCheck:p.eagerCheck,
62
62
  labelAttribute:p.labelAttribute ?? null, hideValues:true});
63
63
  }
64
64
  focus() { this.element.shadowRoot.querySelector('[role=treeitem]')?.focus(); }
@@ -1,6 +1,7 @@
1
1
  import {NativeControl} from './bases.js';
2
2
  import {parseChoices} from './choices.js';
3
3
  import {choiceFieldStyles} from './choice-field-styles.js';
4
+ import {trackChoiceFocus} from '../view/choice-focus.js';
4
5
  import {positionPopup} from './popup.js';
5
6
  import {Bag} from '@genrojs/bag';
6
7
 
@@ -25,18 +26,18 @@ export function ChoiceEditor(HTMLElement) {
25
26
  const doc = this.ownerDocument;
26
27
  const style = doc.createElement('style');
27
28
  style.textContent = choiceFieldStyles + `.option{position:relative} #control{width:100%;padding-right:calc(var(--gramlot-choice-toggle-width,1.6em) + .2em)}
28
- #control:focus-visible{outline:1px solid var(--gramlot-border-control,#7a8798);outline-offset:-3px}
29
29
 
30
30
  .choices{min-width:min(var(--gramlot-choice-popup-min-width,0px),var(--gramlot-popup-available-width,100vw));max-width:var(--gramlot-popup-available-width,100vw);position:fixed;inset:auto;margin:0;padding:var(--gramlot-popup-padding,4px);box-sizing:border-box;max-height:min(var(--gramlot-choice-max-height,20rem),var(--gramlot-popup-available-height,100vh));overflow:auto;
31
31
  border:1px solid var(--gramlot-border-control,#aab4c2);border-radius:var(--gramlot-radius-sm,4px);background:var(--gramlot-surface,Canvas);color:var(--gramlot-ink,CanvasText);font:inherit;font-size:var(--gramlot-field-font-size,1em);line-height:1.4;box-shadow:var(--gramlot-shadow,0 3px 9px #0002)}
32
32
  .choices[hidden]{display:none} .choice{min-height:var(--gramlot-touch-target,0px);display:flex;align-items:center;padding:var(--gramlot-choice-item-padding,.25em .5em);border-radius:var(--gramlot-radius-sm,4px);cursor:pointer}
33
- .choice:nth-child(even){background:var(--gramlot-choice-alternate-background,var(--gramlot-surface-subtle,transparent))}
34
- .choice:hover{background:var(--gramlot-selected,Highlight)}
33
+ .choice:nth-child(even){background:var(--gramlot-choice-alternate-background,transparent)}
34
+ .choice:hover:not([aria-selected=true]){background:var(--gramlot-choice-hover-background,var(--gramlot-surface-subtle,transparent))}
35
35
  .choice-detail{margin-inline-start:var(--gramlot-space-3,.75rem);color:var(--gramlot-text-secondary,GrayText)}
36
- .choice[aria-selected=true]{background:var(--gramlot-selected,Highlight);color:var(--gramlot-ink,HighlightText)}`;
36
+ .choice[aria-selected=true]{background:var(--gramlot-selected,Highlight);color:var(--gramlot-ink,HighlightText);box-shadow:inset 0 0 0 1px var(--gramlot-focus-ring,Highlight)}`;
37
37
  this.toggle = doc.createElement('button');
38
38
  this.toggle.className = 'toggle choice-toggle'; this.toggle.type = 'button'; this.toggle.tabIndex = -1;
39
39
  this.control.parentElement.classList.add('choice-field');
40
+ trackChoiceFocus(this.control.parentElement);
40
41
  this.toggle.setAttribute('aria-label', 'Show options');
41
42
  this.control.parentElement.append(this.toggle);
42
43
  this.choices = doc.createElement('div');
@@ -1,4 +1,4 @@
1
- /** Shared field affordance: one field border, an inset transparent chevron. */
1
+ /** Shared dropdown surface and inset chevron. */
2
2
  export const choiceFieldStyles = `
3
3
  .choice-field{position:relative;min-width:0}
4
4
  .choice-field>input{box-sizing:border-box;width:100%;padding-inline-end:calc(var(--gramlot-choice-toggle-width,1.6em) + .4em)}
@@ -10,5 +10,13 @@ export const choiceFieldStyles = `
10
10
  border-block-end:1.5px solid currentColor;transform:translateY(-.1em) rotate(45deg);pointer-events:none}
11
11
  .choice-toggle:disabled{opacity:.5;cursor:default}
12
12
  .choice-toggle:focus-visible{outline:1px solid var(--gramlot-focus-ring,Highlight);outline-offset:-3px}
13
+ .choice-field>:is(input#control,input.summary){border-width:var(--gramlot-choice-border-width,1px)}
14
+ .choice-field>:is(input#control,input.summary):not([aria-invalid=true]){background:var(--gramlot-choice-background,var(--gramlot-field-background,Canvas))}
15
+ .choice-field>input.summary[aria-invalid=true]{background:var(--gramlot-error-background,Canvas)}
16
+ .choice-field:not(.pointer-focus)>:is(input#control,input.summary):focus-visible,
17
+ .choice-field:not(.pointer-focus):has(>.choice-toggle:focus-visible)>:is(input#control,input.summary){
18
+ outline:1px solid var(--gramlot-focus-ring,Highlight);outline-offset:-1px}
19
+ .choice-field.pointer-focus>:is(input#control,input.summary):focus,.choice-field:has(>input)>.choice-toggle:focus{outline:none}
20
+ @media(forced-colors:active){.choice-field>:is(input#control,input.summary){border:1px solid ButtonText}}
13
21
  .choice-field>input::-webkit-calendar-picker-indicator{opacity:0}
14
22
  `;
@@ -8,6 +8,8 @@ import {closeBrackets, closeBracketsKeymap, autocompletion, completionKeymap} fr
8
8
  import {setDiagnostics} from '@codemirror/lint';
9
9
  import {tags} from '@lezer/highlight';
10
10
  import {python} from '@codemirror/lang-python';
11
+ import {gramlotHighlighting} from './code-mirror-gramlot.js';
12
+ import {rust} from '@codemirror/lang-rust';
11
13
  import {javascript} from '@codemirror/lang-javascript';
12
14
  import {json} from '@codemirror/lang-json';
13
15
  import {html} from '@codemirror/lang-html';
@@ -16,8 +18,17 @@ import {xml} from '@codemirror/lang-xml';
16
18
  import {markdown} from '@codemirror/lang-markdown';
17
19
  import {typst_lezer} from 'codemirror-lang-typst/lezer';
18
20
  import {sql} from '@codemirror/lang-sql';
21
+ import {yaml} from '@codemirror/lang-yaml';
19
22
 
20
- const languages = {text: () => [], python, javascript, typescript: () => javascript({typescript:true}), json, html, css, xml, markdown, sql, typst:typst_lezer};
23
+ // Rust macro arguments are token trees. The parser classifies their bare names
24
+ // as identifiers, including the component and attribute names inside gramlot!().
25
+ const rustNames = syntaxHighlighting(HighlightStyle.define([
26
+ {tag:[tags.variableName, tags.propertyName], color:'var(--gramlot-editor-function, #5499cb)'},
27
+ {tag:[tags.typeName, tags.namespace], color:'light-dark(#65428c, #c9a6ee)'},
28
+ {tag:tags.macroName, color:'var(--gramlot-editor-keyword, #9677d9)', fontWeight:'bold'}
29
+ ]));
30
+ const gramlotModes = {'gramlot-py':'python', 'gramlot-js':'javascript', 'gramlot-rs':'rust'};
31
+ const languages = {text: () => [], python, rust: () => [rust(), rustNames], javascript, typescript: () => javascript({typescript:true}), json, html, css, xml, markdown, sql, typst:typst_lezer, yaml};
21
32
  const colors = syntaxHighlighting(HighlightStyle.define([
22
33
  {tag:[tags.keyword, tags.modifier], color:'var(--gramlot-editor-keyword, #9677d9)'},
23
34
  {tag:[tags.string, tags.regexp], color:'var(--gramlot-editor-string, #318f74)'},
@@ -37,8 +48,11 @@ const theme = EditorView.theme({
37
48
  '.cm-textfield, .cm-button': {color:'inherit', background:'var(--gramlot-field-background, Canvas)', borderColor:'var(--gramlot-border-control, GrayText)'},
38
49
  '.cm-search': {fontFamily:'system-ui', fontSize:'13px'}
39
50
  });
40
- function configuration(p) {
41
- return [languages[p.language](), indentUnit.of(' '.repeat(p.indentUnit)),
51
+ function configuration(host) {
52
+ const p = host.parameters;
53
+ const baseLanguage = gramlotModes[p.language];
54
+ return [languages[baseLanguage ?? p.language](),
55
+ baseLanguage ? gramlotHighlighting(host.componentBuilder, p.language) : [], indentUnit.of(' '.repeat(p.indentUnit)),
42
56
  EditorState.tabSize.of(p.indentUnit), EditorState.readOnly.of(Boolean(p.readonly || p.disabled)),
43
57
  EditorView.editable.of(!p.disabled), EditorView.contentAttributes.of({'aria-readonly':String(p.readonly), 'aria-disabled':String(p.disabled), tabindex:p.disabled ? '-1' : '0', 'aria-label':p.lbl || 'Code editor'}),
44
58
  p.lineNumbers ? lineNumbers() : [], p.lineWrapping ? EditorView.lineWrapping : [],
@@ -77,10 +91,10 @@ export function createEditor(host) {
77
91
  if (update.docChanged || update.transactions.some(transaction => transaction.reconfigured)) publishHistory();
78
92
  })];
79
93
  let projecting = false;
80
- const state = doc => EditorState.create({doc, extensions:[options.of(configuration(host.parameters)), ...extensions]});
94
+ const state = doc => EditorState.create({doc, extensions:[options.of(configuration(host)), ...extensions]});
81
95
  const view = new EditorView({state:state(host.readControlValue()), parent:host.control, root:host.shadowRoot});
82
96
  return {view,
83
- configure() {view.dispatch({effects:options.reconfigure(configuration(host.parameters))});},
97
+ configure() {view.dispatch({effects:options.reconfigure(configuration(host))});},
84
98
  replace(value) {
85
99
  const current = view.state.doc.toString();
86
100
  let from = 0, end = current.length, nextEnd = value.length;
@@ -0,0 +1,85 @@
1
+ // Highlight authored component names against the collections of this editor's page.
2
+ import {Prec} from '@codemirror/state';
3
+ import {syntaxTree} from '@codemirror/language';
4
+ import {Decoration, EditorView, ViewPlugin} from '@codemirror/view';
5
+
6
+ const component = Decoration.mark({class: 'cm-gramlot-component'});
7
+ const attribute = Decoration.mark({class: 'cm-gramlot-attribute'});
8
+
9
+ function highlight(view, builder, mode) {
10
+ const marks = [];
11
+ const text = node => view.state.sliceDoc(node.from, node.to);
12
+ function markComponent(name) {
13
+ const tag = builder.schemaTagNames[text(name).toLowerCase()];
14
+ const definition = builder.schema[tag]?._meta?.gramlot_component;
15
+ if (definition) marks.push(component.range(name.from, name.to));
16
+ return definition;
17
+ }
18
+ function markAttribute(name, definition) {
19
+ if (definition && Object.hasOwn(definition.parameters, text(name))) {
20
+ marks.push(attribute.range(name.from, name.to));
21
+ }
22
+ }
23
+ function call(expression) {
24
+ const member = expression.firstChild;
25
+ if (member?.name !== 'MemberExpression' || member.lastChild?.name !== 'PropertyName') return;
26
+ const args = expression.getChild('ArgList');
27
+ if (!args) return;
28
+ const definition = markComponent(member.lastChild);
29
+ if (!definition) return;
30
+ if (mode === 'gramlot-py') {
31
+ for (const key of args.getChildren('VariableName')) {
32
+ if (key.nextSibling?.name === 'AssignOp') markAttribute(key, definition);
33
+ }
34
+ } else {
35
+ for (const object of args.getChildren('ObjectExpression')) {
36
+ for (const prop of object.getChildren('Property')) {
37
+ const key = prop.getChild('PropertyDefinition');
38
+ if (key) markAttribute(key, definition);
39
+ }
40
+ }
41
+ }
42
+ }
43
+ function nextToken(node) {
44
+ let next = node.nextSibling;
45
+ while (next && ['LineComment', 'BlockComment'].includes(next.name)) next = next.nextSibling;
46
+ return next;
47
+ }
48
+ function rustCall(expression) {
49
+ const field = expression.firstChild;
50
+ if (field?.name !== 'FieldExpression' || field.lastChild?.name !== 'FieldIdentifier') return;
51
+ const definition = markComponent(field.lastChild);
52
+ const kwargs = expression.getChild('ArgList')?.getChild('MacroInvocation');
53
+ if (!definition || !kwargs || text(kwargs.firstChild) !== 'kw') return;
54
+ const body = kwargs.getChild('BracedTokens');
55
+ if (!body) return;
56
+ let keyPosition = true;
57
+ for (let key = nextToken(body.firstChild); key; key = nextToken(key)) {
58
+ if (keyPosition && key.name === 'Identifier' && nextToken(key)?.name === ':') {
59
+ markAttribute(key, definition);
60
+ }
61
+ keyPosition = key.name === ',';
62
+ }
63
+ }
64
+ const tree = syntaxTree(view.state);
65
+ tree.iterate({from:view.viewport.from, to:view.viewport.to, enter(ref) {
66
+ if (ref.name !== 'CallExpression') return;
67
+ if (mode === 'gramlot-rs') rustCall(ref.node);
68
+ else call(ref.node);
69
+ }});
70
+ return Decoration.set(marks, true);
71
+ }
72
+
73
+ export function gramlotHighlighting(builder, mode) {
74
+ return [EditorView.baseTheme({
75
+ '.cm-gramlot-component': {fontWeight:'bold', color:'light-dark(#155c72, #8cd8e8)'},
76
+ '.cm-gramlot-attribute': {color:'light-dark(#80552d, #e3be93)'}
77
+ }), Prec.highest(ViewPlugin.fromClass(class {
78
+ constructor(view) { this.decorations = highlight(view, builder, mode); }
79
+ update(update) {
80
+ if (update.docChanged || update.viewportChanged || syntaxTree(update.startState) !== syntaxTree(update.state)) {
81
+ this.decorations = highlight(update.view, builder, mode);
82
+ }
83
+ }
84
+ }, {decorations: plugin => plugin.decorations}))];
85
+ }
@@ -4,7 +4,7 @@ import {defineComponent} from './registry.js';
4
4
  import {Labelbox} from './labelbox.js';
5
5
  import {FieldState} from './field-state.js';
6
6
 
7
- const languages = ['text', 'python', 'javascript', 'typescript', 'json', 'html', 'css', 'xml', 'markdown', 'sql', 'typst'];
7
+ const languages = ['text', 'gramlot-py', 'gramlot-js', 'gramlot-rs', 'python', 'rust', 'javascript', 'typescript', 'json', 'html', 'css', 'xml', 'markdown', 'sql', 'typst', 'yaml'];
8
8
  let engineModule;
9
9
  function EditorControl(HTMLElement) {
10
10
  return class extends controlElement(HTMLElement) {
@@ -29,6 +29,7 @@ function EditorControl(HTMLElement) {
29
29
  });
30
30
  this.control.addEventListener('focusout', () => this.#emit('change'));
31
31
  }
32
+ setSourceContext(context) { this.componentBuilder = context.sourceNode.rootBuilder; }
32
33
  get liveWrites() { return true; }
33
34
  connectedCallback() {
34
35
  const generation = ++this.#generation;
@@ -79,7 +80,7 @@ EditorControl.parameters = {
79
80
  live:{dtype:'B', default:true, binding:'read'}
80
81
  };
81
82
  const toggle = {dtype:'B', default:true, binding:'read'};
82
- export const CodeMirror = defineComponent({name:'codeMirror', tag:'gramlot-code-mirror', base:EditorControl, mixins:[Labelbox,FieldState],
83
+ export const CodeMirror = defineComponent({name:'codeMirror', tag:'gramlot-code-mirror', base:EditorControl, sourceContext:true, mixins:[Labelbox,FieldState],
83
84
  parameters:{value:{dtype:'T', default:'', binding:'twoWay'}, language:{dtype:'T', default:'text', binding:'read', enum:languages},
84
85
  lineNumbers:toggle, lineWrapping:toggle, indentUnit:{dtype:'L',default:4,binding:'read'},
85
86
  fontSize:{dtype:'L',default:14,binding:'read'}, fontFamily:{dtype:'T',default:'monospace',binding:'read'},
@@ -28,7 +28,7 @@ export const DrawingPane = defineComponent({
28
28
  slot{display:contents} ::slotted(gramlot-menu){flex:0 0 56px;box-sizing:border-box;padding:6px;background:var(--gramlot-surface,Canvas);border-right:1px solid var(--gramlot-border-control,#a8b2bf);overflow:hidden}
29
29
  .canvas{display:block;flex:1;width:0;height:100%;min-width:0;min-height:0;background:var(--gramlot-drawing-background,var(--gramlot-surface-subtle,#eee));touch-action:none;user-select:none}
30
30
  .text-editor{position:absolute;z-index:2;min-width:120px;padding:2px 4px;border:1px solid #3977bc;border-radius:3px;background:white;color:#222;box-shadow:0 2px 8px #0003}
31
- .text-editor[hidden]{display:none}.shape{cursor:pointer}.selected{stroke:#1683ff}.selected [data-text-hit]{stroke:#3977bc;stroke-width:1;stroke-dasharray:4 3}`;
31
+ .text-editor[hidden]{display:none}.shape{cursor:pointer}.shape.selected{outline:2px dashed var(--gramlot-action,Highlight);outline-offset:2px}`;
32
32
  this.shadowRoot.append(style);this.control.replaceChildren();
33
33
  this.#editor=d.createElement('input');this.#editor.type='text';this.#editor.className='text-editor';this.#editor.hidden=true;this.#editor.setAttribute('aria-label','Annotation text');
34
34
  this.#svg=d.createElementNS(SVG_NS,'svg');this.#svg.setAttribute('role','img');this.#svg.setAttribute('aria-label','Annotated image');
@@ -101,27 +101,27 @@ export const DrawingPane = defineComponent({
101
101
  this.#tool=this.#state('tool');this.#lastColor=this.#state('color');this.#lastSize=this.#state('size');
102
102
  if(this.parameters.toolbar===false){this.#built=true;return;}
103
103
  const fragment=new builder.source.constructor(null,builder),root=builder.wrapSource(fragment);
104
- const bar=root.menu({node_label:'bar',presentation:'bar',orientation:'vertical',labelPosition:'tooltip',iconSize:20,aria_label:'Image annotations'});
104
+ const bar=root.menu({node_label:'bar',presentation:'bar',orientation:'vertical',labelPosition:'tooltip',icon_size:20,aria_label:'Image annotations'});
105
105
  sourceTarget(bar)._internal.drawingController=this;
106
106
  const paths={select:'M5 3l13 11-6 .5-3 5z',freehand:'M4 20l3.5-.7L19 7.8 16.2 5 4.7 16.5z M14.7 6.5l2.8 2.8',arrow:'M4 19L19 4 M12 4h7v7',circle:'M20 12a8 8 0 1 1-16 0 8 8 0 0 1 16 0z',text:'M4 5h16 M12 5v14 M8 19h8',delete:'M4 7h16 M9 7V4h6v3 M7 7l1 13h8l1-13 M10 10v7 M14 10v7'};
107
107
  const icon=key=>'data:image/svg+xml,'+encodeURIComponent(`<svg xmlns="${SVG_NS}" viewBox="0 0 24 24" fill="none" stroke="#7e93ad" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="${paths[key]}"/></svg>`);
108
108
  for(const [tool,label] of [['select','Select'],['freehand','Draw'],['arrow','Arrow'],['circle','Circle'],['text','Text']]){
109
- bar.menuline({caption:label,tooltip:label,iconSrc:icon(tool),checked:`^${this.#statePath}.tool:={} === '${tool}'`,action:`this.parentBag.parentNode._internal.drawingController.setTool('${tool}')`});
109
+ bar.menuline({caption:label,tooltip:label,icon:icon(tool),checked:`^${this.#statePath}.tool:={} === '${tool}'`,action:`this.parentBag.parentNode._internal.drawingController.setTool('${tool}')`});
110
110
  }
111
111
  bar.contentPane({height:'1px',margin:'6px 4px',background:'var(--gramlot-border-control,#a8b2bf)'});
112
112
  const circleIcon=color=>'data:image/svg+xml,'+encodeURIComponent(`<svg xmlns="${SVG_NS}" viewBox="0 0 24 24"><circle cx="12" cy="12" r="8" fill="${color}" stroke="#8793a3" stroke-width="1.5"/></svg>`);
113
- const colorMenu=bar.menuline({caption:'Color',tooltip:'Color',iconSrc:`^${this.#statePath}.color:='data:image/svg+xml,' + encodeURIComponent('<svg xmlns="${SVG_NS}" viewBox="0 0 24 24"><circle cx="12" cy="12" r="8" fill="' + {} + '" stroke="#8793a3" stroke-width="1.5"/></svg>')`}).menu({aria_label:'Annotation colors'});
113
+ const colorMenu=bar.menuline({caption:'Color',tooltip:'Color',icon:`^${this.#statePath}.color:='data:image/svg+xml,' + encodeURIComponent('<svg xmlns="${SVG_NS}" viewBox="0 0 24 24"><circle cx="12" cy="12" r="8" fill="' + {} + '" stroke="#8793a3" stroke-width="1.5"/></svg>')`}).menu({aria_label:'Annotation colors'});
114
114
  for(const [color,label] of [['#dd2222','Red'],['#e6a700','Yellow'],['#16834a','Green'],['#1677d2','Blue'],['#ffffff','White'],['#202733','Black']]){
115
- colorMenu.menuline({caption:label,iconSrc:circleIcon(color),checked:`^${this.#statePath}.color:={} === '${color}'`,
115
+ colorMenu.menuline({caption:label,icon:circleIcon(color),checked:`^${this.#statePath}.color:={} === '${color}'`,
116
116
  action:`this.SET('${this.#statePath}.color', '${color}');`});
117
117
  }
118
118
  colorMenu.contentPane({padding:'8px'}).colorpicker({value:`^${this.#statePath}.color`,lbl:'Custom color',aria_label:'Color',width:'140px'});
119
119
  const strokeIcon=size=>'data:image/svg+xml,'+encodeURIComponent(`<svg xmlns="${SVG_NS}" viewBox="0 0 24 24"><path d="M4 12h16" stroke="#7e93ad" stroke-width="${size}" stroke-linecap="round"/></svg>`);
120
- const sizeMenu=bar.menuline({caption:'Pen size',tooltip:'Pen size',iconSrc:`^${this.#statePath}.size:='data:image/svg+xml,' + encodeURIComponent('<svg xmlns="${SVG_NS}" viewBox="0 0 24 24"><path d="M4 12h16" stroke="#7e93ad" stroke-width="' + Math.min({}, 12) + '" stroke-linecap="round"/></svg>')`}).menu({aria_label:'Pen size'});
121
- for(const size of [1,3,5,7,12,20])sizeMenu.menuline({caption:`${size} px`,iconSrc:strokeIcon(Math.min(size,12)),checked:`^${this.#statePath}.size:={} === ${size}`,action:`this.SET('${this.#statePath}.size', ${size});`});
120
+ const sizeMenu=bar.menuline({caption:'Pen size',tooltip:'Pen size',icon:`^${this.#statePath}.size:='data:image/svg+xml,' + encodeURIComponent('<svg xmlns="${SVG_NS}" viewBox="0 0 24 24"><path d="M4 12h16" stroke="#7e93ad" stroke-width="' + Math.min({}, 12) + '" stroke-linecap="round"/></svg>')`}).menu({aria_label:'Pen size'});
121
+ for(const size of [1,3,5,7,12,20])sizeMenu.menuline({caption:`${size} px`,icon:strokeIcon(Math.min(size,12)),checked:`^${this.#statePath}.size:={} === ${size}`,action:`this.SET('${this.#statePath}.size', ${size});`});
122
122
  sizeMenu.contentPane({padding:'8px'}).numberTextBox({value:`^${this.#statePath}.size`,lbl:'Custom size',aria_label:'Pen size',dtype:'L',min:1,max:20,width:'140px'});
123
123
  bar.contentPane({flex:'1',min_height:'12px'});
124
- bar.menuline({caption:'Delete',tooltip:'Delete',iconSrc:icon('delete'),action:'this.parentBag.parentNode._internal.drawingController.deleteSelection()'});
124
+ bar.menuline({caption:'Delete',tooltip:'Delete',icon:icon('delete'),action:'this.parentBag.parentNode._internal.drawingController.deleteSelection()'});
125
125
  const app=builder.binding.gramlot,source=app.src.prepareSource(fragment);
126
126
  app.src.renderer.validateCandidate(source);this.#built=true;node.setValue(source);
127
127
  }
@@ -131,7 +131,8 @@ export const DrawingPane = defineComponent({
131
131
  const tool=this.#state('tool');this.#tool=tool;
132
132
  const color=this.#state('color'),size=this.#state('size');
133
133
  const changed=color!==this.#lastColor||size!==this.#lastSize;this.#lastColor=color;this.#lastSize=size;
134
- if(changed&&!this.#syncing)this.#styleSelection();
134
+ if(this.#syncing)return;
135
+ if(changed)this.#styleSelection();
135
136
  this.#render();
136
137
  }
137
138
  #point(event){
@@ -143,17 +144,44 @@ export const DrawingPane = defineComponent({
143
144
  if(event.button!==0||!this.#dimensions)return;const point=this.#point(event);if(!point)return;
144
145
  const id=event.target.closest('[data-id]')?.getAttribute('data-id');
145
146
  if(this.#tool==='select'){
147
+ this.#svg.querySelector('.selected')?.classList.remove('selected');
146
148
  this.#selected=id||null;
147
- if(id){const value=this.#annotations().getItem(id);if(!(value instanceof Bag))throw new TypeError('Annotation must be a Bag');const row=this.#read(value);this.#syncing=true;try{this.#setState('color',row.color);this.#setState('size',row.width);}finally{this.#syncing=false;}this.#gesture={id,start:point,original:row};}
148
- }else if(this.#tool==='text'){
149
+ if(id){
150
+ event.target.closest('[data-id]').classList.add('selected');
151
+ const row=this.#read(this.#annotations().getItem(id));
152
+ this.#syncing=true;
153
+ try{this.#setState('color',row.color);this.#setState('size',row.width);}
154
+ finally{this.#syncing=false;}
155
+ this.#gesture={id,start:point,original:row};
156
+ event.target.setPointerCapture(event.pointerId);
157
+ }
158
+ // Keep the hit shape mounted until a drag starts so the browser can dispatch dblclick.
159
+ return;
160
+ }
161
+ if(this.#tool==='text'){
149
162
  const value=id?this.#annotations().getItem(id):null;
150
163
  this.#editText(value instanceof Bag&&value.getItem('type')==='text'?id:null,point);
151
164
  }else {this.#selected=null;this.#gesture={start:point,current:point,points:[point]};}
152
165
  if(this.#gesture)this.#svg.setPointerCapture(event.pointerId);this.#render();event.preventDefault();
153
166
  }
154
- #move(event){if(!this.#gesture||!this.#dimensions)return;const point=this.#point(event);if(!point)return;this.#gesture.current=point;if(this.#tool==='freehand')this.#gesture.points.push(point);this.#render();}
167
+ #move(event){
168
+ const gesture=this.#gesture;
169
+ if(!gesture||!this.#dimensions)return;
170
+ const point=this.#point(event);
171
+ if(!point)return;
172
+ if(gesture.id&&!gesture.current){
173
+ if(point.x===gesture.start.x&&point.y===gesture.start.y)return;
174
+ this.#svg.setPointerCapture(event.pointerId);
175
+ }
176
+ gesture.current=point;
177
+ if(this.#tool==='freehand')gesture.points.push(point);
178
+ this.#render();
179
+ }
155
180
  #up(event){
156
- if(!this.#gesture)return;this.#move(event);const gesture=this.#gesture;this.#gesture=null;
181
+ if(!this.#gesture)return;
182
+ this.#move(event);
183
+ const gesture=this.#gesture;this.#gesture=null;
184
+ if(gesture.id&&!gesture.current)return;
157
185
  if(gesture.id){const delta={x:gesture.current.x-gesture.start.x,y:gesture.current.y-gesture.start.y};const row=this.#translate(gesture.original,delta);this.#annotations().setItem(gesture.id,new Bag(row));}
158
186
  else {const {start,current,points}=gesture;let row;
159
187
  if(this.#tool==='arrow')row={type:'arrow',x:start.x,y:start.y,x2:current.x,y2:current.y};
@@ -182,6 +210,7 @@ export const DrawingPane = defineComponent({
182
210
  this.#render();
183
211
  }
184
212
  #read(row){
213
+ if(!(row instanceof Bag))throw new TypeError('Annotation must be a Bag');
185
214
  const result=Object.fromEntries(row.getNodes().map(node=>[node.label,node.getValue()]));
186
215
  if(result.type==='freehand')result.points=result.points.getNodes().map(node=>({x:node.getValue().getItem('x'),y:node.getValue().getItem('y')}));
187
216
  return result;
@@ -206,7 +235,7 @@ export const DrawingPane = defineComponent({
206
235
  const [width,height]=this.#dimensions;this.#svg.setAttribute('viewBox',`0 0 ${width} ${height}`);
207
236
  if(this.#url)this.#svg.append(this.#element('image',{href:this.#url,x:0,y:0,width,height,'pointer-events':'none'}));
208
237
  for(const node of this.#annotations().getNodes()){
209
- const value=node.getValue();if(!(value instanceof Bag))throw new TypeError('Annotation must be a Bag');let row=this.#read(value);
238
+ let row=this.#read(node.getValue());
210
239
  if(this.#gesture?.id===node.label&&this.#gesture.current)row=this.#translate(this.#gesture.original,{x:this.#gesture.current.x-this.#gesture.start.x,y:this.#gesture.current.y-this.#gesture.start.y});
211
240
  const shape=this.#shape(row,node.label);this.#svg.append(shape);
212
241
  if(row.type==='text'){const bounds=shape.querySelector('text').getBBox(),hit=shape.querySelector('[data-text-hit]');for(const name of ['x','y','width','height'])hit.setAttribute(name,bounds[name]);}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Toolbar commands of one editor canvas. The canvas is the target of its frame (GC-350 §020):
3
+ * it subscribes to the command topics on its own Source node and writes the state of every
4
+ * menuline of its namespace in the frame (`checked`, `disabled`), in every region and bar.
5
+ */
6
+ import {commandFrame} from '../view/menu-command.js';
7
+ import {SourceBag} from '@genrojs/builders';
8
+
9
+ export class EditorCommands {
10
+ #context;
11
+ #namespace;
12
+ #handlers;
13
+ #handles = [];
14
+
15
+ /**
16
+ * `context` is the canvas source context. `namespace` is the command group of the editor.
17
+ * `handlers` maps each command name to a function that receives the command message.
18
+ */
19
+ constructor(context, namespace, handlers) {
20
+ this.#context = context;
21
+ this.#namespace = namespace;
22
+ this.#handlers = handlers;
23
+ }
24
+
25
+ get source() { return this.#context.sourceNode; }
26
+ get runtime() { return this.source.rootBuilder.binding; }
27
+ get namespace() { return this.#namespace; }
28
+
29
+ connect() {
30
+ if (this.#handles.length) return;
31
+ const subscriptions = this.runtime.subscriptions;
32
+ for (const [topic, handler] of Object.entries(this.#handlers)) {
33
+ this.#handles.push(subscriptions.subscribe(subscriptions.topicFor(this.source, topic), async message => {
34
+ try { await handler(message); } catch (error) { this.#context.reportError(error, 'Editor command'); }
35
+ }));
36
+ }
37
+ }
38
+
39
+ disconnect() {
40
+ for (const handle of this.#handles) this.runtime.subscriptions.unsubscribe(handle);
41
+ this.#handles = [];
42
+ }
43
+
44
+ /** The menulines of this namespace in the canvas frame. Nested frames have their own target. */
45
+ lines() {
46
+ const frame = commandFrame(this.source), prefix = `${this.#namespace}:`, lines = [];
47
+ const visit = node => {
48
+ if (node.nodeTag === 'menuline' && String(node.getAttr('command') ?? '').startsWith(prefix)) lines.push(node);
49
+ if (node.staticValue instanceof SourceBag) for (const child of node.staticValue.getNodes()) {
50
+ if (child.nodeTag !== 'framePane') visit(child);
51
+ }
52
+ };
53
+ if (frame?.staticValue instanceof SourceBag) for (const child of frame.staticValue.getNodes()) visit(child);
54
+ return lines;
55
+ }
56
+
57
+ /**
58
+ * Write the state of each menuline. `stateOf(name, parameters)` gives `{disabled}` and, for a toggle
59
+ * command, `checked`. Only changed attributes are written.
60
+ */
61
+ refresh(stateOf) {
62
+ const prefix = `${this.#namespace}:`;
63
+ for (const line of this.lines()) {
64
+ const state = stateOf(line.getAttr('command').slice(prefix.length), line.getAttr('parameters') ?? {});
65
+ const changed = Object.fromEntries(Object.entries(state).filter(([name, value]) => line.getAttr(name) !== value));
66
+ if (Object.keys(changed).length) line.setAttr(changed);
67
+ }
68
+ }
69
+ }
@@ -5,7 +5,7 @@ export function codeMirrorWithOptions(parent, {datapath, value, language = 'text
5
5
  const defaults = {language, indentUnit:4, fontSize:14, fontFamily:'monospace', lineNumbers:true, lineWrapping:true,
6
6
  folding:true, bracketMatching:true, autoCloseBrackets:true, autoIndent:true, autocompletion:true, highlightActiveLine:true, highlightSelectionMatches:true};
7
7
  for (const [name, setting] of Object.entries(defaults)) pane.dataSetter({destination_path:`.settings.${name}`, value:setting});
8
- const options = pane.contentPane({region:'right', width:'250px', drawer:'close', drawer_label:'Options', drawer_icon:'⚙', drawer_minimize:false,
8
+ const options = pane.contentPane({region:'right', width:'250px', drawer:'close', drawer_label:'Options', drawer_icon:'settings', drawer_minimize:false,
9
9
  padding:'12px', overflow:'auto', class:'gramlot-editor-settings'});
10
10
  options.h3('Editor options');
11
11
  options.filteringSelect({value:'^.settings.language', lbl:'Language', values:'text:Plain text,python:Python,javascript:JavaScript,typescript:TypeScript,json:JSON,html:HTML,css:CSS,xml:XML,markdown:Markdown,sql:SQL,typst:Typst'});
@@ -1,12 +1,14 @@
1
1
  import {defineCollection} from './registry.js';
2
2
  import {CodeMirror} from './code-mirror.js';
3
- import {HtmlEditor} from './html-editor.js';
3
+ import {HtmlEditorCanvas} from './html-editor.js';
4
+ import {registerHtmlEditorCommands} from './html-editor-commands.js';
4
5
  import {HtmlPreview,MarkdownPreview} from './html-preview.js';
5
6
  import {MarkdownEditor} from './markdown-editor.js';
6
7
  import {Terminal} from './terminal.js';
7
8
  export {CodeMirror} from './code-mirror.js';
8
- export {HtmlEditor} from './html-editor.js';
9
+ export {HtmlEditorCanvas} from './html-editor.js';
9
10
  export {HtmlPreview,MarkdownPreview} from './html-preview.js';
10
11
  export {MarkdownEditor} from './markdown-editor.js';
11
12
  export {Terminal} from './terminal.js';
12
- export default defineCollection({name:'editors', components:[CodeMirror,HtmlEditor,HtmlPreview,MarkdownEditor,MarkdownPreview,Terminal]});
13
+ export default defineCollection({name:'editors', components:[CodeMirror,HtmlEditorCanvas,HtmlPreview,MarkdownEditor,MarkdownPreview,Terminal],
14
+ registerCommands:registerHtmlEditorCommands});
@@ -0,0 +1,18 @@
1
+ /** Field cards expose editing handles only on the selection. */
2
+ import {defineComponent} from './registry.js';
3
+ import {trayDefinition} from './tray-base.js';
4
+
5
+ export const FormTrayPane = defineComponent({
6
+ ...trayDefinition, name:'formTrayPane', tag:'gramlot-form-tray-pane',
7
+ implementation: Base => class FormTray extends Base {
8
+ projectCards() {
9
+ super.projectCards();
10
+ for (const box of this.children) {
11
+ const hidden = !box.hasAttribute('data-selected');
12
+ box.labelbox.rotationHandle.hidden = hidden;
13
+ box.labelbox.resizeHandle.hidden = hidden;
14
+ if (hidden && box.labelbox.closeButton) box.labelbox.closeButton.hidden = true;
15
+ }
16
+ }
17
+ }
18
+ });