@siteping/widget 0.9.2 → 0.9.4
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 +116 -7
- package/dist/index.d.ts +8 -3
- package/dist/index.global.js +1284 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +173 -112
- package/dist/index.js.map +1 -0
- package/dist/schema.d.ts +198 -0
- package/dist/siteping-core.d.ts +4 -0
- package/dist/types.d.ts +307 -0
- package/package.json +13 -5
package/README.md
CHANGED
|
@@ -40,26 +40,133 @@ export default function Layout({ children }: { children: React.ReactNode }) {
|
|
|
40
40
|
|
|
41
41
|
You also need a server-side adapter — see [`@siteping/adapter-prisma`](https://www.npmjs.com/package/@siteping/adapter-prisma).
|
|
42
42
|
|
|
43
|
+
### Client-side mode (no server)
|
|
44
|
+
|
|
45
|
+
Use a `store` instead of an `endpoint` to bypass HTTP entirely:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { initSiteping } from '@siteping/widget'
|
|
49
|
+
import { LocalStorageStore } from '@siteping/adapter-localstorage'
|
|
50
|
+
|
|
51
|
+
initSiteping({
|
|
52
|
+
store: new LocalStorageStore(),
|
|
53
|
+
projectName: 'my-demo',
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Feedback persists in `localStorage` — no server, no database. Perfect for demos and prototyping. See [`@siteping/adapter-localstorage`](https://www.npmjs.com/package/@siteping/adapter-localstorage) and [`@siteping/adapter-memory`](https://www.npmjs.com/package/@siteping/adapter-memory).
|
|
58
|
+
|
|
59
|
+
> **Framework-agnostic** — Works with any frontend framework (React, Vue, Svelte, Astro) or plain HTML. No framework dependency required.
|
|
60
|
+
|
|
61
|
+
> **~23KB gzipped** — zero framework dependencies.
|
|
62
|
+
|
|
43
63
|
## Configuration
|
|
44
64
|
|
|
65
|
+
All configuration options for `initSiteping()`:
|
|
66
|
+
|
|
67
|
+
| Option | Type | Default | Description |
|
|
68
|
+
|--------|------|---------|-------------|
|
|
69
|
+
| `endpoint` | `string` | — | Your API route (e.g. `/api/siteping`). Required unless `store` is provided |
|
|
70
|
+
| `store` | `SitepingStore` | — | Direct store for client-side mode. When set, bypasses HTTP |
|
|
71
|
+
| `projectName` | `string` | — | **Required.** Scopes feedbacks to this project |
|
|
72
|
+
| `position` | `'bottom-right' \| 'bottom-left'` | `'bottom-right'` | Widget FAB position |
|
|
73
|
+
| `accentColor` | `string` | `'#0066ff'` | Widget accent color — hex color (`#RGB`, `#RRGGBB`, `#RRGGBBAA`) |
|
|
74
|
+
| `theme` | `'light' \| 'dark' \| 'auto'` | `'light'` | Widget color theme |
|
|
75
|
+
| `locale` | `'fr' \| 'en'` | `'en'` | Widget UI language |
|
|
76
|
+
| `forceShow` | `boolean` | `false` | Show the widget in production (hidden by default) |
|
|
77
|
+
| `debug` | `boolean` | `false` | Enable debug logging to console |
|
|
78
|
+
|
|
79
|
+
> **Custom translations** — Use `registerLocale(code, translations)` to add your own locale at runtime.
|
|
80
|
+
|
|
81
|
+
### Event callbacks
|
|
82
|
+
|
|
83
|
+
| Option | Signature | Description |
|
|
84
|
+
|--------|-----------|-------------|
|
|
85
|
+
| `onOpen` | `() => void` | Called when the feedback panel opens |
|
|
86
|
+
| `onClose` | `() => void` | Called when the feedback panel closes |
|
|
87
|
+
| `onFeedbackSent` | `(feedback) => void` | Called after a feedback is successfully submitted |
|
|
88
|
+
| `onError` | `(error) => void` | Called on API or internal errors |
|
|
89
|
+
| `onAnnotationStart` | `() => void` | Called when annotation drawing starts |
|
|
90
|
+
| `onAnnotationEnd` | `() => void` | Called when annotation drawing ends |
|
|
91
|
+
| `onSkip` | `(reason) => void` | Called when widget is skipped (production/mobile) |
|
|
92
|
+
|
|
45
93
|
```ts
|
|
46
94
|
initSiteping({
|
|
47
|
-
// Required
|
|
48
95
|
endpoint: '/api/siteping',
|
|
49
96
|
projectName: 'my-project',
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
97
|
+
position: 'bottom-right',
|
|
98
|
+
accentColor: '#0066ff',
|
|
99
|
+
theme: 'light',
|
|
100
|
+
locale: 'en',
|
|
101
|
+
forceShow: false,
|
|
102
|
+
debug: false,
|
|
56
103
|
onOpen: () => {},
|
|
57
104
|
onClose: () => {},
|
|
58
105
|
onFeedbackSent: (feedback) => {},
|
|
59
106
|
onError: (error) => {},
|
|
60
107
|
onAnnotationStart: () => {},
|
|
61
108
|
onAnnotationEnd: () => {},
|
|
109
|
+
onSkip: (reason) => {},
|
|
110
|
+
})
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Return value API
|
|
114
|
+
|
|
115
|
+
`initSiteping()` returns a `SitepingInstance` with the following methods:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
const widget = initSiteping({ ... })
|
|
119
|
+
|
|
120
|
+
widget.open() // Open the feedback panel
|
|
121
|
+
widget.close() // Close the feedback panel
|
|
122
|
+
widget.refresh() // Refresh feedbacks from the server
|
|
123
|
+
widget.destroy() // Remove the widget and clean up all DOM elements + listeners
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Event system
|
|
127
|
+
|
|
128
|
+
Use `widget.on()` / `widget.off()` as an alternative to config callbacks:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
const widget = initSiteping({ ... })
|
|
132
|
+
|
|
133
|
+
// Subscribe to events
|
|
134
|
+
const unsub = widget.on('feedback:sent', (feedback) => {
|
|
135
|
+
console.log('New feedback:', feedback.id)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
widget.on('feedback:deleted', (id) => {
|
|
139
|
+
console.log('Feedback deleted:', id)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
widget.on('panel:open', () => {
|
|
143
|
+
console.log('Panel opened')
|
|
62
144
|
})
|
|
145
|
+
|
|
146
|
+
widget.on('panel:close', () => {
|
|
147
|
+
console.log('Panel closed')
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
// Unsubscribe
|
|
151
|
+
unsub() // via returned function
|
|
152
|
+
widget.off('feedback:sent', handler) // via off()
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### All public events
|
|
156
|
+
|
|
157
|
+
| Event | Payload | Description |
|
|
158
|
+
|-------|---------|-------------|
|
|
159
|
+
| `feedback:sent` | `FeedbackResponse` | Fired after a feedback is successfully submitted |
|
|
160
|
+
| `feedback:deleted` | `string` (feedback id) | Fired after a feedback is deleted |
|
|
161
|
+
| `panel:open` | — | Fired when the feedback panel opens |
|
|
162
|
+
| `panel:close` | — | Fired when the feedback panel closes |
|
|
163
|
+
|
|
164
|
+
## CSP Requirements
|
|
165
|
+
|
|
166
|
+
The widget uses Shadow DOM (closed mode) for encapsulation, but overlay components (annotation layer, screenshot flash) live outside the shadow root. If your site enforces a strict Content Security Policy, you need to allow inline styles:
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
style-src 'unsafe-inline';
|
|
63
170
|
```
|
|
64
171
|
|
|
65
172
|
## Features
|
|
@@ -76,6 +183,8 @@ initSiteping({
|
|
|
76
183
|
| Package | Description |
|
|
77
184
|
|---------|-------------|
|
|
78
185
|
| [`@siteping/adapter-prisma`](https://www.npmjs.com/package/@siteping/adapter-prisma) | Server-side Prisma adapter |
|
|
186
|
+
| [`@siteping/adapter-memory`](https://www.npmjs.com/package/@siteping/adapter-memory) | In-memory adapter (testing, demos) |
|
|
187
|
+
| [`@siteping/adapter-localstorage`](https://www.npmjs.com/package/@siteping/adapter-localstorage) | Client-side localStorage adapter |
|
|
79
188
|
| [`@siteping/cli`](https://www.npmjs.com/package/@siteping/cli) | CLI for project setup |
|
|
80
189
|
|
|
81
190
|
## License
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import { SitepingConfig, SitepingInstance } from '
|
|
2
|
-
export { AnchorData, AnnotationPayload, AnnotationResponse, FeedbackPayload, FeedbackResponse, FeedbackStatus, FeedbackType, RectData, SitepingConfig, SitepingInstance, SitepingPublicEvents } from '
|
|
1
|
+
import { SitepingConfig, SitepingInstance } from './siteping-core.js';
|
|
2
|
+
export { AnchorData, AnnotationPayload, AnnotationResponse, FeedbackPayload, FeedbackResponse, FeedbackStatus, FeedbackType, RectData, SitepingConfig, SitepingInstance, SitepingPublicEvents, SitepingStore } from './siteping-core.js';
|
|
3
|
+
|
|
4
|
+
interface Identity {
|
|
5
|
+
name: string;
|
|
6
|
+
email: string;
|
|
7
|
+
}
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
10
|
* Initialize the Siteping feedback widget.
|
|
@@ -16,4 +21,4 @@ export { AnchorData, AnnotationPayload, AnnotationResponse, FeedbackPayload, Fee
|
|
|
16
21
|
*/
|
|
17
22
|
declare function initSiteping(config: SitepingConfig): SitepingInstance;
|
|
18
23
|
|
|
19
|
-
export { initSiteping };
|
|
24
|
+
export { type Identity, initSiteping };
|