lkt-item-crud 1.1.5 → 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 CHANGED
@@ -1,4 +1,5 @@
1
- export { Be as default };
2
- declare namespace Be {
3
- function install(a: any, U?: {}): void;
1
+ declare function Oe(u?: boolean): void;
2
+ declare namespace Ve {
3
+ function install(u: any, $?: {}): void;
4
4
  }
5
+ export { Oe as debugLktItemCrud, Ve as default };
package/dist/build.js CHANGED
@@ -1,17 +1,25 @@
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
- import { httpCall as oe } from "lkt-http-client";
3
- import { DataState as de } from "lkt-data-state";
4
- const ne = { class: "lkt-item-crud" }, se = {
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
- }, 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 = {
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
- }, ye = {
18
+ }, be = {
11
19
  key: 0,
12
20
  class: "lkt-grid-1"
13
- }, Ce = { name: "LktItemCrud", inheritAttrs: !1 }, he = /* @__PURE__ */ ue({
14
- ...Ce,
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: "" },
@@ -43,170 +51,171 @@ const ne = { class: "lkt-item-crud" }, se = {
43
51
  onCreate: { type: Function, required: !1, default: () => !0 },
44
52
  onUpdate: { type: Function, required: !1, default: () => !0 }
45
53
  },
46
- emits: ["update:modelValue", "read", "create", "update", "drop", "perms", "error", "modified-data"],
47
- setup(a, { expose: U, emit: z }) {
48
- const e = a, _ = re(), d = z;
49
- let G = [];
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;
54
+ emits: ["update:modelValue", "update:isCreate", "read", "create", "update", "drop", "perms", "error", "modified-data"],
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 oe(e.readResource, e.readData);
54
- if (l.value = !1, n.value = t.httpStatus, !t.success) {
55
- f.value = !1, n.value = t.httpStatus, d("error", t.httpStatus);
61
+ const t = await ie(e.readResource, e.readData);
62
+ if (p("fetchItem -> response", t), o.value = !1, i.value = t.httpStatus, !t.success) {
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, y.value = t.perms, C.value.increment(r.value).turnStoredIntoOriginal(), d("read", t);
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
- l.value = !1, f.value = !1, n.value = 404, d("error", 404);
68
+ o.value = !1, f.value = !1, i.value = 404, n("error", 404);
61
69
  return;
62
70
  }
63
- }, Y = o(() => l.value ? !1 : e.title || !!_["post-title"]);
64
- B(() => e.modelValue, (t) => {
65
- r.value = t, C.value.increment(t);
66
- }, { deep: !0 }), B(r, (t) => {
67
- d("update:modelValue", r.value), C.value.increment(t);
68
- }, { deep: !0 }), B(y, () => d("perms", y.value));
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);
71
- const Z = (t, u) => {
72
- if (l.value = !1, n.value = u.httpStatus, !u.success) {
73
- v.value = !0, d("error", u.httpStatus);
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
- v.value = !0, d("drop", u);
77
- }, ee = (t, u) => {
78
- if (I.value) {
79
- if (l.value = !1, n.value = u.httpStatus, !u.success) {
80
- v.value = !0, d("error", u.httpStatus);
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
- v.value = !0;
91
+ m.value = !0;
84
92
  }
85
- let g = e.isCreate ? "create" : "update";
86
- e.isCreate || C.value.turnStoredIntoOriginal(), u.autoReloadId && (e.readData.id = u.autoReloadId, L()), e.isCreate ? typeof e.onCreate == "function" && e.onCreate() : typeof e.onUpdate == "function" && e.onUpdate(), d(g, u);
87
- }, T = () => {
88
- l.value = !0, n.value = -1;
89
- }, $ = () => {
90
- l.value = !1;
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
- U({
100
+ $({
93
101
  doDrop: () => {
94
- k.value && typeof k.value.click == "function" && k.value.click();
102
+ C.value && typeof C.value.click == "function" && C.value.click();
95
103
  },
96
- doRefresh: L,
104
+ doRefresh: U,
97
105
  doSave: () => {
98
- S.value && typeof S.value.click == "function" && S.value.click();
106
+ g.value && typeof g.value.click == "function" && g.value.click();
99
107
  }
100
108
  });
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));
102
- return (t, u) => {
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, [
106
- j("h1", ie, M(a.title), 1),
107
- j("div", ce, [
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: l.value
118
+ loading: o.value
111
119
  })
112
120
  ])
113
- ])) : h("", !0),
114
- R(j("div", fe, [
115
- a.isCreate ? h("", !0) : R((i(), V(g, {
121
+ ])) : D("", !0),
122
+ V(j("div", ye, [
123
+ a.value ? D("", !0) : V((c(), q(R, {
116
124
  key: 0,
117
- ref: (p) => k.value = p,
125
+ ref: (y) => C.value = y,
118
126
  palette: "danger",
119
- disabled: a.dropDisabled || !b.value,
120
- "confirm-modal": a.dropConfirm,
121
- "confirm-data": a.dropConfirmData,
122
- resource: a.dropResource,
123
- "resource-data": a.dropData,
124
- onLoading: T,
125
- onLoaded: $,
126
- onClick: Z
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: A(() => [
129
- H(_)["button-drop"] ? O(t.$slots, "button-drop", {
136
+ default: G(() => [
137
+ K(M)["button-drop"] ? O(t.$slots, "button-drop", {
130
138
  key: 0,
131
139
  item: r.value,
132
- editMode: c.value,
133
- isCreate: a.isCreate,
134
- canUpdate: D.value,
135
- canDrop: b.value
136
- }) : (i(), m("span", ve, M(a.dropText), 1))
140
+ editMode: v.value,
141
+ isCreate: a.value,
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
- [q, x.value]
148
+ [I, H.value]
141
149
  ]),
142
- R(P(g, {
143
- ref: (p) => S.value = p,
150
+ V(Q(R, {
151
+ ref: (y) => g.value = y,
144
152
  palette: "success",
145
- disabled: !N.value,
146
- "confirm-modal": K.value,
147
- "confirm-data": Q.value,
148
- resource: I.value,
149
- "resource-data": W.value,
150
- onLoading: T,
151
- onLoaded: $,
152
- onClick: ee
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: A(() => [
155
- H(_)["button-save"] ? O(t.$slots, "button-save", {
162
+ default: G(() => [
163
+ K(M)["button-save"] ? O(t.$slots, "button-save", {
156
164
  key: 0,
157
165
  item: r.value,
158
- editMode: c.value,
159
- isCreate: a.isCreate,
160
- canUpdate: D.value,
161
- canDrop: b.value
162
- }) : (i(), m("span", pe, M(a.saveText), 1))
166
+ editMode: v.value,
167
+ isCreate: a.value,
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
- [q, J.value]
174
+ [I, A.value]
167
175
  ]),
168
- R(P(ae, {
169
- modelValue: c.value,
170
- "onUpdate:modelValue": u[0] || (u[0] = (p) => c.value = p),
171
- label: a.editModeText
176
+ V(Q(re, {
177
+ modelValue: v.value,
178
+ "onUpdate:modelValue": l[0] || (l[0] = (y) => v.value = y),
179
+ label: u.editModeText
172
180
  }, null, 8, ["modelValue", "label"]), [
173
- [q, E.value]
181
+ [I, P.value]
174
182
  ])
175
183
  ], 512), [
176
- [q, te.value]
184
+ [I, oe.value]
177
185
  ]),
178
- l.value ? h("", !0) : (i(), m("div", me, [
179
- f.value ? (i(), m("div", ye, [
180
- v.value ? (i(), V(F, {
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
- code: n.value,
190
+ code: i.value,
183
191
  quick: "",
184
- palette: n.value === 200 ? "success" : "danger",
192
+ palette: i.value === 200 ? "success" : "danger",
185
193
  "can-close": "",
186
- onClose: u[1] || (u[1] = (p) => v.value = !1)
187
- }, null, 8, ["code", "palette"])) : h("", !0),
194
+ onClose: l[1] || (l[1] = (y) => m.value = !1)
195
+ }, null, 8, ["code", "palette"])) : D("", !0),
188
196
  O(t.$slots, "item", {
189
197
  item: r.value,
190
- loading: l.value,
191
- editMode: c.value,
192
- isCreate: a.isCreate,
193
- canUpdate: D.value,
194
- canDrop: b.value
198
+ loading: o.value,
199
+ editMode: v.value,
200
+ isCreate: a.value,
201
+ canUpdate: B.value,
202
+ canDrop: _.value
195
203
  })
196
- ])) : (i(), V(F, {
204
+ ])) : (c(), q(z, {
197
205
  key: 1,
198
- code: n.value
206
+ code: i.value
199
207
  }, null, 8, ["code"]))
200
208
  ])),
201
- l.value ? (i(), V(le, { key: 2 })) : h("", !0)
209
+ o.value ? (c(), q(de, { key: 2 })) : D("", !0)
202
210
  ]);
203
211
  };
204
212
  }
205
- }), Be = {
206
- install: (a, U = {}) => {
207
- a.component("lkt-item-crud") === void 0 && a.component("lkt-item-crud", he);
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
- Be as default
219
+ Oe as debugLktItemCrud,
220
+ Ve as default
212
221
  };
@@ -0,0 +1,2 @@
1
+ export declare const debug: (...args: any[]) => void;
2
+ export declare const debugLktItemCrud: (state?: boolean) => void;
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ import { Plugin } from "vue";
2
2
  import "./../lkt-item-crud.css";
3
3
  declare const LktItemCrud: Plugin;
4
4
  export default LktItemCrud;
5
+ export { debugLktItemCrud } from "./functions/debug";
@@ -132,6 +132,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
132
132
  drop: (...args: any[]) => void;
133
133
  update: (...args: any[]) => void;
134
134
  "update:modelValue": (...args: any[]) => void;
135
+ "update:isCreate": (...args: any[]) => void;
135
136
  read: (...args: any[]) => void;
136
137
  create: (...args: any[]) => void;
137
138
  perms: (...args: any[]) => void;
@@ -266,6 +267,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
266
267
  onDrop?: ((...args: any[]) => any) | undefined;
267
268
  onUpdate?: ((...args: any[]) => any) | undefined;
268
269
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
270
+ "onUpdate:isCreate"?: ((...args: any[]) => any) | undefined;
269
271
  onRead?: ((...args: any[]) => any) | undefined;
270
272
  onCreate?: ((...args: any[]) => any) | undefined;
271
273
  onPerms?: ((...args: any[]) => any) | undefined;
@@ -0,0 +1,3 @@
1
+ export declare class Settings {
2
+ static debugEnabled: boolean;
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lkt-item-crud",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "module": "./dist/build.js",
@@ -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: () => ({})},
@@ -49,7 +50,7 @@ const props = defineProps({
49
50
 
50
51
  const slots = useSlots();
51
52
 
52
- const emit = defineEmits(['update:modelValue', 'read', 'create', 'update', 'drop', 'perms', 'error', 'modified-data']);
53
+ const emit = defineEmits(['update:modelValue', 'update:isCreate', 'read', 'create', 'update', 'drop', 'perms', 'error', 'modified-data']);
53
54
 
54
55
  let basePerms: string[] = [];
55
56
 
@@ -62,43 +63,46 @@ const isLoading = ref(true),
62
63
  httpStatus = ref(200),
63
64
  saveButton = ref(null),
64
65
  dropButton = ref(null),
65
- dataState = ref(new DataState(item.value));
66
+ dataState = ref(new DataState(item.value)),
67
+ createMode = ref(props.isCreate);
66
68
 
67
69
  const saveConfirm = computed(() => {
68
- return props.isCreate
70
+ return createMode.value
69
71
  ? props.createConfirm
70
72
  : props.updateConfirm;
71
73
  }),
72
74
  confirmData = computed(() => {
73
- return props.isCreate
75
+ return createMode.value
74
76
  ? props.createConfirmData
75
77
  : props.updateConfirmData;
76
78
  }),
77
79
  saveResource = computed(() => {
78
- return props.isCreate
80
+ return createMode.value
79
81
  ? props.createResource
80
82
  : props.updateResource;
81
83
  }),
82
84
  saveData = computed(() => {
83
- if (props.isCreate) {
85
+ if (createMode.value) {
84
86
  return {...props.createData, ...JSON.parse(JSON.stringify(item.value))};
85
87
  }
86
88
  return {...props.updateData, ...JSON.parse(JSON.stringify(item.value))};
87
89
  }),
88
90
  saveDisabled = computed(() => {
89
- return props.isCreate
91
+ return createMode.value
90
92
  ? props.createDisabled
91
93
  : props.updateDisabled;
92
94
  }),
93
- canUpdate = computed(() => !props.isCreate && perms.value.includes('update')),
94
- canDrop = computed(() => !props.isCreate && perms.value.includes('drop'));
95
+ canUpdate = computed(() => !createMode.value && perms.value.includes('update')),
96
+ canDrop = computed(() => !createMode.value && perms.value.includes('drop'));
95
97
 
96
98
  const fetchItem = async () => {
99
+ debug('fetchItem');
97
100
  isLoading.value = true;
98
101
  httpStatus.value = -1;
99
102
  showStoreMessage.value = false;
100
103
  try {
101
104
  const r = await httpCall(props.readResource, props.readData);
105
+ debug('fetchItem -> response', r);
102
106
  isLoading.value = false;
103
107
  httpStatus.value = r.httpStatus;
104
108
  if (!r.success) {
@@ -141,17 +145,18 @@ watch(perms, () => emit('perms', perms.value));
141
145
 
142
146
  const ableToSave = computed(() => {
143
147
  if (saveDisabled.value) return false;
144
- if (!props.isCreate && !canUpdate.value) return false;
148
+ if (!createMode.value && !canUpdate.value) return false;
145
149
 
146
150
  if (typeof props.saveValidator === 'function' && !props.saveValidator(item.value)) return false;
147
151
 
148
152
  return dataState.value.changed();
149
153
  });
150
154
  watch(ableToSave, (v) => emit('modified-data', v));
155
+ watch(createMode, (v) => emit('update:isCreate', v));
151
156
 
152
157
  // Fetch item
153
- if (props.readResource && !props.isCreate) fetchItem();
154
- else if (props.isCreate) {
158
+ if (props.readResource && !createMode.value) fetchItem();
159
+ else if (createMode.value) {
155
160
  httpSuccessRead.value = true;
156
161
  editMode.value = true;
157
162
  isLoading.value = false;
@@ -170,6 +175,7 @@ const onDrop = ($event: PointerEvent, r: HTTPResponse) => {
170
175
 
171
176
  },
172
177
  onSave = ($event: PointerEvent, r: HTTPResponse) => {
178
+ debug('onSave -> received response:', r);
173
179
  if (saveResource.value) {
174
180
  isLoading.value = false;
175
181
  httpStatus.value = r.httpStatus;
@@ -180,19 +186,29 @@ const onDrop = ($event: PointerEvent, r: HTTPResponse) => {
180
186
  }
181
187
  showStoreMessage.value = true;
182
188
  }
183
- let emits: 'create' | 'update' = props.isCreate ? 'create' : 'update';
184
- if (!props.isCreate) {
189
+ let emits: 'create' | 'update' = createMode.value ? 'create' : 'update';
190
+ if (!createMode.value) {
191
+ debug('onSave -> turn stored data into original');
185
192
  dataState.value.turnStoredIntoOriginal();
186
193
  }
187
194
 
188
195
  if (r.autoReloadId) {
196
+ debug('onSave -> autoReloadId detected: ', r.autoReloadId);
189
197
  props.readData['id'] = r.autoReloadId;
198
+ debug('onSave -> turning off create mode');
199
+ createMode.value = false;
190
200
  fetchItem();
191
201
  }
192
- if (props.isCreate) {
193
- if (typeof props.onCreate === 'function') props.onCreate();
202
+ if (createMode.value) {
203
+ if (typeof props.onCreate === 'function') {
204
+ debug('onSave -> trigger onCreate callback');
205
+ props.onCreate();
206
+ }
194
207
  } else {
195
- if (typeof props.onUpdate === 'function') props.onUpdate();
208
+ if (typeof props.onUpdate === 'function') {
209
+ debug('onSave -> trigger onUpdate callback');
210
+ props.onUpdate();
211
+ }
196
212
  }
197
213
  emit(emits, r)
198
214
  },
@@ -227,7 +243,7 @@ const showDropButton = computed(() => {
227
243
  showSaveButton = computed(() => {
228
244
  if (isLoading.value) return false;
229
245
 
230
- if (props.isCreate) return true;
246
+ if (createMode.value) return true;
231
247
 
232
248
  return !props.hiddenSave
233
249
  && editMode.value
@@ -235,7 +251,7 @@ const showDropButton = computed(() => {
235
251
  }),
236
252
  showSwitchButton = computed(() => {
237
253
  return !isLoading.value
238
- && !props.isCreate
254
+ && !createMode.value
239
255
  && httpSuccessRead.value;
240
256
  }),
241
257
  showButtons = computed(() => {
@@ -255,7 +271,7 @@ const showDropButton = computed(() => {
255
271
  <lkt-button
256
272
  :ref="(el:any) => dropButton = el"
257
273
  v-show="showDropButton"
258
- v-if="!isCreate"
274
+ v-if="!createMode"
259
275
  palette="danger"
260
276
  v-bind:disabled="dropDisabled || !canDrop"
261
277
  v-bind:confirm-modal="dropConfirm"
@@ -267,7 +283,7 @@ const showDropButton = computed(() => {
267
283
  v-on:click="onDrop">
268
284
  <slot v-if="!!slots['button-drop']" name="button-drop" v-bind:item="item"
269
285
  v-bind:edit-mode="editMode"
270
- v-bind:is-create="isCreate"
286
+ v-bind:is-create="createMode"
271
287
  v-bind:can-update="canUpdate"
272
288
  v-bind:can-drop="canDrop"></slot>
273
289
  <span v-else>{{ dropText }}</span>
@@ -287,7 +303,7 @@ const showDropButton = computed(() => {
287
303
  v-on:click="onSave">
288
304
  <slot v-if="!!slots['button-save']" name="button-save" v-bind:item="item"
289
305
  v-bind:edit-mode="editMode"
290
- v-bind:is-create="isCreate"
306
+ v-bind:is-create="createMode"
291
307
  v-bind:can-update="canUpdate"
292
308
  v-bind:can-drop="canDrop"></slot>
293
309
  <span v-else>{{ saveText }}</span>
@@ -303,7 +319,7 @@ const showDropButton = computed(() => {
303
319
  :palette="httpStatus === 200 ? 'success' : 'danger'" can-close
304
320
  v-on:close="showStoreMessage = false"></lkt-http-info>
305
321
  <slot name="item" v-bind:item="item" v-bind:loading="isLoading" v-bind:edit-mode="editMode"
306
- v-bind:is-create="isCreate"
322
+ v-bind:is-create="createMode"
307
323
  v-bind:can-update="canUpdate"
308
324
  v-bind:can-drop="canDrop"></slot>
309
325
  </div>