@orangesix/react 1.0.3 → 1.0.6
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/api/index.cjs.js +2 -0
- package/api/index.cjs.js.map +1 -0
- package/api/index.d.ts +26 -0
- package/api/index.esm.js +2 -0
- package/api/index.esm.js.map +1 -0
- package/api/package.json +5 -0
- package/api/theme.css +1 -0
- package/box/_box.scss +83 -0
- package/box/index.cjs.js +2 -0
- package/box/index.cjs.js.map +1 -0
- package/box/index.d.ts +147 -0
- package/box/index.esm.js +2 -0
- package/box/index.esm.js.map +1 -0
- package/box/package.json +5 -0
- package/editor/_editor.scss +53 -0
- package/editor/index.cjs.js +2 -0
- package/editor/index.cjs.js.map +1 -0
- package/editor/index.d.ts +92 -0
- package/editor/index.esm.js +2 -0
- package/editor/index.esm.js.map +1 -0
- package/editor/package.json +5 -0
- package/package.json +19 -15
- package/table/_table.scss +136 -0
- package/table/index.cjs.js +2 -0
- package/table/index.cjs.js.map +1 -0
- package/table/index.d.ts +256 -0
- package/table/index.esm.js +2 -0
- package/table/index.esm.js.map +1 -0
- package/table/package.json +5 -0
- package/utils/index.cjs.js +2 -365
- package/utils/index.cjs.js.map +1 -0
- package/utils/index.d.ts +68 -45
- package/utils/index.esm.js +2 -350
- package/utils/index.esm.js.map +1 -0
package/utils/index.cjs.js
CHANGED
|
@@ -1,365 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var $ = require('jquery');
|
|
4
|
-
var axios = require('axios');
|
|
5
|
-
var SweetAlert = require('sweetalert2');
|
|
6
|
-
var Snackbar = require('node-snackbar');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Envia a mensagem para o evento da janela
|
|
10
|
-
*/
|
|
11
|
-
function sendMessage(params) {
|
|
12
|
-
let Window = window.self === window.top ? window : window.parent;
|
|
13
|
-
const { message, library, type, options } = params;
|
|
14
|
-
Window.postMessage({
|
|
15
|
-
type: "message",
|
|
16
|
-
params: {
|
|
17
|
-
message,
|
|
18
|
-
options,
|
|
19
|
-
type: type ?? "message",
|
|
20
|
-
library: library ?? "snackbar"
|
|
21
|
-
}
|
|
22
|
-
}, "*");
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Retorna o objeto mensagem de acordo com os parâmetros
|
|
26
|
-
*/
|
|
27
|
-
function message(params) {
|
|
28
|
-
let { message, library, type, options } = params;
|
|
29
|
-
library = library ?? "snackbar";
|
|
30
|
-
switch (library) {
|
|
31
|
-
case "sweetAlert":
|
|
32
|
-
let swal = {
|
|
33
|
-
icon: message.type,
|
|
34
|
-
title: message.title,
|
|
35
|
-
text: message.text
|
|
36
|
-
};
|
|
37
|
-
if (type === "toast") {
|
|
38
|
-
const Toast = SweetAlert.mixin(options !== undefined ? options
|
|
39
|
-
: {
|
|
40
|
-
toast: true,
|
|
41
|
-
position: "top-end",
|
|
42
|
-
showConfirmButton: false,
|
|
43
|
-
timer: 3000,
|
|
44
|
-
timerProgressBar: true,
|
|
45
|
-
didOpen: (toast) => {
|
|
46
|
-
toast.onmouseenter = SweetAlert.stopTimer;
|
|
47
|
-
toast.onmouseleave = SweetAlert.resumeTimer;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
Toast.fire(swal);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
SweetAlert.fire({ ...swal, ...options });
|
|
54
|
-
}
|
|
55
|
-
break;
|
|
56
|
-
case "snackbar":
|
|
57
|
-
let config = options;
|
|
58
|
-
let text = message.message ?? message.text ?? message.title ?? "Não foi possível carregar a mensagem.";
|
|
59
|
-
Snackbar.show(config === undefined ? {
|
|
60
|
-
pos: "top-right",
|
|
61
|
-
showAction: false,
|
|
62
|
-
customClass: message.type,
|
|
63
|
-
text: "<p class='d-flex m-0 align-items-center'><i class='me-2 " + message.icon + "'></i>" + text + "</p>",
|
|
64
|
-
} : config);
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Realiza a pesquisa do elemento html na DOM<br>
|
|
71
|
-
* <meta id="???" name="???" content="your-url">
|
|
72
|
-
*/
|
|
73
|
-
function getMetaContent(id) {
|
|
74
|
-
let element = document.getElementById(id);
|
|
75
|
-
let url = element === null ? null : (element.content).replace(".br/", ".br");
|
|
76
|
-
return url === null ? null : url.substr(-1) === "/" ? url.slice(0, url.length - 1) : url;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Realiza a pesquisa do CEP na API pública "https://viacep.com.br/ws/"
|
|
80
|
-
*/
|
|
81
|
-
async function getCep(value) {
|
|
82
|
-
let cep = value.length === 0 ? "00000000" : value.replace("-", "");
|
|
83
|
-
return await axios.get("https://viacep.com.br/ws/" + cep + "/json/")
|
|
84
|
-
.then(data => data.data);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Realiza a pesquisa do elemento na árvore DOM
|
|
88
|
-
*/
|
|
89
|
-
function getElementDOM(element, preloadTimeOut) {
|
|
90
|
-
return new Promise((resolve) => {
|
|
91
|
-
// @ts-ignore
|
|
92
|
-
let body = window.self === window.top ? $("body") : $(window.frameElement).parents("body");
|
|
93
|
-
if (!element || element.length === 0) {
|
|
94
|
-
resolve(body);
|
|
95
|
-
}
|
|
96
|
-
if (element === "#" || element === ".") {
|
|
97
|
-
resolve(null);
|
|
98
|
-
}
|
|
99
|
-
let elementFound = body.find(element);
|
|
100
|
-
if (elementFound.length > 0) {
|
|
101
|
-
resolve(elementFound);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
setTimeout(() => {
|
|
105
|
-
let iframe = body.find("iframe").contents();
|
|
106
|
-
if (iframe.length === 0) {
|
|
107
|
-
resolve(null);
|
|
108
|
-
}
|
|
109
|
-
elementFound = iframe.find(element);
|
|
110
|
-
if (elementFound.length > 0) {
|
|
111
|
-
resolve(elementFound);
|
|
112
|
-
}
|
|
113
|
-
resolve(null);
|
|
114
|
-
}, preloadTimeOut ?? 300);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Permite à comunicação de origem cruzada entre objetos do Windows.<br>
|
|
120
|
-
* Exemplo: Comunicação entre iframe e corpo principal
|
|
121
|
-
*/
|
|
122
|
-
function windowMessageEvent() {
|
|
123
|
-
window.addEventListener("message", function (event) {
|
|
124
|
-
if (event.data?.type === "message") {
|
|
125
|
-
let data = event.data;
|
|
126
|
-
message({ ...data.params });
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const USER = getMetaContent("auth");
|
|
132
|
-
const BASE = getMetaContent("react-base");
|
|
133
|
-
const TOKEN = getMetaContent("csrf-token");
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Realizei o gerenciamento do objeto de resposta
|
|
137
|
-
*/
|
|
138
|
-
function response(response, form = "") {
|
|
139
|
-
let data = response;
|
|
140
|
-
if (!data) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if (data.redirect) {
|
|
144
|
-
window.location.href = data.redirect;
|
|
145
|
-
}
|
|
146
|
-
if (data.errors) {
|
|
147
|
-
messageField(data.errors, form.length === 0 ? "" : form);
|
|
148
|
-
}
|
|
149
|
-
if (data.accept) {
|
|
150
|
-
messageField(data.accept, form.length === 0 ? "" : form, "is-valid");
|
|
151
|
-
}
|
|
152
|
-
if (data.message && data?.errors === undefined) {
|
|
153
|
-
sendMessage({
|
|
154
|
-
message: { ...data.message },
|
|
155
|
-
type: "message",
|
|
156
|
-
library: "snackbar"
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Exibe a mensagem no campo do formulário
|
|
162
|
-
*/
|
|
163
|
-
function messageField(data, form = "", type = "is-invalid") {
|
|
164
|
-
tabViewActiveError(form, data);
|
|
165
|
-
getElementDOM("#" + form)
|
|
166
|
-
.then(formulario => {
|
|
167
|
-
if (formulario === null) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
let validationFeedbackClass = type === "is-invalid" ? "invalid-feedback" : "valid-feedback";
|
|
171
|
-
let removeValidationFeedbackClass = type === "is-invalid" ? "is-valid" : "is-invalid";
|
|
172
|
-
$.each(data, (key, value) => {
|
|
173
|
-
let text = "";
|
|
174
|
-
value.forEach(value => text += value + "<br>");
|
|
175
|
-
formulario.find("input[name='" + key + "']")
|
|
176
|
-
.addClass(type)
|
|
177
|
-
.parent()
|
|
178
|
-
.find("#j_feedback[data-name='" + key + "']")
|
|
179
|
-
.addClass(validationFeedbackClass)
|
|
180
|
-
.removeClass(removeValidationFeedbackClass)
|
|
181
|
-
.html(text);
|
|
182
|
-
formulario.find("input[name='" + key + "']")
|
|
183
|
-
.addClass(type)
|
|
184
|
-
.parent()
|
|
185
|
-
.parent()
|
|
186
|
-
.find("#j_feedback[data-name='" + key + "']")
|
|
187
|
-
.addClass(validationFeedbackClass)
|
|
188
|
-
.removeClass(removeValidationFeedbackClass)
|
|
189
|
-
.html(text);
|
|
190
|
-
formulario.find("input[name='" + key + "']")
|
|
191
|
-
.addClass(type)
|
|
192
|
-
.parent()
|
|
193
|
-
.parent()
|
|
194
|
-
.parent()
|
|
195
|
-
.find("#j_feedback[data-name='" + key + "']")
|
|
196
|
-
.addClass(validationFeedbackClass)
|
|
197
|
-
.removeClass(removeValidationFeedbackClass)
|
|
198
|
-
.html(text);
|
|
199
|
-
formulario.find("select[name='" + key + "']")
|
|
200
|
-
.addClass(type)
|
|
201
|
-
.parent()
|
|
202
|
-
.find("#j_feedback[data-name='" + key + "']")
|
|
203
|
-
.addClass(validationFeedbackClass)
|
|
204
|
-
.removeClass(removeValidationFeedbackClass)
|
|
205
|
-
.html(text);
|
|
206
|
-
formulario.find("textarea[name='" + key + "']")
|
|
207
|
-
.addClass(type)
|
|
208
|
-
.parent()
|
|
209
|
-
.find("#j_feedback[data-name='" + key + "']")
|
|
210
|
-
.addClass(validationFeedbackClass)
|
|
211
|
-
.removeClass(removeValidationFeedbackClass)
|
|
212
|
-
.html(text);
|
|
213
|
-
formulario.find("#j_feedback[data-name='" + key + "']")
|
|
214
|
-
.addClass(type)
|
|
215
|
-
.html(text);
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Limpar as mensagens de feedback do formulário
|
|
221
|
-
*/
|
|
222
|
-
function messageFieldClear(form = "") {
|
|
223
|
-
getElementDOM("#" + form)
|
|
224
|
-
.then(formulario => {
|
|
225
|
-
if (formulario === null) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
let validationClass = ["is-invalid", "is-valid", "p-invalid"];
|
|
229
|
-
let validationFeedbackClass = ["invalid-feedback", "valid-feedback"];
|
|
230
|
-
$.each(formulario.find("input"), function () {
|
|
231
|
-
$(this)
|
|
232
|
-
.removeClass(validationClass)
|
|
233
|
-
.parent()
|
|
234
|
-
.find("#j_feedback")
|
|
235
|
-
.removeClass(validationFeedbackClass)
|
|
236
|
-
.html("");
|
|
237
|
-
$(this)
|
|
238
|
-
.removeClass(validationClass)
|
|
239
|
-
.parent()
|
|
240
|
-
.parent()
|
|
241
|
-
.find("#j_feedback")
|
|
242
|
-
.removeClass(validationFeedbackClass)
|
|
243
|
-
.html("");
|
|
244
|
-
$(this)
|
|
245
|
-
.removeClass(validationClass)
|
|
246
|
-
.parent()
|
|
247
|
-
.parent()
|
|
248
|
-
.parent()
|
|
249
|
-
.find("#j_feedback")
|
|
250
|
-
.removeClass(validationFeedbackClass)
|
|
251
|
-
.html("");
|
|
252
|
-
});
|
|
253
|
-
$.each(formulario.find("select"), function () {
|
|
254
|
-
$(this)
|
|
255
|
-
.removeClass(validationClass)
|
|
256
|
-
.parent()
|
|
257
|
-
.find("#j_feedback")
|
|
258
|
-
.removeClass(validationFeedbackClass)
|
|
259
|
-
.html("");
|
|
260
|
-
});
|
|
261
|
-
$.each(formulario.find("textarea"), function () {
|
|
262
|
-
$(this)
|
|
263
|
-
.removeClass(validationClass)
|
|
264
|
-
.parent()
|
|
265
|
-
.find("#j_feedback")
|
|
266
|
-
.removeClass(validationFeedbackClass)
|
|
267
|
-
.html("");
|
|
268
|
-
});
|
|
269
|
-
$.each(formulario.find("#j_feedback"), function () {
|
|
270
|
-
$(this).removeClass(validationClass).html("");
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Ativa o TabView quando o campo apresenta erro
|
|
276
|
-
*/
|
|
277
|
-
function tabViewActiveError(form = "", errors) {
|
|
278
|
-
getElementDOM("#" + form)
|
|
279
|
-
.then(TabView => {
|
|
280
|
-
if (TabView === null) {
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
let fieldError = Object.keys(errors)[0];
|
|
284
|
-
let TabViewSelected = TabView.find("*[id='" + fieldError + "']").closest(".tab-pane");
|
|
285
|
-
let TabViewSelectedId = TabViewSelected.attr("id");
|
|
286
|
-
let TabViewNav = TabViewSelected.parent().parent().find(".nav");
|
|
287
|
-
TabViewSelected.parent(".tab-content").children(".tab-pane").each(function (_, value) {
|
|
288
|
-
if (typeof value !== "undefined") {
|
|
289
|
-
if ($(value).attr("id") === TabViewSelectedId) {
|
|
290
|
-
$(value).addClass("show active");
|
|
291
|
-
TabViewNav.find("button[data-bs-target='#" + TabViewSelectedId + "']").addClass("active show");
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
$(value).removeClass("show active");
|
|
295
|
-
TabViewNav.find("button[data-bs-target='#" + $(value).attr("id") + "']").removeClass("active");
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Simplifica a solicitação POST HTTP usando a biblioteca axios
|
|
304
|
-
*/
|
|
305
|
-
function post(route, body, form, options) {
|
|
306
|
-
return new Promise((resolve, reject) => {
|
|
307
|
-
let url = BASE + (route.startsWith("/") ? "" : "/") + route;
|
|
308
|
-
messageFieldClear(form);
|
|
309
|
-
handleToManyRequest(options?.url ?? url, options?.blockedToManyRequest ?? false);
|
|
310
|
-
axios({
|
|
311
|
-
method: "post",
|
|
312
|
-
url: options?.url ?? url,
|
|
313
|
-
headers: { "X-CSRF-TOKEN": TOKEN },
|
|
314
|
-
data: !body ? {} : body,
|
|
315
|
-
}).then(data => {
|
|
316
|
-
if (data?.data !== undefined) {
|
|
317
|
-
resolve(data.data);
|
|
318
|
-
}
|
|
319
|
-
if (typeof options?.blockedResponse !== "boolean" || options?.blockedResponse === false) {
|
|
320
|
-
response(data?.data, form);
|
|
321
|
-
}
|
|
322
|
-
}).catch(error => {
|
|
323
|
-
response(error.response?.data, form);
|
|
324
|
-
reject(error);
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Bloqueia várias solicitações simultâneas
|
|
330
|
-
*/
|
|
331
|
-
function handleToManyRequest(url, blocked) {
|
|
332
|
-
let requestCount = 0;
|
|
333
|
-
axios.interceptors.request.use(config => {
|
|
334
|
-
requestCount = requestCount + 1;
|
|
335
|
-
if (requestCount > 1 && axios.getUri(config) === url && blocked) {
|
|
336
|
-
return Promise.reject(new Error("Requisições bloqueadas!"));
|
|
337
|
-
}
|
|
338
|
-
return config;
|
|
339
|
-
});
|
|
340
|
-
if (!blocked) {
|
|
341
|
-
axios.interceptors.request.clear();
|
|
342
|
-
}
|
|
343
|
-
axios.interceptors.response.use(response => {
|
|
344
|
-
requestCount = requestCount - 1;
|
|
345
|
-
return response;
|
|
346
|
-
}, function (error) {
|
|
347
|
-
requestCount = requestCount - 1;
|
|
348
|
-
return Promise.reject(error);
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
exports.BASE = BASE;
|
|
353
|
-
exports.TOKEN = TOKEN;
|
|
354
|
-
exports.USER = USER;
|
|
355
|
-
exports.getCep = getCep;
|
|
356
|
-
exports.getElementDOM = getElementDOM;
|
|
357
|
-
exports.getMetaContent = getMetaContent;
|
|
358
|
-
exports.message = message;
|
|
359
|
-
exports.messageField = messageField;
|
|
360
|
-
exports.messageFieldClear = messageFieldClear;
|
|
361
|
-
exports.post = post;
|
|
362
|
-
exports.response = response;
|
|
363
|
-
exports.sendMessage = sendMessage;
|
|
364
|
-
exports.tabViewActiveError = tabViewActiveError;
|
|
365
|
-
exports.windowMessageEvent = windowMessageEvent;
|
|
1
|
+
"use strict";var e=require("jquery"),t=require("axios"),a=require("node-snackbar"),s=require("sweetalert2");function n(e){let t=window.self===window.top?window:window.parent;const{message:a,library:s,type:n,options:r}=e;t.postMessage({type:"message",params:{message:a,options:r,type:n??"message",library:s??"snackbar"}},"*")}function r(e){let{message:t,library:n,type:r,options:i}=e;switch(n=n??"snackbar",n){case"sweetAlert":let e={icon:t.type,title:t.title,text:t.text};if("toast"===r){let t=i??{toast:!0,position:"top-end",showConfirmButton:!1,timer:3e3,timerProgressBar:!0,didOpen:e=>{e.onmouseenter=s.stopTimer,e.onmouseleave=s.resumeTimer}};s.mixin(t).fire(e)}else s.fire({...e,...i});break;case"snackbar":let n=i,o=t.message??t.text??t.title??"Não foi possível carregar a mensagem.";a.show(void 0===n?{pos:"top-right",showAction:!1,customClass:t.type,text:"<p class='d-flex m-0 align-items-center'><i class='me-2 "+t.icon+"'></i>"+o+"</p>"}:n)}}function i(e){let t=document.getElementById(e),a=null===t?null:t.content.replace(".br/",".br");return null===a?null:"/"===a.substr(-1)?a.slice(0,a.length-1):a}function o(t,a){return new Promise((s=>{let n=window.self===window.top?e("body"):e(window.frameElement).parents("body");t&&0!==t.length||s(n),"#"!==t&&"."!==t||s(null);let r=n.find(t);r.length>0?s(r):setTimeout((()=>{let e=n.find("iframe").contents();0===e.length&&s(null),r=e.find(t),r.length>0&&s(r),s(null)}),a??300)}))}const l=i("auth"),d=i("react-base"),c=i("csrf-token");function m(e,t=""){let a=e;a&&(a.redirect&&(window.location.href=a.redirect),a.errors&&p(a.errors,0===t.length?"":t),a.accept&&p(a.accept,0===t.length?"":t,"is-valid"),a.message&&void 0===a?.errors&&n({message:{...a.message},type:"message",library:"snackbar"}))}function p(t,a="",s="is-invalid"){u(a,t),o("#"+a).then((a=>{if(null===a)return;let n="is-invalid"===s?"invalid-feedback":"valid-feedback",r="is-invalid"===s?"is-valid":"is-invalid";e.each(t,((e,t)=>{let i="";t.forEach((e=>i+=e+"<br>")),a.find("input[name='"+e+"']").addClass(s).parent().find("#j_feedback[data-name='"+e+"']").addClass(n).removeClass(r).html(i),a.find("input[name='"+e+"']").addClass(s).parent().parent().find("#j_feedback[data-name='"+e+"']").addClass(n).removeClass(r).html(i),a.find("input[name='"+e+"']").addClass(s).parent().parent().parent().find("#j_feedback[data-name='"+e+"']").addClass(n).removeClass(r).html(i),a.find("select[name='"+e+"']").addClass(s).parent().find("#j_feedback[data-name='"+e+"']").addClass(n).removeClass(r).html(i),a.find("textarea[name='"+e+"']").addClass(s).parent().find("#j_feedback[data-name='"+e+"']").addClass(n).removeClass(r).html(i),a.find("#j_feedback[data-name='"+e+"']").addClass(s).html(i)}))}))}function f(t=""){o("#"+t).then((t=>{if(null===t)return;let a=["is-invalid","is-valid","p-invalid"],s=["invalid-feedback","valid-feedback"];e.each(t.find("input"),(function(){e(this).removeClass(a).parent().find("#j_feedback").removeClass(s).html(""),e(this).removeClass(a).parent().parent().find("#j_feedback").removeClass(s).html(""),e(this).removeClass(a).parent().parent().parent().find("#j_feedback").removeClass(s).html("")})),e.each(t.find("select"),(function(){e(this).removeClass(a).parent().find("#j_feedback").removeClass(s).html("")})),e.each(t.find("textarea"),(function(){e(this).removeClass(a).parent().find("#j_feedback").removeClass(s).html("")})),e.each(t.find("#j_feedback"),(function(){e(this).removeClass(a).html("")}))}))}function u(t="",a){o("#"+t).then((t=>{if(null===t)return;let s=Object.keys(a)[0],n=t.find("*[id='"+s+"']").closest(".tab-pane"),r=n.attr("id"),i=n.parent().parent().find(".nav");n.parent(".tab-content").children(".tab-pane").each((function(t,a){void 0!==a&&(e(a).attr("id")===r?(e(a).addClass("show active"),i.find("button[data-bs-target='#"+r+"']").addClass("active show")):(e(a).removeClass("show active"),i.find("button[data-bs-target='#"+e(a).attr("id")+"']").removeClass("active")))}))}))}exports.BASE=d,exports.TOKEN=c,exports.USER=l,exports.getCep=async function(e){let a=0===e.length?"00000000":e.replace("-","");return await t.get("https://viacep.com.br/ws/"+a+"/json/").then((e=>e.data))},exports.getElementDOM=o,exports.getMetaContent=i,exports.message=r,exports.messageField=p,exports.messageFieldClear=f,exports.post=function(e,a,s,n){return new Promise(((r,i)=>{let o=d+(e.startsWith("/")?"":"/")+e;f(s),function(e,a){let s=0;t.interceptors.request.use((n=>(s+=1,s>1&&t.getUri(n)===e&&a?Promise.reject(new Error("Requisições bloqueadas!")):n))),a||t.interceptors.request.clear();t.interceptors.response.use((e=>(s-=1,e)),(function(e){return s-=1,Promise.reject(e)}))}(n?.url??o,n?.blockedToManyRequest??!1),t({method:"post",url:n?.url??o,headers:{"X-CSRF-TOKEN":c},data:a||{}}).then((e=>{void 0!==e?.data&&r(e.data),"boolean"==typeof n?.blockedResponse&&!1!==n?.blockedResponse||m(e?.data,s)})).catch((e=>{m(e.response?.data,s),i(e)}))}))},exports.response=m,exports.sendMessage=n,exports.tabViewActiveError=u,exports.windowMessageEvent=function(){window.addEventListener("message",(function(e){if("message"===e.data?.type){r({...e.data.params})}}))};
|
|
2
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../src/utils/message.ts","../../src/utils/helper.ts","../../src/utils/const.ts","../../src/utils/response.ts","../../src/utils/request.ts"],"sourcesContent":["import Snackbar from \"node-snackbar\";\r\nimport SweetAlert, { SweetAlertOptions } from \"sweetalert2\";\r\nimport { IUtilsMessage, IUtilsMessageOptions } from \"./types\";\r\n\r\n/**\r\n * Envia a mensagem para o evento da janela\r\n */\r\nexport function sendMessage<T extends keyof IUtilsMessageOptions>(params: IUtilsMessage<T>) {\r\n let Window: Window = window.self === window.top ? window : window.parent;\r\n const { message, library, type, options } = params;\r\n Window.postMessage({\r\n type: \"message\",\r\n params: {\r\n message,\r\n options,\r\n type: type ?? \"message\",\r\n library: library ?? \"snackbar\"\r\n }\r\n }, \"*\");\r\n}\r\n\r\n/**\r\n * Retorna o objeto mensagem de acordo com os parâmetros\r\n */\r\nexport function message<T extends keyof IUtilsMessageOptions>(params: IUtilsMessage<T>) {\r\n let { message, library, type, options } = params;\r\n\r\n library = library ?? \"snackbar\";\r\n switch (library) {\r\n case \"sweetAlert\":\r\n let swal: any = {\r\n icon: message.type,\r\n title: message.title,\r\n text: message.text\r\n };\r\n if (type === \"toast\") {\r\n let config: SweetAlertOptions = options as SweetAlertOptions ?? {\r\n toast: true,\r\n position: \"top-end\",\r\n showConfirmButton: false,\r\n timer: 3000,\r\n timerProgressBar: true,\r\n didOpen: (toast) => {\r\n toast.onmouseenter = SweetAlert.stopTimer;\r\n toast.onmouseleave = SweetAlert.resumeTimer;\r\n }\r\n };\r\n const Toast = SweetAlert.mixin(config);\r\n Toast.fire(swal);\r\n } else {\r\n SweetAlert.fire({ ...swal, ...options });\r\n }\r\n break;\r\n case \"snackbar\":\r\n let config: any = options;\r\n let text: string = message.message ?? message.text ?? message.title ?? \"Não foi possível carregar a mensagem.\";\r\n Snackbar.show(config === undefined ? {\r\n pos: \"top-right\",\r\n showAction: false,\r\n customClass: message.type,\r\n text: \"<p class='d-flex m-0 align-items-center'><i class='me-2 \" + message.icon + \"'></i>\" + text + \"</p>\",\r\n } : config);\r\n break;\r\n }\r\n}","import $ from \"jquery\";\r\nimport axios from \"axios\";\r\nimport { message } from \"./message\";\r\nimport { IUtilsHelperResponse } from \"./types\";\r\n\r\n/**\r\n * Realiza a pesquisa do elemento html na DOM<br>\r\n * <meta id=\"???\" name=\"???\" content=\"your-url\">\r\n */\r\nexport function getMetaContent(id: string): string | null {\r\n let element: any = document.getElementById(id);\r\n let url: null | string = element === null ? null : (element.content).replace(\".br/\", \".br\");\r\n return url === null ? null : url.substr(-1) === \"/\" ? url.slice(0, url.length - 1) : url;\r\n}\r\n\r\n/**\r\n * Realiza a pesquisa do CEP na API pública \"https://viacep.com.br/ws/\"\r\n */\r\nexport async function getCep(value: string): Promise<IUtilsHelperResponse[\"gep_cep\"]> {\r\n let cep = value.length === 0 ? \"00000000\" : value.replace(\"-\", \"\");\r\n return await axios.get<IUtilsHelperResponse[\"gep_cep\"]>(\"https://viacep.com.br/ws/\" + cep + \"/json/\")\r\n .then(data => data.data);\r\n}\r\n\r\n/**\r\n * Realiza a pesquisa do elemento na árvore DOM\r\n */\r\nexport function getElementDOM(element?: string, preloadTimeOut?: number): Promise<null | JQuery<HTMLElement>> {\r\n return new Promise((resolve) => {\r\n // @ts-ignore\r\n let body = window.self === window.top ? $(\"body\") : $(window.frameElement).parents(\"body\");\r\n if (!element || element.length === 0) {\r\n resolve(body);\r\n }\r\n\r\n if (element === \"#\" || element === \".\") {\r\n resolve(null);\r\n }\r\n\r\n let elementFound = body.find(element);\r\n if (elementFound.length > 0) {\r\n resolve(elementFound);\r\n } else {\r\n setTimeout(() => {\r\n let iframe = body.find(\"iframe\").contents();\r\n if (iframe.length === 0) {\r\n resolve(null);\r\n }\r\n elementFound = iframe.find(element);\r\n if (elementFound.length > 0) {\r\n resolve(elementFound);\r\n }\r\n resolve(null);\r\n }, preloadTimeOut ?? 300);\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Permite à comunicação de origem cruzada entre objetos do Windows.<br>\r\n * Exemplo: Comunicação entre iframe e corpo principal\r\n */\r\nexport function windowMessageEvent(): void {\r\n window.addEventListener(\"message\", function (event: MessageEvent) {\r\n if (event.data?.type === \"message\") {\r\n let data = event.data;\r\n message<any>({ ...data.params });\r\n }\r\n });\r\n}","import { getMetaContent } from \"./helper\";\r\n\r\nexport const USER: string | null = getMetaContent(\"auth\");\r\nexport const BASE: string | null = getMetaContent(\"react-base\");\r\nexport const TOKEN: string | null = getMetaContent(\"csrf-token\");\r\n","import $ from \"jquery\";\r\nimport { sendMessage } from \"./message\";\r\nimport { getElementDOM } from \"./helper\";\r\nimport { IUtilsResponseType, IUtilsResponseError } from \"./types\";\r\n\r\n/**\r\n * Realizei o gerenciamento do objeto de resposta\r\n */\r\nexport function response<Type>(\r\n response: IUtilsResponseType<Type>,\r\n form: string = \"\"\r\n): void {\r\n let data: IUtilsResponseType<Type> = response;\r\n if (!data) {\r\n return;\r\n }\r\n\r\n if (data.redirect) {\r\n window.location.href = data.redirect;\r\n }\r\n\r\n if (data.errors) {\r\n messageField(data.errors, form.length === 0 ? \"\" : form);\r\n }\r\n\r\n if (data.accept) {\r\n messageField(data.accept, form.length === 0 ? \"\" : form, \"is-valid\");\r\n }\r\n\r\n if (data.message && data?.errors === undefined) {\r\n sendMessage<\"snackbar\">({\r\n message: { ...data.message },\r\n type: \"message\",\r\n library: \"snackbar\"\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * Exibe a mensagem no campo do formulário\r\n */\r\nexport function messageField(\r\n data: IUtilsResponseError,\r\n form: string = \"\",\r\n type: string = \"is-invalid\"\r\n): void {\r\n tabViewActiveError(form, data);\r\n getElementDOM(\"#\" + form)\r\n .then(formulario => {\r\n if (formulario === null) {\r\n return;\r\n }\r\n\r\n let validationFeedbackClass: string = type === \"is-invalid\" ? \"invalid-feedback\" : \"valid-feedback\";\r\n let removeValidationFeedbackClass: string = type === \"is-invalid\" ? \"is-valid\" : \"is-invalid\";\r\n\r\n $.each(data, (key: string, value) => {\r\n let text = \"\";\r\n value.forEach(value => text += value + \"<br>\");\r\n\r\n formulario.find(\"input[name='\" + key + \"']\")\r\n .addClass(type)\r\n .parent()\r\n .find(\"#j_feedback[data-name='\" + key + \"']\")\r\n .addClass(validationFeedbackClass)\r\n .removeClass(removeValidationFeedbackClass)\r\n .html(text);\r\n\r\n formulario.find(\"input[name='\" + key + \"']\")\r\n .addClass(type)\r\n .parent()\r\n .parent()\r\n .find(\"#j_feedback[data-name='\" + key + \"']\")\r\n .addClass(validationFeedbackClass)\r\n .removeClass(removeValidationFeedbackClass)\r\n .html(text);\r\n\r\n formulario.find(\"input[name='\" + key + \"']\")\r\n .addClass(type)\r\n .parent()\r\n .parent()\r\n .parent()\r\n .find(\"#j_feedback[data-name='\" + key + \"']\")\r\n .addClass(validationFeedbackClass)\r\n .removeClass(removeValidationFeedbackClass)\r\n .html(text);\r\n\r\n formulario.find(\"select[name='\" + key + \"']\")\r\n .addClass(type)\r\n .parent()\r\n .find(\"#j_feedback[data-name='\" + key + \"']\")\r\n .addClass(validationFeedbackClass)\r\n .removeClass(removeValidationFeedbackClass)\r\n .html(text);\r\n\r\n formulario.find(\"textarea[name='\" + key + \"']\")\r\n .addClass(type)\r\n .parent()\r\n .find(\"#j_feedback[data-name='\" + key + \"']\")\r\n .addClass(validationFeedbackClass)\r\n .removeClass(removeValidationFeedbackClass)\r\n .html(text);\r\n\r\n formulario.find(\"#j_feedback[data-name='\" + key + \"']\")\r\n .addClass(type)\r\n .html(text);\r\n });\r\n });\r\n}\r\n\r\n/**\r\n * Limpar as mensagens de feedback do formulário\r\n */\r\nexport function messageFieldClear(\r\n form: string = \"\"\r\n): void {\r\n getElementDOM(\"#\" + form)\r\n .then(formulario => {\r\n if (formulario === null) {\r\n return;\r\n }\r\n\r\n let validationClass: string[] = [\"is-invalid\", \"is-valid\", \"p-invalid\"];\r\n let validationFeedbackClass: string[] = [\"invalid-feedback\", \"valid-feedback\"];\r\n\r\n $.each(formulario.find(\"input\"), function () {\r\n $(this)\r\n .removeClass(validationClass)\r\n .parent()\r\n .find(\"#j_feedback\")\r\n .removeClass(validationFeedbackClass)\r\n .html(\"\");\r\n\r\n $(this)\r\n .removeClass(validationClass)\r\n .parent()\r\n .parent()\r\n .find(\"#j_feedback\")\r\n .removeClass(validationFeedbackClass)\r\n .html(\"\");\r\n\r\n $(this)\r\n .removeClass(validationClass)\r\n .parent()\r\n .parent()\r\n .parent()\r\n .find(\"#j_feedback\")\r\n .removeClass(validationFeedbackClass)\r\n .html(\"\");\r\n });\r\n\r\n $.each(formulario.find(\"select\"), function () {\r\n $(this)\r\n .removeClass(validationClass)\r\n .parent()\r\n .find(\"#j_feedback\")\r\n .removeClass(validationFeedbackClass)\r\n .html(\"\");\r\n });\r\n\r\n $.each(formulario.find(\"textarea\"), function () {\r\n $(this)\r\n .removeClass(validationClass)\r\n .parent()\r\n .find(\"#j_feedback\")\r\n .removeClass(validationFeedbackClass)\r\n .html(\"\");\r\n });\r\n\r\n $.each(formulario.find(\"#j_feedback\"), function () {\r\n $(this).removeClass(validationClass).html(\"\");\r\n });\r\n });\r\n}\r\n\r\n/**\r\n * Ativa o TabView quando o campo apresenta erro\r\n */\r\nexport function tabViewActiveError(\r\n form: string = \"\",\r\n errors: IUtilsResponseError\r\n): void {\r\n getElementDOM(\"#\" + form)\r\n .then(TabView => {\r\n if (TabView === null) {\r\n return;\r\n }\r\n\r\n let fieldError = Object.keys(errors)[0];\r\n\r\n let TabViewSelected = TabView.find(\"*[id='\" + fieldError + \"']\").closest(\".tab-pane\");\r\n let TabViewSelectedId = TabViewSelected.attr(\"id\");\r\n let TabViewNav = TabViewSelected.parent().parent().find(\".nav\");\r\n\r\n TabViewSelected.parent(\".tab-content\").children(\".tab-pane\").each(function (_, value) {\r\n if (typeof value !== \"undefined\") {\r\n if ($(value).attr(\"id\") === TabViewSelectedId) {\r\n $(value).addClass(\"show active\");\r\n TabViewNav.find(\"button[data-bs-target='#\" + TabViewSelectedId + \"']\").addClass(\"active show\");\r\n } else {\r\n $(value).removeClass(\"show active\");\r\n TabViewNav.find(\"button[data-bs-target='#\" + $(value).attr(\"id\") + \"']\").removeClass(\"active\");\r\n }\r\n }\r\n });\r\n });\r\n}","import axios from \"axios\";\r\nimport { BASE, TOKEN } from \"./const\";\r\nimport { messageFieldClear, response } from \"./response\";\r\nimport { IUtilsRequestPostOptions, IUtilsResponseType } from \"./types\";\r\n\r\n/**\r\n * Simplifica a solicitação POST HTTP usando a biblioteca axios\r\n */\r\nexport function post<TypeDataResponse = IUtilsResponseType<any>>(\r\n route: string,\r\n body: any,\r\n form?: string,\r\n options?: IUtilsRequestPostOptions\r\n): Promise<TypeDataResponse> {\r\n return new Promise((resolve, reject) => {\r\n let url = BASE + (route.startsWith(\"/\") ? \"\" : \"/\") + route;\r\n messageFieldClear(form);\r\n handleToManyRequest(options?.url ?? url, options?.blockedToManyRequest ?? false);\r\n axios<TypeDataResponse>({\r\n method: \"post\",\r\n url: options?.url ?? url,\r\n headers: { \"X-CSRF-TOKEN\": TOKEN },\r\n data: !body ? {} : body,\r\n }).then(data => {\r\n if (data?.data !== undefined) {\r\n resolve(data.data);\r\n }\r\n if (typeof options?.blockedResponse !== \"boolean\" || options?.blockedResponse === false) {\r\n response<TypeDataResponse>((data?.data as IUtilsResponseType<TypeDataResponse>), form);\r\n }\r\n }).catch(error => {\r\n response<TypeDataResponse>(error.response?.data, form);\r\n reject(error);\r\n });\r\n });\r\n}\r\n\r\n/**\r\n * Bloqueia várias solicitações simultâneas\r\n */\r\nfunction handleToManyRequest(url: string, blocked: boolean): void {\r\n let requestCount = 0;\r\n axios.interceptors.request.use(config => {\r\n requestCount = requestCount + 1;\r\n if (requestCount > 1 && axios.getUri(config) === url && blocked) {\r\n return Promise.reject(new Error(\"Requisições bloqueadas!\"));\r\n }\r\n return config;\r\n });\r\n if (!blocked) {\r\n axios.interceptors.request.clear();\r\n }\r\n\r\n axios.interceptors.response.use(response => {\r\n requestCount = requestCount - 1;\r\n return response;\r\n }, function (error) {\r\n requestCount = requestCount - 1;\r\n return Promise.reject(error);\r\n });\r\n}"],"names":["sendMessage","params","Window","window","self","top","parent","message","library","type","options","postMessage","swal","icon","title","text","config","toast","position","showConfirmButton","timer","timerProgressBar","didOpen","onmouseenter","SweetAlert","stopTimer","onmouseleave","resumeTimer","mixin","fire","Snackbar","show","undefined","pos","showAction","customClass","getMetaContent","id","element","document","getElementById","url","replace","substr","slice","length","getElementDOM","preloadTimeOut","Promise","resolve","body","$","frameElement","parents","elementFound","find","setTimeout","iframe","contents","USER","BASE","TOKEN","response","form","data","redirect","location","href","errors","messageField","accept","tabViewActiveError","then","formulario","validationFeedbackClass","removeValidationFeedbackClass","each","key","value","forEach","addClass","removeClass","html","messageFieldClear","validationClass","this","TabView","fieldError","Object","keys","TabViewSelected","closest","TabViewSelectedId","attr","TabViewNav","children","_","async","cep","axios","get","route","reject","startsWith","blocked","requestCount","interceptors","request","use","getUri","Error","clear","error","handleToManyRequest","blockedToManyRequest","method","headers","blockedResponse","catch","addEventListener","event"],"mappings":"4GAOM,SAAUA,EAAkDC,GAC9D,IAAIC,EAAiBC,OAAOC,OAASD,OAAOE,IAAMF,OAASA,OAAOG,OAClE,MAAMC,QAAEA,EAAOC,QAAEA,EAAOC,KAAEA,EAAIC,QAAEA,GAAYT,EAC5CC,EAAOS,YAAY,CACfF,KAAM,UACNR,OAAQ,CACJM,UACAG,UACAD,KAAMA,GAAQ,UACdD,QAASA,GAAW,aAEzB,IACP,CAKM,SAAUD,EAA8CN,GAC1D,IAAIM,QAAEA,EAAOC,QAAEA,EAAOC,KAAEA,EAAIC,QAAEA,GAAYT,EAG1C,OADAO,EAAUA,GAAW,WACbA,GACJ,IAAK,aACD,IAAII,EAAY,CACZC,KAAMN,EAAQE,KACdK,MAAOP,EAAQO,MACfC,KAAMR,EAAQQ,MAElB,GAAa,UAATN,EAAkB,CAClB,IAAIO,EAA4BN,GAAgC,CAC5DO,OAAO,EACPC,SAAU,UACVC,mBAAmB,EACnBC,MAAO,IACPC,kBAAkB,EAClBC,QAAUL,IACNA,EAAMM,aAAeC,EAAWC,UAChCR,EAAMS,aAAeF,EAAWG,WAAW,GAGrCH,EAAWI,MAAMZ,GACzBa,KAAKjB,EACd,MACGY,EAAWK,KAAK,IAAKjB,KAASF,IAElC,MACJ,IAAK,WACD,IAAIM,EAAcN,EACdK,EAAeR,EAAQA,SAAWA,EAAQQ,MAAQR,EAA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FuD,OAAMN,IACLlD,EAA2BkD,EAAMlD,UAAUE,KAAMD,GACjDuC,EAAOU,EAAM,GACf,GAEV,8GH4BI7G,OAAOoH,iBAAiB,WAAW,SAAUC,GACzC,GAAyB,YAArBA,EAAMxD,MAAMvD,KAAoB,CAEhCF,EAAa,IADFiH,EAAMxD,KACM/D,QAC1B,CACL,GACJ"}
|
package/utils/index.d.ts
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import { SweetAlertOptions } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* @author Luiz Fernando Bernardes de Paula
|
|
8
|
-
*/
|
|
9
|
-
export declare const BASE: null | string;
|
|
10
|
-
export declare const TOKEN: null | string;
|
|
11
|
-
export declare const USER: null | string;
|
|
12
|
-
|
|
1
|
+
import { SweetAlertOptions } from 'sweetalert2';
|
|
2
|
+
|
|
3
|
+
declare const USER: string | null;
|
|
4
|
+
declare const BASE: string | null;
|
|
5
|
+
declare const TOKEN: string | null;
|
|
6
|
+
|
|
13
7
|
/**
|
|
14
8
|
* Retorna os tipos do arquivo <b>request.ts</b>
|
|
15
9
|
*
|
|
16
10
|
* @module utils
|
|
17
11
|
* @author Luiz Fernando Bernardes de Paula
|
|
18
12
|
*/
|
|
19
|
-
|
|
13
|
+
interface IUtilsRequestPostOptions {
|
|
20
14
|
|
|
21
15
|
/**
|
|
22
16
|
* Blocks multiple simultaneous requests
|
|
@@ -34,15 +28,13 @@ export interface IUtilsRequestPostOptions {
|
|
|
34
28
|
url?: string
|
|
35
29
|
}
|
|
36
30
|
|
|
37
|
-
export declare function post<TypeDataResponse extends IUtilsResponseType<any>>(route: string, body: any, form?: string, options?: IUtilsRequestPostOptions): Promise<TypeDataResponse>;
|
|
38
|
-
|
|
39
31
|
/**
|
|
40
32
|
* Retorna os tipos do arquivo <b>helper.ts</b>
|
|
41
33
|
*
|
|
42
34
|
* @module utils
|
|
43
35
|
* @author Luiz Fernando Bernardes de Paula
|
|
44
36
|
*/
|
|
45
|
-
|
|
37
|
+
interface IUtilsHelperResponse {
|
|
46
38
|
gep_cep: {
|
|
47
39
|
bairro: string
|
|
48
40
|
cep: string
|
|
@@ -53,22 +45,13 @@ export interface IUtilsHelperResponse {
|
|
|
53
45
|
}
|
|
54
46
|
}
|
|
55
47
|
|
|
56
|
-
export declare function windowMessageEvent(): void
|
|
57
|
-
|
|
58
|
-
export declare function getMetaContent(id: string): string | null
|
|
59
|
-
|
|
60
|
-
export declare async function getCep(value: string): Promise<IUtilsHelperResponse["gep_cep"]>
|
|
61
|
-
|
|
62
|
-
export declare async function getElementDOM(element?: string, preloadTimeOut?: number): Promise<null | JQuery<HTMLElement>>
|
|
63
|
-
|
|
64
|
-
|
|
65
48
|
/**
|
|
66
49
|
* Retorna os tipos do arquivo <b>response.ts</b>
|
|
67
50
|
*
|
|
68
51
|
* @module utils
|
|
69
52
|
* @author Luiz Fernando Bernardes de Paula
|
|
70
53
|
*/
|
|
71
|
-
|
|
54
|
+
interface IUtilsResponseType<T> {
|
|
72
55
|
data?: T
|
|
73
56
|
accept?: any
|
|
74
57
|
redirect?: string
|
|
@@ -78,22 +61,22 @@ export interface IUtilsResponseType<T> {
|
|
|
78
61
|
modal?: IUtilsResponseModal
|
|
79
62
|
}
|
|
80
63
|
|
|
81
|
-
|
|
64
|
+
interface IUtilsResponseError {
|
|
82
65
|
[key: string]: string[];
|
|
83
66
|
}
|
|
84
67
|
|
|
85
|
-
|
|
68
|
+
interface IUtilsResponseField {
|
|
86
69
|
field: string
|
|
87
70
|
messageType: string
|
|
88
71
|
message: string
|
|
89
72
|
}
|
|
90
73
|
|
|
91
|
-
|
|
74
|
+
interface IUtilsResponseModal {
|
|
92
75
|
modal: string,
|
|
93
76
|
action: string
|
|
94
77
|
}
|
|
95
78
|
|
|
96
|
-
|
|
79
|
+
interface IUtilsResponseMessage {
|
|
97
80
|
type?: "success" | "warning" | "error" | "info"
|
|
98
81
|
title?: string
|
|
99
82
|
message?: string
|
|
@@ -101,32 +84,72 @@ export interface IUtilsResponseMessage {
|
|
|
101
84
|
icon?: string
|
|
102
85
|
}
|
|
103
86
|
|
|
104
|
-
export declare function response<Type>(response: IUtilsResponseType<Type>, form: string): void
|
|
105
|
-
|
|
106
|
-
export declare function messageField(data: IUtilsResponseError, form: string, type: string): void
|
|
107
|
-
|
|
108
|
-
export declare function messageFieldClear(form: string): void
|
|
109
|
-
|
|
110
|
-
export declare function tabViewActiveError(form: string, errors: IUtilsResponseError): void
|
|
111
|
-
|
|
112
87
|
/**
|
|
113
88
|
* Retorna os tipos do arquivo <b>message.ts</b>
|
|
114
89
|
*
|
|
115
90
|
* @module utils
|
|
116
91
|
* @author Luiz Fernando Bernardes de Paula
|
|
117
92
|
*/
|
|
118
|
-
|
|
93
|
+
interface IUtilsMessage<T extends keyof IUtilsMessageOptions> {
|
|
119
94
|
message: IUtilsResponseMessage,
|
|
120
95
|
type?: "toast" | "message",
|
|
121
96
|
options?: IUtilsMessageOptions[T],
|
|
122
97
|
library?: keyof IUtilsMessageOptions
|
|
123
98
|
}
|
|
124
99
|
|
|
125
|
-
|
|
100
|
+
interface IUtilsMessageOptions {
|
|
126
101
|
sweetAlert: SweetAlertOptions,
|
|
127
102
|
snackbar: SnackbarOptions
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Realiza a pesquisa do elemento html na DOM<br>
|
|
107
|
+
* <meta id="???" name="???" content="your-url">
|
|
108
|
+
*/
|
|
109
|
+
declare function getMetaContent(id: string): string | null;
|
|
110
|
+
/**
|
|
111
|
+
* Realiza a pesquisa do CEP na API pública "https://viacep.com.br/ws/"
|
|
112
|
+
*/
|
|
113
|
+
declare function getCep(value: string): Promise<IUtilsHelperResponse["gep_cep"]>;
|
|
114
|
+
/**
|
|
115
|
+
* Realiza a pesquisa do elemento na árvore DOM
|
|
116
|
+
*/
|
|
117
|
+
declare function getElementDOM(element?: string, preloadTimeOut?: number): Promise<null | JQuery<HTMLElement>>;
|
|
118
|
+
/**
|
|
119
|
+
* Permite à comunicação de origem cruzada entre objetos do Windows.<br>
|
|
120
|
+
* Exemplo: Comunicação entre iframe e corpo principal
|
|
121
|
+
*/
|
|
122
|
+
declare function windowMessageEvent(): void;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Simplifica a solicitação POST HTTP usando a biblioteca axios
|
|
126
|
+
*/
|
|
127
|
+
declare function post<TypeDataResponse = IUtilsResponseType<any>>(route: string, body: any, form?: string, options?: IUtilsRequestPostOptions): Promise<TypeDataResponse>;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Envia a mensagem para o evento da janela
|
|
131
|
+
*/
|
|
132
|
+
declare function sendMessage<T extends keyof IUtilsMessageOptions>(params: IUtilsMessage<T>): void;
|
|
133
|
+
/**
|
|
134
|
+
* Retorna o objeto mensagem de acordo com os parâmetros
|
|
135
|
+
*/
|
|
136
|
+
declare function message<T extends keyof IUtilsMessageOptions>(params: IUtilsMessage<T>): void;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Realizei o gerenciamento do objeto de resposta
|
|
140
|
+
*/
|
|
141
|
+
declare function response<Type>(response: IUtilsResponseType<Type>, form?: string): void;
|
|
142
|
+
/**
|
|
143
|
+
* Exibe a mensagem no campo do formulário
|
|
144
|
+
*/
|
|
145
|
+
declare function messageField(data: IUtilsResponseError, form?: string, type?: string): void;
|
|
146
|
+
/**
|
|
147
|
+
* Limpar as mensagens de feedback do formulário
|
|
148
|
+
*/
|
|
149
|
+
declare function messageFieldClear(form?: string): void;
|
|
150
|
+
/**
|
|
151
|
+
* Ativa o TabView quando o campo apresenta erro
|
|
152
|
+
*/
|
|
153
|
+
declare function tabViewActiveError(form: string | undefined, errors: IUtilsResponseError): void;
|
|
154
|
+
|
|
155
|
+
export { BASE, TOKEN, USER, getCep, getElementDOM, getMetaContent, message, messageField, messageFieldClear, post, response, sendMessage, tabViewActiveError, windowMessageEvent };
|