lkt-item-crud 2.0.11 → 2.0.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.
@@ -1,12 +1,4 @@
1
- import { SetupContext } from 'vue';
2
- import { HTTPResponse } from 'lkt-http-client';
3
1
  import { ItemCrudButtonNavPosition, ItemCrudConfig, ItemCrudMode, ItemCrudView, LktObject, NotificationType } from 'lkt-vue-kernel';
4
- import ButtonNav from '../components/ButtonNav.vue';
5
- declare const slots: SetupContext['slots'];
6
- declare const isLoading: import("vue").Ref<boolean, boolean>, item: import("vue").Ref<LktObject, LktObject>, perms: import("vue").Ref<string[], string[]>, editMode: import("vue").Ref<boolean, boolean>, httpSuccessRead: import("vue").Ref<boolean, boolean>, showStoreMessage: import("vue").Ref<boolean, boolean>, httpStatus: import("vue").Ref<number, number>, dataChanged: import("vue").Ref<boolean, boolean>, createMode: import("vue").Ref<boolean, boolean>, itemBeingEdited: import("vue").Ref<boolean, boolean>, buttonNav: import("vue").Ref<null, null>, canUpdate: import("vue").ComputedRef<boolean>, canDrop: import("vue").ComputedRef<boolean>, canSwitchEditMode: import("vue").ComputedRef<boolean>;
7
- declare const onCreate: ($event: PointerEvent, r: HTTPResponse) => void, onUpdate: ($event: PointerEvent, r: HTTPResponse) => void, onDrop: ($event: PointerEvent, r: HTTPResponse) => void;
8
- declare const computedTitle: import("vue").ComputedRef<string>, displayHeader: import("vue").ComputedRef<boolean>, computedInsideModal: import("vue").ComputedRef<boolean>, computedContainerTag: import("vue").ComputedRef<"lkt-modal" | "section">, computedContainerAttrs: import("vue").ComputedRef<{}>;
9
- declare const __VLS_ctx: InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>;
10
2
  declare var __VLS_6: {
11
3
  item: LktObject;
12
4
  loading: boolean;
@@ -29,8 +21,9 @@ declare var __VLS_6: {
29
21
  canUpdate: boolean;
30
22
  canDrop: boolean;
31
23
  itemBeingEdited: boolean;
24
+ perms: string[];
32
25
  }, __VLS_54: {}, __VLS_56: {};
33
- type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.$slots> & {
26
+ type __VLS_Slots = {} & {
34
27
  'pre-title'?: (props: typeof __VLS_6) => any;
35
28
  } & {
36
29
  'post-title'?: (props: typeof __VLS_8) => any;
@@ -44,82 +37,12 @@ type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.$
44
37
  'prev-buttons-ever'?: (props: typeof __VLS_54) => any;
45
38
  } & {
46
39
  'prev-buttons'?: (props: typeof __VLS_56) => any;
47
- }>;
48
- declare const __VLS_self: import("vue").DefineComponent<ItemCrudConfig, {
49
- ItemCrudButtonNavPosition: typeof ItemCrudButtonNavPosition;
50
- NotificationType: typeof NotificationType;
51
- ButtonNav: typeof ButtonNav;
52
- slots: typeof slots;
53
- isLoading: typeof isLoading;
54
- item: typeof item;
55
- perms: typeof perms;
56
- editMode: typeof editMode;
57
- httpSuccessRead: typeof httpSuccessRead;
58
- showStoreMessage: typeof showStoreMessage;
59
- httpStatus: typeof httpStatus;
60
- dataChanged: typeof dataChanged;
61
- createMode: typeof createMode;
62
- itemBeingEdited: typeof itemBeingEdited;
63
- buttonNav: typeof buttonNav;
64
- canUpdate: typeof canUpdate;
65
- canDrop: typeof canDrop;
66
- canSwitchEditMode: typeof canSwitchEditMode;
67
- onCreate: typeof onCreate;
68
- onUpdate: typeof onUpdate;
69
- onDrop: typeof onDrop;
70
- computedTitle: typeof computedTitle;
71
- displayHeader: typeof displayHeader;
72
- computedInsideModal: typeof computedInsideModal;
73
- computedContainerTag: typeof computedContainerTag;
74
- computedContainerAttrs: typeof computedContainerAttrs;
75
- }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
76
- error: (...args: any[]) => void;
77
- drop: (...args: any[]) => void;
78
- update: (...args: any[]) => void;
79
- create: (...args: any[]) => void;
80
- read: (...args: any[]) => void;
81
- perms: (...args: any[]) => void;
82
- "update:editing": (...args: any[]) => void;
83
- "update:modelValue": (...args: any[]) => void;
84
- "before-save": (...args: any[]) => void;
85
- "modified-data": (...args: any[]) => void;
86
- }, string, import("vue").PublicProps, Readonly<ItemCrudConfig> & Readonly<{
87
- onError?: ((...args: any[]) => any) | undefined;
88
- onDrop?: ((...args: any[]) => any) | undefined;
89
- onUpdate?: ((...args: any[]) => any) | undefined;
90
- onCreate?: ((...args: any[]) => any) | undefined;
91
- onRead?: ((...args: any[]) => any) | undefined;
92
- onPerms?: ((...args: any[]) => any) | undefined;
93
- "onUpdate:editing"?: ((...args: any[]) => any) | undefined;
94
- "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
95
- "onBefore-save"?: ((...args: any[]) => any) | undefined;
96
- "onModified-data"?: ((...args: any[]) => any) | undefined;
97
- }>, {
98
- view: ItemCrudView;
99
- title: string;
100
- mode: ItemCrudMode;
101
- modelValue: LktObject;
102
- editing: boolean;
103
- perms: import("lkt-vue-kernel").ValidTablePermission[];
104
- editModeButton: import("lkt-vue-kernel").ButtonConfig | false;
105
- dropButton: import("lkt-vue-kernel").ButtonConfig | false;
106
- createButton: import("lkt-vue-kernel").ButtonConfig | false;
107
- updateButton: import("lkt-vue-kernel").ButtonConfig | false;
108
- groupButton: import("lkt-vue-kernel").ButtonConfig | boolean;
109
- buttonNavPosition: ItemCrudButtonNavPosition;
110
- buttonNavVisibility: import("lkt-vue-kernel").ItemCrudButtonNavVisibility;
111
- modalConfig: import("lkt-vue-kernel").ModalConfig;
112
- saveConfig: import("lkt-vue-kernel").SaveConfig;
113
- dataStateConfig: import("lkt-data-state").DataStateConfig;
114
- readResource: string;
115
- readData: LktObject;
116
- beforeEmitUpdate: Function;
117
- notificationType: NotificationType;
118
- }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
40
+ };
119
41
  declare const __VLS_component: import("vue").DefineComponent<ItemCrudConfig, {
120
42
  doDrop: () => void;
121
43
  doRefresh: () => Promise<void>;
122
44
  doSave: () => void;
45
+ turnStoredDataIntoOriginal: () => void;
123
46
  hasModifiedData: () => boolean;
124
47
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
125
48
  error: (...args: any[]) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lkt-item-crud",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "module": "./dist/build.js",
@@ -154,18 +154,15 @@
154
154
  showSaveButton = computed(() => {
155
155
  if (props.mode === ItemCrudMode.Create && props.createButton === false) return false;
156
156
  if (props.mode === ItemCrudMode.Update && props.updateButton === false) return false;
157
- if (props.dataChanged) {
158
- return ableToUpdate.value || ableToCreate.value;
159
- }
160
157
  if (isLoading.value) return false;
161
158
 
162
- if (props.mode === ItemCrudMode.Create) {
163
- return true;
164
- }
159
+ // if (props.dataChanged) {
160
+ // return ableToUpdate.value || ableToCreate.value;
161
+ // }
165
162
 
166
- if (props.buttonNavVisibility === ItemCrudButtonNavVisibility.Never) {
167
- return false;
168
- }
163
+ // if (props.buttonNavVisibility === ItemCrudButtonNavVisibility.Never) {
164
+ // return false;
165
+ // }
169
166
 
170
167
  return props.editing
171
168
  && props.httpSuccessRead;
@@ -181,7 +178,7 @@
181
178
  && props.httpSuccessRead;
182
179
  }),
183
180
  showButtons = computed(() => {
184
- if (props.buttonNavVisibility === ItemCrudButtonNavVisibility.Always && (ableToUpdate.value || ableToCreate.value || ableToDrop.value)) return true;
181
+ if (props.buttonNavVisibility === ItemCrudButtonNavVisibility.Always) return true;
185
182
  if (slots['prev-buttons-ever']) return true;
186
183
  if (props.buttonNavVisibility === ItemCrudButtonNavVisibility.Never) return false;
187
184
  return showSaveButton.value || showDropButton.value || showSwitchButton.value;
@@ -224,7 +221,7 @@
224
221
 
225
222
  <lkt-button
226
223
  ref="saveButtonRef"
227
- v-if="mode === ItemCrudMode.Update && showSaveButton"
224
+ v-show="mode === ItemCrudMode.Update && showSaveButton"
228
225
  v-bind="safeUpdateButton"
229
226
  :disabled="!ableToUpdate"
230
227
  @loading="onButtonLoading"
@@ -239,7 +236,7 @@
239
236
 
240
237
  <lkt-button
241
238
  ref="saveButtonRef"
242
- v-else-if="mode === ItemCrudMode.Create && showSaveButton"
239
+ v-show="mode === ItemCrudMode.Create && showSaveButton"
243
240
  v-bind="safeCreateButton"
244
241
  :disabled="!ableToCreate"
245
242
  @loading="onButtonLoading"
@@ -254,8 +251,7 @@
254
251
 
255
252
  <lkt-button
256
253
  ref="dropButtonRef"
257
- v-show="showDropButton"
258
- v-if="mode !== ItemCrudMode.Create"
254
+ v-show="showDropButton && mode !== ItemCrudMode.Create"
259
255
  v-bind="safeDropButton"
260
256
  :disabled="!ableToDrop"
261
257
  @loading="onButtonLoading"
@@ -295,7 +291,7 @@
295
291
 
296
292
  <lkt-button
297
293
  ref="saveButtonRef"
298
- v-if="mode === ItemCrudMode.Update && showSaveButton"
294
+ v-show="mode === ItemCrudMode.Update && showSaveButton"
299
295
  v-bind="safeUpdateButton"
300
296
  :disabled="!ableToUpdate"
301
297
  @loading="onButtonLoading"
@@ -310,7 +306,7 @@
310
306
 
311
307
  <lkt-button
312
308
  ref="saveButtonRef"
313
- v-else-if="mode === ItemCrudMode.Create && showSaveButton"
309
+ v-show="mode === ItemCrudMode.Create && showSaveButton"
314
310
  v-bind="safeCreateButton"
315
311
  :disabled="!ableToCreate"
316
312
  @loading="onButtonLoading"
@@ -320,13 +316,12 @@
320
316
  :edit-mode="isEditing"
321
317
  :is-create="true"
322
318
  :can-update="canUpdate"
323
- :can-drop="canDrop" />
319
+ :can-drop="false" />
324
320
  </lkt-button>
325
321
 
326
322
  <lkt-button
327
323
  ref="dropButtonRef"
328
- v-show="showDropButton"
329
- v-if="mode !== ItemCrudMode.Create"
324
+ v-show="showDropButton && mode !== ItemCrudMode.Create"
330
325
  v-bind="safeDropButton"
331
326
  :disabled="!ableToDrop"
332
327
  @loading="onButtonLoading"
@@ -17,7 +17,7 @@
17
17
  ToastConfig,
18
18
  ToastPositionX,
19
19
  } from 'lkt-vue-kernel';
20
- import { closeModal } from 'lkt-modal';
20
+ import { closeModal, updateModalKey } from 'lkt-modal';
21
21
  import { __ } from 'lkt-i18n';
22
22
  import ButtonNav from '../components/ButtonNav.vue';
23
23
  import { openToast } from 'lkt-toast';
@@ -61,6 +61,10 @@
61
61
  canDrop = computed(() => !createMode.value && Array.isArray(perms.value) && perms.value.includes(TablePermission.Drop)),
62
62
  canSwitchEditMode = computed(() => !createMode.value && Array.isArray(perms.value) && perms.value.includes(TablePermission.SwitchEditMode));
63
63
 
64
+ watch(() => props.mode, (v) => {
65
+ createMode.value = v === ItemCrudMode.Create;
66
+ })
67
+
64
68
  const fetchItem = async () => {
65
69
  debug('fetchItem');
66
70
  isLoading.value = true;
@@ -171,13 +175,20 @@
171
175
  }
172
176
  return true;
173
177
  },
174
- doAutoReloadId = (r: HTTPResponse) => {
175
- if (!computedInsideModal.value && r.autoReloadId) {
178
+ doAutoReloadId = (r?: HTTPResponse) => {
179
+ debug('doAutoReloadId -> enter: ', r);
180
+ if (typeof r !== 'undefined' && r.autoReloadId) {
176
181
  debug('doAutoReloadId -> autoReloadId detected: ', r.autoReloadId);
177
- props.readData['id'] = r.autoReloadId;
178
- debug('doAutoReloadId -> turning off create mode');
179
- createMode.value = false;
180
- fetchItem();
182
+ if (!computedInsideModal.value) {
183
+ debug('doAutoReloadId -> outsideModal');
184
+ props.readData['id'] = r.autoReloadId;
185
+ debug('doAutoReloadId -> turning off create mode');
186
+ createMode.value = false;
187
+ fetchItem();
188
+ } else {
189
+ debug('doAutoReloadId -> insideModal: ', props);
190
+ updateModalKey(props.modalConfig.modalName, props.modalConfig.modalKey, r.autoReloadId);
191
+ }
181
192
  }
182
193
  },
183
194
  onCreate = ($event: PointerEvent, r: HTTPResponse) => {
@@ -205,6 +216,7 @@
205
216
  });
206
217
  }
207
218
  doAutoReloadId(r);
219
+ debug('onCreate -> beforeEmitCreate');
208
220
  emit('create', r);
209
221
  },
210
222
  onUpdate = ($event: PointerEvent, r: HTTPResponse) => {
@@ -274,6 +286,9 @@
274
286
  doDrop,
275
287
  doRefresh: fetchItem,
276
288
  doSave,
289
+ turnStoredDataIntoOriginal: () => {
290
+ dataState.value.increment(item.value).turnStoredIntoOriginal();
291
+ },
277
292
  hasModifiedData: () => dataState.value.changed(),
278
293
  });
279
294
 
@@ -393,11 +408,16 @@
393
408
  quick
394
409
  can-close
395
410
  v-on:close="showStoreMessage = false" />
396
- <slot name="item" :item="item" :loading="isLoading" :edit-mode="editMode"
411
+ <slot name="item"
412
+ :item="item"
413
+ :loading="isLoading"
414
+ :edit-mode="editMode"
397
415
  :is-create="createMode"
398
416
  :can-update="canUpdate"
399
417
  :can-drop="canDrop"
400
- :item-being-edited="itemBeingEdited"></slot>
418
+ :item-being-edited="itemBeingEdited"
419
+ :perms="perms"
420
+ />
401
421
  </div>
402
422
  <lkt-http-info :code="httpStatus" v-else-if="notificationType === NotificationType.Inline" />
403
423
  </div>
@@ -422,6 +442,7 @@
422
442
  :can-update="canUpdate"
423
443
  :can-drop="canDrop"
424
444
  :can-switch-edit-mode="canSwitchEditMode"
445
+ :perms="perms"
425
446
  @create="onCreate"
426
447
  @save="onUpdate"
427
448
  @drop="onDrop"