adminforth 2.70.0-next.2 → 2.70.0-next.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.
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
:closeByClickOutside="clickToCloseOutside || closeByClickOutside"
|
|
6
6
|
:closeByEsc="closeByEsc || closable"
|
|
7
7
|
:beforeCloseFunction="beforeCloseFunction"
|
|
8
|
+
:beforeCancelFunction="beforeCancelFunction"
|
|
8
9
|
:beforeOpenFunction="beforeOpenFunction"
|
|
9
10
|
:askForCloseConfirmation="askForCloseConfirmation"
|
|
10
11
|
:closeConfirmationText="closeConfirmationText"
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
v-if="headerCloseButton"
|
|
27
28
|
type="button"
|
|
28
29
|
class="text-lightDialogCloseButton bg-transparent hover:bg-lightDialogCloseButtonHoverBackground hover:text-lightDialogCloseButtonHover rounded-lg text-sm w-8 h-8 ms-auto inline-flex justify-center items-center dark:text-darkDialogCloseButton dark:hover:bg-darkDialogCloseButtonHoverBackground dark:hover:text-darkDialogCloseButtonHover"
|
|
29
|
-
@click="
|
|
30
|
+
@click="tryToCancelModal"
|
|
30
31
|
>
|
|
31
32
|
<svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
|
|
32
33
|
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
|
|
@@ -118,10 +119,15 @@ function close() {
|
|
|
118
119
|
modalRef.value.close();
|
|
119
120
|
}
|
|
120
121
|
|
|
122
|
+
function tryToCancelModal() {
|
|
123
|
+
modalRef.value?.cancel();
|
|
124
|
+
}
|
|
125
|
+
|
|
121
126
|
defineExpose({
|
|
122
127
|
open: open,
|
|
123
128
|
close: close,
|
|
124
129
|
tryToHideModal: tryToHideModal,
|
|
130
|
+
tryToCancelModal: tryToCancelModal,
|
|
125
131
|
})
|
|
126
132
|
|
|
127
133
|
function tryToHideModal() {
|
|
@@ -171,6 +177,11 @@ interface DialogProps {
|
|
|
171
177
|
*/
|
|
172
178
|
beforeOpenFunction?: (() => void | Promise<void>) | null
|
|
173
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Function that will be called before the dialog is canceled.
|
|
182
|
+
*/
|
|
183
|
+
beforeCancelFunction?: (() => void | Promise<void | boolean>) | null
|
|
184
|
+
|
|
174
185
|
/**
|
|
175
186
|
* Disables close on Ecs button
|
|
176
187
|
*
|
|
@@ -201,19 +212,21 @@ interface DialogProps {
|
|
|
201
212
|
|
|
202
213
|
/********** for the backward compatibility ***************/
|
|
203
214
|
class Dialog implements IDialogInsideButtonClickHandler {
|
|
204
|
-
hide: () => void
|
|
205
|
-
constructor(
|
|
206
|
-
this.hide =
|
|
215
|
+
hide: (isCancel?: boolean) => void
|
|
216
|
+
constructor(hideFn: (isCancel?: boolean) => void) {
|
|
217
|
+
this.hide = hideFn;
|
|
207
218
|
}
|
|
208
219
|
}
|
|
209
220
|
const dialog: Ref<Dialog> = ref(
|
|
210
|
-
new Dialog(
|
|
211
|
-
()
|
|
212
|
-
if (
|
|
213
|
-
|
|
221
|
+
new Dialog((isCancel = false) => {
|
|
222
|
+
if (dialog.value) {
|
|
223
|
+
if (isCancel) {
|
|
224
|
+
modalRef.value?.cancel();
|
|
225
|
+
} else {
|
|
226
|
+
modalRef.value?.close();
|
|
214
227
|
}
|
|
215
228
|
}
|
|
216
|
-
)
|
|
229
|
+
})
|
|
217
230
|
);
|
|
218
231
|
/*************************************************************/
|
|
219
232
|
|
|
@@ -70,6 +70,7 @@ interface DialogProps {
|
|
|
70
70
|
closeByEsc?: boolean
|
|
71
71
|
beforeCloseFunction?: (() => void | Promise<void | boolean>) | null
|
|
72
72
|
beforeOpenFunction?: (() => void | Promise<void>) | null
|
|
73
|
+
beforeCancelFunction?: (() => void | Promise<void | boolean>) | null
|
|
73
74
|
askForCloseConfirmation?: boolean
|
|
74
75
|
closeConfirmationText?: string
|
|
75
76
|
removeFromDomOnClose?: boolean
|
|
@@ -82,6 +83,7 @@ const props = withDefaults(defineProps<DialogProps>(), {
|
|
|
82
83
|
closeByEsc: true,
|
|
83
84
|
beforeCloseFunction: null,
|
|
84
85
|
beforeOpenFunction: null,
|
|
86
|
+
beforeCancelFunction: null,
|
|
85
87
|
askForCloseConfirmation: false,
|
|
86
88
|
closeConfirmationText: 'Are you sure you want to close this dialog?',
|
|
87
89
|
removeFromDomOnClose: false,
|
|
@@ -109,6 +111,14 @@ async function close() {
|
|
|
109
111
|
isModalOpen.value = false;
|
|
110
112
|
}
|
|
111
113
|
|
|
114
|
+
async function cancel() {
|
|
115
|
+
if (props.beforeCancelFunction) {
|
|
116
|
+
const shouldCancel = await props.beforeCancelFunction?.();
|
|
117
|
+
if (shouldCancel === false) return;
|
|
118
|
+
}
|
|
119
|
+
isModalOpen.value = false;
|
|
120
|
+
}
|
|
121
|
+
|
|
112
122
|
defineOptions({
|
|
113
123
|
inheritAttrs: false,
|
|
114
124
|
})
|
|
@@ -116,12 +126,17 @@ defineOptions({
|
|
|
116
126
|
defineExpose({
|
|
117
127
|
open: open,
|
|
118
128
|
close: close,
|
|
129
|
+
cancel: cancel,
|
|
119
130
|
tryToHideModal: tryToHideModal,
|
|
120
131
|
})
|
|
121
132
|
|
|
122
|
-
function tryToHideModal() {
|
|
123
|
-
if (!props.askForCloseConfirmation
|
|
124
|
-
|
|
133
|
+
function tryToHideModal(isCancelAction = false) {
|
|
134
|
+
if (!props.askForCloseConfirmation) {
|
|
135
|
+
if (isCancelAction) {
|
|
136
|
+
cancel();
|
|
137
|
+
} else {
|
|
138
|
+
close();
|
|
139
|
+
}
|
|
125
140
|
} else {
|
|
126
141
|
showConfirmationOnClose.value = true;
|
|
127
142
|
}
|
|
@@ -136,10 +151,8 @@ function toggleModal() {
|
|
|
136
151
|
}
|
|
137
152
|
|
|
138
153
|
function onEsc(event: KeyboardEvent) {
|
|
139
|
-
if (event.key === 'Escape') {
|
|
140
|
-
|
|
141
|
-
tryToHideModal();
|
|
142
|
-
}
|
|
154
|
+
if (event.key === 'Escape' && props.closeByEsc) {
|
|
155
|
+
tryToHideModal(true);
|
|
143
156
|
}
|
|
144
157
|
}
|
|
145
158
|
|
|
@@ -154,7 +167,7 @@ onUnmounted(() => {
|
|
|
154
167
|
|
|
155
168
|
function backdropClick(e: MouseEvent) {
|
|
156
169
|
if (props.closeByClickOutside && e.target === e.currentTarget) {
|
|
157
|
-
tryToHideModal();
|
|
170
|
+
tryToHideModal(true);
|
|
158
171
|
}
|
|
159
172
|
}
|
|
160
173
|
|