-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show images in documentation #10205
Merged
Merged
Show images in documentation #10205
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
1f8817a
Selection formatting toolbar
kazcw 04b85ac
Merge remote-tracking branch 'origin/develop' into wip/kw/selection-f…
kazcw 9ae2e19
Icons
kazcw f0c9856
Review
kazcw 44d37fd
Fix bold+italic rendering
kazcw 03cad1a
Preparing for top bar
kazcw 703fc0f
Top bar
kazcw d857068
Merge remote-tracking branch 'origin/develop' into wip/kw/format-bar
kazcw 4e229cb
Introduce APIs for Markdown formatting bar UI; use new APIs to simplify
kazcw dba482f
Clean up
kazcw 86fa101
Refactor
kazcw 80001b1
Refactor
kazcw b7a87ab
Lint
kazcw 368794d
Clean up
kazcw a597aee
Merge remote-tracking branch 'origin/develop' into wip/kw/format-bar
kazcw e3c3def
Lint
kazcw 2e4b7ca
Merge remote-tracking branch 'origin/develop' into wip/kw/format-bar
kazcw c329bd2
Merge remote-tracking branch 'origin/develop' into wip/kw/format-bar
kazcw d23acac
Limit smallest heading style to match the levels shown in the formatt…
kazcw e902f1c
Fix block quotes
kazcw 6935465
Close menu on click
kazcw ecd1e01
Merge remote-tracking branch 'origin/develop' into wip/kw/format-bar
kazcw d328f76
Buffer updates
kazcw 6741fce
Fix logical merge conflict
kazcw ecc96b4
Fix close button location
kazcw 461e9f9
Review
kazcw 152421d
Update tests
kazcw cdff55a
Fix
kazcw 284e094
Fix
kazcw b6e321e
fix
kazcw da9e235
Merge remote-tracking branch 'origin/develop' into wip/kw/format-bar
kazcw 0953e65
Update Lexical
kazcw fa8de14
Reorganize
kazcw 5afaa45
Fix bug
kazcw 1c70aea
Merge remote-tracking branch 'origin/develop' into wip/kw/format-bar
kazcw 99fe686
Move some logic out of GraphEditor
kazcw 1f4a2c9
projectStore provides projectRoot
kazcw ddd9e31
Documentation images
kazcw 11d6df4
lint
kazcw 3f53dcb
Merge remote-tracking branch 'origin/develop' into wip/kw/doc-images
kazcw ac26ee4
Review
kazcw 9b9d9a9
CHANGELOG
kazcw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
import { expect, test } from 'playwright/test' | ||
import * as actions from './actions' | ||
import { CONTROL_KEY } from './keyboard' | ||
import * as locate from './locate' | ||
|
||
test('Main method documentation', async ({ page }) => { | ||
await actions.goToGraph(page) | ||
|
||
// Documentation panel hotkey opens right-dock. | ||
await expect(page.getByTestId('rightDock')).not.toBeVisible() | ||
await expect(locate.rightDock(page)).not.toBeVisible() | ||
await page.keyboard.press(`${CONTROL_KEY}+D`) | ||
await expect(page.getByTestId('rightDock')).toBeVisible() | ||
await expect(locate.rightDock(page)).toBeVisible() | ||
|
||
// Right-dock displays main method documentation. | ||
await expect(page.getByTestId('rightDock')).toHaveText('The main method') | ||
await expect(locate.lexicalContent(locate.rightDock(page))).toHaveText('The main method') | ||
|
||
// Documentation hotkey closes right-dock.p | ||
await page.keyboard.press(`${CONTROL_KEY}+D`) | ||
await expect(page.getByTestId('rightDock')).not.toBeVisible() | ||
await expect(locate.rightDock(page)).not.toBeVisible() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<script setup lang="ts"> | ||
import ResizeHandles from '@/components/ResizeHandles.vue' | ||
import SvgButton from '@/components/SvgButton.vue' | ||
import { useResizeObserver } from '@/composables/events' | ||
import { Rect } from '@/util/data/rect' | ||
import { Vec2 } from '@/util/data/vec2' | ||
import { computed, ref } from 'vue' | ||
|
||
const rootElement = ref<HTMLElement>() | ||
|
||
const show = defineModel<boolean>('show', { required: true }) | ||
const size = defineModel<number | undefined>('size') | ||
|
||
const computedSize = useResizeObserver(rootElement) | ||
const computedBounds = computed(() => new Rect(Vec2.Zero, computedSize.value)) | ||
|
||
const style = computed(() => { | ||
return { | ||
width: size.value != null ? `${size.value}px` : undefined, | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<Transition name="rightDock"> | ||
<div v-if="show" ref="rootElement" class="DockPanel rightDock" :style="style"> | ||
<div class="scrollArea"> | ||
<slot /> | ||
</div> | ||
<SvgButton name="close" class="closeButton button" @click.stop="show = false" /> | ||
<ResizeHandles left :modelValue="computedBounds" @update:modelValue="size = $event.width" /> | ||
</div> | ||
</Transition> | ||
</template> | ||
|
||
<style scoped> | ||
.DockPanel { | ||
position: absolute; | ||
top: 46px; | ||
bottom: 0; | ||
width: var(--right-dock-default-width); | ||
right: 0; | ||
border-radius: 7px 0 0; | ||
background-color: rgba(255, 255, 255, 0.35); | ||
backdrop-filter: var(--blur-app-bg); | ||
padding: 4px 12px 0 0; | ||
} | ||
.rightDock-enter-active, | ||
.rightDock-leave-active { | ||
transition: left 0.25s ease; | ||
/* Prevent absolutely-positioned children (such as the close button) from bypassing the show/hide animation. */ | ||
overflow-x: clip; | ||
} | ||
.rightDock-enter-from, | ||
.rightDock-leave-to { | ||
width: 0; | ||
} | ||
.rightDock .scrollArea { | ||
width: 100%; | ||
height: 100%; | ||
overflow-y: auto; | ||
padding-left: 6px; | ||
} | ||
|
||
.rightDock .closeButton { | ||
position: absolute; | ||
top: 4px; | ||
right: 28px; | ||
color: red; | ||
opacity: 0.3; | ||
|
||
&:hover { | ||
opacity: 0.6; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<script setup lang="ts"> | ||
import MarkdownEditor from '@/components/MarkdownEditor.vue' | ||
import { fetcherUrlTransformer } from '@/components/MarkdownEditor/imageUrlTransformer' | ||
import { useProjectStore } from '@/stores/project' | ||
import type { Path, Uuid } from 'shared/languageServerTypes' | ||
import { Err, Ok, mapOk, withContext, type Result } from 'shared/util/data/result' | ||
|
||
const documentation = defineModel<string>({ required: true }) | ||
|
||
const projectStore = useProjectStore() | ||
const { transformImageUrl } = useDocumentationImages( | ||
projectStore.projectRootId, | ||
projectStore.readFileBinary, | ||
) | ||
|
||
function useDocumentationImages( | ||
projectRootId: Promise<Uuid | undefined>, | ||
readFileBinary: (path: Path) => Promise<Result<Blob>>, | ||
) { | ||
async function urlToPath(url: string): Promise<Result<Path> | undefined> { | ||
if (url.includes('//')) { | ||
// Not a relative URL, custom fetching not needed. | ||
return undefined | ||
} else { | ||
return relativeUrlToPath(url) | ||
} | ||
} | ||
|
||
async function relativeUrlToPath(url: string): Promise<Result<Path>> { | ||
const rootId = await projectRootId | ||
if (!rootId) { | ||
return Err('Cannot find project root.') | ||
} | ||
if (url.startsWith('/')) { | ||
// Relative to project root. | ||
return Ok({ rootId, segments: url.slice(1).split('/') }) | ||
} else { | ||
// Relative to current module. | ||
const segments = url.split('/') | ||
if (segments[0] === '..') { | ||
return Ok({ rootId, segments: segments.slice(1) }) | ||
} else { | ||
return Ok({ rootId, segments: ['src', ...segments] }) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We assume we're in |
||
} | ||
|
||
function pathUniqueId(path: Path) { | ||
return path.rootId + ':' + path.segments.join('/') | ||
} | ||
|
||
function pathDebugRepr(path: Path) { | ||
return pathUniqueId(path) | ||
} | ||
|
||
const transformImageUrl = fetcherUrlTransformer( | ||
async (url: string) => { | ||
const path = await urlToPath(url) | ||
if (!path) return | ||
return withContext( | ||
() => `Locating documentation image (${url})`, | ||
() => mapOk(path, (path) => ({ location: path, uniqueId: pathUniqueId(path) })), | ||
) | ||
}, | ||
async (path) => { | ||
return withContext( | ||
() => `Loading documentation image (${pathDebugRepr(path)})`, | ||
async () => await readFileBinary(path), | ||
) | ||
}, | ||
) | ||
|
||
return { transformImageUrl } | ||
} | ||
</script> | ||
|
||
<template> | ||
<MarkdownEditor v-model="documentation" :transformImageUrl="transformImageUrl" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, inside paths, double
/
is treated as single/
, at least on Linuxes. Maybe check for:
presence?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll use the
URL
API.