mirror of
https://github.com/docmost/docmost.git
synced 2025-11-10 09:02:10 +10:00
generic iframe embed (#1234)
This commit is contained in:
@ -18,7 +18,10 @@ import { useForm, zodResolver } from "@mantine/form";
|
|||||||
import { notifications } from "@mantine/notifications";
|
import { notifications } from "@mantine/notifications";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import i18n from "i18next";
|
import i18n from "i18next";
|
||||||
import { getEmbedProviderById, getEmbedUrlAndProvider } from '@docmost/editor-ext';
|
import {
|
||||||
|
getEmbedProviderById,
|
||||||
|
getEmbedUrlAndProvider,
|
||||||
|
} from "@docmost/editor-ext";
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
url: z
|
url: z
|
||||||
@ -49,6 +52,10 @@ export default function EmbedView(props: NodeViewProps) {
|
|||||||
async function onSubmit(data: { url: string }) {
|
async function onSubmit(data: { url: string }) {
|
||||||
if (provider) {
|
if (provider) {
|
||||||
const embedProvider = getEmbedProviderById(provider);
|
const embedProvider = getEmbedProviderById(provider);
|
||||||
|
if (embedProvider.id === "iframe") {
|
||||||
|
updateAttributes({ src: data.url });
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (embedProvider.regex.test(data.url)) {
|
if (embedProvider.regex.test(data.url)) {
|
||||||
updateAttributes({ src: data.url });
|
updateAttributes({ src: data.url });
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -17,8 +17,8 @@ import {
|
|||||||
IconTable,
|
IconTable,
|
||||||
IconTypography,
|
IconTypography,
|
||||||
IconMenu4,
|
IconMenu4,
|
||||||
IconCalendar,
|
IconCalendar, IconAppWindow,
|
||||||
} from "@tabler/icons-react";
|
} from '@tabler/icons-react';
|
||||||
import {
|
import {
|
||||||
CommandProps,
|
CommandProps,
|
||||||
SlashMenuGroupedItemsType,
|
SlashMenuGroupedItemsType,
|
||||||
@ -357,6 +357,20 @@ const CommandGroups: SlashMenuGroupedItemsType = {
|
|||||||
.run();
|
.run();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Iframe embed",
|
||||||
|
description: "Embed any Iframe",
|
||||||
|
searchTerms: ["iframe"],
|
||||||
|
icon: IconAppWindow,
|
||||||
|
command: ({ editor, range }: CommandProps) => {
|
||||||
|
editor
|
||||||
|
.chain()
|
||||||
|
.focus()
|
||||||
|
.deleteRange(range)
|
||||||
|
.setEmbed({ provider: "iframe" })
|
||||||
|
.run();
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: "Airtable",
|
title: "Airtable",
|
||||||
description: "Embed Airtable",
|
description: "Embed Airtable",
|
||||||
|
|||||||
@ -104,6 +104,14 @@ export const embedProviders: IEmbedProvider[] = [
|
|||||||
return url;
|
return url;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "iframe",
|
||||||
|
name: "Iframe",
|
||||||
|
regex: /any-iframe/,
|
||||||
|
getEmbedUrl: (match, url) => {
|
||||||
|
return url;
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export function getEmbedProviderById(id: string) {
|
export function getEmbedProviderById(id: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user