stream-engine-widgets 0.3.23 → 0.3.25

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.
@@ -330,16 +330,66 @@ class WidgetManager {
330
330
  convertAPIResponseToConfig(apiResponse) {
331
331
  return convertAPIResponseToConfig(apiResponse);
332
332
  }
333
+ /**
334
+ * Apply dynamic labels to widget config (overrides ANY selector type)
335
+ * When labels are provided, they completely replace the existing selector
336
+ * configuration, regardless of whether it was label-based, content-based, etc.
337
+ *
338
+ * @param widgetConfig - The widget configuration object
339
+ * @param labelsProp - JSON string containing { isAndGroup: boolean, labels: string[] }
340
+ * @returns Updated widget config with labels applied
341
+ */
342
+ applyLabels(widgetConfig, labelsProp) {
343
+ if (!labelsProp || !widgetConfig) {
344
+ return widgetConfig;
345
+ }
346
+ try {
347
+ const labelsData = JSON.parse(labelsProp);
348
+ if (!labelsData || !Array.isArray(labelsData.labels) || labelsData.labels.length === 0) {
349
+ return widgetConfig;
350
+ }
351
+ const existingSelector = widgetConfig?.selector;
352
+ let labelGroups;
353
+ if (labelsData?.isAndGroup) {
354
+ labelGroups = [{
355
+ id: "dynamic-and-group",
356
+ andLabels: labelsData.labels
357
+ }];
358
+ } else {
359
+ labelGroups = labelsData.labels.map((label, index) => ({
360
+ id: `dynamic-or-${index}`,
361
+ andLabels: [label]
362
+ }));
363
+ }
364
+ return {
365
+ ...widgetConfig,
366
+ selector: {
367
+ source: "labels",
368
+ // Force label-based filtering
369
+ sortBy: existingSelector?.sortBy,
370
+ // Preserve sort order if any
371
+ labels: {
372
+ labelGroups
373
+ }
374
+ }
375
+ };
376
+ } catch (error) {
377
+ console.error("Error applying labels:", error);
378
+ return widgetConfig;
379
+ }
380
+ }
333
381
  /**
334
382
  * Create a new widget instance
335
383
  */
336
384
  async createWidget(config) {
337
- const widgetConfig = "type" in config && config.type === "blaze" ? {
338
- ...this.convertAPIResponseToConfig(config),
339
- // Preserve all additional properties (eventHandlers, requireAuth, viewerCountry, etc.) added by BlazeWidget.tsx
340
- ...config
385
+ const labels = config?.labels;
386
+ let widgetConfig = "type" in config && config.type === "blaze" ? {
387
+ ...config,
388
+ ...this.convertAPIResponseToConfig(config)
341
389
  } : config;
390
+ widgetConfig = this.applyLabels(widgetConfig, labels);
342
391
  if (this.widgets.has(widgetConfig?.containerId)) {
392
+ console.warn("⚠️ Widget Manager - Destroying existing widget with same containerId:", widgetConfig.containerId);
343
393
  this.destroyWidget(widgetConfig.containerId);
344
394
  }
345
395
  if (!blazeSDKManager.isReady()) {
@@ -462,20 +512,24 @@ const BlazeWidget = ({
462
512
  data,
463
513
  viewerCountry,
464
514
  requireAuth,
465
- eventHandlers
515
+ eventHandlers,
516
+ labels
466
517
  }) => {
467
518
  const containerRef = useRef(null);
468
519
  const [error, setError] = useState(null);
469
520
  const [loading, setLoading] = useState(true);
470
521
  const widgetRef = useRef(null);
471
- const initializeWidget = useCallback(async (widgetData) => {
522
+ const uniqueContainerId = useRef(
523
+ `blaze-widget-${crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36).substring(2, 15)}`
524
+ );
525
+ const initializeWidget = useCallback(async (widgetData, labelsProp) => {
472
526
  try {
473
527
  setError(null);
474
528
  setLoading(true);
475
529
  if (!containerRef?.current) {
476
530
  throw new Error("Container ref not available");
477
531
  }
478
- const widgetContainerId = widgetData.containerId || `blaze-widget-${crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36).substring(2, 15)}`;
532
+ const widgetContainerId = uniqueContainerId.current;
479
533
  if (containerRef?.current) {
480
534
  containerRef.current.id = widgetContainerId;
481
535
  const width = widgetData?.settings?.width || "100%";
@@ -500,6 +554,8 @@ const BlazeWidget = ({
500
554
  viewerCountry: effectiveViewerCountry,
501
555
  containerId: widgetContainerId,
502
556
  requireAuth,
557
+ // Pass labels for override (only present when context_enabled=true)
558
+ labels: labelsProp,
503
559
  // Pass event handlers for Blaze SDK delegates - MUST be last
504
560
  eventHandlers
505
561
  };
@@ -512,22 +568,23 @@ const BlazeWidget = ({
512
568
  } finally {
513
569
  setLoading(false);
514
570
  }
515
- }, []);
571
+ }, [viewerCountry, requireAuth, eventHandlers, uniqueContainerId]);
516
572
  useEffect(() => {
517
573
  if (!data) return;
518
- initializeWidget(data);
519
- }, [data, initializeWidget]);
574
+ initializeWidget(data, labels);
575
+ }, [data, labels, initializeWidget]);
520
576
  useEffect(() => {
577
+ const containerId = uniqueContainerId.current;
521
578
  return () => {
522
- if (widgetRef?.current && containerRef?.current) {
523
- widgetManager.destroyWidget(containerRef.current.id);
579
+ if (widgetRef?.current) {
580
+ widgetManager.destroyWidget(containerId);
524
581
  widgetRef.current = null;
525
582
  }
526
583
  };
527
- }, []);
584
+ }, [uniqueContainerId]);
528
585
  if (error) return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
529
- return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { id: containerRef.current?.id, ref: containerRef, children: loading && /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, {}) });
586
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { id: uniqueContainerId.current, ref: containerRef, children: loading && /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, {}) });
530
587
  };
531
588
 
532
589
  export { BlazeWidget as default };
533
- //# sourceMappingURL=blaze-CFK3LEal.js.map
590
+ //# sourceMappingURL=blaze-CKjlj6PD.js.map