Skip to content

Commit

Permalink
fix: allow controls on video html elements in tip tap
Browse files Browse the repository at this point in the history
  • Loading branch information
RitvikSardana committed Oct 29, 2024
1 parent afda3ff commit e6745c4
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 30 deletions.
4 changes: 3 additions & 1 deletion desk/src/components/TextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div class="rounded p-3 shadow">
<FTextEditor
ref="e"
:extensions="[PreserveVideoControls]"
v-bind="$attrs"
editor-class="prose-f max-h-64 max-w-none overflow-auto my-4 min-h-[5rem]"
bubble-menu
Expand Down Expand Up @@ -57,6 +58,7 @@ import { computed, nextTick, ref } from "vue";
import { TextEditor as FTextEditor, TextEditorFixedMenu } from "frappe-ui";
import { useAuthStore } from "@/stores/auth";
import { UserAvatar } from "@/components";
import { PreserveVideoControls } from "@/tiptap-extensions";
interface P {
modelValue: string;
Expand All @@ -65,7 +67,7 @@ interface P {
interface E {
(event: "clear"): void;
(event: "update:modelValue"): string;
(event: "update:modelValue", any): string;
}
const props = withDefaults(defineProps<P>(), {
Expand Down
29 changes: 2 additions & 27 deletions desk/src/pages/KnowledgeBaseArticle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,14 @@ import {
import { createToast } from "@/utils";
import { useAuthStore } from "@/stores/auth";
import { useError } from "@/composables/error";
import { LayoutHeader, PageTitle } from "@/components";
import { LayoutHeader } from "@/components";
import KnowledgeBaseArticleActionsEdit from "./knowledge-base/KnowledgeBaseArticleActionsEdit.vue";
import KnowledgeBaseArticleActionsNew from "./knowledge-base/KnowledgeBaseArticleActionsNew.vue";
import KnowledgeBaseArticleActionsView from "./knowledge-base/KnowledgeBaseArticleActionsView.vue";
import KnowledgeBaseArticleTopEdit from "./knowledge-base/KnowledgeBaseArticleTopEdit.vue";
import KnowledgeBaseArticleTopNew from "./knowledge-base/KnowledgeBaseArticleTopNew.vue";
import KnowledgeBaseArticleTopView from "./knowledge-base/KnowledgeBaseArticleTopView.vue";
import { Extension } from "@tiptap/core";
import { PreserveIds } from "@/tiptap-extensions";
const props = defineProps({
articleId: {
Expand Down Expand Up @@ -390,30 +389,6 @@ const textEditorMenuButtons = [
],
];
// extension to preserve ids in html of headings
const PreserveIds: Extension = Extension.create({
name: "preserveIds",
addGlobalAttributes() {
return [
{
types: ["heading"],
attributes: {
id: {
default: null,
parseHTML: (element) => element.getAttribute("id"),
renderHTML: (attributes) => {
if (!attributes.id) {
return {};
}
return { id: attributes.id };
},
},
},
},
];
},
});
const textEditorContentWithIDs = computed(() =>
article.data?.content ? addLinksToHeadings(article.data?.content) : null
);
Expand Down
7 changes: 6 additions & 1 deletion desk/src/pages/ticket/TicketCommunication.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ withDefaults(defineProps<P>(), {
function sanitize(html: string) {
return sanitizeHtml(html, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img", "video"]),
allowedAttributes: {
a: ["href"],
video: ["src", "controls"],
img: ["src"],
},
});
}
</script>
2 changes: 1 addition & 1 deletion desk/src/pages/ticket/TicketTextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
</template>

<script setup lang="ts">
import { computed, ref } from "vue";
import { FileUploader } from "frappe-ui";
import { Icon } from "@iconify/vue";
import { useAuthStore } from "@/stores/auth";
Expand All @@ -84,7 +85,6 @@ import {
UserAvatar,
} from "@/components";
import { File } from "@/types";
import { computed, ref } from "vue";
interface P {
content: string;
Expand Down
44 changes: 44 additions & 0 deletions desk/src/tiptap-extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Extension } from "@tiptap/core";

export const PreserveVideoControls: Extension = Extension.create({
name: "preserveIds",
addGlobalAttributes() {
return [
{
types: ["video"],
attributes: {
controls: {
default: true,
parseHTML: (element) => element.getAttribute("controls"),
renderHTML: () => {
return { controls: true };
},
},
},
},
];
},
});

export const PreserveIds: Extension = Extension.create({
name: "preserveIds",
addGlobalAttributes() {
return [
{
types: ["heading"],
attributes: {
id: {
default: null,
parseHTML: (element) => element.getAttribute("id"),
renderHTML: (attributes) => {
if (!attributes.id) {
return {};
}
return { id: attributes.id };
},
},
},
},
];
},
});

0 comments on commit e6745c4

Please sign in to comment.