@useinsider/guido 2.0.0-beta.1c331b8 → 2.0.0-beta.1f72712
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/extensions/Blocks/Recommendation/block.js +40 -6
- package/dist/extensions/Blocks/Recommendation/constants/defaultConfig.js +64 -0
- package/dist/extensions/Blocks/Recommendation/constants/layout.js +9 -4
- package/dist/extensions/Blocks/Recommendation/constants/selectors.js +17 -9
- package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +48 -54
- package/dist/extensions/Blocks/Recommendation/controls/layout/index.js +42 -36
- package/dist/extensions/Blocks/Recommendation/controls/main/algorithm.js +51 -27
- package/dist/extensions/Blocks/Recommendation/controls/main/currency.js +146 -73
- package/dist/extensions/Blocks/Recommendation/controls/main/index.js +49 -35
- package/dist/extensions/Blocks/Recommendation/controls/main/locale.js +23 -13
- package/dist/extensions/Blocks/Recommendation/controls/main/productLayout.js +41 -41
- package/dist/extensions/Blocks/Recommendation/controls/main/shuffle.js +27 -16
- package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +79 -67
- package/dist/extensions/Blocks/Recommendation/controls/omnibusDiscount/textAfter.js +1 -1
- package/dist/extensions/Blocks/Recommendation/controls/omnibusDiscount/textBefore.js +3 -3
- package/dist/extensions/Blocks/Recommendation/controls/spacing/index.js +85 -79
- package/dist/extensions/Blocks/Recommendation/recommendation.css.js +8 -4
- package/dist/extensions/Blocks/Recommendation/services/configService.js +239 -0
- package/dist/extensions/Blocks/Recommendation/store/recommendation.js +30 -28
- package/dist/extensions/Blocks/Recommendation/templates/horizontal/elementRenderer.js +49 -25
- package/dist/extensions/Blocks/Recommendation/templates/horizontal/template.js +18 -19
- package/dist/extensions/Blocks/Recommendation/templates/utils.js +44 -101
- package/dist/extensions/Blocks/Recommendation/templates/vertical/elementRenderer.js +60 -35
- package/dist/extensions/Blocks/Recommendation/types/nodeConfig.js +6 -0
- package/dist/extensions/Blocks/Recommendation/utils/priceFormatter.js +29 -0
- package/dist/extensions/Blocks/Recommendation/utils/tagName.js +46 -0
- package/dist/extensions/Blocks/common-control.js +1 -1
- package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +214 -157
- package/dist/src/components/wrappers/WpDrawer.vue.d.ts +1 -1
- package/dist/src/extensions/Blocks/Recommendation/block.d.ts +34 -0
- package/dist/src/extensions/Blocks/Recommendation/constants/defaultConfig.d.ts +49 -0
- package/dist/src/extensions/Blocks/Recommendation/constants/index.d.ts +3 -2
- package/dist/src/extensions/Blocks/Recommendation/constants/layout.d.ts +10 -0
- package/dist/src/extensions/Blocks/Recommendation/constants/selectors.d.ts +12 -0
- package/dist/src/extensions/Blocks/Recommendation/controls/layout/index.d.ts +3 -1
- package/dist/src/extensions/Blocks/Recommendation/controls/main/algorithm.d.ts +13 -1
- package/dist/src/extensions/Blocks/Recommendation/controls/main/currency.d.ts +30 -1
- package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +19 -0
- package/dist/src/extensions/Blocks/Recommendation/controls/main/locale.d.ts +9 -0
- package/dist/src/extensions/Blocks/Recommendation/controls/main/productLayout.d.ts +4 -2
- package/dist/src/extensions/Blocks/Recommendation/controls/main/shuffle.d.ts +8 -0
- package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.d.ts +19 -0
- package/dist/src/extensions/Blocks/Recommendation/controls/spacing/index.d.ts +13 -2
- package/dist/src/extensions/Blocks/Recommendation/services/configService.d.ts +151 -0
- package/dist/src/extensions/Blocks/Recommendation/services/index.d.ts +6 -0
- package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +1 -0
- package/dist/src/extensions/Blocks/Recommendation/types/index.d.ts +7 -0
- package/dist/src/extensions/Blocks/Recommendation/types/nodeConfig.d.ts +154 -0
- package/dist/src/extensions/Blocks/Recommendation/utils/priceFormatter.d.ts +33 -0
- package/dist/src/extensions/Blocks/Recommendation/utils/stylePreserver.d.ts +113 -0
- package/dist/src/extensions/Blocks/Recommendation/utils/tagName.d.ts +77 -0
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Block as
|
|
2
|
-
import {
|
|
1
|
+
import { Block as o, BlockCompositionType as i } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
2
|
+
import { RecommendationConfigService as t } from "./services/configService.js";
|
|
3
|
+
import { getDefaultTemplate as r } from "./templates/vertical/template.js";
|
|
3
4
|
const n = "recommendation-block";
|
|
4
|
-
class
|
|
5
|
+
class g extends o {
|
|
5
6
|
constructor() {
|
|
6
7
|
super();
|
|
7
8
|
}
|
|
@@ -12,7 +13,7 @@ class m extends e {
|
|
|
12
13
|
return "recommendation-icon";
|
|
13
14
|
}
|
|
14
15
|
getBlockCompositionType() {
|
|
15
|
-
return
|
|
16
|
+
return i.CONTAINER;
|
|
16
17
|
}
|
|
17
18
|
getName() {
|
|
18
19
|
return this.api.translate("Recommendation Block");
|
|
@@ -21,10 +22,43 @@ class m extends e {
|
|
|
21
22
|
return this.api.translate("Recommendation Block Title Description");
|
|
22
23
|
}
|
|
23
24
|
getTemplate() {
|
|
24
|
-
return
|
|
25
|
+
return r();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Called when a new block is dropped into the template
|
|
29
|
+
*
|
|
30
|
+
* Initializes the block with default configuration stored via node config.
|
|
31
|
+
* This ensures the configuration persists with the template.
|
|
32
|
+
* @param node - The newly created block node
|
|
33
|
+
*/
|
|
34
|
+
onCreated(e) {
|
|
35
|
+
t.initializeConfig(this.api, e);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Called when the document changes or template is loaded
|
|
39
|
+
*
|
|
40
|
+
* Handles migration from legacy templates that don't have node config.
|
|
41
|
+
* Also handles config version upgrades for future migrations.
|
|
42
|
+
* @param node - The block node that may need migration
|
|
43
|
+
*/
|
|
44
|
+
onDocumentChanged(e) {
|
|
45
|
+
!e || !("getNodeConfig" in e) || t.needsMigration(e) && this._migrateFromLegacy(e);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Migrate configuration from legacy format
|
|
49
|
+
*
|
|
50
|
+
* Legacy templates may store configuration in:
|
|
51
|
+
* - data-attributes (data-layout, data-card-composition, etc.)
|
|
52
|
+
* - Pinia store (lost on reload - this is what we're fixing)
|
|
53
|
+
*
|
|
54
|
+
* This method reads what we can from the DOM and initializes proper node config.
|
|
55
|
+
* @param node - The block node to migrate
|
|
56
|
+
*/
|
|
57
|
+
_migrateFromLegacy(e) {
|
|
58
|
+
t.migrateFromDataAttributes(this.api, e);
|
|
25
59
|
}
|
|
26
60
|
}
|
|
27
61
|
export {
|
|
28
62
|
n as BLOCK_ID,
|
|
29
|
-
|
|
63
|
+
g as RecommendationBlock
|
|
30
64
|
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { DEFAULT_ROW_SPACING as s, DEFAULT_COLUMN_SPACING as R, DEFAULT_CARDS_IN_ROW as n } from "./layout.js";
|
|
2
|
+
import { ATTR_PRODUCT_IMAGE as t, ATTR_PRODUCT_NAME as e, ATTR_PRODUCT_OLD_PRICE as T, ATTR_PRODUCT_PRICE as o, ATTR_PRODUCT_OMNIBUS_PRICE as _, ATTR_PRODUCT_OMNIBUS_DISCOUNT as r, ATTR_PRODUCT_BUTTON as U } from "./selectors.js";
|
|
3
|
+
const I = {
|
|
4
|
+
code: "USD",
|
|
5
|
+
symbol: "USD",
|
|
6
|
+
alignment: "after",
|
|
7
|
+
decimalCount: 2,
|
|
8
|
+
decimalSeparator: ".",
|
|
9
|
+
thousandSeparator: ","
|
|
10
|
+
}, O = {
|
|
11
|
+
textBefore: "",
|
|
12
|
+
textAfter: ""
|
|
13
|
+
}, i = {
|
|
14
|
+
textBefore: "",
|
|
15
|
+
textAfter: ""
|
|
16
|
+
}, C = [
|
|
17
|
+
t,
|
|
18
|
+
e,
|
|
19
|
+
T,
|
|
20
|
+
o,
|
|
21
|
+
_,
|
|
22
|
+
r,
|
|
23
|
+
U
|
|
24
|
+
], D = {
|
|
25
|
+
[t]: !0,
|
|
26
|
+
[e]: !0,
|
|
27
|
+
[o]: !0,
|
|
28
|
+
[T]: !0,
|
|
29
|
+
[_]: !1,
|
|
30
|
+
[r]: !1,
|
|
31
|
+
[U]: !0
|
|
32
|
+
}, a = {
|
|
33
|
+
// Settings
|
|
34
|
+
strategy: "mostPopular",
|
|
35
|
+
productIds: [],
|
|
36
|
+
size: "6",
|
|
37
|
+
shuffleProducts: !1,
|
|
38
|
+
language: "en_US",
|
|
39
|
+
currency: I,
|
|
40
|
+
filters: [],
|
|
41
|
+
// Layout
|
|
42
|
+
layout: "vertical",
|
|
43
|
+
cardsInRow: n,
|
|
44
|
+
columnSpacing: R,
|
|
45
|
+
rowSpacing: s,
|
|
46
|
+
// Composition
|
|
47
|
+
composition: C,
|
|
48
|
+
visibility: D,
|
|
49
|
+
// Element settings
|
|
50
|
+
omnibusPrice: O,
|
|
51
|
+
omnibusDiscount: i,
|
|
52
|
+
textTrimming: !1,
|
|
53
|
+
// Meta
|
|
54
|
+
configVersion: 1
|
|
55
|
+
}, E = 1;
|
|
56
|
+
export {
|
|
57
|
+
E as CURRENT_CONFIG_VERSION,
|
|
58
|
+
C as DEFAULT_COMPOSITION,
|
|
59
|
+
I as DEFAULT_CURRENCY,
|
|
60
|
+
a as DEFAULT_NODE_CONFIG,
|
|
61
|
+
i as DEFAULT_OMNIBUS_DISCOUNT,
|
|
62
|
+
O as DEFAULT_OMNIBUS_PRICE,
|
|
63
|
+
D as DEFAULT_VISIBILITY
|
|
64
|
+
};
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
const _ = 3,
|
|
1
|
+
const _ = 3, A = 3, C = 9, P = 4, o = 10, t = 20, R = 0, c = 50, n = 5;
|
|
2
2
|
export {
|
|
3
|
-
|
|
3
|
+
A as DEFAULT_CARDS_IN_ROW,
|
|
4
|
+
o as DEFAULT_COLUMN_SPACING,
|
|
4
5
|
_ as DEFAULT_PRODUCTS_PER_ROW,
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
t as DEFAULT_ROW_SPACING,
|
|
7
|
+
P as MAX_PRODUCTS_PER_ROW,
|
|
8
|
+
C as MAX_PRODUCT_COUNT,
|
|
9
|
+
c as MAX_SPACING,
|
|
10
|
+
R as MIN_SPACING,
|
|
11
|
+
n as SPACING_STEP
|
|
7
12
|
};
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
const
|
|
1
|
+
const c = ".ins-recommendation-product-container", T = {
|
|
2
|
+
CURRENCY: "currency",
|
|
3
|
+
SYMBOL: "currency-symbol",
|
|
4
|
+
ALIGNMENT: "currency-alignment",
|
|
5
|
+
THOUSAND_SEPARATOR: "currency-thousand-separator",
|
|
6
|
+
DECIMAL_SEPARATOR: "currency-decimal-separator",
|
|
7
|
+
DECIMAL_COUNT: "currency-decimal-count"
|
|
8
|
+
}, r = "productImage", n = "productName", o = "productPrice", t = "productOldPrice", R = "productOmnibusPrice", O = "productOmnibusDiscount", _ = "productButton";
|
|
2
9
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
_ as ATTR_PRODUCT_BUTTON,
|
|
11
|
+
r as ATTR_PRODUCT_IMAGE,
|
|
12
|
+
n as ATTR_PRODUCT_NAME,
|
|
13
|
+
t as ATTR_PRODUCT_OLD_PRICE,
|
|
14
|
+
O as ATTR_PRODUCT_OMNIBUS_DISCOUNT,
|
|
15
|
+
R as ATTR_PRODUCT_OMNIBUS_PRICE,
|
|
16
|
+
o as ATTR_PRODUCT_PRICE,
|
|
17
|
+
c as CONTAINER_SELECTOR,
|
|
18
|
+
T as CURRENCY_ATTR
|
|
11
19
|
};
|
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { ModificationDescription as
|
|
5
|
-
import { CommonControl as
|
|
6
|
-
import { ATTR_PRODUCT_IMAGE as
|
|
7
|
-
import { useRecommendationExtensionStore as
|
|
1
|
+
var T = Object.defineProperty;
|
|
2
|
+
var C = (a, n, t) => n in a ? T(a, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[n] = t;
|
|
3
|
+
var l = (a, n, t) => C(a, typeof n != "symbol" ? n + "" : n, t);
|
|
4
|
+
import { ModificationDescription as u } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
5
|
+
import { CommonControl as f } from "../../../common-control.js";
|
|
6
|
+
import { ATTR_PRODUCT_IMAGE as O, ATTR_PRODUCT_NAME as g, ATTR_PRODUCT_PRICE as R, ATTR_PRODUCT_OLD_PRICE as A, ATTR_PRODUCT_OMNIBUS_PRICE as D, ATTR_PRODUCT_OMNIBUS_DISCOUNT as N, ATTR_PRODUCT_BUTTON as V } from "../../constants/selectors.js";
|
|
7
|
+
import { useRecommendationExtensionStore as E } from "../../store/recommendation.js";
|
|
8
|
+
import { getTableDisplayValue as I } from "../../utils/tagName.js";
|
|
8
9
|
import { getCurrentLayout as P } from "../main/utils.js";
|
|
9
10
|
const S = "ui-elements-recommendation-card-composition", k = {
|
|
10
11
|
ORDERABLE: "cardComposition"
|
|
11
|
-
},
|
|
12
|
-
{ key:
|
|
13
|
-
{ key:
|
|
14
|
-
{ key:
|
|
15
|
-
{ key:
|
|
12
|
+
}, c = ".recommendation-attribute-row", v = ".product-card-wrapper > tbody", _ = "data-card-composition", d = "data-attribute-type", m = "data-visibility", s = [
|
|
13
|
+
{ key: O, label: "Product Image", visible: !0 },
|
|
14
|
+
{ key: g, label: "Product Name", visible: !0 },
|
|
15
|
+
{ key: R, label: "Product Price", visible: !0 },
|
|
16
|
+
{ key: A, label: "Product Original Price", visible: !0 },
|
|
16
17
|
{ key: D, label: "Omnibus Price", visible: !1 },
|
|
17
|
-
{ key:
|
|
18
|
-
{ key:
|
|
18
|
+
{ key: N, label: "Omnibus Discount", visible: !1 },
|
|
19
|
+
{ key: V, label: "Product Button", visible: !0 }
|
|
19
20
|
];
|
|
20
|
-
class
|
|
21
|
+
class H extends f {
|
|
21
22
|
constructor() {
|
|
22
23
|
super(...arguments);
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
l(this, "store", E());
|
|
25
|
+
l(this, "unsubscribeOrientation", null);
|
|
25
26
|
}
|
|
26
27
|
getId() {
|
|
27
28
|
return S;
|
|
28
29
|
}
|
|
29
30
|
getTemplate() {
|
|
30
|
-
const t =
|
|
31
|
+
const t = s.map((e) => ({
|
|
31
32
|
key: e.key,
|
|
32
33
|
label: e.label,
|
|
33
34
|
content: this._createItemContent(e.label, e.key)
|
|
@@ -63,7 +64,7 @@ class q extends O {
|
|
|
63
64
|
_registerValueChangeListeners() {
|
|
64
65
|
this.api.onValueChanged("cardComposition", (t) => {
|
|
65
66
|
this._applyCompositionToBlock(t);
|
|
66
|
-
}),
|
|
67
|
+
}), s.forEach((t) => {
|
|
67
68
|
this.api.onValueChanged(`visibility_${t.key}`, (e) => {
|
|
68
69
|
this._applyVisibilityToBlock(t.key, e);
|
|
69
70
|
});
|
|
@@ -85,15 +86,15 @@ class q extends O {
|
|
|
85
86
|
*/
|
|
86
87
|
_readCompositionFromNode() {
|
|
87
88
|
if (!this.currentNode || !("getAttribute" in this.currentNode))
|
|
88
|
-
return
|
|
89
|
-
const t = this.currentNode.getAttribute(
|
|
90
|
-
return t ? t.split(",").filter(Boolean) :
|
|
89
|
+
return s.map((e) => e.key);
|
|
90
|
+
const t = this.currentNode.getAttribute(_);
|
|
91
|
+
return t ? t.split(",").filter(Boolean) : s.map((e) => e.key);
|
|
91
92
|
}
|
|
92
93
|
/**
|
|
93
94
|
* Builds visibility values object from the visibility map
|
|
94
95
|
*/
|
|
95
96
|
_buildVisibilityValues(t) {
|
|
96
|
-
return
|
|
97
|
+
return s.reduce((e, i) => (e[`visibility_${i.key}`] = t[i.key] ?? !0, e), {});
|
|
97
98
|
}
|
|
98
99
|
/**
|
|
99
100
|
* Read visibility state from individual row elements' data-visibility attributes
|
|
@@ -102,14 +103,14 @@ class q extends O {
|
|
|
102
103
|
_readVisibilityFromRows() {
|
|
103
104
|
if (!this.currentNode)
|
|
104
105
|
return this._getDefaultVisibilities();
|
|
105
|
-
const t = Array.from(this.currentNode.querySelectorAll(
|
|
106
|
+
const t = Array.from(this.currentNode.querySelectorAll(c)), e = this._extractVisibilityFromRows(t);
|
|
106
107
|
return this._mergeWithDefaults(e);
|
|
107
108
|
}
|
|
108
109
|
/**
|
|
109
110
|
* Returns default visibility values for all items
|
|
110
111
|
*/
|
|
111
112
|
_getDefaultVisibilities() {
|
|
112
|
-
return
|
|
113
|
+
return s.reduce((t, e) => (t[e.key] = e.visible, t), {});
|
|
113
114
|
}
|
|
114
115
|
/**
|
|
115
116
|
* Extracts visibility values from DOM nodes
|
|
@@ -119,8 +120,8 @@ class q extends O {
|
|
|
119
120
|
return t.forEach((i) => {
|
|
120
121
|
if (!("getAttribute" in i))
|
|
121
122
|
return;
|
|
122
|
-
const
|
|
123
|
-
|
|
123
|
+
const o = i.getAttribute(d), r = i.getAttribute(m);
|
|
124
|
+
o && r !== null && (e[o] = this._parseVisibilityValue(r));
|
|
124
125
|
}), e;
|
|
125
126
|
}
|
|
126
127
|
/**
|
|
@@ -134,7 +135,7 @@ class q extends O {
|
|
|
134
135
|
* Merges extracted visibilities with default values for missing keys
|
|
135
136
|
*/
|
|
136
137
|
_mergeWithDefaults(t) {
|
|
137
|
-
return
|
|
138
|
+
return s.forEach((e) => {
|
|
138
139
|
e.key in t || (t[e.key] = e.visible);
|
|
139
140
|
}), t;
|
|
140
141
|
}
|
|
@@ -147,7 +148,7 @@ class q extends O {
|
|
|
147
148
|
if (!this.currentNode)
|
|
148
149
|
return;
|
|
149
150
|
const e = this._getCurrentLayout();
|
|
150
|
-
this.api.getDocumentModifier().modifyHtml(this.currentNode).setAttribute(
|
|
151
|
+
this.api.getDocumentModifier().modifyHtml(this.currentNode).setAttribute(_, t.join(",")).apply(new u("Update card composition")), e === "vertical" && this._reorderProductAttributes(t);
|
|
151
152
|
}
|
|
152
153
|
/**
|
|
153
154
|
* Reorders attribute rows within each product card based on composition order
|
|
@@ -160,18 +161,18 @@ class q extends O {
|
|
|
160
161
|
if (!(e != null && e.length))
|
|
161
162
|
return;
|
|
162
163
|
const i = this.api.getDocumentModifier();
|
|
163
|
-
e.forEach((
|
|
164
|
-
const
|
|
165
|
-
i.modifyHtml(
|
|
166
|
-
}), i.apply(new
|
|
164
|
+
e.forEach((o) => {
|
|
165
|
+
const r = this._buildCompositionHtml(o, t);
|
|
166
|
+
i.modifyHtml(o).setInnerHtml(r);
|
|
167
|
+
}), i.apply(new u("Reorder product attributes"));
|
|
167
168
|
}
|
|
168
169
|
/**
|
|
169
170
|
* Builds HTML string with attributes ordered according to composition
|
|
170
171
|
*/
|
|
171
172
|
_buildCompositionHtml(t, e) {
|
|
172
|
-
return e.reduce((i,
|
|
173
|
-
const
|
|
174
|
-
return
|
|
173
|
+
return e.reduce((i, o) => {
|
|
174
|
+
const r = t.querySelector(`${c}[${d}="${o}"]`);
|
|
175
|
+
return r && "getOuterHTML" in r ? i + r.getOuterHTML() : i;
|
|
175
176
|
}, "");
|
|
176
177
|
}
|
|
177
178
|
/**
|
|
@@ -183,21 +184,14 @@ class q extends O {
|
|
|
183
184
|
_applyVisibilityToBlock(t, e) {
|
|
184
185
|
if (!this.currentNode)
|
|
185
186
|
return;
|
|
186
|
-
const i = this.currentNode.querySelectorAll(`${
|
|
187
|
+
const i = this.currentNode.querySelectorAll(`${c}[${d}="${t}"]`);
|
|
187
188
|
if (!(i != null && i.length))
|
|
188
189
|
return;
|
|
189
|
-
const
|
|
190
|
-
i.forEach((
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
else if ("getTagName" in l) {
|
|
195
|
-
const _ = l;
|
|
196
|
-
typeof _.getTagName == "function" && (u = _.getTagName().toUpperCase());
|
|
197
|
-
}
|
|
198
|
-
const h = e ? u === "TD" || u === "BLOCK_IMAGE" || u === "BLOCK_BUTTON" ? "table-cell" : "table-row" : "none";
|
|
199
|
-
m.modifyHtml(l).setStyle("display", h).setAttribute(y, r);
|
|
200
|
-
}), m.apply(new d(o));
|
|
190
|
+
const o = e ? "1" : "0", r = `Set ${t} visibility to ${e ? "visible" : "hidden"}`, b = this.api.getDocumentModifier();
|
|
191
|
+
i.forEach((p) => {
|
|
192
|
+
const y = I(p), h = e ? y : "none";
|
|
193
|
+
b.modifyHtml(p).setStyle("display", h).setAttribute(m, o);
|
|
194
|
+
}), b.apply(new u(r));
|
|
201
195
|
}
|
|
202
196
|
/**
|
|
203
197
|
* Gets the current layout orientation from store or DOM
|
|
@@ -213,11 +207,11 @@ class q extends O {
|
|
|
213
207
|
const e = this._getCurrentLayout() === "horizontal", i = this.getContainer();
|
|
214
208
|
if (!i)
|
|
215
209
|
return;
|
|
216
|
-
const
|
|
217
|
-
if (!
|
|
210
|
+
const o = i.querySelector("[data-card-composition-control]");
|
|
211
|
+
if (!o)
|
|
218
212
|
return;
|
|
219
|
-
const
|
|
220
|
-
|
|
213
|
+
const r = o.querySelector("ue-orderable");
|
|
214
|
+
r && r.classList.toggle("orderable-disabled", e);
|
|
221
215
|
}
|
|
222
216
|
/**
|
|
223
217
|
* Subscribe to store orientation changes
|
|
@@ -234,5 +228,5 @@ class q extends O {
|
|
|
234
228
|
}
|
|
235
229
|
export {
|
|
236
230
|
S as COMPOSITION_CONTROL_BLOCK_ID,
|
|
237
|
-
|
|
231
|
+
H as RecommendationCardCompositionControl
|
|
238
232
|
};
|
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
var
|
|
2
|
-
var p = (e, o, t) => o in e ?
|
|
3
|
-
var
|
|
4
|
-
import { ModificationDescription as
|
|
5
|
-
import { CommonControl as
|
|
1
|
+
var g = Object.defineProperty;
|
|
2
|
+
var p = (e, o, t) => o in e ? g(e, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[o] = t;
|
|
3
|
+
var s = (e, o, t) => p(e, typeof o != "symbol" ? o + "" : o, t);
|
|
4
|
+
import { ModificationDescription as c } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
5
|
+
import { CommonControl as f } from "../../../common-control.js";
|
|
6
6
|
import { CONTAINER_SELECTOR as C } from "../../constants/selectors.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
7
|
+
import { RecommendationConfigService as i } from "../../services/configService.js";
|
|
8
|
+
import { useRecommendationExtensionStore as L } from "../../store/recommendation.js";
|
|
9
|
+
import { prepareProductRows as y } from "../../templates/index.js";
|
|
10
|
+
import { getCurrentLayout as d, getBlockElement as N, getCurrentCardBackgroundColor as T, getCardComposition as _, applyCardBackgroundColor as O } from "../main/utils.js";
|
|
11
|
+
import { getDefaultProducts as R } from "../../templates/utils.js";
|
|
12
|
+
const A = "recommendation-layout-control", a = {
|
|
12
13
|
LAYOUT: "layout"
|
|
13
|
-
},
|
|
14
|
+
}, U = {
|
|
14
15
|
LAYOUT: "data-layout"
|
|
15
|
-
},
|
|
16
|
+
}, w = [
|
|
16
17
|
{ text: "Vertical", value: "vertical" },
|
|
17
18
|
{ text: "Horizontal", value: "horizontal" }
|
|
18
19
|
];
|
|
19
|
-
class
|
|
20
|
+
class V extends f {
|
|
20
21
|
constructor() {
|
|
21
22
|
super(...arguments);
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
s(this, "store", L());
|
|
24
|
+
s(this, "isChangingLayout", !1);
|
|
24
25
|
}
|
|
25
26
|
getId() {
|
|
26
|
-
return
|
|
27
|
+
return A;
|
|
27
28
|
}
|
|
28
29
|
getTemplate() {
|
|
29
30
|
return `
|
|
@@ -31,8 +32,8 @@ class I extends g {
|
|
|
31
32
|
${this._GuTwoColumns([
|
|
32
33
|
this._GuLabel({ text: "Layout Orientation" }),
|
|
33
34
|
this._GuRadioButton({
|
|
34
|
-
name:
|
|
35
|
-
buttons:
|
|
35
|
+
name: a.LAYOUT,
|
|
36
|
+
buttons: w
|
|
36
37
|
})
|
|
37
38
|
])}
|
|
38
39
|
</div>
|
|
@@ -45,27 +46,32 @@ class I extends g {
|
|
|
45
46
|
super.onTemplateNodeUpdated(t), this._setFormValues();
|
|
46
47
|
}
|
|
47
48
|
_setFormValues() {
|
|
48
|
-
const
|
|
49
|
+
const r = i.getConfig(this.currentNode).layout || d(this.currentNode);
|
|
49
50
|
this.api.updateValues({
|
|
50
|
-
[
|
|
51
|
+
[a.LAYOUT]: r
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
54
|
/**
|
|
54
55
|
* Handles layout change
|
|
55
|
-
* Updates
|
|
56
|
+
* Updates node config, data attribute and regenerates product rows
|
|
56
57
|
*/
|
|
57
58
|
_onLayoutChange(t) {
|
|
58
|
-
if (this.isChangingLayout ||
|
|
59
|
+
if (this.isChangingLayout || !this.currentNode || (i.getConfig(this.currentNode).layout || d(this.currentNode)) === t)
|
|
59
60
|
return;
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
61
|
+
const n = N(this.currentNode);
|
|
62
|
+
if (n) {
|
|
62
63
|
this.isChangingLayout = !0;
|
|
63
64
|
try {
|
|
64
|
-
|
|
65
|
+
i.updateConfig(
|
|
66
|
+
this.api,
|
|
67
|
+
this.currentNode,
|
|
68
|
+
{ layout: t },
|
|
69
|
+
`Changed layout to ${t}`
|
|
70
|
+
), this.store.$patch({
|
|
65
71
|
recommendationConfigs: {
|
|
66
72
|
orientation: t
|
|
67
73
|
}
|
|
68
|
-
}), this.api.getDocumentModifier().modifyHtml(
|
|
74
|
+
}), this.api.getDocumentModifier().modifyHtml(n).setAttribute(U.LAYOUT, t).apply(new c(`Update layout to ${t}`)), this._regenerateProductRows(t);
|
|
69
75
|
} finally {
|
|
70
76
|
this.isChangingLayout = !1;
|
|
71
77
|
}
|
|
@@ -78,27 +84,27 @@ class I extends g {
|
|
|
78
84
|
_regenerateProductRows(t) {
|
|
79
85
|
if (!this.currentNode || !("querySelector" in this.currentNode))
|
|
80
86
|
return;
|
|
81
|
-
const
|
|
82
|
-
if (!
|
|
87
|
+
const r = this.currentNode.querySelector(C);
|
|
88
|
+
if (!r)
|
|
83
89
|
return;
|
|
84
|
-
const
|
|
85
|
-
productsPerRow:
|
|
86
|
-
composition:
|
|
90
|
+
const u = T(this.currentNode), n = this.store.recommendationProducts.length > 0 ? this.store.recommendationProducts : R(), m = i.getConfig(this.currentNode), l = _(this.currentNode), h = y(n, t, {
|
|
91
|
+
productsPerRow: m.cardsInRow,
|
|
92
|
+
composition: l
|
|
87
93
|
});
|
|
88
|
-
this.api.getDocumentModifier().modifyHtml(
|
|
94
|
+
this.api.getDocumentModifier().modifyHtml(r).setInnerHtml(h).apply(new c(`Regenerated products for ${t} layout`)), O({
|
|
89
95
|
currentNode: this.currentNode,
|
|
90
96
|
documentModifier: this.api.getDocumentModifier(),
|
|
91
|
-
bgColor:
|
|
97
|
+
bgColor: u,
|
|
92
98
|
layout: t
|
|
93
99
|
});
|
|
94
100
|
}
|
|
95
101
|
_listenToFormUpdates() {
|
|
96
|
-
this.api.onValueChanged(
|
|
102
|
+
this.api.onValueChanged(a.LAYOUT, (t) => {
|
|
97
103
|
this._onLayoutChange(t);
|
|
98
104
|
});
|
|
99
105
|
}
|
|
100
106
|
}
|
|
101
107
|
export {
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
A as LAYOUT_CONTROL_ID,
|
|
109
|
+
V as LayoutControl
|
|
104
110
|
};
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { UEAttr as
|
|
5
|
-
import { CommonControl as
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
var d = Object.defineProperty;
|
|
2
|
+
var c = (o, i, t) => i in o ? d(o, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[i] = t;
|
|
3
|
+
var a = (o, i, t) => c(o, typeof i != "symbol" ? i + "" : i, t);
|
|
4
|
+
import { UEAttr as h } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
5
|
+
import { CommonControl as l } from "../../../common-control.js";
|
|
6
|
+
import { RecommendationConfigService as n } from "../../services/configService.js";
|
|
7
|
+
import { useRecommendationExtensionStore as m } from "../../store/recommendation.js";
|
|
8
|
+
const g = "recommendation-algorithm-control", e = {
|
|
8
9
|
ALGORITHM: "strategy",
|
|
9
10
|
PRODUCT_IDS: "productIds"
|
|
10
11
|
};
|
|
11
|
-
class
|
|
12
|
+
class T extends l {
|
|
12
13
|
constructor() {
|
|
13
14
|
super(...arguments);
|
|
14
|
-
|
|
15
|
+
// Store is used ONLY for API-fetched data (algorithms list), not for config
|
|
16
|
+
a(this, "store", m());
|
|
15
17
|
}
|
|
16
18
|
getId() {
|
|
17
|
-
return
|
|
19
|
+
return g;
|
|
18
20
|
}
|
|
19
21
|
getTemplate() {
|
|
20
22
|
return `
|
|
@@ -39,36 +41,58 @@ class _ extends m {
|
|
|
39
41
|
onRender() {
|
|
40
42
|
this._initializeSelectItems(), this._setFormValues(), this._listenToFormUpdates();
|
|
41
43
|
}
|
|
44
|
+
onTemplateNodeUpdated(t) {
|
|
45
|
+
super.onTemplateNodeUpdated(t), this._setFormValues();
|
|
46
|
+
}
|
|
42
47
|
_setFormValues() {
|
|
43
|
-
const
|
|
44
|
-
this._setProductIdsVisibility(), this.api.updateValues({
|
|
48
|
+
const t = n.getConfig(this.currentNode);
|
|
49
|
+
this._setProductIdsVisibility(t.strategy), this.api.updateValues({
|
|
45
50
|
[e.ALGORITHM]: t.strategy,
|
|
46
51
|
[e.PRODUCT_IDS]: t.productIds.join(",")
|
|
47
52
|
});
|
|
48
53
|
}
|
|
49
54
|
_initializeSelectItems() {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
var s;
|
|
56
|
+
const t = (s = this.store) == null ? void 0 : s.getActivePredictiveAlgorithms;
|
|
57
|
+
if (t != null && t.length)
|
|
58
|
+
try {
|
|
59
|
+
this.api.setUIEAttribute(
|
|
60
|
+
e.ALGORITHM,
|
|
61
|
+
h.SELECTPICKER.items,
|
|
62
|
+
t
|
|
63
|
+
);
|
|
64
|
+
} catch (r) {
|
|
65
|
+
console.warn("[AlgorithmControl] Failed to set algorithm options:", r);
|
|
66
|
+
}
|
|
55
67
|
}
|
|
56
|
-
_setProductIdsVisibility() {
|
|
57
|
-
const
|
|
58
|
-
this.api.setVisibility(e.PRODUCT_IDS,
|
|
68
|
+
_setProductIdsVisibility(t) {
|
|
69
|
+
const r = (t ?? n.getConfig(this.currentNode).strategy) === "manualMerchandising";
|
|
70
|
+
this.api.setVisibility(e.PRODUCT_IDS, r), this.api.setVisibility(`${e.PRODUCT_IDS}_label`, r);
|
|
59
71
|
}
|
|
60
72
|
_onAlgorithmChange(t) {
|
|
61
|
-
this.
|
|
73
|
+
this.currentNode && (n.updateConfig(
|
|
74
|
+
this.api,
|
|
75
|
+
this.currentNode,
|
|
76
|
+
{ strategy: t },
|
|
77
|
+
`Changed algorithm to ${t}`
|
|
78
|
+
), this.store.$patch({
|
|
62
79
|
recommendationConfigs: {
|
|
63
80
|
strategy: t
|
|
64
81
|
}
|
|
65
|
-
}), this._setProductIdsVisibility();
|
|
82
|
+
}), this._setProductIdsVisibility(t));
|
|
66
83
|
}
|
|
67
84
|
_onProductIdsChange(t) {
|
|
68
|
-
|
|
69
|
-
|
|
85
|
+
if (!this.currentNode)
|
|
86
|
+
return;
|
|
87
|
+
const s = t.split(",").map((r) => r.trim()).filter(Boolean);
|
|
88
|
+
n.updateConfig(
|
|
89
|
+
this.api,
|
|
90
|
+
this.currentNode,
|
|
91
|
+
{ productIds: s },
|
|
92
|
+
"Updated product IDs"
|
|
93
|
+
), this.store.$patch({
|
|
70
94
|
recommendationConfigs: {
|
|
71
|
-
productIds:
|
|
95
|
+
productIds: s
|
|
72
96
|
}
|
|
73
97
|
});
|
|
74
98
|
}
|
|
@@ -81,6 +105,6 @@ class _ extends m {
|
|
|
81
105
|
}
|
|
82
106
|
}
|
|
83
107
|
export {
|
|
84
|
-
|
|
85
|
-
|
|
108
|
+
g as ALGORITHM_CONTROL_ID,
|
|
109
|
+
T as AlgorithmControl
|
|
86
110
|
};
|