lkt-step-process 2.0.11 → 2.0.13

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.11",
3
+ "version": "2.0.13",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "module": "./dist/build.js",
@@ -1,13 +1,15 @@
1
1
  <script setup lang="ts">
2
2
  import { computed, onMounted, ref, useSlots, watch } from 'vue';
3
3
  import {
4
- ButtonConfig, ClickEventArgs,
4
+ ButtonConfig,
5
+ ClickEventArgs,
5
6
  getDefaultValues,
6
7
  ItemCrudButtonNavPosition,
7
8
  ItemCrudButtonNavVisibility,
8
9
  StepProcess,
9
10
  StepProcessConfig,
10
11
  StepProcessStepConfig,
12
+ StepRenderType,
11
13
  } from 'lkt-vue-kernel';
12
14
  import ButtonNav from '@/components/ButtonNav.vue';
13
15
  import { ButtonNavProps } from '@/config/ButtonNavProps';
@@ -27,12 +29,16 @@
27
29
  const isLoading = ref(props.loading),
28
30
  currentStep = ref(props.modelValue),
29
31
  stepsHaystack = ref(props.steps),
32
+ firstRenderReached = ref(<{[key:string]:boolean}>{}),
30
33
  navRef = ref(null);
31
34
 
32
35
  watch(() => props.loading, (value) => isLoading.value = value);
33
36
  watch(() => props.modelValue, (value) => currentStep.value = value);
34
37
  watch(isLoading, (value) => emit('update:loading', value));
35
- watch(currentStep, (value) => emit('update:modelValue', value));
38
+ watch(currentStep, (value) => {
39
+ firstRenderReached.value[value] = true;
40
+ emit('update:modelValue', value);
41
+ });
36
42
 
37
43
  const slotsSteps = computed(() => {
38
44
  let r = [];
@@ -162,7 +168,19 @@
162
168
  });
163
169
 
164
170
  const onNext = (data: any) => {
165
- currentStep.value = stepsHaystack.value[currentStepIndex.value + 1].key;
171
+ let nextKey = stepsHaystack.value[currentStepIndex.value]?.nextKey;
172
+ let nextIndex = currentStepIndex.value + 1;
173
+
174
+ if (typeof nextKey === 'function') nextKey = nextKey();
175
+ if (typeof nextKey === 'string') {
176
+ let needle = stepsHaystack.value.findIndex((z) => {
177
+ return z.key === nextKey;
178
+ })
179
+
180
+ if (needle > -1) nextIndex = needle;
181
+ }
182
+
183
+ currentStep.value = stepsHaystack.value[nextIndex].key;
166
184
  if (currentStepIndex.value === (stepsHaystack.value.length - 1)) {
167
185
  emit('finish', data);
168
186
 
@@ -171,8 +189,56 @@
171
189
  }
172
190
  },
173
191
  onPrev = (data: any) => {
174
- currentStep.value = stepsHaystack.value[currentStepIndex.value - 1].key;
192
+ let prevKey = stepsHaystack.value[currentStepIndex.value]?.prevKey;
193
+ let nextIndex = currentStepIndex.value - 1;
194
+
195
+ if (typeof prevKey === 'function') prevKey = prevKey();
196
+ if (typeof prevKey === 'string') {
197
+ let needle = stepsHaystack.value.findIndex((z) => {
198
+ return z.key === prevKey;
199
+ })
200
+
201
+ if (needle > -1) nextIndex = needle;
202
+ }
203
+
204
+ currentStep.value = stepsHaystack.value[nextIndex].key;
175
205
  emit('prev', data);
206
+ },
207
+ canRenderStep = (stepKey:string) => {
208
+ const stepIndex = stepsHaystack.value.findIndex((step: StepProcessStepConfig) => step.key === stepKey);
209
+
210
+ if (stepIndex > -1 && stepsHaystack.value[stepIndex]?.renderType) {
211
+ switch (stepsHaystack.value[stepIndex]?.renderType) {
212
+ case StepRenderType.AlwaysRendersAlwaysVisible:
213
+ case StepRenderType.AlwaysRendersVisibleAfterFirstActive:
214
+ case StepRenderType.AlwaysRendersVisibleIfActive:
215
+ return true;
216
+
217
+ case StepRenderType.RendersAndVisibleIfActive:
218
+ return stepKey === currentStep.value;
219
+ }
220
+ }
221
+ return stepKey === currentStep.value;
222
+ },
223
+ canShowStep = (stepKey:string) => {
224
+
225
+ const stepIndex = stepsHaystack.value.findIndex((step: StepProcessStepConfig) => step.key === stepKey);
226
+
227
+ if (stepIndex > -1 && stepsHaystack.value[stepIndex]?.renderType) {
228
+ switch (stepsHaystack.value[stepIndex]?.renderType) {
229
+ case StepRenderType.AlwaysRendersAlwaysVisible:
230
+ return true;
231
+
232
+ case StepRenderType.AlwaysRendersVisibleAfterFirstActive:
233
+ return firstRenderReached.value[stepKey] === true;
234
+
235
+ case StepRenderType.AlwaysRendersVisibleIfActive:
236
+ case StepRenderType.RendersAndVisibleIfActive:
237
+ return stepKey === currentStep.value;
238
+ }
239
+ }
240
+
241
+ return true;
176
242
  };
177
243
 
178
244
 
@@ -218,7 +284,7 @@
218
284
  <div class="lkt-step-process--content" v-if="!isLoading">
219
285
  <div class="lkt-grid-1">
220
286
  <template v-for="step in slotsSteps">
221
- <div v-if="step === currentStep">
287
+ <div v-if="canRenderStep(step)" v-show="canShowStep(step)">
222
288
  <slot :name="'step-'+step" v-bind:config="stepsHaystack" />
223
289
  </div>
224
290
  </template>