mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 19:57:52 +01:00
Merge pull request #8735 from 01zulfi/editor/restrict-pasting-premium-features
editor: restrict pasting premium features
This commit is contained in:
@@ -42,7 +42,7 @@ export class ClipboardDOMParser extends ProsemirrorDOMParser {
|
|||||||
convertGoogleDocsChecklist(dom);
|
convertGoogleDocsChecklist(dom);
|
||||||
formatCodeblocks(dom);
|
formatCodeblocks(dom);
|
||||||
convertBrToSingleSpacedParagraphs(dom);
|
convertBrToSingleSpacedParagraphs(dom);
|
||||||
removeImages(dom);
|
removePremiumFeatures(dom);
|
||||||
removeBlockId(dom);
|
removeBlockId(dom);
|
||||||
}
|
}
|
||||||
return super.parseSlice(dom, options);
|
return super.parseSlice(dom, options);
|
||||||
@@ -53,7 +53,7 @@ export class ClipboardDOMParser extends ProsemirrorDOMParser {
|
|||||||
convertGoogleDocsChecklist(dom);
|
convertGoogleDocsChecklist(dom);
|
||||||
formatCodeblocks(dom);
|
formatCodeblocks(dom);
|
||||||
convertBrToSingleSpacedParagraphs(dom);
|
convertBrToSingleSpacedParagraphs(dom);
|
||||||
removeImages(dom);
|
removePremiumFeatures(dom);
|
||||||
removeBlockId(dom);
|
removeBlockId(dom);
|
||||||
}
|
}
|
||||||
return super.parse(dom, options);
|
return super.parse(dom, options);
|
||||||
@@ -154,11 +154,29 @@ export function convertGoogleDocsChecklist(dom: HTMLElement | Document) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeImages(dom: HTMLElement | Document) {
|
const premiumFeatures = [
|
||||||
let canInsertImages: boolean | null = null;
|
{
|
||||||
for (const img of dom.querySelectorAll(`img`)) {
|
selector: "div.callout",
|
||||||
canInsertImages = canInsertImages ?? hasPermission("insertImage");
|
permission: "setCallout"
|
||||||
if (!canInsertImages) img.remove();
|
},
|
||||||
|
{
|
||||||
|
selector: 'ul[data-type="outlineList"]',
|
||||||
|
permission: "toggleOutlineList"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
selector: "ul.checklist",
|
||||||
|
permission: "toggleTaskList"
|
||||||
|
}
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
function removePremiumFeatures(dom: HTMLElement | Document) {
|
||||||
|
for (const feature of premiumFeatures) {
|
||||||
|
const elements = dom.querySelectorAll(feature.selector);
|
||||||
|
if (elements.length === 0) continue;
|
||||||
|
|
||||||
|
if (!hasPermission(feature.permission)) {
|
||||||
|
elements.forEach((element) => element.remove());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user