lkt-item-crud 1.1.19 → 1.1.21

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,4 +1,4 @@
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";
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
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";
@@ -12,19 +12,19 @@ const r = (...l) => {
12
12
  O.debugEnabled = l;
13
13
  }, j = (l) => {
14
14
  r("runModalCallback -> init", l);
15
- let f = l.modalKey ? l.modalKey : "_", C = 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, C);
18
+ return be(l.modalName, f, D);
19
19
  case "open":
20
- return Ce(l.modalName, f, C);
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, C);
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, C) : 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,
@@ -75,10 +75,10 @@ const r = (...l) => {
75
75
  onDropModalCallbacks: { default: () => [] }
76
76
  },
77
77
  emits: ["update:modelValue", "update:isCreate", "read", "create", "update", "drop", "perms", "error", "modified-data"],
78
- setup(l, { expose: f, emit: C }) {
79
- const e = l, T = ce(), i = C;
78
+ setup(l, { expose: f, emit: D }) {
79
+ const e = l, T = ce(), i = D;
80
80
  let ee = [];
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
+ 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
82
  r("fetchItem"), d.value = !0, c.value = -1, h.value = !1;
83
83
  try {
84
84
  const a = await fe(e.readResource, e.readData);
@@ -86,31 +86,31 @@ const r = (...l) => {
86
86
  m.value = !1, c.value = a.httpStatus, i("error", a.httpStatus);
87
87
  return;
88
88
  }
89
- m.value = !0, u.value = a.data, S.value = a.perms, y.value.increment(u.value).turnStoredIntoOriginal(), i("read", a);
89
+ m.value = !0, u.value = a.data, _.value = a.perms, S.value.increment(u.value).turnStoredIntoOriginal(), i("read", a);
90
90
  } catch {
91
91
  d.value = !1, m.value = !1, c.value = 404, i("error", 404);
92
92
  return;
93
93
  }
94
94
  }, ue = n(() => d.value ? !1 : e.title || !!T["post-title"]);
95
- _(() => e.modelValue, (a) => {
96
- u.value = a, y.value.increment(a);
97
- }, { deep: !0 }), _(u, (a) => {
95
+ B(() => e.modelValue, (a) => {
96
+ u.value = a, S.value.increment(a);
97
+ }, { deep: !0 }), B(u, (a) => {
98
98
  if ($.value = !0, r("item updated ->", u.value), typeof e.beforeEmitUpdate == "function") {
99
99
  r("item updated -> has beforeEmitUpdate");
100
100
  let t = e.beforeEmitUpdate(u.value);
101
101
  r("item updated -> override with: ", t), typeof t == "object" && (u.value = t);
102
102
  }
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);
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
107
  const de = (a, t) => {
108
108
  if (d.value = !1, c.value = t.httpStatus, !t.success) {
109
109
  h.value = !0, i("error", t.httpStatus);
110
110
  return;
111
111
  }
112
- h.value = !0, e.onDropModalCallbacks.length > 0 && (r("onDrop -> has onDropModalCallbacks"), e.onDropModalCallbacks.forEach((k) => {
113
- j(k);
112
+ h.value = !0, e.onDropModalCallbacks.length > 0 && (r("onDrop -> has onDropModalCallbacks"), e.onDropModalCallbacks.forEach((b) => {
113
+ j(b);
114
114
  })), i("drop", t);
115
115
  }, re = (a, t) => {
116
116
  if (r("onSave -> received response:", t), H.value) {
@@ -120,12 +120,12 @@ const r = (...l) => {
120
120
  }
121
121
  h.value = !0;
122
122
  }
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);
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
129
  }, x = () => {
130
130
  d.value = !0, c.value = -1;
131
131
  }, z = () => {
@@ -133,18 +133,18 @@ const r = (...l) => {
133
133
  };
134
134
  f({
135
135
  doDrop: () => {
136
- U.value && typeof U.value.click == "function" && U.value.click();
136
+ R.value && typeof R.value.click == "function" && R.value.click();
137
137
  },
138
138
  doRefresh: F,
139
139
  doSave: () => {
140
- B.value && typeof B.value.click == "function" && B.value.click();
140
+ w.value && typeof w.value.click == "function" && w.value.click();
141
141
  }
142
142
  });
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));
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
144
  return n(() => u), (a, t) => {
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
+ 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
148
  J("h1", ye, K(a.title), 1),
149
149
  J("div", Me, [
150
150
  V(a.$slots, "post-title", {
@@ -152,13 +152,13 @@ const r = (...l) => {
152
152
  loading: d.value
153
153
  })
154
154
  ])
155
- ])) : g("", !0),
155
+ ])) : U("", !0),
156
156
  I(J("div", _e, [
157
- o.value ? g("", !0) : I((v(), N(k, {
157
+ o.value ? U("", !0) : I((v(), N(b, {
158
158
  key: 0,
159
- ref: (b) => U.value = b,
159
+ ref: (y) => R.value = y,
160
160
  palette: "danger",
161
- disabled: a.dropDisabled || !R.value,
161
+ disabled: a.dropDisabled || !C.value,
162
162
  "confirm-modal": a.dropConfirm,
163
163
  "confirm-data": a.dropConfirmData,
164
164
  resource: a.dropResource,
@@ -173,16 +173,16 @@ const r = (...l) => {
173
173
  item: u.value,
174
174
  editMode: p.value,
175
175
  isCreate: o.value,
176
- canUpdate: w.value,
177
- canDrop: R.value
178
- }) : (v(), D("span", ge, K(a.dropText), 1))
176
+ canUpdate: k.value,
177
+ canDrop: C.value
178
+ }) : (v(), M("span", ge, K(a.dropText), 1))
179
179
  ]),
180
180
  _: 3
181
181
  }, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"])), [
182
182
  [L, A.value]
183
183
  ]),
184
- I(Z(k, {
185
- ref: (b) => B.value = b,
184
+ I(Z(b, {
185
+ ref: (y) => w.value = y,
186
186
  palette: "success",
187
187
  disabled: !P.value,
188
188
  "confirm-modal": ae.value,
@@ -199,17 +199,17 @@ const r = (...l) => {
199
199
  item: u.value,
200
200
  editMode: p.value,
201
201
  isCreate: o.value,
202
- canUpdate: w.value,
203
- canDrop: R.value
204
- }) : (v(), D("span", Be, K(a.saveText), 1))
202
+ canUpdate: k.value,
203
+ canDrop: C.value
204
+ }) : (v(), M("span", Be, K(a.saveText), 1))
205
205
  ]),
206
206
  _: 3
207
207
  }, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"]), [
208
208
  [L, G.value]
209
209
  ]),
210
- I(Z(M, {
210
+ I(Z(g, {
211
211
  modelValue: p.value,
212
- "onUpdate:modelValue": t[0] || (t[0] = (b) => p.value = b),
212
+ "onUpdate:modelValue": t[0] || (t[0] = (y) => p.value = y),
213
213
  label: a.editModeText
214
214
  }, null, 8, ["modelValue", "label"]), [
215
215
  [L, Q.value]
@@ -217,23 +217,23 @@ const r = (...l) => {
217
217
  ], 512), [
218
218
  [L, ne.value]
219
219
  ]),
220
- d.value ? g("", !0) : (v(), D("div", Ue, [
221
- m.value ? (v(), D("div", we, [
220
+ d.value ? U("", !0) : (v(), M("div", Ue, [
221
+ m.value ? (v(), M("div", we, [
222
222
  h.value ? (v(), N(W, {
223
223
  key: 0,
224
224
  code: c.value,
225
225
  quick: "",
226
226
  palette: c.value === 200 ? "success" : "danger",
227
227
  "can-close": "",
228
- onClose: t[1] || (t[1] = (b) => h.value = !1)
229
- }, null, 8, ["code", "palette"])) : g("", !0),
228
+ onClose: t[1] || (t[1] = (y) => h.value = !1)
229
+ }, null, 8, ["code", "palette"])) : U("", !0),
230
230
  V(a.$slots, "item", {
231
231
  item: u.value,
232
232
  loading: d.value,
233
233
  editMode: p.value,
234
234
  isCreate: o.value,
235
- canUpdate: w.value,
236
- canDrop: R.value,
235
+ canUpdate: k.value,
236
+ canDrop: C.value,
237
237
  itemBeingEdited: $.value
238
238
  })
239
239
  ])) : (v(), N(W, {
@@ -241,7 +241,7 @@ const r = (...l) => {
241
241
  code: c.value
242
242
  }, null, 8, ["code"]))
243
243
  ])),
244
- d.value ? (v(), N(se, { key: 2 })) : g("", !0)
244
+ d.value ? (v(), N(se, { key: 2 })) : U("", !0)
245
245
  ]);
246
246
  };
247
247
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lkt-item-crud",
3
- "version": "1.1.19",
3
+ "version": "1.1.21",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "module": "./dist/build.js",
@@ -297,12 +297,16 @@ defineExpose({
297
297
  });
298
298
 
299
299
  const showDropButton = computed(() => {
300
+ if (!canUpdate.value && canDrop.value) return true;
301
+
300
302
  return !props.hiddenDrop
301
303
  && !isLoading.value
302
304
  && editMode.value
303
305
  && httpSuccessRead.value;
304
306
  }),
305
307
  showSaveButton = computed(() => {
308
+
309
+ if (dataState.value.changed()) return true;
306
310
  if (isLoading.value) return false;
307
311
 
308
312
  if (createMode.value) return true;
@@ -312,6 +316,9 @@ const showDropButton = computed(() => {
312
316
  && httpSuccessRead.value;
313
317
  }),
314
318
  showSwitchButton = computed(() => {
319
+ if (!canUpdate.value && !canDrop.value) return false;
320
+ if (!canUpdate.value && canDrop.value) return false;
321
+
315
322
  return !isLoading.value
316
323
  && !createMode.value
317
324
  && httpSuccessRead.value
@@ -319,9 +326,6 @@ const showDropButton = computed(() => {
319
326
  }),
320
327
  showButtons = computed(() => {
321
328
  return !props.hiddenButtons && (showSaveButton.value || showDropButton.value || showSwitchButton.value);
322
- }),
323
- computedItem = computed(() => {
324
- return item;
325
329
  });
326
330
  </script>
327
331