lkt-item-crud 1.1.11 → 1.1.13

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