123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070 |
- var __defProp = Object.defineProperty;
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
- var __publicField = (obj, key, value) => {
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
- return value;
- };
- // src/literals/index.ts
- var ACTIONS = {
- INIT: "init",
- START: "start",
- STOP: "stop",
- RESET: "reset",
- PREV: "prev",
- NEXT: "next",
- GO: "go",
- CLOSE: "close",
- SKIP: "skip",
- UPDATE: "update"
- };
- var EVENTS = {
- TOUR_START: "tour:start",
- STEP_BEFORE: "step:before",
- BEACON: "beacon",
- TOOLTIP: "tooltip",
- STEP_AFTER: "step:after",
- TOUR_END: "tour:end",
- TOUR_STATUS: "tour:status",
- TARGET_NOT_FOUND: "error:target_not_found",
- ERROR: "error"
- };
- var LIFECYCLE = {
- INIT: "init",
- READY: "ready",
- BEACON: "beacon",
- TOOLTIP: "tooltip",
- COMPLETE: "complete",
- ERROR: "error"
- };
- var STATUS = {
- IDLE: "idle",
- READY: "ready",
- WAITING: "waiting",
- RUNNING: "running",
- PAUSED: "paused",
- SKIPPED: "skipped",
- FINISHED: "finished",
- ERROR: "error"
- };
- // src/components/index.tsx
- import * as React9 from "react";
- import isEqual from "@gilbarbara/deep-equal";
- import is6 from "is-lite";
- import treeChanges3 from "tree-changes";
- // src/modules/dom.ts
- import scroll from "scroll";
- import scrollParent from "scrollparent";
- function canUseDOM() {
- return !!(typeof window !== "undefined" && window.document && window.document.createElement);
- }
- function getClientRect(element) {
- if (!element) {
- return null;
- }
- return element.getBoundingClientRect();
- }
- function getDocumentHeight() {
- const { body, documentElement } = document;
- if (!body || !documentElement) {
- return 0;
- }
- return Math.max(
- body.scrollHeight,
- body.offsetHeight,
- documentElement.clientHeight,
- documentElement.scrollHeight,
- documentElement.offsetHeight
- );
- }
- function getElement(element) {
- if (typeof element === "string") {
- return document.querySelector(element);
- }
- return element;
- }
- function getStyleComputedProperty(el) {
- if (!el || el.nodeType !== 1) {
- return null;
- }
- return getComputedStyle(el);
- }
- function getScrollParent(element, skipFix, forListener) {
- if (!element) {
- return scrollDocument();
- }
- const parent = scrollParent(element);
- if (parent) {
- if (parent.isSameNode(scrollDocument())) {
- if (forListener) {
- return document;
- }
- return scrollDocument();
- }
- const hasScrolling = parent.scrollHeight > parent.offsetHeight;
- if (!hasScrolling && !skipFix) {
- parent.style.overflow = "initial";
- return scrollDocument();
- }
- }
- return parent;
- }
- function hasCustomScrollParent(element, skipFix) {
- if (!element) {
- return false;
- }
- const parent = getScrollParent(element, skipFix);
- return parent ? !parent.isSameNode(scrollDocument()) : false;
- }
- function hasCustomOffsetParent(element) {
- return element.offsetParent !== document.body;
- }
- function hasPosition(el, type = "fixed") {
- if (!el || !(el instanceof HTMLElement)) {
- return false;
- }
- const { nodeName } = el;
- const styles = getStyleComputedProperty(el);
- if (nodeName === "BODY" || nodeName === "HTML") {
- return false;
- }
- if (styles && styles.position === type) {
- return true;
- }
- if (!el.parentNode) {
- return false;
- }
- return hasPosition(el.parentNode, type);
- }
- function isElementVisible(element) {
- var _a;
- if (!element) {
- return false;
- }
- let parentElement = element;
- while (parentElement) {
- if (parentElement === document.body) {
- break;
- }
- if (parentElement instanceof HTMLElement) {
- const { display, visibility } = getComputedStyle(parentElement);
- if (display === "none" || visibility === "hidden") {
- return false;
- }
- }
- parentElement = (_a = parentElement.parentElement) != null ? _a : null;
- }
- return true;
- }
- function getElementPosition(element, offset, skipFix) {
- var _a;
- const elementRect = getClientRect(element);
- const parent = getScrollParent(element, skipFix);
- const hasScrollParent = hasCustomScrollParent(element, skipFix);
- let parentTop = 0;
- let top = (_a = elementRect == null ? void 0 : elementRect.top) != null ? _a : 0;
- if (parent instanceof HTMLElement) {
- parentTop = parent.scrollTop;
- if (!hasScrollParent && !hasPosition(element)) {
- top += parentTop;
- }
- if (!parent.isSameNode(scrollDocument())) {
- top += scrollDocument().scrollTop;
- }
- }
- return Math.floor(top - offset);
- }
- function getScrollTo(element, offset, skipFix) {
- var _a;
- if (!element) {
- return 0;
- }
- const { offsetTop = 0, scrollTop = 0 } = (_a = scrollParent(element)) != null ? _a : {};
- let top = element.getBoundingClientRect().top + scrollTop;
- if (!!offsetTop && (hasCustomScrollParent(element, skipFix) || hasCustomOffsetParent(element))) {
- top -= offsetTop;
- }
- const output = Math.floor(top - offset);
- return output < 0 ? 0 : output;
- }
- function scrollDocument() {
- var _a;
- return (_a = document.scrollingElement) != null ? _a : document.documentElement;
- }
- function scrollTo(value, options) {
- const { duration, element } = options;
- return new Promise((resolve, reject) => {
- const { scrollTop } = element;
- const limit = value > scrollTop ? value - scrollTop : scrollTop - value;
- scroll.top(element, value, { duration: limit < 100 ? 50 : duration }, (error) => {
- if (error && error.message !== "Element already at target scroll position") {
- return reject(error);
- }
- return resolve();
- });
- });
- }
- // src/modules/helpers.ts
- import { isValidElement } from "react";
- import { createPortal } from "react-dom";
- import is from "is-lite";
- var isReact16 = createPortal !== void 0;
- function getBrowser(userAgent = navigator.userAgent) {
- let browser = userAgent;
- if (typeof window === "undefined") {
- browser = "node";
- } else if (document.documentMode) {
- browser = "ie";
- } else if (/Edge/.test(userAgent)) {
- browser = "edge";
- } else if (Boolean(window.opera) || userAgent.includes(" OPR/")) {
- browser = "opera";
- } else if (typeof window.InstallTrigger !== "undefined") {
- browser = "firefox";
- } else if (window.chrome) {
- browser = "chrome";
- } else if (/(Version\/([\d._]+).*Safari|CriOS|FxiOS| Mobile\/)/.test(userAgent)) {
- browser = "safari";
- }
- return browser;
- }
- function getText(root) {
- const content = [];
- const recurse = (child) => {
- if (typeof child === "string" || typeof child === "number") {
- content.push(child);
- } else if (Array.isArray(child)) {
- child.forEach((c) => recurse(c));
- } else if (isValidElement(child)) {
- const { children } = child.props;
- if (Array.isArray(children)) {
- children.forEach((c) => recurse(c));
- } else {
- recurse(children);
- }
- }
- };
- recurse(root);
- return content.join(" ").trim();
- }
- function hasValidKeys(object, keys) {
- if (!is.plainObject(object) || !is.array(keys)) {
- return false;
- }
- return Object.keys(object).every((d) => keys.includes(d));
- }
- function hexToRGB(hex) {
- const shorthandRegex = /^#?([\da-f])([\da-f])([\da-f])$/i;
- const properHex = hex.replace(shorthandRegex, (_m, r, g, b) => r + r + g + g + b + b);
- const result = /^#?([\da-f]{2})([\da-f]{2})([\da-f]{2})$/i.exec(properHex);
- return result ? [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)] : [];
- }
- function hideBeacon(step) {
- return step.disableBeacon || step.placement === "center";
- }
- function isLegacy() {
- return !["chrome", "safari", "firefox", "opera"].includes(getBrowser());
- }
- function log({ data, debug = false, title, warn = false }) {
- const logFn = warn ? console.warn || console.error : console.log;
- if (debug) {
- if (title && data) {
- console.groupCollapsed(
- `%creact-joyride: ${title}`,
- "color: #ff0044; font-weight: bold; font-size: 12px;"
- );
- if (Array.isArray(data)) {
- data.forEach((d) => {
- if (is.plainObject(d) && d.key) {
- logFn.apply(console, [d.key, d.value]);
- } else {
- logFn.apply(console, [d]);
- }
- });
- } else {
- logFn.apply(console, [data]);
- }
- console.groupEnd();
- } else {
- console.error("Missing title or data props");
- }
- }
- }
- function shouldScroll(options) {
- const { isFirstStep, lifecycle, previousLifecycle, scrollToFirstStep, step, target } = options;
- return !step.disableScrolling && (!isFirstStep || scrollToFirstStep || lifecycle === LIFECYCLE.TOOLTIP) && step.placement !== "center" && (!step.isFixed || !hasPosition(target)) && // fixed steps don't need to scroll
- previousLifecycle !== lifecycle && [LIFECYCLE.BEACON, LIFECYCLE.TOOLTIP].includes(lifecycle);
- }
- // src/modules/step.ts
- import { omit, pick } from "@gilbarbara/helpers";
- import deepmerge2 from "deepmerge";
- import is2 from "is-lite";
- // src/defaults.ts
- import { noop } from "@gilbarbara/helpers";
- var defaultFloaterProps = {
- options: {
- preventOverflow: {
- boundariesElement: "scrollParent"
- }
- },
- wrapperOptions: {
- offset: -18,
- position: true
- }
- };
- var defaultLocale = {
- back: "Back",
- close: "Close",
- last: "Last",
- next: "Next",
- open: "Open the dialog",
- skip: "Skip"
- };
- var defaultStep = {
- event: "click",
- placement: "bottom",
- offset: 10,
- disableBeacon: false,
- disableCloseOnEsc: false,
- disableOverlay: false,
- disableOverlayClose: false,
- disableScrollParentFix: false,
- disableScrolling: false,
- hideBackButton: false,
- hideCloseButton: false,
- hideFooter: false,
- isFixed: false,
- locale: defaultLocale,
- showProgress: false,
- showSkipButton: false,
- spotlightClicks: false,
- spotlightPadding: 10
- };
- var defaultProps = {
- continuous: false,
- debug: false,
- disableCloseOnEsc: false,
- disableOverlay: false,
- disableOverlayClose: false,
- disableScrolling: false,
- disableScrollParentFix: false,
- getHelpers: noop(),
- hideBackButton: false,
- run: true,
- scrollOffset: 20,
- scrollDuration: 300,
- scrollToFirstStep: false,
- showSkipButton: false,
- showProgress: false,
- spotlightClicks: false,
- spotlightPadding: 10,
- steps: []
- };
- // src/styles.ts
- import deepmerge from "deepmerge";
- var defaultOptions = {
- arrowColor: "#fff",
- backgroundColor: "#fff",
- beaconSize: 36,
- overlayColor: "rgba(0, 0, 0, 0.5)",
- primaryColor: "#f04",
- spotlightShadow: "0 0 15px rgba(0, 0, 0, 0.5)",
- textColor: "#333",
- width: 380,
- zIndex: 100
- };
- var buttonBase = {
- backgroundColor: "transparent",
- border: 0,
- borderRadius: 0,
- color: "#555",
- cursor: "pointer",
- fontSize: 16,
- lineHeight: 1,
- padding: 8,
- WebkitAppearance: "none"
- };
- var spotlight = {
- borderRadius: 4,
- position: "absolute"
- };
- function getStyles(propsStyles, stepStyles) {
- const mergedStyles = deepmerge(propsStyles != null ? propsStyles : {}, stepStyles != null ? stepStyles : {});
- const options = deepmerge(defaultOptions, mergedStyles.options || {});
- let { width } = options;
- if (window.innerWidth > 480) {
- width = 380;
- }
- if ("width" in options) {
- width = typeof options.width === "number" && window.innerWidth < options.width ? window.innerWidth - 30 : options.width;
- }
- const overlay = {
- bottom: 0,
- left: 0,
- overflow: "hidden",
- position: "absolute",
- right: 0,
- top: 0,
- zIndex: options.zIndex
- };
- const defaultStyles = {
- beacon: {
- ...buttonBase,
- display: "inline-block",
- height: options.beaconSize,
- position: "relative",
- width: options.beaconSize,
- zIndex: options.zIndex
- },
- beaconInner: {
- animation: "joyride-beacon-inner 1.2s infinite ease-in-out",
- backgroundColor: options.primaryColor,
- borderRadius: "50%",
- display: "block",
- height: "50%",
- left: "50%",
- opacity: 0.7,
- position: "absolute",
- top: "50%",
- transform: "translate(-50%, -50%)",
- width: "50%"
- },
- beaconOuter: {
- animation: "joyride-beacon-outer 1.2s infinite ease-in-out",
- backgroundColor: `rgba(${hexToRGB(options.primaryColor).join(",")}, 0.2)`,
- border: `2px solid ${options.primaryColor}`,
- borderRadius: "50%",
- boxSizing: "border-box",
- display: "block",
- height: "100%",
- left: 0,
- opacity: 0.9,
- position: "absolute",
- top: 0,
- transformOrigin: "center",
- width: "100%"
- },
- tooltip: {
- backgroundColor: options.backgroundColor,
- borderRadius: 5,
- boxSizing: "border-box",
- color: options.textColor,
- fontSize: 16,
- maxWidth: "100%",
- padding: 15,
- position: "relative",
- width
- },
- tooltipContainer: {
- lineHeight: 1.4,
- textAlign: "center"
- },
- tooltipTitle: {
- fontSize: 18,
- margin: 0
- },
- tooltipContent: {
- padding: "20px 10px"
- },
- tooltipFooter: {
- alignItems: "center",
- display: "flex",
- justifyContent: "flex-end",
- marginTop: 15
- },
- tooltipFooterSpacer: {
- flex: 1
- },
- buttonNext: {
- ...buttonBase,
- backgroundColor: options.primaryColor,
- borderRadius: 4,
- color: "#fff"
- },
- buttonBack: {
- ...buttonBase,
- color: options.primaryColor,
- marginLeft: "auto",
- marginRight: 5
- },
- buttonClose: {
- ...buttonBase,
- color: options.textColor,
- height: 14,
- padding: 15,
- position: "absolute",
- right: 0,
- top: 0,
- width: 14
- },
- buttonSkip: {
- ...buttonBase,
- color: options.textColor,
- fontSize: 14
- },
- overlay: {
- ...overlay,
- backgroundColor: options.overlayColor,
- mixBlendMode: "hard-light"
- },
- overlayLegacy: {
- ...overlay
- },
- overlayLegacyCenter: {
- ...overlay,
- backgroundColor: options.overlayColor
- },
- spotlight: {
- ...spotlight,
- backgroundColor: "gray"
- },
- spotlightLegacy: {
- ...spotlight,
- boxShadow: `0 0 0 9999px ${options.overlayColor}, ${options.spotlightShadow}`
- },
- floaterStyles: {
- arrow: {
- color: options.arrowColor
- },
- options: {
- zIndex: options.zIndex + 100
- }
- },
- options
- };
- return deepmerge(defaultStyles, mergedStyles);
- }
- // src/modules/step.ts
- function getTourProps(props) {
- return pick(
- props,
- "beaconComponent",
- "disableCloseOnEsc",
- "disableOverlay",
- "disableOverlayClose",
- "disableScrolling",
- "disableScrollParentFix",
- "floaterProps",
- "hideBackButton",
- "hideCloseButton",
- "locale",
- "showProgress",
- "showSkipButton",
- "spotlightClicks",
- "spotlightPadding",
- "styles",
- "tooltipComponent"
- );
- }
- function getMergedStep(currentStep, props) {
- var _a, _b, _c, _d, _e, _f;
- const step = currentStep != null ? currentStep : {};
- const mergedStep = deepmerge2.all([defaultStep, getTourProps(props), step], {
- isMergeableObject: is2.plainObject
- });
- const mergedStyles = getStyles(props.styles, mergedStep.styles);
- const scrollParent2 = hasCustomScrollParent(
- getElement(mergedStep.target),
- mergedStep.disableScrollParentFix
- );
- const floaterProps = deepmerge2.all([
- defaultFloaterProps,
- (_a = props.floaterProps) != null ? _a : {},
- (_b = mergedStep.floaterProps) != null ? _b : {}
- ]);
- floaterProps.offset = mergedStep.offset;
- floaterProps.styles = deepmerge2((_c = floaterProps.styles) != null ? _c : {}, mergedStyles.floaterStyles);
- floaterProps.offset += (_e = (_d = props.spotlightPadding) != null ? _d : mergedStep.spotlightPadding) != null ? _e : 0;
- if (mergedStep.placementBeacon && floaterProps.wrapperOptions) {
- floaterProps.wrapperOptions.placement = mergedStep.placementBeacon;
- }
- if (scrollParent2 && floaterProps.options.preventOverflow) {
- floaterProps.options.preventOverflow.boundariesElement = "window";
- }
- return {
- ...mergedStep,
- locale: deepmerge2.all([defaultLocale, (_f = props.locale) != null ? _f : {}, mergedStep.locale || {}]),
- floaterProps,
- styles: omit(mergedStyles, "floaterStyles")
- };
- }
- function validateStep(step, debug = false) {
- if (!is2.plainObject(step)) {
- log({
- title: "validateStep",
- data: "step must be an object",
- warn: true,
- debug
- });
- return false;
- }
- if (!step.target) {
- log({
- title: "validateStep",
- data: "target is missing from the step",
- warn: true,
- debug
- });
- return false;
- }
- return true;
- }
- function validateSteps(steps, debug = false) {
- if (!is2.array(steps)) {
- log({
- title: "validateSteps",
- data: "steps must be an array",
- warn: true,
- debug
- });
- return false;
- }
- return steps.every((d) => validateStep(d, debug));
- }
- // src/modules/store.ts
- import is3 from "is-lite";
- var defaultState = {
- action: "init",
- controlled: false,
- index: 0,
- lifecycle: LIFECYCLE.INIT,
- size: 0,
- status: STATUS.IDLE
- };
- var validKeys = ["action", "index", "lifecycle", "status"];
- var Store = class {
- constructor(options) {
- __publicField(this, "beaconPopper");
- __publicField(this, "tooltipPopper");
- __publicField(this, "data", /* @__PURE__ */ new Map());
- __publicField(this, "listener");
- __publicField(this, "store", /* @__PURE__ */ new Map());
- __publicField(this, "addListener", (listener) => {
- this.listener = listener;
- });
- __publicField(this, "setSteps", (steps) => {
- const { size, status } = this.getState();
- const state = {
- size: steps.length,
- status
- };
- this.data.set("steps", steps);
- if (status === STATUS.WAITING && !size && steps.length) {
- state.status = STATUS.RUNNING;
- }
- this.setState(state);
- });
- __publicField(this, "getPopper", (name) => {
- if (name === "beacon") {
- return this.beaconPopper;
- }
- return this.tooltipPopper;
- });
- __publicField(this, "setPopper", (name, popper) => {
- if (name === "beacon") {
- this.beaconPopper = popper;
- } else {
- this.tooltipPopper = popper;
- }
- });
- __publicField(this, "cleanupPoppers", () => {
- this.beaconPopper = null;
- this.tooltipPopper = null;
- });
- __publicField(this, "close", () => {
- const { index, status } = this.getState();
- if (status !== STATUS.RUNNING) {
- return;
- }
- this.setState({
- ...this.getNextState({ action: ACTIONS.CLOSE, index: index + 1 })
- });
- });
- __publicField(this, "go", (nextIndex) => {
- const { controlled, status } = this.getState();
- if (controlled || status !== STATUS.RUNNING) {
- return;
- }
- const step = this.getSteps()[nextIndex];
- this.setState({
- ...this.getNextState({ action: ACTIONS.GO, index: nextIndex }),
- status: step ? status : STATUS.FINISHED
- });
- });
- __publicField(this, "info", () => this.getState());
- __publicField(this, "next", () => {
- const { index, status } = this.getState();
- if (status !== STATUS.RUNNING) {
- return;
- }
- this.setState(this.getNextState({ action: ACTIONS.NEXT, index: index + 1 }));
- });
- __publicField(this, "open", () => {
- const { status } = this.getState();
- if (status !== STATUS.RUNNING) {
- return;
- }
- this.setState({
- ...this.getNextState({ action: ACTIONS.UPDATE, lifecycle: LIFECYCLE.TOOLTIP })
- });
- });
- __publicField(this, "prev", () => {
- const { index, status } = this.getState();
- if (status !== STATUS.RUNNING) {
- return;
- }
- this.setState({
- ...this.getNextState({ action: ACTIONS.PREV, index: index - 1 })
- });
- });
- __publicField(this, "reset", (restart = false) => {
- const { controlled } = this.getState();
- if (controlled) {
- return;
- }
- this.setState({
- ...this.getNextState({ action: ACTIONS.RESET, index: 0 }),
- status: restart ? STATUS.RUNNING : STATUS.READY
- });
- });
- __publicField(this, "skip", () => {
- const { status } = this.getState();
- if (status !== STATUS.RUNNING) {
- return;
- }
- this.setState({
- action: ACTIONS.SKIP,
- lifecycle: LIFECYCLE.INIT,
- status: STATUS.SKIPPED
- });
- });
- __publicField(this, "start", (nextIndex) => {
- const { index, size } = this.getState();
- this.setState({
- ...this.getNextState(
- {
- action: ACTIONS.START,
- index: is3.number(nextIndex) ? nextIndex : index
- },
- true
- ),
- status: size ? STATUS.RUNNING : STATUS.WAITING
- });
- });
- __publicField(this, "stop", (advance = false) => {
- const { index, status } = this.getState();
- if ([STATUS.FINISHED, STATUS.SKIPPED].includes(status)) {
- return;
- }
- this.setState({
- ...this.getNextState({ action: ACTIONS.STOP, index: index + (advance ? 1 : 0) }),
- status: STATUS.PAUSED
- });
- });
- __publicField(this, "update", (state) => {
- var _a;
- if (!hasValidKeys(state, validKeys)) {
- throw new Error(`State is not valid. Valid keys: ${validKeys.join(", ")}`);
- }
- this.setState({
- ...this.getNextState(
- {
- ...this.getState(),
- ...state,
- action: (_a = state.action) != null ? _a : ACTIONS.UPDATE
- },
- true
- )
- });
- });
- const { continuous = false, stepIndex, steps = [] } = options != null ? options : {};
- this.setState(
- {
- action: ACTIONS.INIT,
- controlled: is3.number(stepIndex),
- continuous,
- index: is3.number(stepIndex) ? stepIndex : 0,
- lifecycle: LIFECYCLE.INIT,
- status: steps.length ? STATUS.READY : STATUS.IDLE
- },
- true
- );
- this.beaconPopper = null;
- this.tooltipPopper = null;
- this.listener = null;
- this.setSteps(steps);
- }
- getState() {
- if (!this.store.size) {
- return { ...defaultState };
- }
- return {
- action: this.store.get("action") || "",
- controlled: this.store.get("controlled") || false,
- index: parseInt(this.store.get("index"), 10),
- lifecycle: this.store.get("lifecycle") || "",
- size: this.store.get("size") || 0,
- status: this.store.get("status") || ""
- };
- }
- getNextState(state, force = false) {
- var _a, _b, _c, _d;
- const { action, controlled, index, size, status } = this.getState();
- const newIndex = is3.number(state.index) ? state.index : index;
- const nextIndex = controlled && !force ? index : Math.min(Math.max(newIndex, 0), size);
- return {
- action: (_a = state.action) != null ? _a : action,
- controlled,
- index: nextIndex,
- lifecycle: (_b = state.lifecycle) != null ? _b : LIFECYCLE.INIT,
- size: (_c = state.size) != null ? _c : size,
- status: nextIndex === size ? STATUS.FINISHED : (_d = state.status) != null ? _d : status
- };
- }
- getSteps() {
- const steps = this.data.get("steps");
- return Array.isArray(steps) ? steps : [];
- }
- hasUpdatedState(oldState) {
- const before = JSON.stringify(oldState);
- const after = JSON.stringify(this.getState());
- return before !== after;
- }
- setState(nextState, initial = false) {
- const state = this.getState();
- const { action, index, lifecycle, size, status } = {
- ...state,
- ...nextState
- };
- this.store.set("action", action);
- this.store.set("index", index);
- this.store.set("lifecycle", lifecycle);
- this.store.set("size", size);
- this.store.set("status", status);
- if (initial) {
- this.store.set("controlled", nextState.controlled);
- this.store.set("continuous", nextState.continuous);
- }
- if (this.listener && this.hasUpdatedState(state)) {
- this.listener(this.getState());
- }
- }
- getHelpers() {
- return {
- close: this.close,
- go: this.go,
- info: this.info,
- next: this.next,
- open: this.open,
- prev: this.prev,
- reset: this.reset,
- skip: this.skip
- };
- }
- };
- function createStore(options) {
- return new Store(options);
- }
- // src/components/Step.tsx
- import * as React8 from "react";
- import Floater from "react-floater";
- import is5 from "is-lite";
- import treeChanges2 from "tree-changes";
- // src/modules/scope.ts
- var Scope = class {
- constructor(element, options) {
- __publicField(this, "element");
- __publicField(this, "options");
- __publicField(this, "canBeTabbed", (element) => {
- const { tabIndex } = element;
- if (tabIndex === null || tabIndex < 0) {
- return false;
- }
- return this.canHaveFocus(element);
- });
- __publicField(this, "canHaveFocus", (element) => {
- const validTabNodes = /input|select|textarea|button|object/;
- const nodeName = element.nodeName.toLowerCase();
- const isValid = validTabNodes.test(nodeName) && !element.getAttribute("disabled") || nodeName === "a" && !!element.getAttribute("href");
- return isValid && this.isVisible(element);
- });
- __publicField(this, "findValidTabElements", () => [].slice.call(this.element.querySelectorAll("*"), 0).filter(this.canBeTabbed));
- __publicField(this, "handleKeyDown", (event) => {
- const { code = "Tab" } = this.options;
- if (event.code === code) {
- this.interceptTab(event);
- }
- });
- __publicField(this, "interceptTab", (event) => {
- event.preventDefault();
- const elements = this.findValidTabElements();
- const { shiftKey } = event;
- if (!elements.length) {
- return;
- }
- let x = document.activeElement ? elements.indexOf(document.activeElement) : 0;
- if (x === -1 || !shiftKey && x + 1 === elements.length) {
- x = 0;
- } else if (shiftKey && x === 0) {
- x = elements.length - 1;
- } else {
- x += shiftKey ? -1 : 1;
- }
- elements[x].focus();
- });
- // eslint-disable-next-line class-methods-use-this
- __publicField(this, "isHidden", (element) => {
- const noSize = element.offsetWidth <= 0 && element.offsetHeight <= 0;
- const style = window.getComputedStyle(element);
- if (noSize && !element.innerHTML) {
- return true;
- }
- return noSize && style.getPropertyValue("overflow") !== "visible" || style.getPropertyValue("display") === "none";
- });
- __publicField(this, "isVisible", (element) => {
- let parentElement = element;
- while (parentElement) {
- if (parentElement instanceof HTMLElement) {
- if (parentElement === document.body) {
- break;
- }
- if (this.isHidden(parentElement)) {
- return false;
- }
- parentElement = parentElement.parentNode;
- }
- }
- return true;
- });
- __publicField(this, "removeScope", () => {
- window.removeEventListener("keydown", this.handleKeyDown);
- });
- __publicField(this, "checkFocus", (target) => {
- if (document.activeElement !== target) {
- target.focus();
- window.requestAnimationFrame(() => this.checkFocus(target));
- }
- });
- __publicField(this, "setFocus", () => {
- const { selector } = this.options;
- if (!selector) {
- return;
- }
- const target = this.element.querySelector(selector);
- if (target) {
- window.requestAnimationFrame(() => this.checkFocus(target));
- }
- });
- if (!(element instanceof HTMLElement)) {
- throw new TypeError("Invalid parameter: element must be an HTMLElement");
- }
- this.element = element;
- this.options = options;
- window.addEventListener("keydown", this.handleKeyDown, false);
- this.setFocus();
- }
- };
- // src/components/Beacon.tsx
- import * as React from "react";
- import innerText from "react-innertext";
- import is4 from "is-lite";
- var JoyrideBeacon = class extends React.Component {
- constructor(props) {
- super(props);
- __publicField(this, "beacon", null);
- __publicField(this, "setBeaconRef", (c) => {
- this.beacon = c;
- });
- if (props.beaconComponent) {
- return;
- }
- const head = document.head || document.getElementsByTagName("head")[0];
- const style = document.createElement("style");
- style.id = "joyride-beacon-animation";
- if (props.nonce) {
- style.setAttribute("nonce", props.nonce);
- }
- const css = `
- @keyframes joyride-beacon-inner {
- 20% {
- opacity: 0.9;
- }
-
- 90% {
- opacity: 0.7;
- }
- }
-
- @keyframes joyride-beacon-outer {
- 0% {
- transform: scale(1);
- }
-
- 45% {
- opacity: 0.7;
- transform: scale(0.75);
- }
-
- 100% {
- opacity: 0.9;
- transform: scale(1);
- }
- }
- `;
- style.appendChild(document.createTextNode(css));
- head.appendChild(style);
- }
- componentDidMount() {
- const { shouldFocus } = this.props;
- if (process.env.NODE_ENV !== "production") {
- if (!is4.domElement(this.beacon)) {
- console.warn("beacon is not a valid DOM element");
- }
- }
- setTimeout(() => {
- if (is4.domElement(this.beacon) && shouldFocus) {
- this.beacon.focus();
- }
- }, 0);
- }
- componentWillUnmount() {
- const style = document.getElementById("joyride-beacon-animation");
- if (style == null ? void 0 : style.parentNode) {
- style.parentNode.removeChild(style);
- }
- }
- render() {
- const {
- beaconComponent,
- continuous,
- index,
- isLastStep,
- locale,
- onClickOrHover,
- size,
- step,
- styles
- } = this.props;
- const title = is4.string(locale.open) ? locale.open : innerText(locale.open);
- const sharedProps = {
- "aria-label": title,
- onClick: onClickOrHover,
- onMouseEnter: onClickOrHover,
- ref: this.setBeaconRef,
- title
- };
- let component;
- if (beaconComponent) {
- const BeaconComponent = beaconComponent;
- component = /* @__PURE__ */ React.createElement(
- BeaconComponent,
- {
- continuous,
- index,
- isLastStep,
- size,
- step,
- ...sharedProps
- }
- );
- } else {
- component = /* @__PURE__ */ React.createElement(
- "button",
- {
- key: "JoyrideBeacon",
- className: "react-joyride__beacon",
- "data-test-id": "button-beacon",
- style: styles.beacon,
- type: "button",
- ...sharedProps
- },
- /* @__PURE__ */ React.createElement("span", { style: styles.beaconInner }),
- /* @__PURE__ */ React.createElement("span", { style: styles.beaconOuter })
- );
- }
- return component;
- }
- };
- // src/components/Overlay.tsx
- import * as React3 from "react";
- import treeChanges from "tree-changes";
- // src/components/Spotlight.tsx
- import * as React2 from "react";
- function JoyrideSpotlight({ styles }) {
- return /* @__PURE__ */ React2.createElement(
- "div",
- {
- key: "JoyrideSpotlight",
- className: "react-joyride__spotlight",
- "data-test-id": "spotlight",
- style: styles
- }
- );
- }
- var Spotlight_default = JoyrideSpotlight;
- // src/components/Overlay.tsx
- var JoyrideOverlay = class extends React3.Component {
- constructor() {
- super(...arguments);
- __publicField(this, "isActive", false);
- __publicField(this, "resizeTimeout");
- __publicField(this, "scrollTimeout");
- __publicField(this, "scrollParent");
- __publicField(this, "state", {
- isScrolling: false,
- mouseOverSpotlight: false,
- showSpotlight: true
- });
- __publicField(this, "handleMouseMove", (event) => {
- const { mouseOverSpotlight } = this.state;
- const { height, left, position, top, width } = this.spotlightStyles;
- const offsetY = position === "fixed" ? event.clientY : event.pageY;
- const offsetX = position === "fixed" ? event.clientX : event.pageX;
- const inSpotlightHeight = offsetY >= top && offsetY <= top + height;
- const inSpotlightWidth = offsetX >= left && offsetX <= left + width;
- const inSpotlight = inSpotlightWidth && inSpotlightHeight;
- if (inSpotlight !== mouseOverSpotlight) {
- this.updateState({ mouseOverSpotlight: inSpotlight });
- }
- });
- __publicField(this, "handleScroll", () => {
- const { target } = this.props;
- const element = getElement(target);
- if (this.scrollParent !== document) {
- const { isScrolling } = this.state;
- if (!isScrolling) {
- this.updateState({ isScrolling: true, showSpotlight: false });
- }
- clearTimeout(this.scrollTimeout);
- this.scrollTimeout = window.setTimeout(() => {
- this.updateState({ isScrolling: false, showSpotlight: true });
- }, 50);
- } else if (hasPosition(element, "sticky")) {
- this.updateState({});
- }
- });
- __publicField(this, "handleResize", () => {
- clearTimeout(this.resizeTimeout);
- this.resizeTimeout = window.setTimeout(() => {
- if (!this.isActive) {
- return;
- }
- this.forceUpdate();
- }, 100);
- });
- }
- componentDidMount() {
- const { debug, disableScrolling, disableScrollParentFix = false, target } = this.props;
- const element = getElement(target);
- this.scrollParent = getScrollParent(element != null ? element : document.body, disableScrollParentFix, true);
- this.isActive = true;
- if (process.env.NODE_ENV !== "production") {
- if (!disableScrolling && hasCustomScrollParent(element, true)) {
- log({
- title: "step has a custom scroll parent and can cause trouble with scrolling",
- data: [{ key: "parent", value: this.scrollParent }],
- debug
- });
- }
- }
- window.addEventListener("resize", this.handleResize);
- }
- componentDidUpdate(previousProps) {
- var _a;
- const { lifecycle, spotlightClicks } = this.props;
- const { changed } = treeChanges(previousProps, this.props);
- if (changed("lifecycle", LIFECYCLE.TOOLTIP)) {
- (_a = this.scrollParent) == null ? void 0 : _a.addEventListener("scroll", this.handleScroll, { passive: true });
- setTimeout(() => {
- const { isScrolling } = this.state;
- if (!isScrolling) {
- this.updateState({ showSpotlight: true });
- }
- }, 100);
- }
- if (changed("spotlightClicks") || changed("disableOverlay") || changed("lifecycle")) {
- if (spotlightClicks && lifecycle === LIFECYCLE.TOOLTIP) {
- window.addEventListener("mousemove", this.handleMouseMove, false);
- } else if (lifecycle !== LIFECYCLE.TOOLTIP) {
- window.removeEventListener("mousemove", this.handleMouseMove);
- }
- }
- }
- componentWillUnmount() {
- var _a;
- this.isActive = false;
- window.removeEventListener("mousemove", this.handleMouseMove);
- window.removeEventListener("resize", this.handleResize);
- clearTimeout(this.resizeTimeout);
- clearTimeout(this.scrollTimeout);
- (_a = this.scrollParent) == null ? void 0 : _a.removeEventListener("scroll", this.handleScroll);
- }
- get spotlightStyles() {
- var _a, _b, _c;
- const { showSpotlight } = this.state;
- const {
- disableScrollParentFix = false,
- spotlightClicks,
- spotlightPadding = 0,
- styles,
- target
- } = this.props;
- const element = getElement(target);
- const elementRect = getClientRect(element);
- const isFixedTarget = hasPosition(element);
- const top = getElementPosition(element, spotlightPadding, disableScrollParentFix);
- return {
- ...isLegacy() ? styles.spotlightLegacy : styles.spotlight,
- height: Math.round(((_a = elementRect == null ? void 0 : elementRect.height) != null ? _a : 0) + spotlightPadding * 2),
- left: Math.round(((_b = elementRect == null ? void 0 : elementRect.left) != null ? _b : 0) - spotlightPadding),
- opacity: showSpotlight ? 1 : 0,
- pointerEvents: spotlightClicks ? "none" : "auto",
- position: isFixedTarget ? "fixed" : "absolute",
- top,
- transition: "opacity 0.2s",
- width: Math.round(((_c = elementRect == null ? void 0 : elementRect.width) != null ? _c : 0) + spotlightPadding * 2)
- };
- }
- updateState(state) {
- if (!this.isActive) {
- return;
- }
- this.setState((previousState) => ({ ...previousState, ...state }));
- }
- render() {
- const { mouseOverSpotlight, showSpotlight } = this.state;
- const { disableOverlay, disableOverlayClose, lifecycle, onClickOverlay, placement, styles } = this.props;
- if (disableOverlay || lifecycle !== LIFECYCLE.TOOLTIP) {
- return null;
- }
- let baseStyles = styles.overlay;
- if (isLegacy()) {
- baseStyles = placement === "center" ? styles.overlayLegacyCenter : styles.overlayLegacy;
- }
- const stylesOverlay = {
- cursor: disableOverlayClose ? "default" : "pointer",
- height: getDocumentHeight(),
- pointerEvents: mouseOverSpotlight ? "none" : "auto",
- ...baseStyles
- };
- let spotlight2 = placement !== "center" && showSpotlight && /* @__PURE__ */ React3.createElement(Spotlight_default, { styles: this.spotlightStyles });
- if (getBrowser() === "safari") {
- const { mixBlendMode, zIndex, ...safarOverlay } = stylesOverlay;
- spotlight2 = /* @__PURE__ */ React3.createElement("div", { style: { ...safarOverlay } }, spotlight2);
- delete stylesOverlay.backgroundColor;
- }
- return /* @__PURE__ */ React3.createElement(
- "div",
- {
- className: "react-joyride__overlay",
- "data-test-id": "overlay",
- onClick: onClickOverlay,
- role: "presentation",
- style: stylesOverlay
- },
- spotlight2
- );
- }
- };
- // src/components/Portal.tsx
- import * as React4 from "react";
- import * as ReactDOM from "react-dom";
- var JoyridePortal = class extends React4.Component {
- constructor() {
- super(...arguments);
- __publicField(this, "node", null);
- }
- componentDidMount() {
- const { id } = this.props;
- if (!canUseDOM()) {
- return;
- }
- this.node = document.createElement("div");
- this.node.id = id;
- document.body.appendChild(this.node);
- if (!isReact16) {
- this.renderReact15();
- }
- }
- componentDidUpdate() {
- if (!canUseDOM()) {
- return;
- }
- if (!isReact16) {
- this.renderReact15();
- }
- }
- componentWillUnmount() {
- if (!canUseDOM() || !this.node) {
- return;
- }
- if (!isReact16) {
- ReactDOM.unmountComponentAtNode(this.node);
- }
- if (this.node.parentNode === document.body) {
- document.body.removeChild(this.node);
- this.node = null;
- }
- }
- renderReact15() {
- if (!canUseDOM()) {
- return;
- }
- const { children } = this.props;
- if (this.node) {
- ReactDOM.unstable_renderSubtreeIntoContainer(this, children, this.node);
- }
- }
- renderReact16() {
- if (!canUseDOM() || !isReact16) {
- return null;
- }
- const { children } = this.props;
- if (!this.node) {
- return null;
- }
- return ReactDOM.createPortal(children, this.node);
- }
- render() {
- if (!isReact16) {
- return null;
- }
- return this.renderReact16();
- }
- };
- // src/components/Tooltip/index.tsx
- import * as React7 from "react";
- // src/components/Tooltip/Container.tsx
- import * as React6 from "react";
- // src/components/Tooltip/CloseButton.tsx
- import React5 from "react";
- function JoyrideTooltipCloseButton({ styles, ...props }) {
- const { color, height, width, ...style } = styles;
- return /* @__PURE__ */ React5.createElement("button", { style, type: "button", ...props }, /* @__PURE__ */ React5.createElement(
- "svg",
- {
- height: typeof height === "number" ? `${height}px` : height,
- preserveAspectRatio: "xMidYMid",
- version: "1.1",
- viewBox: "0 0 18 18",
- width: typeof width === "number" ? `${width}px` : width,
- xmlns: "http://www.w3.org/2000/svg"
- },
- /* @__PURE__ */ React5.createElement("g", null, /* @__PURE__ */ React5.createElement(
- "path",
- {
- d: "M8.13911129,9.00268191 L0.171521827,17.0258467 C-0.0498027049,17.248715 -0.0498027049,17.6098394 0.171521827,17.8327545 C0.28204354,17.9443526 0.427188206,17.9998706 0.572051765,17.9998706 C0.71714958,17.9998706 0.862013139,17.9443526 0.972581703,17.8327545 L9.0000937,9.74924618 L17.0276057,17.8327545 C17.1384085,17.9443526 17.2832721,17.9998706 17.4281356,17.9998706 C17.5729992,17.9998706 17.718097,17.9443526 17.8286656,17.8327545 C18.0499901,17.6098862 18.0499901,17.2487618 17.8286656,17.0258467 L9.86135722,9.00268191 L17.8340066,0.973848225 C18.0553311,0.750979934 18.0553311,0.389855532 17.8340066,0.16694039 C17.6126821,-0.0556467968 17.254037,-0.0556467968 17.0329467,0.16694039 L9.00042166,8.25611765 L0.967006424,0.167268345 C0.745681892,-0.0553188426 0.387317931,-0.0553188426 0.165993399,0.167268345 C-0.0553311331,0.390136635 -0.0553311331,0.751261038 0.165993399,0.974176179 L8.13920499,9.00268191 L8.13911129,9.00268191 Z",
- fill: color
- }
- ))
- ));
- }
- var CloseButton_default = JoyrideTooltipCloseButton;
- // src/components/Tooltip/Container.tsx
- function JoyrideTooltipContainer(props) {
- const {
- backProps,
- closeProps,
- continuous,
- index,
- isLastStep,
- primaryProps,
- size,
- skipProps,
- step,
- tooltipProps
- } = props;
- const {
- content,
- hideBackButton,
- hideCloseButton,
- hideFooter,
- locale,
- showProgress,
- showSkipButton,
- styles,
- title
- } = step;
- const { back, close, last, next, skip } = locale;
- const output = {
- primary: close
- };
- if (continuous) {
- output.primary = isLastStep ? last : next;
- if (showProgress) {
- output.primary = /* @__PURE__ */ React6.createElement("span", null, output.primary, " (", index + 1, "/", size, ")");
- }
- }
- if (showSkipButton && !isLastStep) {
- output.skip = /* @__PURE__ */ React6.createElement(
- "button",
- {
- "aria-live": "off",
- "data-test-id": "button-skip",
- style: styles.buttonSkip,
- type: "button",
- ...skipProps
- },
- skip
- );
- }
- if (!hideBackButton && index > 0) {
- output.back = /* @__PURE__ */ React6.createElement("button", { "data-test-id": "button-back", style: styles.buttonBack, type: "button", ...backProps }, back);
- }
- output.close = !hideCloseButton && /* @__PURE__ */ React6.createElement(CloseButton_default, { "data-test-id": "button-close", styles: styles.buttonClose, ...closeProps });
- return /* @__PURE__ */ React6.createElement(
- "div",
- {
- key: "JoyrideTooltip",
- "aria-label": getText(title) || getText(content),
- className: "react-joyride__tooltip",
- style: styles.tooltip,
- ...tooltipProps
- },
- /* @__PURE__ */ React6.createElement("div", { style: styles.tooltipContainer }, title && /* @__PURE__ */ React6.createElement("h1", { "aria-label": getText(title), style: styles.tooltipTitle }, title), /* @__PURE__ */ React6.createElement("div", { style: styles.tooltipContent }, content)),
- !hideFooter && /* @__PURE__ */ React6.createElement("div", { style: styles.tooltipFooter }, /* @__PURE__ */ React6.createElement("div", { style: styles.tooltipFooterSpacer }, output.skip), output.back, /* @__PURE__ */ React6.createElement(
- "button",
- {
- "data-test-id": "button-primary",
- style: styles.buttonNext,
- type: "button",
- ...primaryProps
- },
- output.primary
- )),
- output.close
- );
- }
- var Container_default = JoyrideTooltipContainer;
- // src/components/Tooltip/index.tsx
- var JoyrideTooltip = class extends React7.Component {
- constructor() {
- super(...arguments);
- __publicField(this, "handleClickBack", (event) => {
- event.preventDefault();
- const { helpers } = this.props;
- helpers.prev();
- });
- __publicField(this, "handleClickClose", (event) => {
- event.preventDefault();
- const { helpers } = this.props;
- helpers.close();
- });
- __publicField(this, "handleClickPrimary", (event) => {
- event.preventDefault();
- const { continuous, helpers } = this.props;
- if (!continuous) {
- helpers.close();
- return;
- }
- helpers.next();
- });
- __publicField(this, "handleClickSkip", (event) => {
- event.preventDefault();
- const { helpers } = this.props;
- helpers.skip();
- });
- __publicField(this, "getElementsProps", () => {
- const { continuous, isLastStep, setTooltipRef, step } = this.props;
- const back = getText(step.locale.back);
- const close = getText(step.locale.close);
- const last = getText(step.locale.last);
- const next = getText(step.locale.next);
- const skip = getText(step.locale.skip);
- let primaryText = continuous ? next : close;
- if (isLastStep) {
- primaryText = last;
- }
- return {
- backProps: {
- "aria-label": back,
- "data-action": "back",
- onClick: this.handleClickBack,
- role: "button",
- title: back
- },
- closeProps: {
- "aria-label": close,
- "data-action": "close",
- onClick: this.handleClickClose,
- role: "button",
- title: close
- },
- primaryProps: {
- "aria-label": primaryText,
- "data-action": "primary",
- onClick: this.handleClickPrimary,
- role: "button",
- title: primaryText
- },
- skipProps: {
- "aria-label": skip,
- "data-action": "skip",
- onClick: this.handleClickSkip,
- role: "button",
- title: skip
- },
- tooltipProps: {
- "aria-modal": true,
- ref: setTooltipRef,
- role: "alertdialog"
- }
- };
- });
- }
- render() {
- const { continuous, index, isLastStep, setTooltipRef, size, step } = this.props;
- const { beaconComponent, tooltipComponent, ...cleanStep } = step;
- let component;
- if (tooltipComponent) {
- const renderProps = {
- ...this.getElementsProps(),
- continuous,
- index,
- isLastStep,
- size,
- step: cleanStep,
- setTooltipRef
- };
- const TooltipComponent = tooltipComponent;
- component = /* @__PURE__ */ React7.createElement(TooltipComponent, { ...renderProps });
- } else {
- component = /* @__PURE__ */ React7.createElement(
- Container_default,
- {
- ...this.getElementsProps(),
- continuous,
- index,
- isLastStep,
- size,
- step
- }
- );
- }
- return component;
- }
- };
- // src/components/Step.tsx
- var JoyrideStep = class extends React8.Component {
- constructor() {
- super(...arguments);
- __publicField(this, "scope", null);
- __publicField(this, "tooltip", null);
- /**
- * Beacon click/hover event listener
- */
- __publicField(this, "handleClickHoverBeacon", (event) => {
- const { step, store } = this.props;
- if (event.type === "mouseenter" && step.event !== "hover") {
- return;
- }
- store.update({ lifecycle: LIFECYCLE.TOOLTIP });
- });
- __publicField(this, "handleClickOverlay", () => {
- const { helpers, step } = this.props;
- if (!step.disableOverlayClose) {
- helpers.close();
- }
- });
- __publicField(this, "setTooltipRef", (element) => {
- this.tooltip = element;
- });
- __publicField(this, "setPopper", (popper, type) => {
- var _a;
- const { action, step, store } = this.props;
- if (type === "wrapper") {
- store.setPopper("beacon", popper);
- } else {
- store.setPopper("tooltip", popper);
- }
- if (store.getPopper("beacon") && store.getPopper("tooltip")) {
- store.update({
- action,
- lifecycle: LIFECYCLE.READY
- });
- }
- if ((_a = step.floaterProps) == null ? void 0 : _a.getPopper) {
- step.floaterProps.getPopper(popper, type);
- }
- });
- __publicField(this, "renderTooltip", (renderProps) => {
- const { continuous, helpers, index, size, step } = this.props;
- return /* @__PURE__ */ React8.createElement(
- JoyrideTooltip,
- {
- continuous,
- helpers,
- index,
- isLastStep: index + 1 === size,
- setTooltipRef: this.setTooltipRef,
- size,
- step,
- ...renderProps
- }
- );
- });
- }
- componentDidMount() {
- const { debug, index } = this.props;
- log({
- title: `step:${index}`,
- data: [{ key: "props", value: this.props }],
- debug
- });
- }
- componentDidUpdate(previousProps) {
- var _a;
- const {
- action,
- callback,
- continuous,
- controlled,
- debug,
- index,
- lifecycle,
- size,
- status,
- step,
- store
- } = this.props;
- const { changed, changedFrom } = treeChanges2(previousProps, this.props);
- const state = { action, controlled, index, lifecycle, size, status };
- const skipBeacon = continuous && action !== ACTIONS.CLOSE && (index > 0 || action === ACTIONS.PREV);
- const hasStoreChanged = changed("action") || changed("index") || changed("lifecycle") || changed("status");
- const isInitial = changedFrom("lifecycle", [LIFECYCLE.TOOLTIP, LIFECYCLE.INIT], LIFECYCLE.INIT);
- const isAfterAction = changed("action", [
- ACTIONS.NEXT,
- ACTIONS.PREV,
- ACTIONS.SKIP,
- ACTIONS.CLOSE
- ]);
- const isControlled = controlled && index === previousProps.index;
- if (isAfterAction && (isInitial || isControlled)) {
- callback({
- ...state,
- index: previousProps.index,
- lifecycle: LIFECYCLE.COMPLETE,
- step: previousProps.step,
- type: EVENTS.STEP_AFTER
- });
- }
- if (step.placement === "center" && status === STATUS.RUNNING && changed("index") && action !== ACTIONS.START && lifecycle === LIFECYCLE.INIT) {
- store.update({ lifecycle: LIFECYCLE.READY });
- }
- if (hasStoreChanged) {
- const element = getElement(step.target);
- const elementExists = !!element;
- const hasRenderedTarget = elementExists && isElementVisible(element);
- if (hasRenderedTarget) {
- if (changedFrom("status", STATUS.READY, STATUS.RUNNING) || changedFrom("lifecycle", LIFECYCLE.INIT, LIFECYCLE.READY)) {
- callback({
- ...state,
- step,
- type: EVENTS.STEP_BEFORE
- });
- }
- } else {
- console.warn(elementExists ? "Target not visible" : "Target not mounted", step);
- callback({
- ...state,
- type: EVENTS.TARGET_NOT_FOUND,
- step
- });
- if (!controlled) {
- store.update({ index: index + (action === ACTIONS.PREV ? -1 : 1) });
- }
- }
- }
- if (changedFrom("lifecycle", LIFECYCLE.INIT, LIFECYCLE.READY)) {
- store.update({
- lifecycle: hideBeacon(step) || skipBeacon ? LIFECYCLE.TOOLTIP : LIFECYCLE.BEACON
- });
- }
- if (changed("index")) {
- log({
- title: `step:${lifecycle}`,
- data: [{ key: "props", value: this.props }],
- debug
- });
- }
- if (changed("lifecycle", LIFECYCLE.BEACON)) {
- callback({
- ...state,
- step,
- type: EVENTS.BEACON
- });
- }
- if (changed("lifecycle", LIFECYCLE.TOOLTIP)) {
- callback({
- ...state,
- step,
- type: EVENTS.TOOLTIP
- });
- if (this.tooltip) {
- this.scope = new Scope(this.tooltip, { selector: "[data-action=primary]" });
- this.scope.setFocus();
- }
- }
- if (changedFrom("lifecycle", [LIFECYCLE.TOOLTIP, LIFECYCLE.INIT], LIFECYCLE.INIT)) {
- (_a = this.scope) == null ? void 0 : _a.removeScope();
- store.cleanupPoppers();
- }
- }
- componentWillUnmount() {
- var _a;
- (_a = this.scope) == null ? void 0 : _a.removeScope();
- }
- get open() {
- const { lifecycle, step } = this.props;
- return hideBeacon(step) || lifecycle === LIFECYCLE.TOOLTIP;
- }
- render() {
- const { continuous, debug, index, lifecycle, nonce, shouldScroll: shouldScroll2, size, step } = this.props;
- const target = getElement(step.target);
- if (!validateStep(step) || !is5.domElement(target)) {
- return null;
- }
- return /* @__PURE__ */ React8.createElement("div", { key: `JoyrideStep-${index}`, className: "react-joyride__step" }, /* @__PURE__ */ React8.createElement(JoyridePortal, { id: "react-joyride-portal" }, /* @__PURE__ */ React8.createElement(
- JoyrideOverlay,
- {
- ...step,
- debug,
- lifecycle,
- onClickOverlay: this.handleClickOverlay
- }
- )), /* @__PURE__ */ React8.createElement(
- Floater,
- {
- ...step.floaterProps,
- component: this.renderTooltip,
- debug,
- getPopper: this.setPopper,
- id: `react-joyride-step-${index}`,
- open: this.open,
- placement: step.placement,
- target: step.target
- },
- /* @__PURE__ */ React8.createElement(
- JoyrideBeacon,
- {
- beaconComponent: step.beaconComponent,
- continuous,
- index,
- isLastStep: index + 1 === size,
- locale: step.locale,
- nonce,
- onClickOrHover: this.handleClickHoverBeacon,
- shouldFocus: shouldScroll2,
- size,
- step,
- styles: step.styles
- }
- )
- ));
- }
- };
- // src/components/index.tsx
- var Joyride = class extends React9.Component {
- constructor(props) {
- super(props);
- __publicField(this, "helpers");
- __publicField(this, "store");
- /**
- * Trigger the callback.
- */
- __publicField(this, "callback", (data) => {
- const { callback } = this.props;
- if (is6.function(callback)) {
- callback(data);
- }
- });
- /**
- * Keydown event listener
- */
- __publicField(this, "handleKeyboard", (event) => {
- const { index, lifecycle } = this.state;
- const { steps } = this.props;
- const step = steps[index];
- if (lifecycle === LIFECYCLE.TOOLTIP) {
- if (event.code === "Escape" && step && !step.disableCloseOnEsc) {
- this.store.close();
- }
- }
- });
- /**
- * Sync the store with the component's state
- */
- __publicField(this, "syncState", (state) => {
- this.setState(state);
- });
- const { debug, getHelpers, run, stepIndex } = props;
- this.store = createStore({
- ...props,
- controlled: run && is6.number(stepIndex)
- });
- this.helpers = this.store.getHelpers();
- const { addListener } = this.store;
- log({
- title: "init",
- data: [
- { key: "props", value: this.props },
- { key: "state", value: this.state }
- ],
- debug
- });
- addListener(this.syncState);
- if (getHelpers) {
- getHelpers(this.helpers);
- }
- this.state = this.store.getState();
- }
- componentDidMount() {
- if (!canUseDOM()) {
- return;
- }
- const { debug, disableCloseOnEsc, run, steps } = this.props;
- const { start } = this.store;
- if (validateSteps(steps, debug) && run) {
- start();
- }
- if (!disableCloseOnEsc) {
- document.body.addEventListener("keydown", this.handleKeyboard, { passive: true });
- }
- }
- componentDidUpdate(previousProps, previousState) {
- if (!canUseDOM()) {
- return;
- }
- const { action, controlled, index, lifecycle, status } = this.state;
- const { debug, run, stepIndex, steps } = this.props;
- const { stepIndex: previousStepIndex, steps: previousSteps } = previousProps;
- const { reset, setSteps, start, stop, update } = this.store;
- const { changed: changedProps } = treeChanges3(previousProps, this.props);
- const { changed, changedFrom } = treeChanges3(previousState, this.state);
- const step = getMergedStep(steps[index], this.props);
- const stepsChanged = !isEqual(previousSteps, steps);
- const stepIndexChanged = is6.number(stepIndex) && changedProps("stepIndex");
- const target = getElement(step.target);
- if (stepsChanged) {
- if (validateSteps(steps, debug)) {
- setSteps(steps);
- } else {
- console.warn("Steps are not valid", steps);
- }
- }
- if (changedProps("run")) {
- if (run) {
- start(stepIndex);
- } else {
- stop();
- }
- }
- if (stepIndexChanged) {
- let nextAction = is6.number(previousStepIndex) && previousStepIndex < stepIndex ? ACTIONS.NEXT : ACTIONS.PREV;
- if (action === ACTIONS.STOP) {
- nextAction = ACTIONS.START;
- }
- if (![STATUS.FINISHED, STATUS.SKIPPED].includes(status)) {
- update({
- action: action === ACTIONS.CLOSE ? ACTIONS.CLOSE : nextAction,
- index: stepIndex,
- lifecycle: LIFECYCLE.INIT
- });
- }
- }
- if (!controlled && status === STATUS.RUNNING && index === 0 && !target) {
- this.store.update({ index: index + 1 });
- this.callback({
- ...this.state,
- type: EVENTS.TARGET_NOT_FOUND,
- step
- });
- }
- const callbackData = {
- ...this.state,
- index,
- step
- };
- const isAfterAction = changed("action", [
- ACTIONS.NEXT,
- ACTIONS.PREV,
- ACTIONS.SKIP,
- ACTIONS.CLOSE
- ]);
- if (isAfterAction && changed("status", STATUS.PAUSED)) {
- const previousStep = getMergedStep(steps[previousState.index], this.props);
- this.callback({
- ...callbackData,
- index: previousState.index,
- lifecycle: LIFECYCLE.COMPLETE,
- step: previousStep,
- type: EVENTS.STEP_AFTER
- });
- }
- if (changed("status", [STATUS.FINISHED, STATUS.SKIPPED])) {
- const previousStep = getMergedStep(steps[previousState.index], this.props);
- if (!controlled) {
- this.callback({
- ...callbackData,
- index: previousState.index,
- lifecycle: LIFECYCLE.COMPLETE,
- step: previousStep,
- type: EVENTS.STEP_AFTER
- });
- }
- this.callback({
- ...callbackData,
- type: EVENTS.TOUR_END,
- // Return the last step when the tour is finished
- step: previousStep,
- index: previousState.index
- });
- reset();
- } else if (changedFrom("status", [STATUS.IDLE, STATUS.READY], STATUS.RUNNING)) {
- this.callback({
- ...callbackData,
- type: EVENTS.TOUR_START
- });
- } else if (changed("status") || changed("action", ACTIONS.RESET)) {
- this.callback({
- ...callbackData,
- type: EVENTS.TOUR_STATUS
- });
- }
- this.scrollToStep(previousState);
- if (step.placement === "center" && status === STATUS.RUNNING && lifecycle === LIFECYCLE.INIT) {
- this.store.update({ lifecycle: LIFECYCLE.READY });
- }
- }
- componentWillUnmount() {
- const { disableCloseOnEsc } = this.props;
- if (!disableCloseOnEsc) {
- document.body.removeEventListener("keydown", this.handleKeyboard);
- }
- }
- scrollToStep(previousState) {
- const { index, lifecycle, status } = this.state;
- const {
- debug,
- disableScrollParentFix = false,
- scrollDuration,
- scrollOffset = 20,
- scrollToFirstStep = false,
- steps
- } = this.props;
- const step = getMergedStep(steps[index], this.props);
- const target = getElement(step.target);
- const shouldScrollToStep = shouldScroll({
- isFirstStep: index === 0,
- lifecycle,
- previousLifecycle: previousState.lifecycle,
- scrollToFirstStep,
- step,
- target
- });
- if (status === STATUS.RUNNING && shouldScrollToStep) {
- const hasCustomScroll = hasCustomScrollParent(target, disableScrollParentFix);
- const scrollParent2 = getScrollParent(target, disableScrollParentFix);
- let scrollY = Math.floor(getScrollTo(target, scrollOffset, disableScrollParentFix)) || 0;
- log({
- title: "scrollToStep",
- data: [
- { key: "index", value: index },
- { key: "lifecycle", value: lifecycle },
- { key: "status", value: status }
- ],
- debug
- });
- const beaconPopper = this.store.getPopper("beacon");
- const tooltipPopper = this.store.getPopper("tooltip");
- if (lifecycle === LIFECYCLE.BEACON && beaconPopper) {
- const { offsets, placement } = beaconPopper;
- if (!["bottom"].includes(placement) && !hasCustomScroll) {
- scrollY = Math.floor(offsets.popper.top - scrollOffset);
- }
- } else if (lifecycle === LIFECYCLE.TOOLTIP && tooltipPopper) {
- const { flipped, offsets, placement } = tooltipPopper;
- if (["top", "right", "left"].includes(placement) && !flipped && !hasCustomScroll) {
- scrollY = Math.floor(offsets.popper.top - scrollOffset);
- } else {
- scrollY -= step.spotlightPadding;
- }
- }
- scrollY = scrollY >= 0 ? scrollY : 0;
- if (status === STATUS.RUNNING) {
- scrollTo(scrollY, { element: scrollParent2, duration: scrollDuration }).then(
- () => {
- setTimeout(() => {
- var _a;
- (_a = this.store.getPopper("tooltip")) == null ? void 0 : _a.instance.update();
- }, 10);
- }
- );
- }
- }
- }
- render() {
- if (!canUseDOM()) {
- return null;
- }
- const { index, status } = this.state;
- const {
- continuous = false,
- debug = false,
- nonce,
- scrollToFirstStep = false,
- steps
- } = this.props;
- let output;
- if (status === STATUS.RUNNING && steps[index]) {
- const step = getMergedStep(steps[index], this.props);
- output = /* @__PURE__ */ React9.createElement(
- JoyrideStep,
- {
- ...this.state,
- callback: this.callback,
- continuous,
- debug,
- helpers: this.helpers,
- nonce,
- shouldScroll: !step.disableScrolling && (index !== 0 || scrollToFirstStep),
- step,
- store: this.store
- }
- );
- }
- return /* @__PURE__ */ React9.createElement("div", { className: "react-joyride" }, output);
- }
- };
- __publicField(Joyride, "defaultProps", defaultProps);
- var components_default = Joyride;
- export {
- ACTIONS,
- EVENTS,
- LIFECYCLE,
- STATUS,
- components_default as default
- };
- //# sourceMappingURL=index.mjs.map
|