@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.
Files changed (40) hide show
  1. package/dist/editor.css +35 -43
  2. package/dist/editor.css.map +1 -1
  3. package/dist/editor.d.mts +20 -2
  4. package/dist/editor.d.ts +20 -2
  5. package/dist/editor.js +397 -327
  6. package/dist/editor.js.map +1 -1
  7. package/dist/editor.mjs +320 -246
  8. package/dist/editor.mjs.map +1 -1
  9. package/dist/render.d.mts +9 -1
  10. package/dist/render.d.ts +9 -1
  11. package/dist/render.js +40 -10
  12. package/dist/render.js.map +1 -1
  13. package/dist/render.mjs +45 -11
  14. package/dist/render.mjs.map +1 -1
  15. package/dist/styles/index.css +35 -43
  16. package/package.json +1 -1
  17. package/src/editor/components/dialog-error/dialog-error.css +35 -0
  18. package/src/editor/components/dialog-error/dialog-error.tsx +65 -0
  19. package/src/editor/components/dialog-error/index.ts +1 -0
  20. package/src/editor/components/index.ts +1 -0
  21. package/src/editor/dialogs/add-link-dialog/add-link-dialog.css +0 -9
  22. package/src/editor/dialogs/add-link-dialog/add-link-dialog.tsx +2 -2
  23. package/src/editor/dialogs/add-video-dialog/add-video-dialog.css +0 -9
  24. package/src/editor/dialogs/add-video-dialog/add-video-dialog.tsx +2 -2
  25. package/src/editor/dialogs/image-dialog/image-dialog.css +1 -29
  26. package/src/editor/dialogs/image-dialog/image-dialog.tsx +7 -13
  27. package/src/editor/editor.tsx +8 -0
  28. package/src/editor/index.ts +1 -0
  29. package/src/extensions/base/link.test.ts +60 -0
  30. package/src/extensions/base/link.ts +61 -9
  31. package/src/extensions/editor/get-editor-extensions.ts +3 -1
  32. package/src/styles/components.css +1 -0
  33. package/src/translations/en.json +4 -4
  34. package/src/translations/ru.json +4 -4
  35. package/src/types/common.ts +3 -0
  36. package/src/types/index.ts +1 -0
  37. package/src/utils/get-shared-extensions.ts +20 -4
  38. package/src/utils/html-to-tiptap-content.ts +13 -4
  39. package/src/utils/index.ts +1 -0
  40. package/src/utils/is-combined-error.ts +9 -0
@@ -1,25 +1,41 @@
1
1
  import StarterKit from "@tiptap/starter-kit";
2
- import { Details, DetailsContent, DetailsSummary } from "@tiptap/extension-details";
2
+ import {
3
+ Details,
4
+ DetailsContent,
5
+ DetailsSummary,
6
+ } from "@tiptap/extension-details";
3
7
  import Highlight from "@tiptap/extension-highlight";
4
- import { LinkExtension, BaseMythReality, BaseMythRealityBlock } from "@/extensions/base";
8
+ import {
9
+ LinkExtension,
10
+ BaseMythReality,
11
+ BaseMythRealityBlock,
12
+ } from "@/extensions/base";
5
13
  import Subscript from "@tiptap/extension-subscript";
6
14
  import Superscript from "@tiptap/extension-superscript";
7
15
  import TextAlign from "@tiptap/extension-text-align";
8
16
  import { TextStyleKit } from "@tiptap/extension-text-style";
9
17
  import { LegacyInlineLatexSE } from "@/extensions/base/compatibility";
10
18
 
19
+ export interface SharedExtensionsOptions {
20
+ /**
21
+ * Domains (with all their subdomains) whose links are treated as internal —
22
+ * see the trustedDomains option of LinkExtension.
23
+ */
24
+ trustedDomains?: string[];
25
+ }
26
+
11
27
  /**
12
28
  * Get all Tiptap extensions for editing and rendering without ReactNodeViewRenderer for Editor
13
29
  * Can be used for both static render and editor
14
30
  */
15
- export function getSharedExtensions() {
31
+ export function getSharedExtensions(options: SharedExtensionsOptions = {}) {
16
32
  return [
17
33
  StarterKit.configure({
18
34
  codeBlock: false,
19
35
  link: false,
20
36
  }),
21
37
  Highlight.configure({ multicolor: true }),
22
- LinkExtension,
38
+ LinkExtension.configure({ trustedDomains: options.trustedDomains ?? [] }),
23
39
  Superscript,
24
40
  Subscript,
25
41
  TextAlign.configure({
@@ -1,16 +1,25 @@
1
1
  import { generateJSON, type JSONContent } from "@tiptap/core";
2
- import { getSharedExtensions } from "./get-shared-extensions";
2
+ import {
3
+ getSharedExtensions,
4
+ type SharedExtensionsOptions,
5
+ } from "./get-shared-extensions";
3
6
  import { BaseFigure } from "@/extensions/base/figure";
4
7
  import { TableKit } from "@tiptap/extension-table";
5
8
  import { BaseCodeBlock } from "@/extensions/base";
6
9
 
7
10
  function isJSONContent(value: unknown): value is JSONContent {
8
11
  return (
9
- typeof value === "object" && value !== null && "type" in value && typeof value.type === "string"
12
+ typeof value === "object" &&
13
+ value !== null &&
14
+ "type" in value &&
15
+ typeof value.type === "string"
10
16
  );
11
17
  }
12
18
 
13
- export function htmlToTiptapContent(content: string | JSONContent): JSONContent {
19
+ export function htmlToTiptapContent(
20
+ content: string | JSONContent,
21
+ options: SharedExtensionsOptions = {},
22
+ ): JSONContent {
14
23
  if (isJSONContent(content)) {
15
24
  return content;
16
25
  }
@@ -30,7 +39,7 @@ export function htmlToTiptapContent(content: string | JSONContent): JSONContent
30
39
  return { type: "doc", content: [{ type: "paragraph" }] };
31
40
  }
32
41
 
33
- const sharedExtensions = getSharedExtensions();
42
+ const sharedExtensions = getSharedExtensions(options);
34
43
 
35
44
  const extensions = [...sharedExtensions, BaseFigure, TableKit, BaseCodeBlock];
36
45
 
@@ -1,2 +1,3 @@
1
1
  export { copyToClipboard } from './copy-to-clipboard';
2
2
  export { pluralize } from './pluralize';
3
+ export { isCombinedError } from './is-combined-error';
@@ -0,0 +1,9 @@
1
+ import { CombinedErrors } from "@/types";
2
+
3
+ export function isCombinedError(error: unknown): error is CombinedErrors {
4
+ return (
5
+ error instanceof Error &&
6
+ Array.isArray(error?.cause) &&
7
+ error.cause.length > 0 && error.cause.every((e) => e instanceof Error)
8
+ );
9
+ }