@wikala/spmkt 4.0.0-alpha.1 → 4.0.0-alpha.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/dist/core/api/address.d.ts +6 -1
- package/dist/core/api/address.js +6 -1
- package/dist/core/api/address.js.map +1 -1
- package/dist/core/api/cart.d.ts +2 -21
- package/dist/core/api/cart.js +4 -30
- package/dist/core/api/cart.js.map +1 -1
- package/dist/core/api/checkout.d.ts +2 -9
- package/dist/core/api/checkout.js +3 -10
- package/dist/core/api/checkout.js.map +1 -1
- package/dist/core/api/index.d.ts +4 -4
- package/dist/core/api/product.d.ts +2 -10
- package/dist/core/api/product.js +0 -12
- package/dist/core/api/product.js.map +1 -1
- package/dist/core/events.d.ts +4 -3
- package/dist/core/events.js.map +1 -1
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +17 -13
- package/dist/core/money.d.ts +2 -0
- package/dist/core/money.js +5 -0
- package/dist/core/money.js.map +1 -1
- package/dist/core/page-events.d.ts +17 -0
- package/dist/core/page-events.js +37 -3
- package/dist/core/page-events.js.map +1 -1
- package/dist/core/state.d.ts +8 -1
- package/dist/core/state.js +75 -3
- package/dist/core/state.js.map +1 -1
- package/dist/core/stores/cart.d.ts +19 -20
- package/dist/core/stores/cart.js +38 -46
- package/dist/core/stores/cart.js.map +1 -1
- package/dist/core/stores/checkout.d.ts +10 -12
- package/dist/core/stores/checkout.js +19 -24
- package/dist/core/stores/checkout.js.map +1 -1
- package/dist/core/stores/index.d.ts +2 -2
- package/dist/core/types.d.ts +29 -7
- package/dist/elements/add-to-cart/add-to-cart.d.ts +6 -7
- package/dist/elements/add-to-cart/add-to-cart.js +34 -20
- package/dist/elements/add-to-cart/add-to-cart.js.map +1 -1
- package/dist/elements/address-book/address-book.d.ts +20 -15
- package/dist/elements/address-book/address-book.js +98 -34
- package/dist/elements/address-book/address-book.js.map +1 -1
- package/dist/elements/cart/cart.d.ts +27 -27
- package/dist/elements/cart/cart.js +195 -80
- package/dist/elements/cart/cart.js.map +1 -1
- package/dist/elements/checkout/checkout.d.ts +13 -20
- package/dist/elements/checkout/checkout.js +73 -40
- package/dist/elements/checkout/checkout.js.map +1 -1
- package/dist/elements/checkout-delivery/checkout-delivery.d.ts +2 -9
- package/dist/elements/checkout-delivery/checkout-delivery.js +1 -8
- package/dist/elements/checkout-delivery/checkout-delivery.js.map +1 -1
- package/dist/elements/checkout-payment/checkout-payment.d.ts +2 -9
- package/dist/elements/checkout-payment/checkout-payment.js +2 -9
- package/dist/elements/checkout-payment/checkout-payment.js.map +1 -1
- package/dist/elements/collection/collection.d.ts +5 -9
- package/dist/elements/collection/collection.js +20 -20
- package/dist/elements/collection/collection.js.map +1 -1
- package/dist/elements/dialog/dialog.d.ts +7 -3
- package/dist/elements/dialog/dialog.js +12 -4
- package/dist/elements/dialog/dialog.js.map +1 -1
- package/dist/elements/mini-cart/mini-cart.d.ts +15 -15
- package/dist/elements/mini-cart/mini-cart.js +74 -62
- package/dist/elements/mini-cart/mini-cart.js.map +1 -1
- package/dist/elements/order-confirmation/index.d.ts +3 -0
- package/dist/elements/order-confirmation/index.js +7 -0
- package/dist/elements/order-confirmation/index.js.map +1 -0
- package/dist/elements/order-confirmation/order-confirmation.d.ts +35 -0
- package/dist/elements/order-confirmation/order-confirmation.js +123 -0
- package/dist/elements/order-confirmation/order-confirmation.js.map +1 -0
- package/dist/elements/quick-view/quick-view.d.ts +10 -7
- package/dist/elements/quick-view/quick-view.js +11 -5
- package/dist/elements/quick-view/quick-view.js.map +1 -1
- package/dist/elements/related/related.d.ts +8 -13
- package/dist/elements/related/related.js +20 -17
- package/dist/elements/related/related.js.map +1 -1
- package/dist/elements/shared/paged-section.js +1 -1
- package/dist/elements/shared/paged-section.js.map +1 -1
- package/dist/elements/shared/totals.d.ts +53 -0
- package/dist/elements/shared/totals.js +82 -0
- package/dist/elements/shared/totals.js.map +1 -0
- package/dist/elements/variant-picker/variant-picker.d.ts +5 -3
- package/dist/elements/variant-picker/variant-picker.js +6 -4
- package/dist/elements/variant-picker/variant-picker.js.map +1 -1
- package/dist/lit/fragments.d.ts +10 -10
- package/dist/lit/fragments.js +6 -10
- package/dist/lit/fragments.js.map +1 -1
- package/dist/locales/en.json +48 -3
- package/dist/locales/sr.json +49 -3
- package/package.json +1 -1
|
@@ -2,7 +2,8 @@ import { SpmktElement } from '../../lit/spmkt-element';
|
|
|
2
2
|
/**
|
|
3
3
|
* Parts of <spmkt-dialog id="...">:
|
|
4
4
|
* - dialog (required): a native <dialog>
|
|
5
|
-
* - content (optional): where open(
|
|
5
|
+
* - content (optional): where open(content) puts server-rendered HTML (a section) or a lit template (what an
|
|
6
|
+
* element renders, e.g. the added-to-cart confirmation); Blade-owned otherwise
|
|
6
7
|
* - close (optional, any number): closes the dialog (a <form method="dialog"> works too)
|
|
7
8
|
*/
|
|
8
9
|
export interface DialogParts {
|
|
@@ -17,7 +18,10 @@ export interface DialogParts {
|
|
|
17
18
|
export declare class SpmktDialog extends SpmktElement {
|
|
18
19
|
connectedCallback(): void;
|
|
19
20
|
get isOpen(): boolean;
|
|
20
|
-
/**
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Opens the dialog; with `content`, first replaces the content part with it: a string is HTML from the
|
|
23
|
+
* server, anything else a lit template (rendered with lit's render(), so its values are escaped).
|
|
24
|
+
*/
|
|
25
|
+
open(content?: string | unknown): void;
|
|
22
26
|
close(): void;
|
|
23
27
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { render } from "lit";
|
|
1
2
|
import { SpmktElement } from "../../lit/spmkt-element.js";
|
|
2
3
|
import { swapInto } from "../../lit/fragments.js";
|
|
3
4
|
let triggersInstalled = false;
|
|
@@ -37,11 +38,18 @@ class SpmktDialog extends SpmktElement {
|
|
|
37
38
|
get isOpen() {
|
|
38
39
|
return this.findPart("dialog")?.open ?? false;
|
|
39
40
|
}
|
|
40
|
-
/**
|
|
41
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Opens the dialog; with `content`, first replaces the content part with it: a string is HTML from the
|
|
43
|
+
* server, anything else a lit template (rendered with lit's render(), so its values are escaped).
|
|
44
|
+
*/
|
|
45
|
+
open(content) {
|
|
42
46
|
const dialog = this.requirePart("dialog");
|
|
43
|
-
if (
|
|
44
|
-
swapInto(this.requirePart("content"),
|
|
47
|
+
if (typeof content === "string") {
|
|
48
|
+
swapInto(this.requirePart("content"), content);
|
|
49
|
+
} else if (content !== void 0) {
|
|
50
|
+
const fragment = document.createDocumentFragment();
|
|
51
|
+
render(content, fragment);
|
|
52
|
+
this.requirePart("content").replaceChildren(fragment);
|
|
45
53
|
}
|
|
46
54
|
if (!dialog.open) {
|
|
47
55
|
dialog.showModal();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog.js","sources":["../../../src/elements/dialog/dialog.ts"],"sourcesContent":["import { SpmktElement } from '../../lit/spmkt-element'\nimport { swapInto } from '../../lit/fragments'\n\n/**\n * Parts of <spmkt-dialog id=\"...\">:\n * - dialog (required): a native <dialog>\n * - content (optional): where open(
|
|
1
|
+
{"version":3,"file":"dialog.js","sources":["../../../src/elements/dialog/dialog.ts"],"sourcesContent":["import { render } from 'lit'\nimport { SpmktElement } from '../../lit/spmkt-element'\nimport { swapInto } from '../../lit/fragments'\n\n/**\n * Parts of <spmkt-dialog id=\"...\">:\n * - dialog (required): a native <dialog>\n * - content (optional): where open(content) puts server-rendered HTML (a section) or a lit template (what an\n * element renders, e.g. the added-to-cart confirmation); Blade-owned otherwise\n * - close (optional, any number): closes the dialog (a <form method=\"dialog\"> works too)\n */\nexport interface DialogParts {\n dialog: HTMLDialogElement\n content?: HTMLElement\n close?: HTMLElement[]\n}\n\nlet triggersInstalled = false\n\n/** Elements with data-spmkt-open=\"<spmkt-dialog id>\" open that dialog: one listener for the document. */\nfunction installTriggers(): void {\n if (triggersInstalled) {\n return\n }\n triggersInstalled = true\n document.addEventListener('click', (event) => {\n const trigger = (event.target as Element | null)?.closest?.<HTMLElement>('[data-spmkt-open]')\n const id = trigger?.dataset.spmktOpen\n const host = id ? document.getElementById(id) : null\n if (!host) {\n return\n }\n event.preventDefault()\n if (host instanceof SpmktDialog) {\n host.open()\n } else {\n // Not upgraded yet (lazily defined): open the native dialog directly\n host.querySelector('dialog')?.showModal()\n }\n })\n}\n\n/**\n * A modal over a native <dialog>: open/close, triggers anywhere in the page, close parts, backdrop click,\n * Escape (native). The browser restores focus to the trigger on close.\n */\nexport class SpmktDialog extends SpmktElement {\n override connectedCallback(): void {\n super.connectedCallback()\n installTriggers()\n const dialog = this.requirePart<HTMLDialogElement>('dialog')\n this.listen(dialog, 'click', (event) => {\n const target = event.target as Element\n if (target === dialog || target.closest('[data-part=\"close\"]')) {\n this.close()\n }\n })\n this.listen(dialog, 'close', () => this.emit('spmkt:dialog-close', { id: this.id }))\n }\n\n get isOpen(): boolean {\n return this.findPart<HTMLDialogElement>('dialog')?.open ?? false\n }\n\n /**\n * Opens the dialog; with `content`, first replaces the content part with it: a string is HTML from the\n * server, anything else a lit template (rendered with lit's render(), so its values are escaped).\n */\n open(content?: string | unknown): void {\n const dialog = this.requirePart<HTMLDialogElement>('dialog')\n if (typeof content === 'string') {\n swapInto(this.requirePart('content'), content)\n } else if (content !== undefined) {\n // Rendered fresh each time, so lit keeps no state on the part and HTML can follow a template\n const fragment = document.createDocumentFragment()\n render(content, fragment)\n this.requirePart('content').replaceChildren(fragment)\n }\n if (!dialog.open) {\n dialog.showModal()\n this.emit('spmkt:dialog-open', { id: this.id })\n }\n }\n\n close(): void {\n const dialog = this.findPart<HTMLDialogElement>('dialog')\n if (dialog?.open) {\n dialog.close()\n }\n }\n}\n"],"names":[],"mappings":";;;AAiBA,IAAI,oBAAoB;AAGxB,SAAS,kBAAwB;AAC/B,MAAI,mBAAmB;AACrB;AAAA,EACF;AACA,sBAAoB;AACpB,WAAS,iBAAiB,SAAS,CAAC,UAAU;AAC5C,UAAM,UAAW,MAAM,QAA2B,UAAuB,mBA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;AACxD,QAAI,QAAQ,MAAM;AAChB,aAAO,MAAA;AAAA,IACT;AAAA,EACF;AACF;"}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
+
import { type TemplateResult } from 'lit';
|
|
1
2
|
import { SpmktElement } from '../../lit/spmkt-element';
|
|
3
|
+
import type { Cart, CartLine } from '../../core/types';
|
|
2
4
|
/**
|
|
3
5
|
* Parts of <spmkt-mini-cart> (the cart in a drawer: put it inside the <spmkt-dialog> that the header's cart link
|
|
4
6
|
* opens):
|
|
5
|
-
* - content (required):
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* - error (optional): why
|
|
7
|
+
* - content (required): empty in the theme's markup; the element renders the cart store into it (lines with a
|
|
8
|
+
* remove button, the subtotal, the ways to the cart and to checkout). Opening the drawer asks nothing of the
|
|
9
|
+
* server, and a change anywhere on the page shows at once.
|
|
10
|
+
* - error (optional): why a removal failed; render it hidden
|
|
11
|
+
*
|
|
12
|
+
* The empty state's button carries data-part="close", which closes the surrounding <spmkt-dialog>.
|
|
9
13
|
*/
|
|
10
14
|
export interface MiniCartParts {
|
|
11
15
|
content: HTMLElement;
|
|
12
16
|
error?: HTMLElement;
|
|
13
17
|
}
|
|
14
18
|
export declare class SpmktMiniCart extends SpmktElement {
|
|
15
|
-
|
|
16
|
-
fragment: {
|
|
17
|
-
type: StringConstructor;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
fragment: string;
|
|
21
|
-
private loading;
|
|
19
|
+
private readonly cart;
|
|
22
20
|
private changing;
|
|
23
21
|
connectedCallback(): void;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
protected updated(): void;
|
|
23
|
+
protected renderContent(current: Cart): TemplateResult;
|
|
24
|
+
protected renderLine(line: CartLine): TemplateResult;
|
|
25
|
+
protected renderFoot(current: Cart): TemplateResult;
|
|
26
|
+
/** Removes a line; the store's answer re-renders every view of the cart. */
|
|
27
|
+
removeLine(id: number): Promise<void>;
|
|
28
28
|
private showError;
|
|
29
29
|
}
|
|
@@ -1,79 +1,98 @@
|
|
|
1
|
+
import { html, nothing } from "lit";
|
|
2
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
1
3
|
import { SpmktElement } from "../../lit/spmkt-element.js";
|
|
2
|
-
import {
|
|
4
|
+
import { SignalController } from "../../lit/signal-controller.js";
|
|
3
5
|
import { errorMessage } from "../../lit/forms.js";
|
|
4
|
-
import {
|
|
5
|
-
import { setQuantity } from "../../core/stores/cart.js";
|
|
6
|
-
import { isAbortError } from "../../core/errors.js";
|
|
6
|
+
import { cart, setQuantity } from "../../core/stores/cart.js";
|
|
7
7
|
import { t } from "../../core/i18n.js";
|
|
8
|
+
import { formatMoney } from "../../core/money.js";
|
|
9
|
+
import { shopUrl } from "../../core/config.js";
|
|
10
|
+
import { lineUrl, lineName, hasImage, cartBlocked } from "../shared/totals.js";
|
|
8
11
|
class SpmktMiniCart extends SpmktElement {
|
|
9
12
|
constructor() {
|
|
10
13
|
super(...arguments);
|
|
11
|
-
this.
|
|
14
|
+
this.cart = new SignalController(this, () => cart.value);
|
|
12
15
|
this.changing = false;
|
|
13
16
|
}
|
|
14
|
-
static {
|
|
15
|
-
this.properties = {
|
|
16
|
-
fragment: { type: String }
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
17
|
connectedCallback() {
|
|
20
18
|
super.connectedCallback();
|
|
21
19
|
this.requirePart("content");
|
|
22
|
-
const hostId = this.closest("spmkt-dialog")?.id;
|
|
23
|
-
this.listen(document, "spmkt:dialog-open", (event) => {
|
|
24
|
-
if (event.detail.id === hostId) void this.load();
|
|
25
|
-
});
|
|
26
|
-
this.listen(document, "spmkt:cart-changed", () => {
|
|
27
|
-
if (!this.changing && this.isOpen) void this.load();
|
|
28
|
-
});
|
|
29
|
-
this.listen(this, "submit", (event) => {
|
|
30
|
-
const form = event.target;
|
|
31
|
-
if (form.dataset.part !== "remove") return;
|
|
32
|
-
event.preventDefault();
|
|
33
|
-
void this.removeLine(form);
|
|
34
|
-
});
|
|
35
|
-
this.onDisconnect(() => this.loading?.abort());
|
|
36
|
-
if (this.isOpen) void this.load();
|
|
37
|
-
}
|
|
38
|
-
get isOpen() {
|
|
39
|
-
return this.closest("dialog")?.open ?? false;
|
|
40
20
|
}
|
|
41
|
-
|
|
42
|
-
async load() {
|
|
43
|
-
this.loading?.abort();
|
|
44
|
-
const controller = this.loading = new AbortController();
|
|
21
|
+
updated() {
|
|
45
22
|
const content = this.requirePart("content");
|
|
46
|
-
content.
|
|
47
|
-
this.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
} catch (error) {
|
|
52
|
-
if (!isAbortError(error)) this.showError(errorMessage(error));
|
|
53
|
-
} finally {
|
|
54
|
-
if (this.loading === controller) content.removeAttribute("aria-busy");
|
|
23
|
+
const hadFocus = content.contains(document.activeElement);
|
|
24
|
+
this.renderPart("content", this.renderContent(this.cart.value));
|
|
25
|
+
if (!this.changing) content.removeAttribute("aria-busy");
|
|
26
|
+
if (hadFocus && !content.contains(document.activeElement)) {
|
|
27
|
+
content.querySelector("a, button")?.focus();
|
|
55
28
|
}
|
|
56
29
|
}
|
|
57
|
-
|
|
30
|
+
renderContent(current) {
|
|
31
|
+
if (!current.items.length) {
|
|
32
|
+
return html`<div class="mini-cart__empty" data-test="mini-cart-empty">
|
|
33
|
+
<p>${t("cart.empty")}</p>
|
|
34
|
+
<button type="button" class="button" data-part="close">${t("cart.continue")}</button>
|
|
35
|
+
</div>`;
|
|
36
|
+
}
|
|
37
|
+
return html`<ul role="list" class="mini-cart__lines">
|
|
38
|
+
${repeat(
|
|
39
|
+
current.items,
|
|
40
|
+
(line) => line.id,
|
|
41
|
+
(line) => this.renderLine(line)
|
|
42
|
+
)}
|
|
43
|
+
</ul>
|
|
44
|
+
${this.renderFoot(current)}`;
|
|
45
|
+
}
|
|
46
|
+
renderLine(line) {
|
|
47
|
+
const url = lineUrl(line, shopUrl);
|
|
48
|
+
const name = lineName(line);
|
|
49
|
+
return html`<li class="mini-cart__line" data-test="mini-cart-line" data-line=${line.id}>
|
|
50
|
+
<a class="mini-cart__image" href=${url} tabindex="-1" aria-hidden="true">
|
|
51
|
+
${hasImage(line) ? html`<img src=${line.image_url} alt="" width="64" height="64" loading="lazy" />` : nothing}
|
|
52
|
+
</a>
|
|
53
|
+
<div class="mini-cart__info">
|
|
54
|
+
<a href=${url}>${name}</a>
|
|
55
|
+
${line.variant ? html`<span class="mini-cart__variant">${line.variant}</span>` : nothing}
|
|
56
|
+
<span class="mini-cart__price">${line.qty} × ${formatMoney(line.price)}</span>
|
|
57
|
+
${line.error ? html`<span class="mini-cart__error">${line.error}</span>` : nothing}
|
|
58
|
+
</div>
|
|
59
|
+
<button
|
|
60
|
+
type="button"
|
|
61
|
+
class="link-button"
|
|
62
|
+
data-test="mini-cart-remove"
|
|
63
|
+
aria-label=${t("cart.removeNamed", { name })}
|
|
64
|
+
@click=${() => void this.removeLine(line.id)}
|
|
65
|
+
>
|
|
66
|
+
${t("cart.remove")}
|
|
67
|
+
</button>
|
|
68
|
+
</li>`;
|
|
69
|
+
}
|
|
70
|
+
renderFoot(current) {
|
|
71
|
+
return html`<div class="mini-cart__foot">
|
|
72
|
+
<p class="mini-cart__subtotal">
|
|
73
|
+
<span>${t("totals.subtotal")}</span>
|
|
74
|
+
<strong data-test="mini-cart-subtotal">${formatMoney(current.subtotal)}</strong>
|
|
75
|
+
</p>
|
|
76
|
+
<a class="button button--block" href=${shopUrl("/shopping-cart")} data-test="mini-cart-view"
|
|
77
|
+
>${t("cart.view")}</a
|
|
78
|
+
>
|
|
79
|
+
${cartBlocked(current.items) ? nothing : html`<a
|
|
80
|
+
class="button button--primary button--block"
|
|
81
|
+
href=${shopUrl("/shopping-cart?step=delivery")}
|
|
82
|
+
data-test="mini-cart-checkout"
|
|
83
|
+
>${t("cart.toCheckout")}</a
|
|
84
|
+
>`}
|
|
85
|
+
</div>`;
|
|
86
|
+
}
|
|
87
|
+
/** Removes a line; the store's answer re-renders every view of the cart. */
|
|
88
|
+
async removeLine(id) {
|
|
58
89
|
if (this.changing) return;
|
|
59
|
-
const data = new FormData(form);
|
|
60
|
-
const line = form.closest("[data-item]");
|
|
61
90
|
const content = this.requirePart("content");
|
|
62
91
|
this.changing = true;
|
|
63
92
|
content.setAttribute("aria-busy", "true");
|
|
64
93
|
this.showError(null);
|
|
65
94
|
try {
|
|
66
|
-
|
|
67
|
-
id: Number(data.get("id")),
|
|
68
|
-
qty: 0,
|
|
69
|
-
previousQty: data.has("previous") ? Number(data.get("previous")) : void 0,
|
|
70
|
-
item: itemOf(line),
|
|
71
|
-
fragments: [this.fragment]
|
|
72
|
-
});
|
|
73
|
-
swapInto(content, fragments[this.fragment] ?? "");
|
|
74
|
-
if (!content.contains(document.activeElement)) {
|
|
75
|
-
content.querySelector("a, button")?.focus();
|
|
76
|
-
}
|
|
95
|
+
await setQuantity({ id, qty: 0 });
|
|
77
96
|
} catch (error) {
|
|
78
97
|
this.showError(errorMessage(error, t("cart.updateFailed")));
|
|
79
98
|
} finally {
|
|
@@ -89,13 +108,6 @@ class SpmktMiniCart extends SpmktElement {
|
|
|
89
108
|
}
|
|
90
109
|
}
|
|
91
110
|
}
|
|
92
|
-
function itemOf(line) {
|
|
93
|
-
try {
|
|
94
|
-
return line?.dataset.item ? JSON.parse(line.dataset.item) : void 0;
|
|
95
|
-
} catch {
|
|
96
|
-
return void 0;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
111
|
export {
|
|
100
112
|
SpmktMiniCart
|
|
101
113
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mini-cart.js","sources":["../../../src/elements/mini-cart/mini-cart.ts"],"sourcesContent":["import { SpmktElement } from '../../lit/spmkt-element'\nimport {
|
|
1
|
+
{"version":3,"file":"mini-cart.js","sources":["../../../src/elements/mini-cart/mini-cart.ts"],"sourcesContent":["import { html, nothing, type TemplateResult } from 'lit'\nimport { repeat } from 'lit/directives/repeat.js'\nimport { SpmktElement } from '../../lit/spmkt-element'\nimport { SignalController } from '../../lit/signal-controller'\nimport { errorMessage } from '../../lit/forms'\nimport { cart, setQuantity } from '../../core/stores/cart'\nimport { t } from '../../core/i18n'\nimport { formatMoney } from '../../core/money'\nimport { shopUrl } from '../../core/config'\nimport type { Cart, CartLine } from '../../core/types'\nimport { cartBlocked, hasImage, lineName, lineUrl } from '../shared/totals'\n\n/**\n * Parts of <spmkt-mini-cart> (the cart in a drawer: put it inside the <spmkt-dialog> that the header's cart link\n * opens):\n * - content (required): empty in the theme's markup; the element renders the cart store into it (lines with a\n * remove button, the subtotal, the ways to the cart and to checkout). Opening the drawer asks nothing of the\n * server, and a change anywhere on the page shows at once.\n * - error (optional): why a removal failed; render it hidden\n *\n * The empty state's button carries data-part=\"close\", which closes the surrounding <spmkt-dialog>.\n */\nexport interface MiniCartParts {\n content: HTMLElement\n error?: HTMLElement\n}\n\nexport class SpmktMiniCart extends SpmktElement {\n private readonly cart = new SignalController(this, () => cart.value)\n private changing = false\n\n override connectedCallback(): void {\n super.connectedCallback()\n this.requirePart('content')\n }\n\n protected override updated(): void {\n const content = this.requirePart('content')\n const hadFocus = content.contains(document.activeElement)\n this.renderPart('content', this.renderContent(this.cart.value))\n if (!this.changing) content.removeAttribute('aria-busy')\n // A removed line took the focus with it\n if (hadFocus && !content.contains(document.activeElement)) {\n content.querySelector<HTMLElement>('a, button')?.focus()\n }\n }\n\n protected renderContent(current: Cart): TemplateResult {\n if (!current.items.length) {\n return html`<div class=\"mini-cart__empty\" data-test=\"mini-cart-empty\">\n <p>${t('cart.empty')}</p>\n <button type=\"button\" class=\"button\" data-part=\"close\">${t('cart.continue')}</button>\n </div>`\n }\n return html`<ul role=\"list\" class=\"mini-cart__lines\">\n ${repeat(\n current.items,\n (line) => line.id,\n (line) => this.renderLine(line),\n )}\n </ul>\n ${this.renderFoot(current)}`\n }\n\n protected renderLine(line: CartLine): TemplateResult {\n const url = lineUrl(line, shopUrl)\n const name = lineName(line)\n return html`<li class=\"mini-cart__line\" data-test=\"mini-cart-line\" data-line=${line.id}>\n <a class=\"mini-cart__image\" href=${url} tabindex=\"-1\" aria-hidden=\"true\">\n ${\n hasImage(line)\n ? html`<img src=${line.image_url} alt=\"\" width=\"64\" height=\"64\" loading=\"lazy\" />`\n : nothing\n }\n </a>\n <div class=\"mini-cart__info\">\n <a href=${url}>${name}</a>\n ${line.variant ? html`<span class=\"mini-cart__variant\">${line.variant}</span>` : nothing}\n <span class=\"mini-cart__price\">${line.qty} × ${formatMoney(line.price)}</span>\n ${line.error ? html`<span class=\"mini-cart__error\">${line.error}</span>` : nothing}\n </div>\n <button\n type=\"button\"\n class=\"link-button\"\n data-test=\"mini-cart-remove\"\n aria-label=${t('cart.removeNamed', { name })}\n @click=${() => void this.removeLine(line.id)}\n >\n ${t('cart.remove')}\n </button>\n </li>`\n }\n\n protected renderFoot(current: Cart): TemplateResult {\n return html`<div class=\"mini-cart__foot\">\n <p class=\"mini-cart__subtotal\">\n <span>${t('totals.subtotal')}</span>\n <strong data-test=\"mini-cart-subtotal\">${formatMoney(current.subtotal)}</strong>\n </p>\n <a class=\"button button--block\" href=${shopUrl('/shopping-cart')} data-test=\"mini-cart-view\"\n >${t('cart.view')}</a\n >\n ${\n cartBlocked(current.items)\n ? nothing\n : html`<a\n class=\"button button--primary button--block\"\n href=${shopUrl('/shopping-cart?step=delivery')}\n data-test=\"mini-cart-checkout\"\n >${t('cart.toCheckout')}</a\n >`\n }\n </div>`\n }\n\n /** Removes a line; the store's answer re-renders every view of the cart. */\n async removeLine(id: number): Promise<void> {\n if (this.changing) return\n const content = this.requirePart('content')\n this.changing = true\n content.setAttribute('aria-busy', 'true')\n this.showError(null)\n try {\n await setQuantity({ id, qty: 0 })\n } catch (error) {\n this.showError(errorMessage(error, t('cart.updateFailed')))\n } finally {\n this.changing = false\n content.removeAttribute('aria-busy')\n }\n }\n\n private showError(message: string | null): void {\n const part = this.findPart('error')\n if (part) {\n part.textContent = message ?? ''\n part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EACF;AACF;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type PropertyValues, type TemplateResult } from 'lit';
|
|
2
|
+
import { SpmktElement } from '../../lit/spmkt-element';
|
|
3
|
+
import type { OrderItem, PlacedOrder } from '../../core/types';
|
|
4
|
+
/**
|
|
5
|
+
* Parts of <spmkt-order-confirmation> (a placed order: in place of the checkout after an instant payment, and
|
|
6
|
+
* on the gateway's success page):
|
|
7
|
+
* - order (optional): <script type="application/json"> with the order (CheckoutController::sendResponse());
|
|
8
|
+
* the `order` property takes its place when set (spmkt-checkout sets it)
|
|
9
|
+
* - content (created when missing): where the element renders the confirmation (renderConfirmation)
|
|
10
|
+
*
|
|
11
|
+
* The purchase is announced (spmkt:purchase) once per order in the tab, whichever page confirms it, and the
|
|
12
|
+
* checkout draft is forgotten with that first announcement.
|
|
13
|
+
*/
|
|
14
|
+
export interface OrderConfirmationParts {
|
|
15
|
+
order?: HTMLScriptElement;
|
|
16
|
+
content?: HTMLElement;
|
|
17
|
+
}
|
|
18
|
+
export declare class SpmktOrderConfirmation extends SpmktElement {
|
|
19
|
+
static properties: {
|
|
20
|
+
order: {
|
|
21
|
+
attribute: boolean;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
order: PlacedOrder | null;
|
|
25
|
+
private readonly signedIn;
|
|
26
|
+
connectedCallback(): void;
|
|
27
|
+
protected updated(changed: PropertyValues<this>): void;
|
|
28
|
+
protected renderConfirmation(order: PlacedOrder, signedIn: boolean): TemplateResult;
|
|
29
|
+
protected renderItem(item: OrderItem): TemplateResult;
|
|
30
|
+
/** spmkt:purchase, once per order in this tab; the first announcement also ends the checkout. */
|
|
31
|
+
private announce;
|
|
32
|
+
private readOrder;
|
|
33
|
+
}
|
|
34
|
+
/** "2026-11-08 20:15:00" as "08.11.2026. 20:15", the shop's own time as the server sent it. */
|
|
35
|
+
export declare function orderDate(date: string): string;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { nothing, html } from "lit";
|
|
2
|
+
import { SpmktElement } from "../../lit/spmkt-element.js";
|
|
3
|
+
import { SignalController } from "../../lit/signal-controller.js";
|
|
4
|
+
import { shopUrl, warnOnce } from "../../core/config.js";
|
|
5
|
+
import { t } from "../../core/i18n.js";
|
|
6
|
+
import { formatMoney, phpRound } from "../../core/money.js";
|
|
7
|
+
import { orderToPurchase, firstPurchase } from "../../core/page-events.js";
|
|
8
|
+
import { clearCheckoutDraft } from "../../core/stores/checkout-draft.js";
|
|
9
|
+
import { customerSignedIn } from "../../core/stores/customer.js";
|
|
10
|
+
import { withStrong, renderTotals } from "../shared/totals.js";
|
|
11
|
+
class SpmktOrderConfirmation extends SpmktElement {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.order = null;
|
|
15
|
+
this.signedIn = new SignalController(this, () => customerSignedIn.value);
|
|
16
|
+
}
|
|
17
|
+
static {
|
|
18
|
+
this.properties = {
|
|
19
|
+
order: { attribute: false }
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
connectedCallback() {
|
|
23
|
+
super.connectedCallback();
|
|
24
|
+
if (!this.order) this.order = this.readOrder();
|
|
25
|
+
if (!this.findPart("content")) {
|
|
26
|
+
const content = document.createElement("div");
|
|
27
|
+
content.dataset.part = "content";
|
|
28
|
+
this.append(content);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
updated(changed) {
|
|
32
|
+
const order = this.order;
|
|
33
|
+
if (!order) return;
|
|
34
|
+
this.renderPart("content", this.renderConfirmation(order, this.signedIn.value));
|
|
35
|
+
this.findPart("content")?.removeAttribute("aria-busy");
|
|
36
|
+
if (changed.has("order")) this.announce(order);
|
|
37
|
+
}
|
|
38
|
+
renderConfirmation(order, signedIn) {
|
|
39
|
+
return html`<section class="order-confirmation" data-test="order-confirmation">
|
|
40
|
+
<h1 class="order-confirmation__title" data-test="checkout-success-title" tabindex="-1">
|
|
41
|
+
${t("order.title")}
|
|
42
|
+
</h1>
|
|
43
|
+
<p class="order-confirmation__lead">
|
|
44
|
+
${withStrong("order.received", "number", `#${order.id}`, "order-number")}
|
|
45
|
+
${order.email ? withStrong("order.emailSent", "email", order.email) : nothing}
|
|
46
|
+
</p>
|
|
47
|
+
<dl class="order-confirmation__facts">
|
|
48
|
+
${order.date ? html`<div>
|
|
49
|
+
<dt>${t("order.date")}</dt>
|
|
50
|
+
<dd>${orderDate(order.date)}</dd>
|
|
51
|
+
</div>` : nothing}
|
|
52
|
+
${order.delivery_type ? html`<div>
|
|
53
|
+
<dt>${t("order.handover")}</dt>
|
|
54
|
+
<dd data-test="order-delivery">
|
|
55
|
+
${order.delivery_type === "pickup" ? t("order.pickup") : t("order.delivery")}
|
|
56
|
+
</dd>
|
|
57
|
+
</div>` : nothing}
|
|
58
|
+
${order.reservation_slot ? html`<div>
|
|
59
|
+
<dt>${t("order.slot")}</dt>
|
|
60
|
+
<dd>${order.reservation_slot}</dd>
|
|
61
|
+
</div>` : nothing}
|
|
62
|
+
</dl>
|
|
63
|
+
<ul role="list" class="checkout-summary__lines order-confirmation__lines">
|
|
64
|
+
${(order.items ?? []).map((item) => this.renderItem(item))}
|
|
65
|
+
</ul>
|
|
66
|
+
${renderTotals(
|
|
67
|
+
{
|
|
68
|
+
shipping: Number(order.shippingAmount) || 0,
|
|
69
|
+
taxAmount: Number(order.taxAmount) || 0,
|
|
70
|
+
total: Number(order.total) || 0
|
|
71
|
+
},
|
|
72
|
+
{ shipping: "always", totalTestId: "order-total", className: "order-confirmation__totals" }
|
|
73
|
+
)}
|
|
74
|
+
<div class="order-confirmation__actions">
|
|
75
|
+
<a class="button button--primary" href=${shopUrl("/")}>${t("cart.continue")}</a>
|
|
76
|
+
${signedIn ? html`<a class="button" href=${shopUrl("/account")} data-test="my-orders-link"
|
|
77
|
+
>${t("order.myOrders")}</a
|
|
78
|
+
>` : html`<a class="button" href=${shopUrl("/register")} data-test="create-account-link"
|
|
79
|
+
>${t("order.createAccount")}</a
|
|
80
|
+
>`}
|
|
81
|
+
</div>
|
|
82
|
+
</section>`;
|
|
83
|
+
}
|
|
84
|
+
renderItem(item) {
|
|
85
|
+
const quantity = Math.trunc(Number(item.quantity) || 0);
|
|
86
|
+
const price = Number(item.price) || 0;
|
|
87
|
+
return html`<li class="checkout-summary__line">
|
|
88
|
+
<span class="checkout-summary__name">
|
|
89
|
+
${item.parent_name ?? item.item_name}
|
|
90
|
+
${item.item_variant ? html`<span class="checkout-summary__variant">${item.item_variant}</span>` : nothing}
|
|
91
|
+
<span class="checkout-summary__qty">${quantity} × ${formatMoney(price)}</span>
|
|
92
|
+
</span>
|
|
93
|
+
<span>${formatMoney(phpRound(price * quantity, 2))}</span>
|
|
94
|
+
</li>`;
|
|
95
|
+
}
|
|
96
|
+
/** spmkt:purchase, once per order in this tab; the first announcement also ends the checkout. */
|
|
97
|
+
announce(order) {
|
|
98
|
+
const purchase = orderToPurchase(order);
|
|
99
|
+
if (!purchase || !firstPurchase(purchase)) return;
|
|
100
|
+
clearCheckoutDraft();
|
|
101
|
+
this.emit("spmkt:purchase", purchase);
|
|
102
|
+
}
|
|
103
|
+
readOrder() {
|
|
104
|
+
const text = this.findPart("order")?.textContent;
|
|
105
|
+
if (!text) return null;
|
|
106
|
+
try {
|
|
107
|
+
const order = JSON.parse(text);
|
|
108
|
+
return order && typeof order === "object" && order.id ? order : null;
|
|
109
|
+
} catch {
|
|
110
|
+
warnOnce("order-confirmation:json", "The order of <spmkt-order-confirmation> is not valid JSON");
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function orderDate(date) {
|
|
116
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2})/.exec(date);
|
|
117
|
+
return match ? `${match[3]}.${match[2]}.${match[1]}. ${match[4]}:${match[5]}` : date;
|
|
118
|
+
}
|
|
119
|
+
export {
|
|
120
|
+
SpmktOrderConfirmation,
|
|
121
|
+
orderDate
|
|
122
|
+
};
|
|
123
|
+
//# sourceMappingURL=order-confirmation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-confirmation.js","sources":["../../../src/elements/order-confirmation/order-confirmation.ts"],"sourcesContent":["import { html, nothing, type PropertyValues, type TemplateResult } from 'lit'\nimport { SpmktElement } from '../../lit/spmkt-element'\nimport { SignalController } from '../../lit/signal-controller'\nimport { warnOnce } from '../../core/config'\nimport { shopUrl } from '../../core/config'\nimport { t } from '../../core/i18n'\nimport { formatMoney, phpRound } from '../../core/money'\nimport { firstPurchase, orderToPurchase } from '../../core/page-events'\nimport { clearCheckoutDraft } from '../../core/stores/checkout-draft'\nimport { customerSignedIn } from '../../core/stores/customer'\nimport type { OrderItem, PlacedOrder } from '../../core/types'\nimport { renderTotals, withStrong } from '../shared/totals'\n\n/**\n * Parts of <spmkt-order-confirmation> (a placed order: in place of the checkout after an instant payment, and\n * on the gateway's success page):\n * - order (optional): <script type=\"application/json\"> with the order (CheckoutController::sendResponse());\n * the `order` property takes its place when set (spmkt-checkout sets it)\n * - content (created when missing): where the element renders the confirmation (renderConfirmation)\n *\n * The purchase is announced (spmkt:purchase) once per order in the tab, whichever page confirms it, and the\n * checkout draft is forgotten with that first announcement.\n */\nexport interface OrderConfirmationParts {\n order?: HTMLScriptElement\n content?: HTMLElement\n}\n\nexport class SpmktOrderConfirmation extends SpmktElement {\n static override properties = {\n order: { attribute: false },\n }\n order: PlacedOrder | null = null\n\n private readonly signedIn = new SignalController(this, () => customerSignedIn.value)\n\n override connectedCallback(): void {\n super.connectedCallback()\n if (!this.order) this.order = this.readOrder()\n if (!this.findPart('content')) {\n const content = document.createElement('div')\n content.dataset.part = 'content'\n this.append(content)\n }\n }\n\n protected override updated(changed: PropertyValues<this>): void {\n const order = this.order\n if (!order) return\n this.renderPart('content', this.renderConfirmation(order, this.signedIn.value))\n this.findPart('content')?.removeAttribute('aria-busy')\n if (changed.has('order')) this.announce(order)\n }\n\n protected renderConfirmation(order: PlacedOrder, signedIn: boolean): TemplateResult {\n return html`<section class=\"order-confirmation\" data-test=\"order-confirmation\">\n <h1 class=\"order-confirmation__title\" data-test=\"checkout-success-title\" tabindex=\"-1\">\n ${t('order.title')}\n </h1>\n <p class=\"order-confirmation__lead\">\n ${withStrong('order.received', 'number', `#${order.id}`, 'order-number')}\n ${order.email ? withStrong('order.emailSent', 'email', order.email) : nothing}\n </p>\n <dl class=\"order-confirmation__facts\">\n ${\n order.date\n ? html`<div>\n <dt>${t('order.date')}</dt>\n <dd>${orderDate(order.date)}</dd>\n </div>`\n : nothing\n }\n ${\n order.delivery_type\n ? html`<div>\n <dt>${t('order.handover')}</dt>\n <dd data-test=\"order-delivery\">\n ${order.delivery_type === 'pickup' ? t('order.pickup') : t('order.delivery')}\n </dd>\n </div>`\n : nothing\n }\n ${\n order.reservation_slot\n ? html`<div>\n <dt>${t('order.slot')}</dt>\n <dd>${order.reservation_slot}</dd>\n </div>`\n : nothing\n }\n </dl>\n <ul role=\"list\" class=\"checkout-summary__lines order-confirmation__lines\">\n ${(order.items ?? []).map((item) => this.renderItem(item))}\n </ul>\n ${renderTotals(\n {\n shipping: Number(order.shippingAmount) || 0,\n taxAmount: Number(order.taxAmount) || 0,\n total: Number(order.total) || 0,\n },\n { shipping: 'always', totalTestId: 'order-total', className: 'order-confirmation__totals' },\n )}\n <div class=\"order-confirmation__actions\">\n <a class=\"button button--primary\" href=${shopUrl('/')}>${t('cart.continue')}</a>\n ${\n signedIn\n ? html`<a class=\"button\" href=${shopUrl('/account')} data-test=\"my-orders-link\"\n >${t('order.myOrders')}</a\n >`\n : html`<a class=\"button\" href=${shopUrl('/register')} data-test=\"create-account-link\"\n >${t('order.createAccount')}</a\n >`\n }\n </div>\n </section>`\n }\n\n protected renderItem(item: OrderItem): TemplateResult {\n const quantity = Math.trunc(Number(item.quantity) || 0)\n const price = Number(item.price) || 0\n return html`<li class=\"checkout-summary__line\">\n <span class=\"checkout-summary__name\">\n ${item.parent_name ?? item.item_name}\n ${item.item_variant ? html`<span class=\"checkout-summary__variant\">${item.item_variant}</span>` : nothing}\n <span class=\"checkout-summary__qty\">${quantity} × ${formatMoney(price)}</span>\n </span>\n <span>${formatMoney(phpRound(price * quantity, 2))}</span>\n </li>`\n }\n\n /** spmkt:purchase, once per order in this tab; the first announcement also ends the checkout. */\n private announce(order: PlacedOrder): void {\n const purchase = orderToPurchase(order)\n if (!purchase || !firstPurchase(purchase)) return\n clearCheckoutDraft()\n this.emit('spmkt:purchase', purchase)\n }\n\n private readOrder(): PlacedOrder | null {\n const text = this.findPart('order')?.textContent\n if (!text) return null\n try {\n const order = JSON.parse(text) as PlacedOrder | null\n return order && typeof order === 'object' && order.id ? order : null\n } catch {\n warnOnce('order-confirmation:json', 'The order of <spmkt-order-confirmation> is not valid JSON')\n return null\n }\n }\n}\n\n/** \"2026-11-08 20:15:00\" as \"08.11.2026. 20:15\", the shop's own time as the server sent it. */\nexport function orderDate(date: string): string {\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})[ T](\\d{2}):(\\d{2})/.exec(date)\n return match ? `${match[3]}.${match[2]}.${match[1]}. ${match[4]}:${match[5]}` : date\n}\n"],"names":[],"mappings":";;;;;;;;;;AA4BO,MAAM,+BAA+B,aAAa;AAAA,EAAlD,cAAA;AAAA,UAAA,GAAA,SAAA;AAIL,SAAA,QAA4B;AAE5B,SAAiB,WAAW,IAAI,iBAAiB,MAAM,MAAM,iBAAiB,KAAK;AAAA,EAAA;AAAA,EALnF,OAAA;AAAA,SAAgB,aAAa;AAAA,MAC3B,OAAO,EAAE,WAAW,MAAA;AAAA,IAAM;AAAA,EAC5B;AAAA,EAKS,oBAA0B;AACjC,UAAM,kBAAA;AACN,QAAI,CAAC,KAAK,MAAO,MAAK,QAAQ,KAAK,UAAA;AACnC,QAAI,CAAC,KAAK,SAAS,SAAS,GAAG;AAC7B,YAAM,UAA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SAAO,QAAQ,GAAG,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,KAAK;AAClF;"}
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import { SpmktElement } from '../../lit/spmkt-element';
|
|
2
2
|
/**
|
|
3
|
-
* <spmkt-quick-view dialog="<spmkt-dialog id>"
|
|
4
|
-
* Any element with data-spmkt-quick-view="<product id>" opens that product's
|
|
5
|
-
* (GET /products/{id}?
|
|
6
|
-
*
|
|
3
|
+
* <spmkt-quick-view dialog="<spmkt-dialog id>" [section="template:product/main"]> has no parts: put it once in
|
|
4
|
+
* the layout. Any element with data-spmkt-quick-view="<product id>" opens that product page's `section`
|
|
5
|
+
* (GET /products/{id}?sections=template:product/main) in the dialog: the product as the merchant set it up,
|
|
6
|
+
* which the dialog's CSS compacts. Make the trigger a link to the product page, so a failed request goes there.
|
|
7
7
|
*
|
|
8
|
-
* The
|
|
8
|
+
* The section's wrapper loses its id (the product page has its own `main` with the same one); its
|
|
9
|
+
* data-section-id and data-theme-document stay, so a variant change inside swaps the dialog's copy only. The
|
|
10
|
+
* section's page events (its view-item script, see dispatchPageEvents) are announced once it is shown.
|
|
9
11
|
*/
|
|
10
12
|
export declare class SpmktQuickView extends SpmktElement {
|
|
11
13
|
static properties: {
|
|
12
14
|
dialog: {
|
|
13
15
|
type: StringConstructor;
|
|
14
16
|
};
|
|
15
|
-
|
|
17
|
+
section: {
|
|
16
18
|
type: StringConstructor;
|
|
17
19
|
};
|
|
18
20
|
};
|
|
19
21
|
dialog: string;
|
|
20
|
-
|
|
22
|
+
/** The product page's section to show */
|
|
23
|
+
section: string;
|
|
21
24
|
private inFlight;
|
|
22
25
|
connectedCallback(): void;
|
|
23
26
|
/** Opens the quick view of product `id`. Resolves false when it could not be shown. */
|
|
@@ -8,12 +8,12 @@ class SpmktQuickView extends SpmktElement {
|
|
|
8
8
|
constructor() {
|
|
9
9
|
super(...arguments);
|
|
10
10
|
this.dialog = "quick-view";
|
|
11
|
-
this.
|
|
11
|
+
this.section = "template:product/main";
|
|
12
12
|
}
|
|
13
13
|
static {
|
|
14
14
|
this.properties = {
|
|
15
15
|
dialog: { type: String },
|
|
16
|
-
|
|
16
|
+
section: { type: String }
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
connectedCallback() {
|
|
@@ -31,14 +31,14 @@ class SpmktQuickView extends SpmktElement {
|
|
|
31
31
|
trigger?.setAttribute("aria-busy", "true");
|
|
32
32
|
try {
|
|
33
33
|
const response = await fetchFragments(productUrl(id), {
|
|
34
|
-
|
|
34
|
+
sections: [this.section],
|
|
35
35
|
signal: controller.signal
|
|
36
36
|
});
|
|
37
|
-
const html = response.
|
|
37
|
+
const html = response.sections[this.section];
|
|
38
38
|
if (!html) {
|
|
39
39
|
return false;
|
|
40
40
|
}
|
|
41
|
-
host.open(html);
|
|
41
|
+
host.open(withoutWrapperId(html));
|
|
42
42
|
dispatchPageEvents(host);
|
|
43
43
|
return true;
|
|
44
44
|
} catch (error) {
|
|
@@ -64,6 +64,12 @@ class SpmktQuickView extends SpmktElement {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
+
function withoutWrapperId(html) {
|
|
68
|
+
const template = document.createElement("template");
|
|
69
|
+
template.innerHTML = html;
|
|
70
|
+
template.content.firstElementChild?.removeAttribute("id");
|
|
71
|
+
return template.innerHTML;
|
|
72
|
+
}
|
|
67
73
|
export {
|
|
68
74
|
SpmktQuickView
|
|
69
75
|
};
|