lkt-step-process 1.2.0 → 2.0.0

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.0",
3
+ "version": "2.0.0",
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,210 +1,153 @@
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
+ nextDisabled = computed(() => {
50
+ return currentStepIndex.value === (stepsHaystack.value.length - 1);
51
+ }),
52
+ computedPrevButton = computed(() => {
53
+ let r: ButtonConfig = { ...props.prevButton };
54
+ if (currentStepConfig.value?.prevButton) {
55
+ r = { ...r, ...currentStepConfig.value?.prevButton };
46
56
  }
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(' ');
57
+ if (typeof r.disabled === 'undefined') {
58
+ r.disabled = prevDisabled.value;
59
+ }
60
+ return r;
61
+ }),
62
+ computedNextButton = computed(() => {
63
+ let r: ButtonConfig = { ...props.nextButton };
64
+ if (currentStepConfig.value?.nextButton) {
65
+ r = { ...r, ...currentStepConfig.value?.nextButton };
66
+ }
67
+ if (typeof r.disabled === 'undefined') {
68
+ r.disabled = nextDisabled.value;
69
+ }
70
+ return r;
71
+ }),
72
+ prevHidden = computed(() => {
73
+ if (typeof currentStepConfig.value?.prevHidden === 'function') {
74
+ return currentStepConfig.value.prevHidden(currentStepConfig.value, stepsHaystack.value);
75
+ }
76
+ if (typeof currentStepConfig.value?.prevHidden === 'boolean') {
77
+ return currentStepConfig.value.prevHidden;
78
+ }
79
+ return currentStepIndex.value === 0;
80
+ }),
81
+ nextHidden = computed(() => {
82
+ if (typeof currentStepConfig.value?.nextHidden === 'function') {
83
+ return currentStepConfig.value.nextHidden(currentStepConfig.value, stepsHaystack.value);
84
+ }
85
+ if (typeof currentStepConfig.value?.nextHidden === 'boolean') {
86
+ return currentStepConfig.value.nextHidden;
87
+ }
88
+ return currentStepIndex.value === (stepsHaystack.value.length - 1);
89
+ }),
90
+ classes = computed(() => {
91
+ const r = [];
92
+ if (currentStep.value) r.push(`step-${currentStep.value}`);
93
+ return r.join(' ');
94
+ });
95
+
96
+ const onNext = (data: any) => {
97
+ currentStep.value = stepsHaystack.value[currentStepIndex.value + 1].key;
98
+ if (currentStepIndex.value === (stepsHaystack.value.length - 1)) {
99
+ emit('finish', data);
100
+
101
+ } else {
102
+ emit('next', data);
103
+ }
104
+ },
105
+ onPrev = (data: any) => {
106
+ currentStep.value = stepsHaystack.value[currentStepIndex.value - 1].key;
107
+ emit('prev', data);
108
+ };
109
+
110
+
111
+ defineExpose({
112
+ goNext: () => {
113
+ // @ts-ignore
114
+ nextButtonRef.value.click();
115
+ },
116
+ goPrev: () => {
117
+ // @ts-ignore
118
+ prevButtonRef.value.click();
119
+ },
120
+ startLoader: () => isLoading.value = true,
121
+ stopLoader: () => isLoading.value = false,
136
122
  });
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
123
  </script>
166
124
 
167
125
  <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"></slot>
173
- </div>
174
- </header>
126
+ <article class="lkt-step-process" :class="classes">
127
+ <lkt-header v-if="header && Object.keys(header).length > 0" v-bind="header" />
128
+
175
129
  <div class="lkt-step-process-buttons">
176
130
  <lkt-button
177
- :ref="(el:any) => prevButton = el"
131
+ ref="prevButtonRef"
178
132
  v-show="!isLoading && !prevHidden"
179
- palette="danger"
180
- v-bind:disabled="prevDisabled"
181
- v-bind:confirm-modal="prevConfirm"
182
- v-on:click="onPrev">
183
- <slot v-if="!!slots['button-prev']" name="button-prev" v-bind:config="config"></slot>
184
- <span v-else>Back</span>
185
- </lkt-button>
186
-
133
+ v-bind="computedPrevButton"
134
+ v-on:click="onPrev"
135
+ />
187
136
  <lkt-button
188
- :ref="(el:any) => nextButton = el"
137
+ ref="nextButtonRef"
189
138
  v-show="!isLoading && !nextHidden"
190
- palette="success"
191
- v-bind:disabled="nextDisabled"
192
- v-bind:confirm-modal="nextConfirm"
193
- v-bind:resource="nextResource"
194
- v-bind:resource-data="nextResourceData"
195
- v-on:click="onNext">
196
- <slot v-if="!!slots['button-next']" name="button-next" v-bind:config="config"></slot>
197
- <span v-else>Next</span>
198
- </lkt-button>
139
+ v-bind="computedNextButton"
140
+ v-on:click="onNext"
141
+ />
199
142
  </div>
200
143
 
201
144
  <div class="lkt-step-process_content" v-if="!isLoading">
202
145
  <div class="lkt-grid-1">
203
146
  <div v-for="step in slotsSteps" v-show="step === currentStep">
204
- <slot :name="'step-'+step" v-bind:config="config"></slot>
147
+ <slot :name="'step-'+step" v-bind:config="stepsHaystack" />
205
148
  </div>
206
149
  </div>
207
150
  </div>
208
- <lkt-loader v-if="isLoading"></lkt-loader>
151
+ <lkt-loader v-if="isLoading" />
209
152
  </article>
210
153
  </template>