stream-engine-widgets 0.3.23 → 0.3.24
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/{blaze-CFK3LEal.js → blaze-CKj9JmQ1.js} +70 -12
- package/dist/{blaze-CFK3LEal.js.map → blaze-CKj9JmQ1.js.map} +1 -1
- package/dist/getPrototypeOf-a55cCBEE.js +32 -0
- package/dist/getPrototypeOf-a55cCBEE.js.map +1 -0
- package/dist/{story-Cpvsn3p0.js → story-CUXTTEzQ.js} +2 -31
- package/dist/story-CUXTTEzQ.js.map +1 -0
- package/dist/stream-engine-widgets.css +3 -0
- package/dist/stream-engine-widgets.js +2454 -1872
- package/dist/stream-engine-widgets.js.map +1 -1
- package/package.json +1 -1
- package/dist/story-Cpvsn3p0.js.map +0 -1
|
@@ -330,16 +330,67 @@ 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
|
|
385
|
+
const labels = config?.labels;
|
|
386
|
+
let widgetConfig = "type" in config && config.type === "blaze" ? {
|
|
338
387
|
...this.convertAPIResponseToConfig(config),
|
|
339
388
|
// Preserve all additional properties (eventHandlers, requireAuth, viewerCountry, etc.) added by BlazeWidget.tsx
|
|
340
389
|
...config
|
|
341
390
|
} : config;
|
|
391
|
+
widgetConfig = this.applyLabels(widgetConfig, labels);
|
|
342
392
|
if (this.widgets.has(widgetConfig?.containerId)) {
|
|
393
|
+
console.warn("⚠️ Widget Manager - Destroying existing widget with same containerId:", widgetConfig.containerId);
|
|
343
394
|
this.destroyWidget(widgetConfig.containerId);
|
|
344
395
|
}
|
|
345
396
|
if (!blazeSDKManager.isReady()) {
|
|
@@ -462,20 +513,24 @@ const BlazeWidget = ({
|
|
|
462
513
|
data,
|
|
463
514
|
viewerCountry,
|
|
464
515
|
requireAuth,
|
|
465
|
-
eventHandlers
|
|
516
|
+
eventHandlers,
|
|
517
|
+
labels
|
|
466
518
|
}) => {
|
|
467
519
|
const containerRef = useRef(null);
|
|
468
520
|
const [error, setError] = useState(null);
|
|
469
521
|
const [loading, setLoading] = useState(true);
|
|
470
522
|
const widgetRef = useRef(null);
|
|
471
|
-
const
|
|
523
|
+
const uniqueContainerId = useRef(
|
|
524
|
+
`blaze-widget-${crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36).substring(2, 15)}`
|
|
525
|
+
);
|
|
526
|
+
const initializeWidget = useCallback(async (widgetData, labelsProp) => {
|
|
472
527
|
try {
|
|
473
528
|
setError(null);
|
|
474
529
|
setLoading(true);
|
|
475
530
|
if (!containerRef?.current) {
|
|
476
531
|
throw new Error("Container ref not available");
|
|
477
532
|
}
|
|
478
|
-
const widgetContainerId =
|
|
533
|
+
const widgetContainerId = uniqueContainerId.current;
|
|
479
534
|
if (containerRef?.current) {
|
|
480
535
|
containerRef.current.id = widgetContainerId;
|
|
481
536
|
const width = widgetData?.settings?.width || "100%";
|
|
@@ -500,6 +555,8 @@ const BlazeWidget = ({
|
|
|
500
555
|
viewerCountry: effectiveViewerCountry,
|
|
501
556
|
containerId: widgetContainerId,
|
|
502
557
|
requireAuth,
|
|
558
|
+
// Pass labels for override (only present when context_enabled=true)
|
|
559
|
+
labels: labelsProp,
|
|
503
560
|
// Pass event handlers for Blaze SDK delegates - MUST be last
|
|
504
561
|
eventHandlers
|
|
505
562
|
};
|
|
@@ -512,22 +569,23 @@ const BlazeWidget = ({
|
|
|
512
569
|
} finally {
|
|
513
570
|
setLoading(false);
|
|
514
571
|
}
|
|
515
|
-
}, []);
|
|
572
|
+
}, [viewerCountry, requireAuth, eventHandlers, uniqueContainerId]);
|
|
516
573
|
useEffect(() => {
|
|
517
574
|
if (!data) return;
|
|
518
|
-
initializeWidget(data);
|
|
519
|
-
}, [data, initializeWidget]);
|
|
575
|
+
initializeWidget(data, labels);
|
|
576
|
+
}, [data, labels, initializeWidget]);
|
|
520
577
|
useEffect(() => {
|
|
578
|
+
const containerId = uniqueContainerId.current;
|
|
521
579
|
return () => {
|
|
522
|
-
if (widgetRef?.current
|
|
523
|
-
widgetManager.destroyWidget(
|
|
580
|
+
if (widgetRef?.current) {
|
|
581
|
+
widgetManager.destroyWidget(containerId);
|
|
524
582
|
widgetRef.current = null;
|
|
525
583
|
}
|
|
526
584
|
};
|
|
527
|
-
}, []);
|
|
585
|
+
}, [uniqueContainerId]);
|
|
528
586
|
if (error) return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
|
|
529
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { id:
|
|
587
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { id: uniqueContainerId.current, ref: containerRef, children: loading && /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, {}) });
|
|
530
588
|
};
|
|
531
589
|
|
|
532
590
|
export { BlazeWidget as default };
|
|
533
|
-
//# sourceMappingURL=blaze-
|
|
591
|
+
//# sourceMappingURL=blaze-CKj9JmQ1.js.map
|