lkt-item-crud 1.2.4 → 1.2.6

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,7 +1,7 @@
1
- declare function Xe(o?: boolean): void;
2
- declare namespace Ye {
1
+ declare function _e(o?: boolean): void;
2
+ declare namespace xe {
3
3
  function install(o: any, g?: {}): void;
4
4
  }
5
- declare function _e(o: any): void;
6
- declare function Ze(o: any): void;
7
- export { Xe as debugLktItemCrud, Ye as default, _e as setItemCrudDefaultDropIcon, Ze as setItemCrudDefaultSaveIcon };
5
+ declare function tt(o: any): void;
6
+ declare function et(o: any): void;
7
+ export { _e as debugLktItemCrud, xe as default, tt as setItemCrudDefaultDropIcon, et as setItemCrudDefaultSaveIcon };
package/dist/build.js CHANGED
@@ -1,42 +1,42 @@
1
- import { defineComponent as ve, useSlots as pe, ref as p, watch as k, resolveComponent as Z, openBlock as s, createElementBlock as S, unref as m, withDirectives as z, renderSlot as y, vShow as K, createCommentVNode as c, createBlock as B, withCtx as $, computed as i, nextTick as he, resolveDynamicComponent as ke, normalizeProps as ye, guardReactiveProps as Ce, createElementVNode as De, toDisplayString as ge, createSlots as ne } from "vue";
2
- import { httpCall as Se } from "lkt-http-client";
3
- import { DataState as se } from "lkt-data-state";
4
- import { execModal as we, refreshModal as Be, closeModal as Me, openModal as Ie, reOpenModal as Te } from "lkt-modal";
5
- import { __ as Ue } from "lkt-i18n";
1
+ import { defineComponent as pe, useSlots as ce, ref as s, watch as C, resolveComponent as Z, openBlock as i, createElementBlock as w, unref as m, withDirectives as z, renderSlot as y, vShow as K, createCommentVNode as c, createBlock as M, withCtx as E, computed as v, nextTick as ye, onMounted as ke, resolveDynamicComponent as De, normalizeProps as ge, guardReactiveProps as Se, createElementVNode as we, toDisplayString as Be, createSlots as se } from "vue";
2
+ import { httpCall as Me } from "lkt-http-client";
3
+ import { DataState as ie } from "lkt-data-state";
4
+ import { execModal as Ie, refreshModal as Te, closeModal as Ue, openModal as Re, reOpenModal as Ne } from "lkt-modal";
5
+ import { __ as $e } from "lkt-i18n";
6
6
  const F = class F {
7
7
  };
8
8
  F.debugEnabled = !1, F.defaultSaveIcon = "", F.defaultDropIcon = "";
9
- let T = F;
10
- const v = (...o) => {
11
- T.debugEnabled && console.info("[LktItemCrud] ", ...o);
12
- }, Xe = (o = !0) => {
13
- T.debugEnabled = o;
9
+ let U = F;
10
+ const p = (...o) => {
11
+ U.debugEnabled && console.info("[LktItemCrud] ", ...o);
12
+ }, _e = (o = !0) => {
13
+ U.debugEnabled = o;
14
14
  }, Y = (o) => {
15
- v("runModalCallback -> init", o);
16
- let g = o.modalKey ? o.modalKey : "_", M = o.args ? o.args : {};
15
+ p("runModalCallback -> init", o);
16
+ let g = o.modalKey ? o.modalKey : "_", I = o.args ? o.args : {};
17
17
  switch (o.action) {
18
18
  case "reOpen":
19
- return Te(o.modalName, g, M);
19
+ return Ne(o.modalName, g, I);
20
20
  case "open":
21
- return Ie(o.modalName, g, M);
21
+ return Re(o.modalName, g, I);
22
22
  case "close":
23
- return Me(o.modalName, g);
23
+ return Ue(o.modalName, g);
24
24
  case "refresh":
25
- return Be(o.modalName, g, M);
25
+ return Te(o.modalName, g, I);
26
26
  case "exec":
27
27
  let e = o.method;
28
- return e ? we(o.modalName, g, e, M) : void 0;
28
+ return e ? Ie(o.modalName, g, e, I) : void 0;
29
29
  }
30
- }, Re = { class: "lkt-item-crud-buttons" }, Ne = {
30
+ }, Ee = { class: "lkt-item-crud-buttons" }, Ve = {
31
31
  key: 0,
32
32
  class: "lkt-item-crud-buttons"
33
- }, $e = {
33
+ }, Le = {
34
34
  key: 1,
35
35
  class: "lkt-item-crud-buttons"
36
- }, Ee = {
36
+ }, Oe = {
37
37
  key: 4,
38
38
  class: "lkt-item-crud-buttons"
39
- }, ie = /* @__PURE__ */ ve({
39
+ }, ve = /* @__PURE__ */ pe({
40
40
  __name: "ButtonNav",
41
41
  props: {
42
42
  item: { default: () => ({}) },
@@ -65,144 +65,144 @@ const v = (...o) => {
65
65
  editModeText: {}
66
66
  },
67
67
  emits: ["update:loading", "update:editing", "save", "drop"],
68
- setup(o, { expose: g, emit: M }) {
69
- const e = M, b = o, u = pe(), E = p(null), r = p(null), d = p(b.loading);
70
- k(() => b.loading, (t) => d.value = t), k(d, (t) => e("update:loading", t));
71
- const f = p(b.editing);
72
- k(() => b.editing, (t) => f.value = t), k(f, (t) => e("update:editing", t));
68
+ setup(o, { expose: g, emit: I }) {
69
+ const e = I, b = o, u = ce(), V = s(null), d = s(null), r = s(b.loading);
70
+ C(() => b.loading, (a) => r.value = a), C(r, (a) => e("update:loading", a));
71
+ const f = s(b.editing);
72
+ C(() => b.editing, (a) => f.value = a), C(f, (a) => e("update:editing", a));
73
73
  const h = () => {
74
- d.value = !0;
75
- }, C = () => {
76
- d.value = !1;
77
- }, w = () => {
78
- e("save");
79
- }, D = () => {
80
- e("drop");
74
+ r.value = !0;
75
+ }, k = () => {
76
+ r.value = !1;
77
+ }, B = (a, S) => {
78
+ e("save", a, S);
79
+ }, D = (a, S) => {
80
+ e("drop", a, S);
81
81
  };
82
82
  return g({
83
83
  doSave: () => {
84
- E.value && typeof E.value.click == "function" && E.value.click();
84
+ V.value && typeof V.value.click == "function" && V.value.click();
85
85
  },
86
86
  doDrop: () => {
87
- r.value && typeof r.value.click == "function" && r.value.click();
87
+ d.value && typeof d.value.click == "function" && d.value.click();
88
88
  }
89
- }), (t, V) => {
89
+ }), (a, S) => {
90
90
  const n = Z("lkt-button");
91
- return s(), S("div", Re, [
92
- m(u)["prev-buttons-ever"] ? z((s(), S("div", Ne, [
93
- y(t.$slots, "prev-buttons-ever")
91
+ return i(), w("div", Ee, [
92
+ m(u)["prev-buttons-ever"] ? z((i(), w("div", Ve, [
93
+ y(a.$slots, "prev-buttons-ever")
94
94
  ], 512)), [
95
- [K, !d.value]
95
+ [K, !r.value]
96
96
  ]) : c("", !0),
97
- m(u)["prev-buttons"] ? z((s(), S("div", $e, [
98
- y(t.$slots, "prev-buttons")
97
+ m(u)["prev-buttons"] ? z((i(), w("div", Le, [
98
+ y(a.$slots, "prev-buttons")
99
99
  ], 512)), [
100
- [K, f.value && !d.value]
100
+ [K, f.value && !r.value]
101
101
  ]) : c("", !0),
102
- t.showSaveButton ? (s(), B(n, {
102
+ a.showSaveButton ? (i(), M(n, {
103
103
  key: 2,
104
104
  ref_key: "saveButton",
105
- ref: E,
105
+ ref: V,
106
106
  palette: "success",
107
- disabled: !t.ableToSave,
108
- "confirm-modal": t.saveConfirm,
109
- "confirm-data": t.confirmData,
110
- resource: t.saveResource,
111
- "resource-data": t.saveData,
112
- text: m(u)["button-save"] ? "" : t.saveText,
113
- icon: m(u)["button-save"] ? "" : t.saveIcon,
107
+ disabled: !a.ableToSave,
108
+ "confirm-modal": a.saveConfirm,
109
+ "confirm-data": a.confirmData,
110
+ resource: a.saveResource,
111
+ "resource-data": a.saveData,
112
+ text: m(u)["button-save"] ? "" : a.saveText,
113
+ icon: m(u)["button-save"] ? "" : a.saveIcon,
114
114
  onLoading: h,
115
- onLoaded: C,
116
- onClick: w
115
+ onLoaded: k,
116
+ onClick: B
117
117
  }, {
118
- default: $(() => [
119
- m(u)["button-save"] ? y(t.$slots, "button-save", {
118
+ default: E(() => [
119
+ m(u)["button-save"] ? y(a.$slots, "button-save", {
120
120
  key: 0,
121
- item: t.item,
121
+ item: a.item,
122
122
  editMode: f.value,
123
- isCreate: t.createMode,
124
- canUpdate: t.canUpdate,
125
- canDrop: t.canDrop
123
+ isCreate: a.createMode,
124
+ canUpdate: a.canUpdate,
125
+ canDrop: a.canDrop
126
126
  }) : c("", !0)
127
127
  ]),
128
128
  _: 3
129
129
  }, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data", "text", "icon"])) : c("", !0),
130
- t.createMode ? c("", !0) : z((s(), B(n, {
130
+ a.createMode ? c("", !0) : z((i(), M(n, {
131
131
  key: 3,
132
132
  ref_key: "dropButton",
133
- ref: r,
133
+ ref: d,
134
134
  palette: "danger",
135
- disabled: !t.ableToDrop,
136
- "confirm-modal": t.dropConfirm,
137
- "confirm-data": t.dropConfirmData,
138
- resource: t.dropResource,
139
- "resource-data": t.dropData,
140
- text: m(u)["button-drop"] ? "" : t.dropText,
141
- icon: m(u)["button-drop"] ? "" : t.dropIcon,
135
+ disabled: !a.ableToDrop,
136
+ "confirm-modal": a.dropConfirm,
137
+ "confirm-data": a.dropConfirmData,
138
+ resource: a.dropResource,
139
+ "resource-data": a.dropData,
140
+ text: m(u)["button-drop"] ? "" : a.dropText,
141
+ icon: m(u)["button-drop"] ? "" : a.dropIcon,
142
142
  onLoading: h,
143
- onLoaded: C,
143
+ onLoaded: k,
144
144
  onClick: D
145
145
  }, {
146
- default: $(() => [
147
- m(u)["button-drop"] ? y(t.$slots, "button-drop", {
146
+ default: E(() => [
147
+ m(u)["button-drop"] ? y(a.$slots, "button-drop", {
148
148
  key: 0,
149
- item: t.item,
149
+ item: a.item,
150
150
  editMode: f.value,
151
- isCreate: t.createMode,
152
- canUpdate: t.canUpdate,
153
- canDrop: t.canDrop
151
+ isCreate: a.createMode,
152
+ canUpdate: a.canUpdate,
153
+ canDrop: a.canDrop
154
154
  }) : c("", !0)
155
155
  ]),
156
156
  _: 3
157
157
  }, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data", "text", "icon"])), [
158
- [K, t.showDropButton]
158
+ [K, a.showDropButton]
159
159
  ]),
160
- m(u).buttons ? z((s(), S("div", Ee, [
161
- y(t.$slots, "buttons")
160
+ m(u).buttons ? z((i(), w("div", Oe, [
161
+ y(a.$slots, "buttons")
162
162
  ], 512)), [
163
- [K, f.value && !d.value]
163
+ [K, f.value && !r.value]
164
164
  ]) : c("", !0),
165
- t.showSwitchButton ? (s(), B(n, {
165
+ a.showSwitchButton ? (i(), M(n, {
166
166
  key: 5,
167
167
  checked: f.value,
168
- "onUpdate:checked": V[0] || (V[0] = (L) => f.value = L),
168
+ "onUpdate:checked": S[0] || (S[0] = (L) => f.value = L),
169
169
  class: "lkt-item-crud--switch-mode-button",
170
170
  "show-switch": "",
171
- text: t.editModeText
171
+ text: a.editModeText
172
172
  }, null, 8, ["checked", "text"])) : c("", !0)
173
173
  ]);
174
174
  };
175
175
  }
176
176
  });
177
177
  var _ = /* @__PURE__ */ ((o) => (o.Top = "top", o.Bottom = "bottom", o))(_ || {}), j = /* @__PURE__ */ ((o) => (o.Changed = "changed", o.Always = "always", o))(j || {});
178
- const Ve = { class: "lkt-item-crud" }, Le = {
178
+ const Ae = { class: "lkt-item-crud" }, ze = {
179
179
  key: 0,
180
180
  class: "lkt-item-crud_header"
181
- }, Oe = {
181
+ }, Ke = {
182
182
  key: 0,
183
183
  class: "lkt-item-crud_header-slot"
184
- }, Ae = {
184
+ }, Fe = {
185
185
  key: 1,
186
186
  class: "lkt-item-crud_header-title"
187
- }, ze = {
187
+ }, Pe = {
188
188
  key: 2,
189
189
  class: "lkt-item-crud_header-slot"
190
- }, Ke = {
190
+ }, Je = {
191
191
  key: 2,
192
192
  class: "lkt-item-crud_content"
193
- }, Fe = {
193
+ }, je = {
194
194
  key: 0,
195
195
  class: "lkt-grid-1"
196
- }, Pe = /* @__PURE__ */ ve({
196
+ }, qe = /* @__PURE__ */ pe({
197
197
  __name: "LktItemCrud",
198
198
  props: {
199
199
  modelValue: { default: () => ({}) },
200
200
  title: { default: "" },
201
201
  editModeText: { default: "Edition Mode" },
202
202
  saveText: { default: "Save" },
203
- saveIcon: { default: () => T.defaultSaveIcon },
203
+ saveIcon: { default: () => U.defaultSaveIcon },
204
204
  dropText: { default: "Delete" },
205
- dropIcon: { default: () => T.defaultDropIcon },
205
+ dropIcon: { default: () => U.defaultDropIcon },
206
206
  hiddenSave: { type: Boolean, default: !1 },
207
207
  hiddenDrop: { type: Boolean, default: !1 },
208
208
  hiddenButtons: { type: Boolean, default: !1 },
@@ -250,63 +250,65 @@ const Ve = { class: "lkt-item-crud" }, Le = {
250
250
  beforeClose: { type: Function, default: void 0 }
251
251
  },
252
252
  emits: ["update:modelValue", "update:isCreate", "update:editing", "read", "create", "update", "drop", "before-save", "perms", "error", "modified-data"],
253
- setup(o, { expose: g, emit: M }) {
254
- const e = o, b = pe(), u = M;
255
- let E = [];
256
- const r = p(!0), d = p(e.modelValue), f = p(E), h = p(e.editing), C = p(!1), w = p(!1), D = p(200), x = p(null), ee = p(null), t = p(new se(d.value, e.dataStateConfig)), V = p(new se(e.readData)), n = p(e.isCreate), L = p(!1), P = p(null), ae = i(() => n.value ? e.createConfirm : e.updateConfirm), te = i(() => n.value ? e.createConfirmData : e.updateConfirmData), q = i(() => n.value ? e.createResource : e.updateResource), oe = i(() => n.value ? { ...e.createData, ...JSON.parse(JSON.stringify(d.value)) } : { ...e.updateData, ...JSON.parse(JSON.stringify(d.value)) }), ce = i(() => n.value ? e.createDisabled : e.updateDisabled), U = i(() => !n.value && Array.isArray(f.value) && f.value.includes("update")), R = i(() => !n.value && Array.isArray(f.value) && f.value.includes("drop")), J = async () => {
257
- v("fetchItem"), r.value = !0, D.value = -1, w.value = !1;
253
+ setup(o, { expose: g, emit: I }) {
254
+ const e = o, b = ce(), u = I;
255
+ let V = [];
256
+ const d = s(!0), r = s(e.modelValue), f = s(V), h = s(e.editing), k = s(!1), B = s(!1), D = s(200), x = s(null), ee = s(null), a = s(new ie(r.value, e.dataStateConfig)), S = s(new ie(e.readData)), n = s(e.isCreate), L = s(!1), te = s(!1), P = s(null), ae = v(() => n.value ? e.createConfirm : e.updateConfirm), oe = v(() => n.value ? e.createConfirmData : e.updateConfirmData), q = v(() => n.value ? e.createResource : e.updateResource), le = v(() => n.value ? { ...e.createData, ...JSON.parse(JSON.stringify(r.value)) } : { ...e.updateData, ...JSON.parse(JSON.stringify(r.value)) }), fe = v(() => n.value ? e.createDisabled : e.updateDisabled), R = v(() => !n.value && Array.isArray(f.value) && f.value.includes("update")), N = v(() => !n.value && Array.isArray(f.value) && f.value.includes("drop")), J = async () => {
257
+ p("fetchItem"), d.value = !0, D.value = -1, B.value = !1;
258
258
  try {
259
- const a = await Se(e.readResource, e.readData);
260
- if (v("fetchItem -> response", a), r.value = !1, D.value = a.httpStatus, !a.success) {
261
- C.value = !1, D.value = a.httpStatus, u("error", a.httpStatus);
259
+ const t = await Me(e.readResource, e.readData);
260
+ if (p("fetchItem -> response", t), d.value = !1, D.value = t.httpStatus, !t.success) {
261
+ k.value = !1, D.value = t.httpStatus, u("error", t.httpStatus);
262
262
  return;
263
263
  }
264
- C.value = !0, d.value = a.data, f.value = a.perms, t.value.increment(d.value).turnStoredIntoOriginal(), V.value.turnStoredIntoOriginal(), u("read", a);
264
+ k.value = !0, r.value = t.data, f.value = t.perms, a.value.increment(r.value).turnStoredIntoOriginal(), S.value.turnStoredIntoOriginal(), u("read", t);
265
265
  } catch {
266
- r.value = !1, C.value = !1, D.value = 404, u("error", 404);
266
+ d.value = !1, k.value = !1, D.value = 404, u("error", 404);
267
267
  return;
268
268
  }
269
269
  };
270
- k(() => e.modelValue, (a) => {
271
- d.value = a, t.value.increment(a);
272
- }, { deep: !0 }), k(d, (a) => {
273
- if (L.value = !0, v("item updated ->", d.value), typeof e.beforeEmitUpdate == "function") {
274
- v("item updated -> has beforeEmitUpdate");
275
- let l = e.beforeEmitUpdate(d.value);
276
- v("item updated -> override with: ", l), typeof l == "object" && (d.value = l);
270
+ C(() => e.modelValue, (t) => {
271
+ r.value = t, a.value.increment(t);
272
+ }, { deep: !0 }), C(r, (t) => {
273
+ if (L.value = !0, p("item updated ->", r.value), typeof e.beforeEmitUpdate == "function") {
274
+ p("item updated -> has beforeEmitUpdate");
275
+ let l = e.beforeEmitUpdate(r.value);
276
+ p("item updated -> override with: ", l), typeof l == "object" && (r.value = l);
277
277
  }
278
- u("update:modelValue", d.value), v("item updated -> update dataState"), t.value.increment(a), he(() => L.value = !1);
279
- }, { deep: !0 }), k(f, () => u("perms", f.value));
280
- const O = i(() => ce.value || !n.value && !U.value || typeof e.saveValidator == "function" && !e.saveValidator(d.value) ? !1 : t.value.changed()), H = i(() => !e.dropDisabled && R.value);
281
- k(O, (a) => u("modified-data", a)), k(n, (a) => u("update:isCreate", a)), k(() => e.readData, (a) => {
282
- V.value.increment(a), V.value.changed() && J();
283
- }), k(() => e.editing, (a) => {
284
- v("editing updated -> updating editMode", a), h.value = a;
285
- }), k(h, (a) => {
286
- v("editMode updated -> emit update", a), u("update:editing", a);
287
- }), e.readResource && !n.value ? J() : n.value && (C.value = !0, h.value = !0, r.value = !1);
288
- const le = (a, l) => {
289
- if (r.value = !1, D.value = l.httpStatus, !l.success) {
290
- w.value = !0, u("error", l.httpStatus);
278
+ u("update:modelValue", r.value), p("item updated -> update dataState"), a.value.increment(t), ye(() => L.value = !1);
279
+ }, { deep: !0 }), C(f, () => u("perms", f.value));
280
+ const O = v(() => fe.value || !n.value && !R.value || typeof e.saveValidator == "function" && !e.saveValidator(r.value) ? !1 : a.value.changed()), H = v(() => !e.dropDisabled && N.value);
281
+ C(O, (t) => u("modified-data", t)), C(n, (t) => u("update:isCreate", t)), C(() => e.readData, (t) => {
282
+ S.value.increment(t), S.value.changed() && J();
283
+ }), C(() => e.editing, (t) => {
284
+ p("editing updated -> updating editMode", t), h.value = t;
285
+ }), C(h, (t) => {
286
+ p("editMode updated -> emit update", t), u("update:editing", t);
287
+ }), ke(() => {
288
+ e.readResource && !n.value ? J() : n.value && (k.value = !0, h.value = !0, d.value = !1, a.value.increment(r.value).turnStoredIntoOriginal());
289
+ });
290
+ const re = (t, l) => {
291
+ if (d.value = !1, D.value = l.httpStatus, !l.success) {
292
+ B.value = !0, u("error", l.httpStatus);
291
293
  return;
292
294
  }
293
- w.value = !0, e.onDropModalCallbacks.length > 0 && (v("onDrop -> has onDropModalCallbacks"), e.onDropModalCallbacks.forEach((N) => {
294
- Y(N);
295
+ B.value = !0, e.onDropModalCallbacks.length > 0 && (p("onDrop -> has onDropModalCallbacks"), e.onDropModalCallbacks.forEach(($) => {
296
+ Y($);
295
297
  })), u("drop", l);
296
- }, de = (a, l) => {
297
- if (v("onSave -> received response:", l), u("before-save"), q.value) {
298
- if (r.value = !1, D.value = l.httpStatus, !l.success) {
299
- w.value = !0, u("error", l.httpStatus);
298
+ }, de = (t, l) => {
299
+ if (p("onSave -> received response:", l), u("before-save"), q.value) {
300
+ if (d.value = !1, typeof l < "u" && (D.value = l.httpStatus, !l.success)) {
301
+ B.value = !0, u("error", l.httpStatus);
300
302
  return;
301
303
  }
302
- w.value = !0;
304
+ B.value = !0;
303
305
  }
304
- let N = n.value ? "create" : "update";
305
- n.value || (v("onSave -> turn stored data into original"), t.value.turnStoredIntoOriginal()), N === "create" ? typeof e.onCreate == "function" && (v("onSave -> trigger onCreate callback"), e.onCreate(l), e.onCreateModalCallbacks.length > 0 && (v("onSave -> has onCreateModalCallbacks"), e.onCreateModalCallbacks.forEach((A) => {
306
+ let $ = n.value ? "create" : "update";
307
+ n.value || (p("onSave -> turn stored data into original"), a.value.turnStoredIntoOriginal()), $ === "create" ? (te.value = !0, a.value.increment(r.value).turnStoredIntoOriginal(), typeof e.onCreate == "function" && (p("onSave -> trigger onCreate callback"), e.onCreate(l), e.onCreateModalCallbacks.length > 0 && (p("onSave -> has onCreateModalCallbacks"), e.onCreateModalCallbacks.forEach((A) => {
306
308
  Y(A);
307
- }))) : typeof e.onUpdate == "function" && (v("onSave -> trigger onUpdate callback"), e.onUpdate(l), e.onUpdateModalCallbacks.length > 0 && (v("onSave -> has onUpdateModalCallbacks"), e.onUpdateModalCallbacks.forEach((A) => {
309
+ })))) : typeof e.onUpdate == "function" && (p("onSave -> trigger onUpdate callback"), e.onUpdate(l), e.onUpdateModalCallbacks.length > 0 && (p("onSave -> has onUpdateModalCallbacks"), e.onUpdateModalCallbacks.forEach((A) => {
308
310
  Y(A);
309
- }))), !e.insideModal && l.autoReloadId && (v("onSave -> autoReloadId detected: ", l.autoReloadId), e.readData.id = l.autoReloadId, v("onSave -> turning off create mode"), n.value = !1, J()), u(N, l);
311
+ }))), !e.insideModal && l.autoReloadId && (p("onSave -> autoReloadId detected: ", l.autoReloadId), e.readData.id = l.autoReloadId, p("onSave -> turning off create mode"), n.value = !1, J()), u($, l);
310
312
  };
311
313
  g({
312
314
  doDrop: () => {
@@ -316,164 +318,171 @@ const Ve = { class: "lkt-item-crud" }, Le = {
316
318
  doSave: () => {
317
319
  P.value && x.value.doSave();
318
320
  },
319
- hasModifiedData: () => t.value.changed()
321
+ hasModifiedData: () => a.value.changed()
320
322
  });
321
- const fe = i(() => t.value.changed() ? e.editedCloseConfirm : ""), W = i(() => !U.value && R.value ? !0 : !e.hiddenDrop && !r.value && h.value && C.value), G = i(() => t.value.changed() ? !0 : r.value ? !1 : n.value ? !0 : e.buttonNavVisibility === j.Always ? O.value : !e.hiddenSave && h.value && C.value), Q = i(() => e.hideSwitchEdition || !U.value && !R.value || !U.value && R.value ? !1 : !r.value && !n.value && C.value && !(e.dropDisabled && e.updateDisabled)), re = i(() => e.buttonNavVisibility === j.Always && (O.value || H.value) || b["prev-buttons-ever"] ? !0 : !e.hiddenButtons && (G.value || W.value || Q.value)), X = i(() => e.title.startsWith("__:") ? String(Ue(e.title.substring(3))) : e.title), me = i(() => r.value ? !1 : X.value.length > 0 || !!b["post-title"]), ue = i(() => e.insideModal ? "lkt-modal" : "section"), be = i(() => ue.value === "lkt-modal" ? {
323
+ const me = v(() => a.value.changed() ? e.editedCloseConfirm : ""), be = (t) => {
324
+ if (typeof e.beforeClose == "function")
325
+ return e.beforeClose({
326
+ ...t,
327
+ itemCreated: te.value
328
+ });
329
+ }, W = v(() => !R.value && N.value ? !0 : !e.hiddenDrop && !d.value && h.value && k.value), G = v(() => a.value.changed() ? !0 : d.value ? !1 : n.value ? !0 : e.buttonNavVisibility === j.Always ? O.value : !e.hiddenSave && h.value && k.value), Q = v(() => e.hideSwitchEdition || !R.value && !N.value || !R.value && N.value ? !1 : !d.value && !n.value && k.value && !(e.dropDisabled && e.updateDisabled)), ue = v(() => e.buttonNavVisibility === j.Always && (O.value || H.value) || b["prev-buttons-ever"] ? !0 : !e.hiddenButtons && (G.value || W.value || Q.value)), X = v(() => e.title.startsWith("__:") ? String($e(e.title.substring(3))) : e.title), he = v(() => d.value ? !1 : X.value.length > 0 || !!b["post-title"]), ne = v(() => e.insideModal ? "lkt-modal" : "section"), Ce = v(() => ne.value === "lkt-modal" ? {
322
330
  "modal-name": e.modalName,
323
331
  "modal-key": e.modalKey,
324
332
  "z-index": e.zIndex,
325
333
  "pre-title": e.preTitle,
326
334
  "show-close": e.showClose,
327
- "before-close": e.beforeClose,
335
+ "before-close": be,
328
336
  "disabled-close": e.disabledClose,
329
337
  "disabled-veil-click": e.disabledVeilClick,
330
- "close-confirm": fe.value,
338
+ "close-confirm": me.value,
331
339
  "close-confirm-key": e.editedCloseConfirmKey,
332
340
  title: e.title,
333
- size: e.size
341
+ size: e.size,
342
+ item: r.value
334
343
  } : {});
335
- return (a, l) => {
336
- const N = Z("lkt-http-info"), A = Z("lkt-loader");
337
- return s(), B(ke(ue.value), ye(Ce(be.value)), {
338
- default: $(() => [
339
- De("article", Ve, [
340
- !a.insideModal && me.value ? (s(), S("header", Le, [
341
- m(b)["pre-title"] ? (s(), S("div", Oe, [
342
- y(a.$slots, "pre-title", {
343
- item: d.value,
344
- loading: r.value
344
+ return (t, l) => {
345
+ const $ = Z("lkt-http-info"), A = Z("lkt-loader");
346
+ return i(), M(De(ne.value), ge(Se(Ce.value)), {
347
+ default: E(() => [
348
+ we("article", Ae, [
349
+ !t.insideModal && he.value ? (i(), w("header", ze, [
350
+ m(b)["pre-title"] ? (i(), w("div", Ke, [
351
+ y(t.$slots, "pre-title", {
352
+ item: r.value,
353
+ loading: d.value
345
354
  })
346
355
  ])) : c("", !0),
347
- X.value.length > 0 ? (s(), S("h1", Ae, ge(X.value), 1)) : c("", !0),
348
- m(b)["post-title"] ? (s(), S("div", ze, [
349
- y(a.$slots, "post-title", {
350
- item: d.value,
351
- loading: r.value
356
+ X.value.length > 0 ? (i(), w("h1", Fe, Be(X.value), 1)) : c("", !0),
357
+ m(b)["post-title"] ? (i(), w("div", Pe, [
358
+ y(t.$slots, "post-title", {
359
+ item: r.value,
360
+ loading: d.value
352
361
  })
353
362
  ])) : c("", !0)
354
363
  ])) : c("", !0),
355
- re.value && a.buttonNavPosition === "top" ? (s(), B(ie, {
364
+ ue.value && t.buttonNavPosition === "top" ? (i(), M(ve, {
356
365
  key: 1,
357
366
  ref_key: "buttonNav",
358
367
  ref: P,
359
- loading: r.value,
360
- "onUpdate:loading": l[0] || (l[0] = (I) => r.value = I),
368
+ loading: d.value,
369
+ "onUpdate:loading": l[0] || (l[0] = (T) => d.value = T),
361
370
  editing: h.value,
362
- "onUpdate:editing": l[1] || (l[1] = (I) => h.value = I),
363
- item: d.value,
371
+ "onUpdate:editing": l[1] || (l[1] = (T) => h.value = T),
372
+ item: r.value,
364
373
  "create-mode": n.value,
365
- "can-update": U.value,
366
- "can-drop": R.value,
374
+ "can-update": R.value,
375
+ "can-drop": N.value,
367
376
  "show-switch-button": Q.value,
368
377
  "show-save-button": G.value,
369
378
  "show-drop-button": W.value,
370
379
  "able-to-save": O.value,
371
380
  "able-to-drop": H.value,
372
381
  "save-confirm": ae.value,
373
- "drop-confirm": a.dropConfirm,
374
- "confirm-data": te.value,
375
- "drop-confirm-data": a.dropConfirmData,
382
+ "drop-confirm": t.dropConfirm,
383
+ "confirm-data": oe.value,
384
+ "drop-confirm-data": t.dropConfirmData,
376
385
  "save-resource": q.value,
377
- "drop-resource": a.dropResource,
378
- "save-data": oe.value,
379
- "drop-data": a.dropData,
380
- "save-text": a.saveText,
381
- "drop-text": a.dropText,
382
- "save-icon": a.saveIcon,
383
- "drop-icon": a.dropIcon,
384
- "edit-mode-text": a.editModeText,
386
+ "drop-resource": t.dropResource,
387
+ "save-data": le.value,
388
+ "drop-data": t.dropData,
389
+ "save-text": t.saveText,
390
+ "drop-text": t.dropText,
391
+ "save-icon": t.saveIcon,
392
+ "drop-icon": t.dropIcon,
393
+ "edit-mode-text": t.editModeText,
385
394
  onSave: de,
386
- onDrop: le
387
- }, ne({ _: 2 }, [
395
+ onDrop: re
396
+ }, se({ _: 2 }, [
388
397
  m(b)["prev-buttons-ever"] ? {
389
398
  name: "prev-buttons-ever",
390
- fn: $(() => [
391
- y(a.$slots, "prev-buttons-ever")
399
+ fn: E(() => [
400
+ y(t.$slots, "prev-buttons-ever")
392
401
  ]),
393
402
  key: "0"
394
403
  } : void 0,
395
404
  m(b)["prev-buttons"] ? {
396
405
  name: "prev-buttons-ever",
397
- fn: $(() => [
398
- y(a.$slots, "prev-buttons")
406
+ fn: E(() => [
407
+ y(t.$slots, "prev-buttons")
399
408
  ]),
400
409
  key: "1"
401
410
  } : void 0
402
411
  ]), 1032, ["loading", "editing", "item", "create-mode", "can-update", "can-drop", "show-switch-button", "show-save-button", "show-drop-button", "able-to-save", "able-to-drop", "save-confirm", "drop-confirm", "confirm-data", "drop-confirm-data", "save-resource", "drop-resource", "save-data", "drop-data", "save-text", "drop-text", "save-icon", "drop-icon", "edit-mode-text"])) : c("", !0),
403
- r.value ? c("", !0) : (s(), S("div", Ke, [
404
- C.value ? (s(), S("div", Fe, [
405
- w.value ? (s(), B(N, {
412
+ d.value ? c("", !0) : (i(), w("div", Je, [
413
+ k.value ? (i(), w("div", je, [
414
+ B.value ? (i(), M($, {
406
415
  key: 0,
407
416
  code: D.value,
408
417
  quick: "",
409
418
  palette: D.value === 200 ? "success" : "danger",
410
419
  "can-close": "",
411
- onClose: l[2] || (l[2] = (I) => w.value = !1)
420
+ onClose: l[2] || (l[2] = (T) => B.value = !1)
412
421
  }, null, 8, ["code", "palette"])) : c("", !0),
413
- y(a.$slots, "item", {
414
- item: d.value,
415
- loading: r.value,
422
+ y(t.$slots, "item", {
423
+ item: r.value,
424
+ loading: d.value,
416
425
  editMode: h.value,
417
426
  isCreate: n.value,
418
- canUpdate: U.value,
419
- canDrop: R.value,
427
+ canUpdate: R.value,
428
+ canDrop: N.value,
420
429
  itemBeingEdited: L.value
421
430
  })
422
- ])) : (s(), B(N, {
431
+ ])) : (i(), M($, {
423
432
  key: 1,
424
433
  code: D.value
425
434
  }, null, 8, ["code"]))
426
435
  ])),
427
- r.value ? (s(), B(A, { key: 3 })) : c("", !0),
428
- a.buttonNavPosition === m(_).Bottom ? z((s(), B(ie, {
436
+ d.value ? (i(), M(A, { key: 3 })) : c("", !0),
437
+ t.buttonNavPosition === m(_).Bottom ? z((i(), M(ve, {
429
438
  key: 4,
430
439
  ref_key: "buttonNav",
431
440
  ref: P,
432
- loading: r.value,
433
- "onUpdate:loading": l[3] || (l[3] = (I) => r.value = I),
441
+ loading: d.value,
442
+ "onUpdate:loading": l[3] || (l[3] = (T) => d.value = T),
434
443
  editing: h.value,
435
- "onUpdate:editing": l[4] || (l[4] = (I) => h.value = I),
436
- item: d.value,
444
+ "onUpdate:editing": l[4] || (l[4] = (T) => h.value = T),
445
+ item: r.value,
437
446
  "create-mode": n.value,
438
- "can-update": U.value,
439
- "can-drop": R.value,
447
+ "can-update": R.value,
448
+ "can-drop": N.value,
440
449
  "show-switch-button": Q.value,
441
450
  "show-save-button": G.value,
442
451
  "show-drop-button": W.value,
443
452
  "able-to-save": O.value,
444
453
  "able-to-drop": H.value,
445
454
  "save-confirm": ae.value,
446
- "drop-confirm": a.dropConfirm,
447
- "confirm-data": te.value,
448
- "drop-confirm-data": a.dropConfirmData,
455
+ "drop-confirm": t.dropConfirm,
456
+ "confirm-data": oe.value,
457
+ "drop-confirm-data": t.dropConfirmData,
449
458
  "save-resource": q.value,
450
- "drop-resource": a.dropResource,
451
- "save-data": oe.value,
452
- "drop-data": a.dropData,
453
- "save-text": a.saveText,
454
- "drop-text": a.dropText,
455
- "save-icon": a.saveIcon,
456
- "drop-icon": a.dropIcon,
457
- "edit-mode-text": a.editModeText,
459
+ "drop-resource": t.dropResource,
460
+ "save-data": le.value,
461
+ "drop-data": t.dropData,
462
+ "save-text": t.saveText,
463
+ "drop-text": t.dropText,
464
+ "save-icon": t.saveIcon,
465
+ "drop-icon": t.dropIcon,
466
+ "edit-mode-text": t.editModeText,
458
467
  onSave: de,
459
- onDrop: le
460
- }, ne({ _: 2 }, [
468
+ onDrop: re
469
+ }, se({ _: 2 }, [
461
470
  m(b)["prev-buttons-ever"] ? {
462
471
  name: "prev-buttons-ever",
463
- fn: $(() => [
464
- y(a.$slots, "prev-buttons-ever")
472
+ fn: E(() => [
473
+ y(t.$slots, "prev-buttons-ever")
465
474
  ]),
466
475
  key: "0"
467
476
  } : void 0,
468
477
  m(b)["prev-buttons"] ? {
469
478
  name: "prev-buttons-ever",
470
- fn: $(() => [
471
- y(a.$slots, "prev-buttons")
479
+ fn: E(() => [
480
+ y(t.$slots, "prev-buttons")
472
481
  ]),
473
482
  key: "1"
474
483
  } : void 0
475
484
  ]), 1032, ["loading", "editing", "item", "create-mode", "can-update", "can-drop", "show-switch-button", "show-save-button", "show-drop-button", "able-to-save", "able-to-drop", "save-confirm", "drop-confirm", "confirm-data", "drop-confirm-data", "save-resource", "drop-resource", "save-data", "drop-data", "save-text", "drop-text", "save-icon", "drop-icon", "edit-mode-text"])), [
476
- [K, re.value]
485
+ [K, ue.value]
477
486
  ]) : c("", !0)
478
487
  ])
479
488
  ]),
@@ -481,18 +490,18 @@ const Ve = { class: "lkt-item-crud" }, Le = {
481
490
  }, 16);
482
491
  };
483
492
  }
484
- }), Ye = {
493
+ }), xe = {
485
494
  install: (o, g = {}) => {
486
- o.component("lkt-item-crud") === void 0 && o.component("lkt-item-crud", Pe);
495
+ o.component("lkt-item-crud") === void 0 && o.component("lkt-item-crud", qe);
487
496
  }
488
- }, Ze = (o) => {
489
- T.defaultSaveIcon = o;
490
- }, _e = (o) => {
491
- T.defaultDropIcon = o;
497
+ }, et = (o) => {
498
+ U.defaultSaveIcon = o;
499
+ }, tt = (o) => {
500
+ U.defaultDropIcon = o;
492
501
  };
493
502
  export {
494
- Xe as debugLktItemCrud,
495
- Ye as default,
496
- _e as setItemCrudDefaultDropIcon,
497
- Ze as setItemCrudDefaultSaveIcon
503
+ _e as debugLktItemCrud,
504
+ xe as default,
505
+ tt as setItemCrudDefaultDropIcon,
506
+ et as setItemCrudDefaultSaveIcon
498
507
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lkt-item-crud",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "module": "./dist/build.js",
@@ -1,6 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { ref, useSlots, watch } from 'vue';
3
3
  import { LktObject } from 'lkt-ts-interfaces';
4
+ import { HTTPResponse } from 'lkt-http-client';
4
5
 
5
6
  const emit = defineEmits(['update:loading', 'update:editing', 'save', 'drop']);
6
7
 
@@ -57,11 +58,11 @@
57
58
  onButtonLoaded = () => {
58
59
  isLoading.value = false;
59
60
  },
60
- onSave = () => {
61
- emit('save');
61
+ onSave = ($event: Event, r: HTTPResponse) => {
62
+ emit('save', $event, r);
62
63
  },
63
- onDrop = () => {
64
- emit('drop');
64
+ onDrop = ($event: Event, r: HTTPResponse) => {
65
+ emit('drop', $event, r);
65
66
  };
66
67
 
67
68
  const doSave = () => {
@@ -100,9 +101,9 @@
100
101
  :resource-data="saveData"
101
102
  :text="slots['button-save'] ? '' : saveText"
102
103
  :icon="slots['button-save'] ? '' : saveIcon"
103
- v-on:loading="onButtonLoading"
104
- v-on:loaded="onButtonLoaded"
105
- v-on:click="onSave">
104
+ @loading="onButtonLoading"
105
+ @loaded="onButtonLoaded"
106
+ @click="onSave">
106
107
  <slot v-if="!!slots['button-save']" name="button-save" :item="item"
107
108
  :edit-mode="isEditing"
108
109
  :is-create="createMode"
@@ -122,9 +123,9 @@
122
123
  :resource-data="dropData"
123
124
  :text="slots['button-drop'] ? '' : dropText"
124
125
  :icon="slots['button-drop'] ? '' : dropIcon"
125
- v-on:loading="onButtonLoading"
126
- v-on:loaded="onButtonLoaded"
127
- v-on:click="onDrop">
126
+ @loading="onButtonLoading"
127
+ @loaded="onButtonLoaded"
128
+ @click="onDrop">
128
129
  <slot v-if="!!slots['button-drop']" name="button-drop" :item="item"
129
130
  :edit-mode="isEditing"
130
131
  :is-create="createMode"
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, nextTick, ref, useSlots, watch } from 'vue';
2
+ import { computed, nextTick, onMounted, ref, useSlots, watch } from 'vue';
3
3
  import { httpCall, HTTPResponse } from 'lkt-http-client';
4
4
  import { DataState } from 'lkt-data-state';
5
5
  import { debug } from '../functions/debug';
@@ -143,7 +143,8 @@
143
143
  dataState = ref(new DataState(item.value, props.dataStateConfig)),
144
144
  readDataState = ref(new DataState(props.readData)),
145
145
  createMode = ref(props.isCreate),
146
- itemBeingEdited = ref(false);
146
+ itemBeingEdited = ref(false),
147
+ itemCreated = ref(false);
147
148
 
148
149
  const buttonNav = ref(null);
149
150
 
@@ -259,13 +260,16 @@
259
260
  emit('update:editing', v);
260
261
  });
261
262
 
262
- // Fetch item
263
- if (props.readResource && !createMode.value) fetchItem();
264
- else if (createMode.value) {
265
- httpSuccessRead.value = true;
266
- editMode.value = true;
267
- isLoading.value = false;
268
- }
263
+ onMounted(() => {
264
+ // Fetch item
265
+ if (props.readResource && !createMode.value) fetchItem();
266
+ else if (createMode.value) {
267
+ httpSuccessRead.value = true;
268
+ editMode.value = true;
269
+ isLoading.value = false;
270
+ dataState.value.increment(item.value).turnStoredIntoOriginal();
271
+ }
272
+ })
269
273
 
270
274
  const onDrop = ($event: PointerEvent, r: HTTPResponse) => {
271
275
  isLoading.value = false;
@@ -289,11 +293,13 @@
289
293
  emit('before-save');
290
294
  if (saveResource.value) {
291
295
  isLoading.value = false;
292
- httpStatus.value = r.httpStatus;
293
- if (!r.success) {
294
- showStoreMessage.value = true;
295
- emit('error', r.httpStatus);
296
- return;
296
+ if (typeof r !== 'undefined') {
297
+ httpStatus.value = r.httpStatus;
298
+ if (!r.success) {
299
+ showStoreMessage.value = true;
300
+ emit('error', r.httpStatus);
301
+ return;
302
+ }
297
303
  }
298
304
  showStoreMessage.value = true;
299
305
  }
@@ -303,7 +309,10 @@
303
309
  dataState.value.turnStoredIntoOriginal();
304
310
  }
305
311
 
312
+
306
313
  if (emits === 'create') {
314
+ itemCreated.value = true;
315
+ dataState.value.increment(item.value).turnStoredIntoOriginal();
307
316
  if (typeof props.onCreate === 'function') {
308
317
  debug('onSave -> trigger onCreate callback');
309
318
  props.onCreate(r);
@@ -357,6 +366,15 @@
357
366
  return dataState.value.changed() ? props.editedCloseConfirm : '';
358
367
  });
359
368
 
369
+ const crudBeforeClose = (modalData: LktObject) => {
370
+ if (typeof props.beforeClose === 'function') {
371
+ return props.beforeClose({
372
+ ...modalData,
373
+ itemCreated: itemCreated.value,
374
+ });
375
+ }
376
+ };
377
+
360
378
  const showDropButton = computed(() => {
361
379
  if (!canUpdate.value && canDrop.value) return true;
362
380
 
@@ -412,19 +430,21 @@
412
430
  }),
413
431
  computedContainerAttrs = computed(() => {
414
432
  if (computedContainerTag.value === 'lkt-modal') {
433
+
415
434
  return {
416
435
  'modal-name': props.modalName,
417
436
  'modal-key': props.modalKey,
418
437
  'z-index': props.zIndex,
419
438
  'pre-title': props.preTitle,
420
439
  'show-close': props.showClose,
421
- 'before-close': props.beforeClose,
440
+ 'before-close': crudBeforeClose,
422
441
  'disabled-close': props.disabledClose,
423
442
  'disabled-veil-click': props.disabledVeilClick,
424
443
  'close-confirm': closeConfirm.value,
425
444
  'close-confirm-key': props.editedCloseConfirmKey,
426
445
  title: props.title,
427
446
  size: props.size,
447
+ item: item.value,
428
448
  };
429
449
  }
430
450
  return {};