lkt-item-crud 1.1.18 → 1.1.19

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 _, nextTick as ve, resolveComponent as E, openBlock as v, createElementBlock as D, createElementVNode as J, toDisplayString as K, renderSlot as V, createCommentVNode as g, 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 : "_", C = 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, C);
19
19
  case "open":
20
- return Ce(l.modalName, f, k);
20
+ return Ce(l.modalName, f, C);
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, C);
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, C) : 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: C }) {
79
+ const e = l, T = ce(), i = C;
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), S = s(ee), p = s(!1), m = s(!1), h = s(!1), c = s(200), B = s(null), U = s(null), y = 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), w = n(() => !o.value && S.value.includes("update")), R = n(() => !o.value && S.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,47 +86,49 @@ 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, S.value = a.perms, y.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
+ _(() => e.modelValue, (a) => {
96
+ u.value = a, y.value.increment(a);
97
+ }, { deep: !0 }), _(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"), y.value.increment(a), ve(() => $.value = !1);
104
+ }, { deep: !0 }), _(S, () => i("perms", S.value));
105
+ const P = n(() => oe.value || !o.value && !w.value || typeof e.saveValidator == "function" && !e.saveValidator(u.value) ? !1 : y.value.changed());
106
+ _(P, (a) => i("modified-data", a)), _(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((k) => {
113
+ j(k);
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 k = o.value ? "create" : "update";
124
+ o.value || (r("onSave -> turn stored data into original"), y.value.turnStoredIntoOriginal()), k === "create" ? typeof e.onCreate == "function" && (r("onSave -> trigger onCreate callback"), e.onCreate(t), e.onCreateModalCallbacks.length > 0 && (r("onSave -> has onCreateModalCallbacks"), e.onCreateModalCallbacks.forEach((M) => {
125
+ j(M);
126
+ }))) : typeof e.onUpdate == "function" && (r("onSave -> trigger onUpdate callback"), e.onUpdate(t), e.onUpdateModalCallbacks.length > 0 && (r("onSave -> has onUpdateModalCallbacks"), e.onUpdateModalCallbacks.forEach((M) => {
127
+ j(M);
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(k, t);
128
129
  }, x = () => {
130
+ d.value = !0, c.value = -1;
131
+ }, z = () => {
129
132
  d.value = !1;
130
133
  };
131
134
  f({
@@ -137,92 +140,92 @@ const r = (...l) => {
137
140
  B.value && typeof B.value.click == "function" && B.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(() => !e.hiddenDrop && !d.value && p.value && m.value), G = n(() => d.value ? !1 : o.value ? !0 : !e.hiddenSave && p.value && m.value), Q = n(() => !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 k = E("lkt-button"), M = E("lkt-field-switch"), W = E("lkt-http-info"), se = E("lkt-loader");
146
+ return v(), D("article", De, [
147
+ ue.value ? (v(), D("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
155
  ])) : g("", !0),
153
- I(J("div", Me, [
154
- o.value ? g("", !0) : I((v(), N(y, {
156
+ I(J("div", _e, [
157
+ o.value ? g("", !0) : I((v(), N(k, {
155
158
  key: 0,
156
- ref: (C) => U.value = C,
159
+ ref: (b) => U.value = b,
157
160
  palette: "danger",
158
161
  disabled: a.dropDisabled || !R.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
176
  canUpdate: w.value,
174
177
  canDrop: R.value
175
- }) : (v(), b("span", ge, K(a.dropText), 1))
178
+ }) : (v(), D("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(k, {
185
+ ref: (b) => B.value = b,
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
202
  canUpdate: w.value,
200
203
  canDrop: R.value
201
- }) : (v(), b("span", Be, K(a.saveText), 1))
204
+ }) : (v(), D("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(M, {
208
211
  modelValue: p.value,
209
- "onUpdate:modelValue": t[0] || (t[0] = (C) => p.value = C),
212
+ "onUpdate:modelValue": t[0] || (t[0] = (b) => p.value = b),
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 ? g("", !0) : (v(), D("div", Ue, [
221
+ m.value ? (v(), D("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)
228
+ onClose: t[1] || (t[1] = (b) => h.value = !1)
226
229
  }, null, 8, ["code", "palette"])) : g("", !0),
227
230
  V(a.$slots, "item", {
228
231
  item: u.value,
@@ -233,7 +236,7 @@ const r = (...l) => {
233
236
  canDrop: R.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"]))
@@ -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.19",
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);