@cyberyozh/text-editor 0.3.2 → 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.css +35 -43
- package/dist/editor.css.map +1 -1
- package/dist/editor.d.mts +20 -2
- package/dist/editor.d.ts +20 -2
- package/dist/editor.js +397 -327
- package/dist/editor.js.map +1 -1
- package/dist/editor.mjs +320 -246
- 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/dist/styles/index.css +35 -43
- package/package.json +1 -1
- package/src/editor/components/dialog-error/dialog-error.css +35 -0
- package/src/editor/components/dialog-error/dialog-error.tsx +65 -0
- package/src/editor/components/dialog-error/index.ts +1 -0
- package/src/editor/components/index.ts +1 -0
- package/src/editor/dialogs/add-link-dialog/add-link-dialog.css +0 -9
- package/src/editor/dialogs/add-link-dialog/add-link-dialog.tsx +2 -2
- package/src/editor/dialogs/add-video-dialog/add-video-dialog.css +0 -9
- package/src/editor/dialogs/add-video-dialog/add-video-dialog.tsx +2 -2
- package/src/editor/dialogs/image-dialog/image-dialog.css +1 -29
- package/src/editor/dialogs/image-dialog/image-dialog.tsx +7 -13
- package/src/editor/editor.tsx +8 -0
- package/src/editor/index.ts +1 -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/styles/components.css +1 -0
- package/src/translations/en.json +4 -4
- package/src/translations/ru.json +4 -4
- package/src/types/common.ts +3 -0
- package/src/types/index.ts +1 -0
- package/src/utils/get-shared-extensions.ts +20 -4
- package/src/utils/html-to-tiptap-content.ts +13 -4
- package/src/utils/index.ts +1 -0
- package/src/utils/is-combined-error.ts +9 -0
package/dist/render.d.mts
CHANGED
|
@@ -56,6 +56,14 @@ interface TiptapRenderProps {
|
|
|
56
56
|
*/
|
|
57
57
|
declare function TiptapRender({ content, getImageById }: TiptapRenderProps): ReactNode;
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
interface SharedExtensionsOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Domains (with all their subdomains) whose links are treated as internal —
|
|
62
|
+
* see the trustedDomains option of LinkExtension.
|
|
63
|
+
*/
|
|
64
|
+
trustedDomains?: string[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare function htmlToTiptapContent(content: string | JSONContent$1, options?: SharedExtensionsOptions): JSONContent$1;
|
|
60
68
|
|
|
61
69
|
export { TiptapRender, htmlToTiptapContent };
|
package/dist/render.d.ts
CHANGED
|
@@ -56,6 +56,14 @@ interface TiptapRenderProps {
|
|
|
56
56
|
*/
|
|
57
57
|
declare function TiptapRender({ content, getImageById }: TiptapRenderProps): ReactNode;
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
interface SharedExtensionsOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Domains (with all their subdomains) whose links are treated as internal —
|
|
62
|
+
* see the trustedDomains option of LinkExtension.
|
|
63
|
+
*/
|
|
64
|
+
trustedDomains?: string[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare function htmlToTiptapContent(content: string | JSONContent$1, options?: SharedExtensionsOptions): JSONContent$1;
|
|
60
68
|
|
|
61
69
|
export { TiptapRender, htmlToTiptapContent };
|
package/dist/render.js
CHANGED
|
@@ -1592,8 +1592,29 @@ var isSameDomain = (url) => {
|
|
|
1592
1592
|
return false;
|
|
1593
1593
|
}
|
|
1594
1594
|
};
|
|
1595
|
+
var isTrustedDomain = (url, trustedDomains) => {
|
|
1596
|
+
try {
|
|
1597
|
+
const { hostname } = new URL(url);
|
|
1598
|
+
if (typeof window !== "undefined" && hostname === window.location.hostname) {
|
|
1599
|
+
return true;
|
|
1600
|
+
}
|
|
1601
|
+
return trustedDomains.some((trusted) => {
|
|
1602
|
+
const domain2 = trusted.toLowerCase();
|
|
1603
|
+
return hostname === domain2 || hostname.endsWith(`.${domain2}`);
|
|
1604
|
+
});
|
|
1605
|
+
} catch {
|
|
1606
|
+
return false;
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1595
1609
|
var LinkExtension = import_extension_link.default.extend({
|
|
1610
|
+
addOptions() {
|
|
1611
|
+
return {
|
|
1612
|
+
...this.parent?.() ?? {},
|
|
1613
|
+
trustedDomains: []
|
|
1614
|
+
};
|
|
1615
|
+
},
|
|
1596
1616
|
addAttributes() {
|
|
1617
|
+
const { trustedDomains } = this.options;
|
|
1597
1618
|
return {
|
|
1598
1619
|
...this.parent?.(),
|
|
1599
1620
|
target: {
|
|
@@ -1607,7 +1628,7 @@ var LinkExtension = import_extension_link.default.extend({
|
|
|
1607
1628
|
default: null,
|
|
1608
1629
|
parseHTML: (element) => {
|
|
1609
1630
|
const href = element.getAttribute("href") ?? "";
|
|
1610
|
-
return
|
|
1631
|
+
return isTrustedDomain(href, trustedDomains) ? null : "noopener noreferrer nofollow";
|
|
1611
1632
|
}
|
|
1612
1633
|
}
|
|
1613
1634
|
};
|
|
@@ -1625,15 +1646,20 @@ var LinkExtension = import_extension_link.default.extend({
|
|
|
1625
1646
|
protocols,
|
|
1626
1647
|
defaultProtocol
|
|
1627
1648
|
})
|
|
1628
|
-
).filter(
|
|
1649
|
+
).filter(
|
|
1650
|
+
(link) => this.options.shouldAutoLink?.(link.value) !== false
|
|
1651
|
+
).map((link) => ({
|
|
1652
|
+
text: link.value,
|
|
1653
|
+
data: { href: link.href },
|
|
1654
|
+
index: link.start
|
|
1655
|
+
})),
|
|
1629
1656
|
type: this.type,
|
|
1630
1657
|
getAttributes: (match) => {
|
|
1631
1658
|
const href = match.data?.href ?? "";
|
|
1632
|
-
const sameDomain = isSameDomain(href);
|
|
1633
1659
|
return {
|
|
1634
1660
|
href,
|
|
1635
|
-
target:
|
|
1636
|
-
rel:
|
|
1661
|
+
target: isSameDomain(href) ? "_self" : "_blank",
|
|
1662
|
+
rel: isTrustedDomain(href, this.options.trustedDomains) ? null : "noopener noreferrer nofollow"
|
|
1637
1663
|
};
|
|
1638
1664
|
}
|
|
1639
1665
|
})
|
|
@@ -1648,7 +1674,11 @@ var LinkExtension = import_extension_link.default.extend({
|
|
|
1648
1674
|
if (!view.editable) return false;
|
|
1649
1675
|
const range = (0, import_core4.getMarkRange)(view.state.doc.resolve(pos), this.type);
|
|
1650
1676
|
if (!range) return false;
|
|
1651
|
-
const selection = import_state3.TextSelection.create(
|
|
1677
|
+
const selection = import_state3.TextSelection.create(
|
|
1678
|
+
view.state.doc,
|
|
1679
|
+
range.from,
|
|
1680
|
+
range.to
|
|
1681
|
+
);
|
|
1652
1682
|
view.dispatch(view.state.tr.setSelection(selection));
|
|
1653
1683
|
return true;
|
|
1654
1684
|
}
|
|
@@ -2769,14 +2799,14 @@ var BaseLegacyFigure = import_extension_image2.default.extend({
|
|
|
2769
2799
|
});
|
|
2770
2800
|
|
|
2771
2801
|
// src/utils/get-shared-extensions.ts
|
|
2772
|
-
function getSharedExtensions() {
|
|
2802
|
+
function getSharedExtensions(options = {}) {
|
|
2773
2803
|
return [
|
|
2774
2804
|
import_starter_kit.default.configure({
|
|
2775
2805
|
codeBlock: false,
|
|
2776
2806
|
link: false
|
|
2777
2807
|
}),
|
|
2778
2808
|
import_extension_highlight.default.configure({ multicolor: true }),
|
|
2779
|
-
LinkExtension,
|
|
2809
|
+
LinkExtension.configure({ trustedDomains: options.trustedDomains ?? [] }),
|
|
2780
2810
|
import_extension_superscript.default,
|
|
2781
2811
|
import_extension_subscript.default,
|
|
2782
2812
|
import_extension_text_align.default.configure({
|
|
@@ -3811,7 +3841,7 @@ var import_extension_table2 = require("@tiptap/extension-table");
|
|
|
3811
3841
|
function isJSONContent(value) {
|
|
3812
3842
|
return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
|
|
3813
3843
|
}
|
|
3814
|
-
function htmlToTiptapContent(content) {
|
|
3844
|
+
function htmlToTiptapContent(content, options = {}) {
|
|
3815
3845
|
if (isJSONContent(content)) {
|
|
3816
3846
|
return content;
|
|
3817
3847
|
}
|
|
@@ -3827,7 +3857,7 @@ function htmlToTiptapContent(content) {
|
|
|
3827
3857
|
if (!content || content.trim() === "") {
|
|
3828
3858
|
return { type: "doc", content: [{ type: "paragraph" }] };
|
|
3829
3859
|
}
|
|
3830
|
-
const sharedExtensions = getSharedExtensions();
|
|
3860
|
+
const sharedExtensions = getSharedExtensions(options);
|
|
3831
3861
|
const extensions = [...sharedExtensions, BaseFigure, import_extension_table2.TableKit, BaseCodeBlock];
|
|
3832
3862
|
try {
|
|
3833
3863
|
return (0, import_core17.generateJSON)(content, extensions);
|