@hidemikimura/chit-ui 0.1.0 → 0.3.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/CHANGELOG.md +91 -0
- package/README.md +314 -11
- package/dist/chit-ui.iife.min.js +416 -94
- package/dist/chit-ui.iife.min.js.map +1 -1
- package/dist/chit-ui.min.js +407 -85
- package/dist/chit-ui.min.js.map +1 -1
- package/dist/types/bundle.d.ts +1 -0
- package/dist/types/chit-ui.d.ts +89 -4
- package/dist/types/controllers/composer-controller.d.ts +4 -0
- package/dist/types/controllers/drag-controller.d.ts +118 -0
- package/dist/types/events.d.ts +3 -0
- package/dist/types/global.d.ts +9 -1
- package/dist/types/i18n/labels.d.ts +16 -0
- package/dist/types/render/composer.d.ts +0 -1
- package/dist/types/render/message-list.d.ts +0 -1
- package/dist/types/theme/default-theme.d.ts +30 -1
- package/dist/types/themes/green.d.ts +16 -0
- package/dist/types/themes/index.d.ts +1 -0
- package/dist/types/types.d.ts +105 -4
- package/package.json +6 -1
- package/src/bundle.js +1 -0
- package/src/chit-ui.js +292 -4
- package/src/controllers/composer-controller.js +2 -0
- package/src/controllers/drag-controller.js +319 -0
- package/src/events.js +3 -0
- package/src/global.d.ts +9 -1
- package/src/i18n/labels.js +12 -0
- package/src/render/composer.js +58 -0
- package/src/render/launcher.js +9 -1
- package/src/render/message-list.js +40 -10
- package/src/render/message.js +13 -4
- package/src/render/panel.js +73 -11
- package/src/styles/composer.css.js +39 -0
- package/src/styles/host.css.js +2 -0
- package/src/styles/launcher.css.js +13 -0
- package/src/styles/message.css.js +168 -9
- package/src/styles/panel.css.js +44 -4
- package/src/theme/default-theme.js +37 -2
- package/src/theme/theme-to-css.js +5 -0
- package/src/themes/green.js +47 -0
- package/src/themes/index.js +15 -0
- package/src/types.js +38 -6
package/dist/types/bundle.d.ts
CHANGED
package/dist/types/chit-ui.d.ts
CHANGED
|
@@ -34,6 +34,12 @@ export class ChitUI extends LitElement {
|
|
|
34
34
|
};
|
|
35
35
|
typing: {
|
|
36
36
|
type: ObjectConstructor;
|
|
37
|
+
noAccessor: boolean;
|
|
38
|
+
};
|
|
39
|
+
loading: {
|
|
40
|
+
type: BooleanConstructor;
|
|
41
|
+
reflect: boolean;
|
|
42
|
+
noAccessor: boolean;
|
|
37
43
|
};
|
|
38
44
|
busy: {
|
|
39
45
|
type: BooleanConstructor;
|
|
@@ -83,10 +89,6 @@ export class ChitUI extends LitElement {
|
|
|
83
89
|
theme: Theme;
|
|
84
90
|
/** @type {Message[]} Rendered as given. The library never mutates this. */
|
|
85
91
|
messages: Message[];
|
|
86
|
-
/** @type {boolean | { html: string }} Show the "typing" bubble. */
|
|
87
|
-
typing: boolean | {
|
|
88
|
-
html: string;
|
|
89
|
-
};
|
|
90
92
|
/** @type {boolean} Lock the composer while a reply is in flight. */
|
|
91
93
|
busy: boolean;
|
|
92
94
|
/** @type {boolean} */
|
|
@@ -119,6 +121,63 @@ export class ChitUI extends LitElement {
|
|
|
119
121
|
sanitize: ((html: string) => string) | undefined;
|
|
120
122
|
/** @type {((time: Date) => string) | undefined} */
|
|
121
123
|
formatTime: ((time: Date) => string) | undefined;
|
|
124
|
+
/** The launcher's drag, for the render function to hook up. */
|
|
125
|
+
get launcherDrag(): DragController;
|
|
126
|
+
/** The panel's drag, likewise. */
|
|
127
|
+
get panelDrag(): DragController;
|
|
128
|
+
set dragOffset(value: {
|
|
129
|
+
x: number;
|
|
130
|
+
y: number;
|
|
131
|
+
} | null);
|
|
132
|
+
/**
|
|
133
|
+
* How far the reader has dragged the widget from where the theme put it, in
|
|
134
|
+
* screen pixels, or null when it is still there.
|
|
135
|
+
*
|
|
136
|
+
* There is one of these for the whole widget rather than one per state: the
|
|
137
|
+
* launcher and the panel are the same widget wearing two shapes, so moving
|
|
138
|
+
* either moves both, and the panel opens where the launcher was left.
|
|
139
|
+
*
|
|
140
|
+
* @type {{ x: number, y: number } | null}
|
|
141
|
+
*/
|
|
142
|
+
get dragOffset(): {
|
|
143
|
+
x: number;
|
|
144
|
+
y: number;
|
|
145
|
+
} | null;
|
|
146
|
+
/** Forget the dragged position and go back to what the theme says. */
|
|
147
|
+
resetPosition(): void;
|
|
148
|
+
/**
|
|
149
|
+
* The composer calls this once a submit has gone out and no listener
|
|
150
|
+
* cancelled it. Listening for `chat-submit` here instead would be wrong:
|
|
151
|
+
* this element's own listener runs before the consumer's, so it cannot see
|
|
152
|
+
* a `preventDefault()` that is still to come.
|
|
153
|
+
*
|
|
154
|
+
* @returns {void}
|
|
155
|
+
*/
|
|
156
|
+
handleSubmitted(): void;
|
|
157
|
+
set loading(value: boolean);
|
|
158
|
+
/**
|
|
159
|
+
* Show the "waiting for an answer" indicator. Turning this on turns
|
|
160
|
+
* `typing` off, for the reason given above.
|
|
161
|
+
*
|
|
162
|
+
* @type {boolean}
|
|
163
|
+
*/
|
|
164
|
+
get loading(): boolean;
|
|
165
|
+
set typing(value: boolean | {
|
|
166
|
+
html: string;
|
|
167
|
+
});
|
|
168
|
+
/**
|
|
169
|
+
* Show the "typing" bubble: `true`, or `{ html }` for your own markup.
|
|
170
|
+
*
|
|
171
|
+
* Turning this on turns `loading` off. The two describe the same pause in
|
|
172
|
+
* the conversation — one says a person is writing, the other that a server
|
|
173
|
+
* has not answered yet — and showing both would leave the reader to work
|
|
174
|
+
* out the difference.
|
|
175
|
+
*
|
|
176
|
+
* @type {boolean | { html: string }}
|
|
177
|
+
*/
|
|
178
|
+
get typing(): boolean | {
|
|
179
|
+
html: string;
|
|
180
|
+
};
|
|
122
181
|
set state(value: ChatState);
|
|
123
182
|
/**
|
|
124
183
|
* Current state. Assigning it starts the transition, exactly as calling the
|
|
@@ -213,6 +272,18 @@ export class ChitUI extends LitElement {
|
|
|
213
272
|
handleKeydown(event: KeyboardEvent): void;
|
|
214
273
|
/** @param {boolean} started */
|
|
215
274
|
handleComposition(started: boolean): void;
|
|
275
|
+
/**
|
|
276
|
+
* Report files the reader picked with the attach button.
|
|
277
|
+
*
|
|
278
|
+
* Nothing is uploaded, previewed or added to the conversation here: the
|
|
279
|
+
* widget does not own `messages` and has nowhere to send bytes.
|
|
280
|
+
*
|
|
281
|
+
* @param {File[]} files
|
|
282
|
+
* @returns {void}
|
|
283
|
+
*/
|
|
284
|
+
handleAttach(files: File[]): void;
|
|
285
|
+
/** Open the file picker from code, as the attach button does. */
|
|
286
|
+
openAttach(): void;
|
|
216
287
|
/**
|
|
217
288
|
* Render a consumer-supplied typing bubble.
|
|
218
289
|
*
|
|
@@ -234,6 +305,18 @@ export class ChitUI extends LitElement {
|
|
|
234
305
|
toggleFromUser(): Promise<boolean>;
|
|
235
306
|
/** Called by the close button and by Esc. */
|
|
236
307
|
closeFromUser(): Promise<boolean>;
|
|
308
|
+
/**
|
|
309
|
+
* Ask to start the conversation over.
|
|
310
|
+
*
|
|
311
|
+
* The widget only announces it: `messages` belongs to the consumer, so
|
|
312
|
+
* clearing it, replaying a scenario or asking for confirmation first are all
|
|
313
|
+
* theirs to do. Cancelling the event is not offered for the same reason —
|
|
314
|
+
* there is nothing here to cancel.
|
|
315
|
+
*
|
|
316
|
+
* @param {Trigger} [trigger='api']
|
|
317
|
+
* @returns {void}
|
|
318
|
+
*/
|
|
319
|
+
home(trigger?: Trigger): void;
|
|
237
320
|
/** @override */
|
|
238
321
|
override willUpdate(): void;
|
|
239
322
|
/** @override */
|
|
@@ -246,6 +329,8 @@ import { LitElement } from 'lit';
|
|
|
246
329
|
import type { Theme } from './types.js';
|
|
247
330
|
import type { Message } from './types.js';
|
|
248
331
|
import type { Labels } from './i18n/labels.js';
|
|
332
|
+
import { DragController } from './controllers/drag-controller.js';
|
|
249
333
|
import type { ChatState } from './types.js';
|
|
250
334
|
import type { Device } from './types.js';
|
|
251
335
|
import type { ResolvedTheme } from './types.js';
|
|
336
|
+
import type { Trigger } from './types.js';
|
|
@@ -49,6 +49,10 @@ export type ComposerHost = {
|
|
|
49
49
|
sendOnEnter: boolean;
|
|
50
50
|
maxLength: number | undefined;
|
|
51
51
|
currentLabels: import("../i18n/labels.js").Labels;
|
|
52
|
+
/**
|
|
53
|
+
* Called after a submit that no listener cancelled.
|
|
54
|
+
*/
|
|
55
|
+
handleSubmitted: () => void;
|
|
52
56
|
};
|
|
53
57
|
import type { ReactiveController } from 'lit';
|
|
54
58
|
import type { LitElement } from 'lit';
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moves one thing — the launcher or the panel — around the viewport.
|
|
3
|
+
*
|
|
4
|
+
* What a gesture produces is not a position but a displacement: how far the
|
|
5
|
+
* reader has dragged the widget from wherever the theme put it, in screen
|
|
6
|
+
* pixels. The host keeps one such displacement for the whole widget and hands
|
|
7
|
+
* it to both controllers, which is what makes the two states travel together:
|
|
8
|
+
* drag the launcher into a corner and the panel opens in that same corner,
|
|
9
|
+
* because both are the theme's position plus the same shift.
|
|
10
|
+
*
|
|
11
|
+
* Each controller then turns the displacement into the terms its own corner
|
|
12
|
+
* uses — at a right-hand corner, moving right means a smaller offset — and
|
|
13
|
+
* writes it into the two custom properties the stylesheet already reads. The
|
|
14
|
+
* offset lives on the host as an inline property, which outranks the theme's
|
|
15
|
+
* sheet and the page's CSS: a reader who dragged the widget somewhere means
|
|
16
|
+
* it, and until the drag is cleared theirs is the most specific word on where
|
|
17
|
+
* it goes.
|
|
18
|
+
*
|
|
19
|
+
* @implements {ReactiveController}
|
|
20
|
+
*/
|
|
21
|
+
export class DragController implements ReactiveController {
|
|
22
|
+
/**
|
|
23
|
+
* @param {LitElement} host
|
|
24
|
+
* @param {DragOptions} options
|
|
25
|
+
*/
|
|
26
|
+
constructor(host: LitElement, options: DragOptions);
|
|
27
|
+
hostConnected(): void;
|
|
28
|
+
hostDisconnected(): void;
|
|
29
|
+
/**
|
|
30
|
+
* True when the gesture that just ended was a drag. Reading it clears it, so
|
|
31
|
+
* the click a pointer-up fires can be skipped exactly once.
|
|
32
|
+
*
|
|
33
|
+
* @returns {boolean}
|
|
34
|
+
*/
|
|
35
|
+
consumeDrag(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Put this thing where the displacement says, within the viewport.
|
|
38
|
+
*
|
|
39
|
+
* @param {{ x: number, y: number } | null} displacement
|
|
40
|
+
* @returns {{ x: number, y: number } | undefined} Where it ended up, when it is on screen.
|
|
41
|
+
*/
|
|
42
|
+
place(displacement: {
|
|
43
|
+
x: number;
|
|
44
|
+
y: number;
|
|
45
|
+
} | null): {
|
|
46
|
+
x: number;
|
|
47
|
+
y: number;
|
|
48
|
+
} | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Begin a drag.
|
|
51
|
+
*
|
|
52
|
+
* @param {PointerEvent} event
|
|
53
|
+
* @returns {void}
|
|
54
|
+
*/
|
|
55
|
+
start(event: PointerEvent): void;
|
|
56
|
+
/**
|
|
57
|
+
* Move with the arrow keys, so the same thing can be done without a pointer.
|
|
58
|
+
*
|
|
59
|
+
* @param {KeyboardEvent} event
|
|
60
|
+
* @returns {boolean} True when the key was used.
|
|
61
|
+
*/
|
|
62
|
+
nudge(event: KeyboardEvent): boolean;
|
|
63
|
+
#private;
|
|
64
|
+
}
|
|
65
|
+
export type DragOptions = {
|
|
66
|
+
name: "launcher" | "panel";
|
|
67
|
+
enabled: () => boolean;
|
|
68
|
+
/**
|
|
69
|
+
* What moves.
|
|
70
|
+
*/
|
|
71
|
+
element: () => HTMLElement | null;
|
|
72
|
+
/**
|
|
73
|
+
* How big it means to be.
|
|
74
|
+
*/
|
|
75
|
+
size: () => {
|
|
76
|
+
width: number;
|
|
77
|
+
height: number;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Which corner the offset counts from.
|
|
81
|
+
*/
|
|
82
|
+
corner: () => Position;
|
|
83
|
+
/**
|
|
84
|
+
* The theme's offset, before any drag.
|
|
85
|
+
*/
|
|
86
|
+
base: () => {
|
|
87
|
+
x: number;
|
|
88
|
+
y: number;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* The widget's displacement now.
|
|
92
|
+
*/
|
|
93
|
+
current: () => {
|
|
94
|
+
x: number;
|
|
95
|
+
y: number;
|
|
96
|
+
} | null;
|
|
97
|
+
/**
|
|
98
|
+
* A new displacement.
|
|
99
|
+
*/
|
|
100
|
+
onMove: (displacement: {
|
|
101
|
+
x: number;
|
|
102
|
+
y: number;
|
|
103
|
+
}) => void;
|
|
104
|
+
/**
|
|
105
|
+
* The gesture ended here.
|
|
106
|
+
*/
|
|
107
|
+
onSettle: (name: "launcher" | "panel") => void;
|
|
108
|
+
/**
|
|
109
|
+
* The custom properties to write.
|
|
110
|
+
*/
|
|
111
|
+
vars: {
|
|
112
|
+
x: string;
|
|
113
|
+
y: string;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
import type { ReactiveController } from 'lit';
|
|
117
|
+
import type { LitElement } from 'lit';
|
|
118
|
+
import type { Position } from '../types.js';
|
package/dist/types/events.d.ts
CHANGED
package/dist/types/global.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChitUI } from './chit-ui.js';
|
|
2
|
-
import type { Message, ChatState, Trigger, Device } from './types.js';
|
|
2
|
+
import type { Message, ChatState, Trigger, Device, Position } from './types.js';
|
|
3
3
|
|
|
4
4
|
export interface ChitUIEventMap {
|
|
5
5
|
'chat-submit': CustomEvent<{ text: string }>;
|
|
@@ -15,6 +15,14 @@ export interface ChitUIEventMap {
|
|
|
15
15
|
'chat-message-click': CustomEvent<{ message: Message; target: Element; originalEvent: MouseEvent }>;
|
|
16
16
|
'chat-scroll-top': CustomEvent<Record<string, never>>;
|
|
17
17
|
'chat-breakpoint-change': CustomEvent<{ device: Device }>;
|
|
18
|
+
'chat-home': CustomEvent<{ trigger: Trigger }>;
|
|
19
|
+
'chat-attach': CustomEvent<{ files: File[] }>;
|
|
20
|
+
'chat-move': CustomEvent<{
|
|
21
|
+
target: 'launcher' | 'panel';
|
|
22
|
+
position: Position;
|
|
23
|
+
offset: { x: number; y: number };
|
|
24
|
+
displacement: { x: number; y: number };
|
|
25
|
+
}>;
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
declare global {
|
|
@@ -33,10 +33,18 @@ export type Labels = {
|
|
|
33
33
|
* Close button.
|
|
34
34
|
*/
|
|
35
35
|
close: string;
|
|
36
|
+
/**
|
|
37
|
+
* Home button: back to the start of the conversation.
|
|
38
|
+
*/
|
|
39
|
+
home: string;
|
|
36
40
|
/**
|
|
37
41
|
* Send button.
|
|
38
42
|
*/
|
|
39
43
|
send: string;
|
|
44
|
+
/**
|
|
45
|
+
* Attach button beside the composer.
|
|
46
|
+
*/
|
|
47
|
+
attach: string;
|
|
40
48
|
/**
|
|
41
49
|
* Composer textarea.
|
|
42
50
|
*/
|
|
@@ -45,6 +53,14 @@ export type Labels = {
|
|
|
45
53
|
* Announced while the other side is typing.
|
|
46
54
|
*/
|
|
47
55
|
typing: string;
|
|
56
|
+
/**
|
|
57
|
+
* Announced while waiting for an answer.
|
|
58
|
+
*/
|
|
59
|
+
loading: string;
|
|
60
|
+
/**
|
|
61
|
+
* The panel's drag handle.
|
|
62
|
+
*/
|
|
63
|
+
move: string;
|
|
48
64
|
/**
|
|
49
65
|
* "Jump to newest" button.
|
|
50
66
|
*/
|
|
@@ -19,10 +19,12 @@ export namespace defaultTheme {
|
|
|
19
19
|
}
|
|
20
20
|
let radius: number;
|
|
21
21
|
let launcher: "hidden";
|
|
22
|
+
let draggable: boolean;
|
|
22
23
|
namespace header {
|
|
24
|
+
let visible: boolean;
|
|
23
25
|
let title: null;
|
|
24
26
|
let logo: null;
|
|
25
|
-
let
|
|
27
|
+
let home: boolean;
|
|
26
28
|
}
|
|
27
29
|
namespace background {
|
|
28
30
|
let image: null;
|
|
@@ -58,6 +60,30 @@ export namespace defaultTheme {
|
|
|
58
60
|
import inputPlaceholder = PALETTE.muted;
|
|
59
61
|
export { inputPlaceholder };
|
|
60
62
|
}
|
|
63
|
+
namespace bubble {
|
|
64
|
+
let radius_1: number;
|
|
65
|
+
export { radius_1 as radius };
|
|
66
|
+
export let tail: "none";
|
|
67
|
+
}
|
|
68
|
+
namespace loading {
|
|
69
|
+
export let auto: boolean;
|
|
70
|
+
export let style: "spinner";
|
|
71
|
+
let text_1: null;
|
|
72
|
+
export { text_1 as text };
|
|
73
|
+
export let timeout: number;
|
|
74
|
+
}
|
|
75
|
+
namespace speaker {
|
|
76
|
+
namespace assistant {
|
|
77
|
+
let name: null;
|
|
78
|
+
let avatar: null;
|
|
79
|
+
}
|
|
80
|
+
namespace user {
|
|
81
|
+
let name_1: null;
|
|
82
|
+
export { name_1 as name };
|
|
83
|
+
let avatar_1: null;
|
|
84
|
+
export { avatar_1 as avatar };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
61
87
|
namespace animation {
|
|
62
88
|
let enter: "scale";
|
|
63
89
|
let exit: "fade";
|
|
@@ -67,6 +93,9 @@ export namespace defaultTheme {
|
|
|
67
93
|
namespace input {
|
|
68
94
|
let maxRows: number;
|
|
69
95
|
let placeholder: null;
|
|
96
|
+
let attach: boolean;
|
|
97
|
+
let accept: string;
|
|
98
|
+
let multiple: boolean;
|
|
70
99
|
}
|
|
71
100
|
}
|
|
72
101
|
namespace hidden {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** @import { Theme } from '../types.js' */
|
|
2
|
+
/**
|
|
3
|
+
* A green messenger look: a pale blue-grey conversation background, white
|
|
4
|
+
* bubbles for them, bright green for you, tails on the top corner.
|
|
5
|
+
*
|
|
6
|
+
* This is Chit UI's own palette in that familiar shape. It carries no other
|
|
7
|
+
* product's logo, wordmark or artwork, and the greens are Chit UI's own: the
|
|
8
|
+
* deep green is dark enough that white text and the send icon clear WCAG AA
|
|
9
|
+
* on it, which the bright green of the bubbles could not do.
|
|
10
|
+
* `test/theme.test.js` re-checks every pair here, so a later tweak cannot
|
|
11
|
+
* quietly drop below AA.
|
|
12
|
+
*
|
|
13
|
+
* @type {Theme}
|
|
14
|
+
*/
|
|
15
|
+
export const greenTheme: Theme;
|
|
16
|
+
import type { Theme } from '../types.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { greenTheme } from "./green.js";
|
package/dist/types/types.d.ts
CHANGED
|
@@ -33,6 +33,11 @@ export type Effect = "fade" | "scale" | "slide" | "none";
|
|
|
33
33
|
* every other file can `@import` from one place and so `tsc` can emit .d.ts.
|
|
34
34
|
*/
|
|
35
35
|
export type Position = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
36
|
+
/**
|
|
37
|
+
* Public types for Chit UI. This module has no runtime value; it exists so that
|
|
38
|
+
* every other file can `@import` from one place and so `tsc` can emit .d.ts.
|
|
39
|
+
*/
|
|
40
|
+
export type BubbleTail = "none" | "top" | "bottom";
|
|
36
41
|
export type MessageBase = {
|
|
37
42
|
/**
|
|
38
43
|
* Unique within the array; used as the diffing key.
|
|
@@ -40,8 +45,14 @@ export type MessageBase = {
|
|
|
40
45
|
id: string;
|
|
41
46
|
role: Role;
|
|
42
47
|
time?: string | Date | undefined;
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Overrides the theme's speaker name; null hides it.
|
|
50
|
+
*/
|
|
51
|
+
name?: string | null | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Overrides the theme's speaker image; null hides it.
|
|
54
|
+
*/
|
|
55
|
+
avatar?: string | null | undefined;
|
|
45
56
|
status?: MessageStatus | undefined;
|
|
46
57
|
streaming?: boolean | undefined;
|
|
47
58
|
/**
|
|
@@ -91,6 +102,10 @@ export type ClosedTheme = {
|
|
|
91
102
|
*/
|
|
92
103
|
image?: string | null | undefined;
|
|
93
104
|
label?: string | null | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Let the reader move it around the viewport.
|
|
107
|
+
*/
|
|
108
|
+
draggable?: boolean | undefined;
|
|
94
109
|
/**
|
|
95
110
|
* A component that draws the whole launcher.
|
|
96
111
|
*/
|
|
@@ -108,6 +123,45 @@ export type ClosedTheme = {
|
|
|
108
123
|
idle?: "none" | "pulse" | "bounce";
|
|
109
124
|
}) | undefined;
|
|
110
125
|
};
|
|
126
|
+
/**
|
|
127
|
+
* The wait between sending and the answer arriving.
|
|
128
|
+
*/
|
|
129
|
+
export type LoadingStyle = "dots" | "spinner" | "text";
|
|
130
|
+
/**
|
|
131
|
+
* The wait between sending and the answer arriving.
|
|
132
|
+
*/
|
|
133
|
+
export type LoadingTheme = {
|
|
134
|
+
/**
|
|
135
|
+
* Show it from `chat-submit` until the next message from the other side.
|
|
136
|
+
*/
|
|
137
|
+
auto?: boolean | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* What it looks like.
|
|
140
|
+
*/
|
|
141
|
+
style?: LoadingStyle | undefined;
|
|
142
|
+
/**
|
|
143
|
+
* Wording beside the animation, or on its own for `'text'`.
|
|
144
|
+
*/
|
|
145
|
+
text?: string | null | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* ms after which it gives up on its own; 0 leaves it to the consumer.
|
|
148
|
+
*/
|
|
149
|
+
timeout?: number | undefined;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Who is talking, as the theme describes them. A message that carries its own
|
|
153
|
+
* `name` or `avatar` wins; `null` on the message hides what the theme set.
|
|
154
|
+
*/
|
|
155
|
+
export type SpeakerTheme = {
|
|
156
|
+
/**
|
|
157
|
+
* Shown above the bubble.
|
|
158
|
+
*/
|
|
159
|
+
name?: string | null | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* Image URL for the speaker's icon.
|
|
162
|
+
*/
|
|
163
|
+
avatar?: string | null | undefined;
|
|
164
|
+
};
|
|
111
165
|
export type OpenColors = {
|
|
112
166
|
background?: string | undefined;
|
|
113
167
|
text?: string | undefined;
|
|
@@ -141,21 +195,53 @@ export type OpenTheme = {
|
|
|
141
195
|
* Keep the launcher visible while open.
|
|
142
196
|
*/
|
|
143
197
|
launcher?: "hidden" | "visible" | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* Let the reader move the panel by its title bar.
|
|
200
|
+
*/
|
|
201
|
+
draggable?: boolean | undefined;
|
|
202
|
+
/**
|
|
203
|
+
* The title bar: whether it is there at all, its text, its image, and whether it offers a way back to the start.
|
|
204
|
+
*/
|
|
144
205
|
header?: {
|
|
206
|
+
visible?: boolean;
|
|
145
207
|
title?: string | null;
|
|
146
208
|
logo?: string | null;
|
|
147
|
-
|
|
209
|
+
home?: boolean;
|
|
148
210
|
} | undefined;
|
|
149
211
|
background?: {
|
|
150
212
|
image?: string | null;
|
|
151
213
|
} | undefined;
|
|
152
214
|
colors?: OpenColors | undefined;
|
|
215
|
+
/**
|
|
216
|
+
* Bubble corner radius, and where the tail points from.
|
|
217
|
+
*/
|
|
218
|
+
bubble?: {
|
|
219
|
+
radius?: number;
|
|
220
|
+
tail?: BubbleTail;
|
|
221
|
+
} | undefined;
|
|
222
|
+
/**
|
|
223
|
+
* Default name and icon per side.
|
|
224
|
+
*/
|
|
225
|
+
speaker?: {
|
|
226
|
+
assistant?: SpeakerTheme;
|
|
227
|
+
user?: SpeakerTheme;
|
|
228
|
+
} | undefined;
|
|
229
|
+
/**
|
|
230
|
+
* The wait for an answer.
|
|
231
|
+
*/
|
|
232
|
+
loading?: LoadingTheme | undefined;
|
|
153
233
|
animation?: (Animation & {
|
|
154
234
|
scroll?: "smooth" | "instant";
|
|
155
235
|
}) | undefined;
|
|
236
|
+
/**
|
|
237
|
+
* Composer: rows, placeholder, and the attach button.
|
|
238
|
+
*/
|
|
156
239
|
input?: {
|
|
157
240
|
maxRows?: number;
|
|
158
241
|
placeholder?: string | null;
|
|
242
|
+
attach?: boolean;
|
|
243
|
+
accept?: string;
|
|
244
|
+
multiple?: boolean;
|
|
159
245
|
} | undefined;
|
|
160
246
|
};
|
|
161
247
|
export type Theme = {
|
|
@@ -192,6 +278,7 @@ export type ResolvedClosed = {
|
|
|
192
278
|
y: number;
|
|
193
279
|
};
|
|
194
280
|
radius: number;
|
|
281
|
+
draggable: boolean;
|
|
195
282
|
image: string | null;
|
|
196
283
|
label: string | null;
|
|
197
284
|
component: (new () => HTMLElement) | string | null;
|
|
@@ -222,15 +309,26 @@ export type ResolvedOpen = {
|
|
|
222
309
|
};
|
|
223
310
|
radius: number;
|
|
224
311
|
launcher: "hidden" | "visible";
|
|
312
|
+
draggable: boolean;
|
|
225
313
|
header: {
|
|
314
|
+
visible: boolean;
|
|
226
315
|
title: string | null;
|
|
227
316
|
logo: string | null;
|
|
228
|
-
|
|
317
|
+
home: boolean;
|
|
229
318
|
};
|
|
230
319
|
background: {
|
|
231
320
|
image: string | null;
|
|
232
321
|
};
|
|
233
322
|
colors: Required<OpenColors>;
|
|
323
|
+
bubble: {
|
|
324
|
+
radius: number;
|
|
325
|
+
tail: BubbleTail;
|
|
326
|
+
};
|
|
327
|
+
speaker: {
|
|
328
|
+
assistant: Required<SpeakerTheme>;
|
|
329
|
+
user: Required<SpeakerTheme>;
|
|
330
|
+
};
|
|
331
|
+
loading: Required<LoadingTheme>;
|
|
234
332
|
animation: {
|
|
235
333
|
enter: Effect;
|
|
236
334
|
exit: Effect;
|
|
@@ -240,6 +338,9 @@ export type ResolvedOpen = {
|
|
|
240
338
|
input: {
|
|
241
339
|
maxRows: number;
|
|
242
340
|
placeholder: string | null;
|
|
341
|
+
attach: boolean;
|
|
342
|
+
accept: string;
|
|
343
|
+
multiple: boolean;
|
|
243
344
|
};
|
|
244
345
|
};
|
|
245
346
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hidemikimura/chit-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Lit-based chat widget UI: launcher, panel, themable, any HTML or Lit component as a message",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Hidemi Kimura",
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"types": "./dist/types/element.d.ts",
|
|
17
17
|
"default": "./src/element.js"
|
|
18
18
|
},
|
|
19
|
+
"./themes.js": {
|
|
20
|
+
"types": "./dist/types/themes/index.d.ts",
|
|
21
|
+
"default": "./src/themes/index.js"
|
|
22
|
+
},
|
|
19
23
|
"./dist/*": "./dist/*",
|
|
20
24
|
"./package.json": "./package.json"
|
|
21
25
|
},
|
|
@@ -23,6 +27,7 @@
|
|
|
23
27
|
"src",
|
|
24
28
|
"dist",
|
|
25
29
|
"README.md",
|
|
30
|
+
"CHANGELOG.md",
|
|
26
31
|
"LICENSE"
|
|
27
32
|
],
|
|
28
33
|
"sideEffects": [
|
package/src/bundle.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// against, so consumers of the bundle define their message components with the
|
|
4
4
|
// very same Lit instance.
|
|
5
5
|
export * from './index.js';
|
|
6
|
+
export * from './themes/index.js';
|
|
6
7
|
export { LitElement, html, css, svg, nothing, render } from 'lit';
|
|
7
8
|
export { repeat } from 'lit/directives/repeat.js';
|
|
8
9
|
export { unsafeHTML } from 'lit/directives/unsafe-html.js';
|