Skip to content

Commit

Permalink
Merge pull request #80 from useplunk/75-pasting-an-link-with-a-templa…
Browse files Browse the repository at this point in the history
…te-tag-breaks-the-template

Added proper handling for pasted links in Plunk editor
  • Loading branch information
driaug authored Sep 7, 2024
2 parents 02085e7 + de51eb9 commit b373827
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 38 deletions.
74 changes: 36 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
{
"name": "plunk",
"version": "1.0.3",
"private": true,
"license": "agpl-3.0",
"workspaces": {
"packages": [
"packages/*"
]
},
"engines": {
"npm": ">=6.14.x",
"yarn": "1.22.x",
"node": ">=18.x"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"lerna": "^8.1.6",
"prisma": "^5.17.0",
"rimraf": "^5.0.9"
},
"dependencies": {
"@prisma/client": "^5.17.0"
},
"scripts": {
"dev:api": "yarn workspace @plunk/api dev",
"dev:dashboard": "yarn workspace @plunk/dashboard dev",
"dev:shared": "yarn workspace @plunk/shared dev",
"build:api": "yarn build:shared && yarn workspace @plunk/api build",
"build:dashboard": "yarn build:shared && yarn workspace @plunk/dashboard build",
"build:shared": "yarn generate && yarn workspace @plunk/shared build",
"clean": "rimraf node_modules yarn.lock && yarn add lerna -DW && lerna run clean",
"preinstall": "node tools/preinstall.js",
"migrate": "prisma migrate dev",
"migrate:deploy": "prisma migrate deploy",
"generate": "prisma generate",
"services:up": "docker compose -f docker-compose.dev.yml up -d",
"services:down": "docker compose -f docker-compose.dev.yml down"
}
"name": "plunk",
"version": "1.0.4",
"private": true,
"license": "agpl-3.0",
"workspaces": {
"packages": ["packages/*"]
},
"engines": {
"npm": ">=6.14.x",
"yarn": "1.22.x",
"node": ">=18.x"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"lerna": "^8.1.6",
"prisma": "^5.17.0",
"rimraf": "^5.0.9"
},
"dependencies": {
"@prisma/client": "^5.17.0"
},
"scripts": {
"dev:api": "yarn workspace @plunk/api dev",
"dev:dashboard": "yarn workspace @plunk/dashboard dev",
"dev:shared": "yarn workspace @plunk/shared dev",
"build:api": "yarn build:shared && yarn workspace @plunk/api build",
"build:dashboard": "yarn build:shared && yarn workspace @plunk/dashboard build",
"build:shared": "yarn generate && yarn workspace @plunk/shared build",
"clean": "rimraf node_modules yarn.lock && yarn add lerna -DW && lerna run clean",
"preinstall": "node tools/preinstall.js",
"migrate": "prisma migrate dev",
"migrate:deploy": "prisma migrate deploy",
"generate": "prisma generate",
"services:up": "docker compose -f docker-compose.dev.yml up -d",
"services:down": "docker compose -f docker-compose.dev.yml down"
}
}
16 changes: 16 additions & 0 deletions packages/dashboard/src/components/Input/MarkdownEditor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ export default function Editor({ value, onChange, mode, modeSwitcher }: Markdown
keydown: (_view, event) => {
return event.key === "Enter" && !event.shiftKey;
},
paste: (view, event) => {
const text = event.clipboardData?.getData("text");
const urlPattern = /^(https?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*({{[\w-]+}})?)*$/;

if (editor && text && urlPattern.test(text)) {
event.preventDefault();
editor
.chain()
.focus()
.extendMarkRange("link")
.setLink({ href: text.startsWith("http") ? text : `https://${text}`, target: "_blank" })
.run();
editor.commands.insertContent(text);
}
return true;
},
},
},
onUpdate: ({ editor }) => {
Expand Down

0 comments on commit b373827

Please sign in to comment.