This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
183 additions
and
10 deletions.
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
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
15 changes: 13 additions & 2 deletions
15
packages/editor/src/extensions/code-block/CodeBlockViewRenderer.vue
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,62 @@ | ||
<script lang="ts" setup> | ||
import type { Node as ProseMirrorNode } from "prosemirror-model"; | ||
import type { Decoration } from "prosemirror-view"; | ||
import { Editor, NodeViewWrapper, Node } from "@tiptap/vue-3"; | ||
import { computed, ref } from "vue"; | ||
import { useResizeObserver } from "@vueuse/core"; | ||
const props = defineProps<{ | ||
editor: Editor; | ||
node: ProseMirrorNode; | ||
decorations: Decoration[]; | ||
selected: boolean; | ||
extension: Node<any, any>; | ||
getPos: () => number; | ||
updateAttributes: (attributes: Record<string, any>) => void; | ||
deleteNode: () => void; | ||
}>(); | ||
const src = computed(() => { | ||
return props.node.attrs.src; | ||
}); | ||
const alt = computed({ | ||
get: () => { | ||
return props.node?.attrs.alt; | ||
}, | ||
set: (alt: string) => { | ||
props.updateAttributes({ alt: alt }); | ||
}, | ||
}); | ||
const resizeRef = ref<HTMLElement>(); | ||
useResizeObserver(resizeRef, (entries) => { | ||
const entry = entries[0]; | ||
const { width, height } = entry.contentRect; | ||
props.updateAttributes({ width: width, height: height }); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<node-view-wrapper as="div"> | ||
<div | ||
ref="resizeRef" | ||
class="resize mt-4 mb-4 inline-block overflow-hidden transition-all text-center relative" | ||
:class="{ | ||
'ring-2 rounded': selected, | ||
}" | ||
:style="{ | ||
width: `${props.node.attrs.width}px`, | ||
height: `${props.node.attrs.height}px`, | ||
}" | ||
> | ||
<img | ||
:src="src" | ||
:title="node.attrs.title" | ||
:alt="alt" | ||
class="w-full h-full" | ||
/> | ||
</div> | ||
</node-view-wrapper> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import TiptapImage from "@tiptap/extension-image"; | ||
import { VueNodeViewRenderer } from "@tiptap/vue-3"; | ||
import ImageView from "./ImageView.vue"; | ||
|
||
const Image = TiptapImage.extend({ | ||
inline() { | ||
return true; | ||
}, | ||
|
||
group() { | ||
return "inline"; | ||
}, | ||
|
||
addAttributes() { | ||
return { | ||
...this.parent?.(), | ||
width: { | ||
default: null, | ||
parseHTML: (element) => { | ||
const width = | ||
element.style.width || element.getAttribute("width") || null; | ||
return width == null ? null : parseInt(width, 10); | ||
}, | ||
renderHTML: (attributes) => { | ||
return { | ||
width: attributes.width, | ||
}; | ||
}, | ||
}, | ||
height: { | ||
default: null, | ||
parseHTML: (element) => { | ||
const height = | ||
element.style.height || element.getAttribute("height") || null; | ||
return height == null ? null : parseInt(height, 10); | ||
}, | ||
renderHTML: (attributes) => { | ||
return { | ||
height: attributes.height, | ||
}; | ||
}, | ||
}, | ||
}; | ||
}, | ||
|
||
addNodeView() { | ||
return VueNodeViewRenderer(ImageView); | ||
}, | ||
|
||
parseHTML() { | ||
return [ | ||
{ | ||
tag: "img[src]", | ||
}, | ||
]; | ||
}, | ||
}); | ||
|
||
export default Image; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.