Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: add support for youtube videos

Brad Barbinc49883a8c66e
diff --git a/apps/erp/app/styles/tailwind.css b/apps/erp/app/styles/tailwind.css
index 73a3ebb845..6f1bb83c09 100644
--- a/apps/erp/app/styles/tailwind.css
+++ b/apps/erp/app/styles/tailwind.css
@@ -114,8 +114,8 @@ p.is-editor-empty:first-child:before {
pointer-events: none;
}
-.tiptap.ProseMirror-focused div[data-loom-video],
-.tiptap.ProseMirror-selectedNode div[data-loom-video] {
+.tiptap.ProseMirror-focused div[data-video-embed],
+.tiptap.ProseMirror-selectedNode div[data-video-embed] {
@apply ring-2 ring-primary cursor-move p-2 rounded-lg;
}
diff --git a/apps/mes/app/styles/tailwind.css b/apps/mes/app/styles/tailwind.css
index 11d77ac675..6fe9d70921 100644
--- a/apps/mes/app/styles/tailwind.css
+++ b/apps/mes/app/styles/tailwind.css
@@ -115,3 +115,8 @@ p.is-editor-empty:first-child:before {
.loading-dot:nth-child(3) {
animation-delay: 0.4s;
}
+
+.tiptap.ProseMirror-focused div[data-video-embed],
+.tiptap.ProseMirror-selectedNode div[data-video-embed] {
+ @apply ring-2 ring-primary cursor-move p-2 rounded-lg;
+}
diff --git a/apps/starter/app/styles/tailwind.css b/apps/starter/app/styles/tailwind.css
index 4d2651dae8..2cbbecb4f4 100644
--- a/apps/starter/app/styles/tailwind.css
+++ b/apps/starter/app/styles/tailwind.css
@@ -103,7 +103,7 @@ p.is-editor-empty:first-child:before {
pointer-events: none;
}
-.tiptap.ProseMirror-focused div[data-loom-video],
-.tiptap.ProseMirror-selectedNode div[data-loom-video] {
+.tiptap.ProseMirror-focused div[data-video-embed],
+.tiptap.ProseMirror-selectedNode div[data-video-embed] {
@apply ring-2 ring-primary cursor-move p-2 rounded-lg;
}
diff --git a/package-lock.json b/package-lock.json
index 097ab23962..4fd03d9301 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -35784,9 +35784,10 @@
"@tiptap/extension-list-item": "^2.0.4",
"@tiptap/extension-table": "^2.0.4",
"@tiptap/extension-table-cell": "^2.0.3",
- "@tiptap/extension-table-header": "^2.0.3",
+ "@tiptap/extension-table-header": "^2.4.0",
"@tiptap/extension-table-row": "^2.0.3",
"@tiptap/extension-text-style": "^2.0.3",
+ "@tiptap/extension-youtube": "^2.0.3",
"@tiptap/pm": "2.0.4",
"@tiptap/react": "^2.0.4",
"@tiptap/starter-kit": "^2.0.4",
diff --git a/packages/react/package.json b/packages/react/package.json
index 10d2451bde..a91eea9929 100644
--- a/packages/react/package.json
+++ b/packages/react/package.json
@@ -42,9 +42,10 @@
"@tiptap/extension-list-item": "^2.0.4",
"@tiptap/extension-table": "^2.0.4",
"@tiptap/extension-table-cell": "^2.0.3",
- "@tiptap/extension-table-header": "^2.0.3",
+ "@tiptap/extension-table-header": "^2.4.0",
"@tiptap/extension-table-row": "^2.0.3",
"@tiptap/extension-text-style": "^2.0.3",
+ "@tiptap/extension-youtube": "^2.0.3",
"@tiptap/pm": "2.0.4",
"@tiptap/react": "^2.0.4",
"@tiptap/starter-kit": "^2.0.4",
diff --git a/packages/react/src/Editor/extensions.ts b/packages/react/src/Editor/extensions.ts
index 53f2058eeb..972d472c88 100644
--- a/packages/react/src/Editor/extensions.ts
+++ b/packages/react/src/Editor/extensions.ts
@@ -18,8 +18,10 @@ import {
} from "novel/extensions";
import { UploadImagesPlugin } from "novel/plugins";
-// Loom video regex pattern
+// Video regex patterns
const LOOM_REGEX = /https:\/\/www\.loom\.com\/share\/([a-zA-Z0-9]+)/;
+const YOUTUBE_REGEX =
+ /https:\/\/(?:www\.youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9]+)/;
// Custom node for HTML content
const HTMLContent = Node.create({
@@ -34,20 +36,23 @@ const HTMLContent = Node.create({
html: {
default: "",
},
+ type: {
+ default: "loom", // or "youtube"
+ },
};
},
parseHTML() {
return [
{
- tag: "div[data-loom-video]",
+ tag: "div[data-video-embed]",
},
];
},
renderHTML({ node }) {
const container = document.createElement("div");
- container.setAttribute("data-loom-video", "true");
+ container.setAttribute("data-video-embed", node.attrs.type);
container.setAttribute("tabindex", "0");
container.className =
"focus:ring-2 focus:ring-primary hover:bg-zinc-200 dark:hover:bg-zinc-800 p-2 border bg-zinc-100 dark:bg-zinc-900 cursor-move rounded-lg";
@@ -56,27 +61,40 @@ const HTMLContent = Node.create({
},
});
-const LoomEmbed = Extension.create({
- name: "loomEmbed",
+const VideoEmbed = Extension.create({
+ name: "videoEmbed",
addProseMirrorPlugins() {
return [
new Plugin({
- key: new PluginKey("loomEmbed"),
+ key: new PluginKey("videoEmbed"),
props: {
handlePaste: (view, event) => {
const text = event.clipboardData?.getData("text/plain");
if (!text) return false;
- const match = text.match(LOOM_REGEX);
- if (!match) return false;
+ const loomMatch = text.match(LOOM_REGEX);
+ const youtubeMatch = text.match(YOUTUBE_REGEX);
+
+ if (!loomMatch && !youtubeMatch) return false;
- const [, videoId] = match;
- const embedHtml = `<div><div style="position: relative; padding-bottom: 62.5%; height: 0;"><iframe src="https://www.loom.com/embed/${videoId}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div></div>`;
+ let embedHtml = "";
+ let videoType = "";
+
+ if (loomMatch) {
+ const [, videoId] = loomMatch;
+ videoType = "loom";
+ embedHtml = `<div><div style="position: relative; padding-bottom: 62.5%; height: 0;"><iframe src="https://www.loom.com/embed/${videoId}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div></div>`;
+ } else if (youtubeMatch) {
+ const [, videoId] = youtubeMatch;
+ videoType = "youtube";
+ embedHtml = `<div><div style="position: relative; padding-bottom: 56.25%; height: 0;"><iframe src="https://www.youtube.com/embed/${videoId}" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div></div>`;
+ }
// Create an HTML content node
const node = view.state.schema.nodes.htmlContent.create({
html: embedHtml,
+ type: videoType,
});
const transaction = view.state.tr.replaceSelectionWith(node);
view.dispatch(transaction);
@@ -210,7 +228,7 @@ export const defaultExtensions = [
taskItem,
horizontalRule,
aiHighlight,
- LoomEmbed,
+ VideoEmbed,
HTMLContent,
Table,
TableCell,