Skip to content

Commit

Permalink
chore(ui): use useTemplateRef instead of plain ref - WF-163
Browse files Browse the repository at this point in the history
  • Loading branch information
madeindjs committed Dec 27, 2024
1 parent e6a4cfe commit 89a0d70
Show file tree
Hide file tree
Showing 29 changed files with 130 additions and 85 deletions.
12 changes: 10 additions & 2 deletions src/ui/src/builder/BuilderInstanceTracker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
</div>
</template>
<script setup lang="ts">
import { nextTick, onMounted, onUnmounted, Ref, ref, toRefs } from "vue";
import {
nextTick,
onMounted,
onUnmounted,
Ref,
ref,
toRefs,
useTemplateRef,
} from "vue";
const REFRESH_INTERVAL_MS = 200;
Expand Down Expand Up @@ -33,7 +41,7 @@ type RootStyle = {
const rootStyle: Ref<RootStyle> = ref(null);
const timerId = ref(0);
const rootEl: Ref<HTMLElement> = ref(null);
const rootEl = useTemplateRef("rootEl");
const MIN_TOP_PX = 36;
const trackElement = (el: HTMLElement) => {
Expand Down
10 changes: 6 additions & 4 deletions src/ui/src/builder/settings/BuilderFieldsAlign.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<div v-if="mode == 'pick' || mode == 'css'" class="main">
<div v-if="mode == 'pick'" class="pickerContainer">
<BuilderSelect
ref="pickerEl"
:model-value="subMode"
:options="selectOptions"
@update:model-value="handleInputSelect"
Expand Down Expand Up @@ -41,6 +42,7 @@ import {
Ref,
ref,
toRefs,
useTemplateRef,
} from "vue";
import { Component } from "@/writerTypes";
import { useComponentActions } from "../useComponentActions";
Expand All @@ -57,9 +59,9 @@ const wf = inject(injectionKeys.core);
const ssbm = inject(injectionKeys.builderManager);
const { setContentValue } = useComponentActions(wf, ssbm);
const rootEl: Ref<HTMLElement> = ref(null);
const pickerEl: Ref<HTMLInputElement> = ref(null);
const freehandInputEl: Ref<HTMLInputElement> = ref(null);
const rootEl = useTemplateRef("rootEl");
const pickerEl = useTemplateRef("pickerEl");
const freehandInputEl = useTemplateRef("freehandInputEl");
enum SubMode {
hleft = "start",
Expand Down Expand Up @@ -129,7 +131,7 @@ const verticalSubmodes: SubModes = [
},
];
const focusEls: Record<Mode, Ref<HTMLInputElement>> = {
const focusEls = {
pick: pickerEl,
css: freehandInputEl,
default: null,
Expand Down
9 changes: 5 additions & 4 deletions src/ui/src/builder/settings/BuilderFieldsColor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
Ref,
ref,
toRefs,
useTemplateRef,
} from "vue";
import { Component } from "@/writerTypes";
import { useComponentActions } from "../useComponentActions";
Expand All @@ -55,11 +56,11 @@ const wf = inject(injectionKeys.core);
const ssbm = inject(injectionKeys.builderManager);
const { setContentValue } = useComponentActions(wf, ssbm);
const rootEl: Ref<HTMLElement> = ref(null);
const pickerEl: Ref<HTMLInputElement> = ref(null);
const freehandInputEl: Ref<HTMLInputElement> = ref(null);
const rootEl = useTemplateRef("rootEl");
const pickerEl = useTemplateRef("pickerEl");
const freehandInputEl = useTemplateRef("freehandInputEl");
const focusEls: Record<Mode, Ref<HTMLInputElement>> = {
const focusEls = {
pick: pickerEl,
css: freehandInputEl,
default: null,
Expand Down
5 changes: 3 additions & 2 deletions src/ui/src/builder/settings/BuilderFieldsKeyValue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import {
onMounted,
ref,
toRefs,
useTemplateRef,
watch,
} from "vue";
import injectionKeys from "../../injectionKeys";
Expand All @@ -92,8 +93,8 @@ const props = defineProps({
const { componentId, fieldKey } = toRefs(props);
const component = computed(() => wf.getComponentById(componentId.value));
const rootEl: Ref<HTMLElement> = ref(null);
const assistedKeyEl: Ref<HTMLInputElement> = ref(null);
const rootEl = useTemplateRef("rootEl");
const assistedKeyEl = useTemplateRef("assistedKeyEl");
type Mode = "assisted" | "freehand";
const mode: Ref<Mode> = ref(null);
const assistedEntries: Ref<Record<string, string | number | null>> = ref({});
Expand Down
13 changes: 7 additions & 6 deletions src/ui/src/builder/settings/BuilderFieldsPadding.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<div v-if="mode == 'pick' || mode == 'css'" class="main">
<div v-if="mode == 'pick'" class="pickerContainer">
<BuilderSelect
ref="pickerEl"
:model-value="subMode"
:options="selectOptions"
@update:model-value="handleInputSelect"
Expand Down Expand Up @@ -102,7 +103,6 @@

<script setup lang="ts">
import {
ComponentInstance,
computed,
inject,
nextTick,
Expand All @@ -111,6 +111,7 @@ import {
Ref,
ref,
toRefs,
useTemplateRef,
} from "vue";
import { Component } from "@/writerTypes";
import { useComponentActions } from "../useComponentActions";
Expand All @@ -128,10 +129,10 @@ const wf = inject(injectionKeys.core);
const ssbm = inject(injectionKeys.builderManager);
const { setContentValue } = useComponentActions(wf, ssbm);
const rootEl: Ref<HTMLElement> = ref(null);
const pickerEl: Ref<HTMLInputElement> = ref(null);
const fixedEl = ref<ComponentInstance<typeof WdsTextInput>>(null);
const freehandInputEl: Ref<HTMLInputElement> = ref(null);
const rootEl = useTemplateRef("rootEl");
const pickerEl = useTemplateRef("pickerEl");
const freehandInputEl = useTemplateRef("freehandInputEl");
const fixedEl = useTemplateRef("fixedEl");
enum SubMode {
all_sides = "all_sides",
Expand Down Expand Up @@ -177,7 +178,7 @@ const subModes: Array<{
},
];
const focusEls: Record<Mode, Ref<HTMLInputElement>> = {
const focusEls = {
pick: pickerEl,
css: freehandInputEl,
default: null,
Expand Down
17 changes: 9 additions & 8 deletions src/ui/src/builder/settings/BuilderFieldsShadow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import {
Ref,
ref,
toRefs,
useTemplateRef,
} from "vue";
import { Component } from "@/writerTypes";
import { useComponentActions } from "../useComponentActions";
Expand All @@ -124,15 +125,15 @@ const wf = inject(injectionKeys.core);
const ssbm = inject(injectionKeys.builderManager);
const { setContentValue } = useComponentActions(wf, ssbm);
const rootEl: Ref<HTMLElement> = ref(null);
const freehandInputEl: Ref<HTMLInputElement> = ref(null);
const paramOffsetXEl: Ref<HTMLInputElement> = ref(null);
const paramOffsetYEl: Ref<HTMLInputElement> = ref(null);
const paramBlurRadiusEl: Ref<HTMLInputElement> = ref(null);
const paramSpreadRadiusEl: Ref<HTMLInputElement> = ref(null);
const paramColorEl: Ref<HTMLInputElement> = ref(null);
const rootEl = useTemplateRef("rootEl");
const freehandInputEl = useTemplateRef("freehandInputEl");
const paramOffsetXEl = useTemplateRef("paramOffsetXEl");
const paramOffsetYEl = useTemplateRef("paramOffsetYEl");
const paramBlurRadiusEl = useTemplateRef("paramBlurRadiusEl");
const paramSpreadRadiusEl = useTemplateRef("paramSpreadRadiusEl");
const paramColorEl = useTemplateRef("paramColorEl");
const focusEls: Record<Mode, Ref<HTMLInputElement>> = {
const focusEls = {
pick: paramOffsetXEl,
css: freehandInputEl,
default: null,
Expand Down
13 changes: 7 additions & 6 deletions src/ui/src/builder/settings/BuilderFieldsWidth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<div v-if="mode == 'pick' || mode == 'css'" class="main">
<div v-if="mode == 'pick'" class="pickerContainer">
<BuilderSelect
ref="pickerEl"
:model-value="subMode"
:options="selectOptions"
@update:model-value="handleInputSelect"
Expand Down Expand Up @@ -41,7 +42,6 @@

<script setup lang="ts">
import {
ComponentInstance,
computed,
inject,
nextTick,
Expand All @@ -50,6 +50,7 @@ import {
Ref,
ref,
toRefs,
useTemplateRef,
} from "vue";
import { Component } from "@/writerTypes";
import { useComponentActions } from "../useComponentActions";
Expand All @@ -67,10 +68,10 @@ const wf = inject(injectionKeys.core);
const ssbm = inject(injectionKeys.builderManager);
const { setContentValue } = useComponentActions(wf, ssbm);
const rootEl: Ref<HTMLElement> = ref(null);
const pickerEl: Ref<HTMLInputElement> = ref(null);
const fixedEl = ref<ComponentInstance<typeof WdsTextInput>>(null);
const freehandInputEl: Ref<HTMLInputElement> = ref(null);
const rootEl = useTemplateRef("rootEl");
const pickerEl = useTemplateRef("pickerEl");
const freehandInputEl = useTemplateRef("freehandInputEl");
const fixedEl = useTemplateRef("fixedEl");
enum SubMode {
fixed = "fixed",
Expand Down Expand Up @@ -105,7 +106,7 @@ const subModes: Array<{
},
];
const focusEls: Record<Mode, Ref<HTMLInputElement>> = {
const focusEls = {
pick: pickerEl,
css: freehandInputEl,
default: null,
Expand Down
19 changes: 14 additions & 5 deletions src/ui/src/components/core/base/BaseSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,16 @@
</template>

<script setup lang="ts">
import { computed, nextTick, PropType, Ref, ref, toRefs, watch } from "vue";
import {
computed,
nextTick,
PropType,
Ref,
ref,
toRefs,
useTemplateRef,
watch,
} from "vue";
const emit = defineEmits(["change"]);
Expand Down Expand Up @@ -121,10 +130,10 @@ const activeValue = computed<string[]>(() =>
);
const LIST_MAX_HEIGHT_PX = 200;
const rootEl: Ref<HTMLElement | null> = ref(null);
const inputEl: Ref<HTMLElement | null> = ref(null);
const selectedOptionsEl: Ref<HTMLElement | null> = ref(null);
const listEl: Ref<HTMLElement | null> = ref(null);
const rootEl = useTemplateRef("rootEl");
const inputEl = useTemplateRef("inputEl");
const selectedOptionsEl = useTemplateRef("selectedOptionsEl");
const listEl = useTemplateRef("listEl");
const activeText: Ref<string> = ref("");
const highlightedOffset: Ref<number | null> = ref(null);
const selectedOptions: Ref<string[]> = ref([]);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/src/components/core/content/CoreAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ export default {
};
</script>
<script setup lang="ts">
import { CSSProperties, Ref, computed, inject, ref } from "vue";
import { CSSProperties, computed, inject, useTemplateRef } from "vue";
import injectionKeys from "@/injectionKeys";
const rootEl: Ref<HTMLElement> = ref(null);
const rootEl = useTemplateRef("rootEl");
const fields = inject(injectionKeys.evaluatedFields);
const componentId = inject(injectionKeys.componentId);
const wf = inject(injectionKeys.core);
Expand Down
7 changes: 4 additions & 3 deletions src/ui/src/components/core/content/CoreChatbot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,16 @@ import {
ref,
computed,
ComputedRef,
useTemplateRef,
} from "vue";
import injectionKeys from "@/injectionKeys";
import CoreChatbotSentMessageIcon from "./CoreChatBot/CoreChatbotSentMessageIcon.vue";
import CoreChatbotMessage from "./CoreChatBot/CoreChatbotMessage.vue";
import type { Message } from "./CoreChatBot/CoreChatbotMessage.vue";
const rootEl: Ref<HTMLElement> = ref(null);
const messageAreaEl: Ref<HTMLElement> = ref(null);
const messagesEl: Ref<HTMLElement> = ref(null);
const rootEl = useTemplateRef("rootEl");
const messageAreaEl = useTemplateRef("messageAreaEl");
const messagesEl = useTemplateRef("messagesEl");
const messageIndexLoading: Ref<number | undefined> = ref(undefined);
const fields = inject(injectionKeys.evaluatedFields);
const files: Ref<File[]> = shallowRef([]);
Expand Down
8 changes: 4 additions & 4 deletions src/ui/src/components/core/content/CoreDataframeLegacy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
</template>

<script lang="ts">
import { Ref, computed, inject, ref } from "vue";
import { Ref, computed, inject, ref, useTemplateRef } from "vue";
import { FieldCategory, FieldType } from "@/writerTypes";
import {
cssClasses,
Expand Down Expand Up @@ -245,9 +245,9 @@ type OrderSetting = {
};
const fields = inject(injectionKeys.evaluatedFields);
const rootEl: Ref<HTMLElement> = ref();
const toolsEl: Ref<HTMLElement> = ref();
const gridContainerEl: Ref<HTMLElement> = ref();
const rootEl = useTemplateRef("rootEl");
const toolsEl = useTemplateRef("toolsEl");
const gridContainerEl = useTemplateRef("gridContainerEl");
let baseTable: aq.internal.ColumnTable = null;
const table: Ref<aq.internal.ColumnTable> = ref(null);
const tableIndex = ref([]);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/src/components/core/content/CoreImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ export default {
</script>

<script setup lang="ts">
import { Ref, computed, inject, ref } from "vue";
import { computed, inject, useTemplateRef } from "vue";
import injectionKeys from "@/injectionKeys";
const rootEl: Ref<HTMLElement> = ref(null);
const rootEl = useTemplateRef("rootEl");
const wf = inject(injectionKeys.core);
const fields = inject(injectionKeys.evaluatedFields);
const componentId = inject(injectionKeys.componentId);
Expand Down
6 changes: 3 additions & 3 deletions src/ui/src/components/core/content/CorePlotlyGraph.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ export default {
</script>

<script setup lang="ts">
import { computed, inject, onMounted, Ref, ref, watch } from "vue";
import { computed, inject, onMounted, useTemplateRef, watch } from "vue";
import injectionKeys from "@/injectionKeys";
const rootEl: Ref<HTMLElement> = ref(null);
const chartTargetEl: Ref<HTMLElement> = ref(null);
const rootEl = useTemplateRef("rootEl");
const chartTargetEl = useTemplateRef("chartTargetEl");
const fields = inject(injectionKeys.evaluatedFields);
const spec = computed(() => fields.spec.value);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/src/components/core/content/CoreTags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default {
};
</script>
<script setup lang="ts">
import { Ref, computed, inject, ref } from "vue";
import { computed, inject, useTemplateRef } from "vue";
import injectionKeys from "@/injectionKeys";
import chroma from "chroma-js";
Expand All @@ -101,7 +101,7 @@ const COLOR_STEPS = [
{ h: 69, s: 0, l: 25 },
{ h: 70, s: 0, l: 29 },
];
const rootEl: Ref<HTMLElement> = ref(null);
const rootEl = useTemplateRef("rootEl");
const fields = inject(injectionKeys.evaluatedFields);
const componentId = inject(injectionKeys.componentId);
const wf = inject(injectionKeys.core);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/src/components/core/content/CoreText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ export default {
};
</script>
<script setup lang="ts">
import { Ref, computed, inject, ref } from "vue";
import { computed, inject, useTemplateRef } from "vue";
import injectionKeys from "@/injectionKeys";
import BaseEmptiness from "../base/BaseEmptiness.vue";
import BaseMarkdown from "../base/BaseMarkdown.vue";
const rootEl: Ref<HTMLElement> = ref(null);
const rootEl = useTemplateRef("rootEl");
const fields = inject(injectionKeys.evaluatedFields);
const componentId = inject(injectionKeys.componentId);
const wf = inject(injectionKeys.core);
Expand Down
6 changes: 3 additions & 3 deletions src/ui/src/components/core/content/CoreVegaLiteChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export default {
</script>

<script setup lang="ts">
import { inject, onMounted, Ref, ref, watch } from "vue";
import { inject, onMounted, useTemplateRef, watch } from "vue";
import injectionKeys from "@/injectionKeys";
const rootEl: Ref<HTMLElement> = ref(null);
const chartTargetEl: Ref<HTMLElement> = ref(null);
const rootEl = useTemplateRef("rootEl");
const chartTargetEl = useTemplateRef("chartTargetEl");
const fields = inject(injectionKeys.evaluatedFields);
const renderChart = async () => {
Expand Down
Loading

0 comments on commit 89a0d70

Please sign in to comment.