starpro-plugin-sdk 1.0.1 → 1.1.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/README.md +65 -34
- package/dist/build/index.d.mts +87 -0
- package/dist/build/index.d.ts +87 -0
- package/dist/build/index.js +413 -0
- package/dist/build/index.mjs +380 -0
- package/dist/chunk-HFHUB6W5.mjs +677 -0
- package/dist/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/index.d.mts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +725 -0
- package/dist/index.mjs +39 -0
- package/dist/react-DS5S7U6B.d.mts +280 -0
- package/dist/react-DS5S7U6B.d.ts +280 -0
- package/dist/react.d.mts +2 -0
- package/dist/react.d.ts +2 -0
- package/dist/react.js +717 -0
- package/dist/react.mjs +33 -0
- package/package.json +17 -2
- package/src/bridge.ts +0 -94
- package/src/define-plugin.ts +0 -79
- package/src/index.ts +0 -6
- package/src/react.tsx +0 -94
- package/src/types.ts +0 -66
- package/tsconfig.json +0 -17
|
@@ -0,0 +1,677 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__require
|
|
3
|
+
} from "./chunk-Y6FXYEAI.mjs";
|
|
4
|
+
|
|
5
|
+
// src/react.tsx
|
|
6
|
+
import { useState as useState2 } from "react";
|
|
7
|
+
|
|
8
|
+
// src/bridge.ts
|
|
9
|
+
function setupStarProAuthBridge(payload) {
|
|
10
|
+
if (typeof window === "undefined") return;
|
|
11
|
+
const { accessToken, refreshToken, user } = payload || {};
|
|
12
|
+
if (!accessToken) return;
|
|
13
|
+
console.log("\u26A1 [StarPro Plugin SDK] Auto-syncing auth tokens across storage & HTTP clients...");
|
|
14
|
+
const tokenKeys = ["accessToken", "access_token", "token", "starpro_token", "authToken"];
|
|
15
|
+
tokenKeys.forEach((key) => {
|
|
16
|
+
try {
|
|
17
|
+
localStorage.setItem(key, accessToken);
|
|
18
|
+
sessionStorage.setItem(key, accessToken);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
if (refreshToken) {
|
|
23
|
+
try {
|
|
24
|
+
localStorage.setItem("refreshToken", refreshToken);
|
|
25
|
+
localStorage.setItem("refresh_token", refreshToken);
|
|
26
|
+
sessionStorage.setItem("refreshToken", refreshToken);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (user) {
|
|
31
|
+
try {
|
|
32
|
+
localStorage.setItem("user", JSON.stringify(user));
|
|
33
|
+
localStorage.setItem("user_email", user.email || "");
|
|
34
|
+
} catch (e) {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
localStorage.setItem("is_starpro_plugin", "true");
|
|
39
|
+
sessionStorage.setItem("is_starpro_plugin", "true");
|
|
40
|
+
} catch (e) {
|
|
41
|
+
}
|
|
42
|
+
if (window.axios) {
|
|
43
|
+
try {
|
|
44
|
+
window.axios.defaults.headers.common["Authorization"] = `Bearer ${accessToken}`;
|
|
45
|
+
} catch (e) {
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (typeof window.fetch === "function") {
|
|
49
|
+
const originalFetch = window.fetch;
|
|
50
|
+
window.fetch = function(input, init) {
|
|
51
|
+
const options = init || {};
|
|
52
|
+
options.headers = options.headers || {};
|
|
53
|
+
if (options.headers instanceof Headers) {
|
|
54
|
+
if (!options.headers.has("Authorization")) {
|
|
55
|
+
options.headers.set("Authorization", `Bearer ${accessToken}`);
|
|
56
|
+
}
|
|
57
|
+
} else if (Array.isArray(options.headers)) {
|
|
58
|
+
const hasAuth = options.headers.some(([k]) => k.toLowerCase() === "authorization");
|
|
59
|
+
if (!hasAuth) {
|
|
60
|
+
options.headers.push(["Authorization", `Bearer ${accessToken}`]);
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
const headersRecord = options.headers;
|
|
64
|
+
if (!headersRecord["Authorization"] && !headersRecord["authorization"]) {
|
|
65
|
+
headersRecord["Authorization"] = `Bearer ${accessToken}`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return originalFetch.call(this, input, options);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function isStarProPlugin() {
|
|
73
|
+
if (typeof window === "undefined") return false;
|
|
74
|
+
return localStorage.getItem("is_starpro_plugin") === "true" || sessionStorage.getItem("is_starpro_plugin") === "true" || Boolean(window.StarProPlugins);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/router.tsx
|
|
78
|
+
import React, { useState, useEffect } from "react";
|
|
79
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
80
|
+
function matchRoute(pattern, pathname) {
|
|
81
|
+
const cleanPattern = pattern.length > 1 && pattern.endsWith("/") ? pattern.slice(0, -1) : pattern;
|
|
82
|
+
const cleanPath = pathname.length > 1 && pathname.endsWith("/") ? pathname.slice(0, -1) : pathname;
|
|
83
|
+
if (cleanPattern === cleanPath) {
|
|
84
|
+
return { matched: true, params: {} };
|
|
85
|
+
}
|
|
86
|
+
const paramNames = [];
|
|
87
|
+
const regexPattern = cleanPattern.replace(/\[\.\.\.([^\]]+)\]/g, (_, name) => {
|
|
88
|
+
paramNames.push(name);
|
|
89
|
+
return "(.*)";
|
|
90
|
+
}).replace(/\[([^\]]+)\]/g, (_, name) => {
|
|
91
|
+
paramNames.push(name);
|
|
92
|
+
return "([^/]+)";
|
|
93
|
+
}).replace(/:([a-zA-Z0-9_]+)/g, (_, name) => {
|
|
94
|
+
paramNames.push(name);
|
|
95
|
+
return "([^/]+)";
|
|
96
|
+
}).replace(/\*([a-zA-Z0-9_]*)/g, (_, name) => {
|
|
97
|
+
paramNames.push(name || "wildcard");
|
|
98
|
+
return "(.*)";
|
|
99
|
+
});
|
|
100
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
101
|
+
const match = cleanPath.match(regex);
|
|
102
|
+
if (!match) {
|
|
103
|
+
return { matched: false, params: {} };
|
|
104
|
+
}
|
|
105
|
+
const params = {};
|
|
106
|
+
paramNames.forEach((name, index) => {
|
|
107
|
+
params[name] = decodeURIComponent(match[index + 1] || "");
|
|
108
|
+
});
|
|
109
|
+
return { matched: true, params };
|
|
110
|
+
}
|
|
111
|
+
var StarProRouter = class {
|
|
112
|
+
constructor(initialUrl = "/") {
|
|
113
|
+
this.currentUrl = "/";
|
|
114
|
+
this.history = ["/"];
|
|
115
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
116
|
+
this.routes = [];
|
|
117
|
+
this.notifyScheduled = false;
|
|
118
|
+
this.currentUrl = initialUrl;
|
|
119
|
+
this.history = [initialUrl];
|
|
120
|
+
}
|
|
121
|
+
setRoutes(routes) {
|
|
122
|
+
this.routes = routes;
|
|
123
|
+
this.notify();
|
|
124
|
+
}
|
|
125
|
+
getRoutes() {
|
|
126
|
+
return this.routes;
|
|
127
|
+
}
|
|
128
|
+
getState() {
|
|
129
|
+
const [pathPart, searchPart] = (this.currentUrl || "/").split("?");
|
|
130
|
+
const pathname = pathPart || "/";
|
|
131
|
+
const searchParams = new URLSearchParams(searchPart || "");
|
|
132
|
+
let params = {};
|
|
133
|
+
for (const r of this.routes) {
|
|
134
|
+
const match = matchRoute(r.path, pathname);
|
|
135
|
+
if (match.matched) {
|
|
136
|
+
params = match.params;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
url: this.currentUrl,
|
|
142
|
+
pathname,
|
|
143
|
+
searchParams,
|
|
144
|
+
params,
|
|
145
|
+
history: [...this.history]
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
getPathname() {
|
|
149
|
+
return this.getState().pathname;
|
|
150
|
+
}
|
|
151
|
+
getSearchParams() {
|
|
152
|
+
return this.getState().searchParams;
|
|
153
|
+
}
|
|
154
|
+
getParams() {
|
|
155
|
+
return this.getState().params;
|
|
156
|
+
}
|
|
157
|
+
subscribe(listener) {
|
|
158
|
+
this.listeners.add(listener);
|
|
159
|
+
return () => {
|
|
160
|
+
this.listeners.delete(listener);
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Asynchronously notifies listeners on the next microtask tick.
|
|
165
|
+
* This completely prevents React warnings when navigating or redirecting
|
|
166
|
+
* during a component's render lifecycle.
|
|
167
|
+
*/
|
|
168
|
+
notify() {
|
|
169
|
+
if (this.notifyScheduled) return;
|
|
170
|
+
this.notifyScheduled = true;
|
|
171
|
+
Promise.resolve().then(() => {
|
|
172
|
+
this.notifyScheduled = false;
|
|
173
|
+
const state = this.getState();
|
|
174
|
+
this.listeners.forEach((fn) => {
|
|
175
|
+
try {
|
|
176
|
+
fn(state);
|
|
177
|
+
} catch (err) {
|
|
178
|
+
console.error("[StarPro Router] Listener error:", err);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
push(url) {
|
|
184
|
+
if (!url || url === this.currentUrl) return;
|
|
185
|
+
this.currentUrl = url;
|
|
186
|
+
this.history.push(url);
|
|
187
|
+
this.notify();
|
|
188
|
+
}
|
|
189
|
+
replace(url) {
|
|
190
|
+
if (!url) return;
|
|
191
|
+
this.currentUrl = url;
|
|
192
|
+
if (this.history.length > 0) {
|
|
193
|
+
this.history[this.history.length - 1] = url;
|
|
194
|
+
} else {
|
|
195
|
+
this.history.push(url);
|
|
196
|
+
}
|
|
197
|
+
this.notify();
|
|
198
|
+
}
|
|
199
|
+
redirect(url) {
|
|
200
|
+
this.replace(url);
|
|
201
|
+
}
|
|
202
|
+
back() {
|
|
203
|
+
if (this.history.length > 1) {
|
|
204
|
+
this.history.pop();
|
|
205
|
+
this.currentUrl = this.history[this.history.length - 1];
|
|
206
|
+
this.notify();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
forward() {
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
var starproRouter = new StarProRouter("/");
|
|
213
|
+
function useStarProRouter() {
|
|
214
|
+
const [state, setState] = useState(
|
|
215
|
+
() => starproRouter.getState()
|
|
216
|
+
);
|
|
217
|
+
useEffect(() => {
|
|
218
|
+
return starproRouter.subscribe(setState);
|
|
219
|
+
}, []);
|
|
220
|
+
return {
|
|
221
|
+
...state,
|
|
222
|
+
push: (url) => starproRouter.push(url),
|
|
223
|
+
replace: (url) => starproRouter.replace(url),
|
|
224
|
+
redirect: (url) => starproRouter.replace(url),
|
|
225
|
+
back: () => starproRouter.back(),
|
|
226
|
+
forward: () => starproRouter.forward()
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function useStarProPathname() {
|
|
230
|
+
const [pathname, setPathname] = useState(
|
|
231
|
+
() => starproRouter.getState().pathname
|
|
232
|
+
);
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
return starproRouter.subscribe((s) => setPathname(s.pathname));
|
|
235
|
+
}, []);
|
|
236
|
+
return pathname;
|
|
237
|
+
}
|
|
238
|
+
function useStarProSearchParams() {
|
|
239
|
+
const [searchParams, setSearchParams] = useState(
|
|
240
|
+
() => starproRouter.getState().searchParams
|
|
241
|
+
);
|
|
242
|
+
useEffect(() => {
|
|
243
|
+
return starproRouter.subscribe((s) => setSearchParams(s.searchParams));
|
|
244
|
+
}, []);
|
|
245
|
+
return searchParams;
|
|
246
|
+
}
|
|
247
|
+
function useStarProParams() {
|
|
248
|
+
const [params, setParams] = useState(
|
|
249
|
+
() => starproRouter.getState().params
|
|
250
|
+
);
|
|
251
|
+
useEffect(() => {
|
|
252
|
+
return starproRouter.subscribe((s) => setParams(s.params));
|
|
253
|
+
}, []);
|
|
254
|
+
return params;
|
|
255
|
+
}
|
|
256
|
+
function autoRoutesFromGlob(modules, options = {}) {
|
|
257
|
+
const routes = [];
|
|
258
|
+
const { stripGroups = true } = options;
|
|
259
|
+
for (const [rawPath, moduleExports] of Object.entries(modules)) {
|
|
260
|
+
let routePath = rawPath.replace(/^[./]+/, "").replace(/^src\//, "").replace(/^(app|pages)\//, "").replace(/\/page\.(tsx|jsx|js|ts)$/, "").replace(/\/index\.(tsx|jsx|js|ts)$/, "").replace(/^page\.(tsx|jsx|js|ts)$/, "").replace(/^index\.(tsx|jsx|js|ts)$/, "");
|
|
261
|
+
if (stripGroups) {
|
|
262
|
+
routePath = routePath.split("/").filter((segment) => !/^\([^)]+\)$/.test(segment)).join("/");
|
|
263
|
+
}
|
|
264
|
+
routePath = routePath.replace(/\[\.\.\.([^\]]+)\]/g, "*$1").replace(/\[([^\]]+)\]/g, ":$1");
|
|
265
|
+
if (!routePath.startsWith("/")) {
|
|
266
|
+
routePath = "/" + routePath;
|
|
267
|
+
}
|
|
268
|
+
if (routePath === "") {
|
|
269
|
+
routePath = "/";
|
|
270
|
+
}
|
|
271
|
+
const Component = moduleExports?.default || moduleExports;
|
|
272
|
+
if (!Component) continue;
|
|
273
|
+
let label = void 0;
|
|
274
|
+
const isDynamic = routePath.includes(":") || routePath.includes("*");
|
|
275
|
+
if (!isDynamic && routePath !== "/") {
|
|
276
|
+
const lastSegment = routePath.split("/").pop() || "";
|
|
277
|
+
label = lastSegment.split(/[-_]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
278
|
+
if (label) {
|
|
279
|
+
label = label.replace(/\bWater Waste Water\b/gi, "Water & Wastewater");
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
routes.push({
|
|
283
|
+
path: routePath,
|
|
284
|
+
component: Component,
|
|
285
|
+
label,
|
|
286
|
+
exact: routePath === "/"
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
return routes.sort((a, b) => {
|
|
290
|
+
if (a.path === "/") return -1;
|
|
291
|
+
if (b.path === "/") return 1;
|
|
292
|
+
const aDyn = a.path.includes(":") || a.path.includes("*");
|
|
293
|
+
const bDyn = b.path.includes(":") || b.path.includes("*");
|
|
294
|
+
if (aDyn && !bDyn) return 1;
|
|
295
|
+
if (!aDyn && bDyn) return -1;
|
|
296
|
+
return a.path.localeCompare(b.path);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
var StarProRedirectBoundary = class extends React.Component {
|
|
300
|
+
constructor(props) {
|
|
301
|
+
super(props);
|
|
302
|
+
this.state = { hasError: false };
|
|
303
|
+
}
|
|
304
|
+
static getDerivedStateFromError(error) {
|
|
305
|
+
if (error?.isStarProRedirect || error?.message === "NEXT_REDIRECT" || typeof error?.digest === "string" && error.digest.startsWith("NEXT_REDIRECT")) {
|
|
306
|
+
return { hasError: true };
|
|
307
|
+
}
|
|
308
|
+
return { hasError: false };
|
|
309
|
+
}
|
|
310
|
+
componentDidCatch(error) {
|
|
311
|
+
if (error?.isStarProRedirect || error?.message === "NEXT_REDIRECT" || typeof error?.digest === "string" && error.digest.startsWith("NEXT_REDIRECT")) {
|
|
312
|
+
const targetUrl = error.url || (typeof error.digest === "string" ? error.digest.split(";")[2] : null);
|
|
313
|
+
if (targetUrl) {
|
|
314
|
+
starproRouter.replace(targetUrl);
|
|
315
|
+
}
|
|
316
|
+
Promise.resolve().then(() => {
|
|
317
|
+
this.setState({ hasError: false });
|
|
318
|
+
});
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
console.error("[StarPro Router] Page render error:", error);
|
|
322
|
+
}
|
|
323
|
+
render() {
|
|
324
|
+
if (this.state.hasError) {
|
|
325
|
+
return this.props.fallback || null;
|
|
326
|
+
}
|
|
327
|
+
return this.props.children;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
var StarProRouterView = ({
|
|
331
|
+
routes,
|
|
332
|
+
defaultRoute,
|
|
333
|
+
payload,
|
|
334
|
+
layout: CustomLayout,
|
|
335
|
+
title,
|
|
336
|
+
badge,
|
|
337
|
+
showNav,
|
|
338
|
+
themeColor = "#059669",
|
|
339
|
+
// emerald
|
|
340
|
+
fallback
|
|
341
|
+
}) => {
|
|
342
|
+
const [routeState, setRouteState] = useState(
|
|
343
|
+
() => starproRouter.getState()
|
|
344
|
+
);
|
|
345
|
+
useEffect(() => {
|
|
346
|
+
starproRouter.setRoutes(routes);
|
|
347
|
+
const current = starproRouter.getState().pathname;
|
|
348
|
+
const hasExactRoot = routes.some((r) => r.path === "/" || r.path === "");
|
|
349
|
+
if (current === "/" || current === "") {
|
|
350
|
+
if (defaultRoute) {
|
|
351
|
+
starproRouter.replace(defaultRoute);
|
|
352
|
+
} else if (!hasExactRoot && routes.length > 0) {
|
|
353
|
+
const first = routes.find((r) => r.path !== "/" && !r.path.includes(":"));
|
|
354
|
+
if (first) {
|
|
355
|
+
starproRouter.replace(first.path);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return starproRouter.subscribe(setRouteState);
|
|
360
|
+
}, [routes, defaultRoute]);
|
|
361
|
+
const { pathname, searchParams, params } = routeState;
|
|
362
|
+
const navTabs = routes.filter((r) => Boolean(r.label));
|
|
363
|
+
const shouldShowNav = showNav !== void 0 ? showNav : !CustomLayout && navTabs.length > 0;
|
|
364
|
+
let MatchedComponent = null;
|
|
365
|
+
for (const r of routes) {
|
|
366
|
+
const match = matchRoute(r.path, pathname);
|
|
367
|
+
if (match.matched) {
|
|
368
|
+
MatchedComponent = r.component;
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
const activeTab = navTabs.find((tab) => {
|
|
373
|
+
if (tab.path === pathname) return true;
|
|
374
|
+
if (tab.path !== "/" && pathname.startsWith(tab.path)) return true;
|
|
375
|
+
return false;
|
|
376
|
+
});
|
|
377
|
+
const pageContent = MatchedComponent ? /* @__PURE__ */ jsx(
|
|
378
|
+
MatchedComponent,
|
|
379
|
+
{
|
|
380
|
+
params,
|
|
381
|
+
searchParams,
|
|
382
|
+
payload
|
|
383
|
+
}
|
|
384
|
+
) : fallback ? fallback : /* @__PURE__ */ jsxs("div", { className: "p-8 text-center border border-dashed border-zinc-300 dark:border-zinc-700 rounded-xl my-4", children: [
|
|
385
|
+
/* @__PURE__ */ jsxs("h3", { className: "text-base font-semibold text-zinc-800 dark:text-zinc-200", children: [
|
|
386
|
+
"Page Not Found (",
|
|
387
|
+
pathname,
|
|
388
|
+
")"
|
|
389
|
+
] }),
|
|
390
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-zinc-500 mt-1", children: "Rute ini belum didaftarkan di StarPro plugin router." }),
|
|
391
|
+
defaultRoute && /* @__PURE__ */ jsx(
|
|
392
|
+
"button",
|
|
393
|
+
{
|
|
394
|
+
type: "button",
|
|
395
|
+
onClick: () => starproRouter.push(defaultRoute),
|
|
396
|
+
style: { backgroundColor: themeColor },
|
|
397
|
+
className: "mt-4 px-4 py-2 text-xs font-medium text-white rounded-lg cursor-pointer",
|
|
398
|
+
children: "Kembali ke Beranda"
|
|
399
|
+
}
|
|
400
|
+
)
|
|
401
|
+
] });
|
|
402
|
+
return /* @__PURE__ */ jsxs("div", { className: "starpro-universal-router-view w-full min-h-screen text-zinc-900 dark:text-zinc-100", children: [
|
|
403
|
+
shouldShowNav && navTabs.length > 0 && /* @__PURE__ */ jsx("div", { className: "sticky top-0 z-30 mb-6 border-b border-zinc-200 bg-white/95 pb-3 pt-2 backdrop-blur dark:border-zinc-800 dark:bg-zinc-900/95", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [
|
|
404
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2.5", children: [
|
|
405
|
+
/* @__PURE__ */ jsx(
|
|
406
|
+
"span",
|
|
407
|
+
{
|
|
408
|
+
style: { backgroundColor: themeColor },
|
|
409
|
+
className: "flex h-8 w-8 items-center justify-center rounded-lg font-bold text-white shadow-xs text-xs",
|
|
410
|
+
children: badge || "PRO"
|
|
411
|
+
}
|
|
412
|
+
),
|
|
413
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
414
|
+
title && /* @__PURE__ */ jsx(
|
|
415
|
+
"div",
|
|
416
|
+
{
|
|
417
|
+
style: { color: themeColor },
|
|
418
|
+
className: "text-xs font-semibold tracking-wider uppercase",
|
|
419
|
+
children: title
|
|
420
|
+
}
|
|
421
|
+
),
|
|
422
|
+
/* @__PURE__ */ jsx("div", { className: "text-xs text-zinc-500 dark:text-zinc-400", children: pathname })
|
|
423
|
+
] })
|
|
424
|
+
] }),
|
|
425
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap items-center gap-1 rounded-xl bg-zinc-100 p-1 dark:bg-zinc-800", children: navTabs.map((tab) => {
|
|
426
|
+
const isActive = activeTab?.path === tab.path;
|
|
427
|
+
return /* @__PURE__ */ jsxs(
|
|
428
|
+
"button",
|
|
429
|
+
{
|
|
430
|
+
type: "button",
|
|
431
|
+
onClick: () => starproRouter.push(tab.path),
|
|
432
|
+
className: `flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-xs font-medium transition-all duration-150 cursor-pointer ${isActive ? "bg-white text-emerald-600 shadow-xs dark:bg-zinc-900 dark:text-emerald-400" : "text-zinc-600 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-100"}`,
|
|
433
|
+
children: [
|
|
434
|
+
tab.icon && /* @__PURE__ */ jsx("span", { children: tab.icon }),
|
|
435
|
+
/* @__PURE__ */ jsx("span", { children: tab.label })
|
|
436
|
+
]
|
|
437
|
+
},
|
|
438
|
+
tab.path
|
|
439
|
+
);
|
|
440
|
+
}) })
|
|
441
|
+
] }) }),
|
|
442
|
+
/* @__PURE__ */ jsx("div", { className: "starpro-page-container", children: /* @__PURE__ */ jsx(StarProRedirectBoundary, { fallback, children: CustomLayout ? /* @__PURE__ */ jsx(
|
|
443
|
+
CustomLayout,
|
|
444
|
+
{
|
|
445
|
+
params,
|
|
446
|
+
searchParams,
|
|
447
|
+
payload,
|
|
448
|
+
children: pageContent
|
|
449
|
+
}
|
|
450
|
+
) : pageContent }) })
|
|
451
|
+
] });
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
// src/define-app.tsx
|
|
455
|
+
import { createRoot } from "react-dom/client";
|
|
456
|
+
|
|
457
|
+
// src/define-plugin.ts
|
|
458
|
+
function defineStarProPlugin(options) {
|
|
459
|
+
if (typeof window === "undefined") return;
|
|
460
|
+
const {
|
|
461
|
+
pluginId = "default",
|
|
462
|
+
onMount,
|
|
463
|
+
onUnmount,
|
|
464
|
+
autoInjectAuth = true
|
|
465
|
+
} = options;
|
|
466
|
+
window.StarProPlugins = window.StarProPlugins || {};
|
|
467
|
+
const pluginModule = {
|
|
468
|
+
mount: function(container, payload) {
|
|
469
|
+
const targetElement = typeof container === "string" ? document.getElementById(container) : container;
|
|
470
|
+
if (!targetElement) {
|
|
471
|
+
console.error(
|
|
472
|
+
`[StarPro Plugin: ${pluginId}] Target container element not found!`
|
|
473
|
+
);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
if (autoInjectAuth) {
|
|
477
|
+
setupStarProAuthBridge(payload);
|
|
478
|
+
}
|
|
479
|
+
let cleanup = void 0;
|
|
480
|
+
if (typeof onMount === "function") {
|
|
481
|
+
cleanup = onMount(targetElement, payload);
|
|
482
|
+
}
|
|
483
|
+
return function unmount() {
|
|
484
|
+
if (typeof cleanup === "function") {
|
|
485
|
+
try {
|
|
486
|
+
cleanup();
|
|
487
|
+
} catch (err) {
|
|
488
|
+
console.warn(`[StarPro Plugin: ${pluginId}] Error in cleanup:`, err);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
if (typeof onUnmount === "function") {
|
|
492
|
+
try {
|
|
493
|
+
onUnmount();
|
|
494
|
+
} catch (err) {
|
|
495
|
+
console.warn(
|
|
496
|
+
`[StarPro Plugin: ${pluginId}] Error in onUnmount:`,
|
|
497
|
+
err
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
targetElement.innerHTML = "";
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
window.StarProPlugins[pluginId] = pluginModule;
|
|
506
|
+
window.StarProPlugins["default"] = pluginModule;
|
|
507
|
+
window.mountStarProPlugin = pluginModule.mount;
|
|
508
|
+
console.log(`\u2713 [StarPro Plugin SDK] Registered plugin "${pluginId}"`);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// src/define-app.tsx
|
|
512
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
513
|
+
function defineStarProApp(options = {}) {
|
|
514
|
+
const {
|
|
515
|
+
pluginId = "default",
|
|
516
|
+
defaultRoute,
|
|
517
|
+
component: RootComponent,
|
|
518
|
+
layout: CustomLayout,
|
|
519
|
+
title,
|
|
520
|
+
badge,
|
|
521
|
+
themeColor,
|
|
522
|
+
showNav,
|
|
523
|
+
autoInjectAuth = true,
|
|
524
|
+
banner = true,
|
|
525
|
+
fallback,
|
|
526
|
+
render: customRender
|
|
527
|
+
} = options;
|
|
528
|
+
let resolvedRoutes = options.routes || [];
|
|
529
|
+
if (resolvedRoutes.length === 0 && typeof window !== "undefined") {
|
|
530
|
+
if (window.__STARPRO_ROUTES__ && Array.isArray(window.__STARPRO_ROUTES__)) {
|
|
531
|
+
resolvedRoutes = window.__STARPRO_ROUTES__;
|
|
532
|
+
} else {
|
|
533
|
+
try {
|
|
534
|
+
const virtualModule = __require("starpro:routes");
|
|
535
|
+
if (virtualModule) {
|
|
536
|
+
resolvedRoutes = virtualModule.default || virtualModule.routes || virtualModule;
|
|
537
|
+
}
|
|
538
|
+
} catch (e) {
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
defineStarProPlugin({
|
|
543
|
+
pluginId,
|
|
544
|
+
autoInjectAuth,
|
|
545
|
+
onMount: (container, payload) => {
|
|
546
|
+
let contentNode;
|
|
547
|
+
if (RootComponent) {
|
|
548
|
+
contentNode = /* @__PURE__ */ jsx2(RootComponent, { payload });
|
|
549
|
+
} else {
|
|
550
|
+
contentNode = /* @__PURE__ */ jsx2(
|
|
551
|
+
StarProRouterView,
|
|
552
|
+
{
|
|
553
|
+
routes: resolvedRoutes,
|
|
554
|
+
defaultRoute,
|
|
555
|
+
payload,
|
|
556
|
+
layout: CustomLayout,
|
|
557
|
+
title,
|
|
558
|
+
badge,
|
|
559
|
+
showNav,
|
|
560
|
+
themeColor,
|
|
561
|
+
fallback
|
|
562
|
+
}
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
const appTree = /* @__PURE__ */ jsx2(StarProPluginWrapper, { payload, banner, children: contentNode });
|
|
566
|
+
if (typeof customRender === "function") {
|
|
567
|
+
const cleanup = customRender(appTree, container);
|
|
568
|
+
return () => {
|
|
569
|
+
if (typeof cleanup === "function") {
|
|
570
|
+
try {
|
|
571
|
+
cleanup();
|
|
572
|
+
} catch (e) {
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
container.innerHTML = "";
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
const root = createRoot(container);
|
|
579
|
+
root.render(appTree);
|
|
580
|
+
return () => {
|
|
581
|
+
try {
|
|
582
|
+
root.unmount();
|
|
583
|
+
} catch (e) {
|
|
584
|
+
}
|
|
585
|
+
container.innerHTML = "";
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
var createStarProApp = defineStarProApp;
|
|
591
|
+
|
|
592
|
+
// src/react.tsx
|
|
593
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
594
|
+
function useStarProAuth() {
|
|
595
|
+
const [authState, setAuthState] = useState2(() => {
|
|
596
|
+
if (typeof window === "undefined") {
|
|
597
|
+
return {
|
|
598
|
+
accessToken: null,
|
|
599
|
+
refreshToken: null,
|
|
600
|
+
user: null,
|
|
601
|
+
isPlugin: false,
|
|
602
|
+
isLoading: true
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
const token = localStorage.getItem("accessToken") || localStorage.getItem("token");
|
|
606
|
+
const refresh = localStorage.getItem("refreshToken");
|
|
607
|
+
let userObj = null;
|
|
608
|
+
try {
|
|
609
|
+
const storedUser = localStorage.getItem("user");
|
|
610
|
+
if (storedUser) userObj = JSON.parse(storedUser);
|
|
611
|
+
} catch (e) {
|
|
612
|
+
}
|
|
613
|
+
return {
|
|
614
|
+
accessToken: token,
|
|
615
|
+
refreshToken: refresh,
|
|
616
|
+
user: userObj,
|
|
617
|
+
isPlugin: isStarProPlugin(),
|
|
618
|
+
isLoading: false
|
|
619
|
+
};
|
|
620
|
+
});
|
|
621
|
+
return authState;
|
|
622
|
+
}
|
|
623
|
+
var StarProPluginWrapper = ({
|
|
624
|
+
payload,
|
|
625
|
+
children,
|
|
626
|
+
banner = true
|
|
627
|
+
}) => {
|
|
628
|
+
const user = payload?.user;
|
|
629
|
+
return /* @__PURE__ */ jsxs2("div", { className: "starpro-plugin-root", children: [
|
|
630
|
+
banner && user && /* @__PURE__ */ jsxs2(
|
|
631
|
+
"div",
|
|
632
|
+
{
|
|
633
|
+
style: {
|
|
634
|
+
background: "#f0fdf4",
|
|
635
|
+
border: "1px solid #bbf7d0",
|
|
636
|
+
color: "#166534",
|
|
637
|
+
padding: "8px 14px",
|
|
638
|
+
fontSize: "12px",
|
|
639
|
+
borderRadius: "8px",
|
|
640
|
+
marginBottom: "16px",
|
|
641
|
+
display: "flex",
|
|
642
|
+
justifyContent: "space-between",
|
|
643
|
+
alignItems: "center",
|
|
644
|
+
fontFamily: "system-ui, -apple-system, sans-serif"
|
|
645
|
+
},
|
|
646
|
+
children: [
|
|
647
|
+
/* @__PURE__ */ jsxs2("span", { children: [
|
|
648
|
+
"\u2713 Terhubung ke StarPro sebagai: ",
|
|
649
|
+
/* @__PURE__ */ jsx3("strong", { children: user.name || user.email })
|
|
650
|
+
] }),
|
|
651
|
+
/* @__PURE__ */ jsx3("span", { style: { fontSize: "11px", opacity: 0.8 }, children: "Login Otomatis Aktif" })
|
|
652
|
+
]
|
|
653
|
+
}
|
|
654
|
+
),
|
|
655
|
+
children
|
|
656
|
+
] });
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
export {
|
|
660
|
+
setupStarProAuthBridge,
|
|
661
|
+
isStarProPlugin,
|
|
662
|
+
defineStarProPlugin,
|
|
663
|
+
matchRoute,
|
|
664
|
+
StarProRouter,
|
|
665
|
+
starproRouter,
|
|
666
|
+
useStarProRouter,
|
|
667
|
+
useStarProPathname,
|
|
668
|
+
useStarProSearchParams,
|
|
669
|
+
useStarProParams,
|
|
670
|
+
autoRoutesFromGlob,
|
|
671
|
+
StarProRedirectBoundary,
|
|
672
|
+
StarProRouterView,
|
|
673
|
+
useStarProAuth,
|
|
674
|
+
StarProPluginWrapper,
|
|
675
|
+
defineStarProApp,
|
|
676
|
+
createStarProApp
|
|
677
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
__require
|
|
10
|
+
};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { S as StarProAuthPayload, D as DefinePluginOptions } from './react-DS5S7U6B.mjs';
|
|
2
|
+
export { M as MountCleanupFn, P as PluginMountHandler, a as StarProAppOptions, b as StarProAuthState, c as StarProPluginWrapper, d as StarProPluginWrapperProps, e as StarProRedirectBoundary, f as StarProRoute, g as StarProRouteState, h as StarProRouter, i as StarProRouterView, j as StarProRouterViewProps, k as StarProUser, l as autoRoutesFromGlob, m as createStarProApp, n as defineStarProApp, o as matchRoute, s as starproRouter, u as useStarProAuth, p as useStarProParams, q as useStarProPathname, r as useStarProRouter, t as useStarProSearchParams } from './react-DS5S7U6B.mjs';
|
|
3
|
+
import 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Injects StarPro authentication tokens across all standard channels:
|
|
7
|
+
* - localStorage & sessionStorage
|
|
8
|
+
* - Global Axios default headers & interceptors
|
|
9
|
+
* - Browser native window.fetch() interceptor
|
|
10
|
+
*/
|
|
11
|
+
declare function setupStarProAuthBridge(payload: StarProAuthPayload): void;
|
|
12
|
+
/**
|
|
13
|
+
* Returns true if the current application is currently running as a StarPro plugin.
|
|
14
|
+
*/
|
|
15
|
+
declare function isStarProPlugin(): boolean;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Universal registration function to define a StarPro plugin in any JavaScript web.
|
|
19
|
+
* Supports React, Next.js, Vue, Svelte, and Vanilla JS.
|
|
20
|
+
*/
|
|
21
|
+
declare function defineStarProPlugin(options: DefinePluginOptions): void;
|
|
22
|
+
|
|
23
|
+
export { DefinePluginOptions, StarProAuthPayload, defineStarProPlugin, isStarProPlugin, setupStarProAuthBridge };
|