teraprox-core-sdk 0.2.0 → 0.3.2

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/dist/dev.js ADDED
@@ -0,0 +1,470 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/dev.ts
21
+ var dev_exports = {};
22
+ __export(dev_exports, {
23
+ DevShell: () => DevShell,
24
+ extractDevRoutes: () => extractDevRoutes
25
+ });
26
+ module.exports = __toCommonJS(dev_exports);
27
+
28
+ // src/dev/DevShell.tsx
29
+ var import_react = require("react");
30
+ var import_react_router_dom = require("react-router-dom");
31
+ var import_jsx_runtime = require("react/jsx-runtime");
32
+ var MenuIcon = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
33
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "3", y1: "6", x2: "21", y2: "6" }),
34
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "3", y1: "12", x2: "21", y2: "12" }),
35
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "3", y1: "18", x2: "21", y2: "18" })
36
+ ] });
37
+ var CloseIcon = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
38
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
39
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
40
+ ] });
41
+ var SearchIcon = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
42
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "11", cy: "11", r: "8" }),
43
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "21", y1: "21", x2: "16.65", y2: "16.65" })
44
+ ] });
45
+ var ChevronIcon = ({ open }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
46
+ "svg",
47
+ {
48
+ width: "12",
49
+ height: "12",
50
+ viewBox: "0 0 24 24",
51
+ fill: "none",
52
+ stroke: "currentColor",
53
+ strokeWidth: "2.5",
54
+ strokeLinecap: "round",
55
+ strokeLinejoin: "round",
56
+ style: { transform: open ? "rotate(90deg)" : "rotate(0)", transition: "transform 0.2s ease" },
57
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: "9 18 15 12 9 6" })
58
+ }
59
+ );
60
+ function DevShell({ appName, routes, children }) {
61
+ const hostedByCore = typeof window !== "undefined" && window.__TERAPROX_HOSTED_BY_CORE__ === true;
62
+ if (hostedByCore) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
63
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
64
+ children,
65
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DevPanel, { appName, routes })
66
+ ] });
67
+ }
68
+ function DevPanel({ appName, routes }) {
69
+ const [show, setShow] = (0, import_react.useState)(false);
70
+ const [search, setSearch] = (0, import_react.useState)("");
71
+ const [openGroups, setOpenGroups] = (0, import_react.useState)(/* @__PURE__ */ new Set());
72
+ const searchRef = (0, import_react.useRef)(null);
73
+ const navigate = (0, import_react_router_dom.useNavigate)();
74
+ const location = (0, import_react_router_dom.useLocation)();
75
+ const grouped = (0, import_react.useMemo)(() => {
76
+ const map = /* @__PURE__ */ new Map();
77
+ const term = search.toLowerCase();
78
+ const filtered = term ? routes.filter(
79
+ (r) => r.label.toLowerCase().includes(term) || r.path.toLowerCase().includes(term)
80
+ ) : routes;
81
+ for (const route of filtered) {
82
+ const cat = route.category || "Geral";
83
+ if (!map.has(cat)) map.set(cat, []);
84
+ map.get(cat).push(route);
85
+ }
86
+ return map;
87
+ }, [routes, search]);
88
+ (0, import_react.useEffect)(() => {
89
+ setOpenGroups(new Set(grouped.keys()));
90
+ }, [grouped]);
91
+ (0, import_react.useEffect)(() => {
92
+ if (show) {
93
+ const t = setTimeout(() => {
94
+ var _a;
95
+ return (_a = searchRef.current) == null ? void 0 : _a.focus();
96
+ }, 150);
97
+ return () => clearTimeout(t);
98
+ }
99
+ }, [show]);
100
+ (0, import_react.useEffect)(() => {
101
+ const handler = (e) => {
102
+ if ((e.ctrlKey || e.metaKey) && e.shiftKey && (e.key === "D" || e.key === "d")) {
103
+ e.preventDefault();
104
+ setShow((s) => !s);
105
+ }
106
+ if (e.key === "Escape" && show) {
107
+ setShow(false);
108
+ }
109
+ };
110
+ window.addEventListener("keydown", handler);
111
+ return () => window.removeEventListener("keydown", handler);
112
+ }, [show]);
113
+ const handleNavigate = (0, import_react.useCallback)((path) => {
114
+ navigate(path);
115
+ setShow(false);
116
+ }, [navigate]);
117
+ const toggleGroup = (0, import_react.useCallback)((category) => {
118
+ setOpenGroups((prev) => {
119
+ const next = new Set(prev);
120
+ if (next.has(category)) next.delete(category);
121
+ else next.add(category);
122
+ return next;
123
+ });
124
+ }, []);
125
+ const totalRoutes = routes.length;
126
+ const currentPath = location.pathname;
127
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
128
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: S.devBar, children: [
129
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: S.devBarLeft, children: [
130
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: S.devBadge, children: "DEV" }),
131
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: S.devAppName, children: appName })
132
+ ] }),
133
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: S.devBarCenter, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { style: S.devCurrentPath, children: currentPath }) }),
134
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
135
+ "button",
136
+ {
137
+ style: S.devBarButton,
138
+ onClick: () => setShow(true),
139
+ title: "Abrir cat\xE1logo de rotas (Ctrl+Shift+D)",
140
+ children: [
141
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuIcon, {}),
142
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { marginLeft: 6 }, children: [
143
+ totalRoutes,
144
+ " rotas"
145
+ ] })
146
+ ]
147
+ }
148
+ )
149
+ ] }),
150
+ show && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: S.backdrop, onClick: () => setShow(false) }),
151
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
152
+ ...S.sidebar,
153
+ transform: show ? "translateX(0)" : "translateX(-100%)"
154
+ }, children: [
155
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: S.sidebarHeader, children: [
156
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
157
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: S.sidebarTitle, children: appName }),
158
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: S.sidebarSubtitle, children: [
159
+ totalRoutes,
160
+ " rotas dispon\xEDveis \xB7 Ctrl+Shift+D"
161
+ ] })
162
+ ] }),
163
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { style: S.closeButton, onClick: () => setShow(false), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CloseIcon, {}) })
164
+ ] }),
165
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: S.searchContainer, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: S.searchInputWrapper, children: [
166
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: S.searchIconWrap, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SearchIcon, {}) }),
167
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
168
+ "input",
169
+ {
170
+ ref: searchRef,
171
+ type: "text",
172
+ placeholder: "Buscar rota...",
173
+ value: search,
174
+ onChange: (e) => setSearch(e.target.value),
175
+ style: S.searchInput
176
+ }
177
+ ),
178
+ search && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { style: S.searchClear, onClick: () => setSearch(""), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CloseIcon, {}) })
179
+ ] }) }),
180
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: S.routeList, children: [
181
+ Array.from(grouped.entries()).map(([category, categoryRoutes]) => {
182
+ const isOpen = openGroups.has(category);
183
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
184
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", { style: S.categoryHeader, onClick: () => toggleGroup(category), children: [
185
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronIcon, { open: isOpen }),
186
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: S.categoryTitle, children: category }),
187
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: S.categoryCount, children: categoryRoutes.length })
188
+ ] }),
189
+ isOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: categoryRoutes.map((route) => {
190
+ const isActive = currentPath === route.path;
191
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
192
+ "button",
193
+ {
194
+ style: {
195
+ ...S.routeItem,
196
+ ...isActive ? S.routeItemActive : {}
197
+ },
198
+ onClick: () => handleNavigate(route.path),
199
+ children: [
200
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: isActive ? S.routeLabelActive : S.routeLabel, children: route.label }),
201
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { style: isActive ? S.routePathActive : S.routePath, children: route.path })
202
+ ]
203
+ },
204
+ route.path
205
+ );
206
+ }) })
207
+ ] }, category);
208
+ }),
209
+ grouped.size === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: S.emptyState, children: [
210
+ "Nenhuma rota encontrada para \u201C",
211
+ search,
212
+ "\u201D"
213
+ ] })
214
+ ] })
215
+ ] })
216
+ ] });
217
+ }
218
+ var S = {
219
+ /* Dev Bar (fixed bottom) */
220
+ devBar: {
221
+ position: "fixed",
222
+ bottom: 0,
223
+ left: 0,
224
+ right: 0,
225
+ height: 36,
226
+ background: "#1a1a2e",
227
+ color: "#e0e0e0",
228
+ display: "flex",
229
+ alignItems: "center",
230
+ justifyContent: "space-between",
231
+ padding: "0 12px",
232
+ zIndex: 9998,
233
+ borderTop: "2px solid #0d6efd",
234
+ fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace',
235
+ fontSize: "0.8rem"
236
+ },
237
+ devBarLeft: {
238
+ display: "flex",
239
+ alignItems: "center",
240
+ gap: 8
241
+ },
242
+ devBadge: {
243
+ background: "#0d6efd",
244
+ color: "#fff",
245
+ padding: "2px 6px",
246
+ borderRadius: 3,
247
+ fontSize: "0.65rem",
248
+ fontWeight: 700,
249
+ letterSpacing: 1
250
+ },
251
+ devAppName: { fontWeight: 600 },
252
+ devBarCenter: { flex: 1, textAlign: "center" },
253
+ devCurrentPath: { color: "#82aaff", fontSize: "0.8rem" },
254
+ devBarButton: {
255
+ background: "transparent",
256
+ border: "1px solid #444",
257
+ borderRadius: 4,
258
+ color: "#e0e0e0",
259
+ padding: "3px 10px",
260
+ cursor: "pointer",
261
+ display: "flex",
262
+ alignItems: "center",
263
+ fontSize: "0.75rem"
264
+ },
265
+ /* Backdrop */
266
+ backdrop: {
267
+ position: "fixed",
268
+ top: 0,
269
+ left: 0,
270
+ right: 0,
271
+ bottom: 0,
272
+ background: "rgba(0, 0, 0, 0.4)",
273
+ zIndex: 9999
274
+ },
275
+ /* Sidebar */
276
+ sidebar: {
277
+ position: "fixed",
278
+ top: 0,
279
+ left: 0,
280
+ bottom: 0,
281
+ width: 380,
282
+ maxWidth: "90vw",
283
+ background: "#fff",
284
+ zIndex: 1e4,
285
+ transition: "transform 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
286
+ display: "flex",
287
+ flexDirection: "column",
288
+ boxShadow: "4px 0 16px rgba(0, 0, 0, 0.15)"
289
+ },
290
+ sidebarHeader: {
291
+ display: "flex",
292
+ justifyContent: "space-between",
293
+ alignItems: "flex-start",
294
+ padding: "16px 16px 12px",
295
+ borderBottom: "1px solid #e9ecef",
296
+ background: "#f8f9fa"
297
+ },
298
+ sidebarTitle: {
299
+ fontSize: "1.1rem",
300
+ fontWeight: 700,
301
+ color: "#1a1a2e"
302
+ },
303
+ sidebarSubtitle: {
304
+ fontSize: "0.75rem",
305
+ color: "#6c757d",
306
+ marginTop: 2
307
+ },
308
+ closeButton: {
309
+ background: "transparent",
310
+ border: "none",
311
+ cursor: "pointer",
312
+ padding: 4,
313
+ color: "#6c757d",
314
+ display: "flex",
315
+ alignItems: "center"
316
+ },
317
+ /* Search */
318
+ searchContainer: {
319
+ padding: "12px 16px",
320
+ borderBottom: "1px solid #e9ecef"
321
+ },
322
+ searchInputWrapper: {
323
+ position: "relative",
324
+ display: "flex",
325
+ alignItems: "center"
326
+ },
327
+ searchIconWrap: {
328
+ position: "absolute",
329
+ left: 10,
330
+ color: "#adb5bd",
331
+ display: "flex",
332
+ alignItems: "center",
333
+ pointerEvents: "none"
334
+ },
335
+ searchInput: {
336
+ width: "100%",
337
+ padding: "6px 30px 6px 32px",
338
+ border: "1px solid #dee2e6",
339
+ borderRadius: 6,
340
+ fontSize: "0.85rem",
341
+ outline: "none"
342
+ },
343
+ searchClear: {
344
+ position: "absolute",
345
+ right: 6,
346
+ background: "transparent",
347
+ border: "none",
348
+ cursor: "pointer",
349
+ padding: 2,
350
+ color: "#adb5bd",
351
+ display: "flex",
352
+ alignItems: "center"
353
+ },
354
+ /* Route List */
355
+ routeList: {
356
+ flex: 1,
357
+ overflowY: "auto",
358
+ paddingBottom: 40
359
+ },
360
+ /* Category Header */
361
+ categoryHeader: {
362
+ width: "100%",
363
+ display: "flex",
364
+ alignItems: "center",
365
+ gap: 8,
366
+ padding: "10px 16px",
367
+ background: "#f8f9fa",
368
+ border: "none",
369
+ borderBottom: "1px solid #e9ecef",
370
+ cursor: "pointer",
371
+ fontSize: "0.8rem",
372
+ fontWeight: 600,
373
+ color: "#495057",
374
+ textAlign: "left"
375
+ },
376
+ categoryTitle: {
377
+ flex: 1,
378
+ textTransform: "uppercase",
379
+ letterSpacing: 0.5
380
+ },
381
+ categoryCount: {
382
+ background: "#e9ecef",
383
+ color: "#495057",
384
+ padding: "1px 8px",
385
+ borderRadius: 10,
386
+ fontSize: "0.7rem",
387
+ fontWeight: 600
388
+ },
389
+ /* Route Item */
390
+ routeItem: {
391
+ width: "100%",
392
+ display: "flex",
393
+ justifyContent: "space-between",
394
+ alignItems: "center",
395
+ padding: "8px 16px 8px 28px",
396
+ border: "none",
397
+ borderBottom: "1px solid #f1f3f5",
398
+ background: "#fff",
399
+ cursor: "pointer",
400
+ textAlign: "left"
401
+ },
402
+ routeItemActive: {
403
+ background: "#e7f1ff",
404
+ borderLeft: "3px solid #0d6efd",
405
+ paddingLeft: 25
406
+ },
407
+ routeLabel: {
408
+ fontSize: "0.85rem",
409
+ color: "#212529"
410
+ },
411
+ routeLabelActive: {
412
+ fontSize: "0.85rem",
413
+ color: "#0d6efd",
414
+ fontWeight: 600
415
+ },
416
+ routePath: {
417
+ fontSize: "0.65rem",
418
+ color: "#adb5bd",
419
+ fontFamily: "monospace",
420
+ marginLeft: 8,
421
+ flexShrink: 0
422
+ },
423
+ routePathActive: {
424
+ fontSize: "0.65rem",
425
+ color: "#0d6efd",
426
+ fontFamily: "monospace",
427
+ marginLeft: 8,
428
+ flexShrink: 0,
429
+ opacity: 0.7
430
+ },
431
+ /* Empty State */
432
+ emptyState: {
433
+ padding: "24px 16px",
434
+ textAlign: "center",
435
+ color: "#adb5bd",
436
+ fontSize: "0.85rem"
437
+ }
438
+ };
439
+
440
+ // src/dev/extractDevRoutes.ts
441
+ var SYSTEM_PATHS = /* @__PURE__ */ new Set(["/", "/Login", "/login", "/errorScreen", "/acessoNaoPermitido"]);
442
+ function extractDevRoutes(routesConfig) {
443
+ const seen = /* @__PURE__ */ new Set();
444
+ return routesConfig.flatMap((serviceConfig) => {
445
+ const category = capitalize(serviceConfig.service || "Geral");
446
+ return (serviceConfig.routes || []).filter((route) => {
447
+ var _a;
448
+ const path = (_a = route == null ? void 0 : route.configuration) == null ? void 0 : _a.path;
449
+ if (!path || SYSTEM_PATHS.has(path) || seen.has(path)) return false;
450
+ seen.add(path);
451
+ return true;
452
+ }).map((route) => ({
453
+ label: pathToLabel(route.configuration.path),
454
+ path: route.configuration.path,
455
+ category
456
+ }));
457
+ });
458
+ }
459
+ function pathToLabel(path) {
460
+ const name = path.replace(/^\//, "").split("/").pop() || path;
461
+ return name.replace(/([A-Z])/g, " $1").replace(/^./, (s) => s.toUpperCase()).trim();
462
+ }
463
+ function capitalize(str) {
464
+ return str.charAt(0).toUpperCase() + str.slice(1);
465
+ }
466
+ // Annotate the CommonJS export names for ESM import in node:
467
+ 0 && (module.exports = {
468
+ DevShell,
469
+ extractDevRoutes
470
+ });