This commit is contained in:
syuilo 2020-09-20 11:07:52 +09:00
parent 208343a3da
commit c50342a19e
4 changed files with 15 additions and 15 deletions

View File

@ -93,11 +93,6 @@ export default defineComponent({
required: true,
},
complete: {
type: Function,
required: true,
},
close: {
type: Function,
required: true,
@ -114,6 +109,8 @@ export default defineComponent({
},
},
emits: ['done', 'closed'],
data() {
return {
getStaticImageUrl,
@ -200,6 +197,11 @@ export default defineComponent({
},
methods: {
complete(type, value) {
this.$emit('done', { type, value });
this.$emit('closed');
},
setPosition() {
if (this.x + this.$el.offsetWidth > window.innerWidth) {
this.$el.style.left = (window.innerWidth - this.$el.offsetWidth) + 'px';

View File

@ -54,20 +54,15 @@ export function popup(component: Component, props: Record<string, any>, events =
markRaw(component);
const id = Math.random().toString(); // TODO: uuidとか使う
const showing = ref(true);
const close = (...args) => {
resolve(...args);
showing.value = false;
};
const modal = {
type: 'popup',
component,
props,
showing,
events,
done: close,
bgClick: () => close(),
closed: () => {
store.commit('removePopup', id);
resolve();
},
id,
};
@ -75,7 +70,7 @@ export function popup(component: Component, props: Record<string, any>, events =
onCancel.shouldReject = false;
onCancel(() => {
close();
showing.value = false;
});
});
}

View File

@ -6,7 +6,7 @@
<component :is="modal.component" v-bind="modal.props" v-on="modal.events" @done="modal.done"/>
</XModal>
<component v-for="popup in $store.state.popups.filter(x => x.type === 'popup')" :key="popup.id" :is="popup.component" v-bind="popup.props" v-on="popup.events" @done="popup.done" @closed="popup.closed"/>
<component v-for="popup in $store.state.popups.filter(x => x.type === 'popup')" :key="popup.id" :is="popup.component" v-bind="popup.props" :showing="popup.showing" v-on="popup.events" @closed="popup.closed"/>
<div id="wait" v-if="$store.state.pendingApiRequestsCount > 0"></div>
</template>

View File

@ -154,12 +154,15 @@ export class Autocomplete {
const promise = popup(MkAutocomplete, {
textarea: this.textarea,
complete: this.complete,
close: this.close,
type: type,
q: _q,
x: _x,
y: _y,
}, {
done: (res) => {
this.complete(res);
}
});
this.suggestion = {
@ -188,7 +191,7 @@ export class Autocomplete {
/**
*
*/
private complete(type, value) {
private complete({ type, value }) {
this.close();
const caret = this.textarea.selectionStart;