mirror of
https://github.com/docmost/docmost.git
synced 2026-05-18 23:44:24 +08:00
657fdf8cb7
* Tiptap3 migration - WIP * fix collaboration * remove unused code * fix flicker * disable duplicate extensions * update tiptap version * Switch to useEditorState - Set shouldRerenderOnTransaction to false * fix editable state * add tippyoptions for reference * merge main * tiptap 3.6.1 * fix bubble menu * fix converter * fix menus * fix collaboration caret css * fix: Set `isInitialized` to force immediate react node view rendering * feat: Migrate tippy.js menus to Floating UI * feat: Update collaboration connection for HocusPocus v3 * fix: Connect/disconnect websocketProvider * cleanup * cleanup * feat: Improved placeholder and upload handling for images * feat: Improved placeholder and upload handling for videos * refactor: Image node and view clean-up * feat: Improved placeholder and upload handling for attachments * fix: Video view styles * fix: Transaction handling on asset upload * fix: Use imageDimensionsFromStream * feat: Multiple file upload, improved placeholders, local previews * fix: Drag & drop, paste upload * fix: Allow media as attachment * * add skeleton pulse animation * add translation strings * fix attachment view responsiveness * fix collab connection status display * Tiptap v3.17.0 * fix suggestion menu exit bug * fix search shortcut * fix history editor css * tiptap 3.17.1 --------- Co-authored-by: Arek Nawo <areknawo@areknawo.com>
122 lines
2.8 KiB
TypeScript
122 lines
2.8 KiB
TypeScript
import { ReactRenderer, useEditor } from "@tiptap/react";
|
|
import EmojiList from "./emoji-list";
|
|
import { init } from "emoji-mart";
|
|
import {
|
|
autoUpdate,
|
|
computePosition,
|
|
flip,
|
|
offset,
|
|
shift,
|
|
} from "@floating-ui/dom";
|
|
|
|
const renderEmojiItems = () => {
|
|
let component: ReactRenderer | null = null;
|
|
let popup: HTMLDivElement | null = null;
|
|
let cleanup: (() => void) | null = null;
|
|
let getReferenceClientRect: (() => DOMRect) | null = null;
|
|
|
|
const destroy = () => {
|
|
if (cleanup) {
|
|
cleanup();
|
|
cleanup = null;
|
|
}
|
|
|
|
if (popup) {
|
|
popup.remove();
|
|
popup = null;
|
|
}
|
|
|
|
if (component) {
|
|
component.destroy();
|
|
component = null;
|
|
}
|
|
};
|
|
|
|
return {
|
|
onBeforeStart: (props: {
|
|
editor: ReturnType<typeof useEditor>;
|
|
clientRect: () => DOMRect;
|
|
}) => {
|
|
init({
|
|
data: async () => (await import("@emoji-mart/data")).default,
|
|
});
|
|
|
|
component = new ReactRenderer(EmojiList, {
|
|
props: { isLoading: true, items: [] },
|
|
editor: props.editor,
|
|
});
|
|
|
|
if (!props.clientRect) {
|
|
return;
|
|
}
|
|
|
|
getReferenceClientRect = props.clientRect;
|
|
popup = document.createElement("div");
|
|
popup.style.zIndex = "9999";
|
|
popup.style.position = "absolute";
|
|
popup.style.top = "0";
|
|
popup.style.left = "0";
|
|
popup.appendChild(component.element);
|
|
document.body.appendChild(popup);
|
|
|
|
const virtualElement = {
|
|
getBoundingClientRect: () => {
|
|
return getReferenceClientRect
|
|
? getReferenceClientRect()
|
|
: new DOMRect(0, 0, 0, 0);
|
|
},
|
|
};
|
|
|
|
cleanup = autoUpdate(virtualElement, popup, () => {
|
|
if (!popup) return;
|
|
|
|
computePosition(virtualElement, popup, {
|
|
placement: "bottom-start",
|
|
middleware: [offset(10), flip(), shift()],
|
|
}).then(({ x, y }) => {
|
|
if (!popup) return;
|
|
|
|
Object.assign(popup.style, {
|
|
transform: `translate(${x}px, ${y}px)`,
|
|
});
|
|
});
|
|
});
|
|
},
|
|
onStart: (props: {
|
|
editor: ReturnType<typeof useEditor>;
|
|
clientRect: () => DOMRect;
|
|
}) => {
|
|
component?.updateProps({ ...props, isLoading: false });
|
|
|
|
if (props.clientRect) {
|
|
getReferenceClientRect = props.clientRect;
|
|
}
|
|
},
|
|
onUpdate: (props: {
|
|
editor: ReturnType<typeof useEditor>;
|
|
clientRect: () => DOMRect;
|
|
}) => {
|
|
component?.updateProps(props);
|
|
|
|
if (props.clientRect) {
|
|
getReferenceClientRect = props.clientRect;
|
|
}
|
|
},
|
|
onKeyDown: (props: { event: KeyboardEvent }) => {
|
|
if (props.event.key === "Escape") {
|
|
destroy();
|
|
|
|
return true;
|
|
}
|
|
|
|
// @ts-ignore
|
|
return component?.ref?.onKeyDown(props);
|
|
},
|
|
onExit: () => {
|
|
destroy();
|
|
},
|
|
};
|
|
};
|
|
|
|
export default renderEmojiItems;
|