sprintify-ui 0.6.74 → 0.6.75
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/package.json
CHANGED
|
@@ -17,7 +17,7 @@ export default {
|
|
|
17
17
|
args: {
|
|
18
18
|
url: 'https://faker.witify.io/api/todos',
|
|
19
19
|
field: 'name',
|
|
20
|
-
primaryKey: '
|
|
20
|
+
primaryKey: 'id',
|
|
21
21
|
showRouteUrl(id) {
|
|
22
22
|
return `https://faker.witify.io/api/todos/${id}`;
|
|
23
23
|
},
|
|
@@ -28,7 +28,7 @@ export default {
|
|
|
28
28
|
const Template = (args) => ({
|
|
29
29
|
components: { BaseBelongsToFetch, ShowValue },
|
|
30
30
|
setup() {
|
|
31
|
-
const value = ref(
|
|
31
|
+
const value = ref(4);
|
|
32
32
|
return { args, value };
|
|
33
33
|
},
|
|
34
34
|
template: `
|
|
@@ -78,9 +78,6 @@ export const Sizes = (args) => ({
|
|
|
78
78
|
|
|
79
79
|
export const Disabled = Template.bind({});
|
|
80
80
|
Disabled.args = {
|
|
81
|
-
currentModel: options[0],
|
|
82
|
-
primaryKey: 'value',
|
|
83
|
-
field: 'label',
|
|
84
81
|
disabled: true,
|
|
85
82
|
};
|
|
86
83
|
|
|
@@ -107,7 +104,7 @@ export const SlotOption = (args) => {
|
|
|
107
104
|
}"
|
|
108
105
|
>
|
|
109
106
|
<p class="text-sm font-medium">{{ option.title }}</p>
|
|
110
|
-
<p class="opacity-60 text-xs">{{ option.
|
|
107
|
+
<p class="opacity-60 text-xs">{{ option.description }}</p>
|
|
111
108
|
</div>
|
|
112
109
|
</template>
|
|
113
110
|
</BaseBelongsToFetch>
|
|
@@ -169,8 +166,8 @@ export const WithSelect = (args) => {
|
|
|
169
166
|
return {
|
|
170
167
|
components: { BaseBelongsToFetch, ShowValue },
|
|
171
168
|
setup() {
|
|
172
|
-
const value = ref(options[0]);
|
|
173
169
|
const selected = ref(null);
|
|
170
|
+
const value = ref(5);
|
|
174
171
|
|
|
175
172
|
const select = {
|
|
176
173
|
options: [
|
|
@@ -49,7 +49,7 @@ import { config } from '@/index';
|
|
|
49
49
|
import BaseAutocompleteFetch from './BaseAutocompleteFetch.vue';
|
|
50
50
|
import { Option, SelectConfiguration } from '@/types';
|
|
51
51
|
import { Size } from '@/utils/sizes';
|
|
52
|
-
import { isObject } from 'lodash';
|
|
52
|
+
import { debounce, isObject } from 'lodash';
|
|
53
53
|
|
|
54
54
|
const props = defineProps({
|
|
55
55
|
modelValue: {
|
|
@@ -145,59 +145,18 @@ const autocompleteFetch = ref<InstanceType<
|
|
|
145
145
|
> | null>(null);
|
|
146
146
|
|
|
147
147
|
const model = ref(props.currentModel);
|
|
148
|
+
const ensureModelIsFilledDebounced = debounce(ensureModelIsFilled, 100);
|
|
148
149
|
|
|
149
150
|
watch(
|
|
150
151
|
() => props.currentModel,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
},
|
|
154
|
-
{ deep: true }
|
|
152
|
+
ensureModelIsFilledDebounced,
|
|
153
|
+
{ immediate: true },
|
|
155
154
|
);
|
|
156
155
|
|
|
157
156
|
watch(
|
|
158
157
|
() => props.modelValue,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (props.showRouteUrl == null) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (props.currentModel !== undefined) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (!props.modelValue) {
|
|
170
|
-
model.value = null;
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (newValue == oldValue) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
http
|
|
179
|
-
.get(props.showRouteUrl(props.modelValue))
|
|
180
|
-
.then((response: AxiosResponse) => {
|
|
181
|
-
|
|
182
|
-
const data = response.data as Record<string, unknown>;
|
|
183
|
-
|
|
184
|
-
if (!isObject(data)) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (data[props.primaryKey as never] == props.modelValue) {
|
|
189
|
-
model.value = data;
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (isObject(data.data) && data.data[props.primaryKey as never] == props.modelValue) {
|
|
194
|
-
model.value = data.data;
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
})
|
|
198
|
-
.catch((e: Error) => e);
|
|
199
|
-
},
|
|
200
|
-
{ immediate: true }
|
|
158
|
+
ensureModelIsFilledDebounced,
|
|
159
|
+
{ immediate: true },
|
|
201
160
|
);
|
|
202
161
|
|
|
203
162
|
function onUpdate(newModel: Option | null) {
|
|
@@ -210,6 +169,54 @@ function onUpdate(newModel: Option | null) {
|
|
|
210
169
|
}
|
|
211
170
|
}
|
|
212
171
|
|
|
172
|
+
function ensureModelIsFilled() {
|
|
173
|
+
|
|
174
|
+
if (props.modelValue == null) {
|
|
175
|
+
model.value = null;
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const modelId = model.value ? model.value[props.primaryKey as never] : null;
|
|
180
|
+
|
|
181
|
+
// Current value is already set
|
|
182
|
+
if (props.modelValue == modelId) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Try with current model
|
|
187
|
+
if (props.currentModel && props.currentModel[props.primaryKey as never] == props.modelValue) {
|
|
188
|
+
model.value = props.currentModel;
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Try with show route
|
|
193
|
+
|
|
194
|
+
if (props.showRouteUrl == null) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
http
|
|
199
|
+
.get(props.showRouteUrl(props.modelValue))
|
|
200
|
+
.then((response: AxiosResponse) => {
|
|
201
|
+
|
|
202
|
+
const data = response.data as Record<string, unknown>;
|
|
203
|
+
|
|
204
|
+
if (!isObject(data)) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (data[props.primaryKey as never] == props.modelValue) {
|
|
209
|
+
model.value = data;
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (isObject(data.data) && data.data[props.primaryKey as never] == props.modelValue) {
|
|
214
|
+
model.value = data.data;
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
213
220
|
defineExpose({
|
|
214
221
|
focus: () => autocompleteFetch.value?.focus(),
|
|
215
222
|
blur: () => autocompleteFetch.value?.blur(),
|