@stack-spot/portal-components 1.0.0 → 1.0.1
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/dist/components/Breadcrumb/styled.d.ts +1 -1
- package/dist/components/Breadcrumb/styled.d.ts.map +1 -1
- package/dist/components/Breadcrumb/styled.js +1 -0
- package/dist/components/Breadcrumb/styled.js.map +1 -1
- package/dist/components/Tour/utils.d.ts +1 -0
- package/dist/components/Tour/utils.d.ts.map +1 -1
- package/dist/components/Tour/utils.js +8 -2
- package/dist/components/Tour/utils.js.map +1 -1
- package/dist/utils/cookie.d.ts +2 -1
- package/dist/utils/cookie.d.ts.map +1 -1
- package/dist/utils/cookie.js +7 -5
- package/dist/utils/cookie.js.map +1 -1
- package/package.json +9 -8
- package/src/components/Breadcrumb/styled.ts +2 -1
- package/src/components/Tour/utils.tsx +9 -2
- package/src/utils/cookie.ts +8 -5
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
export declare const Box:
|
|
2
|
+
export declare const Box: React.FC<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
3
3
|
//# sourceMappingURL=styled.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled.d.ts","sourceRoot":"","sources":["../../../src/components/Breadcrumb/styled.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"styled.d.ts","sourceRoot":"","sources":["../../../src/components/Breadcrumb/styled.ts"],"names":[],"mappings":";AAKA,eAAO,MAAM,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,CA+BjG,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getFontAppearance } from '@citric/core/dist/utils/theme.js';
|
|
2
2
|
import { theme } from '@stack-spot/portal-theme';
|
|
3
3
|
import { styled } from 'styled-components';
|
|
4
|
+
// the type below should be inferred, but a bug in TS+PNPM prevents it: https://github.com/microsoft/TypeScript/issues/42873
|
|
4
5
|
export const Box = styled.nav `
|
|
5
6
|
margin-bottom: 24px;
|
|
6
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled.js","sourceRoot":"","sources":["../../../src/components/Breadcrumb/styled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,MAAM,CAAC,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"styled.js","sourceRoot":"","sources":["../../../src/components/Breadcrumb/styled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,4HAA4H;AAC5H,MAAM,CAAC,MAAM,GAAG,GAAsF,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;cAclG,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,iBAAiB,CAAC,KAAY,EAAE,YAAY,CAAQ;;eAElE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;;;;;;;;;aAS1B,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;;;eAGtB,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,YAAY;;;CAG5C,CAAA"}
|
|
@@ -18,6 +18,7 @@ export declare const isNewTourStep: (step: ReactourStep) => boolean;
|
|
|
18
18
|
* Tutorial: verifies if the key passed as parameter refers to a React Tour step that has already finished.
|
|
19
19
|
*
|
|
20
20
|
* The key refers to a finished step if the array stored as a cookie includes it.
|
|
21
|
+
* If the cookie is set to 'disabled', then the step will be considered finished.Particularly useful in scenarios like e2e tests.
|
|
21
22
|
* @param key the step's identifier to check.
|
|
22
23
|
* @returns true if the key refers to a finished step. False otherwise.
|
|
23
24
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/Tour/utils.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAGvC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/Tour/utils.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAGvC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAYlD;;;GAGG;AACH,eAAO,MAAM,cAAc,QAAS,MAAM,SAIzC,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,SAAU,YAAY,YAA6C,CAAA;AAE7F;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,QAAS,MAAM,YAG9C,CAAA;AAED,UAAU,iBAAkB,SAAQ,YAAY;IAC9C;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,OAAO,EAAE,SAAS,CAAC;IACnB;;OAEG;IACH,gBAAgB,CAAC,EAAE,eAAe,CAAC;CACpC;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,6EAQzB,iBAAiB,KAAG,YAkBrB,CAAA"}
|
|
@@ -3,6 +3,8 @@ import { theme } from '@stack-spot/portal-theme';
|
|
|
3
3
|
import { getCookie, setCookie } from '../../utils/cookie.js';
|
|
4
4
|
import { StepContainer } from './StepContainer.js';
|
|
5
5
|
const TOUR_COOKIE = 'guided-tour-global';
|
|
6
|
+
const defaultExpires = new Date();
|
|
7
|
+
defaultExpires.setFullYear(new Date().getFullYear() + 1);
|
|
6
8
|
const getTourCookie = () => {
|
|
7
9
|
const currentTourObject = getCookie(TOUR_COOKIE);
|
|
8
10
|
return currentTourObject ? currentTourObject.split(',') : [];
|
|
@@ -15,7 +17,7 @@ export const finishTourStep = (key) => {
|
|
|
15
17
|
const finishedTours = getTourCookie();
|
|
16
18
|
if (!finishedTours.includes(key))
|
|
17
19
|
finishedTours.push(key);
|
|
18
|
-
setCookie(TOUR_COOKIE, finishedTours.toString());
|
|
20
|
+
setCookie(TOUR_COOKIE, finishedTours.toString(), { expires: defaultExpires.toUTCString() });
|
|
19
21
|
};
|
|
20
22
|
/**
|
|
21
23
|
* Tutorial: verifies if the React Tour step has not finished yet.
|
|
@@ -29,10 +31,14 @@ export const isNewTourStep = (step) => !hasFinishedTourStep(`${step.selector}`);
|
|
|
29
31
|
* Tutorial: verifies if the key passed as parameter refers to a React Tour step that has already finished.
|
|
30
32
|
*
|
|
31
33
|
* The key refers to a finished step if the array stored as a cookie includes it.
|
|
34
|
+
* If the cookie is set to 'disabled', then the step will be considered finished.Particularly useful in scenarios like e2e tests.
|
|
32
35
|
* @param key the step's identifier to check.
|
|
33
36
|
* @returns true if the key refers to a finished step. False otherwise.
|
|
34
37
|
*/
|
|
35
|
-
export const hasFinishedTourStep = (key) =>
|
|
38
|
+
export const hasFinishedTourStep = (key) => {
|
|
39
|
+
const tourCookie = getTourCookie();
|
|
40
|
+
return tourCookie.includes(key) || tourCookie[0] === 'disabled';
|
|
41
|
+
};
|
|
36
42
|
/**
|
|
37
43
|
* Tutorial: utility for building a React Tour step. This already includes some default configuration for tours in Stackspot.
|
|
38
44
|
* @param options the options for building the step: {@link StackspotTourStep}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/Tour/utils.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AAGhD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,EAAyB,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAGtE,MAAM,WAAW,GAAG,oBAAoB,CAAA;AAExC,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,MAAM,iBAAiB,GAAG,SAAS,CAAC,WAAW,CAAC,CAAA;IAChD,OAAO,iBAAiB,CAAC,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;AAC9D,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAE,EAAE;IAC5C,MAAM,aAAa,GAAa,aAAa,EAAE,CAAA;IAC/C,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACzD,SAAS,CAAC,WAAW,EAAE,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/Tour/utils.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AAGhD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,EAAyB,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAGtE,MAAM,WAAW,GAAG,oBAAoB,CAAA;AAExC,MAAM,cAAc,GAAG,IAAI,IAAI,EAAE,CAAA;AACjC,cAAc,CAAC,WAAW,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAA;AAExD,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,MAAM,iB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,EAAE,gBAAgB,YACjC,OAAO,GACM,CAAC;IACjB,QAAQ;IACR,KAAK,EAAE;QACL,eAAe,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QACzC,KAAK,EAAE,OAAO;QACd,OAAO,EAAE,CAAC;QACV,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAiC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG;QACjF,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;KACjB;IACD,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;CAChB,CAAC,CAAA"}
|
package/dist/utils/cookie.d.ts
CHANGED
|
@@ -17,8 +17,9 @@ export declare function getCookies(): Record<string, string | undefined>;
|
|
|
17
17
|
* Sets the value of a cookie.
|
|
18
18
|
* @param key the cookie name (identifier).
|
|
19
19
|
* @param value the cookie value.
|
|
20
|
+
* @param customAttributes Accepted values: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes.
|
|
20
21
|
*/
|
|
21
|
-
export declare function setCookie(key: string, value: string): void;
|
|
22
|
+
export declare function setCookie(key: string, value: string, customAttributes?: Record<string, string>): void;
|
|
22
23
|
/**
|
|
23
24
|
* Removes a cookie.
|
|
24
25
|
* @param key the cookie name (identifier).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../src/utils/cookie.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,QAI/C;AAED;;;GAGG;AACH,wBAAgB,eAAe,WAG9B;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAO/D;AAED
|
|
1
|
+
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../src/utils/cookie.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,QAI/C;AAED;;;GAGG;AACH,wBAAgB,eAAe,WAG9B;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAO/D;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,QAGlG;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,QAGvC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,sBAEpC"}
|
package/dist/utils/cookie.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const DEFAULT_DOMAIN_REGEX = new RegExp(/(\.*(prd|stg|dev)*.stackspot.com)|localhost/);
|
|
2
2
|
let cookieDomain = '';
|
|
3
|
-
let cookieAttributes =
|
|
3
|
+
let cookieAttributes = {};
|
|
4
4
|
/**
|
|
5
5
|
* Setup the cookie utilities to use a another domain. By default, it's based on *.stackspot.com.
|
|
6
6
|
* @param domainRegex the regex to identify the domain. Example: {@link DEFAULT_DOMAIN_REGEX}.
|
|
@@ -8,7 +8,7 @@ let cookieAttributes = '';
|
|
|
8
8
|
export function setupCookies(domainRegex) {
|
|
9
9
|
const portalUrl = new URL(location.href);
|
|
10
10
|
cookieDomain = domainRegex.exec(portalUrl.host)?.[0] ?? '';
|
|
11
|
-
cookieAttributes =
|
|
11
|
+
cookieAttributes = { domain: cookieDomain, SameSite: 'Strict' };
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Retrieves the current domain used for cookies. To change the domain, use `setupCookies(domainRegex)`.
|
|
@@ -36,11 +36,12 @@ export function getCookies() {
|
|
|
36
36
|
* Sets the value of a cookie.
|
|
37
37
|
* @param key the cookie name (identifier).
|
|
38
38
|
* @param value the cookie value.
|
|
39
|
+
* @param customAttributes Accepted values: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes.
|
|
39
40
|
*/
|
|
40
|
-
export function setCookie(key, value) {
|
|
41
|
+
export function setCookie(key, value, customAttributes = {}) {
|
|
41
42
|
if (!cookieAttributes)
|
|
42
43
|
setupCookies(DEFAULT_DOMAIN_REGEX);
|
|
43
|
-
document.cookie = `${key}=${value}; ${cookieAttributes}`;
|
|
44
|
+
document.cookie = `${key}=${value}; ${objectToCookieString({ ...cookieAttributes, ...customAttributes })}`;
|
|
44
45
|
}
|
|
45
46
|
/**
|
|
46
47
|
* Removes a cookie.
|
|
@@ -49,7 +50,7 @@ export function setCookie(key, value) {
|
|
|
49
50
|
export function removeCookie(key) {
|
|
50
51
|
if (!cookieAttributes)
|
|
51
52
|
setupCookies(DEFAULT_DOMAIN_REGEX);
|
|
52
|
-
document.cookie = `${key}= ; ${cookieAttributes
|
|
53
|
+
document.cookie = `${key}= ; ${objectToCookieString({ ...cookieAttributes, expires: 'Thu, 01 Jan 1970 00:00:00 GMT' })}`;
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
56
|
* Retrieves the value of a cookie given its key/name.
|
|
@@ -59,4 +60,5 @@ export function removeCookie(key) {
|
|
|
59
60
|
export function getCookie(key) {
|
|
60
61
|
return getCookies()[key];
|
|
61
62
|
}
|
|
63
|
+
const objectToCookieString = (object) => Object.entries(object).reduce((prev, current) => `${prev} ${current[0]}=${current[1]};`, '');
|
|
62
64
|
//# sourceMappingURL=cookie.js.map
|
package/dist/utils/cookie.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../src/utils/cookie.ts"],"names":[],"mappings":"AAAA,MAAM,oBAAoB,GAAG,IAAI,MAAM,CAAC,6CAA6C,CAAC,CAAA;AACtF,IAAI,YAAY,GAAG,EAAE,CAAA;AACrB,IAAI,gBAAgB,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"1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
"./svg": "./dist/svg/index.js",
|
|
14
14
|
"./anchor": "./dist/context/anchor.js"
|
|
15
15
|
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "rimraf dist && tsc && tsc-esm-fix --target='dist'",
|
|
18
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
19
|
+
"check-tree-shaking": "agadoo"
|
|
20
|
+
},
|
|
16
21
|
"peerDependencies": {
|
|
17
22
|
"@citric/core": "^6.0.0",
|
|
18
23
|
"@citric/icons": "^5.4.0 || ^6.0.0",
|
|
@@ -38,17 +43,13 @@
|
|
|
38
43
|
"eslint-plugin-react": "^7.33.2",
|
|
39
44
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
40
45
|
"eslint-plugin-react-refresh": "^0.4.4",
|
|
46
|
+
"rimraf": "^5.0.7",
|
|
47
|
+
"styled-components": "6.1.10",
|
|
41
48
|
"tsc-esm-fix": "^2.20.26",
|
|
42
|
-
"typescript": "^5.2.2"
|
|
43
|
-
"styled-components": "6.1.10"
|
|
49
|
+
"typescript": "^5.2.2"
|
|
44
50
|
},
|
|
45
51
|
"dependencies": {
|
|
46
52
|
"lodash": "^4.17.21",
|
|
47
53
|
"reactour": "^1.19.3"
|
|
48
|
-
},
|
|
49
|
-
"scripts": {
|
|
50
|
-
"build": "tsc && tsc-esm-fix --target='dist'",
|
|
51
|
-
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
52
|
-
"check-tree-shaking": "agadoo"
|
|
53
54
|
}
|
|
54
55
|
}
|
|
@@ -2,7 +2,8 @@ import { getFontAppearance } from '@citric/core/dist/utils/theme'
|
|
|
2
2
|
import { theme } from '@stack-spot/portal-theme'
|
|
3
3
|
import { styled } from 'styled-components'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// the type below should be inferred, but a bug in TS+PNPM prevents it: https://github.com/microsoft/TypeScript/issues/42873
|
|
6
|
+
export const Box: React.FC<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>> = styled.nav`
|
|
6
7
|
margin-bottom: 24px;
|
|
7
8
|
|
|
8
9
|
ul {
|
|
@@ -7,6 +7,9 @@ import { NavigationProps } from './StepNavigation'
|
|
|
7
7
|
|
|
8
8
|
const TOUR_COOKIE = 'guided-tour-global'
|
|
9
9
|
|
|
10
|
+
const defaultExpires = new Date()
|
|
11
|
+
defaultExpires.setFullYear(new Date().getFullYear() + 1)
|
|
12
|
+
|
|
10
13
|
const getTourCookie = () => {
|
|
11
14
|
const currentTourObject = getCookie(TOUR_COOKIE)
|
|
12
15
|
return currentTourObject ? currentTourObject.split(',') : []
|
|
@@ -19,7 +22,7 @@ const getTourCookie = () => {
|
|
|
19
22
|
export const finishTourStep = (key: string) => {
|
|
20
23
|
const finishedTours: string[] = getTourCookie()
|
|
21
24
|
if (!finishedTours.includes(key)) finishedTours.push(key)
|
|
22
|
-
setCookie(TOUR_COOKIE, finishedTours.toString())
|
|
25
|
+
setCookie(TOUR_COOKIE, finishedTours.toString(), { expires: defaultExpires.toUTCString() })
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
/**
|
|
@@ -35,10 +38,14 @@ export const isNewTourStep = (step: ReactourStep) => !hasFinishedTourStep(`${ste
|
|
|
35
38
|
* Tutorial: verifies if the key passed as parameter refers to a React Tour step that has already finished.
|
|
36
39
|
*
|
|
37
40
|
* The key refers to a finished step if the array stored as a cookie includes it.
|
|
41
|
+
* If the cookie is set to 'disabled', then the step will be considered finished.Particularly useful in scenarios like e2e tests.
|
|
38
42
|
* @param key the step's identifier to check.
|
|
39
43
|
* @returns true if the key refers to a finished step. False otherwise.
|
|
40
44
|
*/
|
|
41
|
-
export const hasFinishedTourStep = (key: string) =>
|
|
45
|
+
export const hasFinishedTourStep = (key: string) => {
|
|
46
|
+
const tourCookie = getTourCookie()
|
|
47
|
+
return tourCookie.includes(key) || tourCookie[0] === 'disabled'
|
|
48
|
+
}
|
|
42
49
|
|
|
43
50
|
interface StackspotTourStep extends ReactourStep {
|
|
44
51
|
/**
|
package/src/utils/cookie.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const DEFAULT_DOMAIN_REGEX = new RegExp(/(\.*(prd|stg|dev)*.stackspot.com)|localhost/)
|
|
2
2
|
let cookieDomain = ''
|
|
3
|
-
let cookieAttributes =
|
|
3
|
+
let cookieAttributes = {}
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Setup the cookie utilities to use a another domain. By default, it's based on *.stackspot.com.
|
|
@@ -9,7 +9,7 @@ let cookieAttributes = ''
|
|
|
9
9
|
export function setupCookies(domainRegex: RegExp) {
|
|
10
10
|
const portalUrl = new URL(location.href)
|
|
11
11
|
cookieDomain = domainRegex.exec(portalUrl.host)?.[0] ?? ''
|
|
12
|
-
cookieAttributes =
|
|
12
|
+
cookieAttributes = { domain: cookieDomain, SameSite: 'Strict' }
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -38,10 +38,11 @@ export function getCookies(): Record<string, string | undefined> {
|
|
|
38
38
|
* Sets the value of a cookie.
|
|
39
39
|
* @param key the cookie name (identifier).
|
|
40
40
|
* @param value the cookie value.
|
|
41
|
+
* @param customAttributes Accepted values: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes.
|
|
41
42
|
*/
|
|
42
|
-
export function setCookie(key: string, value: string) {
|
|
43
|
+
export function setCookie(key: string, value: string, customAttributes: Record<string, string> = {}) {
|
|
43
44
|
if (!cookieAttributes) setupCookies(DEFAULT_DOMAIN_REGEX)
|
|
44
|
-
document.cookie = `${key}=${value}; ${cookieAttributes}`
|
|
45
|
+
document.cookie = `${key}=${value}; ${objectToCookieString({ ...cookieAttributes, ...customAttributes })}`
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
/**
|
|
@@ -50,7 +51,7 @@ export function setCookie(key: string, value: string) {
|
|
|
50
51
|
*/
|
|
51
52
|
export function removeCookie(key: string) {
|
|
52
53
|
if (!cookieAttributes) setupCookies(DEFAULT_DOMAIN_REGEX)
|
|
53
|
-
document.cookie = `${key}= ; ${cookieAttributes
|
|
54
|
+
document.cookie = `${key}= ; ${objectToCookieString({ ...cookieAttributes, expires: 'Thu, 01 Jan 1970 00:00:00 GMT' })}`
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
/**
|
|
@@ -61,3 +62,5 @@ export function removeCookie(key: string) {
|
|
|
61
62
|
export function getCookie(key: string) {
|
|
62
63
|
return getCookies()[key]
|
|
63
64
|
}
|
|
65
|
+
|
|
66
|
+
const objectToCookieString = (object: Record<string, string>): string => Object.entries(object).reduce((prev, current) => `${prev} ${current[0]}=${current[1]};`, '')
|