UNPKG

79.1 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('lodash.get'), require('body-scroll-lock'), require('lodash.map')) :
3 typeof define === 'function' && define.amd ? define(['exports', 'vue', 'lodash.get', 'body-scroll-lock', 'lodash.map'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.VueTailwind = {}, global.Vue, global.get, global.bodyScrollLock, global.map));
5}(this, (function (exports, Vue, get, bodyScrollLock, map) { 'use strict';
6
7 function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
9 var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
10 var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
11 var map__default = /*#__PURE__*/_interopDefaultLegacy(map);
12
13 /* eslint-disable no-shadow */
14 var HideReason;
15 (function (HideReason) {
16 HideReason["Outside"] = "outside";
17 HideReason["Close"] = "close";
18 HideReason["Esc"] = "esc";
19 HideReason["Cancel"] = "cancel";
20 HideReason["Ok"] = "ok";
21 HideReason["Method"] = "method";
22 HideReason["Value"] = "value";
23 })(HideReason || (HideReason = {}));
24 var DialogType;
25 (function (DialogType) {
26 DialogType["Alert"] = "alert";
27 DialogType["Confirm"] = "confirm";
28 DialogType["Prompt"] = "prompt";
29 })(DialogType || (DialogType = {}));
30
31 /*! *****************************************************************************
32 Copyright (c) Microsoft Corporation.
33
34 Permission to use, copy, modify, and/or distribute this software for any
35 purpose with or without fee is hereby granted.
36
37 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
38 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
39 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
40 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
41 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
42 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
43 PERFORMANCE OF THIS SOFTWARE.
44 ***************************************************************************** */
45
46 function __awaiter(thisArg, _arguments, P, generator) {
47 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
48 return new (P || (P = Promise))(function (resolve, reject) {
49 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
50 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
51 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
52 step((generator = generator.apply(thisArg, _arguments || [])).next());
53 });
54 }
55
56 const mergeClasses = (classesA, classesB) => {
57 let a = classesA;
58 let b = classesB;
59 // Convert array of string classes to a single string
60 if (Array.isArray(classesA) && classesA.every((className) => typeof className === 'string' || !!className)) {
61 a = classesA.filter((className) => !!className).join(' ');
62 }
63 // Convert array of string classes to a single string
64 if (Array.isArray(classesB) && classesB.every((className) => typeof className === 'string' || !!className)) {
65 b = classesB.filter((className) => !!className).join(' ');
66 }
67 if (typeof a === 'string' && typeof b === 'string') {
68 return `${a} ${b}`;
69 }
70 if (typeof a === 'string' && Array.isArray(b)) {
71 return [a].concat(b);
72 }
73 if (typeof b === 'string' && Array.isArray(a)) {
74 return a.concat([b]);
75 }
76 if (Array.isArray(a) && Array.isArray(b)) {
77 return a.concat(b);
78 }
79 return [a, b];
80 };
81 const Component = Vue__default['default'].extend({
82 props: {
83 classes: {
84 type: [String, Array, Object],
85 default: undefined,
86 },
87 fixedClasses: {
88 type: [String, Array, Object],
89 default: undefined,
90 },
91 variants: {
92 type: Object,
93 default: undefined,
94 },
95 variant: {
96 type: [String, Object],
97 default: undefined,
98 },
99 },
100 computed: {
101 componentClass() {
102 return this.getElementCssClass();
103 },
104 activeVariant() {
105 if (!this.variant) {
106 return undefined;
107 }
108 if (typeof this.variant === 'object') {
109 const truthyVariant = Object.keys(this.variant).find((variant) => !!this.variant[variant]);
110 return truthyVariant || undefined;
111 }
112 return this.variant;
113 },
114 },
115 methods: {
116 getElementCssClass(elementName, defaultClasses = '') {
117 let classes;
118 if (elementName) {
119 if (this.activeVariant) {
120 const elementVariant = get__default['default'](this.variants, `${this.activeVariant}.${elementName}`);
121 // If the variant exists but not for the element fallback to the default
122 if (elementVariant === undefined
123 && get__default['default'](this.variants, this.activeVariant) !== undefined) {
124 classes = get__default['default'](this.classes, elementName, defaultClasses);
125 }
126 else {
127 classes = elementVariant === undefined ? defaultClasses : elementVariant;
128 }
129 }
130 else {
131 classes = get__default['default'](this.classes, elementName, defaultClasses);
132 }
133 const fixedClasses = get__default['default'](this.fixedClasses, elementName);
134 if (fixedClasses) {
135 return mergeClasses(fixedClasses, classes);
136 }
137 return classes;
138 }
139 if (this.activeVariant) {
140 classes = get__default['default'](this.variants, this.activeVariant, defaultClasses);
141 }
142 else {
143 classes = this.classes === undefined ? defaultClasses : this.classes;
144 }
145 if (this.fixedClasses) {
146 return mergeClasses(this.fixedClasses, classes);
147 }
148 return classes;
149 },
150 },
151 });
152
153 /* eslint-disable no-shadow */
154 var Key;
155 (function (Key) {
156 Key[Key["LEFT"] = 37] = "LEFT";
157 Key[Key["UP"] = 38] = "UP";
158 Key[Key["RIGHT"] = 39] = "RIGHT";
159 Key[Key["DOWN"] = 40] = "DOWN";
160 Key[Key["ENTER"] = 13] = "ENTER";
161 Key[Key["ESC"] = 27] = "ESC";
162 Key[Key["SPACE"] = 32] = "SPACE";
163 Key[Key["BACKSPACE"] = 8] = "BACKSPACE";
164 })(Key || (Key = {}));
165 var Key$1 = Key;
166
167 const guessOptionValue = (option, valueAttribute) => {
168 if (valueAttribute) {
169 return get__default['default'](option, valueAttribute);
170 }
171 return get__default['default'](option, 'value', get__default['default'](option, 'id', get__default['default'](option, 'text')));
172 };
173 const guessOptionText = (option, textAttribute) => {
174 if (textAttribute) {
175 return get__default['default'](option, textAttribute);
176 }
177 return get__default['default'](option, 'text', get__default['default'](option, 'label'));
178 };
179 const normalizeOption = (option, textAttribute, valueAttribute) => {
180 if (typeof option === 'string'
181 || typeof option === 'number'
182 || typeof option === 'boolean') {
183 return {
184 value: option,
185 text: option,
186 raw: option,
187 };
188 }
189 if (option.children) {
190 const children = option.children.map((childOption) => normalizeOption(childOption));
191 return {
192 value: guessOptionValue(option, valueAttribute),
193 text: guessOptionText(option, textAttribute),
194 children,
195 };
196 }
197 const normalizedOption = {
198 value: guessOptionValue(option, valueAttribute),
199 text: guessOptionText(option, textAttribute),
200 raw: option,
201 };
202 if (option.disabled !== undefined) {
203 normalizedOption.disabled = option.disabled;
204 }
205 return normalizedOption;
206 };
207 const normalizeOptions = (options, textAttribute, valueAttribute) => {
208 if (!options) {
209 return [];
210 }
211 if (Array.isArray(options)) {
212 return options.map((option) => normalizeOption(option, textAttribute, valueAttribute));
213 }
214 return map__default['default'](options, (option, key) => ({
215 value: key,
216 text: option,
217 }));
218 };
219
220 const uniqid = () => Math.random().toString(36).substring(7);
221
222 const TDialogOverlayWrapperTransitionDialogContentInput = Vue__default['default'].extend({
223 name: 'TDialogOverlayWrapperTransitionDialogContentInput',
224 props: {
225 getElementCssClass: {
226 type: Function,
227 required: true,
228 },
229 inputAttributes: {
230 type: Object,
231 default: undefined,
232 },
233 inputType: {
234 type: String,
235 required: true,
236 },
237 inputValue: {
238 type: [String, Array],
239 default: undefined,
240 },
241 inputPlaceholder: {
242 type: String,
243 default: undefined,
244 },
245 inputOptions: {
246 type: [Array, Object],
247 default: undefined,
248 },
249 },
250 data() {
251 return {
252 errorMessage: null,
253 };
254 },
255 mounted() {
256 this.inputHandler();
257 },
258 methods: {
259 getInputValue() {
260 const input = this.$refs.input;
261 if (!input) {
262 return undefined;
263 }
264 const inputName = input.name;
265 if (input.type === 'radio') {
266 const checkedRadio = this.$refs.inputWrapper
267 .querySelector(`input[name="${inputName}"]:checked`);
268 return checkedRadio ? checkedRadio.value : null;
269 }
270 if (input.type === 'checkbox') {
271 if (this.inputOptions) {
272 const checkedCheckboxes = this.$refs.inputWrapper
273 .querySelectorAll(`input[name="${inputName}"]:checked`);
274 const inititalValue = Array.from(checkedCheckboxes).map((checkbox) => checkbox.value);
275 return inititalValue;
276 }
277 return input.checked ? input.value : null;
278 }
279 return input.value;
280 },
281 inputHandler() {
282 this.errorMessage = null;
283 const inputValue = this.getInputValue();
284 this.$emit('input', inputValue);
285 },
286 },
287 render(createElement) {
288 let input;
289 if (this.inputType === 'select') {
290 const options = normalizeOptions((this.inputOptions || []))
291 .map((option) => {
292 const isSelected = this.inputValue === option.value;
293 return createElement('option', {
294 domProps: {
295 value: option.value,
296 selected: isSelected,
297 },
298 }, String(option.text));
299 });
300 input = createElement('select', {
301 class: this.getElementCssClass('select'),
302 ref: 'input',
303 attrs: Object.assign({ name: 'input' }, this.inputAttributes),
304 on: {
305 change: this.inputHandler,
306 },
307 }, options);
308 }
309 else if (this.inputType === 'radio') {
310 input = normalizeOptions((this.inputOptions || []))
311 .map((option) => {
312 const isChecked = this.inputValue === option.value;
313 return createElement('label', {
314 class: this.getElementCssClass('radioWrapper'),
315 attrs: {
316 for: `input-${String(option.value)}`,
317 },
318 }, [
319 createElement('input', {
320 class: this.getElementCssClass('radio'),
321 ref: 'input',
322 attrs: Object.assign({ type: 'radio', name: 'input', id: `input-${String(option.value)}`, value: option.value, checked: isChecked }, this.inputAttributes),
323 on: {
324 change: this.inputHandler,
325 },
326 }),
327 createElement('span', {
328 class: this.getElementCssClass('radioText'),
329 }, String(option.text)),
330 ]);
331 });
332 }
333 else if (this.inputType === 'checkbox') {
334 if (this.inputOptions) {
335 input = normalizeOptions((this.inputOptions || []))
336 .map((option) => {
337 const isChecked = Array.isArray(this.inputValue)
338 ? this.inputValue.includes(option.value)
339 : this.inputValue === option.value;
340 return createElement('label', {
341 class: this.getElementCssClass('checkboxWrapper'),
342 attrs: {
343 for: `input-${String(option.value)}`,
344 },
345 }, [
346 createElement('input', {
347 class: this.getElementCssClass('checkbox'),
348 ref: 'input',
349 attrs: Object.assign({ type: 'checkbox', name: 'input[]', id: `input-${String(option.value)}`, value: option.value, checked: isChecked }, this.inputAttributes),
350 on: {
351 change: this.inputHandler,
352 },
353 }),
354 createElement('span', {
355 class: this.getElementCssClass('checkboxText'),
356 }, String(option.text)),
357 ]);
358 });
359 }
360 else {
361 const id = uniqid();
362 input = createElement('label', {
363 class: this.getElementCssClass('checkboxWrapper'),
364 attrs: {
365 for: `input-${id}`,
366 },
367 }, [
368 createElement('input', {
369 class: this.getElementCssClass('checkbox'),
370 ref: 'input',
371 attrs: Object.assign({ type: 'checkbox', name: 'input', id: `input-${id}`, value: this.inputValue }, this.inputAttributes),
372 on: {
373 change: this.inputHandler,
374 },
375 }),
376 createElement('span', {
377 class: this.getElementCssClass('checkboxText'),
378 }, this.inputPlaceholder ? String(this.inputPlaceholder) : ''),
379 ]);
380 }
381 }
382 else {
383 input = createElement('input', {
384 class: this.getElementCssClass('input'),
385 ref: 'input',
386 domProps: {
387 value: this.inputValue,
388 },
389 attrs: Object.assign({ name: 'input', type: this.inputType, placeholder: this.inputPlaceholder }, this.inputAttributes),
390 on: {
391 input: this.inputHandler,
392 },
393 });
394 }
395 return createElement('div', {
396 ref: 'inputWrapper',
397 class: this.getElementCssClass('inputWrapper'),
398 }, Array.isArray(input) ? input : [input]);
399 },
400 });
401
402 const TDialogOverlayWrapperTransitionDialogContent = Vue__default['default'].extend({
403 name: 'TDialogOverlayWrapperTransitionDialogContent',
404 props: {
405 getElementCssClass: {
406 type: Function,
407 required: true,
408 },
409 titleTag: {
410 type: String,
411 required: true,
412 },
413 title: {
414 type: String,
415 default: undefined,
416 },
417 textTag: {
418 type: String,
419 required: true,
420 },
421 text: {
422 type: String,
423 default: undefined,
424 },
425 type: {
426 type: String,
427 required: true,
428 },
429 inputAttributes: {
430 type: Object,
431 default: undefined,
432 },
433 inputType: {
434 type: String,
435 required: true,
436 },
437 inputValue: {
438 type: [String, Array],
439 default: undefined,
440 },
441 inputPlaceholder: {
442 type: String,
443 default: undefined,
444 },
445 inputOptions: {
446 type: [Array, Object],
447 default: undefined,
448 },
449 errorMessage: {
450 type: String,
451 required: true,
452 },
453 },
454 render(createElement) {
455 const subElements = [];
456 if (this.title || this.$scopedSlots.title) {
457 if (this.$scopedSlots.title) {
458 subElements.push(createElement('div', {
459 class: this.getElementCssClass('titleWrapper'),
460 }, [
461 this.$scopedSlots.title({ class: this.getElementCssClass('title') }),
462 ]));
463 }
464 else {
465 subElements.push(createElement('div', {
466 class: this.getElementCssClass('titleWrapper'),
467 }, [
468 createElement(this.titleTag, {
469 class: this.getElementCssClass('title'),
470 }, this.title || ''),
471 ]));
472 }
473 }
474 if (this.$slots.default) {
475 subElements.push(createElement('div', {
476 class: this.getElementCssClass('textWrapper'),
477 }, this.$slots.default));
478 }
479 else if (this.text) {
480 subElements.push(createElement('div', {
481 class: this.getElementCssClass('textWrapper'),
482 }, this.text ? [
483 createElement(this.textTag, {
484 class: this.getElementCssClass('text'),
485 }, this.text),
486 ] : undefined));
487 }
488 if (this.type === DialogType.Prompt) {
489 subElements.push(createElement(TDialogOverlayWrapperTransitionDialogContentInput, {
490 props: {
491 getElementCssClass: this.getElementCssClass,
492 inputAttributes: this.inputAttributes,
493 inputType: this.inputType,
494 inputValue: this.inputValue,
495 inputOptions: this.inputOptions,
496 inputPlaceholder: this.inputPlaceholder,
497 },
498 on: {
499 input: (val) => this.$emit('input', val),
500 },
501 }));
502 }
503 if (this.errorMessage && typeof this.errorMessage === 'string') {
504 subElements.push(createElement('div', {
505 class: this.getElementCssClass('errorMessage'),
506 }, this.errorMessage));
507 }
508 return createElement('div', {
509 class: this.getElementCssClass('content'),
510 }, subElements);
511 },
512 });
513
514 var IconName;
515 (function (IconName) {
516 IconName["Success"] = "success";
517 IconName["Error"] = "error";
518 IconName["Warning"] = "warning";
519 IconName["Info"] = "info";
520 IconName["Question"] = "question";
521 })(IconName || (IconName = {}));
522 function getHtmlSvgPath(iconName) {
523 if (!iconName) {
524 return undefined;
525 }
526 const icons = {};
527 icons[IconName.Success] = '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>';
528 icons[IconName.Error] = '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>';
529 icons[IconName.Warning] = '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path>';
530 icons[IconName.Info] = '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>';
531 icons[IconName.Question] = '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>';
532 return icons[iconName];
533 }
534 const TDialogOverlayWrapperTransitionDialogIcon = Vue__default['default'].extend({
535 name: 'TDialogOverlayWrapperTransitionDialogIcon',
536 props: {
537 getElementCssClass: {
538 type: Function,
539 required: true,
540 },
541 icon: {
542 type: String,
543 default: undefined,
544 },
545 },
546 render(createElement) {
547 if (this.$scopedSlots.icon) {
548 return createElement('div', {
549 class: this.getElementCssClass('iconWrapper'),
550 }, [
551 this.$scopedSlots.icon({}),
552 ]);
553 }
554 const htmlSvgPath = getHtmlSvgPath(this.icon);
555 if (!htmlSvgPath) {
556 return createElement();
557 }
558 return createElement('div', {
559 class: this.getElementCssClass('iconWrapper'),
560 }, [
561 createElement('svg', {
562 class: this.getElementCssClass('icon'),
563 attrs: {
564 fill: 'none',
565 stroke: 'currentColor',
566 viewBox: '0 0 24 24',
567 xmlns: 'http://www.w3.org/2000/svg',
568 },
569 domProps: {
570 innerHTML: htmlSvgPath,
571 },
572 }),
573 ]);
574 },
575 });
576
577 const TDialogOverlayWrapperTransitionDialogClose = Vue__default['default'].extend({
578 name: 'TDialogOverlayWrapperTransitionDialogClose',
579 props: {
580 getElementCssClass: {
581 type: Function,
582 required: true,
583 },
584 showCloseButton: {
585 type: Boolean,
586 required: true,
587 },
588 },
589 render(createElement) {
590 if (!this.showCloseButton) {
591 return createElement();
592 }
593 if (this.$scopedSlots.closeButton) {
594 return createElement('button', {
595 class: this.getElementCssClass('close'),
596 attrs: {
597 type: 'button',
598 },
599 on: {
600 click: (e) => this.$emit('dismiss', e),
601 },
602 }, [
603 this.$scopedSlots.closeButton({}),
604 ]);
605 }
606 return createElement('button', {
607 class: this.getElementCssClass('close'),
608 attrs: {
609 type: 'button',
610 },
611 on: {
612 click: (e) => this.$emit('dismiss', e),
613 },
614 }, [
615 createElement('svg', {
616 attrs: {
617 fill: 'currentColor',
618 xmlns: 'http://www.w3.org/2000/svg',
619 viewBox: '0 0 20 20',
620 },
621 class: this.getElementCssClass('closeIcon'),
622 }, [
623 createElement('path', {
624 attrs: {
625 'clip-rule': 'evenodd',
626 'fill-rule': 'evenodd',
627 d: 'M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z',
628 },
629 }),
630 ]),
631 ]);
632 },
633 });
634
635 const TDialogOverlayWrapperTransitionDialogLoader = Vue__default['default'].extend({
636 name: 'TDialogOverlayWrapperTransitionDialogLoader',
637 props: {
638 getElementCssClass: {
639 type: Function,
640 required: true,
641 },
642 busy: {
643 type: Boolean,
644 required: true,
645 },
646 },
647 render(createElement) {
648 if (!this.busy) {
649 return createElement();
650 }
651 if (this.$scopedSlots.loader) {
652 return createElement('div', {
653 class: this.getElementCssClass('busyWrapper'),
654 }, [
655 this.$scopedSlots.loader({}),
656 ]);
657 }
658 return createElement('div', {
659 class: this.getElementCssClass('busyWrapper'),
660 }, [
661 createElement('svg', {
662 attrs: {
663 xmlns: 'http://www.w3.org/2000/svg',
664 width: 32,
665 height: 32,
666 viewBox: '0 0 32 32',
667 },
668 class: this.getElementCssClass('busyIcon'),
669 }, [
670 createElement('g', {
671 attrs: {
672 transform: 'scale(0.03125 0.03125)',
673 },
674 }, [
675 createElement('path', {
676 attrs: {
677 d: 'M512 1024c-136.76 0-265.334-53.258-362.040-149.96-96.702-96.706-149.96-225.28-149.96-362.040 0-96.838 27.182-191.134 78.606-272.692 50-79.296 120.664-143.372 204.356-185.3l43 85.832c-68.038 34.084-125.492 86.186-166.15 150.67-41.746 66.208-63.812 142.798-63.812 221.49 0 229.382 186.618 416 416 416s416-186.618 416-416c0-78.692-22.066-155.282-63.81-221.49-40.66-64.484-98.114-116.584-166.15-150.67l43-85.832c83.692 41.928 154.358 106.004 204.356 185.3 51.422 81.558 78.604 175.854 78.604 272.692 0 136.76-53.258 265.334-149.96 362.040-96.706 96.702-225.28 149.96-362.040 149.96z',
678 },
679 }),
680 ]),
681 ]),
682 ]);
683 },
684 });
685
686 const TDialogOverlayWrapperTransitionDialogButtons = Vue__default['default'].extend({
687 name: 'TDialogOverlayWrapperTransitionDialogButtons',
688 props: {
689 getElementCssClass: {
690 type: Function,
691 required: true,
692 },
693 cancelButtonText: {
694 type: String,
695 required: true,
696 },
697 cancelButtonAriaLabel: {
698 type: String,
699 default: undefined,
700 },
701 okButtonText: {
702 type: String,
703 required: true,
704 },
705 okButtonAriaLabel: {
706 type: String,
707 default: undefined,
708 },
709 type: {
710 type: String,
711 required: true,
712 },
713 },
714 methods: {
715 cancel(e) {
716 this.$emit('cancel', e);
717 },
718 ok(e) {
719 this.$emit('submit', e);
720 },
721 },
722 render(createElement) {
723 const type = this.type;
724 if (this.$scopedSlots.buttons) {
725 return createElement('div', {
726 class: this.getElementCssClass('buttons'),
727 }, [
728 this.$scopedSlots.buttons({
729 cancelButtonAriaLabel: this.cancelButtonAriaLabel,
730 okButtonAriaLabel: this.okButtonAriaLabel,
731 cancelButtonText: this.cancelButtonText,
732 okButtonText: this.okButtonText,
733 okButtonClass: this.getElementCssClass('okButton'),
734 cancelButtonClass: this.getElementCssClass('cancelButton'),
735 dialogType: type,
736 cancel: this.cancel,
737 ok: this.ok,
738 }),
739 ]);
740 }
741 const subElements = [];
742 const buttons = {
743 cancel: createElement('button', {
744 attrs: {
745 type: 'button',
746 'aria-label': this.cancelButtonAriaLabel,
747 },
748 class: this.getElementCssClass('cancelButton'),
749 on: {
750 click: this.cancel,
751 },
752 }, this.cancelButtonText),
753 ok: createElement('button', {
754 attrs: {
755 type: 'button',
756 'aria-label': this.okButtonAriaLabel,
757 },
758 class: this.getElementCssClass('okButton'),
759 on: {
760 click: this.ok,
761 },
762 }, this.okButtonText),
763 };
764 if (type === DialogType.Alert) {
765 subElements.push(buttons.ok);
766 }
767 else if (type === DialogType.Confirm || type === DialogType.Prompt) {
768 subElements.push(buttons.cancel);
769 subElements.push(buttons.ok);
770 }
771 return createElement('div', {
772 class: this.getElementCssClass('buttons'),
773 }, subElements);
774 },
775 });
776
777 const TDialogOverlayWrapperTransitionDialog = Vue__default['default'].extend({
778 name: 'TDialogOverlayWrapperTransitionDialog',
779 props: {
780 getElementCssClass: {
781 type: Function,
782 required: true,
783 },
784 dialogShow: {
785 type: Boolean,
786 required: true,
787 },
788 titleTag: {
789 type: String,
790 required: true,
791 },
792 title: {
793 type: String,
794 default: undefined,
795 },
796 icon: {
797 type: String,
798 default: undefined,
799 },
800 textTag: {
801 type: String,
802 required: true,
803 },
804 text: {
805 type: String,
806 default: undefined,
807 },
808 cancelButtonText: {
809 type: String,
810 required: true,
811 },
812 cancelButtonAriaLabel: {
813 type: String,
814 default: undefined,
815 },
816 okButtonText: {
817 type: String,
818 required: true,
819 },
820 okButtonAriaLabel: {
821 type: String,
822 default: undefined,
823 },
824 showCloseButton: {
825 type: Boolean,
826 required: true,
827 },
828 preConfirm: {
829 type: Function,
830 default: undefined,
831 },
832 inputAttributes: {
833 type: Object,
834 default: undefined,
835 },
836 inputType: {
837 type: String,
838 required: true,
839 },
840 inputValidator: {
841 type: Function,
842 default: undefined,
843 },
844 inputValue: {
845 type: [String, Array],
846 default: undefined,
847 },
848 inputOptions: {
849 type: [Array, Object],
850 default: undefined,
851 },
852 inputPlaceholder: {
853 type: String,
854 default: undefined,
855 },
856 type: {
857 type: String,
858 required: true,
859 },
860 },
861 data() {
862 return {
863 currentValue: null,
864 errorMessage: '',
865 busy: false,
866 };
867 },
868 methods: {
869 submitHandler(e) {
870 return this.resolveParam(this.inputValidator, this.currentValue)
871 .then((errorMessage) => {
872 if (errorMessage && typeof errorMessage === 'string') {
873 this.errorMessage = String(errorMessage);
874 return;
875 }
876 this.resolveParam(this.preConfirm, this.currentValue)
877 .then((response) => {
878 this.$emit('submit', e, this.currentValue, response);
879 }).catch((error) => {
880 this.$emit('submit-error', e, this.currentValue, error);
881 }).then(() => {
882 this.busy = false;
883 });
884 }).catch((errorMessage) => {
885 this.errorMessage = String(errorMessage);
886 });
887 },
888 inputHandler(input) {
889 this.errorMessage = '';
890 this.currentValue = input;
891 },
892 resolveParam(resolvable, input) {
893 if (typeof resolvable === 'function') {
894 const result = resolvable(input);
895 if (result instanceof Promise) {
896 this.busy = true;
897 return result;
898 }
899 return new Promise((resolve) => {
900 resolve(result);
901 });
902 }
903 return new Promise((resolve) => resolve());
904 },
905 },
906 render(createElement) {
907 if (!this.dialogShow) {
908 return createElement();
909 }
910 return createElement('div', {
911 ref: 'dialog',
912 class: this.getElementCssClass('dialog'),
913 }, [
914 createElement(TDialogOverlayWrapperTransitionDialogLoader, {
915 props: {
916 getElementCssClass: this.getElementCssClass,
917 busy: this.busy,
918 },
919 scopedSlots: {
920 loader: this.$scopedSlots.loader,
921 },
922 }),
923 createElement(TDialogOverlayWrapperTransitionDialogClose, {
924 props: {
925 getElementCssClass: this.getElementCssClass,
926 showCloseButton: this.showCloseButton,
927 },
928 on: {
929 dismiss: (e) => this.$emit('dismiss', e),
930 },
931 scopedSlots: {
932 closeButton: this.$scopedSlots.closeButton,
933 },
934 }),
935 createElement('div', {
936 ref: 'body',
937 class: this.getElementCssClass('body'),
938 }, [
939 createElement(TDialogOverlayWrapperTransitionDialogIcon, {
940 props: {
941 getElementCssClass: this.getElementCssClass,
942 icon: this.icon,
943 },
944 scopedSlots: {
945 icon: this.$scopedSlots.icon,
946 },
947 }),
948 createElement(TDialogOverlayWrapperTransitionDialogContent, {
949 props: {
950 getElementCssClass: this.getElementCssClass,
951 titleTag: this.titleTag,
952 title: this.title,
953 textTag: this.textTag,
954 text: this.text,
955 type: this.type,
956 inputAttributes: this.inputAttributes,
957 inputType: this.inputType,
958 inputValue: this.inputValue,
959 inputOptions: this.inputOptions,
960 inputPlaceholder: this.inputPlaceholder,
961 errorMessage: this.errorMessage,
962 },
963 on: {
964 input: this.inputHandler,
965 },
966 scopedSlots: {
967 title: this.$scopedSlots.title,
968 },
969 }, this.$slots.default),
970 ]),
971 createElement(TDialogOverlayWrapperTransitionDialogButtons, {
972 props: {
973 getElementCssClass: this.getElementCssClass,
974 type: this.type,
975 cancelButtonText: this.cancelButtonText,
976 cancelButtonAriaLabel: this.cancelButtonAriaLabel,
977 okButtonText: this.okButtonText,
978 okButtonAriaLabel: this.okButtonAriaLabel,
979 },
980 on: {
981 cancel: (e) => this.$emit('cancel', e),
982 submit: this.submitHandler,
983 },
984 scopedSlots: {
985 buttons: this.$scopedSlots.buttons,
986 },
987 }),
988 ]);
989 },
990 });
991
992 const TDialogOverlayWrapperTransition = Vue__default['default'].extend({
993 name: 'TDialogOverlayWrapperTransition',
994 props: {
995 getElementCssClass: {
996 type: Function,
997 required: true,
998 },
999 dialogShow: {
1000 type: Boolean,
1001 required: true,
1002 },
1003 titleTag: {
1004 type: String,
1005 required: true,
1006 },
1007 title: {
1008 type: String,
1009 default: undefined,
1010 },
1011 icon: {
1012 type: String,
1013 default: undefined,
1014 },
1015 textTag: {
1016 type: String,
1017 required: true,
1018 },
1019 text: {
1020 type: String,
1021 default: undefined,
1022 },
1023 cancelButtonText: {
1024 type: String,
1025 required: true,
1026 },
1027 cancelButtonAriaLabel: {
1028 type: String,
1029 default: undefined,
1030 },
1031 okButtonText: {
1032 type: String,
1033 required: true,
1034 },
1035 okButtonAriaLabel: {
1036 type: String,
1037 default: undefined,
1038 },
1039 showCloseButton: {
1040 type: Boolean,
1041 required: true,
1042 },
1043 preConfirm: {
1044 type: Function,
1045 default: undefined,
1046 },
1047 inputAttributes: {
1048 type: Object,
1049 default: undefined,
1050 },
1051 inputType: {
1052 type: String,
1053 required: true,
1054 },
1055 inputValidator: {
1056 type: Function,
1057 default: undefined,
1058 },
1059 inputValue: {
1060 type: [String, Array],
1061 default: undefined,
1062 },
1063 inputOptions: {
1064 type: [Array, Object],
1065 default: undefined,
1066 },
1067 inputPlaceholder: {
1068 type: String,
1069 default: undefined,
1070 },
1071 type: {
1072 type: String,
1073 required: true,
1074 },
1075 },
1076 render(createElement) {
1077 return createElement('transition', {
1078 props: {
1079 enterClass: this.getElementCssClass('enterClass'),
1080 enterActiveClass: this.getElementCssClass('enterActiveClass'),
1081 enterToClass: this.getElementCssClass('enterToClass'),
1082 leaveClass: this.getElementCssClass('leaveClass'),
1083 leaveActiveClass: this.getElementCssClass('leaveActiveClass'),
1084 leaveToClass: this.getElementCssClass('leaveToClass'),
1085 },
1086 }, [
1087 createElement(TDialogOverlayWrapperTransitionDialog, {
1088 props: {
1089 getElementCssClass: this.getElementCssClass,
1090 dialogShow: this.dialogShow,
1091 titleTag: this.titleTag,
1092 title: this.title,
1093 icon: this.icon,
1094 textTag: this.textTag,
1095 text: this.text,
1096 cancelButtonText: this.cancelButtonText,
1097 cancelButtonAriaLabel: this.cancelButtonAriaLabel,
1098 okButtonText: this.okButtonText,
1099 okButtonAriaLabel: this.okButtonAriaLabel,
1100 showCloseButton: this.showCloseButton,
1101 preConfirm: this.preConfirm,
1102 inputAttributes: this.inputAttributes,
1103 inputType: this.inputType,
1104 inputValidator: this.inputValidator,
1105 inputValue: this.inputValue,
1106 inputOptions: this.inputOptions,
1107 inputPlaceholder: this.inputPlaceholder,
1108 type: this.type,
1109 },
1110 scopedSlots: this.$scopedSlots,
1111 on: {
1112 dismiss: (e) => this.$emit('dismiss', e),
1113 cancel: (e) => this.$emit('cancel', e),
1114 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1115 submit: (e, input, response) => this.$emit('submit', e, input, response),
1116 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1117 'submit-error': (e, input, error) => this.$emit('submit-error', e, input, error),
1118 },
1119 }, this.$slots.default),
1120 ]);
1121 },
1122 });
1123
1124 const TDialogOverlayWrapper = Vue__default['default'].extend({
1125 name: 'TDialogOverlayWrapper',
1126 props: {
1127 getElementCssClass: {
1128 type: Function,
1129 required: true,
1130 },
1131 dialogShow: {
1132 type: Boolean,
1133 required: true,
1134 },
1135 titleTag: {
1136 type: String,
1137 required: true,
1138 },
1139 title: {
1140 type: String,
1141 default: undefined,
1142 },
1143 icon: {
1144 type: String,
1145 default: undefined,
1146 },
1147 textTag: {
1148 type: String,
1149 required: true,
1150 },
1151 text: {
1152 type: String,
1153 default: undefined,
1154 },
1155 cancelButtonText: {
1156 type: String,
1157 required: true,
1158 },
1159 cancelButtonAriaLabel: {
1160 type: String,
1161 default: undefined,
1162 },
1163 okButtonText: {
1164 type: String,
1165 required: true,
1166 },
1167 okButtonAriaLabel: {
1168 type: String,
1169 default: undefined,
1170 },
1171 showCloseButton: {
1172 type: Boolean,
1173 required: true,
1174 },
1175 preConfirm: {
1176 type: Function,
1177 default: undefined,
1178 },
1179 inputAttributes: {
1180 type: Object,
1181 default: undefined,
1182 },
1183 inputType: {
1184 type: String,
1185 required: true,
1186 },
1187 inputValidator: {
1188 type: Function,
1189 default: undefined,
1190 },
1191 inputValue: {
1192 type: [String, Array],
1193 default: undefined,
1194 },
1195 inputOptions: {
1196 type: [Array, Object],
1197 default: undefined,
1198 },
1199 inputPlaceholder: {
1200 type: String,
1201 default: undefined,
1202 },
1203 type: {
1204 type: String,
1205 required: true,
1206 },
1207 },
1208 render(createElement) {
1209 return createElement('div', {
1210 ref: 'wrapper',
1211 class: this.getElementCssClass('wrapper'),
1212 }, [
1213 createElement(TDialogOverlayWrapperTransition, {
1214 props: {
1215 type: this.type,
1216 dialogShow: this.dialogShow,
1217 getElementCssClass: this.getElementCssClass,
1218 titleTag: this.titleTag,
1219 title: this.title,
1220 icon: this.icon,
1221 textTag: this.textTag,
1222 text: this.text,
1223 cancelButtonText: this.cancelButtonText,
1224 cancelButtonAriaLabel: this.cancelButtonAriaLabel,
1225 okButtonText: this.okButtonText,
1226 okButtonAriaLabel: this.okButtonAriaLabel,
1227 showCloseButton: this.showCloseButton,
1228 preConfirm: this.preConfirm,
1229 inputAttributes: this.inputAttributes,
1230 inputType: this.inputType,
1231 inputValidator: this.inputValidator,
1232 inputValue: this.inputValue,
1233 inputOptions: this.inputOptions,
1234 inputPlaceholder: this.inputPlaceholder,
1235 },
1236 scopedSlots: this.$scopedSlots,
1237 on: {
1238 dismiss: (e) => this.$emit('dismiss', e),
1239 cancel: (e) => this.$emit('cancel', e),
1240 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1241 submit: (e, input, response) => this.$emit('submit', e, input, response),
1242 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1243 'submit-error': (e, input, error) => this.$emit('submit-error', e, input, error),
1244 },
1245 }, this.$slots.default),
1246 ]);
1247 },
1248 });
1249
1250 const TDialogOverlay = Vue__default['default'].extend({
1251 name: 'TDialogOverlay',
1252 props: {
1253 getElementCssClass: {
1254 type: Function,
1255 required: true,
1256 },
1257 overlayShow: {
1258 type: Boolean,
1259 required: true,
1260 },
1261 dialogShow: {
1262 type: Boolean,
1263 required: true,
1264 },
1265 titleTag: {
1266 type: String,
1267 required: true,
1268 },
1269 title: {
1270 type: String,
1271 default: undefined,
1272 },
1273 textTag: {
1274 type: String,
1275 required: true,
1276 },
1277 text: {
1278 type: String,
1279 default: undefined,
1280 },
1281 icon: {
1282 type: String,
1283 default: undefined,
1284 },
1285 cancelButtonText: {
1286 type: String,
1287 required: true,
1288 },
1289 cancelButtonAriaLabel: {
1290 type: String,
1291 default: undefined,
1292 },
1293 okButtonText: {
1294 type: String,
1295 required: true,
1296 },
1297 okButtonAriaLabel: {
1298 type: String,
1299 default: undefined,
1300 },
1301 showCloseButton: {
1302 type: Boolean,
1303 required: true,
1304 },
1305 preConfirm: {
1306 type: Function,
1307 default: undefined,
1308 },
1309 inputAttributes: {
1310 type: Object,
1311 default: undefined,
1312 },
1313 inputType: {
1314 type: String,
1315 required: true,
1316 },
1317 inputValidator: {
1318 type: Function,
1319 default: undefined,
1320 },
1321 inputValue: {
1322 type: [String, Array],
1323 default: undefined,
1324 },
1325 inputOptions: {
1326 type: [Array, Object],
1327 default: undefined,
1328 },
1329 inputPlaceholder: {
1330 type: String,
1331 default: undefined,
1332 },
1333 type: {
1334 type: String,
1335 default: null,
1336 },
1337 },
1338 methods: {
1339 clickHandler(e) {
1340 if (e.target !== this.$el) {
1341 return;
1342 }
1343 this.$emit('outside-click', e);
1344 },
1345 keyupHandler(e) {
1346 this.$emit('keyup', e);
1347 },
1348 focus() {
1349 const overlay = this.$el;
1350 if (overlay && overlay.focus) {
1351 overlay.focus();
1352 }
1353 },
1354 enableBodyScroll() {
1355 const mdl = this.$el;
1356 bodyScrollLock.enableBodyScroll(mdl);
1357 },
1358 disableBodyScroll() {
1359 const mdl = this.$el;
1360 bodyScrollLock.disableBodyScroll(mdl, {
1361 reserveScrollBarGap: true,
1362 });
1363 },
1364 },
1365 render(createElement) {
1366 if (!this.overlayShow) {
1367 return createElement();
1368 }
1369 return createElement('div', {
1370 attrs: {
1371 tabindex: 0,
1372 },
1373 class: this.getElementCssClass('overlay'),
1374 on: {
1375 keyup: this.keyupHandler,
1376 click: this.clickHandler,
1377 },
1378 }, [
1379 createElement(TDialogOverlayWrapper, {
1380 props: {
1381 type: this.type,
1382 getElementCssClass: this.getElementCssClass,
1383 dialogShow: this.dialogShow,
1384 titleTag: this.titleTag,
1385 title: this.title,
1386 icon: this.icon,
1387 textTag: this.textTag,
1388 text: this.text,
1389 cancelButtonText: this.cancelButtonText,
1390 cancelButtonAriaLabel: this.cancelButtonAriaLabel,
1391 okButtonText: this.okButtonText,
1392 okButtonAriaLabel: this.okButtonAriaLabel,
1393 showCloseButton: this.showCloseButton,
1394 preConfirm: this.preConfirm,
1395 inputAttributes: this.inputAttributes,
1396 inputType: this.inputType,
1397 inputValidator: this.inputValidator,
1398 inputValue: this.inputValue,
1399 inputOptions: this.inputOptions,
1400 inputPlaceholder: this.inputPlaceholder,
1401 },
1402 scopedSlots: this.$scopedSlots,
1403 on: {
1404 dismiss: (e) => this.$emit('dismiss', e),
1405 cancel: (e) => this.$emit('cancel', e),
1406 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1407 submit: (e, input, response) => this.$emit('submit', e, input, response),
1408 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1409 'submit-error': (e, input, error) => this.$emit('submit-error', e, input, error),
1410 },
1411 }, this.$slots.default),
1412 ]);
1413 },
1414 });
1415
1416 const getInitialData = (vm) => ({
1417 overlayShow: vm.value,
1418 dialogShow: vm.value,
1419 params: undefined,
1420 preventAction: false,
1421 hideReason: undefined,
1422 input: undefined,
1423 resolve: null,
1424 reject: null,
1425 preConfirmResponse: undefined,
1426 preConfirmError: undefined,
1427 });
1428 const TDialog = Component.extend({
1429 name: 'TDialog',
1430 props: {
1431 value: {
1432 type: Boolean,
1433 default: false,
1434 },
1435 name: {
1436 type: String,
1437 default: undefined,
1438 },
1439 titleTag: {
1440 type: String,
1441 default: 'h3',
1442 },
1443 title: {
1444 type: String,
1445 default: undefined,
1446 },
1447 icon: {
1448 type: String,
1449 default: undefined,
1450 },
1451 textTag: {
1452 type: String,
1453 default: 'p',
1454 },
1455 text: {
1456 type: String,
1457 default: undefined,
1458 },
1459 clickToClose: {
1460 type: Boolean,
1461 default: true,
1462 },
1463 escToClose: {
1464 type: Boolean,
1465 default: true,
1466 },
1467 cancelButtonText: {
1468 type: String,
1469 default: 'Cancel',
1470 },
1471 cancelButtonAriaLabel: {
1472 type: String,
1473 default: undefined,
1474 },
1475 okButtonText: {
1476 type: String,
1477 default: 'OK',
1478 },
1479 okButtonAriaLabel: {
1480 type: String,
1481 default: undefined,
1482 },
1483 showCloseButton: {
1484 type: Boolean,
1485 default: false,
1486 },
1487 disableBodyScroll: {
1488 type: Boolean,
1489 default: true,
1490 },
1491 focusOnOpen: {
1492 type: Boolean,
1493 default: true,
1494 },
1495 preConfirm: {
1496 type: Function,
1497 default: undefined,
1498 },
1499 inputAttributes: {
1500 type: Object,
1501 default: undefined,
1502 },
1503 inputType: {
1504 type: String,
1505 default: 'text',
1506 },
1507 inputValidator: {
1508 type: Function,
1509 default: undefined,
1510 },
1511 inputValue: {
1512 type: [String, Array],
1513 default: undefined,
1514 },
1515 inputOptions: {
1516 type: [Array, Object],
1517 default: undefined,
1518 },
1519 inputPlaceholder: {
1520 type: String,
1521 default: undefined,
1522 },
1523 type: {
1524 type: String,
1525 default: DialogType.Alert,
1526 },
1527 fixedClasses: {
1528 type: Object,
1529 default() {
1530 return {
1531 overlay: 'overflow-auto scrolling-touch left-0 top-0 bottom-0 right-0 w-full h-full fixed',
1532 wrapper: 'relative mx-auto',
1533 modal: 'overflow-visible relative ',
1534 close: 'flex items-center justify-center',
1535 dialog: 'overflow-visible relative',
1536 };
1537 },
1538 },
1539 classes: {
1540 type: Object,
1541 default() {
1542 return {
1543 close: 'bg-gray-100 text-gray-600 rounded-full absolute right-0 top-0 -m-3 h-8 w-8 transition duration-100 ease-in-out hover:bg-gray-200 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50',
1544 closeIcon: 'fill-current h-4 w-4',
1545 overlay: 'z-40 bg-black bg-opacity-50',
1546 wrapper: 'z-50 max-w-lg px-3 py-12',
1547 dialog: 'bg-white shadow rounded text-left',
1548 body: 'p-3 space-y-3',
1549 buttons: 'p-3 flex space-x-4 justify-center bg-gray-100 rounded-b',
1550 iconWrapper: 'bg-gray-100 flex flex-shrink-0 h-12 items-center justify-center rounded-full w-12 mx-auto',
1551 icon: 'w-6 h-6 text-gray-500',
1552 content: 'w-full flex justify-center flex-col',
1553 titleWrapper: '',
1554 title: 'text-lg font-semibold text-center',
1555 textWrapper: 'text-left w-full',
1556 text: '',
1557 cancelButton: 'block px-4 py-2 transition duration-100 ease-in-out bg-white border border-gray-300 rounded shadow-sm hover:bg-gray-100 focus:border-gray-100 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed w-full max-w-xs',
1558 okButton: 'block px-4 py-2 text-white transition duration-100 ease-in-out bg-blue-500 border border-transparent rounded shadow-sm hover:bg-blue-600 focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed w-full max-w-xs',
1559 inputWrapper: 'mt-3 flex items-center space-x-3',
1560 input: 'block w-full px-3 py-2 text-black placeholder-gray-400 transition duration-100 ease-in-out bg-white border border-gray-300 rounded shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed w-full',
1561 select: 'block w-full px-3 py-2 text-black placeholder-gray-400 transition duration-100 ease-in-out bg-white border border-gray-300 rounded shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed w-full',
1562 radioWrapper: 'flex items-center space-x-2',
1563 radio: 'text-blue-500 transition duration-100 ease-in-out border-gray-300 shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 focus:ring-offset-0 disabled:opacity-50 disabled:cursor-not-allowed',
1564 radioText: '',
1565 checkboxWrapper: 'flex items-center space-x-2',
1566 checkbox: 'text-blue-500 transition duration-100 ease-in-out border-gray-300 rounded shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 focus:ring-offset-0 disabled:opacity-50 disabled:cursor-not-allowed',
1567 checkboxText: '',
1568 errorMessage: 'text-red-500 block text-sm',
1569 busyWrapper: 'absolute bg-opacity-50 bg-white flex h-full items-center justify-center left-0 top-0 w-full',
1570 busyIcon: 'animate-spin h-6 w-6 fill-current text-gray-500',
1571 overlayEnterClass: 'opacity-0',
1572 overlayEnterActiveClass: 'transition ease-out duration-100',
1573 overlayEnterToClass: 'opacity-100',
1574 overlayLeaveClass: 'opacity-100',
1575 overlayLeaveActiveClass: 'transition ease-in duration-75',
1576 overlayLeaveToClass: 'opacity-0',
1577 enterClass: '',
1578 enterActiveClass: '',
1579 enterToClass: '',
1580 leaveClass: '',
1581 leaveActiveClass: '',
1582 leaveToClass: '',
1583 };
1584 },
1585 },
1586 },
1587 data() {
1588 return getInitialData(this);
1589 },
1590 watch: {
1591 value(value) {
1592 if (value) {
1593 this.show();
1594 }
1595 else {
1596 this.hideReason = HideReason.Value;
1597 this.close();
1598 }
1599 },
1600 overlayShow(shown) {
1601 return __awaiter(this, void 0, void 0, function* () {
1602 if (shown) {
1603 this.$emit('input', shown);
1604 this.$emit('change', shown);
1605 yield this.$nextTick();
1606 this.dialogShow = true;
1607 }
1608 else {
1609 this.closed();
1610 }
1611 });
1612 },
1613 dialogShow(shown) {
1614 return __awaiter(this, void 0, void 0, function* () {
1615 if (!shown) {
1616 this.$emit('input', shown);
1617 this.$emit('change', shown);
1618 yield this.$nextTick();
1619 this.overlayShow = false;
1620 }
1621 else {
1622 this.opened();
1623 }
1624 });
1625 },
1626 },
1627 beforeDestroy() {
1628 const overlay = this.getOverlay();
1629 if (this.disableBodyScroll && overlay) {
1630 overlay.focus();
1631 overlay.enableBodyScroll();
1632 }
1633 },
1634 created() {
1635 if (this.name) {
1636 this.$dialog.$on(`show-${this.name}`, (resolve, reject, params = undefined) => {
1637 this.resolve = resolve;
1638 this.reject = reject;
1639 this.show(params);
1640 });
1641 this.$dialog.$on(`hide-${this.name}`, () => {
1642 this.hideReason = HideReason.Method;
1643 this.close();
1644 });
1645 }
1646 },
1647 render(createElement) {
1648 return createElement('transition', {
1649 props: {
1650 enterClass: this.getElementCssClass('overlayEnterClass'),
1651 enterActiveClass: this.getElementCssClass('overlayEnterActiveClass'),
1652 enterToClass: this.getElementCssClass('overlayEnterToClass'),
1653 leaveClass: this.getElementCssClass('overlayLeaveClass'),
1654 leaveActiveClass: this.getElementCssClass('overlayLeaveActiveClass'),
1655 leaveToClass: this.getElementCssClass('overlayLeaveToClass'),
1656 },
1657 }, [
1658 createElement(TDialogOverlay, {
1659 ref: 'overlay',
1660 props: {
1661 type: this.type,
1662 overlayShow: this.overlayShow,
1663 dialogShow: this.dialogShow,
1664 titleTag: this.titleTag,
1665 title: this.title,
1666 icon: this.icon,
1667 textTag: this.textTag,
1668 text: this.text,
1669 cancelButtonText: this.cancelButtonText,
1670 cancelButtonAriaLabel: this.cancelButtonAriaLabel,
1671 okButtonText: this.okButtonText,
1672 okButtonAriaLabel: this.okButtonAriaLabel,
1673 showCloseButton: this.showCloseButton,
1674 preConfirm: this.preConfirm,
1675 inputAttributes: this.inputAttributes,
1676 inputType: this.inputType,
1677 inputValidator: this.inputValidator,
1678 inputValue: this.inputValue,
1679 inputOptions: this.inputOptions,
1680 inputPlaceholder: this.inputPlaceholder,
1681 getElementCssClass: this.getElementCssClass,
1682 },
1683 scopedSlots: this.$scopedSlots,
1684 on: {
1685 'outside-click': this.outsideClick,
1686 keyup: this.keyupHandler,
1687 dismiss: (e) => this.dismiss(e),
1688 cancel: (e) => this.cancel(e),
1689 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1690 submit: (e, input, response) => this.submit(e, input, response),
1691 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1692 'submit-error': (e, input, error) => this.submitError(e, input, error),
1693 },
1694 }, this.$slots.default),
1695 ]);
1696 },
1697 methods: {
1698 getOverlay() {
1699 return this.$refs.overlay;
1700 },
1701 keyupHandler(e) {
1702 if (e.keyCode === Key$1.ESC && this.escToClose) {
1703 this.esc(e);
1704 }
1705 },
1706 beforeOpen() {
1707 this.$emit('before-open', { params: this.params, cancel: this.closeCancel });
1708 },
1709 opened() {
1710 this.$emit('opened', { params: this.params });
1711 this.prepareDomForDialog();
1712 },
1713 beforeClose(event) {
1714 if (this.disableBodyScroll) {
1715 const overlay = this.getOverlay();
1716 if (overlay) {
1717 overlay.focus();
1718 overlay.enableBodyScroll();
1719 }
1720 }
1721 const beforeCloseParams = {
1722 cancel: this.closeCancel,
1723 event,
1724 reason: this.hideReason,
1725 };
1726 if (this.input !== undefined) {
1727 beforeCloseParams.input = this.input;
1728 }
1729 if (this.preConfirmResponse !== undefined) {
1730 beforeCloseParams.response = this.preConfirmResponse;
1731 }
1732 this.$emit('before-close', beforeCloseParams);
1733 },
1734 closed() {
1735 const response = {
1736 hideReason: this.hideReason,
1737 isOk: this.hideReason === HideReason.Ok,
1738 isCancel: this.hideReason === HideReason.Cancel,
1739 isDismissed: typeof this.hideReason === 'string' && [HideReason.Close, HideReason.Esc, HideReason.Outside].includes(this.hideReason),
1740 };
1741 if (this.type === DialogType.Prompt && this.hideReason === HideReason.Ok && this.input !== undefined) {
1742 response.input = this.input;
1743 }
1744 if (this.preConfirmResponse !== undefined) {
1745 response.response = this.preConfirmResponse;
1746 }
1747 else if (this.preConfirmError !== undefined) {
1748 response.response = this.preConfirmError;
1749 }
1750 this.$emit('closed', response);
1751 if (this.reject && this.preConfirmError !== undefined) {
1752 this.reject(this.preConfirmError);
1753 }
1754 else if (this.resolve) {
1755 this.resolve(response);
1756 }
1757 this.reset();
1758 },
1759 prepareDomForDialog() {
1760 const overlay = this.getOverlay();
1761 if (!overlay) {
1762 return;
1763 }
1764 if (this.disableBodyScroll) {
1765 overlay.disableBodyScroll();
1766 }
1767 if (this.focusOnOpen) {
1768 overlay.focus();
1769 }
1770 },
1771 dismiss(e) {
1772 this.hideReason = HideReason.Close;
1773 this.close(e);
1774 },
1775 esc(e) {
1776 this.hideReason = HideReason.Esc;
1777 this.close(e);
1778 },
1779 cancel(e) {
1780 this.hideReason = HideReason.Cancel;
1781 this.close(e);
1782 },
1783 hide(e) {
1784 this.hideReason = HideReason.Method;
1785 this.close(e);
1786 },
1787 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1788 submit(e, input, response) {
1789 this.hideReason = HideReason.Ok;
1790 this.input = input;
1791 this.preConfirmResponse = response;
1792 this.close(e);
1793 },
1794 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1795 submitError(e, input, error) {
1796 this.hideReason = HideReason.Ok;
1797 this.input = input;
1798 this.preConfirmError = error;
1799 this.close(e);
1800 },
1801 close(e) {
1802 this.beforeClose(e);
1803 if (!this.preventAction) {
1804 this.dialogShow = false;
1805 }
1806 else {
1807 this.preventAction = false;
1808 }
1809 },
1810 show(params = undefined) {
1811 this.params = params;
1812 this.beforeOpen();
1813 if (!this.preventAction) {
1814 this.overlayShow = true;
1815 }
1816 else {
1817 this.preventAction = false;
1818 }
1819 },
1820 closeCancel() {
1821 this.preventAction = true;
1822 },
1823 reset() {
1824 Object.assign(this.$data, getInitialData(this));
1825 },
1826 outsideClick(e) {
1827 if (this.clickToClose) {
1828 this.hideReason = HideReason.Outside;
1829 this.close(e);
1830 }
1831 },
1832 },
1833 });
1834
1835 const parseDialogOptions = (type, settings, titleOrDialogOptions, text, icon) => {
1836 const { props } = TDialog.options;
1837 const propsData = Object.assign({ type }, settings);
1838 let target = 'body';
1839 if (titleOrDialogOptions) {
1840 if (typeof titleOrDialogOptions === 'object') {
1841 Object.keys(props).forEach((propName) => {
1842 if (propName in titleOrDialogOptions) {
1843 const defaultValue = get__default['default'](props, `${propName}.default`);
1844 propsData[propName] = get__default['default'](titleOrDialogOptions, propName, defaultValue);
1845 }
1846 });
1847 if (titleOrDialogOptions.target) {
1848 target = titleOrDialogOptions.target;
1849 }
1850 }
1851 else if (typeof titleOrDialogOptions === 'string') {
1852 propsData.title = titleOrDialogOptions;
1853 if (typeof text !== 'undefined') {
1854 propsData.text = text;
1855 }
1856 if (typeof icon !== 'undefined') {
1857 propsData.icon = icon;
1858 }
1859 }
1860 }
1861 return {
1862 propsData,
1863 target,
1864 };
1865 };
1866 const buildDialog = (target, propsData) => {
1867 const domTarget = document.querySelector(target);
1868 if (!domTarget) {
1869 throw new Error('Target not found!');
1870 }
1871 const instance = new TDialog({
1872 propsData,
1873 });
1874 instance.$mount();
1875 domTarget.appendChild(instance.$el);
1876 instance.show();
1877 return new Promise((resolve, reject) => {
1878 instance.resolve = resolve;
1879 instance.reject = reject;
1880 });
1881 };
1882 const configureDialogGlobals = (vueInstance, settings) => {
1883 if (!Vue__default['default'].prototype.$dialog) {
1884 // eslint-disable-next-line no-param-reassign
1885 vueInstance.prototype.$dialog = new Vue__default['default']({
1886 methods: {
1887 alert(titleOrDialogOptions, text, icon) {
1888 const { propsData, target } = parseDialogOptions(DialogType.Alert, settings, titleOrDialogOptions, text, icon);
1889 return buildDialog(target, propsData);
1890 },
1891 confirm(titleOrDialogOptions, text, icon) {
1892 const { propsData, target } = parseDialogOptions(DialogType.Confirm, settings, titleOrDialogOptions, text, icon);
1893 return buildDialog(target, propsData);
1894 },
1895 prompt(titleOrDialogOptions, text, icon) {
1896 const { propsData, target } = parseDialogOptions(DialogType.Prompt, settings, titleOrDialogOptions, text, icon);
1897 return buildDialog(target, propsData);
1898 },
1899 show(name, params = undefined) {
1900 return new Promise((resolve, reject) => {
1901 this.$emit(`show-${name}`, resolve, reject, params);
1902 });
1903 },
1904 hide(name) {
1905 this.$emit(`hide-${name}`);
1906 },
1907 },
1908 });
1909 }
1910 if (!vueInstance.prototype.$alert) {
1911 // eslint-disable-next-line no-param-reassign
1912 vueInstance.prototype.$alert = vueInstance.prototype.$dialog.alert;
1913 // eslint-disable-next-line no-param-reassign
1914 vueInstance.prototype.$confirm = vueInstance.prototype.$dialog.confirm;
1915 // eslint-disable-next-line no-param-reassign
1916 vueInstance.prototype.$prompt = vueInstance.prototype.$dialog.prompt;
1917 }
1918 };
1919
1920 const configure = (component, props) => {
1921 var _a, _b;
1922 const componentProps = (_a = component === null || component === void 0 ? void 0 : component.options) === null || _a === void 0 ? void 0 : _a.props;
1923 const componentName = (_b = component === null || component === void 0 ? void 0 : component.options) === null || _b === void 0 ? void 0 : _b.name;
1924 if (componentName === 'TModal') {
1925 // eslint-disable-next-line no-param-reassign
1926 Vue__default['default'].prototype.$modal = new Vue__default['default']({
1927 methods: {
1928 show(name, params = undefined) {
1929 this.$emit(`show-${name}`, params);
1930 },
1931 hide(name) {
1932 this.$emit(`hide-${name}`);
1933 },
1934 },
1935 });
1936 }
1937 else if (componentName === 'TDialog') {
1938 configureDialogGlobals(Vue__default['default'], props);
1939 }
1940 if (!props || !componentProps) {
1941 return component;
1942 }
1943 const customProps = {};
1944 Object.keys(props).forEach((customPropName) => {
1945 const defaultProp = componentProps[customPropName];
1946 if (!defaultProp) {
1947 return;
1948 }
1949 const newDefaultValue = props[customPropName];
1950 customProps[customPropName] = {
1951 type: defaultProp === null || defaultProp === void 0 ? void 0 : defaultProp.type,
1952 default: ['object', 'function'].includes(typeof newDefaultValue)
1953 ? () => newDefaultValue
1954 : newDefaultValue,
1955 };
1956 });
1957 return component.extend({
1958 props: customProps,
1959 });
1960 };
1961
1962 // install function executed by Vue.use()
1963 // eslint-disable-next-line max-len
1964 const install = function installVueTailwind(vueInstance, settings) {
1965 if (install.installed)
1966 return;
1967 install.installed = true;
1968 // eslint-disable-next-line no-param-reassign
1969 vueInstance.prototype.$vueTailwind = true;
1970 if (!settings) {
1971 return;
1972 }
1973 Object.keys(settings).forEach((componentName) => {
1974 const componentSettings = settings[componentName];
1975 if (typeof componentSettings === 'function' && typeof componentSettings.extend !== undefined) {
1976 const component = componentSettings;
1977 vueInstance.component(componentName, configure(component));
1978 return;
1979 }
1980 const { component, props } = componentSettings;
1981 vueInstance.component(componentName, configure(component, props));
1982 });
1983 };
1984 // Create module definition for Vue.use()
1985 const plugin = {
1986 install,
1987 };
1988
1989 exports.BaseComponent = Component;
1990 exports.default = plugin;
1991
1992 Object.defineProperty(exports, '__esModule', { value: true });
1993
1994})));
1995//# sourceMappingURL=vue-tailwind.js.map