@gramlot/gramlot 0.4.0 → 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 (141) 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/bold.svg +4 -0
  6. package/assets/icons/eraser.svg +4 -0
  7. package/assets/icons/horizontal-rule.svg +4 -0
  8. package/assets/icons/image.svg +4 -0
  9. package/assets/icons/indent.svg +4 -0
  10. package/assets/icons/italic.svg +4 -0
  11. package/assets/icons/list-bulleted.svg +4 -0
  12. package/assets/icons/list-numbered.svg +4 -0
  13. package/assets/icons/outdent.svg +4 -0
  14. package/assets/icons/paragraph.svg +4 -0
  15. package/assets/icons/select-all.svg +4 -0
  16. package/assets/icons/strikethrough.svg +4 -0
  17. package/assets/icons/underline.svg +4 -0
  18. package/dist/components/charts/__init__.py +1 -1
  19. package/dist/components/charts/assets/index.js +1 -1
  20. package/dist/components/charts/grammar.json +2032 -72
  21. package/dist/components/editors/__init__.py +1 -1
  22. package/dist/components/editors/assets/collection.js +1 -1
  23. package/dist/components/editors/assets/index.js +1 -1
  24. package/dist/components/editors/assets/libraries/codemirror.js +30 -30
  25. package/dist/components/editors/assets/libraries/jodit.js +452 -448
  26. package/dist/components/editors/commands.json +113 -1
  27. package/dist/components/editors/grammar.json +6 -4
  28. package/dist/components/grid/__init__.py +1 -1
  29. package/dist/components/grid/assets/index.js +1 -1
  30. package/dist/components/grid/grammar.json +61 -0
  31. package/dist/components/inputs/__init__.py +1 -1
  32. package/dist/components/inputs/assets/index.js +1 -1
  33. package/dist/components/inputs/grammar.json +35 -0
  34. package/dist/components/layout/__init__.py +1 -1
  35. package/dist/components/layout/assets/collection.js +1 -0
  36. package/dist/components/layout/assets/index.js +1 -1
  37. package/dist/components/layout/grammar.json +364 -0
  38. package/dist/components/tree/__init__.py +1 -1
  39. package/dist/components/tree/assets/index.js +1 -1
  40. package/dist/components/tree/grammar.json +35 -0
  41. package/dist/gramlot.js +1165 -420
  42. package/dist/gramlot.min.js +125 -100
  43. package/dist/libraries.json +5 -4
  44. package/dist/standard-collections.js +1 -1
  45. package/dist/standard-grammar.js +1 -1
  46. package/package.json +4 -2
  47. package/src/binding/providers.js +2 -1
  48. package/src/binding/remote.js +41 -6
  49. package/src/binding/runtime.js +24 -0
  50. package/src/builder/gramlot-builder.js +52 -18
  51. package/src/builder/source.js +66 -12
  52. package/src/chat.d.ts +1 -0
  53. package/src/chat.js +13 -1
  54. package/src/components/chart-bar3d-options.js +0 -1
  55. package/src/components/chart-boxplot-options.js +1 -1
  56. package/src/components/chart-candlestick-options.js +1 -1
  57. package/src/components/chart-engines/echarts-options.js +6 -5
  58. package/src/components/chart-engines/echarts.js +27 -10
  59. package/src/components/chart-engines/plotly-map.js +1 -1
  60. package/src/components/chart-engines/plotly.js +21 -14
  61. package/src/components/chart-engines/uplot.js +17 -11
  62. package/src/components/chart-engines/vega.js +17 -11
  63. package/src/components/chart-funnel-options.js +1 -1
  64. package/src/components/chart-geographic-options.js +1 -1
  65. package/src/components/chart-heatmap-options.js +1 -1
  66. package/src/components/chart-map-bar3d-options.js +2 -2
  67. package/src/components/chart-map-options.js +2 -2
  68. package/src/components/chart-parallel-options.js +1 -1
  69. package/src/components/chart-radar-options.js +1 -1
  70. package/src/components/chart-renderer.js +6 -1
  71. package/src/components/chart-sankey-options.js +1 -1
  72. package/src/components/chart-spatial-options.js +1 -1
  73. package/src/components/chart-sunburst-options.js +13 -1
  74. package/src/components/chart-theme.js +14 -0
  75. package/src/components/chart-treemap-options.js +1 -1
  76. package/src/components/chart-type-data.js +24 -4
  77. package/src/components/charts.js +7 -6
  78. package/src/components/check-box-tree.js +1 -1
  79. package/src/components/choice-editor.js +3 -3
  80. package/src/components/code-mirror-engine.js +2 -1
  81. package/src/components/code-mirror.js +1 -1
  82. package/src/components/editor-commands.js +69 -0
  83. package/src/components/editors.js +5 -3
  84. package/src/components/form-tray-pane.js +18 -0
  85. package/src/components/graphical-ranges.js +16 -3
  86. package/src/components/grid-check-sets.js +39 -3
  87. package/src/components/grid-header-interaction.js +3 -3
  88. package/src/components/grid-styles.js +19 -3
  89. package/src/components/grid.js +42 -9
  90. package/src/components/html-editor-commands.js +61 -0
  91. package/src/components/html-editor.js +18 -3
  92. package/src/components/inputs.js +1 -0
  93. package/src/components/jodit-engine.js +107 -6
  94. package/src/components/layout.js +3 -2
  95. package/src/components/menus.js +6 -1
  96. package/src/components/selected-container.js +16 -3
  97. package/src/components/tab-bar.js +20 -2
  98. package/src/components/tray-base.js +528 -0
  99. package/src/components/tray-pane.js +41 -518
  100. package/src/components/tree.js +44 -1
  101. package/src/components/typed-editor.js +5 -2
  102. package/src/editing-session.js +2 -1
  103. package/src/ide-runtime.js +3 -1
  104. package/src/index-page-runtime.js +11 -3
  105. package/src/index.d.ts +2 -1
  106. package/src/index.js +2 -1
  107. package/src/libraries.js +4 -4
  108. package/src/object-extract.d.ts +7 -0
  109. package/src/object-extract.js +31 -0
  110. package/src/renderer/attributes.js +1 -1
  111. package/src/renderer/gramlot-renderer.d.ts +2 -2
  112. package/src/server/chat.d.ts +3 -1
  113. package/src/server/chat.js +17 -6
  114. package/src/server/gramlot-server.js +5 -1
  115. package/src/server/index-page.js +27 -8
  116. package/src/server/toolbar-icon-name.d.ts +17 -0
  117. package/src/view/labelbox.js +6 -1
  118. package/src/visual-editor.d.ts +1 -0
  119. package/src/visual-editor.js +4 -3
  120. package/themes/gramlot-base/theme.css +7 -0
  121. package/themes/gramlot-index/icons/align-center.svg +4 -0
  122. package/themes/gramlot-index/icons/align-justify.svg +4 -0
  123. package/themes/gramlot-index/icons/align-left.svg +4 -0
  124. package/themes/gramlot-index/icons/align-right.svg +4 -0
  125. package/themes/gramlot-index/icons/bold.svg +4 -0
  126. package/themes/gramlot-index/icons/eraser.svg +4 -0
  127. package/themes/gramlot-index/icons/horizontal-rule.svg +4 -0
  128. package/themes/gramlot-index/icons/image.svg +4 -0
  129. package/themes/gramlot-index/icons/indent.svg +4 -0
  130. package/themes/gramlot-index/icons/italic.svg +4 -0
  131. package/themes/gramlot-index/icons/list-bulleted.svg +4 -0
  132. package/themes/gramlot-index/icons/list-numbered.svg +4 -0
  133. package/themes/gramlot-index/icons/outdent.svg +4 -0
  134. package/themes/gramlot-index/icons/paragraph.svg +4 -0
  135. package/themes/gramlot-index/icons/select-all.svg +4 -0
  136. package/themes/gramlot-index/icons/strikethrough.svg +4 -0
  137. package/themes/gramlot-index/icons/underline.svg +4 -0
  138. package/themes/gramlot-index/icons.json +17 -0
  139. package/themes/gramlot-index/theme.css +3 -0
  140. package/tools/gramlot-tools-inspector.js +11 -3
  141. package/src/builder/chart-icon.js +0 -2
@@ -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
+ }
@@ -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
+ });
@@ -33,7 +33,7 @@ function graphicalRange(Base) {
33
33
  .knob{width:5rem;height:5rem;border-radius:50%}
34
34
  .dial-track{stroke:var(--gramlot-border-control,GrayText)}
35
35
  .dial-face{fill:var(--gramlot-field-background,Canvas);stroke:var(--gramlot-border,GrayText)}
36
- .dial-value{fill:var(--gramlot-ink,CanvasText);font:600 12px system-ui;font-variant-numeric:tabular-nums}
36
+ .dial-value{fill:var(--gramlot-ink,CanvasText);font-family:system-ui;font-weight:600;font-variant-numeric:tabular-nums}
37
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
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
39
  .rating svg[data-filled]{stroke:currentColor;fill:currentColor}
@@ -106,6 +106,16 @@ function graphicalRange(Base) {
106
106
  };
107
107
  }
108
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
+
109
119
  export const Knob = defineComponent({
110
120
  name:'knob', tag:'gramlot-knob', base:NativeControl, mixins:[Labelbox, FieldState], sourceContext:true,
111
121
  parameters:{...numericRangeParameters, showValue:{dtype:'B', default:false, binding:'read'}},
@@ -114,8 +124,10 @@ export const Knob = defineComponent({
114
124
  const art = svg(doc,'svg',{class:'range-art knob',viewBox:'0 0 72 72','aria-hidden':true});
115
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};
116
126
  this.progress = svg(doc,'path',{...arc,stroke:'currentColor'});
117
- this.indicator = svg(doc,'path',{d:'M36 16v5',stroke:'currentColor','stroke-width':3,'stroke-linecap':'round'});
118
- this.number = svg(doc,'text',{class:'dial-value',x:36,y:40,'text-anchor':'middle'});
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'});
119
131
  art.append(svg(doc,'path',{...arc,class:'dial-track'}),this.progress,
120
132
  svg(doc,'circle',{class:'dial-face',cx:36,cy:36,r:23}),this.indicator,this.number);
121
133
  return art;
@@ -135,6 +147,7 @@ export const Knob = defineComponent({
135
147
  this.indicator.setAttribute('transform', 'rotate(' + (fraction*270-135) + ' 36 36)');
136
148
  this.number.textContent = this.parameters.showValue ? value.toLocaleString(this.closest('[lang]')?.lang || this.pageContext?.locale,
137
149
  {maximumSignificantDigits:21}) : '';
150
+ this.number.setAttribute('font-size', valueFontSize(this.number.textContent.length));
138
151
  }
139
152
  }
140
153
  });
@@ -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
  }
@@ -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
  }
@@ -106,8 +106,7 @@ th:has(.column-filter){padding-inline-end:28px}
106
106
  min-block-size: 0;
107
107
  min-inline-size: 0;
108
108
  overflow: auto;
109
- background: var(--gramlot-surface-subtle, Canvas);
110
- scrollbar-gutter: stable;
109
+ background: var(--gramlot-grid-empty-background, var(--gramlot-surface-subtle, Canvas));
111
110
  overscroll-behavior: contain;
112
111
  overflow-anchor: none;
113
112
  }
@@ -198,6 +197,8 @@ th:has(.column-filter){padding-inline-end:28px}
198
197
  th[data-field]:hover { background-color: color-mix(in srgb, var(--gramlot-grid-header-background) 92%, var(--gramlot-grid-header-color)); }
199
198
  th:focus-visible, .column-resize:focus-visible { outline: 2px solid var(--gramlot-focus-ring, Highlight); outline-offset: -2px; }
200
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; }
201
202
  th[data-sort-direction] .column-caption { padding-inline-end: 24px; }
202
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; }
203
204
  th[data-sort-direction] .sort-indicator { display: inline-block; }
@@ -251,5 +252,20 @@ th:has(.column-filter){padding-inline-end:28px}
251
252
  tbody .filtered-numbering {
252
253
  background: var(--gramlot-grid-filtered-numbering-background, var(--gramlot-warning-background, Mark));
253
254
  }
254
- .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); }
255
271
  `;
@@ -22,6 +22,20 @@ import {gridSearch} from './grid-search.js';
22
22
  import {SearchBox} from './grid-search-box.js';
23
23
  import structureGrammar from './grid-grammar.json' with {type: 'json'};
24
24
 
25
+ // Built-in texts by language of the page locale; English when the language has none.
26
+ const TEXTS = {
27
+ en: {empty:'No rows', reorder:'Drag to reorder',
28
+ sort:'Click: ascending / descending · Shift-click: add or reverse this column without changing the others · Numbers show sort priority · Drag to reorder',
29
+ resizeColumn:'Drag to resize · Arrow keys adjust width',
30
+ resizeRow:'Drag to resize row · Double-click or Home resets · Arrow keys adjust height', deleteRow:'Delete row',
31
+ checkAll:'Check or uncheck all rows'},
32
+ it: {empty:'Nessuna riga', reorder:'Trascina per riordinare',
33
+ sort:'Clic: crescente / decrescente · Maiusc-clic: aggiunge o inverte questa colonna senza cambiare le altre · I numeri indicano la priorità di ordinamento · Trascina per riordinare',
34
+ resizeColumn:'Trascina per ridimensionare · Le frecce regolano la larghezza',
35
+ resizeRow:'Trascina per ridimensionare la riga · Doppio clic o Home ripristina · Le frecce regolano l\u2019altezza', deleteRow:'Cancella riga',
36
+ checkAll:'Seleziona o deseleziona tutte le righe'},
37
+ };
38
+
25
39
  /** First grid: explicit Bag row representation and a separately observable Data struct. */
26
40
  export const Grid = defineComponent({
27
41
  name: 'grid', tag: 'gramlot-grid', base: Container, sourceContext: true, subTags: 'struct,div',
@@ -32,6 +46,8 @@ export const Grid = defineComponent({
32
46
  storepath: {dtype: 'T'}, structpath: {dtype: 'T'}, rowMode: {dtype: 'T'},
33
47
  delrow: {dtype:'T', nullable:true, default:null},
34
48
  delrow_label: {dtype:'T', nullable:true, default:null, binding:'read'},
49
+ emptyText: {dtype:'T', nullable:true, default:null, binding:'read'},
50
+ autoHeight: {dtype:'B', default:false, binding:'read'},
35
51
  rowHeaders: {dtype:'B', default:false, binding:'read'},
36
52
  footer: {dtype:['B','T'], default:false, binding:'read'},
37
53
  selectionMode: {dtype:'T', default:'multi', binding:'read'},
@@ -255,6 +271,11 @@ export const Grid = defineComponent({
255
271
  if (this.control.style.getPropertyValue('--grid-scrollbar-width') !== width) {
256
272
  this.control.style.setProperty('--grid-scrollbar-width', width);
257
273
  }
274
+ // clientWidth rounds a fractional width; a box wider than the real width adds a horizontal scrollbar.
275
+ const visible = `${Math.floor(this.#bodyViewport.getBoundingClientRect().width) - gutter}px`;
276
+ if (this.control.style.getPropertyValue('--grid-viewport-width') !== visible) {
277
+ this.control.style.setProperty('--grid-viewport-width', visible);
278
+ }
258
279
  this.#sizeRowHeader();
259
280
  for (const handle of this.#head.querySelectorAll('.column-resize')) {
260
281
  handle.setAttribute('aria-valuenow', String(Math.round(handle.parentElement.getBoundingClientRect().width)));
@@ -410,11 +431,11 @@ export const Grid = defineComponent({
410
431
  parameters:() => this.parameters, document:this.ownerDocument});
411
432
  if (this.isConnected) this.#tools.connect();
412
433
  this.#columnFilters.setSourceContext(context);
413
- this.#checkSets = new GridCheckSets(context.sourceNode, this.#body,
434
+ this.#checkSets = new GridCheckSets(context.sourceNode, this.#body, this.#head,
414
435
  () => this.#structure?.columns ?? [],
415
436
  element => { const label = this.#labelOf(element); return label === null ? undefined : this.#rowNodes([label])[0]; },
416
437
  (node,field) => this.#collectionView.value(node,field),
417
- () => this.parameters.setFilter, () => this.#collectionView);
438
+ () => this.parameters.setFilter, () => this.#collectionView, () => this.#windowInfo() !== null);
418
439
  if (this.isConnected) this.#checkSets.connect();
419
440
  this.#cellEditor = new GridCellEditor(this, context, (row, field) => this.#rows.get(row)?.querySelector(`td[data-field="${field}"]`),
420
441
  () => ({labels:() => this.#collectionStore().getRows().map(row => row.label), window:this.#windowInfo()}),
@@ -542,6 +563,8 @@ export const Grid = defineComponent({
542
563
  // View values (#, += and their dependents) derive from the order: they are not searchable.
543
564
  gridSearch(this.#context.sourceNode).update(this.#collectionView,
544
565
  model.columns.filter(column => !column.check && !this.#formulas.viewFields.has(column.field)));
566
+ // The grid takes the height of its rows; a max_height style caps it and the body scrolls.
567
+ this.toggleAttribute('data-auto-height', this.parameters.autoHeight);
545
568
  const rowHeaders = this.parameters.rowHeaders || this.parameters.rowResize;
546
569
  const signature = JSON.stringify([model.groups, rowHeaders, this.parameters.delrow, this.parameters.delrow_label, this.parameters.columnFilters, this.parameters.footer]);
547
570
  this.#rowHeaders = rowHeaders;
@@ -554,6 +577,7 @@ export const Grid = defineComponent({
554
577
  this.#declareDerived(structureChanged);
555
578
  this.#columnFilters.update(this.#collectionView, model.columns, this.parameters.columnFilters, this.#context.format);
556
579
  this.#renderSort();
580
+ this.#checkSets.projectHeaders();
557
581
  this.#renderWindow(true);
558
582
  this.#renderSelection();
559
583
  this.control.setAttribute('aria-colcount', String(this.#columnCount(model.columns)));
@@ -689,10 +713,11 @@ export const Grid = defineComponent({
689
713
  const caption = doc.createElement('span');
690
714
  caption.className = 'column-caption'; caption.textContent = text; cell.replaceChildren(caption);
691
715
  const column = model.columns[index];
716
+ if (column.check === 'multiple') cell.prepend(this.#checkSets.headerInput(column, `${column.title ?? column.name}: ${this.#texts().checkAll}`));
692
717
  cell.dataset.field = column.field;
693
718
  cell.draggable = true; cell.tabIndex = 0;
694
719
  cell.setAttribute('aria-label', column.title ?? column.name);
695
- cell.title = column.check ? (column.title ?? column.name) + ' · Drag to reorder' : 'Click: ascending / descending · Shift-click: add or reverse this column without changing the others · Numbers show sort priority · Drag to reorder';
720
+ cell.title = column.check ? `${column.title ?? column.name} · ${this.#texts().reorder}` : this.#texts().sort;
696
721
  const indicator = doc.createElementNS(SVG_NS, 'svg');
697
722
  indicator.classList.add('sort-indicator'); indicator.setAttribute('viewBox', '0 0 16 16');
698
723
  indicator.setAttribute('aria-hidden', 'true');
@@ -705,7 +730,7 @@ export const Grid = defineComponent({
705
730
  handle.setAttribute('aria-orientation', 'vertical');
706
731
  handle.setAttribute('aria-valuemin', '40');
707
732
  handle.setAttribute('aria-label', `Resize ${column.name}`);
708
- handle.title = 'Drag to resize · Arrow keys adjust width';
733
+ handle.title = this.#texts().resizeColumn;
709
734
  cell.append(handle);
710
735
  }
711
736
  return cell;
@@ -724,7 +749,7 @@ export const Grid = defineComponent({
724
749
  handle.className = 'column-resize'; handle.tabIndex = 0;
725
750
  handle.setAttribute('role', 'separator'); handle.setAttribute('aria-orientation', 'vertical');
726
751
  handle.setAttribute('aria-label', 'Resize row numbers');
727
- handle.title = 'Drag to resize · Arrow keys adjust width';
752
+ handle.title = this.#texts().resizeColumn;
728
753
  corner.append(probe, handle); top.append(corner);
729
754
  }
730
755
  let index = 0;
@@ -787,7 +812,11 @@ export const Grid = defineComponent({
787
812
  }
788
813
 
789
814
  #deleteCaption() {
790
- return this.parameters.delrow_label ?? (this.#context.locale.split('-')[0].toLowerCase() === 'it' ? 'Cancella riga' : 'Delete row');
815
+ return this.parameters.delrow_label ?? this.#texts().deleteRow;
816
+ }
817
+ #texts() {
818
+ const language = this.#context.locale.split('-')[0].toLowerCase();
819
+ return TEXTS[language] ?? TEXTS.en;
791
820
  }
792
821
 
793
822
  #renderRowAction(tr, label, columnCount) {
@@ -854,7 +883,7 @@ export const Grid = defineComponent({
854
883
  handle.className = 'row-height-handle'; handle.tabIndex = 0;
855
884
  handle.setAttribute('role', 'separator');
856
885
  handle.setAttribute('aria-orientation', 'horizontal');
857
- handle.title = 'Drag to resize row · Double-click or Home resets · Arrow keys adjust height';
886
+ handle.title = this.#texts().resizeRow;
858
887
  heading.append(handle);
859
888
  }
860
889
  handle.setAttribute('aria-label', `Resize row ${start + keep.size + 1}`);
@@ -881,7 +910,7 @@ export const Grid = defineComponent({
881
910
  if (capped) content.tabIndex = 0; else content.removeAttribute('tabindex');
882
911
  td.style.textAlign = column.align;
883
912
  td.style.whiteSpace = column.white_space ?? '';
884
- td.style.overflowWrap = column.white_space === 'pre-wrap' || column.white_space === 'normal' ? 'anywhere' : '';
913
+ td.style.overflowWrap = column.white_space === 'pre-wrap' || column.white_space === 'normal' ? 'break-word' : '';
885
914
  td.setAttribute('aria-colindex', String(index + 1 + offset));
886
915
  td.classList.toggle('numeric', ['L', 'R', 'N'].includes(column.dtype));
887
916
  if (tr.cells[index + offset] !== td) tr.insertBefore(td, tr.cells[index + offset] ?? null);
@@ -902,7 +931,11 @@ export const Grid = defineComponent({
902
931
  const tr = this.ownerDocument.createElement('tr'), td = this.ownerDocument.createElement('td');
903
932
  tr.setAttribute('role', 'row'); tr.setAttribute('aria-rowindex', String(this.#headerRows + 1));
904
933
  td.setAttribute('role', 'cell'); td.setAttribute('aria-colspan', String(this.#columnCount(columns)));
905
- td.className = 'empty'; td.colSpan = this.#columnCount(columns); td.textContent = 'No rows'; tr.append(td); this.#body.append(tr);
934
+ td.className = 'empty'; td.colSpan = this.#columnCount(columns);
935
+ // The text box has the visible width and stays at the left edge, so the text is centred on what the user sees.
936
+ const text = this.ownerDocument.createElement('div');
937
+ text.className = 'empty-text'; text.textContent = this.parameters.emptyText ?? this.#texts().empty;
938
+ td.append(text); tr.append(td); this.#body.append(tr);
906
939
  }
907
940
  }
908
941
  #renderCells(row, cells, node) {
@@ -0,0 +1,61 @@
1
+ /** Commands of the `htmlEditor` namespace, delivered by publication to the frame's htmlEditorCanvas. */
2
+ export const HTML_EDITOR_COMMANDS = Object.freeze({
3
+ undo: {label:'Undo', publish:'undo', icon:'undo'},
4
+ redo: {label:'Redo', publish:'redo', icon:'redo'},
5
+ paragraph: {label:'Paragraph', publish:'paragraph', icon:'paragraph', tooltip:'Block format'},
6
+ bold: {label:'Bold', publish:'bold', icon:'bold'},
7
+ italic: {label:'Italic', publish:'italic', icon:'italic'},
8
+ underline: {label:'Underline', publish:'underline', icon:'underline'},
9
+ strikethrough: {label:'Strikethrough', publish:'strikethrough', icon:'strikethrough'},
10
+ color: {label:'Color', publish:'color', icon:'palette', tooltip:'Text and background color'},
11
+ eraser: {label:'Clear formatting', publish:'eraser', icon:'eraser'},
12
+ ul: {label:'Bulleted list', publish:'ul', icon:'list-bulleted'},
13
+ ol: {label:'Numbered list', publish:'ol', icon:'list-numbered'},
14
+ outdent: {label:'Decrease indent', publish:'outdent', icon:'outdent'},
15
+ indent: {label:'Increase indent', publish:'indent', icon:'indent'},
16
+ align: {label:'Align', publish:'align', icon:'align-left'},
17
+ link: {label:'Link', publish:'link', icon:'link', tooltip:'Insert or edit a link'},
18
+ image: {label:'Image', publish:'image', icon:'image', tooltip:'Insert an image'},
19
+ table: {label:'Table', publish:'table', icon:'table', tooltip:'Insert a table'},
20
+ hr: {label:'Horizontal line', publish:'hr', icon:'horizontal-rule'},
21
+ find: {label:'Find', publish:'find', icon:'search', tooltip:'Find and replace'},
22
+ selectall: {label:'Select all', publish:'selectall', icon:'select-all'},
23
+ });
24
+
25
+ /** Block formats of `htmlEditor:paragraph`, by `tag` parameter, in menu order. */
26
+ export const HTML_EDITOR_BLOCKS = Object.freeze({p:'Paragraph', h1:'Heading 1', h2:'Heading 2', h3:'Heading 3',
27
+ h4:'Heading 4', blockquote:'Quote', pre:'Code'});
28
+
29
+ /** Alignments of `htmlEditor:align`, by `value` parameter, with their captions and icons. */
30
+ export const HTML_EDITOR_ALIGNMENTS = Object.freeze({left:['Left', 'align-left'], center:['Center', 'align-center'],
31
+ right:['Right', 'align-right'], justify:['Justify', 'align-justify']});
32
+
33
+ /**
34
+ * The standard toolbar, in order: a command name, `-` for a divider, or a submenu
35
+ * `[name, parameter, choices]` with one line of the command for each choice.
36
+ */
37
+ export const HTML_EDITOR_TOOLBAR = Object.freeze(['undo', 'redo', '-', ['paragraph', 'tag', 'blocks'], 'bold', 'italic',
38
+ 'underline', 'strikethrough', 'color', 'eraser', '-', 'ul', 'ol', 'outdent', 'indent', ['align', 'value', 'alignments'],
39
+ '-', 'link', 'image', 'table', 'hr', '-', 'find', 'selectall']);
40
+
41
+ /** Register the htmlEditor command group on one Gramlot page. */
42
+ export function registerHtmlEditorCommands(gramlot) {
43
+ const group = gramlot.commands.registerGroup('htmlEditor', {description:'HTML editor toolbar commands'});
44
+ for (const [name, definition] of Object.entries(HTML_EDITOR_COMMANDS)) group.register(name, definition);
45
+ }
46
+
47
+ /** Compose the standard toolbar lines in `bar`, a `menu(presentation="bar")` Source node. */
48
+ export function htmlEditorToolbar(bar) {
49
+ const choices = {blocks:Object.fromEntries(Object.entries(HTML_EDITOR_BLOCKS).map(([key, caption]) => [key, [caption, null]])),
50
+ alignments:HTML_EDITOR_ALIGNMENTS};
51
+ HTML_EDITOR_TOOLBAR.forEach((entry, index) => {
52
+ if (entry === '-') { bar.menuline('-', {node_label:`divider_${index}`}); return; }
53
+ if (typeof entry === 'string') { bar.menuline({command:`htmlEditor:${entry}`, node_label:entry}); return; }
54
+ const [name, parameter, list] = entry, definition = HTML_EDITOR_COMMANDS[name];
55
+ const menu = bar.menuline({caption:definition.label, icon:definition.icon, node_label:name}).menu();
56
+ for (const [key, [caption, icon]] of Object.entries(choices[list])) {
57
+ menu.menuline({command:`htmlEditor:${name}`, caption, parameters:{[parameter]:key}, node_label:key,
58
+ ...(icon === null ? {} : {icon})});
59
+ }
60
+ });
61
+ }
@@ -3,6 +3,8 @@ import {loadLibrary} from '../libraries.js';
3
3
  import {defineComponent} from './registry.js';
4
4
  import {Labelbox} from './labelbox.js';
5
5
  import {FieldState} from './field-state.js';
6
+ import {EditorCommands} from './editor-commands.js';
7
+ import {HTML_EDITOR_COMMANDS} from './html-editor-commands.js';
6
8
 
7
9
  let engineModule;
8
10
  function HtmlControl(HTMLElement) {
@@ -22,7 +24,11 @@ function HtmlControl(HTMLElement) {
22
24
  });
23
25
  }
24
26
  get liveWrites() {return true;}
25
- connectedCallback() {this.load();}
27
+ setSourceContext(context) {
28
+ this.commands=new EditorCommands(context,'htmlEditor',Object.fromEntries(Object.keys(HTML_EDITOR_COMMANDS)
29
+ .map(name=>[name,message=>this.engine?.execute(name,message)])));
30
+ }
31
+ connectedCallback() {this.commands.connect();this.load();}
26
32
  load() {
27
33
  const generation=++this.#generation;
28
34
  this.engine?.destroy();this.engine=null;
@@ -31,6 +37,7 @@ function HtmlControl(HTMLElement) {
31
37
  if (generation!==this.#generation || !this.isConnected) return;
32
38
  this.control.textContent='';
33
39
  this.engine=module.createHtmlEditor(this);
40
+ this.editorStateChanged();
34
41
  }).catch(error=>{
35
42
  if (generation!==this.#generation) return;
36
43
  this.control.textContent=`HTML editor could not start: ${error.message}`;
@@ -57,13 +64,21 @@ function HtmlControl(HTMLElement) {
57
64
  this.#value=value;
58
65
  this.control.dispatchEvent(new this.ownerDocument.defaultView.Event('input',{bubbles:true}));
59
66
  }
67
+ /** Write the state of the frame's htmlEditor commands. Called by the engine after a selection or history change. */
68
+ editorStateChanged() {if(this.engine)this.commands.refresh((name,parameters)=>this.engine.commandState(name,parameters));}
69
+ /** The element where a command popup opens: the activated menuline, or the editing area when it is not shown (toolbar overflow). */
70
+ commandAnchor(sender) {
71
+ const element=this.commands.runtime.renderer.getDomNode(sender);
72
+ return element?.getClientRects().length ? element : this.control;
73
+ }
60
74
  editorBlurred() {this.control.dispatchEvent(new this.ownerDocument.defaultView.Event('change',{bubbles:true}));}
61
75
  undo() {return this.engine ? this.engine.undo() : false;}
62
76
  redo() {return this.engine ? this.engine.redo() : false;}
63
77
  focus() {if (!this.parameters.disabled) this.engine?.focus();}
64
- releaseControl() {++this.#generation;this.engine?.destroy();this.engine=null;super.releaseControl();}
78
+ releaseControl() {++this.#generation;this.commands.disconnect();this.engine?.destroy();this.engine=null;super.releaseControl();}
65
79
  };
66
80
  }
67
81
  HtmlControl.parameters={disabled:{dtype:'B',default:false,binding:'read'},readonly:{dtype:'B',default:false,binding:'read'},live:{dtype:'B',default:true,binding:'read'}};
68
- export const HtmlEditor=defineComponent({name:'htmlEditor',tag:'gramlot-html-editor',base:HtmlControl,mixins:[Labelbox,FieldState],
82
+ /** The editing area of `htmlEditor`, which composes it in the center of a framePane with the htmlEditor toolbar. */
83
+ export const HtmlEditorCanvas=defineComponent({name:'htmlEditorCanvas',tag:'gramlot-html-editor-canvas',base:HtmlControl,sourceContext:true,mixins:[Labelbox,FieldState],
69
84
  parameters:{value:{dtype:'T',default:'',binding:'twoWay'}},implementation:Base=>class extends Base {}});
@@ -311,6 +311,7 @@ export const CheckBoxText = defineComponent({
311
311
  cols: {dtype: 'L', default: 1, binding: 'read'},
312
312
  popup: {dtype: 'B', default: false, binding: 'read'},
313
313
  hierarchical: {dtype: 'B', default: false, binding: 'read'},
314
+ eagerCheck: {dtype: 'B', default: false, binding: 'read'},
314
315
  checkChildren: {dtype: 'B', default: true, binding: 'read'},
315
316
  identifier: {dtype: 'T', binding: 'read'},
316
317
  labelAttribute: {dtype: 'T', binding: 'read'},