lkt-item-crud 1.1.6 → 1.1.7
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 +4 -3
- package/dist/build.js +112 -103
- package/dist/functions/debug.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/lib-components/LktItemCrud.vue.d.ts +3 -3
- package/dist/settings/Settings.d.ts +3 -0
- package/package.json +1 -1
- package/src/lib-components/LktItemCrud.vue +16 -3
package/dist/build.d.ts
CHANGED
package/dist/build.js
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { httpCall as
|
|
3
|
-
import { DataState as
|
|
4
|
-
const
|
|
1
|
+
import { defineComponent as ne, useSlots as se, ref as s, computed as d, watch as b, resolveComponent as w, openBlock as c, createElementBlock as h, createElementVNode as j, toDisplayString as N, renderSlot as O, createCommentVNode as D, withDirectives as V, createBlock as q, withCtx as G, unref as K, vShow as I, createVNode as Q } from "vue";
|
|
2
|
+
import { httpCall as ie } from "lkt-http-client";
|
|
3
|
+
import { DataState as ce } from "lkt-data-state";
|
|
4
|
+
const T = class T {
|
|
5
|
+
};
|
|
6
|
+
T.debugEnabled = !1;
|
|
7
|
+
let L = T;
|
|
8
|
+
const p = (...u) => {
|
|
9
|
+
L.debugEnabled && console.info("[LktHttpClient] ", ...u);
|
|
10
|
+
}, Oe = (u = !0) => {
|
|
11
|
+
L.debugEnabled = u;
|
|
12
|
+
}, ve = { class: "lkt-item-crud" }, fe = {
|
|
5
13
|
key: 0,
|
|
6
14
|
class: "lkt-item-crud_header"
|
|
7
|
-
},
|
|
15
|
+
}, pe = { class: "lkt-item-crud_header-title" }, me = { class: "lkt-item-crud_header-slot" }, ye = { class: "lkt-item-crud-buttons" }, he = { key: 1 }, Se = { key: 1 }, ke = {
|
|
8
16
|
key: 1,
|
|
9
17
|
class: "lkt-item-crud_content"
|
|
10
|
-
},
|
|
18
|
+
}, be = {
|
|
11
19
|
key: 0,
|
|
12
20
|
class: "lkt-grid-1"
|
|
13
|
-
},
|
|
14
|
-
...
|
|
21
|
+
}, De = { name: "LktItemCrud", inheritAttrs: !1 }, ge = /* @__PURE__ */ ne({
|
|
22
|
+
...De,
|
|
15
23
|
props: {
|
|
16
24
|
modelValue: { type: Object, required: !1, default: () => ({}) },
|
|
17
25
|
title: { type: String, default: "" },
|
|
@@ -44,169 +52,170 @@ const se = { class: "lkt-item-crud" }, ie = {
|
|
|
44
52
|
onUpdate: { type: Function, required: !1, default: () => !0 }
|
|
45
53
|
},
|
|
46
54
|
emits: ["update:modelValue", "update:isCreate", "read", "create", "update", "drop", "perms", "error", "modified-data"],
|
|
47
|
-
setup(
|
|
48
|
-
const e =
|
|
49
|
-
let
|
|
50
|
-
const
|
|
51
|
-
|
|
55
|
+
setup(u, { expose: $, emit: W }) {
|
|
56
|
+
const e = u, M = se(), n = W;
|
|
57
|
+
let X = [];
|
|
58
|
+
const o = s(!0), r = s(e.modelValue), S = s(X), v = s(!1), f = s(!1), m = s(!1), i = s(200), g = s(null), C = s(null), k = s(new ce(r.value)), a = s(e.isCreate), Y = d(() => a.value ? e.createConfirm : e.updateConfirm), Z = d(() => a.value ? e.createConfirmData : e.updateConfirmData), x = d(() => a.value ? e.createResource : e.updateResource), ee = d(() => a.value ? { ...e.createData, ...JSON.parse(JSON.stringify(r.value)) } : { ...e.updateData, ...JSON.parse(JSON.stringify(r.value)) }), te = d(() => a.value ? e.createDisabled : e.updateDisabled), B = d(() => !a.value && S.value.includes("update")), _ = d(() => !a.value && S.value.includes("drop")), U = async () => {
|
|
59
|
+
p("fetchItem"), o.value = !0, i.value = -1, m.value = !1;
|
|
52
60
|
try {
|
|
53
|
-
const t = await
|
|
54
|
-
if (
|
|
61
|
+
const t = await ie(e.readResource, e.readData);
|
|
62
|
+
if (p("fetchItem -> response", t), o.value = !1, i.value = t.httpStatus, !t.success) {
|
|
55
63
|
f.value = !1, i.value = t.httpStatus, n("error", t.httpStatus);
|
|
56
64
|
return;
|
|
57
65
|
}
|
|
58
|
-
f.value = !0, r.value = t.data,
|
|
66
|
+
f.value = !0, r.value = t.data, S.value = t.perms, k.value.increment(r.value).turnStoredIntoOriginal(), n("read", t);
|
|
59
67
|
} catch {
|
|
60
|
-
|
|
68
|
+
o.value = !1, f.value = !1, i.value = 404, n("error", 404);
|
|
61
69
|
return;
|
|
62
70
|
}
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
r.value = t,
|
|
66
|
-
}, { deep: !0 }),
|
|
67
|
-
n("update:modelValue", r.value),
|
|
68
|
-
}, { deep: !0 }),
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
|
|
71
|
+
}, ae = d(() => o.value ? !1 : e.title || !!M["post-title"]);
|
|
72
|
+
b(() => e.modelValue, (t) => {
|
|
73
|
+
r.value = t, k.value.increment(t);
|
|
74
|
+
}, { deep: !0 }), b(r, (t) => {
|
|
75
|
+
n("update:modelValue", r.value), k.value.increment(t);
|
|
76
|
+
}, { deep: !0 }), b(S, () => n("perms", S.value));
|
|
77
|
+
const E = d(() => te.value || !a.value && !B.value || typeof e.saveValidator == "function" && !e.saveValidator(r.value) ? !1 : k.value.changed());
|
|
78
|
+
b(E, (t) => n("modified-data", t)), b(a, (t) => n("update:isCreate", t)), e.readResource && !a.value ? U() : a.value && (f.value = !0, v.value = !0, o.value = !1);
|
|
79
|
+
const le = (t, l) => {
|
|
80
|
+
if (o.value = !1, i.value = l.httpStatus, !l.success) {
|
|
81
|
+
m.value = !0, n("error", l.httpStatus);
|
|
74
82
|
return;
|
|
75
83
|
}
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
if (
|
|
79
|
-
if (
|
|
80
|
-
|
|
84
|
+
m.value = !0, n("drop", l);
|
|
85
|
+
}, ue = (t, l) => {
|
|
86
|
+
if (p("onSave -> received response:", l), x.value) {
|
|
87
|
+
if (o.value = !1, i.value = l.httpStatus, !l.success) {
|
|
88
|
+
m.value = !0, n("error", l.httpStatus);
|
|
81
89
|
return;
|
|
82
90
|
}
|
|
83
|
-
|
|
91
|
+
m.value = !0;
|
|
84
92
|
}
|
|
85
|
-
let
|
|
86
|
-
a.value ||
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
},
|
|
90
|
-
|
|
93
|
+
let R = a.value ? "create" : "update";
|
|
94
|
+
a.value || (p("onSave -> turn stored data into original"), k.value.turnStoredIntoOriginal()), l.autoReloadId && (p("onSave -> autoReloadId detected: ", l.autoReloadId), e.readData.id = l.autoReloadId, p("onSave -> turning off create mode"), a.value = !1, U()), a.value ? typeof e.onCreate == "function" && (p("onSave -> trigger onCreate callback"), e.onCreate()) : typeof e.onUpdate == "function" && (p("onSave -> trigger onUpdate callback"), e.onUpdate()), n(R, l);
|
|
95
|
+
}, J = () => {
|
|
96
|
+
o.value = !0, i.value = -1;
|
|
97
|
+
}, F = () => {
|
|
98
|
+
o.value = !1;
|
|
91
99
|
};
|
|
92
|
-
|
|
100
|
+
$({
|
|
93
101
|
doDrop: () => {
|
|
94
|
-
|
|
102
|
+
C.value && typeof C.value.click == "function" && C.value.click();
|
|
95
103
|
},
|
|
96
|
-
doRefresh:
|
|
104
|
+
doRefresh: U,
|
|
97
105
|
doSave: () => {
|
|
98
|
-
|
|
106
|
+
g.value && typeof g.value.click == "function" && g.value.click();
|
|
99
107
|
}
|
|
100
108
|
});
|
|
101
|
-
const
|
|
102
|
-
return (t,
|
|
103
|
-
const
|
|
104
|
-
return c(),
|
|
105
|
-
|
|
106
|
-
j("h1",
|
|
107
|
-
j("div",
|
|
109
|
+
const H = d(() => !e.hiddenDrop && !o.value && v.value && f.value), A = d(() => o.value ? !1 : a.value ? !0 : !e.hiddenSave && v.value && f.value), P = d(() => !o.value && !a.value && f.value), oe = d(() => !e.hiddenButtons && (A.value || H.value || P.value));
|
|
110
|
+
return (t, l) => {
|
|
111
|
+
const R = w("lkt-button"), re = w("lkt-field-switch"), z = w("lkt-http-info"), de = w("lkt-loader");
|
|
112
|
+
return c(), h("article", ve, [
|
|
113
|
+
ae.value ? (c(), h("header", fe, [
|
|
114
|
+
j("h1", pe, N(u.title), 1),
|
|
115
|
+
j("div", me, [
|
|
108
116
|
O(t.$slots, "post-title", {
|
|
109
117
|
item: r.value,
|
|
110
|
-
loading:
|
|
118
|
+
loading: o.value
|
|
111
119
|
})
|
|
112
120
|
])
|
|
113
121
|
])) : D("", !0),
|
|
114
|
-
|
|
115
|
-
a.value ? D("", !0) :
|
|
122
|
+
V(j("div", ye, [
|
|
123
|
+
a.value ? D("", !0) : V((c(), q(R, {
|
|
116
124
|
key: 0,
|
|
117
|
-
ref: (
|
|
125
|
+
ref: (y) => C.value = y,
|
|
118
126
|
palette: "danger",
|
|
119
|
-
disabled:
|
|
120
|
-
"confirm-modal":
|
|
121
|
-
"confirm-data":
|
|
122
|
-
resource:
|
|
123
|
-
"resource-data":
|
|
124
|
-
onLoading:
|
|
125
|
-
onLoaded:
|
|
126
|
-
onClick:
|
|
127
|
+
disabled: u.dropDisabled || !_.value,
|
|
128
|
+
"confirm-modal": u.dropConfirm,
|
|
129
|
+
"confirm-data": u.dropConfirmData,
|
|
130
|
+
resource: u.dropResource,
|
|
131
|
+
"resource-data": u.dropData,
|
|
132
|
+
onLoading: J,
|
|
133
|
+
onLoaded: F,
|
|
134
|
+
onClick: le
|
|
127
135
|
}, {
|
|
128
|
-
default:
|
|
129
|
-
|
|
136
|
+
default: G(() => [
|
|
137
|
+
K(M)["button-drop"] ? O(t.$slots, "button-drop", {
|
|
130
138
|
key: 0,
|
|
131
139
|
item: r.value,
|
|
132
140
|
editMode: v.value,
|
|
133
141
|
isCreate: a.value,
|
|
134
|
-
canUpdate:
|
|
135
|
-
canDrop:
|
|
136
|
-
}) : (c(),
|
|
142
|
+
canUpdate: B.value,
|
|
143
|
+
canDrop: _.value
|
|
144
|
+
}) : (c(), h("span", he, N(u.dropText), 1))
|
|
137
145
|
]),
|
|
138
146
|
_: 3
|
|
139
147
|
}, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"])), [
|
|
140
|
-
[
|
|
148
|
+
[I, H.value]
|
|
141
149
|
]),
|
|
142
|
-
|
|
143
|
-
ref: (
|
|
150
|
+
V(Q(R, {
|
|
151
|
+
ref: (y) => g.value = y,
|
|
144
152
|
palette: "success",
|
|
145
|
-
disabled: !
|
|
146
|
-
"confirm-modal":
|
|
147
|
-
"confirm-data":
|
|
148
|
-
resource:
|
|
149
|
-
"resource-data":
|
|
150
|
-
onLoading:
|
|
151
|
-
onLoaded:
|
|
152
|
-
onClick:
|
|
153
|
+
disabled: !E.value,
|
|
154
|
+
"confirm-modal": Y.value,
|
|
155
|
+
"confirm-data": Z.value,
|
|
156
|
+
resource: x.value,
|
|
157
|
+
"resource-data": ee.value,
|
|
158
|
+
onLoading: J,
|
|
159
|
+
onLoaded: F,
|
|
160
|
+
onClick: ue
|
|
153
161
|
}, {
|
|
154
|
-
default:
|
|
155
|
-
|
|
162
|
+
default: G(() => [
|
|
163
|
+
K(M)["button-save"] ? O(t.$slots, "button-save", {
|
|
156
164
|
key: 0,
|
|
157
165
|
item: r.value,
|
|
158
166
|
editMode: v.value,
|
|
159
167
|
isCreate: a.value,
|
|
160
|
-
canUpdate:
|
|
161
|
-
canDrop:
|
|
162
|
-
}) : (c(),
|
|
168
|
+
canUpdate: B.value,
|
|
169
|
+
canDrop: _.value
|
|
170
|
+
}) : (c(), h("span", Se, N(u.saveText), 1))
|
|
163
171
|
]),
|
|
164
172
|
_: 3
|
|
165
173
|
}, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"]), [
|
|
166
|
-
[
|
|
174
|
+
[I, A.value]
|
|
167
175
|
]),
|
|
168
|
-
|
|
176
|
+
V(Q(re, {
|
|
169
177
|
modelValue: v.value,
|
|
170
|
-
"onUpdate:modelValue":
|
|
171
|
-
label:
|
|
178
|
+
"onUpdate:modelValue": l[0] || (l[0] = (y) => v.value = y),
|
|
179
|
+
label: u.editModeText
|
|
172
180
|
}, null, 8, ["modelValue", "label"]), [
|
|
173
|
-
[
|
|
181
|
+
[I, P.value]
|
|
174
182
|
])
|
|
175
183
|
], 512), [
|
|
176
|
-
[
|
|
184
|
+
[I, oe.value]
|
|
177
185
|
]),
|
|
178
|
-
|
|
179
|
-
f.value ? (c(),
|
|
180
|
-
|
|
186
|
+
o.value ? D("", !0) : (c(), h("div", ke, [
|
|
187
|
+
f.value ? (c(), h("div", be, [
|
|
188
|
+
m.value ? (c(), q(z, {
|
|
181
189
|
key: 0,
|
|
182
190
|
code: i.value,
|
|
183
191
|
quick: "",
|
|
184
192
|
palette: i.value === 200 ? "success" : "danger",
|
|
185
193
|
"can-close": "",
|
|
186
|
-
onClose:
|
|
194
|
+
onClose: l[1] || (l[1] = (y) => m.value = !1)
|
|
187
195
|
}, null, 8, ["code", "palette"])) : D("", !0),
|
|
188
196
|
O(t.$slots, "item", {
|
|
189
197
|
item: r.value,
|
|
190
|
-
loading:
|
|
198
|
+
loading: o.value,
|
|
191
199
|
editMode: v.value,
|
|
192
200
|
isCreate: a.value,
|
|
193
|
-
canUpdate:
|
|
194
|
-
canDrop:
|
|
201
|
+
canUpdate: B.value,
|
|
202
|
+
canDrop: _.value
|
|
195
203
|
})
|
|
196
|
-
])) : (c(),
|
|
204
|
+
])) : (c(), q(z, {
|
|
197
205
|
key: 1,
|
|
198
206
|
code: i.value
|
|
199
207
|
}, null, 8, ["code"]))
|
|
200
208
|
])),
|
|
201
|
-
|
|
209
|
+
o.value ? (c(), q(de, { key: 2 })) : D("", !0)
|
|
202
210
|
]);
|
|
203
211
|
};
|
|
204
212
|
}
|
|
205
|
-
}),
|
|
206
|
-
install: (
|
|
207
|
-
|
|
213
|
+
}), Ve = {
|
|
214
|
+
install: (u, $ = {}) => {
|
|
215
|
+
u.component("lkt-item-crud") === void 0 && u.component("lkt-item-crud", ge);
|
|
208
216
|
}
|
|
209
217
|
};
|
|
210
218
|
export {
|
|
211
|
-
|
|
219
|
+
Oe as debugLktItemCrud,
|
|
220
|
+
Ve as default
|
|
212
221
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -306,14 +306,14 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
306
306
|
"button-drop"?(_: {
|
|
307
307
|
item: Record<string, any>;
|
|
308
308
|
editMode: boolean;
|
|
309
|
-
isCreate:
|
|
309
|
+
isCreate: false;
|
|
310
310
|
canUpdate: boolean;
|
|
311
311
|
canDrop: boolean;
|
|
312
312
|
}): any;
|
|
313
313
|
"button-save"?(_: {
|
|
314
314
|
item: Record<string, any>;
|
|
315
315
|
editMode: boolean;
|
|
316
|
-
isCreate:
|
|
316
|
+
isCreate: boolean;
|
|
317
317
|
canUpdate: boolean;
|
|
318
318
|
canDrop: boolean;
|
|
319
319
|
}): any;
|
|
@@ -321,7 +321,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
321
321
|
item: Record<string, any>;
|
|
322
322
|
loading: false;
|
|
323
323
|
editMode: boolean;
|
|
324
|
-
isCreate:
|
|
324
|
+
isCreate: boolean;
|
|
325
325
|
canUpdate: boolean;
|
|
326
326
|
canDrop: boolean;
|
|
327
327
|
}): any;
|
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ export default {name: "LktItemCrud", inheritAttrs: false}
|
|
|
6
6
|
import {ref, watch, useSlots, computed} from "vue";
|
|
7
7
|
import {httpCall, HTTPResponse} from "lkt-http-client";
|
|
8
8
|
import {DataState} from "lkt-data-state";
|
|
9
|
+
import {debug} from "../functions/debug";
|
|
9
10
|
|
|
10
11
|
const props = defineProps({
|
|
11
12
|
modelValue: {type: Object, required: false, default: () => ({})},
|
|
@@ -63,7 +64,7 @@ const isLoading = ref(true),
|
|
|
63
64
|
saveButton = ref(null),
|
|
64
65
|
dropButton = ref(null),
|
|
65
66
|
dataState = ref(new DataState(item.value)),
|
|
66
|
-
createMode = ref(
|
|
67
|
+
createMode = ref(props.isCreate);
|
|
67
68
|
|
|
68
69
|
const saveConfirm = computed(() => {
|
|
69
70
|
return createMode.value
|
|
@@ -95,11 +96,13 @@ const saveConfirm = computed(() => {
|
|
|
95
96
|
canDrop = computed(() => !createMode.value && perms.value.includes('drop'));
|
|
96
97
|
|
|
97
98
|
const fetchItem = async () => {
|
|
99
|
+
debug('fetchItem');
|
|
98
100
|
isLoading.value = true;
|
|
99
101
|
httpStatus.value = -1;
|
|
100
102
|
showStoreMessage.value = false;
|
|
101
103
|
try {
|
|
102
104
|
const r = await httpCall(props.readResource, props.readData);
|
|
105
|
+
debug('fetchItem -> response', r);
|
|
103
106
|
isLoading.value = false;
|
|
104
107
|
httpStatus.value = r.httpStatus;
|
|
105
108
|
if (!r.success) {
|
|
@@ -172,6 +175,7 @@ const onDrop = ($event: PointerEvent, r: HTTPResponse) => {
|
|
|
172
175
|
|
|
173
176
|
},
|
|
174
177
|
onSave = ($event: PointerEvent, r: HTTPResponse) => {
|
|
178
|
+
debug('onSave -> received response:', r);
|
|
175
179
|
if (saveResource.value) {
|
|
176
180
|
isLoading.value = false;
|
|
177
181
|
httpStatus.value = r.httpStatus;
|
|
@@ -184,18 +188,27 @@ const onDrop = ($event: PointerEvent, r: HTTPResponse) => {
|
|
|
184
188
|
}
|
|
185
189
|
let emits: 'create' | 'update' = createMode.value ? 'create' : 'update';
|
|
186
190
|
if (!createMode.value) {
|
|
191
|
+
debug('onSave -> turn stored data into original');
|
|
187
192
|
dataState.value.turnStoredIntoOriginal();
|
|
188
193
|
}
|
|
189
194
|
|
|
190
195
|
if (r.autoReloadId) {
|
|
196
|
+
debug('onSave -> autoReloadId detected: ', r.autoReloadId);
|
|
191
197
|
props.readData['id'] = r.autoReloadId;
|
|
198
|
+
debug('onSave -> turning off create mode');
|
|
192
199
|
createMode.value = false;
|
|
193
200
|
fetchItem();
|
|
194
201
|
}
|
|
195
202
|
if (createMode.value) {
|
|
196
|
-
if (typeof props.onCreate === 'function')
|
|
203
|
+
if (typeof props.onCreate === 'function') {
|
|
204
|
+
debug('onSave -> trigger onCreate callback');
|
|
205
|
+
props.onCreate();
|
|
206
|
+
}
|
|
197
207
|
} else {
|
|
198
|
-
if (typeof props.onUpdate === 'function')
|
|
208
|
+
if (typeof props.onUpdate === 'function') {
|
|
209
|
+
debug('onSave -> trigger onUpdate callback');
|
|
210
|
+
props.onUpdate();
|
|
211
|
+
}
|
|
199
212
|
}
|
|
200
213
|
emit(emits, r)
|
|
201
214
|
},
|