@useinsider/guido 3.8.0-beta.84f6c0a → 3.8.0-beta.bf9ea20
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/config/compiler/utils/recommendationCompilerUtils.js +25 -19
- package/dist/extensions/Blocks/Items/block.js +48 -29
- package/dist/extensions/Blocks/Items/utils/nodeConfigUtils.js +62 -45
- package/dist/extensions/Blocks/Recommendation/constants/selectors.js +10 -11
- package/dist/extensions/Blocks/Recommendation/controls/main/index.js +26 -24
- package/dist/extensions/Blocks/Recommendation/controls/main/layoutOrientation.js +39 -30
- package/dist/extensions/Blocks/Recommendation/controls/main/productLayout.js +34 -28
- package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +333 -285
- package/dist/extensions/Blocks/Recommendation/extension.js +5 -6
- package/dist/extensions/Blocks/Recommendation/settingsPanel.js +2 -3
- package/dist/extensions/Blocks/Recommendation/templates/grid/elementRenderer.js +173 -142
- package/dist/extensions/Blocks/Recommendation/templates/grid/template.js +30 -56
- package/dist/extensions/Blocks/Recommendation/templates/index.js +8 -29
- package/dist/extensions/Blocks/Recommendation/templates/list/elementRenderer.js +105 -132
- package/dist/extensions/Blocks/Recommendation/templates/list/template.js +23 -44
- package/dist/extensions/Blocks/Recommendation/templates/utils.js +64 -112
- package/dist/extensions/Blocks/Recommendation/utils/preserveTextStyles.js +19 -24
- package/dist/extensions/Blocks/Recommendation/utils/tagName.js +22 -30
- package/dist/extensions/Blocks/controlFactories.js +133 -159
- package/dist/src/extensions/Blocks/Items/block.d.ts +8 -0
- package/dist/src/extensions/Blocks/Items/controls/index.d.ts +1 -1
- package/dist/src/extensions/Blocks/Items/utils/nodeConfigUtils.d.ts +1 -1
- package/dist/src/extensions/Blocks/Recommendation/constants/index.d.ts +1 -1
- package/dist/src/extensions/Blocks/Recommendation/constants/selectors.d.ts +0 -2
- package/dist/src/extensions/Blocks/Recommendation/controls/button/index.d.ts +1 -1
- package/dist/src/extensions/Blocks/Recommendation/controls/main/layoutOrientation.d.ts +1 -2
- package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.d.ts +47 -20
- package/dist/src/extensions/Blocks/Recommendation/templates/grid/template.d.ts +4 -4
- package/dist/src/extensions/Blocks/Recommendation/templates/index.d.ts +1 -1
- package/dist/src/extensions/Blocks/Recommendation/templates/list/template.d.ts +2 -3
- package/dist/src/extensions/Blocks/Recommendation/templates/utils.d.ts +11 -165
- package/dist/src/extensions/Blocks/Recommendation/utils/preserveTextStyles.d.ts +0 -15
- package/dist/src/extensions/Blocks/Recommendation/utils/stylePreserver.d.ts +113 -0
- package/dist/src/extensions/Blocks/Recommendation/utils/tagName.d.ts +9 -29
- package/dist/src/extensions/Blocks/controlFactories.d.ts +1 -11
- package/package.json +1 -1
- package/dist/extensions/Blocks/Recommendation/utils/captureStyleTemplates.js +0 -219
- package/dist/src/extensions/Blocks/Recommendation/utils/captureStyleTemplates.d.ts +0 -78
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { RecommendationBlockId as c } from "../constants/blockIds.js";
|
|
2
|
-
import { DESKTOP_CONTAINER_SELECTOR as S, ATTR_PRODUCT_NAME as k, ATTR_PRODUCT_PRICE as E, ATTR_PRODUCT_OLD_PRICE as h, ATTR_PRODUCT_OMNIBUS_PRICE as y, ATTR_PRODUCT_OMNIBUS_DISCOUNT as m, ATTR_PRODUCT_BUTTON as P, ATTR_PRODUCT_IMAGE as x, ATTR_PRODUCT_ATTR as v } from "../constants/selectors.js";
|
|
3
|
-
import { CSS_CLASS_TEXT_TRIM as B } from "../controls/shared/textTrimCssRules.js";
|
|
4
|
-
import { toCustomCompositionKey as U } from "../templates/utils.js";
|
|
5
|
-
import { extractWrapperTags as C } from "./preserveTextStyles.js";
|
|
6
|
-
import { hasQuerySelectorAll as A, hasGetAttribute as l, hasGetStyle as R, hasGetComputedStyle as q } from "./tagName.js";
|
|
7
|
-
const s = [
|
|
8
|
-
"font-size",
|
|
9
|
-
"font-family",
|
|
10
|
-
"font-weight",
|
|
11
|
-
"font-style",
|
|
12
|
-
"color",
|
|
13
|
-
"text-align",
|
|
14
|
-
"line-height",
|
|
15
|
-
"text-decoration"
|
|
16
|
-
], N = [
|
|
17
|
-
"background",
|
|
18
|
-
"background-color",
|
|
19
|
-
"border-width",
|
|
20
|
-
"border-color",
|
|
21
|
-
"border-style",
|
|
22
|
-
"border-radius"
|
|
23
|
-
], M = [
|
|
24
|
-
...s,
|
|
25
|
-
"background",
|
|
26
|
-
"background-color",
|
|
27
|
-
// Stripo's Border Radius control writes the radius to the anchor too, not just the
|
|
28
|
-
// border span — capture it so it survives regeneration (symmetric with BUTTON_BORDER_PROPS).
|
|
29
|
-
"border-radius",
|
|
30
|
-
"padding",
|
|
31
|
-
"width",
|
|
32
|
-
"mso-border-alt",
|
|
33
|
-
"mso-padding-alt"
|
|
34
|
-
], D = [
|
|
35
|
-
"display",
|
|
36
|
-
"width",
|
|
37
|
-
"height",
|
|
38
|
-
"max-width",
|
|
39
|
-
"border-radius",
|
|
40
|
-
"margin"
|
|
41
|
-
], b = /* @__PURE__ */ new Set(["transparent", "rgba(0, 0, 0, 0)"]), G = [
|
|
42
|
-
{ attrKey: k, blockId: c.NAME, kind: "text" },
|
|
43
|
-
{ attrKey: E, blockId: c.PRICE, kind: "text" },
|
|
44
|
-
{ attrKey: h, blockId: c.OLD_PRICE, kind: "text" },
|
|
45
|
-
{ attrKey: y, blockId: c.OMNIBUS_PRICE, kind: "text" },
|
|
46
|
-
{ attrKey: m, blockId: c.OMNIBUS_DISCOUNT, kind: "text" },
|
|
47
|
-
{ attrKey: P, blockId: c.BUTTON, kind: "button" },
|
|
48
|
-
{ attrKey: x, blockId: c.IMAGE, kind: "image" }
|
|
49
|
-
];
|
|
50
|
-
function _(t) {
|
|
51
|
-
return t && "getInnerHTML" in t && typeof t.getInnerHTML == "function" ? t.getInnerHTML().trim() : "";
|
|
52
|
-
}
|
|
53
|
-
function L(t) {
|
|
54
|
-
return t && "getInnerText" in t && typeof t.getInnerText == "function" ? t.getInnerText().trim() : "";
|
|
55
|
-
}
|
|
56
|
-
function a(t, e, r) {
|
|
57
|
-
!e || !R(e) || r.forEach((n) => {
|
|
58
|
-
const i = e.getStyle(n);
|
|
59
|
-
i && i !== "inherit" && i !== "initial" && (t[n] = i);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
function I(t) {
|
|
63
|
-
return Object.entries(t).map(([e, r]) => `${e}: ${r};`).join(" ");
|
|
64
|
-
}
|
|
65
|
-
function O(t) {
|
|
66
|
-
if (!t || !R(t))
|
|
67
|
-
return;
|
|
68
|
-
const e = t.getStyle("background-color") || t.getStyle("background");
|
|
69
|
-
return e && !b.has(e) ? e : void 0;
|
|
70
|
-
}
|
|
71
|
-
function g(t, e) {
|
|
72
|
-
const r = {};
|
|
73
|
-
return a(r, t, e), I(r);
|
|
74
|
-
}
|
|
75
|
-
function w(t) {
|
|
76
|
-
const e = t.querySelector("p"), r = {};
|
|
77
|
-
a(r, t, s), a(r, e, s), a(r, t.querySelector("strong"), s), a(r, t.querySelector("em"), s), a(r, t.querySelector("s"), s);
|
|
78
|
-
const n = I(r), { openTags: i, closeTags: o } = C(_(e));
|
|
79
|
-
return !n && !i ? null : { pStyle: n || void 0, openTags: i, closeTags: o };
|
|
80
|
-
}
|
|
81
|
-
function K(t) {
|
|
82
|
-
const e = t.querySelector(".es-button-border"), r = t.querySelector("a.es-button") ?? t.querySelector("a"), n = g(e, N), i = g(r, M), o = e && "getAttribute" in e ? e.getAttribute("class") ?? "" : "", u = /\bes-fw\b/.test(o), { openTags: T, closeTags: d } = C(_(r)), p = L(r);
|
|
83
|
-
return !n && !i && !u && !T && !p ? null : {
|
|
84
|
-
buttonBorderStyle: n || void 0,
|
|
85
|
-
buttonAnchorStyle: i || void 0,
|
|
86
|
-
buttonFitToContainer: u || void 0,
|
|
87
|
-
buttonText: p || void 0,
|
|
88
|
-
openTags: T,
|
|
89
|
-
closeTags: d
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function H(t) {
|
|
93
|
-
const e = g(t.querySelector("img"), D);
|
|
94
|
-
return e ? { imgStyle: e } : null;
|
|
95
|
-
}
|
|
96
|
-
function $(t, e) {
|
|
97
|
-
return e === "button" ? K(t) : e === "image" ? H(t) : w(t);
|
|
98
|
-
}
|
|
99
|
-
function f(t, e) {
|
|
100
|
-
if (!t || !("querySelector" in t))
|
|
101
|
-
return;
|
|
102
|
-
const r = t.querySelector(S) ?? t;
|
|
103
|
-
if (G.forEach(({ attrKey: o, blockId: u, kind: T }) => {
|
|
104
|
-
const d = r.querySelector(`[esd-extension-block-id="${u}"]`);
|
|
105
|
-
d && e(d, o, T);
|
|
106
|
-
}), !A(r))
|
|
107
|
-
return;
|
|
108
|
-
const n = /* @__PURE__ */ new Set();
|
|
109
|
-
r.querySelectorAll(
|
|
110
|
-
`[esd-extension-block-id="${c.CUSTOM_ATTRIBUTE}"]`
|
|
111
|
-
).forEach((o) => {
|
|
112
|
-
const u = l(o) ? o.getAttribute(v) : null;
|
|
113
|
-
!u || n.has(u) || (n.add(u), e(o, U(u), "text"));
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
function F(t) {
|
|
117
|
-
const e = {};
|
|
118
|
-
return f(t, (r, n, i) => {
|
|
119
|
-
if (!("querySelector" in r))
|
|
120
|
-
return;
|
|
121
|
-
const o = $(r, i);
|
|
122
|
-
o && (e[n] = o);
|
|
123
|
-
}), e;
|
|
124
|
-
}
|
|
125
|
-
function j(t) {
|
|
126
|
-
if (!t || !("querySelector" in t))
|
|
127
|
-
return;
|
|
128
|
-
const e = t.querySelector(S) ?? t, r = e.querySelector(".product-card-segment") ?? e.querySelector(".product-card-wrapper");
|
|
129
|
-
return O(r);
|
|
130
|
-
}
|
|
131
|
-
function X(t) {
|
|
132
|
-
if (!t)
|
|
133
|
-
return;
|
|
134
|
-
const e = l(t) ? t.getAttribute("bgcolor") : null;
|
|
135
|
-
if (e && !b.has(e))
|
|
136
|
-
return e;
|
|
137
|
-
const r = O(t);
|
|
138
|
-
if (r)
|
|
139
|
-
return r;
|
|
140
|
-
const n = q(t) ? t.getComputedStyle("background-color") : void 0;
|
|
141
|
-
return n && !b.has(n) ? n : void 0;
|
|
142
|
-
}
|
|
143
|
-
function z(t) {
|
|
144
|
-
const e = {};
|
|
145
|
-
return f(t, (r, n, i) => {
|
|
146
|
-
if (i !== "text")
|
|
147
|
-
return;
|
|
148
|
-
const o = X(r);
|
|
149
|
-
o && (e[n] = o);
|
|
150
|
-
}), e;
|
|
151
|
-
}
|
|
152
|
-
function Q(t) {
|
|
153
|
-
const e = {};
|
|
154
|
-
return f(t, (r, n, i) => {
|
|
155
|
-
if (i === "image")
|
|
156
|
-
return;
|
|
157
|
-
const o = l(r) ? r.getAttribute("align") : null;
|
|
158
|
-
o && (e[n] = o);
|
|
159
|
-
}), e;
|
|
160
|
-
}
|
|
161
|
-
const V = /^es-[pm]\d+[trbl]?$/;
|
|
162
|
-
function W(t) {
|
|
163
|
-
const e = l(t) ? t.getAttribute("class") : null;
|
|
164
|
-
if (!e)
|
|
165
|
-
return;
|
|
166
|
-
const r = e.split(/\s+/).filter((n) => V.test(n) || n === B);
|
|
167
|
-
return r.length ? r.join(" ") : void 0;
|
|
168
|
-
}
|
|
169
|
-
function Y(t) {
|
|
170
|
-
const e = {};
|
|
171
|
-
return f(t, (r, n, i) => {
|
|
172
|
-
if (i === "image")
|
|
173
|
-
return;
|
|
174
|
-
const o = W(r);
|
|
175
|
-
o && (e[n] = o);
|
|
176
|
-
}), e;
|
|
177
|
-
}
|
|
178
|
-
function J(t) {
|
|
179
|
-
const e = {};
|
|
180
|
-
return f(t, (r, n) => {
|
|
181
|
-
if (n !== y && n !== m || !l(r))
|
|
182
|
-
return;
|
|
183
|
-
const i = r.getAttribute("data-text-before"), o = r.getAttribute("data-text-after");
|
|
184
|
-
(i != null || o != null) && (e[n] = { before: i ?? void 0, after: o ?? void 0 });
|
|
185
|
-
}), e;
|
|
186
|
-
}
|
|
187
|
-
function Z(t) {
|
|
188
|
-
const e = {};
|
|
189
|
-
if (!t || !("querySelector" in t))
|
|
190
|
-
return e;
|
|
191
|
-
const r = t.querySelector(S) ?? t;
|
|
192
|
-
return A(r) && r.querySelectorAll(".recommendation-attribute-row").forEach((n) => {
|
|
193
|
-
if (!l(n))
|
|
194
|
-
return;
|
|
195
|
-
const i = n.getAttribute("data-attribute-type"), o = n.getAttribute("data-visibility");
|
|
196
|
-
i && o != null && (e[i] = o !== "0");
|
|
197
|
-
}), e;
|
|
198
|
-
}
|
|
199
|
-
function ut(t) {
|
|
200
|
-
return {
|
|
201
|
-
styleTemplates: F(t),
|
|
202
|
-
cardBackgroundColor: j(t),
|
|
203
|
-
cellBackgroundColors: z(t),
|
|
204
|
-
cellAlignments: Q(t),
|
|
205
|
-
cellClasses: Y(t),
|
|
206
|
-
omnibusTexts: J(t),
|
|
207
|
-
visibility: Z(t)
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
export {
|
|
211
|
-
F as captureAttributeStyleTemplates,
|
|
212
|
-
j as captureCardBackgroundColor,
|
|
213
|
-
Q as captureCellAlignments,
|
|
214
|
-
z as captureCellBackgroundColors,
|
|
215
|
-
Y as captureCellClasses,
|
|
216
|
-
J as captureOmnibusTexts,
|
|
217
|
-
ut as captureStyles,
|
|
218
|
-
Z as captureVisibility
|
|
219
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Capture Style Templates
|
|
3
|
-
*
|
|
4
|
-
* Reads the user-applied styling of each text attribute from the LIVE block DOM
|
|
5
|
-
* and turns it into per-attribute `AttributeStyleTemplate`s that the template
|
|
6
|
-
* renderers bake straight into regenerated HTML.
|
|
7
|
-
*
|
|
8
|
-
* Why this exists: a full regeneration replaces product cells via `setInnerHtml`.
|
|
9
|
-
* Querying the new cells to re-apply styles after `apply()` requires a second
|
|
10
|
-
* (deferred) commit, and multiple commits corrupt Stripo's selection tracking
|
|
11
|
-
* (the `textContent` crash). Baking the captured styles into the HTML keeps the
|
|
12
|
-
* whole regeneration a SINGLE `setInnerHtml` + SINGLE `apply()`.
|
|
13
|
-
*
|
|
14
|
-
* Inline formats (bold/italic/strike) are captured as TAGS (`<strong>/<em>/<s>`),
|
|
15
|
-
* not CSS, because Stripo applies and detects them as tags — re-emitting
|
|
16
|
-
* `text-decoration` CSS would render a strike its own toggle can't see.
|
|
17
|
-
*/
|
|
18
|
-
import type { AttributeStyleTemplates, OmnibusText, RenderOptions } from '../templates/utils';
|
|
19
|
-
import type { ImmutableHtmlNode } from '@stripoinc/ui-editor-extensions';
|
|
20
|
-
/**
|
|
21
|
-
* Captures per-attribute style templates (text + button + image) from the block's desktop
|
|
22
|
-
* container. Scoped to desktop so the mobile container's duplicate block ids aren't read.
|
|
23
|
-
* Returns only the attributes that actually have styling worth preserving.
|
|
24
|
-
*/
|
|
25
|
-
export declare function captureAttributeStyleTemplates(node: ImmutableHtmlNode | null | undefined): AttributeStyleTemplates;
|
|
26
|
-
/**
|
|
27
|
-
* Captures the card background color (the "Styles" tab control) from the first card
|
|
28
|
-
* container — `.product-card-segment` in grid, `.product-card-wrapper` in list. Returns
|
|
29
|
-
* undefined when unset/transparent so the renderer keeps its (bg-less) default.
|
|
30
|
-
*/
|
|
31
|
-
export declare function captureCardBackgroundColor(node: ImmutableHtmlNode | null | undefined): string | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* Captures each text attribute's "Block Background Color" (Styles tab) from the block's
|
|
34
|
-
* desktop container, keyed by composition key. The renderers bake these
|
|
35
|
-
* straight onto the regenerated `[esd-extension-block-id]` cell so the bg survives a full
|
|
36
|
-
* regeneration — unlike the card background, the text-cell bg lives on the attribute cell
|
|
37
|
-
* itself and is only readable via `getComputedStyle` (see `readCellBackground`). Returns
|
|
38
|
-
* only the attributes that actually carry a non-transparent background.
|
|
39
|
-
*/
|
|
40
|
-
export declare function captureCellBackgroundColors(node: ImmutableHtmlNode | null | undefined): Record<string, string>;
|
|
41
|
-
/**
|
|
42
|
-
* Captures each text attribute's alignment from the cell's `align` attribute, keyed by
|
|
43
|
-
* composition key. Stripo's built-in `TextAlignBuiltInControl` writes the
|
|
44
|
-
* alignment as the `align` HTML attribute on the `[esd-extension-block-id]` cell (not as
|
|
45
|
-
* inline `text-align`), so the renderers' hardcoded `align` would otherwise reset it on
|
|
46
|
-
* every regeneration. We capture the current value and re-bake it.
|
|
47
|
-
*/
|
|
48
|
-
export declare function captureCellAlignments(node: ImmutableHtmlNode | null | undefined): Record<string, string>;
|
|
49
|
-
/**
|
|
50
|
-
* Captures each text/button cell's preservable classes (padding `es-p*`, margin `es-m*`,
|
|
51
|
-
* text-trim) keyed by composition key, so a regeneration can re-bake them
|
|
52
|
-
* instead of resetting to the renderer's hardcoded spacing classes. Stripo stores padding
|
|
53
|
-
* and margin as these classes (NOT inline style), so an inline-style capture misses them.
|
|
54
|
-
*/
|
|
55
|
-
export declare function captureCellClasses(node: ImmutableHtmlNode | null | undefined): Record<string, string>;
|
|
56
|
-
/**
|
|
57
|
-
* Captures the omnibus cells' editable before/after text (from the `data-text-before` /
|
|
58
|
-
* `data-text-after` attributes the omnibus text controls write), keyed by attr, so a
|
|
59
|
-
* regeneration re-bakes the user's wording instead of the renderer's hardcoded prefix.
|
|
60
|
-
*/
|
|
61
|
-
export declare function captureOmnibusTexts(node: ImmutableHtmlNode | null | undefined): Record<string, OmnibusText>;
|
|
62
|
-
/**
|
|
63
|
-
* Captures the current per-attribute visibility from the live block, keyed by composition
|
|
64
|
-
* attribute (`data-attribute-type`). The card-composition control toggles visibility by
|
|
65
|
-
* setting `display`/`data-visibility` on `.recommendation-attribute-row`s, but the renderers
|
|
66
|
-
* re-apply the hardcoded `DEFAULT_CARD_VISIBILITY` on regeneration — so a user who showed
|
|
67
|
-
* omnibus (default-hidden) or hid a row would lose it. Capturing the live `data-visibility`
|
|
68
|
-
* lets the rebuild honor the user's choice.
|
|
69
|
-
*/
|
|
70
|
-
export declare function captureVisibility(node: ImmutableHtmlNode | null | undefined): Record<string, boolean>;
|
|
71
|
-
/**
|
|
72
|
-
* The full bundle of user-applied styling captured from the live block before a
|
|
73
|
-
* regeneration replaces its cells. Threaded as ONE object (not a long positional list)
|
|
74
|
-
* into the rebuild so the regenerated HTML re-bakes every preserved value.
|
|
75
|
-
*/
|
|
76
|
-
export type StyleCaptures = Pick<RenderOptions, 'styleTemplates' | 'cardBackgroundColor' | 'cellBackgroundColors' | 'cellAlignments' | 'cellClasses' | 'omnibusTexts' | 'visibility'>;
|
|
77
|
-
/** Runs every capture against the live node and returns them as a single bundle. */
|
|
78
|
-
export declare function captureStyles(node: ImmutableHtmlNode | null | undefined): StyleCaptures;
|