You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					1 line
				
				28 KiB
			
		
		
			
		
	
	
					1 line
				
				28 KiB
			| 
											3 years ago
										 | {"version":3,"file":"tiptap-react.cjs","sources":["../src/BubbleMenu.tsx","../src/Editor.ts","../src/EditorContent.tsx","../src/FloatingMenu.tsx","../src/useReactNodeView.ts","../src/NodeViewContent.tsx","../src/NodeViewWrapper.tsx","../src/ReactRenderer.tsx","../src/ReactNodeViewRenderer.tsx","../src/useEditor.ts"],"sourcesContent":["import { BubbleMenuPlugin, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'\nimport React, { useEffect, useState } from 'react'\n\ntype Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;\n\nexport type BubbleMenuProps = Omit<Optional<BubbleMenuPluginProps, 'pluginKey'>, 'element'> & {\n  className?: string;\n  children: React.ReactNode;\n  updateDelay?: number;\n};\n\nexport const BubbleMenu = (props: BubbleMenuProps) => {\n  const [element, setElement] = useState<HTMLDivElement | null>(null)\n\n  useEffect(() => {\n    if (!element) {\n      return\n    }\n\n    if (props.editor.isDestroyed) {\n      return\n    }\n\n    const {\n      pluginKey = 'bubbleMenu', editor, tippyOptions = {}, updateDelay, shouldShow = null,\n    } = props\n\n    const plugin = BubbleMenuPlugin({\n      updateDelay,\n      editor,\n      element,\n      pluginKey,\n      shouldShow,\n      tippyOptions,\n    })\n\n    editor.registerPlugin(plugin)\n    return () => editor.unregisterPlugin(pluginKey)\n  }, [props.editor, element])\n\n  return (\n    <div ref={setElement} className={props.className} style={{ visibility: 'hidden' }}>\n      {props.children}\n    </div>\n  )\n}\n","import { Editor as CoreEditor } from '@tiptap/core'\nimport React from 'react'\n\nimport { EditorContentProps, EditorContentState } from './EditorContent'\nimport { ReactRenderer } from './ReactRenderer'\n\ntype ContentComponent = React.Component<EditorContentProps, EditorContentState> & {\n  setRenderer(id: string, renderer: ReactRenderer): void;\n  removeRenderer(id: string): void;\n}\n\nexport class Editor extends CoreEditor {\n  public contentComponent: ContentComponent | null = null\n}\n","import React, { HTMLProps } from 'react'\nimport ReactDOM, { flushSync } from 'react-dom'\n\nimport { Editor } from './Editor'\nimport { ReactRenderer } from './ReactRenderer'\n\nconst Portals: React.FC<{ renderers: Record<string, ReactRenderer> }> = ({ renderers }) => {\n  return (\n    <>\n      {Object.entries(renderers).map(([key, renderer]) => {\n        return ReactDOM.createPortal(\n          renderer.reactElement,\n          renderer.element,\n          key,\n        )\n      })}\n    </>\n  )\n}\n\nexport interface EditorContentProps extends HTMLProps<HTMLDivElement> {\n  editor: Editor | null,\n}\n\nexport interface EditorContentState {\n  renderers: Record<string, ReactRenderer>\n}\n\nexport class PureEditorContent extends React.Component<EditorContentProps, EditorContentState> {\n  editorContentRef: React.RefObject<any>\n\n  initialized: boolean\n\n  constructor(props: EditorContentProps) {\n    super(props)\n    this.editorContentRef = React.createRef()\n    this.initialized = false\n\n    this.state = {\n      renderers: {},\n    }\n  }\n\n  componentDidMount() {\n    this.init()\n  }\n\n  componentDidUpdate() {\n    this.init()\n  }\n\n  init() {\n    const { editor } = this.props\n\n    if (editor && editor.options.element) {\n      if (editor.contentComponent) {\n        return\n      }\n\n      const element = this.editorContentRef.current\n\n      element.append(...editor.options.element.childNodes)\n\n      editor.setOptions({\n        element,\n      })\n\n      editor.contentComponent = this\n\n      editor.createNodeViews()\n\n      this.initialized = true\n    }\n  }\n\n  maybeFlushSync(fn: () => void) {\n    // Avoid calling flushSync until the editor is initialized.\n    // Initialization happens during the componentDidMount or componentDidUpdate\n    // lifecycle methods, and React doesn't allow calling flushSync from inside\n    // a lifecycle method.\n    if (this.initialized) {\n      flushSync(fn)\n    } else {\n      fn()\n    }\n  }\n\n  setRenderer(id: string, renderer: ReactRenderer) { |