@stubwise/widget 0.1.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/dist/core/api.d.ts +93 -0
- package/dist/core/dsn.d.ts +23 -0
- package/dist/core/sse.d.ts +55 -0
- package/dist/core/storage.d.ts +14 -0
- package/dist/i18n.d.ts +46 -0
- package/dist/index.d.ts +31 -0
- package/dist/stubwise-widget.iife.js +199 -0
- package/dist/stubwise-widget.js +1093 -0
- package/dist/ui/chat.d.ts +30 -0
- package/dist/ui/styles.d.ts +12 -0
- package/dist/ui/ticket-card.d.ts +16 -0
- package/dist/ui/widget.d.ts +19 -0
- package/package.json +33 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type WidgetApiBase, type WidgetUser } from "../core/api.js";
|
|
2
|
+
import { type WidgetCitation, type WidgetTicketProposal } from "../core/sse.js";
|
|
3
|
+
import type { WidgetStrings } from "../i18n.js";
|
|
4
|
+
/** Un elemento della timeline della chat. */
|
|
5
|
+
export type ChatItem = {
|
|
6
|
+
kind: "user";
|
|
7
|
+
id: string;
|
|
8
|
+
text: string;
|
|
9
|
+
} | {
|
|
10
|
+
kind: "assistant";
|
|
11
|
+
id: string;
|
|
12
|
+
text: string;
|
|
13
|
+
citations: WidgetCitation[];
|
|
14
|
+
} | {
|
|
15
|
+
kind: "ticket";
|
|
16
|
+
id: string;
|
|
17
|
+
proposal: WidgetTicketProposal;
|
|
18
|
+
};
|
|
19
|
+
export interface ChatProps {
|
|
20
|
+
base: WidgetApiBase;
|
|
21
|
+
user: WidgetUser;
|
|
22
|
+
strings: WidgetStrings;
|
|
23
|
+
/** Messaggio di benvenuto (fittizio) se non c'è storico da caricare. */
|
|
24
|
+
welcomeMessage: string;
|
|
25
|
+
/** Composer attivo solo se la chat è abilitata lato config. */
|
|
26
|
+
chatEnabled: boolean;
|
|
27
|
+
/** conversationId iniziale da storage (o null: nuova conversazione lazy). */
|
|
28
|
+
initialConversationId: string | null;
|
|
29
|
+
}
|
|
30
|
+
export declare function Chat({ base, user, strings, welcomeMessage, chatEnabled, initialConversationId, }: ChatProps): import("preact").JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS del widget come stringa, iniettato in un `<style>` dentro lo Shadow DOM.
|
|
3
|
+
* L'isolamento dello shadow root ci protegge dallo stile del sito ospite (e
|
|
4
|
+
* viceversa): non servono reset globali né `!important`. Tutte le classi sono
|
|
5
|
+
* prefissate `sw-` per chiarezza (anche se lo shadow root le confinerebbe già).
|
|
6
|
+
*
|
|
7
|
+
* Estetica: sobria, sans di sistema, un solo colore d'accento (dal config,
|
|
8
|
+
* iniettato come variabile `--sw-accent`). Nessuna dipendenza esterna.
|
|
9
|
+
*
|
|
10
|
+
* @param accentColor colore d'accento del progetto (bolla, header, bottoni).
|
|
11
|
+
*/
|
|
12
|
+
export declare function widgetStyles(accentColor: string): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { WidgetTicketProposal } from "../core/sse.js";
|
|
2
|
+
import type { WidgetStrings } from "../i18n.js";
|
|
3
|
+
export interface TicketCardProps {
|
|
4
|
+
proposal: WidgetTicketProposal;
|
|
5
|
+
strings: WidgetStrings;
|
|
6
|
+
/** Invia la segnalazione (title/body editati). Rigetta su errore → retry. */
|
|
7
|
+
onConfirm: (input: {
|
|
8
|
+
title: string;
|
|
9
|
+
body: string;
|
|
10
|
+
}) => Promise<{
|
|
11
|
+
number: number;
|
|
12
|
+
}>;
|
|
13
|
+
/** Annulla la card (rimossa dal parent). */
|
|
14
|
+
onCancel: () => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function TicketCard({ proposal, strings, onConfirm, onCancel }: TicketCardProps): import("preact").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { WidgetApiBase, WidgetConfig, WidgetUser } from "../core/api.js";
|
|
2
|
+
/** Config nella variante ATTIVA (l'unica per cui si monta la UI). */
|
|
3
|
+
type ActiveConfig = Extract<WidgetConfig, {
|
|
4
|
+
enabled: true;
|
|
5
|
+
}>;
|
|
6
|
+
export interface WidgetRootProps {
|
|
7
|
+
base: WidgetApiBase;
|
|
8
|
+
config: ActiveConfig;
|
|
9
|
+
user: WidgetUser;
|
|
10
|
+
}
|
|
11
|
+
export declare function WidgetRoot({ base, config, user }: WidgetRootProps): import("preact").JSX.Element;
|
|
12
|
+
/**
|
|
13
|
+
* Crea l'host `<div>` su `document.body`, ci attacca uno shadow root aperto con
|
|
14
|
+
* lo `<style>` del widget e renderizza {@link WidgetRoot} dentro. Ritorna l'host
|
|
15
|
+
* (per test/teardown). Isolato in questa funzione così l'entry può gestire la
|
|
16
|
+
* guardia di doppia init.
|
|
17
|
+
*/
|
|
18
|
+
export declare function mountWidget(base: WidgetApiBase, config: ActiveConfig, user: WidgetUser): HTMLElement;
|
|
19
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stubwise/widget",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/stubwise-widget.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "vite build && tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"typecheck": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"preact": "^10.29.4"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@preact/preset-vite": "^2.10.5",
|
|
28
|
+
"happy-dom": "^17.6.3",
|
|
29
|
+
"typescript": "^5.6.0",
|
|
30
|
+
"vite": "^7.0.0",
|
|
31
|
+
"vitest": "^3.2.0"
|
|
32
|
+
}
|
|
33
|
+
}
|