lkt-item-crud 1.0.4 → 1.0.6
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 +1 -1
- package/dist/lkt-item-crud.es.js +101 -92
- package/dist/lkt-item-crud.umd.js +1 -1
- package/dist/style.css +1 -1
- package/dist/types/lib-components/LktItemCrud.vue.d.ts +30 -7
- package/dist/vite.config.d.ts +1 -0
- package/lkt-item-crud.css +5 -1
- package/package.json +1 -1
- package/src/lib-components/LktItemCrud.vue +49 -19
package/LICENSE
CHANGED
package/dist/lkt-item-crud.es.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { httpCall as
|
|
3
|
-
import { DataState as
|
|
1
|
+
import { defineComponent as X, useSlots as Y, ref as d, computed as p, watch as b, resolveComponent as g, openBlock as i, createElementBlock as m, createElementVNode as L, toDisplayString as w, renderSlot as D, createCommentVNode as k, withDirectives as _, createBlock as R, withCtx as x, unref as j, vShow as V, createVNode as J } from "vue";
|
|
2
|
+
import { httpCall as Z } from "lkt-http-client";
|
|
3
|
+
import { DataState as ee } from "lkt-data-state";
|
|
4
4
|
const te = { class: "lkt-item-crud" }, ae = {
|
|
5
5
|
key: 0,
|
|
6
6
|
class: "lkt-item-crud_header"
|
|
7
|
-
}, le = { class: "lkt-item-crud_header-title" }, ue = { class: "lkt-item-crud_header-slot" },
|
|
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
8
|
key: 1,
|
|
9
9
|
class: "lkt-item-crud_content"
|
|
10
|
-
},
|
|
10
|
+
}, ie = {
|
|
11
11
|
key: 0,
|
|
12
12
|
class: "lkt-grid-1"
|
|
13
|
-
},
|
|
14
|
-
...
|
|
13
|
+
}, ne = { name: "LktItemCrud", inheritAttrs: !1 }, ce = /* @__PURE__ */ X({
|
|
14
|
+
...ne,
|
|
15
15
|
props: {
|
|
16
16
|
modelValue: { type: Object, required: !1, default: () => ({}) },
|
|
17
17
|
title: { type: String, default: "" },
|
|
@@ -26,156 +26,165 @@ const te = { class: "lkt-item-crud" }, ae = {
|
|
|
26
26
|
createData: { type: Object, required: !1, default: () => ({}) },
|
|
27
27
|
updateData: { type: Object, required: !1, default: () => ({}) },
|
|
28
28
|
dropData: { type: Object, required: !1, default: () => ({}) },
|
|
29
|
-
|
|
29
|
+
isCreate: { type: Boolean, default: !1 },
|
|
30
30
|
createConfirm: { type: String, default: "" },
|
|
31
31
|
updateConfirm: { type: String, default: "" },
|
|
32
32
|
dropConfirm: { type: String, default: "" },
|
|
33
33
|
createDisabled: { type: Boolean, default: !1 },
|
|
34
34
|
updateDisabled: { type: Boolean, default: !1 },
|
|
35
|
-
dropDisabled: { type: Boolean, default: !1 }
|
|
35
|
+
dropDisabled: { type: Boolean, default: !1 },
|
|
36
|
+
saveValidator: { type: Function, required: !1, default: () => !0 }
|
|
36
37
|
},
|
|
37
38
|
emits: ["update:modelValue", "read", "create", "update", "drop", "perms", "error", "modified-data"],
|
|
38
|
-
setup(u, { expose:
|
|
39
|
-
const
|
|
40
|
-
let
|
|
41
|
-
const a =
|
|
42
|
-
|
|
43
|
-
|
|
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);
|
|
44
53
|
return;
|
|
45
54
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
v.value = !0, s("error", l.httpStatus);
|
|
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);
|
|
58
66
|
return;
|
|
59
67
|
}
|
|
60
|
-
v.value = !0,
|
|
61
|
-
},
|
|
62
|
-
if (a.value = !1,
|
|
63
|
-
v.value = !0,
|
|
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);
|
|
64
72
|
return;
|
|
65
73
|
}
|
|
66
74
|
v.value = !0;
|
|
67
|
-
let
|
|
68
|
-
|
|
69
|
-
},
|
|
70
|
-
a.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;
|
|
71
79
|
}, T = () => {
|
|
72
80
|
a.value = !1;
|
|
73
81
|
};
|
|
74
|
-
return
|
|
82
|
+
return I({
|
|
75
83
|
doDrop: () => {
|
|
76
|
-
|
|
84
|
+
h.value && typeof h.value.click == "function" && h.value.click();
|
|
77
85
|
},
|
|
78
|
-
doRefresh:
|
|
86
|
+
doRefresh: O,
|
|
79
87
|
doSave: () => {
|
|
80
|
-
|
|
88
|
+
S.value && typeof S.value.click == "function" && S.value.click();
|
|
81
89
|
}
|
|
82
|
-
}), (
|
|
83
|
-
const
|
|
84
|
-
return
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
item:
|
|
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,
|
|
90
98
|
loading: a.value
|
|
91
99
|
})
|
|
92
100
|
])
|
|
93
|
-
])) :
|
|
94
|
-
_(
|
|
95
|
-
_(
|
|
96
|
-
|
|
101
|
+
])) : k("", !0),
|
|
102
|
+
_(L("div", re, [
|
|
103
|
+
u.isCreate ? k("", !0) : _((i(), R(C, {
|
|
104
|
+
key: 0,
|
|
105
|
+
ref: (f) => h.value = f,
|
|
97
106
|
palette: "danger",
|
|
98
107
|
disabled: u.dropDisabled,
|
|
99
108
|
"confirm-modal": u.dropConfirm,
|
|
100
109
|
resource: u.dropResource,
|
|
101
110
|
"resource-data": u.dropData,
|
|
102
|
-
onLoading:
|
|
111
|
+
onLoading: N,
|
|
103
112
|
onLoaded: T,
|
|
104
|
-
onClick:
|
|
113
|
+
onClick: G
|
|
105
114
|
}, {
|
|
106
115
|
default: x(() => [
|
|
107
|
-
j(
|
|
116
|
+
j(q)["button-drop"] ? D(t.$slots, "button-drop", {
|
|
108
117
|
key: 0,
|
|
109
|
-
item:
|
|
110
|
-
editMode:
|
|
111
|
-
}) : (
|
|
118
|
+
item: r.value,
|
|
119
|
+
editMode: c.value
|
|
120
|
+
}) : (i(), m("span", oe, w(u.dropText), 1))
|
|
112
121
|
]),
|
|
113
122
|
_: 3
|
|
114
|
-
}, 8, ["disabled", "confirm-modal", "resource", "resource-data"]), [
|
|
115
|
-
[
|
|
123
|
+
}, 8, ["disabled", "confirm-modal", "resource", "resource-data"])), [
|
|
124
|
+
[V, !a.value && c.value && n.value]
|
|
116
125
|
]),
|
|
117
|
-
_(
|
|
118
|
-
ref: (f) =>
|
|
126
|
+
_(J(C, {
|
|
127
|
+
ref: (f) => S.value = f,
|
|
119
128
|
palette: "success",
|
|
120
|
-
disabled: !
|
|
121
|
-
"confirm-modal":
|
|
122
|
-
resource:
|
|
123
|
-
"resource-data":
|
|
124
|
-
onLoading:
|
|
129
|
+
disabled: !M.value,
|
|
130
|
+
"confirm-modal": F.value,
|
|
131
|
+
resource: H.value,
|
|
132
|
+
"resource-data": P.value,
|
|
133
|
+
onLoading: N,
|
|
125
134
|
onLoaded: T,
|
|
126
|
-
onClick:
|
|
135
|
+
onClick: K
|
|
127
136
|
}, {
|
|
128
137
|
default: x(() => [
|
|
129
|
-
j(
|
|
138
|
+
j(q)["button-save"] ? D(t.$slots, "button-save", {
|
|
130
139
|
key: 0,
|
|
131
|
-
item:
|
|
132
|
-
editMode:
|
|
133
|
-
}) : (
|
|
140
|
+
item: r.value,
|
|
141
|
+
editMode: c.value
|
|
142
|
+
}) : (i(), m("span", se, w(u.saveText), 1))
|
|
134
143
|
]),
|
|
135
144
|
_: 3
|
|
136
145
|
}, 8, ["disabled", "confirm-modal", "resource", "resource-data"]), [
|
|
137
|
-
[
|
|
146
|
+
[V, !a.value && c.value && n.value]
|
|
138
147
|
]),
|
|
139
|
-
_(
|
|
140
|
-
modelValue:
|
|
141
|
-
"onUpdate:modelValue": l[0] || (l[0] = (f) =>
|
|
148
|
+
_(J(Q, {
|
|
149
|
+
modelValue: c.value,
|
|
150
|
+
"onUpdate:modelValue": l[0] || (l[0] = (f) => c.value = f),
|
|
142
151
|
label: u.editModeText
|
|
143
152
|
}, null, 8, ["modelValue", "label"]), [
|
|
144
|
-
[
|
|
153
|
+
[V, !a.value && n.value && !u.isCreate]
|
|
145
154
|
])
|
|
146
155
|
], 512), [
|
|
147
|
-
[
|
|
156
|
+
[V, n.value]
|
|
148
157
|
]),
|
|
149
|
-
a.value ?
|
|
150
|
-
|
|
151
|
-
v.value ? (
|
|
158
|
+
a.value ? k("", !0) : (i(), m("div", de, [
|
|
159
|
+
n.value ? (i(), m("div", ie, [
|
|
160
|
+
v.value ? (i(), R($, {
|
|
152
161
|
key: 0,
|
|
153
|
-
code:
|
|
162
|
+
code: s.value,
|
|
154
163
|
quick: "",
|
|
155
|
-
palette:
|
|
164
|
+
palette: s.value === 200 ? "success" : "danger",
|
|
156
165
|
"can-close": "",
|
|
157
166
|
onClose: l[1] || (l[1] = (f) => v.value = !1)
|
|
158
|
-
}, null, 8, ["code", "palette"])) :
|
|
159
|
-
|
|
160
|
-
item:
|
|
167
|
+
}, null, 8, ["code", "palette"])) : k("", !0),
|
|
168
|
+
D(t.$slots, "item", {
|
|
169
|
+
item: r.value,
|
|
161
170
|
loading: a.value,
|
|
162
|
-
editMode:
|
|
171
|
+
editMode: c.value
|
|
163
172
|
})
|
|
164
|
-
])) : (
|
|
173
|
+
])) : (i(), R($, {
|
|
165
174
|
key: 1,
|
|
166
|
-
code:
|
|
175
|
+
code: s.value
|
|
167
176
|
}, null, 8, ["code"]))
|
|
168
177
|
])),
|
|
169
|
-
a.value ? (
|
|
178
|
+
a.value ? (i(), R(W, { key: 2 })) : k("", !0)
|
|
170
179
|
]);
|
|
171
180
|
};
|
|
172
181
|
}
|
|
173
182
|
});
|
|
174
|
-
const
|
|
175
|
-
install: (u,
|
|
183
|
+
const ke = {
|
|
184
|
+
install: (u, I = {}) => {
|
|
176
185
|
u.component("LktItemCrud", ce);
|
|
177
186
|
}
|
|
178
187
|
};
|
|
179
188
|
export {
|
|
180
|
-
|
|
189
|
+
ke as default
|
|
181
190
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,
|
|
1
|
+
(function(e,p){typeof exports=="object"&&typeof module<"u"?module.exports=p(require("vue"),require("lkt-http-client"),require("lkt-data-state")):typeof define=="function"&&define.amd?define(["vue","lkt-http-client","lkt-data-state"],p):(e=typeof globalThis<"u"?globalThis:e||self,e.LktItemCrud=p(e.Vue,e.LktHttpClient,e.LktDataState))})(this,function(e,p,w){"use strict";const _={class:"lkt-item-crud"},q={key:0,class:"lkt-item-crud_header"},L={class:"lkt-item-crud_header-title"},N={class:"lkt-item-crud_header-slot"},R={class:"lkt-item-crud-buttons"},I={key:1},O={key:1},E={key:1,class:"lkt-item-crud_content"},T={key:0,class:"lkt-grid-1"},x={name:"LktItemCrud",inheritAttrs:!1},M=e.defineComponent({...x,props:{modelValue:{type:Object,required:!1,default:()=>({})},title:{type:String,default:""},editModeText:{type:String,default:"Edition Mode"},saveText:{type:String,default:"Save"},dropText:{type:String,default:"Delete"},readResource:{type:String,required:!0},createResource:{type:String,required:!1},updateResource:{type:String,required:!1},dropResource:{type:String,required:!1},readData:{type:Object,required:!1,default:()=>({})},createData:{type:Object,required:!1,default:()=>({})},updateData:{type:Object,required:!1,default:()=>({})},dropData:{type:Object,required:!1,default:()=>({})},isCreate:{type:Boolean,default:!1},createConfirm:{type:String,default:""},updateConfirm:{type:String,default:""},dropConfirm:{type:String,default:""},createDisabled:{type:Boolean,default:!1},updateDisabled:{type:Boolean,default:!1},dropDisabled:{type:Boolean,default:!1},saveValidator:{type:Function,required:!1,default:()=>!0}},emits:["update:modelValue","read","create","update","drop","perms","error","modified-data"],setup(r,{expose:D,emit:$}){const t=r,v=e.useSlots(),s=$;let j=[];const l=e.ref(!0),d=e.ref(t.modelValue),y=e.ref(j),u=e.ref(!1),i=e.ref(!1),c=e.ref(!1),n=e.ref(200),k=e.ref(null),h=e.ref(null),m=e.ref(new w.DataState(d.value)),J=e.computed(()=>t.isCreate?t.createConfirm:t.updateConfirm),H=e.computed(()=>t.isCreate?t.createResource:t.updateResource),A=e.computed(()=>t.isCreate?{...t.createData,...JSON.parse(JSON.stringify(d.value))}:{...t.updateData,...JSON.parse(JSON.stringify(d.value))}),F=e.computed(()=>t.isCreate?t.createDisabled:t.updateDisabled),C=async()=>{l.value=!0,n.value=-1,c.value=!1;try{const a=await p.httpCall(t.readResource,t.readData);if(l.value=!1,n.value=a.httpStatus,!a.success){i.value=!1,n.value=a.httpStatus,s("error",a.httpStatus);return}i.value=!0,d.value=a.data,y.value=a.perms,m.value.increment(d.value).turnStoredIntoOriginal(),s("read",a)}catch{l.value=!1,i.value=!1,n.value=404,s("error",404);return}},P=e.computed(()=>l.value?!1:t.title||!!v["post-title"]);e.watch(()=>t.modelValue,a=>{d.value=a,m.value.increment(a)},{deep:!0}),e.watch(d,a=>{s("update:modelValue",d.value),m.value.increment(a)},{deep:!0}),e.watch(y,()=>s("perms",y.value));const B=e.computed(()=>F.value||typeof t.saveValidator=="function"&&!t.saveValidator(d.value)?!1:m.value.changed());e.watch(B,a=>s("modified-data",a)),t.readResource&&!t.isCreate?C():t.isCreate&&(i.value=!0,u.value=!0,l.value=!1);const U=(a,o)=>{if(l.value=!1,n.value=o.httpStatus,!o.success){c.value=!0,s("error",o.httpStatus);return}c.value=!0,s("drop",o)},z=(a,o)=>{if(l.value=!1,n.value=o.httpStatus,!o.success){c.value=!0,s("error",o.httpStatus);return}c.value=!0;let S=t.isCreate?"create":"update";t.isCreate||m.value.turnStoredIntoOriginal(),o.autoReloadId&&(t.readData.id=o.autoReloadId,C()),s(S,o)},g=()=>{l.value=!0,n.value=-1},b=()=>{l.value=!1};return D({doDrop:()=>{h.value&&typeof h.value.click=="function"&&h.value.click()},doRefresh:C,doSave:()=>{k.value&&typeof k.value.click=="function"&&k.value.click()}}),(a,o)=>{const S=e.resolveComponent("lkt-button"),G=e.resolveComponent("lkt-field-switch"),V=e.resolveComponent("lkt-http-info"),K=e.resolveComponent("lkt-loader");return e.openBlock(),e.createElementBlock("article",_,[P.value?(e.openBlock(),e.createElementBlock("header",q,[e.createElementVNode("h1",L,e.toDisplayString(r.title),1),e.createElementVNode("div",N,[e.renderSlot(a.$slots,"post-title",{item:d.value,loading:l.value})])])):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("div",R,[r.isCreate?e.createCommentVNode("",!0):e.withDirectives((e.openBlock(),e.createBlock(S,{key:0,ref:f=>h.value=f,palette:"danger",disabled:r.dropDisabled,"confirm-modal":r.dropConfirm,resource:r.dropResource,"resource-data":r.dropData,onLoading:g,onLoaded:b,onClick:U},{default:e.withCtx(()=>[e.unref(v)["button-drop"]?e.renderSlot(a.$slots,"button-drop",{key:0,item:d.value,editMode:u.value}):(e.openBlock(),e.createElementBlock("span",I,e.toDisplayString(r.dropText),1))]),_:3},8,["disabled","confirm-modal","resource","resource-data"])),[[e.vShow,!l.value&&u.value&&i.value]]),e.withDirectives(e.createVNode(S,{ref:f=>k.value=f,palette:"success",disabled:!B.value,"confirm-modal":J.value,resource:H.value,"resource-data":A.value,onLoading:g,onLoaded:b,onClick:z},{default:e.withCtx(()=>[e.unref(v)["button-save"]?e.renderSlot(a.$slots,"button-save",{key:0,item:d.value,editMode:u.value}):(e.openBlock(),e.createElementBlock("span",O,e.toDisplayString(r.saveText),1))]),_:3},8,["disabled","confirm-modal","resource","resource-data"]),[[e.vShow,!l.value&&u.value&&i.value]]),e.withDirectives(e.createVNode(G,{modelValue:u.value,"onUpdate:modelValue":o[0]||(o[0]=f=>u.value=f),label:r.editModeText},null,8,["modelValue","label"]),[[e.vShow,!l.value&&i.value&&!r.isCreate]])],512),[[e.vShow,i.value]]),l.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",E,[i.value?(e.openBlock(),e.createElementBlock("div",T,[c.value?(e.openBlock(),e.createBlock(V,{key:0,code:n.value,quick:"",palette:n.value===200?"success":"danger","can-close":"",onClose:o[1]||(o[1]=f=>c.value=!1)},null,8,["code","palette"])):e.createCommentVNode("",!0),e.renderSlot(a.$slots,"item",{item:d.value,loading:l.value,editMode:u.value})])):(e.openBlock(),e.createBlock(V,{key:1,code:n.value},null,8,["code"]))])),l.value?(e.openBlock(),e.createBlock(K,{key:2})):e.createCommentVNode("",!0)])}}}),Q="";return{install:(r,D={})=>{r.component("LktItemCrud",M)}}});
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.lkt-item-crud,.lkt-item-crud_content{display:flex;flex-direction:column;gap:15px}.lkt-item-crud-buttons{position:sticky;top:
|
|
1
|
+
.lkt-item-crud,.lkt-item-crud_content{display:flex;flex-direction:column;gap:15px}.lkt-item-crud-buttons{position:sticky;top:calc(-1 * var(--gap));display:flex;align-items:center;gap:var(--gap);transition:all linear .15s;background:#ffffff;z-index:2;padding:var(--gap) 0}.lkt-item-crud-buttons>:last-child{margin-left:auto}
|
|
@@ -57,7 +57,7 @@ declare const _default: {
|
|
|
57
57
|
required: false;
|
|
58
58
|
default: () => {};
|
|
59
59
|
};
|
|
60
|
-
|
|
60
|
+
isCreate: {
|
|
61
61
|
type: BooleanConstructor;
|
|
62
62
|
default: boolean;
|
|
63
63
|
};
|
|
@@ -85,6 +85,11 @@ declare const _default: {
|
|
|
85
85
|
type: BooleanConstructor;
|
|
86
86
|
default: boolean;
|
|
87
87
|
};
|
|
88
|
+
saveValidator: {
|
|
89
|
+
type: FunctionConstructor;
|
|
90
|
+
required: false;
|
|
91
|
+
default: () => boolean;
|
|
92
|
+
};
|
|
88
93
|
}>> & {
|
|
89
94
|
onError?: ((...args: any[]) => any) | undefined;
|
|
90
95
|
onDrop?: ((...args: any[]) => any) | undefined;
|
|
@@ -156,7 +161,7 @@ declare const _default: {
|
|
|
156
161
|
required: false;
|
|
157
162
|
default: () => {};
|
|
158
163
|
};
|
|
159
|
-
|
|
164
|
+
isCreate: {
|
|
160
165
|
type: BooleanConstructor;
|
|
161
166
|
default: boolean;
|
|
162
167
|
};
|
|
@@ -184,6 +189,11 @@ declare const _default: {
|
|
|
184
189
|
type: BooleanConstructor;
|
|
185
190
|
default: boolean;
|
|
186
191
|
};
|
|
192
|
+
saveValidator: {
|
|
193
|
+
type: FunctionConstructor;
|
|
194
|
+
required: false;
|
|
195
|
+
default: () => boolean;
|
|
196
|
+
};
|
|
187
197
|
}>> & {
|
|
188
198
|
onError?: ((...args: any[]) => any) | undefined;
|
|
189
199
|
onDrop?: ((...args: any[]) => any) | undefined;
|
|
@@ -203,13 +213,14 @@ declare const _default: {
|
|
|
203
213
|
createData: Record<string, any>;
|
|
204
214
|
updateData: Record<string, any>;
|
|
205
215
|
dropData: Record<string, any>;
|
|
206
|
-
|
|
216
|
+
isCreate: boolean;
|
|
207
217
|
createConfirm: string;
|
|
208
218
|
updateConfirm: string;
|
|
209
219
|
dropConfirm: string;
|
|
210
220
|
createDisabled: boolean;
|
|
211
221
|
updateDisabled: boolean;
|
|
212
222
|
dropDisabled: boolean;
|
|
223
|
+
saveValidator: Function;
|
|
213
224
|
}, true, {}, {}, {
|
|
214
225
|
P: {};
|
|
215
226
|
B: {};
|
|
@@ -275,7 +286,7 @@ declare const _default: {
|
|
|
275
286
|
required: false;
|
|
276
287
|
default: () => {};
|
|
277
288
|
};
|
|
278
|
-
|
|
289
|
+
isCreate: {
|
|
279
290
|
type: BooleanConstructor;
|
|
280
291
|
default: boolean;
|
|
281
292
|
};
|
|
@@ -303,6 +314,11 @@ declare const _default: {
|
|
|
303
314
|
type: BooleanConstructor;
|
|
304
315
|
default: boolean;
|
|
305
316
|
};
|
|
317
|
+
saveValidator: {
|
|
318
|
+
type: FunctionConstructor;
|
|
319
|
+
required: false;
|
|
320
|
+
default: () => boolean;
|
|
321
|
+
};
|
|
306
322
|
}>> & {
|
|
307
323
|
onError?: ((...args: any[]) => any) | undefined;
|
|
308
324
|
onDrop?: ((...args: any[]) => any) | undefined;
|
|
@@ -326,13 +342,14 @@ declare const _default: {
|
|
|
326
342
|
createData: Record<string, any>;
|
|
327
343
|
updateData: Record<string, any>;
|
|
328
344
|
dropData: Record<string, any>;
|
|
329
|
-
|
|
345
|
+
isCreate: boolean;
|
|
330
346
|
createConfirm: string;
|
|
331
347
|
updateConfirm: string;
|
|
332
348
|
dropConfirm: string;
|
|
333
349
|
createDisabled: boolean;
|
|
334
350
|
updateDisabled: boolean;
|
|
335
351
|
dropDisabled: boolean;
|
|
352
|
+
saveValidator: Function;
|
|
336
353
|
}>;
|
|
337
354
|
__isFragment?: undefined;
|
|
338
355
|
__isTeleport?: undefined;
|
|
@@ -395,7 +412,7 @@ declare const _default: {
|
|
|
395
412
|
required: false;
|
|
396
413
|
default: () => {};
|
|
397
414
|
};
|
|
398
|
-
|
|
415
|
+
isCreate: {
|
|
399
416
|
type: BooleanConstructor;
|
|
400
417
|
default: boolean;
|
|
401
418
|
};
|
|
@@ -423,6 +440,11 @@ declare const _default: {
|
|
|
423
440
|
type: BooleanConstructor;
|
|
424
441
|
default: boolean;
|
|
425
442
|
};
|
|
443
|
+
saveValidator: {
|
|
444
|
+
type: FunctionConstructor;
|
|
445
|
+
required: false;
|
|
446
|
+
default: () => boolean;
|
|
447
|
+
};
|
|
426
448
|
}>> & {
|
|
427
449
|
onError?: ((...args: any[]) => any) | undefined;
|
|
428
450
|
onDrop?: ((...args: any[]) => any) | undefined;
|
|
@@ -446,13 +468,14 @@ declare const _default: {
|
|
|
446
468
|
createData: Record<string, any>;
|
|
447
469
|
updateData: Record<string, any>;
|
|
448
470
|
dropData: Record<string, any>;
|
|
449
|
-
|
|
471
|
+
isCreate: boolean;
|
|
450
472
|
createConfirm: string;
|
|
451
473
|
updateConfirm: string;
|
|
452
474
|
dropConfirm: string;
|
|
453
475
|
createDisabled: boolean;
|
|
454
476
|
updateDisabled: boolean;
|
|
455
477
|
dropDisabled: boolean;
|
|
478
|
+
saveValidator: Function;
|
|
456
479
|
}, {}, string, {}> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
|
|
457
480
|
$slots: {
|
|
458
481
|
'post-title': (_: {
|
package/dist/vite.config.d.ts
CHANGED
package/lkt-item-crud.css
CHANGED
|
@@ -12,10 +12,14 @@
|
|
|
12
12
|
|
|
13
13
|
.lkt-item-crud-buttons {
|
|
14
14
|
position: sticky;
|
|
15
|
-
top:
|
|
15
|
+
top: calc(-1 * var(--gap));
|
|
16
16
|
display: flex;
|
|
17
17
|
align-items: center;
|
|
18
18
|
gap: var(--gap);
|
|
19
|
+
transition: all linear .150s;
|
|
20
|
+
background: #ffffff;
|
|
21
|
+
z-index: 2;
|
|
22
|
+
padding: var(--gap) 0;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
.lkt-item-crud-buttons > :last-child {
|
package/package.json
CHANGED
|
@@ -25,7 +25,7 @@ const props = defineProps({
|
|
|
25
25
|
updateData: {type: Object, required: false, default: () => ({})},
|
|
26
26
|
dropData: {type: Object, required: false, default: () => ({})},
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
isCreate: {type: Boolean, default: false},
|
|
29
29
|
createConfirm: {type: String, default: ''},
|
|
30
30
|
updateConfirm: {type: String, default: ''},
|
|
31
31
|
dropConfirm: {type: String, default: ''},
|
|
@@ -33,6 +33,8 @@ const props = defineProps({
|
|
|
33
33
|
createDisabled: {type: Boolean, default: false},
|
|
34
34
|
updateDisabled: {type: Boolean, default: false},
|
|
35
35
|
dropDisabled: {type: Boolean, default: false},
|
|
36
|
+
|
|
37
|
+
saveValidator: {type: Function, required: false, default: () => true},
|
|
36
38
|
});
|
|
37
39
|
|
|
38
40
|
const slots = useSlots();
|
|
@@ -49,27 +51,27 @@ const isLoading = ref(true),
|
|
|
49
51
|
showStoreMessage = ref(false),
|
|
50
52
|
httpStatus = ref(200),
|
|
51
53
|
saveButton = ref(null),
|
|
52
|
-
dropButton = ref(null)
|
|
53
|
-
|
|
54
|
-
const dataState = ref(new DataState(JSON.parse(JSON.stringify(item.value))));
|
|
54
|
+
dropButton = ref(null),
|
|
55
|
+
dataState = ref(new DataState(item.value));
|
|
55
56
|
|
|
56
57
|
const saveConfirm = computed(() => {
|
|
57
|
-
return props.
|
|
58
|
+
return props.isCreate
|
|
58
59
|
? props.createConfirm
|
|
59
60
|
: props.updateConfirm;
|
|
60
61
|
}),
|
|
61
62
|
saveResource = computed(() => {
|
|
62
|
-
return props.
|
|
63
|
+
return props.isCreate
|
|
63
64
|
? props.createResource
|
|
64
65
|
: props.updateResource;
|
|
65
66
|
}),
|
|
66
67
|
saveData = computed(() => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
if (props.isCreate) {
|
|
69
|
+
return {...props.createData, ...JSON.parse(JSON.stringify(item.value))};
|
|
70
|
+
}
|
|
71
|
+
return {...props.updateData, ...JSON.parse(JSON.stringify(item.value))};
|
|
70
72
|
}),
|
|
71
73
|
saveDisabled = computed(() => {
|
|
72
|
-
return props.
|
|
74
|
+
return props.isCreate
|
|
73
75
|
? props.createDisabled
|
|
74
76
|
: props.updateDisabled;
|
|
75
77
|
})
|
|
@@ -77,8 +79,11 @@ const saveConfirm = computed(() => {
|
|
|
77
79
|
const fetchItem = async () => {
|
|
78
80
|
isLoading.value = true;
|
|
79
81
|
httpStatus.value = -1;
|
|
80
|
-
|
|
82
|
+
showStoreMessage.value = false;
|
|
83
|
+
try {
|
|
84
|
+
const r = await httpCall(props.readResource, props.readData);
|
|
81
85
|
isLoading.value = false;
|
|
86
|
+
httpStatus.value = r.httpStatus;
|
|
82
87
|
if (!r.success) {
|
|
83
88
|
httpSuccessRead.value = false;
|
|
84
89
|
httpStatus.value = r.httpStatus;
|
|
@@ -88,9 +93,15 @@ const fetchItem = async () => {
|
|
|
88
93
|
httpSuccessRead.value = true;
|
|
89
94
|
item.value = r.data;
|
|
90
95
|
perms.value = r.perms;
|
|
91
|
-
dataState.value
|
|
96
|
+
dataState.value.increment(item.value).turnStoredIntoOriginal();
|
|
92
97
|
emit('read', r);
|
|
93
|
-
})
|
|
98
|
+
} catch (e) {
|
|
99
|
+
isLoading.value = false;
|
|
100
|
+
httpSuccessRead.value = false;
|
|
101
|
+
httpStatus.value = 404;
|
|
102
|
+
emit('error', 404);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
94
105
|
}
|
|
95
106
|
|
|
96
107
|
const displayHeader = computed(() => {
|
|
@@ -101,23 +112,32 @@ const displayHeader = computed(() => {
|
|
|
101
112
|
|
|
102
113
|
watch(() => props.modelValue, v => {
|
|
103
114
|
item.value = v;
|
|
104
|
-
dataState.value.increment(
|
|
115
|
+
dataState.value.increment(v);
|
|
105
116
|
}, {deep: true});
|
|
117
|
+
|
|
106
118
|
watch(item, (v) => {
|
|
107
119
|
emit('update:modelValue', item.value);
|
|
108
|
-
dataState.value.increment(
|
|
120
|
+
dataState.value.increment(v);
|
|
109
121
|
}, {deep: true});
|
|
122
|
+
|
|
110
123
|
watch(perms, () => emit('perms', perms.value));
|
|
111
124
|
|
|
112
125
|
const ableToSave = computed(() => {
|
|
113
126
|
if (saveDisabled.value) return false;
|
|
114
127
|
|
|
128
|
+
if (typeof props.saveValidator === 'function' && !props.saveValidator(item.value)) return false;
|
|
129
|
+
|
|
115
130
|
return dataState.value.changed();
|
|
116
|
-
})
|
|
131
|
+
});
|
|
117
132
|
watch(ableToSave, (v) => emit('modified-data', v));
|
|
118
133
|
|
|
119
134
|
// Fetch item
|
|
120
|
-
if (props.readResource) fetchItem();
|
|
135
|
+
if (props.readResource && !props.isCreate) fetchItem();
|
|
136
|
+
else if (props.isCreate) {
|
|
137
|
+
httpSuccessRead.value = true;
|
|
138
|
+
editMode.value = true;
|
|
139
|
+
isLoading.value = false;
|
|
140
|
+
}
|
|
121
141
|
|
|
122
142
|
const onDrop = ($event: PointerEvent, r: HTTPResponse) => {
|
|
123
143
|
isLoading.value = false;
|
|
@@ -140,7 +160,15 @@ const onDrop = ($event: PointerEvent, r: HTTPResponse) => {
|
|
|
140
160
|
return;
|
|
141
161
|
}
|
|
142
162
|
showStoreMessage.value = true;
|
|
143
|
-
let emits: 'create' | 'update' = props.
|
|
163
|
+
let emits: 'create' | 'update' = props.isCreate ? 'create' : 'update';
|
|
164
|
+
if (!props.isCreate) {
|
|
165
|
+
dataState.value.turnStoredIntoOriginal();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (r.autoReloadId) {
|
|
169
|
+
props.readData['id'] = r.autoReloadId;
|
|
170
|
+
fetchItem();
|
|
171
|
+
}
|
|
144
172
|
emit(emits, r)
|
|
145
173
|
|
|
146
174
|
},
|
|
@@ -179,6 +207,7 @@ defineExpose({
|
|
|
179
207
|
<lkt-button
|
|
180
208
|
:ref="(el:any) => dropButton = el"
|
|
181
209
|
v-show="!isLoading && editMode && httpSuccessRead"
|
|
210
|
+
v-if="!isCreate"
|
|
182
211
|
palette="danger"
|
|
183
212
|
v-bind:disabled="dropDisabled"
|
|
184
213
|
v-bind:confirm-modal="dropConfirm"
|
|
@@ -209,7 +238,8 @@ defineExpose({
|
|
|
209
238
|
</lkt-button>
|
|
210
239
|
|
|
211
240
|
<lkt-field-switch
|
|
212
|
-
v-show="!isLoading && httpSuccessRead" v-model="editMode"
|
|
241
|
+
v-show="!isLoading && httpSuccessRead && !isCreate" v-model="editMode"
|
|
242
|
+
:label="editModeText"></lkt-field-switch>
|
|
213
243
|
</div>
|
|
214
244
|
<div class="lkt-item-crud_content" v-if="!isLoading">
|
|
215
245
|
<div v-if="httpSuccessRead" class="lkt-grid-1">
|