mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
starlight_help: Do not use type assertions in astro components.
Partially fixes #35435. For KeyboardTip.astro and ZulipTip.astro, we were using type assertions and thus needed to suppress eslint warnings that were being thrown.
This commit is contained in:
committed by
Tim Abbott
parent
5501954637
commit
f20dc8f6cf
@@ -310,14 +310,9 @@ export default tseslint.config(
|
|||||||
},
|
},
|
||||||
...astroConfigs.recommended,
|
...astroConfigs.recommended,
|
||||||
{
|
{
|
||||||
files: [
|
files: ["starlight_help/src/components/ZulipNote.astro"],
|
||||||
"starlight_help/src/components/ZulipNote.astro",
|
|
||||||
"starlight_help/src/components/ZulipTip.astro",
|
|
||||||
"starlight_help/src/components/KeyboardTip.astro",
|
|
||||||
],
|
|
||||||
rules: {
|
rules: {
|
||||||
"import/unambiguous": "off",
|
"import/unambiguous": "off",
|
||||||
"@typescript-eslint/consistent-type-assertions": "off",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -21,22 +21,13 @@ keyboard_icon_first_child.properties.class = "zulip-unplugin-icon";
|
|||||||
// the next line as `Keyboard tip:`. We have to edit slot HTML tree
|
// the next line as `Keyboard tip:`. We have to edit slot HTML tree
|
||||||
// directly instead to solve this. Same case applies for the keyboard
|
// directly instead to solve this. Same case applies for the keyboard
|
||||||
// icon we are inserting. We just inject the icon as raw svg.
|
// icon we are inserting. We just inject the icon as raw svg.
|
||||||
const prefix_element_list = [
|
const prefix_text_element: Element = {
|
||||||
keyboard_icon_first_child,
|
|
||||||
{
|
|
||||||
type: "element",
|
type: "element",
|
||||||
tagName: "strong",
|
tagName: "strong",
|
||||||
properties: {},
|
properties: {},
|
||||||
children: [
|
children: [{type: "text", value: " Keyboard tip: "}],
|
||||||
{
|
};
|
||||||
type: "text",
|
const prefix_element_list = [keyboard_icon_first_child, prefix_text_element];
|
||||||
// Whitespace before the text to ensure space between
|
|
||||||
// this text and the preceding icon.
|
|
||||||
value: " Keyboard tip: ",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
} as Element,
|
|
||||||
];
|
|
||||||
|
|
||||||
const tree = fromHtml(await Astro.slots.render("default"), {fragment: true});
|
const tree = fromHtml(await Astro.slots.render("default"), {fragment: true});
|
||||||
const first_element = tree.children[0];
|
const first_element = tree.children[0];
|
||||||
|
|||||||
@@ -22,9 +22,7 @@ lightbulb_icon_first_child.properties.class =
|
|||||||
// `Tip:`. We have to edit slot HTML tree directly instead to solve this.
|
// `Tip:`. We have to edit slot HTML tree directly instead to solve this.
|
||||||
// Same case applies for the ligthbulb icon we are inserting. We just
|
// Same case applies for the ligthbulb icon we are inserting. We just
|
||||||
// inject the icon as raw svg.
|
// inject the icon as raw svg.
|
||||||
let prefix_element_list = [
|
const prefix_text_element: Element = {
|
||||||
lightbulb_icon_first_child,
|
|
||||||
{
|
|
||||||
type: "element",
|
type: "element",
|
||||||
tagName: "strong",
|
tagName: "strong",
|
||||||
properties: {},
|
properties: {},
|
||||||
@@ -36,8 +34,8 @@ let prefix_element_list = [
|
|||||||
value: " Tip: ",
|
value: " Tip: ",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
} as Element,
|
};
|
||||||
];
|
let prefix_element_list = [lightbulb_icon_first_child, prefix_text_element];
|
||||||
|
|
||||||
const tree = fromHtml(await Astro.slots.render("default"), {fragment: true});
|
const tree = fromHtml(await Astro.slots.render("default"), {fragment: true});
|
||||||
const first_element = tree.children[0];
|
const first_element = tree.children[0];
|
||||||
@@ -47,14 +45,13 @@ assert.ok(first_element?.type === "element");
|
|||||||
// where the tip contains an unordered list. Just placing the element as is without
|
// where the tip contains an unordered list. Just placing the element as is without
|
||||||
// a paragraph does not look good in that case.
|
// a paragraph does not look good in that case.
|
||||||
if (first_element.tagName !== "p") {
|
if (first_element.tagName !== "p") {
|
||||||
prefix_element_list = [
|
const paragraph_wrapping_element: Element = {
|
||||||
{
|
|
||||||
type: "element",
|
type: "element",
|
||||||
tagName: "p",
|
tagName: "p",
|
||||||
properties: {},
|
properties: {},
|
||||||
children: [...prefix_element_list],
|
children: [...prefix_element_list],
|
||||||
} as Element,
|
};
|
||||||
];
|
prefix_element_list = [paragraph_wrapping_element];
|
||||||
}
|
}
|
||||||
|
|
||||||
first_element.children = [...prefix_element_list, ...first_element.children];
|
first_element.children = [...prefix_element_list, ...first_element.children];
|
||||||
|
|||||||
Reference in New Issue
Block a user