From af39e0ec50c1b59aa0c8ee85c6bb510279a505aa Mon Sep 17 00:00:00 2001 From: Adam Obuchowicz Date: Tue, 19 Nov 2024 16:47:46 +0100 Subject: [PATCH] Pasting image in Documentation Editor (#11547) Fixes #10059 https://github.com/user-attachments/assets/a528e26a-b388-4a2a-9bf4-3ccc734373f6 # Important Notes * I put the logic for project's files management to a single composable "projectFiles" --- CHANGELOG.md | 3 + app/gui/e2e/project-view/rightPanel.spec.ts | 11 +- app/gui/src/project-view/bindings.ts | 1 + .../components/DocumentationEditor.vue | 154 +++++++++++- .../project-view/components/GraphEditor.vue | 10 +- .../components/GraphEditor/upload.ts | 127 +++------- .../components/MarkdownEditor.vue | 17 +- .../MarkdownEditor/DocumentationImage.vue | 7 +- .../MarkdownEditor/MarkdownEditorImpl.vue | 32 ++- .../MarkdownEditor/__tests__/markdown.test.ts | 15 ++ .../MarkdownEditor/imageUrlTransformer.ts | 28 ++- .../MarkdownEditor/markdown/decoration.ts | 18 +- .../MarkdownEditor/markdown/lezer.d.ts | 11 + .../MarkdownEditor/markdown/parse.ts | 223 +++++++++++++++++- app/gui/src/project-view/mock/engine.ts | 16 ++ .../src/project-view/stores/project/index.ts | 29 +-- .../src/project-view/stores/projectFiles.ts | 150 ++++++++++++ .../src/project-view/util/net/dataServer.ts | 7 +- app/gui/src/project-view/util/toast.ts | 25 +- tsconfig.json | 4 +- 20 files changed, 726 insertions(+), 162 deletions(-) create mode 100644 app/gui/src/project-view/stores/projectFiles.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index b27e76ed786d..f31e9a856fa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ component.][11452] - [New documentation editor provides improved Markdown editing experience, and paves the way for new documentation features.][11469] +- [You can now add images to documentation panel][11547] by pasting them from + clipboard or by drag'n'dropping image files. - ["Write" button in component menu allows to evaluate it separately from the rest of the workflow][11523]. @@ -42,6 +44,7 @@ [11448]: https://github.com/enso-org/enso/pull/11448 [11452]: https://github.com/enso-org/enso/pull/11452 [11469]: https://github.com/enso-org/enso/pull/11469 +[11547]: https://github.com/enso-org/enso/pull/11547 [11523]: https://github.com/enso-org/enso/pull/11523 #### Enso Standard Library diff --git a/app/gui/e2e/project-view/rightPanel.spec.ts b/app/gui/e2e/project-view/rightPanel.spec.ts index bc907fbe2d61..3f2eb5ef73b5 100644 --- a/app/gui/e2e/project-view/rightPanel.spec.ts +++ b/app/gui/e2e/project-view/rightPanel.spec.ts @@ -7,13 +7,18 @@ import * as locate from './locate' test('Main method documentation', async ({ page }) => { await actions.goToGraph(page) + const rightDock = locate.rightDock(page) // Documentation panel hotkey opens right-dock. - await expect(locate.rightDock(page)).toBeHidden() + await expect(rightDock).toBeHidden() await page.keyboard.press(`${CONTROL_KEY}+D`) - await expect(locate.rightDock(page)).toBeVisible() + await expect(rightDock).toBeVisible() // Right-dock displays main method documentation. - await expect(locate.editorRoot(locate.rightDock(page))).toHaveText('The main method') + await expect(locate.editorRoot(rightDock)).toContainText('The main method') + // All three images are loaded properly + await expect(rightDock.getByAltText('Image')).toHaveCount(3) + for (const img of await rightDock.getByAltText('Image').all()) + await expect(img).toHaveJSProperty('naturalWidth', 3) // Documentation hotkey closes right-dock.p await page.keyboard.press(`${CONTROL_KEY}+D`) diff --git a/app/gui/src/project-view/bindings.ts b/app/gui/src/project-view/bindings.ts index 210094aeb62c..defe7cb055c6 100644 --- a/app/gui/src/project-view/bindings.ts +++ b/app/gui/src/project-view/bindings.ts @@ -12,6 +12,7 @@ export const codeEditorBindings = defineKeybinds('code-editor', { export const documentationEditorBindings = defineKeybinds('documentation-editor', { toggle: ['Mod+D'], openLink: ['Mod+PointerMain'], + paste: ['Mod+V'], }) export const interactionBindings = defineKeybinds('current-interaction', { diff --git a/app/gui/src/project-view/components/DocumentationEditor.vue b/app/gui/src/project-view/components/DocumentationEditor.vue index fc19d6b70888..240aae6e4be3 100644 --- a/app/gui/src/project-view/components/DocumentationEditor.vue +++ b/app/gui/src/project-view/components/DocumentationEditor.vue @@ -1,13 +1,17 @@