teraprox-core-sdk 0.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/dist/index.js ADDED
@@ -0,0 +1,1015 @@
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/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ CoreServiceContext: () => CoreServiceContext,
34
+ RecursoDisplayer: () => RecursoDisplayer_default,
35
+ branchLevelReducer: () => branchLevelReducer_default,
36
+ clearBranchLevelForm: () => clearBranchLevelForm,
37
+ pickTextColorBasedOnBgColorAdvanced: () => pickTextColorBasedOnBgColorAdvanced,
38
+ populateToEdit: () => populateToEdit,
39
+ setColor: () => setColor,
40
+ setExcludeLevels: () => setExcludeLevels,
41
+ setHaveComponente: () => setHaveComponente,
42
+ setLevel: () => setLevel,
43
+ setLevels: () => setLevels,
44
+ setNome: () => setNome,
45
+ useCoreService: () => useCoreService,
46
+ useHttpController: () => useHttpController,
47
+ useMatchingObject: () => useMatchingObject,
48
+ useNavigator: () => useNavigator,
49
+ useNotifications: () => useNotifications,
50
+ useToast: () => useToast
51
+ });
52
+ module.exports = __toCommonJS(index_exports);
53
+
54
+ // src/context/CoreServiceContext.ts
55
+ var import_react = require("react");
56
+ var CoreServiceContext = (0, import_react.createContext)(null);
57
+
58
+ // src/hooks/useCoreService.ts
59
+ var import_react2 = require("react");
60
+ function useCoreService() {
61
+ const ctx = (0, import_react2.useContext)(CoreServiceContext);
62
+ if (!ctx) {
63
+ throw new Error(
64
+ "useCoreService must be used within a CoreServiceProvider. Are you running outside Core (standalone mode)?"
65
+ );
66
+ }
67
+ return ctx;
68
+ }
69
+
70
+ // src/hooks/useHttpController.ts
71
+ var import_react3 = require("react");
72
+ function useHttpController(context, baseEndPoint) {
73
+ const { createController } = useCoreService();
74
+ return (0, import_react3.useMemo)(
75
+ () => createController(context, baseEndPoint),
76
+ [createController, context, baseEndPoint]
77
+ );
78
+ }
79
+
80
+ // src/hooks/useToast.ts
81
+ function useToast() {
82
+ return useCoreService().toast;
83
+ }
84
+
85
+ // src/hooks/useMatchingObject.ts
86
+ var import_react4 = require("react");
87
+ function useMatchingObject(context, location, refresher, deps = []) {
88
+ const { subscribe, unsubscribe } = useCoreService();
89
+ (0, import_react4.useEffect)(() => {
90
+ const mo = { context, location, refresher };
91
+ subscribe(mo);
92
+ return () => unsubscribe(mo);
93
+ }, [context, location, subscribe, unsubscribe, ...deps]);
94
+ }
95
+
96
+ // src/hooks/useNotifications.ts
97
+ var import_react_redux = require("react-redux");
98
+ function useNotifications() {
99
+ return (0, import_react_redux.useSelector)((state) => state.notification);
100
+ }
101
+
102
+ // src/hooks/useNavigator.ts
103
+ var import_react5 = require("react");
104
+ var import_react_router_dom = require("react-router-dom");
105
+ var import_react_redux2 = require("react-redux");
106
+ var defaultPermissionsSelector = (state) => {
107
+ var _a, _b, _c, _d;
108
+ return (_d = (_c = (_b = (_a = state.global) == null ? void 0 : _a.role) == null ? void 0 : _b.permissao) == null ? void 0 : _c[0]) == null ? void 0 : _d.frontEndPerms;
109
+ };
110
+ var defaultPageLocationSelector = (state) => {
111
+ var _a;
112
+ return (_a = state.global) == null ? void 0 : _a.pageLocation;
113
+ };
114
+ var defaultPrevPageSelector = (state) => {
115
+ var _a;
116
+ return (_a = state.global) == null ? void 0 : _a.prevPage;
117
+ };
118
+ function useNavigator(config) {
119
+ const dispatch = (0, import_react_redux2.useDispatch)();
120
+ const navigate = (0, import_react_router_dom.useNavigate)();
121
+ const {
122
+ pageTracking,
123
+ paths,
124
+ permissionsSelector = defaultPermissionsSelector,
125
+ pageLocationSelector = defaultPageLocationSelector,
126
+ prevPageSelector = defaultPrevPageSelector
127
+ } = config;
128
+ const frontEndPerms = (0, import_react_redux2.useSelector)(permissionsSelector);
129
+ const pageLocation = (0, import_react_redux2.useSelector)(pageLocationSelector);
130
+ const prevPage = (0, import_react_redux2.useSelector)(prevPageSelector);
131
+ return (0, import_react5.useCallback)(
132
+ (path, navConfig, pageName) => {
133
+ const allowedPaths = [paths.loginForm];
134
+ if (typeof path === "string" && allowedPaths.includes(path)) {
135
+ return navigate(path);
136
+ }
137
+ if (!path) path = -1;
138
+ if (path === -1) {
139
+ dispatch(pageTracking.setPrevPage(pageLocation));
140
+ dispatch(pageTracking.setPageLocation(prevPage));
141
+ return navigate(-1);
142
+ }
143
+ if (frontEndPerms && frontEndPerms.length > 0) {
144
+ for (const perm of frontEndPerms) {
145
+ const locationBloqueado = `/${perm.locationBloqueado}`;
146
+ if (locationBloqueado === "*") {
147
+ dispatch(pageTracking.setPrevPage(pageLocation));
148
+ return navigate(paths.inativeUser || "/inativeUser");
149
+ }
150
+ if (locationBloqueado === path) {
151
+ return navigate(paths.acessoNaoPermitido);
152
+ }
153
+ dispatch(pageTracking.setPrevPage(pageLocation));
154
+ dispatch(pageTracking.setPageLocation(pageName || ""));
155
+ return navigate(path, { ...navConfig, replace: false });
156
+ }
157
+ }
158
+ dispatch(pageTracking.setPrevPage(pageLocation));
159
+ dispatch(pageTracking.setPageLocation(pageName || ""));
160
+ return navigate(path, { ...navConfig, replace: false });
161
+ },
162
+ [dispatch, navigate, frontEndPerms, pageLocation, prevPage, pageTracking, paths]
163
+ );
164
+ }
165
+
166
+ // src/components/recurso/RecursoDisplayer.tsx
167
+ var import_react11 = require("react");
168
+ var import_react_bootstrap2 = require("react-bootstrap");
169
+ var import_react_redux3 = require("react-redux");
170
+
171
+ // src/reducers/branchLevelReducer.ts
172
+ var import_toolkit = require("@reduxjs/toolkit");
173
+ var initialState = {
174
+ form: {
175
+ nome: "",
176
+ level: 0,
177
+ color: "",
178
+ hasComponents: false,
179
+ excludeLevels: 0
180
+ },
181
+ levels: []
182
+ };
183
+ var branchLevelSlice = (0, import_toolkit.createSlice)({
184
+ name: "branchLevelReducer",
185
+ initialState,
186
+ reducers: {
187
+ setNome(state, action) {
188
+ state.form.nome = action.payload;
189
+ },
190
+ setLevel(state, action) {
191
+ state.form.level = action.payload;
192
+ },
193
+ setColor(state, action) {
194
+ state.form.color = action.payload;
195
+ },
196
+ setHaveComponente(state, action) {
197
+ state.form.hasComponents = action.payload;
198
+ },
199
+ setExcludeLevels(state, action) {
200
+ state.form.excludeLevels = action.payload;
201
+ },
202
+ setLevels(state, action) {
203
+ state.levels = action.payload;
204
+ },
205
+ populateToEdit(state, action) {
206
+ state.form = action.payload;
207
+ },
208
+ clear(state) {
209
+ state.form = initialState.form;
210
+ }
211
+ }
212
+ });
213
+ var {
214
+ setNome,
215
+ setLevel,
216
+ populateToEdit,
217
+ setColor,
218
+ setHaveComponente,
219
+ clear: clearBranchLevelForm,
220
+ setExcludeLevels,
221
+ setLevels
222
+ } = branchLevelSlice.actions;
223
+ var branchLevelReducer_default = branchLevelSlice.reducer;
224
+
225
+ // src/components/recurso/BranchDropDisplay.tsx
226
+ var import_react6 = require("react");
227
+ var import_fa = require("react-icons/fa");
228
+ var import_md = require("react-icons/md");
229
+
230
+ // src/utils/colorUtils.ts
231
+ function pickTextColorBasedOnBgColorAdvanced(bgColor, lightColor, darkColor) {
232
+ const color = bgColor.charAt(0) === "#" ? bgColor.substring(1, 7) : bgColor;
233
+ const r = parseInt(color.substring(0, 2), 16);
234
+ const g = parseInt(color.substring(2, 4), 16);
235
+ const b = parseInt(color.substring(4, 6), 16);
236
+ const uicolors = [r / 255, g / 255, b / 255];
237
+ const c = uicolors.map(
238
+ (col) => col <= 0.03928 ? col / 12.92 : Math.pow((col + 0.055) / 1.055, 2.4)
239
+ );
240
+ const L = 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
241
+ return L > 0.179 ? darkColor : lightColor;
242
+ }
243
+
244
+ // src/components/recurso/BranchDropDisplay.tsx
245
+ var import_jsx_runtime = require("react/jsx-runtime");
246
+ var BranchDropDisplay = ({
247
+ branch,
248
+ addBranch,
249
+ multiMode,
250
+ setMultiMode,
251
+ onSaveRecurso,
252
+ backOnBranch,
253
+ branches,
254
+ singleReturn
255
+ }) => {
256
+ const [fontColor, setFontColor] = (0, import_react6.useState)("#000");
257
+ const [searchTerm, setSearchTerm] = (0, import_react6.useState)("");
258
+ const [show, setShow] = (0, import_react6.useState)(false);
259
+ const [multiSelected, setMultiSelected] = (0, import_react6.useState)([]);
260
+ const dropdownRef = (0, import_react6.useRef)(null);
261
+ (0, import_react6.useEffect)(() => {
262
+ setFontColor(
263
+ pickTextColorBasedOnBgColorAdvanced(branch.branchLevel.color, "#FFFFFF", "#000000")
264
+ );
265
+ }, [branch.branchLevel.color]);
266
+ (0, import_react6.useEffect)(() => {
267
+ const handleClickOutside = (event) => {
268
+ if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
269
+ setShow(false);
270
+ }
271
+ };
272
+ document.addEventListener("mousedown", handleClickOutside);
273
+ return () => document.removeEventListener("mousedown", handleClickOutside);
274
+ }, [backOnBranch, branch]);
275
+ const handleItemClick = (bn) => {
276
+ const rec = bn.recurso;
277
+ if (multiMode) {
278
+ setMultiSelected(
279
+ (prev) => prev.some((r) => r.id === rec.id) ? prev.filter((r) => r.id !== rec.id) : [...prev, rec]
280
+ );
281
+ } else {
282
+ onSaveRecurso([rec]);
283
+ addBranch(bn);
284
+ setShow(false);
285
+ }
286
+ };
287
+ const startMulti = () => {
288
+ setMultiSelected([]);
289
+ setMultiMode(true);
290
+ setShow(true);
291
+ };
292
+ const handleConfirm = () => {
293
+ setMultiMode(false);
294
+ onSaveRecurso(multiSelected);
295
+ setMultiSelected([]);
296
+ setShow(false);
297
+ };
298
+ const cancelMulti = () => {
299
+ setMultiMode(false);
300
+ setMultiSelected([]);
301
+ };
302
+ const isLastBranchClicked = () => branches.length > 0 && branches[branches.length - 1].id === branch.id;
303
+ const visibleNodes = branch.branchNodes.filter(
304
+ (bn) => bn.recurso.nome.toLowerCase().includes(searchTerm.toLowerCase())
305
+ );
306
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
307
+ "div",
308
+ {
309
+ ref: dropdownRef,
310
+ style: {
311
+ position: "relative",
312
+ marginBottom: "0.5rem",
313
+ width: "100%",
314
+ fontFamily: "Arial, sans-serif"
315
+ },
316
+ children: [
317
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
318
+ "button",
319
+ {
320
+ onClick: () => setShow((s) => !s),
321
+ style: {
322
+ width: "100%",
323
+ display: "flex",
324
+ alignItems: "center",
325
+ justifyContent: "space-between",
326
+ padding: "0.5rem 1rem",
327
+ borderRadius: "9999px",
328
+ boxShadow: "0 1px 3px rgba(0, 0, 0, 0.1)",
329
+ border: `1px solid ${branch.branchLevel.color}`,
330
+ background: branch.branchLevel.color,
331
+ color: fontColor,
332
+ cursor: "pointer",
333
+ outline: "none",
334
+ textAlign: "left",
335
+ fontSize: "1rem"
336
+ },
337
+ children: [
338
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: [
339
+ branch.nomeRecurso || branch.branchLevel.nome,
340
+ branch.nomeRecurso && !multiMode && isLastBranchClicked() && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("em", { style: { fontStyle: "italic", opacity: 0.8, marginLeft: "0.5rem" }, children: "(Selecionado)" })
341
+ ] }),
342
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fa.FaChevronDown, {})
343
+ ]
344
+ }
345
+ ),
346
+ show && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
347
+ "div",
348
+ {
349
+ style: {
350
+ position: "absolute",
351
+ top: "100%",
352
+ left: 0,
353
+ width: "100%",
354
+ background: "#f0f0f0",
355
+ borderRadius: "8px",
356
+ boxShadow: "0 2px 6px rgba(0, 0, 0, 0.15)",
357
+ marginTop: "0.25rem",
358
+ zIndex: 100,
359
+ maxHeight: "300px",
360
+ overflow: "auto"
361
+ },
362
+ children: [
363
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
364
+ "div",
365
+ {
366
+ style: {
367
+ display: "flex",
368
+ alignItems: "center",
369
+ padding: "0.5rem",
370
+ borderBottom: "1px solid #ddd"
371
+ },
372
+ children: [
373
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fa.FaSearch, { style: { marginRight: "0.5rem", color: "#555" } }),
374
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
375
+ "input",
376
+ {
377
+ type: "text",
378
+ placeholder: "Pesquisar recurso...",
379
+ value: searchTerm,
380
+ onChange: (e) => setSearchTerm(e.target.value),
381
+ style: {
382
+ flex: 1,
383
+ padding: "0.5rem",
384
+ border: "1px solid #ccc",
385
+ borderRadius: "9999px",
386
+ outline: "none",
387
+ fontSize: "0.95rem"
388
+ }
389
+ }
390
+ )
391
+ ]
392
+ }
393
+ ),
394
+ !multiMode && !singleReturn ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
395
+ "button",
396
+ {
397
+ onClick: startMulti,
398
+ style: {
399
+ display: "flex",
400
+ alignItems: "center",
401
+ justifyContent: "center",
402
+ width: "100%",
403
+ padding: "0.5rem",
404
+ borderRadius: "9999px",
405
+ border: "none",
406
+ background: "#ffc107",
407
+ color: "#000",
408
+ fontSize: "0.95rem",
409
+ cursor: "pointer",
410
+ margin: "0.5rem 0"
411
+ },
412
+ children: [
413
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fa.FaCheckSquare, { style: { marginRight: "0.5rem" } }),
414
+ "Selecionar m\xFAltiplos"
415
+ ]
416
+ }
417
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", gap: "0.5rem", margin: "0.5rem 0" }, children: [
418
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
419
+ "button",
420
+ {
421
+ onClick: handleConfirm,
422
+ style: {
423
+ flex: 1,
424
+ display: "flex",
425
+ alignItems: "center",
426
+ justifyContent: "center",
427
+ padding: "0.5rem",
428
+ borderRadius: "9999px",
429
+ border: "none",
430
+ background: "#28a745",
431
+ color: "#fff",
432
+ fontSize: "0.95rem",
433
+ cursor: "pointer"
434
+ },
435
+ children: [
436
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fa.FaCheck, { style: { marginRight: "0.5rem" } }),
437
+ "Confirmar sele\xE7\xE3o"
438
+ ]
439
+ }
440
+ ),
441
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
442
+ "button",
443
+ {
444
+ onClick: cancelMulti,
445
+ style: {
446
+ flex: 1,
447
+ display: "flex",
448
+ alignItems: "center",
449
+ justifyContent: "center",
450
+ padding: "0.5rem",
451
+ borderRadius: "9999px",
452
+ border: "none",
453
+ background: "#6c757d",
454
+ color: "#fff",
455
+ fontSize: "0.95rem",
456
+ cursor: "pointer"
457
+ },
458
+ children: [
459
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_md.MdClose, { style: { marginRight: "0.5rem" } }),
460
+ "Cancelar"
461
+ ]
462
+ }
463
+ )
464
+ ] }),
465
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { padding: "0.5rem" }, children: visibleNodes.map((bn) => {
466
+ const selected = multiMode ? multiSelected.some((r) => r.id === bn.recurso.id) : false;
467
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
468
+ "div",
469
+ {
470
+ onClick: () => handleItemClick(bn),
471
+ style: {
472
+ display: "flex",
473
+ justifyContent: "space-between",
474
+ alignItems: "center",
475
+ padding: "0.5rem",
476
+ borderBottom: "1px solid #ddd",
477
+ background: selected ? "#e9ecef" : "transparent",
478
+ cursor: "pointer",
479
+ transition: "background 0.1s"
480
+ },
481
+ onMouseEnter: (e) => {
482
+ if (!selected) e.currentTarget.style.background = "#e2e6ea";
483
+ },
484
+ onMouseLeave: (e) => {
485
+ e.currentTarget.style.background = selected ? "#e9ecef" : "transparent";
486
+ },
487
+ children: [
488
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: bn.recurso.nome }),
489
+ selected && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fa.FaCheck, {})
490
+ ]
491
+ },
492
+ bn.recurso.id
493
+ );
494
+ }) })
495
+ ]
496
+ }
497
+ )
498
+ ]
499
+ }
500
+ );
501
+ };
502
+ var BranchDropDisplay_default = BranchDropDisplay;
503
+
504
+ // src/components/recurso/FindRecursoByTagField.tsx
505
+ var import_react10 = require("react");
506
+ var import_gr = require("react-icons/gr");
507
+
508
+ // src/components/recurso/AutoComplete.tsx
509
+ var import_react7 = require("react");
510
+ var import_react_bootstrap = require("react-bootstrap");
511
+ var import_jsx_runtime2 = require("react/jsx-runtime");
512
+ var AutoComplete = ({
513
+ className,
514
+ ops,
515
+ sortKey,
516
+ displayKey,
517
+ displayKeys,
518
+ onValueChanged,
519
+ selectedKey,
520
+ onSelectedClick,
521
+ value,
522
+ actionButton,
523
+ actionButton2,
524
+ placeH,
525
+ title,
526
+ filter,
527
+ filterField,
528
+ loadFunc,
529
+ loadCondition,
530
+ isBold,
531
+ onBlurEvent,
532
+ formatationFunc,
533
+ onEscKeyDown,
534
+ margT,
535
+ hideComponent,
536
+ disableComponent = false,
537
+ disableSelect = false,
538
+ margB,
539
+ autoFocusConfig,
540
+ onLoad,
541
+ onMouseLv,
542
+ useStandardLabel = false,
543
+ isRequired = false,
544
+ ty = "text"
545
+ }) => {
546
+ const [liItem, setListItem] = (0, import_react7.useState)([]);
547
+ const [options, setOptions] = (0, import_react7.useState)([]);
548
+ const [input, setInput] = (0, import_react7.useState)("");
549
+ const [hide, setHide] = (0, import_react7.useState)(true);
550
+ const [onLoaded, setOnLoaded] = (0, import_react7.useState)(false);
551
+ const sortOptions = (opts, key) => {
552
+ if (!key || !Array.isArray(opts)) return opts != null ? opts : [];
553
+ return [...opts].sort((a, b) => String(a[key]).localeCompare(String(b[key])));
554
+ };
555
+ (0, import_react7.useEffect)(() => {
556
+ if (value) setInput(value);
557
+ else setInput("");
558
+ }, [value]);
559
+ (0, import_react7.useEffect)(() => {
560
+ const sortedOptions = sortOptions(ops, sortKey);
561
+ setListItem(sortedOptions);
562
+ setOptions(sortedOptions);
563
+ }, [ops, sortKey]);
564
+ (0, import_react7.useEffect)(() => {
565
+ const loadFunction = async () => {
566
+ if (loadCondition && loadFunc) {
567
+ try {
568
+ const res = await loadFunc();
569
+ let newOps = res.content ? res.content : res;
570
+ newOps = newOps.filter((c) => c != null);
571
+ if (Array.isArray(newOps)) {
572
+ if (filter) {
573
+ newOps = newOps.filter((op) => op[filterField] === filter);
574
+ }
575
+ const sortedOptions = sortOptions(newOps, sortKey);
576
+ setListItem(sortedOptions);
577
+ setOptions(sortedOptions);
578
+ }
579
+ if (onLoad) {
580
+ if (onLoaded) return;
581
+ setOnLoaded(true);
582
+ onLoad(newOps);
583
+ }
584
+ } catch (e) {
585
+ setListItem([]);
586
+ }
587
+ }
588
+ };
589
+ loadFunction();
590
+ }, [loadCondition, filter, filterField, sortKey, onLoad]);
591
+ const onFieldUpdate = (val) => {
592
+ let newListItem;
593
+ if (val && val.length > 0) {
594
+ const regex = new RegExp(`${val}`, "i");
595
+ newListItem = options.filter((liI) => {
596
+ let textToTest;
597
+ if (formatationFunc) {
598
+ textToTest = formatationFunc(liI);
599
+ } else if (displayKey) {
600
+ textToTest = liI[displayKey];
601
+ } else if (displayKeys) {
602
+ textToTest = keysJoinner(liI);
603
+ } else {
604
+ textToTest = liI;
605
+ }
606
+ return regex.test(textToTest);
607
+ });
608
+ setListItem(newListItem);
609
+ } else {
610
+ setListItem(options);
611
+ }
612
+ onValueChanged && onValueChanged(val);
613
+ setInput(val);
614
+ setHide(false);
615
+ };
616
+ const clear = () => {
617
+ setInput("");
618
+ };
619
+ const onOpSelected = (li, index, lItem) => {
620
+ if (formatationFunc) {
621
+ setInput(formatationFunc(li));
622
+ } else if (displayKey) {
623
+ setInput(li[displayKey]);
624
+ } else if (displayKeys) {
625
+ setInput(keysJoinner(li));
626
+ } else {
627
+ setInput(li);
628
+ }
629
+ onSelectedClick(li, index, lItem);
630
+ setHide(true);
631
+ };
632
+ const keysJoinner = (li) => {
633
+ if (!displayKeys || !Array.isArray(displayKeys)) return "";
634
+ const textToRender = displayKeys.map((key) => `${li[key]} `);
635
+ return textToRender.join("").trim();
636
+ };
637
+ const renderMoreThanOneKey = (li, index) => {
638
+ const buildedString = keysJoinner(li);
639
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { children: buildedString }, index);
640
+ };
641
+ const boldedPart = (text, key) => {
642
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { children: text }, key);
643
+ };
644
+ const displayListItens = (li, index) => {
645
+ if (formatationFunc) {
646
+ return boldedPart(formatationFunc(li), index);
647
+ }
648
+ if (displayKey) {
649
+ return boldedPart(li[displayKey], index);
650
+ }
651
+ if (displayKeys) {
652
+ return renderMoreThanOneKey(li, index);
653
+ }
654
+ return boldedPart(li, index);
655
+ };
656
+ const onKeyDownHandler = (event) => {
657
+ if (event.key === "Escape") {
658
+ setHide(true);
659
+ onEscKeyDown && onEscKeyDown();
660
+ }
661
+ };
662
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
663
+ "div",
664
+ {
665
+ className: `${className}`,
666
+ style: { marginTop: margT || 4, marginBottom: margB || 4, position: "relative" },
667
+ onBlur: (e) => {
668
+ setTimeout(() => {
669
+ if (onBlurEvent) onBlurEvent(e, input);
670
+ setHide(true);
671
+ }, 200);
672
+ },
673
+ onKeyDown: (event) => onKeyDownHandler(event),
674
+ onMouseLeave: () => {
675
+ setHide(true);
676
+ },
677
+ children: [
678
+ !hideComponent && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
679
+ useStandardLabel && title && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_bootstrap.Form.Label, { children: [
680
+ title,
681
+ isRequired && " *"
682
+ ] }),
683
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_bootstrap.InputGroup, { children: [
684
+ useStandardLabel ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
685
+ import_react_bootstrap.Form.Control,
686
+ {
687
+ autoFocus: autoFocusConfig,
688
+ disabled: disableComponent || disableSelect,
689
+ placeholder: placeH,
690
+ autoComplete: "off",
691
+ value: input,
692
+ onClickCapture: () => {
693
+ setHide(false);
694
+ if (!input) {
695
+ onFieldUpdate("");
696
+ }
697
+ },
698
+ onChange: (event) => onFieldUpdate(event.currentTarget.value),
699
+ type: "text"
700
+ }
701
+ ) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_bootstrap.FloatingLabel, { style: { zIndex: 0 }, label: title, controlId: "floatingInput", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
702
+ import_react_bootstrap.Form.Control,
703
+ {
704
+ autoFocus: autoFocusConfig,
705
+ disabled: disableComponent || disableSelect,
706
+ placeholder: placeH,
707
+ autoComplete: "off",
708
+ value: input,
709
+ onClickCapture: () => {
710
+ setHide(false);
711
+ if (!input) {
712
+ onFieldUpdate("");
713
+ }
714
+ },
715
+ onChange: (event) => onFieldUpdate(event.currentTarget.value),
716
+ type: "text"
717
+ }
718
+ ) }),
719
+ !disableComponent && actionButton && actionButton(clear),
720
+ !disableComponent && actionButton2 && actionButton2(input)
721
+ ] })
722
+ ] }),
723
+ liItem && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_bootstrap.ListGroup, { className: "listgroup-autocomplete", hidden: hide, children: liItem.map((li, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_bootstrap.ListGroup.Item, { action: true, onClick: () => onOpSelected(li, index, liItem), children: displayListItens(li, index) }, index)) })
724
+ ]
725
+ }
726
+ );
727
+ };
728
+ var AutoComplete_default = AutoComplete;
729
+
730
+ // src/components/recurso/QrCodeScanButton.tsx
731
+ var import_react9 = require("react");
732
+ var import_bs = require("react-icons/bs");
733
+
734
+ // src/components/recurso/QrReader.tsx
735
+ var import_qr_scanner = __toESM(require("qr-scanner"));
736
+ var import_react8 = require("react");
737
+ var import_jsx_runtime3 = require("react/jsx-runtime");
738
+ var QrReader = ({ callback }) => {
739
+ const scanner = (0, import_react8.useRef)(null);
740
+ const videoEl = (0, import_react8.useRef)(null);
741
+ const qrBoxEl = (0, import_react8.useRef)(null);
742
+ const [qrOn, setQrOn] = (0, import_react8.useState)(true);
743
+ const [scannedResult, setScannedResult] = (0, import_react8.useState)("");
744
+ const onScanSuccess = (result) => {
745
+ setScannedResult(result == null ? void 0 : result.data);
746
+ callback(result == null ? void 0 : result.data);
747
+ };
748
+ const onScanFail = (err) => {
749
+ console.error(err);
750
+ };
751
+ (0, import_react8.useEffect)(() => {
752
+ if ((videoEl == null ? void 0 : videoEl.current) && !scanner.current) {
753
+ scanner.current = new import_qr_scanner.default(videoEl.current, onScanSuccess, {
754
+ onDecodeError: onScanFail,
755
+ preferredCamera: "environment",
756
+ highlightScanRegion: true,
757
+ highlightCodeOutline: true,
758
+ overlay: (qrBoxEl == null ? void 0 : qrBoxEl.current) || void 0
759
+ });
760
+ scanner.current.start().then(() => setQrOn(true)).catch((err) => {
761
+ if (err) setQrOn(false);
762
+ });
763
+ }
764
+ return () => {
765
+ var _a;
766
+ if (!(videoEl == null ? void 0 : videoEl.current)) {
767
+ (_a = scanner == null ? void 0 : scanner.current) == null ? void 0 : _a.stop();
768
+ }
769
+ };
770
+ }, []);
771
+ (0, import_react8.useEffect)(() => {
772
+ if (!qrOn)
773
+ alert(
774
+ "Camera est\xE1 bloqueada ou inacess\xEDvel. Por Favor habilite a camera nas permiss\xF5es do seu navegador e recarregue a p\xE1gina."
775
+ );
776
+ }, [qrOn]);
777
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "qr-reader", children: [
778
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("video", { ref: videoEl }),
779
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { ref: qrBoxEl, className: "qr-box" }),
780
+ scannedResult && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
781
+ "p",
782
+ {
783
+ style: {
784
+ position: "absolute",
785
+ top: 0,
786
+ left: 0,
787
+ zIndex: 99999,
788
+ color: "white"
789
+ },
790
+ children: [
791
+ "Scanned Result: ",
792
+ scannedResult
793
+ ]
794
+ }
795
+ )
796
+ ] });
797
+ };
798
+ var QrReader_default = QrReader;
799
+
800
+ // src/components/recurso/QrCodeScanButton.tsx
801
+ var import_jsx_runtime4 = require("react/jsx-runtime");
802
+ var QrCodeScanButton = ({ callback }) => {
803
+ const [showQr, setShowQr] = (0, import_react9.useState)(false);
804
+ const qrShowHandler = () => {
805
+ setShowQr((prev) => !prev);
806
+ };
807
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
808
+ "div",
809
+ {
810
+ className: "hoverable-div",
811
+ style: {
812
+ border: "solid",
813
+ borderTopRightRadius: "3px",
814
+ borderBottomRightRadius: "3px",
815
+ padding: "8px",
816
+ borderLeft: "none",
817
+ borderColor: "#ccc",
818
+ borderWidth: "1px"
819
+ },
820
+ children: [
821
+ showQr && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
822
+ QrReader_default,
823
+ {
824
+ callback: (v) => {
825
+ qrShowHandler();
826
+ callback(v);
827
+ }
828
+ }
829
+ ),
830
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
831
+ import_bs.BsQrCode,
832
+ {
833
+ size: 25,
834
+ onClick: () => {
835
+ qrShowHandler();
836
+ }
837
+ }
838
+ )
839
+ ]
840
+ }
841
+ );
842
+ };
843
+ var QrCodeScanButton_default = QrCodeScanButton;
844
+
845
+ // src/components/recurso/FindRecursoByTagField.tsx
846
+ var import_jsx_runtime5 = require("react/jsx-runtime");
847
+ var FindRecursoByTagField = ({ callback }) => {
848
+ const recursoController = useHttpController("recurso");
849
+ const [selectedTag, setSelectedTag] = (0, import_react10.useState)(null);
850
+ const [reachedRecurso, setReachedRecurso] = (0, import_react10.useState)(null);
851
+ const findRecursoByTagIdHandler = async (tagId) => {
852
+ const r = await recursoController.read("findRecursoByTagId", tagId);
853
+ setReachedRecurso(r);
854
+ };
855
+ const findRecursoByTagDescriptionHandler = async (description) => {
856
+ const recurso = await recursoController.read(
857
+ "recurso/findByTagDescription",
858
+ description.replace(" ", "")
859
+ );
860
+ if (!callback) {
861
+ console.log(recurso);
862
+ } else {
863
+ callback(recurso, true);
864
+ }
865
+ };
866
+ const confirmRecursoSelectionButton = () => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
867
+ "div",
868
+ {
869
+ className: "hoverable-div",
870
+ style: {
871
+ border: "solid",
872
+ borderTopRightRadius: "3px",
873
+ borderBottomRightRadius: "3px",
874
+ padding: "8px",
875
+ borderLeft: "none",
876
+ borderColor: "#ccc",
877
+ borderWidth: "1px"
878
+ },
879
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_gr.GrCheckmark, { size: 25, onClick: () => callback(reachedRecurso, true) })
880
+ }
881
+ );
882
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
883
+ AutoComplete_default,
884
+ {
885
+ sortKey: "id",
886
+ loadCondition: true,
887
+ loadFunc: () => recursoController.get("findActiveRecursosTags"),
888
+ displayKey: "descricao",
889
+ title: "Selecione ou Digite a TAG",
890
+ isBold: true,
891
+ actionButton: confirmRecursoSelectionButton,
892
+ actionButton2: () => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
893
+ QrCodeScanButton_default,
894
+ {
895
+ callback: (description) => findRecursoByTagDescriptionHandler(description)
896
+ }
897
+ ),
898
+ onSelectedClick: (v) => {
899
+ setSelectedTag(v);
900
+ findRecursoByTagIdHandler(v.id);
901
+ },
902
+ value: selectedTag == null ? void 0 : selectedTag.descricao
903
+ }
904
+ ) });
905
+ };
906
+ var FindRecursoByTagField_default = FindRecursoByTagField;
907
+
908
+ // src/components/recurso/RecursoDisplayer.tsx
909
+ var import_jsx_runtime6 = require("react/jsx-runtime");
910
+ var RecursoDisplayer = ({
911
+ selectedList = [],
912
+ onSaveRecurso,
913
+ singleReturn = false
914
+ }) => {
915
+ const arvoreEstruturalController = useHttpController("arvoreEstrutural");
916
+ const branchLevelController = useHttpController("branchLevel");
917
+ const [branches, setBranches] = (0, import_react11.useState)([]);
918
+ const dispatch = (0, import_react_redux3.useDispatch)();
919
+ const [localSelected, setLocalSelected] = (0, import_react11.useState)(selectedList);
920
+ const [selectorDisplay, setSelectorDisplay] = (0, import_react11.useState)("");
921
+ const [multiMode, setMultiMode] = (0, import_react11.useState)(false);
922
+ (0, import_react11.useEffect)(() => {
923
+ const init = async () => {
924
+ const b = await arvoreEstruturalController.get("branchByBranchLevel/1");
925
+ setBranches(b);
926
+ const lv = await branchLevelController.readAll();
927
+ dispatch(setLevels(lv));
928
+ };
929
+ init();
930
+ }, []);
931
+ const branchSetter = async (bn) => {
932
+ const copy = [...branches];
933
+ const branch = await arvoreEstruturalController.read("branch", bn.recurso.branch.id);
934
+ copy[bn.recurso.branch.branchLevel.level - 1] = {
935
+ ...branch,
936
+ nomeRecurso: bn.recurso.nome
937
+ };
938
+ setBranches(copy);
939
+ };
940
+ const backOnBranch = (branch) => {
941
+ const branchsToStay = branches.filter(
942
+ (bArray) => bArray.branchLevel.level <= branch.branchLevel.level
943
+ );
944
+ setBranches(branchsToStay);
945
+ };
946
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { width: "100%", padding: 0 }, children: [
947
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "d-flex justify-content-between align-items-center mb-3", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
948
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("label", { className: "me-2", children: "Selecionar Recurso Por:" }),
949
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
950
+ import_react_bootstrap2.Button,
951
+ {
952
+ size: "sm",
953
+ onClick: () => setSelectorDisplay("branch"),
954
+ variant: selectorDisplay === "branch" ? "primary" : "outline-primary",
955
+ className: "me-1",
956
+ children: "\xC1rvore"
957
+ }
958
+ ),
959
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
960
+ import_react_bootstrap2.Button,
961
+ {
962
+ size: "sm",
963
+ onClick: () => setSelectorDisplay("TAG"),
964
+ variant: selectorDisplay === "TAG" ? "primary" : "outline-primary",
965
+ children: "TAG"
966
+ }
967
+ )
968
+ ] }) }),
969
+ selectorDisplay === "branch" && branches.map((branch, i) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
970
+ BranchDropDisplay_default,
971
+ {
972
+ branch,
973
+ addBranch: branchSetter,
974
+ multiMode,
975
+ setMultiMode,
976
+ onSaveRecurso,
977
+ backOnBranch,
978
+ branches,
979
+ singleReturn
980
+ },
981
+ branch.id || i
982
+ )),
983
+ selectorDisplay === "TAG" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
984
+ FindRecursoByTagField_default,
985
+ {
986
+ callback: (rec, checked) => {
987
+ setLocalSelected([rec]);
988
+ onSaveRecurso([rec], checked);
989
+ }
990
+ }
991
+ )
992
+ ] });
993
+ };
994
+ var RecursoDisplayer_default = RecursoDisplayer;
995
+ // Annotate the CommonJS export names for ESM import in node:
996
+ 0 && (module.exports = {
997
+ CoreServiceContext,
998
+ RecursoDisplayer,
999
+ branchLevelReducer,
1000
+ clearBranchLevelForm,
1001
+ pickTextColorBasedOnBgColorAdvanced,
1002
+ populateToEdit,
1003
+ setColor,
1004
+ setExcludeLevels,
1005
+ setHaveComponente,
1006
+ setLevel,
1007
+ setLevels,
1008
+ setNome,
1009
+ useCoreService,
1010
+ useHttpController,
1011
+ useMatchingObject,
1012
+ useNavigator,
1013
+ useNotifications,
1014
+ useToast
1015
+ });