@useinsider/guido 3.23.0-beta.31d0f5f → 3.23.0-beta.9f6bfbf
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 +1 -0
- package/dist/@types/config/schemas.js +17 -15
- package/dist/components/Guido.vue.js +1 -1
- package/dist/components/Guido.vue2.js +58 -56
- package/dist/composables/useModuleRepair.js +14 -12
- package/dist/config/migrator/index.js +16 -15
- package/dist/config/migrator/itemsPriceFormatMigrator.js +20 -0
- package/dist/extensions/Blocks/Items/block.js +115 -77
- package/dist/extensions/Blocks/Items/constants/currency.js +59 -14
- package/dist/extensions/Blocks/Items/controls/price/currencyLocation.js +33 -22
- package/dist/extensions/Blocks/Items/controls/price/currencySymbol.js +62 -51
- package/dist/extensions/Blocks/Items/controls/price/formattedPrice.js +18 -17
- package/dist/extensions/Blocks/Items/controls/price/singlePrice.js +42 -31
- package/dist/extensions/Blocks/Items/controls/priceFormat.js +145 -0
- package/dist/extensions/Blocks/Items/controls/settingsControl.js +141 -120
- package/dist/extensions/Blocks/Items/enums/controlEnums.js +1 -1
- package/dist/extensions/Blocks/Items/extension.js +9 -8
- package/dist/extensions/Blocks/Items/items.css.js +19 -0
- package/dist/extensions/Blocks/Items/settingsPanel.js +34 -25
- package/dist/extensions/Blocks/Items/template.js +250 -212
- package/dist/extensions/Blocks/Items/utils/priceFormatOps.js +185 -0
- package/dist/extensions/Blocks/Recommendation/utils/priceFormatter.js +1 -0
- package/dist/guido.css +1 -1
- package/dist/package.json.js +1 -1
- package/dist/src/@types/config/schemas.d.ts +4 -0
- package/dist/src/composables/useConfig.d.ts +2 -0
- package/dist/src/config/migrator/index.d.ts +4 -1
- package/dist/src/config/migrator/itemsPriceFormatMigrator.d.ts +1 -0
- package/dist/src/extensions/Blocks/Items/block.d.ts +6 -9
- package/dist/src/extensions/Blocks/Items/constants/currency.d.ts +32 -0
- package/dist/src/extensions/Blocks/Items/controls/priceFormat.d.ts +23 -0
- package/dist/src/extensions/Blocks/Items/controls/settingsControl.d.ts +1 -0
- package/dist/src/extensions/Blocks/Items/enums/controlEnums.d.ts +1 -0
- package/dist/src/extensions/Blocks/Items/template.d.ts +4 -1
- package/dist/src/extensions/Blocks/Items/utils/nodeConfigUtils.d.ts +3 -0
- package/dist/src/extensions/Blocks/Items/utils/priceFormatOps.d.ts +61 -0
- package/dist/src/extensions/Blocks/Recommendation/utils/priceFormatter.d.ts +12 -0
- package/dist/src/stores/config.d.ts +20 -0
- package/dist/src/utils/itemsCurrencyRepair.d.ts +5 -1
- package/dist/utils/itemsCurrencyRepair.js +29 -24
- package/dist/utils/pairProductVariables.js +119 -99
- package/package.json +1 -1
|
@@ -1,33 +1,42 @@
|
|
|
1
1
|
var k = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
var E = (h, d, t) => d in h ? k(h, d, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[d] = t;
|
|
3
|
+
var C = (h, d, t) => E(h, typeof d != "symbol" ? d + "" : d, t);
|
|
4
|
+
import { useConfig as P } from "../../../composables/useConfig.js";
|
|
5
|
+
import { BlockId as H } from "../../../enums/block.js";
|
|
6
|
+
import { useOnboardingStore as N } from "../../../stores/onboarding.js";
|
|
7
|
+
import { getMigrationBannerHtml as R } from "../../../utils/migrationBannerHtml.js";
|
|
8
|
+
import { Block as M, BlockCompositionType as O, ModificationDescription as p } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
9
|
+
import { PRODUCT_WRAPPER_SELECTOR as w, isZeroWidthValue as g } from "./constants/cardWidth.js";
|
|
10
|
+
import { DEFAULT_ITEMS_PRICE_FORMAT as I, isNewPriceFormatRoot as v, currencyAttrTargets as B, ITEMS_CURRENCY_ATTR as y } from "./constants/currency.js";
|
|
11
|
+
import { ItemsBlockId as A } from "./enums/controlEnums.js";
|
|
12
|
+
import { SETTINGS_ENUMS as S, DefaultConfigValues as b } from "./enums/settingsEnums.js";
|
|
13
|
+
import { getDefaultTemplate as F } from "./template.js";
|
|
14
|
+
import { getItemsBlockContainer as T, getItemsBlockConfig as _, deriveItemNumber as L, generateBlockInstanceId as x, getDefaultItemsBlockConfig as V } from "./utils/nodeConfigUtils.js";
|
|
15
|
+
import { buildPriceFormatSnapshot as W, planPriceFormatOps as z, samePriceText as U, replacePriceText as Y, paragraphKindOf as j } from "./utils/priceFormatOps.js";
|
|
16
|
+
const D = H.Items, q = "Reconcile Items currency DOM attributes";
|
|
17
|
+
function K() {
|
|
18
|
+
return {
|
|
19
|
+
priceThousandSeparator: I.thousandSeparator,
|
|
20
|
+
priceDecimalSeparator: I.decimalSeparator,
|
|
21
|
+
priceDecimalCount: I.decimalCount
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
class at extends M {
|
|
16
25
|
constructor() {
|
|
17
26
|
super(...arguments);
|
|
18
27
|
/** Block instances whose currency attrs were already self-healed this session (SD-147588 — undo-safe). */
|
|
19
|
-
|
|
28
|
+
C(this, "_currencyHealed", /* @__PURE__ */ new Set());
|
|
20
29
|
/** blockInstanceIds already claimed by a live block this session (SD-147588 collision detection). */
|
|
21
|
-
|
|
30
|
+
C(this, "_seenInstanceIds", /* @__PURE__ */ new Set());
|
|
22
31
|
}
|
|
23
32
|
getId() {
|
|
24
|
-
return
|
|
33
|
+
return D;
|
|
25
34
|
}
|
|
26
35
|
getIcon() {
|
|
27
36
|
return "items-icon";
|
|
28
37
|
}
|
|
29
38
|
getBlockCompositionType() {
|
|
30
|
-
return
|
|
39
|
+
return O.CONTAINER;
|
|
31
40
|
}
|
|
32
41
|
getName() {
|
|
33
42
|
return this.api.translate("Items");
|
|
@@ -36,20 +45,21 @@ class $ extends H {
|
|
|
36
45
|
return this.api.translate("Items lets you display personalized products based on user behavior.");
|
|
37
46
|
}
|
|
38
47
|
getSettingsPanelTitleHtml() {
|
|
39
|
-
return
|
|
40
|
-
|
|
48
|
+
return R(
|
|
49
|
+
D,
|
|
41
50
|
this.api.translate("Items"),
|
|
42
51
|
this.api.translate("This block is switched from the Old Version to the New Version. We recommend you check the Items block and test your message to ensure it works properly.")
|
|
43
52
|
);
|
|
44
53
|
}
|
|
45
54
|
getTemplate() {
|
|
46
|
-
return
|
|
47
|
-
orientation:
|
|
48
|
-
itemsType:
|
|
55
|
+
return F({
|
|
56
|
+
orientation: S.ORIENTATION.VERTICAL,
|
|
57
|
+
itemsType: S.ITEMS_TYPE.CART_ITEMS,
|
|
49
58
|
itemId: "{{Abandoned Cart Item (1) Url}}",
|
|
50
|
-
currencySymbol:
|
|
51
|
-
currencyLocation:
|
|
52
|
-
formattedPrice:
|
|
59
|
+
currencySymbol: b.productPriceCurrencySymbolControlValue,
|
|
60
|
+
currencyLocation: b.productPriceCurrencyLocationControlValue,
|
|
61
|
+
formattedPrice: b.productPriceFormattedControlValue === "1",
|
|
62
|
+
priceFormat: this._isPriceFormattingEnabled() ? I : void 0
|
|
53
63
|
});
|
|
54
64
|
}
|
|
55
65
|
allowInnerBlocksDND() {
|
|
@@ -59,26 +69,29 @@ class $ extends H {
|
|
|
59
69
|
return !0;
|
|
60
70
|
}
|
|
61
71
|
onCreated(t) {
|
|
62
|
-
const e = this.api.getDocumentModifier(),
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
if (!
|
|
72
|
+
const e = this.api.getDocumentModifier(), s = this.api.getDocumentRootCssNode();
|
|
73
|
+
s.querySelector('[product-attr="imageSrc"] img') || e.modifyCss(s).appendRule('[product-attr="imageSrc"] img {object-fit: contain;}');
|
|
74
|
+
const o = T(t);
|
|
75
|
+
if (!o)
|
|
66
76
|
return;
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
69
|
-
if (!
|
|
70
|
-
const
|
|
71
|
-
|
|
77
|
+
const i = o.getNodeConfig(), c = i && Object.keys(i).length > 0, r = _(t);
|
|
78
|
+
if (r != null && r.initialized) {
|
|
79
|
+
if (!c) {
|
|
80
|
+
const l = this.api.getDocumentModifier();
|
|
81
|
+
l.modifyHtml(o).setNodeConfig(r), this._stampProductTdDomAttributes(o, r, l), this._healCollapsedWidths(o, l), this._shouldReconcileCurrency(r) && this._reconcileCurrencyDomAttributes(o, r, l), l.apply(new p("Migrate legacy config to nodeConfig")), this._markCurrencyHealed(r.blockInstanceId);
|
|
72
82
|
return;
|
|
73
83
|
}
|
|
74
84
|
} else {
|
|
75
|
-
const
|
|
76
|
-
|
|
85
|
+
const l = {
|
|
86
|
+
...V(),
|
|
87
|
+
...this._isPriceFormattingEnabled() ? K() : {}
|
|
88
|
+
}, f = this.api.getDocumentModifier();
|
|
89
|
+
f.modifyHtml(o).setNodeConfig(l), this._stampProductTdDomAttributes(o, l, f, !0), f.apply(new p("Initialize Items block with default configuration")), N().startOnboarding("itemsOnboarding");
|
|
77
90
|
return;
|
|
78
91
|
}
|
|
79
|
-
const
|
|
80
|
-
let
|
|
81
|
-
|
|
92
|
+
const n = this._resolveInstanceId(r.blockInstanceId), a = { ...r, blockInstanceId: n }, u = this.api.getDocumentModifier();
|
|
93
|
+
let m = !1;
|
|
94
|
+
n !== r.blockInstanceId && (u.modifyHtml(o).setNodeConfig(a), m = !0), !this._currencyHealed.has(n) && this._reconcileCurrencyDomAttributes(o, a, u) && (m = !0), this._healCollapsedWidths(o, u) && (m = !0), m && u.apply(new p("Assign Items block instance ID and reconcile currency")), this._markCurrencyHealed(n);
|
|
82
95
|
}
|
|
83
96
|
/**
|
|
84
97
|
* Re-seeds nodeConfig from the persisted esd-ext-config when a saved module
|
|
@@ -87,23 +100,23 @@ class $ extends H {
|
|
|
87
100
|
* Guarded to the nodeConfig-empty case so it runs once and never loops.
|
|
88
101
|
*/
|
|
89
102
|
onDocumentChanged(t) {
|
|
90
|
-
const e =
|
|
103
|
+
const e = T(t);
|
|
91
104
|
if (!e)
|
|
92
105
|
return;
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const
|
|
98
|
-
this._reconcileCurrencyDomAttributes(e,
|
|
106
|
+
const s = e.getNodeConfig();
|
|
107
|
+
if (s && Object.keys(s).length > 0) {
|
|
108
|
+
const r = _(t);
|
|
109
|
+
if (r != null && r.initialized && this._shouldReconcileCurrency(r)) {
|
|
110
|
+
const n = this.api.getDocumentModifier();
|
|
111
|
+
this._reconcileCurrencyDomAttributes(e, r, n) && n.apply(new p(q)), this._markCurrencyHealed(r.blockInstanceId);
|
|
99
112
|
}
|
|
100
113
|
return;
|
|
101
114
|
}
|
|
102
|
-
const
|
|
103
|
-
if (!(
|
|
115
|
+
const i = _(t);
|
|
116
|
+
if (!(i != null && i.initialized))
|
|
104
117
|
return;
|
|
105
|
-
const
|
|
106
|
-
|
|
118
|
+
const c = this.api.getDocumentModifier();
|
|
119
|
+
c.modifyHtml(e).setNodeConfig(i), this._stampProductTdDomAttributes(e, i, c), this._healCollapsedWidths(e, c), this._shouldReconcileCurrency(i) && this._reconcileCurrencyDomAttributes(e, i, c), c.apply(new p("Recover Items block config from saved module")), this._markCurrencyHealed(i.blockInstanceId);
|
|
107
120
|
}
|
|
108
121
|
/**
|
|
109
122
|
* Bakes the compiler-read DOM attributes (`data-type`, `data-number`, `data-nodup`) onto the
|
|
@@ -113,21 +126,21 @@ class $ extends H {
|
|
|
113
126
|
* restored before export. The name `<a>` carries no data-type/data-number of its own and
|
|
114
127
|
* relies on this td-level fallback in pairProductVariables.
|
|
115
128
|
*/
|
|
116
|
-
_stampProductTdDomAttributes(t, e,
|
|
117
|
-
const
|
|
118
|
-
|
|
129
|
+
_stampProductTdDomAttributes(t, e, s, o = !1) {
|
|
130
|
+
const i = L(e.itemsSelectValue, e.type), c = (r, n) => {
|
|
131
|
+
o && t.getAttribute(r) || s.modifyHtml(t).setAttribute(r, n);
|
|
119
132
|
};
|
|
120
|
-
|
|
133
|
+
c("data-type", e.type), c("data-number", i), c("data-nodup", String(e.priceHideDiscount));
|
|
121
134
|
}
|
|
122
135
|
/**
|
|
123
136
|
* Repairs a saved module's collapsed card into the state the load migrator produces. Acts only
|
|
124
137
|
* on a zero width, so Stripo's non-zero drop-time width never triggers it and a healed block no-ops.
|
|
125
138
|
*/
|
|
126
139
|
_healCollapsedWidths(t, e) {
|
|
127
|
-
const
|
|
128
|
-
return !
|
|
129
|
-
const
|
|
130
|
-
(
|
|
140
|
+
const o = t.querySelectorAll(w).filter((i) => g(i.getAttribute("width")) || g(i.getStyle("width")));
|
|
141
|
+
return !g(t.getAttribute("width")) && !o.length ? !1 : (t.hasClass("esd-container-frame") && e.modifyHtml(t).removeClass("esd-container-frame"), t.getAttribute("width") !== null && e.modifyHtml(t).removeAttribute("width"), o.forEach((i) => {
|
|
142
|
+
const c = i.getAttribute("width");
|
|
143
|
+
(c === null || g(c)) && e.modifyHtml(i).setAttribute("width", "100%"), g(i.getStyle("width")) && e.modifyHtml(i).setStyle("width", "100%");
|
|
131
144
|
}), !0);
|
|
132
145
|
}
|
|
133
146
|
/**
|
|
@@ -156,30 +169,55 @@ class $ extends H {
|
|
|
156
169
|
let e = t;
|
|
157
170
|
if (!e || this._seenInstanceIds.has(e))
|
|
158
171
|
do
|
|
159
|
-
e =
|
|
172
|
+
e = x();
|
|
160
173
|
while (this._seenInstanceIds.has(e));
|
|
161
174
|
return this._seenInstanceIds.add(e), e;
|
|
162
175
|
}
|
|
163
176
|
/**
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* Config is the source of truth — never derive from visible text.
|
|
167
|
-
*
|
|
168
|
-
* Authority split lives in `currencyAttrTargets` (SD-147588) — position only when a location
|
|
169
|
-
* is recorded, symbol only when customized — so this heal and the module-drop repair can't drift.
|
|
170
|
-
*
|
|
171
|
-
* Returns true only when an attr actually changed, so the caller can skip an empty apply that
|
|
172
|
-
* would otherwise re-trigger onDocumentChanged and loop.
|
|
177
|
+
* Single self-heal slot: the flag only decides whether a legacy root is converted; a root
|
|
178
|
+
* already in the new format is reconciled from config regardless. Returns whether anything was queued.
|
|
173
179
|
*/
|
|
174
|
-
_reconcileCurrencyDomAttributes(t, e,
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
+
_reconcileCurrencyDomAttributes(t, e, s) {
|
|
181
|
+
const o = this._isPriceFormattingEnabled();
|
|
182
|
+
if (!o && !v(t))
|
|
183
|
+
return this._reconcileLegacyCurrencyAttributes(t, e, s);
|
|
184
|
+
const i = this._priceParagraphs(t), c = W({
|
|
185
|
+
rootAttr: (n) => t.getAttribute(n),
|
|
186
|
+
config: e,
|
|
187
|
+
paragraphs: i.map(({ kind: n, node: a }) => ({
|
|
188
|
+
kind: n,
|
|
189
|
+
attr: (u) => a.getAttribute(u),
|
|
190
|
+
text: a.getInnerText()
|
|
191
|
+
}))
|
|
192
|
+
}), r = z(c, { convertLegacy: o });
|
|
193
|
+
return r.changed ? (Object.entries(r.rootSet).forEach(([n, a]) => {
|
|
194
|
+
s.modifyHtml(t).setAttribute(n, a);
|
|
195
|
+
}), i.forEach(({ kind: n, node: a }) => {
|
|
196
|
+
var l;
|
|
197
|
+
r.paragraphRemove.filter((f) => a.getAttribute(f) !== null).forEach((f) => s.modifyHtml(a).removeAttribute(f));
|
|
198
|
+
const u = (l = r.texts) == null ? void 0 : l[n], m = a.getInnerText();
|
|
199
|
+
u !== void 0 && !U(m, u) && s.modifyHtml(a).setInnerHtml(Y(a.getInnerHTML(), m, u));
|
|
200
|
+
}), r.configPatch && s.modifyHtml(t).setNodeConfig({ ...e, ...r.configPatch }), !0) : !1;
|
|
201
|
+
}
|
|
202
|
+
/** Legacy `<p>` contract via `currencyAttrTargets`: position when recorded, symbol only when custom. */
|
|
203
|
+
_reconcileLegacyCurrencyAttributes(t, e, s) {
|
|
204
|
+
const { position: o, symbol: i } = B(e), c = t.querySelectorAll(`.${A.PRICE} p`);
|
|
205
|
+
let r = !1;
|
|
206
|
+
return c.forEach((n) => {
|
|
207
|
+
o !== void 0 && n.getAttribute(y.POSITION) !== o && (s.modifyHtml(n).setAttribute(y.POSITION, o), r = !0), i !== void 0 && n.getAttribute(y.SYMBOL) !== i && (s.modifyHtml(n).setAttribute(y.SYMBOL, i), r = !0);
|
|
208
|
+
}), r;
|
|
209
|
+
}
|
|
210
|
+
_priceParagraphs(t) {
|
|
211
|
+
return t.querySelectorAll(`.${A.PRICE} p`).flatMap((s) => {
|
|
212
|
+
const o = j(s.getAttribute("product-attr"));
|
|
213
|
+
return o ? [{ kind: o, node: s }] : [];
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
_isPriceFormattingEnabled() {
|
|
217
|
+
return P().isFeatureEnabled("itemsPriceFormatting");
|
|
180
218
|
}
|
|
181
219
|
}
|
|
182
220
|
export {
|
|
183
|
-
|
|
184
|
-
|
|
221
|
+
D as BLOCK_ID,
|
|
222
|
+
at as ItemsBlock
|
|
185
223
|
};
|
|
@@ -1,25 +1,70 @@
|
|
|
1
1
|
import { DefaultConfigValues as c } from "../enums/settingsEnums.js";
|
|
2
|
-
const
|
|
2
|
+
const n = {
|
|
3
3
|
POSITION: "data-curency",
|
|
4
4
|
SYMBOL: "data-currency_symbol"
|
|
5
5
|
};
|
|
6
|
-
function
|
|
7
|
-
return
|
|
6
|
+
function u(t) {
|
|
7
|
+
return t === "1" ? "after" : "before";
|
|
8
8
|
}
|
|
9
|
-
function i(
|
|
10
|
-
const
|
|
11
|
-
return
|
|
9
|
+
function i(t) {
|
|
10
|
+
const r = (t ?? "").trim();
|
|
11
|
+
return r !== "" && r !== c.productPriceCurrencySymbolControlValue;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
const
|
|
13
|
+
function p(t) {
|
|
14
|
+
const r = t.priceCurrencyLocation, e = typeof r == "string" && r.trim() !== "", a = (t.priceCurrencySymbol ?? "").trim();
|
|
15
15
|
return {
|
|
16
|
-
position:
|
|
17
|
-
symbol: i(
|
|
16
|
+
position: e ? u(r) : void 0,
|
|
17
|
+
symbol: i(a) ? a : void 0
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
+
const s = {
|
|
21
|
+
SYMBOL: "currency-symbol",
|
|
22
|
+
ALIGNMENT: "currency-alignment",
|
|
23
|
+
THOUSAND_SEPARATOR: "currency-thousand-separator",
|
|
24
|
+
DECIMAL_SEPARATOR: "currency-decimal-separator",
|
|
25
|
+
DECIMAL_COUNT: "currency-decimal-count",
|
|
26
|
+
SINGLE_PRICE: "data-single_price"
|
|
27
|
+
}, C = [
|
|
28
|
+
"data-formated",
|
|
29
|
+
"data-single_price",
|
|
30
|
+
n.POSITION,
|
|
31
|
+
n.SYMBOL
|
|
32
|
+
], o = {
|
|
33
|
+
thousandSeparator: ",",
|
|
34
|
+
decimalSeparator: ".",
|
|
35
|
+
decimalCount: 2
|
|
36
|
+
};
|
|
37
|
+
function m(t) {
|
|
38
|
+
const r = typeof t == "string" ? parseInt(t) : t;
|
|
39
|
+
return typeof r == "number" && Number.isFinite(r) && r >= 0 ? Math.trunc(r) : o.decimalCount;
|
|
40
|
+
}
|
|
41
|
+
function d(t) {
|
|
42
|
+
const r = t == null ? void 0 : t.priceThousandSeparator, e = t == null ? void 0 : t.priceDecimalSeparator;
|
|
43
|
+
return {
|
|
44
|
+
thousandSeparator: typeof r == "string" && r !== "" ? r : o.thousandSeparator,
|
|
45
|
+
decimalSeparator: typeof e == "string" && e !== "" ? e : o.decimalSeparator,
|
|
46
|
+
decimalCount: (t == null ? void 0 : t.priceDecimalCount) === void 0 ? o.decimalCount : m(t.priceDecimalCount)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function y(t) {
|
|
50
|
+
return typeof (t == null ? void 0 : t.priceDecimalCount) == "number";
|
|
51
|
+
}
|
|
52
|
+
function S(t) {
|
|
53
|
+
if (!t || typeof t.getAttribute != "function")
|
|
54
|
+
return !1;
|
|
55
|
+
const r = t.getAttribute(s.DECIMAL_COUNT);
|
|
56
|
+
return r != null;
|
|
57
|
+
}
|
|
20
58
|
export {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
59
|
+
o as DEFAULT_ITEMS_PRICE_FORMAT,
|
|
60
|
+
n as ITEMS_CURRENCY_ATTR,
|
|
61
|
+
s as ITEMS_PRICE_FORMAT_ATTR,
|
|
62
|
+
C as LEGACY_PRICE_PARAGRAPH_ATTRS,
|
|
63
|
+
p as currencyAttrTargets,
|
|
64
|
+
u as currencyPositionFromLocation,
|
|
65
|
+
i as isCustomCurrencySymbol,
|
|
66
|
+
y as isNewPriceFormatConfig,
|
|
67
|
+
S as isNewPriceFormatRoot,
|
|
68
|
+
m as normalizeDecimalCount,
|
|
69
|
+
d as priceFormatFromConfig
|
|
25
70
|
};
|
|
@@ -1,48 +1,59 @@
|
|
|
1
|
-
import { currencyLocationMaps as
|
|
2
|
-
import { UEAttr as I, ModificationDescription as
|
|
3
|
-
import { CommonControl as
|
|
4
|
-
import { ITEMS_CURRENCY_ATTR as
|
|
5
|
-
import { ItemsBlockControlId as
|
|
6
|
-
import { getItemsBlockConfig as
|
|
7
|
-
|
|
1
|
+
import { currencyLocationMaps as u } from "../../../../../enums/extensions/recommendationBlock.js";
|
|
2
|
+
import { UEAttr as I, ModificationDescription as T } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
3
|
+
import { CommonControl as E } from "../../../common-control.js";
|
|
4
|
+
import { ITEMS_CURRENCY_ATTR as f, currencyPositionFromLocation as h } from "../../constants/currency.js";
|
|
5
|
+
import { ItemsBlockControlId as d } from "../../enums/controlEnums.js";
|
|
6
|
+
import { getItemsBlockConfig as C, setItemsBlockConfig as O, escapeReplacement as P } from "../../utils/nodeConfigUtils.js";
|
|
7
|
+
import { isNewPriceFormatBlock as b, applyPriceFormatChange as U } from "../priceFormat.js";
|
|
8
|
+
const x = d.PRICE_CURRENCY_LOCATION, a = {
|
|
8
9
|
CURRENCY_LOCATION: "currencyLocation"
|
|
9
10
|
};
|
|
10
|
-
class
|
|
11
|
+
class H extends E {
|
|
11
12
|
getId() {
|
|
12
|
-
return
|
|
13
|
+
return x;
|
|
13
14
|
}
|
|
14
15
|
getTemplate() {
|
|
15
16
|
return `
|
|
16
|
-
<div class="container ${
|
|
17
|
+
<div class="container ${d.PRICE_CURRENCY_LOCATION}">
|
|
17
18
|
${this._getCurrencyLocation()}
|
|
18
19
|
</div>
|
|
19
20
|
`;
|
|
20
21
|
}
|
|
21
22
|
onRender() {
|
|
22
|
-
this.forgetLastPanelNode(), this.api.setUIEAttribute(a.CURRENCY_LOCATION, I.SELECTPICKER.items,
|
|
23
|
+
this.forgetLastPanelNode(), this.api.setUIEAttribute(a.CURRENCY_LOCATION, I.SELECTPICKER.items, u), this.api.onValueChanged(a.CURRENCY_LOCATION, (e) => {
|
|
23
24
|
this._onCurrencyLocationChange(e);
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
27
|
onTemplateNodeUpdated(e) {
|
|
27
28
|
super.onTemplateNodeUpdated(e), this.handleBlockInstanceChange(() => {
|
|
28
|
-
const t =
|
|
29
|
+
const t = C(this.currentNode);
|
|
29
30
|
this.api.updateValues({ [a.CURRENCY_LOCATION]: (t == null ? void 0 : t.priceCurrencyLocation) ?? "0" });
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
33
|
_onCurrencyLocationChange(e) {
|
|
33
|
-
|
|
34
|
+
var l;
|
|
35
|
+
if (console.debug("Currency location changed to: ", e), b(this.currentNode)) {
|
|
36
|
+
((l = C(this.currentNode)) == null ? void 0 : l.priceCurrencyLocation) !== e && U(
|
|
37
|
+
this.currentNode,
|
|
38
|
+
this.api,
|
|
39
|
+
{ priceCurrencyLocation: e },
|
|
40
|
+
`Updated currency location to ${h(e)}`
|
|
41
|
+
);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (O(this.currentNode, this.api, { priceCurrencyLocation: e }), !this.currentNode)
|
|
34
45
|
return;
|
|
35
46
|
const t = this._getPriceBlocks();
|
|
36
47
|
if (!t || t.length === 0)
|
|
37
48
|
return;
|
|
38
|
-
const r =
|
|
39
|
-
t.forEach((
|
|
40
|
-
const s = this._getParagraph(
|
|
49
|
+
const r = C(this.currentNode), n = e || "0", o = (r == null ? void 0 : r.priceCurrencySymbol) ?? "", c = h(n), i = this.api.getDocumentModifier();
|
|
50
|
+
t.forEach((g) => {
|
|
51
|
+
const s = this._getParagraph(g);
|
|
41
52
|
if (!s)
|
|
42
53
|
return;
|
|
43
|
-
const
|
|
44
|
-
i.modifyHtml(s).setInnerHtml(R).setAttribute(
|
|
45
|
-
}), i.apply(new
|
|
54
|
+
const _ = s.getInnerHTML().trim() || "", p = s.getInnerText().trim() || "", m = (o == null ? void 0 : o.trim()) || "", y = this._removeCurrencySymbol(p, m), N = this._detectSymbolInText(p) || m, L = this._buildPriceContent(y, N, n), R = _.replace(p, P(L));
|
|
55
|
+
i.modifyHtml(s).setInnerHtml(R).setAttribute(f.POSITION, c);
|
|
56
|
+
}), i.apply(new T(
|
|
46
57
|
`Updated currency location to ${c}`
|
|
47
58
|
));
|
|
48
59
|
}
|
|
@@ -85,13 +96,13 @@ class B extends N {
|
|
|
85
96
|
this._GuSelect({
|
|
86
97
|
name: a.CURRENCY_LOCATION,
|
|
87
98
|
placeholder: "",
|
|
88
|
-
options:
|
|
99
|
+
options: u
|
|
89
100
|
})
|
|
90
101
|
])}
|
|
91
102
|
`;
|
|
92
103
|
}
|
|
93
104
|
}
|
|
94
105
|
export {
|
|
95
|
-
|
|
96
|
-
|
|
106
|
+
x as CONTROL_BLOCK_ID,
|
|
107
|
+
H as PriceCurrencyLocationControl
|
|
97
108
|
};
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
var R = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
2
|
+
var f = (i, c, e) => c in i ? R(i, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[c] = e;
|
|
3
|
+
var y = (i, c, e) => f(i, typeof c != "symbol" ? c + "" : c, e);
|
|
4
|
+
import { useConfig as E } from "../../../../../composables/useConfig.js";
|
|
5
|
+
import { ModificationDescription as B } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
6
|
+
import { CommonControl as P } from "../../../common-control.js";
|
|
7
|
+
import { ITEMS_CURRENCY_ATTR as T } from "../../constants/currency.js";
|
|
8
|
+
import { ItemsBlockControlId as d } from "../../enums/controlEnums.js";
|
|
9
|
+
import { getItemsBlockConfig as p, setItemsBlockConfig as x, escapeReplacement as I } from "../../utils/nodeConfigUtils.js";
|
|
10
|
+
import { isNewPriceFormatBlock as L, applyPriceFormatChange as M } from "../priceFormat.js";
|
|
11
|
+
const Y = d.PRICE_CURRENCY_SYMBOL, u = {
|
|
10
12
|
CURRENCY_SYMBOL: "currencySymbol"
|
|
11
13
|
};
|
|
12
|
-
class
|
|
14
|
+
class A extends P {
|
|
13
15
|
constructor() {
|
|
14
16
|
super(...arguments);
|
|
15
|
-
|
|
17
|
+
y(this, "originalPriceContents", /* @__PURE__ */ new Map());
|
|
16
18
|
}
|
|
17
19
|
getId() {
|
|
18
|
-
return
|
|
20
|
+
return Y;
|
|
19
21
|
}
|
|
20
22
|
getTemplate() {
|
|
23
|
+
const e = E().isFeatureEnabled("itemsPriceFormatting") ? " no-separator" : "";
|
|
21
24
|
return `
|
|
22
|
-
<div class="container ${
|
|
25
|
+
<div class="container ${d.PRICE_CURRENCY_SYMBOL}${e}">
|
|
23
26
|
${this._getCurrencySymbol()}
|
|
24
27
|
</div>
|
|
25
28
|
`;
|
|
@@ -34,28 +37,36 @@ class $ extends f {
|
|
|
34
37
|
}
|
|
35
38
|
onTemplateNodeUpdated(e) {
|
|
36
39
|
super.onTemplateNodeUpdated(e), this.handleBlockInstanceChange(() => {
|
|
37
|
-
const
|
|
38
|
-
this.api.updateValues({ [u.CURRENCY_SYMBOL]: (
|
|
40
|
+
const r = p(this.currentNode);
|
|
41
|
+
this.api.updateValues({ [u.CURRENCY_SYMBOL]: (r == null ? void 0 : r.priceCurrencySymbol) ?? "" }), this._storeOriginalContents();
|
|
39
42
|
});
|
|
40
43
|
}
|
|
41
44
|
_onCurrencySymbolChange(e) {
|
|
42
|
-
var
|
|
43
|
-
console.debug("Currency symbol changed to: ", e)
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
var m, C;
|
|
46
|
+
if (console.debug("Currency symbol changed to: ", e), L(this.currentNode)) {
|
|
47
|
+
((m = p(this.currentNode)) == null ? void 0 : m.priceCurrencySymbol) !== e && M(
|
|
48
|
+
this.currentNode,
|
|
49
|
+
this.api,
|
|
50
|
+
{ priceCurrencySymbol: e },
|
|
51
|
+
`Updated currency symbol to ${(e == null ? void 0 : e.trim()) || "removed"}`
|
|
52
|
+
);
|
|
46
53
|
return;
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
}
|
|
55
|
+
const r = p(this.currentNode), n = ((C = r == null ? void 0 : r.priceCurrencySymbol) == null ? void 0 : C.trim()) || "";
|
|
56
|
+
if (x(this.currentNode, this.api, { priceCurrencySymbol: e }), !this.currentNode)
|
|
57
|
+
return;
|
|
58
|
+
const t = this._getPriceBlocks();
|
|
59
|
+
if (!t || t.length === 0)
|
|
49
60
|
return;
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
if (!
|
|
61
|
+
const o = (e == null ? void 0 : e.trim()) || "", a = (r == null ? void 0 : r.priceCurrencyLocation) ?? "0", s = this.api.getDocumentModifier();
|
|
62
|
+
t.forEach((g) => {
|
|
63
|
+
const l = this._getParagraph(g);
|
|
64
|
+
if (!l)
|
|
54
65
|
return;
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
}),
|
|
58
|
-
`Updated currency symbol to ${
|
|
66
|
+
const S = l.getInnerHTML().trim() || "", h = l.getInnerText().trim() || "", _ = this._removeCurrencySymbol(h, n), b = this._buildPriceContent(_, o, a), N = S.replace(h, I(b));
|
|
67
|
+
s.modifyHtml(l).setInnerHtml(N).setAttribute(T.SYMBOL, o);
|
|
68
|
+
}), s.apply(new B(
|
|
69
|
+
`Updated currency symbol to ${o || "removed"}`
|
|
59
70
|
));
|
|
60
71
|
}
|
|
61
72
|
_storeOriginalContents() {
|
|
@@ -64,18 +75,18 @@ class $ extends f {
|
|
|
64
75
|
const e = p(this.currentNode);
|
|
65
76
|
this.currentNode.querySelectorAll(
|
|
66
77
|
".items-block-price"
|
|
67
|
-
).forEach((
|
|
68
|
-
var
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
71
|
-
const
|
|
72
|
-
this.originalPriceContents.set(
|
|
78
|
+
).forEach((n) => {
|
|
79
|
+
var o;
|
|
80
|
+
const t = n.querySelector("p");
|
|
81
|
+
if (t && !this.originalPriceContents.has(t)) {
|
|
82
|
+
const a = t.getInnerText() || "", s = ((o = e == null ? void 0 : e.priceCurrencySymbol) == null ? void 0 : o.trim()) || "", m = this._removeCurrencySymbol(a, s);
|
|
83
|
+
this.originalPriceContents.set(t, m);
|
|
73
84
|
}
|
|
74
85
|
});
|
|
75
86
|
}
|
|
76
87
|
_getPriceBlocks() {
|
|
77
|
-
var e,
|
|
78
|
-
return ((
|
|
88
|
+
var e, r;
|
|
89
|
+
return ((r = (e = this.currentNode) == null ? void 0 : e.closest(".items-block")) == null ? void 0 : r.querySelectorAll(".items-block-price")) || [];
|
|
79
90
|
}
|
|
80
91
|
_getParagraph(e) {
|
|
81
92
|
return e.querySelector("p");
|
|
@@ -83,23 +94,23 @@ class $ extends f {
|
|
|
83
94
|
_escapeRegex(e) {
|
|
84
95
|
return e.replace(/[-\\^$*+?().|[\]{}]/g, "\\$&");
|
|
85
96
|
}
|
|
86
|
-
_removeCurrencySymbol(e,
|
|
87
|
-
const
|
|
88
|
-
let
|
|
89
|
-
if (
|
|
90
|
-
const
|
|
91
|
-
|
|
97
|
+
_removeCurrencySymbol(e, r) {
|
|
98
|
+
const n = e || "";
|
|
99
|
+
let t = n;
|
|
100
|
+
if (r) {
|
|
101
|
+
const o = new RegExp(`\\s*${this._escapeRegex(r)}\\s*`);
|
|
102
|
+
t = n.replace(o, "").trim();
|
|
92
103
|
} else {
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
const
|
|
96
|
-
|
|
104
|
+
const o = n.match(/([^0-9.,\s]+)/);
|
|
105
|
+
if (o && o[1]) {
|
|
106
|
+
const a = o[1].trim(), s = new RegExp(`\\s*${this._escapeRegex(a)}\\s*`);
|
|
107
|
+
t = n.replace(s, "").trim();
|
|
97
108
|
}
|
|
98
109
|
}
|
|
99
|
-
return
|
|
110
|
+
return t;
|
|
100
111
|
}
|
|
101
|
-
_buildPriceContent(e,
|
|
102
|
-
return
|
|
112
|
+
_buildPriceContent(e, r, n) {
|
|
113
|
+
return r ? n === "1" ? `${e} ${r}` : `${r} ${e}` : e;
|
|
103
114
|
}
|
|
104
115
|
_getCurrencySymbol() {
|
|
105
116
|
return `
|
|
@@ -115,6 +126,6 @@ class $ extends f {
|
|
|
115
126
|
}
|
|
116
127
|
}
|
|
117
128
|
export {
|
|
118
|
-
|
|
119
|
-
|
|
129
|
+
Y as CONTROL_BLOCK_ID,
|
|
130
|
+
A as PriceCurrencySymbolControl
|
|
120
131
|
};
|