Skip to content

Commit

Permalink
feat: include a custom display rendering content as text
Browse files Browse the repository at this point in the history
  • Loading branch information
gbicou committed Mar 30, 2023
1 parent c936909 commit a99e873
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 10 deletions.
24 changes: 20 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,34 @@
"keywords": [
"directus",
"directus-extension",
"directus-custom-bundle",
"directus-custom-interface",
"directus-custom-display",
"tiptap"
],
"homepage": "https://github.com/gbicou/directus-extension-tiptap",
"author": "Benjamin VIELLARD <[email protected]>",
"license": "MIT",
"repository": "github:gbicou/directus-extension-tiptap",
"directus:extension": {
"type": "interface",
"path": "dist/index.js",
"source": "src/index.ts",
"host": "^9.23.4"
"host": "^9.23.4",
"type": "bundle",
"path": {
"app": "dist/app.js",
"api": "dist/api.js"
},
"entries": [
{
"type": "interface",
"name": "directus-extension-tiptap-interface",
"source": "src/interface.ts"
},
{
"type": "display",
"name": "directus-extension-tiptap-display",
"source": "src/display.ts"
}
]
},
"files": [
"dist"
Expand Down
12 changes: 12 additions & 0 deletions src/display.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineDisplay } from "@directus/extensions-sdk";
import TiptapDisplay from "./tiptap-display.vue";

export default defineDisplay({
id: "tiptap",
name: "TipTap",
icon: "text_fields",
description: "Tip Tap content",
component: TiptapDisplay,
options: null,
types: ["json", "text"],
});
1 change: 1 addition & 0 deletions src/index.ts → src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export default defineInterface({
types: ["json", "text"],
group: "standard",
options: null,
recommendedDisplays: ["tiptap"],
});
26 changes: 26 additions & 0 deletions src/tiptap-display.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
<div>{{ text }}</div>
</template>

<script setup lang="ts">
import { computed } from "vue";
import type { TypeType, ValueType } from "./types";
import { generateText } from "@tiptap/core";
import StarterKit from "@tiptap/starter-kit";
import Underline from "@tiptap/extension-underline";
const props = withDefaults(
defineProps<{
value: ValueType | null;
type: TypeType;
}>(),
{ value: null }
);
const text = computed(() => {
if (props.type === "json") {
return generateText(props.value, [StarterKit, Underline]);
}
return props.value;
});
</script>
11 changes: 5 additions & 6 deletions src/tiptap-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,28 +219,27 @@
</style>

<script setup lang="ts">
import { Editor, EditorContent, HTMLContent, JSONContent } from "@tiptap/vue-3";
import { Editor, EditorContent } from "@tiptap/vue-3";
import StarterKit from "@tiptap/starter-kit";
import Underline from "@tiptap/extension-underline";
import { onBeforeUnmount, watch } from "vue";
import { useI18n } from "vue-i18n";
import { translateShortcut } from "./utils/translate-shortcut";
import type { TypeType, ValueType } from "./types";
const { t } = useI18n();
type ValueType = "json" | "text";
const props = withDefaults(
defineProps<{
value: JSONContent | HTMLContent | null;
type: ValueType;
value: ValueType | null;
type: TypeType;
disabled: boolean;
}>(),
{ value: null, disabled: false }
);
const emit = defineEmits<{
(e: "input", value: JSONContent | HTMLContent): void;
(e: "input", value: ValueType): void;
}>();
const editor = new Editor({
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { HTMLContent, JSONContent } from "@tiptap/vue-3";

export type TypeType = "json" | "text";
export type ValueType = JSONContent | HTMLContent;

0 comments on commit a99e873

Please sign in to comment.