lkt-item-crud 1.0.3 → 1.0.4
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 +87 -79
- 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 +6 -2
- package/package.json +2 -1
- package/src/index.ts +1 -0
- package/src/lib-components/LktItemCrud.vue +22 -5
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 Y, useSlots as Z, ref as r, computed as p, watch as b, resolveComponent as g, openBlock as d, createElementBlock as m, createElementVNode as I, toDisplayString as N, renderSlot as C, createCommentVNode as D, withDirectives as _, createVNode as V, withCtx as x, unref as j, vShow as O, createBlock as q } from "vue";
|
|
2
|
+
import { httpCall as ee } from "lkt-http-client";
|
|
3
|
+
import { DataState as E } 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" }, oe = { class: "lkt-item-crud-buttons" }, re = { key: 1 }, se = { key: 1 }, de = {
|
|
7
8
|
key: 1,
|
|
8
9
|
class: "lkt-item-crud_content"
|
|
9
|
-
},
|
|
10
|
+
}, ne = {
|
|
10
11
|
key: 0,
|
|
11
12
|
class: "lkt-grid-1"
|
|
12
|
-
},
|
|
13
|
-
...
|
|
13
|
+
}, ie = { name: "LktItemCrud", inheritAttrs: !1 }, ce = /* @__PURE__ */ Y({
|
|
14
|
+
...ie,
|
|
14
15
|
props: {
|
|
15
16
|
modelValue: { type: Object, required: !1, default: () => ({}) },
|
|
16
17
|
title: { type: String, default: "" },
|
|
@@ -33,141 +34,148 @@ const Y = { class: "lkt-item-crud" }, Z = {
|
|
|
33
34
|
updateDisabled: { type: Boolean, default: !1 },
|
|
34
35
|
dropDisabled: { type: Boolean, default: !1 }
|
|
35
36
|
},
|
|
36
|
-
emits: ["update:modelValue", "read", "create", "update", "drop", "perms", "error"],
|
|
37
|
-
setup(
|
|
38
|
-
const
|
|
39
|
-
let
|
|
40
|
-
const a =
|
|
41
|
-
if (a.value = !1, !
|
|
42
|
-
c.value = !1, n.value =
|
|
37
|
+
emits: ["update:modelValue", "read", "create", "update", "drop", "perms", "error", "modified-data"],
|
|
38
|
+
setup(u, { expose: w, emit: A }) {
|
|
39
|
+
const t = u, R = Z(), s = A;
|
|
40
|
+
let H = [];
|
|
41
|
+
const a = r(!0), o = r(t.modelValue), B = r(H), i = r(!1), c = r(!1), v = r(!1), n = r(200), k = r(null), y = r(null), S = r(new E(JSON.parse(JSON.stringify(o.value)))), P = p(() => t.saveIsCreate ? t.createConfirm : t.updateConfirm), U = p(() => t.saveIsCreate ? t.createResource : t.updateResource), z = p(() => t.saveIsCreate ? t.createData : t.updateData), F = p(() => t.saveIsCreate ? t.createDisabled : t.updateDisabled), L = async () => (a.value = !0, n.value = -1, await ee(t.readResource, t.readData).then((e) => {
|
|
42
|
+
if (a.value = !1, !e.success) {
|
|
43
|
+
c.value = !1, n.value = e.httpStatus, s("error", e.httpStatus);
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
45
|
-
c.value = !0,
|
|
46
|
-
})),
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
c.value = !0, o.value = e.data, B.value = e.perms, S.value = new E(JSON.parse(JSON.stringify(o.value))), s("read", e);
|
|
47
|
+
})), G = p(() => a.value ? !1 : t.title || !!R["post-title"]);
|
|
48
|
+
b(() => t.modelValue, (e) => {
|
|
49
|
+
o.value = e, S.value.increment(JSON.parse(JSON.stringify(e)));
|
|
50
|
+
}, { deep: !0 }), b(o, (e) => {
|
|
51
|
+
s("update:modelValue", o.value), S.value.increment(JSON.parse(JSON.stringify(e)));
|
|
52
|
+
}, { deep: !0 }), b(B, () => s("perms", B.value));
|
|
53
|
+
const J = p(() => F.value ? !1 : S.value.changed());
|
|
54
|
+
b(J, (e) => s("modified-data", e)), t.readResource && L();
|
|
55
|
+
const K = (e, l) => {
|
|
49
56
|
if (a.value = !1, n.value = l.httpStatus, !l.success) {
|
|
50
57
|
v.value = !0, s("error", l.httpStatus);
|
|
51
58
|
return;
|
|
52
59
|
}
|
|
53
60
|
v.value = !0, s("drop", l);
|
|
54
|
-
},
|
|
61
|
+
}, Q = (e, l) => {
|
|
55
62
|
if (a.value = !1, n.value = l.httpStatus, !l.success) {
|
|
56
63
|
v.value = !0, s("error", l.httpStatus);
|
|
57
64
|
return;
|
|
58
65
|
}
|
|
59
66
|
v.value = !0;
|
|
60
|
-
let h =
|
|
67
|
+
let h = t.saveIsCreate ? "create" : "update";
|
|
61
68
|
s(h, l);
|
|
62
|
-
},
|
|
69
|
+
}, M = () => {
|
|
63
70
|
a.value = !0, n.value = -1;
|
|
64
|
-
},
|
|
71
|
+
}, T = () => {
|
|
65
72
|
a.value = !1;
|
|
66
73
|
};
|
|
67
74
|
return w({
|
|
68
75
|
doDrop: () => {
|
|
69
76
|
y.value && typeof y.value.click == "function" && y.value.click();
|
|
70
77
|
},
|
|
71
|
-
doRefresh:
|
|
78
|
+
doRefresh: L,
|
|
72
79
|
doSave: () => {
|
|
73
80
|
k.value && typeof k.value.click == "function" && k.value.click();
|
|
74
81
|
}
|
|
75
|
-
}), (
|
|
76
|
-
const h =
|
|
77
|
-
return
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
item:
|
|
82
|
+
}), (e, l) => {
|
|
83
|
+
const h = g("lkt-button"), W = g("lkt-field-switch"), $ = g("lkt-http-info"), X = g("lkt-loader");
|
|
84
|
+
return d(), m("article", te, [
|
|
85
|
+
G.value ? (d(), m("header", ae, [
|
|
86
|
+
I("h1", le, N(u.title), 1),
|
|
87
|
+
I("div", ue, [
|
|
88
|
+
C(e.$slots, "post-title", {
|
|
89
|
+
item: o.value,
|
|
83
90
|
loading: a.value
|
|
84
91
|
})
|
|
85
92
|
])
|
|
86
|
-
])) :
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
ref: (
|
|
93
|
+
])) : D("", !0),
|
|
94
|
+
_(I("div", oe, [
|
|
95
|
+
_(V(h, {
|
|
96
|
+
ref: (f) => y.value = f,
|
|
90
97
|
palette: "danger",
|
|
91
|
-
disabled:
|
|
92
|
-
"confirm-modal":
|
|
93
|
-
resource:
|
|
94
|
-
"resource-data":
|
|
95
|
-
onLoading:
|
|
96
|
-
onLoaded:
|
|
97
|
-
onClick:
|
|
98
|
+
disabled: u.dropDisabled,
|
|
99
|
+
"confirm-modal": u.dropConfirm,
|
|
100
|
+
resource: u.dropResource,
|
|
101
|
+
"resource-data": u.dropData,
|
|
102
|
+
onLoading: M,
|
|
103
|
+
onLoaded: T,
|
|
104
|
+
onClick: K
|
|
98
105
|
}, {
|
|
99
|
-
default:
|
|
100
|
-
|
|
106
|
+
default: x(() => [
|
|
107
|
+
j(R)["button-drop"] ? C(e.$slots, "button-drop", {
|
|
101
108
|
key: 0,
|
|
102
|
-
item:
|
|
109
|
+
item: o.value,
|
|
103
110
|
editMode: i.value
|
|
104
|
-
}) : (
|
|
111
|
+
}) : (d(), m("span", re, N(u.dropText), 1))
|
|
105
112
|
]),
|
|
106
113
|
_: 3
|
|
107
114
|
}, 8, ["disabled", "confirm-modal", "resource", "resource-data"]), [
|
|
108
|
-
[
|
|
115
|
+
[O, !a.value && i.value && c.value]
|
|
109
116
|
]),
|
|
110
|
-
|
|
111
|
-
ref: (
|
|
117
|
+
_(V(h, {
|
|
118
|
+
ref: (f) => k.value = f,
|
|
112
119
|
palette: "success",
|
|
113
|
-
disabled:
|
|
114
|
-
"confirm-modal":
|
|
115
|
-
resource:
|
|
116
|
-
"resource-data":
|
|
117
|
-
onLoading:
|
|
118
|
-
onLoaded:
|
|
119
|
-
onClick:
|
|
120
|
+
disabled: !J.value,
|
|
121
|
+
"confirm-modal": P.value,
|
|
122
|
+
resource: U.value,
|
|
123
|
+
"resource-data": z.value,
|
|
124
|
+
onLoading: M,
|
|
125
|
+
onLoaded: T,
|
|
126
|
+
onClick: Q
|
|
120
127
|
}, {
|
|
121
|
-
default:
|
|
122
|
-
|
|
128
|
+
default: x(() => [
|
|
129
|
+
j(R)["button-save"] ? C(e.$slots, "button-save", {
|
|
123
130
|
key: 0,
|
|
124
|
-
item:
|
|
131
|
+
item: o.value,
|
|
125
132
|
editMode: i.value
|
|
126
|
-
}) : (
|
|
133
|
+
}) : (d(), m("span", se, N(u.saveText), 1))
|
|
127
134
|
]),
|
|
128
135
|
_: 3
|
|
129
136
|
}, 8, ["disabled", "confirm-modal", "resource", "resource-data"]), [
|
|
130
|
-
[
|
|
137
|
+
[O, !a.value && i.value && c.value]
|
|
131
138
|
]),
|
|
132
|
-
|
|
139
|
+
_(V(W, {
|
|
133
140
|
modelValue: i.value,
|
|
134
|
-
"onUpdate:modelValue": l[0] || (l[0] = (
|
|
135
|
-
label:
|
|
141
|
+
"onUpdate:modelValue": l[0] || (l[0] = (f) => i.value = f),
|
|
142
|
+
label: u.editModeText
|
|
136
143
|
}, null, 8, ["modelValue", "label"]), [
|
|
137
|
-
[
|
|
144
|
+
[O, !a.value && c.value]
|
|
138
145
|
])
|
|
139
146
|
], 512), [
|
|
140
|
-
[
|
|
147
|
+
[O, c.value]
|
|
141
148
|
]),
|
|
142
|
-
a.value ?
|
|
143
|
-
c.value ? (
|
|
144
|
-
v.value ? (
|
|
149
|
+
a.value ? D("", !0) : (d(), m("div", de, [
|
|
150
|
+
c.value ? (d(), m("div", ne, [
|
|
151
|
+
v.value ? (d(), q($, {
|
|
145
152
|
key: 0,
|
|
146
153
|
code: n.value,
|
|
147
154
|
quick: "",
|
|
148
155
|
palette: n.value === 200 ? "success" : "danger",
|
|
149
156
|
"can-close": "",
|
|
150
|
-
onClose: l[1] || (l[1] = (
|
|
151
|
-
}, null, 8, ["code", "palette"])) :
|
|
152
|
-
|
|
153
|
-
item:
|
|
157
|
+
onClose: l[1] || (l[1] = (f) => v.value = !1)
|
|
158
|
+
}, null, 8, ["code", "palette"])) : D("", !0),
|
|
159
|
+
C(e.$slots, "item", {
|
|
160
|
+
item: o.value,
|
|
154
161
|
loading: a.value,
|
|
155
162
|
editMode: i.value
|
|
156
163
|
})
|
|
157
|
-
])) : (
|
|
164
|
+
])) : (d(), q($, {
|
|
158
165
|
key: 1,
|
|
159
166
|
code: n.value
|
|
160
167
|
}, null, 8, ["code"]))
|
|
161
168
|
])),
|
|
162
|
-
a.value ? (
|
|
169
|
+
a.value ? (d(), q(X, { key: 2 })) : D("", !0)
|
|
163
170
|
]);
|
|
164
171
|
};
|
|
165
172
|
}
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
|
|
173
|
+
});
|
|
174
|
+
const ye = {
|
|
175
|
+
install: (u, w = {}) => {
|
|
176
|
+
u.component("LktItemCrud", ce);
|
|
169
177
|
}
|
|
170
178
|
};
|
|
171
179
|
export {
|
|
172
|
-
|
|
180
|
+
ye as default
|
|
173
181
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,f){typeof exports=="object"&&typeof module<"u"?module.exports=f(require("vue"),require("lkt-http-client")):typeof define=="function"&&define.amd?define(["vue","lkt-http-client"],f):(e=typeof globalThis<"u"?globalThis:e||self,e.LktItemCrud=f(e.Vue,e.LktHttpClient))})(this,function(e,f){"use strict";const
|
|
1
|
+
(function(e,f){typeof exports=="object"&&typeof module<"u"?module.exports=f(require("vue"),require("lkt-http-client"),require("lkt-data-state")):typeof define=="function"&&define.amd?define(["vue","lkt-http-client","lkt-data-state"],f):(e=typeof globalThis<"u"?globalThis:e||self,e.LktItemCrud=f(e.Vue,e.LktHttpClient,e.lktDataState))})(this,function(e,f,C){"use strict";const V={class:"lkt-item-crud"},N={key:0,class:"lkt-item-crud_header"},q={class:"lkt-item-crud_header-title"},I={class:"lkt-item-crud_header-slot"},L={class:"lkt-item-crud-buttons"},O={key:1},R={key:1},E={key:1,class:"lkt-item-crud_content"},T={key:0,class:"lkt-grid-1"},x={name:"LktItemCrud",inheritAttrs:!1},J=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:()=>({})},saveIsCreate:{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}},emits:["update:modelValue","read","create","update","drop","perms","error","modified-data"],setup(r,{expose:D,emit:M}){const a=r,y=e.useSlots(),d=M;let $=[];const l=e.ref(!0),s=e.ref(a.modelValue),v=e.ref($),i=e.ref(!1),c=e.ref(!1),u=e.ref(!1),n=e.ref(200),m=e.ref(null),k=e.ref(null),h=e.ref(new C.DataState(JSON.parse(JSON.stringify(s.value)))),j=e.computed(()=>a.saveIsCreate?a.createConfirm:a.updateConfirm),H=e.computed(()=>a.saveIsCreate?a.createResource:a.updateResource),A=e.computed(()=>a.saveIsCreate?a.createData:a.updateData),P=e.computed(()=>a.saveIsCreate?a.createDisabled:a.updateDisabled),g=async()=>(l.value=!0,n.value=-1,await f.httpCall(a.readResource,a.readData).then(t=>{if(l.value=!1,!t.success){c.value=!1,n.value=t.httpStatus,d("error",t.httpStatus);return}c.value=!0,s.value=t.data,v.value=t.perms,h.value=new C.DataState(JSON.parse(JSON.stringify(s.value))),d("read",t)})),U=e.computed(()=>l.value?!1:a.title||!!y["post-title"]);e.watch(()=>a.modelValue,t=>{s.value=t,h.value.increment(JSON.parse(JSON.stringify(t)))},{deep:!0}),e.watch(s,t=>{d("update:modelValue",s.value),h.value.increment(JSON.parse(JSON.stringify(t)))},{deep:!0}),e.watch(v,()=>d("perms",v.value));const B=e.computed(()=>P.value?!1:h.value.changed());e.watch(B,t=>d("modified-data",t)),a.readResource&&g();const z=(t,o)=>{if(l.value=!1,n.value=o.httpStatus,!o.success){u.value=!0,d("error",o.httpStatus);return}u.value=!0,d("drop",o)},F=(t,o)=>{if(l.value=!1,n.value=o.httpStatus,!o.success){u.value=!0,d("error",o.httpStatus);return}u.value=!0;let S=a.saveIsCreate?"create":"update";d(S,o)},b=()=>{l.value=!0,n.value=-1},_=()=>{l.value=!1};return D({doDrop:()=>{k.value&&typeof k.value.click=="function"&&k.value.click()},doRefresh:g,doSave:()=>{m.value&&typeof m.value.click=="function"&&m.value.click()}}),(t,o)=>{const S=e.resolveComponent("lkt-button"),G=e.resolveComponent("lkt-field-switch"),w=e.resolveComponent("lkt-http-info"),K=e.resolveComponent("lkt-loader");return e.openBlock(),e.createElementBlock("article",V,[U.value?(e.openBlock(),e.createElementBlock("header",N,[e.createElementVNode("h1",q,e.toDisplayString(r.title),1),e.createElementVNode("div",I,[e.renderSlot(t.$slots,"post-title",{item:s.value,loading:l.value})])])):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("div",L,[e.withDirectives(e.createVNode(S,{ref:p=>k.value=p,palette:"danger",disabled:r.dropDisabled,"confirm-modal":r.dropConfirm,resource:r.dropResource,"resource-data":r.dropData,onLoading:b,onLoaded:_,onClick:z},{default:e.withCtx(()=>[e.unref(y)["button-drop"]?e.renderSlot(t.$slots,"button-drop",{key:0,item:s.value,editMode:i.value}):(e.openBlock(),e.createElementBlock("span",O,e.toDisplayString(r.dropText),1))]),_:3},8,["disabled","confirm-modal","resource","resource-data"]),[[e.vShow,!l.value&&i.value&&c.value]]),e.withDirectives(e.createVNode(S,{ref:p=>m.value=p,palette:"success",disabled:!B.value,"confirm-modal":j.value,resource:H.value,"resource-data":A.value,onLoading:b,onLoaded:_,onClick:F},{default:e.withCtx(()=>[e.unref(y)["button-save"]?e.renderSlot(t.$slots,"button-save",{key:0,item:s.value,editMode:i.value}):(e.openBlock(),e.createElementBlock("span",R,e.toDisplayString(r.saveText),1))]),_:3},8,["disabled","confirm-modal","resource","resource-data"]),[[e.vShow,!l.value&&i.value&&c.value]]),e.withDirectives(e.createVNode(G,{modelValue:i.value,"onUpdate:modelValue":o[0]||(o[0]=p=>i.value=p),label:r.editModeText},null,8,["modelValue","label"]),[[e.vShow,!l.value&&c.value]])],512),[[e.vShow,c.value]]),l.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",E,[c.value?(e.openBlock(),e.createElementBlock("div",T,[u.value?(e.openBlock(),e.createBlock(w,{key:0,code:n.value,quick:"",palette:n.value===200?"success":"danger","can-close":"",onClose:o[1]||(o[1]=p=>u.value=!1)},null,8,["code","palette"])):e.createCommentVNode("",!0),e.renderSlot(t.$slots,"item",{item:s.value,loading:l.value,editMode:i.value})])):(e.openBlock(),e.createBlock(w,{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",J)}}});
|
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:0;display:flex;align-items:center;gap:var(--gap)}.lkt-item-crud-buttons>:last-child{margin-left:auto}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -93,11 +93,12 @@ declare const _default: {
|
|
|
93
93
|
onRead?: ((...args: any[]) => any) | undefined;
|
|
94
94
|
onCreate?: ((...args: any[]) => any) | undefined;
|
|
95
95
|
onPerms?: ((...args: any[]) => any) | undefined;
|
|
96
|
+
"onModified-data"?: ((...args: any[]) => any) | undefined;
|
|
96
97
|
}, {
|
|
97
98
|
doDrop: () => void;
|
|
98
99
|
doRefresh: () => Promise<void>;
|
|
99
100
|
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<{
|
|
101
|
+
}, 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
102
|
modelValue: {
|
|
102
103
|
type: ObjectConstructor;
|
|
103
104
|
required: false;
|
|
@@ -191,6 +192,7 @@ declare const _default: {
|
|
|
191
192
|
onRead?: ((...args: any[]) => any) | undefined;
|
|
192
193
|
onCreate?: ((...args: any[]) => any) | undefined;
|
|
193
194
|
onPerms?: ((...args: any[]) => any) | undefined;
|
|
195
|
+
"onModified-data"?: ((...args: any[]) => any) | undefined;
|
|
194
196
|
}, {
|
|
195
197
|
title: string;
|
|
196
198
|
modelValue: Record<string, any>;
|
|
@@ -309,6 +311,7 @@ declare const _default: {
|
|
|
309
311
|
onRead?: ((...args: any[]) => any) | undefined;
|
|
310
312
|
onCreate?: ((...args: any[]) => any) | undefined;
|
|
311
313
|
onPerms?: ((...args: any[]) => any) | undefined;
|
|
314
|
+
"onModified-data"?: ((...args: any[]) => any) | undefined;
|
|
312
315
|
}, {
|
|
313
316
|
doDrop: () => void;
|
|
314
317
|
doRefresh: () => Promise<void>;
|
|
@@ -428,11 +431,12 @@ declare const _default: {
|
|
|
428
431
|
onRead?: ((...args: any[]) => any) | undefined;
|
|
429
432
|
onCreate?: ((...args: any[]) => any) | undefined;
|
|
430
433
|
onPerms?: ((...args: any[]) => any) | undefined;
|
|
434
|
+
"onModified-data"?: ((...args: any[]) => any) | undefined;
|
|
431
435
|
}, {
|
|
432
436
|
doDrop: () => void;
|
|
433
437
|
doRefresh: () => Promise<void>;
|
|
434
438
|
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", {
|
|
439
|
+
}, 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
440
|
title: string;
|
|
437
441
|
modelValue: Record<string, any>;
|
|
438
442
|
editModeText: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lkt-item-crud",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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: () => ({})},
|
|
@@ -36,7 +37,7 @@ const props = defineProps({
|
|
|
36
37
|
|
|
37
38
|
const slots = useSlots();
|
|
38
39
|
|
|
39
|
-
const emit = defineEmits(['update:modelValue', 'read', 'create', 'update', 'drop', 'perms', 'error']);
|
|
40
|
+
const emit = defineEmits(['update:modelValue', 'read', 'create', 'update', 'drop', 'perms', 'error', 'modified-data']);
|
|
40
41
|
|
|
41
42
|
let basePerms: string[] = [];
|
|
42
43
|
|
|
@@ -50,6 +51,7 @@ const isLoading = ref(true),
|
|
|
50
51
|
saveButton = ref(null),
|
|
51
52
|
dropButton = ref(null);
|
|
52
53
|
|
|
54
|
+
const dataState = ref(new DataState(JSON.parse(JSON.stringify(item.value))));
|
|
53
55
|
|
|
54
56
|
const saveConfirm = computed(() => {
|
|
55
57
|
return props.saveIsCreate
|
|
@@ -86,6 +88,7 @@ const fetchItem = async () => {
|
|
|
86
88
|
httpSuccessRead.value = true;
|
|
87
89
|
item.value = r.data;
|
|
88
90
|
perms.value = r.perms;
|
|
91
|
+
dataState.value = new DataState(JSON.parse(JSON.stringify(item.value)));
|
|
89
92
|
emit('read', r);
|
|
90
93
|
});
|
|
91
94
|
}
|
|
@@ -96,10 +99,23 @@ const displayHeader = computed(() => {
|
|
|
96
99
|
return props.title || !!slots['post-title'];
|
|
97
100
|
})
|
|
98
101
|
|
|
99
|
-
watch(() => props.modelValue, v =>
|
|
100
|
-
|
|
102
|
+
watch(() => props.modelValue, v => {
|
|
103
|
+
item.value = v;
|
|
104
|
+
dataState.value.increment(JSON.parse(JSON.stringify(v)));
|
|
105
|
+
}, {deep: true});
|
|
106
|
+
watch(item, (v) => {
|
|
107
|
+
emit('update:modelValue', item.value);
|
|
108
|
+
dataState.value.increment(JSON.parse(JSON.stringify(v)));
|
|
109
|
+
}, {deep: true});
|
|
101
110
|
watch(perms, () => emit('perms', perms.value));
|
|
102
111
|
|
|
112
|
+
const ableToSave = computed(() => {
|
|
113
|
+
if (saveDisabled.value) return false;
|
|
114
|
+
|
|
115
|
+
return dataState.value.changed();
|
|
116
|
+
})
|
|
117
|
+
watch(ableToSave, (v) => emit('modified-data', v));
|
|
118
|
+
|
|
103
119
|
// Fetch item
|
|
104
120
|
if (props.readResource) fetchItem();
|
|
105
121
|
|
|
@@ -180,7 +196,7 @@ defineExpose({
|
|
|
180
196
|
:ref="(el:any) => saveButton = el"
|
|
181
197
|
v-show="!isLoading && editMode && httpSuccessRead"
|
|
182
198
|
palette="success"
|
|
183
|
-
v-bind:disabled="
|
|
199
|
+
v-bind:disabled="!ableToSave"
|
|
184
200
|
v-bind:confirm-modal="saveConfirm"
|
|
185
201
|
v-bind:resource="saveResource"
|
|
186
202
|
v-bind:resource-data="saveData"
|
|
@@ -198,7 +214,8 @@ defineExpose({
|
|
|
198
214
|
<div class="lkt-item-crud_content" v-if="!isLoading">
|
|
199
215
|
<div v-if="httpSuccessRead" class="lkt-grid-1">
|
|
200
216
|
<lkt-http-info :code="httpStatus" v-if="showStoreMessage" quick
|
|
201
|
-
:palette="httpStatus === 200 ? 'success' : 'danger'" can-close
|
|
217
|
+
:palette="httpStatus === 200 ? 'success' : 'danger'" can-close
|
|
218
|
+
v-on:close="showStoreMessage = false"></lkt-http-info>
|
|
202
219
|
<slot name="item" v-bind:item="item" v-bind:loading="isLoading" v-bind:edit-mode="editMode"></slot>
|
|
203
220
|
</div>
|
|
204
221
|
<lkt-http-info :code="httpStatus" v-else></lkt-http-info>
|