@founderhq/journeys 0.3.61 → 0.3.63
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/README.md +20 -1
- package/dist/index.cjs +172 -23
- package/dist/index.d.cts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +172 -23
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -512,6 +512,131 @@ function normalizeStepOrder(config) {
|
|
|
512
512
|
}
|
|
513
513
|
return __spreadProps(__spreadValues({}, config), { steps: ordered });
|
|
514
514
|
}
|
|
515
|
+
function getRuntimeOptionOverride(overrides, key) {
|
|
516
|
+
if (!overrides || !key) return void 0;
|
|
517
|
+
if (!Object.prototype.hasOwnProperty.call(overrides, key)) return void 0;
|
|
518
|
+
return overrides[key];
|
|
519
|
+
}
|
|
520
|
+
function applyRuntimeOptionOverridesToBlocks(blocks, overrides) {
|
|
521
|
+
if (!overrides) return blocks;
|
|
522
|
+
let changed = false;
|
|
523
|
+
const nextBlocks = blocks.map((block) => {
|
|
524
|
+
let next = block;
|
|
525
|
+
if (block.type === "single_select" || block.type === "multi_select") {
|
|
526
|
+
const options = getRuntimeOptionOverride(overrides, block.props.variable);
|
|
527
|
+
if (options !== void 0) {
|
|
528
|
+
next = __spreadProps(__spreadValues({}, block), {
|
|
529
|
+
props: __spreadProps(__spreadValues({}, block.props), { options })
|
|
530
|
+
});
|
|
531
|
+
changed = true;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (block.type === "columns") {
|
|
535
|
+
let columnsChanged = false;
|
|
536
|
+
const columns = block.props.columns.map((column) => {
|
|
537
|
+
const columnBlocks = applyRuntimeOptionOverridesToBlocks(
|
|
538
|
+
column.blocks,
|
|
539
|
+
overrides
|
|
540
|
+
);
|
|
541
|
+
if (columnBlocks === column.blocks) return column;
|
|
542
|
+
columnsChanged = true;
|
|
543
|
+
return __spreadProps(__spreadValues({}, column), { blocks: columnBlocks });
|
|
544
|
+
});
|
|
545
|
+
if (columnsChanged) {
|
|
546
|
+
next = __spreadProps(__spreadValues({}, block), {
|
|
547
|
+
props: __spreadProps(__spreadValues({}, block.props), { columns })
|
|
548
|
+
});
|
|
549
|
+
changed = true;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return next;
|
|
553
|
+
});
|
|
554
|
+
return changed ? nextBlocks : blocks;
|
|
555
|
+
}
|
|
556
|
+
function applyRuntimeOptionOverrides(config, overrides) {
|
|
557
|
+
if (!overrides || Object.keys(overrides).length === 0) return config;
|
|
558
|
+
let changed = false;
|
|
559
|
+
const steps = config.steps.map((step) => {
|
|
560
|
+
var _a;
|
|
561
|
+
let next = step;
|
|
562
|
+
const stepUsesOptions = step.type === "single_select" || step.type === "multi_select" || step.type === "counter_select";
|
|
563
|
+
const options = stepUsesOptions ? getRuntimeOptionOverride(overrides, (_a = step.variable) != null ? _a : step.id) : void 0;
|
|
564
|
+
if (options !== void 0) {
|
|
565
|
+
next = __spreadProps(__spreadValues({}, step), { options });
|
|
566
|
+
changed = true;
|
|
567
|
+
}
|
|
568
|
+
if (step.blocks) {
|
|
569
|
+
const blocks = applyRuntimeOptionOverridesToBlocks(
|
|
570
|
+
step.blocks,
|
|
571
|
+
overrides
|
|
572
|
+
);
|
|
573
|
+
if (blocks !== step.blocks) {
|
|
574
|
+
next = __spreadProps(__spreadValues({}, next), { blocks });
|
|
575
|
+
changed = true;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
return next;
|
|
579
|
+
});
|
|
580
|
+
return changed ? __spreadProps(__spreadValues({}, config), { steps }) : config;
|
|
581
|
+
}
|
|
582
|
+
function stripOptionsFromEventBlocks(blocks) {
|
|
583
|
+
let changed = false;
|
|
584
|
+
const nextBlocks = blocks.map((block) => {
|
|
585
|
+
let next = block;
|
|
586
|
+
if (block.type === "single_select" || block.type === "multi_select") {
|
|
587
|
+
const props = __spreadValues({}, block.props);
|
|
588
|
+
delete props.options;
|
|
589
|
+
next = __spreadProps(__spreadValues({}, block), { props });
|
|
590
|
+
changed = true;
|
|
591
|
+
}
|
|
592
|
+
if (block.type === "columns") {
|
|
593
|
+
let columnsChanged = false;
|
|
594
|
+
const columns = block.props.columns.map((column) => {
|
|
595
|
+
const columnBlocks = stripOptionsFromEventBlocks(column.blocks);
|
|
596
|
+
if (columnBlocks === column.blocks) return column;
|
|
597
|
+
columnsChanged = true;
|
|
598
|
+
return __spreadProps(__spreadValues({}, column), { blocks: columnBlocks });
|
|
599
|
+
});
|
|
600
|
+
if (columnsChanged) {
|
|
601
|
+
next = __spreadProps(__spreadValues({}, block), {
|
|
602
|
+
props: __spreadProps(__spreadValues({}, block.props), { columns })
|
|
603
|
+
});
|
|
604
|
+
changed = true;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
return next;
|
|
608
|
+
});
|
|
609
|
+
return changed ? nextBlocks : blocks;
|
|
610
|
+
}
|
|
611
|
+
function stripOptionsFromEventStep(step) {
|
|
612
|
+
var _a;
|
|
613
|
+
let changed = false;
|
|
614
|
+
let next = step;
|
|
615
|
+
if (step.options !== void 0) {
|
|
616
|
+
next = __spreadValues({}, next);
|
|
617
|
+
delete next.options;
|
|
618
|
+
changed = true;
|
|
619
|
+
}
|
|
620
|
+
if ((_a = step.fields) == null ? void 0 : _a.some((field) => field.options !== void 0)) {
|
|
621
|
+
next = __spreadProps(__spreadValues({}, next), {
|
|
622
|
+
fields: step.fields.map((field) => {
|
|
623
|
+
if (field.options === void 0) return field;
|
|
624
|
+
const nextField = __spreadValues({}, field);
|
|
625
|
+
delete nextField.options;
|
|
626
|
+
return nextField;
|
|
627
|
+
})
|
|
628
|
+
});
|
|
629
|
+
changed = true;
|
|
630
|
+
}
|
|
631
|
+
if (step.blocks) {
|
|
632
|
+
const blocks = stripOptionsFromEventBlocks(step.blocks);
|
|
633
|
+
if (blocks !== step.blocks) {
|
|
634
|
+
next = __spreadProps(__spreadValues({}, next), { blocks });
|
|
635
|
+
changed = true;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
return changed ? next : step;
|
|
639
|
+
}
|
|
515
640
|
var JourneyContext = createContext(null);
|
|
516
641
|
function JourneyProvider({
|
|
517
642
|
config: rawConfig,
|
|
@@ -519,6 +644,7 @@ function JourneyProvider({
|
|
|
519
644
|
theme,
|
|
520
645
|
onEvent,
|
|
521
646
|
initialAnswers,
|
|
647
|
+
initialOptions,
|
|
522
648
|
onDiscountCodeApply,
|
|
523
649
|
children
|
|
524
650
|
}) {
|
|
@@ -529,7 +655,14 @@ function JourneyProvider({
|
|
|
529
655
|
useEffect(() => {
|
|
530
656
|
onEventRef.current = onEvent;
|
|
531
657
|
}, [onEvent]);
|
|
532
|
-
const
|
|
658
|
+
const normalizedConfig = useMemo(
|
|
659
|
+
() => normalizeStepOrder(rawConfig),
|
|
660
|
+
[rawConfig]
|
|
661
|
+
);
|
|
662
|
+
const config = useMemo(
|
|
663
|
+
() => applyRuntimeOptionOverrides(normalizedConfig, initialOptions),
|
|
664
|
+
[normalizedConfig, initialOptions]
|
|
665
|
+
);
|
|
533
666
|
const computedVariableIds = useMemo(
|
|
534
667
|
() => getComputedVariableIds(config.computedVariables),
|
|
535
668
|
[config.computedVariables]
|
|
@@ -574,8 +707,8 @@ function JourneyProvider({
|
|
|
574
707
|
rawAnswersRef.current = rawAnswers;
|
|
575
708
|
}, [rawAnswers]);
|
|
576
709
|
const allVariables = useMemo(
|
|
577
|
-
() =>
|
|
578
|
-
[
|
|
710
|
+
() => normalizedConfig.steps.flatMap(getStepVariables),
|
|
711
|
+
[normalizedConfig.steps]
|
|
579
712
|
);
|
|
580
713
|
const setAnswer = useCallback((stepId, answer) => {
|
|
581
714
|
if (computedVariableIds.has(stepId)) return;
|
|
@@ -644,7 +777,7 @@ function JourneyProvider({
|
|
|
644
777
|
const submitted = getSubmittedAnswer(currentStep, latestAnswers);
|
|
645
778
|
(_c = onEventRef.current) == null ? void 0 : _c.call(onEventRef, __spreadProps(__spreadValues({
|
|
646
779
|
type: "step_submit",
|
|
647
|
-
step: currentStep,
|
|
780
|
+
step: stripOptionsFromEventStep(currentStep),
|
|
648
781
|
submitted
|
|
649
782
|
}, eventAnswers), {
|
|
650
783
|
variables: allVariables
|
|
@@ -654,8 +787,8 @@ function JourneyProvider({
|
|
|
654
787
|
navigateToIndex(nextIndex);
|
|
655
788
|
(_d = onEventRef.current) == null ? void 0 : _d.call(onEventRef, __spreadValues({
|
|
656
789
|
type: "navigate",
|
|
657
|
-
from: currentStep,
|
|
658
|
-
to: config.steps[nextIndex],
|
|
790
|
+
from: stripOptionsFromEventStep(currentStep),
|
|
791
|
+
to: stripOptionsFromEventStep(config.steps[nextIndex]),
|
|
659
792
|
direction: "forward"
|
|
660
793
|
}, eventAnswers));
|
|
661
794
|
} else {
|
|
@@ -687,13 +820,18 @@ function JourneyProvider({
|
|
|
687
820
|
navigateToIndex(idx);
|
|
688
821
|
(_a = onEventRef.current) == null ? void 0 : _a.call(onEventRef, __spreadValues({
|
|
689
822
|
type: "navigate",
|
|
690
|
-
from: fromStep,
|
|
691
|
-
to: config.steps[idx],
|
|
823
|
+
from: stripOptionsFromEventStep(fromStep),
|
|
824
|
+
to: stripOptionsFromEventStep(config.steps[idx]),
|
|
692
825
|
direction: idx > currentStepIndex ? "forward" : "backward"
|
|
693
826
|
}, getEventAnswers(config.computedVariables, rawAnswersRef.current)));
|
|
694
827
|
}
|
|
695
828
|
},
|
|
696
|
-
[
|
|
829
|
+
[
|
|
830
|
+
config.computedVariables,
|
|
831
|
+
config.steps,
|
|
832
|
+
currentStepIndex,
|
|
833
|
+
navigateToIndex
|
|
834
|
+
]
|
|
697
835
|
);
|
|
698
836
|
const goBack = useCallback(() => {
|
|
699
837
|
var _a;
|
|
@@ -729,8 +867,8 @@ function JourneyProvider({
|
|
|
729
867
|
setDirection(dir);
|
|
730
868
|
(_b2 = onEventRef.current) == null ? void 0 : _b2.call(onEventRef, __spreadValues({
|
|
731
869
|
type: "navigate",
|
|
732
|
-
from: config.steps[prev],
|
|
733
|
-
to: config.steps[step],
|
|
870
|
+
from: stripOptionsFromEventStep(config.steps[prev]),
|
|
871
|
+
to: stripOptionsFromEventStep(config.steps[step]),
|
|
734
872
|
direction: dir
|
|
735
873
|
}, getEventAnswers(config.computedVariables, rawAnswersRef.current)));
|
|
736
874
|
return step;
|
|
@@ -738,7 +876,11 @@ function JourneyProvider({
|
|
|
738
876
|
};
|
|
739
877
|
window.addEventListener("popstate", handlePopState);
|
|
740
878
|
return () => window.removeEventListener("popstate", handlePopState);
|
|
741
|
-
}, [
|
|
879
|
+
}, [
|
|
880
|
+
config.allowBackNavigation,
|
|
881
|
+
config.computedVariables,
|
|
882
|
+
config.steps
|
|
883
|
+
]);
|
|
742
884
|
const getStepAnswer = useCallback(
|
|
743
885
|
(stepId) => {
|
|
744
886
|
var _a;
|
|
@@ -758,17 +900,22 @@ function JourneyProvider({
|
|
|
758
900
|
);
|
|
759
901
|
const firePurchaseIntent = useCallback(
|
|
760
902
|
(variable, plan, discount) => {
|
|
761
|
-
var _a, _b;
|
|
762
|
-
const currentStep = config.steps[currentStepIndex];
|
|
763
|
-
(
|
|
903
|
+
var _a, _b, _c;
|
|
904
|
+
const currentStep = (_a = normalizedConfig.steps[currentStepIndex]) != null ? _a : config.steps[currentStepIndex];
|
|
905
|
+
(_c = onEventRef.current) == null ? void 0 : _c.call(onEventRef, __spreadValues(__spreadProps(__spreadValues({
|
|
764
906
|
type: "purchase_intent",
|
|
765
907
|
variable,
|
|
766
908
|
plan
|
|
767
909
|
}, discount ? { discount } : {}), {
|
|
768
|
-
stepId: (
|
|
910
|
+
stepId: (_b = currentStep == null ? void 0 : currentStep.id) != null ? _b : ""
|
|
769
911
|
}), getEventAnswers(config.computedVariables, rawAnswersRef.current)));
|
|
770
912
|
},
|
|
771
|
-
[
|
|
913
|
+
[
|
|
914
|
+
config.computedVariables,
|
|
915
|
+
config.steps,
|
|
916
|
+
currentStepIndex,
|
|
917
|
+
normalizedConfig.steps
|
|
918
|
+
]
|
|
772
919
|
);
|
|
773
920
|
const openDiscountCodeDialog = useCallback(
|
|
774
921
|
(state2) => {
|
|
@@ -3790,13 +3937,11 @@ function ColumnsBlock({
|
|
|
3790
3937
|
onBack,
|
|
3791
3938
|
onGoToStep
|
|
3792
3939
|
}) {
|
|
3793
|
-
return /* @__PURE__ */ jsx(
|
|
3940
|
+
return /* @__PURE__ */ jsx("div", { className: "jy-columns-container", children: /* @__PURE__ */ jsx(
|
|
3794
3941
|
"div",
|
|
3795
3942
|
{
|
|
3796
|
-
className: cn(
|
|
3797
|
-
|
|
3798
|
-
className
|
|
3799
|
-
),
|
|
3943
|
+
className: cn("jy-columns", className),
|
|
3944
|
+
"data-responsive": responsive ? "true" : "false",
|
|
3800
3945
|
style: { gap: `${gap}rem` },
|
|
3801
3946
|
children: columns.map((col, i) => {
|
|
3802
3947
|
var _a;
|
|
@@ -3824,7 +3969,7 @@ function ColumnsBlock({
|
|
|
3824
3969
|
);
|
|
3825
3970
|
})
|
|
3826
3971
|
}
|
|
3827
|
-
);
|
|
3972
|
+
) });
|
|
3828
3973
|
}
|
|
3829
3974
|
function easeInOutCubic(t) {
|
|
3830
3975
|
return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
|
|
@@ -9276,6 +9421,7 @@ function JourneyRemote({
|
|
|
9276
9421
|
className,
|
|
9277
9422
|
theme,
|
|
9278
9423
|
initialAnswers,
|
|
9424
|
+
initialOptions,
|
|
9279
9425
|
onDiscountCodeApply,
|
|
9280
9426
|
loadingComponent,
|
|
9281
9427
|
errorComponent
|
|
@@ -9295,6 +9441,7 @@ function JourneyRemote({
|
|
|
9295
9441
|
theme,
|
|
9296
9442
|
onEvent,
|
|
9297
9443
|
initialAnswers,
|
|
9444
|
+
initialOptions,
|
|
9298
9445
|
onDiscountCodeApply,
|
|
9299
9446
|
children: /* @__PURE__ */ jsx(JourneyShell, { className, theme })
|
|
9300
9447
|
}
|
|
@@ -9311,6 +9458,7 @@ function Journey(props) {
|
|
|
9311
9458
|
className,
|
|
9312
9459
|
theme,
|
|
9313
9460
|
initialAnswers,
|
|
9461
|
+
initialOptions,
|
|
9314
9462
|
onDiscountCodeApply
|
|
9315
9463
|
} = props;
|
|
9316
9464
|
return /* @__PURE__ */ jsx(
|
|
@@ -9321,6 +9469,7 @@ function Journey(props) {
|
|
|
9321
9469
|
theme,
|
|
9322
9470
|
onEvent,
|
|
9323
9471
|
initialAnswers,
|
|
9472
|
+
initialOptions,
|
|
9324
9473
|
onDiscountCodeApply,
|
|
9325
9474
|
children: /* @__PURE__ */ jsx(JourneyShell, { className, theme })
|
|
9326
9475
|
}
|