lkt-step-process 1.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 LKT VUE
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ export { ve as default };
2
+ declare namespace ve {
3
+ function install(v: any, g?: {}): void;
4
+ }
package/dist/build.js ADDED
@@ -0,0 +1,114 @@
1
+ import { defineComponent as K, useSlots as M, ref as c, computed as l, resolveComponent as S, openBlock as u, createElementBlock as o, normalizeClass as Q, createElementVNode as f, toDisplayString as U, renderSlot as m, createCommentVNode as _, withDirectives as y, createVNode as H, withCtx as B, unref as D, vShow as h, Fragment as W, renderList as X, createBlock as Y } from "vue";
2
+ const Z = {
3
+ key: 0,
4
+ class: "lkt-step-process_header"
5
+ }, ee = { class: "lkt-step-process_header-title" }, te = { class: "lkt-step-process_header-slot" }, re = { class: "lkt-step-process-buttons" }, le = { key: 1 }, ne = { key: 1 }, ae = {
6
+ key: 1,
7
+ class: "lkt-step-process_content"
8
+ }, ue = { class: "lkt-grid-1" }, oe = { name: "LktStepProcess", inheritAttrs: !1 }, se = /* @__PURE__ */ K({
9
+ ...oe,
10
+ props: {
11
+ modelValue: { type: Object, required: !1, default: () => ({ step: 1, steps: [], data: {} }) },
12
+ title: { type: String, default: "" },
13
+ nextText: { type: String, default: "Next" },
14
+ prevText: { type: String, default: "Back" },
15
+ nextValidator: { type: Function, required: !1, default: () => !0 },
16
+ prevValidator: { type: Function, required: !1, default: () => !0 }
17
+ },
18
+ emits: ["next", "prev", "finish"],
19
+ setup(v, { expose: g, emit: N }) {
20
+ const s = v, p = M(), x = N, n = c(!1), e = c(s.modelValue), V = c(null), b = c(null), L = l(() => n.value ? !1 : s.title || !!p["post-title"]), R = l(() => {
21
+ let r = [];
22
+ for (let k in p)
23
+ k.indexOf("step-") !== -1 && r.push(k.substring(5));
24
+ return r;
25
+ }), d = l(() => e.value.step ? e.value.step : !e.value.steps || !e.value.steps[0] ? null : e.value.steps[0].name), a = l(() => e.value.steps.findIndex((r) => r.name === d.value)), t = l(() => e.value.steps[a.value]), $ = l(() => typeof t.value.prevValidator == "function" ? t.value.prevValidator(e.value) : typeof t.value.prevValidator == "boolean" ? t.value.prevValidator : typeof s.prevValidator == "function" ? s.prevValidator(e.value) : !0), P = l(() => typeof t.value.nextValidator == "function" ? t.value.nextValidator(e.value) : typeof t.value.nextValidator == "boolean" ? t.value.nextValidator : typeof s.nextValidator == "function" ? s.nextValidator(e.value) : !0), j = l(() => a.value === 0 || !$.value), q = l(() => a.value === e.value.steps.length - 1 || !P.value), w = l(() => typeof t.value.prevHidden == "function" ? t.value.prevHidden(e.value) : typeof t.value.prevHidden == "boolean" ? t.value.prevHidden : a.value === 0), F = l(() => typeof t.value.nextHidden == "function" ? t.value.nextHidden(e.value) : typeof t.value.nextHidden == "boolean" ? t.value.nextHidden : a.value === e.value.steps.length - 1), E = l(() => typeof t.value.prevConfirm == "string" ? t.value.prevConfirm : ""), I = l(() => typeof t.value.nextConfirm == "string" ? t.value.nextConfirm : ""), O = l(() => typeof t.value.nextResource == "string" ? t.value.nextResource : ""), T = l(() => typeof t.value.nextResourceData == "object" ? t.value.nextResourceData : {}), z = l(() => {
26
+ const r = ["lkt-step-process"];
27
+ return d.value && r.push(`step-${d.value}`), r.join(" ");
28
+ }), A = (r) => {
29
+ e.value.step = e.value.steps[a.value + 1].name, a.value === e.value.steps.length - 1 ? x("finish", r) : x("next", r);
30
+ }, G = (r) => {
31
+ e.value.step = e.value.steps[a.value - 1].name, x("prev", r);
32
+ };
33
+ return g({
34
+ goNext: () => {
35
+ b.value.click();
36
+ },
37
+ goPrev: () => {
38
+ V.value.click();
39
+ },
40
+ startLoader: () => n.value = !0,
41
+ stopLoader: () => n.value = !1
42
+ }), (r, k) => {
43
+ const C = S("lkt-button"), J = S("lkt-loader");
44
+ return u(), o("article", {
45
+ class: Q(z.value)
46
+ }, [
47
+ L.value ? (u(), o("header", Z, [
48
+ f("h1", ee, U(v.title), 1),
49
+ f("div", te, [
50
+ m(r.$slots, "post-title", {
51
+ config: e.value,
52
+ loading: n.value
53
+ })
54
+ ])
55
+ ])) : _("", !0),
56
+ f("div", re, [
57
+ y(H(C, {
58
+ ref: (i) => V.value = i,
59
+ palette: "danger",
60
+ disabled: j.value,
61
+ "confirm-modal": E.value,
62
+ onClick: G
63
+ }, {
64
+ default: B(() => [
65
+ D(p)["button-prev"] ? m(r.$slots, "button-prev", {
66
+ key: 0,
67
+ config: e.value
68
+ }) : (u(), o("span", le, "Back"))
69
+ ]),
70
+ _: 3
71
+ }, 8, ["disabled", "confirm-modal"]), [
72
+ [h, !n.value && !w.value]
73
+ ]),
74
+ y(H(C, {
75
+ ref: (i) => b.value = i,
76
+ palette: "success",
77
+ disabled: q.value,
78
+ "confirm-modal": I.value,
79
+ resource: O.value,
80
+ "resource-data": T.value,
81
+ onClick: A
82
+ }, {
83
+ default: B(() => [
84
+ D(p)["button-next"] ? m(r.$slots, "button-next", {
85
+ key: 0,
86
+ config: e.value
87
+ }) : (u(), o("span", ne, "Next"))
88
+ ]),
89
+ _: 3
90
+ }, 8, ["disabled", "confirm-modal", "resource", "resource-data"]), [
91
+ [h, !n.value && !F.value]
92
+ ])
93
+ ]),
94
+ n.value ? _("", !0) : (u(), o("div", ae, [
95
+ f("div", ue, [
96
+ (u(!0), o(W, null, X(R.value, (i) => y((u(), o("div", null, [
97
+ m(r.$slots, "step-" + i, { config: e.value })
98
+ ], 512)), [
99
+ [h, i === d.value]
100
+ ])), 256))
101
+ ])
102
+ ])),
103
+ n.value ? (u(), Y(J, { key: 2 })) : _("", !0)
104
+ ], 2);
105
+ };
106
+ }
107
+ }), ve = {
108
+ install: (v, g = {}) => {
109
+ v.component("lkt-step-process", se);
110
+ }
111
+ };
112
+ export {
113
+ ve as default
114
+ };
@@ -0,0 +1,4 @@
1
+ import { Plugin } from "vue";
2
+ import "./../lkt-step-process.css";
3
+ declare const LktStepProcess: Plugin;
4
+ export default LktStepProcess;
@@ -0,0 +1,97 @@
1
+ import { StepProcess } from "../types/StepProcess";
2
+ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
3
+ modelValue: {
4
+ type: ObjectConstructor;
5
+ required: false;
6
+ default: () => StepProcess;
7
+ };
8
+ title: {
9
+ type: StringConstructor;
10
+ default: string;
11
+ };
12
+ nextText: {
13
+ type: StringConstructor;
14
+ default: string;
15
+ };
16
+ prevText: {
17
+ type: StringConstructor;
18
+ default: string;
19
+ };
20
+ nextValidator: {
21
+ type: FunctionConstructor;
22
+ required: false;
23
+ default: () => boolean;
24
+ };
25
+ prevValidator: {
26
+ type: FunctionConstructor;
27
+ required: false;
28
+ default: () => boolean;
29
+ };
30
+ }, {
31
+ goNext: () => void;
32
+ goPrev: () => void;
33
+ startLoader: () => boolean;
34
+ stopLoader: () => boolean;
35
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
36
+ finish: (...args: any[]) => void;
37
+ next: (...args: any[]) => void;
38
+ prev: (...args: any[]) => void;
39
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
40
+ modelValue: {
41
+ type: ObjectConstructor;
42
+ required: false;
43
+ default: () => StepProcess;
44
+ };
45
+ title: {
46
+ type: StringConstructor;
47
+ default: string;
48
+ };
49
+ nextText: {
50
+ type: StringConstructor;
51
+ default: string;
52
+ };
53
+ prevText: {
54
+ type: StringConstructor;
55
+ default: string;
56
+ };
57
+ nextValidator: {
58
+ type: FunctionConstructor;
59
+ required: false;
60
+ default: () => boolean;
61
+ };
62
+ prevValidator: {
63
+ type: FunctionConstructor;
64
+ required: false;
65
+ default: () => boolean;
66
+ };
67
+ }>> & {
68
+ onNext?: ((...args: any[]) => any) | undefined;
69
+ onFinish?: ((...args: any[]) => any) | undefined;
70
+ onPrev?: ((...args: any[]) => any) | undefined;
71
+ }, {
72
+ title: string;
73
+ modelValue: Record<string, any>;
74
+ nextText: string;
75
+ prevText: string;
76
+ nextValidator: Function;
77
+ prevValidator: Function;
78
+ }, {}>, Partial<Record<string, (_: {
79
+ config: Record<string, any>;
80
+ }) => any>> & {
81
+ "post-title"?(_: {
82
+ config: Record<string, any>;
83
+ loading: boolean;
84
+ }): any;
85
+ "button-prev"?(_: {
86
+ config: Record<string, any>;
87
+ }): any;
88
+ "button-next"?(_: {
89
+ config: Record<string, any>;
90
+ }): any;
91
+ }>;
92
+ export default _default;
93
+ type __VLS_WithTemplateSlots<T, S> = T & {
94
+ new (): {
95
+ $slots: S;
96
+ };
97
+ };
package/dist/style.css ADDED
@@ -0,0 +1 @@
1
+ .lkt-step-process,.lkt-step-process_content{display:flex;flex-direction:column;gap:15px}.lkt-step-process-buttons{position:sticky;top:calc(-1 * var(--gap));display:flex;align-items:center;justify-content:flex-end;gap:var(--gap);transition:all linear .15s;background:#fff;z-index:2;padding:var(--gap) 0}
@@ -0,0 +1,13 @@
1
+ import { LktObject } from "lkt-ts-interfaces";
2
+ export type Step = {
3
+ name: string;
4
+ readResource?: string;
5
+ nextResource?: string;
6
+ nextResourceData?: LktObject;
7
+ nextConfirm?: string;
8
+ prevConfirm?: string;
9
+ nextValidator?: Function | boolean;
10
+ prevValidator?: Function | boolean;
11
+ nextHidden?: boolean;
12
+ prevHidden?: boolean;
13
+ };
@@ -0,0 +1,7 @@
1
+ import { LktObject } from "lkt-ts-interfaces";
2
+ import { Step } from "./Step";
3
+ export type StepProcess = {
4
+ step: number | string;
5
+ steps: Step[];
6
+ data: LktObject;
7
+ };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "lkt-step-process",
3
+ "version": "1.1.0",
4
+ "description": "",
5
+ "type": "module",
6
+ "module": "./dist/build.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/build.js"
10
+ },
11
+ "./styles": "./dist/style.css"
12
+ },
13
+ "types": "./dist/index.d.ts",
14
+ "files": ["dist/*", "src/**/*.vue"],
15
+ "license": "MIT",
16
+ "sideEffects": false,
17
+ "scripts": {
18
+ "build": "rm -rf dist/*; vue-tsc --declaration --emitDeclarationOnly; vite build; tsc --project tsconfig.build.json; cp build/* dist/"
19
+ },
20
+ "author": "Antonio Ibáñez",
21
+ "devDependencies": {
22
+ "@babel/types": "^7.23.6",
23
+ "@types/node": "^20.11.19",
24
+ "@types/rollup": "^0.54.0",
25
+ "@vitejs/plugin-vue": "^5.0.4",
26
+ "rollup": "^4.9.6",
27
+ "typescript": "^5.3.3",
28
+ "vite": "^5.1.3",
29
+ "vue": "^3.3.0",
30
+ "vue-tsc": "^1.8.27"
31
+ },
32
+ "engines": {
33
+ "node": ">=18"
34
+ },
35
+ "dependencies": {
36
+ "lkt-button": "^1.0.14",
37
+ "lkt-data-state": "^1.0.9",
38
+ "lkt-events": "^1.0.2",
39
+ "lkt-field-switch": "^1.0.0",
40
+ "lkt-http-client": "^1.0.12",
41
+ "lkt-http-info": "^1.0.2",
42
+ "lkt-loader": "^1.0.2",
43
+ "lkt-string-tools": "^1.0.2",
44
+ "lkt-ts-interfaces": "^1.0.2",
45
+ "path": "^0.12.7",
46
+ "vue": "^3.3.0"
47
+ }
48
+ }
@@ -0,0 +1,210 @@
1
+ <script lang="ts">
2
+ export default {name: "LktStepProcess", inheritAttrs: false}
3
+ </script>
4
+
5
+ <script setup lang="ts">
6
+ import {ref, useSlots, computed} from "vue";
7
+ import {StepProcess} from "../types/StepProcess";
8
+ import {Step} from "../types/Step";
9
+
10
+ const props = defineProps({
11
+ modelValue: {type: Object, required: false, default: (): StepProcess => ({step: 1, steps: [], data: {}})},
12
+
13
+ title: {type: String, default: ''},
14
+ nextText: {type: String, default: 'Next'},
15
+ prevText: {type: String, default: 'Back'},
16
+
17
+ nextValidator: {type: Function, required: false, default: () => true},
18
+ prevValidator: {type: Function, required: false, default: () => true},
19
+ });
20
+
21
+ const slots = useSlots();
22
+
23
+ const emit = defineEmits(['next', 'prev', 'finish']);
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
+ })
41
+
42
+ const currentStep = computed(() => {
43
+ if (!config.value.step) {
44
+ if (!config.value.steps) {
45
+ return null;
46
+ }
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(' ');
136
+ });
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
+ </script>
166
+
167
+ <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>
175
+ <div class="lkt-step-process-buttons">
176
+ <lkt-button
177
+ :ref="(el:any) => prevButton = el"
178
+ 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
+
187
+ <lkt-button
188
+ :ref="(el:any) => nextButton = el"
189
+ 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>
199
+ </div>
200
+
201
+ <div class="lkt-step-process_content" v-if="!isLoading">
202
+ <div class="lkt-grid-1">
203
+ <div v-for="step in slotsSteps" v-show="step === currentStep">
204
+ <slot :name="'step-'+step" v-bind:config="config"></slot>
205
+ </div>
206
+ </div>
207
+ </div>
208
+ <lkt-loader v-if="isLoading"></lkt-loader>
209
+ </article>
210
+ </template>