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