mirror of
https://github.com/docmost/docmost.git
synced 2026-05-21 01:04:39 +08:00
fix: Set isInitialized to force immediate react node view rendering
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
"@emoji-mart/data": "^1.2.1",
|
"@emoji-mart/data": "^1.2.1",
|
||||||
"@emoji-mart/react": "^1.1.1",
|
"@emoji-mart/react": "^1.1.1",
|
||||||
"@excalidraw/excalidraw": "0.18.0-864353b",
|
"@excalidraw/excalidraw": "0.18.0-864353b",
|
||||||
|
"@floating-ui/dom": "^1.7.3",
|
||||||
"@mantine/core": "^8.1.3",
|
"@mantine/core": "^8.1.3",
|
||||||
"@mantine/dates": "^8.3.2",
|
"@mantine/dates": "^8.3.2",
|
||||||
"@mantine/form": "^8.1.3",
|
"@mantine/form": "^8.1.3",
|
||||||
@@ -25,7 +26,6 @@
|
|||||||
"@mantine/spotlight": "^8.1.3",
|
"@mantine/spotlight": "^8.1.3",
|
||||||
"@tabler/icons-react": "^3.34.0",
|
"@tabler/icons-react": "^3.34.0",
|
||||||
"@tanstack/react-query": "^5.80.6",
|
"@tanstack/react-query": "^5.80.6",
|
||||||
"@tiptap/extension-character-count": "^2.10.3",
|
|
||||||
"alfaaz": "^1.1.0",
|
"alfaaz": "^1.1.0",
|
||||||
"axios": "^1.13.2",
|
"axios": "^1.13.2",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
|
|||||||
@@ -166,6 +166,9 @@ export const mainExtensions = [
|
|||||||
},
|
},
|
||||||
}).extend({
|
}).extend({
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
|
// Force the react node view to render immediately using flush sync (https://github.com/ueberdosis/tiptap/blob/b4db352f839e1d82f9add6ee7fb45561336286d8/packages/react/src/ReactRenderer.tsx#L183-L191)
|
||||||
|
this.editor.isInitialized = true;
|
||||||
|
|
||||||
return ReactNodeViewRenderer(MentionView);
|
return ReactNodeViewRenderer(MentionView);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
+32
-34
@@ -21,42 +21,40 @@
|
|||||||
"@braintree/sanitize-url": "^7.1.0",
|
"@braintree/sanitize-url": "^7.1.0",
|
||||||
"@docmost/editor-ext": "workspace:*",
|
"@docmost/editor-ext": "workspace:*",
|
||||||
"@floating-ui/dom": "^1.7.3",
|
"@floating-ui/dom": "^1.7.3",
|
||||||
"@hocuspocus/extension-redis": "3.4.1",
|
"@hocuspocus/extension-redis": "3.4.3",
|
||||||
"@hocuspocus/provider": "3.4.1",
|
"@hocuspocus/provider": "3.4.3",
|
||||||
"@hocuspocus/server": "3.4.1",
|
"@hocuspocus/server": "3.4.3",
|
||||||
"@hocuspocus/transformer": "3.4.1",
|
"@hocuspocus/transformer": "3.4.3",
|
||||||
"@joplin/turndown": "^4.0.74",
|
"@joplin/turndown": "^4.0.74",
|
||||||
"@joplin/turndown-plugin-gfm": "^1.0.56",
|
"@joplin/turndown-plugin-gfm": "^1.0.56",
|
||||||
"@sindresorhus/slugify": "1.1.0",
|
"@sindresorhus/slugify": "1.1.0",
|
||||||
"@tiptap/core": "3.13.0",
|
"@tiptap/core": "3.15.3",
|
||||||
"@tiptap/extension-code-block": "3.13.0",
|
"@tiptap/extension-code-block": "3.15.3",
|
||||||
"@tiptap/extension-collaboration": "3.13.0",
|
"@tiptap/extension-collaboration": "3.15.3",
|
||||||
"@tiptap/extension-collaboration-caret": "3.13.0",
|
"@tiptap/extension-collaboration-caret": "3.15.3",
|
||||||
"@tiptap/extension-color": "3.13.0",
|
"@tiptap/extension-color": "3.15.3",
|
||||||
"@tiptap/extension-document": "3.13.0",
|
"@tiptap/extension-document": "3.15.3",
|
||||||
"@tiptap/extension-heading": "3.13.0",
|
"@tiptap/extension-heading": "3.15.3",
|
||||||
"@tiptap/extension-highlight": "3.13.0",
|
"@tiptap/extension-highlight": "3.15.3",
|
||||||
"@tiptap/extension-history": "3.13.0",
|
"@tiptap/extension-history": "3.15.3",
|
||||||
"@tiptap/extension-image": "3.13.0",
|
"@tiptap/extension-image": "3.15.3",
|
||||||
"@tiptap/extension-link": "3.13.0",
|
"@tiptap/extension-link": "3.15.3",
|
||||||
"@tiptap/extension-list": "3.13.0",
|
"@tiptap/extension-list": "3.15.3",
|
||||||
"@tiptap/extension-list-item": "3.13.0",
|
"@tiptap/extension-placeholder": "3.15.3",
|
||||||
"@tiptap/extension-list-keymap": "3.13.0",
|
"@tiptap/extension-subscript": "3.15.3",
|
||||||
"@tiptap/extension-placeholder": "3.13.0",
|
"@tiptap/extension-superscript": "3.15.3",
|
||||||
"@tiptap/extension-subscript": "3.13.0",
|
"@tiptap/extension-table": "3.15.3",
|
||||||
"@tiptap/extension-superscript": "3.13.0",
|
"@tiptap/extension-text": "3.15.3",
|
||||||
"@tiptap/extension-table": "3.13.0",
|
"@tiptap/extension-text-align": "3.15.3",
|
||||||
"@tiptap/extension-text": "3.13.0",
|
"@tiptap/extension-text-style": "3.15.3",
|
||||||
"@tiptap/extension-text-align": "3.13.0",
|
"@tiptap/extension-typography": "3.15.3",
|
||||||
"@tiptap/extension-text-style": "3.13.0",
|
"@tiptap/extension-unique-id": "^3.15.3",
|
||||||
"@tiptap/extension-typography": "3.13.0",
|
"@tiptap/extension-youtube": "3.15.3",
|
||||||
"@tiptap/extension-unique-id": "^3.13.0",
|
"@tiptap/html": "3.15.3",
|
||||||
"@tiptap/extension-youtube": "3.13.0",
|
"@tiptap/pm": "3.15.3",
|
||||||
"@tiptap/html": "3.13.0",
|
"@tiptap/react": "3.15.3",
|
||||||
"@tiptap/pm": "3.13.0",
|
"@tiptap/starter-kit": "3.15.3",
|
||||||
"@tiptap/react": "3.13.0",
|
"@tiptap/suggestion": "3.15.3",
|
||||||
"@tiptap/starter-kit": "3.13.0",
|
|
||||||
"@tiptap/suggestion": "3.13.0",
|
|
||||||
"@types/qrcode": "^1.5.5",
|
"@types/qrcode": "^1.5.5",
|
||||||
"bytes": "^3.1.2",
|
"bytes": "^3.1.2",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
@@ -73,7 +71,7 @@
|
|||||||
"uuid": "^11.1.0",
|
"uuid": "^11.1.0",
|
||||||
"y-indexeddb": "^9.0.12",
|
"y-indexeddb": "^9.0.12",
|
||||||
"y-prosemirror": "1.3.7",
|
"y-prosemirror": "1.3.7",
|
||||||
"yjs": "^13.6.27"
|
"yjs": "^13.6.29"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nx/js": "20.4.5",
|
"@nx/js": "20.4.5",
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ export const Attachment = Node.create<AttachmentOptions>({
|
|||||||
mergeAttributes(
|
mergeAttributes(
|
||||||
{ "data-type": this.name },
|
{ "data-type": this.name },
|
||||||
this.options.HTMLAttributes,
|
this.options.HTMLAttributes,
|
||||||
HTMLAttributes,
|
HTMLAttributes
|
||||||
),
|
),
|
||||||
[
|
[
|
||||||
"a",
|
"a",
|
||||||
@@ -120,6 +120,9 @@ export const Attachment = Node.create<AttachmentOptions>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
|
// Force the react node view to render immediately using flush sync (https://github.com/ueberdosis/tiptap/blob/b4db352f839e1d82f9add6ee7fb45561336286d8/packages/react/src/ReactRenderer.tsx#L183-L191)
|
||||||
|
this.editor.isInitialized = true;
|
||||||
|
|
||||||
return ReactNodeViewRenderer(this.options.view);
|
return ReactNodeViewRenderer(this.options.view);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ export const Callout = Node.create<CalloutOptions>({
|
|||||||
mergeAttributes(
|
mergeAttributes(
|
||||||
{ "data-type": this.name },
|
{ "data-type": this.name },
|
||||||
this.options.HTMLAttributes,
|
this.options.HTMLAttributes,
|
||||||
HTMLAttributes,
|
HTMLAttributes
|
||||||
),
|
),
|
||||||
0,
|
0,
|
||||||
];
|
];
|
||||||
@@ -130,6 +130,9 @@ export const Callout = Node.create<CalloutOptions>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
|
// Force the react node view to render immediately using flush sync (https://github.com/ueberdosis/tiptap/blob/b4db352f839e1d82f9add6ee7fb45561336286d8/packages/react/src/ReactRenderer.tsx#L183-L191)
|
||||||
|
this.editor.isInitialized = true;
|
||||||
|
|
||||||
return ReactNodeViewRenderer(this.options.view);
|
return ReactNodeViewRenderer(this.options.view);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -193,7 +196,7 @@ export const Callout = Node.create<CalloutOptions>({
|
|||||||
|
|
||||||
tr.delete(pos, pos + nodeSize);
|
tr.delete(pos, pos + nodeSize);
|
||||||
tr.setSelection(
|
tr.setSelection(
|
||||||
TextSelection.near(tr.doc.resolve(previousPosition - 1)),
|
TextSelection.near(tr.doc.resolve(previousPosition - 1))
|
||||||
);
|
);
|
||||||
tr.insert(previousPosition - 1, content);
|
tr.insert(previousPosition - 1, content);
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import type { CodeBlockOptions } from '@tiptap/extension-code-block'
|
import type { CodeBlockOptions } from "@tiptap/extension-code-block";
|
||||||
import CodeBlock from '@tiptap/extension-code-block'
|
import CodeBlock from "@tiptap/extension-code-block";
|
||||||
|
|
||||||
import { LowlightPlugin } from './lowlight-plugin.js'
|
import { LowlightPlugin } from "./lowlight-plugin.js";
|
||||||
import { ReactNodeViewRenderer } from '@tiptap/react';
|
import { ReactNodeViewRenderer } from "@tiptap/react";
|
||||||
|
|
||||||
export interface CodeBlockLowlightOptions extends CodeBlockOptions {
|
export interface CodeBlockLowlightOptions extends CodeBlockOptions {
|
||||||
/**
|
/**
|
||||||
* The lowlight instance.
|
* The lowlight instance.
|
||||||
*/
|
*/
|
||||||
lowlight: any,
|
lowlight: any;
|
||||||
view: any;
|
view: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,13 +25,13 @@ export const CustomCodeBlock = CodeBlock.extend<CodeBlockLowlightOptions>({
|
|||||||
return {
|
return {
|
||||||
...this.parent?.(),
|
...this.parent?.(),
|
||||||
lowlight: {},
|
lowlight: {},
|
||||||
languageClassPrefix: 'language-',
|
languageClassPrefix: "language-",
|
||||||
exitOnTripleEnter: true,
|
exitOnTripleEnter: true,
|
||||||
exitOnArrowDown: true,
|
exitOnArrowDown: true,
|
||||||
defaultLanguage: null,
|
defaultLanguage: null,
|
||||||
HTMLAttributes: {},
|
HTMLAttributes: {},
|
||||||
view: null,
|
view: null,
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
addKeyboardShortcuts() {
|
addKeyboardShortcuts() {
|
||||||
@@ -88,8 +88,10 @@ export const CustomCodeBlock = CodeBlock.extend<CodeBlockLowlightOptions>({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
|
// Force the react node view to render immediately using flush sync (https://github.com/ueberdosis/tiptap/blob/b4db352f839e1d82f9add6ee7fb45561336286d8/packages/react/src/ReactRenderer.tsx#L183-L191)
|
||||||
|
this.editor.isInitialized = true;
|
||||||
|
|
||||||
return ReactNodeViewRenderer(this.options.view);
|
return ReactNodeViewRenderer(this.options.view);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -101,6 +103,6 @@ export const CustomCodeBlock = CodeBlock.extend<CodeBlockLowlightOptions>({
|
|||||||
lowlight: this.options.lowlight,
|
lowlight: this.options.lowlight,
|
||||||
defaultLanguage: this.options.defaultLanguage,
|
defaultLanguage: this.options.defaultLanguage,
|
||||||
}),
|
}),
|
||||||
]
|
];
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|||||||
@@ -41,45 +41,45 @@ export const Drawio = Node.create<DrawioOptions>({
|
|||||||
addAttributes() {
|
addAttributes() {
|
||||||
return {
|
return {
|
||||||
src: {
|
src: {
|
||||||
default: '',
|
default: "",
|
||||||
parseHTML: (element) => element.getAttribute('data-src'),
|
parseHTML: (element) => element.getAttribute("data-src"),
|
||||||
renderHTML: (attributes) => ({
|
renderHTML: (attributes) => ({
|
||||||
'data-src': attributes.src,
|
"data-src": attributes.src,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
default: undefined,
|
default: undefined,
|
||||||
parseHTML: (element) => element.getAttribute('data-title'),
|
parseHTML: (element) => element.getAttribute("data-title"),
|
||||||
renderHTML: (attributes: DrawioAttributes) => ({
|
renderHTML: (attributes: DrawioAttributes) => ({
|
||||||
'data-title': attributes.title,
|
"data-title": attributes.title,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
width: {
|
width: {
|
||||||
default: '100%',
|
default: "100%",
|
||||||
parseHTML: (element) => element.getAttribute('data-width'),
|
parseHTML: (element) => element.getAttribute("data-width"),
|
||||||
renderHTML: (attributes: DrawioAttributes) => ({
|
renderHTML: (attributes: DrawioAttributes) => ({
|
||||||
'data-width': attributes.width,
|
"data-width": attributes.width,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
default: null,
|
default: null,
|
||||||
parseHTML: (element) => element.getAttribute('data-size'),
|
parseHTML: (element) => element.getAttribute("data-size"),
|
||||||
renderHTML: (attributes: DrawioAttributes) => ({
|
renderHTML: (attributes: DrawioAttributes) => ({
|
||||||
'data-size': attributes.size,
|
"data-size": attributes.size,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
align: {
|
align: {
|
||||||
default: 'center',
|
default: "center",
|
||||||
parseHTML: (element) => element.getAttribute('data-align'),
|
parseHTML: (element) => element.getAttribute("data-align"),
|
||||||
renderHTML: (attributes: DrawioAttributes) => ({
|
renderHTML: (attributes: DrawioAttributes) => ({
|
||||||
'data-align': attributes.align,
|
"data-align": attributes.align,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
attachmentId: {
|
attachmentId: {
|
||||||
default: undefined,
|
default: undefined,
|
||||||
parseHTML: (element) => element.getAttribute('data-attachment-id'),
|
parseHTML: (element) => element.getAttribute("data-attachment-id"),
|
||||||
renderHTML: (attributes: DrawioAttributes) => ({
|
renderHTML: (attributes: DrawioAttributes) => ({
|
||||||
'data-attachment-id': attributes.attachmentId,
|
"data-attachment-id": attributes.attachmentId,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -95,13 +95,20 @@ export const Drawio = Node.create<DrawioOptions>({
|
|||||||
|
|
||||||
renderHTML({ HTMLAttributes }) {
|
renderHTML({ HTMLAttributes }) {
|
||||||
return [
|
return [
|
||||||
'div',
|
"div",
|
||||||
mergeAttributes(
|
mergeAttributes(
|
||||||
{ 'data-type': this.name },
|
{ "data-type": this.name },
|
||||||
this.options.HTMLAttributes,
|
this.options.HTMLAttributes,
|
||||||
HTMLAttributes
|
HTMLAttributes
|
||||||
),
|
),
|
||||||
['img', { src: HTMLAttributes['data-src'], alt: HTMLAttributes['data-title'], width: HTMLAttributes['data-width'] }],
|
[
|
||||||
|
"img",
|
||||||
|
{
|
||||||
|
src: HTMLAttributes["data-src"],
|
||||||
|
alt: HTMLAttributes["data-title"],
|
||||||
|
width: HTMLAttributes["data-width"],
|
||||||
|
},
|
||||||
|
],
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -119,6 +126,9 @@ export const Drawio = Node.create<DrawioOptions>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
|
// Force the react node view to render immediately using flush sync (https://github.com/ueberdosis/tiptap/blob/b4db352f839e1d82f9add6ee7fb45561336286d8/packages/react/src/ReactRenderer.tsx#L183-L191)
|
||||||
|
this.editor.isInitialized = true;
|
||||||
|
|
||||||
return ReactNodeViewRenderer(this.options.view);
|
return ReactNodeViewRenderer(this.options.view);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Node, mergeAttributes } from '@tiptap/core';
|
import { Node, mergeAttributes } from "@tiptap/core";
|
||||||
import { ReactNodeViewRenderer } from '@tiptap/react';
|
import { ReactNodeViewRenderer } from "@tiptap/react";
|
||||||
import { sanitizeUrl } from './utils';
|
import { sanitizeUrl } from "./utils";
|
||||||
|
|
||||||
export interface EmbedOptions {
|
export interface EmbedOptions {
|
||||||
HTMLAttributes: Record<string, any>;
|
HTMLAttributes: Record<string, any>;
|
||||||
@@ -14,7 +14,7 @@ export interface EmbedAttributes {
|
|||||||
height?: number;
|
height?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module "@tiptap/core" {
|
||||||
interface Commands<ReturnType> {
|
interface Commands<ReturnType> {
|
||||||
embeds: {
|
embeds: {
|
||||||
setEmbed: (attributes?: EmbedAttributes) => ReturnType;
|
setEmbed: (attributes?: EmbedAttributes) => ReturnType;
|
||||||
@@ -23,9 +23,9 @@ declare module '@tiptap/core' {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Embed = Node.create<EmbedOptions>({
|
export const Embed = Node.create<EmbedOptions>({
|
||||||
name: 'embed',
|
name: "embed",
|
||||||
inline: false,
|
inline: false,
|
||||||
group: 'block',
|
group: "block",
|
||||||
isolating: true,
|
isolating: true,
|
||||||
atom: true,
|
atom: true,
|
||||||
defining: true,
|
defining: true,
|
||||||
@@ -40,41 +40,41 @@ export const Embed = Node.create<EmbedOptions>({
|
|||||||
addAttributes() {
|
addAttributes() {
|
||||||
return {
|
return {
|
||||||
src: {
|
src: {
|
||||||
default: '',
|
default: "",
|
||||||
parseHTML: (element) => {
|
parseHTML: (element) => {
|
||||||
const src = element.getAttribute('data-src');
|
const src = element.getAttribute("data-src");
|
||||||
return sanitizeUrl(src);
|
return sanitizeUrl(src);
|
||||||
},
|
},
|
||||||
renderHTML: (attributes: EmbedAttributes) => ({
|
renderHTML: (attributes: EmbedAttributes) => ({
|
||||||
'data-src': sanitizeUrl(attributes.src),
|
"data-src": sanitizeUrl(attributes.src),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
provider: {
|
provider: {
|
||||||
default: '',
|
default: "",
|
||||||
parseHTML: (element) => element.getAttribute('data-provider'),
|
parseHTML: (element) => element.getAttribute("data-provider"),
|
||||||
renderHTML: (attributes: EmbedAttributes) => ({
|
renderHTML: (attributes: EmbedAttributes) => ({
|
||||||
'data-provider': attributes.provider,
|
"data-provider": attributes.provider,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
align: {
|
align: {
|
||||||
default: 'center',
|
default: "center",
|
||||||
parseHTML: (element) => element.getAttribute('data-align'),
|
parseHTML: (element) => element.getAttribute("data-align"),
|
||||||
renderHTML: (attributes: EmbedAttributes) => ({
|
renderHTML: (attributes: EmbedAttributes) => ({
|
||||||
'data-align': attributes.align,
|
"data-align": attributes.align,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
width: {
|
width: {
|
||||||
default: 640,
|
default: 640,
|
||||||
parseHTML: (element) => element.getAttribute('data-width'),
|
parseHTML: (element) => element.getAttribute("data-width"),
|
||||||
renderHTML: (attributes: EmbedAttributes) => ({
|
renderHTML: (attributes: EmbedAttributes) => ({
|
||||||
'data-width': attributes.width,
|
"data-width": attributes.width,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
height: {
|
height: {
|
||||||
default: 480,
|
default: 480,
|
||||||
parseHTML: (element) => element.getAttribute('data-height'),
|
parseHTML: (element) => element.getAttribute("data-height"),
|
||||||
renderHTML: (attributes: EmbedAttributes) => ({
|
renderHTML: (attributes: EmbedAttributes) => ({
|
||||||
'data-height': attributes.height,
|
"data-height": attributes.height,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -91,13 +91,13 @@ export const Embed = Node.create<EmbedOptions>({
|
|||||||
renderHTML({ HTMLAttributes }) {
|
renderHTML({ HTMLAttributes }) {
|
||||||
const src = HTMLAttributes["data-src"];
|
const src = HTMLAttributes["data-src"];
|
||||||
const safeHref = sanitizeUrl(src);
|
const safeHref = sanitizeUrl(src);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
"div",
|
"div",
|
||||||
mergeAttributes(
|
mergeAttributes(
|
||||||
{ "data-type": this.name },
|
{ "data-type": this.name },
|
||||||
this.options.HTMLAttributes,
|
this.options.HTMLAttributes,
|
||||||
HTMLAttributes,
|
HTMLAttributes
|
||||||
),
|
),
|
||||||
[
|
[
|
||||||
"a",
|
"a",
|
||||||
@@ -120,9 +120,9 @@ export const Embed = Node.create<EmbedOptions>({
|
|||||||
...attrs,
|
...attrs,
|
||||||
src: sanitizeUrl(attrs.src),
|
src: sanitizeUrl(attrs.src),
|
||||||
};
|
};
|
||||||
|
|
||||||
return commands.insertContent({
|
return commands.insertContent({
|
||||||
type: 'embed',
|
type: "embed",
|
||||||
attrs: validatedAttrs,
|
attrs: validatedAttrs,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -130,6 +130,9 @@ export const Embed = Node.create<EmbedOptions>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
|
// Force the react node view to render immediately using flush sync (https://github.com/ueberdosis/tiptap/blob/b4db352f839e1d82f9add6ee7fb45561336286d8/packages/react/src/ReactRenderer.tsx#L183-L191)
|
||||||
|
this.editor.isInitialized = true;
|
||||||
|
|
||||||
return ReactNodeViewRenderer(this.options.view);
|
return ReactNodeViewRenderer(this.options.view);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Node, mergeAttributes } from '@tiptap/core';
|
import { Node, mergeAttributes } from "@tiptap/core";
|
||||||
import { ReactNodeViewRenderer } from '@tiptap/react';
|
import { ReactNodeViewRenderer } from "@tiptap/react";
|
||||||
|
|
||||||
export interface ExcalidrawOptions {
|
export interface ExcalidrawOptions {
|
||||||
HTMLAttributes: Record<string, any>;
|
HTMLAttributes: Record<string, any>;
|
||||||
@@ -14,7 +14,7 @@ export interface ExcalidrawAttributes {
|
|||||||
attachmentId?: string;
|
attachmentId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module "@tiptap/core" {
|
||||||
interface Commands<ReturnType> {
|
interface Commands<ReturnType> {
|
||||||
excalidraw: {
|
excalidraw: {
|
||||||
setExcalidraw: (attributes?: ExcalidrawAttributes) => ReturnType;
|
setExcalidraw: (attributes?: ExcalidrawAttributes) => ReturnType;
|
||||||
@@ -23,9 +23,9 @@ declare module '@tiptap/core' {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Excalidraw = Node.create<ExcalidrawOptions>({
|
export const Excalidraw = Node.create<ExcalidrawOptions>({
|
||||||
name: 'excalidraw',
|
name: "excalidraw",
|
||||||
inline: false,
|
inline: false,
|
||||||
group: 'block',
|
group: "block",
|
||||||
isolating: true,
|
isolating: true,
|
||||||
atom: true,
|
atom: true,
|
||||||
defining: true,
|
defining: true,
|
||||||
@@ -40,45 +40,45 @@ export const Excalidraw = Node.create<ExcalidrawOptions>({
|
|||||||
addAttributes() {
|
addAttributes() {
|
||||||
return {
|
return {
|
||||||
src: {
|
src: {
|
||||||
default: '',
|
default: "",
|
||||||
parseHTML: (element) => element.getAttribute('data-src'),
|
parseHTML: (element) => element.getAttribute("data-src"),
|
||||||
renderHTML: (attributes) => ({
|
renderHTML: (attributes) => ({
|
||||||
'data-src': attributes.src,
|
"data-src": attributes.src,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
default: undefined,
|
default: undefined,
|
||||||
parseHTML: (element) => element.getAttribute('data-title'),
|
parseHTML: (element) => element.getAttribute("data-title"),
|
||||||
renderHTML: (attributes: ExcalidrawAttributes) => ({
|
renderHTML: (attributes: ExcalidrawAttributes) => ({
|
||||||
'data-title': attributes.title,
|
"data-title": attributes.title,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
width: {
|
width: {
|
||||||
default: '100%',
|
default: "100%",
|
||||||
parseHTML: (element) => element.getAttribute('data-width'),
|
parseHTML: (element) => element.getAttribute("data-width"),
|
||||||
renderHTML: (attributes: ExcalidrawAttributes) => ({
|
renderHTML: (attributes: ExcalidrawAttributes) => ({
|
||||||
'data-width': attributes.width,
|
"data-width": attributes.width,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
default: null,
|
default: null,
|
||||||
parseHTML: (element) => element.getAttribute('data-size'),
|
parseHTML: (element) => element.getAttribute("data-size"),
|
||||||
renderHTML: (attributes: ExcalidrawAttributes) => ({
|
renderHTML: (attributes: ExcalidrawAttributes) => ({
|
||||||
'data-size': attributes.size,
|
"data-size": attributes.size,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
align: {
|
align: {
|
||||||
default: 'center',
|
default: "center",
|
||||||
parseHTML: (element) => element.getAttribute('data-align'),
|
parseHTML: (element) => element.getAttribute("data-align"),
|
||||||
renderHTML: (attributes: ExcalidrawAttributes) => ({
|
renderHTML: (attributes: ExcalidrawAttributes) => ({
|
||||||
'data-align': attributes.align,
|
"data-align": attributes.align,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
attachmentId: {
|
attachmentId: {
|
||||||
default: undefined,
|
default: undefined,
|
||||||
parseHTML: (element) => element.getAttribute('data-attachment-id'),
|
parseHTML: (element) => element.getAttribute("data-attachment-id"),
|
||||||
renderHTML: (attributes: ExcalidrawAttributes) => ({
|
renderHTML: (attributes: ExcalidrawAttributes) => ({
|
||||||
'data-attachment-id': attributes.attachmentId,
|
"data-attachment-id": attributes.attachmentId,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -94,13 +94,20 @@ export const Excalidraw = Node.create<ExcalidrawOptions>({
|
|||||||
|
|
||||||
renderHTML({ HTMLAttributes }) {
|
renderHTML({ HTMLAttributes }) {
|
||||||
return [
|
return [
|
||||||
'div',
|
"div",
|
||||||
mergeAttributes(
|
mergeAttributes(
|
||||||
{ 'data-type': this.name },
|
{ "data-type": this.name },
|
||||||
this.options.HTMLAttributes,
|
this.options.HTMLAttributes,
|
||||||
HTMLAttributes
|
HTMLAttributes
|
||||||
),
|
),
|
||||||
['img', { src: HTMLAttributes['data-src'], alt: HTMLAttributes['data-title'], width: HTMLAttributes['data-width'] }],
|
[
|
||||||
|
"img",
|
||||||
|
{
|
||||||
|
src: HTMLAttributes["data-src"],
|
||||||
|
alt: HTMLAttributes["data-title"],
|
||||||
|
width: HTMLAttributes["data-width"],
|
||||||
|
},
|
||||||
|
],
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -110,7 +117,7 @@ export const Excalidraw = Node.create<ExcalidrawOptions>({
|
|||||||
(attrs: ExcalidrawAttributes) =>
|
(attrs: ExcalidrawAttributes) =>
|
||||||
({ commands }) => {
|
({ commands }) => {
|
||||||
return commands.insertContent({
|
return commands.insertContent({
|
||||||
type: 'excalidraw',
|
type: "excalidraw",
|
||||||
attrs: attrs,
|
attrs: attrs,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -118,6 +125,9 @@ export const Excalidraw = Node.create<ExcalidrawOptions>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
|
// Force the react node view to render immediately using flush sync (https://github.com/ueberdosis/tiptap/blob/b4db352f839e1d82f9add6ee7fb45561336286d8/packages/react/src/ReactRenderer.tsx#L183-L191)
|
||||||
|
this.editor.isInitialized = true;
|
||||||
|
|
||||||
return ReactNodeViewRenderer(this.options.view);
|
return ReactNodeViewRenderer(this.options.view);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ declare module "@tiptap/core" {
|
|||||||
imageBlock: {
|
imageBlock: {
|
||||||
setImage: (attributes: ImageAttributes) => ReturnType;
|
setImage: (attributes: ImageAttributes) => ReturnType;
|
||||||
setImageAt: (
|
setImageAt: (
|
||||||
attributes: ImageAttributes & { pos: number | Range },
|
attributes: ImageAttributes & { pos: number | Range }
|
||||||
) => ReturnType;
|
) => ReturnType;
|
||||||
setImageAlign: (align: "left" | "center" | "right") => ReturnType;
|
setImageAlign: (align: "left" | "center" | "right") => ReturnType;
|
||||||
setImageWidth: (width: number) => ReturnType;
|
setImageWidth: (width: number) => ReturnType;
|
||||||
@@ -135,6 +135,9 @@ export const TiptapImage = Image.extend<ImageOptions>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
|
// Force the react node view to render immediately using flush sync (https://github.com/ueberdosis/tiptap/blob/b4db352f839e1d82f9add6ee7fb45561336286d8/packages/react/src/ReactRenderer.tsx#L183-L191)
|
||||||
|
this.editor.isInitialized = true;
|
||||||
|
|
||||||
return ReactNodeViewRenderer(this.options.view);
|
return ReactNodeViewRenderer(this.options.view);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ export const MathBlock = Node.create({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
|
// Force the react node view to render immediately using flush sync (https://github.com/ueberdosis/tiptap/blob/b4db352f839e1d82f9add6ee7fb45561336286d8/packages/react/src/ReactRenderer.tsx#L183-L191)
|
||||||
|
this.editor.isInitialized = true;
|
||||||
|
|
||||||
return ReactNodeViewRenderer(this.options.view);
|
return ReactNodeViewRenderer(this.options.view);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ export const MathInline = Node.create<MathInlineOption>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
|
// Force the react node view to render immediately using flush sync (https://github.com/ueberdosis/tiptap/blob/b4db352f839e1d82f9add6ee7fb45561336286d8/packages/react/src/ReactRenderer.tsx#L183-L191)
|
||||||
|
this.editor.isInitialized = true;
|
||||||
|
|
||||||
return ReactNodeViewRenderer(this.options.view);
|
return ReactNodeViewRenderer(this.options.view);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export const Subpages = Node.create<SubpagesOptions>({
|
|||||||
mergeAttributes(
|
mergeAttributes(
|
||||||
{ "data-type": this.name },
|
{ "data-type": this.name },
|
||||||
this.options.HTMLAttributes,
|
this.options.HTMLAttributes,
|
||||||
HTMLAttributes,
|
HTMLAttributes
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
@@ -63,6 +63,9 @@ export const Subpages = Node.create<SubpagesOptions>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
|
// Force the react node view to render immediately using flush sync (https://github.com/ueberdosis/tiptap/blob/b4db352f839e1d82f9add6ee7fb45561336286d8/packages/react/src/ReactRenderer.tsx#L183-L191)
|
||||||
|
this.editor.isInitialized = true;
|
||||||
|
|
||||||
return ReactNodeViewRenderer(this.options.view);
|
return ReactNodeViewRenderer(this.options.view);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ declare module "@tiptap/core" {
|
|||||||
videoBlock: {
|
videoBlock: {
|
||||||
setVideo: (attributes: VideoAttributes) => ReturnType;
|
setVideo: (attributes: VideoAttributes) => ReturnType;
|
||||||
setVideoAt: (
|
setVideoAt: (
|
||||||
attributes: VideoAttributes & { pos: number | Range },
|
attributes: VideoAttributes & { pos: number | Range }
|
||||||
) => ReturnType;
|
) => ReturnType;
|
||||||
setVideoAlign: (align: "left" | "center" | "right") => ReturnType;
|
setVideoAlign: (align: "left" | "center" | "right") => ReturnType;
|
||||||
setVideoWidth: (width: number) => ReturnType;
|
setVideoWidth: (width: number) => ReturnType;
|
||||||
@@ -87,9 +87,9 @@ export const TiptapVideo = Node.create<VideoOptions>({
|
|||||||
parseHTML() {
|
parseHTML() {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
tag: 'video',
|
tag: "video",
|
||||||
},
|
},
|
||||||
]
|
];
|
||||||
},
|
},
|
||||||
|
|
||||||
renderHTML({ HTMLAttributes }) {
|
renderHTML({ HTMLAttributes }) {
|
||||||
@@ -126,6 +126,9 @@ export const TiptapVideo = Node.create<VideoOptions>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
|
// Force the react node view to render immediately using flush sync (https://github.com/ueberdosis/tiptap/blob/b4db352f839e1d82f9add6ee7fb45561336286d8/packages/react/src/ReactRenderer.tsx#L183-L191)
|
||||||
|
this.editor.isInitialized = true;
|
||||||
|
|
||||||
return ReactNodeViewRenderer(this.options.view);
|
return ReactNodeViewRenderer(this.options.view);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Generated
+397
-436
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user