@jupyter/chat 0.1.0 → 0.2.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.
@@ -0,0 +1,78 @@
1
+ import { Token } from '@lumino/coreutils';
2
+ import { IAutocompletionCommandsProps } from './types';
3
+ /**
4
+ * The token for the autocomplete registry, which can be provided by an extension
5
+ * using @jupyter/chat package.
6
+ */
7
+ export declare const IAutocompletionRegistry: Token<IAutocompletionRegistry>;
8
+ /**
9
+ * The interface of a registry to provide autocompleters.
10
+ */
11
+ export interface IAutocompletionRegistry {
12
+ /**
13
+ * The default autocompletion name.
14
+ */
15
+ default: string | null;
16
+ /**
17
+ * Get the default autocompletion.
18
+ */
19
+ getDefaultCompletion(): IAutocompletionCommandsProps | undefined;
20
+ /**
21
+ * Return a registered autocomplete props.
22
+ *
23
+ * @param name - the name of the registered autocomplete props.
24
+ */
25
+ get(name: string): IAutocompletionCommandsProps | undefined;
26
+ /**
27
+ * Register autocomplete props.
28
+ *
29
+ * @param name - the name for the registration.
30
+ * @param autocompletion - the autocomplete props.
31
+ */
32
+ add(name: string, autocompletion: IAutocompletionCommandsProps): boolean;
33
+ /**
34
+ * Remove a registered autocomplete props.
35
+ *
36
+ * @param name - the name of the autocomplete props.
37
+ */
38
+ remove(name: string): boolean;
39
+ }
40
+ /**
41
+ * A registry to provide autocompleters.
42
+ */
43
+ export declare class AutocompletionRegistry implements IAutocompletionRegistry {
44
+ /**
45
+ * Getter and setter for the default autocompletion name.
46
+ */
47
+ get default(): string | null;
48
+ set default(name: string | null);
49
+ /**
50
+ * Get the default autocompletion.
51
+ */
52
+ getDefaultCompletion(): IAutocompletionCommandsProps | undefined;
53
+ /**
54
+ * Return a registered autocomplete props.
55
+ *
56
+ * @param name - the name of the registered autocomplete props.
57
+ */
58
+ get(name: string): IAutocompletionCommandsProps | undefined;
59
+ /**
60
+ * Register autocomplete props.
61
+ *
62
+ * @param name - the name for the registration.
63
+ * @param autocompletion - the autocomplete props.
64
+ */
65
+ add(name: string, autocompletion: IAutocompletionCommandsProps, isDefault?: boolean): boolean;
66
+ /**
67
+ * Remove a registered autocomplete props.
68
+ *
69
+ * @param name - the name of the autocomplete props.
70
+ */
71
+ remove(name: string): boolean;
72
+ /**
73
+ * Remove all registered autocompletions.
74
+ */
75
+ removeAll(): void;
76
+ private _default;
77
+ private _autocompletions;
78
+ }
@@ -0,0 +1,83 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ import { Token } from '@lumino/coreutils';
6
+ /**
7
+ * The token for the autocomplete registry, which can be provided by an extension
8
+ * using @jupyter/chat package.
9
+ */
10
+ export const IAutocompletionRegistry = new Token('@jupyter/chat:IAutocompleteRegistry');
11
+ /**
12
+ * A registry to provide autocompleters.
13
+ */
14
+ export class AutocompletionRegistry {
15
+ constructor() {
16
+ this._default = null;
17
+ this._autocompletions = new Map();
18
+ }
19
+ /**
20
+ * Getter and setter for the default autocompletion name.
21
+ */
22
+ get default() {
23
+ return this._default;
24
+ }
25
+ set default(name) {
26
+ if (name === null || this._autocompletions.has(name)) {
27
+ this._default = name;
28
+ }
29
+ else {
30
+ console.warn(`There is no registered completer with the name '${name}'`);
31
+ }
32
+ }
33
+ /**
34
+ * Get the default autocompletion.
35
+ */
36
+ getDefaultCompletion() {
37
+ if (this._default === null) {
38
+ return undefined;
39
+ }
40
+ return this._autocompletions.get(this._default);
41
+ }
42
+ /**
43
+ * Return a registered autocomplete props.
44
+ *
45
+ * @param name - the name of the registered autocomplete props.
46
+ */
47
+ get(name) {
48
+ return this._autocompletions.get(name);
49
+ }
50
+ /**
51
+ * Register autocomplete props.
52
+ *
53
+ * @param name - the name for the registration.
54
+ * @param autocompletion - the autocomplete props.
55
+ */
56
+ add(name, autocompletion, isDefault = false) {
57
+ if (!this._autocompletions.has(name)) {
58
+ this._autocompletions.set(name, autocompletion);
59
+ if (this._autocompletions.size === 1 || isDefault) {
60
+ this.default = name;
61
+ }
62
+ return true;
63
+ }
64
+ else {
65
+ console.warn(`A completer with the name '${name}' is already registered`);
66
+ return false;
67
+ }
68
+ }
69
+ /**
70
+ * Remove a registered autocomplete props.
71
+ *
72
+ * @param name - the name of the autocomplete props.
73
+ */
74
+ remove(name) {
75
+ return this._autocompletions.delete(name);
76
+ }
77
+ /**
78
+ * Remove all registered autocompletions.
79
+ */
80
+ removeAll() {
81
+ this._autocompletions.clear();
82
+ }
83
+ }
package/lib/types.d.ts CHANGED
@@ -13,21 +13,36 @@ export interface IUser {
13
13
  * The configuration interface.
14
14
  */
15
15
  export interface IConfig {
16
+ /**
17
+ * Whether to send a message via Shift-Enter instead of Enter.
18
+ */
16
19
  sendWithShiftEnter?: boolean;
20
+ /**
21
+ * Last read message (no use yet).
22
+ */
17
23
  lastRead?: number;
24
+ /**
25
+ * Whether to stack consecutive messages from same user.
26
+ */
27
+ stackMessages?: boolean;
28
+ /**
29
+ * Whether to enable or not the notifications on unread messages.
30
+ */
31
+ unreadNotifications?: boolean;
18
32
  }
19
33
  /**
20
- * The chat message decription.
34
+ * The chat message description.
21
35
  */
22
- export interface IChatMessage {
36
+ export interface IChatMessage<T = IUser> {
23
37
  type: 'msg';
24
38
  body: string;
25
39
  id: string;
26
40
  time: number;
27
- sender: IUser | string;
41
+ sender: T;
28
42
  raw_time?: boolean;
29
43
  deleted?: boolean;
30
44
  edited?: boolean;
45
+ stacked?: boolean;
31
46
  }
32
47
  /**
33
48
  * The chat history interface.
@@ -43,7 +58,44 @@ export interface INewMessage {
43
58
  id?: string;
44
59
  }
45
60
  /**
46
- * An empty interface to describe optional settings taht could be fetched from server.
61
+ * An empty interface to describe optional settings that could be fetched from server.
47
62
  */
48
63
  export interface ISettings {
49
64
  }
65
+ /**
66
+ * The autocomplete command type.
67
+ */
68
+ export type AutocompleteCommand = {
69
+ label: string;
70
+ };
71
+ /**
72
+ * The properties of the autocompletion.
73
+ *
74
+ * The autocompletion component will open if the 'opener' string is typed at the
75
+ * beginning of the input field.
76
+ */
77
+ export interface IAutocompletionCommandsProps {
78
+ /**
79
+ * The string that open the completer.
80
+ */
81
+ opener: string;
82
+ /**
83
+ * The list of available commands.
84
+ */
85
+ commands?: AutocompleteCommand[] | (() => Promise<AutocompleteCommand[]>);
86
+ /**
87
+ * The props for the Autocomplete component.
88
+ *
89
+ * Must be compatible with https://mui.com/material-ui/api/autocomplete/#props.
90
+ *
91
+ * ## NOTES:
92
+ * - providing `options` will overwrite the commands argument.
93
+ * - providing `renderInput` will overwrite the input component.
94
+ * - providing `renderOptions` allows to customize the rendering of the component.
95
+ * - some arguments should not be provided and would be overwritten:
96
+ * - inputValue
97
+ * - onInputChange
98
+ * - onHighlightChange
99
+ */
100
+ props?: any;
101
+ }
@@ -1,4 +1,3 @@
1
- import { IThemeManager, ReactWidget } from '@jupyterlab/apputils';
2
- import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
3
- import { IChatModel } from '../model';
4
- export declare function buildChatSidebar(chatModel: IChatModel, themeManager: IThemeManager | null, rmRegistry: IRenderMimeRegistry): ReactWidget;
1
+ import { ReactWidget } from '@jupyterlab/apputils';
2
+ import { Chat } from '../components/chat';
3
+ export declare function buildChatSidebar(options: Chat.IOptions): ReactWidget;
@@ -6,8 +6,8 @@ import { ReactWidget } from '@jupyterlab/apputils';
6
6
  import React from 'react';
7
7
  import { Chat } from '../components/chat';
8
8
  import { chatIcon } from '../icons';
9
- export function buildChatSidebar(chatModel, themeManager, rmRegistry) {
10
- const ChatWidget = ReactWidget.create(React.createElement(Chat, { model: chatModel, themeManager: themeManager, rmRegistry: rmRegistry }));
9
+ export function buildChatSidebar(options) {
10
+ const ChatWidget = ReactWidget.create(React.createElement(Chat, { ...options }));
11
11
  ChatWidget.id = 'jupyter-chat::side-panel';
12
12
  ChatWidget.title.icon = chatIcon;
13
13
  ChatWidget.title.caption = 'Jupyter Chat'; // TODO: i18n
@@ -5,15 +5,9 @@ import { IChatModel } from '../model';
5
5
  export declare class ChatWidget extends ReactWidget {
6
6
  constructor(options: Chat.IOptions);
7
7
  /**
8
- * Gte the model of the widget.
8
+ * Get the model of the widget.
9
9
  */
10
10
  get model(): IChatModel;
11
11
  render(): React.JSX.Element;
12
- private readonly _model;
13
- private _themeManager;
14
- private _rmRegistry;
15
- }
16
- export declare namespace ChatWidget {
17
- interface IOptions extends Chat.IOptions {
18
- }
12
+ private _chatOptions;
19
13
  }
@@ -12,17 +12,17 @@ export class ChatWidget extends ReactWidget {
12
12
  this.id = 'jupyter-chat::widget';
13
13
  this.title.icon = chatIcon;
14
14
  this.title.caption = 'Jupyter Chat'; // TODO: i18n
15
- this._model = options.model;
16
- this._themeManager = (options === null || options === void 0 ? void 0 : options.themeManager) || null;
17
- this._rmRegistry = options.rmRegistry;
15
+ this._chatOptions = options;
18
16
  }
19
17
  /**
20
- * Gte the model of the widget.
18
+ * Get the model of the widget.
21
19
  */
22
20
  get model() {
23
- return this._model;
21
+ return this._chatOptions.model;
24
22
  }
25
23
  render() {
26
- return (React.createElement(Chat, { model: this._model, themeManager: this._themeManager, rmRegistry: this._rmRegistry }));
24
+ // The model need to be passed, otherwise it is undefined in the widget in
25
+ // the case of collaborative document.
26
+ return React.createElement(Chat, { ...this._chatOptions, model: this._chatOptions.model });
27
27
  }
28
28
  }