@orangesix/react 1.0.0 → 1.0.3

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/package.json CHANGED
@@ -1,25 +1,31 @@
1
1
  {
2
- "name": "@orangesix/react",
3
- "version": "1.0.0",
4
- "description": "Set of components and functions available to be used in a React project.",
5
- "scripts": {
6
- },
7
- "author": "Luiz Fernando Bernardes de Paula",
8
- "license": "MIT",
9
- "files": [
10
- "dist",
11
- "types"
12
- ],
13
- "keywords": [
14
- "react",
15
- "primereact",
16
- "ui-kit",
17
- "ui library",
18
- "component library"
19
- ],
20
- "peerDependencies": {
21
- "@types/react": "^17.0.0 || ^18.0.0",
22
- "react": "^17.0.0 || ^18.0.0",
23
- "react-dom": "^17.0.0 || ^18.0.0"
24
- }
25
- }
2
+ "name": "@orangesix/react",
3
+ "version": "1.0.3",
4
+ "private": false,
5
+ "author": "Luiz Fernando Bernardes de Paula",
6
+ "description": "Set of components and functions available to be used in a React project.",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/Nandovga/orangesix-react.git"
10
+ },
11
+ "license": "MIT",
12
+ "bugs": {
13
+ "url": "https://github.com/Nandovga/orangesix-react/issues"
14
+ },
15
+ "keywords": [
16
+ "react",
17
+ "primereact",
18
+ "ui-kit",
19
+ "ui library",
20
+ "component library"
21
+ ],
22
+ "dependencies": {
23
+ "axios": "^1.7.2",
24
+ "jquery": "^3.7.1",
25
+ "node-snackbar": "^0.1.16",
26
+ "primereact": "^10.6.6",
27
+ "react": "^18.0.0",
28
+ "react-dom": "^18.0.0",
29
+ "sweetalert2": "^11.11.0"
30
+ }
31
+ }
@@ -0,0 +1,365 @@
1
+ 'use strict';
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;
@@ -0,0 +1,132 @@
1
+ import { SweetAlertOptions } from "sweetalert2";
2
+
3
+ /**
4
+ * Retorna os tipos do arquivo <b>const.ts</b>
5
+ *
6
+ * @module utils
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
+
13
+ /**
14
+ * Retorna os tipos do arquivo <b>request.ts</b>
15
+ *
16
+ * @module utils
17
+ * @author Luiz Fernando Bernardes de Paula
18
+ */
19
+ export interface IUtilsRequestPostOptions {
20
+
21
+ /**
22
+ * Blocks multiple simultaneous requests
23
+ */
24
+ blockedToManyRequest?: boolean
25
+
26
+ /**
27
+ * Blocks the execution of the response method upon return from the post.
28
+ */
29
+ blockedResponse?: boolean
30
+
31
+ /**
32
+ * Replace the BASE url with the absolute url provided
33
+ */
34
+ url?: string
35
+ }
36
+
37
+ export declare function post<TypeDataResponse extends IUtilsResponseType<any>>(route: string, body: any, form?: string, options?: IUtilsRequestPostOptions): Promise<TypeDataResponse>;
38
+
39
+ /**
40
+ * Retorna os tipos do arquivo <b>helper.ts</b>
41
+ *
42
+ * @module utils
43
+ * @author Luiz Fernando Bernardes de Paula
44
+ */
45
+ export interface IUtilsHelperResponse {
46
+ gep_cep: {
47
+ bairro: string
48
+ cep: string
49
+ complemento: string
50
+ localidade: string
51
+ logradouro: string
52
+ uf: string
53
+ }
54
+ }
55
+
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
+ /**
66
+ * Retorna os tipos do arquivo <b>response.ts</b>
67
+ *
68
+ * @module utils
69
+ * @author Luiz Fernando Bernardes de Paula
70
+ */
71
+ export interface IUtilsResponseType<T> {
72
+ data?: T
73
+ accept?: any
74
+ redirect?: string
75
+ errors?: IUtilsResponseError
76
+ field?: IUtilsResponseField
77
+ message?: IUtilsResponseMessage
78
+ modal?: IUtilsResponseModal
79
+ }
80
+
81
+ export interface IUtilsResponseError {
82
+ [key: string]: string[];
83
+ }
84
+
85
+ export interface IUtilsResponseField {
86
+ field: string
87
+ messageType: string
88
+ message: string
89
+ }
90
+
91
+ export interface IUtilsResponseModal {
92
+ modal: string,
93
+ action: string
94
+ }
95
+
96
+ export interface IUtilsResponseMessage {
97
+ type?: "success" | "warning" | "error" | "info"
98
+ title?: string
99
+ message?: string
100
+ text?: string
101
+ icon?: string
102
+ }
103
+
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
+ /**
113
+ * Retorna os tipos do arquivo <b>message.ts</b>
114
+ *
115
+ * @module utils
116
+ * @author Luiz Fernando Bernardes de Paula
117
+ */
118
+ export interface IUtilsMessage<T extends keyof IUtilsMessageOptions> {
119
+ message: IUtilsResponseMessage,
120
+ type?: "toast" | "message",
121
+ options?: IUtilsMessageOptions[T],
122
+ library?: keyof IUtilsMessageOptions
123
+ }
124
+
125
+ export interface IUtilsMessageOptions {
126
+ sweetAlert: SweetAlertOptions,
127
+ snackbar: SnackbarOptions
128
+ }
129
+
130
+ export declare function sendMessage<T extends keyof IUtilsMessageOptions>(params: IUtilsMessage<T>)
131
+
132
+ export declare function message<T extends keyof IUtilsMessageOptions>(params: IUtilsMessage<T>)
@@ -0,0 +1,350 @@
1
+ import $ from 'jquery';
2
+ import axios from 'axios';
3
+ import SweetAlert from 'sweetalert2';
4
+ import Snackbar from 'node-snackbar';
5
+
6
+ /**
7
+ * Envia a mensagem para o evento da janela
8
+ */
9
+ function sendMessage(params) {
10
+ let Window = window.self === window.top ? window : window.parent;
11
+ const { message, library, type, options } = params;
12
+ Window.postMessage({
13
+ type: "message",
14
+ params: {
15
+ message,
16
+ options,
17
+ type: type ?? "message",
18
+ library: library ?? "snackbar"
19
+ }
20
+ }, "*");
21
+ }
22
+ /**
23
+ * Retorna o objeto mensagem de acordo com os parâmetros
24
+ */
25
+ function message(params) {
26
+ let { message, library, type, options } = params;
27
+ library = library ?? "snackbar";
28
+ switch (library) {
29
+ case "sweetAlert":
30
+ let swal = {
31
+ icon: message.type,
32
+ title: message.title,
33
+ text: message.text
34
+ };
35
+ if (type === "toast") {
36
+ const Toast = SweetAlert.mixin(options !== undefined ? options
37
+ : {
38
+ toast: true,
39
+ position: "top-end",
40
+ showConfirmButton: false,
41
+ timer: 3000,
42
+ timerProgressBar: true,
43
+ didOpen: (toast) => {
44
+ toast.onmouseenter = SweetAlert.stopTimer;
45
+ toast.onmouseleave = SweetAlert.resumeTimer;
46
+ }
47
+ });
48
+ Toast.fire(swal);
49
+ }
50
+ else {
51
+ SweetAlert.fire({ ...swal, ...options });
52
+ }
53
+ break;
54
+ case "snackbar":
55
+ let config = options;
56
+ let text = message.message ?? message.text ?? message.title ?? "Não foi possível carregar a mensagem.";
57
+ Snackbar.show(config === undefined ? {
58
+ pos: "top-right",
59
+ showAction: false,
60
+ customClass: message.type,
61
+ text: "<p class='d-flex m-0 align-items-center'><i class='me-2 " + message.icon + "'></i>" + text + "</p>",
62
+ } : config);
63
+ break;
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Realiza a pesquisa do elemento html na DOM<br>
69
+ * <meta id="???" name="???" content="your-url">
70
+ */
71
+ function getMetaContent(id) {
72
+ let element = document.getElementById(id);
73
+ let url = element === null ? null : (element.content).replace(".br/", ".br");
74
+ return url === null ? null : url.substr(-1) === "/" ? url.slice(0, url.length - 1) : url;
75
+ }
76
+ /**
77
+ * Realiza a pesquisa do CEP na API pública "https://viacep.com.br/ws/"
78
+ */
79
+ async function getCep(value) {
80
+ let cep = value.length === 0 ? "00000000" : value.replace("-", "");
81
+ return await axios.get("https://viacep.com.br/ws/" + cep + "/json/")
82
+ .then(data => data.data);
83
+ }
84
+ /**
85
+ * Realiza a pesquisa do elemento na árvore DOM
86
+ */
87
+ function getElementDOM(element, preloadTimeOut) {
88
+ return new Promise((resolve) => {
89
+ // @ts-ignore
90
+ let body = window.self === window.top ? $("body") : $(window.frameElement).parents("body");
91
+ if (!element || element.length === 0) {
92
+ resolve(body);
93
+ }
94
+ if (element === "#" || element === ".") {
95
+ resolve(null);
96
+ }
97
+ let elementFound = body.find(element);
98
+ if (elementFound.length > 0) {
99
+ resolve(elementFound);
100
+ }
101
+ else {
102
+ setTimeout(() => {
103
+ let iframe = body.find("iframe").contents();
104
+ if (iframe.length === 0) {
105
+ resolve(null);
106
+ }
107
+ elementFound = iframe.find(element);
108
+ if (elementFound.length > 0) {
109
+ resolve(elementFound);
110
+ }
111
+ resolve(null);
112
+ }, preloadTimeOut ?? 300);
113
+ }
114
+ });
115
+ }
116
+ /**
117
+ * Permite à comunicação de origem cruzada entre objetos do Windows.<br>
118
+ * Exemplo: Comunicação entre iframe e corpo principal
119
+ */
120
+ function windowMessageEvent() {
121
+ window.addEventListener("message", function (event) {
122
+ if (event.data?.type === "message") {
123
+ let data = event.data;
124
+ message({ ...data.params });
125
+ }
126
+ });
127
+ }
128
+
129
+ const USER = getMetaContent("auth");
130
+ const BASE = getMetaContent("react-base");
131
+ const TOKEN = getMetaContent("csrf-token");
132
+
133
+ /**
134
+ * Realizei o gerenciamento do objeto de resposta
135
+ */
136
+ function response(response, form = "") {
137
+ let data = response;
138
+ if (!data) {
139
+ return;
140
+ }
141
+ if (data.redirect) {
142
+ window.location.href = data.redirect;
143
+ }
144
+ if (data.errors) {
145
+ messageField(data.errors, form.length === 0 ? "" : form);
146
+ }
147
+ if (data.accept) {
148
+ messageField(data.accept, form.length === 0 ? "" : form, "is-valid");
149
+ }
150
+ if (data.message && data?.errors === undefined) {
151
+ sendMessage({
152
+ message: { ...data.message },
153
+ type: "message",
154
+ library: "snackbar"
155
+ });
156
+ }
157
+ }
158
+ /**
159
+ * Exibe a mensagem no campo do formulário
160
+ */
161
+ function messageField(data, form = "", type = "is-invalid") {
162
+ tabViewActiveError(form, data);
163
+ getElementDOM("#" + form)
164
+ .then(formulario => {
165
+ if (formulario === null) {
166
+ return;
167
+ }
168
+ let validationFeedbackClass = type === "is-invalid" ? "invalid-feedback" : "valid-feedback";
169
+ let removeValidationFeedbackClass = type === "is-invalid" ? "is-valid" : "is-invalid";
170
+ $.each(data, (key, value) => {
171
+ let text = "";
172
+ value.forEach(value => text += value + "<br>");
173
+ formulario.find("input[name='" + key + "']")
174
+ .addClass(type)
175
+ .parent()
176
+ .find("#j_feedback[data-name='" + key + "']")
177
+ .addClass(validationFeedbackClass)
178
+ .removeClass(removeValidationFeedbackClass)
179
+ .html(text);
180
+ formulario.find("input[name='" + key + "']")
181
+ .addClass(type)
182
+ .parent()
183
+ .parent()
184
+ .find("#j_feedback[data-name='" + key + "']")
185
+ .addClass(validationFeedbackClass)
186
+ .removeClass(removeValidationFeedbackClass)
187
+ .html(text);
188
+ formulario.find("input[name='" + key + "']")
189
+ .addClass(type)
190
+ .parent()
191
+ .parent()
192
+ .parent()
193
+ .find("#j_feedback[data-name='" + key + "']")
194
+ .addClass(validationFeedbackClass)
195
+ .removeClass(removeValidationFeedbackClass)
196
+ .html(text);
197
+ formulario.find("select[name='" + key + "']")
198
+ .addClass(type)
199
+ .parent()
200
+ .find("#j_feedback[data-name='" + key + "']")
201
+ .addClass(validationFeedbackClass)
202
+ .removeClass(removeValidationFeedbackClass)
203
+ .html(text);
204
+ formulario.find("textarea[name='" + key + "']")
205
+ .addClass(type)
206
+ .parent()
207
+ .find("#j_feedback[data-name='" + key + "']")
208
+ .addClass(validationFeedbackClass)
209
+ .removeClass(removeValidationFeedbackClass)
210
+ .html(text);
211
+ formulario.find("#j_feedback[data-name='" + key + "']")
212
+ .addClass(type)
213
+ .html(text);
214
+ });
215
+ });
216
+ }
217
+ /**
218
+ * Limpar as mensagens de feedback do formulário
219
+ */
220
+ function messageFieldClear(form = "") {
221
+ getElementDOM("#" + form)
222
+ .then(formulario => {
223
+ if (formulario === null) {
224
+ return;
225
+ }
226
+ let validationClass = ["is-invalid", "is-valid", "p-invalid"];
227
+ let validationFeedbackClass = ["invalid-feedback", "valid-feedback"];
228
+ $.each(formulario.find("input"), function () {
229
+ $(this)
230
+ .removeClass(validationClass)
231
+ .parent()
232
+ .find("#j_feedback")
233
+ .removeClass(validationFeedbackClass)
234
+ .html("");
235
+ $(this)
236
+ .removeClass(validationClass)
237
+ .parent()
238
+ .parent()
239
+ .find("#j_feedback")
240
+ .removeClass(validationFeedbackClass)
241
+ .html("");
242
+ $(this)
243
+ .removeClass(validationClass)
244
+ .parent()
245
+ .parent()
246
+ .parent()
247
+ .find("#j_feedback")
248
+ .removeClass(validationFeedbackClass)
249
+ .html("");
250
+ });
251
+ $.each(formulario.find("select"), function () {
252
+ $(this)
253
+ .removeClass(validationClass)
254
+ .parent()
255
+ .find("#j_feedback")
256
+ .removeClass(validationFeedbackClass)
257
+ .html("");
258
+ });
259
+ $.each(formulario.find("textarea"), function () {
260
+ $(this)
261
+ .removeClass(validationClass)
262
+ .parent()
263
+ .find("#j_feedback")
264
+ .removeClass(validationFeedbackClass)
265
+ .html("");
266
+ });
267
+ $.each(formulario.find("#j_feedback"), function () {
268
+ $(this).removeClass(validationClass).html("");
269
+ });
270
+ });
271
+ }
272
+ /**
273
+ * Ativa o TabView quando o campo apresenta erro
274
+ */
275
+ function tabViewActiveError(form = "", errors) {
276
+ getElementDOM("#" + form)
277
+ .then(TabView => {
278
+ if (TabView === null) {
279
+ return;
280
+ }
281
+ let fieldError = Object.keys(errors)[0];
282
+ let TabViewSelected = TabView.find("*[id='" + fieldError + "']").closest(".tab-pane");
283
+ let TabViewSelectedId = TabViewSelected.attr("id");
284
+ let TabViewNav = TabViewSelected.parent().parent().find(".nav");
285
+ TabViewSelected.parent(".tab-content").children(".tab-pane").each(function (_, value) {
286
+ if (typeof value !== "undefined") {
287
+ if ($(value).attr("id") === TabViewSelectedId) {
288
+ $(value).addClass("show active");
289
+ TabViewNav.find("button[data-bs-target='#" + TabViewSelectedId + "']").addClass("active show");
290
+ }
291
+ else {
292
+ $(value).removeClass("show active");
293
+ TabViewNav.find("button[data-bs-target='#" + $(value).attr("id") + "']").removeClass("active");
294
+ }
295
+ }
296
+ });
297
+ });
298
+ }
299
+
300
+ /**
301
+ * Simplifica a solicitação POST HTTP usando a biblioteca axios
302
+ */
303
+ function post(route, body, form, options) {
304
+ return new Promise((resolve, reject) => {
305
+ let url = BASE + (route.startsWith("/") ? "" : "/") + route;
306
+ messageFieldClear(form);
307
+ handleToManyRequest(options?.url ?? url, options?.blockedToManyRequest ?? false);
308
+ axios({
309
+ method: "post",
310
+ url: options?.url ?? url,
311
+ headers: { "X-CSRF-TOKEN": TOKEN },
312
+ data: !body ? {} : body,
313
+ }).then(data => {
314
+ if (data?.data !== undefined) {
315
+ resolve(data.data);
316
+ }
317
+ if (typeof options?.blockedResponse !== "boolean" || options?.blockedResponse === false) {
318
+ response(data?.data, form);
319
+ }
320
+ }).catch(error => {
321
+ response(error.response?.data, form);
322
+ reject(error);
323
+ });
324
+ });
325
+ }
326
+ /**
327
+ * Bloqueia várias solicitações simultâneas
328
+ */
329
+ function handleToManyRequest(url, blocked) {
330
+ let requestCount = 0;
331
+ axios.interceptors.request.use(config => {
332
+ requestCount = requestCount + 1;
333
+ if (requestCount > 1 && axios.getUri(config) === url && blocked) {
334
+ return Promise.reject(new Error("Requisições bloqueadas!"));
335
+ }
336
+ return config;
337
+ });
338
+ if (!blocked) {
339
+ axios.interceptors.request.clear();
340
+ }
341
+ axios.interceptors.response.use(response => {
342
+ requestCount = requestCount - 1;
343
+ return response;
344
+ }, function (error) {
345
+ requestCount = requestCount - 1;
346
+ return Promise.reject(error);
347
+ });
348
+ }
349
+
350
+ export { BASE, TOKEN, USER, getCep, getElementDOM, getMetaContent, message, messageField, messageFieldClear, post, response, sendMessage, tabViewActiveError, windowMessageEvent };
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "./index.cjs.js",
3
+ "module": "./index.esm.js",
4
+ "types": "./index.d.ts"
5
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2023 Luiz Fernando Bernardes de Paula @OrangeCode
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
package/README.md DELETED
@@ -1,2 +0,0 @@
1
- <h1 align="center">@Orangecode/React</h1>
2
- <p>🚀 Em construção.</p>