@extantape/payload-plugin-wizards 0.1.1 → 0.1.2
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 +19 -0
- package/dist/client/Wizard.d.ts +15 -2
- package/dist/client/Wizard.js +11 -2
- package/dist/client/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,6 +25,21 @@ Wizards for Payload: gated step-by-step flows, one question per screen with Yes
|
|
|
25
25
|
- your code steps rendered with `next` and `back`;
|
|
26
26
|
- a step with a blank question, stop message or option label shows an alert in place of the step, with no way to answer it;
|
|
27
27
|
- state in memory only.
|
|
28
|
+
- **Button labels:** `labels.next` and `labels.back` take a string (default 'Next' and 'Back') or a function that names the button after the screen it goes to. The function gets `{ index, total, current, target }`. `current` and `target` are slots: `{ step }` for a question or `{ code }` for a code step. `target` is undefined for Next on the last screen and for Back on the first. The button's accessible name is the text you return.
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
<Wizard
|
|
32
|
+
slots={slots}
|
|
33
|
+
renderCode={renderCode}
|
|
34
|
+
onFinish={onFinish}
|
|
35
|
+
labels={{
|
|
36
|
+
next: ({ target }) => (target ? `Next: ${'step' in target ? target.step.question : target.code}` : 'Finish'),
|
|
37
|
+
back: ({ target }) => (target && 'step' in target ? `Back to ${target.step.question}` : 'Back'),
|
|
38
|
+
}}
|
|
39
|
+
/>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Next shows on information steps. Code steps draw their own Next through the `next` they are given.
|
|
28
43
|
- **The answers are checked on the server, not trusted.** Call `answersFor(payload, { flow, answers, req })` before acting. It refuses:
|
|
29
44
|
- a No, or a stopping choice;
|
|
30
45
|
- a step whose question, stop message or an option label is blank in the language asked for (`blankStep`), so nobody is recorded agreeing to text they weren't shown;
|
|
@@ -67,10 +82,14 @@ wizardsPlugin({
|
|
|
67
82
|
|
|
68
83
|
**On its own:** Wizards needs only Payload, an `access.edit` rule, and an upload collection if your steps have videos (`media`, or `false` for none). Your site registers its flows in `flows` and renders its own code steps.
|
|
69
84
|
|
|
85
|
+
**Needs:** Payload `^3.80.0` as a peer dependency, with React `^19.0.0` optional. No other EXTANT APE plugin is required.
|
|
86
|
+
|
|
70
87
|
**Works with:**
|
|
71
88
|
- **Sample Kits:** with `adapters.wizards`, Sample Kits registers its `kit-activation` flow at `config.custom.wizardFlows` and checks the answers with `answersFor`.
|
|
72
89
|
- **Scan:** a code step can show Scan's `<CameraScanButton>`, for example to find a kit. Neither plugin imports the other.
|
|
73
90
|
|
|
91
|
+
**Color Theory:** no direct link. The wizard client brings no colors of its own and takes your site's CSS, so a site styled with Color Theory's `--palette-*` tokens styles it too.
|
|
92
|
+
|
|
74
93
|
**Family:** Wizards sits in the Fulfillment family, with Kitting, Restock, Sample Kits, Shipping, Scan, Labels, Custody and Sequences, though the families are a working draft and Fulfillment is due to be split into different groups.
|
|
75
94
|
|
|
76
95
|
## Install
|
package/dist/client/Wizard.d.ts
CHANGED
|
@@ -19,11 +19,24 @@ export type WizardResult = {
|
|
|
19
19
|
answers: Answer[];
|
|
20
20
|
values: Record<string, unknown>;
|
|
21
21
|
};
|
|
22
|
+
/** What a Next or Back label function is told. */
|
|
23
|
+
export type WizardNavContext = {
|
|
24
|
+
/** Position of the screen the button is on, from 0. */
|
|
25
|
+
index: number;
|
|
26
|
+
/** How many screens the flow has. */
|
|
27
|
+
total: number;
|
|
28
|
+
/** The slot on screen now. A step has `step.question`, a code slot has `code`. */
|
|
29
|
+
current: WizardSlot;
|
|
30
|
+
/** The slot the button goes to. Undefined for Next on the last screen (it finishes the flow) and for Back on the first. */
|
|
31
|
+
target: WizardSlot | undefined;
|
|
32
|
+
};
|
|
33
|
+
/** A fixed string, or a function that names the button from where it goes. The visible text is also the accessible name. */
|
|
34
|
+
export type WizardNavLabel = string | ((ctx: WizardNavContext) => string);
|
|
22
35
|
export type WizardLabels = {
|
|
23
36
|
yes: string;
|
|
24
37
|
no: string;
|
|
25
|
-
next:
|
|
26
|
-
back:
|
|
38
|
+
next: WizardNavLabel;
|
|
39
|
+
back: WizardNavLabel;
|
|
27
40
|
stepOf: (n: number, m: number) => string;
|
|
28
41
|
/** Shown when a code slot has no renderer. That's a bug in the site, not something the person can fix. */
|
|
29
42
|
missingCode: (code: string) => string;
|
package/dist/client/Wizard.js
CHANGED
|
@@ -14,6 +14,9 @@ export const defaultLabels = {
|
|
|
14
14
|
chosen: '(chosen)',
|
|
15
15
|
};
|
|
16
16
|
const buttonStyle = { minHeight: 44, minWidth: 44, padding: '0.5rem 1rem' };
|
|
17
|
+
function resolveNav(label, ctx) {
|
|
18
|
+
return typeof label === 'function' ? label(ctx) : label;
|
|
19
|
+
}
|
|
17
20
|
function isCode(slot) {
|
|
18
21
|
return 'code' in slot;
|
|
19
22
|
}
|
|
@@ -103,7 +106,13 @@ export function Wizard({ slots, renderCode, onFinish, labels: labelOverrides, })
|
|
|
103
106
|
const progress = labels.stepOf(index + 1, slots.length);
|
|
104
107
|
const blank = !isCode(slot) && isBlankStep(slot.step);
|
|
105
108
|
const alertText = blank ? labels.blankStep : error;
|
|
106
|
-
const
|
|
109
|
+
const navContext = (to) => ({
|
|
110
|
+
index,
|
|
111
|
+
total: slots.length,
|
|
112
|
+
current: slot,
|
|
113
|
+
target: slots[to],
|
|
114
|
+
});
|
|
115
|
+
const backButton = index > 0 ? (_jsx("button", { type: "button", style: buttonStyle, onClick: back, disabled: disabled, className: "wizard-back", children: resolveNav(labels.back, navContext(index - 1)) })) : null;
|
|
107
116
|
const liveRegions = (_jsxs(_Fragment, { children: [_jsx("div", { role: "status", "aria-live": "polite", className: "wizard-stop", children: stopMessage ? _jsx("p", { children: stopMessage }) : null }), _jsx("div", { role: "alert", className: "wizard-error", children: alertText ? _jsx("p", { children: alertText }) : null })] }));
|
|
108
117
|
if (isCode(slot)) {
|
|
109
118
|
const render = renderCode[slot.code];
|
|
@@ -131,5 +140,5 @@ export function Wizard({ slots, renderCode, onFinish, labels: labelOverrides, })
|
|
|
131
140
|
focusTarget.current = el;
|
|
132
141
|
}, children: step.question }), step.video ? (
|
|
133
142
|
// Never autoplays; the person starts it. The text version below is always on the page.
|
|
134
|
-
_jsx("video", { controls: true, preload: "none", src: step.video.url, className: "wizard-video", children: _jsx("track", { kind: "captions", default: true, src: step.video.captionsUrl }) })) : null, step.body ? _jsx("p", { className: "wizard-body", children: step.body }) : null, step.kind === 'gate' ? (_jsxs("div", { className: "wizard-actions", role: "group", "aria-labelledby": headingId, children: [_jsxs("button", { type: "button", style: buttonStyle, disabled: disabled, "aria-pressed": previous === 'yes', onClick: () => record(step, 'yes'), children: [labels.yes, previous === 'yes' ? ` ${labels.chosen}` : null] }), _jsx("button", { type: "button", style: buttonStyle, disabled: disabled, onClick: () => stop(step.stopMessage), children: labels.no })] })) : null, step.kind === 'info' ? (_jsx("div", { className: "wizard-actions", children: _jsx("button", { type: "button", style: buttonStyle, disabled: disabled, onClick: () => record(step, 'seen'), children: labels.next }) })) : null, step.kind === 'choice' ? (_jsx("div", { className: "wizard-actions", role: "group", "aria-labelledby": headingId, children: step.options.map((option) => (_jsxs("button", { type: "button", style: buttonStyle, disabled: disabled, "aria-pressed": previous === option.value, onClick: () => (option.stops ? stop(step.stopMessage) : record(step, option.value)), children: [option.label, previous === option.value ? ` ${labels.chosen}` : null] }, option.value))) })) : null, liveRegions, _jsx("div", { className: "wizard-nav", children: backButton })] }));
|
|
143
|
+
_jsx("video", { controls: true, preload: "none", src: step.video.url, className: "wizard-video", children: _jsx("track", { kind: "captions", default: true, src: step.video.captionsUrl }) })) : null, step.body ? _jsx("p", { className: "wizard-body", children: step.body }) : null, step.kind === 'gate' ? (_jsxs("div", { className: "wizard-actions", role: "group", "aria-labelledby": headingId, children: [_jsxs("button", { type: "button", style: buttonStyle, disabled: disabled, "aria-pressed": previous === 'yes', onClick: () => record(step, 'yes'), children: [labels.yes, previous === 'yes' ? ` ${labels.chosen}` : null] }), _jsx("button", { type: "button", style: buttonStyle, disabled: disabled, onClick: () => stop(step.stopMessage), children: labels.no })] })) : null, step.kind === 'info' ? (_jsx("div", { className: "wizard-actions", children: _jsx("button", { type: "button", style: buttonStyle, disabled: disabled, onClick: () => record(step, 'seen'), children: resolveNav(labels.next, navContext(index + 1)) }) })) : null, step.kind === 'choice' ? (_jsx("div", { className: "wizard-actions", role: "group", "aria-labelledby": headingId, children: step.options.map((option) => (_jsxs("button", { type: "button", style: buttonStyle, disabled: disabled, "aria-pressed": previous === option.value, onClick: () => (option.stops ? stop(step.stopMessage) : record(step, option.value)), children: [option.label, previous === option.value ? ` ${labels.chosen}` : null] }, option.value))) })) : null, liveRegions, _jsx("div", { className: "wizard-nav", children: backButton })] }));
|
|
135
144
|
}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Wizard, defaultLabels } from './Wizard.js';
|
|
2
|
-
export type { CodeStepContext, WizardLabels, WizardProps, WizardResult, WizardSlot } from './Wizard.js';
|
|
2
|
+
export type { CodeStepContext, WizardLabels, WizardNavContext, WizardNavLabel, WizardProps, WizardResult, WizardSlot } from './Wizard.js';
|
|
3
3
|
export type { Answer, Step } from '../types.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@extantape/payload-plugin-wizards",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Wizards for Payload: gated step-by-step flows, one question per screen with Yes needed to go on, a video and text per step edited in the admin, and the answers checked on the server and recorded.",
|
|
5
5
|
"homepage": "https://github.com/ExtantApe/payload-plugin-wizards#readme",
|
|
6
6
|
"bugs": {
|