@sysvale/show 1.0.0 → 1.1.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.
@@ -1,623 +0,0 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});function _interopDefault(e){return(e&&(typeof e==='object')&&'default'in e)?e['default']:e}var vue=require('vue'),swal=_interopDefault(require('sweetalert2')),get=_interopDefault(require('lodash.get')),camelCase=_interopDefault(require('lodash.camelcase')),isObject=_interopDefault(require('lodash.isobject')),snakeCase=_interopDefault(require('lodash.snakecase')),keyBy=_interopDefault(require('lodash.keyby'));var isArray = function (arg) { return Array.isArray(arg); };
2
-
3
- var convertKeysToCamelCase = function (data) {
4
- if (isArray(data)) {
5
- return data.map(function (element) {
6
- if (isObject(element) || isArray(element)) {
7
- return convertKeysToCamelCase(element);
8
- }
9
- return element;
10
- });
11
- }
12
- var newData = {};
13
- Object.keys(data).forEach(function (key) {
14
- if (isObject(data[key]) || isArray(data[key])) {
15
- newData[camelCase(key)] = convertKeysToCamelCase(data[key]);
16
- } else {
17
- newData[camelCase(key)] = data[key];
18
- }
19
- });
20
-
21
- return newData;
22
- };var isArray$1 = function (arg) { return Array.isArray(arg); };
23
-
24
- var convertKeysToSnakeCase = function (data) {
25
- if (isArray$1(data)) {
26
- return data.map(function (element) {
27
- if (isObject(element) || isArray$1(element)) {
28
- return convertKeysToSnakeCase(element);
29
- }
30
- return element;
31
- });
32
- }
33
- var newData = {};
34
- Object.keys(data).forEach(function (key) {
35
- if (isObject(data[key]) || isArray$1(data[key])) {
36
- newData[snakeCase(key)] = convertKeysToSnakeCase(data[key]);
37
- } else {
38
- newData[snakeCase(key)] = data[key];
39
- }
40
- });
41
-
42
- return newData;
43
- };function generateKey(length) {
44
- if ( length === void 0 ) length = 8;
45
-
46
- var result = '';
47
- var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
48
- var charactersLength = characters.length;
49
- for (var i = 0; i < length; i += 1) {
50
- result += characters.charAt(Math.floor(Math.random() * charactersLength));
51
- }
52
- return result;
53
- }function getFirstErrorMessage(response, fallbackMsg) {
54
- if ( fallbackMsg === void 0 ) fallbackMsg = 'Não conseguimos processar sua requisição. Tente novamente.';
55
-
56
- var errors = get(response, 'errors', false);
57
- if (!errors) { return fallbackMsg; }
58
- var ref = Object.keys(errors);
59
- var firstKey = ref[0];
60
- return errors[firstKey][0] || fallbackMsg;
61
- }var SUCCESS_SWAL_DEFAULT_CONFIG = {
62
- title: 'Informações salvas com sucesso!',
63
- icon: 'success',
64
- text: '',
65
- showCloseButton: true,
66
- confirmButtonText: 'Ok',
67
- };
68
-
69
- var ERROR_SWAL_DEFAULT_CONFIG = {
70
- icon: 'error',
71
- title: 'Erro',
72
- text: 'mensagem de error',
73
- showCancelButton: true,
74
- showConfirmButton: false,
75
- cancelButtonText: 'Fechar',
76
- };
77
-
78
- var script = {
79
- inject: ['$_requestObserver'],
80
- emits: ['success', 'error', 'success-feedback-ok', 'error-feedback-ok', 'success-feedback-cancel', 'error-feedback-cancel'],
81
- props: {
82
- vid: {
83
- type: String,
84
- default: function () { return generateKey(); },
85
- },
86
- tag: {
87
- type: String,
88
- default: 'div',
89
- },
90
- service: {
91
- type: Function,
92
- required: true,
93
- },
94
- payload: {
95
- type: Object,
96
- default: function () { return ({}); },
97
- },
98
- payloadResolver: {
99
- type: Function,
100
- default: function (data) { return convertKeysToSnakeCase(data); },
101
- },
102
- dataResolver: {
103
- type: Function,
104
- default: function (data) { return convertKeysToCamelCase(data); },
105
- },
106
- successSwalConfig: {
107
- type: Object,
108
- default: function () { return SUCCESS_SWAL_DEFAULT_CONFIG; },
109
- },
110
- errorSwalConfig: {
111
- type: Object,
112
- default: function () { return ERROR_SWAL_DEFAULT_CONFIG; },
113
- },
114
- errorFeedbackResolver: {
115
- type: Function,
116
- default: null,
117
- },
118
- successFeedbackResolver: {
119
- type: Function,
120
- default: null,
121
- },
122
- showSuccessFeedback: {
123
- type: Boolean,
124
- default: false,
125
- },
126
- hideErrorFeedback: {
127
- type: Boolean,
128
- default: false,
129
- },
130
- immediate: {
131
- type: Boolean,
132
- default: false,
133
- },
134
- forceResetError: {
135
- type: Boolean,
136
- default: false,
137
- },
138
- initialData: {
139
- default: null,
140
- },
141
- },
142
-
143
- data: function data() {
144
- return {
145
- loading: false,
146
- failed: false,
147
- succeeded: false,
148
- error: null,
149
- data: this.initialData,
150
- };
151
- },
152
-
153
- computed: {
154
- requestState: function requestState() {
155
- return {
156
- loading: this.loading,
157
- failed: this.failed,
158
- succeeded: this.succeeded,
159
- error: this.error,
160
- data: this.data,
161
- };
162
- }
163
- },
164
-
165
- watch: {
166
- forceResetError: function forceResetError(newValue) {
167
- if (newValue) {
168
- this.error = null;
169
- }
170
- },
171
- },
172
-
173
- mounted: function mounted() {
174
- if (this.immediate) {
175
- this.action();
176
- }
177
- },
178
-
179
- created: function created() {
180
- if(this.$_requestObserver) {
181
- this.$_requestObserver.subscribe(this);
182
- }
183
- },
184
-
185
- beforeDestroy: function beforeDestroy() {
186
- if(this.$_requestObserver) {
187
- this.$_requestObserver.unsubscribe(this);
188
- }
189
- },
190
-
191
- methods: {
192
- action: function action(payloadFromArgs) {
193
- var this$1 = this;
194
-
195
- this.startRequest();
196
- var payload = payloadFromArgs || this.payload;
197
- this.service(this.payloadResolver(payload))
198
- .then(
199
- function (ref) {
200
- var data = ref.data;
201
-
202
- this$1.data = this$1.dataResolver(data);
203
- this$1.succeeded = true;
204
- this$1.$emit('success', this$1.data);
205
-
206
- if (this$1.showSuccessFeedback) {
207
- if (this$1.successFeedbackResolver) {
208
- this$1.successFeedbackResolver({ vm: this$1, data: this$1.data });
209
- return;
210
- }
211
- swal.fire(Object.assign({}, SUCCESS_SWAL_DEFAULT_CONFIG,
212
- this$1.successSwalConfig)).then(function () {
213
- this$1.$emit('success-feedback-ok', this$1.data);
214
- });
215
- }
216
- }
217
- ).catch(
218
- function (error) {
219
- this$1.failed = true;
220
- this$1.error = error;
221
- this$1.$emit('error', error);
222
-
223
- if (!this$1.hideErrorFeedback) {
224
- var errorMessage = getFirstErrorMessage(
225
- get(error, 'response.data', null),
226
- 'Um erro aconteceu... por favor, tente novamente. Se o erro persistir, contate o suporte.'
227
- );
228
-
229
- if (this$1.errorFeedbackResolver) {
230
- this$1.errorFeedbackResolver({ vm: this$1, error: error, errorMessage: errorMessage });
231
- return;
232
- }
233
-
234
- swal.fire(Object.assign({}, ERROR_SWAL_DEFAULT_CONFIG,
235
- this$1.errorSwalConfig,
236
- {text: errorMessage})).then(function (result) {
237
- if (result.isDismissed) {
238
- this$1.$emit('error-feedback-cancel', error);
239
- }
240
- if (result.isConfirmed) {
241
- this$1.$emit('error-feedback-ok', error);
242
- }
243
- });
244
- }
245
- }
246
- ).finally(function () {
247
- this$1.loading = false;
248
- });
249
- },
250
-
251
- loadingTextResolver: function loadingTextResolver(label, loadingLabel) {
252
- if ( loadingLabel === void 0 ) loadingLabel = 'Carregando...';
253
-
254
- if (this.loading) {
255
- return loadingLabel;
256
- }
257
- return label;
258
- },
259
-
260
- startRequest: function startRequest() {
261
- this.loading = true;
262
- this.failed = false;
263
- this.succeeded = false;
264
- this.error = null;
265
- },
266
- },
267
-
268
- render: function render() {
269
- var slotProvider = this.$slots;
270
- var slot = slotProvider.default(Object.assign({}, this.requestState,
271
- {action: this.action,
272
- loadingTextResolver: this.loadingTextResolver,
273
- errorMessage: getFirstErrorMessage(
274
- get(this.error, 'response.data', null),
275
- 'Um erro aconteceu... por favor, tente novamente. Se o erro persistir, contate o suporte.'
276
- )}));
277
-
278
- return vue.h(this.tag, slot);
279
- },
280
- };function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
281
- if (typeof shadowMode !== 'boolean') {
282
- createInjectorSSR = createInjector;
283
- createInjector = shadowMode;
284
- shadowMode = false;
285
- }
286
- // Vue.extend constructor export interop.
287
- var options = typeof script === 'function' ? script.options : script;
288
- // render functions
289
- if (template && template.render) {
290
- options.render = template.render;
291
- options.staticRenderFns = template.staticRenderFns;
292
- options._compiled = true;
293
- // functional template
294
- if (isFunctionalTemplate) {
295
- options.functional = true;
296
- }
297
- }
298
- // scopedId
299
- if (scopeId) {
300
- options._scopeId = scopeId;
301
- }
302
- var hook;
303
- if (moduleIdentifier) {
304
- // server build
305
- hook = function (context) {
306
- // 2.3 injection
307
- context =
308
- context || // cached call
309
- (this.$vnode && this.$vnode.ssrContext) || // stateful
310
- (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext); // functional
311
- // 2.2 with runInNewContext: true
312
- if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
313
- context = __VUE_SSR_CONTEXT__;
314
- }
315
- // inject component styles
316
- if (style) {
317
- style.call(this, createInjectorSSR(context));
318
- }
319
- // register component module identifier for async chunk inference
320
- if (context && context._registeredComponents) {
321
- context._registeredComponents.add(moduleIdentifier);
322
- }
323
- };
324
- // used by ssr in case component is cached and beforeCreate
325
- // never gets called
326
- options._ssrRegister = hook;
327
- }
328
- else if (style) {
329
- hook = shadowMode
330
- ? function (context) {
331
- style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot));
332
- }
333
- : function (context) {
334
- style.call(this, createInjector(context));
335
- };
336
- }
337
- if (hook) {
338
- if (options.functional) {
339
- // register for functional component in vue file
340
- var originalRender = options.render;
341
- options.render = function renderWithStyleInjection(h, context) {
342
- hook.call(context);
343
- return originalRender(h, context);
344
- };
345
- }
346
- else {
347
- // inject component registration as beforeCreate hook
348
- var existing = options.beforeCreate;
349
- options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
350
- }
351
- }
352
- return script;
353
- }/* script */
354
- var __vue_script__ = script;
355
-
356
- /* template */
357
-
358
- /* style */
359
- var __vue_inject_styles__ = undefined;
360
- /* scoped */
361
- var __vue_scope_id__ = undefined;
362
- /* module identifier */
363
- var __vue_module_identifier__ = "data-v-77657dd0";
364
- /* functional template */
365
- var __vue_is_functional_template__ = undefined;
366
- /* style inject */
367
-
368
- /* style inject SSR */
369
-
370
- /* style inject shadow dom */
371
-
372
-
373
-
374
- var __vue_component__ = /*#__PURE__*/normalizeComponent(
375
- {},
376
- __vue_inject_styles__,
377
- __vue_script__,
378
- __vue_scope_id__,
379
- __vue_is_functional_template__,
380
- __vue_module_identifier__,
381
- false,
382
- undefined,
383
- undefined,
384
- undefined
385
- );var booleanReduceByProp = function (arr, prop, operator, defaultValue) {
386
- if ( operator === void 0 ) operator = '||';
387
- if ( defaultValue === void 0 ) defaultValue = false;
388
-
389
- return arr.reduce(function (acc, item) {
390
- if(operator === '||') {
391
- return acc || item[prop];
392
- } else if(operator === '&&') {
393
- return acc && item[prop];
394
- }
395
- }, defaultValue);
396
- };
397
-
398
- var script$1 = {
399
- emits: ['success', 'error'],
400
- props: {
401
- vid: {
402
- type: String,
403
- default: function () { return generateKey(); },
404
- },
405
- tag: {
406
- type: String,
407
- default: 'div',
408
- },
409
- },
410
- data: function data() {
411
- return {
412
- providers: [],
413
- providersVids: {},
414
- };
415
- },
416
- provide: function provide() {
417
- return {
418
- $_requestObserver: this,
419
- }
420
- },
421
-
422
- computed: {
423
- context: function context() {
424
- return {
425
- vid: this.vid,
426
- loading: booleanReduceByProp(this.providers, 'loading'),
427
- failed: booleanReduceByProp(this.providers, 'failed'),
428
- succeeded: booleanReduceByProp(this.providers, 'succeeded', '&&', true),
429
- errors: keyBy(this.providers.filter(function (ref) {
430
- var failed = ref.failed;
431
-
432
- return failed;
433
- }).map(function (ref) {
434
- var error = ref.error;
435
- var vid = ref.vid;
436
-
437
- return ({ error: error, vid: vid });
438
- }), 'vid'),
439
- providerRequestState: this.providerRequestState,
440
- loadingTextResolver: this.loadingTextResolver,
441
- };
442
- },
443
-
444
- providerRequestState: function providerRequestState() {
445
- var this$1 = this;
446
-
447
- return function (vid) {
448
- var element = this$1.providers.find(function (ref) {
449
- var providerVid = ref.vid;
450
-
451
- return providerVid === vid;
452
- });
453
- return element ? element.requestState : {
454
- loading: false,
455
- failed: false,
456
- succeeded: false,
457
- error: null,
458
- data: null,
459
- };
460
- }
461
- },
462
-
463
- loadingTextResolver: function loadingTextResolver() {
464
- var this$1 = this;
465
-
466
- return function (label, loadingLabel) {
467
- if ( loadingLabel === void 0 ) loadingLabel = 'Carregando...';
468
-
469
- if (this$1.context.loading) {
470
- return loadingLabel;
471
- }
472
- return label;
473
- }
474
- },
475
- },
476
-
477
- watch: {
478
- 'context.succeeded': {
479
- handler: function handler(newValue) {
480
- if (newValue) {
481
- this.$emit('success', this.context);
482
- }
483
- },
484
- },
485
- 'context.failed': {
486
- handler: function handler(newValue) {
487
- if (newValue) {
488
- this.$emit('error', this.context);
489
- }
490
- },
491
- },
492
- },
493
-
494
- render: function render() {
495
- var slotProvider = this.$slots;
496
- var slot = slotProvider.default(this.context);
497
- return vue.h(this.tag, slot);
498
- },
499
-
500
- methods: {
501
- subscribe: function subscribe(provider) {
502
- if(!this.providersVids[provider.vid]) {
503
- this.providersVids[provider.vid] = true;
504
- this.providers.push(provider);
505
- } else {
506
- throw new Error(("Provider não reigistrado no observer! Já existe um provider com o vid >> " + (provider.vid) + " <<"));
507
- }
508
- },
509
- unsubscribe: function unsubscribe(provider) {
510
- delete this.providersVids[provider.vid];
511
- this.providers.filter(function (ref) {
512
- var vid = ref.vid;
513
-
514
- return vid !== provider.vid;
515
- });
516
- },
517
- },
518
- };/* script */
519
- var __vue_script__$1 = script$1;
520
-
521
- /* template */
522
-
523
- /* style */
524
- var __vue_inject_styles__$1 = undefined;
525
- /* scoped */
526
- var __vue_scope_id__$1 = undefined;
527
- /* module identifier */
528
- var __vue_module_identifier__$1 = "data-v-074e0922";
529
- /* functional template */
530
- var __vue_is_functional_template__$1 = undefined;
531
- /* style inject */
532
-
533
- /* style inject SSR */
534
-
535
- /* style inject shadow dom */
536
-
537
-
538
-
539
- var __vue_component__$1 = /*#__PURE__*/normalizeComponent(
540
- {},
541
- __vue_inject_styles__$1,
542
- __vue_script__$1,
543
- __vue_scope_id__$1,
544
- __vue_is_functional_template__$1,
545
- __vue_module_identifier__$1,
546
- false,
547
- undefined,
548
- undefined,
549
- undefined
550
- );var components=/*#__PURE__*/Object.freeze({__proto__:null,RequestProvider: __vue_component__,RequestObserver: __vue_component__$1});function removeAccents(str) {
551
- if ( str === void 0 ) str = '';
552
-
553
- var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
554
- var accentsOut = 'AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz';
555
- var strLen = str.length;
556
- var newStr = str.split('');
557
- var x;
558
-
559
- for (var i = 0; i < strLen; i += 1) {
560
- x = accents.indexOf(str[i]);
561
- if (x !== -1) {
562
- newStr[i] = accentsOut[x];
563
- }
564
- }
565
-
566
- newStr = newStr.join('');
567
- newStr = newStr.split('.').join('');
568
- newStr = newStr.split('-').join('');
569
- newStr = newStr.split('/').join('');
570
-
571
- return newStr;
572
- }var utils = {
573
- $showConvertKeysToCamelCase: convertKeysToCamelCase,
574
- $showConvertKeysToSnakeCase: convertKeysToSnakeCase,
575
- $showRemoveAccents: removeAccents,
576
- $showGenerateKey: generateKey,
577
- };
578
-
579
- // install function executed by Vue.use()
580
- function install(app) {
581
- if (install.installed) { return; }
582
-
583
- install.installed = true;
584
-
585
- var version = Number(app.version.split('.')[0]);
586
-
587
- if (version <= 2) {
588
- throw new Error('Essa versão só é compatível com projetos que possuem o Vue 3. Para projetos com a Vue 2, utilize a versão 0.3.0 ou inferior');
589
- }
590
-
591
- if (version > 2) {
592
- // ficará disponível apenas com o uso do Options API
593
- Object.keys(utils).forEach(function (key) {
594
- app.config.globalProperties[key] = utils[key];
595
- });
596
- }
597
-
598
- Object.keys(components).forEach(function (componentName) {
599
- app.component(
600
- ("Show" + componentName),
601
- components[componentName]
602
- );
603
- });
604
- }
605
-
606
- // Create module definition for Vue.use()
607
- var plugin = {
608
- install: install,
609
- };
610
-
611
- // To auto-install when vue is found
612
- /* global window global */
613
- var GlobalVue = null;
614
-
615
- if (typeof window !== 'undefined') {
616
- GlobalVue = window.Vue;
617
- } else if (typeof global !== 'undefined') {
618
- GlobalVue = global.Vue;
619
- }
620
-
621
- if (GlobalVue) {
622
- GlobalVue.use(plugin);
623
- }exports.RequestObserver=__vue_component__$1;exports.RequestProvider=__vue_component__;exports.default=plugin;