lkt-item-crud 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/jest.config.d.ts +2 -0
- package/dist/lkt-item-crud.es.js +71 -0
- package/dist/lkt-item-crud.umd.js +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/lib-components/LktItemCrud.vue.d.ts +206 -0
- package/dist/vite.config.d.ts +44 -0
- package/lkt-item-crud.css +11 -0
- package/package.json +73 -0
- package/src/index.ts +10 -0
- package/src/lib-components/LktItemCrud.vue +103 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 lekrat
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { defineComponent as q, useSlots as w, ref as p, computed as I, watch as m, resolveComponent as B, openBlock as c, createElementBlock as f, createElementVNode as h, toDisplayString as D, renderSlot as k, createCommentVNode as v, createBlock as L } from "vue";
|
|
2
|
+
import { httpCall as d } from "lkt-http-client";
|
|
3
|
+
const b = { class: "lkt-item-crud" }, j = {
|
|
4
|
+
key: 0,
|
|
5
|
+
class: "lkt-item-crud_header"
|
|
6
|
+
}, E = { class: "lkt-item-crud_header-title" }, N = { class: "lkt-item-crud_header-slot" }, O = {
|
|
7
|
+
key: 1,
|
|
8
|
+
class: "lkt-item-crud_content"
|
|
9
|
+
}, $ = { name: "LktItemCrud", inheritAttrs: !1 }, x = /* @__PURE__ */ q({
|
|
10
|
+
...$,
|
|
11
|
+
props: {
|
|
12
|
+
modelValue: { type: Object, required: !1, default: () => ({}) },
|
|
13
|
+
readResource: { type: String, required: !0 },
|
|
14
|
+
readData: { type: Object, required: !1, default: () => ({}) },
|
|
15
|
+
createResource: { type: String, required: !1 },
|
|
16
|
+
updateResource: { type: String, required: !1 },
|
|
17
|
+
dropResource: { type: String, required: !1 },
|
|
18
|
+
title: { type: String, default: "" }
|
|
19
|
+
},
|
|
20
|
+
emits: ["update:modelValue", "read", "create", "update", "drop", "perms"],
|
|
21
|
+
setup(u, { expose: _, emit: y }) {
|
|
22
|
+
const r = u, R = w(), s = y, t = p(!0), o = p(r.modelValue), n = p([]), i = async () => (t.value = !0, await d(r.readResource, r.readData).then((e) => {
|
|
23
|
+
t.value = !1, o.value = e.data, n.value = e.perms, s("read", e);
|
|
24
|
+
})), S = I(() => t.value ? !1 : r.title || !!R["post-title"]);
|
|
25
|
+
m(() => r.modelValue, (e) => o.value = e), m(o, () => s("update:modelValue", o.value)), m(n, () => s("perms", n.value));
|
|
26
|
+
const g = async (e) => {
|
|
27
|
+
const l = r.createResource;
|
|
28
|
+
return t.value = !0, await d(l, { ...e }).then((a) => {
|
|
29
|
+
t.value = !1, s("create", a);
|
|
30
|
+
});
|
|
31
|
+
}, C = async (e) => {
|
|
32
|
+
const l = r.updateResource;
|
|
33
|
+
return t.value = !0, await d(l, { ...e }).then((a) => {
|
|
34
|
+
t.value = !1, s("update", a);
|
|
35
|
+
});
|
|
36
|
+
}, V = async (e) => {
|
|
37
|
+
const l = r.dropResource;
|
|
38
|
+
return t.value = !0, await d(l, { ...e }).then((a) => {
|
|
39
|
+
t.value = !1, s("drop", a);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
return r.readResource && i(), _({
|
|
43
|
+
fetchItem: i,
|
|
44
|
+
create: g,
|
|
45
|
+
update: C,
|
|
46
|
+
drop: V,
|
|
47
|
+
refresh: i
|
|
48
|
+
}), (e, l) => {
|
|
49
|
+
const a = B("lkt-loader");
|
|
50
|
+
return c(), f("article", b, [
|
|
51
|
+
S.value ? (c(), f("header", j, [
|
|
52
|
+
h("h1", E, D(u.title), 1),
|
|
53
|
+
h("div", N, [
|
|
54
|
+
k(e.$slots, "post-title", { item: o.value })
|
|
55
|
+
])
|
|
56
|
+
])) : v("", !0),
|
|
57
|
+
t.value ? v("", !0) : (c(), f("div", O, [
|
|
58
|
+
k(e.$slots, "item", { item: o.value })
|
|
59
|
+
])),
|
|
60
|
+
t.value ? (c(), L(a, { key: 2 })) : v("", !0)
|
|
61
|
+
]);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}), z = {
|
|
65
|
+
install: (u, _ = {}) => {
|
|
66
|
+
u.component("LktItemCrud", x);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
export {
|
|
70
|
+
z as default
|
|
71
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,o){typeof exports=="object"&&typeof module<"u"?module.exports=o(require("vue"),require("lkt-http-client")):typeof define=="function"&&define.amd?define(["vue","lkt-http-client"],o):(e=typeof globalThis<"u"?globalThis:e||self,e.LktItemCrud=o(e.Vue,e.LktHttpClient))})(this,function(e,o){"use strict";const m={class:"lkt-item-crud"},f={key:0,class:"lkt-item-crud_header"},h={class:"lkt-item-crud_header-title"},k={class:"lkt-item-crud_header-slot"},_={key:1,class:"lkt-item-crud_content"},y={name:"LktItemCrud",inheritAttrs:!1},C=e.defineComponent({...y,props:{modelValue:{type:Object,required:!1,default:()=>({})},readResource:{type:String,required:!0},readData:{type:Object,required:!1,default:()=>({})},createResource:{type:String,required:!1},updateResource:{type:String,required:!1},dropResource:{type:String,required:!1},title:{type:String,default:""}},emits:["update:modelValue","read","create","update","drop","perms"],setup(d,{expose:p,emit:V}){const a=d,R=e.useSlots(),l=V,r=e.ref(!0),n=e.ref(a.modelValue),u=e.ref([]),i=async()=>(r.value=!0,await o.httpCall(a.readResource,a.readData).then(t=>{r.value=!1,n.value=t.data,u.value=t.perms,l("read",t)})),S=e.computed(()=>r.value?!1:a.title||!!R["post-title"]);e.watch(()=>a.modelValue,t=>n.value=t),e.watch(n,()=>l("update:modelValue",n.value)),e.watch(u,()=>l("perms",u.value));const q=async t=>{const c=a.createResource;return r.value=!0,await o.httpCall(c,{...t}).then(s=>{r.value=!1,l("create",s)})},B=async t=>{const c=a.updateResource;return r.value=!0,await o.httpCall(c,{...t}).then(s=>{r.value=!1,l("update",s)})},w=async t=>{const c=a.dropResource;return r.value=!0,await o.httpCall(c,{...t}).then(s=>{r.value=!1,l("drop",s)})};return a.readResource&&i(),p({fetchItem:i,create:q,update:B,drop:w,refresh:i}),(t,c)=>{const s=e.resolveComponent("lkt-loader");return e.openBlock(),e.createElementBlock("article",m,[S.value?(e.openBlock(),e.createElementBlock("header",f,[e.createElementVNode("h1",h,e.toDisplayString(d.title),1),e.createElementVNode("div",k,[e.renderSlot(t.$slots,"post-title",{item:n.value})])])):e.createCommentVNode("",!0),r.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",_,[e.renderSlot(t.$slots,"item",{item:n.value})])),r.value?(e.openBlock(),e.createBlock(s,{key:2})):e.createCommentVNode("",!0)])}}});return{install:(d,p={})=>{d.component("LktItemCrud",C)}}});
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { LktObject } from "lkt-ts-interfaces";
|
|
2
|
+
declare const _default: {
|
|
3
|
+
new (...args: any[]): import("vue").CreateComponentPublicInstance<Readonly<import("vue").ExtractPropTypes<{
|
|
4
|
+
modelValue: {
|
|
5
|
+
type: ObjectConstructor;
|
|
6
|
+
required: false;
|
|
7
|
+
default: () => {};
|
|
8
|
+
};
|
|
9
|
+
readResource: {
|
|
10
|
+
type: StringConstructor;
|
|
11
|
+
required: true;
|
|
12
|
+
};
|
|
13
|
+
readData: {
|
|
14
|
+
type: ObjectConstructor;
|
|
15
|
+
required: false;
|
|
16
|
+
default: () => {};
|
|
17
|
+
};
|
|
18
|
+
createResource: {
|
|
19
|
+
type: StringConstructor;
|
|
20
|
+
required: false;
|
|
21
|
+
};
|
|
22
|
+
updateResource: {
|
|
23
|
+
type: StringConstructor;
|
|
24
|
+
required: false;
|
|
25
|
+
};
|
|
26
|
+
dropResource: {
|
|
27
|
+
type: StringConstructor;
|
|
28
|
+
required: false;
|
|
29
|
+
};
|
|
30
|
+
title: {
|
|
31
|
+
type: StringConstructor;
|
|
32
|
+
default: string;
|
|
33
|
+
};
|
|
34
|
+
}>> & {
|
|
35
|
+
onDrop?: ((...args: any[]) => any) | undefined;
|
|
36
|
+
onUpdate?: ((...args: any[]) => any) | undefined;
|
|
37
|
+
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
38
|
+
onRead?: ((...args: any[]) => any) | undefined;
|
|
39
|
+
onCreate?: ((...args: any[]) => any) | undefined;
|
|
40
|
+
onPerms?: ((...args: any[]) => any) | undefined;
|
|
41
|
+
}, {
|
|
42
|
+
fetchItem: () => Promise<void>;
|
|
43
|
+
create: (data: LktObject) => Promise<void>;
|
|
44
|
+
update: (data: LktObject) => Promise<void>;
|
|
45
|
+
drop: (data: LktObject) => Promise<void>;
|
|
46
|
+
refresh: () => Promise<void>;
|
|
47
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("drop" | "update" | "update:modelValue" | "read" | "create" | "perms")[], import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
|
|
48
|
+
modelValue: {
|
|
49
|
+
type: ObjectConstructor;
|
|
50
|
+
required: false;
|
|
51
|
+
default: () => {};
|
|
52
|
+
};
|
|
53
|
+
readResource: {
|
|
54
|
+
type: StringConstructor;
|
|
55
|
+
required: true;
|
|
56
|
+
};
|
|
57
|
+
readData: {
|
|
58
|
+
type: ObjectConstructor;
|
|
59
|
+
required: false;
|
|
60
|
+
default: () => {};
|
|
61
|
+
};
|
|
62
|
+
createResource: {
|
|
63
|
+
type: StringConstructor;
|
|
64
|
+
required: false;
|
|
65
|
+
};
|
|
66
|
+
updateResource: {
|
|
67
|
+
type: StringConstructor;
|
|
68
|
+
required: false;
|
|
69
|
+
};
|
|
70
|
+
dropResource: {
|
|
71
|
+
type: StringConstructor;
|
|
72
|
+
required: false;
|
|
73
|
+
};
|
|
74
|
+
title: {
|
|
75
|
+
type: StringConstructor;
|
|
76
|
+
default: string;
|
|
77
|
+
};
|
|
78
|
+
}>> & {
|
|
79
|
+
onDrop?: ((...args: any[]) => any) | undefined;
|
|
80
|
+
onUpdate?: ((...args: any[]) => any) | undefined;
|
|
81
|
+
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
82
|
+
onRead?: ((...args: any[]) => any) | undefined;
|
|
83
|
+
onCreate?: ((...args: any[]) => any) | undefined;
|
|
84
|
+
onPerms?: ((...args: any[]) => any) | undefined;
|
|
85
|
+
}, {
|
|
86
|
+
title: string;
|
|
87
|
+
modelValue: Record<string, any>;
|
|
88
|
+
readData: Record<string, any>;
|
|
89
|
+
}, true, {}, {}, {
|
|
90
|
+
P: {};
|
|
91
|
+
B: {};
|
|
92
|
+
D: {};
|
|
93
|
+
C: {};
|
|
94
|
+
M: {};
|
|
95
|
+
Defaults: {};
|
|
96
|
+
}, Readonly<import("vue").ExtractPropTypes<{
|
|
97
|
+
modelValue: {
|
|
98
|
+
type: ObjectConstructor;
|
|
99
|
+
required: false;
|
|
100
|
+
default: () => {};
|
|
101
|
+
};
|
|
102
|
+
readResource: {
|
|
103
|
+
type: StringConstructor;
|
|
104
|
+
required: true;
|
|
105
|
+
};
|
|
106
|
+
readData: {
|
|
107
|
+
type: ObjectConstructor;
|
|
108
|
+
required: false;
|
|
109
|
+
default: () => {};
|
|
110
|
+
};
|
|
111
|
+
createResource: {
|
|
112
|
+
type: StringConstructor;
|
|
113
|
+
required: false;
|
|
114
|
+
};
|
|
115
|
+
updateResource: {
|
|
116
|
+
type: StringConstructor;
|
|
117
|
+
required: false;
|
|
118
|
+
};
|
|
119
|
+
dropResource: {
|
|
120
|
+
type: StringConstructor;
|
|
121
|
+
required: false;
|
|
122
|
+
};
|
|
123
|
+
title: {
|
|
124
|
+
type: StringConstructor;
|
|
125
|
+
default: string;
|
|
126
|
+
};
|
|
127
|
+
}>> & {
|
|
128
|
+
onDrop?: ((...args: any[]) => any) | undefined;
|
|
129
|
+
onUpdate?: ((...args: any[]) => any) | undefined;
|
|
130
|
+
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
131
|
+
onRead?: ((...args: any[]) => any) | undefined;
|
|
132
|
+
onCreate?: ((...args: any[]) => any) | undefined;
|
|
133
|
+
onPerms?: ((...args: any[]) => any) | undefined;
|
|
134
|
+
}, {
|
|
135
|
+
fetchItem: () => Promise<void>;
|
|
136
|
+
create: (data: LktObject) => Promise<void>;
|
|
137
|
+
update: (data: LktObject) => Promise<void>;
|
|
138
|
+
drop: (data: LktObject) => Promise<void>;
|
|
139
|
+
refresh: () => Promise<void>;
|
|
140
|
+
}, {}, {}, {}, {
|
|
141
|
+
title: string;
|
|
142
|
+
modelValue: Record<string, any>;
|
|
143
|
+
readData: Record<string, any>;
|
|
144
|
+
}>;
|
|
145
|
+
__isFragment?: undefined;
|
|
146
|
+
__isTeleport?: undefined;
|
|
147
|
+
__isSuspense?: undefined;
|
|
148
|
+
} & import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
|
|
149
|
+
modelValue: {
|
|
150
|
+
type: ObjectConstructor;
|
|
151
|
+
required: false;
|
|
152
|
+
default: () => {};
|
|
153
|
+
};
|
|
154
|
+
readResource: {
|
|
155
|
+
type: StringConstructor;
|
|
156
|
+
required: true;
|
|
157
|
+
};
|
|
158
|
+
readData: {
|
|
159
|
+
type: ObjectConstructor;
|
|
160
|
+
required: false;
|
|
161
|
+
default: () => {};
|
|
162
|
+
};
|
|
163
|
+
createResource: {
|
|
164
|
+
type: StringConstructor;
|
|
165
|
+
required: false;
|
|
166
|
+
};
|
|
167
|
+
updateResource: {
|
|
168
|
+
type: StringConstructor;
|
|
169
|
+
required: false;
|
|
170
|
+
};
|
|
171
|
+
dropResource: {
|
|
172
|
+
type: StringConstructor;
|
|
173
|
+
required: false;
|
|
174
|
+
};
|
|
175
|
+
title: {
|
|
176
|
+
type: StringConstructor;
|
|
177
|
+
default: string;
|
|
178
|
+
};
|
|
179
|
+
}>> & {
|
|
180
|
+
onDrop?: ((...args: any[]) => any) | undefined;
|
|
181
|
+
onUpdate?: ((...args: any[]) => any) | undefined;
|
|
182
|
+
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
183
|
+
onRead?: ((...args: any[]) => any) | undefined;
|
|
184
|
+
onCreate?: ((...args: any[]) => any) | undefined;
|
|
185
|
+
onPerms?: ((...args: any[]) => any) | undefined;
|
|
186
|
+
}, {
|
|
187
|
+
fetchItem: () => Promise<void>;
|
|
188
|
+
create: (data: LktObject) => Promise<void>;
|
|
189
|
+
update: (data: LktObject) => Promise<void>;
|
|
190
|
+
drop: (data: LktObject) => Promise<void>;
|
|
191
|
+
refresh: () => Promise<void>;
|
|
192
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("drop" | "update" | "update:modelValue" | "read" | "create" | "perms")[], "drop" | "update" | "update:modelValue" | "read" | "create" | "perms", {
|
|
193
|
+
title: string;
|
|
194
|
+
modelValue: Record<string, any>;
|
|
195
|
+
readData: Record<string, any>;
|
|
196
|
+
}, {}, string, {}> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
|
|
197
|
+
$slots: {
|
|
198
|
+
'post-title': (_: {
|
|
199
|
+
item: Record<string, any>;
|
|
200
|
+
}) => any;
|
|
201
|
+
item: (_: {
|
|
202
|
+
item: Record<string, any>;
|
|
203
|
+
}) => any;
|
|
204
|
+
};
|
|
205
|
+
});
|
|
206
|
+
export default _default;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
const plugins: import("vite").Plugin[];
|
|
3
|
+
namespace resolve {
|
|
4
|
+
const alias: {
|
|
5
|
+
'@': string;
|
|
6
|
+
'@test': string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
namespace build {
|
|
10
|
+
export namespace lib {
|
|
11
|
+
const entry: string;
|
|
12
|
+
const name: string;
|
|
13
|
+
function fileName(format: any): string;
|
|
14
|
+
}
|
|
15
|
+
export { outDir };
|
|
16
|
+
export const minify: boolean;
|
|
17
|
+
export namespace rollupOptions {
|
|
18
|
+
const external: string[];
|
|
19
|
+
namespace output {
|
|
20
|
+
const globals: {
|
|
21
|
+
vue: string;
|
|
22
|
+
'@vuepic/vue-datepicker': string;
|
|
23
|
+
'vue-next-select': string;
|
|
24
|
+
suneditor: string;
|
|
25
|
+
katex: string;
|
|
26
|
+
'lkt-tools': string;
|
|
27
|
+
'lkt-http-client': string;
|
|
28
|
+
'lkt-string-tools': string;
|
|
29
|
+
'lkt-vue-tools': string;
|
|
30
|
+
'lkt-events': string;
|
|
31
|
+
};
|
|
32
|
+
const sourcemapExcludeSources: boolean;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
namespace test {
|
|
37
|
+
namespace coverage {
|
|
38
|
+
const reporter: string[];
|
|
39
|
+
}
|
|
40
|
+
function resolveSnapshotPath(testPath: any, snapExtension: any): string;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export default _default;
|
|
44
|
+
declare const outDir: string;
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lkt-item-crud",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"module": "src/index.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lkt-item-crud.css",
|
|
9
|
+
"dist/*",
|
|
10
|
+
"src/**/*.vue"
|
|
11
|
+
],
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./dist/lkt-item-crud.es.js",
|
|
16
|
+
"require": "./dist/lkt-item-crud.umd.js"
|
|
17
|
+
},
|
|
18
|
+
"./dist/style.css": "./dist/style.css"
|
|
19
|
+
},
|
|
20
|
+
"types": "./dist/types/index.d.ts",
|
|
21
|
+
"scripts": {
|
|
22
|
+
"serve": "vite",
|
|
23
|
+
"build": "vite build && vue-tsc --emitDeclarationOnly --project tsconfig.json && mv dist/src dist/types",
|
|
24
|
+
"build2": "vite build",
|
|
25
|
+
"preview": "vite preview",
|
|
26
|
+
"test": "jest",
|
|
27
|
+
"test-coverage": "vitest run --coverage"
|
|
28
|
+
},
|
|
29
|
+
"author": "Antonio Ibáñez",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@babel/core": "^7.13.13",
|
|
32
|
+
"@babel/preset-env": "^7.13.12",
|
|
33
|
+
"@babel/types": "^7.18.9",
|
|
34
|
+
"@testing-library/cypress": "^7.0.4",
|
|
35
|
+
"@testing-library/dom": "^7.30.1",
|
|
36
|
+
"@testing-library/jest-dom": "^5.11.10",
|
|
37
|
+
"@types/jest": "^29.0.1",
|
|
38
|
+
"@types/node": "^18.6.2",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
|
40
|
+
"@typescript-eslint/parser": "^5.36.2",
|
|
41
|
+
"@vitejs/plugin-vue": "^3.0.1",
|
|
42
|
+
"babel-eslint": "^10.1.0",
|
|
43
|
+
"babel-jest": "^29.0.3",
|
|
44
|
+
"babel-loader": "^8.2.2",
|
|
45
|
+
"cypress": "^6.8.0",
|
|
46
|
+
"eslint": "8.22.0",
|
|
47
|
+
"eslint-config-prettier": "^8.1.0",
|
|
48
|
+
"eslint-plugin-cypress": "^2.11.2",
|
|
49
|
+
"eslint-plugin-html": "^7.1.0",
|
|
50
|
+
"eslint-plugin-import": "^2.22.1",
|
|
51
|
+
"eslint-plugin-jest": "^24.3.2",
|
|
52
|
+
"eslint-plugin-prettier": "^3.3.1",
|
|
53
|
+
"eslint-plugin-simple-import-sort": "^7.0.0",
|
|
54
|
+
"jest": "^29.0.3",
|
|
55
|
+
"prettier": "^2.7.1",
|
|
56
|
+
"ts-jest": "^29.0.0",
|
|
57
|
+
"typescript": "^4.8.3",
|
|
58
|
+
"vite": "^3.1.2",
|
|
59
|
+
"vue-tsc": "^0.38.9"
|
|
60
|
+
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"lkt-events": "^1.0.2",
|
|
63
|
+
"lkt-http-client": "^1.0.12",
|
|
64
|
+
"lkt-loader": "^1.0.2",
|
|
65
|
+
"lkt-string-tools": "^1.0.2",
|
|
66
|
+
"lkt-ts-interfaces": "^1.0.2",
|
|
67
|
+
"path": "^0.12.7",
|
|
68
|
+
"vue": "^3.3.0"
|
|
69
|
+
},
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">=18"
|
|
72
|
+
}
|
|
73
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
export default {name: "LktItemCrud", inheritAttrs: false}
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
import {ref, watch, useSlots, computed} from "vue";
|
|
7
|
+
import {httpCall} from "lkt-http-client";
|
|
8
|
+
import {LktObject} from "lkt-ts-interfaces";
|
|
9
|
+
|
|
10
|
+
const props = defineProps({
|
|
11
|
+
modelValue: {type: Object, required: false, default: () => ({})},
|
|
12
|
+
readResource: {type: String, required: true},
|
|
13
|
+
readData: {type: Object, required: false, default: () => ({})},
|
|
14
|
+
createResource: {type: String, required: false},
|
|
15
|
+
updateResource: {type: String, required: false},
|
|
16
|
+
dropResource: {type: String, required: false},
|
|
17
|
+
title: {type: String, default: ''},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const slots = useSlots();
|
|
21
|
+
|
|
22
|
+
const emit = defineEmits(['update:modelValue', 'read', 'create', 'update', 'drop', 'perms']);
|
|
23
|
+
|
|
24
|
+
const loading = ref(true),
|
|
25
|
+
item = ref(props.modelValue),
|
|
26
|
+
perms = ref([]);
|
|
27
|
+
|
|
28
|
+
const fetchItem = async () => {
|
|
29
|
+
loading.value = true;
|
|
30
|
+
return await httpCall(props.readResource, props.readData).then(r => {
|
|
31
|
+
loading.value = false;
|
|
32
|
+
item.value = r.data;
|
|
33
|
+
perms.value = r.perms;
|
|
34
|
+
emit('read', r);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const displayHeader = computed(() => {
|
|
39
|
+
if (loading.value) return false;
|
|
40
|
+
|
|
41
|
+
return props.title || !!slots['post-title'];
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
watch(() => props.modelValue, v => item.value = v);
|
|
45
|
+
watch(item, () => emit('update:modelValue', item.value));
|
|
46
|
+
watch(perms, () => emit('perms', perms.value));
|
|
47
|
+
|
|
48
|
+
const create = async (data: LktObject) => {
|
|
49
|
+
const resource = props.createResource;
|
|
50
|
+
|
|
51
|
+
loading.value = true;
|
|
52
|
+
return await httpCall(resource, {...data}).then(r => {
|
|
53
|
+
loading.value = false;
|
|
54
|
+
emit('create', r);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const update = async (data: LktObject) => {
|
|
59
|
+
const resource = props.updateResource;
|
|
60
|
+
|
|
61
|
+
loading.value = true;
|
|
62
|
+
return await httpCall(resource, {...data}).then(r => {
|
|
63
|
+
loading.value = false;
|
|
64
|
+
emit('update', r);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const drop = async (data: LktObject) => {
|
|
69
|
+
const resource = props.dropResource;
|
|
70
|
+
|
|
71
|
+
loading.value = true;
|
|
72
|
+
return await httpCall(resource, {...data}).then(r => {
|
|
73
|
+
loading.value = false;
|
|
74
|
+
emit('drop', r);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Fetch item
|
|
79
|
+
if (props.readResource) fetchItem();
|
|
80
|
+
|
|
81
|
+
defineExpose({
|
|
82
|
+
fetchItem,
|
|
83
|
+
create,
|
|
84
|
+
update,
|
|
85
|
+
drop,
|
|
86
|
+
refresh: fetchItem
|
|
87
|
+
});
|
|
88
|
+
</script>
|
|
89
|
+
|
|
90
|
+
<template>
|
|
91
|
+
<article class="lkt-item-crud">
|
|
92
|
+
<header class="lkt-item-crud_header" v-if="displayHeader">
|
|
93
|
+
<h1 class="lkt-item-crud_header-title">{{ title }}</h1>
|
|
94
|
+
<div class="lkt-item-crud_header-slot">
|
|
95
|
+
<slot name="post-title" v-bind:item="item"></slot>
|
|
96
|
+
</div>
|
|
97
|
+
</header>
|
|
98
|
+
<div class="lkt-item-crud_content" v-if="!loading">
|
|
99
|
+
<slot name="item" v-bind:item="item"></slot>
|
|
100
|
+
</div>
|
|
101
|
+
<lkt-loader v-if="loading"></lkt-loader>
|
|
102
|
+
</article>
|
|
103
|
+
</template>
|