@qaiddev/quests-embed 1.2.0 → 1.4.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 +21 -0
- package/dist/embed.d.ts +6 -0
- package/dist/overflow.d.ts +49 -0
- package/dist/qaid-quests.js +164 -114
- package/dist/qaid-quests.js.map +1 -1
- package/dist/qaid-quests.umd.cjs +4 -4
- package/dist/qaid-quests.umd.cjs.map +1 -1
- package/dist/types.d.ts +23 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -246,6 +246,27 @@ We offer a Free Plan that hosts both the endpoint and a dashboard for managing y
|
|
|
246
246
|
| `saveDebounceMs` | `number` | `500` | Debounce in ms for autosave on text/currency/range |
|
|
247
247
|
| `autoFocus` | `boolean` | `true` | Auto-focus the input on each step. Set `false` in preview/embedded contexts that shouldn't steal focus |
|
|
248
248
|
|
|
249
|
+
### Host integration
|
|
250
|
+
|
|
251
|
+
For programmatic embedding — e.g. launching a quest from another widget — these hooks let the host pass correlation data in and react to the quest's lifecycle. They're only useful when you construct `QaidQuests` yourself (not via the auto-init `<script>` tag).
|
|
252
|
+
|
|
253
|
+
| Option | Type | Default | Description |
|
|
254
|
+
|--------|------|---------|-------------|
|
|
255
|
+
| `metadata` | `Record<string, unknown>` | — | Extra key/value pairs sent verbatim in the create-response `POST` body. The server decides which keys it persists; unknown keys are ignored. Used, for example, by `@qaiddev/thumbs-embed` to pass `{ feedbackId }` so the QAid backend joins the quest answers to the feedback record. |
|
|
256
|
+
| `onComplete` | `(answers) => void` | — | Called once when the quest is completed and submitted (just after the thank-you screen renders), with a copy of the collected answers. Fires in both modal and inline modes. |
|
|
257
|
+
| `onClose` | `() => void` | — | Called once when the embed is torn down — visitor close, host `destroy()`, or teardown after completion. Lets a host that launched the quest drop its reference. |
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
const quest = new QaidQuests({
|
|
261
|
+
endpoint: 'https://qaid.dev/api/quests/responses',
|
|
262
|
+
configUrl: 'https://qaid.dev/api/quests/<questId>/definition',
|
|
263
|
+
apiKey: 'YOUR_API_KEY',
|
|
264
|
+
metadata: { feedbackId: 'clx…' }, // correlate this response server-side
|
|
265
|
+
onComplete: (answers) => console.log('done', answers),
|
|
266
|
+
onClose: () => { /* drop your reference */ },
|
|
267
|
+
});
|
|
268
|
+
```
|
|
269
|
+
|
|
249
270
|
### Appearance
|
|
250
271
|
|
|
251
272
|
| Option | Type | Default | Description |
|
package/dist/embed.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export declare class QaidQuests {
|
|
|
26
26
|
private progressEl;
|
|
27
27
|
private progressFillEl;
|
|
28
28
|
private bodyEl;
|
|
29
|
+
private scrollCueEl;
|
|
30
|
+
private overflow;
|
|
29
31
|
private footerEl;
|
|
30
32
|
private savingEl;
|
|
31
33
|
private backdropEl;
|
|
@@ -40,6 +42,10 @@ export declare class QaidQuests {
|
|
|
40
42
|
private themeUrl;
|
|
41
43
|
private themeDocument;
|
|
42
44
|
private hostCss;
|
|
45
|
+
private metadata;
|
|
46
|
+
private onCompleteCb;
|
|
47
|
+
private onCloseCb;
|
|
48
|
+
private closed;
|
|
43
49
|
constructor(config: QuestsConfig);
|
|
44
50
|
private init;
|
|
45
51
|
private loadTheme;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeping a step readable inside whatever box the host gives us.
|
|
3
|
+
*
|
|
4
|
+
* The card body is the scroll container. Two things were missing: it never
|
|
5
|
+
* adapted its own content to the height available (option tiles have width
|
|
6
|
+
* rules only, so a short container just clipped them), and when content did
|
|
7
|
+
* overflow there was no sign of it at all — the step simply looked cut off.
|
|
8
|
+
*
|
|
9
|
+
* This module owns both. It is DOM-only and free of embed state so it can be
|
|
10
|
+
* driven directly in tests.
|
|
11
|
+
*/
|
|
12
|
+
/** Where the scroll position currently sits. */
|
|
13
|
+
export type ScrollEdge = "none" | "top" | "middle" | "bottom";
|
|
14
|
+
/**
|
|
15
|
+
* Below this many pixels of available height, a step switches to its compact
|
|
16
|
+
* layout: smaller image tiles, tighter gaps. Chosen so the common 2-3 option
|
|
17
|
+
* step fits without scrolling in a ~360px tall container.
|
|
18
|
+
*/
|
|
19
|
+
export declare const COMPACT_HEIGHT = 360;
|
|
20
|
+
/** Which edges of `el` have content beyond them. */
|
|
21
|
+
export declare function scrollEdgeOf(el: {
|
|
22
|
+
scrollTop: number;
|
|
23
|
+
scrollHeight: number;
|
|
24
|
+
clientHeight: number;
|
|
25
|
+
}): ScrollEdge;
|
|
26
|
+
/**
|
|
27
|
+
* Reflect the scroll state onto the body as `data-qaid-scroll`, which the
|
|
28
|
+
* stylesheet turns into a fade mask, and onto the cue element's hidden state.
|
|
29
|
+
*/
|
|
30
|
+
export declare function applyScrollState(body: HTMLElement, cue: HTMLElement | null): ScrollEdge;
|
|
31
|
+
/** Reflect the available height onto the card as `data-qaid-fit`. */
|
|
32
|
+
export declare function applyFitState(card: HTMLElement, availableHeight: number): "compact" | "roomy";
|
|
33
|
+
export interface OverflowWatcher {
|
|
34
|
+
/** Re-measure now — call after rendering a step. */
|
|
35
|
+
refresh(): void;
|
|
36
|
+
/** Detach every listener and observer. */
|
|
37
|
+
destroy(): void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Watch `body` for scrolling and resizing, keeping the scroll and fit state
|
|
41
|
+
* attributes current.
|
|
42
|
+
*
|
|
43
|
+
* A ResizeObserver rather than a CSS container query on height: a container
|
|
44
|
+
* query needs `container-type: size`, which requires a definite height on both
|
|
45
|
+
* axes, and this card is deliberately content-sized when the host does not
|
|
46
|
+
* constrain it. Declaring it would collapse the body to nothing in exactly the
|
|
47
|
+
* inline case the embed supports.
|
|
48
|
+
*/
|
|
49
|
+
export declare function watchOverflow(body: HTMLElement, card: HTMLElement, cue: HTMLElement | null): OverflowWatcher;
|