mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Add LegacyEmbeds component to fix bug
This commit is contained in:
parent
694fb52381
commit
aeac1edb32
@ -1,4 +1,5 @@
|
||||
import Embed from '~/components/Editor/nodes/Embed.js'
|
||||
import LegacyEmbed from '~/components/Editor/nodes/LegacyEmbed.js'
|
||||
import Link from '~/components/Editor/nodes/Link.js'
|
||||
import Strike from '~/components/Editor/marks/Strike'
|
||||
import Italic from '~/components/Editor/marks/Italic'
|
||||
@ -44,5 +45,13 @@ export default function defaultExtensions(component) {
|
||||
return embed
|
||||
},
|
||||
}),
|
||||
new LegacyEmbed({
|
||||
onEmbed: async ({ url }) => {
|
||||
const {
|
||||
data: { embed },
|
||||
} = await $apollo.query({ query: EmbedQuery(), variables: { url } })
|
||||
return embed
|
||||
},
|
||||
}),
|
||||
]
|
||||
}
|
||||
|
||||
93
webapp/components/Editor/nodes/LegacyEmbed.js
Normal file
93
webapp/components/Editor/nodes/LegacyEmbed.js
Normal file
@ -0,0 +1,93 @@
|
||||
import { Node } from 'tiptap'
|
||||
import pasteRule from '../commands/pasteRule'
|
||||
import { compileToFunctions } from 'vue-template-compiler'
|
||||
import Vue from 'vue'
|
||||
import EmbedComponent from '~/components/Embed/EmbedComponent'
|
||||
|
||||
Vue.component(EmbedComponent)
|
||||
const template = `<component :dataEmbedUrl="dataEmbedUrl" :embedData="embedData" :is="componentType" />`
|
||||
|
||||
const compiledTemplate = compileToFunctions(template)
|
||||
|
||||
export default class Embed extends Node {
|
||||
get name() {
|
||||
return 'embed'
|
||||
}
|
||||
|
||||
get defaultOptions() {
|
||||
return {
|
||||
onEmbed: () => ({}),
|
||||
}
|
||||
}
|
||||
|
||||
pasteRules({ type, schema }) {
|
||||
return [
|
||||
pasteRule(
|
||||
// source: https://stackoverflow.com/a/3809435
|
||||
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/g,
|
||||
type,
|
||||
url => ({ dataEmbedUrl: url }),
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
get schema() {
|
||||
return {
|
||||
attrs: {
|
||||
dataEmbedUrl: {
|
||||
default: null,
|
||||
},
|
||||
},
|
||||
group: 'inline',
|
||||
inline: true,
|
||||
parseDOM: [
|
||||
{
|
||||
tag: 'a[href].embed',
|
||||
getAttrs: dom => ({
|
||||
dataEmbedUrl: dom.getAttribute('href'),
|
||||
}),
|
||||
},
|
||||
],
|
||||
toDOM: node => [
|
||||
'a',
|
||||
{
|
||||
href: node.attrs.dataEmbedUrl,
|
||||
class: 'embed',
|
||||
target: '_blank',
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
get view() {
|
||||
return {
|
||||
props: ['node', 'updateAttrs', 'options'],
|
||||
data: () => ({
|
||||
embedData: {},
|
||||
}),
|
||||
async created() {
|
||||
if (this.options) {
|
||||
this.embedData = await this.options.onEmbed({ url: this.dataEmbedUrl })
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
componentType() {
|
||||
return EmbedComponent
|
||||
},
|
||||
dataEmbedUrl: {
|
||||
get() {
|
||||
return this.node.attrs.dataEmbedUrl
|
||||
},
|
||||
set(dataEmbedUrl) {
|
||||
this.updateAttrs({
|
||||
dataEmbedUrl,
|
||||
})
|
||||
},
|
||||
},
|
||||
},
|
||||
render(createElement) {
|
||||
return compiledTemplate.render.call(this, createElement)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user