lkt-step-process 1.2.1 → 2.0.1

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": "1.2.1",
3
+ "version": "2.0.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "module": "./dist/build.js",
@@ -34,13 +34,13 @@
34
34
  "vue-tsc": "^2.2.0"
35
35
  },
36
36
  "peerDependencies": {
37
- "lkt-button": "^2.0.7",
37
+ "lkt-button": "^2.0.23",
38
38
  "lkt-data-state": "^1.0.11",
39
- "lkt-http-client": "^1.0.34",
39
+ "lkt-http-client": "^1.1.0",
40
40
  "lkt-http-info": "^1.1.1",
41
41
  "lkt-loader": "^1.2.0",
42
- "lkt-string-tools": "^1.0.8",
43
- "lkt-vue-kernel": "^1.0.33",
42
+ "lkt-string-tools": "^1.1.0",
43
+ "lkt-vue-kernel": "^1.0.87",
44
44
  "path": "^0.12.7",
45
45
  "vue": "^3.3.0"
46
46
  }
@@ -1,208 +1,147 @@
1
1
  <script setup lang="ts">
2
- import {ref, useSlots, computed} from "vue";
3
- import {StepProcess} from "../types/StepProcess";
4
- import {Step} from "../types/Step";
5
-
6
- const props = defineProps({
7
- modelValue: {type: Object, required: false, default: (): StepProcess => ({step: 1, steps: [], data: {}})},
8
-
9
- title: {type: String, default: ''},
10
- nextText: {type: String, default: 'Next'},
11
- prevText: {type: String, default: 'Back'},
12
-
13
- nextValidator: {type: Function, required: false, default: () => true},
14
- prevValidator: {type: Function, required: false, default: () => true},
15
- });
16
-
17
- const slots = useSlots();
18
-
19
- const emit = defineEmits([
20
- 'next',
21
- 'prev',
22
- 'finish'
23
- ]);
24
-
25
- const isLoading = ref(false),
26
- config = ref(props.modelValue),
27
- prevButton = ref(null),
28
- nextButton = ref(null);
29
-
30
- const displayHeader = computed(() => {
31
- if (isLoading.value) return false;
32
-
33
- return props.title || !!slots['post-title'];
34
- });
35
-
36
- const slotsSteps = computed(() => {
37
- let r = [];
38
- for (let k in slots) if (k.indexOf('step-') !== -1) r.push(k.substring(5));
39
- return r;
40
- })
2
+ import { computed, ref, useSlots, watch } from 'vue';
3
+ import {
4
+ ButtonConfig,
5
+ getDefaultValues,
6
+ StepProcess,
7
+ StepProcessConfig,
8
+ StepProcessStepConfig,
9
+ } from 'lkt-vue-kernel';
10
+
11
+ const props = withDefaults(defineProps<StepProcessConfig>(), getDefaultValues(StepProcess));
12
+
13
+ const slots = useSlots();
14
+
15
+ const emit = defineEmits([
16
+ 'next',
17
+ 'prev',
18
+ 'finish',
19
+ 'update:modelValue',
20
+ 'update:loading',
21
+ ]);
22
+
23
+ const isLoading = ref(props.loading),
24
+ currentStep = ref(props.modelValue),
25
+ stepsHaystack = ref(props.steps),
26
+ prevButtonRef = ref(null),
27
+ nextButtonRef = ref(null);
28
+
29
+ watch(() => props.loading, (value) => isLoading.value = value);
30
+ watch(() => props.modelValue, (value) => currentStep.value = value);
31
+ watch(isLoading, (value) => emit('update:loading', value));
32
+ watch(currentStep, (value) => emit('update:modelValue', value));
33
+
34
+ const slotsSteps = computed(() => {
35
+ let r = [];
36
+ for (let k in slots) if (k.indexOf('step-') !== -1) r.push(k.substring(5));
37
+ return r;
38
+ });
41
39
 
42
- const currentStep = computed(() => {
43
- if (!config.value.step) {
44
- if (!config.value.steps) {
45
- return null;
40
+ const currentStepIndex = computed(() => {
41
+ return stepsHaystack.value.findIndex((step: StepProcessStepConfig) => step.key === currentStep.value);
42
+ }),
43
+ currentStepConfig = computed(() => {
44
+ return stepsHaystack.value[currentStepIndex.value];
45
+ }),
46
+ prevDisabled = computed(() => {
47
+ return currentStepIndex.value === 0;
48
+ }),
49
+ computedPrevButton = computed(() => {
50
+ let r: ButtonConfig = { ...props.prevButton };
51
+ if (currentStepConfig.value?.prevButton) {
52
+ r = { ...r, ...currentStepConfig.value?.prevButton };
46
53
  }
47
- if (!config.value.steps[0]) return null;
48
- return config.value.steps[0].name;
49
- }
50
- return config.value.step;
51
- }),
52
- currentStepIndex = computed(() => {
53
- return config.value.steps.findIndex((step: Step) => step.name === currentStep.value);
54
- }),
55
- currentStepConfig = computed(() => {
56
- return config.value.steps[currentStepIndex.value];
57
- }),
58
- prevValid = computed(() => {
59
- if (typeof currentStepConfig.value.prevValidator === 'function') {
60
- return currentStepConfig.value.prevValidator(config.value);
61
- }
62
- if (typeof currentStepConfig.value.prevValidator === 'boolean') {
63
- return currentStepConfig.value.prevValidator;
64
- }
65
- if (typeof props.prevValidator === 'function') {
66
- return props.prevValidator(config.value);
67
- }
68
- return true;
69
- }),
70
- nextValid = computed(() => {
71
- if (typeof currentStepConfig.value.nextValidator === 'function') {
72
- return currentStepConfig.value.nextValidator(config.value);
73
- }
74
- if (typeof currentStepConfig.value.nextValidator === 'boolean') {
75
- return currentStepConfig.value.nextValidator;
76
- }
77
- if (typeof props.nextValidator === 'function') {
78
- return props.nextValidator(config.value);
79
- }
80
- return true;
81
- }),
82
- prevDisabled = computed(() => {
83
- return currentStepIndex.value === 0 || !prevValid.value;
84
- }),
85
- nextDisabled = computed(() => {
86
- return currentStepIndex.value === (config.value.steps.length - 1) || !nextValid.value;
87
- }),
88
- prevHidden = computed(() => {
89
- if (typeof currentStepConfig.value.prevHidden === 'function') {
90
- return currentStepConfig.value.prevHidden(config.value);
91
- }
92
- if (typeof currentStepConfig.value.prevHidden === 'boolean') {
93
- return currentStepConfig.value.prevHidden;
94
- }
95
- return currentStepIndex.value === 0;
96
- }),
97
- nextHidden = computed(() => {
98
- if (typeof currentStepConfig.value.nextHidden === 'function') {
99
- return currentStepConfig.value.nextHidden(config.value);
100
- }
101
- if (typeof currentStepConfig.value.nextHidden === 'boolean') {
102
- return currentStepConfig.value.nextHidden;
103
- }
104
- return currentStepIndex.value === (config.value.steps.length - 1);
105
- }),
106
- prevConfirm = computed(() => {
107
- if (typeof currentStepConfig.value.prevConfirm === 'string') {
108
- return currentStepConfig.value.prevConfirm;
109
- }
110
- return '';
111
- }),
112
- nextConfirm = computed(() => {
113
- if (typeof currentStepConfig.value.nextConfirm === 'string') {
114
- return currentStepConfig.value.nextConfirm;
115
- }
116
- return '';
117
- }),
118
- nextResource = computed(() => {
119
- if (typeof currentStepConfig.value.nextResource === 'string') {
120
- return currentStepConfig.value.nextResource;
121
- }
122
- return '';
123
- }),
124
- nextResourceData = computed(() => {
125
- if (typeof currentStepConfig.value.nextResourceData === 'object') {
126
- return currentStepConfig.value.nextResourceData;
127
- }
128
- return {};
129
- }),
130
- classes = computed(() => {
131
-
132
- const r = ['lkt-step-process'];
133
-
134
- if (currentStep.value) r.push(`step-${currentStep.value}`);
135
- return r.join(' ');
54
+ if (typeof r.disabled === 'undefined') {
55
+ r.disabled = prevDisabled.value;
56
+ }
57
+ return r;
58
+ }),
59
+ computedNextButton = computed(() => {
60
+ let r: ButtonConfig = { ...props.nextButton };
61
+ if (currentStepConfig.value?.nextButton) {
62
+ r = { ...r, ...currentStepConfig.value?.nextButton };
63
+ }
64
+ return r;
65
+ }),
66
+ prevHidden = computed(() => {
67
+ if (typeof currentStepConfig.value?.prevHidden === 'function') {
68
+ return currentStepConfig.value.prevHidden(currentStepConfig.value, stepsHaystack.value);
69
+ }
70
+ if (typeof currentStepConfig.value?.prevHidden === 'boolean') {
71
+ return currentStepConfig.value.prevHidden;
72
+ }
73
+ return currentStepIndex.value === 0;
74
+ }),
75
+ nextHidden = computed(() => {
76
+ if (typeof currentStepConfig.value?.nextHidden === 'function') {
77
+ return currentStepConfig.value.nextHidden(currentStepConfig.value, stepsHaystack.value);
78
+ }
79
+ if (typeof currentStepConfig.value?.nextHidden === 'boolean') {
80
+ return currentStepConfig.value.nextHidden;
81
+ }
82
+ return currentStepConfig.value.nextButton === false;
83
+ }),
84
+ classes = computed(() => {
85
+ const r = [];
86
+ if (currentStep.value) r.push(`step-${currentStep.value}`);
87
+ return r.join(' ');
88
+ });
89
+
90
+ const onNext = (data: any) => {
91
+ currentStep.value = stepsHaystack.value[currentStepIndex.value + 1].key;
92
+ if (currentStepIndex.value === (stepsHaystack.value.length - 1)) {
93
+ emit('finish', data);
94
+
95
+ } else {
96
+ emit('next', data);
97
+ }
98
+ },
99
+ onPrev = (data: any) => {
100
+ currentStep.value = stepsHaystack.value[currentStepIndex.value - 1].key;
101
+ emit('prev', data);
102
+ };
103
+
104
+
105
+ defineExpose({
106
+ goNext: () => {
107
+ // @ts-ignore
108
+ nextButtonRef.value.click();
109
+ },
110
+ goPrev: () => {
111
+ // @ts-ignore
112
+ prevButtonRef.value.click();
113
+ },
114
+ startLoader: () => isLoading.value = true,
115
+ stopLoader: () => isLoading.value = false,
136
116
  });
137
-
138
- const onNext = (data: any) => {
139
- config.value.step = config.value.steps[currentStepIndex.value + 1].name;
140
- if (currentStepIndex.value === (config.value.steps.length - 1)) {
141
- emit('finish', data);
142
-
143
- } else {
144
- emit('next', data);
145
- }
146
- },
147
- onPrev = (data: any) => {
148
- config.value.step = config.value.steps[currentStepIndex.value - 1].name;
149
- emit('prev', data);
150
- };
151
-
152
-
153
- defineExpose({
154
- goNext: () => {
155
- // @ts-ignore
156
- nextButton.value.click()
157
- },
158
- goPrev: () => {
159
- // @ts-ignore
160
- prevButton.value.click()
161
- },
162
- startLoader: () => isLoading.value = true,
163
- stopLoader: () => isLoading.value = false,
164
- });
165
117
  </script>
166
118
 
167
119
  <template>
168
- <article :class="classes">
169
- <header class="lkt-step-process_header" v-if="displayHeader">
170
- <h1 class="lkt-step-process_header-title">{{ title }}</h1>
171
- <div class="lkt-step-process_header-slot">
172
- <slot name="post-title" v-bind:config="config" v-bind:loading="isLoading"/>
173
- </div>
174
- </header>
120
+ <article class="lkt-step-process" :class="classes">
121
+ <lkt-header v-if="header && Object.keys(header).length > 0" v-bind="header" />
122
+
175
123
  <div class="lkt-step-process-buttons">
176
124
  <lkt-button
177
- :ref="(el:any) => prevButton = el"
125
+ ref="prevButtonRef"
178
126
  v-show="!isLoading && !prevHidden"
179
- v-bind:disabled="prevDisabled"
180
- v-bind:confirm-modal="prevConfirm"
181
- v-on:click="onPrev">
182
- <slot v-if="!!slots['button-prev']" name="button-prev" v-bind:config="config"/>
183
- <span v-else>Back</span>
184
- </lkt-button>
185
-
127
+ v-bind="computedPrevButton"
128
+ v-on:click="onPrev"
129
+ />
186
130
  <lkt-button
187
- :ref="(el:any) => nextButton = el"
131
+ ref="nextButtonRef"
188
132
  v-show="!isLoading && !nextHidden"
189
- v-bind:disabled="nextDisabled"
190
- v-bind:confirm-modal="nextConfirm"
191
- v-bind:resource="nextResource"
192
- v-bind:resource-data="nextResourceData"
193
- v-on:click="onNext">
194
- <slot v-if="!!slots['button-next']" name="button-next" v-bind:config="config"/>
195
- <span v-else>Next</span>
196
- </lkt-button>
133
+ v-bind="computedNextButton"
134
+ v-on:click="onNext"
135
+ />
197
136
  </div>
198
137
 
199
138
  <div class="lkt-step-process_content" v-if="!isLoading">
200
139
  <div class="lkt-grid-1">
201
140
  <div v-for="step in slotsSteps" v-show="step === currentStep">
202
- <slot :name="'step-'+step" v-bind:config="config"/>
141
+ <slot :name="'step-'+step" v-bind:config="stepsHaystack" />
203
142
  </div>
204
143
  </div>
205
144
  </div>
206
- <lkt-loader v-if="isLoading"/>
145
+ <lkt-loader v-if="isLoading" />
207
146
  </article>
208
147
  </template>