@useinsider/guido 2.1.0-beta.a720424 → 2.1.0-beta.e13d291

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 (117) hide show
  1. package/dist/config/migrator/recommendationMigrator.js +2 -2
  2. package/dist/extensions/Blocks/Recommendation/block.js +40 -6
  3. package/dist/extensions/Blocks/Recommendation/constants/blockIds.js +4 -0
  4. package/dist/extensions/Blocks/Recommendation/constants/controlIds.js +4 -0
  5. package/dist/extensions/Blocks/Recommendation/constants/defaultConfig.js +64 -0
  6. package/dist/extensions/Blocks/Recommendation/constants/layout.js +20 -0
  7. package/dist/extensions/Blocks/Recommendation/constants/selectors.js +19 -0
  8. package/dist/extensions/Blocks/Recommendation/controls/button/index.js +64 -0
  9. package/dist/extensions/Blocks/Recommendation/controls/cardBackground/index.js +80 -0
  10. package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +232 -0
  11. package/dist/extensions/Blocks/Recommendation/controls/image/index.js +19 -0
  12. package/dist/extensions/Blocks/Recommendation/controls/layout/index.js +96 -0
  13. package/dist/extensions/Blocks/Recommendation/controls/main/algorithm.js +110 -0
  14. package/dist/extensions/Blocks/Recommendation/controls/main/currency.js +204 -0
  15. package/dist/extensions/Blocks/Recommendation/controls/main/filters.js +54 -0
  16. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +205 -0
  17. package/dist/extensions/Blocks/Recommendation/controls/main/locale.js +74 -0
  18. package/dist/extensions/Blocks/Recommendation/controls/main/productLayout.js +118 -0
  19. package/dist/extensions/Blocks/Recommendation/controls/main/shuffle.js +71 -0
  20. package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +286 -0
  21. package/dist/extensions/Blocks/Recommendation/controls/name/index.js +46 -0
  22. package/dist/extensions/Blocks/Recommendation/controls/name/textTrim.js +76 -0
  23. package/dist/extensions/Blocks/Recommendation/controls/oldPrice/index.js +44 -0
  24. package/dist/extensions/Blocks/Recommendation/controls/omnibusDiscount/index.js +48 -0
  25. package/dist/extensions/Blocks/Recommendation/controls/{omnibusDiscountTextAfterControl.js → omnibusDiscount/textAfter.js} +16 -14
  26. package/dist/extensions/Blocks/Recommendation/controls/{omnibusDiscountTextBeforeControl.js → omnibusDiscount/textBefore.js} +16 -14
  27. package/dist/extensions/Blocks/Recommendation/controls/omnibusPrice/index.js +48 -0
  28. package/dist/extensions/Blocks/Recommendation/controls/{omnibusPriceTextAfterControl.js → omnibusPrice/textAfter.js} +16 -14
  29. package/dist/extensions/Blocks/Recommendation/controls/{omnibusPriceTextBeforeControl.js → omnibusPrice/textBefore.js} +14 -12
  30. package/dist/extensions/Blocks/Recommendation/controls/price/index.js +44 -0
  31. package/dist/extensions/Blocks/Recommendation/controls/spacing/index.js +222 -0
  32. package/dist/extensions/Blocks/Recommendation/extension.js +40 -17
  33. package/dist/extensions/Blocks/Recommendation/iconsRegistry.js +19 -3
  34. package/dist/extensions/Blocks/Recommendation/recommendation.css.js +13 -4
  35. package/dist/extensions/Blocks/Recommendation/services/configService.js +239 -0
  36. package/dist/extensions/Blocks/Recommendation/settingsPanel.js +21 -10
  37. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +41 -36
  38. package/dist/extensions/Blocks/Recommendation/templates/grid/elementRenderer.js +233 -0
  39. package/dist/extensions/Blocks/Recommendation/templates/grid/migration.js +251 -0
  40. package/dist/extensions/Blocks/Recommendation/templates/grid/template.js +69 -0
  41. package/dist/extensions/Blocks/Recommendation/templates/index.js +12 -0
  42. package/dist/extensions/Blocks/Recommendation/templates/list/elementRenderer.js +174 -0
  43. package/dist/extensions/Blocks/Recommendation/templates/list/template.js +73 -0
  44. package/dist/extensions/Blocks/Recommendation/templates/utils.js +121 -0
  45. package/dist/extensions/Blocks/Recommendation/types/nodeConfig.js +6 -0
  46. package/dist/extensions/Blocks/Recommendation/utils/filterUtil.js +9 -9
  47. package/dist/extensions/Blocks/Recommendation/utils/preserveTextStyles.js +27 -16
  48. package/dist/extensions/Blocks/Recommendation/utils/priceFormatter.js +29 -0
  49. package/dist/extensions/Blocks/Recommendation/utils/tagName.js +46 -0
  50. package/dist/extensions/Blocks/controlFactories.js +125 -93
  51. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +223 -169
  52. package/dist/services/recommendationApi.js +10 -9
  53. package/dist/src/components/wrappers/WpDrawer.vue.d.ts +1 -1
  54. package/dist/src/extensions/Blocks/Recommendation/block.d.ts +34 -0
  55. package/dist/src/extensions/Blocks/Recommendation/constants/blockIds.d.ts +13 -0
  56. package/dist/src/extensions/Blocks/Recommendation/{constants.d.ts → constants/controlIds.d.ts} +0 -24
  57. package/dist/src/extensions/Blocks/Recommendation/constants/defaultConfig.d.ts +49 -0
  58. package/dist/src/extensions/Blocks/Recommendation/constants/index.d.ts +13 -0
  59. package/dist/src/extensions/Blocks/Recommendation/constants/layout.d.ts +35 -0
  60. package/dist/src/extensions/Blocks/Recommendation/constants/selectors.d.ts +31 -0
  61. package/dist/src/extensions/Blocks/Recommendation/controls/button/index.d.ts +143 -0
  62. package/dist/src/extensions/Blocks/Recommendation/controls/cardBackground/index.d.ts +31 -0
  63. package/dist/src/extensions/Blocks/Recommendation/{cardCompositionControl.d.ts → controls/cardComposition/index.d.ts} +23 -3
  64. package/dist/src/extensions/Blocks/Recommendation/controls/image/index.d.ts +35 -0
  65. package/dist/src/extensions/Blocks/Recommendation/controls/index.d.ts +21 -589
  66. package/dist/src/extensions/Blocks/Recommendation/controls/layout/index.d.ts +37 -0
  67. package/dist/src/extensions/Blocks/Recommendation/controls/main/algorithm.d.ts +29 -0
  68. package/dist/src/extensions/Blocks/Recommendation/controls/main/currency.d.ts +45 -0
  69. package/dist/src/extensions/Blocks/Recommendation/controls/main/filters.d.ts +22 -0
  70. package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +57 -0
  71. package/dist/src/extensions/Blocks/Recommendation/controls/main/locale.d.ts +24 -0
  72. package/dist/src/extensions/Blocks/Recommendation/controls/main/productLayout.d.ts +42 -0
  73. package/dist/src/extensions/Blocks/Recommendation/controls/main/shuffle.d.ts +23 -0
  74. package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.d.ts +214 -0
  75. package/dist/src/extensions/Blocks/Recommendation/controls/name/index.d.ts +97 -0
  76. package/dist/src/extensions/Blocks/Recommendation/controls/name/textTrim.d.ts +16 -0
  77. package/dist/src/extensions/Blocks/Recommendation/controls/oldPrice/index.d.ts +95 -0
  78. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusDiscount/index.d.ts +100 -0
  79. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusDiscount/textAfter.d.ts +15 -0
  80. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusDiscount/textBefore.d.ts +15 -0
  81. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusPrice/index.d.ts +100 -0
  82. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusPrice/textAfter.d.ts +15 -0
  83. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusPrice/textBefore.d.ts +15 -0
  84. package/dist/src/extensions/Blocks/Recommendation/controls/price/index.d.ts +95 -0
  85. package/dist/src/extensions/Blocks/Recommendation/controls/spacing/index.d.ts +83 -0
  86. package/dist/src/extensions/Blocks/Recommendation/extension.d.ts +9 -0
  87. package/dist/src/extensions/Blocks/Recommendation/services/configService.d.ts +151 -0
  88. package/dist/src/extensions/Blocks/Recommendation/services/index.d.ts +6 -0
  89. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +17 -16
  90. package/dist/src/extensions/Blocks/Recommendation/templates/grid/elementRenderer.d.ts +20 -0
  91. package/dist/src/extensions/Blocks/Recommendation/templates/{migrationTemplate.d.ts → grid/migration.d.ts} +11 -4
  92. package/dist/src/extensions/Blocks/Recommendation/templates/grid/template.d.ts +33 -0
  93. package/dist/src/extensions/Blocks/Recommendation/templates/index.d.ts +39 -0
  94. package/dist/src/extensions/Blocks/Recommendation/templates/list/elementRenderer.d.ts +8 -0
  95. package/dist/src/extensions/Blocks/Recommendation/templates/list/migration.d.ts +25 -0
  96. package/dist/src/extensions/Blocks/Recommendation/templates/list/template.d.ts +18 -0
  97. package/dist/src/extensions/Blocks/Recommendation/templates/utils.d.ts +54 -0
  98. package/dist/src/extensions/Blocks/Recommendation/types/index.d.ts +7 -0
  99. package/dist/src/extensions/Blocks/Recommendation/types/nodeConfig.d.ts +154 -0
  100. package/dist/src/extensions/Blocks/Recommendation/utils/priceFormatter.d.ts +33 -0
  101. package/dist/src/extensions/Blocks/Recommendation/utils/stylePreserver.d.ts +113 -0
  102. package/dist/src/extensions/Blocks/Recommendation/utils/tagName.d.ts +77 -0
  103. package/dist/static/styles/customEditorStyle.css.js +25 -2
  104. package/package.json +1 -1
  105. package/dist/extensions/Blocks/Recommendation/cardCompositionControl.js +0 -187
  106. package/dist/extensions/Blocks/Recommendation/constants.js +0 -13
  107. package/dist/extensions/Blocks/Recommendation/control.js +0 -336
  108. package/dist/extensions/Blocks/Recommendation/controls/cardBackgroundColorControl.js +0 -68
  109. package/dist/extensions/Blocks/Recommendation/controls/index.js +0 -245
  110. package/dist/extensions/Blocks/Recommendation/controls/nameTextTrimControl.js +0 -74
  111. package/dist/extensions/Blocks/Recommendation/controls/spacingControl.js +0 -188
  112. package/dist/extensions/Blocks/Recommendation/templates/blockTemplate.js +0 -181
  113. package/dist/extensions/Blocks/Recommendation/templates/migrationTemplate.js +0 -189
  114. package/dist/extensions/Blocks/Recommendation/templates/templateUtils.js +0 -209
  115. package/dist/src/extensions/Blocks/Recommendation/control.d.ts +0 -38
  116. package/dist/src/extensions/Blocks/Recommendation/templates/blockTemplate.d.ts +0 -16
  117. package/dist/src/extensions/Blocks/Recommendation/templates/templateUtils.d.ts +0 -52
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Price Formatting Utilities
3
+ *
4
+ * Provides functions for formatting prices according to currency settings.
5
+ * Used to format prices displayed in recommendation product cards.
6
+ */
7
+ import type { CurrencyConfig } from '../types/nodeConfig';
8
+ /**
9
+ * Options for formatting a price
10
+ */
11
+ export interface FormatPriceOptions {
12
+ /** The numeric price value */
13
+ price: number;
14
+ /** Currency configuration */
15
+ currency: CurrencyConfig;
16
+ }
17
+ /**
18
+ * Formats a numeric price according to currency settings
19
+ * @example
20
+ * // Returns: "$ 1,999.99"
21
+ * formatPrice({ price: 1999.99, currency: currencyConfig })
22
+ * @param options - Formatting options
23
+ * @returns Formatted price string
24
+ */
25
+ export declare function formatPrice(options: FormatPriceOptions): string;
26
+ /**
27
+ * Parses a formatted price string back to a number
28
+ * Useful for extracting numeric values from formatted price displays
29
+ * @param formattedPrice - The formatted price string
30
+ * @param currency - Currency configuration for parsing
31
+ * @returns Parsed numeric value or NaN if parsing fails
32
+ */
33
+ export declare function parseFormattedPrice(formattedPrice: string, currency: CurrencyConfig): number;
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Style Preserver Utility
3
+ *
4
+ * Captures and restores element styles during block regeneration.
5
+ * This ensures user styling is preserved when:
6
+ * - Layout changes (vertical <-> horizontal)
7
+ * - Cards per row changes
8
+ * - Composition order changes
9
+ *
10
+ * Works with the node config system to provide complete style persistence.
11
+ */
12
+ import type { ImmutableHtmlNode } from '@stripoinc/ui-editor-extensions';
13
+ import { ModificationDescription } from '@stripoinc/ui-editor-extensions';
14
+ /**
15
+ * Style properties that can be captured for text elements
16
+ */
17
+ export interface TextElementStyles {
18
+ fontSize?: string;
19
+ fontFamily?: string;
20
+ fontWeight?: string;
21
+ fontStyle?: string;
22
+ color?: string;
23
+ textAlign?: string;
24
+ lineHeight?: string;
25
+ textDecoration?: string;
26
+ }
27
+ /**
28
+ * Style properties for button elements
29
+ */
30
+ export interface ButtonElementStyles extends TextElementStyles {
31
+ backgroundColor?: string;
32
+ borderRadius?: string;
33
+ border?: string;
34
+ padding?: string;
35
+ }
36
+ /**
37
+ * Style properties for image elements
38
+ */
39
+ export interface ImageElementStyles {
40
+ width?: string;
41
+ height?: string;
42
+ maxWidth?: string;
43
+ }
44
+ /**
45
+ * Complete captured styles for a recommendation block
46
+ */
47
+ export interface CapturedStyles {
48
+ /** Product name text styles */
49
+ name: TextElementStyles;
50
+ /** Current price text styles */
51
+ price: TextElementStyles;
52
+ /** Original/old price text styles */
53
+ oldPrice: TextElementStyles;
54
+ /** Omnibus price text styles */
55
+ omnibusPrice: TextElementStyles;
56
+ /** Omnibus discount text styles */
57
+ omnibusDiscount: TextElementStyles;
58
+ /** CTA button styles */
59
+ button: ButtonElementStyles;
60
+ /** Product image styles */
61
+ image: ImageElementStyles;
62
+ /** Card background color */
63
+ cardBackgroundColor: string | null;
64
+ /** Column spacing in pixels */
65
+ columnSpacing: number;
66
+ /** Row spacing in pixels */
67
+ rowSpacing: number;
68
+ /** Element composition order */
69
+ composition: string[];
70
+ /** Element visibility flags */
71
+ visibility: Record<string, boolean>;
72
+ }
73
+ type DocumentModifier = {
74
+ modifyHtml: (node: ImmutableHtmlNode) => {
75
+ setStyle: (prop: string, value: string) => DocumentModifier;
76
+ };
77
+ apply: (description: ModificationDescription) => void;
78
+ };
79
+ /**
80
+ * Capture all styles from a recommendation block
81
+ *
82
+ * Call this BEFORE any operation that regenerates the block HTML.
83
+ * The captured styles can then be restored after regeneration.
84
+ * @example
85
+ * // Before layout change
86
+ * const styles = captureStyles(this.currentNode);
87
+ *
88
+ * // ... regenerate block HTML ...
89
+ *
90
+ * // After regeneration
91
+ * restoreStyles(this.currentNode, this.api.getDocumentModifier(), styles);
92
+ * @param node - The block node to capture styles from
93
+ * @returns Complete captured styles object
94
+ */
95
+ export declare function captureStyles(node: ImmutableHtmlNode | null | undefined): CapturedStyles;
96
+ /**
97
+ * Restore captured styles to a regenerated block
98
+ *
99
+ * Call this AFTER regenerating block HTML to reapply user styling.
100
+ * @example
101
+ * restoreStyles(this.currentNode, this.api.getDocumentModifier(), capturedStyles);
102
+ * @param node - The block node to restore styles to
103
+ * @param modifier - Document modifier for applying changes
104
+ * @param styles - Previously captured styles
105
+ */
106
+ export declare function restoreStyles(node: ImmutableHtmlNode | null | undefined, modifier: DocumentModifier, styles: CapturedStyles): void;
107
+ /**
108
+ * Check if styles have meaningful content worth restoring
109
+ * @param styles - Captured styles to check
110
+ * @returns True if styles contain restorable content
111
+ */
112
+ export declare function hasRestorableStyles(styles: CapturedStyles): boolean;
113
+ export {};
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Node Type Guards and Tag Name Utilities
3
+ *
4
+ * Provides type-safe utilities for working with ImmutableHtmlNode.
5
+ * Handles both standard DOM properties and Stripo's custom methods.
6
+ */
7
+ import type { ImmutableHtmlNode } from '@stripoinc/ui-editor-extensions';
8
+ /** Interface for nodes with standard tagName property */
9
+ interface NodeWithTagName {
10
+ tagName: string;
11
+ }
12
+ /** Interface for nodes with getStyle method */
13
+ export interface NodeWithGetStyle {
14
+ getStyle: (property: string) => string | null | undefined;
15
+ }
16
+ /** Interface for nodes with parent method */
17
+ export interface NodeWithParent {
18
+ parent: () => ImmutableHtmlNode | null;
19
+ }
20
+ /**
21
+ * Type guard to check if a node has getStyle method
22
+ * @param node - The node to check
23
+ */
24
+ export declare function hasGetStyle(node: unknown): node is NodeWithGetStyle;
25
+ /**
26
+ * Type guard to check if a node has parent method
27
+ * @param node - The node to check
28
+ */
29
+ export declare function hasParent(node: unknown): node is NodeWithParent;
30
+ /**
31
+ * Type guard to check if a node is a TD element
32
+ * @param node - The node to check
33
+ */
34
+ export declare function isTdNode(node: unknown): node is ImmutableHtmlNode & NodeWithTagName;
35
+ /**
36
+ * Safely retrieves a style value from a node
37
+ * @param node - The node to get the style from
38
+ * @param property - The CSS property name
39
+ * @returns The style value or null if not accessible
40
+ */
41
+ export declare function safeGetStyle(node: ImmutableHtmlNode | null, property: string): string | null | undefined;
42
+ /**
43
+ * Safely retrieves the parent element of a node
44
+ * @param node - The node to get the parent from
45
+ * @returns The parent node or null if not accessible
46
+ */
47
+ export declare function safeGetParent(node: ImmutableHtmlNode | null): ImmutableHtmlNode | null;
48
+ /**
49
+ * Safely retrieves the tag name from a node.
50
+ * Handles both standard DOM tagName property and Stripo's getTagName() method.
51
+ * @param node - The node to get the tag name from
52
+ * @param defaultValue - Default value if tag name cannot be determined (default: 'UNKNOWN')
53
+ * @returns The uppercase tag name
54
+ */
55
+ export declare function getTagName(node: ImmutableHtmlNode | null | undefined, defaultValue?: string): string;
56
+ /**
57
+ * Checks if a tag name represents a table cell element.
58
+ * Includes standard TD and Stripo's custom block types (BLOCK_IMAGE, BLOCK_BUTTON).
59
+ * @param tagName - The tag name to check (case-insensitive)
60
+ * @returns True if the tag represents a table cell
61
+ */
62
+ export declare function isTableCellTag(tagName: string): boolean;
63
+ /**
64
+ * Checks if a node is a table cell element.
65
+ * Combines getTagName and isTableCellTag for convenience.
66
+ * @param node - The node to check
67
+ * @returns True if the node is a table cell element
68
+ */
69
+ export declare function isTableCellNode(node: ImmutableHtmlNode | null | undefined): boolean;
70
+ /**
71
+ * Gets the appropriate CSS display value for showing a table element.
72
+ * Table cells use 'table-cell', table rows use 'table-row'.
73
+ * @param node - The table element node
74
+ * @returns The CSS display value ('table-cell' or 'table-row')
75
+ */
76
+ export declare function getTableDisplayValue(node: ImmutableHtmlNode | null | undefined): 'table-cell' | 'table-row';
77
+ export {};
@@ -19,8 +19,31 @@ const n = `.esd-x,
19
19
  box-shadow: none;
20
20
  }
21
21
  .ins-product-cart ue-node-actions,
22
- .ins-recommendation-v3-block-v2 .product-attribute-cell ue-node-actions,
23
- .ins-recommendation-v3-block-v2 .product-attribute-cell ue-node-panel {
22
+ /* Horizontal layout - hide for info, image, and button cells */
23
+ .ins-recommendation-v3-block-v2 .product-info-cell ue-node-actions,
24
+ .ins-recommendation-v3-block-v2 .product-info-cell ue-node-panel,
25
+ .ins-recommendation-v3-block-v2 .product-image-cell ue-node-actions,
26
+ .ins-recommendation-v3-block-v2 .product-image-cell ue-node-panel,
27
+ .ins-recommendation-v3-block-v2 .button-cell ue-node-actions,
28
+ .ins-recommendation-v3-block-v2 .button-cell ue-node-panel,
29
+ /* Vertical layout - hide for product-card-segment inner cells */
30
+ .ins-recommendation-v3-block-v2 .product-card-segment ue-node-actions,
31
+ .ins-recommendation-v3-block-v2 .product-card-segment ue-node-panel,
32
+ /* Hide for specific product attribute cells in both layouts */
33
+ .ins-recommendation-v3-block-v2 .product-image ue-node-actions,
34
+ .ins-recommendation-v3-block-v2 .product-image ue-node-panel,
35
+ .ins-recommendation-v3-block-v2 .product-name ue-node-actions,
36
+ .ins-recommendation-v3-block-v2 .product-name ue-node-panel,
37
+ .ins-recommendation-v3-block-v2 .product-price ue-node-actions,
38
+ .ins-recommendation-v3-block-v2 .product-price ue-node-panel,
39
+ .ins-recommendation-v3-block-v2 .product-old-price ue-node-actions,
40
+ .ins-recommendation-v3-block-v2 .product-old-price ue-node-panel,
41
+ .ins-recommendation-v3-block-v2 .product-omnibus-price ue-node-actions,
42
+ .ins-recommendation-v3-block-v2 .product-omnibus-price ue-node-panel,
43
+ .ins-recommendation-v3-block-v2 .product-omnibus-discount ue-node-actions,
44
+ .ins-recommendation-v3-block-v2 .product-omnibus-discount ue-node-panel,
45
+ .ins-recommendation-v3-block-v2 .product-button ue-node-actions,
46
+ .ins-recommendation-v3-block-v2 .product-button ue-node-panel {
24
47
  display: none !important;
25
48
  }
26
49
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "2.1.0-beta.a720424",
3
+ "version": "2.1.0-beta.e13d291",
4
4
  "description": "Guido is a Vue + TypeScript wrapper for Email Plugin. Easily embed the email editor in your Vue applications.",
5
5
  "main": "./dist/guido.umd.cjs",
6
6
  "module": "./dist/library.js",
@@ -1,187 +0,0 @@
1
- import { ModificationDescription as n } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
2
- import { CommonControl as _ } from "../common-control.js";
3
- import { ATTR_PRODUCT_IMAGE as m, ATTR_PRODUCT_NAME as y, ATTR_PRODUCT_PRICE as T, ATTR_PRODUCT_OLD_PRICE as h, ATTR_PRODUCT_OMNIBUS_PRICE as C, ATTR_PRODUCT_OMNIBUS_DISCOUNT as f, ATTR_PRODUCT_BUTTON as g } from "./constants.js";
4
- const R = "ui-elements-recommendation-card-composition", l = ".recommendation-attribute-row", A = "tr.recommendation-product-row", c = "data-card-composition", a = "data-attribute-type", d = "data-visibility", s = [
5
- { key: m, label: "Product Image", visible: !0 },
6
- { key: y, label: "Product Name", visible: !0 },
7
- { key: T, label: "Product Price", visible: !0 },
8
- { key: h, label: "Product Original Price", visible: !0 },
9
- { key: C, label: "Omnibus Price", visible: !1 },
10
- { key: f, label: "Omnibus Discount", visible: !1 },
11
- { key: g, label: "Product Button", visible: !0 }
12
- ];
13
- class N extends _ {
14
- getId() {
15
- return R;
16
- }
17
- getTemplate() {
18
- const t = s.map((i) => ({
19
- key: i.key,
20
- label: i.label,
21
- content: this._createItemContent(i.label, i.key)
22
- }));
23
- return `
24
- <div class="container">
25
- ${this._GuLabel({ text: "Card Element Order & Visibility" })}
26
- ${this._GuOrderable("cardComposition", t)}
27
- </div>
28
- `;
29
- }
30
- onRender() {
31
- this._initializeComposition(), this._registerValueChangeListeners();
32
- }
33
- onTemplateNodeUpdated(t) {
34
- super.onTemplateNodeUpdated(t), this._initializeComposition();
35
- }
36
- /**
37
- * Creates the HTML content for an orderable item with label and toggle
38
- */
39
- _createItemContent(t, i) {
40
- return `
41
- <div style="display: flex; align-items: center; justify-content: space-between;
42
- padding: 8px; gap: 8px;">
43
- <span style="flex: 1;">${t}</span>
44
- ${this._GuToggle(`visibility_${i}`)}
45
- </div>
46
- `;
47
- }
48
- /**
49
- * Registers event listeners for composition and visibility changes
50
- */
51
- _registerValueChangeListeners() {
52
- this.api.onValueChanged("cardComposition", (t) => {
53
- this._applyCompositionToBlock(t);
54
- }), s.forEach((t) => {
55
- this.api.onValueChanged(`visibility_${t.key}`, (i) => {
56
- this._applyVisibilityToBlock(t.key, i);
57
- });
58
- });
59
- }
60
- /**
61
- * Initializes composition order and visibility state from the current node
62
- */
63
- _initializeComposition() {
64
- const t = this._readCompositionFromNode(), i = this._readVisibilityFromRows(), e = {
65
- cardComposition: t,
66
- ...this._buildVisibilityValues(i)
67
- };
68
- this.api.updateValues(e);
69
- }
70
- /**
71
- * Reads composition order from node's data-card-composition attribute
72
- * Falls back to default order if attribute is not present
73
- */
74
- _readCompositionFromNode() {
75
- if (!this.currentNode || !("getAttribute" in this.currentNode))
76
- return s.map((i) => i.key);
77
- const t = this.currentNode.getAttribute(c);
78
- return t ? t.split(",").filter(Boolean) : s.map((i) => i.key);
79
- }
80
- /**
81
- * Builds visibility values object from the visibility map
82
- */
83
- _buildVisibilityValues(t) {
84
- return s.reduce((i, e) => (i[`visibility_${e.key}`] = t[e.key] ?? !0, i), {});
85
- }
86
- /**
87
- * Read visibility state from individual row elements' data-visibility attributes
88
- * This ensures toggles reflect the actual DOM state
89
- */
90
- _readVisibilityFromRows() {
91
- if (!this.currentNode)
92
- return this._getDefaultVisibilities();
93
- const t = Array.from(this.currentNode.querySelectorAll(l));
94
- console.debug("_readVisibilityFromRows - found attribute rows:", t.length);
95
- const i = this._extractVisibilityFromRows(t);
96
- return this._mergeWithDefaults(i);
97
- }
98
- /**
99
- * Returns default visibility values for all items
100
- */
101
- _getDefaultVisibilities() {
102
- return s.reduce((t, i) => (t[i.key] = i.visible, t), {});
103
- }
104
- /**
105
- * Extracts visibility values from DOM nodes
106
- */
107
- _extractVisibilityFromRows(t) {
108
- const i = {};
109
- return t.forEach((e) => {
110
- if (!("getAttribute" in e))
111
- return;
112
- const o = e.getAttribute(a), r = e.getAttribute(d);
113
- o && r !== null && (i[o] = this._parseVisibilityValue(r), console.debug(
114
- `_readVisibilityFromRows - ${o}: ${i[o]} (raw: ${r})`
115
- ));
116
- }), i;
117
- }
118
- /**
119
- * Parses visibility value from string to boolean
120
- * Accepts "1", "true" as true, everything else as false
121
- */
122
- _parseVisibilityValue(t) {
123
- return t === "1" || t === "true";
124
- }
125
- /**
126
- * Merges extracted visibilities with default values for missing keys
127
- */
128
- _mergeWithDefaults(t) {
129
- return s.forEach((i) => {
130
- i.key in t || (t[i.key] = i.visible, console.debug(`_readVisibilityFromRows - ${i.key}: using default ${i.visible}`));
131
- }), t;
132
- }
133
- /**
134
- * Apply the reordered composition to the block's HTML structure
135
- * Updates the data-card-composition attribute and reorders product attributes
136
- */
137
- _applyCompositionToBlock(t) {
138
- if (console.debug("_applyCompositionToBlock - composition:", t), !this.currentNode) {
139
- console.debug("_applyCompositionToBlock - no current node");
140
- return;
141
- }
142
- this.api.getDocumentModifier().modifyHtml(this.currentNode).setAttribute(c, t.join(",")).apply(new n("Update card composition")), this._reorderProductAttributes(t);
143
- }
144
- /**
145
- * Reorders attribute rows within each product row based on composition order
146
- */
147
- _reorderProductAttributes(t) {
148
- if (!this.currentNode)
149
- return;
150
- const i = this.currentNode.querySelectorAll(A);
151
- if (!(i != null && i.length))
152
- return;
153
- const e = this.api.getDocumentModifier();
154
- i.forEach((o) => {
155
- const r = this._buildCompositionHtml(o, t);
156
- e.modifyHtml(o).setInnerHtml(r);
157
- }), e.apply(new n("Reorder product attributes"));
158
- }
159
- /**
160
- * Builds HTML string with attributes ordered according to composition
161
- */
162
- _buildCompositionHtml(t, i) {
163
- return i.reduce((e, o) => {
164
- const r = t.querySelector(`${l}[${a}="${o}"]`);
165
- return r && "getOuterHTML" in r ? e + r.getOuterHTML() : e;
166
- }, "");
167
- }
168
- /**
169
- * Apply visibility changes to the block's HTML structure
170
- * Updates display style and data-visibility attribute for all matching rows
171
- */
172
- _applyVisibilityToBlock(t, i) {
173
- if (console.debug("_applyVisibilityToBlock", t, i), !this.currentNode)
174
- return;
175
- const e = this.currentNode.querySelectorAll(`${l}[${a}="${t}"]`);
176
- if (!(e != null && e.length))
177
- return;
178
- const o = i ? "table-row" : "none", r = i ? "1" : "0", p = `Set ${t} visibility to ${i ? "visible" : "hidden"}`, u = this.api.getDocumentModifier();
179
- e.forEach((b) => {
180
- u.modifyHtml(b).setStyle("display", o).setAttribute(d, r);
181
- }), u.apply(new n(p));
182
- }
183
- }
184
- export {
185
- R as COMPOSITION_CONTROL_BLOCK_ID,
186
- N as RecommendationCardCompositionControl
187
- };
@@ -1,13 +0,0 @@
1
- const _ = "productImage", b = "productName", n = "productPrice", i = "productOldPrice", O = "productOmnibusPrice", T = "productOmnibusDiscount", t = "productButton";
2
- var o = /* @__PURE__ */ ((c) => (c.BUTTON = "recommendation-block-button", c.NAME = "recommendation-block-name", c.PRICE = "recommendation-block-price", c.OLD_PRICE = "recommendation-block-old-price", c.OMNIBUS_PRICE = "recommendation-block-omnibus-price", c.OMNIBUS_DISCOUNT = "recommendation-block-omnibus-discount", c.IMAGE = "recommendation-block-image", c))(o || {}), r = /* @__PURE__ */ ((c) => (c.BUTTON_ALIGN = "recommendation-block-button-align-control", c.BUTTON_BORDER = "recommendation-block-button-border-control", c.BUTTON_BORDER_RADIUS = "recommendation-block-button-border-radius-control", c.BUTTON_COLOR = "recommendation-block-button-color-control", c.BUTTON_FIT_TO_CONTENT = "recommendation-block-button-fit-to-content-control", c.BUTTON_FONT_FAMILY = "recommendation-block-button-font-family-control", c.BUTTON_MARGINS = "recommendation-block-button-margins-control", c.BUTTON_PADDINGS = "recommendation-block-button-paddings-control", c.BUTTON_TEXT = "recommendation-block-button-text-control", c.BUTTON_TEXT_SIZE = "recommendation-block-button-text-size-control", c.BUTTON_TEXT_STYLE_AND_FONT_COLOR = "recommendation-block-button-text-style-and-font-color-control", c.NAME_ALIGN = "recommendation-block-name-align-control", c.NAME_BACKGROUND = "recommendation-block-name-background-control", c.NAME_COLOR = "recommendation-block-name-color-control", c.NAME_FONT_FAMILY = "recommendation-block-name-font-family-control", c.NAME_PADDINGS = "recommendation-block-name-paddings-control", c.NAME_SIZE = "recommendation-block-name-size-control", c.NAME_STYLE = "recommendation-block-name-style-control", c.NAME_TEXT_TRIM = "recommendation-block-name-text-trim-control", c.PRICE_ALIGN = "recommendation-block-price-align-control", c.PRICE_BACKGROUND = "recommendation-block-price-background-control", c.PRICE_COLOR = "recommendation-block-price-color-control", c.PRICE_FONT_FAMILY = "recommendation-block-price-font-family-control", c.PRICE_PADDINGS = "recommendation-block-price-paddings-control", c.PRICE_SIZE = "recommendation-block-price-size-control", c.PRICE_STYLE = "recommendation-block-price-style-control", c.OLD_PRICE_ALIGN = "recommendation-block-old-price-align-control", c.OLD_PRICE_BACKGROUND = "recommendation-block-old-price-background-control", c.OLD_PRICE_COLOR = "recommendation-block-old-price-color-control", c.OLD_PRICE_FONT_FAMILY = "recommendation-block-old-price-font-family-control", c.OLD_PRICE_PADDINGS = "recommendation-block-old-price-paddings-control", c.OLD_PRICE_SIZE = "recommendation-block-old-price-size-control", c.OLD_PRICE_STYLE = "recommendation-block-old-price-style-control", c.OMNIBUS_PRICE_ALIGN = "recommendation-block-omnibus-price-align-control", c.OMNIBUS_PRICE_BACKGROUND = "recommendation-block-omnibus-price-background-control", c.OMNIBUS_PRICE_COLOR = "recommendation-block-omnibus-price-color-control", c.OMNIBUS_PRICE_FONT_FAMILY = "recommendation-block-omnibus-price-font-family-control", c.OMNIBUS_PRICE_PADDINGS = "recommendation-block-omnibus-price-paddings-control", c.OMNIBUS_PRICE_SIZE = "recommendation-block-omnibus-price-size-control", c.OMNIBUS_PRICE_STYLE = "recommendation-block-omnibus-price-style-control", c.OMNIBUS_PRICE_TEXT_BEFORE = "recommendation-block-omnibus-price-text-before-control", c.OMNIBUS_PRICE_TEXT_AFTER = "recommendation-block-omnibus-price-text-after-control", c.OMNIBUS_DISCOUNT_ALIGN = "recommendation-block-omnibus-discount-align-control", c.OMNIBUS_DISCOUNT_BACKGROUND = "recommendation-block-omnibus-discount-background-control", c.OMNIBUS_DISCOUNT_COLOR = "recommendation-block-omnibus-discount-color-control", c.OMNIBUS_DISCOUNT_FONT_FAMILY = "recommendation-block-omnibus-discount-font-family-control", c.OMNIBUS_DISCOUNT_PADDINGS = "recommendation-block-omnibus-discount-paddings-control", c.OMNIBUS_DISCOUNT_SIZE = "recommendation-block-omnibus-discount-size-control", c.OMNIBUS_DISCOUNT_STYLE = "recommendation-block-omnibus-discount-style-control", c.OMNIBUS_DISCOUNT_TEXT_BEFORE = "recommendation-block-omnibus-discount-text-before-control", c.OMNIBUS_DISCOUNT_TEXT_AFTER = "recommendation-block-omnibus-discount-text-after-control", c.IMAGE_SIZE = "recommendation-block-image-size-control", c.IMAGE_MARGINS = "recommendation-block-image-margins-control", c))(r || {});
3
- export {
4
- t as ATTR_PRODUCT_BUTTON,
5
- _ as ATTR_PRODUCT_IMAGE,
6
- b as ATTR_PRODUCT_NAME,
7
- i as ATTR_PRODUCT_OLD_PRICE,
8
- T as ATTR_PRODUCT_OMNIBUS_DISCOUNT,
9
- O as ATTR_PRODUCT_OMNIBUS_PRICE,
10
- n as ATTR_PRODUCT_PRICE,
11
- o as RecommendationBlockId,
12
- r as RecommendationControlId
13
- };