lkt-item-crud 1.1.2 → 1.1.4

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,4 +1,4 @@
1
1
  export { Be as default };
2
2
  declare namespace Be {
3
- function install(a: any, N?: {}): void;
3
+ function install(a: any, U?: {}): void;
4
4
  }
package/dist/build.js CHANGED
@@ -1,17 +1,17 @@
1
- import { defineComponent as re, useSlots as ue, ref as n, computed as o, watch as B, resolveComponent as w, openBlock as i, createElementBlock as m, createElementVNode as M, toDisplayString as I, renderSlot as R, createCommentVNode as C, withDirectives as V, createBlock as _, withCtx as F, unref as H, vShow as q, createVNode as P } from "vue";
1
+ import { defineComponent as ue, useSlots as re, ref as s, computed as o, watch as B, resolveComponent as w, openBlock as i, createElementBlock as m, createElementVNode as j, toDisplayString as M, renderSlot as O, createCommentVNode as h, withDirectives as R, createBlock as V, withCtx as A, unref as H, vShow as q, createVNode as P } from "vue";
2
2
  import { httpCall as oe } from "lkt-http-client";
3
3
  import { DataState as de } from "lkt-data-state";
4
- const se = { class: "lkt-item-crud" }, ne = {
4
+ const ne = { class: "lkt-item-crud" }, se = {
5
5
  key: 0,
6
6
  class: "lkt-item-crud_header"
7
- }, ie = { class: "lkt-item-crud_header-title" }, ce = { class: "lkt-item-crud_header-slot" }, ve = { class: "lkt-item-crud-buttons" }, fe = { key: 1 }, pe = { key: 1 }, me = {
7
+ }, ie = { class: "lkt-item-crud_header-title" }, ce = { class: "lkt-item-crud_header-slot" }, fe = { class: "lkt-item-crud-buttons" }, ve = { key: 1 }, pe = { key: 1 }, me = {
8
8
  key: 1,
9
9
  class: "lkt-item-crud_content"
10
10
  }, ye = {
11
11
  key: 0,
12
12
  class: "lkt-grid-1"
13
- }, he = { name: "LktItemCrud", inheritAttrs: !1 }, Ce = /* @__PURE__ */ re({
14
- ...he,
13
+ }, Ce = { name: "LktItemCrud", inheritAttrs: !1 }, he = /* @__PURE__ */ ue({
14
+ ...Ce,
15
15
  props: {
16
16
  modelValue: { type: Object, required: !1, default: () => ({}) },
17
17
  title: { type: String, default: "" },
@@ -33,61 +33,63 @@ const se = { class: "lkt-item-crud" }, ne = {
33
33
  createConfirm: { type: String, default: "" },
34
34
  updateConfirm: { type: String, default: "" },
35
35
  dropConfirm: { type: String, default: "" },
36
- createConfirmData: { type: String, default: "" },
37
- updateConfirmData: { type: String, default: "" },
38
- dropConfirmData: { type: String, default: "" },
36
+ createConfirmData: { type: Object, default: () => ({}) },
37
+ updateConfirmData: { type: Object, default: () => ({}) },
38
+ dropConfirmData: { type: Object, default: () => ({}) },
39
39
  createDisabled: { type: Boolean, default: !1 },
40
40
  updateDisabled: { type: Boolean, default: !1 },
41
41
  dropDisabled: { type: Boolean, default: !1 },
42
- saveValidator: { type: Function, required: !1, default: () => !0 }
42
+ saveValidator: { type: Function, required: !1, default: () => !0 },
43
+ onCreate: { type: Function, required: !1, default: () => !0 },
44
+ onUpdate: { type: Function, required: !1, default: () => !0 }
43
45
  },
44
46
  emits: ["update:modelValue", "read", "create", "update", "drop", "perms", "error", "modified-data"],
45
- setup(a, { expose: N, emit: z }) {
46
- const e = a, O = ue(), d = z;
47
+ setup(a, { expose: U, emit: z }) {
48
+ const e = a, _ = re(), d = z;
47
49
  let G = [];
48
- const l = n(!0), u = n(e.modelValue), y = n(G), c = n(!1), v = n(!1), f = n(!1), s = n(200), S = n(null), k = n(null), h = n(new de(u.value)), K = o(() => e.isCreate ? e.createConfirm : e.updateConfirm), Q = o(() => e.isCreate ? e.createConfirmData : e.updateConfirmData), T = o(() => e.isCreate ? e.createResource : e.updateResource), W = o(() => e.isCreate ? { ...e.createData, ...JSON.parse(JSON.stringify(u.value)) } : { ...e.updateData, ...JSON.parse(JSON.stringify(u.value)) }), X = o(() => e.isCreate ? e.createDisabled : e.updateDisabled), D = o(() => !e.isCreate && y.value.includes("update")), g = o(() => !e.isCreate && y.value.includes("drop")), L = async () => {
49
- l.value = !0, s.value = -1, f.value = !1;
50
+ const l = s(!0), r = s(e.modelValue), y = s(G), c = s(!1), f = s(!1), v = s(!1), n = s(200), S = s(null), k = s(null), C = s(new de(r.value)), K = o(() => e.isCreate ? e.createConfirm : e.updateConfirm), Q = o(() => e.isCreate ? e.createConfirmData : e.updateConfirmData), I = o(() => e.isCreate ? e.createResource : e.updateResource), W = o(() => e.isCreate ? { ...e.createData, ...JSON.parse(JSON.stringify(r.value)) } : { ...e.updateData, ...JSON.parse(JSON.stringify(r.value)) }), X = o(() => e.isCreate ? e.createDisabled : e.updateDisabled), D = o(() => !e.isCreate && y.value.includes("update")), b = o(() => !e.isCreate && y.value.includes("drop")), L = async () => {
51
+ l.value = !0, n.value = -1, v.value = !1;
50
52
  try {
51
53
  const t = await oe(e.readResource, e.readData);
52
- if (l.value = !1, s.value = t.httpStatus, !t.success) {
53
- v.value = !1, s.value = t.httpStatus, d("error", t.httpStatus);
54
+ if (l.value = !1, n.value = t.httpStatus, !t.success) {
55
+ f.value = !1, n.value = t.httpStatus, d("error", t.httpStatus);
54
56
  return;
55
57
  }
56
- v.value = !0, u.value = t.data, y.value = t.perms, h.value.increment(u.value).turnStoredIntoOriginal(), d("read", t);
58
+ f.value = !0, r.value = t.data, y.value = t.perms, C.value.increment(r.value).turnStoredIntoOriginal(), d("read", t);
57
59
  } catch {
58
- l.value = !1, v.value = !1, s.value = 404, d("error", 404);
60
+ l.value = !1, f.value = !1, n.value = 404, d("error", 404);
59
61
  return;
60
62
  }
61
- }, Y = o(() => l.value ? !1 : e.title || !!O["post-title"]);
63
+ }, Y = o(() => l.value ? !1 : e.title || !!_["post-title"]);
62
64
  B(() => e.modelValue, (t) => {
63
- u.value = t, h.value.increment(t);
64
- }, { deep: !0 }), B(u, (t) => {
65
- d("update:modelValue", u.value), h.value.increment(t);
65
+ r.value = t, C.value.increment(t);
66
+ }, { deep: !0 }), B(r, (t) => {
67
+ d("update:modelValue", r.value), C.value.increment(t);
66
68
  }, { deep: !0 }), B(y, () => d("perms", y.value));
67
- const $ = o(() => X.value || !e.isCreate && !D.value || typeof e.saveValidator == "function" && !e.saveValidator(u.value) ? !1 : h.value.changed());
68
- B($, (t) => d("modified-data", t)), e.readResource && !e.isCreate ? L() : e.isCreate && (v.value = !0, c.value = !0, l.value = !1);
69
- const Z = (t, r) => {
70
- if (l.value = !1, s.value = r.httpStatus, !r.success) {
71
- f.value = !0, d("error", r.httpStatus);
69
+ const N = o(() => X.value || !e.isCreate && !D.value || typeof e.saveValidator == "function" && !e.saveValidator(r.value) ? !1 : C.value.changed());
70
+ B(N, (t) => d("modified-data", t)), e.readResource && !e.isCreate ? L() : e.isCreate && (f.value = !0, c.value = !0, l.value = !1);
71
+ const Z = (t, u) => {
72
+ if (l.value = !1, n.value = u.httpStatus, !u.success) {
73
+ v.value = !0, d("error", u.httpStatus);
72
74
  return;
73
75
  }
74
- f.value = !0, d("drop", r);
75
- }, ee = (t, r) => {
76
- if (T.value) {
77
- if (l.value = !1, s.value = r.httpStatus, !r.success) {
78
- f.value = !0, d("error", r.httpStatus);
76
+ v.value = !0, d("drop", u);
77
+ }, ee = (t, u) => {
78
+ if (I.value) {
79
+ if (l.value = !1, n.value = u.httpStatus, !u.success) {
80
+ v.value = !0, d("error", u.httpStatus);
79
81
  return;
80
82
  }
81
- f.value = !0;
83
+ v.value = !0;
82
84
  }
83
- let b = e.isCreate ? "create" : "update";
84
- e.isCreate || h.value.turnStoredIntoOriginal(), r.autoReloadId && (e.readData.id = r.autoReloadId, L()), d(b, r);
85
- }, x = () => {
86
- l.value = !0, s.value = -1;
87
- }, j = () => {
85
+ let g = e.isCreate ? "create" : "update";
86
+ e.isCreate || C.value.turnStoredIntoOriginal(), u.autoReloadId && (e.readData.id = u.autoReloadId, L()), e.isCreate && typeof e.onCreate == "function" && e.onCreate(), !e.isCreate && typeof e.onUpdate == "function" && e.onUpdate(), d(g, u);
87
+ }, T = () => {
88
+ l.value = !0, n.value = -1;
89
+ }, $ = () => {
88
90
  l.value = !1;
89
91
  };
90
- N({
92
+ U({
91
93
  doDrop: () => {
92
94
  k.value && typeof k.value.click == "function" && k.value.click();
93
95
  },
@@ -96,76 +98,76 @@ const se = { class: "lkt-item-crud" }, ne = {
96
98
  S.value && typeof S.value.click == "function" && S.value.click();
97
99
  }
98
100
  });
99
- const U = o(() => !e.hiddenDrop && !l.value && c.value && v.value), J = o(() => l.value ? !1 : e.isCreate ? !0 : !e.hiddenSave && c.value && v.value), E = o(() => !l.value && !e.isCreate && v.value), te = o(() => !e.hiddenButtons && (J.value || U.value || E.value));
100
- return (t, r) => {
101
- const b = w("lkt-button"), ae = w("lkt-field-switch"), A = w("lkt-http-info"), le = w("lkt-loader");
102
- return i(), m("article", se, [
103
- Y.value ? (i(), m("header", ne, [
104
- M("h1", ie, I(a.title), 1),
105
- M("div", ce, [
106
- R(t.$slots, "post-title", {
107
- item: u.value,
101
+ const x = o(() => !e.hiddenDrop && !l.value && c.value && f.value), J = o(() => l.value ? !1 : e.isCreate ? !0 : !e.hiddenSave && c.value && f.value), E = o(() => !l.value && !e.isCreate && f.value), te = o(() => !e.hiddenButtons && (J.value || x.value || E.value));
102
+ return (t, u) => {
103
+ const g = w("lkt-button"), ae = w("lkt-field-switch"), F = w("lkt-http-info"), le = w("lkt-loader");
104
+ return i(), m("article", ne, [
105
+ Y.value ? (i(), m("header", se, [
106
+ j("h1", ie, M(a.title), 1),
107
+ j("div", ce, [
108
+ O(t.$slots, "post-title", {
109
+ item: r.value,
108
110
  loading: l.value
109
111
  })
110
112
  ])
111
- ])) : C("", !0),
112
- V(M("div", ve, [
113
- a.isCreate ? C("", !0) : V((i(), _(b, {
113
+ ])) : h("", !0),
114
+ R(j("div", fe, [
115
+ a.isCreate ? h("", !0) : R((i(), V(g, {
114
116
  key: 0,
115
117
  ref: (p) => k.value = p,
116
118
  palette: "danger",
117
- disabled: a.dropDisabled || !g.value,
119
+ disabled: a.dropDisabled || !b.value,
118
120
  "confirm-modal": a.dropConfirm,
119
121
  "confirm-data": a.dropConfirmData,
120
122
  resource: a.dropResource,
121
123
  "resource-data": a.dropData,
122
- onLoading: x,
123
- onLoaded: j,
124
+ onLoading: T,
125
+ onLoaded: $,
124
126
  onClick: Z
125
127
  }, {
126
- default: F(() => [
127
- H(O)["button-drop"] ? R(t.$slots, "button-drop", {
128
+ default: A(() => [
129
+ H(_)["button-drop"] ? O(t.$slots, "button-drop", {
128
130
  key: 0,
129
- item: u.value,
131
+ item: r.value,
130
132
  editMode: c.value,
131
133
  isCreate: a.isCreate,
132
134
  canUpdate: D.value,
133
- canDrop: g.value
134
- }) : (i(), m("span", fe, I(a.dropText), 1))
135
+ canDrop: b.value
136
+ }) : (i(), m("span", ve, M(a.dropText), 1))
135
137
  ]),
136
138
  _: 3
137
139
  }, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"])), [
138
- [q, U.value]
140
+ [q, x.value]
139
141
  ]),
140
- V(P(b, {
142
+ R(P(g, {
141
143
  ref: (p) => S.value = p,
142
144
  palette: "success",
143
- disabled: !$.value,
145
+ disabled: !N.value,
144
146
  "confirm-modal": K.value,
145
147
  "confirm-data": Q.value,
146
- resource: T.value,
148
+ resource: I.value,
147
149
  "resource-data": W.value,
148
- onLoading: x,
149
- onLoaded: j,
150
+ onLoading: T,
151
+ onLoaded: $,
150
152
  onClick: ee
151
153
  }, {
152
- default: F(() => [
153
- H(O)["button-save"] ? R(t.$slots, "button-save", {
154
+ default: A(() => [
155
+ H(_)["button-save"] ? O(t.$slots, "button-save", {
154
156
  key: 0,
155
- item: u.value,
157
+ item: r.value,
156
158
  editMode: c.value,
157
159
  isCreate: a.isCreate,
158
160
  canUpdate: D.value,
159
- canDrop: g.value
160
- }) : (i(), m("span", pe, I(a.saveText), 1))
161
+ canDrop: b.value
162
+ }) : (i(), m("span", pe, M(a.saveText), 1))
161
163
  ]),
162
164
  _: 3
163
165
  }, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"]), [
164
166
  [q, J.value]
165
167
  ]),
166
- V(P(ae, {
168
+ R(P(ae, {
167
169
  modelValue: c.value,
168
- "onUpdate:modelValue": r[0] || (r[0] = (p) => c.value = p),
170
+ "onUpdate:modelValue": u[0] || (u[0] = (p) => c.value = p),
169
171
  label: a.editModeText
170
172
  }, null, 8, ["modelValue", "label"]), [
171
173
  [q, E.value]
@@ -173,36 +175,36 @@ const se = { class: "lkt-item-crud" }, ne = {
173
175
  ], 512), [
174
176
  [q, te.value]
175
177
  ]),
176
- l.value ? C("", !0) : (i(), m("div", me, [
177
- v.value ? (i(), m("div", ye, [
178
- f.value ? (i(), _(A, {
178
+ l.value ? h("", !0) : (i(), m("div", me, [
179
+ f.value ? (i(), m("div", ye, [
180
+ v.value ? (i(), V(F, {
179
181
  key: 0,
180
- code: s.value,
182
+ code: n.value,
181
183
  quick: "",
182
- palette: s.value === 200 ? "success" : "danger",
184
+ palette: n.value === 200 ? "success" : "danger",
183
185
  "can-close": "",
184
- onClose: r[1] || (r[1] = (p) => f.value = !1)
185
- }, null, 8, ["code", "palette"])) : C("", !0),
186
- R(t.$slots, "item", {
187
- item: u.value,
186
+ onClose: u[1] || (u[1] = (p) => v.value = !1)
187
+ }, null, 8, ["code", "palette"])) : h("", !0),
188
+ O(t.$slots, "item", {
189
+ item: r.value,
188
190
  loading: l.value,
189
191
  editMode: c.value,
190
192
  isCreate: a.isCreate,
191
193
  canUpdate: D.value,
192
- canDrop: g.value
194
+ canDrop: b.value
193
195
  })
194
- ])) : (i(), _(A, {
196
+ ])) : (i(), V(F, {
195
197
  key: 1,
196
- code: s.value
198
+ code: n.value
197
199
  }, null, 8, ["code"]))
198
200
  ])),
199
- l.value ? (i(), _(le, { key: 2 })) : C("", !0)
201
+ l.value ? (i(), V(le, { key: 2 })) : h("", !0)
200
202
  ]);
201
203
  };
202
204
  }
203
205
  }), Be = {
204
- install: (a, N = {}) => {
205
- a.component("lkt-item-crud") === void 0 && a.component("lkt-item-crud", Ce);
206
+ install: (a, U = {}) => {
207
+ a.component("lkt-item-crud") === void 0 && a.component("lkt-item-crud", he);
206
208
  }
207
209
  };
208
210
  export {
@@ -85,16 +85,16 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
85
85
  default: string;
86
86
  };
87
87
  createConfirmData: {
88
- type: StringConstructor;
89
- default: string;
88
+ type: ObjectConstructor;
89
+ default: () => {};
90
90
  };
91
91
  updateConfirmData: {
92
- type: StringConstructor;
93
- default: string;
92
+ type: ObjectConstructor;
93
+ default: () => {};
94
94
  };
95
95
  dropConfirmData: {
96
- type: StringConstructor;
97
- default: string;
96
+ type: ObjectConstructor;
97
+ default: () => {};
98
98
  };
99
99
  createDisabled: {
100
100
  type: BooleanConstructor;
@@ -113,6 +113,16 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
113
113
  required: false;
114
114
  default: () => boolean;
115
115
  };
116
+ onCreate: {
117
+ type: FunctionConstructor;
118
+ required: false;
119
+ default: () => boolean;
120
+ };
121
+ onUpdate: {
122
+ type: FunctionConstructor;
123
+ required: false;
124
+ default: () => boolean;
125
+ };
116
126
  }, {
117
127
  doDrop: () => void;
118
128
  doRefresh: () => Promise<void>;
@@ -213,16 +223,16 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
213
223
  default: string;
214
224
  };
215
225
  createConfirmData: {
216
- type: StringConstructor;
217
- default: string;
226
+ type: ObjectConstructor;
227
+ default: () => {};
218
228
  };
219
229
  updateConfirmData: {
220
- type: StringConstructor;
221
- default: string;
230
+ type: ObjectConstructor;
231
+ default: () => {};
222
232
  };
223
233
  dropConfirmData: {
224
- type: StringConstructor;
225
- default: string;
234
+ type: ObjectConstructor;
235
+ default: () => {};
226
236
  };
227
237
  createDisabled: {
228
238
  type: BooleanConstructor;
@@ -241,6 +251,16 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
241
251
  required: false;
242
252
  default: () => boolean;
243
253
  };
254
+ onCreate: {
255
+ type: FunctionConstructor;
256
+ required: false;
257
+ default: () => boolean;
258
+ };
259
+ onUpdate: {
260
+ type: FunctionConstructor;
261
+ required: false;
262
+ default: () => boolean;
263
+ };
244
264
  }>> & {
245
265
  onError?: ((...args: any[]) => any) | undefined;
246
266
  onDrop?: ((...args: any[]) => any) | undefined;
@@ -252,6 +272,8 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
252
272
  "onModified-data"?: ((...args: any[]) => any) | undefined;
253
273
  }, {
254
274
  title: string;
275
+ onUpdate: Function;
276
+ onCreate: Function;
255
277
  modelValue: Record<string, any>;
256
278
  editModeText: string;
257
279
  saveText: string;
@@ -267,9 +289,9 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
267
289
  createConfirm: string;
268
290
  updateConfirm: string;
269
291
  dropConfirm: string;
270
- createConfirmData: string;
271
- updateConfirmData: string;
272
- dropConfirmData: string;
292
+ createConfirmData: Record<string, any>;
293
+ updateConfirmData: Record<string, any>;
294
+ dropConfirmData: Record<string, any>;
273
295
  createDisabled: boolean;
274
296
  updateDisabled: boolean;
275
297
  dropDisabled: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lkt-item-crud",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "module": "./dist/build.js",
@@ -33,15 +33,18 @@ const props = defineProps({
33
33
  updateConfirm: {type: String, default: ''},
34
34
  dropConfirm: {type: String, default: ''},
35
35
 
36
- createConfirmData: {type: String, default: ''},
37
- updateConfirmData: {type: String, default: ''},
38
- dropConfirmData: {type: String, default: ''},
36
+ createConfirmData: {type: Object, default: () => ({})},
37
+ updateConfirmData: {type: Object, default: () => ({})},
38
+ dropConfirmData: {type: Object, default: () => ({})},
39
39
 
40
40
  createDisabled: {type: Boolean, default: false},
41
41
  updateDisabled: {type: Boolean, default: false},
42
42
  dropDisabled: {type: Boolean, default: false},
43
43
 
44
44
  saveValidator: {type: Function, required: false, default: () => true},
45
+
46
+ onCreate: {type: Function, required: false, default: () => true},
47
+ onUpdate: {type: Function, required: false, default: () => true},
45
48
  });
46
49
 
47
50
  const slots = useSlots();
@@ -186,8 +189,9 @@ const onDrop = ($event: PointerEvent, r: HTTPResponse) => {
186
189
  props.readData['id'] = r.autoReloadId;
187
190
  fetchItem();
188
191
  }
192
+ if (props.isCreate && typeof props.onCreate === 'function') props.onCreate();
193
+ if (!props.isCreate && typeof props.onUpdate === 'function') props.onUpdate();
189
194
  emit(emits, r)
190
-
191
195
  },
192
196
  onButtonLoading = () => {
193
197
  isLoading.value = true;