@cyberyozh/text-editor 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/editor.d.mts +15 -1
- package/dist/editor.d.ts +15 -1
- package/dist/editor.js +46 -13
- package/dist/editor.js.map +1 -1
- package/dist/editor.mjs +51 -14
- package/dist/editor.mjs.map +1 -1
- package/dist/render.d.mts +9 -1
- package/dist/render.d.ts +9 -1
- package/dist/render.js +40 -10
- package/dist/render.js.map +1 -1
- package/dist/render.mjs +45 -11
- package/dist/render.mjs.map +1 -1
- package/package.json +1 -1
- package/src/editor/editor.tsx +8 -0
- package/src/extensions/base/link.test.ts +60 -0
- package/src/extensions/base/link.ts +61 -9
- package/src/extensions/editor/get-editor-extensions.ts +3 -1
- package/src/utils/get-shared-extensions.ts +20 -4
- package/src/utils/html-to-tiptap-content.ts +13 -4
package/dist/render.mjs
CHANGED
|
@@ -1555,8 +1555,29 @@ var isSameDomain = (url) => {
|
|
|
1555
1555
|
return false;
|
|
1556
1556
|
}
|
|
1557
1557
|
};
|
|
1558
|
+
var isTrustedDomain = (url, trustedDomains) => {
|
|
1559
|
+
try {
|
|
1560
|
+
const { hostname } = new URL(url);
|
|
1561
|
+
if (typeof window !== "undefined" && hostname === window.location.hostname) {
|
|
1562
|
+
return true;
|
|
1563
|
+
}
|
|
1564
|
+
return trustedDomains.some((trusted) => {
|
|
1565
|
+
const domain2 = trusted.toLowerCase();
|
|
1566
|
+
return hostname === domain2 || hostname.endsWith(`.${domain2}`);
|
|
1567
|
+
});
|
|
1568
|
+
} catch {
|
|
1569
|
+
return false;
|
|
1570
|
+
}
|
|
1571
|
+
};
|
|
1558
1572
|
var LinkExtension = Link.extend({
|
|
1573
|
+
addOptions() {
|
|
1574
|
+
return {
|
|
1575
|
+
...this.parent?.() ?? {},
|
|
1576
|
+
trustedDomains: []
|
|
1577
|
+
};
|
|
1578
|
+
},
|
|
1559
1579
|
addAttributes() {
|
|
1580
|
+
const { trustedDomains } = this.options;
|
|
1560
1581
|
return {
|
|
1561
1582
|
...this.parent?.(),
|
|
1562
1583
|
target: {
|
|
@@ -1570,7 +1591,7 @@ var LinkExtension = Link.extend({
|
|
|
1570
1591
|
default: null,
|
|
1571
1592
|
parseHTML: (element) => {
|
|
1572
1593
|
const href = element.getAttribute("href") ?? "";
|
|
1573
|
-
return
|
|
1594
|
+
return isTrustedDomain(href, trustedDomains) ? null : "noopener noreferrer nofollow";
|
|
1574
1595
|
}
|
|
1575
1596
|
}
|
|
1576
1597
|
};
|
|
@@ -1588,15 +1609,20 @@ var LinkExtension = Link.extend({
|
|
|
1588
1609
|
protocols,
|
|
1589
1610
|
defaultProtocol
|
|
1590
1611
|
})
|
|
1591
|
-
).filter(
|
|
1612
|
+
).filter(
|
|
1613
|
+
(link) => this.options.shouldAutoLink?.(link.value) !== false
|
|
1614
|
+
).map((link) => ({
|
|
1615
|
+
text: link.value,
|
|
1616
|
+
data: { href: link.href },
|
|
1617
|
+
index: link.start
|
|
1618
|
+
})),
|
|
1592
1619
|
type: this.type,
|
|
1593
1620
|
getAttributes: (match) => {
|
|
1594
1621
|
const href = match.data?.href ?? "";
|
|
1595
|
-
const sameDomain = isSameDomain(href);
|
|
1596
1622
|
return {
|
|
1597
1623
|
href,
|
|
1598
|
-
target:
|
|
1599
|
-
rel:
|
|
1624
|
+
target: isSameDomain(href) ? "_self" : "_blank",
|
|
1625
|
+
rel: isTrustedDomain(href, this.options.trustedDomains) ? null : "noopener noreferrer nofollow"
|
|
1600
1626
|
};
|
|
1601
1627
|
}
|
|
1602
1628
|
})
|
|
@@ -1611,7 +1637,11 @@ var LinkExtension = Link.extend({
|
|
|
1611
1637
|
if (!view.editable) return false;
|
|
1612
1638
|
const range = getMarkRange(view.state.doc.resolve(pos), this.type);
|
|
1613
1639
|
if (!range) return false;
|
|
1614
|
-
const selection = TextSelection3.create(
|
|
1640
|
+
const selection = TextSelection3.create(
|
|
1641
|
+
view.state.doc,
|
|
1642
|
+
range.from,
|
|
1643
|
+
range.to
|
|
1644
|
+
);
|
|
1615
1645
|
view.dispatch(view.state.tr.setSelection(selection));
|
|
1616
1646
|
return true;
|
|
1617
1647
|
}
|
|
@@ -1962,7 +1992,11 @@ var BaseFigure = Image.extend({
|
|
|
1962
1992
|
|
|
1963
1993
|
// src/utils/get-shared-extensions.ts
|
|
1964
1994
|
import StarterKit from "@tiptap/starter-kit";
|
|
1965
|
-
import {
|
|
1995
|
+
import {
|
|
1996
|
+
Details,
|
|
1997
|
+
DetailsContent,
|
|
1998
|
+
DetailsSummary
|
|
1999
|
+
} from "@tiptap/extension-details";
|
|
1966
2000
|
import Highlight from "@tiptap/extension-highlight";
|
|
1967
2001
|
import Subscript from "@tiptap/extension-subscript";
|
|
1968
2002
|
import Superscript from "@tiptap/extension-superscript";
|
|
@@ -2732,14 +2766,14 @@ var BaseLegacyFigure = Image2.extend({
|
|
|
2732
2766
|
});
|
|
2733
2767
|
|
|
2734
2768
|
// src/utils/get-shared-extensions.ts
|
|
2735
|
-
function getSharedExtensions() {
|
|
2769
|
+
function getSharedExtensions(options = {}) {
|
|
2736
2770
|
return [
|
|
2737
2771
|
StarterKit.configure({
|
|
2738
2772
|
codeBlock: false,
|
|
2739
2773
|
link: false
|
|
2740
2774
|
}),
|
|
2741
2775
|
Highlight.configure({ multicolor: true }),
|
|
2742
|
-
LinkExtension,
|
|
2776
|
+
LinkExtension.configure({ trustedDomains: options.trustedDomains ?? [] }),
|
|
2743
2777
|
Superscript,
|
|
2744
2778
|
Subscript,
|
|
2745
2779
|
TextAlign.configure({
|
|
@@ -3774,7 +3808,7 @@ import { TableKit as TableKit2 } from "@tiptap/extension-table";
|
|
|
3774
3808
|
function isJSONContent(value) {
|
|
3775
3809
|
return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
|
|
3776
3810
|
}
|
|
3777
|
-
function htmlToTiptapContent(content) {
|
|
3811
|
+
function htmlToTiptapContent(content, options = {}) {
|
|
3778
3812
|
if (isJSONContent(content)) {
|
|
3779
3813
|
return content;
|
|
3780
3814
|
}
|
|
@@ -3790,7 +3824,7 @@ function htmlToTiptapContent(content) {
|
|
|
3790
3824
|
if (!content || content.trim() === "") {
|
|
3791
3825
|
return { type: "doc", content: [{ type: "paragraph" }] };
|
|
3792
3826
|
}
|
|
3793
|
-
const sharedExtensions = getSharedExtensions();
|
|
3827
|
+
const sharedExtensions = getSharedExtensions(options);
|
|
3794
3828
|
const extensions = [...sharedExtensions, BaseFigure, TableKit2, BaseCodeBlock];
|
|
3795
3829
|
try {
|
|
3796
3830
|
return generateJSON(content, extensions);
|