lkt-item-crud 1.3.0 → 2.0.0
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 +362 -403
- package/dist/functions/debug.d.ts +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/settings/Settings.d.ts +5 -0
- package/package.json +7 -10
- package/src/components/ButtonNav.vue +154 -57
- package/src/lib-components/LktItemCrud.vue +128 -336
- /package/dist/{style.css → build.css} +0 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Plugin } from "vue";
|
|
2
|
+
import "./../lkt-item-crud.css";
|
|
3
|
+
declare const LktItemCrud: Plugin;
|
|
4
|
+
export default LktItemCrud;
|
|
5
|
+
export { debugLktItemCrud } from "./functions/debug";
|
|
6
|
+
export declare const setItemCrudDefaultSaveIcon: (icon: string) => void;
|
|
7
|
+
export declare const setItemCrudDefaultDropIcon: (icon: string) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lkt-item-crud",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/build.js",
|
|
@@ -27,27 +27,24 @@
|
|
|
27
27
|
"@types/node": "^20.11.19",
|
|
28
28
|
"@types/rollup": "^0.54.0",
|
|
29
29
|
"@vitejs/plugin-vue": "^5.0.4",
|
|
30
|
-
"rollup": "^4.
|
|
31
|
-
"typescript": "^5.
|
|
32
|
-
"vite": "^
|
|
30
|
+
"rollup": "^4.34.8",
|
|
31
|
+
"typescript": "^5.7.3",
|
|
32
|
+
"vite": "^6.1.1",
|
|
33
33
|
"vue": "^3.3.0",
|
|
34
|
-
"vue-tsc": "^
|
|
34
|
+
"vue-tsc": "^2.2.0"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=18"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"lkt-button": "^
|
|
40
|
+
"lkt-button": "^2.0.1",
|
|
41
41
|
"lkt-data-state": "^1.0.9",
|
|
42
|
-
"lkt-events": "^1.0.2",
|
|
43
|
-
"lkt-field-switch": "^1.0.0",
|
|
44
42
|
"lkt-http-client": "^1.0.12",
|
|
45
43
|
"lkt-http-info": "^1.0.2",
|
|
46
44
|
"lkt-i18n": "^1.0.4",
|
|
47
45
|
"lkt-loader": "^1.0.2",
|
|
48
|
-
"lkt-modal": "^
|
|
46
|
+
"lkt-modal": "^2.0.1",
|
|
49
47
|
"lkt-string-tools": "^1.0.2",
|
|
50
|
-
"lkt-ts-interfaces": "^1.0.2",
|
|
51
48
|
"lkt-vue-kernel": "^1.0.7",
|
|
52
49
|
"path": "^0.12.7"
|
|
53
50
|
}
|
|
@@ -1,48 +1,77 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { ref, useSlots, watch } from 'vue';
|
|
3
|
-
import {
|
|
2
|
+
import { computed, ref, SetupContext, useSlots, watch } from 'vue';
|
|
3
|
+
import {
|
|
4
|
+
ButtonConfig,
|
|
5
|
+
ensureButtonConfig,
|
|
6
|
+
ItemCrudButtonNavVisibility,
|
|
7
|
+
ItemCrudMode,
|
|
8
|
+
ItemCrudView,
|
|
9
|
+
LktObject,
|
|
10
|
+
LktSettings,
|
|
11
|
+
} from 'lkt-vue-kernel';
|
|
4
12
|
import { HTTPResponse } from 'lkt-http-client';
|
|
5
13
|
|
|
6
|
-
const emit = defineEmits([
|
|
14
|
+
const emit = defineEmits([
|
|
15
|
+
'update:loading',
|
|
16
|
+
'update:editing',
|
|
17
|
+
'create',
|
|
18
|
+
'save',
|
|
19
|
+
'drop',
|
|
20
|
+
]);
|
|
7
21
|
|
|
8
22
|
const props = withDefaults(defineProps<{
|
|
9
23
|
item: LktObject,
|
|
10
24
|
editing?: boolean
|
|
11
25
|
loading?: boolean
|
|
12
|
-
|
|
26
|
+
|
|
27
|
+
view: ItemCrudView
|
|
28
|
+
mode: ItemCrudMode
|
|
29
|
+
|
|
30
|
+
createButton?: ButtonConfig
|
|
31
|
+
updateButton?: ButtonConfig
|
|
32
|
+
dropButton?: ButtonConfig
|
|
33
|
+
editModeButton?: ButtonConfig
|
|
34
|
+
|
|
35
|
+
dataChanged: boolean
|
|
36
|
+
|
|
13
37
|
canUpdate?: boolean
|
|
14
38
|
canDrop?: boolean
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
ableToSave?: boolean
|
|
19
|
-
ableToDrop?: boolean
|
|
20
|
-
saveConfirm?: string
|
|
21
|
-
dropConfirm?: string
|
|
22
|
-
confirmData?: LktObject
|
|
23
|
-
dropConfirmData?: LktObject
|
|
24
|
-
saveResource?: string
|
|
25
|
-
dropResource?: string
|
|
26
|
-
saveData?: LktObject
|
|
27
|
-
dropData?: LktObject
|
|
28
|
-
saveText?: string
|
|
29
|
-
dropText?: string
|
|
30
|
-
saveIcon?: string
|
|
31
|
-
dropIcon?: string
|
|
32
|
-
editModeText?: string
|
|
39
|
+
canSwitchEditMode?: boolean
|
|
40
|
+
|
|
41
|
+
httpSuccessRead?: boolean
|
|
33
42
|
|
|
43
|
+
buttonNavVisibility: ItemCrudButtonNavVisibility
|
|
34
44
|
}>(), {
|
|
35
45
|
item: () => ({}),
|
|
36
46
|
editing: false,
|
|
37
47
|
isLoading: false,
|
|
38
|
-
showSaveButton: false,
|
|
39
|
-
ableToSave: false,
|
|
40
48
|
});
|
|
41
49
|
|
|
42
|
-
const
|
|
50
|
+
const safeCreateButton = ref(ensureButtonConfig(props.createButton, LktSettings.defaultCreateButton)),
|
|
51
|
+
safeUpdateButton = ref(ensureButtonConfig(props.updateButton, LktSettings.defaultUpdateButton)),
|
|
52
|
+
safeDropButton = ref(ensureButtonConfig(props.dropButton, LktSettings.defaultDropButton)),
|
|
53
|
+
safeEditModeButton = ref(ensureButtonConfig(props.editModeButton, LktSettings.defaultEditModeButton));
|
|
54
|
+
|
|
55
|
+
watch(() => props.createButton, v => {
|
|
56
|
+
safeCreateButton.value = ensureButtonConfig(v, LktSettings.defaultCreateButton);
|
|
57
|
+
}, { deep: true });
|
|
43
58
|
|
|
44
|
-
|
|
45
|
-
|
|
59
|
+
watch(() => props.updateButton, v => {
|
|
60
|
+
safeUpdateButton.value = ensureButtonConfig(v, LktSettings.defaultUpdateButton);
|
|
61
|
+
}, { deep: true });
|
|
62
|
+
|
|
63
|
+
watch(() => props.dropButton, v => {
|
|
64
|
+
safeDropButton.value = ensureButtonConfig(v, LktSettings.defaultDropButton);
|
|
65
|
+
}, { deep: true });
|
|
66
|
+
|
|
67
|
+
watch(() => props.editModeButton, v => {
|
|
68
|
+
safeEditModeButton.value = ensureButtonConfig(v, LktSettings.defaultEditModeButton);
|
|
69
|
+
}, { deep: true });
|
|
70
|
+
|
|
71
|
+
const slots: SetupContext['slots'] = useSlots();
|
|
72
|
+
|
|
73
|
+
const saveButtonRef = ref(<HTMLButtonElement | null>null);
|
|
74
|
+
const dropButtonRef = ref(<HTMLButtonElement | null>null);
|
|
46
75
|
|
|
47
76
|
const isLoading = ref(props.loading);
|
|
48
77
|
watch(() => props.loading, v => isLoading.value = v);
|
|
@@ -58,6 +87,9 @@
|
|
|
58
87
|
onButtonLoaded = () => {
|
|
59
88
|
isLoading.value = false;
|
|
60
89
|
},
|
|
90
|
+
onCreate = ($event: Event, r: HTTPResponse) => {
|
|
91
|
+
emit('create', $event, r);
|
|
92
|
+
},
|
|
61
93
|
onSave = ($event: Event, r: HTTPResponse) => {
|
|
62
94
|
emit('save', $event, r);
|
|
63
95
|
},
|
|
@@ -66,21 +98,84 @@
|
|
|
66
98
|
};
|
|
67
99
|
|
|
68
100
|
const doSave = () => {
|
|
69
|
-
if (
|
|
101
|
+
if (saveButtonRef.value && typeof saveButtonRef.value.click === 'function') saveButtonRef.value.click();
|
|
70
102
|
},
|
|
71
103
|
doDrop = () => {
|
|
72
|
-
if (
|
|
104
|
+
if (dropButtonRef.value && typeof dropButtonRef.value.click === 'function') dropButtonRef.value.click();
|
|
73
105
|
};
|
|
74
106
|
|
|
75
107
|
defineExpose({
|
|
76
108
|
doSave,
|
|
77
109
|
doDrop,
|
|
78
|
-
})
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
const ableToUpdate = computed(() => {
|
|
114
|
+
if (props.mode !== ItemCrudMode.Create && !props.canUpdate) return false;
|
|
115
|
+
|
|
116
|
+
if (typeof safeUpdateButton.value?.disabled === 'function') return safeUpdateButton.value.disabled(props.item);
|
|
117
|
+
if (typeof safeUpdateButton.value?.disabled === 'boolean') return safeUpdateButton.value.disabled;
|
|
118
|
+
|
|
119
|
+
return props.dataChanged;
|
|
120
|
+
}),
|
|
121
|
+
ableToCreate = computed(() => {
|
|
122
|
+
if (props.mode !== ItemCrudMode.Create) return false;
|
|
123
|
+
|
|
124
|
+
if (typeof safeCreateButton.value?.disabled === 'function') return safeCreateButton.value.disabled(props.item);
|
|
125
|
+
if (typeof safeCreateButton.value?.disabled === 'boolean') return safeCreateButton.value.disabled;
|
|
126
|
+
|
|
127
|
+
return props.dataChanged;
|
|
128
|
+
}),
|
|
129
|
+
ableToDrop = computed(() => {
|
|
130
|
+
|
|
131
|
+
if (!props.canDrop) return false;
|
|
132
|
+
|
|
133
|
+
if (typeof safeDropButton.value?.disabled === 'function') return safeDropButton.value.disabled(props.item);
|
|
134
|
+
if (typeof safeDropButton.value?.disabled === 'boolean') return safeDropButton.value.disabled;
|
|
135
|
+
|
|
136
|
+
return true;
|
|
137
|
+
}),
|
|
138
|
+
showDropButton = computed(() => {
|
|
139
|
+
if (!props.canDrop) return false;
|
|
140
|
+
if (!props.canUpdate && props.canDrop) return true;
|
|
141
|
+
|
|
142
|
+
return !isLoading.value
|
|
143
|
+
&& props.editing
|
|
144
|
+
&& props.httpSuccessRead;
|
|
145
|
+
}),
|
|
146
|
+
showSaveButton = computed(() => {
|
|
147
|
+
if (props.dataChanged) return true;
|
|
148
|
+
if (isLoading.value) return false;
|
|
149
|
+
|
|
150
|
+
if (props.mode === ItemCrudMode.Create) return true;
|
|
151
|
+
|
|
152
|
+
if (props.buttonNavVisibility === ItemCrudButtonNavVisibility.Never) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return props.editing
|
|
157
|
+
&& props.httpSuccessRead;
|
|
158
|
+
}),
|
|
159
|
+
showSwitchButton = computed(() => {
|
|
160
|
+
if (!props.canSwitchEditMode) return false;
|
|
161
|
+
if (!props.canUpdate && !props.canDrop) return false;
|
|
162
|
+
if (!props.canUpdate && props.canDrop) return false;
|
|
163
|
+
|
|
164
|
+
return !isLoading.value
|
|
165
|
+
&& props.mode !== ItemCrudMode.Create
|
|
166
|
+
&& props.httpSuccessRead;
|
|
167
|
+
}),
|
|
168
|
+
showButtons = computed(() => {
|
|
169
|
+
if (props.buttonNavVisibility === ItemCrudButtonNavVisibility.Always && (ableToUpdate.value || ableToCreate.value || ableToDrop.value)) return true;
|
|
170
|
+
if (slots['prev-buttons-ever']) return true;
|
|
171
|
+
if (props.buttonNavVisibility === ItemCrudButtonNavVisibility.Never) return false;
|
|
172
|
+
return showSaveButton.value || showDropButton.value || showSwitchButton.value;
|
|
173
|
+
});
|
|
79
174
|
|
|
80
175
|
</script>
|
|
81
176
|
|
|
82
177
|
<template>
|
|
83
|
-
<div class="lkt-item-crud-buttons">
|
|
178
|
+
<div v-if="showButtons" class="lkt-item-crud-buttons">
|
|
84
179
|
|
|
85
180
|
<div class="lkt-item-crud-buttons" v-if="slots['prev-buttons-ever']" v-show="!isLoading">
|
|
86
181
|
<slot name="prev-buttons-ever" />
|
|
@@ -91,46 +186,49 @@
|
|
|
91
186
|
</div>
|
|
92
187
|
|
|
93
188
|
<lkt-button
|
|
94
|
-
ref="
|
|
95
|
-
v-if="showSaveButton"
|
|
96
|
-
|
|
97
|
-
:disabled="!
|
|
98
|
-
:confirm-modal="saveConfirm"
|
|
99
|
-
:confirm-data="confirmData"
|
|
100
|
-
:resource="saveResource"
|
|
101
|
-
:resource-data="saveData"
|
|
102
|
-
:text="slots['button-save'] ? '' : saveText"
|
|
103
|
-
:icon="slots['button-save'] ? '' : saveIcon"
|
|
189
|
+
ref="saveButtonRef"
|
|
190
|
+
v-if="mode === ItemCrudMode.Update && showSaveButton"
|
|
191
|
+
v-bind="safeUpdateButton"
|
|
192
|
+
:disabled="!ableToUpdate"
|
|
104
193
|
@loading="onButtonLoading"
|
|
105
194
|
@loaded="onButtonLoaded"
|
|
106
195
|
@click="onSave">
|
|
107
196
|
<slot v-if="!!slots['button-save']" name="button-save" :item="item"
|
|
108
197
|
:edit-mode="isEditing"
|
|
109
|
-
:is-create="
|
|
198
|
+
:is-create="false"
|
|
199
|
+
:can-update="canUpdate"
|
|
200
|
+
:can-drop="canDrop" />
|
|
201
|
+
</lkt-button>
|
|
202
|
+
|
|
203
|
+
<lkt-button
|
|
204
|
+
ref="saveButtonRef"
|
|
205
|
+
v-else-if="mode === ItemCrudMode.Create && showSaveButton"
|
|
206
|
+
v-bind="safeCreateButton"
|
|
207
|
+
:disabled="!ableToCreate"
|
|
208
|
+
@loading="onButtonLoading"
|
|
209
|
+
@loaded="onButtonLoaded"
|
|
210
|
+
@click="onCreate">
|
|
211
|
+
<slot v-if="!!slots['button-save']" name="button-save" :item="item"
|
|
212
|
+
:edit-mode="isEditing"
|
|
213
|
+
:is-create="true"
|
|
110
214
|
:can-update="canUpdate"
|
|
111
|
-
:can-drop="canDrop"
|
|
215
|
+
:can-drop="canDrop" />
|
|
112
216
|
</lkt-button>
|
|
113
217
|
|
|
114
218
|
<lkt-button
|
|
115
|
-
ref="
|
|
219
|
+
ref="dropButtonRef"
|
|
116
220
|
v-show="showDropButton"
|
|
117
|
-
v-if="
|
|
118
|
-
|
|
221
|
+
v-if="mode !== ItemCrudMode.Create"
|
|
222
|
+
v-bind="safeDropButton"
|
|
119
223
|
:disabled="!ableToDrop"
|
|
120
|
-
:confirm-modal="dropConfirm"
|
|
121
|
-
:confirm-data="dropConfirmData"
|
|
122
|
-
:resource="dropResource"
|
|
123
|
-
:resource-data="dropData"
|
|
124
|
-
:text="slots['button-drop'] ? '' : dropText"
|
|
125
|
-
:icon="slots['button-drop'] ? '' : dropIcon"
|
|
126
224
|
@loading="onButtonLoading"
|
|
127
225
|
@loaded="onButtonLoaded"
|
|
128
226
|
@click="onDrop">
|
|
129
227
|
<slot v-if="!!slots['button-drop']" name="button-drop" :item="item"
|
|
130
228
|
:edit-mode="isEditing"
|
|
131
|
-
:is-create="
|
|
229
|
+
:is-create="false"
|
|
132
230
|
:can-update="canUpdate"
|
|
133
|
-
:can-drop="canDrop"
|
|
231
|
+
:can-drop="canDrop" />
|
|
134
232
|
</lkt-button>
|
|
135
233
|
|
|
136
234
|
<div class="lkt-item-crud-buttons" v-if="slots.buttons" v-show="isEditing && !isLoading">
|
|
@@ -139,9 +237,8 @@
|
|
|
139
237
|
|
|
140
238
|
<lkt-button
|
|
141
239
|
v-if="showSwitchButton"
|
|
240
|
+
v-bind="safeEditModeButton"
|
|
142
241
|
v-model:checked="isEditing"
|
|
143
|
-
class="lkt-item-crud--switch-mode-button"
|
|
144
|
-
show-switch
|
|
145
|
-
:text="editModeText" />
|
|
242
|
+
class="lkt-item-crud--switch-mode-button" />
|
|
146
243
|
</div>
|
|
147
244
|
</template>
|