lkt-item-crud 2.0.17 → 2.0.19
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 +6 -6
- package/dist/build.js +460 -426
- package/dist/lib-components/LktItemCrud.vue.d.ts +17 -5
- package/package.json +1 -1
- package/src/lib-components/LktItemCrud.vue +72 -22
|
@@ -21,7 +21,7 @@ declare var __VLS_17: {
|
|
|
21
21
|
canUpdate: boolean | undefined;
|
|
22
22
|
canDrop: boolean | undefined;
|
|
23
23
|
perms: string[] | undefined;
|
|
24
|
-
},
|
|
24
|
+
}, __VLS_52: {
|
|
25
25
|
item: LktObject;
|
|
26
26
|
loading: false;
|
|
27
27
|
editMode: boolean;
|
|
@@ -30,7 +30,7 @@ declare var __VLS_17: {
|
|
|
30
30
|
canDrop: boolean;
|
|
31
31
|
itemBeingEdited: boolean;
|
|
32
32
|
perms: string[];
|
|
33
|
-
},
|
|
33
|
+
}, __VLS_73: {}, __VLS_75: {};
|
|
34
34
|
type __VLS_Slots = {} & {
|
|
35
35
|
'prev-buttons-ever'?: (props: typeof __VLS_17) => any;
|
|
36
36
|
} & {
|
|
@@ -44,11 +44,11 @@ type __VLS_Slots = {} & {
|
|
|
44
44
|
} & {
|
|
45
45
|
'prev-buttons'?: (props: typeof __VLS_38) => any;
|
|
46
46
|
} & {
|
|
47
|
-
item?: (props: typeof
|
|
47
|
+
item?: (props: typeof __VLS_52) => any;
|
|
48
48
|
} & {
|
|
49
|
-
'prev-buttons-ever'?: (props: typeof
|
|
49
|
+
'prev-buttons-ever'?: (props: typeof __VLS_73) => any;
|
|
50
50
|
} & {
|
|
51
|
-
'prev-buttons'?: (props: typeof
|
|
51
|
+
'prev-buttons'?: (props: typeof __VLS_75) => any;
|
|
52
52
|
};
|
|
53
53
|
declare const __VLS_component: import("vue").DefineComponent<ItemCrudConfig, {
|
|
54
54
|
doDrop: () => void;
|
|
@@ -65,6 +65,9 @@ declare const __VLS_component: import("vue").DefineComponent<ItemCrudConfig, {
|
|
|
65
65
|
perms: (...args: any[]) => void;
|
|
66
66
|
"update:editing": (...args: any[]) => void;
|
|
67
67
|
"update:modelValue": (...args: any[]) => void;
|
|
68
|
+
"update:perms": (...args: any[]) => void;
|
|
69
|
+
"update:customData": (...args: any[]) => void;
|
|
70
|
+
"update:form": (...args: any[]) => void;
|
|
68
71
|
"before-save": (...args: any[]) => void;
|
|
69
72
|
"modified-data": (...args: any[]) => void;
|
|
70
73
|
}, string, import("vue").PublicProps, Readonly<ItemCrudConfig> & Readonly<{
|
|
@@ -76,15 +79,24 @@ declare const __VLS_component: import("vue").DefineComponent<ItemCrudConfig, {
|
|
|
76
79
|
onPerms?: ((...args: any[]) => any) | undefined;
|
|
77
80
|
"onUpdate:editing"?: ((...args: any[]) => any) | undefined;
|
|
78
81
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
82
|
+
"onUpdate:perms"?: ((...args: any[]) => any) | undefined;
|
|
83
|
+
"onUpdate:customData"?: ((...args: any[]) => any) | undefined;
|
|
84
|
+
"onUpdate:form"?: ((...args: any[]) => any) | undefined;
|
|
79
85
|
"onBefore-save"?: ((...args: any[]) => any) | undefined;
|
|
80
86
|
"onModified-data"?: ((...args: any[]) => any) | undefined;
|
|
81
87
|
}>, {
|
|
82
88
|
view: ItemCrudView;
|
|
89
|
+
form: import("lkt-vue-kernel").FormConfig;
|
|
83
90
|
title: string;
|
|
84
91
|
mode: ItemCrudMode;
|
|
85
92
|
modelValue: LktObject;
|
|
93
|
+
events: {
|
|
94
|
+
httpStart?: undefined | Function;
|
|
95
|
+
httpEnd?: (data: import("lkt-vue-kernel").ClickEventArgs) => void | undefined;
|
|
96
|
+
};
|
|
86
97
|
editing: boolean;
|
|
87
98
|
perms: import("lkt-vue-kernel").ValidTablePermission[];
|
|
99
|
+
customData: LktObject;
|
|
88
100
|
editModeButton: ButtonConfig | false;
|
|
89
101
|
dropButton: ButtonConfig | false;
|
|
90
102
|
createButton: ButtonConfig | false;
|
package/package.json
CHANGED
|
@@ -38,6 +38,9 @@
|
|
|
38
38
|
const emit = defineEmits([
|
|
39
39
|
'update:modelValue',
|
|
40
40
|
'update:editing',
|
|
41
|
+
'update:perms',
|
|
42
|
+
'update:customData',
|
|
43
|
+
'update:form',
|
|
41
44
|
'read',
|
|
42
45
|
'create',
|
|
43
46
|
'update',
|
|
@@ -50,8 +53,10 @@
|
|
|
50
53
|
|
|
51
54
|
const isLoading = ref(true),
|
|
52
55
|
item = ref(props.modelValue),
|
|
53
|
-
|
|
56
|
+
custom = ref(props.customData),
|
|
57
|
+
permissions = ref(props.perms),
|
|
54
58
|
editMode = ref(props.editing),
|
|
59
|
+
validForm = ref(false),
|
|
55
60
|
httpSuccessRead = ref(false),
|
|
56
61
|
showStoreMessage = ref(false),
|
|
57
62
|
httpStatus = ref(200),
|
|
@@ -62,14 +67,20 @@
|
|
|
62
67
|
itemBeingEdited = ref(false),
|
|
63
68
|
itemCreated = ref(false),
|
|
64
69
|
buttonNav = ref(null),
|
|
65
|
-
canUpdate = computed(() => !createMode.value && Array.isArray(
|
|
66
|
-
canDrop = computed(() => !createMode.value && Array.isArray(
|
|
67
|
-
canSwitchEditMode = computed(() => !createMode.value && Array.isArray(
|
|
70
|
+
canUpdate = computed(() => !createMode.value && Array.isArray(permissions.value) && permissions.value.includes(TablePermission.Update)),
|
|
71
|
+
canDrop = computed(() => !createMode.value && Array.isArray(permissions.value) && permissions.value.includes(TablePermission.Drop)),
|
|
72
|
+
canSwitchEditMode = computed(() => !createMode.value && Array.isArray(permissions.value) && permissions.value.includes(TablePermission.SwitchEditMode));
|
|
68
73
|
|
|
69
74
|
watch(() => props.mode, (v) => {
|
|
70
75
|
createMode.value = v === ItemCrudMode.Create;
|
|
71
76
|
})
|
|
72
77
|
|
|
78
|
+
watch(() => props.perms, (v) => {permissions.value = v});
|
|
79
|
+
watch(permissions, (v) => {emit('update:perms', v)});
|
|
80
|
+
|
|
81
|
+
watch(() => props.customData, (v) => {custom.value = v});
|
|
82
|
+
watch(custom, (v) => {emit('update:customData', v)});
|
|
83
|
+
|
|
73
84
|
const safeCreateButton = ref(ensureButtonConfig(props.createButton, LktSettings.defaultCreateButton)),
|
|
74
85
|
safeUpdateButton = ref(ensureButtonConfig(props.updateButton, LktSettings.defaultUpdateButton)),
|
|
75
86
|
safeDropButton = ref(ensureButtonConfig(props.dropButton, LktSettings.defaultDropButton)),
|
|
@@ -98,23 +109,40 @@
|
|
|
98
109
|
httpStatus.value = -1;
|
|
99
110
|
showStoreMessage.value = false;
|
|
100
111
|
|
|
112
|
+
if (typeof props.events?.httpStart === 'function') {
|
|
113
|
+
props.events.httpStart();
|
|
114
|
+
}
|
|
115
|
+
|
|
101
116
|
try {
|
|
102
|
-
const r = await httpCall(props.readResource, props.readData);
|
|
117
|
+
const r: HTTPResponse = await httpCall(props.readResource, props.readData);
|
|
103
118
|
debug('fetchItem -> response', r);
|
|
104
119
|
isLoading.value = false;
|
|
105
120
|
httpStatus.value = r.httpStatus;
|
|
121
|
+
custom.value = r.custom;
|
|
106
122
|
if (!r.success) {
|
|
107
123
|
httpSuccessRead.value = false;
|
|
108
124
|
httpStatus.value = r.httpStatus;
|
|
125
|
+
|
|
126
|
+
if (typeof props.events?.httpEnd === 'function') {
|
|
127
|
+
props.events.httpEnd({
|
|
128
|
+
httpResponse: r,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
109
131
|
emit('error', r.httpStatus);
|
|
110
132
|
return;
|
|
111
133
|
}
|
|
112
134
|
httpSuccessRead.value = true;
|
|
113
135
|
item.value = r.data;
|
|
114
|
-
|
|
136
|
+
permissions.value = r.perms;
|
|
115
137
|
dataState.value.increment(item.value).turnStoredIntoOriginal();
|
|
116
138
|
dataChanged.value = dataState.value.changed();
|
|
117
139
|
readDataState.value.turnStoredIntoOriginal();
|
|
140
|
+
|
|
141
|
+
if (typeof props.events?.httpEnd === 'function') {
|
|
142
|
+
props.events.httpEnd({
|
|
143
|
+
httpResponse: r,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
118
146
|
emit('read', r);
|
|
119
147
|
|
|
120
148
|
} catch (e) {
|
|
@@ -148,7 +176,7 @@
|
|
|
148
176
|
nextTick(() => itemBeingEdited.value = false);
|
|
149
177
|
}, { deep: true });
|
|
150
178
|
|
|
151
|
-
watch(
|
|
179
|
+
watch(permissions, () => emit('perms', permissions.value));
|
|
152
180
|
watch(dataChanged, (v) => {
|
|
153
181
|
emit('modified-data', v);
|
|
154
182
|
});
|
|
@@ -366,8 +394,12 @@
|
|
|
366
394
|
ableToUpdate = computed(() => {
|
|
367
395
|
if (props.mode !== ItemCrudMode.Update || !canUpdate.value) return false;
|
|
368
396
|
if (!props.enabledSaveWithoutChanges && !dataChanged.value) return false;
|
|
397
|
+
console.log('ableToUpdate', validForm.value);
|
|
398
|
+
if (computedHasForm.value && !validForm.value) return false;
|
|
369
399
|
|
|
370
|
-
if (typeof safeUpdateButton.value?.disabled === 'function') return !safeUpdateButton.value.disabled(
|
|
400
|
+
if (typeof safeUpdateButton.value?.disabled === 'function') return !safeUpdateButton.value.disabled({
|
|
401
|
+
prop: item.value
|
|
402
|
+
});
|
|
371
403
|
if (typeof safeUpdateButton.value?.disabled === 'boolean') return !safeUpdateButton.value.disabled;
|
|
372
404
|
|
|
373
405
|
return true;
|
|
@@ -375,8 +407,11 @@
|
|
|
375
407
|
ableToCreate = computed(() => {
|
|
376
408
|
if (props.mode !== ItemCrudMode.Create) return false;
|
|
377
409
|
if (!props.enabledSaveWithoutChanges && !dataChanged.value) return false;
|
|
410
|
+
if (computedHasForm.value && !validForm.value) return false;
|
|
378
411
|
|
|
379
|
-
if (typeof safeCreateButton.value?.disabled === 'function') return !safeCreateButton.value.disabled(
|
|
412
|
+
if (typeof safeCreateButton.value?.disabled === 'function') return !safeCreateButton.value.disabled({
|
|
413
|
+
prop: item.value
|
|
414
|
+
});
|
|
380
415
|
if (typeof safeCreateButton.value?.disabled === 'boolean') return !safeCreateButton.value.disabled;
|
|
381
416
|
|
|
382
417
|
return true;
|
|
@@ -385,7 +420,9 @@
|
|
|
385
420
|
|
|
386
421
|
if (!canDrop.value) return false;
|
|
387
422
|
|
|
388
|
-
if (typeof safeDropButton.value?.disabled === 'function') return !safeDropButton.value.disabled(
|
|
423
|
+
if (typeof safeDropButton.value?.disabled === 'function') return !safeDropButton.value.disabled({
|
|
424
|
+
prop: item.value
|
|
425
|
+
});
|
|
389
426
|
if (typeof safeDropButton.value?.disabled === 'boolean') return !safeDropButton.value.disabled;
|
|
390
427
|
|
|
391
428
|
return true;
|
|
@@ -408,6 +445,9 @@
|
|
|
408
445
|
};
|
|
409
446
|
}
|
|
410
447
|
return {};
|
|
448
|
+
}),
|
|
449
|
+
computedHasForm = computed(() => {
|
|
450
|
+
return typeof props.form === 'object' && Object.keys(props.form).length > 0;
|
|
411
451
|
})
|
|
412
452
|
</script>
|
|
413
453
|
|
|
@@ -442,7 +482,7 @@
|
|
|
442
482
|
:able-to-create="ableToCreate"
|
|
443
483
|
:able-to-update="ableToUpdate"
|
|
444
484
|
:able-to-drop="ableToDrop"
|
|
445
|
-
:perms="
|
|
485
|
+
:perms="permissions"
|
|
446
486
|
@create="onCreate"
|
|
447
487
|
@save="onUpdate"
|
|
448
488
|
@drop="onDrop"
|
|
@@ -499,7 +539,7 @@
|
|
|
499
539
|
:able-to-create="ableToCreate"
|
|
500
540
|
:able-to-update="ableToUpdate"
|
|
501
541
|
:able-to-drop="ableToDrop"
|
|
502
|
-
:perms="
|
|
542
|
+
:perms="permissions"
|
|
503
543
|
@create="onCreate"
|
|
504
544
|
@save="onUpdate"
|
|
505
545
|
@drop="onDrop"
|
|
@@ -529,16 +569,26 @@
|
|
|
529
569
|
quick
|
|
530
570
|
can-close
|
|
531
571
|
v-on:close="showStoreMessage = false" />
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
:can-drop="canDrop"
|
|
539
|
-
:item-being-edited="itemBeingEdited"
|
|
540
|
-
:perms="perms"
|
|
572
|
+
|
|
573
|
+
<lkt-form
|
|
574
|
+
v-if="computedHasForm"
|
|
575
|
+
v-model="item"
|
|
576
|
+
v-model:form="form"
|
|
577
|
+
v-model:valid="validForm"
|
|
541
578
|
/>
|
|
579
|
+
|
|
580
|
+
<template v-else>
|
|
581
|
+
<slot name="item"
|
|
582
|
+
:item="item"
|
|
583
|
+
:loading="isLoading"
|
|
584
|
+
:edit-mode="editMode"
|
|
585
|
+
:is-create="createMode"
|
|
586
|
+
:can-update="canUpdate"
|
|
587
|
+
:can-drop="canDrop"
|
|
588
|
+
:item-being-edited="itemBeingEdited"
|
|
589
|
+
:perms="permissions"
|
|
590
|
+
/>
|
|
591
|
+
</template>
|
|
542
592
|
</div>
|
|
543
593
|
<lkt-http-info :code="httpStatus" v-else-if="notificationType === NotificationType.Inline" />
|
|
544
594
|
</div>
|
|
@@ -568,7 +618,7 @@
|
|
|
568
618
|
:able-to-create="ableToCreate"
|
|
569
619
|
:able-to-update="ableToUpdate"
|
|
570
620
|
:able-to-drop="ableToDrop"
|
|
571
|
-
:perms="
|
|
621
|
+
:perms="permissions"
|
|
572
622
|
@create="onCreate"
|
|
573
623
|
@save="onUpdate"
|
|
574
624
|
@drop="onDrop"
|