@ninetailed/experience.js-react 7.5.3-beta.2 → 7.5.3-beta.4
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 → index.cjs} +5 -3
- package/{index.esm.js → index.js} +114 -102
- package/package.json +12 -18
- package/src/lib/Experience/ESRLoadingComponent.d.ts +1 -1
- package/src/lib/Experience/Experience.d.ts +1 -1
- package/src/lib/MergeTag/MergeTag.d.ts +1 -1
- package/src/lib/NinetailedProvider.d.ts +1 -1
- package/src/lib/Personalize.d.ts +1 -1
- package/index.cjs.d.ts +0 -1
|
@@ -508,6 +508,7 @@ const Experience = _a => {
|
|
|
508
508
|
// @ts-ignore
|
|
509
509
|
const isComponentForwardRef = reactIs.isForwardRef(jsxRuntime.jsx(Component, {}));
|
|
510
510
|
const componentRef = React.useRef(null);
|
|
511
|
+
const isVariantHidden = 'hidden' in variant && variant.hidden;
|
|
511
512
|
React.useEffect(() => {
|
|
512
513
|
const componentElement = componentRef.current;
|
|
513
514
|
if (componentElement && !(componentElement instanceof Element)) {
|
|
@@ -524,7 +525,9 @@ const Experience = _a => {
|
|
|
524
525
|
element: componentElement,
|
|
525
526
|
experience,
|
|
526
527
|
audience,
|
|
527
|
-
variant,
|
|
528
|
+
variant: isVariantHidden ? Object.assign(Object.assign({}, variant), {
|
|
529
|
+
id: `${baseline.id}-hidden`
|
|
530
|
+
}) : variant,
|
|
528
531
|
variantIndex
|
|
529
532
|
});
|
|
530
533
|
return () => {
|
|
@@ -536,7 +539,7 @@ const Experience = _a => {
|
|
|
536
539
|
return () => {
|
|
537
540
|
// noop
|
|
538
541
|
};
|
|
539
|
-
}, [observeElement, unobserveElement, experience, baseline, variant, variantIndex, audience]);
|
|
542
|
+
}, [observeElement, unobserveElement, experience, baseline, variant, variantIndex, audience, isVariantHidden]);
|
|
540
543
|
if (!hasVariants) {
|
|
541
544
|
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
542
545
|
children: [!isComponentForwardRef && jsxRuntime.jsx(ComponentMarker, {
|
|
@@ -556,7 +559,6 @@ const Experience = _a => {
|
|
|
556
559
|
component: Component
|
|
557
560
|
}));
|
|
558
561
|
}
|
|
559
|
-
const isVariantHidden = 'hidden' in variant && variant.hidden;
|
|
560
562
|
if (isVariantHidden) {
|
|
561
563
|
return jsxRuntime.jsx(ComponentMarker, {
|
|
562
564
|
ref: componentRef,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
1
2
|
import React, { createContext, useMemo, useContext, useState, useRef, useEffect, createElement, forwardRef } from 'react';
|
|
2
3
|
import { Ninetailed, selectVariant, makeExperienceSelectMiddleware, selectHasExperienceVariants, selectExperience, selectExperienceVariant } from '@ninetailed/experience.js';
|
|
3
|
-
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { logger, isBrowser } from '@ninetailed/experience.js-shared';
|
|
5
5
|
import { isEqual, get } from 'radash';
|
|
6
6
|
import { useInView } from 'react-intersection-observer';
|
|
@@ -48,10 +48,11 @@ const NinetailedProvider = props => {
|
|
|
48
48
|
const {
|
|
49
49
|
children
|
|
50
50
|
} = props;
|
|
51
|
-
return
|
|
52
|
-
value: ninetailed
|
|
51
|
+
return jsx(NinetailedContext.Provider, Object.assign({
|
|
52
|
+
value: ninetailed
|
|
53
|
+
}, {
|
|
53
54
|
children: children
|
|
54
|
-
});
|
|
55
|
+
}));
|
|
55
56
|
};
|
|
56
57
|
|
|
57
58
|
const useNinetailed = () => {
|
|
@@ -62,30 +63,42 @@ const useNinetailed = () => {
|
|
|
62
63
|
return ninetailed;
|
|
63
64
|
};
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
/******************************************************************************
|
|
67
|
+
Copyright (c) Microsoft Corporation.
|
|
68
|
+
|
|
69
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
70
|
+
purpose with or without fee is hereby granted.
|
|
71
|
+
|
|
72
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
73
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
74
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
75
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
76
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
77
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
78
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
79
|
+
***************************************************************************** */
|
|
80
|
+
|
|
81
|
+
function __rest(s, e) {
|
|
82
|
+
var t = {};
|
|
83
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
84
|
+
t[p] = s[p];
|
|
85
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
86
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
87
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
88
|
+
t[p[i]] = s[p[i]];
|
|
89
|
+
}
|
|
90
|
+
return t;
|
|
76
91
|
}
|
|
77
92
|
|
|
78
|
-
const _excluded$4 = ["experiences"];
|
|
79
93
|
const useProfile = () => {
|
|
80
94
|
const ninetailed = useNinetailed();
|
|
81
95
|
const [profileState, setProfileState] = useState(ninetailed.profileState);
|
|
82
96
|
const profileStateRef = useRef({});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* Furthermore, it was also observed, that it "only" occurred when the preview plugin was used in parallel.
|
|
97
|
+
/**
|
|
98
|
+
* This effect compares the old and new profile state before updating it.
|
|
99
|
+
* We use a ref to avoid an infinite loop which can happen when an empty profile state was updated with no changes.
|
|
100
|
+
* This behaviour occurred as the validation handling on the error property was not set properly in the "CreateProfile" and "UpdateProfile" endpoint types.
|
|
101
|
+
* Furthermore, it was also observed, that it "only" occurred when the preview plugin was used in parallel.
|
|
89
102
|
*/
|
|
90
103
|
useEffect(() => {
|
|
91
104
|
ninetailed.onProfileChange(profileState => {
|
|
@@ -99,8 +112,8 @@ const useProfile = () => {
|
|
|
99
112
|
}
|
|
100
113
|
});
|
|
101
114
|
}, []);
|
|
102
|
-
const profileStateWithoutExperiences =
|
|
103
|
-
return Object.assign({}, profileStateWithoutExperiences, {
|
|
115
|
+
const profileStateWithoutExperiences = __rest(profileState, ["experiences"]);
|
|
116
|
+
return Object.assign(Object.assign({}, profileStateWithoutExperiences), {
|
|
104
117
|
loading: profileState.status === 'loading'
|
|
105
118
|
});
|
|
106
119
|
};
|
|
@@ -134,22 +147,21 @@ const TrackHasSeenComponent = ({
|
|
|
134
147
|
});
|
|
135
148
|
}
|
|
136
149
|
}, [inView]);
|
|
137
|
-
return
|
|
138
|
-
children: [
|
|
150
|
+
return jsxs(Fragment, {
|
|
151
|
+
children: [jsx("div", {
|
|
139
152
|
ref: ref
|
|
140
153
|
}), children]
|
|
141
154
|
});
|
|
142
155
|
};
|
|
143
156
|
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
let {
|
|
157
|
+
const Personalize = _a => {
|
|
158
|
+
var {
|
|
147
159
|
component: Component,
|
|
148
160
|
loadingComponent: LoadingComponent,
|
|
149
161
|
variants = [],
|
|
150
162
|
holdout = -1
|
|
151
|
-
} =
|
|
152
|
-
baseline =
|
|
163
|
+
} = _a,
|
|
164
|
+
baseline = __rest(_a, ["component", "loadingComponent", "variants", "holdout"]);
|
|
153
165
|
const {
|
|
154
166
|
loading,
|
|
155
167
|
variant,
|
|
@@ -160,7 +172,7 @@ const Personalize = _ref => {
|
|
|
160
172
|
});
|
|
161
173
|
const hasVariants = variants.length > 0;
|
|
162
174
|
if (!hasVariants) {
|
|
163
|
-
return
|
|
175
|
+
return jsx(Component, Object.assign({}, baseline, {
|
|
164
176
|
ninetailed: {
|
|
165
177
|
isPersonalized,
|
|
166
178
|
audience
|
|
@@ -169,24 +181,26 @@ const Personalize = _ref => {
|
|
|
169
181
|
}
|
|
170
182
|
if (loading) {
|
|
171
183
|
if (LoadingComponent) {
|
|
172
|
-
return
|
|
184
|
+
return jsx(LoadingComponent, {});
|
|
173
185
|
}
|
|
174
|
-
return
|
|
186
|
+
return jsx("div", Object.assign({
|
|
175
187
|
style: {
|
|
176
188
|
opacity: 0
|
|
177
|
-
}
|
|
178
|
-
|
|
189
|
+
}
|
|
190
|
+
}, {
|
|
191
|
+
children: jsx(Component, Object.assign({}, variant, {
|
|
179
192
|
ninetailed: {
|
|
180
193
|
isPersonalized,
|
|
181
194
|
audience
|
|
182
195
|
}
|
|
183
196
|
}))
|
|
184
|
-
}, "hide");
|
|
197
|
+
}), "hide");
|
|
185
198
|
}
|
|
186
|
-
return
|
|
199
|
+
return jsx(TrackHasSeenComponent, Object.assign({
|
|
187
200
|
variant: variant,
|
|
188
201
|
audience: audience,
|
|
189
|
-
isPersonalized: isPersonalized
|
|
202
|
+
isPersonalized: isPersonalized
|
|
203
|
+
}, {
|
|
190
204
|
children: /*#__PURE__*/createElement(Component, Object.assign({}, variant, {
|
|
191
205
|
key: `${audience.id}-${variant.id}`,
|
|
192
206
|
ninetailed: {
|
|
@@ -194,7 +208,7 @@ const Personalize = _ref => {
|
|
|
194
208
|
audience
|
|
195
209
|
}
|
|
196
210
|
}))
|
|
197
|
-
});
|
|
211
|
+
}));
|
|
198
212
|
};
|
|
199
213
|
|
|
200
214
|
const generateSelectors = id => {
|
|
@@ -225,7 +239,7 @@ const MergeTag = ({
|
|
|
225
239
|
return null;
|
|
226
240
|
}
|
|
227
241
|
const value = selectValueFromProfile(profile, id) || fallback;
|
|
228
|
-
return value ?
|
|
242
|
+
return value ? jsx(Fragment, {
|
|
229
243
|
children: value
|
|
230
244
|
}) : null;
|
|
231
245
|
};
|
|
@@ -259,7 +273,6 @@ const useExperienceSelectionMiddleware = ({
|
|
|
259
273
|
return middleware;
|
|
260
274
|
};
|
|
261
275
|
|
|
262
|
-
const _excluded$2 = ["experience", "variant", "variantIndex"];
|
|
263
276
|
const useExperience = ({
|
|
264
277
|
baseline,
|
|
265
278
|
experiences
|
|
@@ -275,13 +288,13 @@ const useExperience = ({
|
|
|
275
288
|
baseline,
|
|
276
289
|
profile
|
|
277
290
|
});
|
|
278
|
-
const overrideResult =
|
|
279
|
-
|
|
291
|
+
const overrideResult = _a => {
|
|
292
|
+
var {
|
|
280
293
|
experience: originalExperience,
|
|
281
294
|
variant: originalVariant,
|
|
282
295
|
variantIndex: originalVariantIndex
|
|
283
|
-
} =
|
|
284
|
-
other =
|
|
296
|
+
} = _a,
|
|
297
|
+
other = __rest(_a, ["experience", "variant", "variantIndex"]);
|
|
285
298
|
const {
|
|
286
299
|
experience,
|
|
287
300
|
variant,
|
|
@@ -291,21 +304,20 @@ const useExperience = ({
|
|
|
291
304
|
variant: originalVariant,
|
|
292
305
|
variantIndex: originalVariantIndex
|
|
293
306
|
});
|
|
294
|
-
|
|
295
307
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
296
308
|
// @ts-ignore
|
|
297
|
-
return Object.assign({}, other, {
|
|
298
|
-
audience: experience
|
|
309
|
+
return Object.assign(Object.assign({}, other), {
|
|
310
|
+
audience: (experience === null || experience === void 0 ? void 0 : experience.audience) ? experience.audience : null,
|
|
299
311
|
experience,
|
|
300
312
|
variant,
|
|
301
313
|
variantIndex
|
|
302
314
|
});
|
|
303
315
|
};
|
|
304
|
-
const baseReturn = Object.assign({}, profileState, {
|
|
316
|
+
const baseReturn = Object.assign(Object.assign({}, profileState), {
|
|
305
317
|
hasVariants,
|
|
306
318
|
baseline
|
|
307
319
|
});
|
|
308
|
-
const emptyReturn = Object.assign({}, baseReturn, {
|
|
320
|
+
const emptyReturn = Object.assign(Object.assign({}, baseReturn), {
|
|
309
321
|
experience: null,
|
|
310
322
|
variant: baseline,
|
|
311
323
|
variantIndex: 0,
|
|
@@ -335,7 +347,7 @@ const useExperience = ({
|
|
|
335
347
|
if (!experience) {
|
|
336
348
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
337
349
|
// @ts-ignore
|
|
338
|
-
return overrideResult(Object.assign({}, emptyReturn, {
|
|
350
|
+
return overrideResult(Object.assign(Object.assign({}, emptyReturn), {
|
|
339
351
|
profile
|
|
340
352
|
}));
|
|
341
353
|
}
|
|
@@ -347,7 +359,7 @@ const useExperience = ({
|
|
|
347
359
|
experience,
|
|
348
360
|
profile
|
|
349
361
|
});
|
|
350
|
-
return overrideResult(Object.assign({}, baseReturn, {
|
|
362
|
+
return overrideResult(Object.assign(Object.assign({}, baseReturn), {
|
|
351
363
|
status: 'success',
|
|
352
364
|
loading: false,
|
|
353
365
|
error: null,
|
|
@@ -368,12 +380,12 @@ const ComponentMarker = /*#__PURE__*/forwardRef(({
|
|
|
368
380
|
} = useNinetailed();
|
|
369
381
|
const markerRef = useRef(null);
|
|
370
382
|
useEffect(() => {
|
|
371
|
-
var
|
|
372
|
-
/*
|
|
373
|
-
Due to React's limitation on setting !important styles during rendering, we set the display property on the DOM element directly.
|
|
374
|
-
See: https://github.com/facebook/react/issues/1881
|
|
383
|
+
var _a;
|
|
384
|
+
/*
|
|
385
|
+
Due to React's limitation on setting !important styles during rendering, we set the display property on the DOM element directly.
|
|
386
|
+
See: https://github.com/facebook/react/issues/1881
|
|
375
387
|
*/
|
|
376
|
-
(
|
|
388
|
+
(_a = markerRef.current) === null || _a === void 0 ? void 0 : _a.style.setProperty('display', 'none', 'important');
|
|
377
389
|
}, []);
|
|
378
390
|
useEffect(() => {
|
|
379
391
|
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');
|
|
@@ -390,7 +402,7 @@ const ComponentMarker = /*#__PURE__*/forwardRef(({
|
|
|
390
402
|
}
|
|
391
403
|
}
|
|
392
404
|
}, [_hidden]);
|
|
393
|
-
return
|
|
405
|
+
return jsx("div", {
|
|
394
406
|
className: "nt-cmp-marker",
|
|
395
407
|
style: {
|
|
396
408
|
display: 'none'
|
|
@@ -414,15 +426,13 @@ const getNextSibling = (element, recursive = false) => {
|
|
|
414
426
|
return getNextSibling(parentElement, true);
|
|
415
427
|
};
|
|
416
428
|
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
const DefaultExperienceLoadingComponent = _ref => {
|
|
420
|
-
let {
|
|
429
|
+
const DefaultExperienceLoadingComponent = _a => {
|
|
430
|
+
var {
|
|
421
431
|
component: Component,
|
|
422
432
|
unhideAfterMs = 5000,
|
|
423
433
|
passthroughProps
|
|
424
|
-
} =
|
|
425
|
-
baseline =
|
|
434
|
+
} = _a,
|
|
435
|
+
baseline = __rest(_a, ["component", "unhideAfterMs", "passthroughProps"]);
|
|
426
436
|
const {
|
|
427
437
|
logger
|
|
428
438
|
} = useNinetailed();
|
|
@@ -437,11 +447,12 @@ const DefaultExperienceLoadingComponent = _ref => {
|
|
|
437
447
|
};
|
|
438
448
|
}, []);
|
|
439
449
|
if (hidden) {
|
|
440
|
-
return
|
|
450
|
+
return jsx("div", Object.assign({
|
|
441
451
|
style: {
|
|
442
452
|
opacity: 0
|
|
443
|
-
}
|
|
444
|
-
|
|
453
|
+
}
|
|
454
|
+
}, {
|
|
455
|
+
children: jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
445
456
|
ninetailed: {
|
|
446
457
|
isPersonalized: false,
|
|
447
458
|
audience: {
|
|
@@ -449,9 +460,9 @@ const DefaultExperienceLoadingComponent = _ref => {
|
|
|
449
460
|
}
|
|
450
461
|
}
|
|
451
462
|
}))
|
|
452
|
-
}, "hide");
|
|
463
|
+
}), "hide");
|
|
453
464
|
}
|
|
454
|
-
return
|
|
465
|
+
return jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
455
466
|
ninetailed: {
|
|
456
467
|
isPersonalized: false,
|
|
457
468
|
audience: {
|
|
@@ -460,14 +471,14 @@ const DefaultExperienceLoadingComponent = _ref => {
|
|
|
460
471
|
}
|
|
461
472
|
}));
|
|
462
473
|
};
|
|
463
|
-
const Experience =
|
|
464
|
-
|
|
474
|
+
const Experience = _a => {
|
|
475
|
+
var {
|
|
465
476
|
experiences,
|
|
466
477
|
component: Component,
|
|
467
478
|
loadingComponent: LoadingComponent = DefaultExperienceLoadingComponent,
|
|
468
479
|
passthroughProps
|
|
469
|
-
} =
|
|
470
|
-
baseline =
|
|
480
|
+
} = _a,
|
|
481
|
+
baseline = __rest(_a, ["experiences", "component", "loadingComponent", "passthroughProps"]);
|
|
471
482
|
const {
|
|
472
483
|
observeElement,
|
|
473
484
|
unobserveElement,
|
|
@@ -485,11 +496,11 @@ const Experience = _ref2 => {
|
|
|
485
496
|
baseline,
|
|
486
497
|
experiences
|
|
487
498
|
});
|
|
488
|
-
|
|
489
499
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
490
500
|
// @ts-ignore
|
|
491
|
-
const isComponentForwardRef = isForwardRef(
|
|
501
|
+
const isComponentForwardRef = isForwardRef(jsx(Component, {}));
|
|
492
502
|
const componentRef = useRef(null);
|
|
503
|
+
const isVariantHidden = 'hidden' in variant && variant.hidden;
|
|
493
504
|
useEffect(() => {
|
|
494
505
|
const componentElement = componentRef.current;
|
|
495
506
|
if (componentElement && !(componentElement instanceof Element)) {
|
|
@@ -506,7 +517,9 @@ const Experience = _ref2 => {
|
|
|
506
517
|
element: componentElement,
|
|
507
518
|
experience,
|
|
508
519
|
audience,
|
|
509
|
-
variant,
|
|
520
|
+
variant: isVariantHidden ? Object.assign(Object.assign({}, variant), {
|
|
521
|
+
id: `${baseline.id}-hidden`
|
|
522
|
+
}) : variant,
|
|
510
523
|
variantIndex
|
|
511
524
|
});
|
|
512
525
|
return () => {
|
|
@@ -518,12 +531,12 @@ const Experience = _ref2 => {
|
|
|
518
531
|
return () => {
|
|
519
532
|
// noop
|
|
520
533
|
};
|
|
521
|
-
}, [observeElement, unobserveElement, experience, baseline, variant, variantIndex, audience]);
|
|
534
|
+
}, [observeElement, unobserveElement, experience, baseline, variant, variantIndex, audience, isVariantHidden]);
|
|
522
535
|
if (!hasVariants) {
|
|
523
|
-
return
|
|
524
|
-
children: [!isComponentForwardRef &&
|
|
536
|
+
return jsxs(Fragment, {
|
|
537
|
+
children: [!isComponentForwardRef && jsx(ComponentMarker, {
|
|
525
538
|
ref: componentRef
|
|
526
|
-
}, `marker-no-variants-${(experience
|
|
539
|
+
}, `marker-no-variants-${(experience === null || experience === void 0 ? void 0 : experience.id) || 'baseline'}-${variant.id}`), /*#__PURE__*/createElement(Component, Object.assign({}, passthroughProps, baseline, {
|
|
527
540
|
key: baseline.id
|
|
528
541
|
}, isComponentForwardRef ? {
|
|
529
542
|
ref: componentRef
|
|
@@ -538,22 +551,21 @@ const Experience = _ref2 => {
|
|
|
538
551
|
component: Component
|
|
539
552
|
}));
|
|
540
553
|
}
|
|
541
|
-
const isVariantHidden = 'hidden' in variant && variant.hidden;
|
|
542
554
|
if (isVariantHidden) {
|
|
543
|
-
return
|
|
555
|
+
return jsx(ComponentMarker, {
|
|
544
556
|
ref: componentRef,
|
|
545
557
|
hidden: true
|
|
546
|
-
}, `marker-hidden-${(experience
|
|
558
|
+
}, `marker-hidden-${(experience === null || experience === void 0 ? void 0 : experience.id) || 'baseline'}-${variant.id}`);
|
|
547
559
|
}
|
|
548
|
-
return
|
|
549
|
-
children: [!isComponentForwardRef &&
|
|
560
|
+
return jsxs(Fragment, {
|
|
561
|
+
children: [!isComponentForwardRef && jsx(ComponentMarker, {
|
|
550
562
|
ref: componentRef
|
|
551
|
-
}, `marker-${(experience
|
|
552
|
-
key: `${(experience
|
|
563
|
+
}, `marker-${(experience === null || experience === void 0 ? void 0 : experience.id) || 'baseline'}-${variant.id}`), /*#__PURE__*/createElement(Component, Object.assign({}, Object.assign(Object.assign({}, passthroughProps), variant), {
|
|
564
|
+
key: `${(experience === null || experience === void 0 ? void 0 : experience.id) || 'baseline'}-${variant.id}`,
|
|
553
565
|
ninetailed: {
|
|
554
566
|
isPersonalized,
|
|
555
567
|
audience: {
|
|
556
|
-
id: (audience
|
|
568
|
+
id: (audience === null || audience === void 0 ? void 0 : audience.id) || 'all visitors'
|
|
557
569
|
}
|
|
558
570
|
}
|
|
559
571
|
}, isComponentForwardRef ? {
|
|
@@ -562,18 +574,18 @@ const Experience = _ref2 => {
|
|
|
562
574
|
});
|
|
563
575
|
};
|
|
564
576
|
|
|
565
|
-
const _excluded = ["experiences", "component", "passthroughProps"];
|
|
566
577
|
const ESRContext = /*#__PURE__*/React.createContext(undefined);
|
|
567
578
|
const ESRProvider = ({
|
|
568
579
|
experienceVariantsMap,
|
|
569
580
|
children
|
|
570
581
|
}) => {
|
|
571
|
-
return
|
|
582
|
+
return jsx(ESRContext.Provider, Object.assign({
|
|
572
583
|
value: {
|
|
573
584
|
experienceVariantsMap
|
|
574
|
-
}
|
|
585
|
+
}
|
|
586
|
+
}, {
|
|
575
587
|
children: children
|
|
576
|
-
});
|
|
588
|
+
}));
|
|
577
589
|
};
|
|
578
590
|
const useESR = () => {
|
|
579
591
|
const context = React.useContext(ESRContext);
|
|
@@ -584,19 +596,19 @@ const useESR = () => {
|
|
|
584
596
|
experienceVariantsMap: context.experienceVariantsMap
|
|
585
597
|
};
|
|
586
598
|
};
|
|
587
|
-
const ESRLoadingComponent =
|
|
588
|
-
|
|
599
|
+
const ESRLoadingComponent = _a => {
|
|
600
|
+
var {
|
|
589
601
|
experiences,
|
|
590
602
|
component: Component,
|
|
591
603
|
passthroughProps
|
|
592
|
-
} =
|
|
593
|
-
baseline =
|
|
604
|
+
} = _a,
|
|
605
|
+
baseline = __rest(_a, ["experiences", "component", "passthroughProps"]);
|
|
594
606
|
const {
|
|
595
607
|
experienceVariantsMap
|
|
596
608
|
} = useESR();
|
|
597
609
|
const experience = experiences.find(experience => Object.prototype.hasOwnProperty.call(experienceVariantsMap, experience.id));
|
|
598
610
|
if (!experience) {
|
|
599
|
-
return
|
|
611
|
+
return jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
600
612
|
ninetailed: {
|
|
601
613
|
isPersonalized: false,
|
|
602
614
|
audience: {
|
|
@@ -607,7 +619,7 @@ const ESRLoadingComponent = _ref => {
|
|
|
607
619
|
}
|
|
608
620
|
const component = experience.components.find(component => component.baseline.id === baseline.id);
|
|
609
621
|
if (!component) {
|
|
610
|
-
return
|
|
622
|
+
return jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
611
623
|
ninetailed: {
|
|
612
624
|
isPersonalized: false,
|
|
613
625
|
audience: {
|
|
@@ -617,7 +629,7 @@ const ESRLoadingComponent = _ref => {
|
|
|
617
629
|
}));
|
|
618
630
|
}
|
|
619
631
|
if (experienceVariantsMap[experience.id] === 0) {
|
|
620
|
-
return
|
|
632
|
+
return jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
621
633
|
ninetailed: {
|
|
622
634
|
isPersonalized: false,
|
|
623
635
|
audience: {
|
|
@@ -628,7 +640,7 @@ const ESRLoadingComponent = _ref => {
|
|
|
628
640
|
}
|
|
629
641
|
const variant = component.variants[experienceVariantsMap[experience.id] - 1];
|
|
630
642
|
if (!variant) {
|
|
631
|
-
return
|
|
643
|
+
return jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
632
644
|
ninetailed: {
|
|
633
645
|
isPersonalized: false,
|
|
634
646
|
audience: {
|
|
@@ -637,7 +649,7 @@ const ESRLoadingComponent = _ref => {
|
|
|
637
649
|
}
|
|
638
650
|
}));
|
|
639
651
|
}
|
|
640
|
-
return
|
|
652
|
+
return jsx(Component, Object.assign({}, passthroughProps, variant, {
|
|
641
653
|
ninetailed: {
|
|
642
654
|
isPersonalized: false,
|
|
643
655
|
audience: {
|
package/package.json
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js-react",
|
|
3
|
-
"version": "7.5.3-beta.
|
|
3
|
+
"version": "7.5.3-beta.4",
|
|
4
4
|
"description": "Ninetailed SDK for React",
|
|
5
|
-
"dependencies": {
|
|
6
|
-
"@ninetailed/experience.js": "*",
|
|
7
|
-
"@ninetailed/experience.js-shared": "*",
|
|
8
|
-
"radash": "10.9.0",
|
|
9
|
-
"react-intersection-observer": "8.34.0",
|
|
10
|
-
"react-is": "18.2.0",
|
|
11
|
-
"@testing-library/react-hooks": "7.0.2",
|
|
12
|
-
"@testing-library/react": "13.4.0"
|
|
13
|
-
},
|
|
14
5
|
"peerDependencies": {
|
|
15
6
|
"react": ">=16.8.0"
|
|
16
7
|
},
|
|
@@ -20,12 +11,15 @@
|
|
|
20
11
|
"url": "https://github.com/ninetailed-inc/experience.js.git",
|
|
21
12
|
"directory": "packages/sdks/react"
|
|
22
13
|
},
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
14
|
+
"module": "./index.js",
|
|
15
|
+
"main": "./index.cjs",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"types": "./src/index.d.ts",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@ninetailed/experience.js": "7.5.3-beta.4",
|
|
20
|
+
"@ninetailed/experience.js-shared": "7.5.3-beta.4",
|
|
21
|
+
"radash": "10.9.0",
|
|
22
|
+
"react-intersection-observer": "8.34.0",
|
|
23
|
+
"react-is": "18.2.0"
|
|
24
|
+
}
|
|
31
25
|
}
|
|
@@ -12,5 +12,5 @@ export declare const ESRProvider: React.FC<PropsWithChildren<ESRProviderProps>>;
|
|
|
12
12
|
export declare const useESR: () => {
|
|
13
13
|
experienceVariantsMap: Record<string, number>;
|
|
14
14
|
};
|
|
15
|
-
export declare const ESRLoadingComponent: <P, PassThroughProps extends Partial<P> = Partial<P>, Variant extends Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference = Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference>({ experiences, component: Component, passthroughProps, ...baseline }: ExperienceBaseProps<P, PassThroughProps, Variant>) =>
|
|
15
|
+
export declare const ESRLoadingComponent: <P, PassThroughProps extends Partial<P> = Partial<P>, Variant extends Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference = Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference>({ experiences, component: Component, passthroughProps, ...baseline }: ExperienceBaseProps<P, PassThroughProps, Variant>) => JSX.Element;
|
|
16
16
|
export {};
|
|
@@ -23,5 +23,5 @@ type DefaultExperienceLoadingComponentProps = ExperienceBaseProps<Record<string,
|
|
|
23
23
|
unhideAfterMs?: number;
|
|
24
24
|
};
|
|
25
25
|
export declare const DefaultExperienceLoadingComponent: React.FC<DefaultExperienceLoadingComponentProps>;
|
|
26
|
-
export declare const Experience: <P, PassThroughProps extends Partial<P> = Partial<P>, Variant extends Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference = Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference>({ experiences, component: Component, loadingComponent: LoadingComponent, passthroughProps, ...baseline }: ExperienceProps<P, PassThroughProps, Variant>) =>
|
|
26
|
+
export declare const Experience: <P, PassThroughProps extends Partial<P> = Partial<P>, Variant extends Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference = Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference>({ experiences, component: Component, loadingComponent: LoadingComponent, passthroughProps, ...baseline }: ExperienceProps<P, PassThroughProps, Variant>) => JSX.Element;
|
|
27
27
|
export {};
|
|
@@ -3,5 +3,5 @@ type MergeTagProps = {
|
|
|
3
3
|
id: string;
|
|
4
4
|
fallback?: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const MergeTag: ({ id, fallback, }: PropsWithChildren<MergeTagProps>) =>
|
|
6
|
+
export declare const MergeTag: ({ id, fallback, }: PropsWithChildren<MergeTagProps>) => JSX.Element | null;
|
|
7
7
|
export {};
|
|
@@ -19,4 +19,4 @@ export type NinetailedProviderInstantiationProps = {
|
|
|
19
19
|
export type NinetailedProviderProps = NinetailedProviderInstantiationProps | {
|
|
20
20
|
ninetailed: Ninetailed;
|
|
21
21
|
};
|
|
22
|
-
export declare const NinetailedProvider: (props: React.PropsWithChildren<NinetailedProviderProps>) =>
|
|
22
|
+
export declare const NinetailedProvider: (props: React.PropsWithChildren<NinetailedProviderProps>) => JSX.Element;
|
package/src/lib/Personalize.d.ts
CHANGED
|
@@ -19,5 +19,5 @@ type PersonalizeProps<P> = Baseline<P> & {
|
|
|
19
19
|
loadingComponent?: React.ComponentType;
|
|
20
20
|
holdout?: number;
|
|
21
21
|
};
|
|
22
|
-
export declare const Personalize: <P extends object>({ component: Component, loadingComponent: LoadingComponent, variants, holdout, ...baseline }: PersonalizeProps<P>) =>
|
|
22
|
+
export declare const Personalize: <P extends object>({ component: Component, loadingComponent: LoadingComponent, variants, holdout, ...baseline }: PersonalizeProps<P>) => JSX.Element;
|
|
23
23
|
export {};
|
package/index.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|