lkt-step-process 2.0.10 → 2.0.12

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,6 +1,6 @@
1
1
  {
2
2
  "name": "lkt-step-process",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "module": "./dist/build.js",
@@ -13,7 +13,10 @@
13
13
  "./theme/default": "./theme/default.css"
14
14
  },
15
15
  "types": "./dist/index.d.ts",
16
- "files": ["dist/*", "src/**/*.vue"],
16
+ "files": [
17
+ "dist/*",
18
+ "src/**/*.vue"
19
+ ],
17
20
  "license": "MIT",
18
21
  "sideEffects": false,
19
22
  "scripts": {
@@ -32,10 +32,9 @@
32
32
  v-show="!isLoading"
33
33
  v-bind="prevButton"
34
34
  class="is-prev-button"
35
- @click="emit('prev')"
36
35
  />
37
36
 
38
- <div class="lkt-step-process--nav-info">
37
+ <div class="lkt-step-process--nav-info" v-if="slots['nav-info'] || dots && amountOfSteps > 0">
39
38
  <template v-if="slots['nav-info']">
40
39
  <slot
41
40
  name="nav-info"
@@ -65,7 +64,6 @@
65
64
  v-show="!isLoading"
66
65
  v-bind="nextButton"
67
66
  class="is-next-button"
68
- @click="emit('next')"
69
67
  />
70
68
  </div>
71
69
  </template>
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { computed, onMounted, ref, useSlots, watch } from 'vue';
3
3
  import {
4
- ButtonConfig,
4
+ ButtonConfig, ClickEventArgs,
5
5
  getDefaultValues,
6
6
  ItemCrudButtonNavPosition,
7
7
  ItemCrudButtonNavVisibility,
@@ -70,7 +70,24 @@
70
70
  if (typeof r.disabled === 'undefined') {
71
71
  r.disabled = prevDisabled.value;
72
72
  }
73
- return r;
73
+
74
+ const clientClickEvent = r.events?.click;
75
+
76
+ return {
77
+ ...r,
78
+ events: {
79
+ ...r.events,
80
+ click: (data: ClickEventArgs) => {
81
+
82
+ if (typeof clientClickEvent === 'function') clientClickEvent(data);
83
+
84
+ if (data.httpResponse?.success === false) {
85
+ return;
86
+ }
87
+ onPrev(data);
88
+ }
89
+ }
90
+ };
74
91
  }),
75
92
  computedNextButton = computed(() => {
76
93
  if (currentStepConfig.value?.nextButton === false) {
@@ -90,7 +107,24 @@
90
107
  if (typeof currentStepConfig.value?.nextButton === 'object') {
91
108
  r = { ...r, ...currentStepConfig.value?.nextButton };
92
109
  }
93
- return r;
110
+
111
+ const clientClickEvent = r.events?.click;
112
+
113
+ return {
114
+ ...r,
115
+ events: {
116
+ ...r.events,
117
+ click: (data: ClickEventArgs) => {
118
+
119
+ if (typeof clientClickEvent === 'function') clientClickEvent(data);
120
+
121
+ if (data.httpResponse?.success === false) {
122
+ return;
123
+ }
124
+ onNext(data);
125
+ }
126
+ }
127
+ };
94
128
  }),
95
129
  classes = computed(() => {
96
130
  const r = [];
@@ -119,10 +153,28 @@
119
153
  dots: props.dots,
120
154
  dotsNumbers: props.dotsNumbers,
121
155
  };
156
+ }),
157
+ computedHasButtonNavContent = computed(() => {
158
+ return typeof computedPrevButton.value === 'object'
159
+ || typeof computedNextButton.value === 'object'
160
+ || props.dots
161
+ || typeof slots['nav-info'] !== 'undefined';
122
162
  });
123
163
 
124
164
  const onNext = (data: any) => {
125
- currentStep.value = stepsHaystack.value[currentStepIndex.value + 1].key;
165
+ let nextKey = stepsHaystack.value[currentStepIndex.value]?.nextKey;
166
+ let nextIndex = currentStepIndex.value + 1;
167
+
168
+ if (typeof nextKey === 'function') nextKey = nextKey();
169
+ if (typeof nextKey === 'string') {
170
+ let needle = stepsHaystack.value.findIndex((z) => {
171
+ return z.key === nextKey;
172
+ })
173
+
174
+ if (needle > -1) nextIndex = needle;
175
+ }
176
+
177
+ currentStep.value = stepsHaystack.value[nextIndex].key;
126
178
  if (currentStepIndex.value === (stepsHaystack.value.length - 1)) {
127
179
  emit('finish', data);
128
180
 
@@ -131,7 +183,19 @@
131
183
  }
132
184
  },
133
185
  onPrev = (data: any) => {
134
- currentStep.value = stepsHaystack.value[currentStepIndex.value - 1].key;
186
+ let prevKey = stepsHaystack.value[currentStepIndex.value]?.prevKey;
187
+ let nextIndex = currentStepIndex.value - 1;
188
+
189
+ if (typeof prevKey === 'function') prevKey = prevKey();
190
+ if (typeof prevKey === 'string') {
191
+ let needle = stepsHaystack.value.findIndex((z) => {
192
+ return z.key === prevKey;
193
+ })
194
+
195
+ if (needle > -1) nextIndex = needle;
196
+ }
197
+
198
+ currentStep.value = stepsHaystack.value[nextIndex].key;
135
199
  emit('prev', data);
136
200
  };
137
201
 
@@ -159,11 +223,9 @@
159
223
  <lkt-header v-if="header && Object.keys(header).length > 0" v-bind="header" />
160
224
 
161
225
  <button-nav
162
- v-if="computedRenderTopButtonNav"
226
+ v-if="computedRenderTopButtonNav && computedHasButtonNavContent"
163
227
  ref="navRef"
164
228
  v-bind="computedButtonNavProps"
165
- @prev="onPrev"
166
- @next="onNext"
167
229
  >
168
230
  <template #nav-info="{currentStep, currentStepIndex, amountOfSteps}" v-if="slots['nav-info']">
169
231
  <slot
@@ -189,11 +251,9 @@
189
251
  <lkt-loader v-if="isLoading" />
190
252
 
191
253
  <button-nav
192
- v-if="computedRenderBottomButtonNav"
254
+ v-if="computedRenderBottomButtonNav && computedHasButtonNavContent"
193
255
  ref="navRef"
194
256
  v-bind="computedButtonNavProps"
195
- @prev="onPrev"
196
- @next="onNext"
197
257
  >
198
258
  <template #nav-info="{currentStep, currentStepIndex, amountOfSteps}" v-if="slots['nav-info']">
199
259
  <slot