pisi-chat 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +186 -2
- package/dist/ChatBotWidgetProps-C0EUr3Gl.d.ts +42 -0
- package/dist/WidgetCartesianChart-J6WM7ROR.js +9 -0
- package/dist/WidgetCartesianChart-J6WM7ROR.js.map +1 -0
- package/dist/WidgetChart-A4OPP2NO.js +10 -0
- package/dist/WidgetChart-A4OPP2NO.js.map +1 -0
- package/dist/WidgetExtended-A6FOBXPQ.js +11 -0
- package/dist/WidgetExtended-A6FOBXPQ.js.map +1 -0
- package/dist/WidgetExtended-BjBnDLTd.d.ts +6 -0
- package/dist/WidgetMap-OMBGFVSQ.js +59 -0
- package/dist/WidgetMap-OMBGFVSQ.js.map +1 -0
- package/dist/WidgetPieFamilyChart-XZWHJ76R.js +80 -0
- package/dist/WidgetPieFamilyChart-XZWHJ76R.js.map +1 -0
- package/dist/WidgetTable-7MMRGABL.js +10 -0
- package/dist/WidgetTable-7MMRGABL.js.map +1 -0
- package/dist/chunk-55ZDBSRQ.js +223 -0
- package/dist/chunk-55ZDBSRQ.js.map +1 -0
- package/dist/chunk-5DRH5VAQ.js +218 -0
- package/dist/chunk-5DRH5VAQ.js.map +1 -0
- package/dist/chunk-62LGFKIX.js +16 -0
- package/dist/chunk-62LGFKIX.js.map +1 -0
- package/dist/chunk-7K3QOGUA.js +48 -0
- package/dist/chunk-7K3QOGUA.js.map +1 -0
- package/dist/chunk-7XYLDQOR.js +160 -0
- package/dist/chunk-7XYLDQOR.js.map +1 -0
- package/dist/chunk-DASZHJLU.js +7 -0
- package/dist/chunk-DASZHJLU.js.map +1 -0
- package/dist/chunk-LO7TH6UM.js +514 -0
- package/dist/chunk-LO7TH6UM.js.map +1 -0
- package/dist/chunk-MHD5BG24.js +127 -0
- package/dist/chunk-MHD5BG24.js.map +1 -0
- package/dist/chunk-OG3SZEEF.js +134 -0
- package/dist/chunk-OG3SZEEF.js.map +1 -0
- package/dist/chunk-PT7KG65Z.js +1034 -0
- package/dist/chunk-PT7KG65Z.js.map +1 -0
- package/dist/chunk-SQGGEQY2.js +560 -0
- package/dist/chunk-SQGGEQY2.js.map +1 -0
- package/dist/chunk-UM34WSLK.js +8627 -0
- package/dist/chunk-UM34WSLK.js.map +1 -0
- package/dist/index-Bpy0g9oj.d.ts +553 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.global.js +584 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +537 -0
- package/dist/react/index.global.js +76825 -0
- package/dist/react/index.global.js.map +1 -0
- package/dist/react/index.js +54 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/preview.d.ts +20 -0
- package/dist/react/preview.global.js +75377 -0
- package/dist/react/preview.global.js.map +1 -0
- package/dist/react/preview.js +79 -0
- package/dist/react/preview.js.map +1 -0
- package/dist/widget.d.ts +17 -0
- package/dist/widget.global.js +90741 -0
- package/dist/widget.global.js.map +1 -0
- package/dist/widget.js +107 -0
- package/dist/widget.js.map +1 -0
- package/package.json +100 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PiChain Innovations Pvt Ltd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,187 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pisi-chat
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A chat widget and React toolkit for PiSi AI agents. Embed a chat assistant on any website with one script tag, or build your own UI with the React components and hooks.
|
|
4
|
+
|
|
5
|
+
- Streaming answers with live activity indicators
|
|
6
|
+
- Rich replies: markdown, tables, charts, maps, and interactive widgets
|
|
7
|
+
- Suggested prompts, date pickers, option pickers, and file uploads
|
|
8
|
+
- Chat history, feedback, and a themeable interface
|
|
9
|
+
- Optional user-mode agents that authenticate end users with a short-lived token
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install pisi-chat
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The React entry point also needs `react` and `react-dom` (18 or newer). npm installs the other peer dependencies automatically; see `package.json` for the list.
|
|
18
|
+
|
|
19
|
+
## Quick start: script tag
|
|
20
|
+
|
|
21
|
+
The package ships the browser bundle at `dist/widget.global.js`. Serve it from your own origin, then initialise the widget:
|
|
22
|
+
|
|
23
|
+
```html
|
|
24
|
+
<script src="/assets/pisi-chat/widget.global.js"></script>
|
|
25
|
+
<script>
|
|
26
|
+
window.PiSiChatBot.init({
|
|
27
|
+
apiKey: "YOUR_API_KEY",
|
|
28
|
+
agentId: "YOUR_AGENT_ID",
|
|
29
|
+
title: "PiSi Assistant",
|
|
30
|
+
panelMode: "normal",
|
|
31
|
+
onReady: function () {
|
|
32
|
+
console.log("PiSi chat ready");
|
|
33
|
+
},
|
|
34
|
+
onInitError: function (error) {
|
|
35
|
+
console.error("PiSi chat failed to start", error);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
</script>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`panelMode` controls the layout. Use `"normal"` for a launcher in the bottom-right corner, or `"island"` for a centred launcher at the bottom of the page. The other modes are `"sidebar"` and `"fullscreen"`.
|
|
42
|
+
|
|
43
|
+
`init` validates `apiKey` and `agentId` and calls `onInitError` if either is missing or rejected. `window.PiSiChatBot.getStatus()` reports whether a widget is mounted.
|
|
44
|
+
|
|
45
|
+
> **Keep API keys safe.** The browser bundle sends your `apiKey` from the page, so anyone who can view the page can read it. Use a key that is scoped to the agent and to the sites that embed it, and rotate it if it leaks. For authenticated experiences, use user-mode agents (below).
|
|
46
|
+
|
|
47
|
+
## Quick start: React
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { ChatBotWidget } from "pisi-chat/react";
|
|
51
|
+
|
|
52
|
+
export function Assistant() {
|
|
53
|
+
return (
|
|
54
|
+
<ChatBotWidget
|
|
55
|
+
apiKey="YOUR_API_KEY"
|
|
56
|
+
agentId="YOUR_AGENT_ID"
|
|
57
|
+
title="PiSi Assistant"
|
|
58
|
+
panelMode="normal"
|
|
59
|
+
/>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
To build your own interface, use the `useChatBot` hook from `pisi-chat/react`. It manages the conversation, streaming state, and history for you.
|
|
65
|
+
|
|
66
|
+
## Options
|
|
67
|
+
|
|
68
|
+
These options apply to both `init` (script tag) and `<ChatBotWidget>` (React).
|
|
69
|
+
|
|
70
|
+
| Option | Required | Description |
|
|
71
|
+
| --- | --- | --- |
|
|
72
|
+
| `apiKey` | yes | Your PiSi API key. |
|
|
73
|
+
| `agentId` | yes | The agent that answers the chat. |
|
|
74
|
+
| `title` | no | Title shown in the chat header. |
|
|
75
|
+
| `userId` | no | Stable identifier for the end user, used to keep each user's history separate. |
|
|
76
|
+
| `userToken` | no | Short-lived token for user-mode agents. See below. |
|
|
77
|
+
| `baseUrl` | no | Chat service URL. Defaults to the PiSi hosted service. |
|
|
78
|
+
| `chatId` | no | Resume an existing chat. |
|
|
79
|
+
| `panelMode` | no | `"normal"`, `"sidebar"`, `"island"`, or `"fullscreen"`. |
|
|
80
|
+
| `theme` | no | Visual overrides. See [Theming](#theming). |
|
|
81
|
+
| `persistence` | no | Remember the open state and chat in the browser. On by default, in `localStorage` for 7 days. See [Privacy and data](#privacy-and-data). |
|
|
82
|
+
| `onReady` | no | Called when the widget is ready. |
|
|
83
|
+
| `onInitError` | no | Called with an `Error` if initialisation fails. |
|
|
84
|
+
| `onChatId` | no | Called when a new chat is created. |
|
|
85
|
+
| `onStreamingComplete` | no | Called with the final reply, message id, and any action items. |
|
|
86
|
+
|
|
87
|
+
The script-tag `init` call returns a handle with `update(newProps)` and `unmount()`. Use `update` to change options at runtime, for example to refresh a token:
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
const handle = window.PiSiChatBot.init({ apiKey, agentId });
|
|
91
|
+
handle.update({ userToken: newToken });
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## User-mode agents
|
|
95
|
+
|
|
96
|
+
User-mode agents require each end user to be signed in. Authentication happens on your backend; the browser only receives a short-lived token.
|
|
97
|
+
|
|
98
|
+
1. **Create or update the user** on the chat service with a stable `externalId` (your portal's user ID). Call this after every login; it is safe to repeat.
|
|
99
|
+
`POST <CHAT_SERVICE_URL>/users` with header `KAI-API-KEY` and body `{ "externalId", "name", "email" }`.
|
|
100
|
+
2. **Request a token:** `POST <CHAT_SERVICE_URL>/users/{externalId}/token` (URL-encode the ID).
|
|
101
|
+
3. **Return only** `accessToken` and `externalId` to the browser. Never return refresh tokens, internal user IDs, or your API key.
|
|
102
|
+
4. **Start the widget** with the token and user ID:
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
window.PiSiChatBot.init({
|
|
106
|
+
apiKey: "YOUR_API_KEY",
|
|
107
|
+
agentId: "YOUR_USER_MODE_AGENT_ID",
|
|
108
|
+
userToken: credentials.accessToken,
|
|
109
|
+
userId: credentials.externalId
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The SDK sends the token as the `KAI-USER-TOKEN` header on every protected request.
|
|
114
|
+
|
|
115
|
+
**Renewal and logout**
|
|
116
|
+
|
|
117
|
+
- Renew the token with `handle.update({ userToken, userId })` before it expires. If a request returns `401`, renew once; if that fails, unmount and ask the user to sign in again.
|
|
118
|
+
- On logout, call `handle.unmount()`. Never reuse a widget instance for a different user.
|
|
119
|
+
- Use a separate agent ID and widget instance for any public (pre-login) assistant.
|
|
120
|
+
|
|
121
|
+
## Privacy and data
|
|
122
|
+
|
|
123
|
+
- **Client context.** On the first message of a chat, the SDK sends technical context: browser, OS, device type, screen size, language, timezone, referrer, page URL, UTM parameters, and SDK version. Mention this in your privacy notice, and keep personal data out of page URLs and UTM parameters.
|
|
124
|
+
- **Browser storage.** By default the SDK keeps the current chat in `localStorage` for 7 days. For signed-in users, use session storage and always set `userId`:
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
persistence: { enabled: true, storage: "session", ttlMs: 604800000, persistOpen: true }
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Browser storage only controls what the device keeps. Server-side retention is governed by your agreement with PiSi.
|
|
131
|
+
|
|
132
|
+
## Security
|
|
133
|
+
|
|
134
|
+
- The `apiKey` is visible to anyone who can view the page. Scope it to the agent and the sites that embed it, and rotate it if it leaks.
|
|
135
|
+
- Mint and renew user tokens only on your backend. Protect the token endpoint with login, rate limiting, and `Cache-Control: no-store`.
|
|
136
|
+
- Never put tokens in URLs, logs, analytics, or browser storage. `userId` separates browser storage; it does not authenticate anyone.
|
|
137
|
+
- A valid token identifies the user but does not restrict data. Any connector that returns private records must enforce authorization for that user.
|
|
138
|
+
|
|
139
|
+
## Theming
|
|
140
|
+
|
|
141
|
+
Pass a `theme` object to override any part of the default look. Overrides are merged with the defaults, so you only need to set what you want to change.
|
|
142
|
+
|
|
143
|
+
```tsx
|
|
144
|
+
import { ChatBotWidget } from "pisi-chat/react";
|
|
145
|
+
|
|
146
|
+
const theme = {
|
|
147
|
+
primaryColor: "#4b2c5a",
|
|
148
|
+
secondaryColor: "#f3e8ff",
|
|
149
|
+
primaryButtonColor: "#8f5cf3",
|
|
150
|
+
chatButton: {
|
|
151
|
+
background: "#8f5cf3",
|
|
152
|
+
color: "#ffffff",
|
|
153
|
+
text: "Chat",
|
|
154
|
+
},
|
|
155
|
+
header: {
|
|
156
|
+
logo: "/brand/logo.svg",
|
|
157
|
+
title: { text: "Your Brand", color: "#4b2c5a" },
|
|
158
|
+
},
|
|
159
|
+
suggestions: {
|
|
160
|
+
heading: "Try asking",
|
|
161
|
+
items: ["What can you help with?", "Show me a summary"],
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
<ChatBotWidget apiKey="YOUR_API_KEY" agentId="YOUR_AGENT_ID" theme={theme} />;
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
The full set of theme fields is defined by the `ChatThemeOverrides` type, exported from `pisi-chat/react`. Your editor will show the available keys with descriptions.
|
|
169
|
+
|
|
170
|
+
If the agent is configured on the PiSi service, its title, logo, banners, and starter prompts load from the server. Server values take precedence over embed theme values where they overlap.
|
|
171
|
+
|
|
172
|
+
## Activity phrases
|
|
173
|
+
|
|
174
|
+
While the agent works on an answer, the widget cycles through status phrases such as "is checking details...". Phrases can come from the agent configuration or from the theme. Activity stops as soon as answer text or a widget arrives. The widget respects the user's reduced-motion setting.
|
|
175
|
+
|
|
176
|
+
## Development
|
|
177
|
+
|
|
178
|
+
```sh
|
|
179
|
+
npm install
|
|
180
|
+
npm run build # builds dist/
|
|
181
|
+
npm test # runs the test suite
|
|
182
|
+
npm run typecheck # TypeScript check
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
MIT. Copyright (c) 2026 PiChain Innovations Pvt Ltd.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { A as ActionItem, a as ChatThemeOverrides } from './index-Bpy0g9oj.js';
|
|
2
|
+
|
|
3
|
+
type ChatWidgetMode = "normal" | "sidebar" | "island" | "fullscreen";
|
|
4
|
+
type ChatPersistenceOptions = {
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
storage?: "local" | "session";
|
|
7
|
+
ttlMs?: number;
|
|
8
|
+
key?: string;
|
|
9
|
+
persistOpen?: boolean;
|
|
10
|
+
};
|
|
11
|
+
interface ChatBotWidgetProps {
|
|
12
|
+
title?: string;
|
|
13
|
+
userId?: string;
|
|
14
|
+
apiKey: string;
|
|
15
|
+
agentId: string;
|
|
16
|
+
/** Short-lived PiSi integration-user token for user-mode agents. */
|
|
17
|
+
userToken?: string;
|
|
18
|
+
persona?: string;
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
chatId?: string | null;
|
|
21
|
+
query?: string | null;
|
|
22
|
+
textSelections?: Array<{
|
|
23
|
+
text: string;
|
|
24
|
+
page?: number;
|
|
25
|
+
meta?: unknown;
|
|
26
|
+
}> | null;
|
|
27
|
+
fileUploads?: Array<{
|
|
28
|
+
file_name: string;
|
|
29
|
+
file_type: string;
|
|
30
|
+
gcs_uri: string;
|
|
31
|
+
signed_url?: string | null;
|
|
32
|
+
}> | null;
|
|
33
|
+
onChatId?: (id: string) => void;
|
|
34
|
+
onReady?: (payload?: unknown) => void;
|
|
35
|
+
onInitError?: (error: Error) => void;
|
|
36
|
+
onStreamingComplete?: (aiResponse?: string, messageId?: string, actionItems?: ActionItem[]) => void;
|
|
37
|
+
theme?: ChatThemeOverrides;
|
|
38
|
+
persistence?: boolean | ChatPersistenceOptions;
|
|
39
|
+
panelMode?: ChatWidgetMode;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type { ChatBotWidgetProps as C, ChatWidgetMode as a };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WidgetExtended,
|
|
3
|
+
configureWidgetResourceLoader
|
|
4
|
+
} from "./chunk-55ZDBSRQ.js";
|
|
5
|
+
import "./chunk-DASZHJLU.js";
|
|
6
|
+
import "./chunk-62LGFKIX.js";
|
|
7
|
+
export {
|
|
8
|
+
configureWidgetResourceLoader,
|
|
9
|
+
WidgetExtended as default
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=WidgetExtended-A6FOBXPQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type WidgetPayload = Record<string, unknown>;
|
|
2
|
+
type WidgetResourceLoader = (type: "docs" | "invoice" | "live_auction", id: string, signal: AbortSignal) => Promise<WidgetPayload>;
|
|
3
|
+
declare function configureWidgetResourceLoader(loader?: WidgetResourceLoader): void;
|
|
4
|
+
|
|
5
|
+
export { configureWidgetResourceLoader as c };
|
|
6
|
+
export type { WidgetResourceLoader as W };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useWidgetStyles
|
|
3
|
+
} from "./chunk-62LGFKIX.js";
|
|
4
|
+
|
|
5
|
+
// src/react/components/widgets/WidgetMap.tsx
|
|
6
|
+
import { useEffect, useRef, useState } from "react";
|
|
7
|
+
import leafletCss from "leaflet/dist/leaflet.css?inline";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
var colors = { vehicle: "#2563eb", origin: "#16a34a", destination: "#dc2626", stop: "#f59e0b", hub: "#7c3aed" };
|
|
10
|
+
function WidgetMap({ widget }) {
|
|
11
|
+
const containerRef = useRef(null);
|
|
12
|
+
const [error, setError] = useState(false);
|
|
13
|
+
useWidgetStyles("pisi-leaflet-styles", leafletCss);
|
|
14
|
+
const markers = Array.isArray(widget.markers) ? widget.markers.filter((m) => Number.isFinite(m.lat) && Number.isFinite(m.lng)) : [];
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const container = containerRef.current;
|
|
17
|
+
if (!container || !markers.length) return;
|
|
18
|
+
let disposed = false;
|
|
19
|
+
let map;
|
|
20
|
+
setError(false);
|
|
21
|
+
void import("leaflet").then((module) => {
|
|
22
|
+
if (disposed) return;
|
|
23
|
+
const L = module.default ?? module;
|
|
24
|
+
map = L.map(container, { scrollWheelZoom: false }).setView([markers[0].lat, markers[0].lng], 9);
|
|
25
|
+
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
|
26
|
+
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
|
27
|
+
}).addTo(map);
|
|
28
|
+
if (Array.isArray(widget.route) && widget.route.length > 1) L.polyline(widget.route, { color: "#2563eb", weight: 3 }).addTo(map);
|
|
29
|
+
for (const marker of markers) {
|
|
30
|
+
const color = colors[marker.kind ?? "stop"] ?? "#334155";
|
|
31
|
+
const icon = L.divIcon({
|
|
32
|
+
className: "",
|
|
33
|
+
iconSize: [26, 26],
|
|
34
|
+
iconAnchor: [13, 26],
|
|
35
|
+
html: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="26" height="26" fill="${color}"><path d="M12 2C7.6 2 4 5.6 4 10c0 6 8 12 8 12s8-6 8-12c0-4.4-3.6-8-8-8zm0 11a3 3 0 1 1 0-6 3 3 0 0 1 0 6z"/></svg>`
|
|
36
|
+
});
|
|
37
|
+
const pin = L.marker([marker.lat, marker.lng], { icon }).addTo(map);
|
|
38
|
+
if (marker.label) {
|
|
39
|
+
const label = document.createElement("span");
|
|
40
|
+
label.textContent = marker.label;
|
|
41
|
+
pin.bindPopup(label);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}).catch(() => {
|
|
45
|
+
if (!disposed) setError(true);
|
|
46
|
+
});
|
|
47
|
+
return () => {
|
|
48
|
+
disposed = true;
|
|
49
|
+
map?.remove();
|
|
50
|
+
};
|
|
51
|
+
}, [widget]);
|
|
52
|
+
if (!markers.length) return null;
|
|
53
|
+
if (error) return /* @__PURE__ */ jsx("p", { children: "Unable to load the map." });
|
|
54
|
+
return /* @__PURE__ */ jsx("div", { ref: containerRef, style: { height: 224, width: "100%", maxWidth: 448, overflow: "hidden", borderRadius: 12, border: "1px solid #94a3b855", position: "relative", zIndex: 0 } });
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
WidgetMap as default
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=WidgetMap-OMBGFVSQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react/components/widgets/WidgetMap.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport type { WidgetPayload } from \"./WidgetExtended\";\nimport leafletCss from \"leaflet/dist/leaflet.css?inline\";\nimport { useWidgetStyles } from \"../../lib/widgetStyles\";\n\nconst colors: Record<string, string> = { vehicle: \"#2563eb\", origin: \"#16a34a\", destination: \"#dc2626\", stop: \"#f59e0b\", hub: \"#7c3aed\" };\ntype MapMarker = { lat: number; lng: number; label?: string; kind?: string };\n\n/** Leaflet directly avoids requiring React 19-only map adapters in an SDK\n * that supports React 18 hosts. Import Leaflet only in the browser effect. */\nexport default function WidgetMap({ widget }: { widget: WidgetPayload }) {\n const containerRef = useRef<HTMLDivElement>(null);\n const [error, setError] = useState(false);\n useWidgetStyles(\"pisi-leaflet-styles\", leafletCss);\n const markers = Array.isArray(widget.markers) ? (widget.markers as MapMarker[]).filter(m => Number.isFinite(m.lat) && Number.isFinite(m.lng)) : [];\n useEffect(() => {\n const container = containerRef.current;\n if (!container || !markers.length) return;\n let disposed = false;\n let map: import(\"leaflet\").Map | undefined;\n setError(false);\n void import(\"leaflet\").then(module => {\n if (disposed) return;\n const L = module.default ?? module;\n map = L.map(container, { scrollWheelZoom: false }).setView([markers[0].lat, markers[0].lng], 9);\n L.tileLayer(\"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png\", {\n attribution: '© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors',\n }).addTo(map);\n if (Array.isArray(widget.route) && widget.route.length > 1) L.polyline(widget.route as [number, number][], { color: \"#2563eb\", weight: 3 }).addTo(map);\n for (const marker of markers) {\n const color = colors[marker.kind ?? \"stop\"] ?? \"#334155\";\n const icon = L.divIcon({ className: \"\", iconSize: [26, 26], iconAnchor: [13, 26],\n html: `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"26\" height=\"26\" fill=\"${color}\"><path d=\"M12 2C7.6 2 4 5.6 4 10c0 6 8 12 8 12s8-6 8-12c0-4.4-3.6-8-8-8zm0 11a3 3 0 1 1 0-6 3 3 0 0 1 0 6z\"/></svg>` });\n const pin = L.marker([marker.lat, marker.lng], { icon }).addTo(map);\n if (marker.label) { const label = document.createElement(\"span\"); label.textContent = marker.label; pin.bindPopup(label); }\n }\n }).catch(() => { if (!disposed) setError(true); });\n return () => { disposed = true; map?.remove(); };\n }, [widget]);\n if (!markers.length) return null;\n if (error) return <p>Unable to load the map.</p>;\n return <div ref={containerRef} style={{ height: 224, width: \"100%\", maxWidth: 448, overflow: \"hidden\", borderRadius: 12, border: \"1px solid #94a3b855\", position: \"relative\", zIndex: 0 }} />;\n}\n"],"mappings":";;;;;AAAA,SAAS,WAAW,QAAQ,gBAAgB;AAE5C,OAAO,gBAAgB;AAsCH;AAnCpB,IAAM,SAAiC,EAAE,SAAS,WAAW,QAAQ,WAAW,aAAa,WAAW,MAAM,WAAW,KAAK,UAAU;AAKzH,SAAR,UAA2B,EAAE,OAAO,GAA8B;AACvE,QAAM,eAAe,OAAuB,IAAI;AAChD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,KAAK;AACxC,kBAAgB,uBAAuB,UAAU;AACjD,QAAM,UAAU,MAAM,QAAQ,OAAO,OAAO,IAAK,OAAO,QAAwB,OAAO,OAAK,OAAO,SAAS,EAAE,GAAG,KAAK,OAAO,SAAS,EAAE,GAAG,CAAC,IAAI,CAAC;AACjJ,YAAU,MAAM;AACd,UAAM,YAAY,aAAa;AAC/B,QAAI,CAAC,aAAa,CAAC,QAAQ,OAAQ;AACnC,QAAI,WAAW;AACf,QAAI;AACJ,aAAS,KAAK;AACd,SAAK,OAAO,SAAS,EAAE,KAAK,YAAU;AACpC,UAAI,SAAU;AACd,YAAM,IAAI,OAAO,WAAW;AAC5B,YAAM,EAAE,IAAI,WAAW,EAAE,iBAAiB,MAAM,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,QAAQ,CAAC,EAAE,GAAG,GAAG,CAAC;AAC9F,QAAE,UAAU,sDAAsD;AAAA,QAChE,aAAa;AAAA,MACf,CAAC,EAAE,MAAM,GAAG;AACZ,UAAI,MAAM,QAAQ,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,EAAG,GAAE,SAAS,OAAO,OAA6B,EAAE,OAAO,WAAW,QAAQ,EAAE,CAAC,EAAE,MAAM,GAAG;AACrJ,iBAAW,UAAU,SAAS;AAC5B,cAAM,QAAQ,OAAO,OAAO,QAAQ,MAAM,KAAK;AAC/C,cAAM,OAAO,EAAE,QAAQ;AAAA,UAAE,WAAW;AAAA,UAAI,UAAU,CAAC,IAAI,EAAE;AAAA,UAAG,YAAY,CAAC,IAAI,EAAE;AAAA,UAC7E,MAAM,4FAA4F,KAAK;AAAA,QAAuH,CAAC;AACjO,cAAM,MAAM,EAAE,OAAO,CAAC,OAAO,KAAK,OAAO,GAAG,GAAG,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG;AAClE,YAAI,OAAO,OAAO;AAAE,gBAAM,QAAQ,SAAS,cAAc,MAAM;AAAG,gBAAM,cAAc,OAAO;AAAO,cAAI,UAAU,KAAK;AAAA,QAAG;AAAA,MAC5H;AAAA,IACF,CAAC,EAAE,MAAM,MAAM;AAAE,UAAI,CAAC,SAAU,UAAS,IAAI;AAAA,IAAG,CAAC;AACjD,WAAO,MAAM;AAAE,iBAAW;AAAM,WAAK,OAAO;AAAA,IAAG;AAAA,EACjD,GAAG,CAAC,MAAM,CAAC;AACX,MAAI,CAAC,QAAQ,OAAQ,QAAO;AAC5B,MAAI,MAAO,QAAO,oBAAC,OAAE,qCAAuB;AAC5C,SAAO,oBAAC,SAAI,KAAK,cAAc,OAAO,EAAE,QAAQ,KAAK,OAAO,QAAQ,UAAU,KAAK,UAAU,UAAU,cAAc,IAAI,QAAQ,uBAAuB,UAAU,YAAY,QAAQ,EAAE,GAAG;AAC7L;","names":[]}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChartLegend,
|
|
3
|
+
ChartLegendContent,
|
|
4
|
+
ChartTooltip,
|
|
5
|
+
ChartTooltipContent
|
|
6
|
+
} from "./chunk-OG3SZEEF.js";
|
|
7
|
+
|
|
8
|
+
// src/react/components/widgets/WidgetPieFamilyChart.tsx
|
|
9
|
+
import { Cell, Pie, PieChart } from "recharts";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
var COLORS = [
|
|
12
|
+
"#4A6FA5",
|
|
13
|
+
"#D4956A",
|
|
14
|
+
"#6B9080",
|
|
15
|
+
"#9B7FB8",
|
|
16
|
+
"#C07878",
|
|
17
|
+
"#5B8FA8",
|
|
18
|
+
"#B5A36A",
|
|
19
|
+
"#7B6D8A",
|
|
20
|
+
"#6BA09B",
|
|
21
|
+
"#A67D5D"
|
|
22
|
+
];
|
|
23
|
+
function WidgetPieFamilyChart({
|
|
24
|
+
chartType,
|
|
25
|
+
data,
|
|
26
|
+
outerRadius,
|
|
27
|
+
innerRadius,
|
|
28
|
+
shouldShowLabels,
|
|
29
|
+
hasLegend,
|
|
30
|
+
legendWrapperStyle,
|
|
31
|
+
width,
|
|
32
|
+
height
|
|
33
|
+
}) {
|
|
34
|
+
return /* @__PURE__ */ jsxs(PieChart, { width, height, children: [
|
|
35
|
+
/* @__PURE__ */ jsx(
|
|
36
|
+
Pie,
|
|
37
|
+
{
|
|
38
|
+
data,
|
|
39
|
+
dataKey: "value",
|
|
40
|
+
nameKey: "name",
|
|
41
|
+
cx: "50%",
|
|
42
|
+
cy: "50%",
|
|
43
|
+
innerRadius: chartType === "doughnut" ? innerRadius : 0,
|
|
44
|
+
outerRadius,
|
|
45
|
+
paddingAngle: 2,
|
|
46
|
+
label: shouldShowLabels ? (entry) => {
|
|
47
|
+
const pct = (entry.percent ?? 0) * 100;
|
|
48
|
+
if (pct < 5) return null;
|
|
49
|
+
return `${entry.name ?? ""} ${pct.toFixed(0)}%`;
|
|
50
|
+
} : false,
|
|
51
|
+
labelLine: shouldShowLabels ? (props) => {
|
|
52
|
+
const { percent, points, stroke } = props;
|
|
53
|
+
if ((percent ?? 0) * 100 < 5) return /* @__PURE__ */ jsx("polyline", { stroke: "none" });
|
|
54
|
+
return /* @__PURE__ */ jsx(
|
|
55
|
+
"polyline",
|
|
56
|
+
{
|
|
57
|
+
points: points.map((point) => `${point.x},${point.y}`).join(","),
|
|
58
|
+
stroke,
|
|
59
|
+
strokeWidth: 1,
|
|
60
|
+
fill: "none"
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
} : false,
|
|
64
|
+
children: data.map((_, index) => /* @__PURE__ */ jsx(Cell, { fill: COLORS[index % COLORS.length] }, index))
|
|
65
|
+
}
|
|
66
|
+
),
|
|
67
|
+
/* @__PURE__ */ jsx(ChartTooltip, { content: /* @__PURE__ */ jsx(ChartTooltipContent, {}) }),
|
|
68
|
+
hasLegend && /* @__PURE__ */ jsx(
|
|
69
|
+
ChartLegend,
|
|
70
|
+
{
|
|
71
|
+
wrapperStyle: legendWrapperStyle,
|
|
72
|
+
content: /* @__PURE__ */ jsx(ChartLegendContent, {})
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
] });
|
|
76
|
+
}
|
|
77
|
+
export {
|
|
78
|
+
WidgetPieFamilyChart as default
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=WidgetPieFamilyChart-XZWHJ76R.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react/components/widgets/WidgetPieFamilyChart.tsx"],"sourcesContent":["import { Cell, Pie, PieChart } from \"recharts\";\nimport {\n ChartLegend,\n ChartLegendContent,\n ChartTooltip,\n ChartTooltipContent,\n} from \"../ui/chart\";\n\nconst COLORS = [\n \"#4A6FA5\",\n \"#D4956A\",\n \"#6B9080\",\n \"#9B7FB8\",\n \"#C07878\",\n \"#5B8FA8\",\n \"#B5A36A\",\n \"#7B6D8A\",\n \"#6BA09B\",\n \"#A67D5D\",\n] as const;\n\ninterface WidgetPieFamilyChartProps {\n chartType: \"pie\" | \"doughnut\";\n data: Array<{ name: string; value: number }>;\n outerRadius: number;\n innerRadius: number;\n shouldShowLabels: boolean;\n hasLegend: boolean;\n legendWrapperStyle: { fontSize: number; top: number };\n width: number;\n height: number;\n}\n\nexport default function WidgetPieFamilyChart({\n chartType,\n data,\n outerRadius,\n innerRadius,\n shouldShowLabels,\n hasLegend,\n legendWrapperStyle,\n width,\n height,\n}: WidgetPieFamilyChartProps) {\n return (\n <PieChart width={width} height={height}>\n <Pie\n data={data}\n dataKey=\"value\"\n nameKey=\"name\"\n cx=\"50%\"\n cy=\"50%\"\n innerRadius={chartType === \"doughnut\" ? innerRadius : 0}\n outerRadius={outerRadius}\n paddingAngle={2}\n label={\n shouldShowLabels\n ? (entry: { name?: string; percent?: number }) => {\n const pct = (entry.percent ?? 0) * 100;\n if (pct < 5) return null;\n return `${entry.name ?? \"\"} ${pct.toFixed(0)}%`;\n }\n : false\n }\n labelLine={\n shouldShowLabels\n ? (props: any) => {\n const { percent, points, stroke } = props;\n if ((percent ?? 0) * 100 < 5) return <polyline stroke=\"none\" />;\n return (\n <polyline\n points={points.map((point: any) => `${point.x},${point.y}`).join(\",\")}\n stroke={stroke}\n strokeWidth={1}\n fill=\"none\"\n />\n );\n }\n : false\n }\n >\n {data.map((_, index) => (\n <Cell key={index} fill={COLORS[index % COLORS.length]} />\n ))}\n </Pie>\n <ChartTooltip content={<ChartTooltipContent />} />\n {hasLegend && (\n <ChartLegend\n wrapperStyle={legendWrapperStyle}\n content={<ChartLegendContent />}\n />\n )}\n </PieChart>\n );\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,MAAM,KAAK,gBAAgB;AA6ChC,SAuBiD,KAvBjD;AArCJ,IAAM,SAAS;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAce,SAAR,qBAAsC;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA8B;AAC5B,SACE,qBAAC,YAAS,OAAc,QACtB;AAAA;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,SAAQ;AAAA,QACR,SAAQ;AAAA,QACR,IAAG;AAAA,QACH,IAAG;AAAA,QACH,aAAa,cAAc,aAAa,cAAc;AAAA,QACtD;AAAA,QACA,cAAc;AAAA,QACd,OACE,mBACI,CAAC,UAA+C;AAC9C,gBAAM,OAAO,MAAM,WAAW,KAAK;AACnC,cAAI,MAAM,EAAG,QAAO;AACpB,iBAAO,GAAG,MAAM,QAAQ,EAAE,IAAI,IAAI,QAAQ,CAAC,CAAC;AAAA,QAC9C,IACA;AAAA,QAEN,WACE,mBACI,CAAC,UAAe;AACd,gBAAM,EAAE,SAAS,QAAQ,OAAO,IAAI;AACpC,eAAK,WAAW,KAAK,MAAM,EAAG,QAAO,oBAAC,cAAS,QAAO,QAAO;AAC7D,iBACE;AAAA,YAAC;AAAA;AAAA,cACC,QAAQ,OAAO,IAAI,CAAC,UAAe,GAAG,MAAM,CAAC,IAAI,MAAM,CAAC,EAAE,EAAE,KAAK,GAAG;AAAA,cACpE;AAAA,cACA,aAAa;AAAA,cACb,MAAK;AAAA;AAAA,UACP;AAAA,QAEJ,IACA;AAAA,QAGL,eAAK,IAAI,CAAC,GAAG,UACZ,oBAAC,QAAiB,MAAM,OAAO,QAAQ,OAAO,MAAM,KAAzC,KAA4C,CACxD;AAAA;AAAA,IACH;AAAA,IACA,oBAAC,gBAAa,SAAS,oBAAC,uBAAoB,GAAI;AAAA,IAC/C,aACC;AAAA,MAAC;AAAA;AAAA,QACC,cAAc;AAAA,QACd,SAAS,oBAAC,sBAAmB;AAAA;AAAA,IAC/B;AAAA,KAEJ;AAEJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|