@ninetailed/experience.js-react 7.18.12-alpha.3 → 7.18.13
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 +14 -10
- package/index.esm.d.ts +1 -0
- package/index.esm.js +128 -116
- package/package.json +5 -5
package/index.cjs.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
4
|
var React = require('react');
|
|
7
5
|
var experience_js = require('@ninetailed/experience.js');
|
|
@@ -9,10 +7,6 @@ var experience_jsShared = require('@ninetailed/experience.js-shared');
|
|
|
9
7
|
var radash = require('radash');
|
|
10
8
|
var reactIs = require('react-is');
|
|
11
9
|
|
|
12
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
-
|
|
14
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
15
|
-
|
|
16
10
|
const NinetailedContext = /*#__PURE__*/React.createContext(undefined);
|
|
17
11
|
|
|
18
12
|
const NinetailedProvider = props => {
|
|
@@ -86,6 +80,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
86
80
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
87
81
|
PERFORMANCE OF THIS SOFTWARE.
|
|
88
82
|
***************************************************************************** */
|
|
83
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
84
|
+
|
|
89
85
|
|
|
90
86
|
function __rest(s, e) {
|
|
91
87
|
var t = {};
|
|
@@ -97,11 +93,19 @@ function __rest(s, e) {
|
|
|
97
93
|
t[p[i]] = s[p[i]];
|
|
98
94
|
}
|
|
99
95
|
return t;
|
|
100
|
-
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
99
|
+
var e = new Error(message);
|
|
100
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
101
|
+
};
|
|
101
102
|
|
|
102
103
|
function formatProfileForHook(profile) {
|
|
103
104
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
104
|
-
const
|
|
105
|
+
const {
|
|
106
|
+
experiences: _
|
|
107
|
+
} = profile,
|
|
108
|
+
profileStateWithoutExperiences = __rest(profile, ["experiences"]);
|
|
105
109
|
return Object.assign(Object.assign({}, profileStateWithoutExperiences), {
|
|
106
110
|
loading: profile.status === 'loading'
|
|
107
111
|
});
|
|
@@ -633,7 +637,7 @@ const Experience = _a => {
|
|
|
633
637
|
});
|
|
634
638
|
};
|
|
635
639
|
|
|
636
|
-
const ESRContext = /*#__PURE__*/
|
|
640
|
+
const ESRContext = /*#__PURE__*/React.createContext(undefined);
|
|
637
641
|
const ESRProvider = ({
|
|
638
642
|
experienceVariantsMap,
|
|
639
643
|
children
|
|
@@ -647,7 +651,7 @@ const ESRProvider = ({
|
|
|
647
651
|
}));
|
|
648
652
|
};
|
|
649
653
|
const useESR = () => {
|
|
650
|
-
const context =
|
|
654
|
+
const context = React.useContext(ESRContext);
|
|
651
655
|
if (context === undefined) {
|
|
652
656
|
throw new Error('The component using the the context must be a descendant of the ESRProvider');
|
|
653
657
|
}
|
package/index.esm.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
1
2
|
import React, { createContext, useMemo, useContext, useState, useRef, useEffect, useCallback, createElement, forwardRef } from 'react';
|
|
2
3
|
import { Ninetailed, selectVariant, selectHasExperienceVariants } from '@ninetailed/experience.js';
|
|
3
|
-
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { logger, ChangeTypes, isBrowser, circularJsonStringify } from '@ninetailed/experience.js-shared';
|
|
5
5
|
import { isEqual, get } from 'radash';
|
|
6
6
|
import { isForwardRef } from 'react-is';
|
|
@@ -49,10 +49,11 @@ const NinetailedProvider = props => {
|
|
|
49
49
|
const {
|
|
50
50
|
children
|
|
51
51
|
} = props;
|
|
52
|
-
return
|
|
53
|
-
value: ninetailed
|
|
52
|
+
return jsx(NinetailedContext.Provider, Object.assign({
|
|
53
|
+
value: ninetailed
|
|
54
|
+
}, {
|
|
54
55
|
children: children
|
|
55
|
-
});
|
|
56
|
+
}));
|
|
56
57
|
};
|
|
57
58
|
|
|
58
59
|
const useNinetailed = () => {
|
|
@@ -63,43 +64,64 @@ const useNinetailed = () => {
|
|
|
63
64
|
return ninetailed;
|
|
64
65
|
};
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
67
|
+
/******************************************************************************
|
|
68
|
+
Copyright (c) Microsoft Corporation.
|
|
69
|
+
|
|
70
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
71
|
+
purpose with or without fee is hereby granted.
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
74
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
75
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
76
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
77
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
78
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
79
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
80
|
+
***************************************************************************** */
|
|
81
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
function __rest(s, e) {
|
|
85
|
+
var t = {};
|
|
86
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
87
|
+
t[p] = s[p];
|
|
88
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
89
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
90
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
91
|
+
t[p[i]] = s[p[i]];
|
|
92
|
+
}
|
|
93
|
+
return t;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
97
|
+
var e = new Error(message);
|
|
98
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
99
|
+
};
|
|
78
100
|
|
|
79
|
-
const _excluded$4 = ["experiences"];
|
|
80
101
|
function formatProfileForHook(profile) {
|
|
81
102
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
82
|
-
const
|
|
83
|
-
|
|
103
|
+
const {
|
|
104
|
+
experiences: _
|
|
105
|
+
} = profile,
|
|
106
|
+
profileStateWithoutExperiences = __rest(profile, ["experiences"]);
|
|
107
|
+
return Object.assign(Object.assign({}, profileStateWithoutExperiences), {
|
|
84
108
|
loading: profile.status === 'loading'
|
|
85
109
|
});
|
|
86
110
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* @returns The profile state without the 'experiences' property
|
|
111
|
+
/**
|
|
112
|
+
* Custom hook that provides access to the Ninetailed profile state
|
|
113
|
+
* with the 'experiences' property removed to prevent unnecessary re-renders.
|
|
114
|
+
*
|
|
115
|
+
* This hook handles profile state changes efficiently by:
|
|
116
|
+
* 1. Only updating state when actual changes occur
|
|
117
|
+
* 2. Removing the large 'experiences' object from the state
|
|
118
|
+
* 3. Properly cleaning up subscriptions when components unmount
|
|
119
|
+
*
|
|
120
|
+
* @returns The profile state without the 'experiences' property
|
|
98
121
|
*/
|
|
99
122
|
const useProfile = () => {
|
|
100
123
|
const ninetailed = useNinetailed();
|
|
101
124
|
const [strippedProfileState, setStrippedProfileState] = useState(formatProfileForHook(ninetailed.profileState));
|
|
102
|
-
|
|
103
125
|
// Reference to track the previous profile state for comparison
|
|
104
126
|
const profileStateRef = useRef(ninetailed.profileState);
|
|
105
127
|
useEffect(() => {
|
|
@@ -114,7 +136,6 @@ const useProfile = () => {
|
|
|
114
136
|
logger.debug('Profile State Changed', changedProfileState);
|
|
115
137
|
setStrippedProfileState(formatProfileForHook(changedProfileState));
|
|
116
138
|
});
|
|
117
|
-
|
|
118
139
|
// Clean up subscription when component unmounts
|
|
119
140
|
return () => {
|
|
120
141
|
if (typeof unsubscribe === 'function') {
|
|
@@ -133,8 +154,8 @@ const usePersonalize = (baseline, variants, options = {
|
|
|
133
154
|
return selectVariant(baseline, variants, profile, options);
|
|
134
155
|
};
|
|
135
156
|
|
|
136
|
-
/**
|
|
137
|
-
* Hook to access a Ninetailed variable flag with manual tracking control.
|
|
157
|
+
/**
|
|
158
|
+
* Hook to access a Ninetailed variable flag with manual tracking control.
|
|
138
159
|
*/
|
|
139
160
|
function useFlagWithManualTracking(flagKey, defaultValue) {
|
|
140
161
|
const ninetailed = useNinetailed();
|
|
@@ -147,7 +168,6 @@ function useFlagWithManualTracking(flagKey, defaultValue) {
|
|
|
147
168
|
status: 'loading',
|
|
148
169
|
error: null
|
|
149
170
|
});
|
|
150
|
-
|
|
151
171
|
// Reset if inputs change
|
|
152
172
|
useEffect(() => {
|
|
153
173
|
if (!isEqual(defaultValueRef.current, defaultValue) || flagKeyRef.current !== flagKey) {
|
|
@@ -162,7 +182,6 @@ function useFlagWithManualTracking(flagKey, defaultValue) {
|
|
|
162
182
|
});
|
|
163
183
|
}
|
|
164
184
|
}, [flagKey, defaultValue]);
|
|
165
|
-
|
|
166
185
|
// Listen for personalization state changes
|
|
167
186
|
useEffect(() => {
|
|
168
187
|
const unsubscribe = ninetailed.onChangesChange(changesState => {
|
|
@@ -186,13 +205,11 @@ function useFlagWithManualTracking(flagKey, defaultValue) {
|
|
|
186
205
|
});
|
|
187
206
|
return;
|
|
188
207
|
}
|
|
189
|
-
|
|
190
208
|
// Find relevant change for this flag
|
|
191
209
|
const change = changesState.changes.find(c => c.key === flagKeyRef.current && c.type === ChangeTypes.Variable);
|
|
192
210
|
if (change) {
|
|
193
211
|
changeRef.current = change;
|
|
194
212
|
const rawValue = change.value;
|
|
195
|
-
|
|
196
213
|
// Unwrap { value: ... } structure if present
|
|
197
214
|
const actualValue = rawValue && typeof rawValue === 'object' && rawValue !== null && 'value' in rawValue ? rawValue['value'] : rawValue;
|
|
198
215
|
setResult({
|
|
@@ -211,7 +228,6 @@ function useFlagWithManualTracking(flagKey, defaultValue) {
|
|
|
211
228
|
});
|
|
212
229
|
return unsubscribe;
|
|
213
230
|
}, [ninetailed]);
|
|
214
|
-
|
|
215
231
|
// Manual tracking function
|
|
216
232
|
const track = useCallback(() => {
|
|
217
233
|
const change = changeRef.current;
|
|
@@ -229,11 +245,11 @@ function useFlagWithManualTracking(flagKey, defaultValue) {
|
|
|
229
245
|
return [result, track];
|
|
230
246
|
}
|
|
231
247
|
|
|
232
|
-
/**
|
|
233
|
-
* Hook to access a Ninetailed variable flag with built-in auto-tracking.
|
|
234
|
-
*
|
|
235
|
-
* @remarks
|
|
236
|
-
* For manual control over tracking behavior, consider using {@link useFlagWithManualTracking}.
|
|
248
|
+
/**
|
|
249
|
+
* Hook to access a Ninetailed variable flag with built-in auto-tracking.
|
|
250
|
+
*
|
|
251
|
+
* @remarks
|
|
252
|
+
* For manual control over tracking behavior, consider using {@link useFlagWithManualTracking}.
|
|
237
253
|
*/
|
|
238
254
|
function useFlag(flagKey, defaultValue, options = {}) {
|
|
239
255
|
const [result, track] = useFlagWithManualTracking(flagKey, defaultValue);
|
|
@@ -259,7 +275,6 @@ const TrackHasSeenComponent = ({
|
|
|
259
275
|
const observer = new IntersectionObserver(([entry]) => {
|
|
260
276
|
if (entry.isIntersecting) {
|
|
261
277
|
setInView(true);
|
|
262
|
-
|
|
263
278
|
// Disconnect the observer since we only want to track
|
|
264
279
|
// the first time the component is seen
|
|
265
280
|
observer.disconnect();
|
|
@@ -281,22 +296,21 @@ const TrackHasSeenComponent = ({
|
|
|
281
296
|
});
|
|
282
297
|
}
|
|
283
298
|
}, [inView]);
|
|
284
|
-
return
|
|
285
|
-
children: [
|
|
299
|
+
return jsxs(Fragment, {
|
|
300
|
+
children: [jsx("div", {
|
|
286
301
|
ref: ref
|
|
287
302
|
}), children]
|
|
288
303
|
});
|
|
289
304
|
};
|
|
290
305
|
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
let {
|
|
306
|
+
const Personalize = _a => {
|
|
307
|
+
var {
|
|
294
308
|
component: Component,
|
|
295
309
|
loadingComponent: LoadingComponent,
|
|
296
310
|
variants = [],
|
|
297
311
|
holdout = -1
|
|
298
|
-
} =
|
|
299
|
-
baseline =
|
|
312
|
+
} = _a,
|
|
313
|
+
baseline = __rest(_a, ["component", "loadingComponent", "variants", "holdout"]);
|
|
300
314
|
const {
|
|
301
315
|
loading,
|
|
302
316
|
variant,
|
|
@@ -307,7 +321,7 @@ const Personalize = _ref => {
|
|
|
307
321
|
});
|
|
308
322
|
const hasVariants = variants.length > 0;
|
|
309
323
|
if (!hasVariants) {
|
|
310
|
-
return
|
|
324
|
+
return jsx(Component, Object.assign({}, baseline, {
|
|
311
325
|
ninetailed: {
|
|
312
326
|
isPersonalized,
|
|
313
327
|
audience
|
|
@@ -316,24 +330,26 @@ const Personalize = _ref => {
|
|
|
316
330
|
}
|
|
317
331
|
if (loading) {
|
|
318
332
|
if (LoadingComponent) {
|
|
319
|
-
return
|
|
333
|
+
return jsx(LoadingComponent, {});
|
|
320
334
|
}
|
|
321
|
-
return
|
|
335
|
+
return jsx("div", Object.assign({
|
|
322
336
|
style: {
|
|
323
337
|
opacity: 0
|
|
324
|
-
}
|
|
325
|
-
|
|
338
|
+
}
|
|
339
|
+
}, {
|
|
340
|
+
children: jsx(Component, Object.assign({}, variant, {
|
|
326
341
|
ninetailed: {
|
|
327
342
|
isPersonalized,
|
|
328
343
|
audience
|
|
329
344
|
}
|
|
330
345
|
}))
|
|
331
|
-
}, "hide");
|
|
346
|
+
}), "hide");
|
|
332
347
|
}
|
|
333
|
-
return
|
|
348
|
+
return jsx(TrackHasSeenComponent, Object.assign({
|
|
334
349
|
variant: variant,
|
|
335
350
|
audience: audience,
|
|
336
|
-
isPersonalized: isPersonalized
|
|
351
|
+
isPersonalized: isPersonalized
|
|
352
|
+
}, {
|
|
337
353
|
children: /*#__PURE__*/createElement(Component, Object.assign({}, variant, {
|
|
338
354
|
key: `${audience.id}-${variant.id}`,
|
|
339
355
|
ninetailed: {
|
|
@@ -341,7 +357,7 @@ const Personalize = _ref => {
|
|
|
341
357
|
audience
|
|
342
358
|
}
|
|
343
359
|
}))
|
|
344
|
-
});
|
|
360
|
+
}));
|
|
345
361
|
};
|
|
346
362
|
|
|
347
363
|
const generateSelectors = id => {
|
|
@@ -372,7 +388,7 @@ const MergeTag = ({
|
|
|
372
388
|
return null;
|
|
373
389
|
}
|
|
374
390
|
const value = selectValueFromProfile(profile, id) || fallback;
|
|
375
|
-
return value ?
|
|
391
|
+
return value ? jsx(Fragment, {
|
|
376
392
|
children: value
|
|
377
393
|
}) : null;
|
|
378
394
|
};
|
|
@@ -413,12 +429,12 @@ const ComponentMarker = /*#__PURE__*/forwardRef((_, ref) => {
|
|
|
413
429
|
} = useNinetailed();
|
|
414
430
|
const markerRef = useRef(null);
|
|
415
431
|
useEffect(() => {
|
|
416
|
-
var
|
|
417
|
-
/*
|
|
418
|
-
Due to React's limitation on setting !important styles during rendering, we set the display property on the DOM element directly.
|
|
419
|
-
See: https://github.com/facebook/react/issues/1881
|
|
432
|
+
var _a;
|
|
433
|
+
/*
|
|
434
|
+
Due to React's limitation on setting !important styles during rendering, we set the display property on the DOM element directly.
|
|
435
|
+
See: https://github.com/facebook/react/issues/1881
|
|
420
436
|
*/
|
|
421
|
-
(
|
|
437
|
+
(_a = markerRef.current) === null || _a === void 0 ? void 0 : _a.style.setProperty('display', 'none', 'important');
|
|
422
438
|
}, []);
|
|
423
439
|
useEffect(() => {
|
|
424
440
|
logger.debug('Using fallback mechanism to detect when experiences are seen. This can lead to inaccurate results. Consider using a forwardRef instead. See: https://docs.ninetailed.io/for-developers/experience-sdk/rendering-experiences#tracking-impressions-of-experiences');
|
|
@@ -435,7 +451,7 @@ const ComponentMarker = /*#__PURE__*/forwardRef((_, ref) => {
|
|
|
435
451
|
}
|
|
436
452
|
}
|
|
437
453
|
}, []);
|
|
438
|
-
return
|
|
454
|
+
return jsx("div", {
|
|
439
455
|
className: "nt-cmp-marker",
|
|
440
456
|
style: {
|
|
441
457
|
display: 'none'
|
|
@@ -449,7 +465,6 @@ const getObservableSibling = element => {
|
|
|
449
465
|
return null;
|
|
450
466
|
}
|
|
451
467
|
const nextSiblingStyle = getComputedStyle(nextSibling);
|
|
452
|
-
|
|
453
468
|
// Elements with display: none are not observable by the IntersectionObserver
|
|
454
469
|
if (nextSiblingStyle.display !== 'none') {
|
|
455
470
|
return nextSibling;
|
|
@@ -470,15 +485,13 @@ const getObservableElement = element => {
|
|
|
470
485
|
return getObservableElement(parentElement);
|
|
471
486
|
};
|
|
472
487
|
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
const DefaultExperienceLoadingComponent = _ref => {
|
|
476
|
-
let {
|
|
488
|
+
const DefaultExperienceLoadingComponent = _a => {
|
|
489
|
+
var {
|
|
477
490
|
component: Component,
|
|
478
491
|
unhideAfterMs = 5000,
|
|
479
492
|
passthroughProps
|
|
480
|
-
} =
|
|
481
|
-
baseline =
|
|
493
|
+
} = _a,
|
|
494
|
+
baseline = __rest(_a, ["component", "unhideAfterMs", "passthroughProps"]);
|
|
482
495
|
const {
|
|
483
496
|
logger
|
|
484
497
|
} = useNinetailed();
|
|
@@ -493,11 +506,12 @@ const DefaultExperienceLoadingComponent = _ref => {
|
|
|
493
506
|
};
|
|
494
507
|
}, []);
|
|
495
508
|
if (hidden) {
|
|
496
|
-
return
|
|
509
|
+
return jsx("div", Object.assign({
|
|
497
510
|
style: {
|
|
498
511
|
opacity: 0
|
|
499
|
-
}
|
|
500
|
-
|
|
512
|
+
}
|
|
513
|
+
}, {
|
|
514
|
+
children: jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
501
515
|
ninetailed: {
|
|
502
516
|
isPersonalized: false,
|
|
503
517
|
audience: {
|
|
@@ -505,9 +519,9 @@ const DefaultExperienceLoadingComponent = _ref => {
|
|
|
505
519
|
}
|
|
506
520
|
}
|
|
507
521
|
}))
|
|
508
|
-
}, "hide");
|
|
522
|
+
}), "hide");
|
|
509
523
|
}
|
|
510
|
-
return
|
|
524
|
+
return jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
511
525
|
ninetailed: {
|
|
512
526
|
isPersonalized: false,
|
|
513
527
|
audience: {
|
|
@@ -516,14 +530,14 @@ const DefaultExperienceLoadingComponent = _ref => {
|
|
|
516
530
|
}
|
|
517
531
|
}));
|
|
518
532
|
};
|
|
519
|
-
const Experience =
|
|
520
|
-
|
|
533
|
+
const Experience = _a => {
|
|
534
|
+
var {
|
|
521
535
|
experiences,
|
|
522
536
|
component: Component,
|
|
523
537
|
loadingComponent: LoadingComponent = DefaultExperienceLoadingComponent,
|
|
524
538
|
passthroughProps
|
|
525
|
-
} =
|
|
526
|
-
baseline =
|
|
539
|
+
} = _a,
|
|
540
|
+
baseline = __rest(_a, ["experiences", "component", "loadingComponent", "passthroughProps"]);
|
|
527
541
|
const {
|
|
528
542
|
observeElement,
|
|
529
543
|
unobserveElement,
|
|
@@ -541,10 +555,9 @@ const Experience = _ref2 => {
|
|
|
541
555
|
baseline,
|
|
542
556
|
experiences
|
|
543
557
|
});
|
|
544
|
-
|
|
545
558
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
546
559
|
// @ts-ignore
|
|
547
|
-
const isComponentForwardRef = isForwardRef(
|
|
560
|
+
const isComponentForwardRef = isForwardRef(jsx(Component, {}));
|
|
548
561
|
const componentRef = useRef(null);
|
|
549
562
|
const isVariantHidden = 'hidden' in variant && variant.hidden;
|
|
550
563
|
useEffect(() => {
|
|
@@ -566,7 +579,7 @@ const Experience = _ref2 => {
|
|
|
566
579
|
experience,
|
|
567
580
|
componentType: 'Entry',
|
|
568
581
|
audience,
|
|
569
|
-
variant: isVariantHidden ? Object.assign({}, variant, {
|
|
582
|
+
variant: isVariantHidden ? Object.assign(Object.assign({}, variant), {
|
|
570
583
|
id: `${baseline.id}-hidden`
|
|
571
584
|
}) : variant,
|
|
572
585
|
variantIndex
|
|
@@ -582,10 +595,10 @@ const Experience = _ref2 => {
|
|
|
582
595
|
};
|
|
583
596
|
}, [observeElement, unobserveElement, experience, baseline, variant, variantIndex, audience, isVariantHidden]);
|
|
584
597
|
if (!hasVariants) {
|
|
585
|
-
return
|
|
586
|
-
children: [!isComponentForwardRef &&
|
|
598
|
+
return jsxs(Fragment, {
|
|
599
|
+
children: [!isComponentForwardRef && jsx(ComponentMarker, {
|
|
587
600
|
ref: componentRef
|
|
588
|
-
}, `marker-no-variants-${(experience
|
|
601
|
+
}, `marker-no-variants-${(experience === null || experience === void 0 ? void 0 : experience.id) || 'baseline'}-${variant.id}`), /*#__PURE__*/createElement(Component, Object.assign({}, passthroughProps, baseline, {
|
|
589
602
|
key: baseline.id
|
|
590
603
|
}, isComponentForwardRef ? {
|
|
591
604
|
ref: componentRef
|
|
@@ -601,19 +614,19 @@ const Experience = _ref2 => {
|
|
|
601
614
|
}));
|
|
602
615
|
}
|
|
603
616
|
if (isVariantHidden) {
|
|
604
|
-
return
|
|
617
|
+
return jsx(ComponentMarker, {
|
|
605
618
|
ref: componentRef
|
|
606
|
-
}, `marker-hidden-${(experience
|
|
619
|
+
}, `marker-hidden-${(experience === null || experience === void 0 ? void 0 : experience.id) || 'baseline'}-${variant.id}`);
|
|
607
620
|
}
|
|
608
|
-
return
|
|
609
|
-
children: [!isComponentForwardRef &&
|
|
621
|
+
return jsxs(Fragment, {
|
|
622
|
+
children: [!isComponentForwardRef && jsx(ComponentMarker, {
|
|
610
623
|
ref: componentRef
|
|
611
|
-
}, `marker-${(experience
|
|
612
|
-
key: `${(experience
|
|
624
|
+
}, `marker-${(experience === null || experience === void 0 ? void 0 : experience.id) || 'baseline'}-${variant.id}`), /*#__PURE__*/createElement(Component, Object.assign({}, Object.assign(Object.assign({}, passthroughProps), variant), {
|
|
625
|
+
key: `${(experience === null || experience === void 0 ? void 0 : experience.id) || 'baseline'}-${variant.id}`,
|
|
613
626
|
ninetailed: {
|
|
614
627
|
isPersonalized,
|
|
615
628
|
audience: {
|
|
616
|
-
id: (audience
|
|
629
|
+
id: (audience === null || audience === void 0 ? void 0 : audience.id) || 'all visitors'
|
|
617
630
|
}
|
|
618
631
|
}
|
|
619
632
|
}, isComponentForwardRef ? {
|
|
@@ -622,18 +635,18 @@ const Experience = _ref2 => {
|
|
|
622
635
|
});
|
|
623
636
|
};
|
|
624
637
|
|
|
625
|
-
const _excluded$1 = ["experiences", "component", "passthroughProps"];
|
|
626
638
|
const ESRContext = /*#__PURE__*/React.createContext(undefined);
|
|
627
639
|
const ESRProvider = ({
|
|
628
640
|
experienceVariantsMap,
|
|
629
641
|
children
|
|
630
642
|
}) => {
|
|
631
|
-
return
|
|
643
|
+
return jsx(ESRContext.Provider, Object.assign({
|
|
632
644
|
value: {
|
|
633
645
|
experienceVariantsMap
|
|
634
|
-
}
|
|
646
|
+
}
|
|
647
|
+
}, {
|
|
635
648
|
children: children
|
|
636
|
-
});
|
|
649
|
+
}));
|
|
637
650
|
};
|
|
638
651
|
const useESR = () => {
|
|
639
652
|
const context = React.useContext(ESRContext);
|
|
@@ -644,19 +657,19 @@ const useESR = () => {
|
|
|
644
657
|
experienceVariantsMap: context.experienceVariantsMap
|
|
645
658
|
};
|
|
646
659
|
};
|
|
647
|
-
const ESRLoadingComponent =
|
|
648
|
-
|
|
660
|
+
const ESRLoadingComponent = _a => {
|
|
661
|
+
var {
|
|
649
662
|
experiences,
|
|
650
663
|
component: Component,
|
|
651
664
|
passthroughProps
|
|
652
|
-
} =
|
|
653
|
-
baseline =
|
|
665
|
+
} = _a,
|
|
666
|
+
baseline = __rest(_a, ["experiences", "component", "passthroughProps"]);
|
|
654
667
|
const {
|
|
655
668
|
experienceVariantsMap
|
|
656
669
|
} = useESR();
|
|
657
670
|
const experience = experiences.find(experience => Object.prototype.hasOwnProperty.call(experienceVariantsMap, experience.id));
|
|
658
671
|
if (!experience) {
|
|
659
|
-
return
|
|
672
|
+
return jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
660
673
|
ninetailed: {
|
|
661
674
|
isPersonalized: false,
|
|
662
675
|
audience: {
|
|
@@ -675,7 +688,7 @@ const ESRLoadingComponent = _ref => {
|
|
|
675
688
|
return component.baseline.id === baseline.id;
|
|
676
689
|
});
|
|
677
690
|
if (!component) {
|
|
678
|
-
return
|
|
691
|
+
return jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
679
692
|
ninetailed: {
|
|
680
693
|
isPersonalized: false,
|
|
681
694
|
audience: {
|
|
@@ -685,7 +698,7 @@ const ESRLoadingComponent = _ref => {
|
|
|
685
698
|
}));
|
|
686
699
|
}
|
|
687
700
|
if (experienceVariantsMap[experience.id] === 0) {
|
|
688
|
-
return
|
|
701
|
+
return jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
689
702
|
ninetailed: {
|
|
690
703
|
isPersonalized: false,
|
|
691
704
|
audience: {
|
|
@@ -696,7 +709,7 @@ const ESRLoadingComponent = _ref => {
|
|
|
696
709
|
}
|
|
697
710
|
const variant = component.variants[experienceVariantsMap[experience.id] - 1];
|
|
698
711
|
if (!variant) {
|
|
699
|
-
return
|
|
712
|
+
return jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
700
713
|
ninetailed: {
|
|
701
714
|
isPersonalized: false,
|
|
702
715
|
audience: {
|
|
@@ -705,7 +718,7 @@ const ESRLoadingComponent = _ref => {
|
|
|
705
718
|
}
|
|
706
719
|
}));
|
|
707
720
|
}
|
|
708
|
-
return
|
|
721
|
+
return jsx(Component, Object.assign({}, passthroughProps, variant, {
|
|
709
722
|
ninetailed: {
|
|
710
723
|
isPersonalized: false,
|
|
711
724
|
audience: {
|
|
@@ -715,14 +728,13 @@ const ESRLoadingComponent = _ref => {
|
|
|
715
728
|
}));
|
|
716
729
|
};
|
|
717
730
|
|
|
718
|
-
const
|
|
719
|
-
|
|
720
|
-
let {
|
|
731
|
+
const EntryAnalytics = _a => {
|
|
732
|
+
var {
|
|
721
733
|
component: Component,
|
|
722
734
|
passthroughProps
|
|
723
|
-
} =
|
|
724
|
-
entry =
|
|
725
|
-
return
|
|
735
|
+
} = _a,
|
|
736
|
+
entry = __rest(_a, ["component", "passthroughProps"]);
|
|
737
|
+
return jsx(Experience, Object.assign({}, passthroughProps, entry, {
|
|
726
738
|
id: entry.id,
|
|
727
739
|
component: Component,
|
|
728
740
|
experiences: []
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js-react",
|
|
3
|
-
"version": "7.18.
|
|
3
|
+
"version": "7.18.13",
|
|
4
4
|
"description": "Ninetailed SDK for React",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
},
|
|
29
29
|
"sideEffects": false,
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@ninetailed/experience.js": "7.18.
|
|
32
|
-
"@ninetailed/experience.js-shared": "7.18.
|
|
33
|
-
"@ninetailed/experience.js-plugin-analytics": "7.18.
|
|
31
|
+
"@ninetailed/experience.js": "7.18.13",
|
|
32
|
+
"@ninetailed/experience.js-shared": "7.18.13",
|
|
33
|
+
"@ninetailed/experience.js-plugin-analytics": "7.18.13",
|
|
34
34
|
"radash": "10.9.0",
|
|
35
|
-
"react-is": "18.
|
|
35
|
+
"react-is": "18.3.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": ">=16.8.0"
|