@jupyter/chat 0.22.0 → 0.23.0-alpha.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 (61) hide show
  1. package/lib/__tests__/multichat-panel.spec.js +82 -1
  2. package/lib/components/attachments.d.ts +0 -1
  3. package/lib/components/avatar.d.ts +0 -1
  4. package/lib/components/chat.d.ts +0 -1
  5. package/lib/components/chat.js +8 -9
  6. package/lib/components/code-blocks/code-toolbar.d.ts +0 -1
  7. package/lib/components/code-blocks/copy-button.d.ts +0 -1
  8. package/lib/components/input/buttons/attach-button.d.ts +0 -1
  9. package/lib/components/input/buttons/cancel-button.d.ts +0 -1
  10. package/lib/components/input/buttons/save-edit-button.d.ts +0 -1
  11. package/lib/components/input/buttons/save-edit-button.js +2 -2
  12. package/lib/components/input/buttons/send-button.d.ts +0 -1
  13. package/lib/components/input/buttons/send-button.js +3 -10
  14. package/lib/components/input/buttons/stop-button.d.ts +0 -1
  15. package/lib/components/input/chat-input.d.ts +0 -1
  16. package/lib/components/input/chat-input.js +2 -3
  17. package/lib/components/input/submit-message.d.ts +22 -0
  18. package/lib/components/input/submit-message.js +13 -0
  19. package/lib/components/messages/chat-body-placeholder.d.ts +0 -1
  20. package/lib/components/messages/footer.d.ts +0 -1
  21. package/lib/components/messages/header.d.ts +3 -2
  22. package/lib/components/messages/header.js +2 -1
  23. package/lib/components/messages/message.d.ts +3 -6
  24. package/lib/components/messages/message.js +26 -14
  25. package/lib/components/messages/messages.d.ts +0 -1
  26. package/lib/components/messages/messages.js +11 -20
  27. package/lib/components/messages/preamble.d.ts +0 -1
  28. package/lib/components/messages/toolbar.d.ts +0 -1
  29. package/lib/components/messages/welcome.d.ts +0 -1
  30. package/lib/components/mui-extras/tooltipped-icon-button.d.ts +0 -1
  31. package/lib/components/writing-indicator.d.ts +0 -1
  32. package/lib/context.d.ts +0 -1
  33. package/lib/message.d.ts +6 -0
  34. package/lib/message.js +23 -0
  35. package/lib/model.d.ts +8 -1
  36. package/lib/model.js +3 -0
  37. package/lib/registers/chat-commands.d.ts +0 -1
  38. package/lib/registers/footers.d.ts +0 -1
  39. package/lib/registers/preambles.d.ts +0 -1
  40. package/lib/tokens.d.ts +0 -1
  41. package/lib/types.d.ts +5 -0
  42. package/lib/utils.js +2 -2
  43. package/lib/widgets/chat-selector-popup.d.ts +0 -1
  44. package/lib/widgets/multichat-panel.d.ts +21 -5
  45. package/lib/widgets/multichat-panel.js +50 -10
  46. package/package.json +22 -22
  47. package/src/__tests__/multichat-panel.spec.ts +113 -1
  48. package/src/components/chat.tsx +10 -10
  49. package/src/components/input/buttons/save-edit-button.tsx +2 -2
  50. package/src/components/input/buttons/send-button.tsx +3 -13
  51. package/src/components/input/chat-input.tsx +2 -3
  52. package/src/components/input/submit-message.ts +38 -0
  53. package/src/components/messages/header.tsx +5 -1
  54. package/src/components/messages/message.tsx +129 -122
  55. package/src/components/messages/messages.tsx +14 -26
  56. package/src/message.ts +29 -0
  57. package/src/model.ts +10 -2
  58. package/src/types.ts +5 -0
  59. package/src/utils.ts +2 -2
  60. package/src/widgets/multichat-panel.tsx +62 -11
  61. package/style/chat.css +8 -4
@@ -15,15 +15,17 @@ import {
15
15
  closeIcon,
16
16
  launchIcon,
17
17
  PanelWithToolbar,
18
+ ReactiveToolbar,
18
19
  ReactWidget,
19
20
  Spinner,
21
+ Toolbar,
20
22
  ToolbarButton
21
23
  } from '@jupyterlab/ui-components';
22
24
  import { ArrayExt } from '@lumino/algorithm';
23
- import { Message } from '@lumino/messaging';
25
+ import { Message, MessageLoop } from '@lumino/messaging';
24
26
  import { Debouncer } from '@lumino/polling';
25
27
  import { ISignal, Signal } from '@lumino/signaling';
26
- import { Widget } from '@lumino/widgets';
28
+ import { Panel, Widget } from '@lumino/widgets';
27
29
  import React, { useEffect, useRef, useState } from 'react';
28
30
 
29
31
  import { ChatSelectorPopup } from './chat-selector-popup';
@@ -43,8 +45,26 @@ const SIDEPANEL_CLASS = 'jp-chat-sidepanel';
43
45
  const ADD_BUTTON_CLASS = 'jp-chat-add';
44
46
  const OPEN_SELECT_CLASS = 'jp-chat-open';
45
47
  const SIDEPANEL_WIDGET_CLASS = 'jp-chat-sidepanel-widget';
48
+ // TODO: Drop this workaround class (and related CSS) once we depend on
49
+ // @jupyterlab/ui-components >= 4.6.0 (refs - jupyterlab/jupyterlab#18824).
46
50
  const TOOLBAR_CLASS = 'jp-chat-sidepanel-widget-toolbar';
47
51
 
52
+ /**
53
+ * A panel widget with a reactive toolbar.
54
+ */
55
+ class ReactivePanelWithToolbar extends Panel {
56
+ constructor() {
57
+ super();
58
+ this._toolbar = new ReactiveToolbar({ noFocusOnClick: true });
59
+ }
60
+
61
+ get toolbar(): ReactiveToolbar {
62
+ return this._toolbar;
63
+ }
64
+
65
+ private _toolbar: ReactiveToolbar;
66
+ }
67
+
48
68
  /**
49
69
  * Generic sidepanel widget including multiple chats and the add chat button.
50
70
  */
@@ -105,7 +125,7 @@ export class MultiChatPanel extends PanelWithToolbar {
105
125
  chatNames: [],
106
126
  onSelect: this._onSelectChat,
107
127
  onClose: (name: string) => {
108
- this.disposeLoadedModel(name);
128
+ this.unsetLoadedModel(name);
109
129
  },
110
130
  translator
111
131
  });
@@ -180,9 +200,10 @@ export class MultiChatPanel extends PanelWithToolbar {
180
200
  }
181
201
 
182
202
  /**
183
- * Dispose a model, removing it from loaded models.
203
+ * Removing a model from loaded list.
204
+ * Dispose of the widget and optionally dispose of the model.
184
205
  */
185
- disposeLoadedModel(name: string): void {
206
+ unsetLoadedModel(name: string, dispose = true): void {
186
207
  const model = this._loadedModels.get(name);
187
208
  if (model) {
188
209
  // If this is the currently displayed chat, remove it.
@@ -198,7 +219,9 @@ export class MultiChatPanel extends PanelWithToolbar {
198
219
  this._addPlaceholder();
199
220
  }
200
221
 
201
- model.dispose();
222
+ if (dispose) {
223
+ model.dispose();
224
+ }
202
225
  this._loadedModels.delete(name);
203
226
  this._chatSelectorPopup?.setLoadedModels(this.getLoadedModelNames());
204
227
  }
@@ -272,8 +295,8 @@ export class MultiChatPanel extends PanelWithToolbar {
272
295
  displayName: name,
273
296
  openInMain: this._openInMain,
274
297
  renameChat: this._renameChat,
275
- onClose: (name: string) => {
276
- this.disposeLoadedModel(name);
298
+ onClose: (name: string, disposeModel = true) => {
299
+ this.unsetLoadedModel(name, disposeModel);
277
300
  },
278
301
  trans: this._trans
279
302
  });
@@ -508,7 +531,7 @@ export namespace MultiChatPanel {
508
531
  /**
509
532
  * A widget containing the chat and its toolbar.
510
533
  */
511
- class SidePanelWidget extends PanelWithToolbar {
534
+ class SidePanelWidget extends ReactivePanelWithToolbar {
512
535
  constructor(options: SidePanelWidget.IOptions) {
513
536
  super();
514
537
  this._chatWidget = options.widget;
@@ -516,8 +539,11 @@ class SidePanelWidget extends PanelWithToolbar {
516
539
  const trans = options.trans;
517
540
 
518
541
  this.addClass(SIDEPANEL_WIDGET_CLASS);
542
+ // Keep side-panel toolbar baseline sizing from ui-components.
543
+ this.toolbar.addClass('jp-SidePanel-toolbar');
519
544
  this.toolbar.addClass(TOOLBAR_CLASS);
520
545
  this._updateTitle();
546
+ this.toolbar.addItem('titleSpacer', Toolbar.createSpacerItem());
521
547
 
522
548
  this.addWidget(this.toolbar);
523
549
 
@@ -588,7 +614,7 @@ class SidePanelWidget extends PanelWithToolbar {
588
614
  onClick: async () => {
589
615
  const name = this.model.name;
590
616
  if (await options.openInMain?.(name)) {
591
- options.onClose(this._displayName);
617
+ options.onClose(this._displayName, false);
592
618
  }
593
619
  }
594
620
  });
@@ -610,6 +636,16 @@ class SidePanelWidget extends PanelWithToolbar {
610
636
  this._markAsRead.enabled = (this.model?.unreadMessages.length ?? 0) > 0;
611
637
  }
612
638
 
639
+ protected onAfterAttach(msg: Message): void {
640
+ super.onAfterAttach(msg);
641
+ requestAnimationFrame(() => this._updateReactiveToolbar());
642
+ }
643
+
644
+ protected onResize(msg: Widget.ResizeMessage): void {
645
+ super.onResize(msg);
646
+ this._updateReactiveToolbar();
647
+ }
648
+
613
649
  /**
614
650
  * The chat widget embedded in the sidepanel widget.
615
651
  */
@@ -687,6 +723,21 @@ class SidePanelWidget extends PanelWithToolbar {
687
723
  this._markAsRead.enabled = unread.length > 0;
688
724
  };
689
725
 
726
+ /**
727
+ * Trigger reactive toolbar overflow computation from rendered toolbar size.
728
+ */
729
+ private _updateReactiveToolbar(): void {
730
+ const toolbarWidth = this.toolbar.node.offsetWidth;
731
+ if (toolbarWidth <= 0) {
732
+ return;
733
+ }
734
+ const toolbarHeight = this.toolbar.node.offsetHeight;
735
+ MessageLoop.sendMessage(
736
+ this.toolbar,
737
+ new Widget.ResizeMessage(toolbarWidth, toolbarHeight)
738
+ );
739
+ }
740
+
690
741
  private _chatWidget: ChatWidget;
691
742
  private _markAsRead: ToolbarButton;
692
743
  private _displayName: string;
@@ -712,7 +763,7 @@ namespace SidePanelWidget {
712
763
  /**
713
764
  * The callback when closing the chat.
714
765
  */
715
- onClose: (name: string) => void;
766
+ onClose: (name: string, disposeModel?: boolean) => void;
716
767
  /**
717
768
  * The displayed name of the chat.
718
769
  */
package/style/chat.css CHANGED
@@ -61,12 +61,15 @@
61
61
  }
62
62
 
63
63
  .jp-chat-toolbar {
64
- visibility: hidden;
64
+ opacity: 0;
65
+ transition: opacity 0.15s ease;
65
66
  position: absolute;
66
67
  right: 0;
67
- top: 0;
68
+ top: -20px;
68
69
  font-size: var(--jp-ui-font-size0);
69
70
  color: var(--jp-ui-font-color3);
71
+ background-color: var(--jp-layout-color2);
72
+ box-shadow: var(--jp-elevation-z2);
70
73
  }
71
74
 
72
75
  .jp-chat-toolbar:hover {
@@ -75,7 +78,7 @@
75
78
  }
76
79
 
77
80
  .jp-chat-message-container:hover .jp-chat-toolbar {
78
- visibility: visible;
81
+ opacity: 1;
79
82
  }
80
83
 
81
84
  .jp-chat-toolbar > .jp-ToolbarButtonComponent {
@@ -144,10 +147,11 @@
144
147
  .jp-chat-sidepanel-widget-toolbar > .jp-chat-sidepanel-widget-title {
145
148
  display: block;
146
149
  align-content: center;
147
- flex: 1 1 0%;
150
+ max-width: 16em;
148
151
  min-width: 0;
149
152
  overflow: hidden;
150
153
  text-overflow: ellipsis;
154
+ white-space: nowrap;
151
155
  text-transform: uppercase;
152
156
  color: var(--jp-ui-font-color1);
153
157
  font-size: var(--jp-ui-font-size0);