Skip to content

Commit

Permalink
feat: add core imports Node and Mark
Browse files Browse the repository at this point in the history
  • Loading branch information
modbender committed Dec 7, 2023
1 parent 9de8e84 commit b638a19
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/imports/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export const defaultComposables = [
{ name: "useEditor", path: "@tiptap/vue-3" },
];

export const defaultNodes = [
{ name: "Node", path: "@tiptap/core" },
{ name: "Blockquote", path: "@tiptap/extension-blockquote" },
{ name: "BulletList", path: "@tiptap/extension-bullet-list" },
{ name: "OrderedList", path: "@tiptap/extension-ordered-list" },
Expand All @@ -13,6 +18,7 @@ export const defaultNodes = [
];

export const defaultMarks = [
{ name: "Mark", path: "@tiptap/core" },
{ name: "Bold", path: "@tiptap/extension-bold" },
{ name: "Code", path: "@tiptap/extension-code" },
{ name: "Italic", path: "@tiptap/extension-italic" },
Expand All @@ -21,6 +27,7 @@ export const defaultMarks = [
];

export const defaultExtensions = [
{ name: "Extension", path: "@tiptap/core" },
{ name: "StarterKit", path: "@tiptap/starter-kit" },
{ name: "BubbleMenu", path: "@tiptap/extension-bubble-menu" },
{ name: "Gapcursor", path: "@tiptap/extension-gapcursor" },
Expand All @@ -31,7 +38,6 @@ export const defaultExtensions = [

export const defaultImports = [
{ name: "Editor", path: "@tiptap/vue-3" },
{ name: "useEditor", path: "@tiptap/vue-3" },

...defaultNodes,
...defaultMarks,
Expand All @@ -42,4 +48,4 @@ export const defaultComponents = [
{ name: "EditorContent", path: "@tiptap/vue-3" },
{ name: "FloatingMenu", path: "@tiptap/vue-3" },
{ name: "BubbleMenu", path: "@tiptap/vue-3" },
];
];
30 changes: 26 additions & 4 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import * as allImports from "./imports";
// Module options TypeScript interface definition

export interface ModuleOptions {
/**
* Prefix for imported elements
*
* @default 'TipTap'
*/
prefix: string;
/**
* Determine if lowlight should be enabled
*
Expand Down Expand Up @@ -40,24 +46,33 @@ export default defineNuxtModule<ModuleOptions>({
},
// Default configuration options of the Nuxt module
defaults: {
prefix: "Tiptap",
lowlight: false,
},
async setup(options, nuxt) {
// const { resolve } = createResolver(import.meta.url);

nuxt.options.build.transpile.push("@tiptap/vue-3");
nuxt.options.build.transpile.push("@tiptap/starter-kit");
nuxt.options.build.transpile.push("@tiptap/pm");
const transpileModules = new Set<string>([]);

// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
for (const obj of allImports.defaultComposables) {
addImports({
as: obj.name,
name: obj.name,
from: obj.path,
// _internal_install: obj.path,
});
transpileModules.add(obj.path);
}

for (const obj of allImports.defaultImports) {
addImports({
as: obj.name,
as: `${options.prefix}${obj.name}`,
name: obj.name,
from: obj.path,
// _internal_install: obj.path,
});
transpileModules.add(obj.path);
}

for (const obj of allImports.defaultComponents) {
Expand All @@ -68,6 +83,7 @@ export default defineNuxtModule<ModuleOptions>({
filePath: obj.path,
// _internal_install: obj.path,
});
transpileModules.add(obj.path);
}

if (options.lowlight === false) {
Expand All @@ -81,6 +97,12 @@ export default defineNuxtModule<ModuleOptions>({
from: obj.path,
// _internal_install: obj.path,
});
transpileModules.add(obj.path);
}

nuxt.options.build.transpile = [
...nuxt.options.build.transpile,
...transpileModules,
];
},
});

0 comments on commit b638a19

Please sign in to comment.