Add dropdown for advanced search
This commit is contained in:
parent
999722f262
commit
5b686d161a
|
@ -2,7 +2,7 @@
|
||||||
<button
|
<button
|
||||||
v-if="!link"
|
v-if="!link"
|
||||||
class="bghgjjyj _button"
|
class="bghgjjyj _button"
|
||||||
:class="{ inline, primary, gradate, danger, rounded, full, mini }"
|
:class="{ inline, primary, gradate, danger, rounded, full, mini, chip }"
|
||||||
:type="type"
|
:type="type"
|
||||||
@click="emit('click', $event)"
|
@click="emit('click', $event)"
|
||||||
@mousedown="onMousedown"
|
@mousedown="onMousedown"
|
||||||
|
@ -41,7 +41,8 @@ const props = defineProps<{
|
||||||
wait?: boolean;
|
wait?: boolean;
|
||||||
danger?: boolean;
|
danger?: boolean;
|
||||||
full?: boolean;
|
full?: boolean;
|
||||||
mini: boolean;
|
mini?: boolean;
|
||||||
|
chip?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
|
@ -198,6 +199,13 @@ function onMousedown(evt: MouseEvent): void {
|
||||||
border-radius: 100px;
|
border-radius: 100px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.chip {
|
||||||
|
padding: 4px 12px;
|
||||||
|
font-size: max(12px, 0.9em);
|
||||||
|
min-width: unset;
|
||||||
|
border-radius: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
&:disabled {
|
&:disabled {
|
||||||
opacity: 0.7;
|
opacity: 0.7;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
<MkModal
|
<MkModal
|
||||||
ref="modal"
|
ref="modal"
|
||||||
:prefer-type="'dialog'"
|
:prefer-type="'dialog'"
|
||||||
:z-priority="'high'"
|
|
||||||
@click="done(true)"
|
@click="done(true)"
|
||||||
@closed="emit('closed')"
|
@closed="emit('closed')"
|
||||||
>
|
>
|
||||||
|
@ -56,6 +55,7 @@
|
||||||
</header>
|
</header>
|
||||||
<div v-if="text" :class="$style.text"><Mfm :text="text" /></div>
|
<div v-if="text" :class="$style.text"><Mfm :text="text" /></div>
|
||||||
<MkInput
|
<MkInput
|
||||||
|
ref="inputEl"
|
||||||
v-if="input && input.type !== 'paragraph'"
|
v-if="input && input.type !== 'paragraph'"
|
||||||
v-model="inputValue"
|
v-model="inputValue"
|
||||||
autofocus
|
autofocus
|
||||||
|
@ -66,6 +66,15 @@
|
||||||
<template v-if="input.type === 'password'" #prefix
|
<template v-if="input.type === 'password'" #prefix
|
||||||
><i class="ph-password ph-bold ph-lg"></i
|
><i class="ph-password ph-bold ph-lg"></i
|
||||||
></template>
|
></template>
|
||||||
|
<template v-if="input.type === 'search'" #suffix>
|
||||||
|
<button
|
||||||
|
class="_buttonIcon"
|
||||||
|
@click.stop="openSearchFilters"
|
||||||
|
v-tooltip.noDelay="i18n.ts.filter"
|
||||||
|
>
|
||||||
|
<i class="ph-funnel ph-bold"></i>
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
</MkInput>
|
</MkInput>
|
||||||
<MkTextarea
|
<MkTextarea
|
||||||
v-if="input && input.type === 'paragraph'"
|
v-if="input && input.type === 'paragraph'"
|
||||||
|
@ -95,6 +104,7 @@
|
||||||
</optgroup>
|
</optgroup>
|
||||||
</template>
|
</template>
|
||||||
</MkSelect>
|
</MkSelect>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-if="(showOkButton || showCancelButton) && !actions"
|
v-if="(showOkButton || showCancelButton) && !actions"
|
||||||
:class="$style.buttons"
|
:class="$style.buttons"
|
||||||
|
@ -156,13 +166,15 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { onBeforeUnmount, onMounted, ref, shallowRef } from "vue";
|
import { nextTick, onBeforeUnmount, onMounted, ref, shallowRef } from "vue";
|
||||||
import MkModal from "@/components/MkModal.vue";
|
import MkModal from "@/components/MkModal.vue";
|
||||||
import MkButton from "@/components/MkButton.vue";
|
import MkButton from "@/components/MkButton.vue";
|
||||||
import MkInput from "@/components/form/input.vue";
|
import MkInput from "@/components/form/input.vue";
|
||||||
import MkTextarea from "@/components/form/textarea.vue";
|
import MkTextarea from "@/components/form/textarea.vue";
|
||||||
import MkSelect from "@/components/form/select.vue";
|
import MkSelect from "@/components/form/select.vue";
|
||||||
|
import * as os from "@/os";
|
||||||
import { i18n } from "@/i18n";
|
import { i18n } from "@/i18n";
|
||||||
|
import * as Acct from "calckey-js/built/acct";
|
||||||
|
|
||||||
type Input = {
|
type Input = {
|
||||||
type: HTMLInputElement["type"];
|
type: HTMLInputElement["type"];
|
||||||
|
@ -193,7 +205,8 @@ const props = withDefaults(
|
||||||
| "warning"
|
| "warning"
|
||||||
| "info"
|
| "info"
|
||||||
| "question"
|
| "question"
|
||||||
| "waiting";
|
| "waiting"
|
||||||
|
| "search";
|
||||||
title: string;
|
title: string;
|
||||||
text?: string;
|
text?: string;
|
||||||
input?: Input;
|
input?: Input;
|
||||||
|
@ -229,9 +242,11 @@ const emit = defineEmits<{
|
||||||
|
|
||||||
const modal = shallowRef<InstanceType<typeof MkModal>>();
|
const modal = shallowRef<InstanceType<typeof MkModal>>();
|
||||||
|
|
||||||
const inputValue = ref(props.input?.default || null);
|
const inputValue = ref(props.input?.default || "");
|
||||||
const selectedValue = ref(props.select?.default || null);
|
const selectedValue = ref(props.select?.default || null);
|
||||||
|
|
||||||
|
const inputEl = ref<typeof MkInput>();
|
||||||
|
|
||||||
function done(canceled: boolean, result?) {
|
function done(canceled: boolean, result?) {
|
||||||
emit("done", { canceled, result });
|
emit("done", { canceled, result });
|
||||||
modal.value?.close();
|
modal.value?.close();
|
||||||
|
@ -268,6 +283,99 @@ function onInputKeydown(evt: KeyboardEvent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function openSearchFilters(ev) {
|
||||||
|
await os.popupMenu([
|
||||||
|
{
|
||||||
|
icon: "ph-user ph-bold ph-lg",
|
||||||
|
text: "From user",
|
||||||
|
action: () => {
|
||||||
|
os.selectUser().then((user) => {
|
||||||
|
inputValue.value += " from:@" + Acct.toString(user);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "ph-file ph-bold ph-lg",
|
||||||
|
text: "With file",
|
||||||
|
action: () => {
|
||||||
|
os.select({
|
||||||
|
title: "Has file",
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
text: "Image",
|
||||||
|
value: "image",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "Video",
|
||||||
|
value: "video",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "Audio",
|
||||||
|
value: "audio",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "File",
|
||||||
|
value: "file",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}).then((res) => {
|
||||||
|
if (res.canceled) return;
|
||||||
|
inputValue.value += " has:" + res.result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "ph-link ph-bold ph-lg",
|
||||||
|
text: "From domain",
|
||||||
|
action: () => {
|
||||||
|
inputValue.value += " domain:";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "ph-calendar-blank ph-bold ph-lg",
|
||||||
|
text: "Posts before",
|
||||||
|
action: () => {
|
||||||
|
os.inputDate({
|
||||||
|
title: "Posts before"
|
||||||
|
}).then((res) => {
|
||||||
|
inputEl.value.focus();
|
||||||
|
if (res.canceled) return;
|
||||||
|
inputValue.value += " before:" + res.result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "ph-calendar-blank ph-bold ph-lg",
|
||||||
|
text: "Posts after",
|
||||||
|
action: () => {
|
||||||
|
os.inputDate({
|
||||||
|
title: "Posts after"
|
||||||
|
}).then((res) => {
|
||||||
|
inputEl.value.focus();
|
||||||
|
if (res.canceled) return;
|
||||||
|
inputValue.value += " after:" + res.result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "ph-eye ph-bold ph-lg",
|
||||||
|
text: "Following only",
|
||||||
|
action: () => {
|
||||||
|
inputValue.value += " filter:following ";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "ph-users-three ph-bold ph-lg",
|
||||||
|
text: "Followers only",
|
||||||
|
action: () => {
|
||||||
|
inputValue.value += " filter:followers ";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
], ev.target, { noReturnFocus: true });
|
||||||
|
inputEl.value.focus();
|
||||||
|
inputEl.value.selectRange(inputValue.value.length, inputValue.value.length); // cursor at end
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
document.addEventListener("keydown", onKeydown);
|
document.addEventListener("keydown", onKeydown);
|
||||||
});
|
});
|
||||||
|
@ -333,6 +441,10 @@ onBeforeUnmount(() => {
|
||||||
margin: 16px 0 0 0;
|
margin: 16px 0 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:deep(input[type="search"]) {
|
||||||
|
width: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
.buttons {
|
.buttons {
|
||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
<template>
|
<template>
|
||||||
<FocusTrap :active="false" ref="focusTrap">
|
<FocusTrap
|
||||||
|
:active="false"
|
||||||
|
ref="focusTrap"
|
||||||
|
:return-focus-on-deactivate="!noReturnFocus"
|
||||||
|
>
|
||||||
<div tabindex="-1">
|
<div tabindex="-1">
|
||||||
<div
|
<div
|
||||||
ref="itemsEl"
|
ref="itemsEl"
|
||||||
|
@ -205,6 +209,7 @@ const props = defineProps<{
|
||||||
align?: "center" | string;
|
align?: "center" | string;
|
||||||
width?: number;
|
width?: number;
|
||||||
maxHeight?: number;
|
maxHeight?: number;
|
||||||
|
noReturnFocus?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
|
|
|
@ -18,7 +18,10 @@
|
||||||
@enter="emit('opening')"
|
@enter="emit('opening')"
|
||||||
@after-enter="onOpened"
|
@after-enter="onOpened"
|
||||||
>
|
>
|
||||||
<FocusTrap v-model:active="isActive">
|
<FocusTrap
|
||||||
|
v-model:active="isActive"
|
||||||
|
:return-focus-on-deactivate="!noReturnFocus"
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
v-show="manualShowing != null ? manualShowing : showing"
|
v-show="manualShowing != null ? manualShowing : showing"
|
||||||
v-hotkey.global="keymap"
|
v-hotkey.global="keymap"
|
||||||
|
@ -102,6 +105,7 @@ const props = withDefaults(
|
||||||
zPriority?: "low" | "middle" | "high";
|
zPriority?: "low" | "middle" | "high";
|
||||||
noOverlap?: boolean;
|
noOverlap?: boolean;
|
||||||
transparentBg?: boolean;
|
transparentBg?: boolean;
|
||||||
|
noReturnFocus?: boolean;
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
manualShowing: null,
|
manualShowing: null,
|
||||||
|
@ -111,6 +115,7 @@ const props = withDefaults(
|
||||||
zPriority: "low",
|
zPriority: "low",
|
||||||
noOverlap: true,
|
noOverlap: true,
|
||||||
transparentBg: false,
|
transparentBg: false,
|
||||||
|
noReturnFocus: false,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -189,12 +194,16 @@ function close(ev, opts: { useSendAnimation?: boolean } = {}) {
|
||||||
if (props.src) props.src.style.pointerEvents = "auto";
|
if (props.src) props.src.style.pointerEvents = "auto";
|
||||||
showing = false;
|
showing = false;
|
||||||
emit("close");
|
emit("close");
|
||||||
|
if (!noReturnFocus) {
|
||||||
focusedElement.focus();
|
focusedElement.focus();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function onBgClick() {
|
function onBgClick() {
|
||||||
if (contentClicking) return;
|
if (contentClicking) return;
|
||||||
|
if (!noReturnFocus) {
|
||||||
focusedElement.focus();
|
focusedElement.focus();
|
||||||
|
}
|
||||||
emit("click");
|
emit("click");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
:as-drawer="type === 'drawer'"
|
:as-drawer="type === 'drawer'"
|
||||||
class="sfhdhdhq"
|
class="sfhdhdhq"
|
||||||
:class="{ drawer: type === 'drawer' }"
|
:class="{ drawer: type === 'drawer' }"
|
||||||
|
:no-return-focus="noReturnFocus"
|
||||||
@close="modal.close()"
|
@close="modal.close()"
|
||||||
/>
|
/>
|
||||||
</MkModal>
|
</MkModal>
|
||||||
|
@ -35,6 +36,7 @@ defineProps<{
|
||||||
width?: number;
|
width?: number;
|
||||||
viaKeyboard?: boolean;
|
viaKeyboard?: boolean;
|
||||||
src?: any;
|
src?: any;
|
||||||
|
noReturnFocus?;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
|
|
|
@ -108,6 +108,7 @@ const suffixEl = ref<HTMLElement>();
|
||||||
const height = props.small ? 36 : props.large ? 40 : 38;
|
const height = props.small ? 36 : props.large ? 40 : 38;
|
||||||
|
|
||||||
const focus = () => inputEl.value.focus();
|
const focus = () => inputEl.value.focus();
|
||||||
|
const selectRange = (start, end) => inputEl.value.setSelectionRange(start, end);
|
||||||
const onInput = (ev: KeyboardEvent) => {
|
const onInput = (ev: KeyboardEvent) => {
|
||||||
changed.value = true;
|
changed.value = true;
|
||||||
emit("change", ev);
|
emit("change", ev);
|
||||||
|
@ -178,6 +179,11 @@ onMounted(() => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
focus,
|
||||||
|
selectRange
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
@ -255,6 +261,9 @@ onMounted(() => {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
> :deep(button) {
|
||||||
|
pointer-events: all;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
> .prefix {
|
> .prefix {
|
||||||
|
|
|
@ -346,7 +346,7 @@ export function yesno(props: {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function inputText(props: {
|
export function inputText(props: {
|
||||||
type?: "text" | "email" | "password" | "url";
|
type?: "text" | "email" | "password" | "url" | "search";
|
||||||
title?: string | null;
|
title?: string | null;
|
||||||
text?: string | null;
|
text?: string | null;
|
||||||
placeholder?: string | null;
|
placeholder?: string | null;
|
||||||
|
@ -366,6 +366,7 @@ export function inputText(props: {
|
||||||
delay: 1000,
|
delay: 1000,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
|
type: props.type,
|
||||||
title: props.title,
|
title: props.title,
|
||||||
text: props.text,
|
text: props.text,
|
||||||
input: {
|
input: {
|
||||||
|
@ -837,6 +838,7 @@ export function popupMenu(
|
||||||
align?: string;
|
align?: string;
|
||||||
width?: number;
|
width?: number;
|
||||||
viaKeyboard?: boolean;
|
viaKeyboard?: boolean;
|
||||||
|
noReturnFocus?: boolean;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -853,6 +855,7 @@ export function popupMenu(
|
||||||
width: options?.width,
|
width: options?.width,
|
||||||
align: options?.align,
|
align: options?.align,
|
||||||
viaKeyboard: options?.viaKeyboard,
|
viaKeyboard: options?.viaKeyboard,
|
||||||
|
noReturnFocus: options?.noReturnFocus,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
closed: () => {
|
closed: () => {
|
||||||
|
|
|
@ -18,9 +18,9 @@ export async function search() {
|
||||||
// const searchFiltersAvailable = instance.searchFilters;
|
// const searchFiltersAvailable = instance.searchFilters;
|
||||||
|
|
||||||
const { canceled, result: query } = await os.inputText({
|
const { canceled, result: query } = await os.inputText({
|
||||||
|
type: "search",
|
||||||
title: i18n.ts.search,
|
title: i18n.ts.search,
|
||||||
placeholder: i18n.ts.searchPlaceholder,
|
placeholder: i18n.ts.searchPlaceholder,
|
||||||
// text: searchOptions,
|
|
||||||
});
|
});
|
||||||
if (canceled || query == null || query === "") return;
|
if (canceled || query == null || query === "") return;
|
||||||
|
|
||||||
|
|
|
@ -482,6 +482,17 @@ hr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
._flexList {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: .2em;
|
||||||
|
width: min-content;
|
||||||
|
min-width: 100%;
|
||||||
|
&._center {
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
._formLinks {
|
._formLinks {
|
||||||
> *:not(:last-child) {
|
> *:not(:last-child) {
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
|
|
Loading…
Reference in New Issue