@rimori/react-client 0.3.0-next.6 → 0.3.0-next.7

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.
@@ -14,7 +14,7 @@ import ContextMenu from '../components/ContextMenu';
14
14
  import { useTheme } from '../hooks/ThemeSetter';
15
15
  const PluginContext = createContext(null);
16
16
  export const PluginProvider = ({ children, pluginId, settings }) => {
17
- const [plugin, setPlugin] = useState(null);
17
+ const [client, setClient] = useState(null);
18
18
  const [standaloneClient, setStandaloneClient] = useState(false);
19
19
  const [applicationMode, setApplicationMode] = useState(null);
20
20
  const [theme, setTheme] = useState(null);
@@ -30,9 +30,9 @@ export const PluginProvider = ({ children, pluginId, settings }) => {
30
30
  void client.needsLogin().then((needLogin) => setStandaloneClient(needLogin ? client : true));
31
31
  });
32
32
  }
33
- if ((!standaloneDetected && !plugin) || (standaloneDetected && standaloneClient === true)) {
33
+ if ((!standaloneDetected && !client) || (standaloneDetected && standaloneClient === true)) {
34
34
  void RimoriClient.getInstance(pluginId).then((client) => {
35
- setPlugin(client);
35
+ setClient(client);
36
36
  // Get applicationMode and theme from MessageChannel query params
37
37
  if (!standaloneDetected) {
38
38
  const mode = client.getQueryParam('applicationMode');
@@ -43,36 +43,30 @@ export const PluginProvider = ({ children, pluginId, settings }) => {
43
43
  }
44
44
  });
45
45
  }
46
- }, [pluginId, standaloneClient, plugin]);
47
- //route change
46
+ }, [pluginId, standaloneClient, client]);
48
47
  useEffect(() => {
49
- if (!plugin)
48
+ if (!client)
50
49
  return;
51
- //sidebar pages should not report url changes
52
50
  if (isSidebar)
53
- return;
54
- let lastHash = window.location.hash;
55
- const emitUrlChange = (url) => plugin.event.emit('session.triggerUrlChange', { url });
56
- const interval = setInterval(() => {
57
- if (lastHash === window.location.hash)
58
- return;
59
- lastHash = window.location.hash;
60
- // console.log('url changed:', lastHash);
61
- emitUrlChange(lastHash);
62
- }, 1000);
63
- emitUrlChange(lastHash);
64
- return () => clearInterval(interval);
65
- }, [plugin, isSidebar]);
51
+ return; //sidebar pages should not report url changes
52
+ // react router overwrites native pushstate so it gets wrapped to detect url changes
53
+ const originalPushState = history.pushState;
54
+ history.pushState = (...args) => {
55
+ const result = originalPushState.apply(history, args);
56
+ client.event.emit('session.triggerUrlChange', { url: location.hash });
57
+ return result;
58
+ };
59
+ }, [client, isSidebar]);
66
60
  if (standaloneClient instanceof StandaloneClient) {
67
61
  return (_jsx(StandaloneAuth, { onLogin: (email, password) => __awaiter(void 0, void 0, void 0, function* () {
68
62
  if (yield standaloneClient.login(email, password))
69
63
  setStandaloneClient(true);
70
64
  }) }));
71
65
  }
72
- if (!plugin) {
66
+ if (!client) {
73
67
  return '';
74
68
  }
75
- return (_jsxs(PluginContext.Provider, { value: plugin, children: [!(settings === null || settings === void 0 ? void 0 : settings.disableContextMenu) && !isSidebar && !isSettings && _jsx(ContextMenu, { client: plugin }), children] }));
69
+ return (_jsxs(PluginContext.Provider, { value: client, children: [!(settings === null || settings === void 0 ? void 0 : settings.disableContextMenu) && !isSidebar && !isSettings && _jsx(ContextMenu, { client: client }), children] }));
76
70
  };
77
71
  export const useRimori = () => {
78
72
  const context = useContext(PluginContext);
@@ -118,7 +112,7 @@ function StandaloneAuth({ onLogin }) {
118
112
  display: 'flex',
119
113
  alignItems: 'center',
120
114
  justifyContent: 'center',
121
- }, children: [_jsx("p", { style: { fontSize: '2rem', fontWeight: 'bold', marginBottom: '1rem', textAlign: 'center' }, children: "Rimori Login" }), _jsx("p", { style: { marginBottom: '1rem', textAlign: 'center' }, children: "Please login with your Rimori developer account for this plugin to be able to access the Rimori platform the same it will operate in the Rimori platform." }), _jsx("input", { style: {
115
+ }, children: [_jsx("p", { style: { fontSize: '2rem', fontWeight: 'bold', marginBottom: '1rem', textAlign: 'center' }, children: "Rimori Login Required" }), _jsx("p", { style: { marginBottom: '1rem', textAlign: 'center' }, children: "Please login with your Rimori developer account for this plugin to be able to access the Rimori platform the same way it would when being deployed." }), _jsx("input", { style: {
122
116
  marginBottom: '1rem',
123
117
  width: '100%',
124
118
  padding: '0.5rem',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimori/react-client",
3
- "version": "0.3.0-next.6",
3
+ "version": "0.3.0-next.7",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,7 +23,7 @@
23
23
  "format": "prettier --write ."
24
24
  },
25
25
  "peerDependencies": {
26
- "@rimori/client": "2.2.0-next.3",
26
+ "@rimori/client": "2.3.0-next.2",
27
27
  "react": "^18.1.0",
28
28
  "react-dom": "^18.1.0"
29
29
  },
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "@eslint/js": "^9.37.0",
37
- "@rimori/client": "2.2.0-next.3",
37
+ "@rimori/client": "2.3.0-next.2",
38
38
  "@types/react": "^18.3.21",
39
39
  "eslint-config-prettier": "^10.1.8",
40
40
  "eslint-plugin-prettier": "^5.5.4",
@@ -14,7 +14,7 @@ interface PluginProviderProps {
14
14
  const PluginContext = createContext<RimoriClient | null>(null);
15
15
 
16
16
  export const PluginProvider: React.FC<PluginProviderProps> = ({ children, pluginId, settings }) => {
17
- const [plugin, setPlugin] = useState<RimoriClient | null>(null);
17
+ const [client, setClient] = useState<RimoriClient | null>(null);
18
18
  const [standaloneClient, setStandaloneClient] = useState<StandaloneClient | boolean>(false);
19
19
  const [applicationMode, setApplicationMode] = useState<string | null>(null);
20
20
  const [theme, setTheme] = useState<string | null>(null);
@@ -36,9 +36,9 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
36
36
  });
37
37
  }
38
38
 
39
- if ((!standaloneDetected && !plugin) || (standaloneDetected && standaloneClient === true)) {
39
+ if ((!standaloneDetected && !client) || (standaloneDetected && standaloneClient === true)) {
40
40
  void RimoriClient.getInstance(pluginId).then((client) => {
41
- setPlugin(client);
41
+ setClient(client);
42
42
  // Get applicationMode and theme from MessageChannel query params
43
43
  if (!standaloneDetected) {
44
44
  const mode = client.getQueryParam('applicationMode');
@@ -49,28 +49,20 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
49
49
  }
50
50
  });
51
51
  }
52
- }, [pluginId, standaloneClient, plugin]);
52
+ }, [pluginId, standaloneClient, client]);
53
53
 
54
- //route change
55
54
  useEffect(() => {
56
- if (!plugin) return;
57
-
58
- //sidebar pages should not report url changes
59
- if (isSidebar) return;
60
-
61
- let lastHash = window.location.hash;
62
- const emitUrlChange = (url: string) => plugin.event.emit('session.triggerUrlChange', { url });
63
-
64
- const interval = setInterval(() => {
65
- if (lastHash === window.location.hash) return;
66
- lastHash = window.location.hash;
67
- // console.log('url changed:', lastHash);
68
- emitUrlChange(lastHash);
69
- }, 1000);
70
-
71
- emitUrlChange(lastHash);
72
- return () => clearInterval(interval);
73
- }, [plugin, isSidebar]);
55
+ if (!client) return;
56
+ if (isSidebar) return; //sidebar pages should not report url changes
57
+
58
+ // react router overwrites native pushstate so it gets wrapped to detect url changes
59
+ const originalPushState = history.pushState;
60
+ history.pushState = (...args) => {
61
+ const result = originalPushState.apply(history, args);
62
+ client.event.emit('session.triggerUrlChange', { url: location.hash });
63
+ return result;
64
+ };
65
+ }, [client, isSidebar]);
74
66
 
75
67
  if (standaloneClient instanceof StandaloneClient) {
76
68
  return (
@@ -82,13 +74,13 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
82
74
  );
83
75
  }
84
76
 
85
- if (!plugin) {
77
+ if (!client) {
86
78
  return '';
87
79
  }
88
80
 
89
81
  return (
90
- <PluginContext.Provider value={plugin}>
91
- {!settings?.disableContextMenu && !isSidebar && !isSettings && <ContextMenu client={plugin} />}
82
+ <PluginContext.Provider value={client}>
83
+ {!settings?.disableContextMenu && !isSidebar && !isSettings && <ContextMenu client={client} />}
92
84
  {children}
93
85
  </PluginContext.Provider>
94
86
  );
@@ -148,10 +140,12 @@ function StandaloneAuth({ onLogin }: { onLogin: (user: string, password: string)
148
140
  justifyContent: 'center',
149
141
  }}
150
142
  >
151
- <p style={{ fontSize: '2rem', fontWeight: 'bold', marginBottom: '1rem', textAlign: 'center' }}>Rimori Login</p>
143
+ <p style={{ fontSize: '2rem', fontWeight: 'bold', marginBottom: '1rem', textAlign: 'center' }}>
144
+ Rimori Login Required
145
+ </p>
152
146
  <p style={{ marginBottom: '1rem', textAlign: 'center' }}>
153
147
  Please login with your Rimori developer account for this plugin to be able to access the Rimori platform the
154
- same it will operate in the Rimori platform.
148
+ same way it would when being deployed.
155
149
  </p>
156
150
  {/* email and password input */}
157
151
  <input