diff --git a/app/components/app/AppHeaderBody.vue b/app/components/app/AppHeaderBody.vue index 86b9aa3..7b1b063 100644 --- a/app/components/app/AppHeaderBody.vue +++ b/app/components/app/AppHeaderBody.vue @@ -8,11 +8,13 @@ import type { ContentNavigationItem } from "@nuxt/content"; import { getFirstPagePath } from "docus/app/composables/useSubNavigation"; -const navigation = inject>("navigation"); +const navigation = inject>>("navigation"); const { subNavigationMode } = useSubNavigation(); -const items = computed(() => { +const items = computed>(() => { const nav = navigation?.value || []; - if (!subNavigationMode.value) return nav; + if (!subNavigationMode.value) { + return nav; + } return nav.map(({ children, ...item }) => ({ ...item, path: children?.length ? getFirstPagePath({ ...item, children }) : item.path, diff --git a/app/components/content/InklineExample.vue b/app/components/content/InklineExample.vue index 36d00a9..c209f57 100644 --- a/app/components/content/InklineExample.vue +++ b/app/components/content/InklineExample.vue @@ -2,7 +2,6 @@ import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue"; import { INKLINE_PREVIEW_ORIGIN, - type EmbedTheme, embedTheme, inklineEmbedUrl, inklineTarget, @@ -10,6 +9,7 @@ import { themeMessage, themeOnReady, } from "~/lib/inkline-embed"; +import type { EmbedTheme } from "~/lib/inkline-embed"; import { FRAMEWORKS } from "~/data/frameworks"; /** @@ -75,7 +75,9 @@ function post(value: EmbedTheme) { watch( [target, mounted], () => { - if (!mounted.value) return; + if (!mounted.value) { + return; + } urlTheme.value = theme.value; ready.value = false; src.value = inklineEmbedUrl({ @@ -89,18 +91,26 @@ watch( ); watch(theme, (value) => { - if (ready.value) post(value); + if (ready.value) { + post(value); + } }); function onMessage(event: MessageEvent) { const height = readResizeMessage(event, frame.value?.contentWindow); - if (height === undefined) return; + if (height === undefined) { + return; + } reported.value = height; - if (ready.value) return; + if (ready.value) { + return; + } ready.value = true; // A lazy frame that loaded after the mode changed missed the message. const missed = themeOnReady(urlTheme.value, theme.value); - if (missed) post(missed); + if (missed) { + post(missed); + } } onMounted(() => { diff --git a/app/components/content/card/CardPlayground.vue b/app/components/content/card/CardPlayground.vue index 826ef31..25d67a8 100644 --- a/app/components/content/card/CardPlayground.vue +++ b/app/components/content/card/CardPlayground.vue @@ -34,7 +34,7 @@ const { current } = useFramework(); const framework = computed(() => current.value?.value ?? "react"); // Highlighted the way the page's own examples for each framework are. -const LANGUAGES: Record = { +const LANGUAGES = new Map(Object.entries({ react: "tsx", vue: "vue", svelte: "svelte", @@ -42,17 +42,19 @@ const LANGUAGES: Record = { solid: "tsx", astro: "astro", vanilla: "html", -}; +})); // An element's lines, with one attribute per line once they no longer fit on one. -function element(tag: string, attributes: (string | false | undefined)[], children: string[] = []) { - const attrs = attributes.filter((attribute) => !!attribute) as string[]; +function element(tag: string, attributes: Array, children: Array = []) { + const attrs = attributes.filter((attribute) => !!attribute) as Array; const line = `<${tag}${attrs.map((attribute) => ` ${attribute}`).join("")}`; const open = line.length > 88 || attrs.some((attribute) => attribute.includes("\n")) ? [`<${tag}`, ...attrs.flatMap((attribute) => attribute.split("\n").map((part) => ` ${part}`)), children.length ? ">" : "/>"] : [`${line}${children.length ? ">" : " />"}`]; - if (!children.length) return open; + if (!children.length) { + return open; + } return [...open, ...children.map((child) => ` ${child}`), ``]; } @@ -64,7 +66,7 @@ const code = computed(() => { const jsx = fw === "react" || fw === "solid"; const body = `

${BODY}

`; // The Button among the actions, which Angular puts on the native element, and Vanilla writes out. - const button = (attributes: string[] = []) => { + const button = (attributes: Array = []) => { if (fw === "vanilla") { return ''; } @@ -72,7 +74,7 @@ const code = computed(() => { return `<${tag} ${[...attributes, 'size="sm"', 'variant="outline"'].join(" ")}>Save`; }; - let card: string[]; + let card: Array; if (fw === "vanilla") { const title = link.value ? `${HEADING}` : HEADING; card = element(as.value, ['class="card"'], [ @@ -177,7 +179,7 @@ const code = computed(() => { {{ code }} diff --git a/app/components/content/checkbox-group/CheckboxGroupPlayground.vue b/app/components/content/checkbox-group/CheckboxGroupPlayground.vue index d5f8766..4f25846 100644 --- a/app/components/content/checkbox-group/CheckboxGroupPlayground.vue +++ b/app/components/content/checkbox-group/CheckboxGroupPlayground.vue @@ -18,7 +18,7 @@ const orientation = ref>("vertica const selectAll = ref(false); const disabled = ref(false); const invalid = ref(false); -const picked = ref(["news"]); +const picked = ref>(["news"]); const sizes = ["xs", "sm", "md", "lg", "xl"]; const orientations = ["vertical", "horizontal"]; @@ -35,7 +35,7 @@ const { current } = useFramework(); const framework = computed(() => current.value?.value ?? "react"); // Highlighted the way the page's own examples for each framework are. -const LANGUAGES: Record = { +const LANGUAGES = new Map(Object.entries({ react: "tsx", vue: "vue", svelte: "svelte", @@ -43,11 +43,11 @@ const LANGUAGES: Record = { solid: "tsx", astro: "astro", vanilla: "html", -}; +})); // An element's lines, with one attribute per line once they no longer fit on one. -function element(tag: string, attributes: (string | false | undefined)[], children: string[] = []) { - const attrs = attributes.filter((attribute) => !!attribute) as string[]; +function element(tag: string, attributes: Array, children: Array = []) { + const attrs = attributes.filter((attribute) => !!attribute) as Array; const line = `<${tag}${attrs.map((attribute) => ` ${attribute}`).join("")}`; const open = line.length > 88 ? [`<${tag}`, ...attrs.map((attribute) => ` ${attribute}`), ">"] : [`${line}>`]; // A short child stays on the line, as in Which emails would you like?. @@ -58,7 +58,7 @@ function element(tag: string, attributes: (string | false | undefined)[], childr } // A Checkbox from the DOM contract, for Vanilla. -function box(attributes: string[], label: string) { +function box(attributes: Array, label: string) { return element("label", ['class="checkbox"', `data-size="${size.value}"`], [ ``, '', @@ -113,18 +113,18 @@ const code = computed(() => { } // The value is bound where the framework holds it, and left to the form where it doesn't. - const binding: Record = { + const binding = new Map>(Object.entries({ react: ["options={emails}", "value={picked}", "onValueChange={setPicked}"], vue: [':options="emails"', 'v-model:value="picked"'], svelte: ["options={emails}", "bind:value={picked}"], angular: ['[options]="emails"', '[(value)]="picked"'], solid: ["options={emails}", "value={picked()}", "onValueChange={setPicked}"], astro: ["options={emails}", `value={${JSON.stringify(picked.value)}}`], - }; + })); const attributes = [ fw === "angular" && "appCheckboxGroup", 'name="emails"', - ...binding[fw]!, + ...(binding.get(fw) ?? []), size.value !== "md" && `size="${size.value}"`, orientation.value !== "vertical" && `orientation="${orientation.value}"`, selectAll.value && `${fw === "vue" ? "select-all" : "selectAll"}="${allLabel}"`, @@ -175,7 +175,7 @@ const code = computed(() => { {{ code }} diff --git a/app/components/content/checkbox-group/examples/CheckboxGroupSizesExample.vue b/app/components/content/checkbox-group/examples/CheckboxGroupSizesExample.vue index 26d7177..b035fe3 100644 --- a/app/components/content/checkbox-group/examples/CheckboxGroupSizesExample.vue +++ b/app/components/content/checkbox-group/examples/CheckboxGroupSizesExample.vue @@ -3,7 +3,7 @@ import CheckboxGroup from "~/reference/checkbox-group/CheckboxGroup.vue"; import type { CheckboxGroupProps } from "~/reference/checkbox-group/CheckboxGroup.vue"; /** `::checkbox-group-sizes-example`: a group at each size. */ -const sizes = ["xs", "sm", "md", "lg", "xl"] as const satisfies CheckboxGroupProps["size"][]; +const sizes = ["xs", "sm", "md", "lg", "xl"] as const satisfies Array; const emails = [ { value: "news", label: "Product news" }, { value: "tips", label: "Tips and guides" }, diff --git a/app/components/content/checkbox-group/examples/CheckboxGroupValidationExample.vue b/app/components/content/checkbox-group/examples/CheckboxGroupValidationExample.vue index 230e40d..d9888ea 100644 --- a/app/components/content/checkbox-group/examples/CheckboxGroupValidationExample.vue +++ b/app/components/content/checkbox-group/examples/CheckboxGroupValidationExample.vue @@ -8,15 +8,17 @@ const emails = [ { value: "tips", label: "Tips and guides" }, { value: "events", label: "Events near you" }, ]; -const picked = ref([]); +const picked = ref>([]); const error = ref(""); const status = ref(""); const group = useTemplateRef("group"); -function update(value: string[]) { +function update(value: Array) { picked.value = value; // Picking one fixes the error, so it clears right away. - if (value.length) error.value = ""; + if (value.length) { + error.value = ""; + } } async function signUp() { diff --git a/app/components/content/checkbox/CheckboxPlayground.vue b/app/components/content/checkbox/CheckboxPlayground.vue index 45bdcab..3095f54 100644 --- a/app/components/content/checkbox/CheckboxPlayground.vue +++ b/app/components/content/checkbox/CheckboxPlayground.vue @@ -29,7 +29,7 @@ const { current } = useFramework(); const framework = computed(() => current.value?.value ?? "react"); // Highlighted the way the page's own examples for each framework are. -const LANGUAGES: Record = { +const LANGUAGES = new Map(Object.entries({ react: "tsx", vue: "vue", svelte: "svelte", @@ -37,18 +37,20 @@ const LANGUAGES: Record = { solid: "tsx", astro: "astro", vanilla: "html", -}; +})); // An element's lines, with one attribute per line once they no longer fit on one. -function element(tag: string, attributes: (string | false | undefined)[], children: string[] = []) { - const attrs = attributes.filter((attribute) => !!attribute) as string[]; +function element(tag: string, attributes: Array, children: Array = []) { + const attrs = attributes.filter((attribute) => !!attribute) as Array; const line = `<${tag}${attrs.map((attribute) => ` ${attribute}`).join("")}`; const close = children.length ? ">" : "/>"; const open = line.length > 88 ? [`<${tag}`, ...attrs.map((attribute) => ` ${attribute}`), close] : [`${line}${children.length ? ">" : " />"}`]; - if (!children.length) return open; + if (!children.length) { + return open; + } // A short child stays on the line, as in I agree to the terms. if (open.length === 1 && children.length === 1 && `${open[0]}${children[0]}`.length <= 88) { return [`${open[0]}${children[0]}`]; @@ -65,15 +67,15 @@ const code = computed(() => { const scripted = fw === "astro" || fw === "vanilla"; // The checked state is bound where the framework holds it, and left to the form where it doesn't. - const binding: Record = { + const binding = new Map>(Object.entries({ react: ["checked={checked}", "onChange={(event) => setChecked(event.target.checked)}"], vue: ['v-model:checked="checked"'], svelte: ["bind:checked"], angular: ['[(ngModel)]="checked"'], solid: ["checked={checked()}", "onChange={(event) => setChecked(event.currentTarget.checked)}"], - astro: ['name="terms"', checked.value && "checked"].filter((attribute) => !!attribute) as string[], - vanilla: ['name="terms"', checked.value && "checked"].filter((attribute) => !!attribute) as string[], - }; + astro: ['name="terms"', checked.value && "checked"].filter((attribute) => !!attribute) as Array, + vanilla: ['name="terms"', checked.value && "checked"].filter((attribute) => !!attribute) as Array, + })); // Angular binds the property on the , and Astro and Vanilla set it from a script. const mixed = indeterminate.value && !scripted && (fw === "angular" ? '[indeterminate]="true"' : "indeterminate"); const attributes = [ @@ -81,7 +83,7 @@ const code = computed(() => { fw === "vanilla" && 'type="checkbox"', fw === "angular" && 'type="checkbox"', scripted && indeterminate.value && 'id="terms"', - ...binding[fw]!, + ...(binding.get(fw) ?? []), fw !== "vanilla" && fw !== "angular" && size.value !== "md" && `size="${size.value}"`, mixed, disabled.value && "disabled", @@ -93,7 +95,7 @@ const code = computed(() => { invalid.value && 'aria-describedby="terms-error"', ]; - let checkbox: string[]; + let checkbox: Array; if (fw === "angular" || fw === "vanilla") { // The