@gramlot/gramlot 0.3.41 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/icons/align-center.svg +4 -0
- package/assets/icons/align-justify.svg +4 -0
- package/assets/icons/align-left.svg +4 -0
- package/assets/icons/align-right.svg +4 -0
- package/assets/icons/applications.svg +4 -0
- package/assets/icons/archive.svg +4 -0
- package/assets/icons/attachment.svg +4 -0
- package/assets/icons/bold.svg +4 -0
- package/assets/icons/book.svg +4 -0
- package/assets/icons/bookmark.svg +4 -0
- package/assets/icons/calendar.svg +4 -0
- package/assets/icons/cancel.svg +4 -0
- package/assets/icons/chart.svg +4 -1
- package/assets/icons/chat.svg +4 -0
- package/assets/icons/clock.svg +4 -0
- package/assets/icons/code.svg +4 -0
- package/assets/icons/collapse.svg +4 -0
- package/assets/icons/columns.svg +4 -0
- package/assets/icons/confirm.svg +4 -0
- package/assets/icons/copy.svg +4 -0
- package/assets/icons/cut.svg +4 -0
- package/assets/icons/database.svg +4 -0
- package/assets/icons/delete.svg +4 -0
- package/assets/icons/detach.svg +4 -0
- package/assets/icons/document.svg +4 -0
- package/assets/icons/download.svg +4 -0
- package/assets/icons/duplicate.svg +4 -0
- package/assets/icons/edit.svg +4 -0
- package/assets/icons/eraser.svg +4 -0
- package/assets/icons/expand.svg +4 -0
- package/assets/icons/export.svg +4 -0
- package/assets/icons/eye.svg +4 -0
- package/assets/icons/filter.svg +4 -0
- package/assets/icons/first.svg +4 -0
- package/assets/icons/folder.svg +4 -0
- package/assets/icons/group.svg +4 -0
- package/assets/icons/help.svg +4 -0
- package/assets/icons/home.svg +4 -0
- package/assets/icons/horizontal-rule.svg +4 -0
- package/assets/icons/image.svg +4 -0
- package/assets/icons/import.svg +4 -0
- package/assets/icons/indent.svg +4 -0
- package/assets/icons/info.svg +4 -0
- package/assets/icons/inspector.svg +4 -0
- package/assets/icons/italic.svg +4 -0
- package/assets/icons/last.svg +4 -0
- package/assets/icons/layers.svg +4 -0
- package/assets/icons/link.svg +4 -0
- package/assets/icons/list-bulleted.svg +4 -0
- package/assets/icons/list-numbered.svg +4 -0
- package/assets/icons/list.svg +4 -0
- package/assets/icons/lock.svg +4 -0
- package/assets/icons/logout.svg +4 -0
- package/assets/icons/navigation.svg +4 -0
- package/assets/icons/new.svg +4 -0
- package/assets/icons/next.svg +4 -0
- package/assets/icons/open.svg +4 -0
- package/assets/icons/outdent.svg +4 -0
- package/assets/icons/palette.svg +4 -0
- package/assets/icons/panel-bottom.svg +4 -0
- package/assets/icons/panel-left.svg +4 -0
- package/assets/icons/panel-right.svg +4 -0
- package/assets/icons/panel-top.svg +4 -0
- package/assets/icons/paragraph.svg +4 -0
- package/assets/icons/paste.svg +4 -0
- package/assets/icons/pause.svg +4 -0
- package/assets/icons/pin.svg +4 -0
- package/assets/icons/play.svg +4 -0
- package/assets/icons/previous.svg +4 -0
- package/assets/icons/print.svg +4 -0
- package/assets/icons/redo.svg +4 -0
- package/assets/icons/refresh.svg +4 -0
- package/assets/icons/save.svg +4 -0
- package/assets/icons/search.svg +4 -0
- package/assets/icons/select-all.svg +4 -0
- package/assets/icons/send.svg +4 -0
- package/assets/icons/settings.svg +4 -0
- package/assets/icons/sort-ascending.svg +4 -0
- package/assets/icons/sort-descending.svg +4 -0
- package/assets/icons/stop.svg +4 -0
- package/assets/icons/strikethrough.svg +4 -0
- package/assets/icons/table.svg +4 -0
- package/assets/icons/tree.svg +4 -0
- package/assets/icons/underline.svg +4 -0
- package/assets/icons/undo.svg +4 -0
- package/assets/icons/unlock.svg +4 -0
- package/assets/icons/upload.svg +4 -0
- package/assets/icons/user.svg +4 -0
- package/assets/icons/warning.svg +4 -0
- package/assets/icons/zoom-in.svg +4 -0
- package/assets/icons/zoom-out.svg +4 -0
- package/dist/components/charts/__init__.py +1 -1
- package/dist/components/charts/assets/index.js +1 -1
- package/dist/components/charts/assets/libraries/vega.js +11 -11
- package/dist/components/charts/grammar.json +2032 -72
- package/dist/components/editors/__init__.py +1 -1
- package/dist/components/editors/assets/collection.js +1 -1
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/libraries/codemirror.js +30 -31
- package/dist/components/editors/assets/libraries/jodit.js +453 -447
- package/dist/components/editors/commands.json +113 -1
- package/dist/components/editors/grammar.json +12 -5
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/commands.json +4 -6
- package/dist/components/grid/grammar.json +112 -0
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +5165 -359
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +1 -0
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +433 -4
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +51 -0
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +6 -6
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/uploads/grammar.json +66 -0
- package/dist/declared-collections.js +1 -1
- package/dist/gramlot.js +5486 -2029
- package/dist/gramlot.min.js +361 -138
- package/dist/libraries.json +6 -4
- package/dist/standard-collections.js +1 -1
- package/dist/standard-grammar.js +1 -1
- package/package.json +6 -2
- package/src/binding/ask-dialog.js +17 -3
- package/src/binding/providers.js +3 -2
- package/src/binding/remote.js +41 -6
- package/src/binding/runtime.js +30 -3
- package/src/builder/gramlot-builder.d.ts +3 -1
- package/src/builder/gramlot-builder.js +77 -26
- package/src/builder/source.js +78 -15
- package/src/builder/xml-recipe.js +144 -0
- package/src/chat-file-types.js +13 -0
- package/src/chat.d.ts +1 -0
- package/src/chat.js +35 -25
- package/src/commands.d.ts +1 -1
- package/src/commands.js +1 -1
- package/src/components/border-container.js +64 -6
- package/src/components/buttons.js +26 -31
- package/src/components/chart-bar3d-options.js +0 -1
- package/src/components/chart-boxplot-options.js +1 -1
- package/src/components/chart-candlestick-options.js +1 -1
- package/src/components/chart-engines/echarts-options.js +6 -5
- package/src/components/chart-engines/echarts.js +27 -10
- package/src/components/chart-engines/plotly-map.js +1 -1
- package/src/components/chart-engines/plotly.js +21 -14
- package/src/components/chart-engines/uplot.js +17 -11
- package/src/components/chart-engines/vega.js +17 -11
- package/src/components/chart-funnel-options.js +1 -1
- package/src/components/chart-geographic-options.js +2 -2
- package/src/components/chart-heatmap-options.js +1 -1
- package/src/components/chart-map-bar3d-options.js +2 -2
- package/src/components/chart-map-options.js +2 -2
- package/src/components/chart-pane.js +5 -5
- package/src/components/chart-parallel-options.js +1 -1
- package/src/components/chart-radar-options.js +1 -1
- package/src/components/chart-renderer.js +6 -1
- package/src/components/chart-sankey-options.js +1 -1
- package/src/components/chart-spatial-options.js +6 -2
- package/src/components/chart-sunburst-options.js +13 -1
- package/src/components/chart-theme.js +14 -0
- package/src/components/chart-treemap-options.js +1 -1
- package/src/components/chart-type-data.js +24 -4
- package/src/components/charts.js +7 -6
- package/src/components/check-box-text-editor.js +1 -0
- package/src/components/check-box-text.js +2 -0
- package/src/components/check-box-tree.js +1 -1
- package/src/components/choice-editor.js +5 -4
- package/src/components/choice-field-styles.js +9 -1
- package/src/components/code-mirror-engine.js +19 -5
- package/src/components/code-mirror-gramlot.js +85 -0
- package/src/components/code-mirror.js +3 -2
- package/src/components/drawing.js +43 -14
- package/src/components/editor-commands.js +69 -0
- package/src/components/editor-options.js +1 -1
- package/src/components/editors.js +5 -3
- package/src/components/form-tray-pane.js +18 -0
- package/src/components/graphical-ranges.js +190 -0
- package/src/components/grid-check-sets.js +39 -3
- package/src/components/grid-footer.js +6 -1
- package/src/components/grid-header-interaction.js +3 -3
- package/src/components/grid-styles.js +30 -5
- package/src/components/grid-tools.js +15 -7
- package/src/components/grid.js +109 -15
- package/src/components/html-editor-commands.js +61 -0
- package/src/components/html-editor.js +18 -3
- package/src/components/inputs.js +94 -23
- package/src/components/jodit-engine.js +110 -7
- package/src/components/layout.js +3 -2
- package/src/components/menus.js +89 -26
- package/src/components/numeric-range.js +39 -0
- package/src/components/selected-container.js +123 -64
- package/src/components/tab-bar.js +389 -0
- package/src/components/toolbar-icon-style.js +22 -0
- package/src/components/toolbar-overflow.js +74 -12
- package/src/components/tray-base.js +528 -0
- package/src/components/tray-pane.js +41 -518
- package/src/components/tree.js +56 -4
- package/src/components/typed-editor.js +5 -2
- package/src/components/typst-preview.js +3 -3
- package/src/components/upload-blocks.js +88 -0
- package/src/components/upload-engine.js +21 -31
- package/src/components/uploader.js +168 -47
- package/src/editing-session.js +2 -1
- package/src/gramlot.js +6 -3
- package/src/handlers/dom-handler.d.ts +2 -0
- package/src/handlers/dom-handler.js +9 -0
- package/src/handlers/rpc-handler.d.ts +1 -1
- package/src/handlers/rpc-handler.js +2 -0
- package/src/handlers/source-handler.d.ts +5 -3
- package/src/handlers/source-handler.js +31 -13
- package/src/icons.js +84 -0
- package/src/ide-runtime.js +3 -1
- package/src/index-page-runtime.js +20 -5
- package/src/index-page-styles.js +1 -1
- package/src/index-theme.js +210 -3
- package/src/index.d.ts +7 -2
- package/src/index.js +7 -2
- package/src/libraries.js +4 -4
- package/src/object-extract.d.ts +7 -0
- package/src/object-extract.js +31 -0
- package/src/renderer/attributes.js +1 -1
- package/src/renderer/gramlot-renderer.d.ts +2 -2
- package/src/renderer/gramlot-renderer.js +4 -1
- package/src/server/chat-attachments.js +139 -0
- package/src/server/chat.d.ts +33 -0
- package/src/server/chat.js +168 -0
- package/src/server/database-selectors.d.ts +6 -0
- package/src/server/database-selectors.js +13 -0
- package/src/server/gramlot-file-server.js +6 -1
- package/src/server/gramlot-server.d.ts +19 -3
- package/src/server/gramlot-server.js +149 -19
- package/src/server/index-page.d.ts +10 -0
- package/src/server/index-page.js +92 -8
- package/src/server/index.d.ts +1 -1
- package/src/server/index.js +1 -1
- package/src/server/page-base.js +4 -0
- package/src/server/page-store.d.ts +21 -0
- package/src/server/page-store.js +219 -0
- package/src/server/page.d.ts +6 -1
- package/src/server/page.js +5 -1
- package/src/server/store-recipe.js +102 -0
- package/src/server/toolbar-icon-name.d.ts +93 -0
- package/src/server/upload.d.ts +2 -0
- package/src/server/upload.js +36 -18
- package/src/server/visual-editor.js +4 -2
- package/src/tree-store.d.ts +5 -1
- package/src/tree-store.js +11 -2
- package/src/view/choice-focus.js +17 -0
- package/src/view/html.js +21 -1
- package/src/view/labelbox.js +6 -1
- package/src/view/menu.js +9 -3
- package/src/visual-editor.d.ts +1 -0
- package/src/visual-editor.js +10 -5
- package/themes/gramlot-base/theme.css +60 -28
- package/themes/gramlot-compact/theme.css +2 -0
- package/themes/gramlot-index/icons/align-center.svg +4 -0
- package/themes/gramlot-index/icons/align-justify.svg +4 -0
- package/themes/gramlot-index/icons/align-left.svg +4 -0
- package/themes/gramlot-index/icons/align-right.svg +4 -0
- package/themes/gramlot-index/icons/applications.svg +4 -0
- package/themes/gramlot-index/icons/archive.svg +4 -0
- package/themes/gramlot-index/icons/attachment.svg +4 -0
- package/themes/gramlot-index/icons/bold.svg +4 -0
- package/themes/gramlot-index/icons/book.svg +4 -0
- package/themes/gramlot-index/icons/bookmark.svg +4 -0
- package/themes/gramlot-index/icons/calendar.svg +4 -0
- package/themes/gramlot-index/icons/cancel.svg +4 -0
- package/themes/gramlot-index/icons/chart.svg +4 -0
- package/themes/gramlot-index/icons/chat.svg +4 -0
- package/themes/gramlot-index/icons/clock.svg +4 -0
- package/themes/gramlot-index/icons/code.svg +4 -0
- package/themes/gramlot-index/icons/collapse.svg +4 -0
- package/themes/gramlot-index/icons/columns.svg +4 -0
- package/themes/gramlot-index/icons/confirm.svg +4 -0
- package/themes/gramlot-index/icons/copy.svg +4 -0
- package/themes/gramlot-index/icons/cut.svg +4 -0
- package/themes/gramlot-index/icons/database.svg +4 -0
- package/themes/gramlot-index/icons/delete.svg +4 -0
- package/themes/gramlot-index/icons/detach.svg +4 -0
- package/themes/gramlot-index/icons/document.svg +4 -0
- package/themes/gramlot-index/icons/download.svg +4 -0
- package/themes/gramlot-index/icons/duplicate.svg +4 -0
- package/themes/gramlot-index/icons/edit.svg +4 -0
- package/themes/gramlot-index/icons/eraser.svg +4 -0
- package/themes/gramlot-index/icons/expand.svg +4 -0
- package/themes/gramlot-index/icons/export.svg +4 -0
- package/themes/gramlot-index/icons/eye.svg +4 -0
- package/themes/gramlot-index/icons/filter.svg +4 -0
- package/themes/gramlot-index/icons/first.svg +4 -0
- package/themes/gramlot-index/icons/folder.svg +4 -0
- package/themes/gramlot-index/icons/group.svg +4 -0
- package/themes/gramlot-index/icons/help.svg +4 -0
- package/themes/gramlot-index/icons/home.svg +4 -0
- package/themes/gramlot-index/icons/horizontal-rule.svg +4 -0
- package/themes/gramlot-index/icons/image.svg +4 -0
- package/themes/gramlot-index/icons/import.svg +4 -0
- package/themes/gramlot-index/icons/indent.svg +4 -0
- package/themes/gramlot-index/icons/info.svg +4 -0
- package/themes/gramlot-index/icons/inspector.svg +4 -0
- package/themes/gramlot-index/icons/italic.svg +4 -0
- package/themes/gramlot-index/icons/last.svg +4 -0
- package/themes/gramlot-index/icons/layers.svg +4 -0
- package/themes/gramlot-index/icons/link.svg +4 -0
- package/themes/gramlot-index/icons/list-bulleted.svg +4 -0
- package/themes/gramlot-index/icons/list-numbered.svg +4 -0
- package/themes/gramlot-index/icons/list.svg +4 -0
- package/themes/gramlot-index/icons/lock.svg +4 -0
- package/themes/gramlot-index/icons/logout.svg +4 -0
- package/themes/gramlot-index/icons/navigation.svg +4 -0
- package/themes/gramlot-index/icons/new.svg +4 -0
- package/themes/gramlot-index/icons/next.svg +4 -0
- package/themes/gramlot-index/icons/open.svg +4 -0
- package/themes/gramlot-index/icons/outdent.svg +4 -0
- package/themes/gramlot-index/icons/palette.svg +4 -0
- package/themes/gramlot-index/icons/panel-bottom.svg +4 -0
- package/themes/gramlot-index/icons/panel-left.svg +4 -0
- package/themes/gramlot-index/icons/panel-right.svg +4 -0
- package/themes/gramlot-index/icons/panel-top.svg +4 -0
- package/themes/gramlot-index/icons/paragraph.svg +4 -0
- package/themes/gramlot-index/icons/paste.svg +4 -0
- package/themes/gramlot-index/icons/pause.svg +4 -0
- package/themes/gramlot-index/icons/pin.svg +4 -0
- package/themes/gramlot-index/icons/play.svg +4 -0
- package/themes/gramlot-index/icons/previous.svg +4 -0
- package/themes/gramlot-index/icons/print.svg +4 -0
- package/themes/gramlot-index/icons/redo.svg +4 -0
- package/themes/gramlot-index/icons/refresh.svg +4 -0
- package/themes/gramlot-index/icons/save.svg +4 -0
- package/themes/gramlot-index/icons/search.svg +4 -0
- package/themes/gramlot-index/icons/select-all.svg +4 -0
- package/themes/gramlot-index/icons/send.svg +4 -0
- package/themes/gramlot-index/icons/settings.svg +4 -0
- package/themes/gramlot-index/icons/sort-ascending.svg +4 -0
- package/themes/gramlot-index/icons/sort-descending.svg +4 -0
- package/themes/gramlot-index/icons/stop.svg +4 -0
- package/themes/gramlot-index/icons/strikethrough.svg +4 -0
- package/themes/gramlot-index/icons/table.svg +4 -0
- package/themes/gramlot-index/icons/tree.svg +4 -0
- package/themes/gramlot-index/icons/underline.svg +4 -0
- package/themes/gramlot-index/icons/undo.svg +4 -0
- package/themes/gramlot-index/icons/unlock.svg +4 -0
- package/themes/gramlot-index/icons/upload.svg +4 -0
- package/themes/gramlot-index/icons/user.svg +4 -0
- package/themes/gramlot-index/icons/warning.svg +4 -0
- package/themes/gramlot-index/icons/zoom-in.svg +4 -0
- package/themes/gramlot-index/icons/zoom-out.svg +4 -0
- package/themes/gramlot-index/icons.json +93 -0
- package/themes/gramlot-index/theme.css +24 -0
- package/themes/joanna/theme.css +2 -0
- package/themes/mela/theme.css +2 -0
- package/themes/mimi/theme.css +2 -0
- package/tools/gramlot-tools-inspector.js +11 -3
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import {positionPopup} from './popup.js';
|
|
2
|
+
|
|
3
|
+
const minimumTabWidth = 80;
|
|
4
|
+
// The transitions of a tab entry that change its size, as declared in tabBarStyles.
|
|
5
|
+
const resizeTransitions = ['flex-grow', 'min-width'];
|
|
6
|
+
|
|
7
|
+
/** A sideways drop along a strip stays within the tab order. */
|
|
8
|
+
export function outsideTabStrip(strip, vertical, event) {
|
|
9
|
+
const bounds = strip.getBoundingClientRect();
|
|
10
|
+
return vertical ? Math.max(bounds.left-event.clientX, event.clientX-bounds.right) > 24
|
|
11
|
+
: Math.max(bounds.top-event.clientY, event.clientY-bounds.bottom) > 24;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Presentation for the existing TabContainer buttons. Panels never move during a drag. */
|
|
15
|
+
export function createTabBar(document) {
|
|
16
|
+
const window = document.defaultView;
|
|
17
|
+
if (!window.customElements.get('gramlot-tab-bar')) {
|
|
18
|
+
window.customElements.define('gramlot-tab-bar', TabBar(window.HTMLElement));
|
|
19
|
+
}
|
|
20
|
+
return document.createElement('gramlot-tab-bar');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function TabBar(HTMLElement) {
|
|
24
|
+
return class extends HTMLElement {
|
|
25
|
+
#observer;
|
|
26
|
+
#frame = null;
|
|
27
|
+
#follow = null;
|
|
28
|
+
#slot;
|
|
29
|
+
#more;
|
|
30
|
+
#menu;
|
|
31
|
+
#selected;
|
|
32
|
+
#drag;
|
|
33
|
+
#suppressClick = false;
|
|
34
|
+
constructor() {
|
|
35
|
+
super();
|
|
36
|
+
const shadow = this.attachShadow({mode: 'open'});
|
|
37
|
+
const style = this.ownerDocument.createElement('style');
|
|
38
|
+
style.textContent = `
|
|
39
|
+
:host{display:var(--gramlot-tab-strip-display,grid);flex:none;min-width:0;min-height:0;
|
|
40
|
+
grid-template-rows:1fr;opacity:1;transition:grid-template-rows 200ms ease-out,opacity 200ms ease-out}
|
|
41
|
+
:host([inert]){grid-template-rows:0fr;opacity:0}
|
|
42
|
+
.clip{overflow:hidden;min-height:0;min-width:0}
|
|
43
|
+
.scroll{box-sizing:border-box;padding:4px 8px;overflow:auto;scrollbar-width:none;overscroll-behavior:contain}
|
|
44
|
+
:host([data-position=vertical]){grid-template-rows:1fr;grid-template-columns:1fr;
|
|
45
|
+
transition:grid-template-columns 200ms ease-out,opacity 200ms ease-out}
|
|
46
|
+
:host([data-position=vertical][inert]){grid-template-columns:0fr}
|
|
47
|
+
:host([data-position=vertical]) .scroll{height:100%}
|
|
48
|
+
:host([data-position=horizontal]) .scroll{display:flex;align-items:stretch;overflow:hidden}
|
|
49
|
+
:host([data-position=horizontal]) slot{display:block;min-width:0;flex:1;overflow:clip}
|
|
50
|
+
.more{flex:none;width:max(30px,var(--gramlot-touch-target,0px));min-height:max(24px,var(--gramlot-touch-target,0px));font:bold 17px system-ui;
|
|
51
|
+
color:inherit;background:transparent;border:0;border-radius:5px;cursor:pointer}
|
|
52
|
+
.more:hover,.more:focus-visible,[role=menuitem]:is(:hover,:focus-visible){background:var(--gramlot-selected,ButtonFace)}
|
|
53
|
+
[role=menu]{position:fixed;inset:auto;margin:0;padding:4px;box-sizing:border-box;
|
|
54
|
+
min-width:min(10rem,var(--gramlot-popup-available-width));max-width:var(--gramlot-popup-available-width);
|
|
55
|
+
max-height:var(--gramlot-popup-available-height);overflow:auto;border:1px solid var(--gramlot-border,#999);
|
|
56
|
+
border-radius:8px;background:var(--gramlot-surface,Canvas);color:var(--gramlot-ink,CanvasText);
|
|
57
|
+
box-shadow:0 3px 14px #0003}
|
|
58
|
+
[role=menuitem]{box-sizing:border-box;display:flex;align-items:center;gap:.75em;width:100%;padding:5px 8px;
|
|
59
|
+
min-height:var(--gramlot-touch-target,24px);border:0;border-radius:4px;background:transparent;color:inherit;
|
|
60
|
+
text-align:start;font:inherit;cursor:pointer}
|
|
61
|
+
.caption{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
62
|
+
.badge{border-radius:999px;padding:0 .4em;background:var(--gramlot-tab-badge-background,#3766b5);
|
|
63
|
+
color:var(--gramlot-tab-badge-color,white);font-size:.85em}
|
|
64
|
+
.drag-preview{position:fixed;inset:auto;left:0;top:0;margin:0;box-sizing:border-box;
|
|
65
|
+
padding:0 10px;pointer-events:none;user-select:none;border:1px solid var(--gramlot-border,#bbb);
|
|
66
|
+
border-radius:7px;background:var(--gramlot-surface,Canvas);color:var(--tabs-text,var(--gramlot-ink,CanvasText));
|
|
67
|
+
box-shadow:0 4px 12px #0003;font:12px system-ui;overflow:visible;will-change:transform}
|
|
68
|
+
.drag-preview:popover-open{display:flex;align-items:center;justify-content:center;gap:.4em}
|
|
69
|
+
.drag-preview .caption{flex:0 1 auto}
|
|
70
|
+
.drag-preview[data-detach]{outline:2px solid var(--gramlot-action,Highlight);box-shadow:0 7px 18px #0004}
|
|
71
|
+
.drag-preview[data-detach]::after{content:'↗';position:absolute;right:-6px;top:-7px;
|
|
72
|
+
border-radius:50%;padding:1px 4px;background:var(--gramlot-action,Highlight);color:var(--gramlot-surface,Canvas);font-weight:bold}
|
|
73
|
+
@media(prefers-reduced-motion:reduce){:host{transition:none!important}}`;
|
|
74
|
+
const clip = this.ownerDocument.createElement('div');
|
|
75
|
+
const scroll = this.ownerDocument.createElement('div');
|
|
76
|
+
clip.className = 'clip';
|
|
77
|
+
scroll.className = 'scroll';
|
|
78
|
+
this.#slot = this.ownerDocument.createElement('slot');
|
|
79
|
+
this.#more = this.ownerDocument.createElement('button');
|
|
80
|
+
this.#more.className = 'more';
|
|
81
|
+
this.#more.type = 'button';
|
|
82
|
+
this.#more.hidden = true;
|
|
83
|
+
this.#more.textContent = '»';
|
|
84
|
+
this.#more.title = 'More tabs';
|
|
85
|
+
this.#more.setAttribute('aria-label', 'More tabs');
|
|
86
|
+
this.#more.setAttribute('aria-haspopup', 'menu');
|
|
87
|
+
this.#more.setAttribute('aria-expanded', 'false');
|
|
88
|
+
this.#menu = this.ownerDocument.createElement('div');
|
|
89
|
+
this.#menu.id = 'more-tabs';
|
|
90
|
+
this.#menu.setAttribute('role','menu');
|
|
91
|
+
this.#menu.setAttribute('aria-label','More tabs');
|
|
92
|
+
this.#menu.setAttribute('popover','auto');
|
|
93
|
+
this.#more.popoverTargetElement = this.#menu;
|
|
94
|
+
this.#more.setAttribute('aria-controls', this.#menu.id);
|
|
95
|
+
this.#menu.addEventListener('beforetoggle', event => {
|
|
96
|
+
this.#more.setAttribute('aria-expanded', String(event.newState === 'open'));
|
|
97
|
+
if (event.newState === 'open') this.#refreshMenu();
|
|
98
|
+
});
|
|
99
|
+
this.#menu.addEventListener('toggle', () => {
|
|
100
|
+
if (!this.#menu.matches(':popover-open')) return;
|
|
101
|
+
positionPopup(this.#menu, this.#more, {align:'end'});
|
|
102
|
+
});
|
|
103
|
+
this.#more.addEventListener('keydown', event => {
|
|
104
|
+
if (event.key === 'ArrowDown') { event.preventDefault(); this.#more.click(); }
|
|
105
|
+
});
|
|
106
|
+
this.#menu.addEventListener('keydown', event => {
|
|
107
|
+
const items = [...this.#menu.querySelectorAll('button:not(:disabled)')];
|
|
108
|
+
const index = items.indexOf(event.target);
|
|
109
|
+
if (!items.length || !['Home','End','ArrowDown','ArrowUp'].includes(event.key)) return;
|
|
110
|
+
event.preventDefault();
|
|
111
|
+
const next = event.key === 'Home' ? 0 : event.key === 'End' ? items.length-1
|
|
112
|
+
: (index + (event.key === 'ArrowDown' ? 1 : -1) + items.length) % items.length;
|
|
113
|
+
items[next].focus();
|
|
114
|
+
});
|
|
115
|
+
scroll.append(this.#slot, this.#more);
|
|
116
|
+
clip.append(scroll);
|
|
117
|
+
shadow.append(style, clip, this.#menu);
|
|
118
|
+
const view = this.ownerDocument.defaultView;
|
|
119
|
+
this.#observer = new view.ResizeObserver(() => {
|
|
120
|
+
if (this.#frame !== null) return;
|
|
121
|
+
this.#frame = view.requestAnimationFrame(() => {
|
|
122
|
+
this.#frame = null;
|
|
123
|
+
this.#layout();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
this.addEventListener('pointerdown', event => {
|
|
127
|
+
const button = event.target.closest('[role=tab]');
|
|
128
|
+
if (this.#drag || !button || button.disabled || event.button !== 0 || !event.isPrimary) return;
|
|
129
|
+
this.#suppressClick = false;
|
|
130
|
+
this.#drag = {entry:button.parentElement, strip:button.parentElement.parentElement, id:event.pointerId, x:event.clientX, y:event.clientY};
|
|
131
|
+
button.setPointerCapture(event.pointerId);
|
|
132
|
+
});
|
|
133
|
+
this.addEventListener('pointermove', event => {
|
|
134
|
+
const drag = this.#drag;
|
|
135
|
+
if (drag?.id !== event.pointerId) return;
|
|
136
|
+
if (!drag.preview) {
|
|
137
|
+
if (Math.hypot(event.clientX - drag.x, event.clientY - drag.y) < 4) return;
|
|
138
|
+
this.#suppressClick = true;
|
|
139
|
+
this.#lift(drag);
|
|
140
|
+
}
|
|
141
|
+
const drop = this.#dropPosition(event);
|
|
142
|
+
drag.preview.style.transform = 'translate(' + (event.clientX - drag.gripX) + 'px,' + (event.clientY - drag.gripY) + 'px)';
|
|
143
|
+
drag.preview.toggleAttribute('data-detach', drop.outside && drag.entry.hasAttribute('data-detachable'));
|
|
144
|
+
this.#showGap(drop);
|
|
145
|
+
});
|
|
146
|
+
this.addEventListener('pointerup', event => {
|
|
147
|
+
const drag = this.#drag;
|
|
148
|
+
if (drag?.id !== event.pointerId) return;
|
|
149
|
+
const drop = drag.preview && this.#dropPosition(event);
|
|
150
|
+
this.#endDrag();
|
|
151
|
+
if (!drop) return;
|
|
152
|
+
if (drop.outside) {
|
|
153
|
+
this.detachTab(drag.entry, {left:event.clientX-12, top:event.clientY-12});
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const strip = drag.entry.parentElement;
|
|
157
|
+
const focused = strip.getRootNode().activeElement;
|
|
158
|
+
strip.insertBefore(drag.entry, drop.before);
|
|
159
|
+
if (drag.entry.contains(focused)) focused.focus({preventScroll:true});
|
|
160
|
+
this.#layout();
|
|
161
|
+
});
|
|
162
|
+
for (const type of ['pointercancel','lostpointercapture']) {
|
|
163
|
+
this.addEventListener(type, event => {
|
|
164
|
+
if (this.#drag?.id === event.pointerId) this.#endDrag();
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
this.addEventListener('keydown', event => {
|
|
168
|
+
if (event.key === 'Escape' && this.#drag) {
|
|
169
|
+
event.preventDefault();
|
|
170
|
+
this.#endDrag();
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
this.addEventListener('click', event => {
|
|
174
|
+
if (event.detail && this.#suppressClick) {
|
|
175
|
+
event.stopPropagation();
|
|
176
|
+
this.#suppressClick = false;
|
|
177
|
+
}
|
|
178
|
+
}, true);
|
|
179
|
+
this.addEventListener('auxclick', event => {
|
|
180
|
+
const button = event.target.closest('[role=tab]');
|
|
181
|
+
if (event.button !== 1 || !button || button.disabled) return;
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
const close = button.parentElement.querySelector('.close');
|
|
184
|
+
if (!close.hidden) close.click();
|
|
185
|
+
});
|
|
186
|
+
this.addEventListener('transitionend', () => this.#position());
|
|
187
|
+
}
|
|
188
|
+
#lift(drag) {
|
|
189
|
+
const rect = drag.entry.getBoundingClientRect();
|
|
190
|
+
drag.gripX = drag.x - rect.left;
|
|
191
|
+
drag.gripY = drag.y - rect.top;
|
|
192
|
+
const preview = this.ownerDocument.createElement('div');
|
|
193
|
+
preview.className = 'drag-preview';
|
|
194
|
+
preview.setAttribute('popover','manual');
|
|
195
|
+
preview.setAttribute('aria-hidden','true');
|
|
196
|
+
preview.inert = true;
|
|
197
|
+
preview.style.width = rect.width + 'px';
|
|
198
|
+
preview.style.height = rect.height + 'px';
|
|
199
|
+
for (const part of drag.entry.querySelector('[role=tab]').children) {
|
|
200
|
+
if (!part.hidden && part.textContent) preview.append(part.cloneNode(true));
|
|
201
|
+
}
|
|
202
|
+
this.shadowRoot.append(preview);
|
|
203
|
+
preview.showPopover();
|
|
204
|
+
drag.preview = preview;
|
|
205
|
+
drag.entry.setAttribute('data-dragging','');
|
|
206
|
+
}
|
|
207
|
+
#dropPosition(event) {
|
|
208
|
+
const entry = this.#drag.entry, strip = entry.parentElement;
|
|
209
|
+
const vertical = this.dataset.position === 'vertical';
|
|
210
|
+
const outside = outsideTabStrip(this, vertical, event);
|
|
211
|
+
const rect = strip.getBoundingClientRect();
|
|
212
|
+
const point = vertical ? event.clientY - rect.top : event.clientX - rect.left;
|
|
213
|
+
// A tab moves only among the tabs of its own tab_align group: CSS order keeps the groups apart.
|
|
214
|
+
const tabs = [...strip.children].filter(tab => !tab.hidden && !tab.inert && !tab.hasAttribute('data-overflow')
|
|
215
|
+
&& tab.dataset.tabAlign === entry.dataset.tabAlign);
|
|
216
|
+
// Offsets describe the committed slots even while their contents slide into the proposed order.
|
|
217
|
+
const before = tabs.find(tab => tab !== entry && point < (vertical
|
|
218
|
+
? tab.offsetTop + tab.offsetHeight / 2 : tab.offsetLeft + tab.offsetWidth / 2));
|
|
219
|
+
return {outside, vertical, tabs, before:before ?? tabs.at(-1)?.nextElementSibling ?? null};
|
|
220
|
+
}
|
|
221
|
+
#showGap({outside, vertical, tabs, before}) {
|
|
222
|
+
const {entry} = this.#drag;
|
|
223
|
+
const strip = entry.parentElement;
|
|
224
|
+
const from = tabs.indexOf(entry);
|
|
225
|
+
const others = tabs.filter(tab => tab !== entry);
|
|
226
|
+
const beforeIndex = others.indexOf(before);
|
|
227
|
+
const to = outside ? from : beforeIndex < 0 ? others.length : beforeIndex;
|
|
228
|
+
const size = vertical ? entry.offsetHeight : entry.offsetWidth;
|
|
229
|
+
tabs.forEach((tab, index) => {
|
|
230
|
+
let shift = 0;
|
|
231
|
+
if (index > from && index <= to) shift = -size;
|
|
232
|
+
if (index < from && index >= to) shift = size;
|
|
233
|
+
tab.style.translate = shift ? (vertical ? '0 ' + shift + 'px' : shift + 'px 0') : '';
|
|
234
|
+
if (tab === this.#selected) strip.style.setProperty('--capsule-shift', tab.style.translate || 'none');
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
#endDrag() {
|
|
238
|
+
const drag = this.#drag;
|
|
239
|
+
this.#drag = null;
|
|
240
|
+
if (!drag) return;
|
|
241
|
+
if (drag.preview) {
|
|
242
|
+
drag.preview.remove();
|
|
243
|
+
drag.entry.removeAttribute('data-dragging');
|
|
244
|
+
for (const tab of drag.strip.children) tab.style.removeProperty('translate');
|
|
245
|
+
drag.strip.style.removeProperty('--capsule-shift');
|
|
246
|
+
}
|
|
247
|
+
const button = drag.entry.querySelector('[role=tab]');
|
|
248
|
+
if (button.hasPointerCapture(drag.id)) button.releasePointerCapture(drag.id);
|
|
249
|
+
}
|
|
250
|
+
connectedCallback() {
|
|
251
|
+
this.#observer.observe(this);
|
|
252
|
+
if (this.#selected) this.#observer.observe(this.#selected);
|
|
253
|
+
}
|
|
254
|
+
disconnectedCallback() {
|
|
255
|
+
this.#observer.disconnect();
|
|
256
|
+
if (this.#frame !== null) this.ownerDocument.defaultView.cancelAnimationFrame(this.#frame);
|
|
257
|
+
if (this.#follow !== null) this.ownerDocument.defaultView.cancelAnimationFrame(this.#follow);
|
|
258
|
+
this.#frame = null;
|
|
259
|
+
this.#follow = null;
|
|
260
|
+
this.#endDrag();
|
|
261
|
+
}
|
|
262
|
+
update(count, selected) {
|
|
263
|
+
const collapsed = count === 0 || (count === 1 && !this.querySelector('.tab-entry[data-detachable]:not([hidden])'));
|
|
264
|
+
const reveal = this.hasAttribute('inert') && !collapsed;
|
|
265
|
+
this.toggleAttribute('inert', collapsed);
|
|
266
|
+
this.setAttribute('aria-hidden', String(collapsed));
|
|
267
|
+
const changed = selected !== this.#selected;
|
|
268
|
+
if (changed) {
|
|
269
|
+
if (this.#selected) this.#observer.unobserve(this.#selected);
|
|
270
|
+
this.#selected = selected;
|
|
271
|
+
if (selected) this.#observer.observe(selected);
|
|
272
|
+
}
|
|
273
|
+
this.#layout();
|
|
274
|
+
if (this.dataset.position === 'vertical' && selected && !collapsed && (changed || reveal)) {
|
|
275
|
+
const scroller = this.shadowRoot.querySelector('.scroll');
|
|
276
|
+
const target = selected.getBoundingClientRect(), bounds = scroller.getBoundingClientRect();
|
|
277
|
+
if (target.left < bounds.left) scroller.scrollLeft += target.left - bounds.left;
|
|
278
|
+
if (target.right > bounds.right) scroller.scrollLeft += target.right - bounds.right;
|
|
279
|
+
if (target.top < bounds.top) scroller.scrollTop += target.top - bounds.top;
|
|
280
|
+
if (target.bottom > bounds.bottom) scroller.scrollTop += target.bottom - bounds.bottom;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
#refreshMenu() {
|
|
284
|
+
const focused = this.shadowRoot.activeElement?.dataset.tab;
|
|
285
|
+
const items = [...this.querySelectorAll('.tab-entry[data-overflow]:not([hidden]) [role=tab]')].map(tab => {
|
|
286
|
+
const item = this.ownerDocument.createElement('button');
|
|
287
|
+
item.type = 'button';
|
|
288
|
+
item.setAttribute('role','menuitem');
|
|
289
|
+
item.tabIndex = -1;
|
|
290
|
+
item.dataset.tab = tab.id;
|
|
291
|
+
item.disabled = tab.disabled;
|
|
292
|
+
item.append(tab.querySelector('.caption').cloneNode(true));
|
|
293
|
+
const badge = tab.querySelector('.badge');
|
|
294
|
+
if (!badge.hidden) item.append(badge.cloneNode(true));
|
|
295
|
+
item.addEventListener('click', () => {
|
|
296
|
+
this.#menu.hidePopover();
|
|
297
|
+
tab.click();
|
|
298
|
+
if (tab.offsetWidth) tab.focus();
|
|
299
|
+
else this.#more.focus();
|
|
300
|
+
});
|
|
301
|
+
return item;
|
|
302
|
+
});
|
|
303
|
+
const first = items.find(item => !item.disabled);
|
|
304
|
+
if (first) first.autofocus = true;
|
|
305
|
+
this.#menu.replaceChildren(...items);
|
|
306
|
+
if (focused) (items.find(item => item.dataset.tab === focused) ?? items.find(item => !item.disabled))?.focus();
|
|
307
|
+
}
|
|
308
|
+
#layout() {
|
|
309
|
+
const tabs = [...this.querySelectorAll('.tab-entry:not([hidden]):not(.closing)')];
|
|
310
|
+
const horizontal = this.dataset.position === 'horizontal';
|
|
311
|
+
const width = this.#slot.clientWidth + this.#more.offsetWidth;
|
|
312
|
+
const overflow = horizontal && width > 0 && tabs.length > 1 && tabs.length * minimumTabWidth > width;
|
|
313
|
+
this.#more.hidden = !overflow;
|
|
314
|
+
const capacity = overflow ? Math.max(0, Math.floor((width-this.#more.offsetWidth)/minimumTabWidth)) : tabs.length;
|
|
315
|
+
const visible = tabs.slice(0,capacity);
|
|
316
|
+
if (capacity && this.#selected && !visible.includes(this.#selected)) visible[capacity-1] = this.#selected;
|
|
317
|
+
for (const tab of tabs) tab.toggleAttribute('data-overflow', !visible.includes(tab));
|
|
318
|
+
if (this.#more.getAttribute('aria-expanded') === 'true') {
|
|
319
|
+
if (overflow) {
|
|
320
|
+
this.#refreshMenu();
|
|
321
|
+
positionPopup(this.#menu, this.#more, {align:'end'});
|
|
322
|
+
} else this.#menu.hidePopover();
|
|
323
|
+
}
|
|
324
|
+
if (this.#drag && (!visible.includes(this.#drag.entry) || this.inert || this.#drag.entry.querySelector('[role=tab]').disabled)) this.#endDrag();
|
|
325
|
+
this.#position();
|
|
326
|
+
}
|
|
327
|
+
#position() {
|
|
328
|
+
const tab = this.#selected;
|
|
329
|
+
if (!tab) return;
|
|
330
|
+
const strip = tab.parentElement, style = strip.style;
|
|
331
|
+
style.setProperty('--capsule-x', tab.offsetLeft + 'px');
|
|
332
|
+
style.setProperty('--capsule-y', tab.offsetTop + 'px');
|
|
333
|
+
style.setProperty('--capsule-width', tab.offsetWidth + 'px');
|
|
334
|
+
style.setProperty('--capsule-height', tab.offsetHeight + 'px');
|
|
335
|
+
// While tabs grow or close, the capsule follows the selected tab on each frame without its own transition.
|
|
336
|
+
const resizing = [...strip.children].some(entry => entry.getAnimations().some(animation =>
|
|
337
|
+
resizeTransitions.includes(animation.transitionProperty) || animation.animationName === 'tab-bar-close'));
|
|
338
|
+
strip.toggleAttribute('data-following', resizing);
|
|
339
|
+
if (resizing && this.#follow === null) {
|
|
340
|
+
this.#follow = this.ownerDocument.defaultView.requestAnimationFrame(() => {
|
|
341
|
+
this.#follow = null;
|
|
342
|
+
this.#position();
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** Entries stay in the container's shadow tree alongside the panels they label. */
|
|
350
|
+
export const tabBarStyles = `
|
|
351
|
+
gramlot-tab-bar .tabs.tabs{position:relative;box-sizing:border-box;display:flex;align-items:stretch;
|
|
352
|
+
min-width:min-content;width:100%;padding:0;border:0;gap:0;overflow:visible;border-radius:8px;
|
|
353
|
+
background:var(--tabs-track,light-dark(rgb(0 0 0 / .06),rgb(255 255 255 / .08)))}
|
|
354
|
+
gramlot-tab-bar .tabs:has([aria-selected=true])::before{content:"";position:absolute;top:0;left:0;
|
|
355
|
+
pointer-events:none;border-radius:6px;width:var(--capsule-width);height:var(--capsule-height);
|
|
356
|
+
transform:translate(var(--capsule-x),var(--capsule-y));translate:var(--capsule-shift,none);transition:transform 180ms ease-out,translate 120ms ease-out;
|
|
357
|
+
background:var(--tabs-active,light-dark(white,rgb(255 255 255 / .18)));
|
|
358
|
+
box-shadow:0 0 0 .5px rgb(0 0 0 / .12),0 1px 2px rgb(0 0 0 / .12)}
|
|
359
|
+
gramlot-tab-bar .tabs[data-following]::before{transition:none}
|
|
360
|
+
gramlot-tab-bar .tabs .tab-entry{box-sizing:border-box;min-width:${minimumTabWidth}px;flex:1 1 0;overflow:hidden;
|
|
361
|
+
height:max(24px,var(--gramlot-touch-target,0px));border:0;border-radius:6px;
|
|
362
|
+
background:transparent;color:var(--tabs-text,var(--gramlot-ink,CanvasText));
|
|
363
|
+
transition:flex-grow 200ms ease-out,min-width 200ms ease-out}
|
|
364
|
+
gramlot-tab-bar .tabs:has([data-dragging]) .tab-entry{transition:translate 120ms ease-out}
|
|
365
|
+
gramlot-tab-bar .tab-entry[data-dragging]{opacity:.25}
|
|
366
|
+
gramlot-tab-bar .tabs:has([data-dragging] [aria-selected=true])::before{opacity:.25}
|
|
367
|
+
gramlot-tab-bar[data-position=horizontal] .tab-entry{max-width:200px;contain:inline-size}
|
|
368
|
+
gramlot-tab-bar .tab-entry[data-overflow]{display:none}
|
|
369
|
+
@starting-style{gramlot-tab-bar .tabs .tab-entry{flex-grow:0;min-width:0}}
|
|
370
|
+
gramlot-tab-bar .tabs .tab-entry button{padding:0 20px;min-height:0;font:12px system-ui}
|
|
371
|
+
gramlot-tab-bar .tabs .tab-entry [role=tab]{width:100%;color:inherit;justify-content:center;
|
|
372
|
+
touch-action:none;user-select:none;cursor:grab;opacity:.55}
|
|
373
|
+
gramlot-tab-bar .tabs .tab-entry[data-dragging] [role=tab]{cursor:grabbing}
|
|
374
|
+
gramlot-tab-bar .tabs .tab-entry [aria-selected=true]{opacity:1}
|
|
375
|
+
gramlot-tab-bar .tabs .tab-entry .close{position:absolute;inset-inline-start:0;top:0;height:100%;
|
|
376
|
+
margin:0;padding:0;width:20px;min-width:0;font:14px system-ui;opacity:0}
|
|
377
|
+
gramlot-tab-bar .tabs .tab-entry:is(:hover,:focus-within) .close{opacity:1}
|
|
378
|
+
@media(hover:hover){gramlot-tab-bar .tabs .tab-entry button:hover{background:transparent}
|
|
379
|
+
gramlot-tab-bar .tabs .tab-entry:hover:not(:has([aria-selected=true])){background:rgb(0 0 0 / .05)}}
|
|
380
|
+
@media(pointer:coarse){gramlot-tab-bar .tabs .tab-entry{height:max(44px,var(--gramlot-touch-target,0px))}
|
|
381
|
+
gramlot-tab-bar .tabs .tab-entry .close{opacity:1;width:36px}
|
|
382
|
+
gramlot-tab-bar .tabs .tab-entry [role=tab]{padding-inline:36px}}
|
|
383
|
+
gramlot-tab-bar[data-position=vertical] .tabs.tabs{height:100%;max-width:none;width:100%}
|
|
384
|
+
gramlot-tab-bar[data-position=vertical] .tabs .tab-entry{min-height:24px}
|
|
385
|
+
gramlot-tab-bar .tabs .closing{animation:tab-bar-close 200ms ease-out forwards;pointer-events:none}
|
|
386
|
+
@keyframes tab-bar-close{to{min-width:0;min-height:0;flex-grow:0}}
|
|
387
|
+
@media(prefers-reduced-motion:reduce){gramlot-tab-bar .tabs .closing{animation:none;display:none}
|
|
388
|
+
gramlot-tab-bar .tabs::before,gramlot-tab-bar .tabs .tab-entry{transition:none!important}}
|
|
389
|
+
`;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The toolbar, frame and individual occurrence share the same inherited icon paint. */
|
|
2
|
+
export const toolbarIconParameters = {
|
|
3
|
+
icon_color: {dtype:'T', nullable:true, binding:'read'},
|
|
4
|
+
icon_opacity: {dtype:'R', nullable:true, binding:'read'},
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export function projectToolbarIconStyle(element, rest) {
|
|
8
|
+
const {icon_color, icon_opacity} = element.parameters;
|
|
9
|
+
if (icon_color == null && icon_opacity == null) return rest;
|
|
10
|
+
const style = element.ownerDocument.createElement('span').style;
|
|
11
|
+
style.cssText = rest.style ?? '';
|
|
12
|
+
if (icon_color) {
|
|
13
|
+
style.setProperty('--gramlot-toolbar-icon-color', icon_color);
|
|
14
|
+
style.setProperty('--gramlot-toolbar-original-icon', 'hidden');
|
|
15
|
+
}
|
|
16
|
+
if (icon_opacity != null) {
|
|
17
|
+
if (!Number.isFinite(icon_opacity) || icon_opacity < 0 || icon_opacity > 1)
|
|
18
|
+
throw new RangeError('icon_opacity must be between 0 and 1');
|
|
19
|
+
style.setProperty('--gramlot-toolbar-icon-opacity', String(icon_opacity));
|
|
20
|
+
}
|
|
21
|
+
return {...rest, style:style.cssText};
|
|
22
|
+
}
|
|
@@ -40,11 +40,12 @@ export class ToolbarOverflow {
|
|
|
40
40
|
:host([role=toolbar]){min-width:0;min-height:0;max-width:100%;width:100%;flex-shrink:1;gap:0}
|
|
41
41
|
:host([role=toolbar][aria-orientation=vertical]){width:auto;height:100%;max-height:100%}
|
|
42
42
|
.toolbar-viewport{display:contents}
|
|
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
|
|
44
|
-
:host([role=toolbar][aria-orientation=vertical]) .toolbar-viewport{flex-direction:column;align-items:stretch;overflow
|
|
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:clip}
|
|
44
|
+
:host([role=toolbar][aria-orientation=vertical]) .toolbar-viewport{flex-direction:column;align-items:stretch;overflow:clip;width:100%}
|
|
45
45
|
:host([role=toolbar]) ::slotted(*){flex-shrink:0}
|
|
46
46
|
:host([role=toolbar]) .toolbar-viewport[data-measuring]{flex:none;width:max-content;height:max-content;overflow:visible}
|
|
47
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}
|
|
48
|
+
:host([aria-orientation=horizontal]) .toolbar-more{height:max(calc(var(--gramlot-toolbar-icon-size) + 8px),var(--gramlot-touch-target,0px))}
|
|
48
49
|
.toolbar-more svg{display:block;width:18px;height:18px;pointer-events:none}
|
|
49
50
|
.toolbar-more:hover,.toolbar-more:focus-visible{background:var(--gramlot-selected,Highlight)}
|
|
50
51
|
:host([role=toolbar][aria-orientation=vertical]) .toolbar-more{width:100%}
|
|
@@ -76,8 +77,13 @@ export class ToolbarOverflow {
|
|
|
76
77
|
disconnect(){
|
|
77
78
|
this.close(false); this.#resize?.disconnect();this.#resize=null;this.#events?.abort();
|
|
78
79
|
if(this.#frame!==null)this.#menu.ownerDocument.defaultView.cancelAnimationFrame(this.#frame);
|
|
80
|
+
for (const unit of this.#units) this.#resetInline(unit);
|
|
79
81
|
this.#frame=null;this.#units=[];
|
|
80
82
|
}
|
|
83
|
+
#resetInline(unit) {
|
|
84
|
+
const line = labelboxContent(unit);
|
|
85
|
+
if (line.hasAttribute('data-menu-expanded')) line.showInBar(false);
|
|
86
|
+
}
|
|
81
87
|
schedule(){
|
|
82
88
|
if(!this.#menu.isConnected)return;
|
|
83
89
|
if(!this.#menu.permanent){
|
|
@@ -93,14 +99,22 @@ export class ToolbarOverflow {
|
|
|
93
99
|
const menu=this.#menu,win=menu.ownerDocument.defaultView;
|
|
94
100
|
if(!menu.permanent || !menu.isConnected)return;
|
|
95
101
|
const vertical=menu.parameters.orientation==='vertical',axis=vertical?'height':'width';
|
|
102
|
+
this.#button.style.setProperty('--gramlot-toolbar-icon-size', menu.parameters.icon_size + 'px');
|
|
96
103
|
const style=win.getComputedStyle(menu);
|
|
97
|
-
|
|
104
|
+
// clientWidth rounds fractional CSS pixels. Use the content box to avoid
|
|
105
|
+
// fitting an extra command at fractional zoom or with a toolbar border.
|
|
106
|
+
const edges = vertical ? ['Top','Bottom'] : ['Left','Right'];
|
|
107
|
+
const outer = menu.getBoundingClientRect()[axis];
|
|
108
|
+
const available = outer > 0
|
|
109
|
+
? outer - edges.reduce((sum, edge) => sum + parseFloat(style['padding' + edge] || 0)
|
|
110
|
+
+ parseFloat(style['border' + edge + 'Width'] || 0), 0)
|
|
111
|
+
: (vertical ? menu.clientHeight : menu.clientWidth) - edges.reduce((sum, edge) => sum + parseFloat(style['padding' + edge] || 0), 0);
|
|
98
112
|
if(available<=0)return;
|
|
99
113
|
let active=menu.ownerDocument.activeElement;
|
|
100
114
|
while(active?.shadowRoot?.activeElement)active=active.shadowRoot.activeElement;
|
|
101
115
|
const units=[...menu.children].filter(unit=>!unit.hidden && (labelboxContent(unit).localName!=='gramlot-menu' || labelboxContent(unit).permanent));
|
|
102
116
|
for(const unit of this.#units)if(!units.includes(unit)){
|
|
103
|
-
this.#resize.unobserve(unit);unit.removeAttribute('slot');unit.removeAttribute('data-menu-overflow');
|
|
117
|
+
this.#resetInline(unit);this.#resize.unobserve(unit);unit.removeAttribute('slot');unit.removeAttribute('data-menu-overflow');
|
|
104
118
|
}
|
|
105
119
|
for(const unit of units)if(!this.#units.includes(unit))this.#resize.observe(unit);
|
|
106
120
|
this.#units=units;
|
|
@@ -108,18 +122,28 @@ export class ToolbarOverflow {
|
|
|
108
122
|
// slots synchronously before paint. No clones or Source changes are made.
|
|
109
123
|
for(const unit of units){unit.removeAttribute('slot');unit.removeAttribute('data-menu-overflow');}
|
|
110
124
|
this.#overflow.clear();
|
|
111
|
-
|
|
112
|
-
for(const
|
|
125
|
+
const candidates = [];
|
|
126
|
+
for (const unit of units) {
|
|
127
|
+
const line = labelboxContent(unit);
|
|
128
|
+
this.#resetInline(unit);
|
|
129
|
+
if (line.parameters?.expandInBar != null && line.submenu && !line.submenu.permanent &&
|
|
130
|
+
!line.submenu.hidden && line.submenu.visibleItems.length && !['error','loading'].includes(line.submenu.status)) {
|
|
131
|
+
candidates.push(unit);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (const line of menu.querySelectorAll('gramlot-menu-line')) {
|
|
135
|
+
if (line.menuOwner === menu) line.refreshAvailability();
|
|
136
|
+
}
|
|
113
137
|
// Auto margins distribute spare space; they are not intrinsic content.
|
|
114
138
|
// Measure synchronously without flex allocation, then restore before paint.
|
|
115
139
|
this.#viewport.setAttribute('data-measuring','');
|
|
116
140
|
const gap=parseFloat(win.getComputedStyle(this.#viewport).gap)||0;
|
|
117
|
-
const
|
|
141
|
+
const measure = unit => {
|
|
118
142
|
const css=win.getComputedStyle(unit);
|
|
119
143
|
const length=labelboxContent(unit).localName==='gramlot-spacer'?(labelboxContent(unit).parameters.size??0):unit.getBoundingClientRect()[axis];
|
|
120
|
-
return
|
|
121
|
-
}
|
|
122
|
-
|
|
144
|
+
return length+(parseFloat(css[vertical?'marginTop':'marginLeft'])||0)+(parseFloat(css[vertical?'marginBottom':'marginRight'])||0);
|
|
145
|
+
};
|
|
146
|
+
const lengths = new Map(units.map(unit => [unit, measure(unit)]));
|
|
123
147
|
const separator=unit=>labelboxContent(unit).getAttribute('role')==='separator';
|
|
124
148
|
const tidy=list=>list.filter((unit,index)=>!separator(unit) ||
|
|
125
149
|
list.slice(0,index).some(item=>labelboxContent(item).localName!=='gramlot-spacer'&&!separator(item)) &&
|
|
@@ -127,9 +151,36 @@ export class ToolbarOverflow {
|
|
|
127
151
|
!separator(list.slice(index+1).find(item=>labelboxContent(item).localName!=='gramlot-spacer')));
|
|
128
152
|
const required=remaining=>remaining.reduce((sum,unit)=>sum+lengths.get(unit),0)+Math.max(0,remaining.length-1)*gap;
|
|
129
153
|
let remaining=tidy(units);
|
|
154
|
+
// Measure both presentations at their intrinsic sizes with the original controls.
|
|
155
|
+
const compact = new Map();
|
|
156
|
+
for (const unit of candidates) {
|
|
157
|
+
const line = labelboxContent(unit);
|
|
158
|
+
compact.set(unit, lengths.get(unit));
|
|
159
|
+
line.showInBar(true, menu.parameters.orientation);
|
|
160
|
+
lengths.set(unit, Math.max(measure(unit), line.submenu.getBoundingClientRect()[axis]));
|
|
161
|
+
}
|
|
162
|
+
// Stable sort after reversal makes the later submenu close first on a tie.
|
|
163
|
+
candidates.reverse().sort((a,b) => labelboxContent(a).parameters.expandInBar - labelboxContent(b).parameters.expandInBar);
|
|
164
|
+
for (const unit of candidates) {
|
|
165
|
+
if (required(remaining) <= available) break;
|
|
166
|
+
labelboxContent(unit).showInBar(false);
|
|
167
|
+
lengths.set(unit, compact.get(unit));
|
|
168
|
+
}
|
|
169
|
+
this.#viewport.removeAttribute('data-measuring');
|
|
170
|
+
for (const unit of candidates) {
|
|
171
|
+
const line = labelboxContent(unit);
|
|
172
|
+
if (line.hasAttribute('data-menu-expanded')) {
|
|
173
|
+
if (line.submenu.opened) line.submenu.close(false);
|
|
174
|
+
} else {
|
|
175
|
+
line.submenu.refreshItems();
|
|
176
|
+
if (!line.submenu.opened) line.submenu.close(false);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
130
179
|
if(required(remaining)>available){
|
|
180
|
+
this.#button.hidden = false;
|
|
181
|
+
const capacity = available - this.#button.getBoundingClientRect()[axis];
|
|
131
182
|
let cut=units.length;
|
|
132
|
-
while(cut>0 && required(remaining)>
|
|
183
|
+
while(cut>0 && required(remaining)>capacity) {
|
|
133
184
|
cut--;
|
|
134
185
|
remaining=tidy(units.slice(0,cut));
|
|
135
186
|
}
|
|
@@ -149,7 +200,18 @@ export class ToolbarOverflow {
|
|
|
149
200
|
if(this.#overflow.size===0)this.close(false);
|
|
150
201
|
else if(activeUnit && this.#overflow.has(activeUnit))this.open(false);
|
|
151
202
|
else if(this.#opened)this.#place();
|
|
152
|
-
if(activeUnit && active?.isConnected)
|
|
203
|
+
if (activeUnit && active?.isConnected) {
|
|
204
|
+
const line = labelboxContent(activeUnit);
|
|
205
|
+
let target = active;
|
|
206
|
+
if (line.submenu && line.parameters.expandInBar != null) {
|
|
207
|
+
if (line.hasAttribute('data-menu-expanded') && active === line.control) {
|
|
208
|
+
target = menu.usableItems.find(item => line.contains(item))?.control ?? menu;
|
|
209
|
+
} else if (!line.hasAttribute('data-menu-expanded') && !line.submenu.opened) {
|
|
210
|
+
target = line.control;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
target.focus({preventScroll:true});
|
|
214
|
+
}
|
|
153
215
|
menu.refreshItems();
|
|
154
216
|
}
|
|
155
217
|
#place(){positionPopup(this.#panel,this.#button,{placement:this.#menu.parameters.orientation==='vertical'?'side':'bottom'});}
|