lkt-item-crud 1.1.6 → 1.1.8

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 { _e as default };
2
- declare namespace _e {
3
- function install(o: any, I?: {}): 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 oe, useSlots as re, ref as s, computed as d, watch as k, resolveComponent as w, openBlock as c, createElementBlock as y, createElementVNode as j, toDisplayString as U, renderSlot as O, createCommentVNode as D, withDirectives as R, createBlock as V, withCtx as H, unref as P, vShow as q, createVNode as z } from "vue";
2
- import { httpCall as de } from "lkt-http-client";
3
- import { DataState as ne } from "lkt-data-state";
4
- const se = { class: "lkt-item-crud" }, ie = {
1
+ import { defineComponent as ne, useSlots as se, ref as s, computed as d, watch as D, resolveComponent as w, openBlock as c, createElementBlock as h, createElementVNode as j, toDisplayString as N, renderSlot as O, createCommentVNode as g, 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
- }, ce = { class: "lkt-item-crud_header-title" }, ve = { class: "lkt-item-crud_header-slot" }, fe = { class: "lkt-item-crud-buttons" }, pe = { key: 1 }, me = { key: 1 }, ye = {
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
- }, he = {
18
+ }, be = {
11
19
  key: 0,
12
20
  class: "lkt-grid-1"
13
- }, Se = { name: "LktItemCrud", inheritAttrs: !1 }, ke = /* @__PURE__ */ oe({
14
- ...Se,
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(o, { expose: I, emit: G }) {
48
- const e = o, L = re(), n = G;
49
- let K = [];
50
- const l = s(!0), r = s(e.modelValue), h = s(K), v = s(!1), f = s(!1), p = s(!1), i = s(200), C = s(null), b = s(null), S = s(new ne(r.value)), a = s(a.value), Q = d(() => a.value ? e.createConfirm : e.updateConfirm), W = d(() => a.value ? e.createConfirmData : e.updateConfirmData), N = d(() => a.value ? e.createResource : e.updateResource), X = d(() => a.value ? { ...e.createData, ...JSON.parse(JSON.stringify(r.value)) } : { ...e.updateData, ...JSON.parse(JSON.stringify(r.value)) }), Y = d(() => a.value ? e.createDisabled : e.updateDisabled), g = d(() => !a.value && h.value.includes("update")), B = d(() => !a.value && h.value.includes("drop")), M = async () => {
51
- l.value = !0, i.value = -1, p.value = !1;
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), C = s(null), B = 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), _ = d(() => !a.value && S.value.includes("update")), R = 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 de(e.readResource, e.readData);
54
- if (l.value = !1, i.value = t.httpStatus, !t.success) {
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, h.value = t.perms, S.value.increment(r.value).turnStoredIntoOriginal(), n("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, i.value = 404, n("error", 404);
68
+ o.value = !1, f.value = !1, i.value = 404, n("error", 404);
61
69
  return;
62
70
  }
63
- }, Z = d(() => l.value ? !1 : e.title || !!L["post-title"]);
64
- k(() => e.modelValue, (t) => {
65
- r.value = t, S.value.increment(t);
66
- }, { deep: !0 }), k(r, (t) => {
67
- n("update:modelValue", r.value), S.value.increment(t);
68
- }, { deep: !0 }), k(h, () => n("perms", h.value));
69
- const T = d(() => Y.value || !a.value && !g.value || typeof e.saveValidator == "function" && !e.saveValidator(r.value) ? !1 : S.value.changed());
70
- k(T, (t) => n("modified-data", t)), k(a, (t) => n("update:isCreate", t)), e.readResource && !a.value ? M() : a.value && (f.value = !0, v.value = !0, l.value = !1);
71
- const ee = (t, u) => {
72
- if (l.value = !1, i.value = u.httpStatus, !u.success) {
73
- p.value = !0, n("error", u.httpStatus);
71
+ }, ae = d(() => o.value ? !1 : e.title || !!M["post-title"]);
72
+ D(() => e.modelValue, (t) => {
73
+ r.value = t, k.value.increment(t);
74
+ }, { deep: !0 }), D(r, (t) => {
75
+ n("update:modelValue", r.value), k.value.increment(t);
76
+ }, { deep: !0 }), D(S, () => n("perms", S.value));
77
+ const E = d(() => te.value || !a.value && !_.value || typeof e.saveValidator == "function" && !e.saveValidator(r.value) ? !1 : k.value.changed());
78
+ D(E, (t) => n("modified-data", t)), D(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
- p.value = !0, n("drop", u);
77
- }, te = (t, u) => {
78
- if (N.value) {
79
- if (l.value = !1, i.value = u.httpStatus, !u.success) {
80
- p.value = !0, n("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
- p.value = !0;
91
+ m.value = !0;
84
92
  }
85
- let _ = a.value ? "create" : "update";
86
- a.value || S.value.turnStoredIntoOriginal(), u.autoReloadId && (e.readData.id = u.autoReloadId, a.value = !1, M()), a.value ? typeof e.onCreate == "function" && e.onCreate() : typeof e.onUpdate == "function" && e.onUpdate(), n(_, u);
87
- }, $ = () => {
88
- l.value = !0, i.value = -1;
89
- }, x = () => {
90
- l.value = !1;
93
+ let b = 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()), b === "create" ? typeof e.onCreate == "function" && (p("onSave -> trigger onCreate callback"), e.onCreate()) : typeof e.onUpdate == "function" && (p("onSave -> trigger onUpdate callback"), e.onUpdate()), n(b, l);
95
+ }, J = () => {
96
+ o.value = !0, i.value = -1;
97
+ }, F = () => {
98
+ o.value = !1;
91
99
  };
92
- I({
100
+ $({
93
101
  doDrop: () => {
94
- b.value && typeof b.value.click == "function" && b.value.click();
102
+ B.value && typeof B.value.click == "function" && B.value.click();
95
103
  },
96
- doRefresh: M,
104
+ doRefresh: U,
97
105
  doSave: () => {
98
106
  C.value && typeof C.value.click == "function" && C.value.click();
99
107
  }
100
108
  });
101
- const J = d(() => !e.hiddenDrop && !l.value && v.value && f.value), E = d(() => l.value ? !1 : a.value ? !0 : !e.hiddenSave && v.value && f.value), F = d(() => !l.value && !a.value && f.value), ae = d(() => !e.hiddenButtons && (E.value || J.value || F.value));
102
- return (t, u) => {
103
- const _ = w("lkt-button"), le = w("lkt-field-switch"), A = w("lkt-http-info"), ue = w("lkt-loader");
104
- return c(), y("article", se, [
105
- Z.value ? (c(), y("header", ie, [
106
- j("h1", ce, U(o.title), 1),
107
- j("div", ve, [
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 b = 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
- ])) : D("", !0),
114
- R(j("div", fe, [
115
- a.value ? D("", !0) : R((c(), V(_, {
121
+ ])) : g("", !0),
122
+ V(j("div", ye, [
123
+ a.value ? g("", !0) : V((c(), q(b, {
116
124
  key: 0,
117
- ref: (m) => b.value = m,
125
+ ref: (y) => B.value = y,
118
126
  palette: "danger",
119
- disabled: o.dropDisabled || !B.value,
120
- "confirm-modal": o.dropConfirm,
121
- "confirm-data": o.dropConfirmData,
122
- resource: o.dropResource,
123
- "resource-data": o.dropData,
124
- onLoading: $,
125
- onLoaded: x,
126
- onClick: ee
127
+ disabled: u.dropDisabled || !R.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: H(() => [
129
- P(L)["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
140
  editMode: v.value,
133
141
  isCreate: a.value,
134
- canUpdate: g.value,
135
- canDrop: B.value
136
- }) : (c(), y("span", pe, U(o.dropText), 1))
142
+ canUpdate: _.value,
143
+ canDrop: R.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, J.value]
148
+ [I, H.value]
141
149
  ]),
142
- R(z(_, {
143
- ref: (m) => C.value = m,
150
+ V(Q(b, {
151
+ ref: (y) => C.value = y,
144
152
  palette: "success",
145
- disabled: !T.value,
146
- "confirm-modal": Q.value,
147
- "confirm-data": W.value,
148
- resource: N.value,
149
- "resource-data": X.value,
150
- onLoading: $,
151
- onLoaded: x,
152
- onClick: te
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: H(() => [
155
- P(L)["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
166
  editMode: v.value,
159
167
  isCreate: a.value,
160
- canUpdate: g.value,
161
- canDrop: B.value
162
- }) : (c(), y("span", me, U(o.saveText), 1))
168
+ canUpdate: _.value,
169
+ canDrop: R.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, E.value]
174
+ [I, A.value]
167
175
  ]),
168
- R(z(le, {
176
+ V(Q(re, {
169
177
  modelValue: v.value,
170
- "onUpdate:modelValue": u[0] || (u[0] = (m) => v.value = m),
171
- label: o.editModeText
178
+ "onUpdate:modelValue": l[0] || (l[0] = (y) => v.value = y),
179
+ label: u.editModeText
172
180
  }, null, 8, ["modelValue", "label"]), [
173
- [q, F.value]
181
+ [I, P.value]
174
182
  ])
175
183
  ], 512), [
176
- [q, ae.value]
184
+ [I, oe.value]
177
185
  ]),
178
- l.value ? D("", !0) : (c(), y("div", ye, [
179
- f.value ? (c(), y("div", he, [
180
- p.value ? (c(), V(A, {
186
+ o.value ? g("", !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: u[1] || (u[1] = (m) => p.value = !1)
187
- }, null, 8, ["code", "palette"])) : D("", !0),
194
+ onClose: l[1] || (l[1] = (y) => m.value = !1)
195
+ }, null, 8, ["code", "palette"])) : g("", !0),
188
196
  O(t.$slots, "item", {
189
197
  item: r.value,
190
- loading: l.value,
198
+ loading: o.value,
191
199
  editMode: v.value,
192
200
  isCreate: a.value,
193
- canUpdate: g.value,
194
- canDrop: B.value
201
+ canUpdate: _.value,
202
+ canDrop: R.value
195
203
  })
196
- ])) : (c(), V(A, {
204
+ ])) : (c(), q(z, {
197
205
  key: 1,
198
206
  code: i.value
199
207
  }, null, 8, ["code"]))
200
208
  ])),
201
- l.value ? (c(), V(ue, { key: 2 })) : D("", !0)
209
+ o.value ? (c(), q(de, { key: 2 })) : g("", !0)
202
210
  ]);
203
211
  };
204
212
  }
205
- }), _e = {
206
- install: (o, I = {}) => {
207
- o.component("lkt-item-crud") === void 0 && o.component("lkt-item-crud", ke);
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
- _e 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";
@@ -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: any;
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: any;
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: any;
324
+ isCreate: boolean;
325
325
  canUpdate: boolean;
326
326
  canDrop: boolean;
327
327
  }): any;
@@ -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.6",
3
+ "version": "1.1.8",
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: () => ({})},
@@ -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(createMode.value);
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
- if (createMode.value) {
196
- if (typeof props.onCreate === 'function') props.onCreate();
202
+ if (emits === 'create') {
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') props.onUpdate();
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
  },