lkt-item-crud 1.1.3 → 1.1.5

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, I?: {}): void;
3
+ function install(a: any, U?: {}): void;
4
4
  }
package/dist/build.js CHANGED
@@ -1,17 +1,17 @@
1
- import { defineComponent as ue, useSlots as re, ref as n, 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 C, withDirectives as R, createBlock as V, withCtx as F, unref as H, vShow as _, 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__ */ ue({
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: "" },
@@ -39,55 +39,57 @@ const se = { class: "lkt-item-crud" }, ne = {
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: I, emit: z }) {
46
- const e = a, q = re(), 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), r = 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(r.value)), K = o(() => e.isCreate ? e.createConfirm : e.updateConfirm), Q = o(() => e.isCreate ? e.createConfirmData : e.updateConfirmData), N = 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 () => {
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, r.value = t.data, y.value = t.perms, h.value.increment(r.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 || !!q["post-title"]);
63
+ }, Y = o(() => l.value ? !1 : e.title || !!_["post-title"]);
62
64
  B(() => e.modelValue, (t) => {
63
- r.value = t, h.value.increment(t);
65
+ r.value = t, C.value.increment(t);
64
66
  }, { deep: !0 }), B(r, (t) => {
65
- d("update:modelValue", r.value), h.value.increment(t);
67
+ d("update:modelValue", r.value), C.value.increment(t);
66
68
  }, { deep: !0 }), B(y, () => d("perms", y.value));
67
- const T = o(() => X.value || !e.isCreate && !D.value || typeof e.saveValidator == "function" && !e.saveValidator(r.value) ? !1 : h.value.changed());
68
- B(T, (t) => d("modified-data", t)), e.readResource && !e.isCreate ? L() : e.isCreate && (v.value = !0, c.value = !0, l.value = !1);
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);
69
71
  const Z = (t, u) => {
70
- if (l.value = !1, s.value = u.httpStatus, !u.success) {
71
- f.value = !0, d("error", u.httpStatus);
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", u);
76
+ v.value = !0, d("drop", u);
75
77
  }, ee = (t, u) => {
76
- if (N.value) {
77
- if (l.value = !1, s.value = u.httpStatus, !u.success) {
78
- f.value = !0, d("error", u.httpStatus);
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
85
  let g = e.isCreate ? "create" : "update";
84
- e.isCreate || h.value.turnStoredIntoOriginal(), u.autoReloadId && (e.readData.id = u.autoReloadId, L()), d(g, u);
86
+ e.isCreate || C.value.turnStoredIntoOriginal(), u.autoReloadId && (e.readData.id = u.autoReloadId, L()), e.isCreate ? typeof e.onCreate == "function" && e.onCreate() : typeof e.onUpdate == "function" && e.onUpdate(), d(g, u);
87
+ }, T = () => {
88
+ l.value = !0, n.value = -1;
85
89
  }, $ = () => {
86
- l.value = !0, s.value = -1;
87
- }, x = () => {
88
90
  l.value = !1;
89
91
  };
90
- I({
92
+ U({
91
93
  doDrop: () => {
92
94
  k.value && typeof k.value.click == "function" && k.value.click();
93
95
  },
@@ -96,11 +98,11 @@ 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));
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));
100
102
  return (t, u) => {
101
- const g = 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, [
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, [
104
106
  j("h1", ie, M(a.title), 1),
105
107
  j("div", ce, [
106
108
  O(t.$slots, "post-title", {
@@ -108,9 +110,9 @@ const se = { class: "lkt-item-crud" }, ne = {
108
110
  loading: l.value
109
111
  })
110
112
  ])
111
- ])) : C("", !0),
112
- R(j("div", ve, [
113
- a.isCreate ? C("", !0) : R((i(), V(g, {
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",
@@ -119,38 +121,38 @@ const se = { class: "lkt-item-crud" }, ne = {
119
121
  "confirm-data": a.dropConfirmData,
120
122
  resource: a.dropResource,
121
123
  "resource-data": a.dropData,
122
- onLoading: $,
123
- onLoaded: x,
124
+ onLoading: T,
125
+ onLoaded: $,
124
126
  onClick: Z
125
127
  }, {
126
- default: F(() => [
127
- H(q)["button-drop"] ? O(t.$slots, "button-drop", {
128
+ default: A(() => [
129
+ H(_)["button-drop"] ? O(t.$slots, "button-drop", {
128
130
  key: 0,
129
131
  item: r.value,
130
132
  editMode: c.value,
131
133
  isCreate: a.isCreate,
132
134
  canUpdate: D.value,
133
135
  canDrop: b.value
134
- }) : (i(), m("span", fe, M(a.dropText), 1))
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
- [_, U.value]
140
+ [q, x.value]
139
141
  ]),
140
142
  R(P(g, {
141
143
  ref: (p) => S.value = p,
142
144
  palette: "success",
143
- disabled: !T.value,
145
+ disabled: !N.value,
144
146
  "confirm-modal": K.value,
145
147
  "confirm-data": Q.value,
146
- resource: N.value,
148
+ resource: I.value,
147
149
  "resource-data": W.value,
148
- onLoading: $,
149
- onLoaded: x,
150
+ onLoading: T,
151
+ onLoaded: $,
150
152
  onClick: ee
151
153
  }, {
152
- default: F(() => [
153
- H(q)["button-save"] ? O(t.$slots, "button-save", {
154
+ default: A(() => [
155
+ H(_)["button-save"] ? O(t.$slots, "button-save", {
154
156
  key: 0,
155
157
  item: r.value,
156
158
  editMode: c.value,
@@ -161,28 +163,28 @@ const se = { class: "lkt-item-crud" }, ne = {
161
163
  ]),
162
164
  _: 3
163
165
  }, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"]), [
164
- [_, J.value]
166
+ [q, J.value]
165
167
  ]),
166
168
  R(P(ae, {
167
169
  modelValue: c.value,
168
170
  "onUpdate:modelValue": u[0] || (u[0] = (p) => c.value = p),
169
171
  label: a.editModeText
170
172
  }, null, 8, ["modelValue", "label"]), [
171
- [_, E.value]
173
+ [q, E.value]
172
174
  ])
173
175
  ], 512), [
174
- [_, te.value]
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(), V(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: u[1] || (u[1] = (p) => f.value = !1)
185
- }, null, 8, ["code", "palette"])) : C("", !0),
186
+ onClose: u[1] || (u[1] = (p) => v.value = !1)
187
+ }, null, 8, ["code", "palette"])) : h("", !0),
186
188
  O(t.$slots, "item", {
187
189
  item: r.value,
188
190
  loading: l.value,
@@ -191,18 +193,18 @@ const se = { class: "lkt-item-crud" }, ne = {
191
193
  canUpdate: D.value,
192
194
  canDrop: b.value
193
195
  })
194
- ])) : (i(), V(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(), V(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, I = {}) => {
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 {
@@ -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>;
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lkt-item-crud",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "module": "./dist/build.js",
@@ -42,6 +42,9 @@ const props = defineProps({
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,12 @@ const onDrop = ($event: PointerEvent, r: HTTPResponse) => {
186
189
  props.readData['id'] = r.autoReloadId;
187
190
  fetchItem();
188
191
  }
192
+ if (props.isCreate) {
193
+ if (typeof props.onCreate === 'function') props.onCreate();
194
+ } else {
195
+ if (typeof props.onUpdate === 'function') props.onUpdate();
196
+ }
189
197
  emit(emits, r)
190
-
191
198
  },
192
199
  onButtonLoading = () => {
193
200
  isLoading.value = true;