@helpdice/theme 1.0.9 → 1.1.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.
@@ -58,8 +58,6 @@ function _typeof(o) {
58
58
  }
59
59
 
60
60
  var shadows = {
61
- button: "0 2px #0000000b",
62
- text: "0 -1px 0 rgb(0 0 0 / 12%)",
63
61
  drop: {
64
62
  z1: "0px 2px 8px rgba(0, 0, 0, 0.4)",
65
63
  z2: "rgba(149, 157, 165, 0.2) 0px 8px 24px",
@@ -103,8 +103,6 @@ function _unsupportedIterableToArray(r, a) {
103
103
  }
104
104
 
105
105
  var shadows = {
106
- button: "0 2px #0000000b",
107
- text: "0 -1px 0 rgb(0 0 0 / 12%)",
108
106
  drop: {
109
107
  z1: "0px 2px 8px rgba(0, 0, 0, 0.4)",
110
108
  z2: "rgba(149, 157, 165, 0.2) 0px 8px 24px",
@@ -58,8 +58,6 @@ function _typeof(o) {
58
58
  }
59
59
 
60
60
  var shadows = {
61
- button: "0 2px #0000000b",
62
- text: "0 -1px 0 rgb(0 0 0 / 12%)",
63
61
  drop: {
64
62
  z1: "0px 2px 8px rgba(0, 0, 0, 0.4)",
65
63
  z2: "rgba(149, 157, 165, 0.2) 0px 8px 24px",
package/esm/index.d.ts CHANGED
@@ -22,3 +22,4 @@ export { default as Dropdown } from './shared/dropdown';
22
22
  export { default as CssTransition } from './shared/css-transition';
23
23
  export { default as Backdrop } from './shared/backdrop';
24
24
  export { addColorAlpha, colorToRgbValues } from './utils/color';
25
+ export { withSubscription } from './subscription';
package/esm/index.js CHANGED
@@ -17,4 +17,5 @@ export { default as Expand } from './shared/expand';
17
17
  export { default as Dropdown } from './shared/dropdown';
18
18
  export { default as CssTransition } from './shared/css-transition';
19
19
  export { default as Backdrop } from './shared/backdrop';
20
- export { addColorAlpha, colorToRgbValues } from './utils/color';
20
+ export { addColorAlpha, colorToRgbValues } from './utils/color';
21
+ export { withSubscription } from './subscription';
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ type SubscriptionState = {
3
+ status: 'loading';
4
+ } | {
5
+ status: 'active' | 'expired' | 'trial' | 'inactive';
6
+ } | {
7
+ status: 'error';
8
+ reason: 'OFFLINE' | 'SERVER_DOWN' | 'UNAUTHORIZED';
9
+ };
10
+ export declare const SubscriptionProvider: React.FC<{
11
+ children: React.ReactNode;
12
+ }>;
13
+ export declare const useSubscription: () => SubscriptionState;
14
+ export {};
@@ -0,0 +1,67 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ // context/SubscriptionContext.tsx
3
+ import axios from 'axios';
4
+ import React, { createContext, useContext, useEffect, useState } from 'react';
5
+ import { Account } from '@helpdice/sdk';
6
+ var SubscriptionContext = /*#__PURE__*/createContext({
7
+ status: 'loading'
8
+ });
9
+ export var SubscriptionProvider = function SubscriptionProvider(_ref) {
10
+ var children = _ref.children;
11
+ var _useState = useState({
12
+ status: 'loading'
13
+ }),
14
+ _useState2 = _slicedToArray(_useState, 2),
15
+ state = _useState2[0],
16
+ setState = _useState2[1];
17
+ useEffect(function () {
18
+ var controller = new AbortController();
19
+ try {
20
+ Account.verifySubscription({
21
+ config: {
22
+ signal: controller.signal,
23
+ // AbortController supported in axios v1+
24
+ timeout: 8000 // prevents hanging forever
25
+ },
26
+ onSuccess: function onSuccess(res) {
27
+ setState({
28
+ status: res === null || res === void 0 ? void 0 : res.data.status
29
+ });
30
+ },
31
+ onError: function onError(err) {
32
+ var _err$response, _err$response2;
33
+ // Request cancelled
34
+ if (axios.isCancel(err)) {
35
+ throw err;
36
+ }
37
+
38
+ // No response → server down or CORS or offline
39
+ if (!(err !== null && err !== void 0 && err.response)) {
40
+ if (!navigator.onLine) throw 'OFFLINE';
41
+ throw 'SERVER_DOWN';
42
+ }
43
+ if ((err === null || err === void 0 || (_err$response = err.response) === null || _err$response === void 0 ? void 0 : _err$response.status) === 401) throw 'UNAUTHORIZED';
44
+ if ((err === null || err === void 0 || (_err$response2 = err.response) === null || _err$response2 === void 0 ? void 0 : _err$response2.status) >= 500) throw 'SERVER_DOWN';
45
+ throw 'UNKNOWN';
46
+ }
47
+ });
48
+ } catch (reason) {
49
+ if (reason !== 'AbortError') {
50
+ setState({
51
+ status: 'error',
52
+ reason: reason !== null && reason !== void 0 ? reason : 'SERVER_DOWN'
53
+ });
54
+ }
55
+ }
56
+ ;
57
+ return function () {
58
+ return controller.abort();
59
+ };
60
+ }, []);
61
+ return /*#__PURE__*/React.createElement(SubscriptionContext.Provider, {
62
+ value: state
63
+ }, children);
64
+ };
65
+ export var useSubscription = function useSubscription() {
66
+ return useContext(SubscriptionContext);
67
+ };
@@ -0,0 +1,5 @@
1
+ import React from "react";
2
+ declare const SubscriptionError: ({ reason }: {
3
+ reason: string;
4
+ }) => React.JSX.Element;
5
+ export default SubscriptionError;
@@ -0,0 +1,13 @@
1
+ // components/SubscriptionError.tsx
2
+ import React from "react";
3
+ var SubscriptionError = function SubscriptionError(_ref) {
4
+ var reason = _ref.reason;
5
+ if (reason === 'OFFLINE') {
6
+ return /*#__PURE__*/React.createElement("p", null, "No internet connection. Please check your network.");
7
+ }
8
+ if (reason === 'SERVER_DOWN') {
9
+ return /*#__PURE__*/React.createElement("p", null, "Service temporarily unavailable. Try again later.");
10
+ }
11
+ return /*#__PURE__*/React.createElement("p", null, "Unable to verify subscription.");
12
+ };
13
+ export default SubscriptionError;
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ declare const UpgradeNotice: () => React.JSX.Element;
3
+ export default UpgradeNotice;
@@ -0,0 +1,15 @@
1
+ // components/UpgradeNotice.tsx
2
+ import React from "react";
3
+ var UpgradeNotice = function UpgradeNotice() {
4
+ return /*#__PURE__*/React.createElement("div", {
5
+ style: {
6
+ padding: 24,
7
+ textAlign: 'center'
8
+ }
9
+ }, /*#__PURE__*/React.createElement("h2", null, "Upgrade Required"), /*#__PURE__*/React.createElement("p", null, "This feature is available for pro users."), /*#__PURE__*/React.createElement("button", {
10
+ onClick: function onClick() {
11
+ return window.location.href = 'https://ui.helpdice.com/pro';
12
+ }
13
+ }, "Upgrade Now"));
14
+ };
15
+ export default UpgradeNotice;
@@ -0,0 +1,3 @@
1
+ import { SubscriptionProvider } from "./SubscriptionContext";
2
+ import { withSubscription } from "./withSubscription";
3
+ export { withSubscription, SubscriptionProvider };
@@ -0,0 +1,3 @@
1
+ import { SubscriptionProvider } from "./SubscriptionContext";
2
+ import { withSubscription } from "./withSubscription";
3
+ export { withSubscription, SubscriptionProvider };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const withSubscription: (Component: React.FC) => (props: any) => React.JSX.Element;
@@ -0,0 +1,44 @@
1
+ // hoc/withSubscription.tsx
2
+
3
+ // import React from 'react';
4
+ // import { useSubscription } from './SubscriptionContext';
5
+ // import UpgradeNotice from './UpgradeNotice';
6
+
7
+ // export const withSubscription =
8
+ // (Component: React.FC) =>
9
+ // (props: any) => {
10
+ // const status = useSubscription();
11
+
12
+ // if (status === 'loading') {
13
+ // return <div>Loading...</div>;
14
+ // }
15
+
16
+ // if (status !== 'active') {
17
+ // return <UpgradeNotice />;
18
+ // }
19
+
20
+ // return <Component {...props} />;
21
+ // };
22
+
23
+ // hoc/withSubscription.tsx
24
+ import React from 'react';
25
+ import { useSubscription } from './SubscriptionContext';
26
+ import UpgradeNotice from './UpgradeNotice';
27
+ import SubscriptionError from './SubscriptionError';
28
+ export var withSubscription = function withSubscription(Component) {
29
+ return function (props) {
30
+ var sub = useSubscription();
31
+ if (sub.status === 'loading') {
32
+ return /*#__PURE__*/React.createElement("div", null, "Checking subscription...");
33
+ }
34
+ if (sub.status === 'error') {
35
+ return /*#__PURE__*/React.createElement(SubscriptionError, {
36
+ reason: sub.reason
37
+ });
38
+ }
39
+ if (sub.status !== 'active') {
40
+ return /*#__PURE__*/React.createElement(UpgradeNotice, null);
41
+ }
42
+ return /*#__PURE__*/React.createElement(Component, props);
43
+ };
44
+ };
@@ -81,8 +81,6 @@ export interface HUIThemesBreakpoints {
81
81
  xl: BreakpointsItem;
82
82
  }
83
83
  export interface HUIThemesShadow {
84
- button: string;
85
- text: string;
86
84
  drop: Record<string, string>;
87
85
  level: Record<string, string>;
88
86
  border: Record<string, string>;
@@ -1,6 +1,4 @@
1
1
  export declare const shadows: {
2
- button: string;
3
- text: string;
4
2
  drop: {
5
3
  z1: string;
6
4
  z2: string;
@@ -1,6 +1,4 @@
1
1
  export var shadows = {
2
- button: "0 2px #0000000b",
3
- text: "0 -1px 0 rgb(0 0 0 / 12%)",
4
2
  drop: {
5
3
  z1: "0px 2px 8px rgba(0, 0, 0, 0.4)",
6
4
  z2: "rgba(149, 157, 165, 0.2) 0px 8px 24px",
@@ -6,6 +6,7 @@ import { HUIContent, defaultToastLayout } from '../utils/use-hd-ui-context';
6
6
  import ThemeProvider from './theme-provider';
7
7
  import useCurrentState from '../utils/use-current-state';
8
8
  import ToastContainer from '../use-toasts/toast-container';
9
+ import { SubscriptionProvider } from '../subscription';
9
10
  var HuiProvider = function HuiProvider(_ref) {
10
11
  var themes = _ref.themes,
11
12
  themeType = _ref.themeType,
@@ -50,6 +51,6 @@ var HuiProvider = function HuiProvider(_ref) {
50
51
  }, /*#__PURE__*/React.createElement(ThemeProvider, {
51
52
  themes: themes,
52
53
  themeType: themeType
53
- }, children, /*#__PURE__*/React.createElement(ToastContainer, null)));
54
+ }, /*#__PURE__*/React.createElement(SubscriptionProvider, null, children), /*#__PURE__*/React.createElement(ToastContainer, null)));
54
55
  };
55
56
  export default HuiProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helpdice/theme",
3
- "version": "1.0.9",
3
+ "version": "1.1.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "esm/index.d.ts",
6
6
  "unpkg": "dist/index.min.js",
@@ -101,6 +101,7 @@
101
101
  "tslib": "^2.8.1"
102
102
  },
103
103
  "peerDependencies": {
104
+ "@helpdice/sdk": "^0.4.3",
104
105
  "react": "^18.3.1 || ^19.1.0"
105
106
  },
106
107
  "jest": {