@gramlot/gramlot 0.4.0 → 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.
Files changed (141) hide show
  1. package/assets/icons/align-center.svg +4 -0
  2. package/assets/icons/align-justify.svg +4 -0
  3. package/assets/icons/align-left.svg +4 -0
  4. package/assets/icons/align-right.svg +4 -0
  5. package/assets/icons/bold.svg +4 -0
  6. package/assets/icons/eraser.svg +4 -0
  7. package/assets/icons/horizontal-rule.svg +4 -0
  8. package/assets/icons/image.svg +4 -0
  9. package/assets/icons/indent.svg +4 -0
  10. package/assets/icons/italic.svg +4 -0
  11. package/assets/icons/list-bulleted.svg +4 -0
  12. package/assets/icons/list-numbered.svg +4 -0
  13. package/assets/icons/outdent.svg +4 -0
  14. package/assets/icons/paragraph.svg +4 -0
  15. package/assets/icons/select-all.svg +4 -0
  16. package/assets/icons/strikethrough.svg +4 -0
  17. package/assets/icons/underline.svg +4 -0
  18. package/dist/components/charts/__init__.py +1 -1
  19. package/dist/components/charts/assets/index.js +1 -1
  20. package/dist/components/charts/grammar.json +2032 -72
  21. package/dist/components/editors/__init__.py +1 -1
  22. package/dist/components/editors/assets/collection.js +1 -1
  23. package/dist/components/editors/assets/index.js +1 -1
  24. package/dist/components/editors/assets/libraries/codemirror.js +30 -30
  25. package/dist/components/editors/assets/libraries/jodit.js +452 -448
  26. package/dist/components/editors/commands.json +113 -1
  27. package/dist/components/editors/grammar.json +6 -4
  28. package/dist/components/grid/__init__.py +1 -1
  29. package/dist/components/grid/assets/index.js +1 -1
  30. package/dist/components/grid/grammar.json +61 -0
  31. package/dist/components/inputs/__init__.py +1 -1
  32. package/dist/components/inputs/assets/index.js +1 -1
  33. package/dist/components/inputs/grammar.json +35 -0
  34. package/dist/components/layout/__init__.py +1 -1
  35. package/dist/components/layout/assets/collection.js +1 -0
  36. package/dist/components/layout/assets/index.js +1 -1
  37. package/dist/components/layout/grammar.json +364 -0
  38. package/dist/components/tree/__init__.py +1 -1
  39. package/dist/components/tree/assets/index.js +1 -1
  40. package/dist/components/tree/grammar.json +35 -0
  41. package/dist/gramlot.js +1165 -420
  42. package/dist/gramlot.min.js +125 -100
  43. package/dist/libraries.json +5 -4
  44. package/dist/standard-collections.js +1 -1
  45. package/dist/standard-grammar.js +1 -1
  46. package/package.json +4 -2
  47. package/src/binding/providers.js +2 -1
  48. package/src/binding/remote.js +41 -6
  49. package/src/binding/runtime.js +24 -0
  50. package/src/builder/gramlot-builder.js +52 -18
  51. package/src/builder/source.js +66 -12
  52. package/src/chat.d.ts +1 -0
  53. package/src/chat.js +13 -1
  54. package/src/components/chart-bar3d-options.js +0 -1
  55. package/src/components/chart-boxplot-options.js +1 -1
  56. package/src/components/chart-candlestick-options.js +1 -1
  57. package/src/components/chart-engines/echarts-options.js +6 -5
  58. package/src/components/chart-engines/echarts.js +27 -10
  59. package/src/components/chart-engines/plotly-map.js +1 -1
  60. package/src/components/chart-engines/plotly.js +21 -14
  61. package/src/components/chart-engines/uplot.js +17 -11
  62. package/src/components/chart-engines/vega.js +17 -11
  63. package/src/components/chart-funnel-options.js +1 -1
  64. package/src/components/chart-geographic-options.js +1 -1
  65. package/src/components/chart-heatmap-options.js +1 -1
  66. package/src/components/chart-map-bar3d-options.js +2 -2
  67. package/src/components/chart-map-options.js +2 -2
  68. package/src/components/chart-parallel-options.js +1 -1
  69. package/src/components/chart-radar-options.js +1 -1
  70. package/src/components/chart-renderer.js +6 -1
  71. package/src/components/chart-sankey-options.js +1 -1
  72. package/src/components/chart-spatial-options.js +1 -1
  73. package/src/components/chart-sunburst-options.js +13 -1
  74. package/src/components/chart-theme.js +14 -0
  75. package/src/components/chart-treemap-options.js +1 -1
  76. package/src/components/chart-type-data.js +24 -4
  77. package/src/components/charts.js +7 -6
  78. package/src/components/check-box-tree.js +1 -1
  79. package/src/components/choice-editor.js +3 -3
  80. package/src/components/code-mirror-engine.js +2 -1
  81. package/src/components/code-mirror.js +1 -1
  82. package/src/components/editor-commands.js +69 -0
  83. package/src/components/editors.js +5 -3
  84. package/src/components/form-tray-pane.js +18 -0
  85. package/src/components/graphical-ranges.js +16 -3
  86. package/src/components/grid-check-sets.js +39 -3
  87. package/src/components/grid-header-interaction.js +3 -3
  88. package/src/components/grid-styles.js +19 -3
  89. package/src/components/grid.js +42 -9
  90. package/src/components/html-editor-commands.js +61 -0
  91. package/src/components/html-editor.js +18 -3
  92. package/src/components/inputs.js +1 -0
  93. package/src/components/jodit-engine.js +107 -6
  94. package/src/components/layout.js +3 -2
  95. package/src/components/menus.js +6 -1
  96. package/src/components/selected-container.js +16 -3
  97. package/src/components/tab-bar.js +20 -2
  98. package/src/components/tray-base.js +528 -0
  99. package/src/components/tray-pane.js +41 -518
  100. package/src/components/tree.js +44 -1
  101. package/src/components/typed-editor.js +5 -2
  102. package/src/editing-session.js +2 -1
  103. package/src/ide-runtime.js +3 -1
  104. package/src/index-page-runtime.js +11 -3
  105. package/src/index.d.ts +2 -1
  106. package/src/index.js +2 -1
  107. package/src/libraries.js +4 -4
  108. package/src/object-extract.d.ts +7 -0
  109. package/src/object-extract.js +31 -0
  110. package/src/renderer/attributes.js +1 -1
  111. package/src/renderer/gramlot-renderer.d.ts +2 -2
  112. package/src/server/chat.d.ts +3 -1
  113. package/src/server/chat.js +17 -6
  114. package/src/server/gramlot-server.js +5 -1
  115. package/src/server/index-page.js +27 -8
  116. package/src/server/toolbar-icon-name.d.ts +17 -0
  117. package/src/view/labelbox.js +6 -1
  118. package/src/visual-editor.d.ts +1 -0
  119. package/src/visual-editor.js +4 -3
  120. package/themes/gramlot-base/theme.css +7 -0
  121. package/themes/gramlot-index/icons/align-center.svg +4 -0
  122. package/themes/gramlot-index/icons/align-justify.svg +4 -0
  123. package/themes/gramlot-index/icons/align-left.svg +4 -0
  124. package/themes/gramlot-index/icons/align-right.svg +4 -0
  125. package/themes/gramlot-index/icons/bold.svg +4 -0
  126. package/themes/gramlot-index/icons/eraser.svg +4 -0
  127. package/themes/gramlot-index/icons/horizontal-rule.svg +4 -0
  128. package/themes/gramlot-index/icons/image.svg +4 -0
  129. package/themes/gramlot-index/icons/indent.svg +4 -0
  130. package/themes/gramlot-index/icons/italic.svg +4 -0
  131. package/themes/gramlot-index/icons/list-bulleted.svg +4 -0
  132. package/themes/gramlot-index/icons/list-numbered.svg +4 -0
  133. package/themes/gramlot-index/icons/outdent.svg +4 -0
  134. package/themes/gramlot-index/icons/paragraph.svg +4 -0
  135. package/themes/gramlot-index/icons/select-all.svg +4 -0
  136. package/themes/gramlot-index/icons/strikethrough.svg +4 -0
  137. package/themes/gramlot-index/icons/underline.svg +4 -0
  138. package/themes/gramlot-index/icons.json +17 -0
  139. package/themes/gramlot-index/theme.css +3 -0
  140. package/tools/gramlot-tools-inspector.js +11 -3
  141. package/src/builder/chart-icon.js +0 -2
@@ -8,11 +8,13 @@ import 'jodit/esm/plugins/drag-and-drop/drag-and-drop.js';
8
8
  import 'jodit/esm/plugins/fullsize/fullsize.js';
9
9
  import 'jodit/esm/plugins/hr/hr.js';
10
10
  import 'jodit/esm/plugins/indent/indent.js';
11
+ import 'jodit/esm/plugins/justify/justify.js';
11
12
  import 'jodit/esm/plugins/search/search.js';
12
13
  import 'jodit/esm/plugins/select/select.js';
13
14
  import 'jodit/esm/plugins/select-cells/select-cells.js';
14
15
  import 'jodit/esm/plugins/resize-cells/resize-cells.js';
15
16
  import 'jodit/esm/plugins/table-keyboard-navigation/table-keyboard-navigation.js';
17
+ import {isEditorEmpty, placeholder} from 'jodit/esm/plugins/placeholder/placeholder.js';
16
18
  import css from 'jodit/es2021/jodit.min.css';
17
19
  import {randomId} from '../random-id.js';
18
20
  import {prepareHtmlDocument} from './html-document.js';
@@ -21,6 +23,22 @@ const theme=`.jodit-container,.jodit-popup,.jodit-dialog{--jd-color-background-d
21
23
  .jodit-popup .jodit-ui-input{--jd-color-white:var(--gramlot-field-background,Field);color:var(--gramlot-ink,FieldText)}
22
24
  .jodit-toolbar-button__button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight)}`;
23
25
  const styles=new WeakSet();
26
+ // Prefix of the inert history marker that starts each projected document (prepare in createHtmlEditor).
27
+ const MARKER_PREFIX='gramlot-document-';
28
+ /** Jodit's placeholder plugin. Its emptiness test does not see the history marker.
29
+ * The marker comment is the first body node, so Jodit's own test never finds an empty document. */
30
+ class GramlotPlaceholder extends placeholder {
31
+ toggle() {
32
+ const editor=this.j;
33
+ if(!editor.editor||editor.isInDestruct)return;
34
+ if(editor.getRealMode()!==Jodit.constants.MODE_WYSIWYG){this.hide();return;}
35
+ const body=editor.editor, first=body.firstChild;
36
+ let content=body;
37
+ if(first?.nodeType===8&&first.data.startsWith(MARKER_PREFIX)){content=body.cloneNode(true);content.firstChild.remove();}
38
+ if(isEditorEmpty(content))this.show();else this.hide();
39
+ }
40
+ }
41
+ Jodit.plugins.add('gramlotPlaceholder',GramlotPlaceholder);
24
42
  export function createHtmlEditor(host) {
25
43
  const document=host.ownerDocument, window=document.defaultView;
26
44
  if (!styles.has(host.shadowRoot)) {
@@ -42,7 +60,7 @@ export function createHtmlEditor(host) {
42
60
  if(node.nodeType===8)data.allowedTags['#comment']=documents.has(`<!--${node.data}-->`);
43
61
  });
44
62
  const prepare=value=>{
45
- const content=prepareHtmlDocument(value,window), marker=`<!--gramlot-document-${randomId()}-->`;
63
+ const content=prepareHtmlDocument(value,window), marker=`<!--${MARKER_PREFIX}${randomId()}-->`;
46
64
  const record={content,value,marker,initialHtml:null};
47
65
  documents.set(marker,record);
48
66
  return record;
@@ -59,9 +77,9 @@ export function createHtmlEditor(host) {
59
77
  FORBID_TAGS:['style','form','input','button','select','textarea','iframe','object','embed','noscript'],
60
78
  FORBID_ATTR:['autofocus','srcdoc']
61
79
  })},
62
- toolbarAdaptive:false,toolbarSticky:false,showXPathInStatusbar:false,showCharsCounter:false,showWordsCounter:false,
63
- sourceEditor:'area',beautifyHTML:false,disablePlugins:['mobile'],
64
- buttons:['undo','redo','|','paragraph','bold','italic','underline','strikethrough','brush','eraser','|','ul','ol','outdent','indent','align','|','link','image','table','hr','|','find','selectall'],
80
+ // The commands are Gramlot menulines of the htmlEditor namespace (html-editor-commands.js).
81
+ toolbar:false,showXPathInStatusbar:false,showCharsCounter:false,showWordsCounter:false,
82
+ sourceEditor:'area',beautifyHTML:false,disablePlugins:['mobile','placeholder'],
65
83
  uploader:{insertImageAsBase64URI:true}
66
84
  });
67
85
  const frameDoc=editor.editor.ownerDocument;
@@ -106,12 +124,95 @@ export function createHtmlEditor(host) {
106
124
  });
107
125
  editor.events.on('blur',()=>host.editorBlurred());
108
126
  editor.events.on('changeStack',history);
127
+ // Jodit's backspace cases take a comment with text as a neighbor and put the cursor in it (#169).
128
+ // The history marker is out of the body while the cases run, and it is the first body node again after them.
129
+ let detachedMarker=null;
130
+ editor.events.on('backSpaceBeforeCases',()=>{
131
+ const first=editor.editor.firstChild;
132
+ if(first?.nodeType===8&&documents.has(`<!--${first.data}-->`)){detachedMarker=first;first.remove();}
133
+ });
134
+ editor.events.on('backSpaceAfterDelete',()=>{
135
+ if(!detachedMarker)return;
136
+ editor.editor.prepend(detachedMarker);detachedMarker=null;
137
+ });
109
138
  const resize=new window.ResizeObserver(entries=>{
110
139
  if(!disposed && entries.some(entry=>entry.contentRect.width>0 && entry.contentRect.height>0)) editor.events.fire('resize');
111
140
  });
112
141
  resize.observe(host.control);
113
142
  history();
143
+ // Command state follows the selection and the history, as Jodit's own toolbar does (ToolbarCollection).
144
+ let stateTimer=null;
145
+ const stateChanged=()=>{
146
+ if(disposed||stateTimer!==null)return;
147
+ stateTimer=window.setTimeout(()=>{stateTimer=null;if(!disposed)host.editorStateChanged();},50);
148
+ };
149
+ editor.events.on('updateToolbar changeStack mouseup keyup change readonly afterSetMode focus',stateChanged);
150
+ frameDoc.addEventListener('selectionchange',stateChanged,options);
151
+ const {Dom,Helpers,Popup}=Jodit.modules, controls=Jodit.defaultOptions.controls;
152
+ // Jodit's active rule of a control (ToolbarEditorCollection.shouldBeActive): its tags or its css,
153
+ // from the current node up to the editing area.
154
+ const matchesCss=(rules,node)=>Object.entries(rules).every(([property,value])=>{
155
+ const actual=Helpers.css(node,property).toString();
156
+ return typeof value==='function' ? value(editor,actual) : value.indexOf(actual)!==-1;
157
+ });
158
+ const active=name=>{
159
+ const control=controls[name], current=editor.s.current();
160
+ if(!current)return false;
161
+ if(control.isActive)return Boolean(control.isActive(editor,{control,state:{}}));
162
+ if(control.tags&&Dom.up(current,node=>node&&control.tags.includes(node.nodeName.toLowerCase()),editor.editor))return true;
163
+ return Boolean(control.css&&Dom.up(current,node=>node&&!Dom.isText(node)&&!Dom.isComment(node)&&matchesCss(control.css,node),editor.editor));
164
+ };
165
+ const block=()=>{
166
+ const current=editor.s.current();
167
+ return current ? Dom.closest(current,Dom.isBlock,editor.editor) : null;
168
+ };
169
+ const alignment=()=>{
170
+ const value=Helpers.css(block()||editor.editor,'text-align').toString();
171
+ return controls.align.defaultValue.includes(value) ? 'left' : value;
172
+ };
173
+ const ALIGN_COMMANDS={left:'justifyLeft',center:'justifyCenter',right:'justifyRight',justify:'justifyFull'};
174
+ const TOGGLES=new Set(['bold','italic','underline','strikethrough','ul','ol','link']);
175
+ const POPUPS=new Set(['color','image','link','table']);
176
+ // Jodit control names of the htmlEditor commands, where they differ.
177
+ const CONTROLS={color:'brush'};
178
+ // The last popup stays referenced until the next one or destroy: Jodit can close it itself on an outside click.
179
+ let openPopup=null;
180
+ const closePopup=()=>{if(openPopup){const popup=openPopup;openPopup=null;popup.close();popup.destruct();}};
181
+ const showPopup=(name,sender)=>{
182
+ closePopup();
183
+ const control={name:CONTROLS[name]??name,...controls[CONTROLS[name]??name]};
184
+ const anchor=host.commandAnchor(sender);
185
+ const popup=new Popup(editor);openPopup=popup;
186
+ // The control receives the button argument of a Jodit toolbar button: its control, its state and a parent
187
+ // (the table form draws its size grid only for a button inside a toolbar).
188
+ const content=control.popup(editor,editor.s.current(),closePopup,{control,state:{icon:{}},parentElement:popup});
189
+ if(!content){closePopup();return;}
190
+ popup.setContent(typeof content==='string' ? editor.c.fromHTML(content) : content)
191
+ .open(()=>Helpers.position(anchor,editor));
192
+ };
193
+ const execute=(name,message)=>{
194
+ if(name==='undo')return editor.history.canUndo()&&!locked()&&editor.history.undo();
195
+ if(name==='redo')return editor.history.canRedo()&&!locked()&&editor.history.redo();
196
+ if(POPUPS.has(name))return showPopup(name,message.sender);
197
+ if(name==='paragraph')return editor.execCommand('formatBlock',false,message.parameters.tag);
198
+ if(name==='align')return editor.execCommand(ALIGN_COMMANDS[message.parameters.value]);
199
+ const commands={eraser:'removeFormat',ul:'insertUnorderedList',ol:'insertOrderedList',hr:'insertHorizontalRule',
200
+ find:'openSearchDialog'};
201
+ editor.execCommand(commands[name]??name);
202
+ };
203
+ const commandState=(name,parameters)=>{
204
+ if(host.parameters.disabled)return TOGGLES.has(name) ? {disabled:true,checked:false} : {disabled:true};
205
+ if(name==='undo'||name==='redo')
206
+ return {disabled:locked()||!(name==='undo' ? editor.history.canUndo() : editor.history.canRedo())};
207
+ // Jodit keeps Select all active in read-only mode (activeButtonsInReadOnly).
208
+ const disabled=host.parameters.readonly&&name!=='selectall';
209
+ if(TOGGLES.has(name))return {disabled,checked:active(name)};
210
+ if(name==='paragraph')return {disabled,checked:block()?.nodeName.toLowerCase()===parameters.tag};
211
+ if(name==='align')return {disabled,checked:alignment()===parameters.value};
212
+ return {disabled};
213
+ };
114
214
  return {
215
+ execute,commandState,
115
216
  replace(value){
116
217
  const record=prepare(value), active=document.activeElement;
117
218
  restoring=true;
@@ -143,10 +244,10 @@ export function createHtmlEditor(host) {
143
244
  }
144
245
  history();
145
246
  },
146
- configure(){editor.setReadOnly(locked());history();},
247
+ configure(){editor.setReadOnly(locked());history();stateChanged();},
147
248
  undo(){if(locked()||!editor.history.canUndo())return false;editor.history.undo();return true;},
148
249
  redo(){if(locked()||!editor.history.canRedo())return false;editor.history.redo();return true;},
149
250
  focus(){editor.selection.focus();},
150
- destroy(){disposed=true;resize.disconnect();events.abort();editor.destruct();sanitizer.removeAllHooks();documents.clear();}
251
+ destroy(){disposed=true;window.clearTimeout(stateTimer);closePopup();resize.disconnect();events.abort();editor.destruct();sanitizer.removeAllHooks();documents.clear();}
151
252
  };
152
253
  }
@@ -12,7 +12,8 @@ import {FormletLabels} from './formlet-labels.js';
12
12
  import {Dialog, FloatingPane} from './windows.js';
13
13
  export {Dialog, FloatingPane};
14
14
  import {TrayPane} from './tray-pane.js';
15
- export {TrayPane};
15
+ import {FormTrayPane} from './form-tray-pane.js';
16
+ export {TrayPane, FormTrayPane};
16
17
 
17
18
  import {TransformPane} from './transform-pane.js';
18
19
  export {TransformPane};
@@ -184,4 +185,4 @@ export const GroupBox = defineComponent({
184
185
  }
185
186
  }
186
187
  });
187
- export default defineCollection({name: 'layout', components: [TransformPane, Dialog, FloatingPane, FramePane, TrayPane, Formlet, GroupBox, ContentPane, BorderContainer, StackContainer, TabContainer]});
188
+ export default defineCollection({name: 'layout', components: [TransformPane, Dialog, FloatingPane, FramePane, TrayPane, FormTrayPane, Formlet, GroupBox, ContentPane, BorderContainer, StackContainer, TabContainer]});
@@ -158,8 +158,13 @@ export function MenuContainer(HTMLElement) {
158
158
  const options = {signal:this.#events.signal};
159
159
  const place = () => positionPopup(this, opener, {point,placement:this.parentMenu && (!this.parentMenu.permanent || this.parentMenu.parameters.orientation==='vertical' || this.parentMenu.isOverflowed(this.parentElement)) ? 'side' : 'bottom'});
160
160
  place();
161
- this.ownerDocument.defaultView.addEventListener('resize',place,options);
162
161
  this.ownerDocument.addEventListener('scroll',place,{...options,capture:true});
162
+ // The open chain closes when the window resizes, loses focus or becomes hidden.
163
+ this.ownerDocument.defaultView.addEventListener('resize',() => this.closeChain(false),options);
164
+ this.ownerDocument.defaultView.addEventListener('blur',() => this.closeChain(false),options);
165
+ this.ownerDocument.addEventListener('visibilitychange',() => {
166
+ if (this.ownerDocument.visibilityState==='hidden') this.closeChain(false);
167
+ },options);
163
168
  this.ownerDocument.addEventListener('pointerdown',event => {
164
169
  if (!event.composedPath().includes(this) && (opener===this.#attachment || !event.composedPath().includes(opener))) this.closeChain(false);
165
170
  },options);
@@ -13,13 +13,15 @@ function SelectedContainer(HTMLElement) {
13
13
  static #selectionPanels = new WeakMap();
14
14
  static #panelSequence = 0;
15
15
  static projectChild(element, attrs, actions) {
16
- const {pageName = null, title = '', icon = '', icon_size = null, icon_color = null, icon_opacity = null, badge = null, badge_color = '', closable = false, detachable = false, onClose, hidden = false, disabled = false, ...rest} = attrs;
16
+ const {pageName = null, title = '', icon = '', icon_size = null, icon_color = null, icon_opacity = null, badge = null, badge_color = '', caption_color = null, tab_align = 'start', closable = false, detachable = false, onClose, hidden = false, disabled = false, ...rest} = attrs;
17
17
  if (pageName !== null && typeof pageName !== 'string') throw new TypeError('pageName must be a string');
18
18
  if (typeof closable !== 'boolean') throw new TypeError('closable must be a boolean');
19
19
  if (typeof detachable !== 'boolean') throw new TypeError('detachable must be a boolean');
20
+ if (caption_color != null && typeof caption_color !== 'string') throw new TypeError('caption_color must be text');
21
+ if (!['start','end'].includes(tab_align)) throw new TypeError('Invalid tab_align');
20
22
  const panels = SelectedContainer.#selectionPanels;
21
23
  const slot = panels.get(element)?.slot ?? `panel-${++SelectedContainer.#panelSequence}`;
22
- panels.set(element, {pageName, title, icon, icon_size, icon_color, icon_opacity, badge, badge_color, closable, detachable, hidden, disabled, slot,
24
+ panels.set(element, {pageName, title, icon, icon_size, icon_color, icon_opacity, badge, badge_color, caption_color, tab_align, closable, detachable, hidden, disabled, slot,
23
25
  remove: actions.remove, allowClose: () => onClose == null ? true : actions.invoke('onClose', onClose, {})});
24
26
  rest.slot = slot;
25
27
  if (element.parentElement) element.parentElement.scheduleSelection();
@@ -205,6 +207,11 @@ const selectionChildParameters = {
205
207
  title: {dtype:'T', default:''},
206
208
  onClose: {inline: []},
207
209
  };
210
+ // Tab presentation of a child pane: only a tabContainer draws a strip.
211
+ const tabChildParameters = {
212
+ caption_color: {dtype:'T', nullable:true, binding:'read'},
213
+ tab_align: {dtype:'T', default:'start', binding:'read', enum:['start','end']},
214
+ };
208
215
 
209
216
  export const StackContainer = defineComponent({
210
217
  name:'stackContainer', tag:'gramlot-stack-container', base:SelectedContainer, subTags:'*',
@@ -214,7 +221,7 @@ export const StackContainer = defineComponent({
214
221
 
215
222
  export const TabContainer = defineComponent({
216
223
  name:'tabContainer', tag:'gramlot-tab-container', base:SelectedContainer, subTags:'*',
217
- sourceContext: true, childParameters: {...selectionChildParameters, title:{...selectionChildParameters.title, required:true}, detachable:{dtype:'B'}},
224
+ sourceContext: true, childParameters: {...selectionChildParameters, title:{...selectionChildParameters.title, required:true}, detachable:{dtype:'B'}, ...tabChildParameters},
218
225
  parameters: {
219
226
  tabMode: {dtype:'T', default:'tabs', binding:'read', enum:['tabs','underline','tabBar']},
220
227
  tabPosition: {dtype:'T', default:'top', binding:'read', enum:['top','bottom','left','right']},
@@ -238,6 +245,9 @@ export const TabContainer = defineComponent({
238
245
  border-bottom:1px solid var(--tab-border);background:var(--gramlot-tab-background,var(--gramlot-surface-subtle,#eef1f5))}
239
246
  [data-align=center] .tabs{justify-content:safe center}
240
247
  [data-align=end] .tabs{justify-content:safe flex-end}
248
+ .tab-entry[data-tab-align=end]{order:1}
249
+ .tab-entry:nth-child(1 of [data-tab-align=end]:not([hidden]):not([data-overflow])){margin-inline-start:auto}
250
+ :is([data-position=left],[data-position=right]) .tab-entry:nth-child(1 of [data-tab-align=end]:not([hidden]):not([data-overflow])){margin-inline-start:0;margin-block-start:auto}
241
251
  .tab-entry{position:relative;display:flex;flex:none;align-items:stretch;border:1px solid transparent;border-bottom:0;
242
252
  border-radius:var(--tab-radius) var(--tab-radius) 0 0;color:var(--gramlot-tab-color,var(--gramlot-text-secondary,#555))}
243
253
  .tab-entry:has([aria-selected=true]){border-color:var(--tab-border);color:var(--gramlot-tab-selected-color,var(--gramlot-ink,#222));
@@ -407,6 +417,9 @@ export const TabContainer = defineComponent({
407
417
  entry.root.toggleAttribute('data-detachable', record.config.detachable && !record.surface);
408
418
  const caption = record.config.title || record.config.pageName || String(record.index + 1);
409
419
  entry.caption.textContent = caption;
420
+ entry.caption.style.color = record.config.caption_color ?? '';
421
+ if (record.config.tab_align === 'end') entry.root.dataset.tabAlign = 'end';
422
+ else delete entry.root.dataset.tabAlign;
410
423
  if (entry.root.hasAttribute('data-detachable')) {
411
424
  entry.button.title = `${caption} · Drag out or press Shift+Enter to detach`;
412
425
  entry.button.setAttribute('aria-keyshortcuts', 'Shift+Enter');
@@ -1,6 +1,8 @@
1
1
  import {positionPopup} from './popup.js';
2
2
 
3
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'];
4
6
 
5
7
  /** A sideways drop along a strip stays within the tab order. */
6
8
  export function outsideTabStrip(strip, vertical, event) {
@@ -22,6 +24,7 @@ function TabBar(HTMLElement) {
22
24
  return class extends HTMLElement {
23
25
  #observer;
24
26
  #frame = null;
27
+ #follow = null;
25
28
  #slot;
26
29
  #more;
27
30
  #menu;
@@ -207,7 +210,9 @@ function TabBar(HTMLElement) {
207
210
  const outside = outsideTabStrip(this, vertical, event);
208
211
  const rect = strip.getBoundingClientRect();
209
212
  const point = vertical ? event.clientY - rect.top : event.clientX - rect.left;
210
- const tabs = [...strip.children].filter(tab => !tab.hidden && !tab.inert && !tab.hasAttribute('data-overflow'));
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);
211
216
  // Offsets describe the committed slots even while their contents slide into the proposed order.
212
217
  const before = tabs.find(tab => tab !== entry && point < (vertical
213
218
  ? tab.offsetTop + tab.offsetHeight / 2 : tab.offsetLeft + tab.offsetWidth / 2));
@@ -249,7 +254,9 @@ function TabBar(HTMLElement) {
249
254
  disconnectedCallback() {
250
255
  this.#observer.disconnect();
251
256
  if (this.#frame !== null) this.ownerDocument.defaultView.cancelAnimationFrame(this.#frame);
257
+ if (this.#follow !== null) this.ownerDocument.defaultView.cancelAnimationFrame(this.#follow);
252
258
  this.#frame = null;
259
+ this.#follow = null;
253
260
  this.#endDrag();
254
261
  }
255
262
  update(count, selected) {
@@ -320,11 +327,21 @@ function TabBar(HTMLElement) {
320
327
  #position() {
321
328
  const tab = this.#selected;
322
329
  if (!tab) return;
323
- const style = tab.parentElement.style;
330
+ const strip = tab.parentElement, style = strip.style;
324
331
  style.setProperty('--capsule-x', tab.offsetLeft + 'px');
325
332
  style.setProperty('--capsule-y', tab.offsetTop + 'px');
326
333
  style.setProperty('--capsule-width', tab.offsetWidth + 'px');
327
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
+ }
328
345
  }
329
346
  };
330
347
  }
@@ -339,6 +356,7 @@ export const tabBarStyles = `
339
356
  transform:translate(var(--capsule-x),var(--capsule-y));translate:var(--capsule-shift,none);transition:transform 180ms ease-out,translate 120ms ease-out;
340
357
  background:var(--tabs-active,light-dark(white,rgb(255 255 255 / .18)));
341
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}
342
360
  gramlot-tab-bar .tabs .tab-entry{box-sizing:border-box;min-width:${minimumTabWidth}px;flex:1 1 0;overflow:hidden;
343
361
  height:max(24px,var(--gramlot-touch-target,0px));border:0;border-radius:6px;
344
362
  background:transparent;color:var(--tabs-text,var(--gramlot-ink,CanvasText));