lkt-item-crud 1.1.3 → 1.1.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/build.d.ts
CHANGED
package/dist/build.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { defineComponent as ue, useSlots as re, ref as
|
|
1
|
+
import { defineComponent as ue, useSlots as re, ref as s, computed as o, watch as B, resolveComponent as w, openBlock as i, createElementBlock as m, createElementVNode as j, toDisplayString as M, renderSlot as O, createCommentVNode as h, withDirectives as R, createBlock as V, withCtx as A, unref as H, vShow as q, createVNode as P } from "vue";
|
|
2
2
|
import { httpCall as oe } from "lkt-http-client";
|
|
3
3
|
import { DataState as de } from "lkt-data-state";
|
|
4
|
-
const
|
|
4
|
+
const ne = { class: "lkt-item-crud" }, se = {
|
|
5
5
|
key: 0,
|
|
6
6
|
class: "lkt-item-crud_header"
|
|
7
|
-
}, ie = { class: "lkt-item-crud_header-title" }, ce = { class: "lkt-item-crud_header-slot" },
|
|
7
|
+
}, ie = { class: "lkt-item-crud_header-title" }, ce = { class: "lkt-item-crud_header-slot" }, fe = { class: "lkt-item-crud-buttons" }, ve = { key: 1 }, pe = { key: 1 }, me = {
|
|
8
8
|
key: 1,
|
|
9
9
|
class: "lkt-item-crud_content"
|
|
10
10
|
}, ye = {
|
|
11
11
|
key: 0,
|
|
12
12
|
class: "lkt-grid-1"
|
|
13
|
-
},
|
|
14
|
-
...
|
|
13
|
+
}, Ce = { name: "LktItemCrud", inheritAttrs: !1 }, he = /* @__PURE__ */ ue({
|
|
14
|
+
...Ce,
|
|
15
15
|
props: {
|
|
16
16
|
modelValue: { type: Object, required: !1, default: () => ({}) },
|
|
17
17
|
title: { type: String, default: "" },
|
|
@@ -39,55 +39,57 @@ const se = { class: "lkt-item-crud" }, ne = {
|
|
|
39
39
|
createDisabled: { type: Boolean, default: !1 },
|
|
40
40
|
updateDisabled: { type: Boolean, default: !1 },
|
|
41
41
|
dropDisabled: { type: Boolean, default: !1 },
|
|
42
|
-
saveValidator: { type: Function, required: !1, default: () => !0 }
|
|
42
|
+
saveValidator: { type: Function, required: !1, default: () => !0 },
|
|
43
|
+
onCreate: { type: Function, required: !1, default: () => !0 },
|
|
44
|
+
onUpdate: { type: Function, required: !1, default: () => !0 }
|
|
43
45
|
},
|
|
44
46
|
emits: ["update:modelValue", "read", "create", "update", "drop", "perms", "error", "modified-data"],
|
|
45
|
-
setup(a, { expose:
|
|
46
|
-
const e = a,
|
|
47
|
+
setup(a, { expose: U, emit: z }) {
|
|
48
|
+
const e = a, _ = re(), d = z;
|
|
47
49
|
let G = [];
|
|
48
|
-
const l =
|
|
49
|
-
l.value = !0,
|
|
50
|
+
const l = s(!0), r = s(e.modelValue), y = s(G), c = s(!1), f = s(!1), v = s(!1), n = s(200), S = s(null), k = s(null), C = s(new de(r.value)), K = o(() => e.isCreate ? e.createConfirm : e.updateConfirm), Q = o(() => e.isCreate ? e.createConfirmData : e.updateConfirmData), I = o(() => e.isCreate ? e.createResource : e.updateResource), W = o(() => e.isCreate ? { ...e.createData, ...JSON.parse(JSON.stringify(r.value)) } : { ...e.updateData, ...JSON.parse(JSON.stringify(r.value)) }), X = o(() => e.isCreate ? e.createDisabled : e.updateDisabled), D = o(() => !e.isCreate && y.value.includes("update")), b = o(() => !e.isCreate && y.value.includes("drop")), L = async () => {
|
|
51
|
+
l.value = !0, n.value = -1, v.value = !1;
|
|
50
52
|
try {
|
|
51
53
|
const t = await oe(e.readResource, e.readData);
|
|
52
|
-
if (l.value = !1,
|
|
53
|
-
|
|
54
|
+
if (l.value = !1, n.value = t.httpStatus, !t.success) {
|
|
55
|
+
f.value = !1, n.value = t.httpStatus, d("error", t.httpStatus);
|
|
54
56
|
return;
|
|
55
57
|
}
|
|
56
|
-
|
|
58
|
+
f.value = !0, r.value = t.data, y.value = t.perms, C.value.increment(r.value).turnStoredIntoOriginal(), d("read", t);
|
|
57
59
|
} catch {
|
|
58
|
-
l.value = !1,
|
|
60
|
+
l.value = !1, f.value = !1, n.value = 404, d("error", 404);
|
|
59
61
|
return;
|
|
60
62
|
}
|
|
61
|
-
}, Y = o(() => l.value ? !1 : e.title || !!
|
|
63
|
+
}, Y = o(() => l.value ? !1 : e.title || !!_["post-title"]);
|
|
62
64
|
B(() => e.modelValue, (t) => {
|
|
63
|
-
r.value = t,
|
|
65
|
+
r.value = t, C.value.increment(t);
|
|
64
66
|
}, { deep: !0 }), B(r, (t) => {
|
|
65
|
-
d("update:modelValue", r.value),
|
|
67
|
+
d("update:modelValue", r.value), C.value.increment(t);
|
|
66
68
|
}, { deep: !0 }), B(y, () => d("perms", y.value));
|
|
67
|
-
const
|
|
68
|
-
B(
|
|
69
|
+
const N = o(() => X.value || !e.isCreate && !D.value || typeof e.saveValidator == "function" && !e.saveValidator(r.value) ? !1 : C.value.changed());
|
|
70
|
+
B(N, (t) => d("modified-data", t)), e.readResource && !e.isCreate ? L() : e.isCreate && (f.value = !0, c.value = !0, l.value = !1);
|
|
69
71
|
const Z = (t, u) => {
|
|
70
|
-
if (l.value = !1,
|
|
71
|
-
|
|
72
|
+
if (l.value = !1, n.value = u.httpStatus, !u.success) {
|
|
73
|
+
v.value = !0, d("error", u.httpStatus);
|
|
72
74
|
return;
|
|
73
75
|
}
|
|
74
|
-
|
|
76
|
+
v.value = !0, d("drop", u);
|
|
75
77
|
}, ee = (t, u) => {
|
|
76
|
-
if (
|
|
77
|
-
if (l.value = !1,
|
|
78
|
-
|
|
78
|
+
if (I.value) {
|
|
79
|
+
if (l.value = !1, n.value = u.httpStatus, !u.success) {
|
|
80
|
+
v.value = !0, d("error", u.httpStatus);
|
|
79
81
|
return;
|
|
80
82
|
}
|
|
81
|
-
|
|
83
|
+
v.value = !0;
|
|
82
84
|
}
|
|
83
85
|
let g = e.isCreate ? "create" : "update";
|
|
84
|
-
e.isCreate ||
|
|
86
|
+
e.isCreate || C.value.turnStoredIntoOriginal(), u.autoReloadId && (e.readData.id = u.autoReloadId, L()), e.isCreate && typeof e.onCreate == "function" && e.onCreate(), !e.isCreate && typeof e.onUpdate == "function" && e.onUpdate(), d(g, u);
|
|
87
|
+
}, T = () => {
|
|
88
|
+
l.value = !0, n.value = -1;
|
|
85
89
|
}, $ = () => {
|
|
86
|
-
l.value = !0, s.value = -1;
|
|
87
|
-
}, x = () => {
|
|
88
90
|
l.value = !1;
|
|
89
91
|
};
|
|
90
|
-
|
|
92
|
+
U({
|
|
91
93
|
doDrop: () => {
|
|
92
94
|
k.value && typeof k.value.click == "function" && k.value.click();
|
|
93
95
|
},
|
|
@@ -96,11 +98,11 @@ const se = { class: "lkt-item-crud" }, ne = {
|
|
|
96
98
|
S.value && typeof S.value.click == "function" && S.value.click();
|
|
97
99
|
}
|
|
98
100
|
});
|
|
99
|
-
const
|
|
101
|
+
const x = o(() => !e.hiddenDrop && !l.value && c.value && f.value), J = o(() => l.value ? !1 : e.isCreate ? !0 : !e.hiddenSave && c.value && f.value), E = o(() => !l.value && !e.isCreate && f.value), te = o(() => !e.hiddenButtons && (J.value || x.value || E.value));
|
|
100
102
|
return (t, u) => {
|
|
101
|
-
const g = w("lkt-button"), ae = w("lkt-field-switch"),
|
|
102
|
-
return i(), m("article",
|
|
103
|
-
Y.value ? (i(), m("header",
|
|
103
|
+
const g = w("lkt-button"), ae = w("lkt-field-switch"), F = w("lkt-http-info"), le = w("lkt-loader");
|
|
104
|
+
return i(), m("article", ne, [
|
|
105
|
+
Y.value ? (i(), m("header", se, [
|
|
104
106
|
j("h1", ie, M(a.title), 1),
|
|
105
107
|
j("div", ce, [
|
|
106
108
|
O(t.$slots, "post-title", {
|
|
@@ -108,9 +110,9 @@ const se = { class: "lkt-item-crud" }, ne = {
|
|
|
108
110
|
loading: l.value
|
|
109
111
|
})
|
|
110
112
|
])
|
|
111
|
-
])) :
|
|
112
|
-
R(j("div",
|
|
113
|
-
a.isCreate ?
|
|
113
|
+
])) : h("", !0),
|
|
114
|
+
R(j("div", fe, [
|
|
115
|
+
a.isCreate ? h("", !0) : R((i(), V(g, {
|
|
114
116
|
key: 0,
|
|
115
117
|
ref: (p) => k.value = p,
|
|
116
118
|
palette: "danger",
|
|
@@ -119,38 +121,38 @@ const se = { class: "lkt-item-crud" }, ne = {
|
|
|
119
121
|
"confirm-data": a.dropConfirmData,
|
|
120
122
|
resource: a.dropResource,
|
|
121
123
|
"resource-data": a.dropData,
|
|
122
|
-
onLoading:
|
|
123
|
-
onLoaded:
|
|
124
|
+
onLoading: T,
|
|
125
|
+
onLoaded: $,
|
|
124
126
|
onClick: Z
|
|
125
127
|
}, {
|
|
126
|
-
default:
|
|
127
|
-
H(
|
|
128
|
+
default: A(() => [
|
|
129
|
+
H(_)["button-drop"] ? O(t.$slots, "button-drop", {
|
|
128
130
|
key: 0,
|
|
129
131
|
item: r.value,
|
|
130
132
|
editMode: c.value,
|
|
131
133
|
isCreate: a.isCreate,
|
|
132
134
|
canUpdate: D.value,
|
|
133
135
|
canDrop: b.value
|
|
134
|
-
}) : (i(), m("span",
|
|
136
|
+
}) : (i(), m("span", ve, M(a.dropText), 1))
|
|
135
137
|
]),
|
|
136
138
|
_: 3
|
|
137
139
|
}, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"])), [
|
|
138
|
-
[
|
|
140
|
+
[q, x.value]
|
|
139
141
|
]),
|
|
140
142
|
R(P(g, {
|
|
141
143
|
ref: (p) => S.value = p,
|
|
142
144
|
palette: "success",
|
|
143
|
-
disabled: !
|
|
145
|
+
disabled: !N.value,
|
|
144
146
|
"confirm-modal": K.value,
|
|
145
147
|
"confirm-data": Q.value,
|
|
146
|
-
resource:
|
|
148
|
+
resource: I.value,
|
|
147
149
|
"resource-data": W.value,
|
|
148
|
-
onLoading:
|
|
149
|
-
onLoaded:
|
|
150
|
+
onLoading: T,
|
|
151
|
+
onLoaded: $,
|
|
150
152
|
onClick: ee
|
|
151
153
|
}, {
|
|
152
|
-
default:
|
|
153
|
-
H(
|
|
154
|
+
default: A(() => [
|
|
155
|
+
H(_)["button-save"] ? O(t.$slots, "button-save", {
|
|
154
156
|
key: 0,
|
|
155
157
|
item: r.value,
|
|
156
158
|
editMode: c.value,
|
|
@@ -161,28 +163,28 @@ const se = { class: "lkt-item-crud" }, ne = {
|
|
|
161
163
|
]),
|
|
162
164
|
_: 3
|
|
163
165
|
}, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"]), [
|
|
164
|
-
[
|
|
166
|
+
[q, J.value]
|
|
165
167
|
]),
|
|
166
168
|
R(P(ae, {
|
|
167
169
|
modelValue: c.value,
|
|
168
170
|
"onUpdate:modelValue": u[0] || (u[0] = (p) => c.value = p),
|
|
169
171
|
label: a.editModeText
|
|
170
172
|
}, null, 8, ["modelValue", "label"]), [
|
|
171
|
-
[
|
|
173
|
+
[q, E.value]
|
|
172
174
|
])
|
|
173
175
|
], 512), [
|
|
174
|
-
[
|
|
176
|
+
[q, te.value]
|
|
175
177
|
]),
|
|
176
|
-
l.value ?
|
|
177
|
-
|
|
178
|
-
|
|
178
|
+
l.value ? h("", !0) : (i(), m("div", me, [
|
|
179
|
+
f.value ? (i(), m("div", ye, [
|
|
180
|
+
v.value ? (i(), V(F, {
|
|
179
181
|
key: 0,
|
|
180
|
-
code:
|
|
182
|
+
code: n.value,
|
|
181
183
|
quick: "",
|
|
182
|
-
palette:
|
|
184
|
+
palette: n.value === 200 ? "success" : "danger",
|
|
183
185
|
"can-close": "",
|
|
184
|
-
onClose: u[1] || (u[1] = (p) =>
|
|
185
|
-
}, null, 8, ["code", "palette"])) :
|
|
186
|
+
onClose: u[1] || (u[1] = (p) => v.value = !1)
|
|
187
|
+
}, null, 8, ["code", "palette"])) : h("", !0),
|
|
186
188
|
O(t.$slots, "item", {
|
|
187
189
|
item: r.value,
|
|
188
190
|
loading: l.value,
|
|
@@ -191,18 +193,18 @@ const se = { class: "lkt-item-crud" }, ne = {
|
|
|
191
193
|
canUpdate: D.value,
|
|
192
194
|
canDrop: b.value
|
|
193
195
|
})
|
|
194
|
-
])) : (i(), V(
|
|
196
|
+
])) : (i(), V(F, {
|
|
195
197
|
key: 1,
|
|
196
|
-
code:
|
|
198
|
+
code: n.value
|
|
197
199
|
}, null, 8, ["code"]))
|
|
198
200
|
])),
|
|
199
|
-
l.value ? (i(), V(le, { key: 2 })) :
|
|
201
|
+
l.value ? (i(), V(le, { key: 2 })) : h("", !0)
|
|
200
202
|
]);
|
|
201
203
|
};
|
|
202
204
|
}
|
|
203
205
|
}), Be = {
|
|
204
|
-
install: (a,
|
|
205
|
-
a.component("lkt-item-crud") === void 0 && a.component("lkt-item-crud",
|
|
206
|
+
install: (a, U = {}) => {
|
|
207
|
+
a.component("lkt-item-crud") === void 0 && a.component("lkt-item-crud", he);
|
|
206
208
|
}
|
|
207
209
|
};
|
|
208
210
|
export {
|
|
@@ -113,6 +113,16 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
113
113
|
required: false;
|
|
114
114
|
default: () => boolean;
|
|
115
115
|
};
|
|
116
|
+
onCreate: {
|
|
117
|
+
type: FunctionConstructor;
|
|
118
|
+
required: false;
|
|
119
|
+
default: () => boolean;
|
|
120
|
+
};
|
|
121
|
+
onUpdate: {
|
|
122
|
+
type: FunctionConstructor;
|
|
123
|
+
required: false;
|
|
124
|
+
default: () => boolean;
|
|
125
|
+
};
|
|
116
126
|
}, {
|
|
117
127
|
doDrop: () => void;
|
|
118
128
|
doRefresh: () => Promise<void>;
|
|
@@ -241,6 +251,16 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
241
251
|
required: false;
|
|
242
252
|
default: () => boolean;
|
|
243
253
|
};
|
|
254
|
+
onCreate: {
|
|
255
|
+
type: FunctionConstructor;
|
|
256
|
+
required: false;
|
|
257
|
+
default: () => boolean;
|
|
258
|
+
};
|
|
259
|
+
onUpdate: {
|
|
260
|
+
type: FunctionConstructor;
|
|
261
|
+
required: false;
|
|
262
|
+
default: () => boolean;
|
|
263
|
+
};
|
|
244
264
|
}>> & {
|
|
245
265
|
onError?: ((...args: any[]) => any) | undefined;
|
|
246
266
|
onDrop?: ((...args: any[]) => any) | undefined;
|
|
@@ -252,6 +272,8 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
252
272
|
"onModified-data"?: ((...args: any[]) => any) | undefined;
|
|
253
273
|
}, {
|
|
254
274
|
title: string;
|
|
275
|
+
onUpdate: Function;
|
|
276
|
+
onCreate: Function;
|
|
255
277
|
modelValue: Record<string, any>;
|
|
256
278
|
editModeText: string;
|
|
257
279
|
saveText: string;
|
package/package.json
CHANGED
|
@@ -42,6 +42,9 @@ const props = defineProps({
|
|
|
42
42
|
dropDisabled: {type: Boolean, default: false},
|
|
43
43
|
|
|
44
44
|
saveValidator: {type: Function, required: false, default: () => true},
|
|
45
|
+
|
|
46
|
+
onCreate: {type: Function, required: false, default: () => true},
|
|
47
|
+
onUpdate: {type: Function, required: false, default: () => true},
|
|
45
48
|
});
|
|
46
49
|
|
|
47
50
|
const slots = useSlots();
|
|
@@ -186,8 +189,9 @@ const onDrop = ($event: PointerEvent, r: HTTPResponse) => {
|
|
|
186
189
|
props.readData['id'] = r.autoReloadId;
|
|
187
190
|
fetchItem();
|
|
188
191
|
}
|
|
192
|
+
if (props.isCreate && typeof props.onCreate === 'function') props.onCreate();
|
|
193
|
+
if (!props.isCreate && typeof props.onUpdate === 'function') props.onUpdate();
|
|
189
194
|
emit(emits, r)
|
|
190
|
-
|
|
191
195
|
},
|
|
192
196
|
onButtonLoading = () => {
|
|
193
197
|
isLoading.value = true;
|