@mx-cartographer/experiences 9.7.16 → 9.7.18
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/CHANGELOG.md +10 -0
- package/dist/core/api/BeatApi.d.ts +15 -2
- package/dist/core/api/BeatApi.es.js +8 -7
- package/dist/core/api/BeatApi.es.js.map +1 -1
- package/dist/core/constants/ApiEndpoints.d.ts +1 -0
- package/dist/core/constants/ApiEndpoints.es.js +1 -0
- package/dist/core/constants/ApiEndpoints.es.js.map +1 -1
- package/dist/core/stores/BeatStore.d.ts +2 -2
- package/dist/core/stores/BeatStore.es.js +29 -29
- package/dist/core/stores/BeatStore.es.js.map +1 -1
- package/dist/core/types/Insights.d.ts +8 -0
- package/dist/core/types/Insights.es.js.map +1 -1
- package/dist/insights-v2/blocks/ComponentBlocks/WithdrawalBlock/WithdrawalBlock.d.ts +8 -12
- package/dist/insights-v2/blocks/ComponentBlocks/WithdrawalBlock/WithdrawalBlock.es.js +7 -8
- package/dist/insights-v2/blocks/ComponentBlocks/WithdrawalBlock/WithdrawalBlock.es.js.map +1 -1
- package/dist/microinsights/InsightsMicroWidget.es.js +39 -38
- package/dist/microinsights/InsightsMicroWidget.es.js.map +1 -1
- package/dist/microinsights/beatActions.d.ts +21 -0
- package/dist/microinsights/beatActions.es.js +23 -0
- package/dist/microinsights/beatActions.es.js.map +1 -0
- package/dist/microinsights/cards/InlineActionBlock.d.ts +16 -0
- package/dist/microinsights/cards/InlineActionBlock.es.js +41 -0
- package/dist/microinsights/cards/InlineActionBlock.es.js.map +1 -0
- package/dist/microinsights/cards/InsightCard.es.js +68 -61
- package/dist/microinsights/cards/InsightCard.es.js.map +1 -1
- package/dist/microinsights/carousel/BeatList.es.js +17 -16
- package/dist/microinsights/carousel/BeatList.es.js.map +1 -1
- package/dist/microinsights/carousel/MicroBeatCarousel.d.ts +1 -0
- package/dist/microinsights/carousel/MicroBeatCarousel.es.js +34 -33
- package/dist/microinsights/carousel/MicroBeatCarousel.es.js.map +1 -1
- package/dist/microinsights/context/hooks.es.js +11 -6
- package/dist/microinsights/context/hooks.es.js.map +1 -1
- package/dist/microinsights/interfaces.d.ts +12 -0
- package/dist/microinsights/stores/InsightsMicroWidgetStore.d.ts +3 -1
- package/dist/microinsights/stores/InsightsMicroWidgetStore.es.js +18 -17
- package/dist/microinsights/stores/InsightsMicroWidgetStore.es.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ANALYTICS_CLICK_EVENTS as a } from "../constants/Analytics.es.js";
|
|
2
|
-
import { useCopyStore as
|
|
3
|
-
import { CarouselControls as
|
|
4
|
-
import
|
|
2
|
+
import { useCopyStore as H, useEvent as J } from "../context/hooks.es.js";
|
|
3
|
+
import { CarouselControls as Q } from "./CarouselControls.es.js";
|
|
4
|
+
import Z from "./BeatList.es.js";
|
|
5
5
|
import n from "react";
|
|
6
|
-
import { observer as
|
|
6
|
+
import { observer as $ } from "mobx-react-lite";
|
|
7
7
|
import I from "@mui/material/Stack";
|
|
8
|
-
import { jsx as R, jsxs as
|
|
9
|
-
var
|
|
10
|
-
const t = n.useRef(null), s = n.useRef(null), [u,
|
|
8
|
+
import { jsx as R, jsxs as tt } from "react/jsx-runtime";
|
|
9
|
+
var et = ({ analyticsMetadata: i, allowSingleCardPeeking: h, beats: E = [], elevation: y, heightOverrides: f, inDescriptionCtaBehavior: b, onCardClick: z, posthog: N, showCarouselControls: g, showIcon: k, showWithMargin: m = !0, variant: K, widthOverrides: _, visibleCardsCount: e = 1 }) => {
|
|
10
|
+
const t = n.useRef(null), s = n.useRef(null), [u, X] = n.useState(0), [v, A] = n.useState(null), [L, U] = n.useState(null), [o, T] = n.useState(null), { carouselCopy: D } = H(), { onEvent: d } = J();
|
|
11
11
|
n.useEffect(() => {
|
|
12
12
|
const r = (p) => {
|
|
13
13
|
const c = s.current;
|
|
@@ -39,7 +39,7 @@ var tt = ({ analyticsMetadata: i, allowSingleCardPeeking: h, beats: E = [], elev
|
|
|
39
39
|
maxWidth: 900,
|
|
40
40
|
cardWidth: 600
|
|
41
41
|
}
|
|
42
|
-
].find((
|
|
42
|
+
].find((G) => l <= G.maxWidth);
|
|
43
43
|
T(w ? w.cardWidth : 750);
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
@@ -63,29 +63,29 @@ var tt = ({ analyticsMetadata: i, allowSingleCardPeeking: h, beats: E = [], elev
|
|
|
63
63
|
e,
|
|
64
64
|
m
|
|
65
65
|
]);
|
|
66
|
-
const
|
|
66
|
+
const j = () => {
|
|
67
67
|
d(a.ON_CAROUSEL_FORWARD_CLICK, i), t.current && o && t.current.scrollTo({
|
|
68
68
|
left: u + o + 8,
|
|
69
69
|
top: 0,
|
|
70
70
|
behavior: "smooth"
|
|
71
71
|
});
|
|
72
|
-
},
|
|
72
|
+
}, F = () => {
|
|
73
73
|
d(a.ON_CAROUSEL_BACK_CLICK, i), t.current && o && t.current.scrollTo({
|
|
74
74
|
left: Math.max(0, u - (o + 8)),
|
|
75
75
|
top: 0,
|
|
76
76
|
behavior: "smooth"
|
|
77
77
|
});
|
|
78
|
-
}, F = () => {
|
|
79
|
-
t.current && K(t.current.scrollLeft);
|
|
80
78
|
}, M = () => {
|
|
79
|
+
t.current && X(t.current.scrollLeft);
|
|
80
|
+
}, P = () => {
|
|
81
81
|
!L || !v || (L - v > 50 ? d(a.ON_CAROUSEL_FORWARD_SWIPE, i) : d(a.ON_CAROUSEL_BACK_SWIPE, i));
|
|
82
|
-
}, P = (r) => {
|
|
83
|
-
A(r.targetTouches[0].clientX);
|
|
84
82
|
}, Y = (r) => {
|
|
85
|
-
A(
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
A(r.targetTouches[0].clientX);
|
|
84
|
+
}, V = (r) => {
|
|
85
|
+
A(null), U(r.targetTouches[0].clientX);
|
|
86
|
+
}, B = o ? Math.round(u / (o + 8)) : 0, q = t.current ? t.current.scrollWidth - t.current.offsetWidth : 0;
|
|
87
|
+
return /* @__PURE__ */ tt(I, {
|
|
88
|
+
"aria-label": D?.carousel_title,
|
|
89
89
|
"aria-roledescription": "carousel",
|
|
90
90
|
ref: s,
|
|
91
91
|
role: "region",
|
|
@@ -97,10 +97,10 @@ var tt = ({ analyticsMetadata: i, allowSingleCardPeeking: h, beats: E = [], elev
|
|
|
97
97
|
},
|
|
98
98
|
children: [/* @__PURE__ */ R(I, {
|
|
99
99
|
direction: "row",
|
|
100
|
-
onScroll:
|
|
101
|
-
onTouchEnd:
|
|
102
|
-
onTouchMove:
|
|
103
|
-
onTouchStart:
|
|
100
|
+
onScroll: M,
|
|
101
|
+
onTouchEnd: P,
|
|
102
|
+
onTouchMove: Y,
|
|
103
|
+
onTouchStart: V,
|
|
104
104
|
ref: t,
|
|
105
105
|
sx: {
|
|
106
106
|
alignItems: "center",
|
|
@@ -117,31 +117,32 @@ var tt = ({ analyticsMetadata: i, allowSingleCardPeeking: h, beats: E = [], elev
|
|
|
117
117
|
WebkitOverflowScrolling: "touch",
|
|
118
118
|
"&::-webkit-scrollbar": { display: "none" }
|
|
119
119
|
},
|
|
120
|
-
children: /* @__PURE__ */ R(
|
|
120
|
+
children: /* @__PURE__ */ R(Z, {
|
|
121
121
|
activeCardIndex: B,
|
|
122
122
|
beats: E,
|
|
123
123
|
cardWidth: o,
|
|
124
124
|
elevation: y,
|
|
125
125
|
heightOverrides: f,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
inDescriptionCtaBehavior: b,
|
|
127
|
+
onCardClick: z,
|
|
128
|
+
posthog: N,
|
|
129
|
+
showIcon: k,
|
|
130
|
+
variant: K
|
|
130
131
|
})
|
|
131
|
-
}),
|
|
132
|
+
}), g && /* @__PURE__ */ R(Q, {
|
|
132
133
|
currentBeatIndex: B + e - 1,
|
|
133
134
|
numBeats: E.length + 1,
|
|
134
|
-
onNextClick:
|
|
135
|
-
onPreviousClick:
|
|
136
|
-
scrollRightBoundary:
|
|
135
|
+
onNextClick: j,
|
|
136
|
+
onPreviousClick: F,
|
|
137
|
+
scrollRightBoundary: q,
|
|
137
138
|
scrollX: u,
|
|
138
139
|
shouldApplyDotAnimation: h,
|
|
139
140
|
visibleCardsCount: e
|
|
140
141
|
})]
|
|
141
142
|
});
|
|
142
|
-
},
|
|
143
|
+
}, dt = $(et);
|
|
143
144
|
export {
|
|
144
|
-
|
|
145
|
+
dt as default
|
|
145
146
|
};
|
|
146
147
|
|
|
147
148
|
//# sourceMappingURL=MicroBeatCarousel.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MicroBeatCarousel.es.js","names":[],"sources":["../../../src/microinsights/carousel/MicroBeatCarousel.tsx"],"sourcesContent":["/* eslint-disable consistent-return */\nimport React from 'react'\nimport { observer } from 'mobx-react-lite'\n\nimport Stack from '@mui/material/Stack'\n\nimport { CarouselControls } from './CarouselControls'\nimport BeatList from './BeatList'\n\nimport type { MicroWidgetProps } from '..'\n\nimport { useCopyStore, useEvent } from '../context/hooks'\n\nimport type { Beat } from '../../core/types/Beat'\n\nimport { ANALYTICS_CLICK_EVENTS } from '../constants/Analytics'\nimport { MINIMUM_SWIPE_DISTANCE } from '../constants/App'\n\ninterface MicroBeatCarouselProps {\n allowSingleCardPeeking?: boolean\n analyticsMetadata?: Record<string, string>\n beats?: Beat[]\n elevation?: number\n heightOverrides?: MicroWidgetProps['heightOverrides']\n onCardClick?: MicroWidgetProps['onCardClick']\n posthog?: MicroWidgetProps['posthog']\n showCarouselControls?: boolean\n showIcon?: boolean\n showWithMargin?: boolean\n variant?: 'outlined' | 'elevation' | undefined\n visibleCardsCount?: number\n widthOverrides?: number\n}\n\nconst MicroBeatCarousel: React.FC<MicroBeatCarouselProps> = ({\n analyticsMetadata,\n allowSingleCardPeeking,\n beats = [],\n elevation,\n heightOverrides,\n onCardClick,\n posthog,\n showCarouselControls,\n showIcon,\n showWithMargin = true,\n variant,\n widthOverrides,\n visibleCardsCount = 1, // Default to 1 card visible\n}) => {\n // ************** Use Ref Hooks **************************\n const ref = React.useRef<HTMLDivElement | null>(null)\n const carouselRef = React.useRef<HTMLDivElement | null>(null)\n\n // ************** Use States Hooks ***********************\n const [scrollX, setScrollX] = React.useState<number>(0)\n const [touchEnd, setTouchEnd] = React.useState<number | null>(null)\n const [touchStart, setTouchStart] = React.useState<number | null>(null)\n const [cardWidth, setCardWidth] = React.useState<number | null>(null)\n\n // *************** Context functions *********************\n const { carouselCopy: copy } = useCopyStore()\n const { onEvent } = useEvent()\n\n // ************** Use Effects Hooks **********************\n\n React.useEffect(() => {\n // Single source of truth for card-width sizing. The two layout modes\n // (breakpoint-based peeking vs. proportional visible-cards math) are\n // mutually exclusive on `allowSingleCardPeeking`, so they share one\n // ResizeObserver/effect to keep resize tracking in one place.\n //\n // Observe the outer, structurally stable container (carouselRef) rather\n // than the inner shrink-wrapped flex row (ref). The inner row's width\n // depends on cardWidth, so observing it would feed back into itself and\n // cause a shrinking ResizeObserver loop / stuck-small layout.\n const computeCardWidth = (observedWidth?: number) => {\n const node = carouselRef.current\n if (!node) return\n\n // Prefer the width reported by the ResizeObserver entry to avoid an\n // extra layout read (thrashing); fall back to a DOM read on mount and\n // on the window-resize fallback path.\n const rawWidth = observedWidth ?? node.offsetWidth\n\n if (allowSingleCardPeeking) {\n // Use until token sizes are actually implemented in the mxui repo\n const breakpoints = [\n { maxWidth: 320, cardWidth: 220 },\n { maxWidth: 375, cardWidth: 268 },\n { maxWidth: 444, cardWidth: 300 },\n { maxWidth: 599, cardWidth: 350 },\n { maxWidth: 749, cardWidth: 450 },\n { maxWidth: 900, cardWidth: 600 },\n ]\n\n const matchingBreakpoint = breakpoints.find((bp) => rawWidth <= bp.maxWidth)\n setCardWidth(matchingBreakpoint ? matchingBreakpoint.cardWidth : 750)\n return\n }\n\n // The inner row is constrained to `calc(100% - 32px)` when showWithMargin\n // is set, so subtract that margin to match the actual available width.\n // Clamp to 0 so a tiny/unmeasured container never yields a negative width.\n const containerWidth = showWithMargin ? Math.max(0, rawWidth - 32) : rawWidth\n const gap = 8 // gap between cards\n\n // When visibleCardsCount > 1, make each card narrower to fit multiple cards and show a peek of the next card\n // When visibleCardsCount is 1, use full container width\n let calculatedCardWidth\n if (visibleCardsCount > 1) {\n // First calculate what a single full card width would be\n const fullCardWidth = (containerWidth - (visibleCardsCount - 1) * gap) / visibleCardsCount\n // Set the peek area to be 1/3 of a card width instead of fixed 60px\n const peekAreaWidth = fullCardWidth / 3\n // Calculate final card width, accounting for the peek area and gaps\n calculatedCardWidth =\n (containerWidth - peekAreaWidth - (visibleCardsCount - 1) * gap) / visibleCardsCount\n } else {\n calculatedCardWidth = containerWidth\n }\n\n // Clamp to prevent negative widths.\n setCardWidth(Math.max(0, calculatedCardWidth))\n }\n\n computeCardWidth()\n\n // Recompute on container resize via ResizeObserver, falling back to the\n // window resize event only when ResizeObserver is unavailable.\n const handleResize = () => computeCardWidth()\n let observer: ResizeObserver | null = null\n if (typeof ResizeObserver !== 'undefined' && carouselRef.current) {\n observer = new ResizeObserver((entries) => {\n const entry = entries[0]\n if (!entry) return\n const width = entry.borderBoxSize?.[0]?.inlineSize ?? entry.contentRect.width\n computeCardWidth(width)\n })\n observer.observe(carouselRef.current)\n } else {\n window.addEventListener('resize', handleResize)\n }\n\n return () => {\n window.removeEventListener('resize', handleResize)\n observer?.disconnect()\n }\n }, [allowSingleCardPeeking, visibleCardsCount, showWithMargin])\n\n // *************** Click handlers ************************\n const handleNextClick = () => {\n onEvent(ANALYTICS_CLICK_EVENTS.ON_CAROUSEL_FORWARD_CLICK, analyticsMetadata)\n\n if (ref.current && cardWidth) {\n // Scroll by one card width + gap\n ref.current.scrollTo({\n left: scrollX + cardWidth + 8,\n top: 0,\n behavior: 'smooth',\n })\n }\n }\n\n const handlePreviousClick = () => {\n onEvent(ANALYTICS_CLICK_EVENTS.ON_CAROUSEL_BACK_CLICK, analyticsMetadata)\n\n if (ref.current && cardWidth) {\n // Scroll by one card width + gap\n ref.current.scrollTo({\n left: Math.max(0, scrollX - (cardWidth + 8)),\n top: 0,\n behavior: 'smooth',\n })\n }\n }\n\n const handleScroll = () => {\n if (ref.current) {\n setScrollX(ref.current.scrollLeft)\n }\n }\n\n // *************** Mobile handlers ************************\n const onTouchEnd = () => {\n if (!touchStart || !touchEnd) return\n const distance = touchStart - touchEnd\n\n // swiping left\n if (distance > MINIMUM_SWIPE_DISTANCE) {\n onEvent(ANALYTICS_CLICK_EVENTS.ON_CAROUSEL_FORWARD_SWIPE, analyticsMetadata)\n } else {\n // swiping right\n onEvent(ANALYTICS_CLICK_EVENTS.ON_CAROUSEL_BACK_SWIPE, analyticsMetadata)\n }\n }\n\n const onTouchMove = (e: React.TouchEvent) => {\n setTouchEnd(e.targetTouches[0].clientX)\n }\n\n const onTouchStart = (e: React.TouchEvent) => {\n // otherwise the swipe is fired even with usual touch events\n setTouchEnd(null)\n setTouchStart(e.targetTouches[0].clientX)\n }\n\n // Calculate active card index based on scroll position and card width\n const activeCardIndex = cardWidth ? Math.round(scrollX / (cardWidth + 8)) : 0\n const scrollBoundry = ref.current ? ref.current.scrollWidth - ref.current.offsetWidth : 0\n\n return (\n <Stack\n aria-label={copy?.carousel_title}\n aria-roledescription=\"carousel\"\n ref={carouselRef}\n role=\"region\"\n sx={{\n alignItems: 'center',\n boxSizing: 'border-box',\n height: heightOverrides,\n width: widthOverrides ? widthOverrides : '100%',\n }}\n >\n <Stack\n direction=\"row\"\n onScroll={handleScroll}\n onTouchEnd={onTouchEnd}\n onTouchMove={onTouchMove}\n onTouchStart={onTouchStart}\n ref={ref}\n sx={{\n alignItems: 'center',\n height: heightOverrides && '100%',\n gap: 8,\n listStyleType: 'none',\n m: 0,\n maxWidth: showWithMargin ? `calc(100% - 32px)` : '100%',\n overflowX: 'auto',\n overflowY: 'hidden',\n p: 0,\n scrollbarWidth: 'none',\n msOverflowStyle: 'none',\n WebkitOverflowScrolling: 'touch',\n '&::-webkit-scrollbar': {\n display: 'none',\n },\n }}\n >\n <BeatList\n activeCardIndex={activeCardIndex}\n beats={beats}\n cardWidth={cardWidth}\n elevation={elevation}\n heightOverrides={heightOverrides}\n onCardClick={onCardClick}\n posthog={posthog}\n showIcon={showIcon}\n variant={variant}\n />\n </Stack>\n {showCarouselControls && (\n <CarouselControls\n currentBeatIndex={activeCardIndex + visibleCardsCount - 1}\n numBeats={beats.length + 1}\n onNextClick={handleNextClick}\n onPreviousClick={handlePreviousClick}\n scrollRightBoundary={scrollBoundry}\n scrollX={scrollX}\n shouldApplyDotAnimation={allowSingleCardPeeking}\n visibleCardsCount={visibleCardsCount}\n />\n )}\n </Stack>\n )\n}\n\nexport default observer(MicroBeatCarousel)\n"],"mappings":";;;;;;;;AAkCA,IAAM,KAAA,CAAuD,EAC3D,mBAAA,GACA,wBAAA,GACA,OAAA,IAAQ,CAAC,GACT,WAAA,GACA,iBAAA,GACA,aAAA,GACA,SAAA,GACA,sBAAA,GACA,UAAA,GACA,gBAAA,IAAiB,IACjB,SAAA,GACA,gBAAA,GACA,mBAAA,IAAoB,EAAA,MAChB;AAEJ,QAAM,IAAM,EAAM,OAA8B,IAAI,GAC9C,IAAc,EAAM,OAA8B,IAAI,GAGtD,CAAC,GAAS,CAAA,IAAc,EAAM,SAAiB,CAAC,GAChD,CAAC,GAAU,CAAA,IAAe,EAAM,SAAwB,IAAI,GAC5D,CAAC,GAAY,CAAA,IAAiB,EAAM,SAAwB,IAAI,GAChE,CAAC,GAAW,CAAA,IAAgB,EAAM,SAAwB,IAAI,GAG9D,EAAE,cAAc,EAAA,IAAS,EAAa,GACtC,EAAE,SAAA,EAAA,IAAY,EAAS;AAI7B,EAAA,EAAM,UAAA,MAAgB;AAUpB,UAAM,IAAA,CAAoB,MAA2B;AACnD,YAAM,IAAO,EAAY;AACzB,UAAI,CAAC,EAAM;AAKX,YAAM,IAAW,KAAiB,EAAK;AAEvC,UAAI,GAAwB;AAW1B,cAAM,IAAqB;AAAA,UARzB;AAAA,YAAE,UAAU;AAAA,YA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;AAAA,MACE,WAAU;AAAA,MACV,UAAU;AAAA,MACE,YAAA;AAAA,MACC,aAAA;AAAA,MACC,cAAA;AAAA,MACT,KAAA;AAAA,MACL,IAAI;AAAA,QACF,YAAY;AAAA,QACZ,QAAQ,KAAmB;AAAA,QAC3B,KAAK;AAAA,QACL,eAAe;AAAA,QACf,GAAG;AAAA,QACH,UAAU,IAAiB,sBAAsB;AAAA,QACjD,WAAW;AAAA,QACX,WAAW;AAAA,QACX,GAAG;AAAA,QACH,gBAAgB;AAAA,QAChB,iBAAiB;AAAA,QACjB,yBAAyB;AAAA,QACzB,wBAAwB,EACtB,SAAS,OACX;AAAA,MACF;AAAA,MAEA,UAAA,gBAAA,EAAC,GAAD;AAAA,QACmB,iBAAA;AAAA,QACV,OAAA;AAAA,QACI,WAAA;AAAA,QACA,WAAA;AAAA,QACM,iBAAA;AAAA,QACJ,aAAA;AAAA,QACJ,SAAA;AAAA,QACC,UAAA;AAAA,QACD,SAAA;AAAA,MACV,CAAA;AAAA,IACI,CAAA,GACN,KACC,gBAAA,EAAC,GAAD;AAAA,MACE,kBAAkB,IAAkB,IAAoB;AAAA,MACxD,UAAU,EAAM,SAAS;AAAA,MACzB,aAAa;AAAA,MACb,iBAAiB;AAAA,MACjB,qBAAqB;AAAA,MACZ,SAAA;AAAA,MACT,yBAAyB;AAAA,MACN,mBAAA;AAAA,IACpB,CAAA,CAEE;AAAA;AAEX,GAEA,KAAe,EAAS,EAAiB"}
|
|
1
|
+
{"version":3,"file":"MicroBeatCarousel.es.js","names":[],"sources":["../../../src/microinsights/carousel/MicroBeatCarousel.tsx"],"sourcesContent":["/* eslint-disable consistent-return */\nimport React from 'react'\nimport { observer } from 'mobx-react-lite'\n\nimport Stack from '@mui/material/Stack'\n\nimport { CarouselControls } from './CarouselControls'\nimport BeatList from './BeatList'\n\nimport type { MicroWidgetProps } from '..'\n\nimport { useCopyStore, useEvent } from '../context/hooks'\n\nimport type { Beat } from '../../core/types/Beat'\n\nimport { ANALYTICS_CLICK_EVENTS } from '../constants/Analytics'\nimport { MINIMUM_SWIPE_DISTANCE } from '../constants/App'\n\ninterface MicroBeatCarouselProps {\n allowSingleCardPeeking?: boolean\n analyticsMetadata?: Record<string, string>\n beats?: Beat[]\n elevation?: number\n heightOverrides?: MicroWidgetProps['heightOverrides']\n inDescriptionCtaBehavior?: MicroWidgetProps['inDescriptionCtaBehavior']\n onCardClick?: MicroWidgetProps['onCardClick']\n posthog?: MicroWidgetProps['posthog']\n showCarouselControls?: boolean\n showIcon?: boolean\n showWithMargin?: boolean\n variant?: 'outlined' | 'elevation' | undefined\n visibleCardsCount?: number\n widthOverrides?: number\n}\n\nconst MicroBeatCarousel: React.FC<MicroBeatCarouselProps> = ({\n analyticsMetadata,\n allowSingleCardPeeking,\n beats = [],\n elevation,\n heightOverrides,\n inDescriptionCtaBehavior,\n onCardClick,\n posthog,\n showCarouselControls,\n showIcon,\n showWithMargin = true,\n variant,\n widthOverrides,\n visibleCardsCount = 1, // Default to 1 card visible\n}) => {\n // ************** Use Ref Hooks **************************\n const ref = React.useRef<HTMLDivElement | null>(null)\n const carouselRef = React.useRef<HTMLDivElement | null>(null)\n\n // ************** Use States Hooks ***********************\n const [scrollX, setScrollX] = React.useState<number>(0)\n const [touchEnd, setTouchEnd] = React.useState<number | null>(null)\n const [touchStart, setTouchStart] = React.useState<number | null>(null)\n const [cardWidth, setCardWidth] = React.useState<number | null>(null)\n\n // *************** Context functions *********************\n const { carouselCopy: copy } = useCopyStore()\n const { onEvent } = useEvent()\n\n // ************** Use Effects Hooks **********************\n\n React.useEffect(() => {\n // Single source of truth for card-width sizing. The two layout modes\n // (breakpoint-based peeking vs. proportional visible-cards math) are\n // mutually exclusive on `allowSingleCardPeeking`, so they share one\n // ResizeObserver/effect to keep resize tracking in one place.\n //\n // Observe the outer, structurally stable container (carouselRef) rather\n // than the inner shrink-wrapped flex row (ref). The inner row's width\n // depends on cardWidth, so observing it would feed back into itself and\n // cause a shrinking ResizeObserver loop / stuck-small layout.\n const computeCardWidth = (observedWidth?: number) => {\n const node = carouselRef.current\n if (!node) return\n\n // Prefer the width reported by the ResizeObserver entry to avoid an\n // extra layout read (thrashing); fall back to a DOM read on mount and\n // on the window-resize fallback path.\n const rawWidth = observedWidth ?? node.offsetWidth\n\n if (allowSingleCardPeeking) {\n // Use until token sizes are actually implemented in the mxui repo\n const breakpoints = [\n { maxWidth: 320, cardWidth: 220 },\n { maxWidth: 375, cardWidth: 268 },\n { maxWidth: 444, cardWidth: 300 },\n { maxWidth: 599, cardWidth: 350 },\n { maxWidth: 749, cardWidth: 450 },\n { maxWidth: 900, cardWidth: 600 },\n ]\n\n const matchingBreakpoint = breakpoints.find((bp) => rawWidth <= bp.maxWidth)\n setCardWidth(matchingBreakpoint ? matchingBreakpoint.cardWidth : 750)\n return\n }\n\n // The inner row is constrained to `calc(100% - 32px)` when showWithMargin\n // is set, so subtract that margin to match the actual available width.\n // Clamp to 0 so a tiny/unmeasured container never yields a negative width.\n const containerWidth = showWithMargin ? Math.max(0, rawWidth - 32) : rawWidth\n const gap = 8 // gap between cards\n\n // When visibleCardsCount > 1, make each card narrower to fit multiple cards and show a peek of the next card\n // When visibleCardsCount is 1, use full container width\n let calculatedCardWidth\n if (visibleCardsCount > 1) {\n // First calculate what a single full card width would be\n const fullCardWidth = (containerWidth - (visibleCardsCount - 1) * gap) / visibleCardsCount\n // Set the peek area to be 1/3 of a card width instead of fixed 60px\n const peekAreaWidth = fullCardWidth / 3\n // Calculate final card width, accounting for the peek area and gaps\n calculatedCardWidth =\n (containerWidth - peekAreaWidth - (visibleCardsCount - 1) * gap) / visibleCardsCount\n } else {\n calculatedCardWidth = containerWidth\n }\n\n // Clamp to prevent negative widths.\n setCardWidth(Math.max(0, calculatedCardWidth))\n }\n\n computeCardWidth()\n\n // Recompute on container resize via ResizeObserver, falling back to the\n // window resize event only when ResizeObserver is unavailable.\n const handleResize = () => computeCardWidth()\n let observer: ResizeObserver | null = null\n if (typeof ResizeObserver !== 'undefined' && carouselRef.current) {\n observer = new ResizeObserver((entries) => {\n const entry = entries[0]\n if (!entry) return\n const width = entry.borderBoxSize?.[0]?.inlineSize ?? entry.contentRect.width\n computeCardWidth(width)\n })\n observer.observe(carouselRef.current)\n } else {\n window.addEventListener('resize', handleResize)\n }\n\n return () => {\n window.removeEventListener('resize', handleResize)\n observer?.disconnect()\n }\n }, [allowSingleCardPeeking, visibleCardsCount, showWithMargin])\n\n // *************** Click handlers ************************\n const handleNextClick = () => {\n onEvent(ANALYTICS_CLICK_EVENTS.ON_CAROUSEL_FORWARD_CLICK, analyticsMetadata)\n\n if (ref.current && cardWidth) {\n // Scroll by one card width + gap\n ref.current.scrollTo({\n left: scrollX + cardWidth + 8,\n top: 0,\n behavior: 'smooth',\n })\n }\n }\n\n const handlePreviousClick = () => {\n onEvent(ANALYTICS_CLICK_EVENTS.ON_CAROUSEL_BACK_CLICK, analyticsMetadata)\n\n if (ref.current && cardWidth) {\n // Scroll by one card width + gap\n ref.current.scrollTo({\n left: Math.max(0, scrollX - (cardWidth + 8)),\n top: 0,\n behavior: 'smooth',\n })\n }\n }\n\n const handleScroll = () => {\n if (ref.current) {\n setScrollX(ref.current.scrollLeft)\n }\n }\n\n // *************** Mobile handlers ************************\n const onTouchEnd = () => {\n if (!touchStart || !touchEnd) return\n const distance = touchStart - touchEnd\n\n // swiping left\n if (distance > MINIMUM_SWIPE_DISTANCE) {\n onEvent(ANALYTICS_CLICK_EVENTS.ON_CAROUSEL_FORWARD_SWIPE, analyticsMetadata)\n } else {\n // swiping right\n onEvent(ANALYTICS_CLICK_EVENTS.ON_CAROUSEL_BACK_SWIPE, analyticsMetadata)\n }\n }\n\n const onTouchMove = (e: React.TouchEvent) => {\n setTouchEnd(e.targetTouches[0].clientX)\n }\n\n const onTouchStart = (e: React.TouchEvent) => {\n // otherwise the swipe is fired even with usual touch events\n setTouchEnd(null)\n setTouchStart(e.targetTouches[0].clientX)\n }\n\n // Calculate active card index based on scroll position and card width\n const activeCardIndex = cardWidth ? Math.round(scrollX / (cardWidth + 8)) : 0\n const scrollBoundry = ref.current ? ref.current.scrollWidth - ref.current.offsetWidth : 0\n\n return (\n <Stack\n aria-label={copy?.carousel_title}\n aria-roledescription=\"carousel\"\n ref={carouselRef}\n role=\"region\"\n sx={{\n alignItems: 'center',\n boxSizing: 'border-box',\n height: heightOverrides,\n width: widthOverrides ? widthOverrides : '100%',\n }}\n >\n <Stack\n direction=\"row\"\n onScroll={handleScroll}\n onTouchEnd={onTouchEnd}\n onTouchMove={onTouchMove}\n onTouchStart={onTouchStart}\n ref={ref}\n sx={{\n alignItems: 'center',\n height: heightOverrides && '100%',\n gap: 8,\n listStyleType: 'none',\n m: 0,\n maxWidth: showWithMargin ? `calc(100% - 32px)` : '100%',\n overflowX: 'auto',\n overflowY: 'hidden',\n p: 0,\n scrollbarWidth: 'none',\n msOverflowStyle: 'none',\n WebkitOverflowScrolling: 'touch',\n '&::-webkit-scrollbar': {\n display: 'none',\n },\n }}\n >\n <BeatList\n activeCardIndex={activeCardIndex}\n beats={beats}\n cardWidth={cardWidth}\n elevation={elevation}\n heightOverrides={heightOverrides}\n inDescriptionCtaBehavior={inDescriptionCtaBehavior}\n onCardClick={onCardClick}\n posthog={posthog}\n showIcon={showIcon}\n variant={variant}\n />\n </Stack>\n {showCarouselControls && (\n <CarouselControls\n currentBeatIndex={activeCardIndex + visibleCardsCount - 1}\n numBeats={beats.length + 1}\n onNextClick={handleNextClick}\n onPreviousClick={handlePreviousClick}\n scrollRightBoundary={scrollBoundry}\n scrollX={scrollX}\n shouldApplyDotAnimation={allowSingleCardPeeking}\n visibleCardsCount={visibleCardsCount}\n />\n )}\n </Stack>\n )\n}\n\nexport default observer(MicroBeatCarousel)\n"],"mappings":";;;;;;;;AAmCA,IAAM,KAAA,CAAuD,EAC3D,mBAAA,GACA,wBAAA,GACA,OAAA,IAAQ,CAAC,GACT,WAAA,GACA,iBAAA,GACA,0BAAA,GACA,aAAA,GACA,SAAA,GACA,sB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AA,QACJ,SAAA;AAAA,QACC,UAAA;AAAA,QACD,SAAA;AAAA,MACV,CAAA;AAAA,IACI,CAAA,GACN,KACC,gBAAA,EAAC,GAAD;AAAA,MACE,kBAAkB,IAAkB,IAAoB;AAAA,MACxD,UAAU,EAAM,SAAS;AAAA,MACzB,aAAa;AAAA,MACb,iBAAiB;AAAA,MACjB,qBAAqB;AAAA,MACZ,SAAA;AAAA,MACT,yBAAyB;AAAA,MACN,mBAAA;AAAA,IACpB,CAAA,CAEE;AAAA;AAEX,GAEA,KAAe,EAAS,EAAiB"}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { InsightsMicroWidgetDataContext as e } from "./InsightsMicroWidgetDataProvider.es.js";
|
|
2
2
|
import r from "react";
|
|
3
3
|
var s = () => {
|
|
4
|
+
const t = r.useContext(e);
|
|
5
|
+
if (!t) throw new Error("useStore() must be used within the InsightsMicroWidgetDataProvider");
|
|
6
|
+
return t.store;
|
|
7
|
+
}, n = () => {
|
|
4
8
|
const t = r.useContext(e);
|
|
5
9
|
if (!t) throw new Error("useCopyStore() must be used within the InsightsMicroWidgetDataProvider");
|
|
6
10
|
return t.store.copyStore;
|
|
7
|
-
},
|
|
11
|
+
}, u = () => {
|
|
8
12
|
const t = r.useContext(e);
|
|
9
13
|
if (!t?.store?.insightsMicroWidgetStore) throw new Error("useInsightsMicroWidgetStore() must be used within the InsightsMicroWidgetDataProvider");
|
|
10
14
|
return t.store.insightsMicroWidgetStore;
|
|
11
|
-
},
|
|
15
|
+
}, h = () => {
|
|
12
16
|
const t = r.useContext(e);
|
|
13
17
|
if (!t) throw new Error("useEvent() must be used within the InsightsMicroWidgetDataProvider");
|
|
14
18
|
return { onEvent: t.onEvent };
|
|
@@ -18,10 +22,11 @@ var s = () => {
|
|
|
18
22
|
return { onPageview: t.onPageview };
|
|
19
23
|
};
|
|
20
24
|
export {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
g as usePageview
|
|
25
|
+
n as useCopyStore,
|
|
26
|
+
h as useEvent,
|
|
27
|
+
u as useInsightsMicroWidgetStore,
|
|
28
|
+
g as usePageview,
|
|
29
|
+
s as useStore
|
|
25
30
|
};
|
|
26
31
|
|
|
27
32
|
//# sourceMappingURL=hooks.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.es.js","names":[],"sources":["../../../src/microinsights/context/hooks.tsx"],"sourcesContent":["import React from 'react'\n\nimport { InsightsMicroWidgetDataContext } from './InsightsMicroWidgetDataProvider'\n\nexport const useDataContext = () => {\n const context = React.useContext(InsightsMicroWidgetDataContext)\n\n if (!context) {\n throw new Error('useDataContext() must be used within the InsightsMicroWidgetDataProvider')\n }\n\n return context\n}\n\nexport const useStore = () => {\n const context = React.useContext(InsightsMicroWidgetDataContext)\n\n if (!context) {\n throw new Error('useStore() must be used within the InsightsMicroWidgetDataProvider')\n }\n\n return context.store\n}\n\nexport const useCopyStore = () => {\n const context = React.useContext(InsightsMicroWidgetDataContext)\n\n if (!context) {\n throw new Error('useCopyStore() must be used within the InsightsMicroWidgetDataProvider')\n }\n\n return context.store.copyStore\n}\n\nexport const useInsightsMicroWidgetStore = () => {\n const context = React.useContext(InsightsMicroWidgetDataContext)\n\n if (!context?.store?.insightsMicroWidgetStore) {\n throw new Error(\n 'useInsightsMicroWidgetStore() must be used within the InsightsMicroWidgetDataProvider',\n )\n }\n\n return context.store.insightsMicroWidgetStore\n}\n\nexport const useEvent = () => {\n const context = React.useContext(InsightsMicroWidgetDataContext)\n\n if (!context) {\n throw new Error('useEvent() must be used within the InsightsMicroWidgetDataProvider')\n }\n\n return { onEvent: context.onEvent }\n}\n\nexport const usePageview = () => {\n const context = React.useContext(InsightsMicroWidgetDataContext)\n\n if (!context) {\n throw new Error('usePageview() must be used within the InsightsMicroWidgetDataProvider')\n }\n\n return { onPageview: context.onPageview }\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"hooks.es.js","names":[],"sources":["../../../src/microinsights/context/hooks.tsx"],"sourcesContent":["import React from 'react'\n\nimport { InsightsMicroWidgetDataContext } from './InsightsMicroWidgetDataProvider'\n\nexport const useDataContext = () => {\n const context = React.useContext(InsightsMicroWidgetDataContext)\n\n if (!context) {\n throw new Error('useDataContext() must be used within the InsightsMicroWidgetDataProvider')\n }\n\n return context\n}\n\nexport const useStore = () => {\n const context = React.useContext(InsightsMicroWidgetDataContext)\n\n if (!context) {\n throw new Error('useStore() must be used within the InsightsMicroWidgetDataProvider')\n }\n\n return context.store\n}\n\nexport const useCopyStore = () => {\n const context = React.useContext(InsightsMicroWidgetDataContext)\n\n if (!context) {\n throw new Error('useCopyStore() must be used within the InsightsMicroWidgetDataProvider')\n }\n\n return context.store.copyStore\n}\n\nexport const useInsightsMicroWidgetStore = () => {\n const context = React.useContext(InsightsMicroWidgetDataContext)\n\n if (!context?.store?.insightsMicroWidgetStore) {\n throw new Error(\n 'useInsightsMicroWidgetStore() must be used within the InsightsMicroWidgetDataProvider',\n )\n }\n\n return context.store.insightsMicroWidgetStore\n}\n\nexport const useEvent = () => {\n const context = React.useContext(InsightsMicroWidgetDataContext)\n\n if (!context) {\n throw new Error('useEvent() must be used within the InsightsMicroWidgetDataProvider')\n }\n\n return { onEvent: context.onEvent }\n}\n\nexport const usePageview = () => {\n const context = React.useContext(InsightsMicroWidgetDataContext)\n\n if (!context) {\n throw new Error('usePageview() must be used within the InsightsMicroWidgetDataProvider')\n }\n\n return { onPageview: context.onPageview }\n}\n"],"mappings":";;AAcA,IAAa,IAAA,MAAiB;AAC5B,QAAM,IAAU,EAAM,WAAW,CAA8B;AAE/D,MAAI,CAAC,EACH,OAAM,IAAI,MAAM,oEAAoE;AAGtF,SAAO,EAAQ;AACjB,GAEa,IAAA,MAAqB;AAChC,QAAM,IAAU,EAAM,WAAW,CAA8B;AAE/D,MAAI,CAAC,EACH,OAAM,IAAI,MAAM,wEAAwE;AAG1F,SAAO,EAAQ,MAAM;AACvB,GAEa,IAAA,MAAoC;AAC/C,QAAM,IAAU,EAAM,WAAW,CAA8B;AAE/D,MAAI,CAAC,GAAS,OAAO,yBACnB,OAAM,IAAI,MACR,uFACF;AAGF,SAAO,EAAQ,MAAM;AACvB,GAEa,IAAA,MAAiB;AAC5B,QAAM,IAAU,EAAM,WAAW,CAA8B;AAE/D,MAAI,CAAC,EACH,OAAM,IAAI,MAAM,oEAAoE;AAGtF,SAAO,EAAE,SAAS,EAAQ,QAAQ;AACpC,GAEa,IAAA,MAAoB;AAC/B,QAAM,IAAU,EAAM,WAAW,CAA8B;AAE/D,MAAI,CAAC,EACH,OAAM,IAAI,MAAM,uEAAuE;AAGzF,SAAO,EAAE,YAAY,EAAQ,WAAW;AAC1C"}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { Beat, Offer } from '../core';
|
|
2
2
|
import { SxProps } from '@mui/material/styles';
|
|
3
|
+
/**
|
|
4
|
+
* What an Insights 2.0 card's in-description CTA does when the card is tapped.
|
|
5
|
+
* - `external` (default): the host decides, through `onCardClick` (pulse posts a message, the money
|
|
6
|
+
* dashboard navigates to the full insights feed).
|
|
7
|
+
* - `internal`: the widget opens the CTA's own action block in place (its `in_description_cta.block`
|
|
8
|
+
* and `variant`), fires its analytics, and does NOT call `onCardClick`.
|
|
9
|
+
* Only a beat that carries a real block on `in_description_cta` opens in place; every other beat
|
|
10
|
+
* (legacy, or no block) keeps the `external` behavior. Needs the host's `GlobalDataProvider`.
|
|
11
|
+
*/
|
|
12
|
+
export type InDescriptionCtaBehavior = 'internal' | 'external';
|
|
3
13
|
export interface MicroWidgetProps {
|
|
4
14
|
allowSingleCardPeeking?: boolean;
|
|
5
15
|
areBeatsLoading?: boolean;
|
|
@@ -8,6 +18,7 @@ export interface MicroWidgetProps {
|
|
|
8
18
|
endpoint?: string;
|
|
9
19
|
headerSx?: SxProps;
|
|
10
20
|
heightOverrides?: number | string;
|
|
21
|
+
inDescriptionCtaBehavior?: InDescriptionCtaBehavior;
|
|
11
22
|
logOutUser?: () => void;
|
|
12
23
|
onCardClick?: (beat?: Beat | undefined) => void;
|
|
13
24
|
onEvent?: (event?: string | undefined) => void;
|
|
@@ -26,6 +37,7 @@ export interface MicroInsightCardProps {
|
|
|
26
37
|
ariaLabel?: string;
|
|
27
38
|
elevation?: number;
|
|
28
39
|
heightOverrides?: number | string;
|
|
40
|
+
inDescriptionCtaBehavior?: InDescriptionCtaBehavior;
|
|
29
41
|
isActiveCard?: boolean;
|
|
30
42
|
onCardClick?: (beat?: Beat | undefined) => void;
|
|
31
43
|
posthog?: TheWholeHog;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnalyticSession } from '../analytics';
|
|
2
|
-
import { BeatApi } from '../../core/api/BeatApi';
|
|
2
|
+
import { BeatApi, BeatFeedbackRequest } from '../../core/api/BeatApi';
|
|
3
3
|
import { Beat } from '../../core/types/Beat';
|
|
4
4
|
export interface ErrPromise<TSuccess, TError = unknown> {
|
|
5
5
|
then<TResult1 = TSuccess, TResult2 = never>(onfulfilled?: ((value: TSuccess) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: TError) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
|
|
@@ -13,4 +13,6 @@ export declare class InsightsMicroWidgetStore {
|
|
|
13
13
|
initialize: (endpoint: string, token: string, logOutUser: () => void) => Promise<void>;
|
|
14
14
|
updateBeat: (beat: Beat) => Promise<void>;
|
|
15
15
|
updateOffer: (beat: Beat) => Promise<void>;
|
|
16
|
+
/** Unlike the updates above this returns the request: a survey needs to know if it failed. */
|
|
17
|
+
sendBeatFeedback: (feedback: BeatFeedbackRequest) => Promise<any>;
|
|
16
18
|
}
|
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
import { BeatApi as
|
|
2
|
-
import { onAnalyticEvent as
|
|
1
|
+
import { BeatApi as s } from "../../core/api/BeatApi.es.js";
|
|
2
|
+
import { onAnalyticEvent as c, onAnalyticPageView as o } from "../analytics.es.js";
|
|
3
3
|
import { makeAutoObservable as p } from "mobx";
|
|
4
|
-
var
|
|
5
|
-
onAnalyticEvent =
|
|
6
|
-
onAnalyticPageView =
|
|
7
|
-
beatApi = new
|
|
4
|
+
var d = class {
|
|
5
|
+
onAnalyticEvent = c;
|
|
6
|
+
onAnalyticPageView = o;
|
|
7
|
+
beatApi = new s("/", "");
|
|
8
8
|
constructor() {
|
|
9
9
|
p(this);
|
|
10
10
|
}
|
|
11
|
-
initialize = async (
|
|
12
|
-
this.onAnalyticEvent = (
|
|
13
|
-
|
|
11
|
+
initialize = async (e, h, n) => {
|
|
12
|
+
this.onAnalyticEvent = (a, i) => {
|
|
13
|
+
c(a, i).then((t) => t).catch((t) => {
|
|
14
14
|
throw t.status === 401 && n(), t;
|
|
15
15
|
});
|
|
16
|
-
}, this.onAnalyticPageView = (
|
|
17
|
-
|
|
16
|
+
}, this.onAnalyticPageView = (a, i) => {
|
|
17
|
+
o(a, i).then((t) => t).catch((t) => {
|
|
18
18
|
throw t.status === 401 && n(), t;
|
|
19
19
|
});
|
|
20
|
-
}, this.beatApi = new
|
|
20
|
+
}, this.beatApi = new s(e, h);
|
|
21
21
|
};
|
|
22
|
-
updateBeat = async (
|
|
23
|
-
this.beatApi.updateBeat(
|
|
22
|
+
updateBeat = async (e) => {
|
|
23
|
+
this.beatApi.updateBeat(e);
|
|
24
24
|
};
|
|
25
|
-
updateOffer = async (
|
|
26
|
-
this.beatApi.updateOffer(
|
|
25
|
+
updateOffer = async (e) => {
|
|
26
|
+
this.beatApi.updateOffer(e);
|
|
27
27
|
};
|
|
28
|
+
sendBeatFeedback = (e) => this.beatApi.sendBeatFeedback(e);
|
|
28
29
|
};
|
|
29
30
|
export {
|
|
30
|
-
|
|
31
|
+
d as InsightsMicroWidgetStore
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
//# sourceMappingURL=InsightsMicroWidgetStore.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InsightsMicroWidgetStore.es.js","names":[],"sources":["../../../src/microinsights/stores/InsightsMicroWidgetStore.ts"],"sourcesContent":["import { makeAutoObservable } from 'mobx'\n\nimport { type AnalyticSession, onAnalyticEvent, onAnalyticPageView } from '../analytics'\nimport { BeatApi } from '../../core/api/BeatApi'\nimport type { Beat } from '../../core/types/Beat'\n\nexport interface ErrPromise<TSuccess, TError = unknown> {\n then<TResult1 = TSuccess, TResult2 = never>(\n onfulfilled?: ((value: TSuccess) => TResult1 | PromiseLike<TResult1>) | undefined | null,\n onrejected?: ((reason: TError) => TResult2 | PromiseLike<TResult2>) | undefined | null,\n ): Promise<TResult1 | TResult2>\n catch<TResult = never>(\n onrejected?: ((reason: TError) => TResult | PromiseLike<TResult>) | undefined | null,\n ): Promise<TSuccess | TResult>\n}\n\nexport class InsightsMicroWidgetStore {\n onAnalyticEvent: (\n event: string,\n session: AnalyticSession,\n ) => ErrPromise<string, AnalyticSession> = onAnalyticEvent\n onAnalyticPageView: (\n event: string,\n session: AnalyticSession,\n ) => ErrPromise<string, AnalyticSession> = onAnalyticPageView\n\n beatApi = new BeatApi('/', '')\n\n constructor() {\n makeAutoObservable(this)\n }\n\n initialize = async (endpoint: string, token: string, logOutUser: () => void) => {\n this.onAnalyticEvent = (event: string, session: AnalyticSession): any => {\n onAnalyticEvent(event, session)\n .then((res) => res)\n .catch((err) => {\n if (err.status === 401) {\n logOutUser()\n }\n throw err\n })\n }\n\n this.onAnalyticPageView = (page: string, session: AnalyticSession): any => {\n onAnalyticPageView(page, session)\n .then((res) => res)\n .catch((err) => {\n if (err.status === 401) {\n logOutUser()\n }\n throw err\n })\n }\n\n this.beatApi = new BeatApi(endpoint, token)\n }\n\n updateBeat = async (beat: Beat) => {\n this.beatApi.updateBeat(beat)\n }\n\n updateOffer = async (beat: Beat) => {\n this.beatApi.updateOffer(beat)\n }\n}\n"],"mappings":";;;AAgBA,IAAa,IAAb,MAAsC;AAAA,EACpC,kBAG2C;AAAA,EAC3C,qBAG2C;AAAA,EAE3C,UAAU,IAAI,EAAQ,KAAK,EAAE;AAAA,EAE7B,cAAc;AACZ,IAAA,EAAmB,IAAI;AAAA,EACzB;AAAA,EAEA,aAAa,OAAO,GAAkB,GAAe,MAA2B;AAC9E,SAAK,kBAAA,CAAmB,GAAe,MAAkC;AACvE,MAAA,EAAgB,GAAO,CAAO,EAC3B,KAAA,CAAM,MAAQ,CAAG,EACjB,MAAA,CAAO,MAAQ;AACd,cAAI,EAAI,WAAW,OACjB,EAAW,GAEP;AAAA,MACR,CAAC;AAAA,IACL,GAEA,KAAK,qBAAA,CAAsB,GAAc,MAAkC;AACzE,MAAA,EAAmB,GAAM,CAAO,EAC7B,KAAA,CAAM,MAAQ,CAAG,EACjB,MAAA,CAAO,MAAQ;AACd,cAAI,EAAI,WAAW,OACjB,EAAW,GAEP;AAAA,MACR,CAAC;AAAA,IACL,GAEA,KAAK,UAAU,IAAI,EAAQ,GAAU,CAAK;AAAA,EAC5C;AAAA,EAEA,aAAa,OAAO,MAAe;AACjC,SAAK,QAAQ,WAAW,CAAI;AAAA,EAC9B;AAAA,EAEA,cAAc,OAAO,MAAe;AAClC,SAAK,QAAQ,YAAY,CAAI;AAAA,EAC/B;
|
|
1
|
+
{"version":3,"file":"InsightsMicroWidgetStore.es.js","names":[],"sources":["../../../src/microinsights/stores/InsightsMicroWidgetStore.ts"],"sourcesContent":["import { makeAutoObservable } from 'mobx'\n\nimport { type AnalyticSession, onAnalyticEvent, onAnalyticPageView } from '../analytics'\nimport { BeatApi, type BeatFeedbackRequest } from '../../core/api/BeatApi'\nimport type { Beat } from '../../core/types/Beat'\n\nexport interface ErrPromise<TSuccess, TError = unknown> {\n then<TResult1 = TSuccess, TResult2 = never>(\n onfulfilled?: ((value: TSuccess) => TResult1 | PromiseLike<TResult1>) | undefined | null,\n onrejected?: ((reason: TError) => TResult2 | PromiseLike<TResult2>) | undefined | null,\n ): Promise<TResult1 | TResult2>\n catch<TResult = never>(\n onrejected?: ((reason: TError) => TResult | PromiseLike<TResult>) | undefined | null,\n ): Promise<TSuccess | TResult>\n}\n\nexport class InsightsMicroWidgetStore {\n onAnalyticEvent: (\n event: string,\n session: AnalyticSession,\n ) => ErrPromise<string, AnalyticSession> = onAnalyticEvent\n onAnalyticPageView: (\n event: string,\n session: AnalyticSession,\n ) => ErrPromise<string, AnalyticSession> = onAnalyticPageView\n\n beatApi = new BeatApi('/', '')\n\n constructor() {\n makeAutoObservable(this)\n }\n\n initialize = async (endpoint: string, token: string, logOutUser: () => void) => {\n this.onAnalyticEvent = (event: string, session: AnalyticSession): any => {\n onAnalyticEvent(event, session)\n .then((res) => res)\n .catch((err) => {\n if (err.status === 401) {\n logOutUser()\n }\n throw err\n })\n }\n\n this.onAnalyticPageView = (page: string, session: AnalyticSession): any => {\n onAnalyticPageView(page, session)\n .then((res) => res)\n .catch((err) => {\n if (err.status === 401) {\n logOutUser()\n }\n throw err\n })\n }\n\n this.beatApi = new BeatApi(endpoint, token)\n }\n\n updateBeat = async (beat: Beat) => {\n this.beatApi.updateBeat(beat)\n }\n\n updateOffer = async (beat: Beat) => {\n this.beatApi.updateOffer(beat)\n }\n\n /** Unlike the updates above this returns the request: a survey needs to know if it failed. */\n sendBeatFeedback = (feedback: BeatFeedbackRequest) => this.beatApi.sendBeatFeedback(feedback)\n}\n"],"mappings":";;;AAgBA,IAAa,IAAb,MAAsC;AAAA,EACpC,kBAG2C;AAAA,EAC3C,qBAG2C;AAAA,EAE3C,UAAU,IAAI,EAAQ,KAAK,EAAE;AAAA,EAE7B,cAAc;AACZ,IAAA,EAAmB,IAAI;AAAA,EACzB;AAAA,EAEA,aAAa,OAAO,GAAkB,GAAe,MAA2B;AAC9E,SAAK,kBAAA,CAAmB,GAAe,MAAkC;AACvE,MAAA,EAAgB,GAAO,CAAO,EAC3B,KAAA,CAAM,MAAQ,CAAG,EACjB,MAAA,CAAO,MAAQ;AACd,cAAI,EAAI,WAAW,OACjB,EAAW,GAEP;AAAA,MACR,CAAC;AAAA,IACL,GAEA,KAAK,qBAAA,CAAsB,GAAc,MAAkC;AACzE,MAAA,EAAmB,GAAM,CAAO,EAC7B,KAAA,CAAM,MAAQ,CAAG,EACjB,MAAA,CAAO,MAAQ;AACd,cAAI,EAAI,WAAW,OACjB,EAAW,GAEP;AAAA,MACR,CAAC;AAAA,IACL,GAEA,KAAK,UAAU,IAAI,EAAQ,GAAU,CAAK;AAAA,EAC5C;AAAA,EAEA,aAAa,OAAO,MAAe;AACjC,SAAK,QAAQ,WAAW,CAAI;AAAA,EAC9B;AAAA,EAEA,cAAc,OAAO,MAAe;AAClC,SAAK,QAAQ,YAAY,CAAI;AAAA,EAC/B;AAAA,EAGA,mBAAA,CAAoB,MAAkC,KAAK,QAAQ,iBAAiB,CAAQ;AAC9F"}
|