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