@gramlot/gramlot 0.3.20 → 0.3.24

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 (102) hide show
  1. package/dist/components/chat/__init__.py +13 -0
  2. package/dist/components/chat/assets/collection.js +9 -0
  3. package/dist/components/chat/assets/index.js +3 -0
  4. package/dist/components/chat/commands.json +7 -0
  5. package/dist/components/chat/grammar.json +48 -0
  6. package/dist/components/editors/__init__.py +2 -2
  7. package/dist/components/editors/assets/collection.js +22 -120909
  8. package/dist/components/editors/assets/index.js +2 -1
  9. package/dist/components/editors/assets/modules/chunk-AU4HFPIY.js +1 -0
  10. package/dist/components/editors/assets/modules/chunk-MMJXUHRQ.js +3 -0
  11. package/dist/components/editors/assets/modules/chunk-OCFLP2K4.js +16 -0
  12. package/dist/components/editors/assets/modules/chunk-YSGSC7KM.js +1 -0
  13. package/dist/components/editors/assets/modules/code-mirror-engine-QX4A5FVO.js +92 -0
  14. package/dist/components/editors/assets/modules/jodit-engine-MMSPIWM7.js +1853 -0
  15. package/dist/components/editors/assets/modules/prose-mirror-engine-IXTRTG6B.js +24 -0
  16. package/dist/components/grid/__init__.py +13 -0
  17. package/dist/components/grid/assets/collection.js +211 -0
  18. package/dist/components/grid/assets/index.js +3 -0
  19. package/dist/components/grid/commands.json +7 -0
  20. package/dist/components/grid/grammar.json +714 -0
  21. package/dist/components/grouplets/__init__.py +13 -0
  22. package/dist/components/grouplets/assets/collection.js +202 -0
  23. package/dist/components/grouplets/assets/index.js +3 -0
  24. package/dist/components/grouplets/commands.json +7 -0
  25. package/dist/components/grouplets/grammar.json +355 -0
  26. package/dist/components/inputs/__init__.py +1 -1
  27. package/dist/components/inputs/assets/collection.js +32 -24503
  28. package/dist/components/inputs/assets/index.js +2 -1
  29. package/dist/components/inputs/grammar.json +214 -6
  30. package/dist/components/layout/__init__.py +1 -1
  31. package/dist/components/layout/assets/collection.js +27 -26701
  32. package/dist/components/layout/assets/index.js +2 -1
  33. package/dist/components/layout/grammar.json +4 -0
  34. package/dist/components/selection_trial/__init__.py +13 -0
  35. package/dist/components/selection_trial/assets/collection.js +4 -0
  36. package/dist/components/selection_trial/assets/index.js +3 -0
  37. package/dist/components/selection_trial/commands.json +7 -0
  38. package/dist/components/selection_trial/grammar.json +552 -0
  39. package/dist/components/tree/__init__.py +1 -1
  40. package/dist/components/tree/assets/collection.js +24 -24612
  41. package/dist/components/tree/assets/index.js +2 -1
  42. package/dist/components/typst/__init__.py +2 -2
  43. package/dist/components/typst/assets/collection.js +12 -4
  44. package/dist/components/typst/assets/index.js +2 -1
  45. package/dist/components/typst/assets/modules/chunk-BLMUM44K.js +1 -0
  46. package/dist/components/typst/assets/modules/typst-client-JHC6UVYG.js +4 -0
  47. package/dist/gramlot.js +2749 -1627
  48. package/dist/gramlot.min.js +46 -41
  49. package/package.json +7 -2
  50. package/src/binding/grid-struct.js +63 -0
  51. package/src/binding/installation.js +5 -2
  52. package/src/binding/runtime.js +51 -6
  53. package/src/builder/gramlot-builder.d.ts +5 -0
  54. package/src/builder/gramlot-builder.js +16 -0
  55. package/src/builder/source.js +23 -0
  56. package/src/chat.d.ts +12 -0
  57. package/src/chat.js +198 -0
  58. package/src/collection-artifact.js +1 -1
  59. package/src/components/bases.js +2 -0
  60. package/src/components/chat.js +28 -0
  61. package/src/components/choice-editor.js +89 -34
  62. package/src/components/database-choices.js +131 -9
  63. package/src/components/field-state.js +10 -1
  64. package/src/components/grid-grammar.json +237 -0
  65. package/src/components/grid-header-interaction.js +196 -0
  66. package/src/components/grid-row-interaction.js +184 -0
  67. package/src/components/grid-row-layout.js +96 -0
  68. package/src/components/grid-rows.js +28 -0
  69. package/src/components/grid-search-box.js +142 -0
  70. package/src/components/grid-search-styles.js +42 -0
  71. package/src/components/grid-search.js +37 -0
  72. package/src/components/grid-structure.js +84 -0
  73. package/src/components/grid-styles.js +151 -0
  74. package/src/components/grid.js +589 -0
  75. package/src/components/grouplet-card.js +437 -0
  76. package/src/components/grouplets.js +17 -0
  77. package/src/components/menus.js +1 -0
  78. package/src/components/registry.js +4 -3
  79. package/src/components/tray-pane.js +32 -4
  80. package/src/components/typed-editor.js +4 -2
  81. package/src/experiments/selection-transfer.js +78 -0
  82. package/src/experiments/selection-trial.js +48 -0
  83. package/src/experiments/window-selection.js +124 -0
  84. package/src/form-state.d.ts +20 -0
  85. package/src/form-state.js +198 -0
  86. package/src/index-page-styles.js +1 -1
  87. package/src/index.d.ts +3 -1
  88. package/src/index.js +3 -1
  89. package/src/renderer/gramlot-renderer.js +8 -1
  90. package/src/server/gramlot-server.d.ts +2 -0
  91. package/src/server/gramlot-server.js +13 -1
  92. package/src/stores/bag-collection-store.js +51 -0
  93. package/src/stores/bag-collection-view.js +127 -0
  94. package/src/stores/collection-filter.js +77 -0
  95. package/src/view/controls.js +33 -1
  96. package/src/view/grouplet-card.js +54 -0
  97. package/src/view/html.js +20 -3
  98. package/src/view/labelbox.js +7 -3
  99. package/themes/gramlot-base/theme.css +28 -0
  100. package/themes/gramlot-compact/theme.css +8 -0
  101. package/themes/joanna/theme.css +8 -0
  102. package/themes/mimi/theme.css +8 -0
@@ -0,0 +1,96 @@
1
+ /** Per-grid row geometry. BagNode identity survives sorting and filtering. */
2
+ export class GridRowLayout {
3
+ #store;
4
+ #window = null;
5
+ setWindow(info) {
6
+ if (info !== null && (!Number.isSafeInteger(info.start) || info.start < 0
7
+ || !Number.isSafeInteger(info.total) || info.total < info.start)) {
8
+ throw new TypeError('Invalid grid window');
9
+ }
10
+ this.#window = info;
11
+ this.#dirty = true;
12
+ }
13
+ #headerWidth = null;
14
+ get headerWidth() { return this.#headerWidth; }
15
+ setHeaderWidth(width) {
16
+ if (!Number.isFinite(width) || width <= 0) throw new TypeError('Grid row header width must be positive pixels');
17
+ this.#headerWidth = Math.round(width);
18
+ }
19
+ #heights = new Map();
20
+ #measured = new Map();
21
+ #nodes = [];
22
+ #offsets = [0];
23
+ #dirty = true;
24
+ #estimate = 32;
25
+ bindStore(store) {
26
+ if (store !== this.#store) {
27
+ this.#heights.clear(); this.resetMeasurements();
28
+ this.#store = store;
29
+ }
30
+ }
31
+ retain(nodes) {
32
+ const current = new Set(nodes);
33
+ for (const map of [this.#heights, this.#measured]) {
34
+ for (const node of map.keys()) if (!current.has(node)) map.delete(node);
35
+ }
36
+ this.#dirty = true;
37
+ }
38
+ height(node) { return this.#heights.get(node) ?? null; }
39
+ setHeight(node, height) {
40
+ if (node.parentBag !== this.#store) return;
41
+ if (height === null) this.#heights.delete(node);
42
+ else {
43
+ if (!Number.isFinite(height) || height <= 0) throw new TypeError('Grid row height must be positive pixels');
44
+ this.#heights.set(node, Math.round(height));
45
+ }
46
+ this.forget(node);
47
+ }
48
+ setRows(nodes) { this.#nodes = nodes; this.#dirty = true; }
49
+ resetMeasurements() { this.#measured.clear(); this.#dirty = true; }
50
+ forget(node) { this.#measured.delete(node); this.#dirty = true; }
51
+ measure(node, height) {
52
+ // Hidden/unlaid-out rows have no usable measurement yet.
53
+ if (height <= 0 || this.#measured.get(node) === height) return false;
54
+ this.#measured.set(node, height);
55
+ this.#dirty = true;
56
+ return true;
57
+ }
58
+ #index() {
59
+ if (!this.#dirty) return;
60
+ // The smallest observed natural row gives a theme-derived estimate for
61
+ // unseen rows. Explicit heights and measured wrapped rows take priority.
62
+ let natural = Infinity;
63
+ for (const [node, height] of this.#measured) if (!this.#heights.has(node)) natural = Math.min(natural, height);
64
+ if (natural !== Infinity) this.#estimate = natural;
65
+ this.#offsets = [0];
66
+ for (const node of this.#nodes) this.#offsets.push(this.#offsets.at(-1) +
67
+ (this.#measured.get(node) ?? Math.max(this.#heights.get(node) ?? 0, this.#estimate)));
68
+ this.#dirty = false;
69
+ }
70
+ offset(index) {
71
+ this.#index();
72
+ if (!this.#window) return this.#offsets[index];
73
+ const local = index - this.#window.start;
74
+ if (local <= 0) return index * this.#estimate;
75
+ if (local <= this.#nodes.length) return this.#window.start * this.#estimate + this.#offsets[local];
76
+ return index * this.#estimate + this.#offsets.at(-1) - this.#nodes.length * this.#estimate;
77
+ }
78
+ get count() { return this.#window?.total ?? this.#nodes.length; }
79
+ get totalHeight() { return this.offset(this.count); }
80
+ indexAt(position) {
81
+ this.#index();
82
+ let low = 0, high = this.count;
83
+ while (low < high) {
84
+ const middle = (low + high) >>> 1;
85
+ if (this.offset(middle + 1) <= position) low = middle + 1;
86
+ else high = middle;
87
+ }
88
+ return Math.min(low, Math.max(0, this.count - 1));
89
+ }
90
+ window(top, height) {
91
+ this.#index();
92
+ const margin = Math.max(height, this.#estimate * 8);
93
+ return {start: this.indexAt(Math.max(0, top - margin)),
94
+ end: Math.min(this.count, this.indexAt(top + height + margin) + 1)};
95
+ }
96
+ }
@@ -0,0 +1,28 @@
1
+ import {isDecimal} from '@genrojs/tytx';
2
+
3
+ /** Formatting projection only; collection membership and ordering belong to the store. */
4
+ export class GridRows {
5
+ constructor(store, format) {
6
+ this.store = store;
7
+ this.format = format;
8
+ }
9
+ read(columns, nodes = this.store.getRows()) {
10
+ return nodes.map(node => ({node, cells:columns.map(column =>
11
+ cellText(this.store.value(node, column.field), column, this.format))}));
12
+ }
13
+ }
14
+
15
+ function cellText(value, column, format) {
16
+ if (value == null) return '';
17
+ const {dtype, format: pattern} = column;
18
+ if (dtype === 'T' && typeof value !== 'string' || dtype === 'B' && typeof value !== 'boolean') throw new TypeError(`grid ${column.field} does not match ${dtype}`);
19
+ if (typeof value === 'string' || typeof value === 'boolean') {
20
+ if (dtype && !['T', 'B'].includes(dtype) || pattern != null) throw new TypeError(`grid ${column.field} requires a typed numeric or temporal value`);
21
+ return String(value);
22
+ }
23
+ if (value instanceof Date || pattern != null) return format(value, {dtype, pattern: pattern ?? 'short'});
24
+ if (dtype && !['L', 'R', 'N'].includes(dtype)) throw new TypeError(`grid ${column.field} does not match ${dtype}`);
25
+ if (dtype === 'L' && !Number.isInteger(value)) throw new TypeError('grid L requires an integer');
26
+ if (typeof value === 'number' && Number.isFinite(value) || isDecimal(value) && value.isFinite()) return String(value);
27
+ throw new TypeError(`grid ${column.field} requires a scalar value`);
28
+ }
@@ -0,0 +1,142 @@
1
+ import {defineComponent} from './registry.js';
2
+ import {Container} from './container.js';
3
+ import {gridSearch, searchColumns} from './grid-search.js';
4
+ import {SVG_NS} from '../renderer/attributes.js';
5
+ import {positionPopup} from './popup.js';
6
+ import {gridSearchStyles} from './grid-search-styles.js';
7
+
8
+ /** FrameGrid's search slot. The collection view owns the accepted filter. */
9
+ export const SearchBox = defineComponent({
10
+ name:'searchBox', tag:'gramlot-search-box', base:Container, sourceContext:true,
11
+ parameters:{searchOn:{dtype:['B','T'], default:true, binding:'read'},
12
+ searchTime:{dtype:'R', nullable:true, default:null, binding:'write'}},
13
+ implementation:Base => class extends Base {
14
+ #context; #grid; #release; #releaseView; #view; #timer = null;
15
+ #field; #input; #error; #helpText; #filterSignature; #bag;
16
+ constructor() {
17
+ super();
18
+ const doc = this.ownerDocument;
19
+ const style = doc.createElement('style');
20
+ style.textContent = gridSearchStyles;
21
+ const icon = path => {
22
+ const svg = doc.createElementNS(SVG_NS,'svg'); svg.setAttribute('viewBox','0 0 24 24'); svg.setAttribute('aria-hidden','true');
23
+ const shape = doc.createElementNS(SVG_NS,'path'); shape.setAttribute('d',path); svg.append(shape); return svg;
24
+ };
25
+ this.#field = doc.createElement('select'); this.#field.setAttribute('aria-label','Search column');
26
+ this.#input = doc.createElement('input'); this.#input.type = 'text'; this.#input.setAttribute('role','searchbox'); this.#input.setAttribute('aria-label','Filter rows');
27
+ this.#input.setAttribute('aria-describedby','search-error');
28
+ this.#input.placeholder = ' ';
29
+ const clear = doc.createElement('button'); clear.type = 'button'; clear.title = 'Clear filter'; clear.setAttribute('aria-label','Clear filter'); clear.append(icon('M6 6L18 18M18 6L6 18'));
30
+ this.#error = doc.createElement('span'); this.#error.id = 'search-error'; this.#error.className = 'error'; this.#error.setAttribute('role','alert');
31
+ const choice = doc.createElement('span'); choice.className = 'column-choice';
32
+ choice.append(this.#field,icon('M7 10L12 15L17 10'));
33
+ const entry = doc.createElement('span'); entry.className = 'search-entry';
34
+ const lens = icon('M21 21L16 16M18 10A8 8 0 1 1 2 10A8 8 0 0 1 18 10'); lens.classList.add('search-lens');
35
+ clear.className = 'clear';
36
+ const info = doc.createElement('button'); info.type = 'button'; info.className = 'info';
37
+ info.setAttribute('aria-label','Search instructions'); info.title = 'Search instructions';
38
+ info.setAttribute('aria-haspopup','dialog'); info.setAttribute('aria-expanded','false'); info.setAttribute('aria-controls','search-help');
39
+ info.append(icon('M21 12A9 9 0 1 1 3 12A9 9 0 0 1 21 12M12 11V17M12 7V7.1'));
40
+ const help = doc.createElement('div'); help.id = 'search-help'; help.className = 'search-help';
41
+ help.setAttribute('popover','auto'); help.setAttribute('role','dialog'); help.setAttribute('aria-label','Search instructions');
42
+ const heading = doc.createElement('strong'); heading.textContent = 'Search instructions';
43
+ this.#helpText = doc.createElement('p');
44
+ const common = doc.createElement('p'); common.textContent = 'Clear with × or Escape. Changing column clears the query. An incomplete expression keeps the last valid result.';
45
+ help.append(heading,this.#helpText,common); this.shadowRoot.append(help);
46
+ info.addEventListener('click', () => {
47
+ if (help.matches(':popover-open')) help.hidePopover();
48
+ else {help.showPopover(); positionPopup(help,info,{align:'end'});}
49
+ });
50
+ help.addEventListener('toggle', () => info.setAttribute('aria-expanded',String(help.matches(':popover-open'))));
51
+ entry.append(lens,this.#input,clear,info);
52
+ this.control.replaceChildren(choice,entry,this.#error);
53
+ this.shadowRoot.append(style);
54
+ this.#input.addEventListener('input', () => {
55
+ this.#cancel(); this.#timer = doc.defaultView.setTimeout(() => { this.#timer = null; this.#apply(); },100);
56
+ });
57
+ this.#input.addEventListener('keydown', event => {
58
+ if (event.isComposing) return;
59
+ if (event.key === 'Enter') { event.preventDefault(); this.#cancel(); this.#apply(); }
60
+ if (event.key === 'Escape') { event.preventDefault(); this.#clear(); }
61
+ });
62
+ this.#field.addEventListener('change', () => this.#clear());
63
+ clear.addEventListener('click', () => {this.#clear(); this.#input.focus();});
64
+ }
65
+ setSourceContext(context) {
66
+ this.#context = context;
67
+ const target = context.frameRecipient();
68
+ if (target?.nodeTag !== 'grid') throw new TypeError('searchBox requires a FrameGrid target');
69
+ this.#grid = gridSearch(target);
70
+ }
71
+ projectAttributes(attrs, adapt) {
72
+ const rest = super.projectAttributes(attrs, adapt);
73
+ if (this.isConnected) this.#configure();
74
+ return rest;
75
+ }
76
+ connectedCallback() {
77
+ this.#release = this.#grid.subscribe(() => this.#configure());
78
+ this.#configure();
79
+ }
80
+ disconnectedCallback() {
81
+ this.#cancel(); this.#release?.(); this.#releaseView?.(); this.#release = this.#releaseView = null;
82
+ }
83
+ #cancel() { if (this.#timer !== null) this.ownerDocument.defaultView.clearTimeout(this.#timer); this.#timer = null; }
84
+ #configure() {
85
+ try { this.#update(); }
86
+ catch (error) { this.#input.disabled = true; this.#error.textContent = error.message; }
87
+ }
88
+ #update() {
89
+ if (!this.#grid.view) return;
90
+ if (this.#view !== this.#grid.view || this.#bag !== this.#grid.view.bag || !this.#releaseView) {
91
+ this.#cancel(); this.#releaseView?.(); this.#view = this.#grid.view; this.#bag = this.#view.bag;
92
+ this.#filterSignature = undefined;
93
+ this.#releaseView = this.#view.subscribe(() => this.#sync());
94
+ }
95
+ const previous = this.#field.value;
96
+ const options = searchColumns(this.parameters.searchOn,this.#grid.columns);
97
+ this.#field.replaceChildren(...options.map(({field,name}) => {
98
+ const option = this.ownerDocument.createElement('option'); option.value = field; option.textContent = name; return option;
99
+ }));
100
+ if (options.some(option => option.field === previous)) this.#field.value = previous;
101
+ this.#input.disabled = !options.length;
102
+ this.#sync(); this.#hint();
103
+ }
104
+ #sync() {
105
+ const filter = this.#view.filter;
106
+ // Uncommitted drafts (including errors) survive unrelated row notifications.
107
+ const signature = JSON.stringify(filter);
108
+ if (this.#filterSignature === signature) return;
109
+ this.#filterSignature = signature;
110
+ this.#cancel(); this.#input.value = filter?.value ?? '';
111
+ if (filter) this.#field.value = filter.columns.join('+');
112
+ this.#error.textContent = ''; this.#input.removeAttribute('aria-invalid'); this.#hint();
113
+ }
114
+ #dtype() {
115
+ const column = this.#grid.columns.find(column => column.field === this.#field.value);
116
+ return ['L','R','N','D'].includes(column?.dtype) ? column.dtype : 'T';
117
+ }
118
+ #hint() {
119
+ const dtype = this.#dtype();
120
+ this.#helpText.textContent = dtype === 'T'
121
+ ? 'Type a word to find it anywhere. Text is case-insensitive. You can also use expressions: lamp|desk matches either word; ^lamp matches the start.'
122
+ : dtype === 'D'
123
+ ? 'Compare dates: = 2026-10-15, >= 2026-10-15 or < 2026-10-15. ISO dates and your browser’s local date notation are accepted.'
124
+ : 'Compare numbers: = 12, > 100, <= 50 or ! 0 (not equal). Decimal punctuation follows your browser locale.';
125
+ }
126
+ #clear() { this.#cancel(); this.#input.value = ''; this.#apply(); this.#hint(); }
127
+ #apply() {
128
+ if (!this.#view) return;
129
+ try {
130
+ const value = this.#input.value;
131
+ const started = performance.now();
132
+ this.#view.applyFilter(value.trim() ? {value, columns:this.#field.value.split('+'), dtype:this.#dtype(),
133
+ locale:this.#context.locale,
134
+ timeZone:this.#context.timeZone} : null);
135
+ this.#context.writeParameter('searchTime', performance.now() - started);
136
+ this.#error.textContent = ''; this.#input.removeAttribute('aria-invalid');
137
+ } catch (error) {
138
+ this.#error.textContent = error.message; this.#input.setAttribute('aria-invalid','true');
139
+ }
140
+ }
141
+ }
142
+ });
@@ -0,0 +1,42 @@
1
+ /** Search capsule: uses shared field, surface and focus tokens in every theme. */
2
+ export const gridSearchStyles = `
3
+ :host{display:inline-block;inline-size:clamp(14rem,40vw,22rem);max-inline-size:100%;min-inline-size:0}
4
+ .control-box{display:flex;align-items:stretch;position:relative;min-block-size:var(--gramlot-field-height,2.75rem);
5
+ border:1px solid var(--gramlot-border,GrayText);border-radius:999px;
6
+ background:var(--gramlot-field-background,Canvas);color:var(--gramlot-ink,CanvasText);
7
+ transition:border-color .15s}
8
+ .control-box:hover{border-color:var(--gramlot-border-control,GrayText)}
9
+ .control-box:focus-within{border-color:var(--gramlot-border-control,GrayText)}
10
+ select,input,button{font:inherit;color:inherit;min-inline-size:0;border:0;background:transparent}
11
+ .column-choice{display:flex;align-items:center;background:var(--gramlot-surface-subtle,ButtonFace);border-radius:999px 0 0 999px;position:relative;flex:0 1 auto;max-inline-size:42%;border-inline-end:1px solid var(--gramlot-border,GrayText)}
12
+ select{display:block;appearance:none;inline-size:100%;padding:.35rem 1.8rem .35rem .85rem;
13
+ border-radius:999px;font-size:.9em;color:var(--gramlot-text-secondary,GrayText);cursor:pointer;text-overflow:ellipsis}
14
+ select option{background:var(--gramlot-field-background,Canvas);color:var(--gramlot-ink,CanvasText)}
15
+ .column-choice>svg{position:absolute;inset-inline-end:.55rem;inset-block-start:50%;transform:translateY(-50%);pointer-events:none;color:var(--gramlot-text-secondary,GrayText);width:.8rem;height:.8rem}
16
+ .search-entry{position:relative;display:flex;align-items:center;flex:1;min-inline-size:0}
17
+ .search-lens{position:absolute;inset-inline-start:.65rem;pointer-events:none;color:var(--gramlot-text-secondary,GrayText);opacity:.6}
18
+ input{inline-size:100%;min-block-size:var(--gramlot-field-height,2.75rem);padding:.4rem 3.6rem .4rem 2.1rem;border-radius:999px;outline:none}
19
+ input::placeholder{color:var(--gramlot-text-secondary,GrayText);opacity:.75}
20
+ input:disabled{opacity:.5}
21
+ .clear,.info{position:absolute;display:grid;place-items:center;padding:.3rem;
22
+ inline-size:1.6rem;block-size:1.6rem;border-radius:50%;color:var(--gramlot-text-secondary,GrayText);cursor:pointer}
23
+ .clear{inset-inline-end:1.95rem}
24
+ .info{inset-inline-end:.35rem;opacity:.7}
25
+ .clear:hover,.info:hover{color:var(--gramlot-ink,CanvasText);background:var(--gramlot-surface-subtle,ButtonFace)}
26
+ input:placeholder-shown~.clear{display:none}
27
+ select:focus-visible,button:focus-visible{outline:1px solid var(--gramlot-text-secondary,GrayText);outline-offset:-3px}
28
+ svg{width:1rem;height:1rem;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round;flex:none}
29
+ .control-box:has([aria-invalid=true]){border-color:var(--gramlot-error,Mark)}
30
+ .error{position:absolute;inset-block-start:calc(100% + .35rem);inset-inline:0;z-index:1;
31
+ border:1px solid var(--gramlot-border,GrayText);border-radius:var(--gramlot-radius,.5rem);
32
+ background:var(--gramlot-field-background,Canvas);color:var(--gramlot-error,Mark);
33
+ font-size:.85em;padding:.5rem .75rem;box-shadow:var(--gramlot-shadow,0 2px 5px #0002)}
34
+ .error:empty{display:none}
35
+ .search-help{position:fixed;inset:auto;margin:0;inline-size:19rem;max-inline-size:calc(100vw - 1rem);
36
+ max-block-size:var(--gramlot-popup-available-height,80vh);overflow:auto;padding:1rem;
37
+ border:1px solid var(--gramlot-border,GrayText);border-radius:var(--gramlot-radius-lg,.75rem);
38
+ background:var(--gramlot-surface,Canvas);color:var(--gramlot-ink,CanvasText);
39
+ box-shadow:var(--gramlot-shadow,0 3px 12px #0002);font:inherit;font-size:.9em;line-height:1.5}
40
+ .search-help p{margin:.6rem 0 0}.search-help p:last-child{color:var(--gramlot-text-secondary,GrayText)}
41
+ @media(prefers-reduced-motion:reduce){.control-box{transition:none}}
42
+ `;
@@ -0,0 +1,37 @@
1
+ /** Source-owned connection: current grid resources, never copied row data. */
2
+ export class GridSearch {
3
+ #listeners = new Set();
4
+ view = null;
5
+ #bag;
6
+ columns = [];
7
+ update(view, columns) {
8
+ if (this.view === view && this.#bag === view.bag && this.columns === columns) return;
9
+ this.view = view; this.#bag = view.bag; this.columns = columns;
10
+ for (const listener of this.#listeners) listener();
11
+ }
12
+ subscribe(listener) { this.#listeners.add(listener); return () => this.#listeners.delete(listener); }
13
+ }
14
+
15
+ export function gridSearch(node) {
16
+ if (!Object.hasOwn(node, 'gridSearch')) {
17
+ Object.defineProperty(node, 'gridSearch', {value:new GridSearch(), configurable:true});
18
+ }
19
+ return node.gridSearch;
20
+ }
21
+
22
+ export function searchColumns(searchOn, columns) {
23
+ if (searchOn === true || typeof searchOn === 'string' && searchOn.startsWith('*')) {
24
+ const allowed = searchOn === true ? columns : columns.filter(column => searchOn.slice(1).includes(column.dtype ?? 'T'));
25
+ return allowed.length ? [{field:allowed.map(column => column.field).join('+'), name:'All columns'},
26
+ ...allowed.map(column => ({field:column.field, name:column.name}))] : [];
27
+ }
28
+ if (typeof searchOn !== 'string' || !searchOn.trim()) throw new TypeError('searchOn requires true or a column list');
29
+ return searchOn.split(',').map(item => {
30
+ const parts = item.trim().split(':');
31
+ const field = parts.at(-1), name = parts.length === 2 ? parts[0] : columns.find(column => column.field === field)?.name;
32
+ if (parts.length > 2 || !field || field.split('+').some(key => !columns.some(column => column.field === key))) {
33
+ throw new TypeError(`Unknown searchOn column: ${item}`);
34
+ }
35
+ return {field, name:name ?? field};
36
+ });
37
+ }
@@ -0,0 +1,84 @@
1
+ import {Bag} from '@gramlot/gramlot';
2
+
3
+ const TYPES = new Set(['T', 'B', 'L', 'R', 'N', 'D', 'H', 'DHZ']);
4
+ const COLUMN_KEYS = new Set(['tag', 'field', 'name', 'dtype', 'width', 'align', 'format', 'columnset', 'white_space']);
5
+ const GROUP_KEYS = new Set(['tag', 'code', 'name', 'background', 'color']);
6
+
7
+ /** Legacy Data contract: ordered cells and independent columnset definitions. */
8
+ export class GridStructure {
9
+ #nodes = new Map();
10
+ constructor(bag) {
11
+ if (!(bag instanceof Bag)) throw new TypeError('grid structpath must resolve to a Bag');
12
+ const view = branch(bag, 'view_0'), info = branch(bag, 'info');
13
+ const cells = branch(view, 'rows_0'), definitions = branch(info, 'columnsets');
14
+ const fields = new Set(), groups = new Map();
15
+ for (const node of definitions.getNodes()) {
16
+ const attrs = node.getAttr();
17
+ requireKeys(attrs, GROUP_KEYS);
18
+ requireIdentity(attrs.code, 'colgroup code');
19
+ if (attrs.tag !== 'columnset' || node.resolver || node.staticValue != null || node.label !== attrs.code) {
20
+ throw new TypeError('grid columnset requires a scalar definition labelled by code');
21
+ }
22
+ if (groups.has(attrs.code)) throw new TypeError(`Duplicate grid colgroup: ${attrs.code}`);
23
+ if (attrs.name != null && typeof attrs.name !== 'string') throw new TypeError('grid group name must be text');
24
+ for (const key of ['background','color']) if (attrs[key] != null && typeof attrs[key] !== 'string') throw new TypeError(`grid ${key} must be text`);
25
+ groups.set(attrs.code, {...attrs, name:attrs.name ?? attrs.code});
26
+ }
27
+ this.columns = [];
28
+ this.groups = [];
29
+ for (const node of cells.getNodes()) {
30
+ const attrs = node.getAttr();
31
+ requireKeys(attrs, COLUMN_KEYS);
32
+ if (attrs.tag !== 'cell' || node.staticValue != null || node.resolver) throw new TypeError('grid cell must be a scalar declaration');
33
+ requireIdentity(attrs.field, 'field');
34
+ if (fields.has(attrs.field)) throw new TypeError(`Duplicate grid field: ${attrs.field}`);
35
+ fields.add(attrs.field); this.#nodes.set(attrs.field, node);
36
+ if (attrs.columnset != null && !groups.has(attrs.columnset)) throw new TypeError(`Unknown grid columnset: ${attrs.columnset}`);
37
+ if (attrs.dtype != null && !TYPES.has(attrs.dtype)) throw new TypeError(`Unsupported grid dtype: ${attrs.dtype}`);
38
+ if (attrs.align != null && !['start', 'center', 'end'].includes(attrs.align)) throw new TypeError('grid align requires start, center or end');
39
+ if (attrs.width != null && (typeof attrs.width !== 'string' || !/^(?:\d+(?:\.\d+)?)(?:px|em|rem|ch|%)$/.test(attrs.width))) {
40
+ throw new TypeError('grid width requires a nonnegative CSS length (px, em, rem, ch or %)');
41
+ }
42
+ if (attrs.white_space != null && !['normal','nowrap','pre-wrap'].includes(attrs.white_space)) throw new TypeError('grid white_space requires normal, nowrap or pre-wrap');
43
+ for (const key of ['name', 'format']) if (attrs[key] != null && typeof attrs[key] !== 'string') throw new TypeError(`grid ${key} must be text`);
44
+ const column = Object.freeze({...attrs, name: attrs.name ?? attrs.field,
45
+ align: attrs.align ?? (['L', 'R', 'N'].includes(attrs.dtype) ? 'end' : 'start')});
46
+ this.columns.push(column);
47
+ const code = attrs.columnset ?? null;
48
+ let run = this.groups.at(-1);
49
+ if (!run || run.code !== code) {
50
+ run = {code, ...(code === null ? {name:null} : groups.get(code)), columns:[]};
51
+ this.groups.push(run);
52
+ }
53
+ run.columns.push(column);
54
+ }
55
+ if (!this.columns.length) throw new TypeError('grid struct requires at least one column');
56
+ for (const group of this.groups) { Object.freeze(group.columns); Object.freeze(group); }
57
+ Object.freeze(this.columns); Object.freeze(this.groups); Object.freeze(this);
58
+ }
59
+ columnNode(field) { return this.#nodes.get(field); }
60
+ moveColumn(field, targetField, after = false) {
61
+ const node = this.#nodes.get(field), target = this.#nodes.get(targetField);
62
+ if (!node || !target || node === target) return;
63
+ const bag = node.parentBag, nodes = bag.getNodes();
64
+ const from = nodes.indexOf(node), targetIndex = nodes.indexOf(target);
65
+ const position = targetIndex + Number(after) - Number(from < targetIndex);
66
+ if (position !== from) bag.move(from, position);
67
+ }
68
+ setColumnWidth(field, width) {
69
+ if (!Number.isFinite(width) || width <= 0) throw new TypeError('grid resized width must be positive pixels');
70
+ this.#nodes.get(field).setAttr({width: `${Math.round(width)}px`});
71
+ }
72
+ }
73
+
74
+ function branch(bag, label) {
75
+ const node = bag.getNode(label);
76
+ if (!node || node.resolver || !(node.staticValue instanceof Bag)) throw new TypeError(`grid struct requires Bag ${label}`);
77
+ return node.staticValue;
78
+ }
79
+ function requireKeys(attrs, allowed) {
80
+ for (const key of Object.keys(attrs)) if (!allowed.has(key)) throw new TypeError(`Unsupported grid struct attribute: ${key}`);
81
+ }
82
+ function requireIdentity(value, label) {
83
+ if (typeof value !== 'string' || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(value)) throw new TypeError(`grid ${label} requires a simple field identifier`);
84
+ }
@@ -0,0 +1,151 @@
1
+ /** Grid geometry and token consumption. Themes own the palette and density.
2
+ * A JS stylesheet module keeps the same source usable in Node and browser builds.
3
+ */
4
+ export const gridStyles = `
5
+ :host {
6
+ min-block-size: 0;
7
+ color: var(--gramlot-grid-color, var(--gramlot-ink, CanvasText));
8
+ font-family: var(--gramlot-font-ui, inherit);
9
+ font-size: var(--gramlot-grid-font-size, inherit);
10
+ line-height: var(--gramlot-grid-line-height, 1.35);
11
+ }
12
+ .control-box {
13
+ display: flex;
14
+ flex-direction: column;
15
+ block-size: 100%;
16
+ min-block-size: 0;
17
+ overflow: hidden;
18
+ border: 1px solid var(--gramlot-grid-border-color, var(--gramlot-border, ButtonBorder));
19
+ border-radius: var(--gramlot-grid-radius, var(--gramlot-radius-sm, 0));
20
+ background: var(--gramlot-grid-background, var(--gramlot-surface, Canvas));
21
+ }
22
+ .header-frame {
23
+ flex: none;
24
+ min-inline-size: 0;
25
+ padding-inline-end: var(--grid-scrollbar-width, 0px);
26
+ background: var(--gramlot-grid-header-background, var(--gramlot-surface-subtle, ButtonFace));
27
+ border-block-end: 1px solid var(--gramlot-grid-border-color, var(--gramlot-border, ButtonBorder));
28
+ }
29
+ .header-viewport { overflow: hidden; min-inline-size: 0; }
30
+ .body-viewport {
31
+ flex: 1 1 auto;
32
+ min-block-size: 0;
33
+ min-inline-size: 0;
34
+ overflow: auto;
35
+ background: var(--gramlot-surface-subtle, Canvas);
36
+ scrollbar-gutter: stable;
37
+ overscroll-behavior: contain;
38
+ overflow-anchor: none;
39
+ }
40
+ .row-space { pointer-events: none; inline-size: 1px; }
41
+ .body-viewport:focus-visible {
42
+ outline: 2px solid var(--gramlot-focus-ring, Highlight);
43
+ outline-offset: -2px;
44
+ }
45
+ table {
46
+ border-spacing: 0;
47
+ table-layout: fixed;
48
+ inline-size: var(--grid-columns-width);
49
+ font: inherit;
50
+ color: inherit;
51
+ }
52
+ th, td {
53
+ padding: var(--gramlot-grid-cell-padding, .3rem .6rem);
54
+ overflow: hidden;
55
+ text-overflow: ellipsis;
56
+ white-space: nowrap;
57
+ vertical-align: middle;
58
+ border-inline-end: 1px solid var(--gramlot-grid-column-border-color, var(--gramlot-border, ButtonBorder));
59
+ }
60
+ th {
61
+ position: relative;
62
+ block-size: var(--gramlot-grid-header-height, 2rem);
63
+ color: var(--gramlot-grid-header-color, var(--gramlot-ink, ButtonText));
64
+ background: var(--gramlot-grid-header-background, var(--gramlot-surface-subtle, ButtonFace));
65
+ font-weight: var(--gramlot-grid-header-weight, 600);
66
+ text-align: start;
67
+ }
68
+ th[scope=col], th.row-heading {
69
+ background-image: linear-gradient(to bottom, var(--gramlot-grid-header-highlight), transparent 65%);
70
+ border-inline-end-color: var(--gramlot-grid-header-border-color, ButtonBorder);
71
+ box-shadow: inset 0 1px var(--gramlot-grid-header-highlight), inset 0 -1px var(--gramlot-grid-header-border-color, ButtonBorder);
72
+ }
73
+ .group-spacer, th[scope=colgroup] {
74
+ box-sizing: border-box;
75
+ block-size: var(--gramlot-grid-group-height, 1.5rem);
76
+ padding-block: 0;
77
+ }
78
+ .group-spacer { background: var(--gramlot-grid-header-background); border: 0; }
79
+ th[scope=colgroup] {
80
+ border-start-start-radius: var(--gramlot-radius-lg, 10px);
81
+ border-start-end-radius: var(--gramlot-radius-lg, 10px);
82
+ border-inline-start: 2px solid var(--gramlot-grid-header-background);
83
+ background-clip: padding-box;
84
+ background: var(--gramlot-grid-group-background, var(--gramlot-surface-subtle, ButtonFace));
85
+ color: var(--gramlot-grid-group-color, var(--gramlot-ink, ButtonText));
86
+ border-block-end: 1px solid var(--gramlot-grid-border-color, var(--gramlot-border, ButtonBorder));
87
+ }
88
+ td {
89
+ vertical-align: top;
90
+ block-size: var(--gramlot-grid-row-height, 2rem);
91
+ border-block-end: 1px solid var(--gramlot-grid-row-border-color, var(--gramlot-border, ButtonBorder));
92
+ }
93
+ tbody tr { background: var(--gramlot-grid-background, var(--gramlot-surface, Canvas)); }
94
+ tbody tr.alternate { background: var(--gramlot-grid-row-alt-background, var(--gramlot-surface-subtle, Canvas)); }
95
+ tbody tr:hover { background: var(--gramlot-grid-row-hover-background, var(--gramlot-selected, Highlight)); }
96
+ th[data-field] { padding-inline-end: 14px; cursor: grab; user-select: none; }
97
+ th[data-field]:hover { background-color: color-mix(in srgb, var(--gramlot-grid-header-background) 92%, var(--gramlot-grid-header-color)); }
98
+ th:focus-visible, .column-resize:focus-visible { outline: 2px solid var(--gramlot-focus-ring, Highlight); outline-offset: -2px; }
99
+ .column-caption { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
100
+ th[data-sort-direction] .column-caption { padding-inline-end: 24px; }
101
+ .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; }
102
+ th[data-sort-direction] .sort-indicator { display: inline-block; }
103
+ th[data-sort-direction=descending] .sort-indicator { transform: rotate(180deg); }
104
+ th[data-sort-priority]::after { content: attr(data-sort-priority); position: absolute; inset-inline-end: 7px; top: calc(50% - .8em); font-size: .7em; opacity: .8; }
105
+ .column-resize { position: absolute; inset: 0 -4px 0 auto; inline-size: 9px; z-index: 1; cursor: col-resize; touch-action: none; }
106
+ .column-resize::after { content: ''; position: absolute; inset: 20% 4px; background: transparent; }
107
+ th:hover .column-resize::after, .column-resize:focus-visible::after { background: var(--gramlot-focus-ring, Highlight); }
108
+ .resizing, .resizing * { cursor: col-resize; user-select: none; }
109
+ th.column-dragging { opacity: .45; }
110
+ th[data-drop=before] { box-shadow: inset 3px 0 var(--gramlot-focus-ring, Highlight); }
111
+ th[data-drop=after] { box-shadow: inset -3px 0 var(--gramlot-focus-ring, Highlight); }
112
+ th.row-heading {
113
+ font-variant-numeric: tabular-nums;
114
+ position: sticky;
115
+ inset-inline-start: 0;
116
+ z-index: 2;
117
+ text-align: end;
118
+ font-weight: 400;
119
+ vertical-align: top;
120
+ user-select: none;
121
+ block-size: var(--gramlot-grid-row-height, 2rem);
122
+ }
123
+ thead th.row-heading { vertical-align: middle; font-weight: var(--gramlot-grid-header-weight, 600); }
124
+ .row-number-measure {
125
+ position: absolute;
126
+ visibility: hidden;
127
+ pointer-events: none;
128
+ inline-size: max-content;
129
+ padding-inline: inherit;
130
+ border-inline-end: inherit;
131
+ font-weight: 400;
132
+ }
133
+ .row-height-handle {
134
+ position: absolute;
135
+ inset: auto 0 0;
136
+ block-size: 7px;
137
+ cursor: row-resize;
138
+ touch-action: none;
139
+ }
140
+ .row-height-handle:hover, .row-height-handle:focus-visible {
141
+ background: color-mix(in srgb, var(--gramlot-focus-ring, Highlight) 35%, transparent);
142
+ }
143
+ .row-height-handle:focus-visible { outline: 2px solid var(--gramlot-focus-ring, Highlight); outline-offset: -2px; }
144
+ .resizing-row, .resizing-row * { cursor: row-resize; user-select: none; }
145
+ tbody tr[draggable=true] { cursor: grab; }
146
+ tbody tr.row-dragging { opacity: .45; }
147
+ tbody tr[data-row-drop=before] > * { box-shadow: inset 0 2px var(--gramlot-focus-ring, Highlight); }
148
+ tbody tr[data-row-drop=after] > * { box-shadow: inset 0 -2px var(--gramlot-focus-ring, Highlight); }
149
+ .numeric { font-variant-numeric: tabular-nums; }
150
+ .empty { text-align: center; color: var(--gramlot-text-secondary, GrayText); }
151
+ `;