lkt-item-crud 1.1.12 → 1.1.14

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 Oe(u?: boolean): void;
2
- declare namespace Ve {
3
- function install(u: any, $?: {}): void;
1
+ declare function we(u?: boolean): void;
2
+ declare namespace Oe {
3
+ function install(u: any, T?: {}): void;
4
4
  }
5
- export { Oe as debugLktItemCrud, Ve as default };
5
+ export { we as debugLktItemCrud, Oe as default };
package/dist/build.js CHANGED
@@ -1,21 +1,21 @@
1
- import { defineComponent as ne, useSlots as se, ref as s, computed as d, watch as D, resolveComponent as w, openBlock as c, createElementBlock as h, createElementVNode as j, toDisplayString as N, renderSlot as O, createCommentVNode as g, withDirectives as V, createBlock as q, withCtx as G, unref as K, vShow as I, createVNode as Q } from "vue";
1
+ import { defineComponent as ne, useSlots as se, ref as s, computed as d, watch as D, resolveComponent as q, openBlock as v, createElementBlock as h, createElementVNode as E, toDisplayString as j, renderSlot as w, createCommentVNode as g, withDirectives as O, createBlock as V, withCtx as G, unref as K, vShow as I, createVNode as Q } from "vue";
2
2
  import { httpCall as ie } from "lkt-http-client";
3
3
  import { DataState as ce } from "lkt-data-state";
4
- const T = class T {
4
+ const N = class N {
5
5
  };
6
- T.debugEnabled = !1;
7
- let L = T;
8
- const p = (...u) => {
9
- L.debugEnabled && console.info("[LktItemCrud] ", ...u);
10
- }, Oe = (u = !0) => {
11
- L.debugEnabled = u;
6
+ N.debugEnabled = !1;
7
+ let U = N;
8
+ const i = (...u) => {
9
+ U.debugEnabled && console.info("[LktItemCrud] ", ...u);
10
+ }, we = (u = !0) => {
11
+ U.debugEnabled = u;
12
12
  }, ve = { class: "lkt-item-crud" }, fe = {
13
13
  key: 0,
14
14
  class: "lkt-item-crud_header"
15
- }, pe = { class: "lkt-item-crud_header-title" }, me = { class: "lkt-item-crud_header-slot" }, ye = { class: "lkt-item-crud-buttons" }, he = { key: 1 }, Se = { key: 1 }, ke = {
15
+ }, pe = { class: "lkt-item-crud_header-title" }, me = { class: "lkt-item-crud_header-slot" }, ye = { class: "lkt-item-crud-buttons" }, he = { key: 1 }, Se = { key: 1 }, be = {
16
16
  key: 1,
17
17
  class: "lkt-item-crud_content"
18
- }, be = {
18
+ }, ke = {
19
19
  key: 0,
20
20
  class: "lkt-grid-1"
21
21
  }, De = { name: "LktItemCrud", inheritAttrs: !1 }, ge = /* @__PURE__ */ ne({
@@ -48,80 +48,81 @@ const p = (...u) => {
48
48
  updateDisabled: { type: Boolean, default: !1 },
49
49
  dropDisabled: { type: Boolean, default: !1 },
50
50
  saveValidator: { type: Function, required: !1, default: () => !0 },
51
+ beforeEmitUpdate: { type: Function, required: !1, default: () => !0 },
51
52
  onCreate: { type: Function, required: !1, default: () => !0 },
52
53
  onUpdate: { type: Function, required: !1, default: () => !0 },
53
54
  insideModal: { type: Boolean, default: !1 }
54
55
  },
55
56
  emits: ["update:modelValue", "update:isCreate", "read", "create", "update", "drop", "perms", "error", "modified-data"],
56
- setup(u, { expose: $, emit: W }) {
57
- const e = u, M = se(), n = W;
57
+ setup(u, { expose: T, emit: W }) {
58
+ const e = u, L = se(), n = W;
58
59
  let X = [];
59
- const o = s(!0), r = s(e.modelValue), S = s(X), v = s(!1), f = s(!1), m = s(!1), i = s(200), C = s(null), B = s(null), k = s(new ce(r.value)), a = s(e.isCreate), Y = d(() => a.value ? e.createConfirm : e.updateConfirm), Z = d(() => a.value ? e.createConfirmData : e.updateConfirmData), x = d(() => a.value ? e.createResource : e.updateResource), ee = d(() => a.value ? { ...e.createData, ...JSON.parse(JSON.stringify(r.value)) } : { ...e.updateData, ...JSON.parse(JSON.stringify(r.value)) }), te = d(() => a.value ? e.createDisabled : e.updateDisabled), _ = d(() => !a.value && S.value.includes("update")), R = d(() => !a.value && S.value.includes("drop")), U = async () => {
60
- p("fetchItem"), o.value = !0, i.value = -1, m.value = !1;
60
+ const o = s(!0), r = s(e.modelValue), S = s(X), f = s(!1), p = s(!1), m = s(!1), c = s(200), C = s(null), B = s(null), b = s(new ce(r.value)), a = s(e.isCreate), Y = d(() => a.value ? e.createConfirm : e.updateConfirm), Z = d(() => a.value ? e.createConfirmData : e.updateConfirmData), $ = d(() => a.value ? e.createResource : e.updateResource), ee = d(() => a.value ? { ...e.createData, ...JSON.parse(JSON.stringify(r.value)) } : { ...e.updateData, ...JSON.parse(JSON.stringify(r.value)) }), te = d(() => a.value ? e.createDisabled : e.updateDisabled), _ = d(() => !a.value && S.value.includes("update")), R = d(() => !a.value && S.value.includes("drop")), M = async () => {
61
+ i("fetchItem"), o.value = !0, c.value = -1, m.value = !1;
61
62
  try {
62
63
  const t = await ie(e.readResource, e.readData);
63
- if (p("fetchItem -> response", t), o.value = !1, i.value = t.httpStatus, !t.success) {
64
- f.value = !1, i.value = t.httpStatus, n("error", t.httpStatus);
64
+ if (i("fetchItem -> response", t), o.value = !1, c.value = t.httpStatus, !t.success) {
65
+ p.value = !1, c.value = t.httpStatus, n("error", t.httpStatus);
65
66
  return;
66
67
  }
67
- f.value = !0, r.value = t.data, S.value = t.perms, k.value.increment(r.value).turnStoredIntoOriginal(), n("read", t);
68
+ p.value = !0, r.value = t.data, S.value = t.perms, b.value.increment(r.value).turnStoredIntoOriginal(), n("read", t);
68
69
  } catch {
69
- o.value = !1, f.value = !1, i.value = 404, n("error", 404);
70
+ o.value = !1, p.value = !1, c.value = 404, n("error", 404);
70
71
  return;
71
72
  }
72
- }, ae = d(() => o.value ? !1 : e.title || !!M["post-title"]);
73
+ }, ae = d(() => o.value ? !1 : e.title || !!L["post-title"]);
73
74
  D(() => e.modelValue, (t) => {
74
- r.value = t, k.value.increment(t);
75
+ r.value = t, b.value.increment(t);
75
76
  }, { deep: !0 }), D(r, (t) => {
76
- n("update:modelValue", r.value), k.value.increment(t);
77
+ i("item updated ->", r.value), typeof e.beforeEmitUpdate == "function" && (i("item updated -> has beforeEmitUpdate"), e.beforeEmitUpdate(r.value)), n("update:modelValue", r.value), i("item updated -> update dataState"), b.value.increment(t);
77
78
  }, { deep: !0 }), D(S, () => n("perms", S.value));
78
- const E = d(() => te.value || !a.value && !_.value || typeof e.saveValidator == "function" && !e.saveValidator(r.value) ? !1 : k.value.changed());
79
- D(E, (t) => n("modified-data", t)), D(a, (t) => n("update:isCreate", t)), e.readResource && !a.value ? U() : a.value && (f.value = !0, v.value = !0, o.value = !1);
79
+ const x = d(() => te.value || !a.value && !_.value || typeof e.saveValidator == "function" && !e.saveValidator(r.value) ? !1 : b.value.changed());
80
+ D(x, (t) => n("modified-data", t)), D(a, (t) => n("update:isCreate", t)), e.readResource && !a.value ? M() : a.value && (p.value = !0, f.value = !0, o.value = !1);
80
81
  const le = (t, l) => {
81
- if (o.value = !1, i.value = l.httpStatus, !l.success) {
82
+ if (o.value = !1, c.value = l.httpStatus, !l.success) {
82
83
  m.value = !0, n("error", l.httpStatus);
83
84
  return;
84
85
  }
85
86
  m.value = !0, n("drop", l);
86
87
  }, ue = (t, l) => {
87
- if (p("onSave -> received response:", l), x.value) {
88
- if (o.value = !1, i.value = l.httpStatus, !l.success) {
88
+ if (i("onSave -> received response:", l), $.value) {
89
+ if (o.value = !1, c.value = l.httpStatus, !l.success) {
89
90
  m.value = !0, n("error", l.httpStatus);
90
91
  return;
91
92
  }
92
93
  m.value = !0;
93
94
  }
94
- let b = a.value ? "create" : "update";
95
- a.value || (p("onSave -> turn stored data into original"), k.value.turnStoredIntoOriginal()), b === "create" ? typeof e.onCreate == "function" && (p("onSave -> trigger onCreate callback"), e.onCreate(l)) : typeof e.onUpdate == "function" && (p("onSave -> trigger onUpdate callback"), e.onUpdate(l)), !e.insideModal && l.autoReloadId && (p("onSave -> autoReloadId detected: ", l.autoReloadId), e.readData.id = l.autoReloadId, p("onSave -> turning off create mode"), a.value = !1, U()), n(b, l);
96
- }, J = () => {
97
- o.value = !0, i.value = -1;
95
+ let k = a.value ? "create" : "update";
96
+ a.value || (i("onSave -> turn stored data into original"), b.value.turnStoredIntoOriginal()), k === "create" ? typeof e.onCreate == "function" && (i("onSave -> trigger onCreate callback"), e.onCreate(l)) : typeof e.onUpdate == "function" && (i("onSave -> trigger onUpdate callback"), e.onUpdate(l)), !e.insideModal && l.autoReloadId && (i("onSave -> autoReloadId detected: ", l.autoReloadId), e.readData.id = l.autoReloadId, i("onSave -> turning off create mode"), a.value = !1, M()), n(k, l);
98
97
  }, F = () => {
98
+ o.value = !0, c.value = -1;
99
+ }, J = () => {
99
100
  o.value = !1;
100
101
  };
101
- $({
102
+ T({
102
103
  doDrop: () => {
103
104
  B.value && typeof B.value.click == "function" && B.value.click();
104
105
  },
105
- doRefresh: U,
106
+ doRefresh: M,
106
107
  doSave: () => {
107
108
  C.value && typeof C.value.click == "function" && C.value.click();
108
109
  }
109
110
  });
110
- const A = d(() => !e.hiddenDrop && !o.value && v.value && f.value), H = d(() => o.value ? !1 : a.value ? !0 : !e.hiddenSave && v.value && f.value), P = d(() => !o.value && !a.value && f.value), oe = d(() => !e.hiddenButtons && (H.value || A.value || P.value));
111
+ const A = d(() => !e.hiddenDrop && !o.value && f.value && p.value), H = d(() => o.value ? !1 : a.value ? !0 : !e.hiddenSave && f.value && p.value), P = d(() => !o.value && !a.value && p.value && !(e.dropDisabled && e.updateDisabled)), oe = d(() => !e.hiddenButtons && (H.value || A.value || P.value));
111
112
  return (t, l) => {
112
- const b = w("lkt-button"), re = w("lkt-field-switch"), z = w("lkt-http-info"), de = w("lkt-loader");
113
- return c(), h("article", ve, [
114
- ae.value ? (c(), h("header", fe, [
115
- j("h1", pe, N(u.title), 1),
116
- j("div", me, [
117
- O(t.$slots, "post-title", {
113
+ const k = q("lkt-button"), re = q("lkt-field-switch"), z = q("lkt-http-info"), de = q("lkt-loader");
114
+ return v(), h("article", ve, [
115
+ ae.value ? (v(), h("header", fe, [
116
+ E("h1", pe, j(u.title), 1),
117
+ E("div", me, [
118
+ w(t.$slots, "post-title", {
118
119
  item: r.value,
119
120
  loading: o.value
120
121
  })
121
122
  ])
122
123
  ])) : g("", !0),
123
- V(j("div", ye, [
124
- a.value ? g("", !0) : V((c(), q(b, {
124
+ O(E("div", ye, [
125
+ a.value ? g("", !0) : O((v(), V(k, {
125
126
  key: 0,
126
127
  ref: (y) => B.value = y,
127
128
  palette: "danger",
@@ -130,53 +131,53 @@ const p = (...u) => {
130
131
  "confirm-data": u.dropConfirmData,
131
132
  resource: u.dropResource,
132
133
  "resource-data": u.dropData,
133
- onLoading: J,
134
- onLoaded: F,
134
+ onLoading: F,
135
+ onLoaded: J,
135
136
  onClick: le
136
137
  }, {
137
138
  default: G(() => [
138
- K(M)["button-drop"] ? O(t.$slots, "button-drop", {
139
+ K(L)["button-drop"] ? w(t.$slots, "button-drop", {
139
140
  key: 0,
140
141
  item: r.value,
141
- editMode: v.value,
142
+ editMode: f.value,
142
143
  isCreate: a.value,
143
144
  canUpdate: _.value,
144
145
  canDrop: R.value
145
- }) : (c(), h("span", he, N(u.dropText), 1))
146
+ }) : (v(), h("span", he, j(u.dropText), 1))
146
147
  ]),
147
148
  _: 3
148
149
  }, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"])), [
149
150
  [I, A.value]
150
151
  ]),
151
- V(Q(b, {
152
+ O(Q(k, {
152
153
  ref: (y) => C.value = y,
153
154
  palette: "success",
154
- disabled: !E.value,
155
+ disabled: !x.value,
155
156
  "confirm-modal": Y.value,
156
157
  "confirm-data": Z.value,
157
- resource: x.value,
158
+ resource: $.value,
158
159
  "resource-data": ee.value,
159
- onLoading: J,
160
- onLoaded: F,
160
+ onLoading: F,
161
+ onLoaded: J,
161
162
  onClick: ue
162
163
  }, {
163
164
  default: G(() => [
164
- K(M)["button-save"] ? O(t.$slots, "button-save", {
165
+ K(L)["button-save"] ? w(t.$slots, "button-save", {
165
166
  key: 0,
166
167
  item: r.value,
167
- editMode: v.value,
168
+ editMode: f.value,
168
169
  isCreate: a.value,
169
170
  canUpdate: _.value,
170
171
  canDrop: R.value
171
- }) : (c(), h("span", Se, N(u.saveText), 1))
172
+ }) : (v(), h("span", Se, j(u.saveText), 1))
172
173
  ]),
173
174
  _: 3
174
175
  }, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"]), [
175
176
  [I, H.value]
176
177
  ]),
177
- V(Q(re, {
178
- modelValue: v.value,
179
- "onUpdate:modelValue": l[0] || (l[0] = (y) => v.value = y),
178
+ O(Q(re, {
179
+ modelValue: f.value,
180
+ "onUpdate:modelValue": l[0] || (l[0] = (y) => f.value = y),
180
181
  label: u.editModeText
181
182
  }, null, 8, ["modelValue", "label"]), [
182
183
  [I, P.value]
@@ -184,39 +185,39 @@ const p = (...u) => {
184
185
  ], 512), [
185
186
  [I, oe.value]
186
187
  ]),
187
- o.value ? g("", !0) : (c(), h("div", ke, [
188
- f.value ? (c(), h("div", be, [
189
- m.value ? (c(), q(z, {
188
+ o.value ? g("", !0) : (v(), h("div", be, [
189
+ p.value ? (v(), h("div", ke, [
190
+ m.value ? (v(), V(z, {
190
191
  key: 0,
191
- code: i.value,
192
+ code: c.value,
192
193
  quick: "",
193
- palette: i.value === 200 ? "success" : "danger",
194
+ palette: c.value === 200 ? "success" : "danger",
194
195
  "can-close": "",
195
196
  onClose: l[1] || (l[1] = (y) => m.value = !1)
196
197
  }, null, 8, ["code", "palette"])) : g("", !0),
197
- O(t.$slots, "item", {
198
+ w(t.$slots, "item", {
198
199
  item: r.value,
199
200
  loading: o.value,
200
- editMode: v.value,
201
+ editMode: f.value,
201
202
  isCreate: a.value,
202
203
  canUpdate: _.value,
203
204
  canDrop: R.value
204
205
  })
205
- ])) : (c(), q(z, {
206
+ ])) : (v(), V(z, {
206
207
  key: 1,
207
- code: i.value
208
+ code: c.value
208
209
  }, null, 8, ["code"]))
209
210
  ])),
210
- o.value ? (c(), q(de, { key: 2 })) : g("", !0)
211
+ o.value ? (v(), V(de, { key: 2 })) : g("", !0)
211
212
  ]);
212
213
  };
213
214
  }
214
- }), Ve = {
215
- install: (u, $ = {}) => {
215
+ }), Oe = {
216
+ install: (u, T = {}) => {
216
217
  u.component("lkt-item-crud") === void 0 && u.component("lkt-item-crud", ge);
217
218
  }
218
219
  };
219
220
  export {
220
- Oe as debugLktItemCrud,
221
- Ve as default
221
+ we as debugLktItemCrud,
222
+ Oe as default
222
223
  };
@@ -113,6 +113,11 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
113
113
  required: false;
114
114
  default: () => boolean;
115
115
  };
116
+ beforeEmitUpdate: {
117
+ type: FunctionConstructor;
118
+ required: false;
119
+ default: () => boolean;
120
+ };
116
121
  onCreate: {
117
122
  type: FunctionConstructor;
118
123
  required: false;
@@ -256,6 +261,11 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
256
261
  required: false;
257
262
  default: () => boolean;
258
263
  };
264
+ beforeEmitUpdate: {
265
+ type: FunctionConstructor;
266
+ required: false;
267
+ default: () => boolean;
268
+ };
259
269
  onCreate: {
260
270
  type: FunctionConstructor;
261
271
  required: false;
@@ -306,6 +316,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
306
316
  updateDisabled: boolean;
307
317
  dropDisabled: boolean;
308
318
  saveValidator: Function;
319
+ beforeEmitUpdate: Function;
309
320
  insideModal: boolean;
310
321
  }, {}>, {
311
322
  "post-title"?(_: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lkt-item-crud",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "module": "./dist/build.js",
@@ -43,6 +43,7 @@ const props = defineProps({
43
43
  dropDisabled: {type: Boolean, default: false},
44
44
 
45
45
  saveValidator: {type: Function, required: false, default: () => true},
46
+ beforeEmitUpdate: {type: Function, required: false, default: () => true},
46
47
 
47
48
  onCreate: {type: Function, required: false, default: () => true},
48
49
  onUpdate: {type: Function, required: false, default: () => true},
@@ -139,7 +140,13 @@ watch(() => props.modelValue, v => {
139
140
  }, {deep: true});
140
141
 
141
142
  watch(item, (v) => {
143
+ debug('item updated ->', item.value);
144
+ if (typeof props.beforeEmitUpdate === 'function') {
145
+ debug('item updated -> has beforeEmitUpdate');
146
+ props.beforeEmitUpdate(item.value);
147
+ }
142
148
  emit('update:modelValue', item.value);
149
+ debug('item updated -> update dataState');
143
150
  dataState.value.increment(v);
144
151
  }, {deep: true});
145
152
 
@@ -255,7 +262,8 @@ const showDropButton = computed(() => {
255
262
  showSwitchButton = computed(() => {
256
263
  return !isLoading.value
257
264
  && !createMode.value
258
- && httpSuccessRead.value;
265
+ && httpSuccessRead.value
266
+ && !(props.dropDisabled && props.updateDisabled);
259
267
  }),
260
268
  showButtons = computed(() => {
261
269
  return !props.hiddenButtons && (showSaveButton.value || showDropButton.value || showSwitchButton.value);