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
5 changed files
with
235 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<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 } from "vue"; | ||
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({ | ||
get: () => { | ||
return props.node?.attrs.src; | ||
}, | ||
set: (src: string) => { | ||
props.updateAttributes({ src: src }); | ||
}, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<node-view-wrapper | ||
as="div" | ||
class="divide-gray-100 bg-gray-100 overflow-hidden rounded-md w-full my-3" | ||
> | ||
<div class="block w-full relative"> | ||
<div class="px-2 py-1.5"> | ||
<input | ||
v-model="src" | ||
class="block px-2 w-full py-1.5 text-sm text-gray-900 border border-gray-300 rounded-md bg-gray-50 focus:ring-blue-500 focus:border-blue-500" | ||
placeholder="输入链接" | ||
/> | ||
</div> | ||
<iframe | ||
v-if="src" | ||
class="rounded-md" | ||
:src="node!.attrs.src" | ||
:width="node.attrs.width" | ||
:height="node.attrs.height" | ||
scrolling="no" | ||
border="0" | ||
frameborder="no" | ||
framespacing="0" | ||
allowfullscreen="true" | ||
></iframe> | ||
</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,158 @@ | ||
import { mergeAttributes, Node, nodeInputRule } from "@tiptap/core"; | ||
import { VueNodeViewRenderer } from "@tiptap/vue-3"; | ||
import IframeView from "./IframeView.vue"; | ||
|
||
declare module "@tiptap/core" { | ||
interface Commands<ReturnType> { | ||
iframe: { | ||
setIframe: (options: { src: string }) => ReturnType; | ||
}; | ||
} | ||
} | ||
|
||
const Iframe = Node.create({ | ||
name: "iframe", | ||
|
||
group: "block", | ||
|
||
selectable: false, | ||
|
||
addAttributes() { | ||
return { | ||
...this.parent?.(), | ||
src: { | ||
default: null, | ||
parseHTML: (element) => { | ||
const src = element.getAttribute("src"); | ||
return src; | ||
}, | ||
}, | ||
width: { | ||
default: "100%", | ||
parseHTML: (element) => { | ||
return element.getAttribute("width"); | ||
}, | ||
renderHTML(attributes) { | ||
return { | ||
width: attributes.width, | ||
}; | ||
}, | ||
}, | ||
height: { | ||
default: 200, | ||
parseHTML: (element) => { | ||
const height = element.getAttribute("height"); | ||
return height ? parseInt(height, 10) : null; | ||
}, | ||
renderHTML: (attributes) => { | ||
return { | ||
height: attributes.height, | ||
}; | ||
}, | ||
}, | ||
scrolling: { | ||
default: null, | ||
parseHTML: (element) => { | ||
return element.getAttribute("scrolling"); | ||
}, | ||
renderHTML: (attributes) => { | ||
return { | ||
scrolling: attributes.scrolling, | ||
}; | ||
}, | ||
}, | ||
border: { | ||
default: 0, | ||
parseHTML: (element) => { | ||
const border = element.getAttribute("border"); | ||
return border ? parseInt(border, 10) : null; | ||
}, | ||
renderHTML: (attributes) => { | ||
return { | ||
border: attributes.border, | ||
}; | ||
}, | ||
}, | ||
frameborder: { | ||
default: "no", | ||
parseHTML: (element) => { | ||
return element.getAttribute("frameborder"); | ||
}, | ||
renderHTML: (attributes) => { | ||
return { | ||
frameborder: attributes.frameborder, | ||
}; | ||
}, | ||
}, | ||
allowfullscreen: { | ||
default: true, | ||
parseHTML: (element) => { | ||
return element.getAttribute("allowfullscreen"); | ||
}, | ||
renderHTML: (attributes) => { | ||
return { | ||
allowfullscreen: attributes.allowfullscreen, | ||
}; | ||
}, | ||
}, | ||
framespacing: { | ||
default: 0, | ||
parseHTML: (element) => { | ||
const framespacing = element.getAttribute("framespacing"); | ||
return framespacing ? parseInt(framespacing, 10) : null; | ||
}, | ||
renderHTML: (attributes) => { | ||
return { | ||
framespacing: attributes.framespacing, | ||
}; | ||
}, | ||
}, | ||
}; | ||
}, | ||
|
||
parseHTML() { | ||
return [ | ||
{ | ||
tag: "iframe", | ||
}, | ||
]; | ||
}, | ||
|
||
renderHTML({ HTMLAttributes }) { | ||
return [ | ||
"p", | ||
["iframe", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)], | ||
]; | ||
}, | ||
|
||
addCommands() { | ||
return { | ||
setIframe: | ||
(options) => | ||
({ commands }) => { | ||
return commands.insertContent({ | ||
type: this.name, | ||
attrs: options, | ||
}); | ||
}, | ||
}; | ||
}, | ||
|
||
addInputRules() { | ||
return [ | ||
nodeInputRule({ | ||
find: /^\$iframe\$$/, | ||
type: this.type, | ||
getAttributes: () => { | ||
return { width: "100%" }; | ||
}, | ||
}), | ||
]; | ||
}, | ||
|
||
addNodeView() { | ||
return VueNodeViewRenderer(IframeView); | ||
}, | ||
}); | ||
|
||
export default Iframe; |
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