@qaiddev/quests-embed 1.5.3 → 1.6.1

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 CHANGED
@@ -248,7 +248,7 @@ We offer a Free Plan that hosts both the endpoint and a dashboard for managing y
248
248
 
249
249
  ### Host integration
250
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).
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. `metadata` can also be set on the `<script>` tag as `data-metadata`; the two callbacks are functions, so they need you to construct `QaidQuests` yourself.
252
252
 
253
253
  | Option | Type | Default | Description |
254
254
  |--------|------|---------|-------------|
@@ -297,25 +297,45 @@ Colors accept hex (`#ABC`, `#AABBCC`) or `rgb(r, g, b)` format. The text color u
297
297
 
298
298
  ## Script Tag Data Attributes
299
299
 
300
- When using the script tag method, all config options are available as `data-*` attributes:
300
+ Every config option except the two callbacks (`onComplete`, `onClose`) has a `data-*` attribute, so the script tag alone can set anything else. If a JSON config block is also on the page, the block wins and the attributes are not read.
301
+
302
+ Object options take JSON. In HTML, wrap the value in single quotes so the JSON's double quotes survive: `data-metadata='{"feedbackId":"clx1"}'`.
301
303
 
302
304
  | Attribute | Maps To |
303
305
  |-----------|---------|
304
- | `data-endpoint` | `endpoint` |
305
- | `data-config-url` | `configUrl` |
306
+ | `data-endpoint` | `endpoint` (required) |
306
307
  | `data-api-key` | `apiKey` |
308
+ | `data-questionnaire` | `questionnaire`: the questionnaire as JSON, with a `questions` array. Starts the quest without `data-config-url` |
309
+ | `data-config-url` | `configUrl` |
307
310
  | `data-container` | `container` |
308
311
  | `data-zindex` | `zIndex` |
309
- | `data-positive-color` | `colors.positive` |
310
- | `data-negative-color` | `colors.negative` |
311
- | `data-marker-color` | `colors.marker` |
312
+ | `data-accent-color` | `colors.accent` |
313
+ | `data-error-color` | `colors.error` |
314
+ | `data-focus-color` | `colors.focus` |
315
+ | `data-positive-color` | `colors.positive` (deprecated alias for `colors.accent`) |
316
+ | `data-negative-color` | `colors.negative` (deprecated alias for `colors.error`) |
317
+ | `data-marker-color` | `colors.marker` (deprecated alias for `colors.focus`) |
312
318
  | `data-modal-width` | `modalWidth` |
313
319
  | `data-backdrop-opacity` | `backdropOpacity` |
314
320
  | `data-font-family` | `fontFamily` |
315
321
  | `data-font-size` | `fontSize` |
322
+ | `data-css` | `css` (wins over `data-css-selector`) |
323
+ | `data-css-selector` | `css`, taken from the `textContent` of the element this selector matches |
316
324
  | `data-auto-advance` | `autoAdvance` (`"true"` to enable) |
317
325
  | `data-save-debounce-ms` | `saveDebounceMs` |
318
- | `data-css-selector` | CSS selector for an element whose `textContent` is used as `css` |
326
+ | `data-auto-focus` | `autoFocus` (`"true"` or `"false"`) |
327
+ | `data-animate` | `animate` (`"true"` or `"false"`) |
328
+ | `data-progress-position` | `progressPosition` (`"top"` or `"bottom"`) |
329
+ | `data-theme` | `theme` (`"light"`, `"dark"` or `"auto"`) |
330
+ | `data-unstyled` | `unstyled` (`"true"` to enable) |
331
+ | `data-preset` | `preset` (`"default"`, `"minimal"`, `"pill"` or `"dense"`) |
332
+ | `data-theme-url` | `themeUrl` |
333
+ | `data-theme-document` | `themeDocument`, as a JSON object |
334
+ | `data-metadata` | `metadata`, as a JSON object |
335
+
336
+ `onComplete` and `onClose` are functions, so they can only be passed from code (`new QaidQuests({ ... })`).
337
+
338
+ A value the embed can't use (malformed JSON, a questionnaire with no `questions` array, `data-auto-focus="yes"`, an unknown `data-progress-position`) is ignored with one `console.warn` naming the attribute, and the default stays.
319
339
 
320
340
  ## Modal vs. Inline
321
341
 
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Reading config from the page for the script-tag install: the JSON config
3
+ * block and the embed's own `data-*` attributes.
4
+ *
5
+ * Kept out of `index.ts` so it can be tested: `index.ts` runs auto-init as a
6
+ * side effect of being imported and is excluded from coverage. Not re-exported
7
+ * from `index.ts`, so none of this is public API.
8
+ */
9
+ import type { QuestsConfig } from "./types";
10
+ /**
11
+ * Config from `<script type="application/json" data-quests-config>`.
12
+ * When present and valid it wins outright; the attributes are not read.
13
+ */
14
+ export declare function parseJsonConfig(): Partial<QuestsConfig> | null;
15
+ /**
16
+ * Config from the embed's own `data-*` attributes. Every option that can be
17
+ * written as text has one; only the `onComplete` / `onClose` callbacks need
18
+ * code.
19
+ */
20
+ export declare function parseDataAttributes(script: HTMLScriptElement): Partial<QuestsConfig> | null;
package/dist/embed.d.ts CHANGED
@@ -45,6 +45,7 @@ export declare class QaidQuests {
45
45
  private scrollCueEl;
46
46
  private overflow;
47
47
  private footerEl;
48
+ private primaryBtn;
48
49
  private savingEl;
49
50
  private backdropEl;
50
51
  private currentInput;
@@ -96,6 +97,15 @@ export declare class QaidQuests {
96
97
  private advance;
97
98
  private back;
98
99
  private recomputeVisible;
100
+ /**
101
+ * Label the step's primary button for what pressing it will do: "Submit"
102
+ * when no question after this one is visible under the current answers,
103
+ * "Next" otherwise. Uses the same test as `advance()`, so the two cannot
104
+ * disagree. Called on draw AND on every answer, because an answer can
105
+ * reveal a follow-up (Submit → Next) or hide the last one (Next → Submit).
106
+ * Edits the one button in place — no redraw, so focus and typed text stay.
107
+ */
108
+ private syncPrimaryLabel;
99
109
  private handleAnswerChange;
100
110
  private flushPendingSave;
101
111
  private saveAnswer;