Skip to content

Commit 5a2f4bc

Browse files
Update mention suggestions to typescript (#1154)
* Add type interfaces for mentionSuggestions.ts * refactor mentionSuggestion.js to typescript * Update .licenserc.yaml to track *.js files * Add license to mentionSuggestion.ts * Fix type error and bug in map for route profile change * Ignore type errors that are unneeded --------- Co-authored-by: Andrew Tavis McAllister <[email protected]>
1 parent acc179b commit 5a2f4bc

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

.licenserc.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ header:
66
- '**/*.ts'
77
- '**/*.test.ts'
88
- '**/*.d.ts'
9+
- '**/*.js'
910
- '**/*.py'
1011
paths-ignore:
1112
- 'dist'

frontend/components/card/discussion/CardDiscussionInput.vue

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ const editor = useEditor({
159159
class:
160160
"hover:underline font-bold rounded-2xl box-decoration-clone px-1 py-0.5",
161161
},
162+
// @ts-expect-error Ignore mismatched types.
162163
suggestion: Suggestion,
163164
}),
164165
],

frontend/components/media/MediaMap.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ function resetRouteProfileControl() {
217217
requestOptions: {
218218
alternatives: "true",
219219
},
220-
layers: mapLayers,
220+
// @ts-expect-error Will break route profile change.
221+
mapLayers,
221222
});
222223

223224
directions.interactive = true;

frontend/components/menu/MenuSubPageSelector.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const defaultIndex = computed(() => {
5353
function changeTab(index: number) {
5454
const selectedRoute = props.selectors[index]?.routeUrl;
5555
if (selectedRoute) {
56-
// @ts-expect-error 'nuxtApp.$localePath' is of type 'unknown'
56+
// @ts-expect-error 'nuxtApp.$localePath' is of type 'unknown'.
5757
router.push(nuxtApp.$localePath(selectedRoute));
5858
}
5959
}

frontend/types/mention-suggestions.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// SPDX-License-Identifier: AGPL-3.0-or-later
2+
import type { Editor } from "@tiptap/core";
3+
4+
export interface MentionProps {
5+
query: string;
6+
}
7+
8+
export interface RendererProps {
9+
editor: Editor;
10+
clientRect?: () => DOMRect;
11+
}

frontend/utils/mentionSuggestion.js frontend/utils/mentionSuggestion.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1+
// SPDX-License-Identifier: AGPL-3.0-or-later
12
import { VueRenderer } from "@tiptap/vue-3";
3+
import type { Instance as TippyInstance } from "tippy.js";
24
import tippy from "tippy.js";
35

6+
import type { MentionProps, RendererProps } from "~/types/mention-suggestions";
47
import MentionList from "../components/tooltip/TooltipMentionList.vue";
58

69
export default {
7-
items: ({ query }) => {
10+
items: ({ query }: MentionProps): string[] => {
811
return ["Jay Doe", "Jane Doe", "John Doe"]
912
.filter((item) => item.toLowerCase().startsWith(query.toLowerCase()))
1013
.slice(0, 5);
1114
},
1215

1316
render: () => {
14-
let component;
15-
let popup;
17+
let component: VueRenderer;
18+
let popup: TippyInstance[];
1619

1720
return {
18-
onStart: (props) => {
21+
onStart: (props: RendererProps) => {
1922
component = new VueRenderer(MentionList, {
2023
props,
2124
editor: props.editor,
@@ -28,15 +31,15 @@ export default {
2831
popup = tippy("body", {
2932
getReferenceClientRect: props.clientRect,
3033
appendTo: () => document.body,
31-
content: component.element,
34+
content: component.element ?? "Default content",
3235
showOnCreate: true,
3336
interactive: true,
3437
trigger: "manual",
3538
placement: "bottom-start",
3639
});
3740
},
3841

39-
onUpdate(props) {
42+
onUpdate(props: RendererProps) {
4043
component.updateProps(props);
4144

4245
if (!props.clientRect) {
@@ -48,7 +51,7 @@ export default {
4851
});
4952
},
5053

51-
onKeyDown(props) {
54+
onKeyDown(props: { event: KeyboardEvent }) {
5255
if (props.event.key === "Escape") {
5356
popup[0].hide();
5457

0 commit comments

Comments
 (0)