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

refactor(frontend): クリップボードAPIを使用する #220

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions packages/frontend/src/components/MkCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import * as os from '@/os.js';
import MkLoading from '@/components/global/MkLoading.vue';
import { defaultStore } from '@/store.js';
import { i18n } from '@/i18n.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';

const props = defineProps<{
code: string;
Expand All @@ -42,7 +42,7 @@ const show = ref(!defaultStore.state.dataSaver.code);
const XCode = defineAsyncComponent(() => import('@/components/MkCode.core.vue'));

function copy() {
copyToClipboard(props.code);
copyText(props.code);
os.success();
}
</script>
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/MkDrive.folder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { misskeyApi } from '@/scripts/misskey-api.js';
import { i18n } from '@/i18n.js';
import { defaultStore } from '@/store.js';
import { claimAchievement } from '@/scripts/achievements.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';
import { MenuItem } from '@/types/menu.js';

const props = withDefaults(defineProps<{
Expand Down Expand Up @@ -277,7 +277,7 @@ function onContextmenu(ev: MouseEvent) {
icon: 'ti ti-id',
text: i18n.ts.copyFolderId,
action: () => {
copyToClipboard(props.folder.id);
copyText(props.folder.id);
},
}]);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/MkInviteCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import { computed } from 'vue';
import * as Misskey from 'misskey-js';
import MkFolder from '@/components/MkFolder.vue';
import MkButton from '@/components/MkButton.vue';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';
import { i18n } from '@/i18n.js';
import * as os from '@/os.js';

Expand All @@ -87,7 +87,7 @@ function deleteCode() {
}

function copyInviteCode() {
copyToClipboard(props.invite.code);
copyText(props.invite.code);
os.success();
}
</script>
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/MkKeyValue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import { } from 'vue';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';
import * as os from '@/os.js';
import { i18n } from '@/i18n.js';

Expand All @@ -30,7 +30,7 @@ const props = withDefaults(defineProps<{
});

const copy_ = () => {
copyToClipboard(props.copy);
copyText(props.copy);
os.success();
};
</script>
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/MkPageWindow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { computed, onMounted, onUnmounted, provide, ref, shallowRef } from 'vue'
import RouterView from '@/components/global/RouterView.vue';
import MkWindow from '@/components/MkWindow.vue';
import { popout as _popout } from '@/scripts/popout.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';
import { url } from '@/config.js';
import { useScrollPositionManager } from '@/nirax.js';
import { i18n } from '@/i18n.js';
Expand Down Expand Up @@ -129,7 +129,7 @@ const contextmenu = computed(() => ([{
icon: 'ti ti-link',
text: i18n.ts.copyLink,
action: () => {
copyToClipboard(url + windowRouter.getCurrentPath());
copyText(url + windowRouter.getCurrentPath());
},
}]));

Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/global/MkA.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type MkABehavior = 'window' | 'browser' | null;
<script lang="ts" setup>
import { computed, inject, shallowRef } from 'vue';
import * as os from '@/os.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';
import { url } from '@/config.js';
import { i18n } from '@/i18n.js';
import { useRouter } from '@/router/supplier.js';
Expand Down Expand Up @@ -86,7 +86,7 @@ function onContextmenu(ev) {
icon: 'ti ti-link',
text: i18n.ts.copyLink,
action: () => {
copyToClipboard(`${url}${props.to}`);
copyText(`${url}${props.to}`);
},
}], ev);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/global/MkCustomEmoji.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { defaultStore } from '@/store.js';
import { customEmojisMap } from '@/custom-emojis.js';
import * as os from '@/os.js';
import { misskeyApiGet } from '@/scripts/misskey-api.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';
import * as sound from '@/scripts/sound.js';
import { i18n } from '@/i18n.js';
import MkCustomEmojiDetailedDialog from '@/components/MkCustomEmojiDetailedDialog.vue';
Expand Down Expand Up @@ -92,7 +92,7 @@ function onClick(ev: MouseEvent) {
text: i18n.ts.copy,
icon: 'ti ti-copy',
action: () => {
copyToClipboard(`:${props.name}:`);
copyText(`:${props.name}:`);
os.success();
},
}, ...(props.menuReaction && react ? [{
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/global/MkEmoji.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { char2fluentEmojiFilePath, char2twemojiFilePath } from '@/scripts/emoji-
import { defaultStore } from '@/store.js';
import { colorizeEmoji, getEmojiName } from '@/scripts/emojilist.js';
import * as os from '@/os.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';
import * as sound from '@/scripts/sound.js';
import { i18n } from '@/i18n.js';

Expand Down Expand Up @@ -46,7 +46,7 @@ function onClick(ev: MouseEvent) {
text: i18n.ts.copy,
icon: 'ti ti-copy',
action: () => {
copyToClipboard(props.emoji);
copyText(props.emoji);
os.success();
},
}, ...(props.menuReaction && react ? [{
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/os.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import MkEmojiPickerDialog from '@/components/MkEmojiPickerDialog.vue';
import MkPopupMenu from '@/components/MkPopupMenu.vue';
import MkContextMenu from '@/components/MkContextMenu.vue';
import { MenuItem } from '@/types/menu.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';
import { showMovedDialog } from '@/scripts/show-moved-dialog.js';

export const openingWindowsCount = ref(0);
Expand Down Expand Up @@ -54,7 +54,7 @@ export const apiWithDialog = (<E extends keyof Misskey.Endpoints = keyof Misskey
}],
});
if (result === 'copy') {
copyToClipboard(`Endpoint: ${endpoint}\nInfo: ${JSON.stringify(err.info)}\nDate: ${date}`);
copyText(`Endpoint: ${endpoint}\nInfo: ${JSON.stringify(err.info)}\nDate: ${date}`);
success();
}
return;
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/pages/channel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import MkFoldableSection from '@/components/MkFoldableSection.vue';
import MkHorizontalSwipe from '@/components/MkHorizontalSwipe.vue';
import { PageHeaderItem } from '@/types/page-header.js';
import { isSupportShare } from '@/scripts/navigator.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';
import { miLocalStorage } from '@/local-storage.js';
import { useRouter } from '@/router/supplier.js';

Expand Down Expand Up @@ -202,7 +202,7 @@ const headerActions = computed(() => {
console.warn('failed to copy channel URL. channel.value is null.');
return;
}
copyToClipboard(`${url}/channels/${channel.value.id}`);
copyText(`${url}/channels/${channel.value.id}`);
os.success();
},
});
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/pages/clip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { url } from '@/config.js';
import MkButton from '@/components/MkButton.vue';
import { clipsCache } from '@/cache.js';
import { isSupportShare } from '@/scripts/navigator.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';

const props = defineProps<{
clipId: string;
Expand Down Expand Up @@ -130,7 +130,7 @@ const headerActions = computed(() => clip.value && isOwned.value ? [{
icon: 'ti ti-link',
text: i18n.ts.copyUrl,
handler: async (): Promise<void> => {
copyToClipboard(`${url}/clips/${clip.value.id}`);
copyText(`${url}/clips/${clip.value.id}`);
os.success();
},
}] : []), ...(clip.value.isPublic && isSupportShare() ? [{
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/pages/drop-and-fusion.game.vue
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ import { apiUrl } from '@/config.js';
import { $i } from '@/account.js';
import * as sound from '@/scripts/sound.js';
import MkRange from '@/components/MkRange.vue';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';

type FrontendMonoDefinition = {
id: string;
Expand Down Expand Up @@ -847,7 +847,7 @@ function exportLog() {
d: new Date().toISOString(),
l: DropAndFusionGame.serializeLogs(logs),
});
copyToClipboard(data);
copyText(data);
os.success();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/pages/emojis.emoji.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SPDX-License-Identifier: AGPL-3.0-only
import * as os from '@/os.js';
import * as Misskey from 'misskey-js';
import { misskeyApiGet } from '@/scripts/misskey-api.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';
import { i18n } from '@/i18n.js';
import MkCustomEmojiDetailedDialog from '@/components/MkCustomEmojiDetailedDialog.vue';

Expand All @@ -33,7 +33,7 @@ function menu(ev) {
text: i18n.ts.copy,
icon: 'ti ti-copy',
action: () => {
copyToClipboard(`:${props.emoji.name}:`);
copyText(`:${props.emoji.name}:`);
os.success();
},
}, {
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/pages/flash/flash.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import MkCode from '@/components/MkCode.vue';
import { defaultStore } from '@/store.js';
import { $i } from '@/account.js';
import { isSupportShare } from '@/scripts/navigator.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';

const props = defineProps<{
id: string;
Expand Down Expand Up @@ -118,7 +118,7 @@ function share(ev: MouseEvent) {
function copyLink() {
if (!flash.value) return;

copyToClipboard(`${url}/play/${flash.value.id}`);
copyText(`${url}/play/${flash.value.id}`);
os.success();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/pages/gallery/post.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import { definePageMetadata } from '@/scripts/page-metadata.js';
import { defaultStore } from '@/store.js';
import { $i } from '@/account.js';
import { isSupportShare } from '@/scripts/navigator.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';
import { useRouter } from '@/router/supplier.js';

const router = useRouter();
Expand Down Expand Up @@ -108,7 +108,7 @@ function fetchPost() {
}

function copyLink() {
copyToClipboard(`${url}/gallery/${post.value.id}`);
copyText(`${url}/gallery/${post.value.id}`);
os.success();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/pages/page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ import { $i } from '@/account.js';
import { isSupportShare } from '@/scripts/navigator.js';
import { instance } from '@/instance.js';
import { getStaticImageUrl } from '@/scripts/media-proxy.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';

const props = defineProps<{
pageName: string;
Expand Down Expand Up @@ -184,7 +184,7 @@ function share(ev: MouseEvent) {
function copyLink() {
if (!page.value) return;

copyToClipboard(`${url}/@${page.value.user.username}/pages/${page.value.name}`);
copyText(`${url}/@${page.value.user.username}/pages/${page.value.name}`);
os.success();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/pages/settings/plugin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import MkCode from '@/components/MkCode.vue';
import MkFolder from '@/components/MkFolder.vue';
import MkKeyValue from '@/components/MkKeyValue.vue';
import * as os from '@/os.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';
import { ColdDeviceStorage } from '@/store.js';
import { unisonReload } from '@/scripts/unison-reload.js';
import { i18n } from '@/i18n.js';
Expand All @@ -107,7 +107,7 @@ async function uninstall(plugin) {
}

function copy(text) {
copyToClipboard(text ?? '');
copyText(text ?? '');
os.success();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/pages/settings/theme.manage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import MkSelect from '@/components/MkSelect.vue';
import MkInput from '@/components/MkInput.vue';
import MkButton from '@/components/MkButton.vue';
import { Theme, getBuiltinThemesRef } from '@/scripts/theme.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';
import * as os from '@/os.js';
import { getThemes, removeTheme } from '@/theme-store.js';
import { i18n } from '@/i18n.js';
Expand All @@ -66,7 +66,7 @@ const selectedThemeCode = computed(() => {
});

function copyThemeCode() {
copyToClipboard(selectedThemeCode.value);
copyText(selectedThemeCode.value);
os.success();
}

Expand Down
1 change: 1 addition & 0 deletions packages/frontend/src/scripts/copy-to-clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

/**
* Clipboardに値をコピー(TODO: 文字列以外も対応)
* @deprecated
*/
export default val => {
// 空div 生成
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/scripts/get-drive-file-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as Misskey from 'misskey-js';
import { defineAsyncComponent } from 'vue';
import { i18n } from '@/i18n.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { copyText } from '@/scripts/tms/clipboard.js';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { MenuItem } from '@/types/menu.js';
Expand Down Expand Up @@ -54,7 +54,7 @@ function toggleSensitive(file: Misskey.entities.DriveFile) {
}

function copyUrl(file: Misskey.entities.DriveFile) {
copyToClipboard(file.url);
copyText(file.url);
os.success();
}

Expand Down Expand Up @@ -131,7 +131,7 @@ export function getDriveFileMenu(file: Misskey.entities.DriveFile, folder?: Miss
icon: 'ti ti-id',
text: i18n.ts.copyFileId,
action: () => {
copyToClipboard(file.id);
copyText(file.id);
},
}]);
}
Expand Down
Loading