@useinsider/guido 3.24.0 → 3.25.0
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 +7 -1
- package/dist/@types/config/schemas.js +9 -7
- package/dist/components/Guido.vue.js +1 -1
- package/dist/components/Guido.vue2.js +79 -77
- package/dist/composables/useActionsApi.js +2 -2
- package/dist/composables/useEditorTrackingIds.js +49 -0
- package/dist/composables/useHtmlCompiler.js +2 -0
- package/dist/composables/useModuleRepair.js +14 -12
- package/dist/composables/useStripo.js +70 -70
- package/dist/config/compiler/htmlCompilerRules.js +14 -6
- 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/blockBackground/index.js +11 -0
- package/dist/extensions/Blocks/Items/controls/price/currencyLocation.js +34 -23
- 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 +135 -0
- package/dist/extensions/Blocks/Items/controls/settingsControl.js +141 -120
- package/dist/extensions/Blocks/Items/enums/controlEnums.js +2 -2
- package/dist/extensions/Blocks/Items/extension.js +15 -13
- package/dist/extensions/Blocks/Items/items.css.js +19 -0
- package/dist/extensions/Blocks/Items/settingsPanel.js +35 -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/controls/main/index.js +10 -8
- package/dist/extensions/Blocks/Recommendation/store/recommendation.js +28 -24
- package/dist/extensions/Blocks/Recommendation/utils/nodeConfigWriter.js +23 -22
- package/dist/extensions/Blocks/Recommendation/utils/priceFormatter.js +1 -0
- package/dist/extensions/Blocks/controlFactories.js +104 -104
- package/dist/guido.css +1 -1
- package/dist/package.json.js +1 -1
- package/dist/services/templateLibraryApi.js +39 -36
- package/dist/src/@types/config/schemas.d.ts +4 -0
- package/dist/src/composables/useConfig.d.ts +2 -0
- package/dist/src/composables/useEditorTrackingIds.d.ts +7 -0
- package/dist/src/composables/useStripo.d.ts +1 -1
- 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/blockBackground/index.d.ts +15 -0
- package/dist/src/extensions/Blocks/Items/controls/priceFormat.d.ts +24 -0
- package/dist/src/extensions/Blocks/Items/controls/settingsControl.d.ts +1 -0
- package/dist/src/extensions/Blocks/Items/enums/controlEnums.d.ts +2 -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 +66 -0
- package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +2 -0
- package/dist/src/extensions/Blocks/Recommendation/utils/priceFormatter.d.ts +12 -0
- package/dist/src/extensions/Blocks/controlFactories.d.ts +1 -1
- package/dist/src/stores/config.d.ts +20 -0
- package/dist/src/utils/itemsCurrencyRepair.d.ts +5 -1
- package/dist/src/utils/linkTrackingIds.d.ts +19 -0
- package/dist/src/utils/trimHrefWhitespace.d.ts +5 -0
- package/dist/utils/itemsCurrencyRepair.js +29 -24
- package/dist/utils/linkTrackingIds.js +82 -48
- package/dist/utils/pairProductVariables.js +119 -99
- package/dist/utils/templatePreparation.js +30 -33
- package/dist/utils/trimHrefWhitespace.js +10 -0
- package/package.json +1 -1
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { useActionsApi as
|
|
2
|
-
import { useBlocksConfig as
|
|
3
|
-
import { useConfig as
|
|
4
|
-
import { useCustomInterfaceAppearance as
|
|
5
|
-
import { useFullStoryBridge as
|
|
6
|
-
import { useModuleRepair as
|
|
7
|
-
import { useStripoEventHandler as
|
|
8
|
-
import { useStripoNotifications as
|
|
9
|
-
import { useToaster as
|
|
10
|
-
import { localePatch as
|
|
1
|
+
import { useActionsApi as N } from "./useActionsApi.js";
|
|
2
|
+
import { useBlocksConfig as j } from "./useBlocksConfig.js";
|
|
3
|
+
import { useConfig as z } from "./useConfig.js";
|
|
4
|
+
import { useCustomInterfaceAppearance as v } from "./useCustomInterfaceAppearance.js";
|
|
5
|
+
import { useFullStoryBridge as $ } from "./useFullStoryBridge.js";
|
|
6
|
+
import { useModuleRepair as G } from "./useModuleRepair.js";
|
|
7
|
+
import { useStripoEventHandler as X } from "./useStripoEventHandler.js";
|
|
8
|
+
import { useStripoNotifications as J } from "./useStripoNotifications.js";
|
|
9
|
+
import { useToaster as K } from "./useToaster.js";
|
|
10
|
+
import { localePatch as Q } from "../config/i18n/index.js";
|
|
11
11
|
import { en as B } from "../config/i18n/en/index.js";
|
|
12
|
-
import { ToasterTypeOptions as
|
|
13
|
-
import { useStripoApi as
|
|
14
|
-
import
|
|
15
|
-
import { useEditorStore as
|
|
16
|
-
import { buildMergeTagEntries as
|
|
17
|
-
import { getStripoRuntimeBaseUrl as
|
|
18
|
-
let d = null,
|
|
19
|
-
const
|
|
20
|
-
const { features: u, template: m, isFeatureEnabled: p } =
|
|
12
|
+
import { ToasterTypeOptions as W } from "../enums/toaster.js";
|
|
13
|
+
import { useStripoApi as Y } from "../services/stripoApi.js";
|
|
14
|
+
import Z from "../static/styles/customEditorStyle.css.js";
|
|
15
|
+
import { useEditorStore as T } from "../stores/editor.js";
|
|
16
|
+
import { buildMergeTagEntries as ee, flattenDynamicContentList as te } from "../utils/genericUtil.js";
|
|
17
|
+
import { getStripoRuntimeBaseUrl as oe } from "../utils/stripoRuntime.js";
|
|
18
|
+
let d = null, F = !1;
|
|
19
|
+
const ke = (t) => {
|
|
20
|
+
const { features: u, template: m, isFeatureEnabled: p } = z(), { handleError: f, showToaster: A } = K(), { getToken: P, getCustomFonts: R, getSyncModulesStatus: U } = Y(), { handleEvent: V } = X(), { handleModuleAdd: D } = G(), { getStripoBlocksConfig: I } = j(), { getStripoNotifications: L } = J(), g = () => d || (d = new Promise((n, a) => {
|
|
21
21
|
if (document.getElementById("UiEditorScript")) {
|
|
22
|
-
|
|
22
|
+
n();
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
-
const i =
|
|
25
|
+
const i = oe();
|
|
26
26
|
if (!i) {
|
|
27
|
-
|
|
27
|
+
a(
|
|
28
28
|
new Error("guido.stripo.version is not set in package.json. Please configure the Stripo version.")
|
|
29
29
|
);
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
}, document.body.appendChild(
|
|
32
|
+
const s = `${i}UIEditor.js`, e = document.createElement("script");
|
|
33
|
+
e.id = "UiEditorScript", e.type = "module", e.src = s, e.onload = () => {
|
|
34
|
+
F = !0, n();
|
|
35
|
+
}, e.onerror = () => {
|
|
36
|
+
e.remove(), a(new Error(`Failed to load Stripo UIEditor script from S3: ${s}`));
|
|
37
|
+
}, document.body.appendChild(e);
|
|
38
38
|
}), d.catch(() => {
|
|
39
39
|
d = null;
|
|
40
|
-
}), d),
|
|
41
|
-
var
|
|
42
|
-
const o =
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
40
|
+
}), d), q = async (n, a, i, s = [], e = !1, c = !1) => {
|
|
41
|
+
var w, k, b, _;
|
|
42
|
+
const o = T(), { html: S, css: y } = n, { baseBlocks: E, extensions: x } = await I();
|
|
43
|
+
t.mark("blocks_config_ready");
|
|
44
|
+
const h = ((w = u.value) == null ? void 0 : w.displayConditions) ?? !0, O = ((k = u.value) == null ? void 0 : k.modulesDisabled) ?? !1, C = c || (((b = m.value) == null ? void 0 : b.forceRecreate) ?? !1), H = "https://email-static.useinsider.com https://edge.fullstory.com https://rs.fullstory.com";
|
|
45
|
+
t.setTemplate({ html: S, css: y, forceRecreate: C }), v().importCss(), t.mark("init_editor"), await window.UIEditor.initEditor(
|
|
46
46
|
document.querySelector("#guido-editor"),
|
|
47
47
|
{
|
|
48
|
-
metadata:
|
|
49
|
-
html:
|
|
50
|
-
css:
|
|
51
|
-
forceRecreate:
|
|
48
|
+
metadata: a,
|
|
49
|
+
html: S,
|
|
50
|
+
css: y,
|
|
51
|
+
forceRecreate: C,
|
|
52
52
|
locale: "en",
|
|
53
53
|
undoButtonSelector: "#guido__undo-button",
|
|
54
54
|
redoButtonSelector: "#guido__redo-button",
|
|
@@ -58,12 +58,12 @@ const we = (e) => {
|
|
|
58
58
|
customAppearanceMergetags: !p("liquidSyntax"),
|
|
59
59
|
customAppearanceMergetagsBorderColor: "#f1f3fe",
|
|
60
60
|
customAppearanceMergetagsBackgroundColor: "#f1f3fe",
|
|
61
|
-
customViewStyles:
|
|
62
|
-
conditionsEnabled:
|
|
63
|
-
customConditionsEnabled:
|
|
61
|
+
customViewStyles: Z,
|
|
62
|
+
conditionsEnabled: h,
|
|
63
|
+
customConditionsEnabled: h,
|
|
64
64
|
enableXSSSecurity: !0,
|
|
65
|
-
modulesDisabled:
|
|
66
|
-
syncModulesEnabled:
|
|
65
|
+
modulesDisabled: O,
|
|
66
|
+
syncModulesEnabled: e,
|
|
67
67
|
messageSettingsEnabled: !0,
|
|
68
68
|
displayGmailAnnotations: !0,
|
|
69
69
|
displayHiddenPreheader: !1,
|
|
@@ -73,37 +73,37 @@ const we = (e) => {
|
|
|
73
73
|
copyPasteEnabled: !1,
|
|
74
74
|
selectElementAfterDrop: !0,
|
|
75
75
|
sameFontSizeForOutlook: !0,
|
|
76
|
-
allowedScriptSourceDomains:
|
|
77
|
-
...
|
|
76
|
+
allowedScriptSourceDomains: H,
|
|
77
|
+
...E ? { baseBlocks: E } : {},
|
|
78
78
|
editorFonts: {
|
|
79
79
|
showDefaultStandardFonts: !0,
|
|
80
80
|
showDefaultNotStandardFonts: !0,
|
|
81
|
-
customFonts:
|
|
81
|
+
customFonts: s
|
|
82
82
|
},
|
|
83
83
|
mergeTags: [
|
|
84
84
|
{
|
|
85
|
-
entries:
|
|
85
|
+
entries: ee(
|
|
86
86
|
i.preselectedDynamicContentList,
|
|
87
|
-
|
|
87
|
+
te((_ = m.value) == null ? void 0 : _.dynamicContentList),
|
|
88
88
|
p("liquidSyntax")
|
|
89
89
|
)
|
|
90
90
|
}
|
|
91
91
|
],
|
|
92
92
|
async onTokenRefreshRequest(r) {
|
|
93
93
|
try {
|
|
94
|
-
|
|
95
|
-
const l = await
|
|
96
|
-
|
|
94
|
+
t.mark("token_start");
|
|
95
|
+
const l = await P();
|
|
96
|
+
t.mark("token_end"), r(l);
|
|
97
97
|
} catch (l) {
|
|
98
98
|
f(l, "Failed to refresh token");
|
|
99
99
|
}
|
|
100
100
|
},
|
|
101
101
|
onTemplateLoaded() {
|
|
102
102
|
try {
|
|
103
|
-
const { activateCustomViewStyles: r, updateTimerInClonedTemplate: l } =
|
|
104
|
-
|
|
103
|
+
const { activateCustomViewStyles: r, updateTimerInClonedTemplate: l } = N(), { injectFullStory: M } = $();
|
|
104
|
+
v().importCss(), r(), M(), l(), i.onReady(), o.isStripoInitialized = !0, o.loadingStatus = !1, setTimeout(() => {
|
|
105
105
|
o.hasChanges = !1;
|
|
106
|
-
}, 1e3),
|
|
106
|
+
}, 1e3), t.markReady();
|
|
107
107
|
} catch (r) {
|
|
108
108
|
f(r, "Failed to load custom interface appearance");
|
|
109
109
|
}
|
|
@@ -120,9 +120,9 @@ const we = (e) => {
|
|
|
120
120
|
onDataChanged() {
|
|
121
121
|
o.hasChanges = !0, o.changeSeq += 1;
|
|
122
122
|
},
|
|
123
|
-
onEvent:
|
|
124
|
-
onModuleAdd:
|
|
125
|
-
notifications:
|
|
123
|
+
onEvent: V,
|
|
124
|
+
onModuleAdd: D,
|
|
125
|
+
notifications: L(),
|
|
126
126
|
// Stripo deselects the block on any click outside the canvas, so every surface
|
|
127
127
|
// that belongs to the block's own flow has to be listed here (SD-153273).
|
|
128
128
|
ignoreClickOutsideSelectors: [
|
|
@@ -132,29 +132,29 @@ const we = (e) => {
|
|
|
132
132
|
".in-modal-v2-wrapper",
|
|
133
133
|
".in-toasts-wrapper"
|
|
134
134
|
],
|
|
135
|
-
extensions:
|
|
136
|
-
localePatch:
|
|
135
|
+
extensions: x,
|
|
136
|
+
localePatch: Q
|
|
137
137
|
}
|
|
138
138
|
);
|
|
139
139
|
};
|
|
140
|
-
return { initPlugin: async (a,
|
|
141
|
-
const
|
|
140
|
+
return { initPlugin: async (n, a, i, s = !1) => {
|
|
141
|
+
const e = T();
|
|
142
142
|
try {
|
|
143
|
-
|
|
144
|
-
const [
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
t.mark("plugin_start"), t.setScriptPreloaded(F), await g(), t.mark("script_ready");
|
|
144
|
+
const [c, o] = await Promise.all([
|
|
145
|
+
R(),
|
|
146
|
+
U()
|
|
147
147
|
]);
|
|
148
|
-
|
|
148
|
+
t.mark("fonts_sync_ready"), e.syncModulesEnabled = o, await q(n, a, i, c, o, s);
|
|
149
149
|
} catch {
|
|
150
|
-
|
|
151
|
-
type:
|
|
150
|
+
e.loadingStatus = !1, A({
|
|
151
|
+
type: W.Error,
|
|
152
152
|
message: B["An error has occurred. Please report the error code to support."],
|
|
153
153
|
actionButton: {
|
|
154
154
|
text: B["Reload page"],
|
|
155
155
|
onClick: () => window.location.reload()
|
|
156
156
|
}
|
|
157
|
-
}),
|
|
157
|
+
}), t.markFailed();
|
|
158
158
|
}
|
|
159
159
|
}, preloadRuntime: () => {
|
|
160
160
|
g().catch(() => {
|
|
@@ -162,5 +162,5 @@ const we = (e) => {
|
|
|
162
162
|
} };
|
|
163
163
|
};
|
|
164
164
|
export {
|
|
165
|
-
|
|
165
|
+
ke as useStripo
|
|
166
166
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { stripFontTags as
|
|
2
|
-
|
|
1
|
+
import { stripFontTags as c } from "../../utils/stripFontTags.js";
|
|
2
|
+
import { trimHrefWhitespace as l } from "../../utils/trimHrefWhitespace.js";
|
|
3
|
+
const f = [
|
|
3
4
|
{
|
|
4
5
|
id: "fix-url-encoding-start",
|
|
5
6
|
description: "Replace {%22 with %7B%22 to fix URL encoding",
|
|
@@ -58,9 +59,16 @@ const d = [
|
|
|
58
59
|
id: "strip-font-tags",
|
|
59
60
|
description: 'Unwrap browser-translate-injected <font dir="auto"> tags, keeping inner content; other <font> elements are left intact.',
|
|
60
61
|
type: "custom",
|
|
61
|
-
processor: (e) =>
|
|
62
|
+
processor: (e) => c(e),
|
|
62
63
|
priority: 15
|
|
63
64
|
},
|
|
65
|
+
{
|
|
66
|
+
id: "trim-href-whitespace",
|
|
67
|
+
description: "Trim leading/trailing whitespace and from every href value",
|
|
68
|
+
type: "custom",
|
|
69
|
+
processor: (e) => l(e),
|
|
70
|
+
priority: 16
|
|
71
|
+
},
|
|
64
72
|
{
|
|
65
73
|
id: "remove-apty-iframe",
|
|
66
74
|
description: "Cleanup Apty Iframe Code",
|
|
@@ -157,8 +165,8 @@ const d = [
|
|
|
157
165
|
processor: (e) => {
|
|
158
166
|
const t = (i) => i.toString(16).padStart(2, "0");
|
|
159
167
|
return e.replace(/rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/gi, (i, o, n, r) => {
|
|
160
|
-
const [s, a,
|
|
161
|
-
return s > 255 || a > 255 ||
|
|
168
|
+
const [s, a, p] = [Number(o), Number(n), Number(r)];
|
|
169
|
+
return s > 255 || a > 255 || p > 255 ? i : `#${t(s)}${t(a)}${t(p)}`;
|
|
162
170
|
}).replace(/#([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3\b/gi, "#$1$2$3");
|
|
163
171
|
},
|
|
164
172
|
priority: 44
|
|
@@ -200,5 +208,5 @@ const d = [
|
|
|
200
208
|
}
|
|
201
209
|
];
|
|
202
210
|
export {
|
|
203
|
-
|
|
211
|
+
f as defaultHtmlCompilerRules
|
|
204
212
|
};
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { migrateCheckbox as
|
|
2
|
-
import { migrateCouponBlock as
|
|
3
|
-
import { migrateFullStoryScripts as
|
|
4
|
-
import { migrateItemsBlock as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { migrateCheckbox as e } from "./checkboxMigrator.js";
|
|
2
|
+
import { migrateCouponBlock as a } from "./couponBlockMigrator.js";
|
|
3
|
+
import { migrateFullStoryScripts as c } from "./fullStoryScriptMigrator.js";
|
|
4
|
+
import { migrateItemsBlock as g } from "./itemsBlockMigrator.js";
|
|
5
|
+
import { migrateItemsPriceFormat as n } from "./itemsPriceFormatMigrator.js";
|
|
6
|
+
import { migrateProductNameLink as p } from "./productNameLinkMigrator.js";
|
|
7
|
+
import { migrateRadioButton as f } from "./radioButtonMigrator.js";
|
|
8
|
+
import { migrateRecommendation as l } from "./recommendationMigrator.js";
|
|
9
|
+
import { migrateRecommendationPartnerScope as d } from "./recommendationPartnerMigrator.js";
|
|
10
|
+
import { migrateRecommendationTitle as s } from "./recommendationTitleMigrator.js";
|
|
11
|
+
import { migrateSocialIcons as k } from "./socialIconMigrator.js";
|
|
12
|
+
import { migrateUnsubscribe as P } from "./unsubscribeMigrator.js";
|
|
13
|
+
const H = async (t, i = {}, r, o) => {
|
|
14
|
+
let m = t;
|
|
15
|
+
return m = e(m), m = f(m), m = await P(m), m = a(m), m = l(m, i), r && (m = d(m, r)), m = s(m), m = g(m), o != null && o.itemsPriceFormatting && (m = n(m)), m = p(m), m = k(m), m = c(m), m;
|
|
15
16
|
};
|
|
16
17
|
export {
|
|
17
|
-
|
|
18
|
+
H as migrate
|
|
18
19
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ITEMS_PRICE_FORMAT_ATTR as e } from "../../extensions/Blocks/Items/constants/currency.js";
|
|
2
|
+
import { applyPriceFormatOpsToElement as o, planPriceFormatOps as n, snapshotPriceFormatFromElement as c } from "../../extensions/Blocks/Items/utils/priceFormatOps.js";
|
|
3
|
+
import { protectLiquid as i, restoreLiquid as s } from "../../utils/liquidProtection.js";
|
|
4
|
+
const m = `td.ins-product-td.items-block-v2:not([${e.DECIMAL_COUNT}])`, a = (r) => o(
|
|
5
|
+
r,
|
|
6
|
+
n(c(r), { convertLegacy: !0 })
|
|
7
|
+
);
|
|
8
|
+
function T(r) {
|
|
9
|
+
if (typeof r != "string" || !r.includes("ins-product-td"))
|
|
10
|
+
return r;
|
|
11
|
+
try {
|
|
12
|
+
const t = new DOMParser().parseFromString(i(r), "text/html");
|
|
13
|
+
return Array.from(t.querySelectorAll(m)).map(a).includes(!0) ? s(t.documentElement.outerHTML) : r;
|
|
14
|
+
} catch (t) {
|
|
15
|
+
return console.error("ItemsPriceFormatMigrator failed:", t), r;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
T as migrateItemsPriceFormat
|
|
20
|
+
};
|
|
@@ -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
|
};
|