@liquidcommerce/elements-sdk 2.4.1 → 2.4.3

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 CHANGED
@@ -207,8 +207,7 @@ By default, you get a floating cart button. Here's how to customize it:
207
207
  data-liquid-commerce-elements
208
208
  data-token="YOUR_API_KEY"
209
209
  data-env="production"
210
- data-cart-id="header-cart"
211
- data-show-cart-items
210
+ data-cart-badge-button="header-cart"
212
211
  src="https://assets-elements.liquidcommerce.us/all/elements.js"
213
212
  ></script>
214
213
  ```
@@ -220,7 +219,7 @@ By default, you get a floating cart button. Here's how to customize it:
220
219
  data-liquid-commerce-elements
221
220
  data-token="YOUR_API_KEY"
222
221
  data-env="production"
223
- data-hide-cart-floating-button
222
+ data-cart-button-hidden
224
223
  src="https://assets-elements.liquidcommerce.us/all/elements.js"
225
224
  ></script>
226
225
  ```
@@ -324,9 +323,15 @@ Here's every available data attribute:
324
323
  data-env="production|staging|development|local"
325
324
 
326
325
  <!-- Cart Button -->
327
- data-cart-id="container-id"
328
- data-show-cart-items
329
- data-hide-cart-floating-button
326
+ data-cart-button="container-id"
327
+ data-cart-badge-button="container-id"
328
+ data-cart-button-hidden
329
+
330
+ <!-- Cart Button with Position Prefixes -->
331
+ data-cart-button="above:.logo"
332
+ data-cart-badge-button="below:#header"
333
+ data-cart-button="inside:.nav"
334
+ data-cart-badge-button="replace:.old-cart"
330
335
 
331
336
  <!-- Products (Method 1: Direct) -->
332
337
  data-container-1="div-id"
@@ -392,7 +397,7 @@ pnpm add @liquidcommerce/elements-sdk
392
397
  });
393
398
 
394
399
  // Inject components
395
- await client.injectProductElement([
400
+ const components = await client.injectProductElement([
396
401
  { containerId: 'pdp-1', identifier: '00619947000020' }
397
402
  ]);
398
403
 
@@ -559,15 +564,20 @@ promoTicker: [
559
564
 
560
565
  ### Component Injection
561
566
 
562
- Inject SDK components into your page containers.
567
+ Inject SDK components into your page containers. All injection methods return wrapper objects that provide component control.
563
568
 
564
569
  #### Products
565
570
 
566
571
  ```js
567
- await client.injectProductElement([
572
+ const components = await client.injectProductElement([
568
573
  { containerId: 'pdp-1', identifier: '00619947000020' },
569
574
  { containerId: 'pdp-2', identifier: '00832889005513' }
570
575
  ]);
576
+
577
+ // Returns: IInjectedComponent[] - Array of component wrappers
578
+ // components[0].rerender() - Rerender the first component
579
+ // components[0].getElement() - Get the container element
580
+ // components[0].getType() - Get component type
571
581
  ```
572
582
 
573
583
  **Identifier types:** UPC, product ID, or Salsify grouping ID
@@ -575,7 +585,12 @@ await client.injectProductElement([
575
585
  #### Cart
576
586
 
577
587
  ```js
578
- await client.injectCartElement('cart-container');
588
+ const component = await client.injectCartElement('cart-container');
589
+
590
+ // Returns: IInjectedComponent | null - Component wrapper or null if failed
591
+ // component.rerender() - Rerender the component
592
+ // component.getElement() - Get the container element
593
+ // component.getType() - Get component type
579
594
  ```
580
595
 
581
596
  **Use case:** Dedicated cart page
@@ -583,7 +598,12 @@ await client.injectCartElement('cart-container');
583
598
  #### Checkout
584
599
 
585
600
  ```js
586
- await client.injectCheckoutElement('checkout-container');
601
+ const component = await client.injectCheckoutElement('checkout-container');
602
+
603
+ // Returns: IInjectedComponent | null - Component wrapper or null if failed
604
+ // component.rerender() - Rerender the component
605
+ // component.getElement() - Get the container element
606
+ // component.getType() - Get component type
587
607
  ```
588
608
 
589
609
  **Use case:** Dedicated checkout page
@@ -591,11 +611,51 @@ await client.injectCheckoutElement('checkout-container');
591
611
  #### Address
592
612
 
593
613
  ```js
594
- await client.injectAddressElement('address-container');
614
+ const component = await client.injectAddressElement('address-container');
615
+
616
+ // Returns: IInjectedComponent | null - Component wrapper or null if failed
617
+ // component.rerender() - Rerender the component
618
+ // component.getElement() - Get the container element
619
+ // component.getType() - Get component type
595
620
  ```
596
621
 
597
622
  **Use case:** Shipping address collection page
598
623
 
624
+ #### Access All Injected Components
625
+
626
+ ```js
627
+ // Get all injected components
628
+ const injectedComponents = client.getInjectedComponents();
629
+
630
+ // Access specific components by container ID
631
+ const productComponent = injectedComponents.get('product-container-1');
632
+ const cartComponent = injectedComponents.get('cart-container');
633
+
634
+ // Iterate through all components
635
+ injectedComponents.forEach((component, containerId) => {
636
+ console.log(`Container: ${containerId}, Type: ${component.getType()}`);
637
+
638
+ // Rerender specific components
639
+ if (component.getType() === 'product') {
640
+ component.rerender();
641
+ }
642
+ });
643
+
644
+ // Get all components of a specific type
645
+ const productComponents = Array.from(injectedComponents.values())
646
+ .filter(component => component.getType() === 'product');
647
+
648
+ // Rerender all components of a type
649
+ productComponents.forEach(component => component.rerender());
650
+ ```
651
+
652
+ **Returns:** `Map<string, IInjectedComponent>` - Map of container IDs to component wrappers
653
+
654
+ **Use cases:**
655
+ - Debugging and inspecting injected components
656
+ - Bulk operations on multiple components
657
+ - Component management and cleanup
658
+
599
659
  ### UI Helpers
600
660
 
601
661
  Create standalone UI elements that integrate with the SDK.
@@ -661,10 +721,12 @@ client.builder.updateCheckoutComponent(checkoutTheme);
661
721
  client.builder.updateAddressComponent(addressTheme);
662
722
 
663
723
  // Builder injection methods (same as regular methods)
664
- await client.builder.injectProductElement(params);
665
- await client.builder.injectCartElement(containerId);
666
- await client.builder.injectCheckoutElement(containerId);
667
- await client.builder.injectAddressElement(containerId);
724
+ const components = await client.builder.injectProductElement(params);
725
+ const component = await client.builder.injectCartElement(containerId);
726
+ const checkoutComponent = await client.builder.injectCheckoutElement(containerId);
727
+ const addressComponent = await client.builder.injectAddressElement(containerId);
728
+
729
+ // All return IInjectedComponent wrapper objects with rerender(), getElement(), getType() methods
668
730
  ```
669
731
 
670
732
  ## 🎬 Actions
@@ -1583,9 +1645,10 @@ Components are created on-demand using a factory pattern:
1583
1645
 
1584
1646
  ```js
1585
1647
  // When you call:
1586
- await client.injectProductElement([
1648
+ const components = await client.injectProductElement([
1587
1649
  { containerId: 'pdp-1', identifier: 'product-123' }
1588
1650
  ]);
1651
+ // Returns: IInjectedComponent[] - Array of component wrappers
1589
1652
 
1590
1653
  // The SDK:
1591
1654
  // 1. Creates a ProductComponent instance
@@ -1717,7 +1780,7 @@ export default function ProductPage({ productId }: { productId: string }) {
1717
1780
  env: 'production'
1718
1781
  });
1719
1782
 
1720
- await client.injectProductElement([
1783
+ const components = await client.injectProductElement([
1721
1784
  { containerId: 'product-container', identifier: productId }
1722
1785
  ]);
1723
1786
 
@@ -1789,7 +1852,7 @@ await client.injectProductElement([
1789
1852
 
1790
1853
  // cart-page.js
1791
1854
  const client = await getElementsClient();
1792
- await client.injectCartElement('cart-container');
1855
+ const cartComponent = await client.injectCartElement('cart-container');
1793
1856
  ```
1794
1857
 
1795
1858
  ---