@gramlot/gramlot 0.3.27 → 0.3.31
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 +2 -2
- package/dist/components/grid/assets/collection.js +71 -34
- package/dist/components/grid/assets/files/0a1df3a083d0c010560aa342e87959c8c1070e6fd54545741f083f22d0c8b551-fflate.txt +21 -0
- package/dist/components/grid/assets/files/8cf9b31947daf7adb4a7a00a037459e58241af050cd0a603bfcf1756e533f75e-write-excel-file.txt +21 -0
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/assets/modules/browser-LVJHKBBV.js +19 -0
- package/dist/components/grid/assets/modules/chunk-RMRBEYTI.js +1 -0
- package/dist/components/grid/commands.json +42 -1
- package/dist/components/grid/grammar.json +650 -10
- 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 +944 -193
- package/dist/gramlot.min.js +85 -53
- package/dist/standard-collections.js +2 -0
- package/package.json +13 -4
- package/src/binding/grid-struct.js +5 -2
- package/src/binding/runtime.js +12 -1
- package/src/bootstrap.js +1 -1
- package/src/builder/gramlot-builder.d.ts +15 -2
- package/src/builder/gramlot-builder.js +116 -8
- package/src/builder/source.js +42 -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-footer.js +120 -0
- package/src/components/grid-formulas.js +403 -0
- package/src/components/grid-grammar.json +131 -2
- 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-selection.js +118 -0
- package/src/components/grid-structure.js +36 -5
- package/src/components/grid-styles.js +37 -1
- package/src/components/grid-tools.js +229 -0
- package/src/components/grid.js +223 -15
- 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/fflate.txt +21 -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/licenses/write-excel-file.txt +21 -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/editing-session.d.ts +2 -0
- package/src/editing-session.js +35 -3
- 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-store.js +14 -5
- package/src/stores/bag-collection-view.js +80 -18
- 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
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Leon Sorokin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Copyright (c) 2015-2023, University of Washington Interactive Data Lab
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
15
|
+
may be used to endorse or promote products derived from this software
|
|
16
|
+
without specific prior written permission.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 gitlab.com/catamphetamine
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/src/components/menus.js
CHANGED
|
@@ -13,9 +13,9 @@ export function MenuContainer(HTMLElement) {
|
|
|
13
13
|
const doc = this.ownerDocument, shadow = this.attachShadow({mode: 'open'});
|
|
14
14
|
const style = doc.createElement('style');
|
|
15
15
|
style.textContent = `:host{box-sizing:border-box;color:var(--gramlot-ink,CanvasText)}
|
|
16
|
-
:host([role=menu]){position:fixed;inset:auto;margin:0;padding:
|
|
16
|
+
:host([role=menu]){position:fixed;inset:auto;margin:0;padding:3px;min-width:0;width:max-content;font:inherit;
|
|
17
17
|
max-width:min(28rem,var(--gramlot-popup-available-width));max-height:var(--gramlot-popup-available-height);overflow:auto;
|
|
18
|
-
background:var(--gramlot-field-background,Canvas);border:1px solid var(--gramlot-border-control,#888);border-radius:var(--gramlot-radius-
|
|
18
|
+
background:var(--gramlot-field-background,Canvas);border:1px solid var(--gramlot-border-control,#888);border-radius:var(--gramlot-radius-sm,5px);box-shadow:0 4px 14px #0003}
|
|
19
19
|
:host([role=toolbar][aria-orientation=vertical]){flex-direction:column;align-items:stretch}
|
|
20
20
|
:host([role=toolbar]){display:flex;gap:var(--gramlot-toolbar-gap,4px);align-items:center}
|
|
21
21
|
:host([role=menu]) ::slotted([role=separator]){margin:5px 7px 5px 2.5rem;border-top:1px solid var(--gramlot-border-control,#888)}
|
|
@@ -39,7 +39,8 @@ export function MenuContainer(HTMLElement) {
|
|
|
39
39
|
get items() { return [...this.querySelectorAll('gramlot-menu-line')].filter(item => item.menuOwner===this && !item.parameters.group); }
|
|
40
40
|
get overflow() { return this.#overflow; }
|
|
41
41
|
isOverflowed(item) { return this.#overflow.contains(item); }
|
|
42
|
-
get
|
|
42
|
+
get visibleItems() { return this.items.filter(item => labelboxPresentation(item).slot!=='suppressed' && !item.hidden && !item.closest('[hidden]') && item.getAttribute('role') !== 'separator'); }
|
|
43
|
+
get usableItems() { return this.visibleItems.filter(item => !item.disabled); }
|
|
43
44
|
get parentMenu() { return this.parentElement?.closest('gramlot-menu') ?? null; }
|
|
44
45
|
connectedCallback() {
|
|
45
46
|
this.#observer = new this.ownerDocument.defaultView.MutationObserver(() => {this.refreshItems();this.#overflow.schedule();});
|
|
@@ -114,6 +115,12 @@ export function MenuContainer(HTMLElement) {
|
|
|
114
115
|
for(const group of this.querySelectorAll('gramlot-menu-line'))if(group.menuOwner===this && group.parameters.group)group.refreshAvailability();
|
|
115
116
|
for(const item of this.items)item.refreshAvailability();
|
|
116
117
|
const usable = this.usableItems;
|
|
118
|
+
// Reserve only the adornments used by this menu; keep captions aligned.
|
|
119
|
+
for (const [part, present, width] of [
|
|
120
|
+
['check', this.visibleItems.some(item => item.parameters.checked != null), '1.4em'],
|
|
121
|
+
['icon', this.visibleItems.some(item => item.entryIcon || item.entryIconSrc), '1.5em'],
|
|
122
|
+
['arrow', this.visibleItems.some(item => item.submenu), '.9em'],
|
|
123
|
+
]) this.style.setProperty(`--gramlot-menu-${part}-track`, present ? width : '0px');
|
|
117
124
|
if (this.#active && !usable.includes(this.#active)) {
|
|
118
125
|
const index = this.#previous.indexOf(this.#active);
|
|
119
126
|
const next = this.#previous.slice(index+1).find(item => usable.includes(item))
|
|
@@ -208,10 +215,10 @@ export function menuLine(Base) {
|
|
|
208
215
|
const style=doc.createElement('style');
|
|
209
216
|
style.textContent=`:host{color:var(--gramlot-ink,CanvasText)} .control-box{color:inherit;height:100%} :host button{color:inherit}
|
|
210
217
|
.menu-check:empty,.menu-arrow:empty{display:none}
|
|
211
|
-
button.menu-row{display:grid;grid-template-columns:
|
|
212
|
-
align-items:center;width:100%;min-height:max(
|
|
218
|
+
button.menu-row{display:grid;grid-template-columns:var(--gramlot-menu-check-track,0px) var(--gramlot-menu-icon-track,0px) minmax(0,1fr) var(--gramlot-menu-arrow-track,0px);column-gap:0;
|
|
219
|
+
align-items:center;width:100%;min-height:max(24px,var(--gramlot-touch-target,0px));padding:2px 7px;
|
|
213
220
|
line-height:1.3;text-align:left;border:0;border-radius:var(--gramlot-radius-sm,5px);background:transparent;cursor:default}
|
|
214
|
-
.menu-row .menu-check,.menu-row .icon,.menu-row .menu-arrow{display:flex;align-items:center;justify-content:
|
|
221
|
+
.menu-row .menu-check,.menu-row .icon,.menu-row .menu-arrow{display:flex;align-items:center;justify-content:start;min-width:0}
|
|
215
222
|
.menu-row .menu-check{grid-column:1}.menu-row .icon{grid-column:2}
|
|
216
223
|
.menu-row .menu-caption{grid-column:3;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
217
224
|
.menu-row .menu-arrow{grid-column:4;font-size:1.2em;line-height:1}
|
|
@@ -223,6 +230,7 @@ export function menuLine(Base) {
|
|
|
223
230
|
background:transparent;cursor:pointer;line-height:1.2;white-space:nowrap}
|
|
224
231
|
:host button.toolbar-button .icon{display:inline-flex;align-items:center;justify-content:center;
|
|
225
232
|
width:var(--gramlot-toolbar-icon-size);height:var(--gramlot-toolbar-icon-size);font-size:var(--gramlot-toolbar-icon-size);line-height:1}
|
|
233
|
+
#control.toolbar-button.icon-only{--gramlot-button-icon-size:var(--gramlot-toolbar-icon-size)}
|
|
226
234
|
:host button.toolbar-button .icon:empty{display:none}
|
|
227
235
|
:host button.toolbar-button:hover:not(:disabled){background:color-mix(in srgb,currentColor 10%,transparent)}
|
|
228
236
|
:host button.toolbar-button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-2px}
|
|
@@ -232,7 +240,7 @@ export function menuLine(Base) {
|
|
|
232
240
|
:host button.toolbar-below .menu-caption{font-size:11px;line-height:1.2}
|
|
233
241
|
:host button.toolbar-tooltip .menu-caption{display:none}
|
|
234
242
|
:host button.toolbar-button .menu-check{display:none}
|
|
235
|
-
:host button.toolbar-tooltip .menu-arrow{position:
|
|
243
|
+
:host button.toolbar-tooltip .menu-arrow{position:static;flex:0 0 8px;margin-inline-start:2px;font-size:12px;line-height:1}
|
|
236
244
|
:host button.toolbar-below .menu-arrow{position:absolute;inset:4px 3px auto auto;font-size:12px}`;
|
|
237
245
|
style.textContent+=`
|
|
238
246
|
:host([role=group]){display:block;min-width:0}
|
|
@@ -263,7 +271,7 @@ export function menuLine(Base) {
|
|
|
263
271
|
this.addEventListener('pointerleave',()=>clearTimeout(this.#hover));
|
|
264
272
|
}
|
|
265
273
|
get menuOwner() { return this.parentElement?.closest('gramlot-menu') ?? null; }
|
|
266
|
-
get submenu() { return [...this.children].map(labelboxContent).find(child=>child
|
|
274
|
+
get submenu() { return [...this.children].map(labelboxContent).find(child=>child?.localName==='gramlot-menu') ?? null; }
|
|
267
275
|
get entryCaption() { return this.parameters.caption ?? this.#registry?.label ?? ''; }
|
|
268
276
|
get entryIcon() { return this.parameters.icon || this.parameters.iconSrc ? this.parameters.icon : this.#registry?.icon; }
|
|
269
277
|
get entryIconSrc() { return this.parameters.icon || this.parameters.iconSrc ? this.parameters.iconSrc : this.#registry?.iconSrc; }
|
|
@@ -275,9 +283,8 @@ export function menuLine(Base) {
|
|
|
275
283
|
const rest=super.projectAttributes(attrs,adapt);
|
|
276
284
|
this.#accessibleLabel=attrs['aria-label'];
|
|
277
285
|
if(this.parameters.iconSize!=null&&(!Number.isFinite(this.parameters.iconSize)||this.parameters.iconSize<=0))throw new TypeError('menuline iconSize must be positive');
|
|
278
|
-
if(!Number.isFinite(this.parameters.priority))throw new TypeError('menuline priority must be finite');
|
|
279
286
|
this.#authoredDisabled=Boolean(this.parameters.disabled);
|
|
280
|
-
this.#render(); this.menuOwner?.overflow.schedule(); return rest;
|
|
287
|
+
this.#render(); this.menuOwner?.refreshItems(); this.menuOwner?.overflow.schedule(); return rest;
|
|
281
288
|
}
|
|
282
289
|
#render() {
|
|
283
290
|
const separator=[...this.childNodes].filter(node=>node.nodeType===3)
|
|
@@ -318,12 +325,13 @@ export function menuLine(Base) {
|
|
|
318
325
|
else this.control.style.removeProperty('--gramlot-toolbar-icon-size');
|
|
319
326
|
this.toggleAttribute('data-menu-group-rows',Boolean(popup || owner?.parameters.orientation==='vertical'));
|
|
320
327
|
this.control.classList.toggle('menu-row', popup);
|
|
321
|
-
this.#arrow.textContent = this.submenu ? (popup || owner?.parameters.orientation==='vertical' ? '›' : '▾') : '';
|
|
328
|
+
this.#arrow.textContent = this.submenu ? (toolbar && labelPosition==='tooltip' ? '⌄' : popup || owner?.parameters.orientation==='vertical' ? '›' : '▾') : '';
|
|
322
329
|
const disabled=this.#authoredDisabled || this.getAttribute('role')==='separator'
|
|
323
330
|
|| Boolean(this.parameters.command && !this.#registry)
|
|
324
331
|
|| ['loading','error'].includes(owner?.status)
|
|
325
332
|
|| Boolean(this.closest('gramlot-drop-down-button')?.parameters.disabled);
|
|
326
333
|
if(this.control.disabled!==disabled)this.control.disabled=disabled;
|
|
334
|
+
this.refreshIconOnly();
|
|
327
335
|
}
|
|
328
336
|
get disabled() {
|
|
329
337
|
for(let p=this.parentElement;p && p!==this.menuOwner;p=p.parentElement)if(p.localName==='gramlot-menu-line' && p.parameters.disabled)return true;
|
|
@@ -43,6 +43,7 @@ export class ToolbarOverflow {
|
|
|
43
43
|
:host([role=toolbar]) .toolbar-viewport{display:flex;align-items:center;gap:var(--gramlot-toolbar-gap,4px);flex:1 1 0%;min-width:0;min-height:0;overflow-x:auto;overflow-y:hidden}
|
|
44
44
|
:host([role=toolbar][aria-orientation=vertical]) .toolbar-viewport{flex-direction:column;align-items:stretch;overflow-x:hidden;overflow-y:auto;width:100%}
|
|
45
45
|
:host([role=toolbar]) ::slotted(*){flex-shrink:0}
|
|
46
|
+
:host([role=toolbar]) .toolbar-viewport[data-measuring]{flex:none;width:max-content;height:max-content;overflow:visible}
|
|
46
47
|
.toolbar-more{flex:0 0 auto;width:max(var(--gramlot-field-height,32px),var(--gramlot-touch-target,0px));height:max(var(--gramlot-field-height,32px),var(--gramlot-touch-target,0px));padding:0;border:0;border-radius:4px;background:transparent;color:inherit;font:inherit;display:grid;place-items:center}
|
|
47
48
|
.toolbar-more svg{display:block;width:18px;height:18px;pointer-events:none}
|
|
48
49
|
.toolbar-more:hover,.toolbar-more:focus-visible{background:var(--gramlot-selected,Highlight)}
|
|
@@ -109,12 +110,16 @@ export class ToolbarOverflow {
|
|
|
109
110
|
this.#overflow.clear();
|
|
110
111
|
menu.refreshItems();
|
|
111
112
|
for(const item of menu.items)item.refreshAvailability();
|
|
113
|
+
// Auto margins distribute spare space; they are not intrinsic content.
|
|
114
|
+
// Measure synchronously without flex allocation, then restore before paint.
|
|
115
|
+
this.#viewport.setAttribute('data-measuring','');
|
|
112
116
|
const gap=parseFloat(win.getComputedStyle(this.#viewport).gap)||0;
|
|
113
117
|
const lengths=new Map(units.map(unit=>{
|
|
114
118
|
const css=win.getComputedStyle(unit);
|
|
115
119
|
const length=labelboxContent(unit).localName==='gramlot-spacer'?(labelboxContent(unit).parameters.size??0):unit.getBoundingClientRect()[axis];
|
|
116
120
|
return [unit,length+(parseFloat(css[vertical?'marginTop':'marginLeft'])||0)+(parseFloat(css[vertical?'marginBottom':'marginRight'])||0)];
|
|
117
121
|
}));
|
|
122
|
+
this.#viewport.removeAttribute('data-measuring');
|
|
118
123
|
const separator=unit=>labelboxContent(unit).getAttribute('role')==='separator';
|
|
119
124
|
const tidy=list=>list.filter((unit,index)=>!separator(unit) ||
|
|
120
125
|
list.slice(0,index).some(item=>labelboxContent(item).localName!=='gramlot-spacer'&&!separator(item)) &&
|
|
@@ -123,16 +128,15 @@ export class ToolbarOverflow {
|
|
|
123
128
|
const required=remaining=>remaining.reduce((sum,unit)=>sum+lengths.get(unit),0)+Math.max(0,remaining.length-1)*gap;
|
|
124
129
|
let remaining=tidy(units);
|
|
125
130
|
if(required(remaining)>available){
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
this.#overflow.add(unit);remaining=tidy(remaining.filter(item=>item!==unit));
|
|
131
|
+
let cut=units.length;
|
|
132
|
+
while(cut>0 && required(remaining)>available-32) {
|
|
133
|
+
cut--;
|
|
134
|
+
remaining=tidy(units.slice(0,cut));
|
|
131
135
|
}
|
|
136
|
+
const suffix=tidy(units.slice(cut).filter(unit=>labelboxContent(unit).localName!=='gramlot-spacer'));
|
|
137
|
+
for(const unit of suffix)this.#overflow.add(unit);
|
|
132
138
|
}
|
|
133
|
-
const
|
|
134
|
-
for(const unit of overflowRows)this.#overflow.add(unit);
|
|
135
|
-
for(const unit of units)if(separator(unit)&&!remaining.includes(unit)&&!this.#overflow.has(unit))unit.slot='suppressed';
|
|
139
|
+
for(const unit of units)if(!remaining.includes(unit)&&!this.#overflow.has(unit))unit.slot='suppressed';
|
|
136
140
|
for(const unit of this.#overflow){unit.slot='overflow';unit.setAttribute('data-menu-overflow','');}
|
|
137
141
|
this.#button.hidden=this.#overflow.size===0;
|
|
138
142
|
for(const item of menu.items)item.refreshAvailability();
|
package/src/components/tree.js
CHANGED
|
@@ -53,13 +53,17 @@ export const Tree = defineComponent({
|
|
|
53
53
|
excludeRoot: {dtype: 'T', nullable: true, default: null, binding: 'read'},
|
|
54
54
|
labelCb: {dtype: 'T', nullable: true, default: null},
|
|
55
55
|
getLabel: {dtype: 'T', nullable: true, default: null},
|
|
56
|
+
labelState: {dtype: 'X', nullable: true, default: null, binding: 'read'},
|
|
56
57
|
getLabelClass: {dtype: 'T', nullable: true, default: null},
|
|
57
58
|
getIconClass: {dtype: 'T', nullable: true, default: null},
|
|
58
59
|
selectedLabelClass: {dtype: 'T', default: '', binding: 'read'},
|
|
59
60
|
searchText: {dtype: 'T', default: '', binding: 'read'},
|
|
61
|
+
searchEager: {dtype: 'B', default: true, binding: 'read'},
|
|
62
|
+
searchAttributes: {dtype: 'T', default: '', binding: 'read'},
|
|
60
63
|
favorites: {dtype: 'X', nullable: true, default: null, binding: 'read'},
|
|
61
64
|
favoritesLabel: {dtype: 'T', default: 'Favorites', binding: 'read'},
|
|
62
65
|
autoCollapse: {dtype: 'B', default: false, binding: 'read'},
|
|
66
|
+
resolveLazy: {dtype: 'B', default: true, binding: 'read'},
|
|
63
67
|
selectedPath: {dtype: 'T', nullable: true, default: null, binding: 'twoWay'},
|
|
64
68
|
onChecked: {dtype: ['B', 'T'], nullable: true, default: null},
|
|
65
69
|
checkedPaths: {dtype: 'T', nullable: true, default: null, binding: 'twoWay'},
|
|
@@ -146,13 +150,17 @@ export const Tree = defineComponent({
|
|
|
146
150
|
});
|
|
147
151
|
}
|
|
148
152
|
setSourceContext(context) { this.#context = context; }
|
|
153
|
+
get storeBag() { return this.#store; }
|
|
149
154
|
/** Read only the rendered row and its BagNode; never request a resolver value. */
|
|
150
155
|
getDragContext(event) {
|
|
151
156
|
for (const element of event.composedPath()) {
|
|
152
157
|
const row = this.#dragRows.get(element);
|
|
153
158
|
if (!row) continue;
|
|
154
159
|
const {item, path, caption} = row;
|
|
155
|
-
|
|
160
|
+
const rect = element.getBoundingClientRect();
|
|
161
|
+
const fraction = rect.height ? (event.clientY - rect.top) / rect.height : 0.5;
|
|
162
|
+
const placement = fraction < 0.25 ? 'before' : fraction > 0.75 ? 'after' : 'inside';
|
|
163
|
+
return {element, item, path, placement, dragValues: {
|
|
156
164
|
'text/plain': caption.textContent,
|
|
157
165
|
nodeattr: {...item.getAttr()},
|
|
158
166
|
treenode: {fullpath: item.fullpath, relpath: path}
|
|
@@ -179,7 +187,13 @@ export const Tree = defineComponent({
|
|
|
179
187
|
projectAttributes(attrs, adapt) {
|
|
180
188
|
this.#pathsEnabled = Object.hasOwn(attrs, 'checkedPaths');
|
|
181
189
|
this.#checksEnabled = this.#pathsEnabled || Boolean(attrs.onChecked);
|
|
190
|
+
const previousEager = this.parameters?.searchEager;
|
|
191
|
+
const previousResolve = this.parameters?.resolveLazy;
|
|
182
192
|
const rest = super.projectAttributes(attrs, adapt);
|
|
193
|
+
if (previousEager !== this.parameters.searchEager || previousResolve !== this.parameters.resolveLazy) {
|
|
194
|
+
this.#resetSearch();
|
|
195
|
+
this.#searchText = this.#searchInput.toLowerCase();
|
|
196
|
+
}
|
|
183
197
|
if (this.#excludedRoot !== this.parameters.excludeRoot) {
|
|
184
198
|
this.#excludedRoot = this.parameters.excludeRoot;
|
|
185
199
|
this.#resetSearch();
|
|
@@ -210,7 +224,8 @@ export const Tree = defineComponent({
|
|
|
210
224
|
#opened(node) { return this.#searchText ? this.#searchOpen.has(node) : this.#expanded.has(node); }
|
|
211
225
|
async #searchBranches() {
|
|
212
226
|
const version = this.#searchVersion, store = this.#store;
|
|
213
|
-
const current = () => this.isConnected && version === this.#searchVersion && store === this.#store
|
|
227
|
+
const current = () => this.isConnected && version === this.#searchVersion && store === this.#store
|
|
228
|
+
&& this.parameters.searchEager && this.parameters.resolveLazy;
|
|
214
229
|
this.#searching = true;
|
|
215
230
|
const visit = async (bag, ancestors = new Set()) => {
|
|
216
231
|
if (!current()) return;
|
|
@@ -220,6 +235,7 @@ export const Tree = defineComponent({
|
|
|
220
235
|
if (bag === this.#store && node.label === this.parameters.excludeRoot) continue;
|
|
221
236
|
if (!current()) return;
|
|
222
237
|
if (node.attr.loop === true) continue;
|
|
238
|
+
if (node.resolver !== null && !this.parameters.resolveLazy) continue;
|
|
223
239
|
if (node.resolver !== null && node.resolver.expired && !this.#searchAttempted.has(node)) {
|
|
224
240
|
this.#searchAttempted.add(node);
|
|
225
241
|
await this.#resolve(node, true);
|
|
@@ -272,14 +288,14 @@ export const Tree = defineComponent({
|
|
|
272
288
|
for (const node of bag.getNodes()) {
|
|
273
289
|
if (bag === this.#store && node.label === this.parameters.excludeRoot) continue;
|
|
274
290
|
const path = prefix ? `${prefix}.${node.label}` : node.label;
|
|
275
|
-
const value = node.
|
|
291
|
+
const value = node.resolver !== null && !this.parameters.resolveLazy ? null : node.staticValue;
|
|
276
292
|
items.set(path, {node, ancestors, children: value instanceof Bag ? value : null});
|
|
277
293
|
if (value instanceof Bag) visit(value, path, [...ancestors, node]);
|
|
278
294
|
}
|
|
279
295
|
seen.delete(bag);
|
|
280
296
|
};
|
|
281
297
|
visit(this.#store, '', []);
|
|
282
|
-
if (this.#searchText && this.#searchTimer === null && !this.#searching && [...items.values()].some(({node}) =>
|
|
298
|
+
if (this.parameters.searchEager && this.parameters.resolveLazy && this.#searchText && this.#searchTimer === null && !this.#searching && [...items.values()].some(({node}) =>
|
|
283
299
|
node.attr.loop !== true && node.resolver !== null && node.resolver.expired && !this.#searchAttempted.has(node))) {
|
|
284
300
|
void this.#searchBranches();
|
|
285
301
|
}
|
|
@@ -351,7 +367,7 @@ export const Tree = defineComponent({
|
|
|
351
367
|
const {children} = items.get(path);
|
|
352
368
|
const scalar = children === null && !this.parameters.hideValues && (node.resolver === null || !node.resolver.expired);
|
|
353
369
|
const branch = children !== null ? children.length > 0
|
|
354
|
-
: scalar || (node.resolver !== null && node.attr.child_count !== 0);
|
|
370
|
+
: scalar || (node.resolver !== null && this.parameters.resolveLazy && node.attr.child_count !== 0);
|
|
355
371
|
const entry = this.ownerDocument.createElement('li');
|
|
356
372
|
entry.className = `node ${branch ? 'branch' : 'leaf'}`;
|
|
357
373
|
entry.setAttribute('part', `node ${branch ? 'branch' : 'leaf'}`);
|
|
@@ -453,7 +469,7 @@ export const Tree = defineComponent({
|
|
|
453
469
|
badge.hidden = value == null || value === '';
|
|
454
470
|
badge.style.backgroundColor = color ?? '';
|
|
455
471
|
badge.toggleAttribute('data-colored', color != null && color !== '');
|
|
456
|
-
const keywords = {item: node, path, opened, selected};
|
|
472
|
+
const keywords = {item: node, path, opened, selected, state: this.parameters.labelState};
|
|
457
473
|
const attribute = this.parameters.labelAttribute;
|
|
458
474
|
const label = this.parameters.internalNames && node.getAttr('fieldpath') ? node.label
|
|
459
475
|
: this.parameters.getLabel !== null ? this.#call('getLabel', keywords)
|
|
@@ -549,7 +565,12 @@ export const Tree = defineComponent({
|
|
|
549
565
|
for (const [path, row] of this.#rows) {
|
|
550
566
|
const caption = row.firstElementChild.querySelector('.caption'), item = items.get(path);
|
|
551
567
|
if (item.ancestors.some(ancestor => ancestor.attr.loop === true)) continue;
|
|
552
|
-
const
|
|
568
|
+
const metadata = this.parameters.searchAttributes.split(',').map(name => name.trim()).filter(Boolean)
|
|
569
|
+
.flatMap(name => {
|
|
570
|
+
const value = item.node.getAttr(name);
|
|
571
|
+
return Array.isArray(value) ? value.filter(part => typeof part === 'string') : typeof value === 'string' ? [value] : [];
|
|
572
|
+
});
|
|
573
|
+
const match = [caption.textContent, ...metadata].some(text => text.toLowerCase().includes(this.#searchText));
|
|
553
574
|
if (match) matches.push(caption);
|
|
554
575
|
if (match || this.#errors.has(item.node) || this.#loading.has(item.node)) {
|
|
555
576
|
visible.add(item.node);
|
|
@@ -648,6 +669,7 @@ export const Tree = defineComponent({
|
|
|
648
669
|
if (!current()) return;
|
|
649
670
|
const node = bag.getNode(part);
|
|
650
671
|
if (!node) return;
|
|
672
|
+
if (node.resolver !== null && !this.parameters.resolveLazy) return;
|
|
651
673
|
if (node.resolver === null && !(node.staticValue instanceof Bag)) return;
|
|
652
674
|
if (!current() || bag.getNode(part) !== node) return;
|
|
653
675
|
this.#expand(node);
|
|
@@ -774,7 +796,7 @@ export const Tree = defineComponent({
|
|
|
774
796
|
return value.split(/\s+/).filter(Boolean);
|
|
775
797
|
}
|
|
776
798
|
#rowActions() {
|
|
777
|
-
const bars = this.
|
|
799
|
+
const bars = [...this.children].filter(child => child.localName === 'gramlot-row-actions');
|
|
778
800
|
if (bars.length > 1) throw new Error('tree accepts one rowActions bar');
|
|
779
801
|
return bars[0] ?? null;
|
|
780
802
|
}
|
|
@@ -90,12 +90,14 @@ export function TypedEditor(HTMLElement) {
|
|
|
90
90
|
this.checkValue(value);
|
|
91
91
|
return this.validateCandidate(value, accepted => {
|
|
92
92
|
this.checkValue(accepted);
|
|
93
|
+
this.acceptDraft(accepted, this.#selection ? null : this.control.value, this.#policy ?? this.context());
|
|
93
94
|
this.#value = accepted; this.#selection = null; this.#dirty = false;
|
|
94
95
|
// Preserve accepted spelling unless validation normalized the candidate.
|
|
95
96
|
if (!this.#focused || !this.sameControlValue(value, accepted)) { this.#policy = null; this.display(); }
|
|
96
97
|
});
|
|
97
98
|
} catch (error) { if (this.pageContext.form) this.pageContext.formParseError(error.message); this.error(error.message); return {ok: false}; }
|
|
98
99
|
}
|
|
100
|
+
acceptDraft(value, text, context) {}
|
|
99
101
|
restoreFormDraft(text) { this.#dirty = true; this.#policy = this.context(); this.control.value = text; }
|
|
100
102
|
restoreFormValue(value) { this.#dirty = false; this.#policy = null; this.#selection = null; this.error(''); this.writeControlValue(value); this.display(); }
|
|
101
103
|
display() {
|
|
@@ -234,14 +236,23 @@ export const dateEditor = Base => class extends Base {
|
|
|
234
236
|
static validationValueCheck() { return checkCivilDate; }
|
|
235
237
|
checkValue(value) { checkCivilDate(value); }
|
|
236
238
|
editText(value, context) { return this.pageContext.format(value, {...context, pattern: 'short'}); }
|
|
237
|
-
|
|
239
|
+
dateExpression(text, context) {
|
|
238
240
|
const now = new Date();
|
|
239
241
|
const workdate = this.parameters.workdate ?? `${now.getFullYear()}-${pad(now.getMonth()+1)}-${pad(now.getDate())}`;
|
|
240
242
|
const options = {locale: context.locale, workdate};
|
|
241
243
|
const result = parseDateExpression(text, options);
|
|
242
244
|
if (!result.ok) throw new Error(result.error.message);
|
|
243
|
-
if (result.kind !== 'date') throw new Error('Enter one complete date, not a period.');
|
|
244
|
-
|
|
245
|
+
if (result.kind !== 'date' && !this.parameters.period_to) throw new Error('Enter one complete date, not a period.');
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
acceptDraft(value, text, context) {
|
|
249
|
+
if (!text?.trim() || !this.parameters.period_to) return;
|
|
250
|
+
const result = this.dateExpression(text, context);
|
|
251
|
+
if (result.kind === 'period') this.pageContext.periodOutput(this.parameters.period_to, new Date(result.end + 'T00:00:00Z'));
|
|
252
|
+
}
|
|
253
|
+
parse(text, context) {
|
|
254
|
+
const result = this.dateExpression(text, context);
|
|
255
|
+
const [y, m, d] = (result.kind === 'date' ? result.date : result.start).split('-').map(Number);
|
|
245
256
|
const value = new Date(0); value.setUTCFullYear(y, m - 1, d); return value;
|
|
246
257
|
}
|
|
247
258
|
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {randomId} from '../random-id.js';
|
|
2
|
+
|
|
3
|
+
/** One optional Vizabi instance; the Gramlot Bag owns authored state. */
|
|
4
|
+
export class VizabiSession {
|
|
5
|
+
constructor(library, element, view, configuration) {
|
|
6
|
+
this.library=library; this.configuration=configuration; this.element=element;
|
|
7
|
+
const {Vizabi,BubbleChart,mobx}=library;
|
|
8
|
+
if(!Number.isInteger(configuration.getItem('year'))||typeof configuration.getItem('playing')!=='boolean'||!Number.isFinite(configuration.getItem('speed'))||configuration.getItem('speed')<=0)throw new TypeError('Vizabi requires an integer year, Boolean playing and positive speed in milliseconds');
|
|
9
|
+
const keys=['entityField','timeField','xField','yField','sizeField','colorField'];
|
|
10
|
+
const fields=Object.fromEntries(keys.map(key=>[key,configuration.getItem(key)]));
|
|
11
|
+
for(const [key,value] of Object.entries(fields))if(typeof value!=='string'||!value)throw new TypeError(`${key} requires a field name`);
|
|
12
|
+
if(Object.entries(fields).some(([key,value])=>value==='name'&&key!=='entityField'))throw new TypeError('The Vizabi entity catalogue reserves name for the entity display name');
|
|
13
|
+
const rows=view.getRows().map(node=>Object.fromEntries([...new Set(Object.values(fields))].map(field=>[field,view.value(node,field)])));
|
|
14
|
+
const identities=new Set();
|
|
15
|
+
for(const row of rows) {
|
|
16
|
+
if(typeof row[fields.entityField]!=='string'||!Number.isInteger(row[fields.timeField]))throw new TypeError('Vizabi trial requires text entities and integer years');
|
|
17
|
+
const key=JSON.stringify([row[fields.entityField],row[fields.timeField]]);
|
|
18
|
+
if(identities.has(key))throw new TypeError('Vizabi requires one prepared row per entity and year');
|
|
19
|
+
identities.add(key);
|
|
20
|
+
for(const field of [fields.xField,fields.yField,fields.sizeField])if(typeof row[field]!=='number'||!Number.isFinite(row[field]))throw new TypeError(`${field} requires finite numbers`);
|
|
21
|
+
if(row[fields.sizeField]<0)throw new TypeError('Bubble size cannot be negative');
|
|
22
|
+
if(typeof row[fields.colorField]!=='string')throw new TypeError('Bubble color requires a text category');
|
|
23
|
+
}
|
|
24
|
+
// Vizabi's entity catalogue requires its reserved display-name property.
|
|
25
|
+
for(const row of rows)row.name=row[fields.entityField];
|
|
26
|
+
if(!rows.length)throw new TypeError('No data to display');
|
|
27
|
+
this.id=`bubble_${randomId()}`;this.legendId=`legend_${randomId()}`;this.sourceId=`data_${randomId()}`;
|
|
28
|
+
const defaults=JSON.parse(JSON.stringify(BubbleChart.DEFAULT_MODEL).replaceAll('markers.bubble',`markers.${this.id}`).replaceAll('markers.legend',`markers.${this.legendId}`));
|
|
29
|
+
const bubble=defaults.bubble;
|
|
30
|
+
bubble.data={source:this.sourceId,space:[fields.entityField,fields.timeField]};
|
|
31
|
+
for(const [encoding,field] of Object.entries({x:fields.xField,y:fields.yField,size:fields.sizeField,color:fields.colorField,label:fields.entityField}))bubble.encoding[encoding].data={concept:field,constant:null};
|
|
32
|
+
bubble.encoding.label.data={modelType:'entityPropertyDataConfig',concept:'name'};
|
|
33
|
+
bubble.requiredEncodings=['x','y','size','color','label'];
|
|
34
|
+
bubble.encoding.y.modelType='baseType';
|
|
35
|
+
bubble.encoding.y.scale.type='linear';
|
|
36
|
+
bubble.encoding.frame={modelType:'frame',data:{concept:fields.timeField},value:String(configuration.getItem('year')),speed:configuration.getItem('speed'),splash:false,loop:true};
|
|
37
|
+
const models=Vizabi({dataSources:{[this.sourceId]:{values:rows,keyConcepts:[fields.entityField,fields.timeField],dtypes:{[fields.timeField]:'year'}}},markers:{[this.id]:bubble,[this.legendId]:defaults.legend}});
|
|
38
|
+
this.models=models;
|
|
39
|
+
this.frame=models.markers[this.id].encoding.frame;
|
|
40
|
+
this.tool=new BubbleChart({Vizabi,placeholder:element,model:{config:models.config,dataSources:models.dataSources,markers:{bubble:models.markers[this.id],legend:models.markers[this.legendId]}},locale:{id:'en',resolve:{en:library.locale},placeholder:element},layout:{placeholder:element},ui:{buttons:{buttons:[]},dialogs:{dialogs:{sidebar:[],popup:[]}}}});
|
|
41
|
+
this.release=mobx.reaction(()=>{const marker=models.markers[this.id];return [marker.state==='fulfilled'?this.frame.value.getUTCFullYear():null,this.frame.playing,...['x','y','size','color'].map(key=>marker.encoding[key].data.concept)];},([year,playing,x,y,size,color])=>{
|
|
42
|
+
if(!Number.isFinite(year))return;
|
|
43
|
+
this.writing=true;
|
|
44
|
+
try { for(const [key,value] of Object.entries({xField:x,yField:y,sizeField:size,colorField:color}))if(configuration.getItem(key)!==value)configuration.setItem(key,value);if(configuration.getItem('year')!==year)configuration.setItem('year',year);if(configuration.getItem('playing')!==playing)configuration.setItem('playing',playing); }
|
|
45
|
+
finally {this.writing=false;}
|
|
46
|
+
});
|
|
47
|
+
this.ready=mobx.when(()=>models.markers[this.id].state==='fulfilled',()=>this.update());
|
|
48
|
+
}
|
|
49
|
+
update() {
|
|
50
|
+
|
|
51
|
+
if(this.writing||this.models.markers[this.id].state!=='fulfilled')return;
|
|
52
|
+
const c=this.configuration,f=this.frame;
|
|
53
|
+
this.library.mobx.runInAction(()=>{
|
|
54
|
+
f.setSpeed(c.getItem('speed'));
|
|
55
|
+
if(f.value?.getUTCFullYear()!==c.getItem('year'))f.setValue(String(c.getItem('year')));
|
|
56
|
+
if(f.playing!==c.getItem('playing'))f.setPlaying(c.getItem('playing'));
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
resize() { this.tool.services.layout._resizeHandler(); }
|
|
60
|
+
dispose() {
|
|
61
|
+
this.release();this.ready();this.frame.stopPlaying();this.tool.deconstruct();
|
|
62
|
+
const stores=this.library.Vizabi.stores;
|
|
63
|
+
stores.markers.dispose(this.legendId);stores.markers.dispose(this.id);stores.dataSources.dispose(this.sourceId);
|
|
64
|
+
this.element.replaceChildren();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {Bag} from '@gramlot/gramlot';
|
|
2
|
+
import {defineCollection,defineComponent} from '@gramlot/gramlot/components';
|
|
3
|
+
import {Container} from './container.js';
|
|
4
|
+
import {BagCollectionView} from '../stores/bag-collection-view.js';
|
|
5
|
+
import {VizabiSession} from './vizabi-session.js';
|
|
6
|
+
|
|
7
|
+
const VizabiBubble=defineComponent({
|
|
8
|
+
name:'vizabiBubble',tag:'gramlot-vizabi-bubble',base:Container,sourceContext:true,bagStore:true,
|
|
9
|
+
parameters:{storepath:{dtype:'T'},rowMode:{dtype:'T',default:'attributes'},configuration:{dtype:'X',binding:'read'},libraryUrl:{dtype:'T'}},
|
|
10
|
+
implementation:Base=>class extends Base {
|
|
11
|
+
#context;#bag;#signature;#libraryUrl;#configuration;#view;#release;#session;#resize;#revision=0;#active=false;#subscription=Symbol('vizabi-config');#style;#message;#host;
|
|
12
|
+
constructor(){
|
|
13
|
+
super();this.control.replaceChildren();
|
|
14
|
+
this.#style=this.ownerDocument.createElement('style');this.shadowRoot.append(this.#style);
|
|
15
|
+
this.#message=this.ownerDocument.createElement('div');this.#message.setAttribute('role','status');
|
|
16
|
+
this.#host=this.ownerDocument.createElement('div');this.#host.style.cssText='width:100%;height:100%;position:relative;background:white;color:#222';
|
|
17
|
+
this.control.append(this.#message,this.#host);this.control.style.height='100%';
|
|
18
|
+
this.#resize=new this.ownerDocument.defaultView.ResizeObserver(()=>this.#session?.resize());
|
|
19
|
+
}
|
|
20
|
+
setSourceContext(context){this.#context=context;}
|
|
21
|
+
setStoreBag(bag){this.#bag=bag;}
|
|
22
|
+
projectAttributes(attrs,adapt){const result=super.projectAttributes(attrs,adapt);if(this.#active)this.#connect();return result;}
|
|
23
|
+
connectedCallback(){this.#active=true;this.#connect();this.#resize.observe(this.#host);}
|
|
24
|
+
#connect(){
|
|
25
|
+
let changed=this.#libraryUrl!==this.parameters.libraryUrl;this.#libraryUrl=this.parameters.libraryUrl;
|
|
26
|
+
const configuration=this.parameters.configuration;
|
|
27
|
+
if(!(configuration instanceof Bag))throw new TypeError('vizabiBubble requires a configuration Bag');
|
|
28
|
+
if(this.#configuration!==configuration){
|
|
29
|
+
changed=true;
|
|
30
|
+
this.#configuration?.unsubscribe(this.#subscription,{any:true});this.#configuration=configuration;
|
|
31
|
+
configuration.subscribe(this.#subscription,{any:()=>{
|
|
32
|
+
if(this.#session?.writing)return;
|
|
33
|
+
this.#refreshConfiguration();
|
|
34
|
+
}});
|
|
35
|
+
}
|
|
36
|
+
const store=this.#context.sourceNode.rootBuilder.binding.collectionStore(this.#bag,this.parameters.rowMode);
|
|
37
|
+
if(!this.#view){changed=true;this.#view=new BagCollectionView(store);this.#view.connect();this.#release=this.#view.subscribe(()=>this.#render());}
|
|
38
|
+
else if(this.#view.bag!==this.#bag){this.#view.bindStore(store);return;}
|
|
39
|
+
if(changed)this.#signature=null;
|
|
40
|
+
this.#refreshConfiguration();
|
|
41
|
+
}
|
|
42
|
+
#refreshConfiguration(){
|
|
43
|
+
const signature=JSON.stringify(['entityField','timeField','xField','yField','sizeField','colorField'].map(key=>this.#configuration.getItem(key)));
|
|
44
|
+
if(this.#session?.writing){this.#signature=signature;return;}
|
|
45
|
+
if(signature!==this.#signature){this.#signature=signature;this.#render();}
|
|
46
|
+
else this.#session?.update();
|
|
47
|
+
}
|
|
48
|
+
async #render(){
|
|
49
|
+
const revision=++this.#revision;this.#session?.dispose();this.#session=null;
|
|
50
|
+
this.#message.hidden=false;this.#message.textContent='Loading optional Vizabi library…';
|
|
51
|
+
try{
|
|
52
|
+
if(!this.parameters.libraryUrl)throw new Error('Provide libraryUrl to load the optional Vizabi module');
|
|
53
|
+
const library=await import(this.parameters.libraryUrl);
|
|
54
|
+
if(!this.#active||revision!==this.#revision)return;
|
|
55
|
+
this.#style.textContent=library.style+'\n:host{display:block;height:100%;min-height:0}.control-box{height:100%}';
|
|
56
|
+
this.#session=new VizabiSession(library,this.#host,this.#view,this.#configuration);
|
|
57
|
+
this.#message.hidden=true;
|
|
58
|
+
}catch(error){if(revision!==this.#revision)return;this.#message.setAttribute('role','alert');this.#message.textContent=error.message;}
|
|
59
|
+
}
|
|
60
|
+
disconnectedCallback(){
|
|
61
|
+
this.#active=false;this.#revision++;this.#resize.disconnect();this.#configuration?.unsubscribe(this.#subscription,{any:true});
|
|
62
|
+
this.#release?.();this.#view?.disconnect();this.#session?.dispose();this.#session=null;this.#view=null;this.#configuration=null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
export default defineCollection({name:'vizabi',components:[VizabiBubble]});
|