Skip to content

Commit 7a3aace

Browse files
committed
Convert tooltip-body to svelte
1 parent 5f9f097 commit 7a3aace

File tree

6 files changed

+727
-243
lines changed

6 files changed

+727
-243
lines changed

assets/build/build.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const fsExtra = require('fs-extra')
66
const fs = require('node:fs/promises')
77
const handlebars = require('handlebars')
88
const util = require('node:util')
9+
const sveltePlugin = require('esbuild-svelte')
910

1011
const exec = util.promisify(cp.exec)
1112

@@ -43,14 +44,14 @@ Promise.all(formatters.map(async ({formatter, ...options}) => {
4344
// Clean outdir.
4445
await fsExtra.emptyDir(options.outdir)
4546

46-
await esbuild.build({
47+
options = {
4748
entryNames: watchMode ? '[name]-dev' : '[name]-[hash]',
4849
bundle: true,
50+
conditions: [watchMode ? 'development' : 'production'],
4951
minify: !watchMode,
5052
logLevel: watchMode ? 'warning' : 'info',
51-
watch: watchMode,
5253
...options,
53-
plugins: [{
54+
plugins: [sveltePlugin(), {
5455
name: 'ex_doc',
5556
setup (build) {
5657
// Pre-compile handlebars templates.
@@ -98,7 +99,14 @@ Promise.all(formatters.map(async ({formatter, ...options}) => {
9899
}
99100
}
100101
}]
101-
})
102+
}
103+
104+
if (watchMode) {
105+
const ctx = (await esbuild.context(options))
106+
await ctx.watch()
107+
} else {
108+
await esbuild.build(options)
109+
}
102110
})).catch((error) => {
103111
console.error(error)
104112
process.exit(1)

assets/js/handlebars/templates/tooltip-body.handlebars

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script>
2+
const { isPlain, hint } = $props()
3+
</script>
4+
5+
{#if isPlain}
6+
<section class="docstring docstring-plain">
7+
{hint.description}
8+
</section>
9+
{:else}
10+
<div class="detail-header">
11+
<h1 class="signature">
12+
<span translate="no">{hint.title}</span>
13+
<div class="version-info" translate="no">{hint.version}</div>
14+
</h1>
15+
</div>
16+
{#if hint.description}
17+
<section class="docstring">
18+
{@html hint.description}
19+
</section>
20+
{/if}
21+
{/if}

assets/js/tooltips/tooltips.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { qs, qsAll } from '../helpers'
22
import { settingsStore } from '../settings-store'
33
import { cancelHintFetchingIfAny, getHint, HINT_KIND, isValidHintHref } from './hints'
4-
import tooltipBodyTemplate from '../handlebars/templates/tooltip-body.handlebars'
4+
import tooltipBodyTemplate from '../handlebars/templates/tooltip-body.svelte'
5+
import {mount} from 'svelte'
56

67
const TOOLTIP_HTML = '<div class="tooltip"><div class="tooltip-body"></div></div>'
78

@@ -92,17 +93,18 @@ function handleHoverStart (event) {
9293
}
9394

9495
function renderTooltip (hint) {
95-
const tooltipBodyHtml = tooltipBodyTemplate({
96-
isPlain: hint.kind === HINT_KIND.plain,
97-
hint
98-
})
99-
10096
let tooltipBody = qs(TOOLTIP_BODY_SELECTOR)
10197
if (!tooltipBody) {
10298
qs(CONTENT_INNER_SELECTOR).insertAdjacentHTML('beforeend', TOOLTIP_HTML)
10399
tooltipBody = qs(TOOLTIP_BODY_SELECTOR)
104100
}
105-
tooltipBody.innerHTML = tooltipBodyHtml
101+
mount(tooltipBodyTemplate, {
102+
target: tooltipBody,
103+
props: {
104+
isPlain: hint.kind === HINT_KIND.plain,
105+
hint
106+
}
107+
})
106108

107109
updateTooltipPosition()
108110

0 commit comments

Comments
 (0)