@axceera/playstep-react 0.0.0-stage → 0.2.0
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/LICENSE +19 -0
- package/README.md +29 -2
- package/dist/index.d.ts +31 -0
- package/dist/index.js +53 -0
- package/package.json +42 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PlayStep
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
6
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
7
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
11
|
+
Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
14
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
15
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
16
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
17
|
+
|
|
18
|
+
Icons: Lucide (https://lucide.dev), ISC License. Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022
|
|
19
|
+
as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
|
package/README.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @axceera/playstep-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
PlayStep for React: a provider and hooks around [`@axceera/playstep`](https://www.npmjs.com/package/@axceera/playstep).
|
|
4
|
+
Guides render in their own Shadow DOM, outside your React tree, so they never re-render your app.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm install @axceera/playstep-react
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```tsx
|
|
11
|
+
import { PlayStepProvider, guideAnchor, useTrack } from '@axceera/playstep-react'
|
|
12
|
+
|
|
13
|
+
export function App() {
|
|
14
|
+
return (
|
|
15
|
+
<PlayStepProvider appKey="ps_pub_xxx" user={user ? { id: user.id, traits: { plan: user.plan } } : undefined}>
|
|
16
|
+
<Invoices />
|
|
17
|
+
</PlayStepProvider>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function Invoices() {
|
|
22
|
+
useTrack('invoice_page_opened')
|
|
23
|
+
return <button {...guideAnchor('new-invoice-btn')}>New invoice</button>
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`usePlayStep()` returns the SDK (`start`, `complete`, `track`, `openLauncher`, `resetProgress`, `reset`). The provider initialises once
|
|
28
|
+
and re-identifies when `user` changes.
|
|
29
|
+
|
|
30
|
+
Docs: https://playstep.app/docs/sdk/react
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AnalyticsEvent, AppConfig, Guide, InitOptions, InitOptions as InitOptions$1, PlayStep, PlayStep as PlayStep$1, playstep } from "@axceera/playstep";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
export interface PlayStepUser {
|
|
5
|
+
/** Your user id. Hashed in the browser before it is sent. */
|
|
6
|
+
id: string;
|
|
7
|
+
/** Traits used by guide targeting segments, e.g. `{ plan: 'pro' }`. */
|
|
8
|
+
traits?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface PlayStepProviderProps extends Omit<InitOptions$1, 'appKey' | 'sdkName' | 'transport'> {
|
|
11
|
+
/** Your publishable key, `ps_pub_…`. */
|
|
12
|
+
appKey: string;
|
|
13
|
+
/** The signed-in user. Pass null after sign-out to forget them and their guide progress. */
|
|
14
|
+
user?: PlayStepUser | null;
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
}
|
|
17
|
+
/** Starts PlayStep once for your app and keeps the signed-in user in sync. Renders only its children. */
|
|
18
|
+
export declare function PlayStepProvider({ appKey, user, children, ...options }: PlayStepProviderProps): import("react").JSX.Element;
|
|
19
|
+
/**
|
|
20
|
+
* The PlayStep SDK: `track`, `start`, `complete`, `page`, `openLauncher` (the guide list, for your own help menu),
|
|
21
|
+
* `resetProgress` (let users replay guides), `identify`, `reset`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function usePlayStep(): PlayStep$1;
|
|
24
|
+
/** Reports one of your events when the component mounts (and again whenever `event` changes). */
|
|
25
|
+
export declare function useTrack(event: string | null | undefined): void;
|
|
26
|
+
/** Props that mark an element as a guide anchor: `<button {...guideAnchor('new-invoice-btn')}>`. */
|
|
27
|
+
export declare function guideAnchor(id: string): {
|
|
28
|
+
'data-guide': string;
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { type AnalyticsEvent, type AppConfig, type Guide, type InitOptions, type PlayStep, playstep };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { playstep } from "@axceera/playstep";
|
|
2
|
+
import { createContext, useContext, useEffect, useRef } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/index.tsx
|
|
6
|
+
const Context = createContext(playstep);
|
|
7
|
+
/** Starts PlayStep once for your app and keeps the signed-in user in sync. Renders only its children. */
|
|
8
|
+
function PlayStepProvider({ appKey, user, children, ...options }) {
|
|
9
|
+
const optionsRef = useRef(options);
|
|
10
|
+
const lastUser = useRef(null);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
playstep.init({
|
|
13
|
+
...optionsRef.current,
|
|
14
|
+
appKey,
|
|
15
|
+
sdkName: "react"
|
|
16
|
+
});
|
|
17
|
+
}, [appKey]);
|
|
18
|
+
const traits = JSON.stringify(user?.traits ?? {});
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (user?.id) {
|
|
21
|
+
playstep.identify(user.id, user.traits);
|
|
22
|
+
lastUser.current = user.id;
|
|
23
|
+
} else if (user === null && lastUser.current) {
|
|
24
|
+
playstep.reset();
|
|
25
|
+
lastUser.current = null;
|
|
26
|
+
}
|
|
27
|
+
}, [user?.id, traits]);
|
|
28
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
29
|
+
value: playstep,
|
|
30
|
+
children
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The PlayStep SDK: `track`, `start`, `complete`, `page`, `openLauncher` (the guide list, for your own help menu),
|
|
35
|
+
* `resetProgress` (let users replay guides), `identify`, `reset`.
|
|
36
|
+
*/
|
|
37
|
+
function usePlayStep() {
|
|
38
|
+
return useContext(Context);
|
|
39
|
+
}
|
|
40
|
+
/** Reports one of your events when the component mounts (and again whenever `event` changes). */
|
|
41
|
+
function useTrack(event) {
|
|
42
|
+
const ps = usePlayStep();
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (event) ps.track(event);
|
|
45
|
+
}, [event, ps]);
|
|
46
|
+
}
|
|
47
|
+
/** Props that mark an element as a guide anchor: `<button {...guideAnchor('new-invoice-btn')}>`. */
|
|
48
|
+
function guideAnchor(id) {
|
|
49
|
+
return { "data-guide": id };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { PlayStepProvider, guideAnchor, playstep, usePlayStep, useTrack };
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axceera/playstep-react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "PlayStep for React: a provider and hooks around @axceera/playstep. Guides render in their own Shadow DOM, outside your React tree.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"homepage": "https://playstep.app/docs/sdk/react",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"react": ">=18"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@axceera/playstep": "^0.2.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@testing-library/react": "^16.3.3",
|
|
29
|
+
"@types/react": "^19.3.0",
|
|
30
|
+
"@types/react-dom": "^19.2.0",
|
|
31
|
+
"happy-dom": "^20.14.6",
|
|
32
|
+
"react": "^19.3.0",
|
|
33
|
+
"react-dom": "^19.3.0",
|
|
34
|
+
"tsdown": "^0.23.0",
|
|
35
|
+
"typescript": "~6.0.3",
|
|
36
|
+
"vitest": "^4.1.11",
|
|
37
|
+
"@playstep/spec": "0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsdown",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"lint": "eslint ."
|
|
44
|
+
}
|
|
6
45
|
}
|