lkt-item-crud 1.1.13 → 1.1.15
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.js +54 -49
- package/package.json +1 -1
- package/src/lib-components/LktItemCrud.vue +7 -1
package/dist/build.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { defineComponent as ne, useSlots as se, ref as s, computed as d, watch as D, resolveComponent as q, openBlock as
|
|
1
|
+
import { defineComponent as ne, useSlots as se, ref as s, computed as d, watch as D, resolveComponent as q, openBlock as v, createElementBlock as h, createElementVNode as E, toDisplayString as j, renderSlot as w, createCommentVNode as g, withDirectives as O, createBlock as V, withCtx as G, unref as K, vShow as I, createVNode as Q } from "vue";
|
|
2
2
|
import { httpCall as ie } from "lkt-http-client";
|
|
3
3
|
import { DataState as ce } from "lkt-data-state";
|
|
4
4
|
const N = class N {
|
|
5
5
|
};
|
|
6
6
|
N.debugEnabled = !1;
|
|
7
7
|
let U = N;
|
|
8
|
-
const
|
|
8
|
+
const i = (...u) => {
|
|
9
9
|
U.debugEnabled && console.info("[LktItemCrud] ", ...u);
|
|
10
10
|
}, we = (u = !0) => {
|
|
11
11
|
U.debugEnabled = u;
|
|
12
12
|
}, ve = { class: "lkt-item-crud" }, fe = {
|
|
13
13
|
key: 0,
|
|
14
14
|
class: "lkt-item-crud_header"
|
|
15
|
-
}, pe = { class: "lkt-item-crud_header-title" }, me = { class: "lkt-item-crud_header-slot" }, ye = { class: "lkt-item-crud-buttons" }, he = { key: 1 },
|
|
15
|
+
}, pe = { class: "lkt-item-crud_header-title" }, me = { class: "lkt-item-crud_header-slot" }, ye = { class: "lkt-item-crud-buttons" }, he = { key: 1 }, be = { key: 1 }, Se = {
|
|
16
16
|
key: 1,
|
|
17
17
|
class: "lkt-item-crud_content"
|
|
18
18
|
}, ke = {
|
|
@@ -57,45 +57,50 @@ const p = (...u) => {
|
|
|
57
57
|
setup(u, { expose: T, emit: W }) {
|
|
58
58
|
const e = u, L = se(), n = W;
|
|
59
59
|
let X = [];
|
|
60
|
-
const o = s(!0), r = s(e.modelValue),
|
|
61
|
-
|
|
60
|
+
const o = s(!0), r = s(e.modelValue), b = s(X), f = s(!1), p = s(!1), m = s(!1), c = s(200), C = s(null), B = s(null), S = s(new ce(r.value)), l = s(e.isCreate), Y = d(() => l.value ? e.createConfirm : e.updateConfirm), Z = d(() => l.value ? e.createConfirmData : e.updateConfirmData), $ = d(() => l.value ? e.createResource : e.updateResource), ee = d(() => l.value ? { ...e.createData, ...JSON.parse(JSON.stringify(r.value)) } : { ...e.updateData, ...JSON.parse(JSON.stringify(r.value)) }), te = d(() => l.value ? e.createDisabled : e.updateDisabled), _ = d(() => !l.value && b.value.includes("update")), R = d(() => !l.value && b.value.includes("drop")), M = async () => {
|
|
61
|
+
i("fetchItem"), o.value = !0, c.value = -1, m.value = !1;
|
|
62
62
|
try {
|
|
63
63
|
const t = await ie(e.readResource, e.readData);
|
|
64
|
-
if (
|
|
65
|
-
|
|
64
|
+
if (i("fetchItem -> response", t), o.value = !1, c.value = t.httpStatus, !t.success) {
|
|
65
|
+
p.value = !1, c.value = t.httpStatus, n("error", t.httpStatus);
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
p.value = !0, r.value = t.data, b.value = t.perms, S.value.increment(r.value).turnStoredIntoOriginal(), n("read", t);
|
|
69
69
|
} catch {
|
|
70
|
-
o.value = !1,
|
|
70
|
+
o.value = !1, p.value = !1, c.value = 404, n("error", 404);
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
73
|
}, ae = d(() => o.value ? !1 : e.title || !!L["post-title"]);
|
|
74
74
|
D(() => e.modelValue, (t) => {
|
|
75
|
-
r.value = t,
|
|
75
|
+
r.value = t, S.value.increment(t);
|
|
76
76
|
}, { deep: !0 }), D(r, (t) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
if (i("item updated ->", r.value), typeof e.beforeEmitUpdate == "function") {
|
|
78
|
+
i("item updated -> has beforeEmitUpdate");
|
|
79
|
+
let a = e.beforeEmitUpdate(r.value);
|
|
80
|
+
typeof a == "object" && (r.value = a);
|
|
81
|
+
}
|
|
82
|
+
n("update:modelValue", r.value), i("item updated -> update dataState"), S.value.increment(t);
|
|
83
|
+
}, { deep: !0 }), D(b, () => n("perms", b.value));
|
|
84
|
+
const x = d(() => te.value || !l.value && !_.value || typeof e.saveValidator == "function" && !e.saveValidator(r.value) ? !1 : S.value.changed());
|
|
85
|
+
D(x, (t) => n("modified-data", t)), D(l, (t) => n("update:isCreate", t)), e.readResource && !l.value ? M() : l.value && (p.value = !0, f.value = !0, o.value = !1);
|
|
86
|
+
const le = (t, a) => {
|
|
87
|
+
if (o.value = !1, c.value = a.httpStatus, !a.success) {
|
|
88
|
+
m.value = !0, n("error", a.httpStatus);
|
|
84
89
|
return;
|
|
85
90
|
}
|
|
86
|
-
m.value = !0, n("drop",
|
|
87
|
-
}, ue = (t,
|
|
88
|
-
if (
|
|
89
|
-
if (o.value = !1,
|
|
90
|
-
m.value = !0, n("error",
|
|
91
|
+
m.value = !0, n("drop", a);
|
|
92
|
+
}, ue = (t, a) => {
|
|
93
|
+
if (i("onSave -> received response:", a), $.value) {
|
|
94
|
+
if (o.value = !1, c.value = a.httpStatus, !a.success) {
|
|
95
|
+
m.value = !0, n("error", a.httpStatus);
|
|
91
96
|
return;
|
|
92
97
|
}
|
|
93
98
|
m.value = !0;
|
|
94
99
|
}
|
|
95
|
-
let k =
|
|
96
|
-
|
|
100
|
+
let k = l.value ? "create" : "update";
|
|
101
|
+
l.value || (i("onSave -> turn stored data into original"), S.value.turnStoredIntoOriginal()), k === "create" ? typeof e.onCreate == "function" && (i("onSave -> trigger onCreate callback"), e.onCreate(a)) : typeof e.onUpdate == "function" && (i("onSave -> trigger onUpdate callback"), e.onUpdate(a)), !e.insideModal && a.autoReloadId && (i("onSave -> autoReloadId detected: ", a.autoReloadId), e.readData.id = a.autoReloadId, i("onSave -> turning off create mode"), l.value = !1, M()), n(k, a);
|
|
97
102
|
}, F = () => {
|
|
98
|
-
o.value = !0,
|
|
103
|
+
o.value = !0, c.value = -1;
|
|
99
104
|
}, J = () => {
|
|
100
105
|
o.value = !1;
|
|
101
106
|
};
|
|
@@ -108,11 +113,11 @@ const p = (...u) => {
|
|
|
108
113
|
C.value && typeof C.value.click == "function" && C.value.click();
|
|
109
114
|
}
|
|
110
115
|
});
|
|
111
|
-
const A = d(() => !e.hiddenDrop && !o.value &&
|
|
112
|
-
return (t,
|
|
116
|
+
const A = d(() => !e.hiddenDrop && !o.value && f.value && p.value), H = d(() => o.value ? !1 : l.value ? !0 : !e.hiddenSave && f.value && p.value), P = d(() => !o.value && !l.value && p.value && !(e.dropDisabled && e.updateDisabled)), oe = d(() => !e.hiddenButtons && (H.value || A.value || P.value));
|
|
117
|
+
return (t, a) => {
|
|
113
118
|
const k = q("lkt-button"), re = q("lkt-field-switch"), z = q("lkt-http-info"), de = q("lkt-loader");
|
|
114
|
-
return
|
|
115
|
-
ae.value ? (
|
|
119
|
+
return v(), h("article", ve, [
|
|
120
|
+
ae.value ? (v(), h("header", fe, [
|
|
116
121
|
E("h1", pe, j(u.title), 1),
|
|
117
122
|
E("div", me, [
|
|
118
123
|
w(t.$slots, "post-title", {
|
|
@@ -122,7 +127,7 @@ const p = (...u) => {
|
|
|
122
127
|
])
|
|
123
128
|
])) : g("", !0),
|
|
124
129
|
O(E("div", ye, [
|
|
125
|
-
|
|
130
|
+
l.value ? g("", !0) : O((v(), V(k, {
|
|
126
131
|
key: 0,
|
|
127
132
|
ref: (y) => B.value = y,
|
|
128
133
|
palette: "danger",
|
|
@@ -139,11 +144,11 @@ const p = (...u) => {
|
|
|
139
144
|
K(L)["button-drop"] ? w(t.$slots, "button-drop", {
|
|
140
145
|
key: 0,
|
|
141
146
|
item: r.value,
|
|
142
|
-
editMode:
|
|
143
|
-
isCreate:
|
|
147
|
+
editMode: f.value,
|
|
148
|
+
isCreate: l.value,
|
|
144
149
|
canUpdate: _.value,
|
|
145
150
|
canDrop: R.value
|
|
146
|
-
}) : (
|
|
151
|
+
}) : (v(), h("span", he, j(u.dropText), 1))
|
|
147
152
|
]),
|
|
148
153
|
_: 3
|
|
149
154
|
}, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"])), [
|
|
@@ -165,19 +170,19 @@ const p = (...u) => {
|
|
|
165
170
|
K(L)["button-save"] ? w(t.$slots, "button-save", {
|
|
166
171
|
key: 0,
|
|
167
172
|
item: r.value,
|
|
168
|
-
editMode:
|
|
169
|
-
isCreate:
|
|
173
|
+
editMode: f.value,
|
|
174
|
+
isCreate: l.value,
|
|
170
175
|
canUpdate: _.value,
|
|
171
176
|
canDrop: R.value
|
|
172
|
-
}) : (
|
|
177
|
+
}) : (v(), h("span", be, j(u.saveText), 1))
|
|
173
178
|
]),
|
|
174
179
|
_: 3
|
|
175
180
|
}, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"]), [
|
|
176
181
|
[I, H.value]
|
|
177
182
|
]),
|
|
178
183
|
O(Q(re, {
|
|
179
|
-
modelValue:
|
|
180
|
-
"onUpdate:modelValue":
|
|
184
|
+
modelValue: f.value,
|
|
185
|
+
"onUpdate:modelValue": a[0] || (a[0] = (y) => f.value = y),
|
|
181
186
|
label: u.editModeText
|
|
182
187
|
}, null, 8, ["modelValue", "label"]), [
|
|
183
188
|
[I, P.value]
|
|
@@ -185,30 +190,30 @@ const p = (...u) => {
|
|
|
185
190
|
], 512), [
|
|
186
191
|
[I, oe.value]
|
|
187
192
|
]),
|
|
188
|
-
o.value ? g("", !0) : (
|
|
189
|
-
|
|
190
|
-
m.value ? (
|
|
193
|
+
o.value ? g("", !0) : (v(), h("div", Se, [
|
|
194
|
+
p.value ? (v(), h("div", ke, [
|
|
195
|
+
m.value ? (v(), V(z, {
|
|
191
196
|
key: 0,
|
|
192
|
-
code:
|
|
197
|
+
code: c.value,
|
|
193
198
|
quick: "",
|
|
194
|
-
palette:
|
|
199
|
+
palette: c.value === 200 ? "success" : "danger",
|
|
195
200
|
"can-close": "",
|
|
196
|
-
onClose:
|
|
201
|
+
onClose: a[1] || (a[1] = (y) => m.value = !1)
|
|
197
202
|
}, null, 8, ["code", "palette"])) : g("", !0),
|
|
198
203
|
w(t.$slots, "item", {
|
|
199
204
|
item: r.value,
|
|
200
205
|
loading: o.value,
|
|
201
|
-
editMode:
|
|
202
|
-
isCreate:
|
|
206
|
+
editMode: f.value,
|
|
207
|
+
isCreate: l.value,
|
|
203
208
|
canUpdate: _.value,
|
|
204
209
|
canDrop: R.value
|
|
205
210
|
})
|
|
206
|
-
])) : (
|
|
211
|
+
])) : (v(), V(z, {
|
|
207
212
|
key: 1,
|
|
208
|
-
code:
|
|
213
|
+
code: c.value
|
|
209
214
|
}, null, 8, ["code"]))
|
|
210
215
|
])),
|
|
211
|
-
o.value ? (
|
|
216
|
+
o.value ? (v(), V(de, { key: 2 })) : g("", !0)
|
|
212
217
|
]);
|
|
213
218
|
};
|
|
214
219
|
}
|
package/package.json
CHANGED
|
@@ -140,8 +140,14 @@ watch(() => props.modelValue, v => {
|
|
|
140
140
|
}, {deep: true});
|
|
141
141
|
|
|
142
142
|
watch(item, (v) => {
|
|
143
|
-
|
|
143
|
+
debug('item updated ->', item.value);
|
|
144
|
+
if (typeof props.beforeEmitUpdate === 'function') {
|
|
145
|
+
debug('item updated -> has beforeEmitUpdate');
|
|
146
|
+
let override = props.beforeEmitUpdate(item.value);
|
|
147
|
+
if (typeof override === 'object') item.value = override;
|
|
148
|
+
}
|
|
144
149
|
emit('update:modelValue', item.value);
|
|
150
|
+
debug('item updated -> update dataState');
|
|
145
151
|
dataState.value.increment(v);
|
|
146
152
|
}, {deep: true});
|
|
147
153
|
|