lkt-item-crud 1.1.21 → 1.1.23

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