@superbased/feedback-widget 0.0.1-placeholder.0 → 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/NOTICE +4 -0
- package/README.md +262 -4
- package/dist/define.d.ts +2 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +8 -0
- package/dist/define.js.map +1 -0
- package/dist/index.d.ts +138 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +457 -0
- package/dist/index.js.map +1 -0
- package/dist/react.d.ts +64 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +89 -0
- package/dist/react.js.map +1 -0
- package/package.json +68 -4
- package/src/define.ts +9 -0
- package/src/index.ts +490 -0
- package/src/react.ts +132 -0
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,10 +1,268 @@
|
|
|
1
|
-
# @superbased/feedback-widget
|
|
1
|
+
# @superbased/feedback-widget
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
A tiny thumbs up / down widget, with an optional comment, that your end users
|
|
4
|
+
click on an AI answer. Their vote becomes a superbased `feedback` score on the
|
|
5
|
+
trace that produced the answer.
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
- A framework-agnostic web component, `<superbased-feedback>`, and a React
|
|
8
|
+
wrapper.
|
|
9
|
+
- No runtime dependencies (React is an optional peer, for the wrapper only).
|
|
10
|
+
- Keyboard and screen-reader accessible; themeable with CSS variables.
|
|
11
|
+
- Apache-2.0.
|
|
7
12
|
|
|
13
|
+
## How it works, and why the browser never holds a key
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
browser your backend superbased
|
|
17
|
+
<superbased-feedback> -- POST /api/feedback --> feedback(value, {traceId, ...}) --> machine / gateway
|
|
18
|
+
(no key, no superbased URL) (holds the SDK key)
|
|
8
19
|
```
|
|
20
|
+
|
|
21
|
+
The widget never talks to superbased and never holds an SDK key. It only:
|
|
22
|
+
|
|
23
|
+
1. dispatches a `superbased-feedback` DOM event with the vote, and
|
|
24
|
+
2. when you set `endpoint`, POSTs that same body to **your own backend**
|
|
25
|
+
(same origin by default; another origin only with the `cross-origin`
|
|
26
|
+
attribute; never a redirect).
|
|
27
|
+
|
|
28
|
+
Your backend calls the SDK's `feedback()` with the trace (and span) id it
|
|
29
|
+
rendered the answer with. The SDK key stays on your server, where the rest of
|
|
30
|
+
your SDK calls already run.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
9
35
|
npm install @superbased/feedback-widget
|
|
10
36
|
```
|
|
37
|
+
|
|
38
|
+
It releases with the superbased SDKs, on the same version.
|
|
39
|
+
|
|
40
|
+
## Use it
|
|
41
|
+
|
|
42
|
+
Render the trace id (and, optionally, the span id) of the answer next to it.
|
|
43
|
+
On the server, inside the request that produced the answer:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { getCurrentTraceId, getCurrentSpanId } from "@superbased/sdk";
|
|
47
|
+
const traceId = getCurrentTraceId(); // send these to the page with the answer
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Plain HTML
|
|
51
|
+
|
|
52
|
+
A browser cannot resolve a package name such as
|
|
53
|
+
`@superbased/feedback-widget/define` without a bundler. Serve the package's
|
|
54
|
+
`dist/` folder with your static files (here under `/vendor/feedback-widget/`)
|
|
55
|
+
and load its `define.js` by path; it registers `<superbased-feedback>`:
|
|
56
|
+
|
|
57
|
+
```html
|
|
58
|
+
<superbased-feedback
|
|
59
|
+
trace-id="4bf92f3577b34da6a3ce929d0e0e4736"
|
|
60
|
+
span-id="00f067aa0ba902b7"
|
|
61
|
+
endpoint="/api/feedback"
|
|
62
|
+
comment="optional"></superbased-feedback>
|
|
63
|
+
|
|
64
|
+
<script type="module" src="/vendor/feedback-widget/define.js"></script>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
With a bundler (Vite, webpack, Next.js), import it by name in your client
|
|
68
|
+
code instead: `import "@superbased/feedback-widget/define";`.
|
|
69
|
+
|
|
70
|
+
Or register it yourself: `import { defineFeedbackElement } from
|
|
71
|
+
"@superbased/feedback-widget"; defineFeedbackElement();` (idempotent; a no-op
|
|
72
|
+
where there is no DOM, so it is safe in server-rendered code).
|
|
73
|
+
|
|
74
|
+
### React
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
import { SuperbasedFeedback } from "@superbased/feedback-widget/react";
|
|
78
|
+
|
|
79
|
+
<SuperbasedFeedback
|
|
80
|
+
traceId={answer.traceId}
|
|
81
|
+
spanId={answer.spanId}
|
|
82
|
+
endpoint="/api/feedback"
|
|
83
|
+
comment="optional"
|
|
84
|
+
onSent={() => console.log("thanks")}
|
|
85
|
+
/>;
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Without an endpoint
|
|
89
|
+
|
|
90
|
+
Leave `endpoint` out and handle the event yourself (or call
|
|
91
|
+
`event.preventDefault()` to stop the POST):
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
el.addEventListener("superbased-feedback", (e) => myApi.sendFeedback(e.detail));
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Attributes
|
|
98
|
+
|
|
99
|
+
| Attribute | React prop | Default | Meaning |
|
|
100
|
+
|---|---|---|---|
|
|
101
|
+
| `trace-id` | `traceId` | required | The answer's trace (32 hex). |
|
|
102
|
+
| `span-id` | `spanId` | none | The answer's span (16 hex). Without it the score is trace-level. |
|
|
103
|
+
| `endpoint` | `endpoint` | none | Your backend's route. Same origin unless `cross-origin`. |
|
|
104
|
+
| `name` | `name` | `user_feedback` | The score name the widget sends. Your server decides the name it records (see "The server half"). |
|
|
105
|
+
| `comment` | `comment` | `off` | `off`, `optional` (a box after the vote), `required` (a thumbs-down needs a comment). |
|
|
106
|
+
| `token` | `token` | none | An opaque value your server rendered with the answer, passed through to your endpoint (see "Trust" below). |
|
|
107
|
+
| `cross-origin` | `crossOrigin` | off | Allow an `endpoint` on another origin. |
|
|
108
|
+
| `credentials` | `credentials` | `same-origin` | `same-origin`, `include` or `omit` for the POST. |
|
|
109
|
+
| `disabled` | `disabled` | off | Turns the buttons off. |
|
|
110
|
+
| `nonce` | `nonce` | none | Your Content Security Policy nonce, used only by browsers without constructable stylesheets (see "Content Security Policy"). |
|
|
111
|
+
| `question`, `label-up`, `label-down`, `comment-label`, `comment-placeholder`, `submit-label`, `skip-label`, `thanks`, `error-text`, `comment-required-text`, `comment-too-long-text` | camelCase of each | English texts | Every text the widget shows. |
|
|
112
|
+
|
|
113
|
+
Properties: `fetch` (a fetch to use instead of the global one), `value` (the
|
|
114
|
+
vote: `true`, `false` or `null`), `reset()`, `retry()`.
|
|
115
|
+
|
|
116
|
+
## The body and the events
|
|
117
|
+
|
|
118
|
+
The POST body, and the `detail` of the `superbased-feedback` event, use the
|
|
119
|
+
SDKs' field names:
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{ "trace_id": "4bf9...", "span_id": "00f0...", "value": false, "comment": "wrong city", "name": "user_feedback", "token": "..." }
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
| Event | When | `detail` |
|
|
126
|
+
|---|---|---|
|
|
127
|
+
| `superbased-feedback` | a vote (and its comment) is ready; cancelable | the body |
|
|
128
|
+
| `superbased-feedback-sent` | the POST answered 2xx | `{ payload, status }` |
|
|
129
|
+
| `superbased-feedback-error` | an invalid id, a refused endpoint, a network error or a non-2xx | `{ payload, status, error }` |
|
|
130
|
+
|
|
131
|
+
All three bubble and cross the shadow boundary (`composed`). The widget checks
|
|
132
|
+
the same rules the SDKs' `feedback()` applies (ids, name, a comment of at most
|
|
133
|
+
2,000 bytes) before it sends. The comment bound is in UTF-8 bytes, not
|
|
134
|
+
characters: a comment over it is held back with a "too long" hint while the
|
|
135
|
+
end user shortens it, and the vote is kept.
|
|
136
|
+
|
|
137
|
+
## The server half
|
|
138
|
+
|
|
139
|
+
Your endpoint receives the body above and calls `feedback()`. Each SDK's
|
|
140
|
+
snippet:
|
|
141
|
+
|
|
142
|
+
### TypeScript / Node (`@superbased/sdk`)
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import express from "express";
|
|
146
|
+
import { feedback, init } from "@superbased/sdk";
|
|
147
|
+
|
|
148
|
+
init(); // as everywhere else in your app; the key comes from SUPERBASED_API_KEY or your machine
|
|
149
|
+
const app = express();
|
|
150
|
+
app.use(express.json());
|
|
151
|
+
|
|
152
|
+
app.post("/api/feedback", async (req, res) => {
|
|
153
|
+
const { trace_id, span_id, value, comment } = req.body ?? {};
|
|
154
|
+
if (typeof value !== "boolean") return res.sendStatus(400);
|
|
155
|
+
// Check here that trace_id is an answer you rendered for this user (see "Trust").
|
|
156
|
+
// The score name is yours, not the browser's: any page visitor can send any body.
|
|
157
|
+
const r = await feedback(value, { traceId: trace_id, spanId: span_id, comment, name: "user_feedback" });
|
|
158
|
+
res.sendStatus(r.ok ? 204 : 502);
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
If your pages use more than one widget name, accept the body's `name` only
|
|
163
|
+
from a list you keep on the server.
|
|
164
|
+
|
|
165
|
+
`sdk/widget/test/server.test.mjs` runs this handler against the TypeScript SDK.
|
|
166
|
+
|
|
167
|
+
### Python (`superbased-sdk`)
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from fastapi import FastAPI, Request, Response
|
|
171
|
+
import superbased_sdk as sb
|
|
172
|
+
|
|
173
|
+
sb.init()
|
|
174
|
+
app = FastAPI()
|
|
175
|
+
|
|
176
|
+
@app.post("/api/feedback")
|
|
177
|
+
async def post_feedback(request: Request) -> Response:
|
|
178
|
+
body = await request.json()
|
|
179
|
+
if not isinstance(body.get("value"), bool):
|
|
180
|
+
return Response(status_code=400)
|
|
181
|
+
# Check here that trace_id is an answer you rendered for this user (see "Trust").
|
|
182
|
+
r = await sb.async_feedback(
|
|
183
|
+
body["value"],
|
|
184
|
+
trace_id=body.get("trace_id"),
|
|
185
|
+
span_id=body.get("span_id"),
|
|
186
|
+
comment=body.get("comment"),
|
|
187
|
+
name="user_feedback", # yours, not the browser's
|
|
188
|
+
)
|
|
189
|
+
return Response(status_code=204 if r.ok else 502)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Flask or Django: the same, with the synchronous `sb.feedback(...)`.
|
|
193
|
+
|
|
194
|
+
### Any other language
|
|
195
|
+
|
|
196
|
+
Send the score over OpenTelemetry (`gen_ai.evaluation.result`) or to the SDK
|
|
197
|
+
control API from your server; see
|
|
198
|
+
[superbased.app/docs/sdk/otel-any-language](https://superbased.app/docs/sdk/otel-any-language). The
|
|
199
|
+
browser part is the same.
|
|
200
|
+
|
|
201
|
+
## Trust
|
|
202
|
+
|
|
203
|
+
The trace id is not a secret: anyone can POST any body to your endpoint. If a
|
|
204
|
+
forged vote matters to you, render a `token` with the answer, for example an
|
|
205
|
+
HMAC of the trace id with a server-side secret, and check it in your endpoint
|
|
206
|
+
before calling `feedback()`. The widget passes `token` through untouched.
|
|
207
|
+
Rate-limit the endpoint like any other public form.
|
|
208
|
+
|
|
209
|
+
The comment is your end user's text: it is content, stored under the same
|
|
210
|
+
capture rules as the rest of your app's traced content (scrubbed for
|
|
211
|
+
secrets at ingest).
|
|
212
|
+
|
|
213
|
+
## Content Security Policy
|
|
214
|
+
|
|
215
|
+
The widget adds no inline script and no inline style. Its styles go on its
|
|
216
|
+
shadow root as a constructed stylesheet, which a strict `style-src` allows,
|
|
217
|
+
so a policy such as `default-src 'self'` needs no exception. A browser
|
|
218
|
+
without constructable stylesheets gets a `<style>` element instead; give the
|
|
219
|
+
widget your policy's nonce (`nonce="..."`) and it carries it.
|
|
220
|
+
|
|
221
|
+
## Theming
|
|
222
|
+
|
|
223
|
+
Set any of these on the element or an ancestor:
|
|
224
|
+
|
|
225
|
+
| Variable | Default | Styles |
|
|
226
|
+
|---|---|---|
|
|
227
|
+
| `--sb-feedback-font` | `inherit` | the whole widget |
|
|
228
|
+
| `--sb-feedback-fg` | `inherit` | text |
|
|
229
|
+
| `--sb-feedback-muted` | `inherit` | the question |
|
|
230
|
+
| `--sb-feedback-bg` | `transparent` | buttons and the comment box |
|
|
231
|
+
| `--sb-feedback-border` | `currentColor` | borders |
|
|
232
|
+
| `--sb-feedback-accent` | `#2b6cb0` | the chosen button, Send |
|
|
233
|
+
| `--sb-feedback-accent-fg` | `#fff` | text on the accent |
|
|
234
|
+
| `--sb-feedback-radius` | `0.5em` | corners |
|
|
235
|
+
| `--sb-feedback-gap` | `0.5em` | spacing |
|
|
236
|
+
| `--sb-feedback-focus` | `#2b6cb0` | the focus ring |
|
|
237
|
+
| `--sb-feedback-error` | `#c53030` | the error text and the hint |
|
|
238
|
+
|
|
239
|
+
```css
|
|
240
|
+
superbased-feedback { --sb-feedback-accent: #0f766e; --sb-feedback-radius: 999px; }
|
|
241
|
+
superbased-feedback::part(button) { padding: 0.4em 0.8em; }
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Parts for deeper styling: `root`, `vote`, `question`, `button`, `up`, `down`,
|
|
245
|
+
`comment`, `comment-label`, `textarea`, `hint`, `submit`, `skip`, `status`.
|
|
246
|
+
|
|
247
|
+
## Accessibility
|
|
248
|
+
|
|
249
|
+
- Native `<button>`s in a labelled group, each with an accessible name and
|
|
250
|
+
`aria-pressed`; 44 px minimum targets.
|
|
251
|
+
- The comment box has a visible label and takes focus when it opens.
|
|
252
|
+
Ctrl/Cmd+Enter sends, Escape skips (when the comment is optional).
|
|
253
|
+
- A required comment sets `aria-required`, and a missing one `aria-invalid`
|
|
254
|
+
with an announced hint.
|
|
255
|
+
- The result ("Thanks for your feedback.", or the error) is announced through
|
|
256
|
+
a polite live region.
|
|
257
|
+
|
|
258
|
+
## Development
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
npm ci
|
|
262
|
+
npm run typecheck
|
|
263
|
+
npm test # builds, then node --test (happy-dom; offline)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## License
|
|
267
|
+
|
|
268
|
+
Apache-2.0. See `LICENSE` and `NOTICE`.
|
package/dist/define.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/define.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Side-effect entry: `import "@superbased/feedback-widget/define"` registers
|
|
3
|
+
* `<superbased-feedback>` (in a browser; a no-op elsewhere).
|
|
4
|
+
*/
|
|
5
|
+
import { defineFeedbackElement } from "./index.js";
|
|
6
|
+
defineFeedbackElement();
|
|
7
|
+
export { TAG } from "./index.js";
|
|
8
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,qBAAqB,EAAE,CAAC;AAExB,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<superbased-feedback>`: an end user's thumbs up / down, and an optional
|
|
3
|
+
* comment, on one AI answer (plan W5-6). Framework-agnostic, no runtime
|
|
4
|
+
* dependencies, keyboard and screen-reader accessible, themeable with CSS
|
|
5
|
+
* variables.
|
|
6
|
+
*
|
|
7
|
+
* Security: the browser never holds a superbased SDK key. The widget only
|
|
8
|
+
* dispatches a `superbased-feedback` event and, when `endpoint` is set,
|
|
9
|
+
* POSTs to YOUR backend (same origin by default). Your backend calls the
|
|
10
|
+
* SDK's `feedback()` with the trace and span id it rendered the answer
|
|
11
|
+
* with. See the README for that server half in each SDK.
|
|
12
|
+
*
|
|
13
|
+
* ```html
|
|
14
|
+
* <superbased-feedback trace-id="4bf9..." span-id="00f0..." endpoint="/api/feedback" comment="optional"></superbased-feedback>
|
|
15
|
+
* <script type="module">import { defineFeedbackElement } from "@superbased/feedback-widget"; defineFeedbackElement();</script>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
/** The custom element's default tag name. */
|
|
19
|
+
export declare const TAG = "superbased-feedback";
|
|
20
|
+
/** The event the widget dispatches (bubbles, composed, cancelable: `preventDefault()` skips the POST). */
|
|
21
|
+
export declare const FEEDBACK_EVENT = "superbased-feedback";
|
|
22
|
+
/** Dispatched after the POST answered 2xx (`detail`: the payload and the status). */
|
|
23
|
+
export declare const SENT_EVENT = "superbased-feedback-sent";
|
|
24
|
+
/** Dispatched when the POST failed (`detail`: the payload, the status (0 = no answer) and the error). */
|
|
25
|
+
export declare const ERROR_EVENT = "superbased-feedback-error";
|
|
26
|
+
/** The score name the SDK's `feedback()` uses by default. */
|
|
27
|
+
export declare const DEFAULT_NAME = "user_feedback";
|
|
28
|
+
/** The body the widget POSTs, and the `detail` of its event (snake_case, the SDKs' field names). */
|
|
29
|
+
export interface FeedbackPayload {
|
|
30
|
+
/** The trace the answer belongs to (32 hex), as your server rendered it. */
|
|
31
|
+
trace_id: string;
|
|
32
|
+
/** The answer's span (16 hex), when your server gave one. */
|
|
33
|
+
span_id?: string;
|
|
34
|
+
/** true = thumbs up, false = thumbs down. */
|
|
35
|
+
value: boolean;
|
|
36
|
+
/** The end user's comment, when they wrote one. */
|
|
37
|
+
comment?: string;
|
|
38
|
+
/** The score name (default `user_feedback`). */
|
|
39
|
+
name: string;
|
|
40
|
+
/** An opaque value your server rendered with the answer (for example an HMAC of the trace id), passed through untouched. */
|
|
41
|
+
token?: string;
|
|
42
|
+
}
|
|
43
|
+
/** Comment box: `off` (default), `optional` (offered after a vote) or `required` (a thumbs-down needs one). */
|
|
44
|
+
export type CommentMode = "off" | "optional" | "required";
|
|
45
|
+
/** The texts the widget shows; every one is an attribute (`question`, `label-up`, ...). */
|
|
46
|
+
export interface FeedbackTexts {
|
|
47
|
+
question: string;
|
|
48
|
+
labelUp: string;
|
|
49
|
+
labelDown: string;
|
|
50
|
+
commentLabel: string;
|
|
51
|
+
commentPlaceholder: string;
|
|
52
|
+
submit: string;
|
|
53
|
+
skip: string;
|
|
54
|
+
thanks: string;
|
|
55
|
+
error: string;
|
|
56
|
+
commentRequired: string;
|
|
57
|
+
commentTooLong: string;
|
|
58
|
+
}
|
|
59
|
+
export declare const DEFAULT_TEXTS: Readonly<FeedbackTexts>;
|
|
60
|
+
/** The SDKs' comment bound (scores.md: up to 2,000 bytes). */
|
|
61
|
+
export declare const MAX_COMMENT_BYTES = 2000;
|
|
62
|
+
/** Why a payload cannot be sent ("" when it can). The same rules the SDKs apply to `feedback()`. */
|
|
63
|
+
/** A comment's size in UTF-8 bytes, the unit the SDKs bound it in. */
|
|
64
|
+
export declare function commentBytes(comment: string): number;
|
|
65
|
+
export declare function validatePayload(p: FeedbackPayload): string;
|
|
66
|
+
/**
|
|
67
|
+
* Whether `endpoint` may be posted to from `origin`: relative and same-origin
|
|
68
|
+
* URLs always; another origin only with `allowCrossOrigin` (the trace id and
|
|
69
|
+
* the comment are the app's data, so they go to the app's own backend by
|
|
70
|
+
* default). Never a non-http(s) scheme.
|
|
71
|
+
*/
|
|
72
|
+
export declare function endpointAllowed(endpoint: string, origin: string, allowCrossOrigin?: boolean): boolean;
|
|
73
|
+
/** The theme variables (set them on the element or any ancestor). */
|
|
74
|
+
export declare const CSS_VARIABLES: readonly ["--sb-feedback-font", "--sb-feedback-fg", "--sb-feedback-muted", "--sb-feedback-bg", "--sb-feedback-border", "--sb-feedback-accent", "--sb-feedback-accent-fg", "--sb-feedback-radius", "--sb-feedback-gap", "--sb-feedback-focus", "--sb-feedback-error"];
|
|
75
|
+
/**
|
|
76
|
+
* Put the styles on the shadow root without inline CSS where the browser
|
|
77
|
+
* can: a constructed stylesheet (`adoptedStyleSheets`) is not inline style,
|
|
78
|
+
* so a strict `style-src` Content Security Policy allows it. Older browsers
|
|
79
|
+
* get a `<style>` element carrying the element's `nonce` attribute, which a
|
|
80
|
+
* nonce-based policy allows. Returns which one it used.
|
|
81
|
+
*/
|
|
82
|
+
export declare function applyStyles(root: ShadowRoot, nonce: string | null): "adopted" | "style";
|
|
83
|
+
type FetchLike = (input: string, init: RequestInit) => Promise<{
|
|
84
|
+
ok: boolean;
|
|
85
|
+
status: number;
|
|
86
|
+
}>;
|
|
87
|
+
declare const Base: typeof HTMLElement;
|
|
88
|
+
/**
|
|
89
|
+
* The element. Attributes: `trace-id` (required), `span-id`, `endpoint`,
|
|
90
|
+
* `name` (default `user_feedback`), `comment` (`off` | `optional` |
|
|
91
|
+
* `required`), `token`, `cross-origin` (allow an endpoint on another
|
|
92
|
+
* origin), `credentials` (`same-origin` default, `include`, `omit`),
|
|
93
|
+
* `disabled`, `nonce` (for a nonce-based CSP in browsers without
|
|
94
|
+
* constructable stylesheets), and the texts (`question`, `label-up`,
|
|
95
|
+
* `label-down`, `comment-label`, `comment-placeholder`, `submit-label`,
|
|
96
|
+
* `skip-label`, `thanks`, `error-text`, `comment-required-text`,
|
|
97
|
+
* `comment-too-long-text`). Properties: `fetch` (a
|
|
98
|
+
* fetch to use instead of the global one), `value` (the vote, or null),
|
|
99
|
+
* `reset()`.
|
|
100
|
+
*/
|
|
101
|
+
export declare class FeedbackElement extends Base {
|
|
102
|
+
static get observedAttributes(): string[];
|
|
103
|
+
/** A fetch to use instead of the global one (tests, an app's own client). */
|
|
104
|
+
fetch: FetchLike | null;
|
|
105
|
+
private vote;
|
|
106
|
+
private stage;
|
|
107
|
+
private lastPayload;
|
|
108
|
+
private readonly uid;
|
|
109
|
+
private built;
|
|
110
|
+
/** The end user's vote (true up, false down), or null before one. */
|
|
111
|
+
get value(): boolean | null;
|
|
112
|
+
/** Back to the start (for example when the element is reused for another answer). */
|
|
113
|
+
reset(): void;
|
|
114
|
+
connectedCallback(): void;
|
|
115
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
116
|
+
private texts;
|
|
117
|
+
private commentMode;
|
|
118
|
+
private $;
|
|
119
|
+
private build;
|
|
120
|
+
private render;
|
|
121
|
+
private choose;
|
|
122
|
+
/** Mark the comment invalid while it is over the byte bound; true when it fits. */
|
|
123
|
+
private checkLength;
|
|
124
|
+
private submitComment;
|
|
125
|
+
/** Build the payload from the attributes; null (with an error event) when it cannot be sent. */
|
|
126
|
+
private payload;
|
|
127
|
+
private fail;
|
|
128
|
+
private send;
|
|
129
|
+
/** Send the last vote again after an error (no-op otherwise). */
|
|
130
|
+
retry(): void;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Register the element (idempotent; a no-op where there is no
|
|
134
|
+
* `customElements`, such as server rendering). Returns the tag name.
|
|
135
|
+
*/
|
|
136
|
+
export declare function defineFeedbackElement(tag?: string): string;
|
|
137
|
+
export {};
|
|
138
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,6CAA6C;AAC7C,eAAO,MAAM,GAAG,wBAAwB,CAAC;AACzC,0GAA0G;AAC1G,eAAO,MAAM,cAAc,wBAAwB,CAAC;AACpD,qFAAqF;AACrF,eAAO,MAAM,UAAU,6BAA6B,CAAC;AACrD,yGAAyG;AACzG,eAAO,MAAM,WAAW,8BAA8B,CAAC;AACvD,6DAA6D;AAC7D,eAAO,MAAM,YAAY,kBAAkB,CAAC;AAE5C,oGAAoG;AACpG,MAAM,WAAW,eAAe;IAC9B,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,KAAK,EAAE,OAAO,CAAC;IACf,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,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