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

fix: emoji picker crash #26

Merged
merged 2 commits into from
Mar 29, 2023
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
3 changes: 1 addition & 2 deletions packages/comment-widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@
"./dist/style.css": "./dist/style.css"
},
"dependencies": {
"@emoji-mart/data": "^1.1.2",
"@halo-dev/api-client": "^2.3.0",
"@halo-dev/components": "^1.2.0",
"@vueuse/components": "8.9.4",
"@vueuse/core": "8.9.4",
"axios": "^0.27.2",
"emoji-mart": "^5.5.2",
"emoji-mart-vue-fast": "^12.0.1",
"lodash.clonedeep": "^4.5.0",
"qs": "^6.11.0",
"uuid": "^9.0.0"
Expand Down
43 changes: 15 additions & 28 deletions packages/comment-widget/src/components/Form.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<script lang="ts" setup>
import { VButton, VAvatar } from "@halo-dev/components";
import LoginModal from "./LoginModal.vue";
import data from "@emoji-mart/data";
import i18n from "@emoji-mart/data/i18n/zh.json";
import MdiStickerEmoji from "~icons/mdi/sticker-emoji";
import MdiSendCircleOutline from "~icons/mdi/send-circle-outline";
import type {
Expand All @@ -13,11 +11,14 @@ import type {
User,
} from "@halo-dev/api-client";
// @ts-ignore
import { Picker } from "emoji-mart";
import { computed, inject, ref, watchEffect, type Ref } from "vue";
import { Picker, EmojiIndex } from "emoji-mart-vue-fast/src";
import data from "emoji-mart-vue-fast/data/all.json";
import "emoji-mart-vue-fast/css/emoji-mart.css";
import { inject, ref, watchEffect, type Ref } from "vue";
import { apiClient } from "@/utils/api-client";
import { useLocalStorage, useMagicKeys } from "@vueuse/core";
import axios from "axios";
import { onClickOutside } from "@vueuse/core";

interface CustomAccount {
displayName: string;
Expand All @@ -44,7 +45,6 @@ const currentUser = inject<Ref<User | undefined>>("currentUser");
const kind = inject<string>("kind");
const name = inject<string>("name");
const group = inject<string>("group");
const colorScheme = inject<string>("colorScheme");
const allowAnonymousComments = inject<Ref<boolean | undefined>>(
"allowAnonymousComments"
);
Expand Down Expand Up @@ -193,36 +193,19 @@ const handleLogout = async () => {
};

// Emoji picker
const getColorScheme = computed(() => {
if (colorScheme === "system") {
return window.matchMedia("(prefers-color-scheme: dark)").matches
? "dark"
: "light";
}
return colorScheme;
});
let emojiIndex = new EmojiIndex(data);

const emojiPickerRef = ref<HTMLElement | null>(null);
const contentInputRef = ref();
const emojiPickerVisible = ref(false);

const emojiPicker = new Picker({
data: data,
theme: getColorScheme.value,
autoFocus: true,
i18n: i18n,
onEmojiSelect: onEmojiSelect,
});
const emojiPickerRef = ref(null);

function onEmojiSelect(emoji: { native: string }) {
raw.value += emoji.native;
contentInputRef.value.focus();
}

watchEffect(() => {
if (emojiPickerRef.value) {
emojiPickerRef.value?.appendChild(emojiPicker);
}
onClickOutside(emojiPickerRef, () => {
emojiPickerVisible.value = false;
});

// KeyBoard shortcuts
Expand Down Expand Up @@ -297,7 +280,7 @@ watchEffect(() => {
</template>
</div>
<div class="flex flex-row items-center gap-3">
<div class="relative">
<div ref="emojiPickerRef" class="relative">
<MdiStickerEmoji
class="h-5 w-5 cursor-pointer text-gray-500 transition-all hover:text-gray-900 dark:text-slate-300 dark:hover:text-slate-50"
@click="emojiPickerVisible = !emojiPickerVisible"
Expand All @@ -314,7 +297,11 @@ watchEffect(() => {
v-show="emojiPickerVisible"
class="absolute right-0 z-10 mt-3 transform px-4 sm:px-0"
>
<div ref="emojiPickerRef"></div>
<Picker
:data="emojiIndex"
:native="true"
@select="onEmojiSelect"
/>
</div>
</transition>
</div>
Expand Down
35 changes: 25 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

755 changes: 20 additions & 735 deletions src/main/resources/static/comment-widget.iife.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/resources/static/style.css

Large diffs are not rendered by default.