diff --git a/src/client/components/post-form.vue b/src/client/components/post-form.vue
index af810d2498..7e742e79cb 100644
--- a/src/client/components/post-form.vue
+++ b/src/client/components/post-form.vue
@@ -33,8 +33,8 @@
-
-
+
+
@@ -68,6 +68,7 @@ import extractMentions from '../../misc/extract-mentions';
import getAcct from '../../misc/acct/render';
import { formatTimeString } from '../../misc/format-time-string';
import { selectDriveFile } from '@/scripts/select-drive-file';
+import { Autocomplete } from '@/scripts/autocomplete';
import { noteVisibilities } from '../../types';
import { utils } from '@syuilo/aiscript';
import * as os from '@/os';
@@ -280,6 +281,9 @@ export default defineComponent({
this.focus();
});
+ new Autocomplete(this.$refs.text, this, { model: 'text' });
+ new Autocomplete(this.$refs.cw, this, { model: 'cw' });
+
this.$nextTick(() => {
// 書きかけの投稿を復元
if (!this.instant && !this.mention) {
diff --git a/src/client/directives/index.ts b/src/client/directives/index.ts
index 4ff90fa7fd..4e14535e09 100644
--- a/src/client/directives/index.ts
+++ b/src/client/directives/index.ts
@@ -1,13 +1,11 @@
import { App } from 'vue';
import userPreview from './user-preview';
-import autocomplete from './autocomplete';
import size from './size';
import particle from './particle';
import tooltip from './tooltip';
export default function(app: App) {
- app.directive('autocomplete', autocomplete);
app.directive('userPreview', userPreview);
app.directive('user-preview', userPreview);
app.directive('size', size);
diff --git a/src/client/directives/user-preview.ts b/src/client/directives/user-preview.ts
index 1e514e5277..f4f32d1146 100644
--- a/src/client/directives/user-preview.ts
+++ b/src/client/directives/user-preview.ts
@@ -29,7 +29,6 @@ export default {
self.close = os.popup(MkUserPreview, {
user: self.user,
- }, null, {
source: el
});
diff --git a/src/client/os.ts b/src/client/os.ts
index 7a130a3408..0d65e6deaf 100644
--- a/src/client/os.ts
+++ b/src/client/os.ts
@@ -60,7 +60,6 @@ export function popup(component: Component, props: Record, events =
props,
showing,
events,
- source: option?.source,
done: close,
bgClick: () => close(),
closed: () => {
diff --git a/src/client/directives/autocomplete.ts b/src/client/scripts/autocomplete.ts
similarity index 84%
rename from src/client/directives/autocomplete.ts
rename to src/client/scripts/autocomplete.ts
index efba808f37..9520d1307e 100644
--- a/src/client/directives/autocomplete.ts
+++ b/src/client/scripts/autocomplete.ts
@@ -1,25 +1,15 @@
-import { Directive } from 'vue';
+import { Ref, ref } from 'vue';
import * as getCaretCoordinates from 'textarea-caret';
import { toASCII } from 'punycode';
+import { popup } from '@/os';
-export default {
- mounted(el, binding, vn) {
- const self = el._autoCompleteDirective_ = {} as any;
- self.x = new Autocomplete(el, vn.context, binding.value);
- self.x.attach();
- },
-
- unmounted(el, binding, vn) {
- const self = el._autoCompleteDirective_;
- self.x.detach();
- }
-} as Directive;
-
-/**
- * オートコンプリートを管理するクラス。
- */
-class Autocomplete {
- private suggestion: any;
+export class Autocomplete {
+ private suggestion: {
+ x: Ref;
+ y: Ref;
+ q: Ref;
+ close: Function;
+ };
private textarea: any;
private vm: any;
private currentType: string;
@@ -148,31 +138,34 @@ class Autocomplete {
//#endregion
if (this.suggestion) {
- // TODO: Vueの警告が出るのでなんとかする
- this.suggestion.x = x;
- this.suggestion.y = y;
- this.suggestion.q = q;
+ this.suggestion.x.value = x;
+ this.suggestion.y.value = y;
+ this.suggestion.q.value = q;
this.opening = false;
} else {
const MkAutocomplete = await import('@/components/autocomplete.vue');
- // サジェスト要素作成
- this.suggestion = new MkAutocomplete({
- parent: this.vm,
- propsData: {
- textarea: this.textarea,
- complete: this.complete,
- close: this.close,
- type: type,
- q: q,
- x,
- y
- }
- }).$mount();
+ const _x = ref(x);
+ const _y = ref(y);
+ const _q = ref(q);
- // 要素追加
- document.body.appendChild(this.suggestion.$el);
+ const promise = popup(MkAutocomplete, {
+ textarea: this.textarea,
+ complete: this.complete,
+ close: this.close,
+ type: type,
+ q: _q,
+ x: _x,
+ y: _y,
+ });
+
+ this.suggestion = {
+ q: _q,
+ x: _x,
+ y: _y,
+ close: () => promise.cancel(),
+ };
this.opening = false;
}
@@ -184,7 +177,7 @@ class Autocomplete {
private close() {
if (this.suggestion == null) return;
- this.suggestion.destroyDom();
+ this.suggestion.close();
this.suggestion = null;
this.textarea.focus();