Skip to content

Commit

Permalink
feat: add imports for default extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
modbender committed Dec 7, 2023
1 parent 5ab4595 commit 05c4ca8
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 25 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"scripts": {
"prepack": "nuxt-module-build build",
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"build": "nuxi build playground",
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
"lint": "eslint .",
Expand All @@ -29,9 +29,12 @@
},
"dependencies": {
"@nuxt/kit": "^3.8.2",
"@tiptap/extension-code-block-lowlight": "^2.1.13",
"@tiptap/extension-link": "^2.1.13",
"@tiptap/pm": "^2.1.13",
"@tiptap/starter-kit": "^2.1.13",
"@tiptap/vue-3": "^2.1.13"
"@tiptap/vue-3": "^2.1.13",
"lowlight": "^3.1.0"
},
"devDependencies": {
"@nuxt/devtools": "latest",
Expand All @@ -45,4 +48,4 @@
"nuxt": "^3.8.2",
"vitest": "^0.33.0"
}
}
}
45 changes: 45 additions & 0 deletions src/imports/defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export const defaultNodes = [
{ name: "Blockquote", path: "@tiptap/extension-blockquote" },
{ name: "BulletList", path: "@tiptap/extension-bullet-list" },
{ name: "OrderedList", path: "@tiptap/extension-ordered-list" },
{ name: "ListItem", path: "@tiptap/extension-list-item" },
{ name: "CodeBlock", path: "@tiptap/extension-code-block" },
{ name: "Document", path: "@tiptap/extension-document" },
{ name: "HardBreak", path: "@tiptap/extension-hard-break" },
{ name: "Heading", path: "@tiptap/extension-heading" },
{ name: "HorizontalRule", path: "@tiptap/extension-horizontal-rule" },
{ name: "Paragraph", path: "@tiptap/extension-paragraph" },
{ name: "Text", path: "@tiptap/extension-text" },
];

export const defaultMarks = [
{ name: "Bold", path: "@tiptap/extension-bold" },
{ name: "Code", path: "@tiptap/extension-code" },
{ name: "Italic", path: "@tiptap/extension-italic" },
{ name: "Link", path: "@tiptap/extension-link" },
{ name: "Strike", path: "@tiptap/extension-strike" },
];

export const defaultExtensions = [
{ name: "StarterKit", path: "@tiptap/starter-kit" },
{ name: "BubbleMenu", path: "@tiptap/extension-bubble-menu" },
{ name: "Gapcursor", path: "@tiptap/extension-gapcursor" },
{ name: "FloatingMenu", path: "@tiptap/extension-floating-menu" },
{ name: "Dropcursor", path: "@tiptap/extension-dropcursor" },
{ name: "History", path: "@tiptap/extension-history" },
];

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

...defaultNodes,
...defaultMarks,
...defaultExtensions,
];

export const defaultComponents = [
{ name: "EditorContent", path: "@tiptap/vue-3" },
{ name: "FloatingMenu", path: "@tiptap/vue-3" },
{ name: "BubbleMenu", path: "@tiptap/vue-3" },
];
2 changes: 2 additions & 0 deletions src/imports/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./defaults";
export * from "./optional";
7 changes: 7 additions & 0 deletions src/imports/optional.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const lowlightImports = [
{ name: "lowlight ", path: "lowlight" },
{ name: "CodeBlock", path: "@tiptap/extension-code-block" },
];

export const optionalImports: {[key: string]: any}[] = [];
export const optionalComponents: {[key: string]: any}[] = [];
68 changes: 46 additions & 22 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import {
defineNuxtModule,
addImports,
addComponent,
createResolver,
} from "@nuxt/kit";
import { defineNuxtModule, addImports, addComponent } from "@nuxt/kit";

import { name, version } from "../package.json";

const defaultImports = [
{ name: "Editor", path: "@tiptap/vue-3" },
{ name: "useEditor", path: "@tiptap/vue-3" },
{ name: "StarterKit", path: "@tiptap/starter-kit" },
];

const defaultComponents = [
{ name: "EditorContent", path: "@tiptap/vue-3" },
{ name: "FloatingMenu", path: "@tiptap/vue-3" },
{ name: "BubbleMenu", path: "@tiptap/vue-3" },
];
import * as allImports from "./imports";

// Module options TypeScript interface definition
export interface ModuleOptions {}

export interface ModuleOptions {
/**
* Determine if lowlight should be enabled
*
* @default false
*/
lowlight?:
| boolean
| {
/**
* Determine if lowlight should be enabled
*
* @default false
*/
enabled: boolean;
/**
* Languages to be loaded for highlighting
*
*/
languages: string[];
};
}

export default defineNuxtModule<ModuleOptions>({
meta: {
Expand All @@ -32,7 +39,9 @@ export default defineNuxtModule<ModuleOptions>({
},
},
// Default configuration options of the Nuxt module
defaults: {},
defaults: {
lowlight: false,
},
async setup(options, nuxt) {
// const { resolve } = createResolver(import.meta.url);

Expand All @@ -42,20 +51,35 @@ export default defineNuxtModule<ModuleOptions>({

// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`

for (const obj of defaultImports) {
for (const obj of allImports.defaultImports) {
addImports({
as: obj.name,
name: obj.name,
from: obj.path,
// _internal_install: obj.path,
});
}

for (const obj of defaultComponents) {
for (const obj of allImports.defaultComponents) {
addComponent({
mode: "client",
name: obj.name,
export: obj.name,
filePath: obj.path,
mode: "client",
// _internal_install: obj.path,
});
}

if (options.lowlight === false) {
allImports.optionalImports.push(...allImports.lowlightImports);
}

for (const obj of allImports.optionalImports) {
addImports({
as: obj.name,
name: obj.name,
from: obj.path,
// _internal_install: obj.path,
});
}
},
Expand Down
55 changes: 55 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,11 @@
resolved "https://registry.yarnpkg.com/@tiptap/extension-bullet-list/-/extension-bullet-list-2.1.13.tgz#0a26731ebf98ddfd268884ff1712f7189be7b63c"
integrity sha512-NkWlQ5bLPUlcROj6G/d4oqAxMf3j3wfndGOPp0z8OoXJtVbVoXl/aMSlLbVgE6n8r6CS8MYxKhXNxrb7Ll2foA==

"@tiptap/extension-code-block-lowlight@^2.1.13":
version "2.1.13"
resolved "https://registry.yarnpkg.com/@tiptap/extension-code-block-lowlight/-/extension-code-block-lowlight-2.1.13.tgz#91110f44d6cc8a12d95ac92aee0c848fdedefb0d"
integrity sha512-PlU0lzAEbUGqPykl7fYqlAiY7/zFRtQExsbrpi2kctSIzxC+jgMM4vEpWxLS4jZEXl7jVHvBRH6lRNINDHWmQA==

"@tiptap/extension-code-block@^2.1.13":
version "2.1.13"
resolved "https://registry.yarnpkg.com/@tiptap/extension-code-block/-/extension-code-block-2.1.13.tgz#3e441d171d3ed821e67291dbf4cbad7e2ea29809"
Expand Down Expand Up @@ -1468,6 +1473,13 @@
resolved "https://registry.yarnpkg.com/@tiptap/extension-italic/-/extension-italic-2.1.13.tgz#1e9521dea002c8d6de833d9fd928d4617623eab8"
integrity sha512-HyDJfuDn5hzwGKZiANcvgz6wcum6bEgb4wmJnfej8XanTMJatNVv63TVxCJ10dSc9KGpPVcIkg6W8/joNXIEbw==

"@tiptap/extension-link@^2.1.13":
version "2.1.13"
resolved "https://registry.yarnpkg.com/@tiptap/extension-link/-/extension-link-2.1.13.tgz#ae4abd7c43292e3a1841488bfc7a687b2f014249"
integrity sha512-wuGMf3zRtMHhMrKm9l6Tft5M2N21Z0UP1dZ5t1IlOAvOeYV2QZ5UynwFryxGKLO0NslCBLF/4b/HAdNXbfXWUA==
dependencies:
linkifyjs "^4.1.0"

"@tiptap/extension-list-item@^2.1.13":
version "2.1.13"
resolved "https://registry.yarnpkg.com/@tiptap/extension-list-item/-/extension-list-item-2.1.13.tgz#3c62127df97974f3196866ec00ee397f4c9acdc4"
Expand Down Expand Up @@ -1585,6 +1597,13 @@
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4"
integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==

"@types/hast@^3.0.0":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/hast/-/hast-3.0.3.tgz#7f75e6b43bc3f90316046a287d9ad3888309f7e1"
integrity sha512-2fYGlaDy/qyLlhidX42wAH0KBi2TCjKMH8CHmBXgRlJ3Y+OXTiqsPQ6IWarZKwF1JoUcAJdPogv1d4b0COTpmQ==
dependencies:
"@types/unist" "*"

"@types/http-proxy@^1.17.14":
version "1.17.14"
resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.14.tgz#57f8ccaa1c1c3780644f8a94f9c6b5000b5e2eec"
Expand Down Expand Up @@ -1629,6 +1648,11 @@
resolved "https://registry.yarnpkg.com/@types/throttle-debounce/-/throttle-debounce-2.1.0.tgz#1c3df624bfc4b62f992d3012b84c56d41eab3776"
integrity sha512-5eQEtSCoESnh2FsiLTxE121IiE60hnMqcb435fShf4bpLRjEu1Eoekht23y6zXS9Ts3l+Szu3TARnTsA0GkOkQ==

"@types/unist@*":
version "3.0.2"
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-3.0.2.tgz#6dd61e43ef60b34086287f83683a5c1b2dc53d20"
integrity sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==

"@typescript-eslint/eslint-plugin@^6.5.0":
version "6.13.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.13.1.tgz#f98bd887bf95551203c917e734d113bf8d527a0c"
Expand Down Expand Up @@ -2803,6 +2827,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df"
integrity sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==

dequal@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/dequal/-/dequal-2.0.3.tgz#2644214f1997d39ed0ee0ece72335490a7ac67be"
integrity sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==

destr@^2.0.0, destr@^2.0.1, destr@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/destr/-/destr-2.0.2.tgz#8d3c0ee4ec0a76df54bc8b819bca215592a8c218"
Expand All @@ -2828,6 +2857,13 @@ devalue@^4.3.2:
resolved "https://registry.yarnpkg.com/devalue/-/devalue-4.3.2.tgz#cc44e4cf3872ac5a78229fbce3b77e57032727b5"
integrity sha512-KqFl6pOgOW+Y6wJgu80rHpo2/3H07vr8ntR9rkkFIRETewbf5GaYYcakYfiKz89K+sLsuPkQIZaXDMjUObZwWg==

devlop@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/devlop/-/devlop-1.1.0.tgz#4db7c2ca4dc6e0e834c30be70c94bbc976dc7018"
integrity sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==
dependencies:
dequal "^2.0.0"

diff-sequences@^29.4.3:
version "29.6.3"
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-29.6.3.tgz#4deaf894d11407c51efc8418012f9e70b84ea921"
Expand Down Expand Up @@ -3608,6 +3644,11 @@ hasown@^2.0.0:
dependencies:
function-bind "^1.1.2"

highlight.js@~11.9.0:
version "11.9.0"
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-11.9.0.tgz#04ab9ee43b52a41a047432c8103e2158a1b8b5b0"
integrity sha512-fJ7cW7fQGCYAkgv4CPfwFHrfd/cLS4Hau96JuJ+ZTOWhjnhoeN1ub1tFmALm/+lW5z4WCAuAV9bm05AP0mS6Gw==

hookable@^5.5.3:
version "5.5.3"
resolved "https://registry.yarnpkg.com/hookable/-/hookable-5.5.3.tgz#6cfc358984a1ef991e2518cb9ed4a778bbd3215d"
Expand Down Expand Up @@ -4080,6 +4121,11 @@ linkify-it@^4.0.1:
dependencies:
uc.micro "^1.0.1"

linkifyjs@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/linkifyjs/-/linkifyjs-4.1.3.tgz#0edbc346428a7390a23ea2e5939f76112c9ae07f"
integrity sha512-auMesunaJ8yfkHvK4gfg1K0SaKX/6Wn9g2Aac/NwX+l5VdmFZzo/hdPGxEOETj+ryRa4/fiOPjeeKURSAJx1sg==

listhen@^1.5.5:
version "1.5.5"
resolved "https://registry.yarnpkg.com/listhen/-/listhen-1.5.5.tgz#58915512af70f770aa3e9fb19367adf479bb58c4"
Expand Down Expand Up @@ -4170,6 +4216,15 @@ loupe@^2.3.6:
dependencies:
get-func-name "^2.0.1"

lowlight@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lowlight/-/lowlight-3.1.0.tgz#aa394c5f3a7689fce35fa49a7c850ba3ead4f590"
integrity sha512-CEbNVoSikAxwDMDPjXlqlFYiZLkDJHwyGu/MfOsJnF3d7f3tds5J3z8s/l9TMXhzfsJCCJEAsD78842mwmg0PQ==
dependencies:
"@types/hast" "^3.0.0"
devlop "^1.0.0"
highlight.js "~11.9.0"

lru-cache@^10.0.1, lru-cache@^10.0.2, "lru-cache@^9.1.1 || ^10.0.0":
version "10.1.0"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.1.0.tgz#2098d41c2dc56500e6c88584aa656c84de7d0484"
Expand Down

0 comments on commit 05c4ca8

Please sign in to comment.