lkt-item-crud 2.0.12 → 2.0.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.
@@ -1,27 +1,27 @@
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
- declare var __VLS_6: {
2
+ declare var __VLS_17: {
3
+ canUpdate: boolean | undefined;
4
+ canDrop: boolean | undefined;
5
+ perms: string[] | undefined;
6
+ }, __VLS_19: {
7
+ canUpdate: boolean | undefined;
8
+ canDrop: boolean | undefined;
9
+ perms: string[] | undefined;
10
+ }, __VLS_21: {
11
11
  item: LktObject;
12
12
  loading: boolean;
13
- }, __VLS_8: {
13
+ }, __VLS_23: {
14
14
  item: LktObject;
15
15
  loading: boolean;
16
- }, __VLS_21: {
16
+ }, __VLS_36: {
17
17
  canUpdate: boolean | undefined;
18
18
  canDrop: boolean | undefined;
19
19
  perms: string[] | undefined;
20
- }, __VLS_23: {
20
+ }, __VLS_38: {
21
21
  canUpdate: boolean | undefined;
22
22
  canDrop: boolean | undefined;
23
23
  perms: string[] | undefined;
24
- }, __VLS_33: {
24
+ }, __VLS_48: {
25
25
  item: LktObject;
26
26
  loading: false;
27
27
  editMode: boolean;
@@ -30,97 +30,31 @@ declare var __VLS_6: {
30
30
  canDrop: boolean;
31
31
  itemBeingEdited: boolean;
32
32
  perms: string[];
33
- }, __VLS_54: {}, __VLS_56: {};
34
- type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.$slots> & {
35
- 'pre-title'?: (props: typeof __VLS_6) => any;
33
+ }, __VLS_69: {}, __VLS_71: {};
34
+ type __VLS_Slots = {} & {
35
+ 'prev-buttons-ever'?: (props: typeof __VLS_17) => any;
36
36
  } & {
37
- 'post-title'?: (props: typeof __VLS_8) => any;
37
+ 'prev-buttons'?: (props: typeof __VLS_19) => any;
38
38
  } & {
39
- 'prev-buttons-ever'?: (props: typeof __VLS_21) => any;
39
+ 'pre-title'?: (props: typeof __VLS_21) => any;
40
40
  } & {
41
- 'prev-buttons'?: (props: typeof __VLS_23) => any;
41
+ 'post-title'?: (props: typeof __VLS_23) => any;
42
42
  } & {
43
- item?: (props: typeof __VLS_33) => any;
43
+ 'prev-buttons-ever'?: (props: typeof __VLS_36) => any;
44
44
  } & {
45
- 'prev-buttons-ever'?: (props: typeof __VLS_54) => any;
45
+ 'prev-buttons'?: (props: typeof __VLS_38) => any;
46
46
  } & {
47
- 'prev-buttons'?: (props: typeof __VLS_56) => any;
48
- }>;
49
- declare const __VLS_self: import("vue").DefineComponent<ItemCrudConfig, {
50
- ItemCrudButtonNavPosition: typeof ItemCrudButtonNavPosition;
51
- NotificationType: typeof NotificationType;
52
- ButtonNav: typeof ButtonNav;
53
- slots: typeof slots;
54
- isLoading: typeof isLoading;
55
- item: typeof item;
56
- perms: typeof perms;
57
- editMode: typeof editMode;
58
- httpSuccessRead: typeof httpSuccessRead;
59
- showStoreMessage: typeof showStoreMessage;
60
- httpStatus: typeof httpStatus;
61
- dataChanged: typeof dataChanged;
62
- createMode: typeof createMode;
63
- itemBeingEdited: typeof itemBeingEdited;
64
- buttonNav: typeof buttonNav;
65
- canUpdate: typeof canUpdate;
66
- canDrop: typeof canDrop;
67
- canSwitchEditMode: typeof canSwitchEditMode;
68
- onCreate: typeof onCreate;
69
- onUpdate: typeof onUpdate;
70
- onDrop: typeof onDrop;
71
- computedTitle: typeof computedTitle;
72
- displayHeader: typeof displayHeader;
73
- computedInsideModal: typeof computedInsideModal;
74
- computedContainerTag: typeof computedContainerTag;
75
- computedContainerAttrs: typeof computedContainerAttrs;
76
- }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
77
- error: (...args: any[]) => void;
78
- drop: (...args: any[]) => void;
79
- update: (...args: any[]) => void;
80
- create: (...args: any[]) => void;
81
- read: (...args: any[]) => void;
82
- perms: (...args: any[]) => void;
83
- "update:editing": (...args: any[]) => void;
84
- "update:modelValue": (...args: any[]) => void;
85
- "before-save": (...args: any[]) => void;
86
- "modified-data": (...args: any[]) => void;
87
- }, string, import("vue").PublicProps, Readonly<ItemCrudConfig> & Readonly<{
88
- onError?: ((...args: any[]) => any) | undefined;
89
- onDrop?: ((...args: any[]) => any) | undefined;
90
- onUpdate?: ((...args: any[]) => any) | undefined;
91
- onCreate?: ((...args: any[]) => any) | undefined;
92
- onRead?: ((...args: any[]) => any) | undefined;
93
- onPerms?: ((...args: any[]) => any) | undefined;
94
- "onUpdate:editing"?: ((...args: any[]) => any) | undefined;
95
- "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
96
- "onBefore-save"?: ((...args: any[]) => any) | undefined;
97
- "onModified-data"?: ((...args: any[]) => any) | undefined;
98
- }>, {
99
- view: ItemCrudView;
100
- title: string;
101
- mode: ItemCrudMode;
102
- modelValue: LktObject;
103
- editing: boolean;
104
- perms: import("lkt-vue-kernel").ValidTablePermission[];
105
- editModeButton: import("lkt-vue-kernel").ButtonConfig | false;
106
- dropButton: import("lkt-vue-kernel").ButtonConfig | false;
107
- createButton: import("lkt-vue-kernel").ButtonConfig | false;
108
- updateButton: import("lkt-vue-kernel").ButtonConfig | false;
109
- groupButton: import("lkt-vue-kernel").ButtonConfig | boolean;
110
- buttonNavPosition: ItemCrudButtonNavPosition;
111
- buttonNavVisibility: import("lkt-vue-kernel").ItemCrudButtonNavVisibility;
112
- modalConfig: import("lkt-vue-kernel").ModalConfig;
113
- saveConfig: import("lkt-vue-kernel").SaveConfig;
114
- dataStateConfig: import("lkt-data-state").DataStateConfig;
115
- readResource: string;
116
- readData: LktObject;
117
- beforeEmitUpdate: Function;
118
- notificationType: NotificationType;
119
- }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
47
+ item?: (props: typeof __VLS_48) => any;
48
+ } & {
49
+ 'prev-buttons-ever'?: (props: typeof __VLS_69) => any;
50
+ } & {
51
+ 'prev-buttons'?: (props: typeof __VLS_71) => any;
52
+ };
120
53
  declare const __VLS_component: import("vue").DefineComponent<ItemCrudConfig, {
121
54
  doDrop: () => void;
122
55
  doRefresh: () => Promise<void>;
123
56
  doSave: () => void;
57
+ turnStoredDataIntoOriginal: () => void;
124
58
  hasModifiedData: () => boolean;
125
59
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
126
60
  error: (...args: any[]) => void;
@@ -156,6 +90,7 @@ declare const __VLS_component: import("vue").DefineComponent<ItemCrudConfig, {
156
90
  createButton: import("lkt-vue-kernel").ButtonConfig | false;
157
91
  updateButton: import("lkt-vue-kernel").ButtonConfig | false;
158
92
  groupButton: import("lkt-vue-kernel").ButtonConfig | boolean;
93
+ groupButtonAsModalActions: boolean;
159
94
  buttonNavPosition: ItemCrudButtonNavPosition;
160
95
  buttonNavVisibility: import("lkt-vue-kernel").ItemCrudButtonNavVisibility;
161
96
  modalConfig: import("lkt-vue-kernel").ModalConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lkt-item-crud",
3
- "version": "2.0.12",
3
+ "version": "2.0.14",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "module": "./dist/build.js",
@@ -32,6 +32,7 @@
32
32
  dropButton?: ButtonConfig|false
33
33
  editModeButton?: ButtonConfig|false
34
34
  groupButton?: ButtonConfig|boolean
35
+ groupButtonAsModalActions?: boolean
35
36
 
36
37
  dataChanged: boolean
37
38
 
@@ -189,7 +190,80 @@
189
190
  <template>
190
191
  <div v-if="showButtons" class="lkt-item-crud-buttons">
191
192
 
192
- <template v-if="groupButton !== false">
193
+ <template v-if="groupButton !== false && groupButtonAsModalActions">
194
+ <lkt-button
195
+ v-if="showSwitchButton"
196
+ v-bind="safeEditModeButton"
197
+ v-model:checked="isEditing"
198
+ class="lkt-item-crud--switch-mode-button" />
199
+
200
+
201
+ <template v-if="slots['prev-buttons-ever']" v-show="!isLoading">
202
+ <slot name="prev-buttons-ever"
203
+ :can-update="canUpdate"
204
+ :can-drop="canDrop"
205
+ :perms="perms"
206
+ />
207
+ </template>
208
+
209
+ <template v-if="slots['prev-buttons']" v-show="isEditing && !isLoading">
210
+ <slot name="prev-buttons"
211
+ :can-update="canUpdate"
212
+ :can-drop="canDrop"
213
+ :perms="perms"
214
+ />
215
+ </template>
216
+
217
+ <lkt-button
218
+ ref="saveButtonRef"
219
+ v-show="mode === ItemCrudMode.Update && showSaveButton"
220
+ v-bind="safeUpdateButton"
221
+ :disabled="!ableToUpdate"
222
+ @loading="onButtonLoading"
223
+ @loaded="onButtonLoaded"
224
+ @click="onSave">
225
+ <slot v-if="!!slots['button-save']" name="button-save" :item="item"
226
+ :edit-mode="isEditing"
227
+ :is-create="false"
228
+ :can-update="canUpdate"
229
+ :can-drop="canDrop" />
230
+ </lkt-button>
231
+
232
+ <lkt-button
233
+ ref="saveButtonRef"
234
+ v-show="mode === ItemCrudMode.Create && showSaveButton"
235
+ v-bind="safeCreateButton"
236
+ :disabled="!ableToCreate"
237
+ @loading="onButtonLoading"
238
+ @loaded="onButtonLoaded"
239
+ @click="onCreate">
240
+ <slot v-if="!!slots['button-save']" name="button-save" :item="item"
241
+ :edit-mode="isEditing"
242
+ :is-create="true"
243
+ :can-update="canUpdate"
244
+ :can-drop="canDrop" />
245
+ </lkt-button>
246
+
247
+ <lkt-button
248
+ ref="dropButtonRef"
249
+ v-show="showDropButton && mode !== ItemCrudMode.Create"
250
+ v-bind="safeDropButton"
251
+ :disabled="!ableToDrop"
252
+ @loading="onButtonLoading"
253
+ @loaded="onButtonLoaded"
254
+ @click="onDrop">
255
+ <slot v-if="!!slots['button-drop']" name="button-drop" :item="item"
256
+ :edit-mode="isEditing"
257
+ :is-create="false"
258
+ :can-update="canUpdate"
259
+ :can-drop="canDrop" />
260
+ </lkt-button>
261
+
262
+ <template v-if="slots.buttons" v-show="isEditing && !isLoading">
263
+ <slot name="buttons" />
264
+ </template>
265
+ </template>
266
+ <template v-else-if="groupButton !== false">
193
267
  <lkt-button
194
268
  ref="groupButton"
195
269
  v-bind="safeGroupButton"
@@ -316,7 +390,7 @@
316
390
  :edit-mode="isEditing"
317
391
  :is-create="true"
318
392
  :can-update="canUpdate"
319
- :can-drop="canDrop" />
393
+ :can-drop="false" />
320
394
  </lkt-button>
321
395
 
322
396
  <lkt-button
@@ -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;
@@ -172,12 +176,19 @@
172
176
  return true;
173
177
  },
174
178
  doAutoReloadId = (r?: HTTPResponse) => {
175
- if (!computedInsideModal.value && typeof r !== 'undefined' && r.autoReloadId) {
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
 
@@ -332,7 +347,51 @@
332
347
  <component
333
348
  :is="computedContainerTag"
334
349
  v-bind="computedContainerAttrs"
350
+ class="lkt-item-crud"
335
351
  >
352
+ <template v-if="groupButton !== false && groupButtonAsModalActions" #header-actions>
353
+ <button-nav
354
+ ref="buttonNav"
355
+ v-if="buttonNavPosition === ItemCrudButtonNavPosition.Top"
356
+ v-model:loading="isLoading"
357
+ v-model:editing="editMode"
358
+ :item="item"
359
+ :mode="mode"
360
+ :view="view"
361
+ :button-nav-visibility="buttonNavVisibility"
362
+ :create-button="createButton"
363
+ :update-button="updateButton"
364
+ :drop-button="dropButton"
365
+ :edit-mode-button="editModeButton"
366
+ :group-button="groupButton"
367
+ :group-button-as-modal-actions="groupButtonAsModalActions"
368
+ :data-changed="dataChanged"
369
+ :http-success-read="httpSuccessRead"
370
+ :can-update="canUpdate"
371
+ :can-drop="canDrop"
372
+ :can-switch-edit-mode="canSwitchEditMode"
373
+ :perms="perms"
374
+ @create="onCreate"
375
+ @save="onUpdate"
376
+ @drop="onDrop"
377
+ >
378
+ <template #prev-buttons-ever="{canUpdate, canDrop, perms}" v-if="slots['prev-buttons-ever']">
379
+ <slot name="prev-buttons-ever"
380
+ :can-update="canUpdate"
381
+ :can-drop="canDrop"
382
+ :perms="perms"
383
+ />
384
+ </template>
385
+ <template #prev-buttons="{canUpdate, canDrop, perms}" v-if="slots['prev-buttons']">
386
+ <slot name="prev-buttons"
387
+ :can-update="canUpdate"
388
+ :can-drop="canDrop"
389
+ :perms="perms"
390
+ />
391
+ </template>
392
+ </button-nav>
393
+ </template>
394
+
336
395
  <article class="lkt-item-crud">
337
396
  <header class="lkt-item-crud_header" v-if="!computedInsideModal && displayHeader">
338
397
  <div class="lkt-item-crud_header-slot" v-if="slots['pre-title']">
@@ -346,7 +405,7 @@
346
405
 
347
406
  <button-nav
348
407
  ref="buttonNav"
349
- v-if="buttonNavPosition === ItemCrudButtonNavPosition.Top"
408
+ v-if="buttonNavPosition === ItemCrudButtonNavPosition.Top && (groupButton === false || !groupButtonAsModalActions)"
350
409
  v-model:loading="isLoading"
351
410
  v-model:editing="editMode"
352
411
  :item="item"
@@ -363,6 +422,7 @@
363
422
  :can-update="canUpdate"
364
423
  :can-drop="canDrop"
365
424
  :can-switch-edit-mode="canSwitchEditMode"
425
+ :group-button-as-modal-actions="groupButtonAsModalActions"
366
426
  :perms="perms"
367
427
  @create="onCreate"
368
428
  @save="onUpdate"
@@ -410,7 +470,7 @@
410
470
 
411
471
  <button-nav
412
472
  ref="buttonNav"
413
- v-if="buttonNavPosition === ItemCrudButtonNavPosition.Bottom"
473
+ v-if="buttonNavPosition === ItemCrudButtonNavPosition.Bottom && (groupButton === false || !groupButtonAsModalActions)"
414
474
  v-model:loading="isLoading"
415
475
  v-model:editing="editMode"
416
476
  :item="item"
@@ -427,6 +487,7 @@
427
487
  :can-update="canUpdate"
428
488
  :can-drop="canDrop"
429
489
  :can-switch-edit-mode="canSwitchEditMode"
490
+ :group-button-as-modal-actions="groupButtonAsModalActions"
430
491
  :perms="perms"
431
492
  @create="onCreate"
432
493
  @save="onUpdate"