Skip to content

Commit

Permalink
feat: focus extension
Browse files Browse the repository at this point in the history
  • Loading branch information
gbicou committed Apr 20, 2023
1 parent 62541ba commit 3fdeb42
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@semantic-release/git": "^10.0.1",
"@tiptap/core": "^2.0.2",
"@tiptap/extension-character-count": "^2.0.2",
"@tiptap/extension-focus": "^2.0.3",
"@tiptap/extension-highlight": "^2.0.2",
"@tiptap/extension-link": "^2.0.2",
"@tiptap/extension-placeholder": "^2.0.2",
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import StarterKit from "@tiptap/starter-kit";
import type { CharacterCountOptions } from "@tiptap/extension-character-count";
import type { TextAlignOptions } from "@tiptap/extension-text-align";
import type { PlaceholderOptions } from "@tiptap/extension-placeholder";
import type { FocusOptions } from "@tiptap/extension-focus";
import type { DeepPartial, Field } from "@directus/shared/types";
import underline from "./extensions/underline";
import textAlign from "./extensions/text-align";
Expand All @@ -13,13 +14,15 @@ import highlight from "./extensions/highlight";
import typography from "./extensions/typography";
import placeholder from "./extensions/placeholder";
import link from "./extensions/link";
import focus from "./extensions/focus";

interface ExtensionsProps {
extensions: string[] | null;
placeholder: PlaceholderOptions["placeholder"];
characterCountLimit: CharacterCountOptions["limit"];
characterCountMode: CharacterCountOptions["mode"];
textAlignTypes: TextAlignOptions["types"];
focusMode: FocusOptions["mode"];
}

type ExtensionGroup = "mark" | "node" | "editor";
Expand All @@ -45,6 +48,7 @@ export const localExtensions: IExtension<AnyExtension>[] = [
textAlign,
// editor
placeholder,
focus,
typography,
characterCount,
];
Expand Down
43 changes: 43 additions & 0 deletions src/extensions/focus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { IExtension } from "../extensions";
import Focus, { type FocusOptions } from "@tiptap/extension-focus";

const defaults: Partial<FocusOptions> = {
mode: "all",
};

const extension: IExtension<typeof Focus> = {
name: "focus",
title: "Focus",
package: "@tiptap/extension-focus",
group: "editor",
defaults,
options: [
{
field: "focusMode",
name: "Focus mode",
type: "string",
meta: {
interface: "select-dropdown",
width: "half",
note: "Apply the effect to 'all', the 'shallowest' or the 'deepest' node",
options: {
choices: [
{ text: "all", value: "all" },
{ text: "shallowest", value: "shallowest" },
{ text: "deepest", value: "deepest" },
],
},
},
schema: {
default_value: defaults.mode,
},
},
],
load(props) {
return Focus.configure({
mode: props.focusMode ?? defaults.mode,
});
},
};

export default extension;
12 changes: 11 additions & 1 deletion src/tiptap-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,18 @@
height: 0;
pointer-events: none;
}
.has-focus {
border-radius: 3px;
//box-shadow: 0 0 6px 2px var(--background-subdued);
box-shadow: var(--card-shadow);
}
}
}
</style>

<script setup lang="ts">
import { Editor, EditorContent, BubbleMenu } from "@tiptap/vue-3";
import { BubbleMenu, Editor, EditorContent } from "@tiptap/vue-3";
import { onBeforeUnmount, watch } from "vue";
import { useI18n } from "vue-i18n";
import { translateShortcut } from "./utils/translate-shortcut";
Expand Down Expand Up @@ -583,6 +589,8 @@ import characterCount from "./extensions/character-count";
import type { PlaceholderOptions } from "@tiptap/extension-placeholder";
import placeholder from "./extensions/placeholder";
import { useLink } from "./composables/link";
import type { FocusOptions } from "@tiptap/extension-focus";
import focus from "./extensions/focus";
const { t } = useI18n({ messages });
Expand All @@ -597,6 +605,7 @@ interface Props {
textAlignTypes: TextAlignOptions["types"];
characterCountLimit: CharacterCountOptions["limit"];
characterCountMode: CharacterCountOptions["mode"];
focusMode: FocusOptions["mode"];
}
const props = withDefaults(defineProps<Props>(), {
Expand All @@ -608,6 +617,7 @@ const props = withDefaults(defineProps<Props>(), {
textAlignTypes: () => textAlign.defaults.types,
characterCountLimit: () => characterCount.defaults.limit,
characterCountMode: () => characterCount.defaults.mode,
focusMode: () => focus.defaults.mode,
});
const emit = defineEmits<{
Expand Down

0 comments on commit 3fdeb42

Please sign in to comment.