@ninetailed/experience.js-plugin-preview 7.18.8 → 7.18.10

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/index.cjs.js CHANGED
@@ -371,6 +371,14 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
371
371
  [curr]: this.experienceVariantIndexes[curr] || 0
372
372
  });
373
373
  }, {}));
374
+ this.experiences.filter(experience => {
375
+ var _b;
376
+ return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
377
+ }).forEach(experience => {
378
+ const variantIndex = this.experienceVariantIndexOverwrites[experience.id] || 0;
379
+ // Keep inline variable flags in sync when forcing an audience.
380
+ this.applyInlineVariableOverridesForExperience(experience, variantIndex);
381
+ });
374
382
  this.onChange();
375
383
  }
376
384
  deactivateAudience(id) {
@@ -417,6 +425,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
417
425
  this.audienceOverwrites = audienceOverwrites;
418
426
  this.onChange();
419
427
  }
428
+ // This is exposed to the window api but not used
420
429
  setExperienceVariant({
421
430
  experienceId,
422
431
  variantIndex
@@ -444,21 +453,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
444
453
  this.experienceVariantIndexOverwrites = Object.assign(Object.assign({}, this.experienceVariantIndexOverwrites), {
445
454
  [experienceId]: variantIndex
446
455
  });
447
- // Process all components to extract variable values
448
- experience.components.forEach(component => {
449
- var _b, _c;
450
- if (component.type === experience_jsShared.ComponentTypeEnum.InlineVariable) {
451
- const key = component.key;
452
- const value = variantIndex === 0 ? component.baseline.value : (_c = (_b = component.variants[variantIndex - 1]) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : component.baseline.value;
453
- // Set the variable value
454
- this.setVariableValue({
455
- experienceId,
456
- key,
457
- value,
458
- variantIndex
459
- });
460
- }
461
- });
456
+ this.applyInlineVariableOverridesForExperience(experience, variantIndex);
462
457
  // Trigger change notification - this updates the middleware
463
458
  this.onChange();
464
459
  }
@@ -533,7 +528,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
533
528
  get pluginApi() {
534
529
  var _b;
535
530
  return {
536
- version: "7.18.8" ,
531
+ version: "7.18.10" ,
537
532
  open: this.open.bind(this),
538
533
  close: this.close.bind(this),
539
534
  toggle: this.toggle.bind(this),
@@ -624,6 +619,48 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
624
619
  getOverrideKey(experienceId, key) {
625
620
  return `${experienceId}:${key}`;
626
621
  }
622
+ /**
623
+ * Ensure inline variables for a given experience reflect the selected variant
624
+ * without triggering multiple onChange calls. Keeps custom flags in sync with forced variants.
625
+ */
626
+ applyInlineVariableOverridesForExperience(experience, variantIndex) {
627
+ const {
628
+ hasChanges,
629
+ overrides
630
+ } = experience.components.reduce((acc, component) => {
631
+ var _b, _c, _d;
632
+ if (component.type !== experience_jsShared.ComponentTypeEnum.InlineVariable) {
633
+ return acc;
634
+ }
635
+ const value = variantIndex === 0 ? component.baseline.value : (_c = (_b = component.variants[variantIndex - 1]) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : component.baseline.value;
636
+ const overrideKey = this.getOverrideKey(experience.id, component.key);
637
+ const currentOverride = acc.overrides[overrideKey];
638
+ const nextChange = {
639
+ type: experience_jsShared.ChangeTypes.Variable,
640
+ key: component.key,
641
+ value,
642
+ meta: {
643
+ experienceId: experience.id,
644
+ variantIndex
645
+ }
646
+ };
647
+ if (currentOverride && radash.isEqual(currentOverride.value, value) && ((_d = currentOverride.meta) === null || _d === void 0 ? void 0 : _d.variantIndex) === variantIndex) {
648
+ return acc;
649
+ }
650
+ return {
651
+ hasChanges: true,
652
+ overrides: Object.assign(Object.assign({}, acc.overrides), {
653
+ [overrideKey]: nextChange
654
+ })
655
+ };
656
+ }, {
657
+ hasChanges: false,
658
+ overrides: Object.assign({}, this.variableOverwrites)
659
+ });
660
+ if (hasChanges) {
661
+ this.variableOverwrites = overrides;
662
+ }
663
+ }
627
664
  /**
628
665
  * Get effective changes by applying overwrites - compute on demand
629
666
  */
package/index.esm.js CHANGED
@@ -348,6 +348,15 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
348
348
  [curr]: this.experienceVariantIndexes[curr] || 0
349
349
  });
350
350
  }, {}));
351
+ this.experiences.filter(experience => {
352
+ var _experience$audience3;
353
+ return ((_experience$audience3 = experience.audience) == null ? void 0 : _experience$audience3.id) === id;
354
+ }).forEach(experience => {
355
+ const variantIndex = this.experienceVariantIndexOverwrites[experience.id] || 0;
356
+
357
+ // Keep inline variable flags in sync when forcing an audience.
358
+ this.applyInlineVariableOverridesForExperience(experience, variantIndex);
359
+ });
351
360
  this.onChange();
352
361
  }
353
362
  deactivateAudience(id) {
@@ -374,8 +383,8 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
374
383
 
375
384
  // Identify all experiences that belong to this audience
376
385
  const experiencesToReset = this.experiences.filter(experience => {
377
- var _experience$audience3;
378
- return ((_experience$audience3 = experience.audience) == null ? void 0 : _experience$audience3.id) === id;
386
+ var _experience$audience4;
387
+ return ((_experience$audience4 = experience.audience) == null ? void 0 : _experience$audience4.id) === id;
379
388
  });
380
389
  if (experiencesToReset.length > 0) {
381
390
  const experienceIdsToReset = experiencesToReset.map(e => e.id);
@@ -396,6 +405,8 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
396
405
  this.audienceOverwrites = audienceOverwrites;
397
406
  this.onChange();
398
407
  }
408
+
409
+ // This is exposed to the window api but not used
399
410
  setExperienceVariant({
400
411
  experienceId,
401
412
  variantIndex
@@ -409,8 +420,8 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
409
420
  return;
410
421
  }
411
422
  if (experience.audience && !this.activeAudiences.some(id => {
412
- var _experience$audience4;
413
- return id === ((_experience$audience4 = experience.audience) == null ? void 0 : _experience$audience4.id);
423
+ var _experience$audience5;
424
+ return id === ((_experience$audience5 = experience.audience) == null ? void 0 : _experience$audience5.id);
414
425
  })) {
415
426
  logger.warn(`Cannot activate a variant for an experience (id: ${experienceId}) which is not in the active audiences.`);
416
427
  return;
@@ -424,23 +435,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
424
435
  this.experienceVariantIndexOverwrites = Object.assign({}, this.experienceVariantIndexOverwrites, {
425
436
  [experienceId]: variantIndex
426
437
  });
427
-
428
- // Process all components to extract variable values
429
- experience.components.forEach(component => {
430
- if (component.type === ComponentTypeEnum.InlineVariable) {
431
- var _component$variants$v, _component$variants;
432
- const key = component.key;
433
- const value = variantIndex === 0 ? component.baseline.value : (_component$variants$v = (_component$variants = component.variants[variantIndex - 1]) == null ? void 0 : _component$variants.value) != null ? _component$variants$v : component.baseline.value;
434
-
435
- // Set the variable value
436
- this.setVariableValue({
437
- experienceId,
438
- key,
439
- value,
440
- variantIndex
441
- });
442
- }
443
- });
438
+ this.applyInlineVariableOverridesForExperience(experience, variantIndex);
444
439
 
445
440
  // Trigger change notification - this updates the middleware
446
441
  this.onChange();
@@ -518,7 +513,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
518
513
  get pluginApi() {
519
514
  var _this$profile;
520
515
  return {
521
- version: "7.18.8" ,
516
+ version: "7.18.10" ,
522
517
  open: this.open.bind(this),
523
518
  close: this.close.bind(this),
524
519
  toggle: this.toggle.bind(this),
@@ -611,6 +606,49 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
611
606
  return `${experienceId}:${key}`;
612
607
  }
613
608
 
609
+ /**
610
+ * Ensure inline variables for a given experience reflect the selected variant
611
+ * without triggering multiple onChange calls. Keeps custom flags in sync with forced variants.
612
+ */
613
+ applyInlineVariableOverridesForExperience(experience, variantIndex) {
614
+ const {
615
+ hasChanges,
616
+ overrides
617
+ } = experience.components.reduce((acc, component) => {
618
+ var _component$variants$v, _component$variants, _currentOverride$meta;
619
+ if (component.type !== ComponentTypeEnum.InlineVariable) {
620
+ return acc;
621
+ }
622
+ const value = variantIndex === 0 ? component.baseline.value : (_component$variants$v = (_component$variants = component.variants[variantIndex - 1]) == null ? void 0 : _component$variants.value) != null ? _component$variants$v : component.baseline.value;
623
+ const overrideKey = this.getOverrideKey(experience.id, component.key);
624
+ const currentOverride = acc.overrides[overrideKey];
625
+ const nextChange = {
626
+ type: ChangeTypes.Variable,
627
+ key: component.key,
628
+ value,
629
+ meta: {
630
+ experienceId: experience.id,
631
+ variantIndex
632
+ }
633
+ };
634
+ if (currentOverride && isEqual(currentOverride.value, value) && ((_currentOverride$meta = currentOverride.meta) == null ? void 0 : _currentOverride$meta.variantIndex) === variantIndex) {
635
+ return acc;
636
+ }
637
+ return {
638
+ hasChanges: true,
639
+ overrides: Object.assign({}, acc.overrides, {
640
+ [overrideKey]: nextChange
641
+ })
642
+ };
643
+ }, {
644
+ hasChanges: false,
645
+ overrides: Object.assign({}, this.variableOverwrites)
646
+ });
647
+ if (hasChanges) {
648
+ this.variableOverwrites = overrides;
649
+ }
650
+ }
651
+
614
652
  /**
615
653
  * Get effective changes by applying overwrites - compute on demand
616
654
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-plugin-preview",
3
- "version": "7.18.8",
3
+ "version": "7.18.10",
4
4
  "description": "Ninetailed SDK plugin for preview",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "sideEffects": false,
30
30
  "dependencies": {
31
- "@ninetailed/experience.js-shared": "7.18.8",
32
- "@ninetailed/experience.js": "7.18.8",
33
- "@ninetailed/experience.js-preview-bridge": "7.18.8",
34
- "@ninetailed/experience.js-plugin-analytics": "7.18.8",
31
+ "@ninetailed/experience.js-shared": "7.18.10",
32
+ "@ninetailed/experience.js": "7.18.10",
33
+ "@ninetailed/experience.js-preview-bridge": "7.18.10",
34
+ "@ninetailed/experience.js-plugin-analytics": "7.18.10",
35
35
  "radash": "10.9.0"
36
36
  }
37
37
  }
@@ -84,6 +84,11 @@ export declare class NinetailedPreviewPlugin extends NinetailedPlugin implements
84
84
  * Get the override key for a variable
85
85
  */
86
86
  private getOverrideKey;
87
+ /**
88
+ * Ensure inline variables for a given experience reflect the selected variant
89
+ * without triggering multiple onChange calls. Keeps custom flags in sync with forced variants.
90
+ */
91
+ private applyInlineVariableOverridesForExperience;
87
92
  /**
88
93
  * Get effective changes by applying overwrites - compute on demand
89
94
  */