lkt-item-crud 1.1.18 → 1.1.20

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 CHANGED
@@ -1,35 +1,35 @@
1
- import { defineComponent as ie, useSlots as ce, ref as s, computed as n, watch as M, nextTick as ve, resolveComponent as E, openBlock as v, createElementBlock as b, createElementVNode as J, toDisplayString as K, renderSlot as V, createCommentVNode as g, withDirectives as I, createBlock as N, withCtx as W, unref as X, vShow as L, createVNode as Y } from "vue";
1
+ import { defineComponent as ie, useSlots as ce, ref as s, computed as n, watch as B, nextTick as ve, resolveComponent as E, openBlock as v, createElementBlock as y, createElementVNode as J, toDisplayString as K, renderSlot as V, createCommentVNode as U, withDirectives as I, createBlock as N, withCtx as X, unref as Y, vShow as L, createVNode as Z } from "vue";
2
2
  import { httpCall as fe } from "lkt-http-client";
3
3
  import { DataState as pe } from "lkt-data-state";
4
4
  import { execModal as me, refreshModal as he, closeModal as ke, openModal as Ce, reOpenModal as be } from "lkt-modal";
5
- const j = class j {
5
+ const q = class q {
6
6
  };
7
- j.debugEnabled = !1;
8
- let O = j;
7
+ q.debugEnabled = !1;
8
+ let O = q;
9
9
  const r = (...l) => {
10
10
  O.debugEnabled && console.info("[LktItemCrud] ", ...l);
11
11
  }, Te = (l = !0) => {
12
12
  O.debugEnabled = l;
13
- }, Z = (l) => {
13
+ }, j = (l) => {
14
14
  r("runModalCallback -> init", l);
15
- let f = l.modalKey ? l.modalKey : "_", k = l.args ? l.args : {};
15
+ let f = l.modalKey ? l.modalKey : "_", D = l.args ? l.args : {};
16
16
  switch (l.action) {
17
17
  case "reOpen":
18
- return be(l.modalName, f, k);
18
+ return be(l.modalName, f, D);
19
19
  case "open":
20
- return Ce(l.modalName, f, k);
20
+ return Ce(l.modalName, f, D);
21
21
  case "close":
22
22
  return ke(l.modalName, f);
23
23
  case "refresh":
24
- return he(l.modalName, f, k);
24
+ return he(l.modalName, f, D);
25
25
  case "exec":
26
26
  let e = l.method;
27
- return e ? me(l.modalName, f, e, k) : void 0;
27
+ return e ? me(l.modalName, f, e, D) : void 0;
28
28
  }
29
29
  }, De = { class: "lkt-item-crud" }, Se = {
30
30
  key: 0,
31
31
  class: "lkt-item-crud_header"
32
- }, ye = { class: "lkt-item-crud_header-title" }, _e = { class: "lkt-item-crud_header-slot" }, Me = { class: "lkt-item-crud-buttons" }, ge = { key: 1 }, Be = { key: 1 }, Ue = {
32
+ }, ye = { class: "lkt-item-crud_header-title" }, Me = { class: "lkt-item-crud_header-slot" }, _e = { class: "lkt-item-crud-buttons" }, ge = { key: 1 }, Be = { key: 1 }, Ue = {
33
33
  key: 1,
34
34
  class: "lkt-item-crud_content"
35
35
  }, we = {
@@ -71,13 +71,14 @@ const r = (...l) => {
71
71
  insideModal: { type: Boolean, default: !1 },
72
72
  dataStateConfig: { default: () => ({}) },
73
73
  onCreateModalCallbacks: { default: () => [] },
74
- onUpdateModalCallbacks: { default: () => [] }
74
+ onUpdateModalCallbacks: { default: () => [] },
75
+ onDropModalCallbacks: { default: () => [] }
75
76
  },
76
77
  emits: ["update:modelValue", "update:isCreate", "read", "create", "update", "drop", "perms", "error", "modified-data"],
77
- setup(l, { expose: f, emit: k }) {
78
- const e = l, T = ce(), i = k;
78
+ setup(l, { expose: f, emit: D }) {
79
+ const e = l, T = ce(), i = D;
79
80
  let ee = [];
80
- const d = s(!0), u = s(e.modelValue), D = s(ee), p = s(!1), m = s(!1), h = s(!1), c = s(200), B = s(null), U = s(null), S = s(new pe(u.value, e.dataStateConfig)), o = s(e.isCreate), $ = s(!1), ae = n(() => o.value ? e.createConfirm : e.updateConfirm), te = n(() => o.value ? e.createConfirmData : e.updateConfirmData), q = n(() => o.value ? e.createResource : e.updateResource), le = n(() => o.value ? { ...e.createData, ...JSON.parse(JSON.stringify(u.value)) } : { ...e.updateData, ...JSON.parse(JSON.stringify(u.value)) }), oe = n(() => o.value ? e.createDisabled : e.updateDisabled), w = n(() => !o.value && D.value.includes("update")), R = n(() => !o.value && D.value.includes("drop")), F = async () => {
81
+ const d = s(!0), u = s(e.modelValue), M = s(ee), p = s(!1), m = s(!1), h = s(!1), c = s(200), w = s(null), R = s(null), _ = s(new pe(u.value, e.dataStateConfig)), o = s(e.isCreate), $ = s(!1), ae = n(() => o.value ? e.createConfirm : e.updateConfirm), te = n(() => o.value ? e.createConfirmData : e.updateConfirmData), H = n(() => o.value ? e.createResource : e.updateResource), le = n(() => o.value ? { ...e.createData, ...JSON.parse(JSON.stringify(u.value)) } : { ...e.updateData, ...JSON.parse(JSON.stringify(u.value)) }), oe = n(() => o.value ? e.createDisabled : e.updateDisabled), k = n(() => !o.value && M.value.includes("update")), C = n(() => !o.value && M.value.includes("drop")), F = async () => {
81
82
  r("fetchItem"), d.value = !0, c.value = -1, h.value = !1;
82
83
  try {
83
84
  const a = await fe(e.readResource, e.readData);
@@ -85,160 +86,162 @@ const r = (...l) => {
85
86
  m.value = !1, c.value = a.httpStatus, i("error", a.httpStatus);
86
87
  return;
87
88
  }
88
- m.value = !0, u.value = a.data, D.value = a.perms, S.value.increment(u.value).turnStoredIntoOriginal(), i("read", a);
89
+ m.value = !0, u.value = a.data, M.value = a.perms, _.value.increment(u.value).turnStoredIntoOriginal(), i("read", a);
89
90
  } catch {
90
91
  d.value = !1, m.value = !1, c.value = 404, i("error", 404);
91
92
  return;
92
93
  }
93
94
  }, ue = n(() => d.value ? !1 : e.title || !!T["post-title"]);
94
- M(() => e.modelValue, (a) => {
95
- u.value = a, S.value.increment(a);
96
- }, { deep: !0 }), M(u, (a) => {
95
+ B(() => e.modelValue, (a) => {
96
+ u.value = a, _.value.increment(a);
97
+ }, { deep: !0 }), B(u, (a) => {
97
98
  if ($.value = !0, r("item updated ->", u.value), typeof e.beforeEmitUpdate == "function") {
98
99
  r("item updated -> has beforeEmitUpdate");
99
100
  let t = e.beforeEmitUpdate(u.value);
100
101
  r("item updated -> override with: ", t), typeof t == "object" && (u.value = t);
101
102
  }
102
- i("update:modelValue", u.value), r("item updated -> update dataState"), S.value.increment(a), ve(() => $.value = !1);
103
- }, { deep: !0 }), M(D, () => i("perms", D.value));
104
- const H = n(() => oe.value || !o.value && !w.value || typeof e.saveValidator == "function" && !e.saveValidator(u.value) ? !1 : S.value.changed());
105
- M(H, (a) => i("modified-data", a)), M(o, (a) => i("update:isCreate", a)), e.readResource && !o.value ? F() : o.value && (m.value = !0, p.value = !0, d.value = !1);
103
+ i("update:modelValue", u.value), r("item updated -> update dataState"), _.value.increment(a), ve(() => $.value = !1);
104
+ }, { deep: !0 }), B(M, () => i("perms", M.value));
105
+ const P = n(() => oe.value || !o.value && !k.value || typeof e.saveValidator == "function" && !e.saveValidator(u.value) ? !1 : _.value.changed());
106
+ B(P, (a) => i("modified-data", a)), B(o, (a) => i("update:isCreate", a)), e.readResource && !o.value ? F() : o.value && (m.value = !0, p.value = !0, d.value = !1);
106
107
  const de = (a, t) => {
107
108
  if (d.value = !1, c.value = t.httpStatus, !t.success) {
108
109
  h.value = !0, i("error", t.httpStatus);
109
110
  return;
110
111
  }
111
- h.value = !0, i("drop", t);
112
+ h.value = !0, e.onDropModalCallbacks.length > 0 && (r("onDrop -> has onDropModalCallbacks"), e.onDropModalCallbacks.forEach((b) => {
113
+ j(b);
114
+ })), i("drop", t);
112
115
  }, re = (a, t) => {
113
- if (r("onSave -> received response:", t), q.value) {
116
+ if (r("onSave -> received response:", t), H.value) {
114
117
  if (d.value = !1, c.value = t.httpStatus, !t.success) {
115
118
  h.value = !0, i("error", t.httpStatus);
116
119
  return;
117
120
  }
118
121
  h.value = !0;
119
122
  }
120
- let y = o.value ? "create" : "update";
121
- o.value || (r("onSave -> turn stored data into original"), S.value.turnStoredIntoOriginal()), y === "create" ? typeof e.onCreate == "function" && (r("onSave -> trigger onCreate callback"), e.onCreate(t), e.onCreateModalCallbacks.length > 0 && (r("onSave -> has onCreateModalCallbacks"), e.onCreateModalCallbacks.forEach((_) => {
122
- Z(_);
123
- }))) : typeof e.onUpdate == "function" && (r("onSave -> trigger onUpdate callback"), e.onUpdate(t), e.onUpdateModalCallbacks.length > 0 && (r("onSave -> has onUpdateModalCallbacks"), e.onUpdateModalCallbacks.forEach((_) => {
124
- Z(_);
125
- }))), !e.insideModal && t.autoReloadId && (r("onSave -> autoReloadId detected: ", t.autoReloadId), e.readData.id = t.autoReloadId, r("onSave -> turning off create mode"), o.value = !1, F()), i(y, t);
126
- }, P = () => {
127
- d.value = !0, c.value = -1;
123
+ let b = o.value ? "create" : "update";
124
+ o.value || (r("onSave -> turn stored data into original"), _.value.turnStoredIntoOriginal()), b === "create" ? typeof e.onCreate == "function" && (r("onSave -> trigger onCreate callback"), e.onCreate(t), e.onCreateModalCallbacks.length > 0 && (r("onSave -> has onCreateModalCallbacks"), e.onCreateModalCallbacks.forEach((g) => {
125
+ j(g);
126
+ }))) : typeof e.onUpdate == "function" && (r("onSave -> trigger onUpdate callback"), e.onUpdate(t), e.onUpdateModalCallbacks.length > 0 && (r("onSave -> has onUpdateModalCallbacks"), e.onUpdateModalCallbacks.forEach((g) => {
127
+ j(g);
128
+ }))), !e.insideModal && t.autoReloadId && (r("onSave -> autoReloadId detected: ", t.autoReloadId), e.readData.id = t.autoReloadId, r("onSave -> turning off create mode"), o.value = !1, F()), i(b, t);
128
129
  }, x = () => {
130
+ d.value = !0, c.value = -1;
131
+ }, z = () => {
129
132
  d.value = !1;
130
133
  };
131
134
  f({
132
135
  doDrop: () => {
133
- U.value && typeof U.value.click == "function" && U.value.click();
136
+ R.value && typeof R.value.click == "function" && R.value.click();
134
137
  },
135
138
  doRefresh: F,
136
139
  doSave: () => {
137
- B.value && typeof B.value.click == "function" && B.value.click();
140
+ w.value && typeof w.value.click == "function" && w.value.click();
138
141
  }
139
142
  });
140
- const z = n(() => !e.hiddenDrop && !d.value && p.value && m.value), A = n(() => d.value ? !1 : o.value ? !0 : !e.hiddenSave && p.value && m.value), G = n(() => !d.value && !o.value && m.value && !(e.dropDisabled && e.updateDisabled)), ne = n(() => !e.hiddenButtons && (A.value || z.value || G.value));
143
+ const A = n(() => !k.value && C.value ? !0 : !e.hiddenDrop && !d.value && p.value && m.value), G = n(() => d.value ? !1 : o.value ? !0 : !e.hiddenSave && p.value && m.value), Q = n(() => !k.value && !C.value || !k.value && C.value ? !1 : !d.value && !o.value && m.value && !(e.dropDisabled && e.updateDisabled)), ne = n(() => !e.hiddenButtons && (G.value || A.value || Q.value));
141
144
  return n(() => u), (a, t) => {
142
- const y = E("lkt-button"), _ = E("lkt-field-switch"), Q = E("lkt-http-info"), se = E("lkt-loader");
143
- return v(), b("article", De, [
144
- ue.value ? (v(), b("header", Se, [
145
+ const b = E("lkt-button"), g = E("lkt-field-switch"), W = E("lkt-http-info"), se = E("lkt-loader");
146
+ return v(), y("article", De, [
147
+ ue.value ? (v(), y("header", Se, [
145
148
  J("h1", ye, K(a.title), 1),
146
- J("div", _e, [
149
+ J("div", Me, [
147
150
  V(a.$slots, "post-title", {
148
151
  item: u.value,
149
152
  loading: d.value
150
153
  })
151
154
  ])
152
- ])) : g("", !0),
153
- I(J("div", Me, [
154
- o.value ? g("", !0) : I((v(), N(y, {
155
+ ])) : U("", !0),
156
+ I(J("div", _e, [
157
+ o.value ? U("", !0) : I((v(), N(b, {
155
158
  key: 0,
156
- ref: (C) => U.value = C,
159
+ ref: (S) => R.value = S,
157
160
  palette: "danger",
158
- disabled: a.dropDisabled || !R.value,
161
+ disabled: a.dropDisabled || !C.value,
159
162
  "confirm-modal": a.dropConfirm,
160
163
  "confirm-data": a.dropConfirmData,
161
164
  resource: a.dropResource,
162
165
  "resource-data": a.dropData,
163
- onLoading: P,
164
- onLoaded: x,
166
+ onLoading: x,
167
+ onLoaded: z,
165
168
  onClick: de
166
169
  }, {
167
- default: W(() => [
168
- X(T)["button-drop"] ? V(a.$slots, "button-drop", {
170
+ default: X(() => [
171
+ Y(T)["button-drop"] ? V(a.$slots, "button-drop", {
169
172
  key: 0,
170
173
  item: u.value,
171
174
  editMode: p.value,
172
175
  isCreate: o.value,
173
- canUpdate: w.value,
174
- canDrop: R.value
175
- }) : (v(), b("span", ge, K(a.dropText), 1))
176
+ canUpdate: k.value,
177
+ canDrop: C.value
178
+ }) : (v(), y("span", ge, K(a.dropText), 1))
176
179
  ]),
177
180
  _: 3
178
181
  }, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"])), [
179
- [L, z.value]
182
+ [L, A.value]
180
183
  ]),
181
- I(Y(y, {
182
- ref: (C) => B.value = C,
184
+ I(Z(b, {
185
+ ref: (S) => w.value = S,
183
186
  palette: "success",
184
- disabled: !H.value,
187
+ disabled: !P.value,
185
188
  "confirm-modal": ae.value,
186
189
  "confirm-data": te.value,
187
- resource: q.value,
190
+ resource: H.value,
188
191
  "resource-data": le.value,
189
- onLoading: P,
190
- onLoaded: x,
192
+ onLoading: x,
193
+ onLoaded: z,
191
194
  onClick: re
192
195
  }, {
193
- default: W(() => [
194
- X(T)["button-save"] ? V(a.$slots, "button-save", {
196
+ default: X(() => [
197
+ Y(T)["button-save"] ? V(a.$slots, "button-save", {
195
198
  key: 0,
196
199
  item: u.value,
197
200
  editMode: p.value,
198
201
  isCreate: o.value,
199
- canUpdate: w.value,
200
- canDrop: R.value
201
- }) : (v(), b("span", Be, K(a.saveText), 1))
202
+ canUpdate: k.value,
203
+ canDrop: C.value
204
+ }) : (v(), y("span", Be, K(a.saveText), 1))
202
205
  ]),
203
206
  _: 3
204
207
  }, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"]), [
205
- [L, A.value]
208
+ [L, G.value]
206
209
  ]),
207
- I(Y(_, {
210
+ I(Z(g, {
208
211
  modelValue: p.value,
209
- "onUpdate:modelValue": t[0] || (t[0] = (C) => p.value = C),
212
+ "onUpdate:modelValue": t[0] || (t[0] = (S) => p.value = S),
210
213
  label: a.editModeText
211
214
  }, null, 8, ["modelValue", "label"]), [
212
- [L, G.value]
215
+ [L, Q.value]
213
216
  ])
214
217
  ], 512), [
215
218
  [L, ne.value]
216
219
  ]),
217
- d.value ? g("", !0) : (v(), b("div", Ue, [
218
- m.value ? (v(), b("div", we, [
219
- h.value ? (v(), N(Q, {
220
+ d.value ? U("", !0) : (v(), y("div", Ue, [
221
+ m.value ? (v(), y("div", we, [
222
+ h.value ? (v(), N(W, {
220
223
  key: 0,
221
224
  code: c.value,
222
225
  quick: "",
223
226
  palette: c.value === 200 ? "success" : "danger",
224
227
  "can-close": "",
225
- onClose: t[1] || (t[1] = (C) => h.value = !1)
226
- }, null, 8, ["code", "palette"])) : g("", !0),
228
+ onClose: t[1] || (t[1] = (S) => h.value = !1)
229
+ }, null, 8, ["code", "palette"])) : U("", !0),
227
230
  V(a.$slots, "item", {
228
231
  item: u.value,
229
232
  loading: d.value,
230
233
  editMode: p.value,
231
234
  isCreate: o.value,
232
- canUpdate: w.value,
233
- canDrop: R.value,
235
+ canUpdate: k.value,
236
+ canDrop: C.value,
234
237
  itemBeingEdited: $.value
235
238
  })
236
- ])) : (v(), N(Q, {
239
+ ])) : (v(), N(W, {
237
240
  key: 1,
238
241
  code: c.value
239
242
  }, null, 8, ["code"]))
240
243
  ])),
241
- d.value ? (v(), N(se, { key: 2 })) : g("", !0)
244
+ d.value ? (v(), N(se, { key: 2 })) : U("", !0)
242
245
  ]);
243
246
  };
244
247
  }
@@ -35,6 +35,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
35
35
  dataStateConfig: LktObject;
36
36
  onCreateModalCallbacks: ModalCallbackConfig[];
37
37
  onUpdateModalCallbacks: ModalCallbackConfig[];
38
+ onDropModalCallbacks: ModalCallbackConfig[];
38
39
  }>, {
39
40
  modelValue: () => {};
40
41
  title: string;
@@ -70,6 +71,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
70
71
  dataStateConfig: () => {};
71
72
  onCreateModalCallbacks: () => never[];
72
73
  onUpdateModalCallbacks: () => never[];
74
+ onDropModalCallbacks: () => never[];
73
75
  }>, {
74
76
  doDrop: () => void;
75
77
  doRefresh: () => Promise<void>;
@@ -119,6 +121,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
119
121
  dataStateConfig: LktObject;
120
122
  onCreateModalCallbacks: ModalCallbackConfig[];
121
123
  onUpdateModalCallbacks: ModalCallbackConfig[];
124
+ onDropModalCallbacks: ModalCallbackConfig[];
122
125
  }>, {
123
126
  modelValue: () => {};
124
127
  title: string;
@@ -154,6 +157,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
154
157
  dataStateConfig: () => {};
155
158
  onCreateModalCallbacks: () => never[];
156
159
  onUpdateModalCallbacks: () => never[];
160
+ onDropModalCallbacks: () => never[];
157
161
  }>>> & {
158
162
  onError?: ((...args: any[]) => any) | undefined;
159
163
  onDrop?: ((...args: any[]) => any) | undefined;
@@ -199,6 +203,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
199
203
  dataStateConfig: LktObject;
200
204
  onCreateModalCallbacks: ModalCallbackConfig[];
201
205
  onUpdateModalCallbacks: ModalCallbackConfig[];
206
+ onDropModalCallbacks: ModalCallbackConfig[];
202
207
  }, {}>, {
203
208
  "post-title"?(_: {
204
209
  item: LktObject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lkt-item-crud",
3
- "version": "1.1.18",
3
+ "version": "1.1.20",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "module": "./dist/build.js",
@@ -42,6 +42,7 @@ const props = withDefaults(defineProps<{
42
42
  dataStateConfig: LktObject
43
43
  onCreateModalCallbacks: ModalCallbackConfig[]
44
44
  onUpdateModalCallbacks: ModalCallbackConfig[]
45
+ onDropModalCallbacks: ModalCallbackConfig[]
45
46
  }>(), {
46
47
  modelValue: () => ({}),
47
48
  title: '',
@@ -77,6 +78,7 @@ const props = withDefaults(defineProps<{
77
78
  dataStateConfig: () => ({}),
78
79
  onCreateModalCallbacks: () => [],
79
80
  onUpdateModalCallbacks: () => [],
81
+ onDropModalCallbacks: () => [],
80
82
  });
81
83
 
82
84
  const slots = useSlots();
@@ -213,8 +215,13 @@ const onDrop = ($event: PointerEvent, r: HTTPResponse) => {
213
215
  return;
214
216
  }
215
217
  showStoreMessage.value = true;
218
+ if (props.onDropModalCallbacks.length > 0) {
219
+ debug('onDrop -> has onDropModalCallbacks');
220
+ props.onDropModalCallbacks.forEach(cb => {
221
+ runModalCallback(cb);
222
+ });
223
+ }
216
224
  emit('drop', r)
217
-
218
225
  },
219
226
  onSave = ($event: PointerEvent, r: HTTPResponse) => {
220
227
  debug('onSave -> received response:', r);
@@ -290,6 +297,8 @@ defineExpose({
290
297
  });
291
298
 
292
299
  const showDropButton = computed(() => {
300
+ if (!canUpdate.value && canDrop.value) return true;
301
+
293
302
  return !props.hiddenDrop
294
303
  && !isLoading.value
295
304
  && editMode.value
@@ -305,6 +314,9 @@ const showDropButton = computed(() => {
305
314
  && httpSuccessRead.value;
306
315
  }),
307
316
  showSwitchButton = computed(() => {
317
+ if (!canUpdate.value && !canDrop.value) return false;
318
+ if (!canUpdate.value && canDrop.value) return false;
319
+
308
320
  return !isLoading.value
309
321
  && !createMode.value
310
322
  && httpSuccessRead.value