Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance(frontend): MFMの属性にオートコンプリートが利用できるように #12803

Merged
merged 33 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ce5ed43
MFMのパラメータでオートコンプリートできるように
1STEP621 Dec 21, 2023
0279d49
tweak conditions & refactor
1STEP621 Dec 23, 2023
ec94715
ファイル末尾の改行忘れ
1STEP621 Dec 23, 2023
e7e3d4d
remove console.log & refactor
1STEP621 Dec 23, 2023
bacc436
型付けに敗北
1STEP621 Dec 25, 2023
d92453e
fix
1STEP621 Dec 25, 2023
178658f
Merge branch 'develop' of github.com:misskey-dev/misskey into enhance…
1STEP621 Dec 25, 2023
facbf1d
update CHANGELOG.md
1STEP621 Dec 25, 2023
d686115
tweak conditions
1STEP621 Dec 25, 2023
38ebbcf
CHANGELOGの様式ミス
1STEP621 Dec 25, 2023
b95dbdf
CHANGELOGを書く場所を間違えていたので修正
1STEP621 Dec 25, 2023
12eb374
Merge branch 'develop' into enhance/mfm-params-autocomplete
1STEP621 Dec 26, 2023
900bfef
Merge branch 'develop' into enhance/mfm-params-autocomplete
1STEP621 Dec 27, 2023
50473e3
Merge branch 'develop' into enhance/mfm-params-autocomplete
1STEP621 Dec 28, 2023
58de16e
move changelog
1STEP621 Dec 28, 2023
82f62e6
move changelog
1STEP621 Dec 28, 2023
63be822
Merge branch 'enhance/mfm-params-autocomplete' of github.com:1STEP621…
1STEP621 Dec 28, 2023
52f3554
Merge branch 'develop' into enhance/mfm-params-autocomplete
1STEP621 Dec 29, 2023
4146b35
Merge branch 'develop' into enhance/mfm-params-autocomplete
1STEP621 Dec 31, 2023
df2e1f5
Merge branch 'develop' into enhance/mfm-params-autocomplete
1STEP621 Jan 2, 2024
82894b6
Merge branch 'develop' into enhance/mfm-params-autocomplete
1STEP621 Jan 4, 2024
1f3d36e
Merge branch 'develop' into enhance/mfm-params-autocomplete
1STEP621 Jan 8, 2024
c39b53b
Merge branch 'develop' into enhance/mfm-params-autocomplete
1STEP621 Jan 10, 2024
10c4dbf
Merge branch 'develop' into enhance/mfm-params-autocomplete
1STEP621 Jan 10, 2024
8763bb9
Merge branch 'develop' into enhance/mfm-params-autocomplete
1STEP621 Jan 13, 2024
ba5ee0e
Merge branch 'develop' into enhance/mfm-params-autocomplete
1STEP621 Jan 14, 2024
c631637
Merge branch 'develop' into enhance/mfm-params-autocomplete
1STEP621 Jan 15, 2024
99071eb
Merge branch 'develop' of github.com:misskey-dev/misskey into enhance…
1STEP621 Jan 17, 2024
8a673e2
typeof MFM_TAGS[number]
1STEP621 Jan 17, 2024
5a7b9bf
Merge branch 'develop' of github.com:misskey-dev/misskey into enhance…
1STEP621 Jan 17, 2024
cbcc272
Merge branch 'enhance/mfm-params-autocomplete' of github.com:1STEP621…
1STEP621 Jan 17, 2024
a36dfc2
$[border.noclip ]対応
1STEP621 Jan 17, 2024
5ebc950
Update const.ts
syuilo Jan 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-

### Client
-
- MFMの属性でオートコンプリートが使用できるように #12735

### Server
-
Expand Down
17 changes: 15 additions & 2 deletions packages/frontend/src/components/MkAutocomplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ SPDX-License-Identifier: AGPL-3.0-only
<span>{{ tag }}</span>
</li>
</ol>
<ol v-else-if="mfmParams.length > 0" ref="suggests" :class="$style.list">
<li v-for="param in mfmParams" tabindex="-1" :class="$style.item" @click="complete(type, q.params.toSpliced(-1, 1, param).join(','))" @keydown="onKeydown">
<span>{{ param }}</span>
</li>
</ol>
</div>
</template>

Expand All @@ -50,7 +55,7 @@ import { emojilist, getEmojiName } from '@/scripts/emojilist.js';
import { i18n } from '@/i18n.js';
import { miLocalStorage } from '@/local-storage.js';
import { customEmojis } from '@/custom-emojis.js';
import { MFM_TAGS } from '@/const.js';
import { MFM_TAGS, MFM_PARAMS } from '@/const.js';

type EmojiDef = {
emoji: string;
Expand Down Expand Up @@ -129,7 +134,7 @@ export default {
<script lang="ts" setup>
const props = defineProps<{
type: string;
q: string | null;
q: any;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここがanyになっちゃうのが微妙かなと思いましたが、直せませんでした...

textarea: HTMLTextAreaElement;
close: () => void;
x: number;
Expand All @@ -150,6 +155,7 @@ const hashtags = ref<any[]>([]);
const emojis = ref<(EmojiDef)[]>([]);
const items = ref<Element[] | HTMLCollection>([]);
const mfmTags = ref<string[]>([]);
const mfmParams = ref<string[]>([]);
const select = ref(-1);
const zIndex = os.claimZIndex('high');

Expand Down Expand Up @@ -250,6 +256,13 @@ function exec() {
}

mfmTags.value = MFM_TAGS.filter(tag => tag.startsWith(props.q ?? ''));
} else if (props.type === 'mfmParam') {
if (props.q.params.at(-1) === '') {
mfmParams.value = MFM_PARAMS[props.q.tag] ?? [];
return;
}

mfmParams.value = MFM_PARAMS[props.q.tag].filter(param => param.startsWith(props.q.params.at(-1) ?? ''));
}
}

Expand Down
23 changes: 23 additions & 0 deletions packages/frontend/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,26 @@ export const DEFAULT_NOT_FOUND_IMAGE_URL = 'https://xn--931a.moe/assets/not-foun
export const DEFAULT_INFO_IMAGE_URL = 'https://xn--931a.moe/assets/info.jpg';

export const MFM_TAGS = ['tada', 'jelly', 'twitch', 'shake', 'spin', 'jump', 'bounce', 'flip', 'x2', 'x3', 'x4', 'scale', 'position', 'fg', 'bg', 'font', 'blur', 'rainbow', 'sparkle', 'rotate', 'ruby', 'unixtime'];
export const MFM_PARAMS = {
tada: ['speed=', 'delay='],
jelly: ['speed=', 'delay='],
twitch: ['speed=', 'delay='],
shake: ['speed=', 'delay='],
spin: ['speed=', 'delay=', 'left', 'alternate', 'x', 'y'],
jump: ['speed=', 'delay='],
bounce: ['speed=', 'delay='],
flip: ['h', 'v'],
x2: [],
x3: [],
x4: [],
scale: ['x=', 'y='],
position: ['x=', 'y='],
fg: ['color='],
bg: ['color='],
font: ['serif', 'monospace', 'cursive', 'fantasy', 'emoji', 'math'],
blur: [],
rainbow: ['speed=', 'delay='],
rotate: ['deg='],
ruby: [],
unixtime: [],
} as Record<string, string[]>;
1STEP621 marked this conversation as resolved.
Show resolved Hide resolved
39 changes: 34 additions & 5 deletions packages/frontend/src/scripts/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import getCaretCoordinates from 'textarea-caret';
import { toASCII } from 'punycode/';
import { popup } from '@/os.js';

export type SuggestionType = 'user' | 'hashtag' | 'emoji' | 'mfmTag';
export type SuggestionType = 'user' | 'hashtag' | 'emoji' | 'mfmTag' | 'mfmParam';

export class Autocomplete {
private suggestion: {
x: Ref<number>;
y: Ref<number>;
q: Ref<string | null>;
q: Ref<any>;
close: () => void;
} | null;
private textarea: HTMLInputElement | HTMLTextAreaElement;
Expand Down Expand Up @@ -49,7 +49,7 @@ export class Autocomplete {
this.textarea = textarea;
this.textRef = textRef;
this.opening = false;
this.onlyType = onlyType ?? ['user', 'hashtag', 'emoji', 'mfmTag'];
this.onlyType = onlyType ?? ['user', 'hashtag', 'emoji', 'mfmTag', 'mfmParam'];

this.attach();
}
Expand Down Expand Up @@ -80,6 +80,7 @@ export class Autocomplete {
const hashtagIndex = text.lastIndexOf('#');
const emojiIndex = text.lastIndexOf(':');
const mfmTagIndex = text.lastIndexOf('$');
const mfmParamIndex = text.lastIndexOf('.');

const max = Math.max(
mentionIndex,
Expand All @@ -94,7 +95,8 @@ export class Autocomplete {

const isMention = mentionIndex !== -1;
const isHashtag = hashtagIndex !== -1;
const isMfmTag = mfmTagIndex !== -1;
const isMfmParam = mfmParamIndex !== -1 && text.split(/\$\[[a-zA-Z]+/).pop()?.includes('.');
const isMfmTag = mfmTagIndex !== -1 && !isMfmParam;
const isEmoji = emojiIndex !== -1 && text.split(/:[a-z0-9_+\-]+:/).pop()!.includes(':');

let opened = false;
Expand Down Expand Up @@ -134,6 +136,17 @@ export class Autocomplete {
}
}

if (isMfmParam && !opened && this.onlyType.includes('mfmParam')) {
const mfmParam = text.substring(mfmParamIndex + 1);
if (!mfmParam.includes(' ')) {
this.open('mfmParam', {
tag: text.substring(mfmTagIndex + 2, mfmParamIndex),
params: mfmParam.split(','),
});
opened = true;
}
}

if (!opened) {
this.close();
}
Expand All @@ -142,7 +155,7 @@ export class Autocomplete {
/**
* サジェストを提示します。
*/
private async open(type: string, q: string | null) {
private async open(type: string, q: any) {
if (type !== this.currentType) {
this.close();
}
Expand Down Expand Up @@ -280,6 +293,22 @@ export class Autocomplete {
const pos = trimmedBefore.length + (value.length + 3);
this.textarea.setSelectionRange(pos, pos);
});
} else if (type === 'mfmParam') {
const source = this.text;

const before = source.substring(0, caret);
const trimmedBefore = before.substring(0, before.lastIndexOf('.'));
const after = source.substring(caret);

// 挿入
this.text = `${trimmedBefore}.${value}${after}`;

// キャレットを戻す
nextTick(() => {
this.textarea.focus();
const pos = trimmedBefore.length + (value.length + 1);
this.textarea.setSelectionRange(pos, pos);
});
}
}
}
Loading