@weavix/sdk-react 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -28
- package/dist/index.mjs +528 -835
- package/dist/index.mjs.map +1 -1
- package/dist/plugin-sdk-react/src/__tests__/setup.d.ts +1 -0
- package/dist/plugin-sdk-react/src/__tests__/setup.d.ts.map +1 -0
- package/dist/plugin-sdk-react/src/components/ErrorBoundary.d.ts +17 -0
- package/dist/plugin-sdk-react/src/components/ErrorBoundary.d.ts.map +1 -0
- package/dist/plugin-sdk-react/src/components/PluginError.d.ts +9 -0
- package/dist/plugin-sdk-react/src/components/PluginError.d.ts.map +1 -0
- package/dist/plugin-sdk-react/src/components/PluginLoader.d.ts +6 -0
- package/dist/plugin-sdk-react/src/components/PluginLoader.d.ts.map +1 -0
- package/dist/plugin-sdk-react/src/components/PluginProvider.d.ts +107 -0
- package/dist/plugin-sdk-react/src/components/PluginProvider.d.ts.map +1 -0
- package/dist/plugin-sdk-react/src/hooks/useConfirm.d.ts +6 -0
- package/dist/plugin-sdk-react/src/hooks/useConfirm.d.ts.map +1 -0
- package/dist/plugin-sdk-react/src/hooks/useContext.d.ts +20 -0
- package/dist/plugin-sdk-react/src/hooks/useContext.d.ts.map +1 -0
- package/dist/plugin-sdk-react/src/hooks/useIsYateam.d.ts +13 -0
- package/dist/plugin-sdk-react/src/hooks/useIsYateam.d.ts.map +1 -0
- package/dist/plugin-sdk-react/src/hooks/useLanguage.d.ts +13 -0
- package/dist/plugin-sdk-react/src/hooks/useLanguage.d.ts.map +1 -0
- package/dist/plugin-sdk-react/src/hooks/useLocalizedString.d.ts +6 -0
- package/dist/plugin-sdk-react/src/hooks/useLocalizedString.d.ts.map +1 -0
- package/dist/plugin-sdk-react/src/hooks/useTheme.d.ts +14 -0
- package/dist/plugin-sdk-react/src/hooks/useTheme.d.ts.map +1 -0
- package/dist/plugin-sdk-react/src/hooks/useToaster.d.ts +8 -0
- package/dist/plugin-sdk-react/src/hooks/useToaster.d.ts.map +1 -0
- package/dist/plugin-sdk-react/src/hooks/useUserId.d.ts +13 -0
- package/dist/plugin-sdk-react/src/hooks/useUserId.d.ts.map +1 -0
- package/dist/plugin-sdk-react/src/index.d.ts +16 -0
- package/dist/plugin-sdk-react/src/index.d.ts.map +1 -0
- package/package.json +7 -13
- package/dist/index.d.ts +0 -265
package/README.md
CHANGED
|
@@ -1,45 +1,53 @@
|
|
|
1
1
|
# @weavix/sdk-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Generic plugin SDK React package — framework-agnostic `PluginProvider` and hooks, no Tracker-specific types.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Automatically includes [`@weavix/sdk-core`](https://www.npmjs.com/package/@weavix/sdk-core) as a dependency.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install @weavix/sdk-react
|
|
11
|
-
#
|
|
12
|
-
pnpm add @weavix/sdk-react @weavix/sdk-core @weavix/tracker-api-types react
|
|
10
|
+
npm install @weavix/sdk-react
|
|
11
|
+
# @weavix/sdk-core is installed automatically
|
|
13
12
|
```
|
|
14
13
|
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
- `<TrackerPluginProvider>` — провайдер инициализирует плагин.
|
|
18
|
-
- `useTrackerPluginContext()` — реактивные значения (theme, language, slot, slotContext) и `registerHandler`.
|
|
19
|
-
- `useTheme()`, `useLanguage()`, `useUserId()`, `useIsYateam()` — реактивные хуки.
|
|
20
|
-
- `useToaster()`, `useConfirm()` — UI-методы.
|
|
21
|
-
- `useLocalizedString()`, `useContext()` — вспомогательные.
|
|
22
|
-
- `<PluginError>`, `<PluginLoader>` — компоненты для fallback'ов.
|
|
23
|
-
|
|
24
|
-
API surface идентичен internal flavor'у.
|
|
25
|
-
|
|
26
|
-
## Пример
|
|
14
|
+
## Usage
|
|
27
15
|
|
|
28
16
|
```tsx
|
|
29
|
-
import {
|
|
17
|
+
import { PluginProvider, usePluginContext } from '@weavix/sdk-react';
|
|
18
|
+
|
|
19
|
+
// Wrap your app
|
|
20
|
+
root.render(
|
|
21
|
+
<PluginProvider>
|
|
22
|
+
<App />
|
|
23
|
+
</PluginProvider>
|
|
24
|
+
);
|
|
30
25
|
|
|
26
|
+
// Use in components
|
|
31
27
|
function App() {
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
const { slot, slotContext, theme, language, registerHandler } = usePluginContext();
|
|
29
|
+
|
|
30
|
+
return <div>Slot: {slot}</div>;
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
// Full context (requires contextLevel: "full" in manifest)
|
|
34
|
+
function AppFull() {
|
|
35
|
+
const { slotContext } = usePluginContext('full');
|
|
36
|
+
// slotContext: unknown — cast to your type
|
|
37
|
+
const ctx = slotContext as { entityId: string };
|
|
38
|
+
return <div>Entity: {ctx.entityId}</div>;
|
|
39
|
+
}
|
|
41
40
|
```
|
|
42
41
|
|
|
43
|
-
##
|
|
42
|
+
## What's included
|
|
43
|
+
|
|
44
|
+
- **`PluginProvider`** — initializes the plugin, manages lifecycle, provides context
|
|
45
|
+
- **`usePluginContext()`** — hook for accessing theme, language, slot, slotContext, registerHandler
|
|
46
|
+
- **`isInternalUrl()`** — utility for checking if a URL is internal
|
|
47
|
+
- **Hooks**: `useTheme`, `useLanguage`, `useIsYateam`, `useUserId`, `useConfirm`, `useToaster`, `useLocalizedString`
|
|
48
|
+
- **Components**: `PluginError`, `PluginLoader`, `ErrorBoundary`
|
|
49
|
+
- **Re-exports from `@weavix/sdk-core`**: `hostApi`, `uiApi`, `on`, `dispatchHostEvent`, error codes, types (no `trackerApi` — use tracker-react packages for Tracker HTTP)
|
|
50
|
+
|
|
51
|
+
## For Tracker plugins
|
|
44
52
|
|
|
45
|
-
|
|
53
|
+
Use [`@yandex-data-ui/tracker-plugin-sdk-react`](https://npm.yandex-team.ru/@yandex-data-ui/tracker-plugin-sdk-react) (internal) or [`@weavix/tracker-plugin-sdk-react`](https://www.npmjs.com/package/@weavix/tracker-plugin-sdk-react) (external) for fully typed Tracker-specific wrappers.
|