@ninetailed/experience.js-plugin-preview 4.0.0-beta.9 → 4.1.0-beta.1
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 +199 -140
- package/index.js +195 -140
- package/lib/plugin/NinetailedPreviewPlugin.d.ts +5 -3
- package/package.json +9 -8
package/index.cjs
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var omit = require('lodash/omit');
|
|
5
6
|
var experience_js = require('@ninetailed/experience.js');
|
|
6
|
-
var experience_jsPluginAnalytics = require('@ninetailed/experience.js-plugin-analytics');
|
|
7
7
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
8
|
var react = require('react');
|
|
9
9
|
var uuid = require('uuid');
|
|
10
10
|
|
|
11
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
+
|
|
11
13
|
function _interopNamespace(e) {
|
|
12
14
|
if (e && e.__esModule) return e;
|
|
13
15
|
var n = Object.create(null);
|
|
@@ -26,6 +28,8 @@ function _interopNamespace(e) {
|
|
|
26
28
|
return Object.freeze(n);
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
|
|
32
|
+
|
|
29
33
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
30
34
|
|
|
31
35
|
var check = function (it) {
|
|
@@ -2432,9 +2436,99 @@ var addToUnscopables$2 = function (key) {
|
|
|
2432
2436
|
ArrayPrototype[UNSCOPABLES][key] = true;
|
|
2433
2437
|
};
|
|
2434
2438
|
|
|
2439
|
+
var $$3 = _export;
|
|
2440
|
+
var $includes = arrayIncludes.includes;
|
|
2435
2441
|
var fails$3 = fails$f;
|
|
2442
|
+
var addToUnscopables$1 = addToUnscopables$2;
|
|
2443
|
+
|
|
2444
|
+
// FF99+ bug
|
|
2445
|
+
var BROKEN_ON_SPARSE = fails$3(function () {
|
|
2446
|
+
return !Array(1).includes();
|
|
2447
|
+
});
|
|
2448
|
+
|
|
2449
|
+
// `Array.prototype.includes` method
|
|
2450
|
+
// https://tc39.es/ecma262/#sec-array.prototype.includes
|
|
2451
|
+
$$3({ target: 'Array', proto: true, forced: BROKEN_ON_SPARSE }, {
|
|
2452
|
+
includes: function includes(el /* , fromIndex = 0 */) {
|
|
2453
|
+
return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined);
|
|
2454
|
+
}
|
|
2455
|
+
});
|
|
2456
|
+
|
|
2457
|
+
// https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
|
|
2458
|
+
addToUnscopables$1('includes');
|
|
2459
|
+
|
|
2460
|
+
var isObject$1 = isObject$9;
|
|
2461
|
+
var classof$1 = classofRaw$2;
|
|
2462
|
+
var wellKnownSymbol$4 = wellKnownSymbol$g;
|
|
2463
|
+
|
|
2464
|
+
var MATCH$1 = wellKnownSymbol$4('match');
|
|
2465
|
+
|
|
2466
|
+
// `IsRegExp` abstract operation
|
|
2467
|
+
// https://tc39.es/ecma262/#sec-isregexp
|
|
2468
|
+
var isRegexp = function (it) {
|
|
2469
|
+
var isRegExp;
|
|
2470
|
+
return isObject$1(it) && ((isRegExp = it[MATCH$1]) !== undefined ? !!isRegExp : classof$1(it) == 'RegExp');
|
|
2471
|
+
};
|
|
2472
|
+
|
|
2473
|
+
var isRegExp = isRegexp;
|
|
2474
|
+
|
|
2475
|
+
var $TypeError$1 = TypeError;
|
|
2476
|
+
|
|
2477
|
+
var notARegexp = function (it) {
|
|
2478
|
+
if (isRegExp(it)) {
|
|
2479
|
+
throw $TypeError$1("The method doesn't accept regular expressions");
|
|
2480
|
+
} return it;
|
|
2481
|
+
};
|
|
2482
|
+
|
|
2483
|
+
var classof = classof$4;
|
|
2484
|
+
|
|
2485
|
+
var $String = String;
|
|
2486
|
+
|
|
2487
|
+
var toString$1 = function (argument) {
|
|
2488
|
+
if (classof(argument) === 'Symbol') throw TypeError('Cannot convert a Symbol value to a string');
|
|
2489
|
+
return $String(argument);
|
|
2490
|
+
};
|
|
2491
|
+
|
|
2492
|
+
var wellKnownSymbol$3 = wellKnownSymbol$g;
|
|
2436
2493
|
|
|
2437
|
-
var
|
|
2494
|
+
var MATCH = wellKnownSymbol$3('match');
|
|
2495
|
+
|
|
2496
|
+
var correctIsRegexpLogic = function (METHOD_NAME) {
|
|
2497
|
+
var regexp = /./;
|
|
2498
|
+
try {
|
|
2499
|
+
'/./'[METHOD_NAME](regexp);
|
|
2500
|
+
} catch (error1) {
|
|
2501
|
+
try {
|
|
2502
|
+
regexp[MATCH] = false;
|
|
2503
|
+
return '/./'[METHOD_NAME](regexp);
|
|
2504
|
+
} catch (error2) { /* empty */ }
|
|
2505
|
+
} return false;
|
|
2506
|
+
};
|
|
2507
|
+
|
|
2508
|
+
var $$2 = _export;
|
|
2509
|
+
var uncurryThis = functionUncurryThis;
|
|
2510
|
+
var notARegExp = notARegexp;
|
|
2511
|
+
var requireObjectCoercible = requireObjectCoercible$3;
|
|
2512
|
+
var toString = toString$1;
|
|
2513
|
+
var correctIsRegExpLogic = correctIsRegexpLogic;
|
|
2514
|
+
|
|
2515
|
+
var stringIndexOf = uncurryThis(''.indexOf);
|
|
2516
|
+
|
|
2517
|
+
// `String.prototype.includes` method
|
|
2518
|
+
// https://tc39.es/ecma262/#sec-string.prototype.includes
|
|
2519
|
+
$$2({ target: 'String', proto: true, forced: !correctIsRegExpLogic('includes') }, {
|
|
2520
|
+
includes: function includes(searchString /* , position = 0 */) {
|
|
2521
|
+
return !!~stringIndexOf(
|
|
2522
|
+
toString(requireObjectCoercible(this)),
|
|
2523
|
+
toString(notARegExp(searchString)),
|
|
2524
|
+
arguments.length > 1 ? arguments[1] : undefined
|
|
2525
|
+
);
|
|
2526
|
+
}
|
|
2527
|
+
});
|
|
2528
|
+
|
|
2529
|
+
var fails$2 = fails$f;
|
|
2530
|
+
|
|
2531
|
+
var correctPrototypeGetter = !fails$2(function () {
|
|
2438
2532
|
function F() { /* empty */ }
|
|
2439
2533
|
F.prototype.constructor = null;
|
|
2440
2534
|
// eslint-disable-next-line es/no-object-getprototypeof -- required for testing
|
|
@@ -2463,14 +2557,14 @@ var objectGetPrototypeOf = CORRECT_PROTOTYPE_GETTER ? $Object.getPrototypeOf : f
|
|
|
2463
2557
|
} return object instanceof $Object ? ObjectPrototype : null;
|
|
2464
2558
|
};
|
|
2465
2559
|
|
|
2466
|
-
var fails$
|
|
2560
|
+
var fails$1 = fails$f;
|
|
2467
2561
|
var isCallable$1 = isCallable$k;
|
|
2468
|
-
var isObject
|
|
2562
|
+
var isObject = isObject$9;
|
|
2469
2563
|
var getPrototypeOf$1 = objectGetPrototypeOf;
|
|
2470
2564
|
var defineBuiltIn$1 = defineBuiltIn$5;
|
|
2471
|
-
var wellKnownSymbol$
|
|
2565
|
+
var wellKnownSymbol$2 = wellKnownSymbol$g;
|
|
2472
2566
|
|
|
2473
|
-
var ITERATOR$2 = wellKnownSymbol$
|
|
2567
|
+
var ITERATOR$2 = wellKnownSymbol$2('iterator');
|
|
2474
2568
|
var BUGGY_SAFARI_ITERATORS$1 = false;
|
|
2475
2569
|
|
|
2476
2570
|
// `%IteratorPrototype%` object
|
|
@@ -2488,7 +2582,7 @@ if ([].keys) {
|
|
|
2488
2582
|
}
|
|
2489
2583
|
}
|
|
2490
2584
|
|
|
2491
|
-
var NEW_ITERATOR_PROTOTYPE = !isObject
|
|
2585
|
+
var NEW_ITERATOR_PROTOTYPE = !isObject(IteratorPrototype$2) || fails$1(function () {
|
|
2492
2586
|
var test = {};
|
|
2493
2587
|
// FF44- legacy iterators case
|
|
2494
2588
|
return IteratorPrototype$2[ITERATOR$2].call(test) !== test;
|
|
@@ -2525,7 +2619,7 @@ var iteratorCreateConstructor = function (IteratorConstructor, NAME, next, ENUME
|
|
|
2525
2619
|
return IteratorConstructor;
|
|
2526
2620
|
};
|
|
2527
2621
|
|
|
2528
|
-
var $$
|
|
2622
|
+
var $$1 = _export;
|
|
2529
2623
|
var call = functionCall;
|
|
2530
2624
|
var FunctionName = functionName;
|
|
2531
2625
|
var isCallable = isCallable$k;
|
|
@@ -2535,7 +2629,7 @@ var setPrototypeOf = objectSetPrototypeOf;
|
|
|
2535
2629
|
var setToStringTag = setToStringTag$3;
|
|
2536
2630
|
var createNonEnumerableProperty$1 = createNonEnumerableProperty$4;
|
|
2537
2631
|
var defineBuiltIn = defineBuiltIn$5;
|
|
2538
|
-
var wellKnownSymbol$
|
|
2632
|
+
var wellKnownSymbol$1 = wellKnownSymbol$g;
|
|
2539
2633
|
var Iterators$1 = iterators;
|
|
2540
2634
|
var IteratorsCore = iteratorsCore;
|
|
2541
2635
|
|
|
@@ -2543,7 +2637,7 @@ var PROPER_FUNCTION_NAME = FunctionName.PROPER;
|
|
|
2543
2637
|
var CONFIGURABLE_FUNCTION_NAME = FunctionName.CONFIGURABLE;
|
|
2544
2638
|
var IteratorPrototype = IteratorsCore.IteratorPrototype;
|
|
2545
2639
|
var BUGGY_SAFARI_ITERATORS = IteratorsCore.BUGGY_SAFARI_ITERATORS;
|
|
2546
|
-
var ITERATOR$1 = wellKnownSymbol$
|
|
2640
|
+
var ITERATOR$1 = wellKnownSymbol$1('iterator');
|
|
2547
2641
|
var KEYS = 'keys';
|
|
2548
2642
|
var VALUES = 'values';
|
|
2549
2643
|
var ENTRIES = 'entries';
|
|
@@ -2610,7 +2704,7 @@ var iteratorDefine = function (Iterable, NAME, IteratorConstructor, next, DEFAUL
|
|
|
2610
2704
|
if (BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME || !(KEY in IterablePrototype)) {
|
|
2611
2705
|
defineBuiltIn(IterablePrototype, KEY, methods[KEY]);
|
|
2612
2706
|
}
|
|
2613
|
-
} else $$
|
|
2707
|
+
} else $$1({ target: NAME, proto: true, forced: BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME }, methods);
|
|
2614
2708
|
}
|
|
2615
2709
|
|
|
2616
2710
|
// define iterator
|
|
@@ -2629,7 +2723,7 @@ var createIterResultObject$1 = function (value, done) {
|
|
|
2629
2723
|
};
|
|
2630
2724
|
|
|
2631
2725
|
var toIndexedObject = toIndexedObject$5;
|
|
2632
|
-
var addToUnscopables
|
|
2726
|
+
var addToUnscopables = addToUnscopables$2;
|
|
2633
2727
|
var Iterators = iterators;
|
|
2634
2728
|
var InternalStateModule = internalState;
|
|
2635
2729
|
var defineProperty = objectDefineProperty.f;
|
|
@@ -2680,9 +2774,9 @@ var es_array_iterator = defineIterator(Array, 'Array', function (iterated, kind)
|
|
|
2680
2774
|
var values = Iterators.Arguments = Iterators.Array;
|
|
2681
2775
|
|
|
2682
2776
|
// https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
|
|
2683
|
-
addToUnscopables
|
|
2684
|
-
addToUnscopables
|
|
2685
|
-
addToUnscopables
|
|
2777
|
+
addToUnscopables('keys');
|
|
2778
|
+
addToUnscopables('values');
|
|
2779
|
+
addToUnscopables('entries');
|
|
2686
2780
|
|
|
2687
2781
|
// V8 ~ Chrome 45- bug
|
|
2688
2782
|
if (DESCRIPTORS && values.name !== 'values') try {
|
|
@@ -2738,10 +2832,10 @@ var DOMIterables = domIterables;
|
|
|
2738
2832
|
var DOMTokenListPrototype = domTokenListPrototype;
|
|
2739
2833
|
var ArrayIteratorMethods = es_array_iterator;
|
|
2740
2834
|
var createNonEnumerableProperty = createNonEnumerableProperty$4;
|
|
2741
|
-
var wellKnownSymbol
|
|
2835
|
+
var wellKnownSymbol = wellKnownSymbol$g;
|
|
2742
2836
|
|
|
2743
|
-
var ITERATOR = wellKnownSymbol
|
|
2744
|
-
var TO_STRING_TAG = wellKnownSymbol
|
|
2837
|
+
var ITERATOR = wellKnownSymbol('iterator');
|
|
2838
|
+
var TO_STRING_TAG = wellKnownSymbol('toStringTag');
|
|
2745
2839
|
var ArrayValues = ArrayIteratorMethods.values;
|
|
2746
2840
|
|
|
2747
2841
|
var handlePrototype = function (CollectionPrototype, COLLECTION_NAME) {
|
|
@@ -2772,96 +2866,6 @@ for (var COLLECTION_NAME in DOMIterables) {
|
|
|
2772
2866
|
|
|
2773
2867
|
handlePrototype(DOMTokenListPrototype, 'DOMTokenList');
|
|
2774
2868
|
|
|
2775
|
-
var $$2 = _export;
|
|
2776
|
-
var $includes = arrayIncludes.includes;
|
|
2777
|
-
var fails$1 = fails$f;
|
|
2778
|
-
var addToUnscopables = addToUnscopables$2;
|
|
2779
|
-
|
|
2780
|
-
// FF99+ bug
|
|
2781
|
-
var BROKEN_ON_SPARSE = fails$1(function () {
|
|
2782
|
-
return !Array(1).includes();
|
|
2783
|
-
});
|
|
2784
|
-
|
|
2785
|
-
// `Array.prototype.includes` method
|
|
2786
|
-
// https://tc39.es/ecma262/#sec-array.prototype.includes
|
|
2787
|
-
$$2({ target: 'Array', proto: true, forced: BROKEN_ON_SPARSE }, {
|
|
2788
|
-
includes: function includes(el /* , fromIndex = 0 */) {
|
|
2789
|
-
return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined);
|
|
2790
|
-
}
|
|
2791
|
-
});
|
|
2792
|
-
|
|
2793
|
-
// https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
|
|
2794
|
-
addToUnscopables('includes');
|
|
2795
|
-
|
|
2796
|
-
var isObject = isObject$9;
|
|
2797
|
-
var classof$1 = classofRaw$2;
|
|
2798
|
-
var wellKnownSymbol$1 = wellKnownSymbol$g;
|
|
2799
|
-
|
|
2800
|
-
var MATCH$1 = wellKnownSymbol$1('match');
|
|
2801
|
-
|
|
2802
|
-
// `IsRegExp` abstract operation
|
|
2803
|
-
// https://tc39.es/ecma262/#sec-isregexp
|
|
2804
|
-
var isRegexp = function (it) {
|
|
2805
|
-
var isRegExp;
|
|
2806
|
-
return isObject(it) && ((isRegExp = it[MATCH$1]) !== undefined ? !!isRegExp : classof$1(it) == 'RegExp');
|
|
2807
|
-
};
|
|
2808
|
-
|
|
2809
|
-
var isRegExp = isRegexp;
|
|
2810
|
-
|
|
2811
|
-
var $TypeError$1 = TypeError;
|
|
2812
|
-
|
|
2813
|
-
var notARegexp = function (it) {
|
|
2814
|
-
if (isRegExp(it)) {
|
|
2815
|
-
throw $TypeError$1("The method doesn't accept regular expressions");
|
|
2816
|
-
} return it;
|
|
2817
|
-
};
|
|
2818
|
-
|
|
2819
|
-
var classof = classof$4;
|
|
2820
|
-
|
|
2821
|
-
var $String = String;
|
|
2822
|
-
|
|
2823
|
-
var toString$1 = function (argument) {
|
|
2824
|
-
if (classof(argument) === 'Symbol') throw TypeError('Cannot convert a Symbol value to a string');
|
|
2825
|
-
return $String(argument);
|
|
2826
|
-
};
|
|
2827
|
-
|
|
2828
|
-
var wellKnownSymbol = wellKnownSymbol$g;
|
|
2829
|
-
|
|
2830
|
-
var MATCH = wellKnownSymbol('match');
|
|
2831
|
-
|
|
2832
|
-
var correctIsRegexpLogic = function (METHOD_NAME) {
|
|
2833
|
-
var regexp = /./;
|
|
2834
|
-
try {
|
|
2835
|
-
'/./'[METHOD_NAME](regexp);
|
|
2836
|
-
} catch (error1) {
|
|
2837
|
-
try {
|
|
2838
|
-
regexp[MATCH] = false;
|
|
2839
|
-
return '/./'[METHOD_NAME](regexp);
|
|
2840
|
-
} catch (error2) { /* empty */ }
|
|
2841
|
-
} return false;
|
|
2842
|
-
};
|
|
2843
|
-
|
|
2844
|
-
var $$1 = _export;
|
|
2845
|
-
var uncurryThis = functionUncurryThis;
|
|
2846
|
-
var notARegExp = notARegexp;
|
|
2847
|
-
var requireObjectCoercible = requireObjectCoercible$3;
|
|
2848
|
-
var toString = toString$1;
|
|
2849
|
-
var correctIsRegExpLogic = correctIsRegexpLogic;
|
|
2850
|
-
|
|
2851
|
-
var stringIndexOf = uncurryThis(''.indexOf);
|
|
2852
|
-
|
|
2853
|
-
// `String.prototype.includes` method
|
|
2854
|
-
// https://tc39.es/ecma262/#sec-string.prototype.includes
|
|
2855
|
-
$$1({ target: 'String', proto: true, forced: !correctIsRegExpLogic('includes') }, {
|
|
2856
|
-
includes: function includes(searchString /* , position = 0 */) {
|
|
2857
|
-
return !!~stringIndexOf(
|
|
2858
|
-
toString(requireObjectCoercible(this)),
|
|
2859
|
-
toString(notARegExp(searchString)),
|
|
2860
|
-
arguments.length > 1 ? arguments[1] : undefined
|
|
2861
|
-
);
|
|
2862
|
-
}
|
|
2863
|
-
});
|
|
2864
|
-
|
|
2865
2869
|
var aCallable = aCallable$8;
|
|
2866
2870
|
var toObject = toObject$4;
|
|
2867
2871
|
var IndexedObject = indexedObject;
|
|
@@ -3023,7 +3027,7 @@ class WidgetContainer {
|
|
|
3023
3027
|
}
|
|
3024
3028
|
|
|
3025
3029
|
const PreviewRenderPlugin = ctx => {
|
|
3026
|
-
const
|
|
3030
|
+
const PreviewRenderPlugin = props => {
|
|
3027
3031
|
const [pluginApi, setPluginApi] = react.useState(ctx.pluginApi);
|
|
3028
3032
|
const {
|
|
3029
3033
|
children,
|
|
@@ -3041,37 +3045,41 @@ const PreviewRenderPlugin = ctx => {
|
|
|
3041
3045
|
};
|
|
3042
3046
|
}, [id]);
|
|
3043
3047
|
react.useEffect(() => {
|
|
3044
|
-
const
|
|
3045
|
-
const
|
|
3046
|
-
|
|
3048
|
+
const experienceIds = Object.keys(pluginApi.experienceVariantIndexes);
|
|
3049
|
+
const experience = experiences.find(experience => {
|
|
3050
|
+
const hasActiveAudience = pluginApi.activeAudiences.some(activeAudienceId => {
|
|
3051
|
+
var _a;
|
|
3052
|
+
return ((_a = experience.audience) === null || _a === void 0 ? void 0 : _a.id) === activeAudienceId;
|
|
3053
|
+
});
|
|
3054
|
+
return hasActiveAudience && experienceIds.includes(experience.id);
|
|
3047
3055
|
});
|
|
3048
|
-
if (!
|
|
3049
|
-
setComponentProps(
|
|
3056
|
+
if (!experience) {
|
|
3057
|
+
setComponentProps(baseline);
|
|
3050
3058
|
return;
|
|
3051
3059
|
}
|
|
3052
|
-
const baselineComponent =
|
|
3060
|
+
const baselineComponent = experience.components.find(component => component.baseline.id === baseline.id);
|
|
3053
3061
|
if (!baselineComponent) {
|
|
3054
|
-
setComponentProps(
|
|
3062
|
+
setComponentProps(baseline);
|
|
3055
3063
|
return;
|
|
3056
3064
|
}
|
|
3057
3065
|
const allVariants = [baseline, ...baselineComponent.variants];
|
|
3058
|
-
const variantIndex = pluginApi.
|
|
3066
|
+
const variantIndex = pluginApi.experienceVariantIndexes[experience.id];
|
|
3059
3067
|
if (allVariants.length <= variantIndex) {
|
|
3060
|
-
setComponentProps(
|
|
3068
|
+
setComponentProps(baseline);
|
|
3061
3069
|
return;
|
|
3062
3070
|
}
|
|
3063
3071
|
const variant = allVariants[variantIndex];
|
|
3064
3072
|
if (!variant) {
|
|
3065
|
-
setComponentProps(
|
|
3073
|
+
setComponentProps(baseline);
|
|
3066
3074
|
return;
|
|
3067
3075
|
}
|
|
3068
|
-
setComponentProps(
|
|
3069
|
-
}, [experiences, baseline, setComponentProps, pluginApi.
|
|
3076
|
+
setComponentProps(variant);
|
|
3077
|
+
}, [experiences, baseline, setComponentProps, pluginApi.experienceVariantIndexes, pluginApi.activeAudiences]);
|
|
3070
3078
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
3071
3079
|
children: children
|
|
3072
3080
|
});
|
|
3073
3081
|
};
|
|
3074
|
-
return
|
|
3082
|
+
return PreviewRenderPlugin;
|
|
3075
3083
|
};
|
|
3076
3084
|
|
|
3077
3085
|
class PreviewRenderPluginContext {
|
|
@@ -3092,7 +3100,7 @@ class PreviewRenderPluginContext {
|
|
|
3092
3100
|
}
|
|
3093
3101
|
|
|
3094
3102
|
var _a;
|
|
3095
|
-
class NinetailedPreviewPlugin extends
|
|
3103
|
+
class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
|
|
3096
3104
|
constructor(options) {
|
|
3097
3105
|
super();
|
|
3098
3106
|
this.options = options;
|
|
@@ -3105,6 +3113,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
|
|
|
3105
3113
|
this.container = null;
|
|
3106
3114
|
this.bridge = null;
|
|
3107
3115
|
this.renderPluginContext = new PreviewRenderPluginContext(this.pluginApi);
|
|
3116
|
+
this.onChangeEmitter = new experience_js.OnChangeEmitter();
|
|
3108
3117
|
this.initialize = () => __awaiter(this, void 0, void 0, function* () {
|
|
3109
3118
|
var _b;
|
|
3110
3119
|
if (typeof window !== 'undefined') {
|
|
@@ -3139,8 +3148,56 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
|
|
|
3139
3148
|
this.onProfileChange(payload.profile);
|
|
3140
3149
|
}
|
|
3141
3150
|
};
|
|
3151
|
+
this.getExperienceSelectionMiddleware = ({
|
|
3152
|
+
baseline,
|
|
3153
|
+
experiences
|
|
3154
|
+
}) => {
|
|
3155
|
+
return () => {
|
|
3156
|
+
const experienceIds = Object.keys(this.pluginApi.experienceVariantIndexes);
|
|
3157
|
+
const experience = experiences.find(experience => {
|
|
3158
|
+
const hasActiveAudience = this.pluginApi.activeAudiences.some(activeAudienceId => {
|
|
3159
|
+
var _b;
|
|
3160
|
+
return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === activeAudienceId;
|
|
3161
|
+
});
|
|
3162
|
+
return hasActiveAudience && experienceIds.includes(experience.id);
|
|
3163
|
+
});
|
|
3164
|
+
if (!experience) {
|
|
3165
|
+
return {
|
|
3166
|
+
experience: null,
|
|
3167
|
+
variant: null
|
|
3168
|
+
};
|
|
3169
|
+
}
|
|
3170
|
+
const baselineComponent = experience.components.find(component => component.baseline.id === baseline.id);
|
|
3171
|
+
if (!baselineComponent) {
|
|
3172
|
+
return {
|
|
3173
|
+
experience,
|
|
3174
|
+
variant: null
|
|
3175
|
+
};
|
|
3176
|
+
}
|
|
3177
|
+
const allVariants = [baseline, ...baselineComponent.variants];
|
|
3178
|
+
const variantIndex = this.pluginApi.experienceVariantIndexes[experience.id];
|
|
3179
|
+
if (allVariants.length <= variantIndex) {
|
|
3180
|
+
return {
|
|
3181
|
+
experience,
|
|
3182
|
+
variant: null
|
|
3183
|
+
};
|
|
3184
|
+
}
|
|
3185
|
+
const variant = allVariants[variantIndex];
|
|
3186
|
+
if (!variant) {
|
|
3187
|
+
return {
|
|
3188
|
+
experience,
|
|
3189
|
+
variant: null
|
|
3190
|
+
};
|
|
3191
|
+
}
|
|
3192
|
+
return {
|
|
3193
|
+
experience,
|
|
3194
|
+
variant
|
|
3195
|
+
};
|
|
3196
|
+
};
|
|
3197
|
+
};
|
|
3142
3198
|
this.onChange = () => {
|
|
3143
3199
|
var _b;
|
|
3200
|
+
console.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
|
|
3144
3201
|
Object.assign({}, window.ninetailed, {
|
|
3145
3202
|
plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
|
|
3146
3203
|
preview: this.windowApi
|
|
@@ -3149,9 +3206,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
|
|
|
3149
3206
|
this.bridge.updateProps({
|
|
3150
3207
|
props: this.pluginApi
|
|
3151
3208
|
});
|
|
3152
|
-
|
|
3153
|
-
this.renderPluginContext.setPluginApi(this.pluginApi);
|
|
3154
|
-
}
|
|
3209
|
+
this.onChangeEmitter.invokeListeners();
|
|
3155
3210
|
};
|
|
3156
3211
|
this.onProfileChange = profile => {
|
|
3157
3212
|
this.profile = profile;
|
|
@@ -3189,30 +3244,34 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
|
|
|
3189
3244
|
this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
|
|
3190
3245
|
[id]: true
|
|
3191
3246
|
});
|
|
3192
|
-
this.
|
|
3193
|
-
// When a audience is activated, they should show their natural state
|
|
3194
|
-
this.experiences.filter(experience => {
|
|
3247
|
+
this.experienceVariantIndexOverwrites = Object.assign(Object.assign({}, this.experienceVariantIndexOverwrites), this.experiences.filter(experience => {
|
|
3195
3248
|
var _b;
|
|
3196
3249
|
return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
|
|
3197
|
-
}).
|
|
3198
|
-
|
|
3199
|
-
|
|
3250
|
+
}).map(experience => experience.id).reduce((acc, curr) => {
|
|
3251
|
+
return Object.assign(Object.assign({}, acc), {
|
|
3252
|
+
[curr]: this.experienceVariantIndexes[curr] || 0
|
|
3253
|
+
});
|
|
3254
|
+
}, {}));
|
|
3255
|
+
this.onChange();
|
|
3200
3256
|
}
|
|
3201
3257
|
deactivateAudience(id) {
|
|
3202
3258
|
if (!this.isKnownAudience(id)) {
|
|
3203
3259
|
console.log(`You cannot deactivate an unkown audience (id: ${id}). How did you get it in the first place?`);
|
|
3204
3260
|
return;
|
|
3205
3261
|
}
|
|
3206
|
-
// When a audience is deactivated, the normal state will be that the experience goes into the control
|
|
3207
|
-
this.experiences
|
|
3262
|
+
// // When a audience is deactivated, the normal state will be that the experience goes into the control
|
|
3263
|
+
// this.experiences
|
|
3264
|
+
// .filter((experience) => experience.audience?.id === id)
|
|
3265
|
+
// .forEach((experience) => {
|
|
3266
|
+
// this.setExperienceVariant({
|
|
3267
|
+
// experienceId: experience.id,
|
|
3268
|
+
// variantIndex: 0,
|
|
3269
|
+
// });
|
|
3270
|
+
// });
|
|
3271
|
+
this.experienceVariantIndexOverwrites = omit__default["default"](this.experienceVariantIndexOverwrites, this.experiences.filter(experience => {
|
|
3208
3272
|
var _b;
|
|
3209
3273
|
return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
|
|
3210
|
-
}).
|
|
3211
|
-
this.setExperienceVariant({
|
|
3212
|
-
experienceId: experience.id,
|
|
3213
|
-
variantIndex: 0
|
|
3214
|
-
});
|
|
3215
|
-
});
|
|
3274
|
+
}).map(experience => experience.id));
|
|
3216
3275
|
this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
|
|
3217
3276
|
[id]: false
|
|
3218
3277
|
});
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { NinetailedPlugin } from '@ninetailed/experience.js
|
|
1
|
+
import omit from 'lodash/omit';
|
|
2
|
+
import { NinetailedPlugin, OnChangeEmitter, selectActiveExperiments, selectEligibleExperiences, isExperienceMatch, selectDistribution, PROFILE_CHANGE } from '@ninetailed/experience.js';
|
|
3
3
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { useState, useRef, useEffect } from 'react';
|
|
5
5
|
import { v4 } from 'uuid';
|
|
@@ -2410,9 +2410,99 @@ var addToUnscopables$2 = function (key) {
|
|
|
2410
2410
|
ArrayPrototype[UNSCOPABLES][key] = true;
|
|
2411
2411
|
};
|
|
2412
2412
|
|
|
2413
|
+
var $$3 = _export;
|
|
2414
|
+
var $includes = arrayIncludes.includes;
|
|
2413
2415
|
var fails$3 = fails$f;
|
|
2416
|
+
var addToUnscopables$1 = addToUnscopables$2;
|
|
2417
|
+
|
|
2418
|
+
// FF99+ bug
|
|
2419
|
+
var BROKEN_ON_SPARSE = fails$3(function () {
|
|
2420
|
+
return !Array(1).includes();
|
|
2421
|
+
});
|
|
2422
|
+
|
|
2423
|
+
// `Array.prototype.includes` method
|
|
2424
|
+
// https://tc39.es/ecma262/#sec-array.prototype.includes
|
|
2425
|
+
$$3({ target: 'Array', proto: true, forced: BROKEN_ON_SPARSE }, {
|
|
2426
|
+
includes: function includes(el /* , fromIndex = 0 */) {
|
|
2427
|
+
return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined);
|
|
2428
|
+
}
|
|
2429
|
+
});
|
|
2430
|
+
|
|
2431
|
+
// https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
|
|
2432
|
+
addToUnscopables$1('includes');
|
|
2433
|
+
|
|
2434
|
+
var isObject$1 = isObject$9;
|
|
2435
|
+
var classof$1 = classofRaw$2;
|
|
2436
|
+
var wellKnownSymbol$4 = wellKnownSymbol$g;
|
|
2437
|
+
|
|
2438
|
+
var MATCH$1 = wellKnownSymbol$4('match');
|
|
2439
|
+
|
|
2440
|
+
// `IsRegExp` abstract operation
|
|
2441
|
+
// https://tc39.es/ecma262/#sec-isregexp
|
|
2442
|
+
var isRegexp = function (it) {
|
|
2443
|
+
var isRegExp;
|
|
2444
|
+
return isObject$1(it) && ((isRegExp = it[MATCH$1]) !== undefined ? !!isRegExp : classof$1(it) == 'RegExp');
|
|
2445
|
+
};
|
|
2446
|
+
|
|
2447
|
+
var isRegExp = isRegexp;
|
|
2414
2448
|
|
|
2415
|
-
var
|
|
2449
|
+
var $TypeError$1 = TypeError;
|
|
2450
|
+
|
|
2451
|
+
var notARegexp = function (it) {
|
|
2452
|
+
if (isRegExp(it)) {
|
|
2453
|
+
throw $TypeError$1("The method doesn't accept regular expressions");
|
|
2454
|
+
} return it;
|
|
2455
|
+
};
|
|
2456
|
+
|
|
2457
|
+
var classof = classof$4;
|
|
2458
|
+
|
|
2459
|
+
var $String = String;
|
|
2460
|
+
|
|
2461
|
+
var toString$1 = function (argument) {
|
|
2462
|
+
if (classof(argument) === 'Symbol') throw TypeError('Cannot convert a Symbol value to a string');
|
|
2463
|
+
return $String(argument);
|
|
2464
|
+
};
|
|
2465
|
+
|
|
2466
|
+
var wellKnownSymbol$3 = wellKnownSymbol$g;
|
|
2467
|
+
|
|
2468
|
+
var MATCH = wellKnownSymbol$3('match');
|
|
2469
|
+
|
|
2470
|
+
var correctIsRegexpLogic = function (METHOD_NAME) {
|
|
2471
|
+
var regexp = /./;
|
|
2472
|
+
try {
|
|
2473
|
+
'/./'[METHOD_NAME](regexp);
|
|
2474
|
+
} catch (error1) {
|
|
2475
|
+
try {
|
|
2476
|
+
regexp[MATCH] = false;
|
|
2477
|
+
return '/./'[METHOD_NAME](regexp);
|
|
2478
|
+
} catch (error2) { /* empty */ }
|
|
2479
|
+
} return false;
|
|
2480
|
+
};
|
|
2481
|
+
|
|
2482
|
+
var $$2 = _export;
|
|
2483
|
+
var uncurryThis = functionUncurryThis;
|
|
2484
|
+
var notARegExp = notARegexp;
|
|
2485
|
+
var requireObjectCoercible = requireObjectCoercible$3;
|
|
2486
|
+
var toString = toString$1;
|
|
2487
|
+
var correctIsRegExpLogic = correctIsRegexpLogic;
|
|
2488
|
+
|
|
2489
|
+
var stringIndexOf = uncurryThis(''.indexOf);
|
|
2490
|
+
|
|
2491
|
+
// `String.prototype.includes` method
|
|
2492
|
+
// https://tc39.es/ecma262/#sec-string.prototype.includes
|
|
2493
|
+
$$2({ target: 'String', proto: true, forced: !correctIsRegExpLogic('includes') }, {
|
|
2494
|
+
includes: function includes(searchString /* , position = 0 */) {
|
|
2495
|
+
return !!~stringIndexOf(
|
|
2496
|
+
toString(requireObjectCoercible(this)),
|
|
2497
|
+
toString(notARegExp(searchString)),
|
|
2498
|
+
arguments.length > 1 ? arguments[1] : undefined
|
|
2499
|
+
);
|
|
2500
|
+
}
|
|
2501
|
+
});
|
|
2502
|
+
|
|
2503
|
+
var fails$2 = fails$f;
|
|
2504
|
+
|
|
2505
|
+
var correctPrototypeGetter = !fails$2(function () {
|
|
2416
2506
|
function F() { /* empty */ }
|
|
2417
2507
|
F.prototype.constructor = null;
|
|
2418
2508
|
// eslint-disable-next-line es/no-object-getprototypeof -- required for testing
|
|
@@ -2441,14 +2531,14 @@ var objectGetPrototypeOf = CORRECT_PROTOTYPE_GETTER ? $Object.getPrototypeOf : f
|
|
|
2441
2531
|
} return object instanceof $Object ? ObjectPrototype : null;
|
|
2442
2532
|
};
|
|
2443
2533
|
|
|
2444
|
-
var fails$
|
|
2534
|
+
var fails$1 = fails$f;
|
|
2445
2535
|
var isCallable$1 = isCallable$k;
|
|
2446
|
-
var isObject
|
|
2536
|
+
var isObject = isObject$9;
|
|
2447
2537
|
var getPrototypeOf$1 = objectGetPrototypeOf;
|
|
2448
2538
|
var defineBuiltIn$1 = defineBuiltIn$5;
|
|
2449
|
-
var wellKnownSymbol$
|
|
2539
|
+
var wellKnownSymbol$2 = wellKnownSymbol$g;
|
|
2450
2540
|
|
|
2451
|
-
var ITERATOR$2 = wellKnownSymbol$
|
|
2541
|
+
var ITERATOR$2 = wellKnownSymbol$2('iterator');
|
|
2452
2542
|
var BUGGY_SAFARI_ITERATORS$1 = false;
|
|
2453
2543
|
|
|
2454
2544
|
// `%IteratorPrototype%` object
|
|
@@ -2466,7 +2556,7 @@ if ([].keys) {
|
|
|
2466
2556
|
}
|
|
2467
2557
|
}
|
|
2468
2558
|
|
|
2469
|
-
var NEW_ITERATOR_PROTOTYPE = !isObject
|
|
2559
|
+
var NEW_ITERATOR_PROTOTYPE = !isObject(IteratorPrototype$2) || fails$1(function () {
|
|
2470
2560
|
var test = {};
|
|
2471
2561
|
// FF44- legacy iterators case
|
|
2472
2562
|
return IteratorPrototype$2[ITERATOR$2].call(test) !== test;
|
|
@@ -2503,7 +2593,7 @@ var iteratorCreateConstructor = function (IteratorConstructor, NAME, next, ENUME
|
|
|
2503
2593
|
return IteratorConstructor;
|
|
2504
2594
|
};
|
|
2505
2595
|
|
|
2506
|
-
var $$
|
|
2596
|
+
var $$1 = _export;
|
|
2507
2597
|
var call = functionCall;
|
|
2508
2598
|
var FunctionName = functionName;
|
|
2509
2599
|
var isCallable = isCallable$k;
|
|
@@ -2513,7 +2603,7 @@ var setPrototypeOf = objectSetPrototypeOf;
|
|
|
2513
2603
|
var setToStringTag = setToStringTag$3;
|
|
2514
2604
|
var createNonEnumerableProperty$1 = createNonEnumerableProperty$4;
|
|
2515
2605
|
var defineBuiltIn = defineBuiltIn$5;
|
|
2516
|
-
var wellKnownSymbol$
|
|
2606
|
+
var wellKnownSymbol$1 = wellKnownSymbol$g;
|
|
2517
2607
|
var Iterators$1 = iterators;
|
|
2518
2608
|
var IteratorsCore = iteratorsCore;
|
|
2519
2609
|
|
|
@@ -2521,7 +2611,7 @@ var PROPER_FUNCTION_NAME = FunctionName.PROPER;
|
|
|
2521
2611
|
var CONFIGURABLE_FUNCTION_NAME = FunctionName.CONFIGURABLE;
|
|
2522
2612
|
var IteratorPrototype = IteratorsCore.IteratorPrototype;
|
|
2523
2613
|
var BUGGY_SAFARI_ITERATORS = IteratorsCore.BUGGY_SAFARI_ITERATORS;
|
|
2524
|
-
var ITERATOR$1 = wellKnownSymbol$
|
|
2614
|
+
var ITERATOR$1 = wellKnownSymbol$1('iterator');
|
|
2525
2615
|
var KEYS = 'keys';
|
|
2526
2616
|
var VALUES = 'values';
|
|
2527
2617
|
var ENTRIES = 'entries';
|
|
@@ -2588,7 +2678,7 @@ var iteratorDefine = function (Iterable, NAME, IteratorConstructor, next, DEFAUL
|
|
|
2588
2678
|
if (BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME || !(KEY in IterablePrototype)) {
|
|
2589
2679
|
defineBuiltIn(IterablePrototype, KEY, methods[KEY]);
|
|
2590
2680
|
}
|
|
2591
|
-
} else $$
|
|
2681
|
+
} else $$1({ target: NAME, proto: true, forced: BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME }, methods);
|
|
2592
2682
|
}
|
|
2593
2683
|
|
|
2594
2684
|
// define iterator
|
|
@@ -2607,7 +2697,7 @@ var createIterResultObject$1 = function (value, done) {
|
|
|
2607
2697
|
};
|
|
2608
2698
|
|
|
2609
2699
|
var toIndexedObject = toIndexedObject$5;
|
|
2610
|
-
var addToUnscopables
|
|
2700
|
+
var addToUnscopables = addToUnscopables$2;
|
|
2611
2701
|
var Iterators = iterators;
|
|
2612
2702
|
var InternalStateModule = internalState;
|
|
2613
2703
|
var defineProperty = objectDefineProperty.f;
|
|
@@ -2658,9 +2748,9 @@ var es_array_iterator = defineIterator(Array, 'Array', function (iterated, kind)
|
|
|
2658
2748
|
var values = Iterators.Arguments = Iterators.Array;
|
|
2659
2749
|
|
|
2660
2750
|
// https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
|
|
2661
|
-
addToUnscopables
|
|
2662
|
-
addToUnscopables
|
|
2663
|
-
addToUnscopables
|
|
2751
|
+
addToUnscopables('keys');
|
|
2752
|
+
addToUnscopables('values');
|
|
2753
|
+
addToUnscopables('entries');
|
|
2664
2754
|
|
|
2665
2755
|
// V8 ~ Chrome 45- bug
|
|
2666
2756
|
if (DESCRIPTORS && values.name !== 'values') try {
|
|
@@ -2716,10 +2806,10 @@ var DOMIterables = domIterables;
|
|
|
2716
2806
|
var DOMTokenListPrototype = domTokenListPrototype;
|
|
2717
2807
|
var ArrayIteratorMethods = es_array_iterator;
|
|
2718
2808
|
var createNonEnumerableProperty = createNonEnumerableProperty$4;
|
|
2719
|
-
var wellKnownSymbol
|
|
2809
|
+
var wellKnownSymbol = wellKnownSymbol$g;
|
|
2720
2810
|
|
|
2721
|
-
var ITERATOR = wellKnownSymbol
|
|
2722
|
-
var TO_STRING_TAG = wellKnownSymbol
|
|
2811
|
+
var ITERATOR = wellKnownSymbol('iterator');
|
|
2812
|
+
var TO_STRING_TAG = wellKnownSymbol('toStringTag');
|
|
2723
2813
|
var ArrayValues = ArrayIteratorMethods.values;
|
|
2724
2814
|
|
|
2725
2815
|
var handlePrototype = function (CollectionPrototype, COLLECTION_NAME) {
|
|
@@ -2750,96 +2840,6 @@ for (var COLLECTION_NAME in DOMIterables) {
|
|
|
2750
2840
|
|
|
2751
2841
|
handlePrototype(DOMTokenListPrototype, 'DOMTokenList');
|
|
2752
2842
|
|
|
2753
|
-
var $$2 = _export;
|
|
2754
|
-
var $includes = arrayIncludes.includes;
|
|
2755
|
-
var fails$1 = fails$f;
|
|
2756
|
-
var addToUnscopables = addToUnscopables$2;
|
|
2757
|
-
|
|
2758
|
-
// FF99+ bug
|
|
2759
|
-
var BROKEN_ON_SPARSE = fails$1(function () {
|
|
2760
|
-
return !Array(1).includes();
|
|
2761
|
-
});
|
|
2762
|
-
|
|
2763
|
-
// `Array.prototype.includes` method
|
|
2764
|
-
// https://tc39.es/ecma262/#sec-array.prototype.includes
|
|
2765
|
-
$$2({ target: 'Array', proto: true, forced: BROKEN_ON_SPARSE }, {
|
|
2766
|
-
includes: function includes(el /* , fromIndex = 0 */) {
|
|
2767
|
-
return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined);
|
|
2768
|
-
}
|
|
2769
|
-
});
|
|
2770
|
-
|
|
2771
|
-
// https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
|
|
2772
|
-
addToUnscopables('includes');
|
|
2773
|
-
|
|
2774
|
-
var isObject = isObject$9;
|
|
2775
|
-
var classof$1 = classofRaw$2;
|
|
2776
|
-
var wellKnownSymbol$1 = wellKnownSymbol$g;
|
|
2777
|
-
|
|
2778
|
-
var MATCH$1 = wellKnownSymbol$1('match');
|
|
2779
|
-
|
|
2780
|
-
// `IsRegExp` abstract operation
|
|
2781
|
-
// https://tc39.es/ecma262/#sec-isregexp
|
|
2782
|
-
var isRegexp = function (it) {
|
|
2783
|
-
var isRegExp;
|
|
2784
|
-
return isObject(it) && ((isRegExp = it[MATCH$1]) !== undefined ? !!isRegExp : classof$1(it) == 'RegExp');
|
|
2785
|
-
};
|
|
2786
|
-
|
|
2787
|
-
var isRegExp = isRegexp;
|
|
2788
|
-
|
|
2789
|
-
var $TypeError$1 = TypeError;
|
|
2790
|
-
|
|
2791
|
-
var notARegexp = function (it) {
|
|
2792
|
-
if (isRegExp(it)) {
|
|
2793
|
-
throw $TypeError$1("The method doesn't accept regular expressions");
|
|
2794
|
-
} return it;
|
|
2795
|
-
};
|
|
2796
|
-
|
|
2797
|
-
var classof = classof$4;
|
|
2798
|
-
|
|
2799
|
-
var $String = String;
|
|
2800
|
-
|
|
2801
|
-
var toString$1 = function (argument) {
|
|
2802
|
-
if (classof(argument) === 'Symbol') throw TypeError('Cannot convert a Symbol value to a string');
|
|
2803
|
-
return $String(argument);
|
|
2804
|
-
};
|
|
2805
|
-
|
|
2806
|
-
var wellKnownSymbol = wellKnownSymbol$g;
|
|
2807
|
-
|
|
2808
|
-
var MATCH = wellKnownSymbol('match');
|
|
2809
|
-
|
|
2810
|
-
var correctIsRegexpLogic = function (METHOD_NAME) {
|
|
2811
|
-
var regexp = /./;
|
|
2812
|
-
try {
|
|
2813
|
-
'/./'[METHOD_NAME](regexp);
|
|
2814
|
-
} catch (error1) {
|
|
2815
|
-
try {
|
|
2816
|
-
regexp[MATCH] = false;
|
|
2817
|
-
return '/./'[METHOD_NAME](regexp);
|
|
2818
|
-
} catch (error2) { /* empty */ }
|
|
2819
|
-
} return false;
|
|
2820
|
-
};
|
|
2821
|
-
|
|
2822
|
-
var $$1 = _export;
|
|
2823
|
-
var uncurryThis = functionUncurryThis;
|
|
2824
|
-
var notARegExp = notARegexp;
|
|
2825
|
-
var requireObjectCoercible = requireObjectCoercible$3;
|
|
2826
|
-
var toString = toString$1;
|
|
2827
|
-
var correctIsRegExpLogic = correctIsRegexpLogic;
|
|
2828
|
-
|
|
2829
|
-
var stringIndexOf = uncurryThis(''.indexOf);
|
|
2830
|
-
|
|
2831
|
-
// `String.prototype.includes` method
|
|
2832
|
-
// https://tc39.es/ecma262/#sec-string.prototype.includes
|
|
2833
|
-
$$1({ target: 'String', proto: true, forced: !correctIsRegExpLogic('includes') }, {
|
|
2834
|
-
includes: function includes(searchString /* , position = 0 */) {
|
|
2835
|
-
return !!~stringIndexOf(
|
|
2836
|
-
toString(requireObjectCoercible(this)),
|
|
2837
|
-
toString(notARegExp(searchString)),
|
|
2838
|
-
arguments.length > 1 ? arguments[1] : undefined
|
|
2839
|
-
);
|
|
2840
|
-
}
|
|
2841
|
-
});
|
|
2842
|
-
|
|
2843
2843
|
var aCallable = aCallable$8;
|
|
2844
2844
|
var toObject = toObject$4;
|
|
2845
2845
|
var IndexedObject = indexedObject;
|
|
@@ -3001,7 +3001,7 @@ class WidgetContainer {
|
|
|
3001
3001
|
}
|
|
3002
3002
|
|
|
3003
3003
|
const PreviewRenderPlugin = ctx => {
|
|
3004
|
-
const
|
|
3004
|
+
const PreviewRenderPlugin = props => {
|
|
3005
3005
|
const [pluginApi, setPluginApi] = useState(ctx.pluginApi);
|
|
3006
3006
|
const {
|
|
3007
3007
|
children,
|
|
@@ -3019,37 +3019,41 @@ const PreviewRenderPlugin = ctx => {
|
|
|
3019
3019
|
};
|
|
3020
3020
|
}, [id]);
|
|
3021
3021
|
useEffect(() => {
|
|
3022
|
-
const
|
|
3023
|
-
const
|
|
3024
|
-
|
|
3022
|
+
const experienceIds = Object.keys(pluginApi.experienceVariantIndexes);
|
|
3023
|
+
const experience = experiences.find(experience => {
|
|
3024
|
+
const hasActiveAudience = pluginApi.activeAudiences.some(activeAudienceId => {
|
|
3025
|
+
var _a;
|
|
3026
|
+
return ((_a = experience.audience) === null || _a === void 0 ? void 0 : _a.id) === activeAudienceId;
|
|
3027
|
+
});
|
|
3028
|
+
return hasActiveAudience && experienceIds.includes(experience.id);
|
|
3025
3029
|
});
|
|
3026
|
-
if (!
|
|
3027
|
-
setComponentProps(
|
|
3030
|
+
if (!experience) {
|
|
3031
|
+
setComponentProps(baseline);
|
|
3028
3032
|
return;
|
|
3029
3033
|
}
|
|
3030
|
-
const baselineComponent =
|
|
3034
|
+
const baselineComponent = experience.components.find(component => component.baseline.id === baseline.id);
|
|
3031
3035
|
if (!baselineComponent) {
|
|
3032
|
-
setComponentProps(
|
|
3036
|
+
setComponentProps(baseline);
|
|
3033
3037
|
return;
|
|
3034
3038
|
}
|
|
3035
3039
|
const allVariants = [baseline, ...baselineComponent.variants];
|
|
3036
|
-
const variantIndex = pluginApi.
|
|
3040
|
+
const variantIndex = pluginApi.experienceVariantIndexes[experience.id];
|
|
3037
3041
|
if (allVariants.length <= variantIndex) {
|
|
3038
|
-
setComponentProps(
|
|
3042
|
+
setComponentProps(baseline);
|
|
3039
3043
|
return;
|
|
3040
3044
|
}
|
|
3041
3045
|
const variant = allVariants[variantIndex];
|
|
3042
3046
|
if (!variant) {
|
|
3043
|
-
setComponentProps(
|
|
3047
|
+
setComponentProps(baseline);
|
|
3044
3048
|
return;
|
|
3045
3049
|
}
|
|
3046
|
-
setComponentProps(
|
|
3047
|
-
}, [experiences, baseline, setComponentProps, pluginApi.
|
|
3050
|
+
setComponentProps(variant);
|
|
3051
|
+
}, [experiences, baseline, setComponentProps, pluginApi.experienceVariantIndexes, pluginApi.activeAudiences]);
|
|
3048
3052
|
return jsx(Fragment, {
|
|
3049
3053
|
children: children
|
|
3050
3054
|
});
|
|
3051
3055
|
};
|
|
3052
|
-
return
|
|
3056
|
+
return PreviewRenderPlugin;
|
|
3053
3057
|
};
|
|
3054
3058
|
|
|
3055
3059
|
class PreviewRenderPluginContext {
|
|
@@ -3083,6 +3087,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
3083
3087
|
this.container = null;
|
|
3084
3088
|
this.bridge = null;
|
|
3085
3089
|
this.renderPluginContext = new PreviewRenderPluginContext(this.pluginApi);
|
|
3090
|
+
this.onChangeEmitter = new OnChangeEmitter();
|
|
3086
3091
|
this.initialize = () => __awaiter(this, void 0, void 0, function* () {
|
|
3087
3092
|
var _b;
|
|
3088
3093
|
if (typeof window !== 'undefined') {
|
|
@@ -3117,8 +3122,56 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
3117
3122
|
this.onProfileChange(payload.profile);
|
|
3118
3123
|
}
|
|
3119
3124
|
};
|
|
3125
|
+
this.getExperienceSelectionMiddleware = ({
|
|
3126
|
+
baseline,
|
|
3127
|
+
experiences
|
|
3128
|
+
}) => {
|
|
3129
|
+
return () => {
|
|
3130
|
+
const experienceIds = Object.keys(this.pluginApi.experienceVariantIndexes);
|
|
3131
|
+
const experience = experiences.find(experience => {
|
|
3132
|
+
const hasActiveAudience = this.pluginApi.activeAudiences.some(activeAudienceId => {
|
|
3133
|
+
var _b;
|
|
3134
|
+
return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === activeAudienceId;
|
|
3135
|
+
});
|
|
3136
|
+
return hasActiveAudience && experienceIds.includes(experience.id);
|
|
3137
|
+
});
|
|
3138
|
+
if (!experience) {
|
|
3139
|
+
return {
|
|
3140
|
+
experience: null,
|
|
3141
|
+
variant: null
|
|
3142
|
+
};
|
|
3143
|
+
}
|
|
3144
|
+
const baselineComponent = experience.components.find(component => component.baseline.id === baseline.id);
|
|
3145
|
+
if (!baselineComponent) {
|
|
3146
|
+
return {
|
|
3147
|
+
experience,
|
|
3148
|
+
variant: null
|
|
3149
|
+
};
|
|
3150
|
+
}
|
|
3151
|
+
const allVariants = [baseline, ...baselineComponent.variants];
|
|
3152
|
+
const variantIndex = this.pluginApi.experienceVariantIndexes[experience.id];
|
|
3153
|
+
if (allVariants.length <= variantIndex) {
|
|
3154
|
+
return {
|
|
3155
|
+
experience,
|
|
3156
|
+
variant: null
|
|
3157
|
+
};
|
|
3158
|
+
}
|
|
3159
|
+
const variant = allVariants[variantIndex];
|
|
3160
|
+
if (!variant) {
|
|
3161
|
+
return {
|
|
3162
|
+
experience,
|
|
3163
|
+
variant: null
|
|
3164
|
+
};
|
|
3165
|
+
}
|
|
3166
|
+
return {
|
|
3167
|
+
experience,
|
|
3168
|
+
variant
|
|
3169
|
+
};
|
|
3170
|
+
};
|
|
3171
|
+
};
|
|
3120
3172
|
this.onChange = () => {
|
|
3121
3173
|
var _b;
|
|
3174
|
+
console.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
|
|
3122
3175
|
Object.assign({}, window.ninetailed, {
|
|
3123
3176
|
plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
|
|
3124
3177
|
preview: this.windowApi
|
|
@@ -3127,9 +3180,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
3127
3180
|
this.bridge.updateProps({
|
|
3128
3181
|
props: this.pluginApi
|
|
3129
3182
|
});
|
|
3130
|
-
|
|
3131
|
-
this.renderPluginContext.setPluginApi(this.pluginApi);
|
|
3132
|
-
}
|
|
3183
|
+
this.onChangeEmitter.invokeListeners();
|
|
3133
3184
|
};
|
|
3134
3185
|
this.onProfileChange = profile => {
|
|
3135
3186
|
this.profile = profile;
|
|
@@ -3167,30 +3218,34 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
3167
3218
|
this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
|
|
3168
3219
|
[id]: true
|
|
3169
3220
|
});
|
|
3170
|
-
this.
|
|
3171
|
-
// When a audience is activated, they should show their natural state
|
|
3172
|
-
this.experiences.filter(experience => {
|
|
3221
|
+
this.experienceVariantIndexOverwrites = Object.assign(Object.assign({}, this.experienceVariantIndexOverwrites), this.experiences.filter(experience => {
|
|
3173
3222
|
var _b;
|
|
3174
3223
|
return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
|
|
3175
|
-
}).
|
|
3176
|
-
|
|
3177
|
-
|
|
3224
|
+
}).map(experience => experience.id).reduce((acc, curr) => {
|
|
3225
|
+
return Object.assign(Object.assign({}, acc), {
|
|
3226
|
+
[curr]: this.experienceVariantIndexes[curr] || 0
|
|
3227
|
+
});
|
|
3228
|
+
}, {}));
|
|
3229
|
+
this.onChange();
|
|
3178
3230
|
}
|
|
3179
3231
|
deactivateAudience(id) {
|
|
3180
3232
|
if (!this.isKnownAudience(id)) {
|
|
3181
3233
|
console.log(`You cannot deactivate an unkown audience (id: ${id}). How did you get it in the first place?`);
|
|
3182
3234
|
return;
|
|
3183
3235
|
}
|
|
3184
|
-
// When a audience is deactivated, the normal state will be that the experience goes into the control
|
|
3185
|
-
this.experiences
|
|
3236
|
+
// // When a audience is deactivated, the normal state will be that the experience goes into the control
|
|
3237
|
+
// this.experiences
|
|
3238
|
+
// .filter((experience) => experience.audience?.id === id)
|
|
3239
|
+
// .forEach((experience) => {
|
|
3240
|
+
// this.setExperienceVariant({
|
|
3241
|
+
// experienceId: experience.id,
|
|
3242
|
+
// variantIndex: 0,
|
|
3243
|
+
// });
|
|
3244
|
+
// });
|
|
3245
|
+
this.experienceVariantIndexOverwrites = omit(this.experienceVariantIndexOverwrites, this.experiences.filter(experience => {
|
|
3186
3246
|
var _b;
|
|
3187
3247
|
return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
|
|
3188
|
-
}).
|
|
3189
|
-
this.setExperienceVariant({
|
|
3190
|
-
experienceId: experience.id,
|
|
3191
|
-
variantIndex: 0
|
|
3192
|
-
});
|
|
3193
|
-
});
|
|
3248
|
+
}).map(experience => experience.id));
|
|
3194
3249
|
this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
|
|
3195
3250
|
[id]: false
|
|
3196
3251
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { NinetailedPlugin } from '@ninetailed/experience.js
|
|
1
|
+
import { Reference } from '@ninetailed/experience.js-shared';
|
|
2
|
+
import { ExperienceConfiguration, PROFILE_CHANGE, NinetailedPlugin, HasExperienceSelectionMiddleware, ExperienceSelectionMiddleware } from '@ninetailed/experience.js';
|
|
3
3
|
import { RenderPluginWrapperComponent } from '@ninetailed/experience.js-react';
|
|
4
4
|
export declare const NINETAILED_PREVIEW_EVENTS: {
|
|
5
5
|
previewAudiences: string;
|
|
@@ -15,7 +15,7 @@ type NinetailedPreviewPluginOptions = {
|
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
export declare class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
18
|
+
export declare class NinetailedPreviewPlugin extends NinetailedPlugin implements HasExperienceSelectionMiddleware<Reference> {
|
|
19
19
|
private readonly options;
|
|
20
20
|
name: string;
|
|
21
21
|
private isOpen;
|
|
@@ -27,6 +27,7 @@ export declare class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
27
27
|
private bridge;
|
|
28
28
|
private renderPluginContext;
|
|
29
29
|
private renderPluginComponent;
|
|
30
|
+
private onChangeEmitter;
|
|
30
31
|
constructor(options: NinetailedPreviewPluginOptions);
|
|
31
32
|
initialize: () => Promise<void>;
|
|
32
33
|
getRenderWrapper: () => RenderPluginWrapperComponent;
|
|
@@ -46,6 +47,7 @@ export declare class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
46
47
|
}): void;
|
|
47
48
|
resetExperience(experienceId: string): void;
|
|
48
49
|
reset(): void;
|
|
50
|
+
getExperienceSelectionMiddleware: ExperienceSelectionMiddleware<Reference>;
|
|
49
51
|
private get pluginApi();
|
|
50
52
|
private get windowApi();
|
|
51
53
|
private isKnownAudience;
|
package/package.json
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js-plugin-preview",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0-beta.1",
|
|
4
4
|
"module": "./index.js",
|
|
5
5
|
"main": "./index.cjs",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "./index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"
|
|
10
|
-
"@ninetailed/experience.js": "4.
|
|
11
|
-
"@ninetailed/experience.js
|
|
12
|
-
"@ninetailed/experience.js-utils": "4.0.0-beta.
|
|
13
|
-
"@ninetailed/experience.js-react": "4.
|
|
14
|
-
"@ninetailed/experience.js-preview-bridge": "4.
|
|
9
|
+
"lodash": "4.17.21",
|
|
10
|
+
"@ninetailed/experience.js-shared": "4.1.0-beta.1",
|
|
11
|
+
"@ninetailed/experience.js": "4.1.0-beta.1",
|
|
12
|
+
"@ninetailed/experience.js-utils": "4.0.0-beta.14",
|
|
13
|
+
"@ninetailed/experience.js-react": "4.1.0-beta.1",
|
|
14
|
+
"@ninetailed/experience.js-preview-bridge": "4.1.0-beta.1",
|
|
15
15
|
"react": "18.2.0",
|
|
16
|
-
"uuid": "9.0.0"
|
|
16
|
+
"uuid": "9.0.0",
|
|
17
|
+
"ts-toolbelt": "9.6.0"
|
|
17
18
|
},
|
|
18
19
|
"peerDependencies": {}
|
|
19
20
|
}
|