@useinsider/guido 3.24.0-beta.2a3ba08 → 3.24.0-beta.3686ce3

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.
Files changed (50) hide show
  1. package/README.md +6 -2
  2. package/dist/@types/config/schemas.js +7 -9
  3. package/dist/components/Guido.vue.js +1 -1
  4. package/dist/components/Guido.vue2.js +77 -79
  5. package/dist/composables/useActionsApi.js +2 -2
  6. package/dist/composables/useHtmlCompiler.js +2 -0
  7. package/dist/composables/useModuleRepair.js +12 -14
  8. package/dist/composables/useStripo.js +70 -70
  9. package/dist/config/compiler/htmlCompilerRules.js +14 -6
  10. package/dist/config/migrator/index.js +15 -16
  11. package/dist/extensions/Blocks/Items/block.js +77 -115
  12. package/dist/extensions/Blocks/Items/constants/currency.js +14 -59
  13. package/dist/extensions/Blocks/Items/controls/price/currencyLocation.js +22 -33
  14. package/dist/extensions/Blocks/Items/controls/price/currencySymbol.js +51 -62
  15. package/dist/extensions/Blocks/Items/controls/price/formattedPrice.js +17 -18
  16. package/dist/extensions/Blocks/Items/controls/price/singlePrice.js +31 -42
  17. package/dist/extensions/Blocks/Items/controls/settingsControl.js +120 -141
  18. package/dist/extensions/Blocks/Items/enums/controlEnums.js +1 -1
  19. package/dist/extensions/Blocks/Items/extension.js +8 -9
  20. package/dist/extensions/Blocks/Items/items.css.js +0 -19
  21. package/dist/extensions/Blocks/Items/settingsPanel.js +25 -34
  22. package/dist/extensions/Blocks/Items/template.js +212 -250
  23. package/dist/extensions/Blocks/Recommendation/utils/priceFormatter.js +0 -1
  24. package/dist/guido.css +1 -1
  25. package/dist/package.json.js +2 -2
  26. package/dist/src/@types/config/schemas.d.ts +0 -4
  27. package/dist/src/composables/useConfig.d.ts +0 -2
  28. package/dist/src/composables/useStripo.d.ts +1 -1
  29. package/dist/src/config/migrator/index.d.ts +1 -4
  30. package/dist/src/extensions/Blocks/Items/block.d.ts +9 -6
  31. package/dist/src/extensions/Blocks/Items/constants/currency.d.ts +0 -32
  32. package/dist/src/extensions/Blocks/Items/controls/settingsControl.d.ts +0 -1
  33. package/dist/src/extensions/Blocks/Items/enums/controlEnums.d.ts +0 -1
  34. package/dist/src/extensions/Blocks/Items/template.d.ts +1 -4
  35. package/dist/src/extensions/Blocks/Items/utils/nodeConfigUtils.d.ts +0 -3
  36. package/dist/src/extensions/Blocks/Recommendation/utils/priceFormatter.d.ts +0 -12
  37. package/dist/src/stores/config.d.ts +0 -20
  38. package/dist/src/utils/itemsCurrencyRepair.d.ts +1 -5
  39. package/dist/src/utils/trimHrefWhitespace.d.ts +5 -0
  40. package/dist/utils/itemsCurrencyRepair.js +24 -29
  41. package/dist/utils/pairProductVariables.js +99 -119
  42. package/dist/utils/templatePreparation.js +22 -25
  43. package/dist/utils/trimHrefWhitespace.js +10 -0
  44. package/package.json +1 -1
  45. package/dist/config/migrator/itemsPriceFormatMigrator.js +0 -20
  46. package/dist/extensions/Blocks/Items/controls/priceFormat.js +0 -145
  47. package/dist/extensions/Blocks/Items/utils/priceFormatOps.js +0 -185
  48. package/dist/src/config/migrator/itemsPriceFormatMigrator.d.ts +0 -1
  49. package/dist/src/extensions/Blocks/Items/controls/priceFormat.d.ts +0 -23
  50. package/dist/src/extensions/Blocks/Items/utils/priceFormatOps.d.ts +0 -61
@@ -1,185 +0,0 @@
1
- import { formatNumber as w } from "../../Recommendation/utils/priceFormatter.js";
2
- import { escapeHtml as q } from "../../../../utils/htmlEscape.js";
3
- import { extractWrapperTags as B } from "../../../../utils/preserveTextStyles.js";
4
- import { ITEMS_PRICE_FORMAT_ATTR as c, priceFormatFromConfig as _, normalizeDecimalCount as V, LEGACY_PRICE_PARAGRAPH_ATTRS as O, ITEMS_CURRENCY_ATTR as b } from "../constants/currency.js";
5
- import { productPairs as W } from "../enums/productEnums.js";
6
- import { DefaultConfigValues as I } from "../enums/settingsEnums.js";
7
- import { escapeReplacement as z } from "./nodeConfigUtils.js";
8
- const J = 'p[product-attr="price"], p[product-attr="originalPrice"]', K = [
9
- ...Object.values(c),
10
- "data-type"
11
- ], L = "CART_ITEMS";
12
- function X() {
13
- return { rootSet: {}, paragraphRemove: [], configPatch: null, texts: null, changed: !1 };
14
- }
15
- function h(t) {
16
- return t != null;
17
- }
18
- function Pt(t) {
19
- return t === "price" || t === "originalPrice" ? t : null;
20
- }
21
- function N(t) {
22
- const n = W.PAIRS_FOR_EXTENSION, r = t != null && t.type && t.type in n.price ? t.type : L, o = (t == null ? void 0 : t.priceSinglePrice) === !0, e = n.price[r], i = n.originalPrice[r];
23
- return {
24
- price: o ? e.DEFAULT_SINGLE_PRICE : e.DEFAULT_PRICE,
25
- originalPrice: o ? i.DEFAULT_SINGLE_PRICE : i.DEFAULT_PRICE
26
- };
27
- }
28
- function P({ amount: t, format: n, symbol: r, alignment: o }) {
29
- const e = w(Number(t), n), i = q((r ?? "").trim());
30
- return i ? o === "1" ? `${e} ${i}` : `${i} ${e}` : e;
31
- }
32
- function Tt(t) {
33
- const n = N(t), r = {
34
- format: _(t),
35
- symbol: (t == null ? void 0 : t.priceCurrencySymbol) ?? I.productPriceCurrencySymbolControlValue,
36
- alignment: (t == null ? void 0 : t.priceCurrencyLocation) ?? "0"
37
- };
38
- return {
39
- price: P({ amount: n.price, ...r }),
40
- originalPrice: P({ amount: n.originalPrice, ...r })
41
- };
42
- }
43
- const x = /&nbsp;|\u00a0|\s+/g, Q = "(?:&nbsp;| |\\s)+", Z = /&(amp|lt|gt|quot|#x27|#39);/g, tt = { amp: "&", lt: "<", gt: ">", quot: '"', "#x27": "'", "#39": "'" }, rt = {
44
- "&": "(?:&amp;|&)",
45
- "<": "(?:&lt;|<)",
46
- ">": "(?:&gt;|>)",
47
- '"': '(?:&quot;|")',
48
- "'": "(?:&#x27;|&#39;|')"
49
- }, et = (t) => t.replace(Z, (n, r) => tt[r]), nt = (t) => t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
50
- function ot(t) {
51
- return Array.from(t, (n) => rt[n] ?? nt(n)).join("");
52
- }
53
- function D(t, n) {
54
- const r = (o) => o.replace(x, " ").trim();
55
- return r(t ?? "") === r(et(n ?? ""));
56
- }
57
- function it(t, n, r) {
58
- const o = t.trim(), e = n.trim().split(x).filter(Boolean), i = e.length ? new RegExp(e.map(ot).join(Q)) : null;
59
- if (i != null && i.test(o))
60
- return o.replace(i, z(r));
61
- const { openTags: s, closeTags: u } = B(o);
62
- return `${s}${r}${u}`;
63
- }
64
- function ct(t, n) {
65
- if (!t)
66
- return null;
67
- const r = Object.fromEntries(
68
- Object.entries(n).filter(([o, e]) => t[o] !== e)
69
- );
70
- return Object.keys(r).length > 0 ? r : null;
71
- }
72
- function Ct(t, { convertLegacy: n }) {
73
- const { rootAttrs: r, paragraphs: o, config: e } = t, i = h(r[c.DECIMAL_COUNT]);
74
- if (!i && !n)
75
- return X();
76
- const s = o.find((a) => a.kind === "price") ?? o[0], u = (a) => (s == null ? void 0 : s.attrs[a]) ?? null, l = i ? r[c.SINGLE_PRICE] : u("data-single_price"), m = typeof (e == null ? void 0 : e.priceSinglePrice) == "boolean" ? e.priceSinglePrice : l === "true", A = e == null ? void 0 : e.priceCurrencyLocation, j = u(b.POSITION) === "after" ? "1" : "0", H = i ? r[c.ALIGNMENT] : j, E = (typeof A == "string" && A.trim() !== "" ? A : H) === "1" ? "1" : "0", U = i ? r[c.SYMBOL] : u(b.SYMBOL), S = typeof (e == null ? void 0 : e.priceCurrencySymbol) == "string" ? e.priceCurrencySymbol : U ?? I.productPriceCurrencySymbolControlValue, p = _({
77
- priceThousandSeparator: (e == null ? void 0 : e.priceThousandSeparator) ?? (i ? r[c.THOUSAND_SEPARATOR] ?? void 0 : void 0),
78
- priceDecimalSeparator: (e == null ? void 0 : e.priceDecimalSeparator) ?? (i ? r[c.DECIMAL_SEPARATOR] ?? void 0 : void 0),
79
- priceDecimalCount: (e == null ? void 0 : e.priceDecimalCount) ?? (i ? V(r[c.DECIMAL_COUNT]) : void 0)
80
- }), G = {
81
- [c.SYMBOL]: S.trim(),
82
- [c.ALIGNMENT]: E,
83
- [c.THOUSAND_SEPARATOR]: p.thousandSeparator,
84
- [c.DECIMAL_SEPARATOR]: p.decimalSeparator,
85
- [c.DECIMAL_COUNT]: String(p.decimalCount),
86
- [c.SINGLE_PRICE]: m ? "true" : "false"
87
- }, T = Object.fromEntries(
88
- Object.entries(G).filter(([a, d]) => r[a] !== d)
89
- ), C = O.filter(
90
- (a) => o.some((d) => h(d.attrs[a]))
91
- ), $ = {
92
- priceThousandSeparator: p.thousandSeparator,
93
- priceDecimalSeparator: p.decimalSeparator,
94
- priceDecimalCount: p.decimalCount,
95
- priceSinglePrice: m,
96
- priceCurrencyLocation: E,
97
- priceCurrencySymbol: S
98
- }, f = ct(e, $), k = (e == null ? void 0 : e.type) ?? r["data-type"] ?? L, R = N({ type: k, priceSinglePrice: m }), y = (a) => P({ amount: a, format: p, symbol: S, alignment: E }), g = { price: y(R.price), originalPrice: y(R.originalPrice) }, Y = o.some((a) => !D(a.text, g[a.kind]));
99
- return {
100
- rootSet: T,
101
- paragraphRemove: C,
102
- configPatch: f,
103
- texts: g,
104
- changed: Object.keys(T).length > 0 || C.length > 0 || f !== null || Y
105
- };
106
- }
107
- function at(t) {
108
- const n = {};
109
- return K.forEach((r) => {
110
- n[r] = t.rootAttr(r) ?? null;
111
- }), {
112
- rootAttrs: n,
113
- config: t.config,
114
- paragraphs: t.paragraphs.map((r) => {
115
- const o = {};
116
- return O.forEach((e) => {
117
- o[e] = r.attr(e) ?? null;
118
- }), { kind: r.kind, attrs: o, text: r.text.trim() };
119
- })
120
- };
121
- }
122
- function M(t) {
123
- const n = t.getAttribute("esd-ext-config");
124
- if (!n)
125
- return null;
126
- try {
127
- const r = JSON.parse(n);
128
- return r && typeof r == "object" ? r : null;
129
- } catch {
130
- return null;
131
- }
132
- }
133
- function F(t) {
134
- return Array.from(t.querySelectorAll(J)).map((n) => ({
135
- kind: n.getAttribute("product-attr"),
136
- element: n
137
- }));
138
- }
139
- function v(t) {
140
- return t.textContent;
141
- }
142
- function ft(t) {
143
- return at({
144
- rootAttr: (n) => t.getAttribute(n),
145
- config: M(t),
146
- paragraphs: F(t).map(({ kind: n, element: r }) => ({
147
- kind: n,
148
- attr: (o) => r.getAttribute(o),
149
- text: v(r)
150
- }))
151
- });
152
- }
153
- function Rt(t, n) {
154
- if (!n.changed)
155
- return !1;
156
- let r = !1;
157
- if (Object.entries(n.rootSet).forEach(([o, e]) => {
158
- t.getAttribute(o) !== e && (t.setAttribute(o, e), r = !0);
159
- }), F(t).forEach(({ kind: o, element: e }) => {
160
- var u;
161
- n.paragraphRemove.forEach((l) => {
162
- e.hasAttribute(l) && (e.removeAttribute(l), r = !0);
163
- });
164
- const i = (u = n.texts) == null ? void 0 : u[o], s = v(e).trim();
165
- i !== void 0 && !D(s, i) && (e.innerHTML = it(e.innerHTML, s, i), r = !0);
166
- }), n.configPatch) {
167
- const o = M(t);
168
- o && (t.setAttribute("esd-ext-config", JSON.stringify({ ...o, ...n.configPatch })), r = !0);
169
- }
170
- return r;
171
- }
172
- export {
173
- J as PRICE_PARAGRAPH_SELECTOR,
174
- Rt as applyPriceFormatOpsToElement,
175
- at as buildPriceFormatSnapshot,
176
- P as formatItemsDummyPrice,
177
- Pt as paragraphKindOf,
178
- Ct as planPriceFormatOps,
179
- Tt as priceTextsFromConfig,
180
- M as readPersistedConfigAttribute,
181
- it as replacePriceText,
182
- N as resolvePriceDummyAmounts,
183
- D as samePriceText,
184
- ft as snapshotPriceFormatFromElement
185
- };
@@ -1 +0,0 @@
1
- export declare function migrateItemsPriceFormat(html: string): string;
@@ -1,23 +0,0 @@
1
- import { ControlApi, ImmutableHtmlNode } from '@stripoinc/ui-editor-extensions';
2
- import { CommonControl } from '../../common-control';
3
- import { ItemsBlockControlId } from '../enums/controlEnums';
4
- import { type ItemsBlockConfig } from '../utils/nodeConfigUtils';
5
- export declare const CONTROL_BLOCK_ID = ItemsBlockControlId.PRICE_FORMAT;
6
- export declare function isNewPriceFormatBlock(currentNode: ImmutableHtmlNode | undefined): boolean;
7
- /** One apply: the config patch, the root attrs the export reads, and both price texts re-rendered. */
8
- export declare function applyPriceFormatChange(currentNode: ImmutableHtmlNode | undefined, api: ControlApi, patch: Partial<ItemsBlockConfig>, description: string): void;
9
- export declare class ItemsBlockPriceFormatControl extends CommonControl {
10
- private lastWritten;
11
- getId(): string;
12
- getTemplate(): string;
13
- onRender(): void;
14
- onTemplateNodeUpdated(node: ImmutableHtmlNode): void;
15
- onDestroy(): void;
16
- _onThousandSeparatorChange(value: string): void;
17
- _onDecimalSeparatorChange(value: string): void;
18
- _onDecimalCountChange(value: string): void;
19
- private _currentFormat;
20
- private _write;
21
- private _formValues;
22
- private _getSelectRow;
23
- }
@@ -1,61 +0,0 @@
1
- import { type ItemsPriceFormat } from '../constants/currency';
2
- import { type ItemsBlockConfig } from './nodeConfigUtils';
3
- export type PriceParagraphKind = 'price' | 'originalPrice';
4
- export declare const PRICE_PARAGRAPH_SELECTOR = "p[product-attr=\"price\"], p[product-attr=\"originalPrice\"]";
5
- type AttrMap = Record<string, string | null | undefined>;
6
- export interface PriceParagraphSnapshot {
7
- kind: PriceParagraphKind;
8
- attrs: AttrMap;
9
- text: string;
10
- }
11
- export interface PriceFormatSnapshot {
12
- rootAttrs: AttrMap;
13
- paragraphs: PriceParagraphSnapshot[];
14
- config: Partial<ItemsBlockConfig> | null;
15
- }
16
- export interface PriceTexts {
17
- price: string;
18
- originalPrice: string;
19
- }
20
- export interface PriceFormatOps {
21
- rootSet: Record<string, string>;
22
- paragraphRemove: string[];
23
- configPatch: Partial<ItemsBlockConfig> | null;
24
- texts: PriceTexts | null;
25
- changed: boolean;
26
- }
27
- export interface PlanPriceFormatOptions {
28
- convertLegacy: boolean;
29
- }
30
- export interface FormatDummyPriceInput {
31
- amount: string | number;
32
- format: ItemsPriceFormat;
33
- symbol: string | null | undefined;
34
- alignment: string | null | undefined;
35
- }
36
- export declare function paragraphKindOf(productAttr: string | null | undefined): PriceParagraphKind | null;
37
- export declare function resolvePriceDummyAmounts(config: Pick<Partial<ItemsBlockConfig>, 'type' | 'priceSinglePrice'> | null | undefined): PriceTexts;
38
- export declare function formatItemsDummyPrice({ amount, format, symbol, alignment }: FormatDummyPriceInput): string;
39
- export declare function priceTextsFromConfig(config: Partial<ItemsBlockConfig> | null | undefined): PriceTexts;
40
- /** `text` is decoded DOM text, `html` the rendered markup text (entities allowed). */
41
- export declare function samePriceText(text: string | null | undefined, html: string | null | undefined): boolean;
42
- /** Swaps the whole price text inside the paragraph markup, keeping the style wrappers around it. */
43
- export declare function replacePriceText(innerHtml: string, currentText: string, newText: string): string;
44
- export declare function planPriceFormatOps(snapshot: PriceFormatSnapshot, { convertLegacy }: PlanPriceFormatOptions): PriceFormatOps;
45
- export interface PriceParagraphSource {
46
- kind: PriceParagraphKind;
47
- attr(name: string): string | null | undefined;
48
- text: string;
49
- }
50
- export interface PriceFormatSnapshotSource {
51
- rootAttr(name: string): string | null | undefined;
52
- paragraphs: PriceParagraphSource[];
53
- config: Partial<ItemsBlockConfig> | null;
54
- }
55
- /** Shared snapshot builder so DOM (migrator, repair) and Stripo-node callers read the same attrs. */
56
- export declare function buildPriceFormatSnapshot(source: PriceFormatSnapshotSource): PriceFormatSnapshot;
57
- export declare function readPersistedConfigAttribute(root: Element): Partial<ItemsBlockConfig> | null;
58
- export declare function snapshotPriceFormatFromElement(root: Element): PriceFormatSnapshot;
59
- /** DOM applier for parsed HTML (migrator, module repair). Returns whether anything was written. */
60
- export declare function applyPriceFormatOpsToElement(root: Element, ops: PriceFormatOps): boolean;
61
- export {};