From 293f8c3d8108f05fb10924512fca8c0c716d0898 Mon Sep 17 00:00:00 2001 From: Laila Los <44241786+ElectronicBlueberry@users.noreply.github.com> Date: Thu, 18 Jan 2024 16:01:38 +0100 Subject: [PATCH] replace multiselect with custom component --- client/package.json | 1 + .../History/Content/ContentItem.vue | 1 + .../TagsMultiselect/HeadlessMultiselect.vue | 371 ++++++++++++++++++ .../TagsMultiselect/StatelessTags.vue | 113 ++---- client/src/stores/userTagsStore.ts | 2 +- client/yarn.lock | 5 + package.json | 1 - 7 files changed, 411 insertions(+), 83 deletions(-) create mode 100644 client/src/components/TagsMultiselect/HeadlessMultiselect.vue diff --git a/client/package.json b/client/package.json index d3d06ff51b73..a3a45a7fc868 100644 --- a/client/package.json +++ b/client/package.json @@ -105,6 +105,7 @@ "vue-router": "^3.6.5", "vue-rx": "^6.2.0", "vue-virtual-scroll-list": "^2.3.5", + "vue2-teleport": "^1.0.1", "vuedraggable": "^2.24.3", "vuex": "^3.6.2", "vuex-cache": "^3.4.0", diff --git a/client/src/components/History/Content/ContentItem.vue b/client/src/components/History/Content/ContentItem.vue index aeae2c6bff83..ddc2b2491a71 100644 --- a/client/src/components/History/Content/ContentItem.vue +++ b/client/src/components/History/Content/ContentItem.vue @@ -304,6 +304,7 @@ export default { .content-item { cursor: default; + container-type: inline-size; .name { word-break: break-all; diff --git a/client/src/components/TagsMultiselect/HeadlessMultiselect.vue b/client/src/components/TagsMultiselect/HeadlessMultiselect.vue new file mode 100644 index 000000000000..da8652f42fbe --- /dev/null +++ b/client/src/components/TagsMultiselect/HeadlessMultiselect.vue @@ -0,0 +1,371 @@ + + + + + diff --git a/client/src/components/TagsMultiselect/StatelessTags.vue b/client/src/components/TagsMultiselect/StatelessTags.vue index 0e1419e9258a..61bb6f5ebe18 100644 --- a/client/src/components/TagsMultiselect/StatelessTags.vue +++ b/client/src/components/TagsMultiselect/StatelessTags.vue @@ -3,15 +3,16 @@ import { library } from "@fortawesome/fontawesome-svg-core"; import { faCheck, faPlus, faTags, faTimes } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome"; import { BButton } from "bootstrap-vue"; +import { storeToRefs } from "pinia"; import type { Ref } from "vue"; import { computed, nextTick, ref } from "vue"; import Multiselect from "vue-multiselect"; import { useToast } from "@/composables/toast"; -import { useMultiselect } from "@/composables/useMultiselect"; import { useUid } from "@/composables/utils/uid"; import { useUserTagsStore } from "@/stores/userTagsStore"; +import HeadlessMultiselect from "./HeadlessMultiselect.vue"; import Tag from "./Tag.vue"; interface StatelessTagsProps { @@ -39,14 +40,15 @@ const emit = defineEmits<{ library.add(faTags, faCheck, faTimes, faPlus); -const { userTags, addLocalTag } = useUserTagsStore(); +const userTagsStore = useUserTagsStore(); +const { userTags } = storeToRefs(userTagsStore); const { warning } = useToast(); function onAddTag(tag: string) { const newTag = tag.trim(); if (isValid(newTag)) { - addLocalTag(newTag); + userTagsStore.addLocalTag(newTag); emit("input", [...props.value, newTag]); } else { warning(`"${newTag}" is not a valid tag.`, "Invalid Tag"); @@ -64,7 +66,7 @@ function onDelete(tag: string) { emit("input", val); } -const { editing, ariaExpanded, onOpen, onClose } = useMultiselect(); +const editing = ref(false); const multiselectElement: Ref = ref(null); @@ -97,12 +99,8 @@ const slicedTags = computed(() => { const invalidTagRegex = /([.:\s][.:\s])|(^[.:])|([.:]$)|(^[\s]*$)/; -function isValid(tag: string | { label: string }) { - if (typeof tag === "string") { - return !tag.match(invalidTagRegex); - } else { - return !tag.label.match(invalidTagRegex); - } +function isValid(tag: string) { + return !tag.match(invalidTagRegex); } function onTagClicked(tag: string) { @@ -112,78 +110,31 @@ function onTagClicked(tag: string) {