@gramlot/gramlot 0.3.26 → 0.3.30
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.
- package/assets/icons/chart.svg +1 -0
- package/dist/components/audio/__init__.py +13 -0
- package/dist/components/audio/assets/collection.js +3 -0
- package/dist/components/audio/assets/index.js +3 -0
- package/dist/components/audio/commands.json +7 -0
- package/dist/components/audio/grammar.json +335 -0
- package/dist/components/charts/__init__.py +13 -0
- package/dist/components/charts/assets/collection.js +47 -0
- package/dist/components/charts/assets/files/55ea01207028f76d844678511f29fc800f8a1e67a8a0fe80470128677847ad32-echarts-gl.txt +29 -0
- package/dist/components/charts/assets/files/63727832aaf62004a2b249c933e327f3c90caf49e41a72f4bf436edf632cbda8-vega.txt +27 -0
- package/dist/components/charts/assets/files/8c45d9eaf50c2f72dd9c7ab9ef440788ba58a3538484b5c51c1f17d5128752e7-plotly.txt +21 -0
- package/dist/components/charts/assets/files/8f989229699b4fe2f1a0432d0e9edc338a8a911e250e2d1b01ecd770a5f5b1bd-uplot.txt +21 -0
- package/dist/components/charts/assets/files/c8fa058cba98f7f288b5d8fa4116f441d6dacb25b96da859e518c973fff41d0c-claygl.txt +23 -0
- package/dist/components/charts/assets/index.js +3 -0
- package/dist/components/charts/assets/modules/chunk-2CCTLZE7.js +76 -0
- package/dist/components/charts/assets/modules/chunk-RMRBEYTI.js +1 -0
- package/dist/components/charts/assets/modules/echarts-gl-CXVTZA6G.js +4409 -0
- package/dist/components/charts/assets/modules/plotly.min-4LB7HE7P.js +3596 -0
- package/dist/components/charts/assets/modules/uPlot.esm-5JJNHHRF.js +3 -0
- package/dist/components/charts/assets/modules/uPlot.min-N3E3FA74.js +1 -0
- package/dist/components/charts/assets/modules/vega.module-2QCOVQ3A.js +13 -0
- package/dist/components/charts/commands.json +7 -0
- package/dist/components/charts/grammar.json +1113 -0
- package/dist/components/chat/__init__.py +1 -1
- package/dist/components/chat/assets/collection.js +3 -3
- package/dist/components/chat/assets/index.js +1 -1
- package/dist/components/drawing/__init__.py +15 -0
- package/dist/components/drawing/assets/collection.js +28 -0
- package/dist/components/drawing/assets/index.js +3 -0
- package/dist/components/drawing/commands.json +7 -0
- package/dist/components/drawing/grammar.json +110 -0
- package/dist/components/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +18 -18
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/modules/{prose-mirror-engine-GMZPJPNN.js → prose-mirror-engine-DQEAEIMV.js} +2 -2
- package/dist/components/editors/grammar.json +150 -0
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/collection.js +63 -33
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +279 -0
- package/dist/components/grouplets/__init__.py +1 -1
- package/dist/components/grouplets/assets/collection.js +3 -3
- package/dist/components/grouplets/assets/index.js +1 -1
- package/dist/components/inputs/__init__.py +3 -2
- package/dist/components/inputs/assets/collection.js +38 -23
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +1533 -321
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +27 -23
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +85 -0
- package/dist/components/selection_trial/__init__.py +1 -1
- package/dist/components/selection_trial/assets/collection.js +3 -3
- package/dist/components/selection_trial/assets/index.js +1 -1
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +12 -12
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +126 -0
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +3 -3
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/collection.js +9 -9
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/vizabi/__init__.py +13 -0
- package/dist/components/vizabi/assets/collection.js +22 -0
- package/dist/components/vizabi/assets/index.js +3 -0
- package/dist/components/vizabi/commands.json +7 -0
- package/dist/components/vizabi/grammar.json +128 -0
- package/dist/gramlot.js +1190 -256
- package/dist/gramlot.min.js +85 -52
- package/dist/standard-collections.js +2 -0
- package/package.json +12 -4
- package/src/binding/grid-struct.js +2 -2
- package/src/binding/runtime.js +10 -0
- package/src/binding/validation-context.js +2 -1
- package/src/bootstrap.js +1 -1
- package/src/builder/gramlot-builder.d.ts +15 -2
- package/src/builder/gramlot-builder.js +22 -3
- package/src/builder/source.js +24 -1
- package/src/components/audio-analysis-session.js +65 -0
- package/src/components/audio.js +44 -0
- package/src/components/bases.js +11 -7
- package/src/components/border-container.js +6 -3
- package/src/components/buttons.js +47 -3
- package/src/components/chart-bar3d-options.js +30 -0
- package/src/components/chart-controls.js +83 -0
- package/src/components/chart-data-view.js +52 -0
- package/src/components/chart-data.js +42 -0
- package/src/components/chart-domains.js +46 -0
- package/src/components/chart-engines/echarts-options.js +50 -0
- package/src/components/chart-engines/echarts.js +82 -0
- package/src/components/chart-engines/index.js +22 -0
- package/src/components/chart-engines/plotly-map.js +34 -0
- package/src/components/chart-engines/plotly-spatial.js +35 -0
- package/src/components/chart-engines/plotly.js +138 -0
- package/src/components/chart-engines/uplot.js +57 -0
- package/src/components/chart-engines/vega.js +101 -0
- package/src/components/chart-fields.js +110 -0
- package/src/components/chart-geographic-options.js +47 -0
- package/src/components/chart-geojson.js +60 -0
- package/src/components/chart-geometry.js +11 -0
- package/src/components/chart-map-anchors.js +24 -0
- package/src/components/chart-map-bar3d-options.js +41 -0
- package/src/components/chart-map-data.js +25 -0
- package/src/components/chart-map-labels.js +8 -0
- package/src/components/chart-map-options.js +20 -0
- package/src/components/chart-pane.js +91 -0
- package/src/components/chart-renderer.js +58 -0
- package/src/components/chart-sample-view.js +32 -0
- package/src/components/chart-spatial-options.js +40 -0
- package/src/components/chart-time.js +84 -0
- package/src/components/chart-timeline.js +70 -0
- package/src/components/chart-types/area.js +2 -0
- package/src/components/chart-types/bar.js +2 -0
- package/src/components/chart-types/bar3D.js +2 -0
- package/src/components/chart-types/donut.js +2 -0
- package/src/components/chart-types/horizontalBar.js +2 -0
- package/src/components/chart-types/index.js +26 -0
- package/src/components/chart-types/line.js +2 -0
- package/src/components/chart-types/line3D.js +2 -0
- package/src/components/chart-types/lines3D.js +2 -0
- package/src/components/chart-types/map.js +2 -0
- package/src/components/chart-types/map3D.js +2 -0
- package/src/components/chart-types/mapBar3D.js +2 -0
- package/src/components/chart-types/pie.js +2 -0
- package/src/components/chart-types/polygons3D.js +2 -0
- package/src/components/chart-types/scatter.js +2 -0
- package/src/components/chart-types/scatter3D.js +2 -0
- package/src/components/chart-types/stackedArea.js +2 -0
- package/src/components/chart-types/stackedBar.js +2 -0
- package/src/components/chart-types/surface.js +2 -0
- package/src/components/charts.js +152 -0
- package/src/components/check-box-text-editor.js +88 -0
- package/src/components/check-box-text.js +193 -0
- package/src/components/check-box-tree.js +62 -0
- package/src/components/choice-editor.js +35 -18
- package/src/components/choice-field-styles.js +14 -0
- package/src/components/choices.js +5 -0
- package/src/components/database-choices.js +9 -6
- package/src/components/drawing.js +199 -0
- package/src/components/field-state.js +8 -1
- package/src/components/grid-cell-editor.js +83 -19
- package/src/components/grid-check-sets.js +98 -0
- package/src/components/grid-column-filters.js +198 -0
- package/src/components/grid-grammar.json +65 -0
- package/src/components/grid-header-interaction.js +3 -1
- package/src/components/grid-rows.js +2 -2
- package/src/components/grid-search-box.js +38 -22
- package/src/components/grid-search-styles.js +13 -14
- package/src/components/grid-search.js +8 -1
- package/src/components/grid-structure.js +13 -2
- package/src/components/grid-styles.js +34 -2
- package/src/components/grid.js +67 -10
- package/src/components/image-uploader.js +2 -2
- package/src/components/inputs.js +21 -12
- package/src/components/labelbox.js +5 -1
- package/src/components/licenses/claygl.txt +23 -0
- package/src/components/licenses/echarts-gl.txt +29 -0
- package/src/components/licenses/plotly.txt +21 -0
- package/src/components/licenses/uplot.txt +21 -0
- package/src/components/licenses/vega.txt +27 -0
- package/src/components/menus.js +19 -11
- package/src/components/parameters.js +6 -2
- package/src/components/toolbar-overflow.js +12 -8
- package/src/components/tree.js +31 -8
- package/src/components/typed-editor.js +18 -7
- package/src/components/validation.js +1 -1
- package/src/components/vizabi-session.js +66 -0
- package/src/components/vizabi.js +66 -0
- package/src/components/window-surface.js +20 -9
- package/src/components/windows.js +1 -1
- package/src/editing-session.d.ts +1 -0
- package/src/editing-session.js +113 -15
- package/src/editor-values.js +57 -0
- package/src/gramlot.d.ts +2 -0
- package/src/gramlot.js +9 -4
- package/src/handlers/device-handler.js +32 -32
- package/src/handlers/source-handler.d.ts +2 -2
- package/src/ide-documents.js +19 -3
- package/src/ide-runtime.d.ts +1 -0
- package/src/ide-runtime.js +45 -31
- package/src/index.d.ts +2 -1
- package/src/renderer/drag-drop.js +1 -0
- package/src/renderer/gramlot-renderer.d.ts +3 -0
- package/src/renderer/gramlot-renderer.js +16 -4
- package/src/server/assets.d.ts +3 -0
- package/src/server/assets.js +9 -0
- package/src/server/gramlot-server.d.ts +1 -1
- package/src/server/gramlot-server.js +2 -1
- package/src/server/index.d.ts +1 -1
- package/src/server/index.js +1 -1
- package/src/server/source-import.d.ts +1 -1
- package/src/server/source-import.js +5 -1
- package/src/server/visual-editor.d.ts +1 -1
- package/src/server/visual-editor.js +44 -34
- package/src/source-picker.d.ts +1 -1
- package/src/source-picker.js +1 -2
- package/src/stores/bag-collection-view.js +79 -17
- package/src/stores/collection-filter.js +2 -1
- package/src/stores/column-filter.js +49 -0
- package/src/stores/id-set.js +10 -0
- package/src/view/controls.js +8 -0
- package/src/view/html.js +10 -1
- package/src/view/label-menu.js +61 -0
- package/src/view/labelbox.js +15 -2
- package/src/visual-editor-canvas.js +29 -0
- package/src/visual-editor-catalogue.js +34 -0
- package/src/visual-editor.d.ts +5 -0
- package/src/visual-editor.js +244 -26
- package/themes/gramlot-base/theme.css +84 -36
- package/tools/gramlot-tools-inspector.js +170 -506
- package/tools/inspector-agent.js +1 -1
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import {Bag, sourceTarget} from '@gramlot/gramlot';
|
|
2
|
+
import {positionPopup} from './popup.js';
|
|
3
|
+
import {cellText} from './grid-rows.js';
|
|
4
|
+
import {SVG_NS} from '../renderer/attributes.js';
|
|
5
|
+
import {randomId} from '../random-id.js';
|
|
6
|
+
|
|
7
|
+
/** Source composition over a derived Data Bag; accepted filters remain in the outer view. */
|
|
8
|
+
export class GridColumnFilters {
|
|
9
|
+
#host; #head; #view; #columns = []; #format; #context;
|
|
10
|
+
#panel; #anchor = null; #field = null; #pane; #frame; #search; #path; #data;
|
|
11
|
+
#rangeQueued = false; #rangeFields = [];
|
|
12
|
+
#release; #registrations = []; #connected = false; #syncing = false;
|
|
13
|
+
constructor(host, head) {
|
|
14
|
+
this.#host=host;this.#head=head;
|
|
15
|
+
const panel=this.#panel=host.ownerDocument.createElement('div');
|
|
16
|
+
panel.className='column-filter-panel';panel.setAttribute('popover','auto');panel.setAttribute('role','dialog');
|
|
17
|
+
const slot=host.ownerDocument.createElement('slot');slot.name='column-filter';panel.append(slot);
|
|
18
|
+
panel.addEventListener('toggle',event=>{if(event.newState==='closed' && !panel.matches(':popover-open'))this.#closed();});
|
|
19
|
+
host.addEventListener('keydown',event=>{
|
|
20
|
+
if(this.#anchor && event.key==='Escape'){event.preventDefault();event.stopPropagation();this.close();}
|
|
21
|
+
});
|
|
22
|
+
host.shadowRoot.append(panel);
|
|
23
|
+
}
|
|
24
|
+
setSourceContext(context) {
|
|
25
|
+
this.#context=context;
|
|
26
|
+
const owner=context.sourceNode,builder=owner.rootBuilder;
|
|
27
|
+
// Prepare the child Source during initial component construction, before it is rendered.
|
|
28
|
+
// Opening the popup later inserts children; it never replaces the grid Source value.
|
|
29
|
+
if(owner.staticValue===null)owner.setValue(new builder.source.constructor(null,builder),false);
|
|
30
|
+
context.sourceNode.rootBuilder.binding.bindingFor(context.sourceNode).track(()=>this.dispose());
|
|
31
|
+
}
|
|
32
|
+
#build() {
|
|
33
|
+
if(this.#data)return;
|
|
34
|
+
const owner=this.#context.sourceNode,builder=owner.rootBuilder;
|
|
35
|
+
this.#path=`_gramlot.grid.${randomId()}.columnFilter`;
|
|
36
|
+
this.#data=new Bag({rows:new Bag(),checked:'',title:'',summary:'',from:null,to:null,hideRange:true,rangeError:''});
|
|
37
|
+
owner.setRelativeData(this.#path,this.#data);
|
|
38
|
+
const container=builder.wrapSource(owner).div({node_label:`column_filter_${randomId()}`,slot:'column-filter',
|
|
39
|
+
display:'flex',flex_direction:'column',gap:'8px',padding:'10px',
|
|
40
|
+
style:'font-size:12px;--gramlot-grid-row-height:28px;--gramlot-grid-font-size:12px;--gramlot-grid-cell-padding:4px 7px;--gramlot-menu-item-padding:4px 7px'});
|
|
41
|
+
this.#pane=sourceTarget(container);
|
|
42
|
+
this.#pane.setAttr({datapath:this.#path});
|
|
43
|
+
const fragment=new builder.source.constructor(null,builder);
|
|
44
|
+
const pane=builder.wrapSource(fragment);
|
|
45
|
+
pane.div('^.title',{font_weight:'600',padding:'0 2px'});
|
|
46
|
+
const dates=pane.div({display:'flex',gap:'8px',hidden:'^.hideRange'});
|
|
47
|
+
this.#rangeFields=[sourceTarget(dates.dateTextBox({value:'^.from',period_to:'.to',lbl:'From',width:'136px'})),
|
|
48
|
+
sourceTarget(dates.dateTextBox({value:'^.to',lbl:'To',width:'136px'}))];
|
|
49
|
+
pane.div('^.rangeError',{role:'alert',color:'var(--gramlot-error)'});
|
|
50
|
+
const frame=pane.frameGrid({storepath:'.rows',rowMode:'attributes',height:'270px',width:'100%'});
|
|
51
|
+
this.#frame=sourceTarget(frame);
|
|
52
|
+
this.#search=sourceTarget(frame.toolbar.menuline({group:true,class:'gramlot-grid-search'})
|
|
53
|
+
.searchBox({searchOn:'Value:caption',searchLiteral:true}));
|
|
54
|
+
const grid=frame.grid;
|
|
55
|
+
grid.setAttr({sortedBy:'caption:a'});
|
|
56
|
+
const struct=grid.struct();
|
|
57
|
+
struct.column({field:'selected',name:'✓',title:'Selected values',width:'32px',align:'center',check:'multiple',checked:'^.checked',checkedField:'id'});
|
|
58
|
+
struct.column({field:'caption',name:'Value',width:'170px'});
|
|
59
|
+
struct.column({field:'count',name:'Rows',dtype:'L',width:'64px',align:'end'});
|
|
60
|
+
const bar=pane.menu({presentation:'bar',aria_label:'Column filter actions'});
|
|
61
|
+
Object.defineProperty(sourceTarget(bar),'gridColumnFilters',{value:this,configurable:true});
|
|
62
|
+
for(const [caption,method] of [['All','selectAll'],['None','selectNone'],['Reset','reset']]) {
|
|
63
|
+
bar.menuline({caption,action:`this.parentBag.parentNode.gridColumnFilters.${method}()`});
|
|
64
|
+
}
|
|
65
|
+
pane.div('^.summary',{color:'var(--gramlot-text-secondary)',font_size:'11px',padding:'0 2px'});
|
|
66
|
+
const prepared=builder.binding.gramlot.src.prepareSource(fragment);
|
|
67
|
+
builder.binding.renderer.validateCandidate(prepared);
|
|
68
|
+
this.#pane.setValue(prepared);
|
|
69
|
+
this.#subscribeData();
|
|
70
|
+
}
|
|
71
|
+
#subscribeData() {
|
|
72
|
+
if(!this.#data || this.#registrations.length)return;
|
|
73
|
+
const router=this.#context.sourceNode.rootBuilder.binding.router;
|
|
74
|
+
this.#registrations.push(router.register({path:this.#path+'.checked',recipient:{receive:()=>this.#selectionChanged()}}));
|
|
75
|
+
for(const name of ['from','to'])this.#registrations.push(router.register({path:this.#path+'.'+name,recipient:{receive:()=>this.#queueRange()}}));
|
|
76
|
+
}
|
|
77
|
+
#selectionChanged() {
|
|
78
|
+
if(this.#syncing || this.#field===null)return;
|
|
79
|
+
const checked=','+this.#data.getItem('checked')+',';
|
|
80
|
+
const nodes=this.#data.getItem('rows').getNodes();
|
|
81
|
+
const values=nodes.filter(node=>checked.includes(','+node.label+',' )).map(node=>node.getAttr('value'));
|
|
82
|
+
this.#view.applyColumnFilter(this.#field,this.#view.columnRange(this.#field) && values.length===nodes.length ? null : values);
|
|
83
|
+
}
|
|
84
|
+
#queueRange() {
|
|
85
|
+
if(this.#syncing || this.#rangeQueued || this.#field===null)return;
|
|
86
|
+
this.#rangeQueued=true;
|
|
87
|
+
// period_to and the edited start commit in the same turn.
|
|
88
|
+
queueMicrotask(()=>{this.#rangeQueued=false;if(this.#field!==null && this.#connected)this.#rangeChanged();});
|
|
89
|
+
}
|
|
90
|
+
#rangeChanged() {
|
|
91
|
+
const column=this.#columns.find(item=>item.field===this.#field);
|
|
92
|
+
if(!['D','DH','DHZ'].includes(column.dtype))return;
|
|
93
|
+
let from=this.#data.getItem('from'),to=this.#data.getItem('to');
|
|
94
|
+
const previous=this.#view.columnRange(this.#field);
|
|
95
|
+
if(previous?.from && !from){to=null;this.#syncing=true;this.#data.setItem('to',null);this.#syncing=false;}
|
|
96
|
+
if(from && to && from>to){this.#data.setItem('rangeError','From must not be after To.');return;}
|
|
97
|
+
this.#data.setItem('rangeError','');
|
|
98
|
+
if(+from===+(previous?.from ?? null) && +to===+(previous?.to ?? null))return;
|
|
99
|
+
const values=!from && !to ? this.#view.columnFacets(this.#field).filter(item=>item.selected).map(item=>item.value) : null;
|
|
100
|
+
this.#view.applyColumnFilter(this.#field,values,{from,to,dtype:column.dtype,timeZone:this.#context.timeZone});
|
|
101
|
+
}
|
|
102
|
+
selectAll() { this.#view.applyColumnFilter(this.#field,this.#view.columnRange(this.#field) ? null : this.#view.columnFacets(this.#field).map(item=>item.value)); }
|
|
103
|
+
selectNone() { this.#view.applyColumnFilter(this.#field,[]); }
|
|
104
|
+
reset() {
|
|
105
|
+
this.#syncing=true;
|
|
106
|
+
try {
|
|
107
|
+
this.#data.setItem('from',null);this.#data.setItem('to',null);this.#data.setItem('rangeError','');
|
|
108
|
+
const renderer=this.#context.sourceNode.rootBuilder.binding.renderer;
|
|
109
|
+
for(const node of this.#rangeFields)renderer.getDomNode(node).restoreFormValue(null);
|
|
110
|
+
} finally {this.#syncing=false;}
|
|
111
|
+
this.#view.applyColumnFilter(this.#field,null,null);
|
|
112
|
+
}
|
|
113
|
+
button(column) {
|
|
114
|
+
const doc = this.#host.ownerDocument, button = doc.createElement('button');
|
|
115
|
+
button.type = 'button'; button.className = 'column-filter'; button.dataset.field = column.field;
|
|
116
|
+
button.setAttribute('aria-label',`Filter ${column.title ?? column.name}`);
|
|
117
|
+
button.setAttribute('aria-haspopup','dialog');button.setAttribute('aria-expanded','false');
|
|
118
|
+
button.title = `Filter ${column.title ?? column.name}`;
|
|
119
|
+
const svg=doc.createElementNS(SVG_NS,'svg');svg.setAttribute('viewBox','0 0 24 24');svg.setAttribute('aria-hidden','true');
|
|
120
|
+
const path=doc.createElementNS(SVG_NS,'path');path.setAttribute('d','M3 5h18l-7 8v6l-4 2v-8z');svg.append(path);button.append(svg);
|
|
121
|
+
return button;
|
|
122
|
+
}
|
|
123
|
+
update(view,columns,enabled,format) {
|
|
124
|
+
if(view!==this.#view){this.close();this.#release?.();this.#release=null;this.#view=view;}
|
|
125
|
+
this.#columns=columns;this.#format=format;
|
|
126
|
+
if(!enabled || this.#anchor && !this.#anchor.isConnected)this.close();
|
|
127
|
+
if(this.#connected && !this.#release)this.#release=view.subscribe(this.refresh);
|
|
128
|
+
this.refresh();
|
|
129
|
+
}
|
|
130
|
+
#click = event => {
|
|
131
|
+
const anchor=event.target.closest('.column-filter');
|
|
132
|
+
if(!anchor)return;event.stopPropagation();
|
|
133
|
+
if(anchor===this.#anchor){this.close();return;}
|
|
134
|
+
this.close();this.#build();this.#anchor=anchor;this.#field=anchor.dataset.field;
|
|
135
|
+
this.#syncing=true;
|
|
136
|
+
const range=this.#view.columnRange(this.#field);
|
|
137
|
+
this.#data.setItem('from',range?.from ?? null);this.#data.setItem('to',range?.to ?? null);this.#data.setItem('rangeError','');
|
|
138
|
+
const column=this.#columns.find(item=>item.field===this.#field);
|
|
139
|
+
this.#data.setItem('hideRange',!['D','DH','DHZ'].includes(column.dtype));
|
|
140
|
+
const renderer=this.#context.sourceNode.rootBuilder.binding.renderer;
|
|
141
|
+
for(const [index,key] of ['from','to'].entries())renderer.getDomNode(this.#rangeFields[index]).restoreFormValue(this.#data.getItem(key));
|
|
142
|
+
this.#data.getItem('rows').clear();this.#data.setItem('checked','');renderer.getDomNode(this.#search).clear();
|
|
143
|
+
this.#syncing=false;
|
|
144
|
+
this.refresh();this.#panel.showPopover();anchor.setAttribute('aria-expanded','true');this.#position();
|
|
145
|
+
this.#context.sourceNode.rootBuilder.binding.renderer.getDomNode(this.#search).focus();
|
|
146
|
+
};
|
|
147
|
+
refresh = () => {
|
|
148
|
+
if(!this.#view)return;
|
|
149
|
+
for(const button of this.#head.querySelectorAll('.column-filter')) {
|
|
150
|
+
const active=(this.#view.columnFilter(button.dataset.field)!==null || this.#view.columnRange(button.dataset.field)!==null);
|
|
151
|
+
button.classList.toggle('active',active);button.closest('th').classList.toggle('column-filtered',active);
|
|
152
|
+
button.setAttribute('aria-pressed',String(active));
|
|
153
|
+
}
|
|
154
|
+
if(this.#field===null)return;
|
|
155
|
+
const column=this.#columns.find(column=>column.field===this.#field);
|
|
156
|
+
if(!column){this.close();return;}
|
|
157
|
+
const title=column.title??column.name;
|
|
158
|
+
this.#panel.setAttribute('aria-label',`Filter ${title}`);
|
|
159
|
+
const entries=this.#view.columnFacets(this.#field),rows=this.#data.getItem('rows');
|
|
160
|
+
this.#frame.setAttr({height:`${76+28*Math.max(1,Math.min(entries.length,8))}px`});
|
|
161
|
+
const existing=new Map(rows.getNodes().map(node=>[node.getAttr('key'),node]));
|
|
162
|
+
const selected=[];
|
|
163
|
+
this.#syncing=true;
|
|
164
|
+
try {
|
|
165
|
+
this.#data.setItem('title',title);
|
|
166
|
+
for(const entry of entries) {
|
|
167
|
+
const caption=entry.value===null?'Empty':cellText(entry.value,column,this.#format);
|
|
168
|
+
const attrs={key:entry.key,value:entry.value,caption,count:entry.count};
|
|
169
|
+
let node=existing.get(entry.key);
|
|
170
|
+
if(node){existing.delete(entry.key);node.setAttr(attrs);}
|
|
171
|
+
else {const id=`v_${randomId()}`;rows.setItem(id,null,{...attrs,id});node=rows.getNode(id);}
|
|
172
|
+
if(entry.selected)selected.push(node.label);
|
|
173
|
+
}
|
|
174
|
+
for(const node of existing.values())rows.popNode(node.label);
|
|
175
|
+
const checked=selected.join(',');
|
|
176
|
+
if(this.#data.getItem('checked')!==checked)this.#data.setItem('checked',checked);
|
|
177
|
+
this.#data.setItem('summary',`${selected.length} of ${entries.length} values selected`);
|
|
178
|
+
} finally {this.#syncing=false;}
|
|
179
|
+
this.#position();
|
|
180
|
+
};
|
|
181
|
+
#position = () => {if(this.#anchor)positionPopup(this.#panel,this.#anchor,{align:'start'});};
|
|
182
|
+
#closed(){this.#anchor?.setAttribute('aria-expanded','false');this.#anchor=null;this.#field=null;}
|
|
183
|
+
close(){if(!this.#anchor)return;const anchor=this.#anchor;this.#panel.hidePopover();this.#closed();if(anchor.isConnected)anchor.focus({preventScroll:true});}
|
|
184
|
+
connect(){
|
|
185
|
+
if(this.#connected)return;this.#connected=true;this.#subscribeData();
|
|
186
|
+
this.#head.addEventListener('click',this.#click);
|
|
187
|
+
this.#host.ownerDocument.defaultView.addEventListener('resize',this.#position);
|
|
188
|
+
this.#host.ownerDocument.defaultView.addEventListener('scroll',this.#position,true);
|
|
189
|
+
}
|
|
190
|
+
disconnect(){
|
|
191
|
+
this.close();this.#connected=false;this.#release?.();this.#release=null;
|
|
192
|
+
for(const registration of this.#registrations)registration.close();this.#registrations=[];
|
|
193
|
+
this.#head.removeEventListener('click',this.#click);
|
|
194
|
+
this.#host.ownerDocument.defaultView.removeEventListener('resize',this.#position);
|
|
195
|
+
this.#host.ownerDocument.defaultView.removeEventListener('scroll',this.#position,true);
|
|
196
|
+
}
|
|
197
|
+
dispose(){this.disconnect();if(this.#path)this.#context.sourceNode.data.popNode(this.#path);}
|
|
198
|
+
}
|
|
@@ -101,6 +101,27 @@
|
|
|
101
101
|
"has_default": true,
|
|
102
102
|
"default": null
|
|
103
103
|
},
|
|
104
|
+
{
|
|
105
|
+
"name": "max_height",
|
|
106
|
+
"kind": "keyword_only",
|
|
107
|
+
"role": "attribute",
|
|
108
|
+
"annotation": {
|
|
109
|
+
"kind": "annotated",
|
|
110
|
+
"base": {
|
|
111
|
+
"kind": "dtype",
|
|
112
|
+
"dtype": "T"
|
|
113
|
+
},
|
|
114
|
+
"metadata": [
|
|
115
|
+
{
|
|
116
|
+
"kind": "regex",
|
|
117
|
+
"pattern": "^[0-9]+([.][0-9]+)?(px|em|rem)$",
|
|
118
|
+
"flags": 0
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
"has_default": true,
|
|
123
|
+
"default": null
|
|
124
|
+
},
|
|
104
125
|
{
|
|
105
126
|
"name": "align",
|
|
106
127
|
"kind": "keyword_only",
|
|
@@ -174,6 +195,50 @@
|
|
|
174
195
|
},
|
|
175
196
|
"has_default": true,
|
|
176
197
|
"default": false
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"name": "check",
|
|
201
|
+
"kind": "keyword_only",
|
|
202
|
+
"role": "attribute",
|
|
203
|
+
"annotation": {
|
|
204
|
+
"kind": "dtype",
|
|
205
|
+
"dtype": "T"
|
|
206
|
+
},
|
|
207
|
+
"has_default": true,
|
|
208
|
+
"default": null
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"name": "checked",
|
|
212
|
+
"kind": "keyword_only",
|
|
213
|
+
"role": "attribute",
|
|
214
|
+
"annotation": {
|
|
215
|
+
"kind": "dtype",
|
|
216
|
+
"dtype": "T"
|
|
217
|
+
},
|
|
218
|
+
"has_default": true,
|
|
219
|
+
"default": null
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"name": "checkedField",
|
|
223
|
+
"kind": "keyword_only",
|
|
224
|
+
"role": "attribute",
|
|
225
|
+
"annotation": {
|
|
226
|
+
"kind": "dtype",
|
|
227
|
+
"dtype": "T"
|
|
228
|
+
},
|
|
229
|
+
"has_default": true,
|
|
230
|
+
"default": null
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"name": "title",
|
|
234
|
+
"kind": "keyword_only",
|
|
235
|
+
"role": "attribute",
|
|
236
|
+
"annotation": {
|
|
237
|
+
"kind": "dtype",
|
|
238
|
+
"dtype": "T"
|
|
239
|
+
},
|
|
240
|
+
"has_default": true,
|
|
241
|
+
"default": null
|
|
177
242
|
}
|
|
178
243
|
],
|
|
179
244
|
"accepts_var_keyword": false,
|
|
@@ -46,11 +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')) return;
|
|
49
|
+
if (event.target.closest('.column-resize, .column-filter')) 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
55
|
const header = event.target.closest('th[data-field]');
|
|
55
56
|
if (!header || this.#gesture) { event.preventDefault(); return; }
|
|
56
57
|
this.#suppressClick = true;
|
|
@@ -149,6 +150,7 @@ export class GridHeaderInteraction {
|
|
|
149
150
|
this.#focus(gesture.field);
|
|
150
151
|
};
|
|
151
152
|
#key = event => {
|
|
153
|
+
if (event.target.closest('.column-filter')) return;
|
|
152
154
|
if (event.key === 'Escape' && this.#gesture) {
|
|
153
155
|
this.cancel(); event.preventDefault(); return;
|
|
154
156
|
}
|
|
@@ -8,11 +8,11 @@ export class GridRows {
|
|
|
8
8
|
}
|
|
9
9
|
read(columns, nodes = this.store.getRows()) {
|
|
10
10
|
return nodes.map(node => ({node, cells:columns.map(column =>
|
|
11
|
-
cellText(this.store.value(node, column.field), column, this.format))}));
|
|
11
|
+
column.check ? '' : cellText(this.store.value(node, column.field), column, this.format))}));
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function cellText(value, column, format) {
|
|
15
|
+
export function cellText(value, column, format) {
|
|
16
16
|
if (value == null) return '';
|
|
17
17
|
const {dtype, format: pattern} = column;
|
|
18
18
|
if (dtype === 'T' && typeof value !== 'string' || dtype === 'B' && typeof value !== 'boolean') throw new TypeError(`grid ${column.field} does not match ${dtype}`);
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import {defineComponent} from './registry.js';
|
|
2
|
+
import {Labelbox} from './labelbox.js';
|
|
2
3
|
import {Container} from './container.js';
|
|
3
4
|
import {gridSearch, searchColumns} from './grid-search.js';
|
|
4
5
|
import {SVG_NS} from '../renderer/attributes.js';
|
|
5
6
|
import {positionPopup} from './popup.js';
|
|
6
|
-
import {gridSearchStyles} from './grid-search-styles.js';
|
|
7
|
+
import {gridSearchStyles, gridSearchLabelStyle} from './grid-search-styles.js';
|
|
7
8
|
|
|
8
9
|
/** FrameGrid's search slot. The collection view owns the accepted filter. */
|
|
9
10
|
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'},
|
|
11
|
+
name:'searchBox', tag:'gramlot-search-box', base:Container, sourceContext:true, mixins:[Labelbox],
|
|
12
|
+
parameters:{lbl_position:{dtype:'T',default:'L',binding:'read'},searchLiteral:{dtype:'B',default:false,binding:'read'},searchHelp:{dtype:'B',default:false,binding:'read'},searchOn:{dtype:['B','T'], default:true, binding:'read'},
|
|
12
13
|
searchTime:{dtype:'R', nullable:true, default:null, binding:'write'}},
|
|
13
14
|
implementation:Base => class extends Base {
|
|
14
15
|
#context; #grid; #release; #releaseView; #view; #timer = null;
|
|
15
|
-
#
|
|
16
|
+
#input; #error; #info; #help; #helpText; #filterSignature; #bag;
|
|
16
17
|
constructor() {
|
|
17
18
|
super();
|
|
18
19
|
const doc = this.ownerDocument;
|
|
@@ -22,22 +23,19 @@ export const SearchBox = defineComponent({
|
|
|
22
23
|
const svg = doc.createElementNS(SVG_NS,'svg'); svg.setAttribute('viewBox','0 0 24 24'); svg.setAttribute('aria-hidden','true');
|
|
23
24
|
const shape = doc.createElementNS(SVG_NS,'path'); shape.setAttribute('d',path); svg.append(shape); return svg;
|
|
24
25
|
};
|
|
25
|
-
this.#field = doc.createElement('select'); this.#field.setAttribute('aria-label','Search column');
|
|
26
26
|
this.#input = doc.createElement('input'); this.#input.type = 'text'; this.#input.setAttribute('role','searchbox'); this.#input.setAttribute('aria-label','Filter rows');
|
|
27
27
|
this.#input.setAttribute('aria-describedby','search-error');
|
|
28
28
|
this.#input.placeholder = ' ';
|
|
29
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
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
31
|
const entry = doc.createElement('span'); entry.className = 'search-entry';
|
|
34
32
|
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
33
|
clear.className = 'clear';
|
|
36
|
-
const info = doc.createElement('button'); info.type = 'button'; info.className = 'info';
|
|
34
|
+
const info = this.#info = doc.createElement('button'); info.type = 'button'; info.className = 'info'; info.hidden = true;
|
|
37
35
|
info.setAttribute('aria-label','Search instructions'); info.title = 'Search instructions';
|
|
38
36
|
info.setAttribute('aria-haspopup','dialog'); info.setAttribute('aria-expanded','false'); info.setAttribute('aria-controls','search-help');
|
|
39
37
|
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';
|
|
38
|
+
const help = this.#help = doc.createElement('div'); help.id = 'search-help'; help.className = 'search-help';
|
|
41
39
|
help.setAttribute('popover','auto'); help.setAttribute('role','dialog'); help.setAttribute('aria-label','Search instructions');
|
|
42
40
|
const heading = doc.createElement('strong'); heading.textContent = 'Search instructions';
|
|
43
41
|
this.#helpText = doc.createElement('p');
|
|
@@ -49,7 +47,7 @@ export const SearchBox = defineComponent({
|
|
|
49
47
|
});
|
|
50
48
|
help.addEventListener('toggle', () => info.setAttribute('aria-expanded',String(help.matches(':popover-open'))));
|
|
51
49
|
entry.append(lens,this.#input,clear,info);
|
|
52
|
-
this.control.replaceChildren(
|
|
50
|
+
this.control.replaceChildren(entry,this.#error);
|
|
53
51
|
this.shadowRoot.append(style);
|
|
54
52
|
this.#input.addEventListener('input', () => {
|
|
55
53
|
this.#cancel(); this.#timer = doc.defaultView.setTimeout(() => { this.#timer = null; this.#apply(); },100);
|
|
@@ -59,9 +57,17 @@ export const SearchBox = defineComponent({
|
|
|
59
57
|
if (event.key === 'Enter') { event.preventDefault(); this.#cancel(); this.#apply(); }
|
|
60
58
|
if (event.key === 'Escape') { event.preventDefault(); this.#clear(); }
|
|
61
59
|
});
|
|
62
|
-
this.#field.addEventListener('change', () => this.#clear());
|
|
63
60
|
clear.addEventListener('click', () => {this.#clear(); this.#input.focus();});
|
|
64
61
|
}
|
|
62
|
+
setLabelbox(layout) {
|
|
63
|
+
super.setLabelbox(layout);
|
|
64
|
+
layout.box.classList.add('gramlot-search-labelbox');
|
|
65
|
+
const style = this.ownerDocument.createElement('style');
|
|
66
|
+
style.textContent = gridSearchLabelStyle;
|
|
67
|
+
layout.box.prepend(style);
|
|
68
|
+
}
|
|
69
|
+
focus(options) { this.#input.focus(options); }
|
|
70
|
+
clear() { this.#clear(); }
|
|
65
71
|
setSourceContext(context) {
|
|
66
72
|
this.#context = context;
|
|
67
73
|
const target = context.frameRecipient();
|
|
@@ -69,8 +75,16 @@ export const SearchBox = defineComponent({
|
|
|
69
75
|
this.#grid = gridSearch(target);
|
|
70
76
|
}
|
|
71
77
|
projectAttributes(attrs, adapt) {
|
|
78
|
+
const previous = this.parameters?.lbl_value;
|
|
72
79
|
const rest = super.projectAttributes(attrs, adapt);
|
|
73
|
-
|
|
80
|
+
const wasVisible = !this.#info.hidden;
|
|
81
|
+
this.#info.hidden = !this.parameters.searchHelp;
|
|
82
|
+
if (wasVisible && this.#info.hidden && this.#help.matches(':popover-open')) this.#help.hidePopover();
|
|
83
|
+
if (this.isConnected) {
|
|
84
|
+
this.#configure();
|
|
85
|
+
if (previous != null && previous !== this.parameters.lbl_value
|
|
86
|
+
&& this.#view?.filter?.columns.join('+') !== this.parameters.lbl_value) this.#clear();
|
|
87
|
+
}
|
|
74
88
|
return rest;
|
|
75
89
|
}
|
|
76
90
|
connectedCallback() {
|
|
@@ -92,12 +106,13 @@ export const SearchBox = defineComponent({
|
|
|
92
106
|
this.#filterSignature = undefined;
|
|
93
107
|
this.#releaseView = this.#view.subscribe(() => this.#sync());
|
|
94
108
|
}
|
|
95
|
-
const previous = this.#field.value;
|
|
96
109
|
const options = searchColumns(this.parameters.searchOn,this.#grid.columns);
|
|
97
|
-
this.#
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
110
|
+
const node = this.#context.sourceNode;
|
|
111
|
+
const values = options.map(({field,name}) => `${field}:${name}`).join(',');
|
|
112
|
+
const value = options.some(option => option.field === this.parameters.lbl_value)
|
|
113
|
+
? this.parameters.lbl_value : options[0]?.field ?? '';
|
|
114
|
+
if (node.getAttr('lbl_values') !== values) node.setAttr({lbl_values:values});
|
|
115
|
+
if (this.parameters.lbl_value !== value) this.box.labelbox.choose(value);
|
|
101
116
|
this.#input.disabled = !options.length;
|
|
102
117
|
this.#sync(); this.#hint();
|
|
103
118
|
}
|
|
@@ -108,17 +123,18 @@ export const SearchBox = defineComponent({
|
|
|
108
123
|
if (this.#filterSignature === signature) return;
|
|
109
124
|
this.#filterSignature = signature;
|
|
110
125
|
this.#cancel(); this.#input.value = filter?.value ?? '';
|
|
111
|
-
if (filter
|
|
126
|
+
if (filter && this.parameters.lbl_value !== filter.columns.join('+'))
|
|
127
|
+
this.box.labelbox.choose(filter.columns.join('+'));
|
|
112
128
|
this.#error.textContent = ''; this.#input.removeAttribute('aria-invalid'); this.#hint();
|
|
113
129
|
}
|
|
114
130
|
#dtype() {
|
|
115
|
-
const column = this.#grid.columns.find(column => column.field === this
|
|
131
|
+
const column = this.#grid.columns.find(column => column.field === this.parameters.lbl_value);
|
|
116
132
|
return ['L','R','N','D'].includes(column?.dtype) ? column.dtype : 'T';
|
|
117
133
|
}
|
|
118
134
|
#hint() {
|
|
119
135
|
const dtype = this.#dtype();
|
|
120
136
|
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.'
|
|
137
|
+
? this.parameters.searchLiteral ? 'Type literal text to find it anywhere. Matching is case-insensitive.' : '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
138
|
: dtype === 'D'
|
|
123
139
|
? 'Compare dates: = 2026-10-15, >= 2026-10-15 or < 2026-10-15. ISO dates and your browser’s local date notation are accepted.'
|
|
124
140
|
: 'Compare numbers: = 12, > 100, <= 50 or ! 0 (not equal). Decimal punctuation follows your browser locale.';
|
|
@@ -129,8 +145,8 @@ export const SearchBox = defineComponent({
|
|
|
129
145
|
try {
|
|
130
146
|
const value = this.#input.value;
|
|
131
147
|
const started = performance.now();
|
|
132
|
-
this.#view.applyFilter(value.trim() ? {value, columns:this
|
|
133
|
-
locale:this.#context.locale,
|
|
148
|
+
this.#view.applyFilter(value.trim() ? {value, columns:this.parameters.lbl_value.split('+'), dtype:this.#dtype(),
|
|
149
|
+
...(this.parameters.searchLiteral ? {literal:true} : {}), locale:this.#context.locale,
|
|
134
150
|
timeZone:this.#context.timeZone} : null);
|
|
135
151
|
this.#context.writeParameter('searchTime', performance.now() - started);
|
|
136
152
|
this.#error.textContent = ''; this.#input.removeAttribute('aria-invalid');
|
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
/** Search capsule: uses shared field, surface and focus tokens in every theme. */
|
|
2
|
+
export const gridSearchLabelStyle = `.gramlot-search-labelbox{inline-size:var(--gramlot-search-width,240px);max-inline-size:100%;font-size:var(--gramlot-search-font-size,12px)}`;
|
|
2
3
|
export const gridSearchStyles = `
|
|
3
|
-
:host{display:inline-block;inline-size:
|
|
4
|
-
.control-box{display:flex;align-items:stretch;position:relative;min-block-size:var(--gramlot-
|
|
4
|
+
:host{display:inline-block;inline-size:100%;font-size:var(--gramlot-search-font-size,12px);max-inline-size:100%;min-inline-size:0}
|
|
5
|
+
.control-box{display:flex;align-items:stretch;position:relative;min-block-size:max(var(--gramlot-search-height,26px),var(--gramlot-touch-target,0px));
|
|
5
6
|
border:1px solid var(--gramlot-border,GrayText);border-radius:999px;
|
|
6
7
|
background:var(--gramlot-field-background,Canvas);color:var(--gramlot-ink,CanvasText);
|
|
7
8
|
transition:border-color .15s}
|
|
8
9
|
.control-box:hover{border-color:var(--gramlot-border-control,GrayText)}
|
|
9
10
|
.control-box:focus-within{border-color:var(--gramlot-border-control,GrayText)}
|
|
10
|
-
|
|
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}
|
|
11
|
+
input,button{font:inherit;color:inherit;min-inline-size:0;border:0;background:transparent}
|
|
16
12
|
.search-entry{position:relative;display:flex;align-items:center;flex:1;min-inline-size:0}
|
|
17
13
|
.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-
|
|
14
|
+
input{inline-size:100%;min-block-size:max(var(--gramlot-search-height,26px),var(--gramlot-touch-target,0px));padding:2px calc(2 * max(24px,var(--gramlot-touch-target,0px)) + 4px) 2px 26px;border-radius:999px;outline:none}
|
|
19
15
|
input::placeholder{color:var(--gramlot-text-secondary,GrayText);opacity:.75}
|
|
20
16
|
input:disabled{opacity:.5}
|
|
21
17
|
.clear,.info{position:absolute;display:grid;place-items:center;padding:.3rem;
|
|
22
|
-
inline-size:
|
|
23
|
-
.clear{inset-inline-end:
|
|
24
|
-
.info{
|
|
18
|
+
inline-size:max(24px,var(--gramlot-touch-target,0px));block-size:max(24px,var(--gramlot-touch-target,0px));border-radius:50%;color:var(--gramlot-text-secondary,GrayText);cursor:pointer}
|
|
19
|
+
.clear{inset-inline-end:calc(max(24px,var(--gramlot-touch-target,0px)) + 2px)}
|
|
20
|
+
.info[hidden]{display:none}
|
|
21
|
+
.search-entry:has(.info[hidden]) .clear{inset-inline-end:2px}
|
|
22
|
+
.search-entry:has(.info[hidden]) input{padding-inline-end:calc(max(24px,var(--gramlot-touch-target,0px)) + 4px)}
|
|
23
|
+
.info{inset-inline-end:2px;opacity:.7}
|
|
25
24
|
.clear:hover,.info:hover{color:var(--gramlot-ink,CanvasText);background:var(--gramlot-surface-subtle,ButtonFace)}
|
|
26
25
|
input:placeholder-shown~.clear{display:none}
|
|
27
|
-
|
|
26
|
+
button:focus-visible{outline:1px solid var(--gramlot-text-secondary,GrayText);outline-offset:-3px}
|
|
28
27
|
svg{width:1rem;height:1rem;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round;flex:none}
|
|
29
28
|
.control-box:has([aria-invalid=true]){border-color:var(--gramlot-error,Mark)}
|
|
30
29
|
.error{position:absolute;inset-block-start:calc(100% + .35rem);inset-inline:0;z-index:1;
|
|
@@ -36,7 +35,7 @@ svg{width:1rem;height:1rem;fill:none;stroke:currentColor;stroke-width:1.7;stroke
|
|
|
36
35
|
max-block-size:var(--gramlot-popup-available-height,80vh);overflow:auto;padding:1rem;
|
|
37
36
|
border:1px solid var(--gramlot-border,GrayText);border-radius:var(--gramlot-radius-lg,.75rem);
|
|
38
37
|
background:var(--gramlot-surface,Canvas);color:var(--gramlot-ink,CanvasText);
|
|
39
|
-
box-shadow:var(--gramlot-shadow,0 3px 12px #0002);font:inherit;font-size
|
|
38
|
+
box-shadow:var(--gramlot-shadow,0 3px 12px #0002);font:inherit;font-size:inherit;line-height:1.5}
|
|
40
39
|
.search-help p{margin:.6rem 0 0}.search-help p:last-child{color:var(--gramlot-text-secondary,GrayText)}
|
|
41
40
|
@media(prefers-reduced-motion:reduce){.control-box{transition:none}}
|
|
42
41
|
`;
|
|
@@ -9,6 +9,13 @@ export class GridSearch {
|
|
|
9
9
|
this.view = view; this.#bag = view.bag; this.columns = columns;
|
|
10
10
|
for (const listener of this.#listeners) listener();
|
|
11
11
|
}
|
|
12
|
+
detach(view) {
|
|
13
|
+
if (this.view !== view) return;
|
|
14
|
+
this.view = null;
|
|
15
|
+
this.#bag = null;
|
|
16
|
+
this.columns = [];
|
|
17
|
+
for (const listener of this.#listeners) listener();
|
|
18
|
+
}
|
|
12
19
|
subscribe(listener) { this.#listeners.add(listener); return () => this.#listeners.delete(listener); }
|
|
13
20
|
}
|
|
14
21
|
|
|
@@ -22,7 +29,7 @@ export function gridSearch(node) {
|
|
|
22
29
|
export function searchColumns(searchOn, columns) {
|
|
23
30
|
if (searchOn === true || typeof searchOn === 'string' && searchOn.startsWith('*')) {
|
|
24
31
|
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'},
|
|
32
|
+
return allowed.length ? [...(allowed.length > 1 ? [{field:allowed.map(column => column.field).join('+'), name:'All columns'}] : []),
|
|
26
33
|
...allowed.map(column => ({field:column.field, name:column.name}))] : [];
|
|
27
34
|
}
|
|
28
35
|
if (typeof searchOn !== 'string' || !searchOn.trim()) throw new TypeError('searchOn requires true or a column list');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Bag} from '@gramlot/gramlot';
|
|
2
2
|
|
|
3
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', 'edit']);
|
|
4
|
+
const COLUMN_KEYS = new Set(['tag', 'field', 'name', 'title', 'dtype', 'width', 'align', 'format', 'columnset', 'white_space', 'max_height', 'edit', 'check', 'checked', 'checkedField']);
|
|
5
5
|
const GROUP_KEYS = new Set(['tag', 'code', 'name', 'background', 'color']);
|
|
6
6
|
|
|
7
7
|
/** Legacy Data contract: ordered cells and independent columnset definitions. */
|
|
@@ -39,9 +39,20 @@ export class GridStructure {
|
|
|
39
39
|
if (attrs.width != null && (typeof attrs.width !== 'string' || !/^(?:\d+(?:\.\d+)?)(?:px|em|rem|ch|%)$/.test(attrs.width))) {
|
|
40
40
|
throw new TypeError('grid width requires a nonnegative CSS length (px, em, rem, ch or %)');
|
|
41
41
|
}
|
|
42
|
+
if (attrs.max_height != null && (typeof attrs.max_height !== 'string' || !/^(?:\d+(?:\.\d+)?)(?:px|em|rem)$/.test(attrs.max_height))) {
|
|
43
|
+
throw new TypeError('grid max_height requires a nonnegative CSS length (px, em or rem)');
|
|
44
|
+
}
|
|
42
45
|
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`);
|
|
46
|
+
for (const key of ['name', 'title', 'format']) if (attrs[key] != null && typeof attrs[key] !== 'string') throw new TypeError(`grid ${key} must be text`);
|
|
44
47
|
if (attrs.edit != null && typeof attrs.edit !== 'boolean' && (typeof attrs.edit !== 'object' || Array.isArray(attrs.edit))) throw new TypeError('grid edit requires a boolean or editor options');
|
|
48
|
+
if (attrs.check != null || attrs.checked != null || attrs.checkedField != null) {
|
|
49
|
+
if (!['multiple','single'].includes(attrs.check) || typeof attrs.checked !== 'string' ||
|
|
50
|
+
!attrs.checked.startsWith('^') || attrs.checked.length < 2 || attrs.checked.includes('?')) {
|
|
51
|
+
throw new TypeError('grid check requires single or multiple and checked=^DataPath');
|
|
52
|
+
}
|
|
53
|
+
requireIdentity(attrs.checkedField, 'checkedField');
|
|
54
|
+
if (attrs.edit) throw new TypeError('external check sets cannot edit row fields');
|
|
55
|
+
}
|
|
45
56
|
const column = Object.freeze({...attrs, name: attrs.name ?? attrs.field,
|
|
46
57
|
align: attrs.align ?? (['L', 'R', 'N'].includes(attrs.dtype) ? 'end' : 'start')});
|
|
47
58
|
this.columns.push(column);
|
|
@@ -2,12 +2,22 @@
|
|
|
2
2
|
* A JS stylesheet module keeps the same source usable in Node and browser builds.
|
|
3
3
|
*/
|
|
4
4
|
export const gridStyles = `
|
|
5
|
+
.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
|
+
th:has(.column-filter){padding-inline-end:28px}
|
|
7
|
+
.column-filter svg{width:13px;height:13px;fill:none;stroke:currentColor;stroke-width:1.5}
|
|
8
|
+
.column-filter.active{opacity:1;color:var(--gramlot-action,Highlight)}
|
|
9
|
+
.column-filter.active svg{fill:currentColor}
|
|
10
|
+
.column-filtered{box-shadow:inset 0 -2px var(--gramlot-action,Highlight)}
|
|
11
|
+
.column-filter:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight)}
|
|
12
|
+
.column-filter-panel{position:fixed;inset:auto;margin:0;padding:0;border:1px solid var(--gramlot-border,GrayText);border-radius:8px;background:var(--gramlot-surface,Canvas);color:var(--gramlot-ink,CanvasText);font:inherit;box-shadow:0 8px 24px #0003;width:310px;max-width:var(--gramlot-popup-available-width);max-height:var(--gramlot-popup-available-height);overflow:auto}
|
|
13
|
+
.column-filter-panel slot{display:contents}
|
|
14
|
+
|
|
5
15
|
.control-box{position:relative}
|
|
6
16
|
.cell-editor{
|
|
7
|
-
position:absolute;z-index:4;height:var(--grid-editor-height);
|
|
17
|
+
position:absolute;z-index:4;height:min(var(--grid-editor-height),var(--grid-cell-max-height,var(--grid-editor-height)));
|
|
8
18
|
background:var(--gramlot-grid-background,var(--gramlot-surface,Canvas));
|
|
9
19
|
--gramlot-field-height:0px;
|
|
10
|
-
--gramlot-field-block-size:var(--grid-editor-height);
|
|
20
|
+
--gramlot-field-block-size:min(var(--grid-editor-height),var(--grid-cell-max-height,var(--grid-editor-height)));
|
|
11
21
|
--gramlot-field-padding:var(--gramlot-grid-cell-padding,.3rem .6rem);
|
|
12
22
|
--gramlot-field-font-size:1em;
|
|
13
23
|
--gramlot-field-line-height:var(--gramlot-grid-line-height,1.35);
|
|
@@ -140,6 +150,28 @@ export const gridStyles = `
|
|
|
140
150
|
block-size: var(--gramlot-grid-row-height, 2rem);
|
|
141
151
|
border-block-end: 1px solid var(--gramlot-grid-row-border-color, var(--gramlot-border, ButtonBorder));
|
|
142
152
|
}
|
|
153
|
+
.cell-color-swatch { display:inline-block;vertical-align:middle;width:100%;max-width:48px;height:14px;
|
|
154
|
+
border:1px solid var(--gramlot-border-control,#888);border-radius:3px; }
|
|
155
|
+
.cell-color-swatch[hidden] { display:none; }
|
|
156
|
+
td[data-field] { padding: 0; }
|
|
157
|
+
.cell-content {
|
|
158
|
+
padding: var(--gramlot-grid-cell-padding, .3rem .6rem);
|
|
159
|
+
overflow: hidden;
|
|
160
|
+
text-overflow: ellipsis;
|
|
161
|
+
max-height: var(--grid-cell-max-height, none);
|
|
162
|
+
}
|
|
163
|
+
td.check-cell { vertical-align: middle; }
|
|
164
|
+
.check-cell > .cell-content {
|
|
165
|
+
display: flex;
|
|
166
|
+
align-items: center;
|
|
167
|
+
justify-content: center;
|
|
168
|
+
padding: 0;
|
|
169
|
+
min-block-size: calc(var(--gramlot-grid-row-height, 2rem) - 1px);
|
|
170
|
+
text-overflow: clip;
|
|
171
|
+
}
|
|
172
|
+
.grid-set-check { margin: 0; flex: none; }
|
|
173
|
+
.cell-scroll { overflow: auto; overscroll-behavior: contain; }
|
|
174
|
+
.cell-scroll:focus-visible { outline: 1px solid var(--gramlot-focus-ring, Highlight); outline-offset: -1px; }
|
|
143
175
|
tbody tr { background: var(--gramlot-grid-background, var(--gramlot-surface, Canvas)); }
|
|
144
176
|
tbody tr.alternate { background: var(--gramlot-grid-row-alt-background, var(--gramlot-surface-subtle, Canvas)); }
|
|
145
177
|
tbody tr:hover { background: var(--gramlot-grid-row-hover-background, var(--gramlot-selected, Highlight)); }
|