@nymbalhq/web-components 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/dist/chunk-5IO2QUHO.js +155 -0
- package/dist/chunk-5IO2QUHO.js.map +1 -0
- package/dist/chunk-ALPHUJIM.js +155 -0
- package/dist/chunk-ALPHUJIM.js.map +1 -0
- package/dist/chunk-T74ECICK.js +143 -0
- package/dist/chunk-T74ECICK.js.map +1 -0
- package/dist/{chunk-6XCCAAMF.js → chunk-YQEMZOJL.js} +25 -12
- package/dist/chunk-YQEMZOJL.js.map +1 -0
- package/dist/{chunk-XE6IWISA.js → chunk-YXAE7NDX.js} +31 -19
- package/dist/chunk-YXAE7NDX.js.map +1 -0
- package/dist/elements/nymbal-checkout.d.ts +5 -2
- package/dist/elements/nymbal-checkout.js +1 -1
- package/dist/elements/nymbal-notify-me.d.ts +29 -0
- package/dist/elements/nymbal-notify-me.js +13 -0
- package/dist/elements/nymbal-notify-me.js.map +1 -0
- package/dist/elements/nymbal-order-timeline.d.ts +16 -0
- package/dist/elements/nymbal-order-timeline.js +10 -0
- package/dist/elements/nymbal-order-timeline.js.map +1 -0
- package/dist/elements/nymbal-recently-viewed.d.ts +41 -0
- package/dist/elements/nymbal-recently-viewed.js +13 -0
- package/dist/elements/nymbal-recently-viewed.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +31 -19
- package/dist/register-components.d.ts +4 -1
- package/dist/register-components.js +12 -9
- package/dist/ssr/index.js +12 -9
- package/dist/ssr/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-6XCCAAMF.js.map +0 -1
- package/dist/chunk-XE6IWISA.js.map +0 -1
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import '@lit-labs/ssr-client/lit-element-hydrate-support.js'
|
|
2
|
+
import {
|
|
3
|
+
NymbalVariantElement
|
|
4
|
+
} from "./chunk-UYSZOEOA.js";
|
|
5
|
+
import {
|
|
6
|
+
renderField
|
|
7
|
+
} from "./chunk-PN6QKYE4.js";
|
|
8
|
+
import {
|
|
9
|
+
buttonStyles,
|
|
10
|
+
fieldStyles
|
|
11
|
+
} from "./chunk-GHXTJ2CF.js";
|
|
12
|
+
import {
|
|
13
|
+
baseStyles,
|
|
14
|
+
propertiesOf
|
|
15
|
+
} from "./chunk-EYDMJNNK.js";
|
|
16
|
+
|
|
17
|
+
// src/components/notify-me.ts
|
|
18
|
+
import { css, html, nothing } from "lit";
|
|
19
|
+
var SCHEMA = {
|
|
20
|
+
tag: "nymbal-notify-me",
|
|
21
|
+
reactName: "NotifyMe",
|
|
22
|
+
// The product's first variant and its stock as a server read them; the product store's selected variant once it
|
|
23
|
+
// holds this product.
|
|
24
|
+
attributes: [
|
|
25
|
+
{ name: "product-id", prop: "productId", type: "string" },
|
|
26
|
+
{ name: "variant-id", prop: "variantId", type: "string" },
|
|
27
|
+
{ name: "stock", prop: "stock", type: "number" }
|
|
28
|
+
],
|
|
29
|
+
events: [
|
|
30
|
+
{
|
|
31
|
+
name: "nymbal:alert:requested",
|
|
32
|
+
prop: "onRequested",
|
|
33
|
+
detail: "{ kind: AlertKind; variantId: string }"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
parts: ["form", "heading", "field", "label", "input", "submit", "notice", "error"],
|
|
37
|
+
slots: [],
|
|
38
|
+
children: false
|
|
39
|
+
};
|
|
40
|
+
var NOTICE = "Check your inbox to confirm.";
|
|
41
|
+
var HEADINGS = {
|
|
42
|
+
back_in_stock: "Email me when it's back",
|
|
43
|
+
price_drop: "Email me if the price drops"
|
|
44
|
+
};
|
|
45
|
+
function kindFor(stock) {
|
|
46
|
+
if (stock === void 0 || Number.isNaN(stock)) return null;
|
|
47
|
+
return stock > 0 ? "price_drop" : "back_in_stock";
|
|
48
|
+
}
|
|
49
|
+
var NymbalNotifyMe = class extends NymbalVariantElement {
|
|
50
|
+
static schema = SCHEMA;
|
|
51
|
+
static properties = propertiesOf(SCHEMA);
|
|
52
|
+
static styles = [
|
|
53
|
+
baseStyles,
|
|
54
|
+
buttonStyles,
|
|
55
|
+
fieldStyles,
|
|
56
|
+
css`
|
|
57
|
+
:host {
|
|
58
|
+
display: block;
|
|
59
|
+
max-width: 32rem;
|
|
60
|
+
}
|
|
61
|
+
[part~='heading'] {
|
|
62
|
+
margin: 0 0 var(--nymbal-spacing-sm, 0.5rem);
|
|
63
|
+
font-size: var(--nymbal-font-size-md, 1rem);
|
|
64
|
+
font-weight: var(--nymbal-font-weight-bold, 700);
|
|
65
|
+
}
|
|
66
|
+
[part~='notice'] {
|
|
67
|
+
margin-top: var(--nymbal-spacing-sm, 0.5rem);
|
|
68
|
+
font-size: var(--nymbal-font-size-sm, 0.875rem);
|
|
69
|
+
color: var(--nymbal-color-success, #16a34a);
|
|
70
|
+
}
|
|
71
|
+
[part~='error'] {
|
|
72
|
+
margin-top: var(--nymbal-spacing-sm, 0.5rem);
|
|
73
|
+
font-size: var(--nymbal-font-size-sm, 0.875rem);
|
|
74
|
+
color: var(--nymbal-color-error, #dc2626);
|
|
75
|
+
}
|
|
76
|
+
`
|
|
77
|
+
];
|
|
78
|
+
pending = false;
|
|
79
|
+
error = null;
|
|
80
|
+
/** `${variantId}:${kind}` of each accepted request. */
|
|
81
|
+
acceptedFor = /* @__PURE__ */ new Set();
|
|
82
|
+
/** The variant the form is for and its stock: the store's selected one once it holds this product. */
|
|
83
|
+
followed() {
|
|
84
|
+
const store = this.selected();
|
|
85
|
+
if (store === null) return { variantId: this.variantId, stock: this.stock };
|
|
86
|
+
return { variantId: store.variant?.id, stock: store.variant?.stock ?? 0 };
|
|
87
|
+
}
|
|
88
|
+
onSubmit = (event) => {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
const { variantId, stock } = this.followed();
|
|
91
|
+
const kind = kindFor(stock);
|
|
92
|
+
if (this.pending || variantId === void 0 || kind === null) return;
|
|
93
|
+
if (this.acceptedFor.has(`${variantId}:${kind}`)) return;
|
|
94
|
+
this.pending = true;
|
|
95
|
+
this.error = null;
|
|
96
|
+
const email = this.renderRoot.querySelector('[name="email"]')?.value ?? "";
|
|
97
|
+
const sent = this.client.adapter.alerts.subscribe({ email, variantId, kind });
|
|
98
|
+
this.requestUpdate();
|
|
99
|
+
sent.then(
|
|
100
|
+
() => {
|
|
101
|
+
this.pending = false;
|
|
102
|
+
this.acceptedFor.add(`${variantId}:${kind}`);
|
|
103
|
+
this.requestUpdate();
|
|
104
|
+
this.dispatchEvent(
|
|
105
|
+
new CustomEvent("nymbal:alert:requested", {
|
|
106
|
+
bubbles: true,
|
|
107
|
+
composed: true,
|
|
108
|
+
detail: { kind, variantId }
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
},
|
|
112
|
+
() => {
|
|
113
|
+
this.pending = false;
|
|
114
|
+
this.error = "Something went wrong. Please try again.";
|
|
115
|
+
this.requestUpdate();
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
render() {
|
|
120
|
+
const { variantId, stock } = this.followed();
|
|
121
|
+
const kind = kindFor(stock);
|
|
122
|
+
if (kind === null) return nothing;
|
|
123
|
+
const accepted = variantId !== void 0 && this.acceptedFor.has(`${variantId}:${kind}`);
|
|
124
|
+
return html`
|
|
125
|
+
<form part="form" data-testid="notify-me" data-kind=${kind} @submit=${this.onSubmit}>
|
|
126
|
+
<h3 part="heading">${HEADINGS[kind]}</h3>
|
|
127
|
+
${renderField({
|
|
128
|
+
id: "notify-me-email",
|
|
129
|
+
name: "email",
|
|
130
|
+
label: "Email",
|
|
131
|
+
type: "email",
|
|
132
|
+
autocomplete: "email",
|
|
133
|
+
required: true,
|
|
134
|
+
placeholder: "you@example.com"
|
|
135
|
+
})}
|
|
136
|
+
<button
|
|
137
|
+
type="submit"
|
|
138
|
+
part="submit"
|
|
139
|
+
class="btn btn-primary"
|
|
140
|
+
data-testid="notify-me-submit"
|
|
141
|
+
?disabled=${this.pending || accepted}
|
|
142
|
+
>
|
|
143
|
+
Notify me
|
|
144
|
+
</button>
|
|
145
|
+
${accepted ? html`<p part="notice" role="status" data-testid="notify-me-notice">${NOTICE}</p>` : nothing}
|
|
146
|
+
${this.error === null ? nothing : html`<p part="error" role="alert" data-testid="notify-me-error">${this.error}</p>`}
|
|
147
|
+
</form>
|
|
148
|
+
`;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export {
|
|
153
|
+
NymbalNotifyMe
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=chunk-5IO2QUHO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/notify-me.ts"],"sourcesContent":["import { css, html, nothing } from 'lit'\nimport type { AlertKind } from '@nymbalhq/types'\nimport { baseStyles, propertiesOf, type ElementSchema } from '../base-element.js'\nimport { renderField } from '../form-element.js'\nimport { NymbalVariantElement } from '../selected-variant.js'\nimport { buttonStyles, fieldStyles } from '../view-styles.js'\n\nconst SCHEMA: ElementSchema = {\n tag: 'nymbal-notify-me',\n reactName: 'NotifyMe',\n // The product's first variant and its stock as a server read them; the product store's selected variant once it\n // holds this product.\n attributes: [\n { name: 'product-id', prop: 'productId', type: 'string' },\n { name: 'variant-id', prop: 'variantId', type: 'string' },\n { name: 'stock', prop: 'stock', type: 'number' },\n ],\n events: [\n {\n name: 'nymbal:alert:requested',\n prop: 'onRequested',\n detail: '{ kind: AlertKind; variantId: string }',\n },\n ],\n parts: ['form', 'heading', 'field', 'label', 'input', 'submit', 'notice', 'error'],\n slots: [],\n children: false,\n}\n\nconst NOTICE = 'Check your inbox to confirm.'\n\nconst HEADINGS: Record<AlertKind, string> = {\n back_in_stock: \"Email me when it's back\",\n price_drop: 'Email me if the price drops',\n}\n\n/** The alert a variant at `stock` offers, or none while its stock is unknown. */\nfunction kindFor(stock: number | undefined): AlertKind | null {\n if (stock === undefined || Number.isNaN(stock)) return null\n return stock > 0 ? 'price_drop' : 'back_in_stock'\n}\n\n/**\n * The alert form for the variant the page shows: \"email me when it's back\" for an out-of-stock variant, \"email me if\n * the price drops\" for an in-stock one. One subscribe per submission: `requestSubmit()` and Enter fire `submit` while\n * the button is disabled, so the pending flag, not the button, is the guard (as `NymbalFormElement`'s). An accepted\n * request stays accepted for its variant and kind, so a second click cannot send a second confirmation.\n */\nexport class NymbalNotifyMe extends NymbalVariantElement {\n static override schema = SCHEMA\n static override properties = propertiesOf(SCHEMA)\n static override styles = [\n baseStyles,\n buttonStyles,\n fieldStyles,\n css`\n :host {\n display: block;\n max-width: 32rem;\n }\n [part~='heading'] {\n margin: 0 0 var(--nymbal-spacing-sm, 0.5rem);\n font-size: var(--nymbal-font-size-md, 1rem);\n font-weight: var(--nymbal-font-weight-bold, 700);\n }\n [part~='notice'] {\n margin-top: var(--nymbal-spacing-sm, 0.5rem);\n font-size: var(--nymbal-font-size-sm, 0.875rem);\n color: var(--nymbal-color-success, #16a34a);\n }\n [part~='error'] {\n margin-top: var(--nymbal-spacing-sm, 0.5rem);\n font-size: var(--nymbal-font-size-sm, 0.875rem);\n color: var(--nymbal-color-error, #dc2626);\n }\n `,\n ]\n\n declare variantId: string | undefined\n declare stock: number | undefined\n\n private pending = false\n private error: string | null = null\n /** `${variantId}:${kind}` of each accepted request. */\n private readonly acceptedFor = new Set<string>()\n\n /** The variant the form is for and its stock: the store's selected one once it holds this product. */\n private followed(): { variantId: string | undefined; stock: number | undefined } {\n const store = this.selected()\n if (store === null) return { variantId: this.variantId, stock: this.stock }\n return { variantId: store.variant?.id, stock: store.variant?.stock ?? 0 }\n }\n\n private readonly onSubmit = (event: Event): void => {\n event.preventDefault()\n const { variantId, stock } = this.followed()\n const kind = kindFor(stock)\n if (this.pending || variantId === undefined || kind === null) return\n if (this.acceptedFor.has(`${variantId}:${kind}`)) return\n this.pending = true\n this.error = null\n const email = this.renderRoot.querySelector<HTMLInputElement>('[name=\"email\"]')?.value ?? ''\n const sent = this.client.adapter.alerts.subscribe({ email, variantId, kind })\n this.requestUpdate()\n sent.then(\n () => {\n this.pending = false\n this.acceptedFor.add(`${variantId}:${kind}`)\n this.requestUpdate()\n this.dispatchEvent(\n new CustomEvent('nymbal:alert:requested', {\n bubbles: true,\n composed: true,\n detail: { kind, variantId },\n }),\n )\n },\n () => {\n this.pending = false\n this.error = 'Something went wrong. Please try again.'\n this.requestUpdate()\n },\n )\n }\n\n protected override render() {\n const { variantId, stock } = this.followed()\n const kind = kindFor(stock)\n if (kind === null) return nothing\n const accepted = variantId !== undefined && this.acceptedFor.has(`${variantId}:${kind}`)\n return html`\n <form part=\"form\" data-testid=\"notify-me\" data-kind=${kind} @submit=${this.onSubmit}>\n <h3 part=\"heading\">${HEADINGS[kind]}</h3>\n ${renderField({\n id: 'notify-me-email',\n name: 'email',\n label: 'Email',\n type: 'email',\n autocomplete: 'email',\n required: true,\n placeholder: 'you@example.com',\n })}\n <button\n type=\"submit\"\n part=\"submit\"\n class=\"btn btn-primary\"\n data-testid=\"notify-me-submit\"\n ?disabled=${this.pending || accepted}\n >\n Notify me\n </button>\n ${accepted\n ? html`<p part=\"notice\" role=\"status\" data-testid=\"notify-me-notice\">${NOTICE}</p>`\n : nothing}\n ${this.error === null\n ? nothing\n : html`<p part=\"error\" role=\"alert\" data-testid=\"notify-me-error\">${this.error}</p>`}\n </form>\n `\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAS,KAAK,MAAM,eAAe;AAOnC,IAAM,SAAwB;AAAA,EAC5B,KAAK;AAAA,EACL,WAAW;AAAA;AAAA;AAAA,EAGX,YAAY;AAAA,IACV,EAAE,MAAM,cAAc,MAAM,aAAa,MAAM,SAAS;AAAA,IACxD,EAAE,MAAM,cAAc,MAAM,aAAa,MAAM,SAAS;AAAA,IACxD,EAAE,MAAM,SAAS,MAAM,SAAS,MAAM,SAAS;AAAA,EACjD;AAAA,EACA,QAAQ;AAAA,IACN;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF;AAAA,EACA,OA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-support.js'
|
|
2
|
+
import {
|
|
3
|
+
NymbalElement,
|
|
4
|
+
baseStyles,
|
|
5
|
+
parsedJson,
|
|
6
|
+
propertiesOf
|
|
7
|
+
} from "./chunk-EYDMJNNK.js";
|
|
8
|
+
|
|
9
|
+
// src/components/order-timeline.ts
|
|
10
|
+
import { css, html, nothing } from "lit";
|
|
11
|
+
var SCHEMA = {
|
|
12
|
+
tag: "nymbal-order-timeline",
|
|
13
|
+
reactName: "OrderTimeline",
|
|
14
|
+
// The `timeline` `GET /api/orders/:n` serves: `[{ kind, at }]`, oldest first.
|
|
15
|
+
attributes: [
|
|
16
|
+
{ name: "entries", prop: "entries", type: "json" },
|
|
17
|
+
{ name: "time-zone", prop: "timeZone", type: "string" }
|
|
18
|
+
],
|
|
19
|
+
events: [],
|
|
20
|
+
parts: ["timeline", "heading", "list", "entry", "label", "time"],
|
|
21
|
+
slots: [],
|
|
22
|
+
children: false
|
|
23
|
+
};
|
|
24
|
+
var LABELS = {
|
|
25
|
+
placed: "Order placed",
|
|
26
|
+
paid: "Payment received",
|
|
27
|
+
shipped: "Shipped",
|
|
28
|
+
delivered: "Delivered",
|
|
29
|
+
cancelled: "Cancelled",
|
|
30
|
+
partially_refunded: "Partially refunded",
|
|
31
|
+
refunded: "Refunded"
|
|
32
|
+
};
|
|
33
|
+
var formatters = /* @__PURE__ */ new Map();
|
|
34
|
+
function formatterFor(timeZone) {
|
|
35
|
+
let formatter = formatters.get(timeZone);
|
|
36
|
+
if (formatter === void 0) {
|
|
37
|
+
try {
|
|
38
|
+
formatter = new Intl.DateTimeFormat("en-GB", {
|
|
39
|
+
day: "numeric",
|
|
40
|
+
month: "short",
|
|
41
|
+
year: "numeric",
|
|
42
|
+
hour: "2-digit",
|
|
43
|
+
minute: "2-digit",
|
|
44
|
+
hourCycle: "h23",
|
|
45
|
+
timeZone,
|
|
46
|
+
timeZoneName: "short"
|
|
47
|
+
});
|
|
48
|
+
} catch {
|
|
49
|
+
formatter = formatterFor("UTC");
|
|
50
|
+
}
|
|
51
|
+
formatters.set(timeZone, formatter);
|
|
52
|
+
}
|
|
53
|
+
return formatter;
|
|
54
|
+
}
|
|
55
|
+
function renderable(value) {
|
|
56
|
+
if (!Array.isArray(value)) return [];
|
|
57
|
+
const entries = [];
|
|
58
|
+
for (const item of value) {
|
|
59
|
+
if (typeof item !== "object" || item === null) continue;
|
|
60
|
+
const { kind, at } = item;
|
|
61
|
+
if (typeof kind !== "string" || !Object.hasOwn(LABELS, kind) || typeof at !== "string") continue;
|
|
62
|
+
const date = new Date(at);
|
|
63
|
+
if (Number.isNaN(date.getTime())) continue;
|
|
64
|
+
entries.push({ kind, at, date });
|
|
65
|
+
}
|
|
66
|
+
return entries;
|
|
67
|
+
}
|
|
68
|
+
var NymbalOrderTimeline = class extends NymbalElement {
|
|
69
|
+
static schema = SCHEMA;
|
|
70
|
+
static properties = propertiesOf(SCHEMA);
|
|
71
|
+
static styles = [
|
|
72
|
+
baseStyles,
|
|
73
|
+
css`
|
|
74
|
+
:host {
|
|
75
|
+
display: block;
|
|
76
|
+
font-family: var(--nymbal-font-family, system-ui, -apple-system, sans-serif);
|
|
77
|
+
color: var(--nymbal-color-text, #18181b);
|
|
78
|
+
}
|
|
79
|
+
[part~='timeline'] {
|
|
80
|
+
padding: var(--nymbal-spacing-lg, 1.5rem);
|
|
81
|
+
background-color: var(--nymbal-color-surface, #ffffff);
|
|
82
|
+
border: 1px solid var(--nymbal-color-border, #e4e4e7);
|
|
83
|
+
border-radius: var(--nymbal-radius-lg, 0.75rem);
|
|
84
|
+
}
|
|
85
|
+
[part~='heading'] {
|
|
86
|
+
margin: 0 0 var(--nymbal-spacing-md, 1rem);
|
|
87
|
+
line-height: 1.2;
|
|
88
|
+
font-size: var(--nymbal-font-size-lg, 1.125rem);
|
|
89
|
+
font-weight: var(--nymbal-font-weight-bold, 700);
|
|
90
|
+
}
|
|
91
|
+
[part~='list'] {
|
|
92
|
+
margin: 0;
|
|
93
|
+
padding: 0;
|
|
94
|
+
list-style: none;
|
|
95
|
+
}
|
|
96
|
+
[part~='entry'] {
|
|
97
|
+
position: relative;
|
|
98
|
+
display: flex;
|
|
99
|
+
flex-wrap: wrap;
|
|
100
|
+
justify-content: space-between;
|
|
101
|
+
gap: var(--nymbal-spacing-xs, 0.25rem) var(--nymbal-spacing-md, 1rem);
|
|
102
|
+
padding: var(--nymbal-spacing-xs, 0.25rem) 0 var(--nymbal-spacing-sm, 0.5rem)
|
|
103
|
+
var(--nymbal-spacing-lg, 1.5rem);
|
|
104
|
+
border-left: 2px solid var(--nymbal-color-border, #e4e4e7);
|
|
105
|
+
font-size: var(--nymbal-font-size-sm, 0.875rem);
|
|
106
|
+
}
|
|
107
|
+
[part~='entry']::before {
|
|
108
|
+
content: '';
|
|
109
|
+
position: absolute;
|
|
110
|
+
left: -0.4375rem;
|
|
111
|
+
top: 0.375rem;
|
|
112
|
+
width: 0.75rem;
|
|
113
|
+
height: 0.75rem;
|
|
114
|
+
border-radius: 50%;
|
|
115
|
+
background-color: var(--nymbal-color-border, #e4e4e7);
|
|
116
|
+
}
|
|
117
|
+
[part~='entry'][aria-current='step']::before {
|
|
118
|
+
background-color: var(--nymbal-color-primary, #18181b);
|
|
119
|
+
}
|
|
120
|
+
[part~='entry'][aria-current='step'] [part~='label'] {
|
|
121
|
+
font-weight: var(--nymbal-font-weight-bold, 700);
|
|
122
|
+
}
|
|
123
|
+
[part~='time'] {
|
|
124
|
+
color: var(--nymbal-color-text-muted, #71717a);
|
|
125
|
+
}
|
|
126
|
+
`
|
|
127
|
+
];
|
|
128
|
+
render() {
|
|
129
|
+
const entries = renderable(parsedJson(this, "entries", this.entries));
|
|
130
|
+
if (entries.length === 0) return nothing;
|
|
131
|
+
const format = formatterFor(this.timeZone || "UTC");
|
|
132
|
+
const last = entries.length - 1;
|
|
133
|
+
return html`<section part="timeline" data-testid="order-timeline">
|
|
134
|
+
<h2 part="heading">Order progress</h2>
|
|
135
|
+
<ol part="list">
|
|
136
|
+
${entries.map(
|
|
137
|
+
(e, i) => html`<li
|
|
138
|
+
part="entry"
|
|
139
|
+
data-testid="timeline-entry"
|
|
140
|
+
data-kind=${e.kind}
|
|
141
|
+
aria-current=${i === last ? "step" : nothing}
|
|
142
|
+
>
|
|
143
|
+
<span part="label">${LABELS[e.kind]}</span>
|
|
144
|
+
<time part="time" datetime=${e.at}>${format.format(e.date)}</time>
|
|
145
|
+
</li>`
|
|
146
|
+
)}
|
|
147
|
+
</ol>
|
|
148
|
+
</section>`;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export {
|
|
153
|
+
NymbalOrderTimeline
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=chunk-ALPHUJIM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/order-timeline.ts"],"sourcesContent":["import { css, html, nothing } from 'lit'\nimport type { OrderTimelineKind } from '@nymbalhq/types'\nimport {\n baseStyles,\n NymbalElement,\n parsedJson,\n propertiesOf,\n type ElementSchema,\n} from '../base-element.js'\n\nconst SCHEMA: ElementSchema = {\n tag: 'nymbal-order-timeline',\n reactName: 'OrderTimeline',\n // The `timeline` `GET /api/orders/:n` serves: `[{ kind, at }]`, oldest first.\n attributes: [\n { name: 'entries', prop: 'entries', type: 'json' },\n { name: 'time-zone', prop: 'timeZone', type: 'string' },\n ],\n events: [],\n parts: ['timeline', 'heading', 'list', 'entry', 'label', 'time'],\n slots: [],\n children: false,\n}\n\nconst LABELS: Record<OrderTimelineKind, string> = {\n placed: 'Order placed',\n paid: 'Payment received',\n shipped: 'Shipped',\n delivered: 'Delivered',\n cancelled: 'Cancelled',\n partially_refunded: 'Partially refunded',\n refunded: 'Refunded',\n}\n\ninterface Entry {\n kind: OrderTimelineKind\n at: string\n date: Date\n}\n\nconst formatters = new Map<string, Intl.DateTimeFormat>()\n\n// The options are pinned so Node's ICU and the browser's give the same text; the zone is never the host's.\nfunction formatterFor(timeZone: string): Intl.DateTimeFormat {\n let formatter = formatters.get(timeZone)\n if (formatter === undefined) {\n try {\n formatter = new Intl.DateTimeFormat('en-GB', {\n day: 'numeric',\n month: 'short',\n year: 'numeric',\n hour: '2-digit',\n minute: '2-digit',\n hourCycle: 'h23',\n timeZone,\n timeZoneName: 'short',\n })\n } catch {\n formatter = formatterFor('UTC')\n }\n formatters.set(timeZone, formatter)\n }\n return formatter\n}\n\nfunction renderable(value: unknown): Entry[] {\n if (!Array.isArray(value)) return []\n const entries: Entry[] = []\n for (const item of value as unknown[]) {\n if (typeof item !== 'object' || item === null) continue\n const { kind, at } = item as { kind?: unknown; at?: unknown }\n if (typeof kind !== 'string' || !Object.hasOwn(LABELS, kind) || typeof at !== 'string') continue\n const date = new Date(at)\n if (Number.isNaN(date.getTime())) continue\n entries.push({ kind: kind as OrderTimelineKind, at, date })\n }\n return entries\n}\n\n/** What has happened to an order, oldest first, each entry with its time; the last is the order's current step. */\nexport class NymbalOrderTimeline extends NymbalElement {\n static override schema = SCHEMA\n static override properties = propertiesOf(SCHEMA)\n static override styles = [\n baseStyles,\n css`\n :host {\n display: block;\n font-family: var(--nymbal-font-family, system-ui, -apple-system, sans-serif);\n color: var(--nymbal-color-text, #18181b);\n }\n [part~='timeline'] {\n padding: var(--nymbal-spacing-lg, 1.5rem);\n background-color: var(--nymbal-color-surface, #ffffff);\n border: 1px solid var(--nymbal-color-border, #e4e4e7);\n border-radius: var(--nymbal-radius-lg, 0.75rem);\n }\n [part~='heading'] {\n margin: 0 0 var(--nymbal-spacing-md, 1rem);\n line-height: 1.2;\n font-size: var(--nymbal-font-size-lg, 1.125rem);\n font-weight: var(--nymbal-font-weight-bold, 700);\n }\n [part~='list'] {\n margin: 0;\n padding: 0;\n list-style: none;\n }\n [part~='entry'] {\n position: relative;\n display: flex;\n flex-wrap: wrap;\n justify-content: space-between;\n gap: var(--nymbal-spacing-xs, 0.25rem) var(--nymbal-spacing-md, 1rem);\n padding: var(--nymbal-spacing-xs, 0.25rem) 0 var(--nymbal-spacing-sm, 0.5rem)\n var(--nymbal-spacing-lg, 1.5rem);\n border-left: 2px solid var(--nymbal-color-border, #e4e4e7);\n font-size: var(--nymbal-font-size-sm, 0.875rem);\n }\n [part~='entry']::before {\n content: '';\n position: absolute;\n left: -0.4375rem;\n top: 0.375rem;\n width: 0.75rem;\n height: 0.75rem;\n border-radius: 50%;\n background-color: var(--nymbal-color-border, #e4e4e7);\n }\n [part~='entry'][aria-current='step']::before {\n background-color: var(--nymbal-color-primary, #18181b);\n }\n [part~='entry'][aria-current='step'] [part~='label'] {\n font-weight: var(--nymbal-font-weight-bold, 700);\n }\n [part~='time'] {\n color: var(--nymbal-color-text-muted, #71717a);\n }\n `,\n ]\n\n declare entries: unknown\n declare timeZone: string | undefined\n\n protected override render() {\n const entries = renderable(parsedJson<unknown>(this, 'entries', this.entries))\n if (entries.length === 0) return nothing\n const format = formatterFor(this.timeZone || 'UTC')\n const last = entries.length - 1\n return html`<section part=\"timeline\" data-testid=\"order-timeline\">\n <h2 part=\"heading\">Order progress</h2>\n <ol part=\"list\">\n ${entries.map(\n (e, i) =>\n html`<li\n part=\"entry\"\n data-testid=\"timeline-entry\"\n data-kind=${e.kind}\n aria-current=${i === last ? 'step' : nothing}\n >\n <span part=\"label\">${LABELS[e.kind]}</span>\n <time part=\"time\" datetime=${e.at}>${format.format(e.date)}</time>\n </li>`,\n )}\n </ol>\n </section>`\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,KAAK,MAAM,eAAe;AAUnC,IAAM,SAAwB;AAAA,EAC5B,KAAK;AAAA,EACL,WAAW;AAAA;AAAA,EAEX,YAAY;AAAA,IACV,EAAE,MAAM,WAAW,MAAM,WAAW,MAAM,OAAO;AAAA,IACjD,EAAE,MAAM,aAAa,MAAM,YAAY,MAAM,SAAS;AAAA,EACxD;AAAA,EACA,QAAQ,CAAC;AAAA,EACT,OAAO,CAAC,YAAY,WAAW,QAAQ,SAAS,SAAS,MAAM;AAAA,EAC/D,OAAO,CAA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AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsDF;AAAA,EAKmB,SAAS;AAC1B,UAAM,UAAU,WAAW,WAAoB,MAAM,WAAW,KAAK,OAAO,CAAC;AAC7E,QAAI,QAAQ,WAAW,EAAG,QAAO;AACjC,UAAM,SAAS,aAAa,KAAK,YAAY,KAAK;AAClD,UAAM,OAAO,QAAQ,SAAS;AAC9B,WAAO;AAAA;AAAA;AAAA,UAGD,QAAQ;AAAA,MACR,CAAC,GAAG,MACF;AAAA;AAAA;AAAA,0BAGc,EAAE,IAAI;AAAA,6BACH,MAAM,OAAO,SAAS,OAAO;AAAA;AAAA,mCAEvB,OAAO,EAAE,IAAI,CAAC;AAAA,2CACN,EAAE,EAAE,IAAI,OAAO,OAAO,EAAE,IAAI,CAAC;AAAA;AAAA,IAEhE,CAAC;AAAA;AAAA;AAAA,EAGP;AACF;","names":[]}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import '@lit-labs/ssr-client/lit-element-hydrate-support.js'
|
|
2
|
+
import {
|
|
3
|
+
NymbalProductCard,
|
|
4
|
+
cardProductOf
|
|
5
|
+
} from "./chunk-RZVFA3N5.js";
|
|
6
|
+
import {
|
|
7
|
+
NymbalElement,
|
|
8
|
+
baseStyles,
|
|
9
|
+
propertiesOf
|
|
10
|
+
} from "./chunk-EYDMJNNK.js";
|
|
11
|
+
|
|
12
|
+
// src/components/recently-viewed.ts
|
|
13
|
+
import { css, html, nothing } from "lit";
|
|
14
|
+
var SCHEMA = {
|
|
15
|
+
tag: "nymbal-recently-viewed",
|
|
16
|
+
reactName: "RecentlyViewed",
|
|
17
|
+
// `current`: the page's product, recorded as viewed and left out of the list. `limit`: how many cards it shows.
|
|
18
|
+
attributes: [
|
|
19
|
+
{ name: "current", prop: "current", type: "string" },
|
|
20
|
+
{ name: "limit", prop: "limit", type: "number" }
|
|
21
|
+
],
|
|
22
|
+
events: [
|
|
23
|
+
{ name: "nymbal:recently-viewed:loaded", prop: "onLoaded", detail: "{ productIds: string[] }" }
|
|
24
|
+
],
|
|
25
|
+
parts: ["section", "heading", "grid"],
|
|
26
|
+
slots: ["heading"],
|
|
27
|
+
children: false
|
|
28
|
+
};
|
|
29
|
+
var DEFAULT_LIMIT = 4;
|
|
30
|
+
var NymbalRecentlyViewed = class extends NymbalElement {
|
|
31
|
+
static schema = SCHEMA;
|
|
32
|
+
static uses = [NymbalProductCard];
|
|
33
|
+
static properties = { ...propertiesOf(SCHEMA), listed: { state: true } };
|
|
34
|
+
static styles = [
|
|
35
|
+
baseStyles,
|
|
36
|
+
css`
|
|
37
|
+
:host {
|
|
38
|
+
display: block;
|
|
39
|
+
font-family: var(--nymbal-font-family, system-ui, -apple-system, sans-serif);
|
|
40
|
+
color: var(--nymbal-color-text, #18181b);
|
|
41
|
+
}
|
|
42
|
+
[part~='section'] {
|
|
43
|
+
margin-top: var(--nymbal-spacing-xl, 2rem);
|
|
44
|
+
}
|
|
45
|
+
[part~='heading'] {
|
|
46
|
+
margin: 0 0 var(--nymbal-spacing-lg, 1.5rem);
|
|
47
|
+
font-size: var(--nymbal-font-size-xl, 1.25rem);
|
|
48
|
+
font-weight: var(--nymbal-font-weight-bold, 700);
|
|
49
|
+
}
|
|
50
|
+
[part~='grid'] {
|
|
51
|
+
display: grid;
|
|
52
|
+
gap: var(--nymbal-spacing-md, 1rem);
|
|
53
|
+
grid-template-columns: 1fr;
|
|
54
|
+
}
|
|
55
|
+
@media (min-width: 641px) {
|
|
56
|
+
[part~='grid'] {
|
|
57
|
+
grid-template-columns: repeat(2, 1fr);
|
|
58
|
+
gap: var(--nymbal-spacing-lg, 1.5rem);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
@media (min-width: 1025px) {
|
|
62
|
+
[part~='grid'] {
|
|
63
|
+
grid-template-columns: repeat(4, 1fr);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
`
|
|
67
|
+
];
|
|
68
|
+
/** The last `current` recorded: a re-render, a reconnect or the same value again records nothing. */
|
|
69
|
+
recorded;
|
|
70
|
+
started = false;
|
|
71
|
+
/** Reads run one after another, so each new `current` is recorded before the list it changes is read. */
|
|
72
|
+
reads = Promise.resolve();
|
|
73
|
+
constructor() {
|
|
74
|
+
super();
|
|
75
|
+
this.listed = [];
|
|
76
|
+
}
|
|
77
|
+
get shown() {
|
|
78
|
+
const n = this.limit;
|
|
79
|
+
const limit = typeof n === "number" && Number.isInteger(n) && n > 0 ? n : DEFAULT_LIMIT;
|
|
80
|
+
return this.listed.filter((p) => p.id !== this.current).slice(0, limit);
|
|
81
|
+
}
|
|
82
|
+
/** After the first update, so a `current` set as the element connects is recorded before the first read. */
|
|
83
|
+
updated(changed) {
|
|
84
|
+
super.updated(changed);
|
|
85
|
+
if (!this.hasClient) return;
|
|
86
|
+
const current = typeof this.current === "string" && this.current !== "" ? this.current : void 0;
|
|
87
|
+
if (!this.started) {
|
|
88
|
+
this.started = true;
|
|
89
|
+
this.queueRead(current);
|
|
90
|
+
} else if (changed.has("current") && current !== void 0 && current !== this.recorded) {
|
|
91
|
+
this.queueRead(current);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
queueRead(current) {
|
|
95
|
+
if (current !== void 0) this.recorded = current;
|
|
96
|
+
this.reads = this.reads.then(() => this.read(current));
|
|
97
|
+
}
|
|
98
|
+
async read(current) {
|
|
99
|
+
const { recentlyViewed } = this.client;
|
|
100
|
+
if (current !== void 0) {
|
|
101
|
+
try {
|
|
102
|
+
await recentlyViewed.record(current);
|
|
103
|
+
} catch (err) {
|
|
104
|
+
console.warn("[nymbal-recently-viewed] the view was not recorded", err);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
this.listed = (await recentlyViewed.list()).items;
|
|
109
|
+
} catch (err) {
|
|
110
|
+
console.warn("[nymbal-recently-viewed] the list could not be read", err);
|
|
111
|
+
this.listed = [];
|
|
112
|
+
}
|
|
113
|
+
await this.updateComplete;
|
|
114
|
+
this.dispatchEvent(
|
|
115
|
+
new CustomEvent("nymbal:recently-viewed:loaded", {
|
|
116
|
+
detail: { productIds: this.shown.map((p) => p.id) },
|
|
117
|
+
bubbles: true,
|
|
118
|
+
composed: true
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
render() {
|
|
123
|
+
const shown = this.readsStores ? this.shown : [];
|
|
124
|
+
if (shown.length === 0) return nothing;
|
|
125
|
+
return html`
|
|
126
|
+
<section part="section">
|
|
127
|
+
<h2 part="heading"><slot name="heading">Recently viewed</slot></h2>
|
|
128
|
+
<div part="grid">
|
|
129
|
+
${shown.map(
|
|
130
|
+
(p) => html`<nymbal-product-card
|
|
131
|
+
product=${JSON.stringify(cardProductOf(p))}
|
|
132
|
+
></nymbal-product-card>`
|
|
133
|
+
)}
|
|
134
|
+
</div>
|
|
135
|
+
</section>
|
|
136
|
+
`;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
NymbalRecentlyViewed
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=chunk-T74ECICK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/recently-viewed.ts"],"sourcesContent":["import { css, html, nothing, type PropertyValues } from 'lit'\nimport { baseStyles, NymbalElement, propertiesOf, type ElementSchema } from '../base-element.js'\nimport { cardProductOf, NymbalProductCard } from './product-card.js'\n\nconst SCHEMA: ElementSchema = {\n tag: 'nymbal-recently-viewed',\n reactName: 'RecentlyViewed',\n // `current`: the page's product, recorded as viewed and left out of the list. `limit`: how many cards it shows.\n attributes: [\n { name: 'current', prop: 'current', type: 'string' },\n { name: 'limit', prop: 'limit', type: 'number' },\n ],\n events: [\n { name: 'nymbal:recently-viewed:loaded', prop: 'onLoaded', detail: '{ productIds: string[] }' },\n ],\n parts: ['section', 'heading', 'grid'],\n slots: ['heading'],\n children: false,\n}\n\nconst DEFAULT_LIMIT = 4\n\ntype Listed = Parameters<typeof cardProductOf>[0] & { id: string }\n\n/**\n * The shopper's recently viewed products, from the store: one page view records `current` once, then reads the list\n * once. It renders nothing until the list has something besides `current`, and nothing without a client (a server).\n */\nexport class NymbalRecentlyViewed extends NymbalElement {\n static override schema = SCHEMA\n static uses = [NymbalProductCard]\n static override properties = { ...propertiesOf(SCHEMA), listed: { state: true } }\n static override styles = [\n baseStyles,\n css`\n :host {\n display: block;\n font-family: var(--nymbal-font-family, system-ui, -apple-system, sans-serif);\n color: var(--nymbal-color-text, #18181b);\n }\n [part~='section'] {\n margin-top: var(--nymbal-spacing-xl, 2rem);\n }\n [part~='heading'] {\n margin: 0 0 var(--nymbal-spacing-lg, 1.5rem);\n font-size: var(--nymbal-font-size-xl, 1.25rem);\n font-weight: var(--nymbal-font-weight-bold, 700);\n }\n [part~='grid'] {\n display: grid;\n gap: var(--nymbal-spacing-md, 1rem);\n grid-template-columns: 1fr;\n }\n @media (min-width: 641px) {\n [part~='grid'] {\n grid-template-columns: repeat(2, 1fr);\n gap: var(--nymbal-spacing-lg, 1.5rem);\n }\n }\n @media (min-width: 1025px) {\n [part~='grid'] {\n grid-template-columns: repeat(4, 1fr);\n }\n }\n `,\n ]\n\n declare current: string | undefined\n declare limit: number | undefined\n declare listed: Listed[]\n\n /** The last `current` recorded: a re-render, a reconnect or the same value again records nothing. */\n private recorded: string | undefined\n private started = false\n /** Reads run one after another, so each new `current` is recorded before the list it changes is read. */\n private reads: Promise<void> = Promise.resolve()\n\n constructor() {\n super()\n this.listed = []\n }\n\n private get shown(): Listed[] {\n const n = this.limit\n const limit = typeof n === 'number' && Number.isInteger(n) && n > 0 ? n : DEFAULT_LIMIT\n return this.listed.filter((p) => p.id !== this.current).slice(0, limit)\n }\n\n /** After the first update, so a `current` set as the element connects is recorded before the first read. */\n protected override updated(changed: PropertyValues): void {\n super.updated(changed)\n if (!this.hasClient) return\n const current = typeof this.current === 'string' && this.current !== '' ? this.current : undefined\n if (!this.started) {\n this.started = true\n this.queueRead(current)\n } else if (changed.has('current') && current !== undefined && current !== this.recorded) {\n this.queueRead(current)\n }\n }\n\n private queueRead(current: string | undefined): void {\n if (current !== undefined) this.recorded = current\n this.reads = this.reads.then(() => this.read(current))\n }\n\n private async read(current: string | undefined): Promise<void> {\n const { recentlyViewed } = this.client\n if (current !== undefined) {\n try {\n await recentlyViewed.record(current)\n } catch (err) {\n console.warn('[nymbal-recently-viewed] the view was not recorded', err)\n }\n }\n try {\n this.listed = (await recentlyViewed.list()).items as Listed[]\n } catch (err) {\n console.warn('[nymbal-recently-viewed] the list could not be read', err)\n this.listed = []\n }\n await this.updateComplete\n this.dispatchEvent(\n new CustomEvent('nymbal:recently-viewed:loaded', {\n detail: { productIds: this.shown.map((p) => p.id) },\n bubbles: true,\n composed: true,\n }),\n )\n }\n\n protected override render() {\n const shown = this.readsStores ? this.shown : []\n if (shown.length === 0) return nothing\n return html`\n <section part=\"section\">\n <h2 part=\"heading\"><slot name=\"heading\">Recently viewed</slot></h2>\n <div part=\"grid\">\n ${shown.map(\n (p) =>\n html`<nymbal-product-card\n product=${JSON.stringify(cardProductOf(p))}\n ></nymbal-product-card>`,\n )}\n </div>\n </section>\n `\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,KAAK,MAAM,eAAoC;AAIxD,IAAM,SAAwB;AAAA,EAC5B,KAAK;AAAA,EACL,WAAW;AAAA;AAAA,EAEX,YAAY;AAAA,IACV,EAAE,MAAM,WAAW,MAAM,WAAW,MAAM,SAAS;AAAA,IACnD,EAAE,MAAM,SAAS,MAAM,SAAS,MAAM,S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kout:placed",
|
|
34
34
|
prop: "onPlaced",
|
|
35
|
-
detail: "{ orderNumber: string }"
|
|
35
|
+
detail: "{ orderNumber: string; orderKey?: string }"
|
|
36
36
|
}
|
|
37
37
|
],
|
|
38
38
|
parts: [
|
|
@@ -297,7 +297,7 @@ var NymbalCheckout = class extends NymbalElement {
|
|
|
297
297
|
billingSame = true;
|
|
298
298
|
placing = false;
|
|
299
299
|
placed = false;
|
|
300
|
-
/** True from a step change until the next animation frame
|
|
300
|
+
/** True from a step change until the next animation frame, so a second click of a double click is ignored. */
|
|
301
301
|
stepChanging = false;
|
|
302
302
|
stepTurn = 0;
|
|
303
303
|
heightRelease;
|
|
@@ -424,8 +424,8 @@ var NymbalCheckout = class extends NymbalElement {
|
|
|
424
424
|
checkout.setBillingAddress(billing);
|
|
425
425
|
const result = await checkout.submitPayment();
|
|
426
426
|
if (result === null) {
|
|
427
|
-
const { placedOrderNumber, error } = checkout.getState();
|
|
428
|
-
if (placedOrderNumber) return this.leaveFor(placedOrderNumber);
|
|
427
|
+
const { placedOrderNumber, placedOrderKey, error } = checkout.getState();
|
|
428
|
+
if (placedOrderNumber) return this.leaveFor(placedOrderNumber, placedOrderKey ?? void 0);
|
|
429
429
|
return this.stay(error ?? PAYMENT_FAILED);
|
|
430
430
|
}
|
|
431
431
|
if (result.payment.status === "failed") {
|
|
@@ -440,7 +440,7 @@ var NymbalCheckout = class extends NymbalElement {
|
|
|
440
440
|
if (!confirmation.ok) return this.stay(confirmation.error);
|
|
441
441
|
if (confirmation.confirmed) checkout.markConfirmed();
|
|
442
442
|
}
|
|
443
|
-
this.leaveFor(result.orderNumber);
|
|
443
|
+
this.leaveFor(result.orderNumber, result.orderKey);
|
|
444
444
|
} catch (err) {
|
|
445
445
|
this.stay(err instanceof Error && err.message !== "" ? err.message : PAYMENT_FAILED);
|
|
446
446
|
}
|
|
@@ -452,8 +452,11 @@ var NymbalCheckout = class extends NymbalElement {
|
|
|
452
452
|
this.placing = false;
|
|
453
453
|
this.showError(message);
|
|
454
454
|
}
|
|
455
|
-
/**
|
|
456
|
-
|
|
455
|
+
/**
|
|
456
|
+
* Place Order stays disabled from here through the page's navigation. `orderKey`, when the answer carried one, lets
|
|
457
|
+
* the order's page read it with no session.
|
|
458
|
+
*/
|
|
459
|
+
leaveFor(orderNumber, orderKey) {
|
|
457
460
|
this.client.checkout.reset();
|
|
458
461
|
this.placing = false;
|
|
459
462
|
this.placed = true;
|
|
@@ -462,7 +465,7 @@ var NymbalCheckout = class extends NymbalElement {
|
|
|
462
465
|
new CustomEvent("nymbal:checkout:placed", {
|
|
463
466
|
bubbles: true,
|
|
464
467
|
composed: true,
|
|
465
|
-
detail: { orderNumber }
|
|
468
|
+
detail: { orderNumber, ...orderKey !== void 0 && { orderKey } }
|
|
466
469
|
})
|
|
467
470
|
);
|
|
468
471
|
}
|
|
@@ -532,9 +535,17 @@ var NymbalCheckout = class extends NymbalElement {
|
|
|
532
535
|
<section part="section" data-testid="checkout-shipping" ?hidden=${this.step !== "shipping"}>
|
|
533
536
|
<form part="form" novalidate @submit=${this.onShipping}>
|
|
534
537
|
<h2 part="section-title">Shipping Address</h2>
|
|
535
|
-
<nymbal-address-form
|
|
538
|
+
<nymbal-address-form
|
|
539
|
+
id-prefix="shipping"
|
|
540
|
+
data-testid="shipping-form"
|
|
541
|
+
></nymbal-address-form>
|
|
536
542
|
<div part="actions">
|
|
537
|
-
<button
|
|
543
|
+
<button
|
|
544
|
+
type="button"
|
|
545
|
+
part="back"
|
|
546
|
+
class="btn btn-secondary"
|
|
547
|
+
@click=${this.back("contact")}
|
|
548
|
+
>
|
|
538
549
|
Back
|
|
539
550
|
</button>
|
|
540
551
|
<button
|
|
@@ -643,7 +654,9 @@ var NymbalCheckout = class extends NymbalElement {
|
|
|
643
654
|
${this.renderSteps()}
|
|
644
655
|
${this.error === null ? nothing : html`<div part="error" role="alert" data-testid="checkout-error">${this.error}</div>`}
|
|
645
656
|
<div part="layout">
|
|
646
|
-
<div part="main"
|
|
657
|
+
<div part="main">
|
|
658
|
+
${this.renderContact()} ${this.renderShipping()} ${this.renderPayment()}
|
|
659
|
+
</div>
|
|
647
660
|
${this.renderSummary()}
|
|
648
661
|
</div>
|
|
649
662
|
`;
|
|
@@ -653,4 +666,4 @@ var NymbalCheckout = class extends NymbalElement {
|
|
|
653
666
|
export {
|
|
654
667
|
NymbalCheckout
|
|
655
668
|
};
|
|
656
|
-
//# sourceMappingURL=chunk-
|
|
669
|
+
//# sourceMappingURL=chunk-YQEMZOJL.js.map
|