@gramlot/gramlot 0.3.27 → 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 +51 -30
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +258 -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 +11 -11
- 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 +2 -2
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/collection.js +8 -8
- 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 +572 -176
- package/dist/gramlot.min.js +85 -53
- 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/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 +6 -4
- 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 +7 -5
- package/src/components/choice-field-styles.js +14 -0
- package/src/components/choices.js +5 -0
- package/src/components/drawing.js +199 -0
- package/src/components/grid-check-sets.js +98 -0
- package/src/components/grid-column-filters.js +198 -0
- package/src/components/grid-grammar.json +44 -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 +10 -2
- package/src/components/grid-styles.js +23 -0
- package/src/components/grid.js +52 -10
- package/src/components/image-uploader.js +2 -2
- package/src/components/inputs.js +19 -10
- 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/toolbar-overflow.js +12 -8
- package/src/components/tree.js +30 -8
- package/src/components/typed-editor.js +14 -3
- 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/gramlot.d.ts +1 -0
- package/src/gramlot.js +2 -0
- 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 +1 -0
- package/src/renderer/drag-drop.js +1 -0
- package/src/renderer/gramlot-renderer.d.ts +2 -0
- package/src/renderer/gramlot-renderer.js +5 -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/visual-editor.js +17 -17
- 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/themes/gramlot-base/theme.css +6 -0
- package/tools/gramlot-tools-inspector.js +169 -505
package/src/ide-documents.js
CHANGED
|
@@ -14,6 +14,8 @@ export class IdeDocuments {
|
|
|
14
14
|
get state() { return this.source.getRelativeData('.'); }
|
|
15
15
|
get documents() { return this.state.getItem('documents'); }
|
|
16
16
|
async open(root, path) {
|
|
17
|
+
// Only registered IDE document types may create an editor tab.
|
|
18
|
+
if (!/\.(?:py|js|mjs|ts|json|html|css|xml|md|markdown|sql|typ|txt|png|jpg|jpeg|webp)$/i.test(path)) return null;
|
|
17
19
|
const key = documentKey(root, path);
|
|
18
20
|
const existing = this.documents.getNodes().find(node => !node.value.getItem('isNew') && node.value.getItem('root') === root && node.value.getItem('path') === path);
|
|
19
21
|
if (existing) return existing.label;
|
|
@@ -22,7 +24,13 @@ export class IdeDocuments {
|
|
|
22
24
|
const promise = this.gramlot.rpc.call('data', 'document_read', {root,path}, {signal:request.signal}).then(result => {
|
|
23
25
|
if (this.disposed || request.signal.aborted) return null;
|
|
24
26
|
const document = new Bag();
|
|
25
|
-
|
|
27
|
+
const content = result.language === 'image' ? result.content.toTytx() : result.content;
|
|
28
|
+
for (const [name,value] of Object.entries({...result, content, root, saved:content, busy:false})) document.setItem(name,value);
|
|
29
|
+
if (result.language === 'image') {
|
|
30
|
+
const annotations = result.content;
|
|
31
|
+
document.setItem('annotations',annotations);
|
|
32
|
+
annotations.subscribe('ide-annotations',{any:()=>document.setItem('content',annotations.toTytx())});
|
|
33
|
+
}
|
|
26
34
|
this.documents.setItem(key, document);
|
|
27
35
|
return key;
|
|
28
36
|
}).finally(() => this.pending.delete(key));
|
|
@@ -104,8 +112,12 @@ export class IdeDocuments {
|
|
|
104
112
|
if (!doc || doc.getItem('isNew') || !this.dirty(key) || !doc.getItem('writable') || this.pending.has(key)) return false;
|
|
105
113
|
const content = doc.getItem('content'), request = new AbortController();
|
|
106
114
|
doc.setItem('busy',true);
|
|
107
|
-
const
|
|
108
|
-
|
|
115
|
+
const image = doc.getItem('language') === 'image';
|
|
116
|
+
const path = image ? doc.getItem('annotationPath') : doc.getItem('path');
|
|
117
|
+
const creating = image && doc.getItem('revision') === null;
|
|
118
|
+
const promise = this.gramlot.rpc.call('data',creating ? 'document_create' : 'document_save', {
|
|
119
|
+
root:doc.getItem('root'), path, content:image ? Bag.fromTytx(content) : content,
|
|
120
|
+
...(creating ? {} : {revision:doc.getItem('revision')})
|
|
109
121
|
}, {signal:request.signal}).then(result => {
|
|
110
122
|
if (this.disposed || request.signal.aborted) return false;
|
|
111
123
|
doc.setItem('revision',result.revision);
|
|
@@ -119,6 +131,10 @@ export class IdeDocuments {
|
|
|
119
131
|
const doc = this.documents.getItem(key);
|
|
120
132
|
if (!doc || !this.dirty(key) || this.pending.has(key)) return false;
|
|
121
133
|
doc.setItem('content',doc.getItem('saved'));
|
|
134
|
+
if (doc.getItem('language') === 'image') {
|
|
135
|
+
doc.getItem('annotations').replace(Bag.fromTytx(doc.getItem('saved')));
|
|
136
|
+
doc.setItem('content',doc.getItem('saved'));
|
|
137
|
+
}
|
|
122
138
|
return true;
|
|
123
139
|
}
|
|
124
140
|
canClose(key, discard = false) {
|
package/src/ide-runtime.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export class IdeLogic {
|
|
|
9
9
|
fileSystemOpen(node:SourceBagNode,args:{root:string|null}):Promise<string|null>|undefined;
|
|
10
10
|
ideMount(node:SourceBagNode):void;
|
|
11
11
|
ideOpenWorkspace(node:SourceBagNode):void;
|
|
12
|
+
ideUploadCompleted(node:SourceBagNode,args:{result:{root:string,path:string}}):Promise<void>;
|
|
12
13
|
ideDocumentState(node:SourceBagNode,key:string):void;
|
|
13
14
|
ideOpenDocument(node:SourceBagNode,root:string,path:string):Promise<void>;
|
|
14
15
|
ideNew(node:SourceBagNode):void;
|
package/src/ide-runtime.js
CHANGED
|
@@ -65,6 +65,16 @@ export class IdeLogic {
|
|
|
65
65
|
const root = state.getItem('workspace');
|
|
66
66
|
if (root && root !== state.getItem('browser.root')) state.setItem('browser.requestedRoot',root);
|
|
67
67
|
}
|
|
68
|
+
async ideUploadCompleted(node, {result}) {
|
|
69
|
+
const context=ideContext(node), state=context.scope.getRelativeData('.');
|
|
70
|
+
if (state.getItem('browser.root') !== result.root) return;
|
|
71
|
+
state.setItem('upload.open',false);
|
|
72
|
+
const controller=context.scope.value.getNode('frame.left.browser').fileSystemController;
|
|
73
|
+
if (controller.request) return;
|
|
74
|
+
const opened=await controller.open(result.root);
|
|
75
|
+
if (opened === result.root && !context.documents.disposed && state.getItem('browser.root') === result.root)
|
|
76
|
+
await this.ideOpenDocument(context.scope,result.root,result.path);
|
|
77
|
+
}
|
|
68
78
|
ideDocumentState(node, key) {
|
|
69
79
|
const context = ideContext(node), {documents} = context;
|
|
70
80
|
const doc = documents.documents.getItem(key);
|
|
@@ -147,38 +157,42 @@ export class IdeLogic {
|
|
|
147
157
|
form.button('Create file',{disabled:'^.busy'}).dataController({func:'ideCreate',documentKey:key});
|
|
148
158
|
form.button('Cancel',{disabled:'^.busy',class:'button--quiet'}).dataController({func:'ideCancelCreate',documentKey:key});
|
|
149
159
|
const editorArea = target.div({flex:'1',min_height:0});
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
height:'100%',
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
previewPane.
|
|
160
|
+
if (doc.getItem('language') === 'image') {
|
|
161
|
+
editorArea.drawingPane({image:`^.documents.${key}.image`,annotations:`^.documents.${key}.annotations`,height:'100%'});
|
|
162
|
+
} else {
|
|
163
|
+
const html = doc.getItem('language') === 'html';
|
|
164
|
+
const markdown = doc.getItem('language') === 'markdown';
|
|
165
|
+
const rich = html || markdown;
|
|
166
|
+
const typst = doc.getItem('language') === 'typst';
|
|
167
|
+
const preview = rich || typst || recipe;
|
|
168
|
+
const views = preview ? editorArea.tabContainer({height:'100%',selectedPage:`^.documents.${key}.view`}) : null;
|
|
169
|
+
const code = preview ? views.contentPane({title:'Code',pageName:'code',height:'100%'}) : editorArea;
|
|
170
|
+
codeMirrorWithOptions(code,{datapath:`.documents.${key}`,value:'^.content',language:doc.getItem('language'),
|
|
171
|
+
height:'100%', readonly:'^.readonly',nodeId:`${context.editorPrefix}_editor_${key}`,
|
|
172
|
+
editorView:'code',selfsubscribe_historyChanged:'ideHistoryChanged'});
|
|
173
|
+
target.dataController({func:'ideSave',documentKey:key,[`subscribe_${context.editorPrefix}_editor_${key}_save`]:true});
|
|
174
|
+
if (typst) views.contentPane({title:'Preview',pageName:'preview',height:'100%'}).typstPreview({value:`^.documents.${key}.content`,filename:`^.documents.${key}.pdfFilename`,height:'100%'});
|
|
175
|
+
if (recipe) {
|
|
176
|
+
const output = views.contentPane({title:'Preview',pageName:'preview',height:'100%',display:'flex',flex_direction:'column'});
|
|
177
|
+
output.div(`^.documents.${key}.renderStatus`,{role:'status',padding:'8px 12px',white_space:'pre-wrap',overflow:'auto',max_height:'30%'});
|
|
178
|
+
output.typstPreview({value:`^.documents.${key}.typstSource`,filename:`^.documents.${key}.pdfFilename`,
|
|
179
|
+
hidden:`^.documents.${key}.previewHidden`,flex:'1',min_height:0});
|
|
180
|
+
views.contentPane({title:'Generated Typst',pageName:'generated',height:'100%'})
|
|
181
|
+
.codeMirror({value:`^.documents.${key}.typstSource`,language:'typst',readonly:true,height:'100%'});
|
|
182
|
+
}
|
|
183
|
+
if (rich) {
|
|
184
|
+
const previewPane = views.contentPane({title:'Preview',pageName:'preview',height:'100%',display:'flex',flex_direction:'column'});
|
|
185
|
+
if (markdown) {
|
|
186
|
+
doc.setItem('allowHtml',false);
|
|
187
|
+
previewPane.checkbox({value:`^.documents.${key}.allowHtml`,label:'Allow embedded HTML',class:'gramlot-ide-allow-html',padding:'8px 12px',flex_shrink:0});
|
|
188
|
+
}
|
|
189
|
+
previewPane[html ? 'htmlPreview' : 'markdownPreview']({value:`^.documents.${key}.content`,flex:'1',min_height:0,
|
|
190
|
+
...(markdown ? {allowHtml:`^.documents.${key}.allowHtml`} : {})});
|
|
191
|
+
views.contentPane({title:'Rich text',pageName:'rich',height:'100%'})[html ? 'htmlEditor' : 'markdownEditor']({
|
|
192
|
+
datapath:`.documents.${key}`,value:'^.content',readonly:'^.readonly',height:'100%',
|
|
193
|
+
nodeId:`${context.editorPrefix}_rich_editor_${key}`,editorView:'rich',selfsubscribe_historyChanged:'ideHistoryChanged'});
|
|
194
|
+
target.dataController({func:'ideSave',documentKey:key,[`subscribe_${context.editorPrefix}_rich_editor_${key}_save`]:true});
|
|
175
195
|
}
|
|
176
|
-
previewPane[html ? 'htmlPreview' : 'markdownPreview']({value:`^.documents.${key}.content`,flex:'1',min_height:0,
|
|
177
|
-
...(markdown ? {allowHtml:`^.documents.${key}.allowHtml`} : {})});
|
|
178
|
-
views.contentPane({title:'Rich text',pageName:'rich',height:'100%'})[html ? 'htmlEditor' : 'markdownEditor']({
|
|
179
|
-
datapath:`.documents.${key}`,value:'^.content',readonly:'^.readonly',height:'100%',
|
|
180
|
-
nodeId:`${context.editorPrefix}_rich_editor_${key}`,editorView:'rich',selfsubscribe_historyChanged:'ideHistoryChanged'});
|
|
181
|
-
target.dataController({func:'ideSave',documentKey:key,[`subscribe_${context.editorPrefix}_rich_editor_${key}_save`]:true});
|
|
182
196
|
}
|
|
183
197
|
}
|
|
184
198
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export {PageBootstrap} from './bootstrap.js';
|
|
|
16
16
|
export type {PageBootstrapOptions, PageResources} from './bootstrap.js';
|
|
17
17
|
export {Exposed, Page, codeMirrorWithOptions} from './server/page.js';
|
|
18
18
|
export {GramlotBuilder} from './builder/gramlot-builder.js';
|
|
19
|
+
export type {GramlotSourceNode, GramlotSourceBag} from './builder/gramlot-builder.js';
|
|
19
20
|
export {GramlotRenderer} from './renderer/gramlot-renderer.js';
|
|
20
21
|
export {GramlotHtmlRenderer} from './renderer/gramlot-html-renderer.js';
|
|
21
22
|
export {GramlotSvgRenderer} from './renderer/gramlot-svg-renderer.js';
|
|
@@ -107,6 +107,7 @@ export class DragDrop {
|
|
|
107
107
|
type.startsWith('text/') ? session.wires.get(type) : fromTytx(session.wires.get(type))]));
|
|
108
108
|
const context = {dropValues, item: row.item, path: row.path, source: {...session.source},
|
|
109
109
|
selfdrop: record === session.record, dropEffect: policy.dropEffect, dataAvailable: true};
|
|
110
|
+
if (row.placement !== undefined) context.placement = row.placement;
|
|
110
111
|
const accepted = policy.accepted && this.#renderer.checkDropTarget(record.node, context)
|
|
111
112
|
&& this.#renderer.records.get(record.node) === record && row.element.isConnected;
|
|
112
113
|
return {record, element: row.element, accepted, context};
|
|
@@ -41,12 +41,14 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
41
41
|
dropValues: Record<string, unknown>; item: unknown; path: string | undefined;
|
|
42
42
|
source: Record<string, unknown>; selfdrop: boolean;
|
|
43
43
|
dropEffect: 'copy' | 'move' | 'link'; dataAvailable: boolean;
|
|
44
|
+
placement?: 'before' | 'inside' | 'after';
|
|
44
45
|
}): boolean;
|
|
45
46
|
/** Invoke the general onDrop action on already accepted data not consumed by typed actions. */
|
|
46
47
|
invokeDrop(node: SourceBagNode, context: {
|
|
47
48
|
dropValues: Record<string, unknown>; item: unknown; path: string | undefined;
|
|
48
49
|
source: Record<string, unknown>; selfdrop: boolean;
|
|
49
50
|
dropEffect: 'copy' | 'move' | 'link'; dataAvailable: boolean;
|
|
51
|
+
placement?: 'before' | 'inside' | 'after';
|
|
50
52
|
}): Promise<void>;
|
|
51
53
|
/** Origin callback, followed by local endDrag publication even if the callback fails. */
|
|
52
54
|
endDrag(node: SourceBagNode, context: {source: Record<string, unknown>; dropEffect: string}, topic: string): Promise<void>;
|
|
@@ -78,21 +78,21 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
78
78
|
/** Prepare a local payload snapshot: no DataTransfer writes or native gesture commit. */
|
|
79
79
|
prepareDrag(node, event) { return this.dragPreparation.prepare(node, event); }
|
|
80
80
|
/** Dynamic eligibility only; cannot replace the independent type/tag/effect policy. */
|
|
81
|
-
checkDropTarget(node, {dropValues, item, path, source, selfdrop, dropEffect, dataAvailable}) {
|
|
81
|
+
checkDropTarget(node, {dropValues, item, path, source, selfdrop, dropEffect, dataAvailable, placement}) {
|
|
82
82
|
const record = this.records.get(node);
|
|
83
83
|
if (!record) return false;
|
|
84
84
|
if (!record.resolved.dropTargetCb) return true;
|
|
85
85
|
const allowed = this.html.callLogic(node, record.resolved.dropTargetCb,
|
|
86
|
-
{dropValues, item, path, source, selfdrop, dropEffect, dataAvailable});
|
|
86
|
+
{dropValues, item, path, source, selfdrop, dropEffect, dataAvailable, ...(placement === undefined ? {} : {placement})});
|
|
87
87
|
if (typeof allowed !== 'boolean') throw new TypeError('dropTargetCb must return a boolean synchronously');
|
|
88
88
|
return allowed;
|
|
89
89
|
}
|
|
90
90
|
/** Invoke only the general action, after acceptance and removal of data handled by typed actions. */
|
|
91
|
-
async invokeDrop(node, {dropValues, item, path, source, selfdrop, dropEffect, dataAvailable}) {
|
|
91
|
+
async invokeDrop(node, {dropValues, item, path, source, selfdrop, dropEffect, dataAvailable, placement}) {
|
|
92
92
|
const record = this.records.get(node);
|
|
93
93
|
if (!record || !record.resolved.onDrop || Object.keys(dropValues).length === 0) return;
|
|
94
94
|
await this.html.callLogic(node, record.resolved.onDrop,
|
|
95
|
-
{dropValues, item, path, source, selfdrop, dropEffect, dataAvailable});
|
|
95
|
+
{dropValues, item, path, source, selfdrop, dropEffect, dataAvailable, ...(placement === undefined ? {} : {placement})});
|
|
96
96
|
}
|
|
97
97
|
/** Notify origin completion independently of application-operation success. */
|
|
98
98
|
async endDrag(node, {source, dropEffect}, topic) {
|
|
@@ -206,6 +206,7 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
206
206
|
...this.html.create(node, document, tag, attrs, resolved.visible ?? null),
|
|
207
207
|
};
|
|
208
208
|
this.html.compose(record, text, children);
|
|
209
|
+
if (record.labelbox) record.cleanup.push(() => record.labelbox.menu?.dispose());
|
|
209
210
|
record.shape = ControlAdapter.shape(record.element, resolved);
|
|
210
211
|
// Registered before any listener: a failed first projection leaves a record the failed-build
|
|
211
212
|
// cleanup removes, listeners included (ASTRA-06).
|
package/src/server/assets.d.ts
CHANGED
|
@@ -10,3 +10,6 @@ export function gramlotDev(): 'YES' | 'DEBUG' | null;
|
|
|
10
10
|
* URL from JSR (read with `fetch`). Without a name, the runtime to serve at the runtime URL: `gramlot.js`
|
|
11
11
|
* when `GRAMLOT_DEV=DEBUG`, `gramlot.min.js` otherwise. Another name throws a `TypeError`. */
|
|
12
12
|
export function runtimeAsset(name?: 'gramlot.js' | 'gramlot.min.js' | 'gramlot-markdown.js' | 'runtime-notices.json' | null): URL;
|
|
13
|
+
|
|
14
|
+
/** Packaged standard collection entry points for host artifact verification. */
|
|
15
|
+
export function standardCollectionAssets(): Array<{url: string; file: URL}>;
|
package/src/server/assets.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* @ts-self-types="./assets.d.ts" */
|
|
2
|
+
import {standardCollections} from '../../dist/standard-collections.js';
|
|
2
3
|
/**
|
|
3
4
|
* Development mode and the runtime file to serve. `gramlotDev` imports nothing from Node.js, so the
|
|
4
5
|
* neutral `GramlotServer` can read it in a serverless Worker, where it is null without `process`.
|
|
@@ -28,3 +29,11 @@ export function runtimeAsset(name = null) {
|
|
|
28
29
|
if (!RUNTIME_ASSETS.includes(name)) throw new TypeError(`Unknown Gramlot runtime asset: ${name}`);
|
|
29
30
|
return new URL(`../../dist/${name}`, import.meta.url);
|
|
30
31
|
}
|
|
32
|
+
|
|
33
|
+
/** Standard collection entry points; hosts verify their complete artifact inventories. */
|
|
34
|
+
export function standardCollectionAssets() {
|
|
35
|
+
return standardCollections.map(collection => ({
|
|
36
|
+
url: collection.module,
|
|
37
|
+
file: new URL(`../../dist/components/${collection.name}/assets/index.js`, import.meta.url),
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
@@ -72,7 +72,7 @@ export interface GramlotServerOptions {
|
|
|
72
72
|
pageTtl?: number;
|
|
73
73
|
/** Maximum number of registered pages. */
|
|
74
74
|
maxPages?: number;
|
|
75
|
-
/**
|
|
75
|
+
/** Custom collections added to the packaged standards: Builder grammar and root-relative module URL. */
|
|
76
76
|
collections?: PreparedCollection[];
|
|
77
77
|
/** Enable upload control only when the adapter provides a binary transport. */
|
|
78
78
|
uploadsEnabled?: boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* @ts-self-types="./gramlot-server.d.ts" */
|
|
2
|
+
import {standardCollections} from '../../dist/standard-collections.js';
|
|
2
3
|
/**
|
|
3
4
|
* The neutral server: registers pages and builds their Sources, with no HTTP engine.
|
|
4
5
|
*
|
|
@@ -122,7 +123,7 @@ export class GramlotServer {
|
|
|
122
123
|
Object.assign(this, {runtimeUrl, rpcUrl, closeUrl, rootId, pageTtl, maxPages, cssTheme});
|
|
123
124
|
this.pages = new Map();
|
|
124
125
|
this.uploads = uploadsEnabled ? new UploadRegistry() : null;
|
|
125
|
-
this.collections = [...collections];
|
|
126
|
+
this.collections = this.collectionGraph([...standardCollections, ...collections]);
|
|
126
127
|
this.preparedGrammars = new WeakMap();
|
|
127
128
|
this.environmentPages = new WeakMap();
|
|
128
129
|
}
|
package/src/server/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type {GramlotServerOptions, OpenedPage, RegisteredPage} from './gramlot-s
|
|
|
11
11
|
export {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
12
12
|
export {GramlotFileServer} from './gramlot-file-server.js';
|
|
13
13
|
export type {GramlotFileServerOptions} from './gramlot-file-server.js';
|
|
14
|
-
export {gramlotDev, runtimeAsset} from './assets.js';
|
|
14
|
+
export {gramlotDev, runtimeAsset, standardCollectionAssets} from './assets.js';
|
|
15
15
|
export {checkProtocol} from './conformance.js';
|
|
16
16
|
export {InvalidResourceName, parseRequires} from './resources.js';
|
|
17
17
|
export type {Resources} from './resources.js';
|
package/src/server/index.js
CHANGED
|
@@ -11,7 +11,7 @@ export {GramlotServer, EndpointNotFound, InvalidRequest, NotAuthenticated, NotAu
|
|
|
11
11
|
SourceNotFound, ServerCapacity} from './gramlot-server.js';
|
|
12
12
|
export {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
13
13
|
export {GramlotFileServer} from './gramlot-file-server.js';
|
|
14
|
-
export {gramlotDev, runtimeAsset} from './assets.js';
|
|
14
|
+
export {gramlotDev, runtimeAsset, standardCollectionAssets} from './assets.js';
|
|
15
15
|
export {checkProtocol} from './conformance.js';
|
|
16
16
|
export {InvalidResourceName, parseRequires} from './resources.js';
|
|
17
17
|
export {NAME_SYNTAX, NameSyntax} from '../builder/name-syntax.js';
|
|
@@ -24,30 +24,30 @@ export class VisualEditor {
|
|
|
24
24
|
pane.dataController({func:'initializeEditorAppearance', _onBuilt:true});
|
|
25
25
|
pane.dataController({func:'applyEditorAppearance', profile:'^.appearanceProfile', palette:'^.appearancePalette', mode:'^.appearanceMode'});
|
|
26
26
|
const rail = this.rail = pane.menu({presentation:'bar', orientation:'vertical', aria_label:'Editor panels', class:'visual-editor-rail'});
|
|
27
|
-
this.toolButton(rail.menuline({group:true
|
|
28
|
-
this.toolButton(rail.menuline({group:true
|
|
29
|
-
this.toolButton(rail.menuline({group:true
|
|
30
|
-
this.toolButton(rail.menuline({group:true
|
|
27
|
+
this.toolButton(rail.menuline({group:true}), 'Source / Data', 'toggleNavigation', toolIcons.navigation);
|
|
28
|
+
this.toolButton(rail.menuline({group:true}), 'Catalogue', 'openCatalogue', toolIcons.catalogue);
|
|
29
|
+
this.toolButton(rail.menuline({group:true}), 'Properties', 'openProperties', toolIcons.properties);
|
|
30
|
+
this.toolButton(rail.menuline({group:true}), 'Clipboard', "this.SET('.clipboardVisible', !this.GET('.clipboardVisible'))", toolIcons.paste,
|
|
31
31
|
{dropTarget:true, dropTypes:'app/source', dropTags:`${editorId}Source`, dropEffect:'^.clipboardDropEffect',
|
|
32
32
|
connect_ondragover:'clipboardModifiers', connect_ondrop:'clipboardModifiers', onDrop:'dropClipboard'});
|
|
33
33
|
rail.spacer({flex:1});
|
|
34
|
-
this.toolButton(rail.menuline({group:true
|
|
34
|
+
this.toolButton(rail.menuline({group:true}), 'Appearance', "this.SET('.appearanceOpen', !this.GET('.appearanceOpen'))", toolIcons.appearance);
|
|
35
35
|
const layoutRoot = pane.framePane({node_label:'layout', height:'100%', id:`${editorId}-editor-frame`, class:'visual-editor-layout'});
|
|
36
36
|
layoutRoot.top.setAttr({height:'30px'});
|
|
37
37
|
const toolbar = layoutRoot.top.menu({presentation:'bar', aria_label:'Editor tools', class:'visual-editor-toolbar'});
|
|
38
|
-
toolbar.menuline({group:true
|
|
39
|
-
const files = toolbar.menuline({group:true,
|
|
38
|
+
toolbar.menuline({group:true}).span('Source editor', {class:'visual-editor-brand'});
|
|
39
|
+
const files = toolbar.menuline({group:true, gap:'4px', hidden:!fileCommands});
|
|
40
40
|
for (const [caption,action,icon] of [['New','newPage','new'],['Open','openUpload','open'],['Download','downloadPage','download'],['Copy Source','copySource','copy']])
|
|
41
41
|
this.toolButton(files,caption,action,toolIcons[icon],{id:`${editorId}-${icon}`});
|
|
42
|
-
toolbar.menuline({group:true
|
|
43
|
-
const edit = toolbar.menuline({group:true,
|
|
42
|
+
toolbar.menuline({group:true}).span({class:'visual-toolbar-divider', aria_hidden:'true'});
|
|
43
|
+
const edit = toolbar.menuline({group:true, gap:'2px'});
|
|
44
44
|
this.toolButton(edit,'Cut branch','cutBranch',toolIcons.cut,{title:'Cut branch (F8)'});
|
|
45
45
|
this.toolButton(edit,'Copy branch','copyBranch',toolIcons.copy);
|
|
46
46
|
this.toolButton(edit,'Paste branch','pasteBranch',toolIcons.paste,{title:'Paste branch (F9)'});
|
|
47
47
|
toolbar.spacer({flex:1});
|
|
48
|
-
toolbar.menuline({group:true,
|
|
49
|
-
toolbar.menuline({group:true
|
|
50
|
-
toolbar.menuline({group:true
|
|
48
|
+
toolbar.menuline({group:true, hidden:'^.modified:=!{}'}).span('Unsaved changes', {role:'status', class:'visual-editor-hint'});
|
|
49
|
+
toolbar.menuline({group:true}).span('^.fileStatus', {role:'status', class:'visual-editor-file-status'});
|
|
50
|
+
toolbar.menuline({group:true}).span('^.filename', {class:'visual-editor-filename'});
|
|
51
51
|
const left = layoutRoot.left;
|
|
52
52
|
left.setAttr({width:'min(240px, 34vw)', splitter:true,
|
|
53
53
|
drawer:'^.navigationOpen', default_drawer:true, drawer_label:'Source / Data',
|
|
@@ -96,7 +96,7 @@ export class VisualEditor {
|
|
|
96
96
|
naming.frame.center.p('^.error', {role:'alert', margin:'12px'});
|
|
97
97
|
const namingBar = naming.frame.bottom.menu({presentation:'bar', aria_label:'Clipboard commands', padding:'3px 6px'});
|
|
98
98
|
namingBar.spacer({flex:1});
|
|
99
|
-
const namingButtons = namingBar.menuline({group:true,
|
|
99
|
+
const namingButtons = namingBar.menuline({group:true, gap:'8px'});
|
|
100
100
|
namingButtons.button('Cancel', {action:"this.SET('.clipboardOpen', false)"});
|
|
101
101
|
namingButtons.button('Save branch', {action:'saveClipboard'});
|
|
102
102
|
const dialog = pane.dialog({class:'visual-editor-popup', title:'Required parameters', open:'^.insertionOpen', width:'400px', height:'280px', movable:true, resizable:true});
|
|
@@ -104,7 +104,7 @@ export class VisualEditor {
|
|
|
104
104
|
dialog.frame.center.p('^.error', {role:'alert'});
|
|
105
105
|
const bar = dialog.frame.bottom.menu({presentation:'bar', aria_label:'Insertion commands', padding:'3px 6px', border_top:'1px solid var(--gramlot-border)'});
|
|
106
106
|
bar.spacer({flex:1});
|
|
107
|
-
const buttons = bar.menuline({group:true,
|
|
107
|
+
const buttons = bar.menuline({group:true, gap:'8px'});
|
|
108
108
|
buttons.button('Cancel', {action:"this.SET('.insertionOpen', false)"});
|
|
109
109
|
buttons.button('Insert', {action:'insertWidget'});
|
|
110
110
|
const settings = pane.floatingPane({class:'visual-editor-popup', title:'Appearance', open:'^.appearanceOpen', default_open:false, width:'280px', height:'260px', movable:true, resizable:true});
|
|
@@ -128,7 +128,7 @@ export class VisualEditor {
|
|
|
128
128
|
pane.dataSetter({destination_path:'.codeDocument', value:new Bag({...document, saved:document.content, busy:false, status:''})});
|
|
129
129
|
const anchor = `#${pane.getAttr('visualEditorId')}Editor`;
|
|
130
130
|
const opener = frame === this.frame ? this.toolbar : frame.top.menu({presentation:'bar', aria_label:'Code drawer'});
|
|
131
|
-
opener.menuline({group:true
|
|
131
|
+
opener.menuline({group:true}).button('Code', {action:'openCode', class:'button--quiet'});
|
|
132
132
|
const drawer = frame.right;
|
|
133
133
|
drawer.setAttr({class:'visual-editor-code', datapath:anchor, title:'Page code', detachable:true, width:'60%', minSize:240, splitter:true,
|
|
134
134
|
drawer:'^.codeOpen', default_drawer:'close', drawer_label:'Code', drawer_minimize:false,
|
|
@@ -141,7 +141,7 @@ export class VisualEditor {
|
|
|
141
141
|
code.bottom.div('^.codeDocument.status', {role:'status', font_size:'12px', padding:'4px 10px'});
|
|
142
142
|
const bar = code.bottom.menu({presentation:'bar', aria_label:'Page code commands', padding:'3px 6px'});
|
|
143
143
|
bar.spacer({flex:1});
|
|
144
|
-
const commands = bar.menuline({group:true,
|
|
144
|
+
const commands = bar.menuline({group:true, gap:'6px'});
|
|
145
145
|
commands.button('Close', {action:"this.SET('.codeOpen', 'close')"});
|
|
146
146
|
commands.button('Preview saved', {action:'codePreview', disabled:'^.codeDocument.busy'});
|
|
147
147
|
commands.button('Save', {action:'codeSave', disabled:'^.codeSaveDisabled'});
|
|
@@ -150,7 +150,7 @@ export class VisualEditor {
|
|
|
150
150
|
}
|
|
151
151
|
search(pane, path, label) {
|
|
152
152
|
const bar = pane.menu({presentation:'bar', aria_label:label, class:'visual-search-toolbar'});
|
|
153
|
-
const field = bar.menuline({group:true,
|
|
153
|
+
const field = bar.menuline({group:true, flex:1, min_width:0}).div({class:'visual-search-field'});
|
|
154
154
|
field.span({class:'visual-search-icon', aria_hidden:'true'});
|
|
155
155
|
field.input({type:'search', value:`^.${path}`, default:'', live:true, placeholder:label, aria_label:label});
|
|
156
156
|
field.html_button({type:'button', class:'visual-search-clear', aria_label:`Clear ${label.toLowerCase()}`,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import {columnValue, columnValueKey, columnSelection, columnDateRange, columnDateMatches} from './column-filter.js';
|
|
1
2
|
import {isDecimal} from '@genrojs/tytx';
|
|
2
3
|
import {compileFilter} from './collection-filter.js';
|
|
4
|
+
import {containsId, requireId, requireIdSet} from './id-set.js';
|
|
3
5
|
import {publishCollection} from './bag-collection-store.js';
|
|
4
6
|
|
|
5
7
|
/** Source-owned view: original BagNodes, independent indices and criteria. */
|
|
@@ -9,15 +11,25 @@ export class BagCollectionView {
|
|
|
9
11
|
#listeners = new Set();
|
|
10
12
|
#indices = new Map();
|
|
11
13
|
#sortedBy = '';
|
|
12
|
-
#
|
|
13
|
-
#predicate = null;
|
|
14
|
+
#filters = new Map();
|
|
14
15
|
#filtered = null;
|
|
15
16
|
constructor(store) { this.bindStore(store); }
|
|
16
17
|
get bag() { return this.#store.bag; }
|
|
17
18
|
get rowMode() { return this.#store.rowMode; }
|
|
18
19
|
get sortedBy() { return this.#sortedBy; }
|
|
19
20
|
get criteria() { return parseSort(this.#sortedBy); }
|
|
20
|
-
get filter() { return this.#
|
|
21
|
+
get filter() { return this.#filters.get('search')?.definition ?? null; }
|
|
22
|
+
get filterSignature() { return JSON.stringify([...this.#filters].map(([name,{definition}]) => [name,definition])); }
|
|
23
|
+
/** Immutable accepted entries cross runtime/collection bundle boundaries. */
|
|
24
|
+
get filterContributions() {
|
|
25
|
+
return Object.freeze([...this.#filters].map(([name, entry]) =>
|
|
26
|
+
Object.freeze([name, Object.freeze({...entry})])));
|
|
27
|
+
}
|
|
28
|
+
/** Copy immutable accepted criteria into another Source-owned view, never rows. */
|
|
29
|
+
copyFiltersFrom(view) {
|
|
30
|
+
if (this.filterSignature === view.filterSignature) return;
|
|
31
|
+
this.#commit(this.#orderedNodes(),this.#sortedBy,new Map(view.filterContributions));
|
|
32
|
+
}
|
|
21
33
|
get filtered() { return this.#filtered === null ? null : [...this.#filtered]; }
|
|
22
34
|
isFiltered() { return this.#filtered !== null; }
|
|
23
35
|
value(node, field) { return this.#store.value(node, field); }
|
|
@@ -49,40 +61,90 @@ export class BagCollectionView {
|
|
|
49
61
|
return this.#store.getRows().toSorted((a,b) => (this.#indices.get(a) ?? Infinity) - (this.#indices.get(b) ?? Infinity));
|
|
50
62
|
}
|
|
51
63
|
synchronize(change = {full:true, rows:[]}) {
|
|
52
|
-
if (!change.full && !this.#sortedBy && !this.#
|
|
64
|
+
if (!change.full && !this.#sortedBy && !this.#filters.size) {
|
|
53
65
|
publishCollection(this.#listeners,change);
|
|
54
66
|
return;
|
|
55
67
|
}
|
|
56
|
-
this.#commit(this.#sorted(this.#orderedNodes(),this.criteria),this.#sortedBy,this.#
|
|
68
|
+
this.#commit(this.#sorted(this.#orderedNodes(),this.criteria),this.#sortedBy,this.#filters,change);
|
|
57
69
|
}
|
|
58
70
|
sort(sortedBy) {
|
|
59
71
|
const nodes = this.#sorted(this.#orderedNodes(),parseSort(sortedBy));
|
|
60
|
-
this.#commit(nodes,sortedBy,this.#
|
|
72
|
+
this.#commit(nodes,sortedBy,this.#filters);
|
|
61
73
|
}
|
|
62
74
|
moveRow(node, target, after = false) {
|
|
63
75
|
if (node === target || node.parentBag !== this.bag || target.parentBag !== this.bag) return;
|
|
64
76
|
const nodes = this.getRows(false);
|
|
65
77
|
nodes.splice(nodes.indexOf(node),1);
|
|
66
78
|
nodes.splice(nodes.indexOf(target)+Number(after),0,node);
|
|
67
|
-
this.#commit(nodes,'',this.#
|
|
79
|
+
this.#commit(nodes,'',this.#filters);
|
|
68
80
|
}
|
|
69
|
-
applyFilter(filter) {
|
|
70
|
-
|
|
71
|
-
// cannot replace it, the predicate or the visible index.
|
|
81
|
+
applyFilter(filter, contribution = 'search') {
|
|
82
|
+
if (!['base','search'].includes(contribution)) throw new TypeError('Unknown collection filter contribution');
|
|
72
83
|
const definition = filter === null ? null : Object.freeze({...filter,columns:Object.freeze([...filter.columns])});
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
this.#applyContribution(contribution, definition, compileFilter(definition));
|
|
85
|
+
}
|
|
86
|
+
applySetFilter(sets) {
|
|
87
|
+
const definition = sets === null ? null : Object.freeze(sets.map(({field,value}) => {
|
|
88
|
+
if (typeof field !== 'string' || !field) throw new TypeError('Set filter requires an identity field');
|
|
89
|
+
requireIdSet(value);
|
|
90
|
+
return Object.freeze({field,value});
|
|
91
|
+
}));
|
|
92
|
+
const predicate = definition === null ? null : read => definition.every(({field,value}) =>
|
|
93
|
+
containsId(value,requireId(read(field))));
|
|
94
|
+
this.#applyContribution('sets',definition,predicate);
|
|
95
|
+
}
|
|
96
|
+
columnFilter(field) { return this.#filters.get(`column:${field}`)?.definition.values ?? null; }
|
|
97
|
+
columnRange(field) {
|
|
98
|
+
const range = this.#filters.get(`column:${field}`)?.definition.range;
|
|
99
|
+
return range ? {...range,from:range.from && new Date(range.from+'T00:00:00Z'),to:range.to && new Date(range.to+'T00:00:00Z')} : null;
|
|
100
|
+
}
|
|
101
|
+
applyColumnFilter(field, values, range = this.columnRange(field)) {
|
|
102
|
+
range = columnDateRange(range);
|
|
103
|
+
if (typeof field !== 'string' || !field) throw new TypeError('Column filter requires a field');
|
|
104
|
+
const selected = values === null ? null : columnSelection(values);
|
|
105
|
+
const keys = selected?.map(columnValueKey);
|
|
106
|
+
const definition = selected === null && range === null ? null : Object.freeze({field,values:selected,keys:keys && Object.freeze(keys),range});
|
|
107
|
+
const predicate = definition === null ? null : read => columnDateMatches(read(field),range) && (keys === undefined || keys.includes(columnValueKey(read(field))));
|
|
108
|
+
this.#applyContribution(`column:${field}`,definition,predicate);
|
|
109
|
+
}
|
|
110
|
+
columnFacets(field) {
|
|
111
|
+
const facets = new Map();
|
|
112
|
+
const range = this.#filters.get(`column:${field}`)?.definition.range ?? null;
|
|
113
|
+
const selected = this.columnFilter(field);
|
|
114
|
+
const keys = selected?.map(columnValueKey);
|
|
115
|
+
const predicates = [...this.#filters].filter(([name]) => name !== `column:${field}`)
|
|
116
|
+
.map(([,entry]) => entry.predicate).filter(predicate => predicate !== null);
|
|
117
|
+
for (const node of this.#orderedNodes()) {
|
|
118
|
+
const value = columnValue(this.value(node,field)), key = columnValueKey(value);
|
|
119
|
+
if (!facets.has(key)) facets.set(key,{key,value,count:0,selected:columnDateMatches(value,range) && (keys === undefined || keys.includes(key))});
|
|
120
|
+
if (predicates.every(predicate => predicate(field => this.value(node,field)))) facets.get(key).count++;
|
|
121
|
+
}
|
|
122
|
+
// Selections absent from the current Bag remain visible and removable.
|
|
123
|
+
for (const value of selected ?? []) {
|
|
124
|
+
const key = columnValueKey(value);
|
|
125
|
+
if (!facets.has(key)) facets.set(key,{key,value,count:0,selected:true});
|
|
126
|
+
}
|
|
127
|
+
return [...facets.values()].filter(entry => columnDateMatches(entry.value,range));
|
|
128
|
+
}
|
|
129
|
+
#applyContribution(name, definition, predicate) {
|
|
130
|
+
if (JSON.stringify(this.#filters.get(name)?.definition ?? null) === JSON.stringify(definition)) return;
|
|
131
|
+
const filters = new Map(this.#filters);
|
|
132
|
+
if (definition === null) filters.delete(name);
|
|
133
|
+
else filters.set(name,{definition,predicate});
|
|
134
|
+
this.#commit(this.#orderedNodes(),this.#sortedBy,filters);
|
|
75
135
|
}
|
|
76
|
-
#commit(nodes, sortedBy,
|
|
77
|
-
const
|
|
78
|
-
const
|
|
136
|
+
#commit(nodes, sortedBy, filters, change = {full:false, rows:[]}) {
|
|
137
|
+
const predicates = [...filters.values()].map(entry => entry.predicate).filter(predicate => predicate !== null);
|
|
138
|
+
const filtered = predicates.length ? nodes.flatMap((node,index) =>
|
|
139
|
+
predicates.every(predicate => predicate(field => this.value(node,field))) ? [index] : []) : null;
|
|
140
|
+
const full = change.full || sortedBy !== this.#sortedBy || filters !== this.#filters ||
|
|
79
141
|
nodes.length !== this.#indices.size || nodes.some((node,index) => this.#indices.get(node) !== index) ||
|
|
80
142
|
JSON.stringify(filtered) !== JSON.stringify(this.#filtered);
|
|
81
143
|
this.#indices = new Map(nodes.map((node,index) => [node,index]));
|
|
82
|
-
this.#sortedBy = sortedBy; this.#
|
|
144
|
+
this.#sortedBy = sortedBy; this.#filters = filters; this.#filtered = filtered;
|
|
83
145
|
const visible = filtered === null ? null : new Set(filtered);
|
|
84
146
|
const rows = full ? [] : change.rows.filter(node => this.#indices.has(node) && (visible === null || visible.has(this.#indices.get(node))));
|
|
85
|
-
if (full || rows.length) publishCollection(this.#listeners,{full,rows});
|
|
147
|
+
if (full || rows.length || change.rows.length) publishCollection(this.#listeners,{full,rows});
|
|
86
148
|
}
|
|
87
149
|
#sorted(nodes, criteria) {
|
|
88
150
|
if (!criteria.length) return nodes;
|
|
@@ -11,7 +11,8 @@ export function compileFilter(filter) {
|
|
|
11
11
|
!['T', 'L', 'R', 'N', 'D'].includes(dtype)) throw new TypeError('Invalid collection filter');
|
|
12
12
|
if (!value.trim()) return null;
|
|
13
13
|
if (dtype === 'T') {
|
|
14
|
-
const
|
|
14
|
+
const pattern = filter.literal === true ? value.replace(/[.*+?^${}()|[\]\\]/g,'\\$&') : value;
|
|
15
|
+
const expression = new RegExp(pattern, 'i');
|
|
15
16
|
return read => expression.test(columns.map(field => searchText(read(field), locale, filter.timeZone)).join(' '));
|
|
16
17
|
}
|
|
17
18
|
if (columns.length !== 1) throw new TypeError('Typed filters require one column');
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {isDecimal, toTytx, fromTytx} from '@genrojs/tytx';
|
|
2
|
+
|
|
3
|
+
/** Typed identities: captions never determine membership. Blank values share one bucket. */
|
|
4
|
+
export function columnValue(value) {
|
|
5
|
+
if (value == null || value === '') return null;
|
|
6
|
+
if (typeof value === 'string' || typeof value === 'boolean' ||
|
|
7
|
+
typeof value === 'number' && Number.isFinite(value) ||
|
|
8
|
+
value instanceof Date && Number.isFinite(value.getTime()) ||
|
|
9
|
+
isDecimal(value) && value.isFinite()) return value;
|
|
10
|
+
throw new TypeError('Column filters require loaded scalar values');
|
|
11
|
+
}
|
|
12
|
+
export function columnValueKey(value) { return toTytx(columnValue(value)); }
|
|
13
|
+
export function columnSelection(values) {
|
|
14
|
+
if (!Array.isArray(values)) throw new TypeError('Column selection requires an array or null');
|
|
15
|
+
return Object.freeze([...new Map(values.map(value => {
|
|
16
|
+
const key = columnValueKey(value);
|
|
17
|
+
return [key, fromTytx(key)];
|
|
18
|
+
})).values()]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Civil bounds; datetime values use the same day convention as their display. */
|
|
22
|
+
export function columnDateRange(range) {
|
|
23
|
+
if (range === null) return null;
|
|
24
|
+
const {from, to, dtype, timeZone} = range;
|
|
25
|
+
if (!['D','DH','DHZ'].includes(dtype)) throw new TypeError('Date range requires a date column');
|
|
26
|
+
for (const value of [from,to]) {
|
|
27
|
+
if (value !== null && (!(value instanceof Date) || !Number.isFinite(value.getTime()) ||
|
|
28
|
+
value.getUTCHours() || value.getUTCMinutes() || value.getUTCSeconds() || value.getUTCMilliseconds())) {
|
|
29
|
+
throw new TypeError('Date bounds require civil dates');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (from && to && from > to) throw new RangeError('From must not be after To.');
|
|
33
|
+
if (dtype === 'DHZ' && !timeZone) throw new TypeError('DHZ requires a timeZone');
|
|
34
|
+
return from || to ? Object.freeze({from:from?.toISOString().slice(0,10) ?? null,
|
|
35
|
+
to:to?.toISOString().slice(0,10) ?? null,dtype,timeZone}) : null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function columnDateMatches(value, range) {
|
|
39
|
+
if (!range) return true;
|
|
40
|
+
if (value == null || value === '') return false;
|
|
41
|
+
if (!(value instanceof Date) || !Number.isFinite(value.getTime())) throw new TypeError('Date range requires date values');
|
|
42
|
+
let day;
|
|
43
|
+
if (range.dtype === 'DHZ') {
|
|
44
|
+
const parts = new Intl.DateTimeFormat('en', {timeZone:range.timeZone,year:'numeric',month:'2-digit',day:'2-digit'}).formatToParts(value);
|
|
45
|
+
const part = type => parts.find(item=>item.type===type).value;
|
|
46
|
+
day = `${part('year')}-${part('month')}-${part('day')}`;
|
|
47
|
+
} else day = value.toISOString().slice(0,10);
|
|
48
|
+
return (!range.from || day >= range.from) && (!range.to || day <= range.to);
|
|
49
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Literal membership shared by checkbox projections and collection-view predicates. */
|
|
2
|
+
export function containsId(value, id) { return (',' + value + ',').includes(',' + id + ','); }
|
|
3
|
+
export function requireIdSet(value) {
|
|
4
|
+
if (typeof value !== 'string') throw new TypeError('grid checked must refer to a string (empty string for an empty set)');
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
export function requireId(id) {
|
|
8
|
+
if (typeof id !== 'string' || !id || id.includes(',')) throw new TypeError('grid checkedField requires nonempty text IDs without commas');
|
|
9
|
+
return id;
|
|
10
|
+
}
|