@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,190 @@
1
+ import {SVG_NS} from '../renderer/attributes.js';
2
+ import {NativeControl} from './bases.js';
3
+ import {FieldState} from './field-state.js';
4
+ import {Labelbox} from './labelbox.js';
5
+ import {numericRange, numericRangeParameters} from './numeric-range.js';
6
+ import {defineComponent} from './registry.js';
7
+
8
+ function svg(doc, tag, attrs) {
9
+ const node = doc.createElementNS(SVG_NS, tag);
10
+ for (const [name, value] of Object.entries(attrs)) node.setAttribute(name, value);
11
+ return node;
12
+ }
13
+
14
+ // Pointer geometry belongs to the illustrated surface. The underlying range still
15
+ // provides the single focus stop, accessible value, keyboard steps and Data events.
16
+ function graphicalRange(Base) {
17
+ return class extends numericRange(Base) {
18
+ #drag;
19
+
20
+ constructor() {
21
+ super();
22
+ const doc = this.ownerDocument;
23
+ const style = doc.createElement('style');
24
+ style.textContent = `
25
+ .option{position:relative;display:inline-flex;max-width:100%;vertical-align:middle;
26
+ border-radius:var(--gramlot-radius-sm,4px);color:var(--gramlot-action,Highlight);
27
+ touch-action:none;user-select:none;cursor:pointer}
28
+ .option:has(.knob){border-radius:50%}
29
+ .option:not(.pointer-focus):has(input:focus-visible){outline:1px solid var(--gramlot-focus-ring,Highlight);outline-offset:-1px}
30
+ .option:has(:disabled){opacity:.45;cursor:default}
31
+ .option input[type=range]{position:absolute;inset:0;margin:0;width:100%;height:100%;opacity:0;pointer-events:none}
32
+ .range-art{display:block;pointer-events:none;max-width:100%}
33
+ .knob{width:5rem;height:5rem;border-radius:50%}
34
+ .dial-track{stroke:var(--gramlot-border-control,GrayText)}
35
+ .dial-face{fill:var(--gramlot-field-background,Canvas);stroke:var(--gramlot-border,GrayText)}
36
+ .dial-value{fill:var(--gramlot-ink,CanvasText);font-family:system-ui;font-weight:600;font-variant-numeric:tabular-nums}
37
+ .rating{border-radius:var(--gramlot-radius-sm,4px);display:inline-flex;align-items:center;min-height:max(2rem,var(--gramlot-touch-target,0px))}
38
+ .rating svg{width:1.65rem;height:1.65rem;stroke-width:1.6;stroke-linejoin:round;stroke:var(--gramlot-border-control,GrayText);fill:none}
39
+ .rating svg[data-filled]{stroke:currentColor;fill:currentColor}
40
+ `;
41
+ this.shadowRoot.append(style);
42
+ this.surface = this.control.parentElement;
43
+ this.surface.append(this.createArt(doc));
44
+ this.control.addEventListener('input', () => this.paint());
45
+ this.control.addEventListener('blur', () => this.surface.classList.remove('pointer-focus'));
46
+ this.control.addEventListener('keydown', event => {
47
+ this.surface.classList.remove('pointer-focus');
48
+ if (this.control.readOnly && ['ArrowLeft','ArrowRight','ArrowUp','ArrowDown','Home','End','PageUp','PageDown'].includes(event.key)) event.preventDefault();
49
+ });
50
+ this.surface.addEventListener('pointerdown', event => {
51
+ if (this.#drag || !event.isPrimary || event.button !== 0 || this.control.disabled || this.control.readOnly) return;
52
+ event.preventDefault();
53
+ this.surface.classList.add('pointer-focus');
54
+ this.control.focus({preventScroll:true});
55
+ this.surface.setPointerCapture(event.pointerId);
56
+ this.#drag = {id:event.pointerId, start:this.control.value};
57
+ this.#move(event);
58
+ });
59
+ this.surface.addEventListener('pointermove', event => this.#move(event));
60
+ this.surface.addEventListener('pointerup', event => {
61
+ if (this.#drag?.id !== event.pointerId) return;
62
+ this.#move(event);
63
+ const changed = this.control.value !== this.#drag.start;
64
+ this.#drag = null;
65
+ if (changed) this.#emit('change');
66
+ });
67
+ for (const type of ['pointercancel','lostpointercapture']) this.surface.addEventListener(type, event => {
68
+ if (this.#drag?.id === event.pointerId) this.#cancel();
69
+ });
70
+ }
71
+ #emit(type) {
72
+ this.control.dispatchEvent(new this.ownerDocument.defaultView.Event(type, {bubbles:true}));
73
+ }
74
+ #move(event) {
75
+ if (this.#drag?.id !== event.pointerId) return;
76
+ const value = this.valueAt(event, this.surface.getBoundingClientRect());
77
+ if (value == null) return;
78
+ const previous = this.control.value;
79
+ this.control.valueAsNumber = value;
80
+ if (this.control.value !== previous) this.#emit('input');
81
+ }
82
+ #cancel() {
83
+ if (!this.#drag) return;
84
+ const {id,start} = this.#drag;
85
+ this.#drag = null;
86
+ if (this.surface.hasPointerCapture(id)) this.surface.releasePointerCapture(id);
87
+ if (this.control.value !== start) {
88
+ this.control.value = start;
89
+ this.#emit('input');
90
+ }
91
+ }
92
+ releaseControl() {
93
+ this.#cancel();
94
+ super.releaseControl();
95
+ }
96
+ projectAttributes(attrs, adapt) {
97
+ const rest = super.projectAttributes(attrs, adapt);
98
+ if (this.control.disabled || this.control.readOnly) this.#cancel();
99
+ this.paint();
100
+ return rest;
101
+ }
102
+ writeControlValue(value) {
103
+ super.writeControlValue(value);
104
+ this.paint();
105
+ }
106
+ };
107
+ }
108
+
109
+ // The value fits a box of 29 units inside the free circle of radius 15.5.
110
+ // A digit of a tabular system-ui font is at most 0.6 em wide, so the font
111
+ // size comes from the number of characters, with a maximum of 12 units.
112
+ // The size is an SVG attribute: a page can replace it with ::part(value).
113
+ const VALUE_WIDTH = 29, VALUE_FONT_SIZE = 12, CHARACTER_WIDTH = 0.6;
114
+
115
+ function valueFontSize(characters) {
116
+ return String(Math.min(VALUE_FONT_SIZE, Math.floor(VALUE_WIDTH / (CHARACTER_WIDTH * characters) * 10) / 10));
117
+ }
118
+
119
+ export const Knob = defineComponent({
120
+ name:'knob', tag:'gramlot-knob', base:NativeControl, mixins:[Labelbox, FieldState], sourceContext:true,
121
+ parameters:{...numericRangeParameters, showValue:{dtype:'B', default:false, binding:'read'}},
122
+ implementation:Base => class extends graphicalRange(Base) {
123
+ createArt(doc) {
124
+ const art = svg(doc,'svg',{class:'range-art knob',viewBox:'0 0 72 72','aria-hidden':true});
125
+ const arc = {d:'M16.201 55.799a28 28 0 1 1 39.598 0',fill:'none','stroke-width':4,'stroke-linecap':'round',pathLength:1};
126
+ this.progress = svg(doc,'path',{...arc,stroke:'currentColor'});
127
+ // The indicator turns on the rim of the face (radius 18 to 22, face radius 23).
128
+ // Its round cap reaches radius 16.5, so the value has a free circle of radius 15.5.
129
+ this.indicator = svg(doc,'path',{d:'M36 14v4',stroke:'currentColor','stroke-width':3,'stroke-linecap':'round'});
130
+ this.number = svg(doc,'text',{class:'dial-value',part:'value',x:36,y:36,'text-anchor':'middle','dominant-baseline':'central'});
131
+ art.append(svg(doc,'path',{...arc,class:'dial-track'}),this.progress,
132
+ svg(doc,'circle',{class:'dial-face',cx:36,cy:36,r:23}),this.indicator,this.number);
133
+ return art;
134
+ }
135
+ valueAt(event, box) {
136
+ const x = event.clientX - box.left - box.width / 2;
137
+ const y = box.top + box.height / 2 - event.clientY;
138
+ if (Math.hypot(x,y) < Math.min(box.width,box.height) * 0.12) return null;
139
+ const angle = Math.atan2(x,y) * 180 / Math.PI;
140
+ const fraction = (Math.max(-135, Math.min(135,angle)) + 135) / 270;
141
+ return Number(this.control.min) + fraction * (Number(this.control.max) - Number(this.control.min));
142
+ }
143
+ paint() {
144
+ const value = this.control.valueAsNumber, min = Number(this.control.min), max = Number(this.control.max);
145
+ const fraction = max > min ? (value - min) / (max - min) : 0;
146
+ this.progress.setAttribute('stroke-dasharray', fraction + ' 1');
147
+ this.indicator.setAttribute('transform', 'rotate(' + (fraction*270-135) + ' 36 36)');
148
+ this.number.textContent = this.parameters.showValue ? value.toLocaleString(this.closest('[lang]')?.lang || this.pageContext?.locale,
149
+ {maximumSignificantDigits:21}) : '';
150
+ this.number.setAttribute('font-size', valueFontSize(this.number.textContent.length));
151
+ }
152
+ }
153
+ });
154
+
155
+ export const StarRating = defineComponent({
156
+ name:'starRating', tag:'gramlot-star-rating', base:NativeControl, mixins:[Labelbox,FieldState], sourceContext:true,
157
+ parameters:{
158
+ value:{dtype:'L', default:0, binding:'twoWay'},
159
+ max:{dtype:'L', default:5, binding:'read', target:'control'}
160
+ },
161
+ implementation:Base => class extends graphicalRange(Base) {
162
+ createArt(doc) {
163
+ this.control.min = '0';
164
+ this.control.step = '1';
165
+ this.stars = doc.createElement('span');
166
+ this.stars.className = 'range-art rating';
167
+ this.stars.setAttribute('aria-hidden','true');
168
+ return this.stars;
169
+ }
170
+ valueAt(event, box) {
171
+ const x = this.matches(':dir(rtl)') ? box.right - event.clientX : event.clientX - box.left;
172
+ const count = this.stars.childElementCount;
173
+ return Math.max(0, Math.min(count, Math.ceil(x * count / box.width)));
174
+ }
175
+ paint() {
176
+ const count = Number(this.control.max);
177
+ if (!Number.isSafeInteger(count) || count < 1) throw new RangeError('starRating max must be a positive integer');
178
+ while (this.stars.childElementCount > count) this.stars.lastElementChild.remove();
179
+ while (this.stars.childElementCount < count) {
180
+ const star = svg(this.ownerDocument, 'svg', {viewBox:'0 0 24 24'});
181
+ star.append(svg(this.ownerDocument, 'path', {
182
+ d:'m12 2.8 2.8 5.7 6.3.9-4.6 4.5 1.1 6.3-5.6-3-5.6 3 1.1-6.3-4.6-4.5 6.3-.9z'
183
+ }));
184
+ this.stars.append(star);
185
+ }
186
+ const value = this.control.valueAsNumber;
187
+ Array.from(this.stars.children).forEach((star,index) => star.toggleAttribute('data-filled', index < value));
188
+ }
189
+ }
190
+ });
@@ -9,9 +9,9 @@ function singleId(id) {
9
9
  export class GridCheckSets {
10
10
  #registrations = [];
11
11
  #connected = false;
12
- constructor(source, body, columns, rowFor, read, selection, view) {
13
- this.source = source; this.body = body; this.columns = columns;
14
- this.rowFor = rowFor; this.read = read; this.selection = selection; this.view = view;
12
+ constructor(source, body, head, columns, rowFor, read, selection, view, windowed) {
13
+ this.source = source; this.body = body; this.head = head; this.columns = columns;
14
+ this.rowFor = rowFor; this.read = read; this.selection = selection; this.view = view; this.windowed = windowed;
15
15
  }
16
16
  path(column) { return this.source.absDatapath(column.checked.slice(1)); }
17
17
  value(column) {
@@ -47,8 +47,42 @@ export class GridCheckSets {
47
47
  input.setAttribute('aria-label', `${column.title ?? column.name}: ${id}`);
48
48
  input.checked = this.contains(column,value,id);
49
49
  }
50
+ /** Header checkbox of a multiple column: it checks or unchecks every row of the current view. */
51
+ headerInput(column, label) {
52
+ const input = this.head.ownerDocument.createElement('input');
53
+ input.type = 'checkbox'; input.className = 'grid-set-check-all'; input.dataset.field = column.field;
54
+ input.setAttribute('aria-label', label);
55
+ return input;
56
+ }
57
+ /** IDs of the rows in the current view: base filter, search and set filter applied. */
58
+ viewIds(column) { return this.view().getRows().map(row => this.id(row,column)); }
59
+ /** Checked when every view row is a member, indeterminate when only some are. A windowed grid has no header checkbox. */
60
+ projectHeaders() {
61
+ for (const input of this.head.querySelectorAll('input.grid-set-check-all')) {
62
+ input.hidden = this.windowed();
63
+ if (input.hidden) continue;
64
+ const column = this.columns().find(c => c.field === input.dataset.field);
65
+ const value = this.value(column);
66
+ const ids = this.viewIds(column), members = ids.filter(id => containsId(value,id)).length;
67
+ input.checked = ids.length > 0 && members === ids.length;
68
+ input.indeterminate = members > 0 && members < ids.length;
69
+ }
70
+ }
71
+ changeAll = event => {
72
+ const input = event.target;
73
+ if (!input.matches('input.grid-set-check-all')) return;
74
+ const column = this.columns().find(c => c.field === input.dataset.field);
75
+ const value = this.value(column), ids = this.viewIds(column);
76
+ const all = ids.length > 0 && ids.every(id => containsId(value,id));
77
+ const current = value === '' ? [] : value.split(',');
78
+ const next = all ? current.filter(id => !ids.includes(id))
79
+ : [...current, ...ids.filter(id => !containsId(value,id))];
80
+ this.source.setRelativeData(column.checked.slice(1),next.join(','));
81
+ this.projectHeaders();
82
+ };
50
83
  refresh = () => {
51
84
  this.filter();
85
+ this.projectHeaders();
52
86
  for (const input of this.body.querySelectorAll('input.grid-set-check')) {
53
87
  const cell = input.closest('td[data-field]');
54
88
  const column = this.columns().find(c => c.field === cell.dataset.field);
@@ -89,9 +123,11 @@ export class GridCheckSets {
89
123
  if (this.#connected) return;
90
124
  this.#connected = true;
91
125
  this.body.addEventListener('change',this.change);
126
+ this.head.addEventListener('change',this.changeAll);
92
127
  }
93
128
  disconnect() {
94
129
  this.body.removeEventListener('change',this.change);
130
+ this.head.removeEventListener('change',this.changeAll);
95
131
  this.#connected = false;
96
132
  this.configure();
97
133
  }
@@ -53,7 +53,7 @@ export class GridFooter {
53
53
  cell(field) { return this.#row.querySelector(`td[data-field="${field}"]`); }
54
54
 
55
55
  /** `footer` is false, true or a caption; `columns` are the displayed columns. */
56
- configure(footer, columns, rowHeaders) {
56
+ configure(footer, columns, rowHeaders, rowDelete) {
57
57
  this.#caption = footer;
58
58
  this.#columns = columns;
59
59
  if (footer === false) this.#frame.remove();
@@ -73,6 +73,11 @@ export class GridFooter {
73
73
  cell.classList.toggle('numeric', Boolean(column.totalize));
74
74
  cells.push(cell);
75
75
  }
76
+ if (rowDelete) {
77
+ const action = document.createElement('td');
78
+ action.setAttribute('role', 'cell');
79
+ cells.push(action);
80
+ }
76
81
  this.#row.replaceChildren(...cells);
77
82
  }
78
83
 
@@ -46,12 +46,12 @@ export class GridHeaderInteraction {
46
46
  }
47
47
  #click = event => {
48
48
  if (this.#suppressClick) { this.#suppressClick = false; return; }
49
- if (event.target.closest('.column-resize, .column-filter')) return;
49
+ if (event.target.closest('.column-resize, .column-filter, .grid-set-check-all')) return;
50
50
  const header = event.target.closest('th[data-field]');
51
51
  if (header) this.#sort(header.dataset.field, event.shiftKey);
52
52
  };
53
53
  #dragStart = event => {
54
- if (event.target.closest('.column-filter')) { event.preventDefault(); return; }
54
+ if (event.target.closest('.column-filter, .grid-set-check-all')) { event.preventDefault(); return; }
55
55
  const header = event.target.closest('th[data-field]');
56
56
  if (!header || this.#gesture) { event.preventDefault(); return; }
57
57
  this.#suppressClick = true;
@@ -149,7 +149,7 @@ export class GridHeaderInteraction {
149
149
  this.#focus(gesture.field);
150
150
  };
151
151
  #key = event => {
152
- if (event.target.closest('.column-filter')) return;
152
+ if (event.target.closest('.column-filter, .grid-set-check-all')) return;
153
153
  if (event.key === 'Escape' && this.#gesture) {
154
154
  this.cancel(); event.preventDefault(); return;
155
155
  }
@@ -2,6 +2,11 @@
2
2
  * A JS stylesheet module keeps the same source usable in Node and browser builds.
3
3
  */
4
4
  export const gridStyles = `
5
+ .row-delete{text-align:center}
6
+ .row-delete button{display:inline-grid;place-items:center;padding:.15em .3em;border:0;border-radius:var(--gramlot-radius-sm,4px);background:transparent;color:inherit;cursor:pointer}
7
+ .row-delete button:hover{background:var(--gramlot-button-hover,ButtonFace)}
8
+ .row-delete button:focus-visible{outline:1px solid var(--gramlot-focus-ring,Highlight);outline-offset:-1px}
9
+ .row-delete img{width:1em;height:1em}
5
10
  .column-filter{position:absolute;inset-inline-end:8px;top:50%;transform:translateY(-50%);border:0;background:transparent;color:inherit;cursor:pointer;padding:2px;margin-inline-start:4px;vertical-align:middle;line-height:0;opacity:.6}
6
11
  th:has(.column-filter){padding-inline-end:28px}
7
12
  .column-filter svg{width:13px;height:13px;fill:none;stroke:currentColor;stroke-width:1.5}
@@ -101,8 +106,7 @@ th:has(.column-filter){padding-inline-end:28px}
101
106
  min-block-size: 0;
102
107
  min-inline-size: 0;
103
108
  overflow: auto;
104
- background: var(--gramlot-surface-subtle, Canvas);
105
- scrollbar-gutter: stable;
109
+ background: var(--gramlot-grid-empty-background, var(--gramlot-surface-subtle, Canvas));
106
110
  overscroll-behavior: contain;
107
111
  overflow-anchor: none;
108
112
  }
@@ -183,12 +187,18 @@ th:has(.column-filter){padding-inline-end:28px}
183
187
  .cell-scroll:focus-visible { outline: 1px solid var(--gramlot-focus-ring, Highlight); outline-offset: -1px; }
184
188
  tbody tr { background: var(--gramlot-grid-background, var(--gramlot-surface, Canvas)); }
185
189
  tbody tr.alternate { background: var(--gramlot-grid-row-alt-background, var(--gramlot-surface-subtle, Canvas)); }
186
- tbody tr[aria-selected=true] { background: var(--gramlot-grid-selected-background, var(--gramlot-selected, Highlight)); }
187
- tbody tr:hover { background: var(--gramlot-grid-row-hover-background, var(--gramlot-selected, Highlight)); }
190
+ tbody tr[aria-selected=true] {
191
+ background: var(--gramlot-grid-selected-background, var(--gramlot-selected, Highlight));
192
+ outline: 2px solid var(--gramlot-action, Highlight);
193
+ outline-offset: -2px;
194
+ }
195
+ tbody tr:hover:not([aria-selected=true]) { background: var(--gramlot-grid-row-hover-background, var(--gramlot-selected, Highlight)); }
188
196
  th[data-field] { padding-inline-end: 14px; cursor: grab; user-select: none; }
189
197
  th[data-field]:hover { background-color: color-mix(in srgb, var(--gramlot-grid-header-background) 92%, var(--gramlot-grid-header-color)); }
190
198
  th:focus-visible, .column-resize:focus-visible { outline: 2px solid var(--gramlot-focus-ring, Highlight); outline-offset: -2px; }
191
199
  .column-caption { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
200
+ .grid-set-check-all { float: inline-start; margin: 0; margin-inline-end: .4em; block-size: 1lh; cursor: pointer; }
201
+ .grid-set-check-all + .column-caption { display: flow-root; }
192
202
  th[data-sort-direction] .column-caption { padding-inline-end: 24px; }
193
203
  .sort-indicator { display: none; position: absolute; inset-inline-end: 14px; top: calc(50% - 7px); inline-size: 14px; block-size: 14px; fill: none; stroke: currentColor; stroke-width: 1.7; }
194
204
  th[data-sort-direction] .sort-indicator { display: inline-block; }
@@ -242,5 +252,20 @@ th:has(.column-filter){padding-inline-end:28px}
242
252
  tbody .filtered-numbering {
243
253
  background: var(--gramlot-grid-filtered-numbering-background, var(--gramlot-warning-background, Mark));
244
254
  }
245
- .empty { text-align: center; color: var(--gramlot-text-secondary, GrayText); }
255
+ .empty { padding: 0; overflow: visible; color: var(--gramlot-text-secondary, GrayText); }
256
+ .empty-text {
257
+ position: sticky;
258
+ inset-inline-start: 0;
259
+ box-sizing: border-box;
260
+ inline-size: var(--grid-viewport-width, 100%);
261
+ padding: var(--gramlot-grid-cell-padding, .3rem .6rem);
262
+ overflow: hidden;
263
+ text-overflow: ellipsis;
264
+ text-align: center;
265
+ }
266
+ /* autoHeight: the rows give the height. A max_height style or the enclosing pane caps it; then the body scrolls. */
267
+ :host([data-auto-height]) { display: flex; flex-direction: column; block-size: auto !important; max-block-size: 100%; }
268
+ :host([data-auto-height]) .control-box { flex: 0 1 auto; block-size: auto; box-sizing: border-box; }
269
+ :host([data-auto-height]) .body-frame { flex: 0 1 auto; }
270
+ :host([data-auto-height]) .body-viewport { min-block-size: var(--gramlot-grid-row-height, 2rem); }
246
271
  `;
@@ -17,12 +17,12 @@ let excelEngine = null;
17
17
 
18
18
  /** Grid toolbar commands of the `grid` namespace, delivered to the frame's target grid by publication. */
19
19
  export const GRID_COMMANDS = Object.freeze({
20
- export: {label:'Export', publish:'export', icon:'⇩', tooltip:'Export the visible rows'},
21
- printRows: {label:'Print', publish:'printRows', icon:'⎙', tooltip:'Print the visible rows'},
20
+ export: {label:'Export', publish:'export', icon:'download', tooltip:'Export the visible rows'},
21
+ printRows: {label:'Print', publish:'printRows', icon:'print', tooltip:'Print the visible rows'},
22
22
  lineNumbers: {label:'Line numbers', publish:'lineNumbers', tooltip:'Show or hide the row numbers'},
23
- addrow: {label:'Add row', publish:'addrow', icon:'+', tooltip:'Add a row'},
24
- duprow: {label:'Duplicate', publish:'duprow', icon:'⧉', tooltip:'Duplicate the selected rows'},
25
- delrow: {label:'Delete', publish:'delrow', icon:'−', tooltip:'Delete the selected rows'},
23
+ addrow: {label:'New row', publish:'addrow', tooltip:'Add a row'},
24
+ duprow: {label:'Duplicate', publish:'duprow', icon:'duplicate', tooltip:'Duplicate the selected rows'},
25
+ delrow: {label:'Delete', publish:'delrow', tooltip:'Delete the selected rows'},
26
26
  });
27
27
 
28
28
  // Commands that change rows: they require at least one editable column.
@@ -33,7 +33,13 @@ const SELECTION_COMMANDS = new Set(['grid:duprow', 'grid:delrow']);
33
33
  /** Register the grid command group on one Gramlot page. */
34
34
  export function registerGridCommands(gramlot) {
35
35
  const group = gramlot.commands.registerGroup('grid', {description:'Grid toolbar tools'});
36
- for (const [name, definition] of Object.entries(GRID_COMMANDS)) group.register(name, definition);
36
+ const italian = gramlot.locale?.split('-')[0].toLowerCase() === 'it';
37
+ const labels = italian ? {
38
+ addrow:{label:'Nuova riga', tooltip:'Aggiungi una riga'},
39
+ delrow:{label:'Cancella', tooltip:'Cancella le righe selezionate'},
40
+ duprow:{label:'Duplica', tooltip:'Duplica le righe selezionate'},
41
+ } : {};
42
+ for (const [name, definition] of Object.entries(GRID_COMMANDS)) group.register(name, {...definition, ...labels[name]});
37
43
  }
38
44
 
39
45
  function csvField(text) {
@@ -206,8 +212,10 @@ export class GridTools {
206
212
  }
207
213
 
208
214
  /** Remove the selected rows at their paths in the store; an editing session records each removal. */
215
+ deleteRow(label) { this.source.data.popNode(this.#rowPath(label)); }
216
+
209
217
  deleteRows() {
210
- for (const label of this.#host.selected().map(node => node.label)) this.source.data.popNode(this.#rowPath(label));
218
+ for (const node of this.#host.selected()) this.deleteRow(node.label);
211
219
  }
212
220
 
213
221
  /** Edit tools declared in the grid's frame require an editable column; selection tools a selection mode. */