@matrix-widget-toolkit/react 2.0.2 → 2.0.4

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.
Files changed (28) hide show
  1. package/build/cjs/components/CapabilitiesGuard/CapabilitiesGuard.d.cts +31 -0
  2. package/build/cjs/components/CapabilitiesGuard/CapabilitiesGuard.test.d.cts +1 -0
  3. package/build/cjs/components/CapabilitiesGuard/index.d.cts +2 -0
  4. package/build/cjs/components/ThemeSelectionProvider/ThemeSelectionProvider.d.cts +43 -0
  5. package/build/cjs/components/ThemeSelectionProvider/ThemeSelectionProvider.test.d.cts +1 -0
  6. package/build/cjs/components/ThemeSelectionProvider/index.d.cts +2 -0
  7. package/build/cjs/components/WidgetApiProvider/WidgetApiProvider.d.cts +55 -0
  8. package/build/cjs/components/WidgetApiProvider/WidgetApiProvider.test.d.cts +1 -0
  9. package/build/cjs/components/WidgetApiProvider/context.d.cts +17 -0
  10. package/build/cjs/components/WidgetApiProvider/index.d.cts +3 -0
  11. package/build/cjs/components/index.d.cts +3 -0
  12. package/build/cjs/index.d.cts +5 -0
  13. package/build/cjs/setupTests.d.cts +1 -0
  14. package/build/esm/components/CapabilitiesGuard/CapabilitiesGuard.d.ts +31 -0
  15. package/build/esm/components/CapabilitiesGuard/CapabilitiesGuard.test.d.ts +1 -0
  16. package/build/esm/components/CapabilitiesGuard/index.d.ts +2 -0
  17. package/build/esm/components/ThemeSelectionProvider/ThemeSelectionProvider.d.ts +43 -0
  18. package/build/esm/components/ThemeSelectionProvider/ThemeSelectionProvider.test.d.ts +1 -0
  19. package/build/esm/components/ThemeSelectionProvider/index.d.ts +2 -0
  20. package/build/esm/components/WidgetApiProvider/WidgetApiProvider.d.ts +55 -0
  21. package/build/esm/components/WidgetApiProvider/WidgetApiProvider.test.d.ts +1 -0
  22. package/build/esm/components/WidgetApiProvider/context.d.ts +17 -0
  23. package/build/esm/components/WidgetApiProvider/index.d.ts +3 -0
  24. package/build/esm/components/index.d.ts +3 -0
  25. package/build/esm/index.d.ts +5 -0
  26. package/build/esm/setupTests.d.ts +1 -0
  27. package/package.json +33 -19
  28. /package/build/cjs/{index.js → index.cjs} +0 -0
@@ -0,0 +1,31 @@
1
+ import { Capability, WidgetEventCapability } from 'matrix-widget-api';
2
+ import { ComponentType, DispatchWithoutAction, PropsWithChildren, ReactElement } from 'react';
3
+ /**
4
+ * Props for the {@link CapabilitiesGuard} component.
5
+ */
6
+ export type CapabilitiesGuardProps = PropsWithChildren<{
7
+ /**
8
+ * Required capabilities to display the `children`.
9
+ */
10
+ capabilities: Array<WidgetEventCapability | Capability>;
11
+ /**
12
+ * Component to display if the required capabilities are missing. The
13
+ * `onRetry` callback can be used to re-request them from the user.
14
+ */
15
+ missingCapabilitiesComponent: ComponentType<{
16
+ onRetry: DispatchWithoutAction;
17
+ }>;
18
+ /**
19
+ * Component to display while the capabilities are evaluated or requested from
20
+ * the user.
21
+ */
22
+ loadingComponent: ComponentType;
23
+ }>;
24
+ /**
25
+ * A guard that ask the user for capabilities and only shows the `children`
26
+ * if all capabilities were accepted.
27
+ * If capabilities are denined, a message and a button to retry is displayed
28
+ * instead.
29
+ * @param param0 - {@link CapabilitiesGuardProps}
30
+ */
31
+ export declare function CapabilitiesGuard({ capabilities, children, missingCapabilitiesComponent: MissingCapabilitiesComponent, loadingComponent: LoadingComponent, }: CapabilitiesGuardProps): ReactElement;
@@ -0,0 +1,2 @@
1
+ export { CapabilitiesGuard } from './CapabilitiesGuard';
2
+ export type { CapabilitiesGuardProps } from './CapabilitiesGuard';
@@ -0,0 +1,43 @@
1
+ import { PropsWithChildren, ReactElement } from 'react';
2
+ /**
3
+ * Themes with different color schemes, either `light` or `dark`.
4
+ */
5
+ export type Theme = 'light' | 'dark' | string;
6
+ /**
7
+ * Return value of the {@link useThemeSelection} hook.
8
+ */
9
+ export type ThemeSelectionContextType = {
10
+ /**
11
+ * The current color scheme.
12
+ */
13
+ theme: Theme;
14
+ /**
15
+ * Whether the widget is displayed in a modal.
16
+ *
17
+ * @remarks Modals have different background colors which the theme needs to
18
+ * take into account.
19
+ */
20
+ isModal: boolean;
21
+ /**
22
+ * Select the current color scheme.
23
+ *
24
+ * @param theme - The new color scheme.
25
+ */
26
+ setTheme: (theme: Theme) => void;
27
+ };
28
+ export declare const ThemeSelectionContext: import("react").Context<ThemeSelectionContextType | undefined>;
29
+ /**
30
+ * Hook for accessing the current theme selection.
31
+ * @returns The current theme selection.
32
+ */
33
+ export declare const useThemeSelection: () => ThemeSelectionContextType;
34
+ /**
35
+ * Props for the {@link ThemeSelectionProvider} component.
36
+ */
37
+ export type ThemeSelectionProviderProps = PropsWithChildren;
38
+ /**
39
+ * Provides the current theme selection to child components.
40
+ * Use the {@link useThemeSelection} hook to access it.
41
+ * @param param0 - {@link ThemeSelectionProviderProps}
42
+ */
43
+ export declare function ThemeSelectionProvider({ children, }: ThemeSelectionProviderProps): ReactElement;
@@ -0,0 +1,2 @@
1
+ export { ThemeSelectionProvider, useThemeSelection, } from './ThemeSelectionProvider';
2
+ export type { Theme, ThemeSelectionContextType, ThemeSelectionProviderProps, } from './ThemeSelectionProvider';
@@ -0,0 +1,55 @@
1
+ import { WidgetApi, WidgetRegistration } from '@matrix-widget-toolkit/api';
2
+ import { ComponentType, DispatchWithoutAction, PropsWithChildren, ReactElement } from 'react';
3
+ import { FallbackProps } from 'react-error-boundary';
4
+ /**
5
+ * Props for the {@link (WidgetApiProvider:function)} component.
6
+ */
7
+ export type WidgetApiProviderProps = PropsWithChildren<{
8
+ /**
9
+ * Configuration to set during Widget registration.
10
+ */
11
+ widgetRegistration?: WidgetRegistration;
12
+ /**
13
+ * Result from a call to `WidgetApiImpl.create`.
14
+ */
15
+ widgetApiPromise: Promise<WidgetApi>;
16
+ /**
17
+ * Component to display while the widget API communication is established or
18
+ * while capabilities are evaluated or requested from the user.
19
+ */
20
+ loadingViewComponent: ComponentType;
21
+ /**
22
+ * Component to display if the widget is opened in an unsupported mobile
23
+ * client.
24
+ */
25
+ mobileClientErrorComponent: ComponentType;
26
+ /**
27
+ * Component to display if the widget is opened outside a Matrix client.
28
+ */
29
+ outsideClientErrorComponent: ComponentType;
30
+ /**
31
+ * Component to display when a child component fails to render.
32
+ */
33
+ childErrorComponent: ComponentType<FallbackProps>;
34
+ /**
35
+ * Component to display if the required capabilities are missing. The
36
+ * `onRetry` callback can be used to re-request them from the user.
37
+ */
38
+ missingCapabilitiesComponent: ComponentType<{
39
+ onRetry: DispatchWithoutAction;
40
+ }>;
41
+ /**
42
+ * Component to display when the widget is not properly configured in the
43
+ * room. Takes the expected `widgetRegistration` as a parameter.
44
+ */
45
+ missingParametersErrorComponent: ComponentType<{
46
+ widgetRegistration?: WidgetRegistration;
47
+ }>;
48
+ }>;
49
+ /**
50
+ * Provides the `WidgetApi` in the React context once it's fully
51
+ * initialized without errors.
52
+ * Use {@link useWidgetApi} to access it.
53
+ * @param param0 - {@link WidgetApiProviderProps}
54
+ */
55
+ export declare function WidgetApiProvider({ children, widgetApiPromise, widgetRegistration, loadingViewComponent: LoadingViewComponent, mobileClientErrorComponent: MobileClientErrorComponent, outsideClientErrorComponent: OutsideClientErrorComponent, childErrorComponent: ChildErrorComponent, missingCapabilitiesComponent: MissingCapabilitiesComponent, missingParametersErrorComponent: MissingParametersErrorComponent, }: WidgetApiProviderProps): ReactElement;
@@ -0,0 +1,17 @@
1
+ import { WidgetApi } from '@matrix-widget-toolkit/api';
2
+ export declare const WidgetApiContext: import("react").Context<WidgetApi | undefined>;
3
+ /**
4
+ * Hook for accessing the widget API.
5
+ *
6
+ * @remarks Can only be called inside a `WidgetApiProvider`
7
+ * (or WidgetApiMockProvider in tests).
8
+ *
9
+ * @returns A fully initialized widget API.
10
+ */
11
+ export declare const useWidgetApi: () => WidgetApi;
12
+ /**
13
+ * Provides a custom instance of the `WidgetApi` to the context.
14
+ *
15
+ * @remarks Should only be used in tests.
16
+ */
17
+ export declare const WidgetApiMockProvider: import("react").Provider<WidgetApi | undefined>;
@@ -0,0 +1,3 @@
1
+ export { WidgetApiMockProvider, useWidgetApi } from './context';
2
+ export { WidgetApiProvider } from './WidgetApiProvider';
3
+ export type { WidgetApiProviderProps } from './WidgetApiProvider';
@@ -0,0 +1,3 @@
1
+ export * from './CapabilitiesGuard';
2
+ export * from './ThemeSelectionProvider';
3
+ export * from './WidgetApiProvider';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @packageDocumentation This is package that provides a Widget API
3
+ * intergration for React apps.
4
+ */
5
+ export * from './components';
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom/vitest';
@@ -0,0 +1,31 @@
1
+ import { Capability, WidgetEventCapability } from 'matrix-widget-api';
2
+ import { ComponentType, DispatchWithoutAction, PropsWithChildren, ReactElement } from 'react';
3
+ /**
4
+ * Props for the {@link CapabilitiesGuard} component.
5
+ */
6
+ export type CapabilitiesGuardProps = PropsWithChildren<{
7
+ /**
8
+ * Required capabilities to display the `children`.
9
+ */
10
+ capabilities: Array<WidgetEventCapability | Capability>;
11
+ /**
12
+ * Component to display if the required capabilities are missing. The
13
+ * `onRetry` callback can be used to re-request them from the user.
14
+ */
15
+ missingCapabilitiesComponent: ComponentType<{
16
+ onRetry: DispatchWithoutAction;
17
+ }>;
18
+ /**
19
+ * Component to display while the capabilities are evaluated or requested from
20
+ * the user.
21
+ */
22
+ loadingComponent: ComponentType;
23
+ }>;
24
+ /**
25
+ * A guard that ask the user for capabilities and only shows the `children`
26
+ * if all capabilities were accepted.
27
+ * If capabilities are denined, a message and a button to retry is displayed
28
+ * instead.
29
+ * @param param0 - {@link CapabilitiesGuardProps}
30
+ */
31
+ export declare function CapabilitiesGuard({ capabilities, children, missingCapabilitiesComponent: MissingCapabilitiesComponent, loadingComponent: LoadingComponent, }: CapabilitiesGuardProps): ReactElement;
@@ -0,0 +1,2 @@
1
+ export { CapabilitiesGuard } from './CapabilitiesGuard';
2
+ export type { CapabilitiesGuardProps } from './CapabilitiesGuard';
@@ -0,0 +1,43 @@
1
+ import { PropsWithChildren, ReactElement } from 'react';
2
+ /**
3
+ * Themes with different color schemes, either `light` or `dark`.
4
+ */
5
+ export type Theme = 'light' | 'dark' | string;
6
+ /**
7
+ * Return value of the {@link useThemeSelection} hook.
8
+ */
9
+ export type ThemeSelectionContextType = {
10
+ /**
11
+ * The current color scheme.
12
+ */
13
+ theme: Theme;
14
+ /**
15
+ * Whether the widget is displayed in a modal.
16
+ *
17
+ * @remarks Modals have different background colors which the theme needs to
18
+ * take into account.
19
+ */
20
+ isModal: boolean;
21
+ /**
22
+ * Select the current color scheme.
23
+ *
24
+ * @param theme - The new color scheme.
25
+ */
26
+ setTheme: (theme: Theme) => void;
27
+ };
28
+ export declare const ThemeSelectionContext: import("react").Context<ThemeSelectionContextType | undefined>;
29
+ /**
30
+ * Hook for accessing the current theme selection.
31
+ * @returns The current theme selection.
32
+ */
33
+ export declare const useThemeSelection: () => ThemeSelectionContextType;
34
+ /**
35
+ * Props for the {@link ThemeSelectionProvider} component.
36
+ */
37
+ export type ThemeSelectionProviderProps = PropsWithChildren;
38
+ /**
39
+ * Provides the current theme selection to child components.
40
+ * Use the {@link useThemeSelection} hook to access it.
41
+ * @param param0 - {@link ThemeSelectionProviderProps}
42
+ */
43
+ export declare function ThemeSelectionProvider({ children, }: ThemeSelectionProviderProps): ReactElement;
@@ -0,0 +1,2 @@
1
+ export { ThemeSelectionProvider, useThemeSelection, } from './ThemeSelectionProvider';
2
+ export type { Theme, ThemeSelectionContextType, ThemeSelectionProviderProps, } from './ThemeSelectionProvider';
@@ -0,0 +1,55 @@
1
+ import { WidgetApi, WidgetRegistration } from '@matrix-widget-toolkit/api';
2
+ import { ComponentType, DispatchWithoutAction, PropsWithChildren, ReactElement } from 'react';
3
+ import { FallbackProps } from 'react-error-boundary';
4
+ /**
5
+ * Props for the {@link (WidgetApiProvider:function)} component.
6
+ */
7
+ export type WidgetApiProviderProps = PropsWithChildren<{
8
+ /**
9
+ * Configuration to set during Widget registration.
10
+ */
11
+ widgetRegistration?: WidgetRegistration;
12
+ /**
13
+ * Result from a call to `WidgetApiImpl.create`.
14
+ */
15
+ widgetApiPromise: Promise<WidgetApi>;
16
+ /**
17
+ * Component to display while the widget API communication is established or
18
+ * while capabilities are evaluated or requested from the user.
19
+ */
20
+ loadingViewComponent: ComponentType;
21
+ /**
22
+ * Component to display if the widget is opened in an unsupported mobile
23
+ * client.
24
+ */
25
+ mobileClientErrorComponent: ComponentType;
26
+ /**
27
+ * Component to display if the widget is opened outside a Matrix client.
28
+ */
29
+ outsideClientErrorComponent: ComponentType;
30
+ /**
31
+ * Component to display when a child component fails to render.
32
+ */
33
+ childErrorComponent: ComponentType<FallbackProps>;
34
+ /**
35
+ * Component to display if the required capabilities are missing. The
36
+ * `onRetry` callback can be used to re-request them from the user.
37
+ */
38
+ missingCapabilitiesComponent: ComponentType<{
39
+ onRetry: DispatchWithoutAction;
40
+ }>;
41
+ /**
42
+ * Component to display when the widget is not properly configured in the
43
+ * room. Takes the expected `widgetRegistration` as a parameter.
44
+ */
45
+ missingParametersErrorComponent: ComponentType<{
46
+ widgetRegistration?: WidgetRegistration;
47
+ }>;
48
+ }>;
49
+ /**
50
+ * Provides the `WidgetApi` in the React context once it's fully
51
+ * initialized without errors.
52
+ * Use {@link useWidgetApi} to access it.
53
+ * @param param0 - {@link WidgetApiProviderProps}
54
+ */
55
+ export declare function WidgetApiProvider({ children, widgetApiPromise, widgetRegistration, loadingViewComponent: LoadingViewComponent, mobileClientErrorComponent: MobileClientErrorComponent, outsideClientErrorComponent: OutsideClientErrorComponent, childErrorComponent: ChildErrorComponent, missingCapabilitiesComponent: MissingCapabilitiesComponent, missingParametersErrorComponent: MissingParametersErrorComponent, }: WidgetApiProviderProps): ReactElement;
@@ -0,0 +1,17 @@
1
+ import { WidgetApi } from '@matrix-widget-toolkit/api';
2
+ export declare const WidgetApiContext: import("react").Context<WidgetApi | undefined>;
3
+ /**
4
+ * Hook for accessing the widget API.
5
+ *
6
+ * @remarks Can only be called inside a `WidgetApiProvider`
7
+ * (or WidgetApiMockProvider in tests).
8
+ *
9
+ * @returns A fully initialized widget API.
10
+ */
11
+ export declare const useWidgetApi: () => WidgetApi;
12
+ /**
13
+ * Provides a custom instance of the `WidgetApi` to the context.
14
+ *
15
+ * @remarks Should only be used in tests.
16
+ */
17
+ export declare const WidgetApiMockProvider: import("react").Provider<WidgetApi | undefined>;
@@ -0,0 +1,3 @@
1
+ export { WidgetApiMockProvider, useWidgetApi } from './context';
2
+ export { WidgetApiProvider } from './WidgetApiProvider';
3
+ export type { WidgetApiProviderProps } from './WidgetApiProvider';
@@ -0,0 +1,3 @@
1
+ export * from './CapabilitiesGuard';
2
+ export * from './ThemeSelectionProvider';
3
+ export * from './WidgetApiProvider';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @packageDocumentation This is package that provides a Widget API
3
+ * intergration for React apps.
4
+ */
5
+ export * from './components';
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom/vitest';
package/package.json CHANGED
@@ -1,26 +1,36 @@
1
1
  {
2
2
  "name": "@matrix-widget-toolkit/react",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "A simplified layer on top of @matrix-widget-toolkit/api to use it in a React based widget.",
5
5
  "author": "Nordeck IT + Consulting GmbH",
6
6
  "license": "Apache-2.0",
7
7
  "source": "./src/index.ts",
8
- "types": "./build/index.d.ts",
8
+ "types": "./build/esm/index.d.ts",
9
9
  "exports": {
10
- "import": "./build/esm/index.js",
11
- "require": "./build/cjs/index.js"
10
+ ".": {
11
+ "module": "./build/esm/index.js",
12
+ "import": {
13
+ "types": "./build/esm/index.d.ts",
14
+ "default": "./build/esm/index.js"
15
+ },
16
+ "require": {
17
+ "types": "./build/cjs/index.d.cts",
18
+ "default": "./build/cjs/index.cjs"
19
+ }
20
+ },
21
+ "./package.json": "./package.json"
12
22
  },
13
23
  "type": "module",
14
24
  "devDependencies": {
15
- "@testing-library/jest-dom": "^6.5.0",
16
- "@testing-library/react": "^16.0.1",
17
- "@testing-library/user-event": "^14.5.2",
18
- "@types/node": "^22.7.5",
19
- "@types/react": "^18.2.74",
20
- "@vitest/coverage-v8": "^2.1.3",
21
- "typescript": "^5.6.3",
22
- "vite": "^5.4.8",
23
- "vitest": "^2.1.3"
25
+ "@testing-library/jest-dom": "6.6.3",
26
+ "@testing-library/react": "16.1.0",
27
+ "@testing-library/user-event": "14.5.2",
28
+ "@types/node": "22.10.1",
29
+ "@types/react": "18.3.14",
30
+ "@vitest/coverage-v8": "2.1.8",
31
+ "typescript": "5.7.2",
32
+ "vite": "5.4.11",
33
+ "vitest": "2.1.8"
24
34
  },
25
35
  "scripts": {
26
36
  "build": "tsc && rollup --config ../../rollup.config.mjs",
@@ -35,11 +45,13 @@
35
45
  "generate-api-report": "tsc && api-extractor run --verbose --local"
36
46
  },
37
47
  "dependencies": {
38
- "@matrix-widget-toolkit/api": "^3.4.1",
39
- "matrix-widget-api": "^1.9.0",
40
- "react": "^18.2.0",
41
- "react-error-boundary": "^3.1.4",
42
- "react-use": "^17.5.1"
48
+ "@matrix-widget-toolkit/api": "^4.0.0",
49
+ "matrix-widget-api": "1.10.0",
50
+ "react-error-boundary": "4.1.2",
51
+ "react-use": "17.5.1"
52
+ },
53
+ "peerDependencies": {
54
+ "react": "18.3.1"
43
55
  },
44
56
  "repository": {
45
57
  "type": "git",
@@ -53,5 +65,7 @@
53
65
  "matrix",
54
66
  "widget",
55
67
  "matrix-widget-api"
56
- ]
68
+ ],
69
+ "module": "./build/esm/index.js",
70
+ "main": "./build/cjs/index.cjs"
57
71
  }
File without changes