@dinghy-chat/widget 0.16.0 → 0.18.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/README.md CHANGED
@@ -21,7 +21,7 @@ const dinghy = init({ url: "https://chat.example.com", key: "YOUR_PUBLIC_KEY" })
21
21
  dinghy.on("unread", (count) => console.log(count));
22
22
  ```
23
23
 
24
- `init` adds the tag once and returns the typed `Dinghy` object. Calls made before the script loads wait for it. It takes `url`, `key`, and `primary`, `accent`, `mascot`, `launcher`, `position`, `offsetX`, `offsetY` and `zIndex`.
24
+ `init` adds the tag once and returns the typed `Dinghy` object. Calls made before the script loads wait for it. It takes `url`, `key`, and `primary`, `accent`, `mascot`, `branding`, `launcher`, `position`, `offsetX`, `offsetY` and `zIndex`.
25
25
 
26
26
  ## Attributes
27
27
 
package/dist/index.d.ts CHANGED
@@ -3,10 +3,12 @@ export type { Appearance, DinghyApi, DinghyEvent, DinghyEvents, DinghyState, Ide
3
3
  export interface InitOptions extends Appearance {
4
4
  /** Your Dinghy server, such as `https://chat.example.com`. */
5
5
  url: string;
6
- /** The workspace's public key, from Settings > Widget snippet. */
6
+ /** The workspace's public key, from Settings > Install. */
7
7
  key: string;
8
- /** False removes the boat. Every state keeps its text. */
8
+ /** Hides or shows the boat in the open chat, over the saved setting. Every state keeps its text. */
9
9
  mascot?: boolean;
10
+ /** Hides or shows the "Powered by Dinghy" line, over the saved setting. */
11
+ branding?: boolean;
10
12
  /** False hides the launcher, so your own button opens the chat. */
11
13
  launcher?: boolean;
12
14
  }
package/dist/index.js CHANGED
@@ -58,7 +58,8 @@ function init(options) {
58
58
  ["position", options.position],
59
59
  ["offset-x", options.offsetX],
60
60
  ["offset-y", options.offsetY],
61
- ["mascot", options.mascot === false ? "false" : void 0],
61
+ ["mascot", options.mascot === void 0 ? void 0 : String(options.mascot)],
62
+ ["branding", options.branding === void 0 ? void 0 : String(options.branding)],
62
63
  ["launcher", options.launcher === false ? "hidden" : void 0]
63
64
  ];
64
65
  for (const [name, value] of attributes) {
package/dist/shared.d.ts CHANGED
@@ -17,6 +17,63 @@ export interface Appearance {
17
17
  offsetY?: number;
18
18
  zIndex?: number;
19
19
  }
20
+ /** What an owner saves in the operator app's Widget tab. Null texts and colors mean the widget's own. */
21
+ export interface WidgetSettings {
22
+ title: string | null;
23
+ greeting: string | null;
24
+ away: string | null;
25
+ /** A full hex color, as `primary` in configure(). */
26
+ primary: string | null;
27
+ accent: string | null;
28
+ position: "left" | "right";
29
+ theme: "light" | "dark" | "auto";
30
+ launcher: "bubble" | "label" | "square" | "boat" | "hidden";
31
+ /** The boat in the open chat. */
32
+ mascot: boolean;
33
+ /** Pixels, for the chat's corners and the launcher's. */
34
+ radius: number;
35
+ emailAsk: "off" | "after_first" | "before_first";
36
+ /** The "Powered by Dinghy" line. */
37
+ branding: boolean;
38
+ }
39
+ /** A member the widget's header shows: a first name and a picture, never an email. */
40
+ export interface TeamFace {
41
+ /** A hash of the operator's ID, the same as `authorId` on their replies. It tells two members
42
+ * with one first name apart. */
43
+ id: string;
44
+ name: string;
45
+ pictureUrl: string | null;
46
+ }
47
+ /** The saved settings, as the widget's appearance route answers them. */
48
+ export interface SavedAppearance extends WidgetSettings {
49
+ logoUrl: string | null;
50
+ /** Up to 3 members, the ones who sent the latest replies. */
51
+ team: TeamFace[];
52
+ }
53
+ /** The longest title an owner can save. */
54
+ export declare const TITLE_MAX = 40;
55
+ /** The longest greeting or away text. */
56
+ export declare const TEXT_MAX = 200;
57
+ /** The roundest corners an owner can save. */
58
+ export declare const RADIUS_MAX_PX = 24;
59
+ /** The widget's own colors, which a null color in the settings keeps. */
60
+ export declare const DEFAULT_COLORS: {
61
+ primary: string;
62
+ accent: string;
63
+ };
64
+ /** What a new workspace saves, and what the widget shows when the server cannot answer. */
65
+ export declare const WIDGET_DEFAULTS: SavedAppearance;
66
+ /**
67
+ * The first word of a name, which is all a visitor learns of an operator. It stops at an @ too, so
68
+ * a name typed as an email never shows one.
69
+ */
70
+ export declare const firstName: (name: string) => string;
71
+ /**
72
+ * Asks for the saved settings, once a page. Null means the workspace serves no widget, and
73
+ * undefined that the server gave no answer, so WIDGET_DEFAULTS apply. The loader has no bytes for
74
+ * that object, so it leaves those values to its CSS, which holds the same ones.
75
+ */
76
+ export declare const loadAppearance: (base: string, publicKey: string) => Promise<SavedAppearance | null | undefined>;
20
77
  export interface DinghyState {
21
78
  /** The chat bundle has loaded. */
22
79
  ready: boolean;
@@ -71,13 +128,23 @@ interface ChatHandlers {
71
128
  export type Listeners = {
72
129
  [E in DinghyEvent]?: Set<(data: DinghyEvents[E]) => void>;
73
130
  };
131
+ /**
132
+ * The shape of WidgetContext. Bump it in any change to what the loader or page.js hands the chat
133
+ * bundle: a tab keeps the loader it started with for days, and the chat bundle replaces a loader
134
+ * with another number instead of reading a context it does not know.
135
+ */
136
+ export declare const CONTEXT_VERSION = 1;
74
137
  /** What the loader hands to the chat bundle. */
75
138
  export interface WidgetContext {
139
+ /** CONTEXT_VERSION, as the loader knew it. Loaders before it set none. */
140
+ version: number;
76
141
  publicKey: string;
77
142
  base: string;
78
143
  shadow: ShadowRoot;
79
- /** False when the page set data-mascot="false". Every state still has its text. */
80
- mascot: boolean;
144
+ /** The saved settings, which the loader asked for. See loadAppearance. */
145
+ appearance: Promise<SavedAppearance | null | undefined>;
146
+ /** Reads the tag's data attributes by dataset name, such as `mascot`. They win over the saved settings. */
147
+ attribute(name: string): string | undefined;
81
148
  /** The full-page chat that a reply email opens, on the Dinghy server's own origin. */
82
149
  page?: boolean;
83
150
  /** Set by identify() and cleared by reset(). */
@@ -100,8 +167,9 @@ export declare function writeToken(publicKey: string, token: string | null): voi
100
167
  export declare function wasOpen(publicKey: string): boolean;
101
168
  export declare function rememberOpen(publicKey: string, open: boolean): void;
102
169
  /**
103
- * Tells other tabs of this site to start again. A storage event fires only in other tabs. The key
104
- * goes at once, so nothing stays stored for a visitor who never chatted.
170
+ * Clears this browser's token, and tells other tabs of this site to start again. A storage event
171
+ * fires only in other tabs. The key goes at once, so nothing stays stored for a visitor who never
172
+ * chatted.
105
173
  */
106
- export declare function broadcastReset(publicKey: string): void;
174
+ export declare function forgetVisitor(publicKey: string): void;
107
175
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dinghy-chat/widget",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "description": "Add the Dinghy chat to your site from code, with a typed API.",
5
5
  "type": "module",
6
6
  "license": "MIT",