lkt-item-crud 1.0.6 → 1.0.8
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/dist/lkt-item-crud.es.js
CHANGED
|
@@ -1,190 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}, le = { class: "lkt-item-crud_header-title" }, ue = { class: "lkt-item-crud_header-slot" }, re = { class: "lkt-item-crud-buttons" }, oe = { key: 1 }, se = { key: 1 }, de = {
|
|
8
|
-
key: 1,
|
|
9
|
-
class: "lkt-item-crud_content"
|
|
10
|
-
}, ie = {
|
|
11
|
-
key: 0,
|
|
12
|
-
class: "lkt-grid-1"
|
|
13
|
-
}, ne = { name: "LktItemCrud", inheritAttrs: !1 }, ce = /* @__PURE__ */ X({
|
|
14
|
-
...ne,
|
|
15
|
-
props: {
|
|
16
|
-
modelValue: { type: Object, required: !1, default: () => ({}) },
|
|
17
|
-
title: { type: String, default: "" },
|
|
18
|
-
editModeText: { type: String, default: "Edition Mode" },
|
|
19
|
-
saveText: { type: String, default: "Save" },
|
|
20
|
-
dropText: { type: String, default: "Delete" },
|
|
21
|
-
readResource: { type: String, required: !0 },
|
|
22
|
-
createResource: { type: String, required: !1 },
|
|
23
|
-
updateResource: { type: String, required: !1 },
|
|
24
|
-
dropResource: { type: String, required: !1 },
|
|
25
|
-
readData: { type: Object, required: !1, default: () => ({}) },
|
|
26
|
-
createData: { type: Object, required: !1, default: () => ({}) },
|
|
27
|
-
updateData: { type: Object, required: !1, default: () => ({}) },
|
|
28
|
-
dropData: { type: Object, required: !1, default: () => ({}) },
|
|
29
|
-
isCreate: { type: Boolean, default: !1 },
|
|
30
|
-
createConfirm: { type: String, default: "" },
|
|
31
|
-
updateConfirm: { type: String, default: "" },
|
|
32
|
-
dropConfirm: { type: String, default: "" },
|
|
33
|
-
createDisabled: { type: Boolean, default: !1 },
|
|
34
|
-
updateDisabled: { type: Boolean, default: !1 },
|
|
35
|
-
dropDisabled: { type: Boolean, default: !1 },
|
|
36
|
-
saveValidator: { type: Function, required: !1, default: () => !0 }
|
|
37
|
-
},
|
|
38
|
-
emits: ["update:modelValue", "read", "create", "update", "drop", "perms", "error", "modified-data"],
|
|
39
|
-
setup(u, { expose: I, emit: E }) {
|
|
40
|
-
const e = u, q = Y(), o = E;
|
|
41
|
-
let A = [];
|
|
42
|
-
const a = d(!0), r = d(e.modelValue), B = d(A), c = d(!1), n = d(!1), v = d(!1), s = d(200), S = d(null), h = d(null), y = d(new ee(r.value)), F = p(() => e.isCreate ? e.createConfirm : e.updateConfirm), H = p(() => e.isCreate ? e.createResource : e.updateResource), P = p(() => e.isCreate ? { ...e.createData, ...JSON.parse(JSON.stringify(r.value)) } : { ...e.updateData, ...JSON.parse(JSON.stringify(r.value)) }), U = p(() => e.isCreate ? e.createDisabled : e.updateDisabled), O = async () => {
|
|
43
|
-
a.value = !0, s.value = -1, v.value = !1;
|
|
44
|
-
try {
|
|
45
|
-
const t = await Z(e.readResource, e.readData);
|
|
46
|
-
if (a.value = !1, s.value = t.httpStatus, !t.success) {
|
|
47
|
-
n.value = !1, s.value = t.httpStatus, o("error", t.httpStatus);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
n.value = !0, r.value = t.data, B.value = t.perms, y.value.increment(r.value).turnStoredIntoOriginal(), o("read", t);
|
|
51
|
-
} catch {
|
|
52
|
-
a.value = !1, n.value = !1, s.value = 404, o("error", 404);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
}, z = p(() => a.value ? !1 : e.title || !!q["post-title"]);
|
|
56
|
-
b(() => e.modelValue, (t) => {
|
|
57
|
-
r.value = t, y.value.increment(t);
|
|
58
|
-
}, { deep: !0 }), b(r, (t) => {
|
|
59
|
-
o("update:modelValue", r.value), y.value.increment(t);
|
|
60
|
-
}, { deep: !0 }), b(B, () => o("perms", B.value));
|
|
61
|
-
const M = p(() => U.value || typeof e.saveValidator == "function" && !e.saveValidator(r.value) ? !1 : y.value.changed());
|
|
62
|
-
b(M, (t) => o("modified-data", t)), e.readResource && !e.isCreate ? O() : e.isCreate && (n.value = !0, c.value = !0, a.value = !1);
|
|
63
|
-
const G = (t, l) => {
|
|
64
|
-
if (a.value = !1, s.value = l.httpStatus, !l.success) {
|
|
65
|
-
v.value = !0, o("error", l.httpStatus);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
v.value = !0, o("drop", l);
|
|
69
|
-
}, K = (t, l) => {
|
|
70
|
-
if (a.value = !1, s.value = l.httpStatus, !l.success) {
|
|
71
|
-
v.value = !0, o("error", l.httpStatus);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
v.value = !0;
|
|
75
|
-
let C = e.isCreate ? "create" : "update";
|
|
76
|
-
e.isCreate || y.value.turnStoredIntoOriginal(), l.autoReloadId && (e.readData.id = l.autoReloadId, O()), o(C, l);
|
|
77
|
-
}, N = () => {
|
|
78
|
-
a.value = !0, s.value = -1;
|
|
79
|
-
}, T = () => {
|
|
80
|
-
a.value = !1;
|
|
81
|
-
};
|
|
82
|
-
return I({
|
|
83
|
-
doDrop: () => {
|
|
84
|
-
h.value && typeof h.value.click == "function" && h.value.click();
|
|
85
|
-
},
|
|
86
|
-
doRefresh: O,
|
|
87
|
-
doSave: () => {
|
|
88
|
-
S.value && typeof S.value.click == "function" && S.value.click();
|
|
89
|
-
}
|
|
90
|
-
}), (t, l) => {
|
|
91
|
-
const C = g("lkt-button"), Q = g("lkt-field-switch"), $ = g("lkt-http-info"), W = g("lkt-loader");
|
|
92
|
-
return i(), m("article", te, [
|
|
93
|
-
z.value ? (i(), m("header", ae, [
|
|
94
|
-
L("h1", le, w(u.title), 1),
|
|
95
|
-
L("div", ue, [
|
|
96
|
-
D(t.$slots, "post-title", {
|
|
97
|
-
item: r.value,
|
|
98
|
-
loading: a.value
|
|
99
|
-
})
|
|
100
|
-
])
|
|
101
|
-
])) : k("", !0),
|
|
102
|
-
_(L("div", re, [
|
|
103
|
-
u.isCreate ? k("", !0) : _((i(), R(C, {
|
|
104
|
-
key: 0,
|
|
105
|
-
ref: (f) => h.value = f,
|
|
106
|
-
palette: "danger",
|
|
107
|
-
disabled: u.dropDisabled,
|
|
108
|
-
"confirm-modal": u.dropConfirm,
|
|
109
|
-
resource: u.dropResource,
|
|
110
|
-
"resource-data": u.dropData,
|
|
111
|
-
onLoading: N,
|
|
112
|
-
onLoaded: T,
|
|
113
|
-
onClick: G
|
|
114
|
-
}, {
|
|
115
|
-
default: x(() => [
|
|
116
|
-
j(q)["button-drop"] ? D(t.$slots, "button-drop", {
|
|
117
|
-
key: 0,
|
|
118
|
-
item: r.value,
|
|
119
|
-
editMode: c.value
|
|
120
|
-
}) : (i(), m("span", oe, w(u.dropText), 1))
|
|
121
|
-
]),
|
|
122
|
-
_: 3
|
|
123
|
-
}, 8, ["disabled", "confirm-modal", "resource", "resource-data"])), [
|
|
124
|
-
[V, !a.value && c.value && n.value]
|
|
125
|
-
]),
|
|
126
|
-
_(J(C, {
|
|
127
|
-
ref: (f) => S.value = f,
|
|
128
|
-
palette: "success",
|
|
129
|
-
disabled: !M.value,
|
|
130
|
-
"confirm-modal": F.value,
|
|
131
|
-
resource: H.value,
|
|
132
|
-
"resource-data": P.value,
|
|
133
|
-
onLoading: N,
|
|
134
|
-
onLoaded: T,
|
|
135
|
-
onClick: K
|
|
136
|
-
}, {
|
|
137
|
-
default: x(() => [
|
|
138
|
-
j(q)["button-save"] ? D(t.$slots, "button-save", {
|
|
139
|
-
key: 0,
|
|
140
|
-
item: r.value,
|
|
141
|
-
editMode: c.value
|
|
142
|
-
}) : (i(), m("span", se, w(u.saveText), 1))
|
|
143
|
-
]),
|
|
144
|
-
_: 3
|
|
145
|
-
}, 8, ["disabled", "confirm-modal", "resource", "resource-data"]), [
|
|
146
|
-
[V, !a.value && c.value && n.value]
|
|
147
|
-
]),
|
|
148
|
-
_(J(Q, {
|
|
149
|
-
modelValue: c.value,
|
|
150
|
-
"onUpdate:modelValue": l[0] || (l[0] = (f) => c.value = f),
|
|
151
|
-
label: u.editModeText
|
|
152
|
-
}, null, 8, ["modelValue", "label"]), [
|
|
153
|
-
[V, !a.value && n.value && !u.isCreate]
|
|
154
|
-
])
|
|
155
|
-
], 512), [
|
|
156
|
-
[V, n.value]
|
|
157
|
-
]),
|
|
158
|
-
a.value ? k("", !0) : (i(), m("div", de, [
|
|
159
|
-
n.value ? (i(), m("div", ie, [
|
|
160
|
-
v.value ? (i(), R($, {
|
|
161
|
-
key: 0,
|
|
162
|
-
code: s.value,
|
|
163
|
-
quick: "",
|
|
164
|
-
palette: s.value === 200 ? "success" : "danger",
|
|
165
|
-
"can-close": "",
|
|
166
|
-
onClose: l[1] || (l[1] = (f) => v.value = !1)
|
|
167
|
-
}, null, 8, ["code", "palette"])) : k("", !0),
|
|
168
|
-
D(t.$slots, "item", {
|
|
169
|
-
item: r.value,
|
|
170
|
-
loading: a.value,
|
|
171
|
-
editMode: c.value
|
|
172
|
-
})
|
|
173
|
-
])) : (i(), R($, {
|
|
174
|
-
key: 1,
|
|
175
|
-
code: s.value
|
|
176
|
-
}, null, 8, ["code"]))
|
|
177
|
-
])),
|
|
178
|
-
a.value ? (i(), R(W, { key: 2 })) : k("", !0)
|
|
179
|
-
]);
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
const ke = {
|
|
184
|
-
install: (u, I = {}) => {
|
|
185
|
-
u.component("LktItemCrud", ce);
|
|
1
|
+
import o from "lkt-button";
|
|
2
|
+
import n from "lkt-http-info";
|
|
3
|
+
import e from "lkt-loader";
|
|
4
|
+
const i = {
|
|
5
|
+
install: (t, m = {}) => {
|
|
6
|
+
t.component("lkt-item-crud") === void 0 && t.component("lkt-item-crud", i), t.component("lkt-button") === void 0 && t.use(o), t.component("lkt-http-info") === void 0 && t.use(n), t.component("lkt-loader") === void 0 && t.use(e);
|
|
186
7
|
}
|
|
187
8
|
};
|
|
188
9
|
export {
|
|
189
|
-
|
|
10
|
+
i as default
|
|
190
11
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,
|
|
1
|
+
(function(e,o){typeof exports=="object"&&typeof module<"u"?module.exports=o(require("lkt-button"),require("lkt-http-info"),require("lkt-loader")):typeof define=="function"&&define.amd?define(["lkt-button","lkt-http-info","lkt-loader"],o):(e=typeof globalThis<"u"?globalThis:e||self,e.LktItemCrud=o(e.LktButton,e.LktHttpInfo,e.LktLoader))})(this,function(e,o,d){"use strict";const n=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},i=n(e),f=n(o),l=n(d),k="",u={install:(t,r={})=>{t.component("lkt-item-crud")===void 0&&t.component("lkt-item-crud",u),t.component("lkt-button")===void 0&&t.use(i.default),t.component("lkt-http-info")===void 0&&t.use(f.default),t.component("lkt-loader")===void 0&&t.use(l.default)}};return u});
|
|
@@ -23,7 +23,7 @@ declare const _default: {
|
|
|
23
23
|
};
|
|
24
24
|
readResource: {
|
|
25
25
|
type: StringConstructor;
|
|
26
|
-
required:
|
|
26
|
+
required: false;
|
|
27
27
|
};
|
|
28
28
|
createResource: {
|
|
29
29
|
type: StringConstructor;
|
|
@@ -127,7 +127,7 @@ declare const _default: {
|
|
|
127
127
|
};
|
|
128
128
|
readResource: {
|
|
129
129
|
type: StringConstructor;
|
|
130
|
-
required:
|
|
130
|
+
required: false;
|
|
131
131
|
};
|
|
132
132
|
createResource: {
|
|
133
133
|
type: StringConstructor;
|
|
@@ -252,7 +252,7 @@ declare const _default: {
|
|
|
252
252
|
};
|
|
253
253
|
readResource: {
|
|
254
254
|
type: StringConstructor;
|
|
255
|
-
required:
|
|
255
|
+
required: false;
|
|
256
256
|
};
|
|
257
257
|
createResource: {
|
|
258
258
|
type: StringConstructor;
|
|
@@ -378,7 +378,7 @@ declare const _default: {
|
|
|
378
378
|
};
|
|
379
379
|
readResource: {
|
|
380
380
|
type: StringConstructor;
|
|
381
|
-
required:
|
|
381
|
+
required: false;
|
|
382
382
|
};
|
|
383
383
|
createResource: {
|
|
384
384
|
type: StringConstructor;
|
|
@@ -485,15 +485,24 @@ declare const _default: {
|
|
|
485
485
|
'button-drop': (_: {
|
|
486
486
|
item: Record<string, any>;
|
|
487
487
|
editMode: boolean;
|
|
488
|
+
isCreate: false;
|
|
489
|
+
canUpdate: boolean;
|
|
490
|
+
canDrop: boolean;
|
|
488
491
|
}) => any;
|
|
489
492
|
'button-save': (_: {
|
|
490
493
|
item: Record<string, any>;
|
|
491
494
|
editMode: boolean;
|
|
495
|
+
isCreate: boolean;
|
|
496
|
+
canUpdate: boolean;
|
|
497
|
+
canDrop: boolean;
|
|
492
498
|
}) => any;
|
|
493
499
|
item: (_: {
|
|
494
500
|
item: Record<string, any>;
|
|
495
501
|
loading: false;
|
|
496
502
|
editMode: boolean;
|
|
503
|
+
isCreate: boolean;
|
|
504
|
+
canUpdate: boolean;
|
|
505
|
+
canDrop: boolean;
|
|
497
506
|
}) => any;
|
|
498
507
|
};
|
|
499
508
|
});
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,10 +2,19 @@ import {App} from "vue";
|
|
|
2
2
|
import {default as itemCrud} from "./lib-components/LktItemCrud.vue";
|
|
3
3
|
|
|
4
4
|
import "./../lkt-item-crud.css";
|
|
5
|
+
import LktButton from "lkt-button";
|
|
6
|
+
import LktHttpInfo from "lkt-http-info";
|
|
7
|
+
import LktLoader from "lkt-loader";
|
|
5
8
|
|
|
6
9
|
const LktItemCrud = {
|
|
7
10
|
install: (app: App, options = {}) => {
|
|
8
|
-
|
|
11
|
+
// Register plugin components
|
|
12
|
+
if (app.component('lkt-item-crud') === undefined) app.component('lkt-item-crud', LktItemCrud);
|
|
13
|
+
|
|
14
|
+
// Register additional components
|
|
15
|
+
if (app.component('lkt-button') === undefined) app.use(LktButton);
|
|
16
|
+
if (app.component('lkt-http-info') === undefined) app.use(LktHttpInfo);
|
|
17
|
+
if (app.component('lkt-loader') === undefined) app.use(LktLoader);
|
|
9
18
|
},
|
|
10
19
|
};
|
|
11
20
|
export default LktItemCrud;
|
|
@@ -15,7 +15,7 @@ const props = defineProps({
|
|
|
15
15
|
saveText: {type: String, default: 'Save'},
|
|
16
16
|
dropText: {type: String, default: 'Delete'},
|
|
17
17
|
|
|
18
|
-
readResource: {type: String, required:
|
|
18
|
+
readResource: {type: String, required: false},
|
|
19
19
|
createResource: {type: String, required: false},
|
|
20
20
|
updateResource: {type: String, required: false},
|
|
21
21
|
dropResource: {type: String, required: false},
|
|
@@ -74,7 +74,9 @@ const saveConfirm = computed(() => {
|
|
|
74
74
|
return props.isCreate
|
|
75
75
|
? props.createDisabled
|
|
76
76
|
: props.updateDisabled;
|
|
77
|
-
})
|
|
77
|
+
}),
|
|
78
|
+
canUpdate = computed(() => !props.isCreate && perms.value.includes('update')),
|
|
79
|
+
canDrop = computed(() => !props.isCreate && perms.value.includes('drop'));
|
|
78
80
|
|
|
79
81
|
const fetchItem = async () => {
|
|
80
82
|
isLoading.value = true;
|
|
@@ -124,6 +126,7 @@ watch(perms, () => emit('perms', perms.value));
|
|
|
124
126
|
|
|
125
127
|
const ableToSave = computed(() => {
|
|
126
128
|
if (saveDisabled.value) return false;
|
|
129
|
+
if (!props.isCreate && !canUpdate.value) return false;
|
|
127
130
|
|
|
128
131
|
if (typeof props.saveValidator === 'function' && !props.saveValidator(item.value)) return false;
|
|
129
132
|
|
|
@@ -152,14 +155,16 @@ const onDrop = ($event: PointerEvent, r: HTTPResponse) => {
|
|
|
152
155
|
|
|
153
156
|
},
|
|
154
157
|
onSave = ($event: PointerEvent, r: HTTPResponse) => {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
+
if (saveResource.value) {
|
|
159
|
+
isLoading.value = false;
|
|
160
|
+
httpStatus.value = r.httpStatus;
|
|
161
|
+
if (!r.success) {
|
|
162
|
+
showStoreMessage.value = true;
|
|
163
|
+
emit('error', r.httpStatus);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
158
166
|
showStoreMessage.value = true;
|
|
159
|
-
emit('error', r.httpStatus);
|
|
160
|
-
return;
|
|
161
167
|
}
|
|
162
|
-
showStoreMessage.value = true;
|
|
163
168
|
let emits: 'create' | 'update' = props.isCreate ? 'create' : 'update';
|
|
164
169
|
if (!props.isCreate) {
|
|
165
170
|
dataState.value.turnStoredIntoOriginal();
|
|
@@ -209,7 +214,7 @@ defineExpose({
|
|
|
209
214
|
v-show="!isLoading && editMode && httpSuccessRead"
|
|
210
215
|
v-if="!isCreate"
|
|
211
216
|
palette="danger"
|
|
212
|
-
v-bind:disabled="dropDisabled"
|
|
217
|
+
v-bind:disabled="dropDisabled || !canDrop"
|
|
213
218
|
v-bind:confirm-modal="dropConfirm"
|
|
214
219
|
v-bind:resource="dropResource"
|
|
215
220
|
v-bind:resource-data="dropData"
|
|
@@ -217,7 +222,10 @@ defineExpose({
|
|
|
217
222
|
v-on:loaded="onButtonLoaded"
|
|
218
223
|
v-on:click="onDrop">
|
|
219
224
|
<slot v-if="!!slots['button-drop']" name="button-drop" v-bind:item="item"
|
|
220
|
-
v-bind:edit-mode="editMode"
|
|
225
|
+
v-bind:edit-mode="editMode"
|
|
226
|
+
v-bind:is-create="isCreate"
|
|
227
|
+
v-bind:can-update="canUpdate"
|
|
228
|
+
v-bind:can-drop="canDrop"></slot>
|
|
221
229
|
<span v-else>{{ dropText }}</span>
|
|
222
230
|
</lkt-button>
|
|
223
231
|
|
|
@@ -233,7 +241,10 @@ defineExpose({
|
|
|
233
241
|
v-on:loaded="onButtonLoaded"
|
|
234
242
|
v-on:click="onSave">
|
|
235
243
|
<slot v-if="!!slots['button-save']" name="button-save" v-bind:item="item"
|
|
236
|
-
v-bind:edit-mode="editMode"
|
|
244
|
+
v-bind:edit-mode="editMode"
|
|
245
|
+
v-bind:is-create="isCreate"
|
|
246
|
+
v-bind:can-update="canUpdate"
|
|
247
|
+
v-bind:can-drop="canDrop"></slot>
|
|
237
248
|
<span v-else>{{ saveText }}</span>
|
|
238
249
|
</lkt-button>
|
|
239
250
|
|
|
@@ -246,7 +257,10 @@ defineExpose({
|
|
|
246
257
|
<lkt-http-info :code="httpStatus" v-if="showStoreMessage" quick
|
|
247
258
|
:palette="httpStatus === 200 ? 'success' : 'danger'" can-close
|
|
248
259
|
v-on:close="showStoreMessage = false"></lkt-http-info>
|
|
249
|
-
<slot name="item" v-bind:item="item" v-bind:loading="isLoading" v-bind:edit-mode="editMode"
|
|
260
|
+
<slot name="item" v-bind:item="item" v-bind:loading="isLoading" v-bind:edit-mode="editMode"
|
|
261
|
+
v-bind:is-create="isCreate"
|
|
262
|
+
v-bind:can-update="canUpdate"
|
|
263
|
+
v-bind:can-drop="canDrop"></slot>
|
|
250
264
|
</div>
|
|
251
265
|
<lkt-http-info :code="httpStatus" v-else></lkt-http-info>
|
|
252
266
|
</div>
|
package/lkt-item-crud.css
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
.lkt-item-crud {
|
|
2
|
-
display: flex;
|
|
3
|
-
flex-direction: column;
|
|
4
|
-
gap: 15px;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
.lkt-item-crud_content {
|
|
8
|
-
display: flex;
|
|
9
|
-
flex-direction: column;
|
|
10
|
-
gap: 15px;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.lkt-item-crud-buttons {
|
|
14
|
-
position: sticky;
|
|
15
|
-
top: calc(-1 * var(--gap));
|
|
16
|
-
display: flex;
|
|
17
|
-
align-items: center;
|
|
18
|
-
gap: var(--gap);
|
|
19
|
-
transition: all linear .150s;
|
|
20
|
-
background: #ffffff;
|
|
21
|
-
z-index: 2;
|
|
22
|
-
padding: var(--gap) 0;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
.lkt-item-crud-buttons > :last-child {
|
|
26
|
-
margin-left: auto;
|
|
27
|
-
}
|