refactor: refactor tiptap

pull/25/head
fantasticit 2022-04-04 21:53:51 +08:00
parent 52329d92f0
commit e90330ad9d
121 changed files with 98 additions and 103 deletions

View File

@ -1,7 +1,7 @@
import { Node, mergeAttributes } from '@tiptap/core';
import { ReactNodeViewRenderer } from '@tiptap/react';
import { AttachmentWrapper } from '../wrappers/attachment';
import { getDatasetAttribute } from '../services/dataset';
import { getDatasetAttribute } from '../utils/dataset';
declare module '@tiptap/core' {
interface Commands<ReturnType> {

View File

@ -1,8 +1,7 @@
import { Node, Command, mergeAttributes, wrappingInputRule } from '@tiptap/core';
import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core';
import { ReactNodeViewRenderer } from '@tiptap/react';
import { BannerWrapper } from '../wrappers/banner';
import { typesAvailable } from '../services/markdown/markdown-to-html/markdownBanner';
import { getDatasetAttribute } from '../services/dataset';
import { getDatasetAttribute } from '../utils/dataset';
declare module '@tiptap/core' {
interface Commands<ReturnType> {

View File

@ -1,7 +1,7 @@
import { Blockquote as BuiltInBlockquote } from '@tiptap/extension-blockquote';
import { wrappingInputRule } from '@tiptap/core';
import { getParents } from '../services/dom';
import { getMarkdownSource } from '../services/markdown';
import { getParents } from '../utils/dom';
import { getMarkdownSource } from '../markdown/markdown-to-prosemirror';
export const Blockquote = BuiltInBlockquote.extend({
addAttributes() {

View File

@ -1,5 +1,5 @@
import { BulletList as BuiltInBulletList } from '@tiptap/extension-bullet-list';
import { getMarkdownSource } from '../services/markdown';
import { getMarkdownSource } from '../markdown/markdown-to-prosemirror';
export const BulletList = BuiltInBulletList.extend({
addAttributes() {

View File

@ -2,7 +2,7 @@ import { lowlight } from 'lowlight/lib/all';
import { Node, textblockTypeInputRule, mergeAttributes } from '@tiptap/core';
import { Plugin, PluginKey, TextSelection } from 'prosemirror-state';
import { ReactNodeViewRenderer } from '@tiptap/react';
import { LowlightPlugin } from '../services/lowlight-plugin';
import { LowlightPlugin } from '../utils/lowlight-plugin';
import { CodeBlockWrapper } from '../wrappers/code-block';
export interface CodeBlockOptions {

View File

@ -1,6 +1,6 @@
import { Extension } from '@tiptap/core';
import { Plugin } from 'prosemirror-state';
import { findColors } from '../services/color';
import { findColors } from '../utils/color';
export const ColorHighlighter = Extension.create({
name: 'colorHighlighter',

View File

@ -1,7 +1,7 @@
import { Node, mergeAttributes } from '@tiptap/core';
import { ReactNodeViewRenderer } from '@tiptap/react';
import { CountdownWrapper } from '../wrappers/countdown';
import { getDatasetAttribute } from '../services/dataset';
import { getDatasetAttribute } from '../utils/dataset';
declare module '@tiptap/core' {
interface Commands<ReturnType> {

View File

@ -1,7 +1,7 @@
import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core';
import { ReactNodeViewRenderer } from '@tiptap/react';
import { DocumentChildrenWrapper } from '../wrappers/document-children';
import { getDatasetAttribute } from '../services/dataset';
import { getDatasetAttribute } from '../utils/dataset';
declare module '@tiptap/core' {
interface Commands<ReturnType> {

View File

@ -1,7 +1,7 @@
import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core';
import { ReactNodeViewRenderer } from '@tiptap/react';
import { DocumentReferenceWrapper } from '../wrappers/document-reference';
import { getDatasetAttribute } from '../services/dataset';
import { getDatasetAttribute } from '../utils/dataset';
declare module '@tiptap/core' {
interface Commands<ReturnType> {

View File

@ -1,6 +1,6 @@
import { Mark, mergeAttributes, markInputRule } from '@tiptap/core';
import { PARSE_HTML_PRIORITY_LOWEST } from '../constants';
import { markInputRegex, extractMarkAttributesFromMatch } from '../services/mark-utils';
import { markInputRegex, extractMarkAttributesFromMatch } from '../utils/mark-utils';
export const marks = [{ name: 'underline', tag: 'u' }];

View File

@ -1,7 +1,7 @@
import { Node, mergeAttributes } from '@tiptap/core';
import { ReactNodeViewRenderer } from '@tiptap/react';
import { IframeWrapper } from '../wrappers/iframe';
import { getDatasetAttribute } from '../services/dataset';
import { getDatasetAttribute } from '../utils/dataset';
declare module '@tiptap/core' {
interface Commands<ReturnType> {

View File

@ -1,10 +1,10 @@
import { Command, Extension } from '@tiptap/core';
import { sinkListItem, liftListItem } from 'prosemirror-schema-list';
import { TextSelection, AllSelection, Transaction } from 'prosemirror-state';
import { isListActive } from '../services/is-active';
import { clamp } from '../services/clamp';
import { getNodeType } from '../services/type';
import { isListNode } from '../services/node';
import { isListActive } from '../utils/is-active';
import { clamp } from '../utils/clamp';
import { getNodeType } from '../utils/type';
import { isListNode } from '../utils/node';
type IndentOptions = {
types: string[];

View File

@ -1,7 +1,7 @@
import { Node, mergeAttributes, nodeInputRule } from '@tiptap/core';
import { ReactNodeViewRenderer } from '@tiptap/react';
import { MindWrapper } from '../wrappers/mind';
import { getDatasetAttribute } from '../services/dataset';
import { getDatasetAttribute } from '../utils/dataset';
const DEFAULT_MIND_DATA = {
meta: {

View File

@ -1,5 +1,5 @@
import { OrderedList as BuiltInOrderedList } from '@tiptap/extension-ordered-list';
import { getMarkdownSource } from '../services/markdown';
import { getMarkdownSource } from '../markdown/markdown-to-prosemirror';
export const OrderedList = BuiltInOrderedList.extend({
addAttributes() {

View File

@ -1,15 +1,15 @@
import { Extension } from '@tiptap/core';
import { Plugin, PluginKey } from 'prosemirror-state';
import { EXTENSION_PRIORITY_HIGHEST } from '../constants';
import { handleFileEvent } from '../services/upload';
import { isInCode, LANGUAGES } from '../services/code';
import { handleFileEvent } from '../utils/upload';
import { isInCode, LANGUAGES } from '../utils/code';
import {
isMarkdown,
normalizePastedMarkdown,
markdownToProsemirror,
prosemirrorToMarkdown,
} from '../services/markdown';
import { isTitleNode } from '../services/node';
} from '../markdown/markdown-to-prosemirror';
import { isTitleNode } from '../utils/node';
export const Paste = Extension.create({
name: 'paste',

View File

@ -1,7 +1,7 @@
import { Extension } from '@tiptap/core';
import { Plugin, PluginKey, NodeSelection, TextSelection, Selection, AllSelection } from 'prosemirror-state';
import { Decoration, DecorationSet } from 'prosemirror-view';
import { getCurrentNode, isInCodeBlock, isInBanner } from '../services/node';
import { getCurrentNode, isInCodeBlock, isInBanner } from '../utils/node';
import { EXTENSION_PRIORITY_HIGHEST } from '../constants';
export const selectionPluginKey = new PluginKey('selection');

View File

@ -1,7 +1,7 @@
import { Node, mergeAttributes } from '@tiptap/core';
import { ReactNodeViewRenderer } from '@tiptap/react';
import { StatusWrapper } from '../wrappers/status';
import { getDatasetAttribute } from '../services/dataset';
import { getDatasetAttribute } from '../utils/dataset';
declare module '@tiptap/core' {
interface Commands<ReturnType> {

View File

@ -13,7 +13,7 @@ import {
isTableSelected,
selectRow,
selectTable,
} from '../services/table';
} from '../utils/table';
import { FloatMenuView } from '../views/float-menu';
export const TableCell = BuiltInTableCell.extend({

View File

@ -5,7 +5,7 @@ import { TableHeader as BuiltInTableHeader } from '@tiptap/extension-table-heade
import { Tooltip } from 'components/tooltip';
import { Plugin, PluginKey } from 'prosemirror-state';
import { Decoration, DecorationSet } from 'prosemirror-view';
import { getCellsInRow, isColumnSelected, isTableSelected, selectColumn } from '../services/table';
import { getCellsInRow, isColumnSelected, isTableSelected, selectColumn } from '../utils/table';
import { FloatMenuView } from '../views/float-menu';
// @flow

View File

@ -1,6 +1,6 @@
import { Node, mergeAttributes } from '@tiptap/core';
import { Plugin, PluginKey } from 'prosemirror-state';
import { isInTitle } from '../services/node';
import { isInTitle } from '../utils/node';
import { TextSelection } from 'prosemirror-state';
export interface TitleOptions {

View File

@ -4,7 +4,7 @@ import { CollaborationCursor } from './collaboration-cursor';
import History from '@tiptap/extension-history';
import { getRandomColor } from 'helpers/color';
import { Document } from './extensions/document';
export { BaseKit, CommentKit } from './basekit';
export { BaseKit, CommentKit } from './start-kit';
export { getSchema } from '@tiptap/core';
export * from './menubar';

View File

@ -1,4 +1,4 @@
import { BaseKit } from '../../../basekit';
import { BaseKit } from '../../../start-kit';
/**
* tiptap extension DOM
@ -17,11 +17,7 @@ const getAttribute = (
accu[key] = conf.default;
if (conf.parseHTML) {
// try {
accu[key] = conf.parseHTML(element);
// } catch (e) {
//
// }
}
return accu;

View File

@ -1,6 +1,6 @@
import { htmlToPromsemirror } from './html-to-prosemirror';
import { markdownToHTML } from './markdown-to-html';
export { prosemirrorToMarkdown } from './prosemirror-to-markdown';
export { prosemirrorToMarkdown } from '../prosemirror-to-markdown';
export * from './helpers';
export * from './markdown-source-map';

View File

@ -1,5 +1,5 @@
import container from 'markdown-it-container';
import { strToJSON, jsonToDOMDataset } from '../../dataset';
import { strToJSON, jsonToDOMDataset } from '../../../utils/dataset';
export const createMarkdownContainer = (types: string | Array<string>) => (md) => {
if (!Array.isArray(types)) {

View File

@ -1,4 +1,4 @@
import { jsonToStr } from '../../dataset';
import { jsonToStr } from '../../utils/dataset';
const uniq = (arr: string[]) => [...new Set(arr)];

View File

@ -1,39 +1,39 @@
import { MarkdownSerializer as ProseMirrorMarkdownSerializer, defaultMarkdownSerializer } from 'prosemirror-markdown';
import { Attachment } from '../../../extensions/attachment';
import { Banner } from '../../../extensions/banner';
import { Bold } from '../../../extensions/bold';
import { BulletList } from '../../../extensions/bullet-list';
import { Code } from '../../../extensions/code';
import { CodeBlock } from '../../../extensions/code-block';
import { Countdown } from '../../../extensions/countdown';
import { DocumentChildren } from '../../../extensions/document-children';
import { DocumentReference } from '../../../extensions/document-reference';
import { HardBreak } from '../../../extensions/hard-break';
import { Heading } from '../../../extensions/heading';
import { HorizontalRule } from '../../../extensions/horizontal-rule';
import { marks } from '../../../extensions/html-marks';
import { Iframe } from '../../../extensions/iframe';
import { Image } from '../../../extensions/image';
import { Italic } from '../../../extensions/italic';
import { Katex } from '../../../extensions/katex';
import { Link } from '../../../extensions/link';
import { ListItem } from '../../../extensions/listItem';
import { Mind } from '../../../extensions/mind';
import { OrderedList } from '../../../extensions/ordered-list';
import { Paragraph } from '../../../extensions/paragraph';
import { Status } from '../../../extensions/status';
import { Strike } from '../../../extensions/strike';
import { Subscript } from '../../../extensions/subscript';
import { Superscript } from '../../../extensions/superscript';
import { Table } from '../../../extensions/table';
import { TableCell } from '../../../extensions/table-cell';
import { TableHeader } from '../../../extensions/table-header';
import { TableRow } from '../../../extensions/table-row';
import { Text } from '../../../extensions/text';
import { TaskItem } from '../../../extensions/task-item';
import { TaskList } from '../../../extensions/task-list';
import { TextStyle } from '../../../extensions/text-style';
import { Title } from '../../../extensions/title';
import { Attachment } from '../../extensions/attachment';
import { Banner } from '../../extensions/banner';
import { Bold } from '../../extensions/bold';
import { BulletList } from '../../extensions/bullet-list';
import { Code } from '../../extensions/code';
import { CodeBlock } from '../../extensions/code-block';
import { Countdown } from '../../extensions/countdown';
import { DocumentChildren } from '../../extensions/document-children';
import { DocumentReference } from '../../extensions/document-reference';
import { HardBreak } from '../../extensions/hard-break';
import { Heading } from '../../extensions/heading';
import { HorizontalRule } from '../../extensions/horizontal-rule';
import { marks } from '../../extensions/html-marks';
import { Iframe } from '../../extensions/iframe';
import { Image } from '../../extensions/image';
import { Italic } from '../../extensions/italic';
import { Katex } from '../../extensions/katex';
import { Link } from '../../extensions/link';
import { ListItem } from '../../extensions/listItem';
import { Mind } from '../../extensions/mind';
import { OrderedList } from '../../extensions/ordered-list';
import { Paragraph } from '../../extensions/paragraph';
import { Status } from '../../extensions/status';
import { Strike } from '../../extensions/strike';
import { Subscript } from '../../extensions/subscript';
import { Superscript } from '../../extensions/superscript';
import { Table } from '../../extensions/table';
import { TableCell } from '../../extensions/table-cell';
import { TableHeader } from '../../extensions/table-header';
import { TableRow } from '../../extensions/table-row';
import { Text } from '../../extensions/text';
import { TaskItem } from '../../extensions/task-item';
import { TaskList } from '../../extensions/task-list';
import { TextStyle } from '../../extensions/text-style';
import { Title } from '../../extensions/title';
import {
isPlainURL,
renderHardBreak,

View File

@ -2,7 +2,7 @@ import React from 'react';
import { Editor } from '@tiptap/core';
import { Button, Dropdown, Tooltip } from '@douyinfe/semi-ui';
import { IconAlignLeft, IconAlignCenter, IconAlignRight, IconAlignJustify } from '@douyinfe/semi-icons';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
export const Align: React.FC<{ editor: Editor }> = ({ editor }) => {
const current = (() => {

View File

@ -3,7 +3,7 @@ import { Editor } from '@tiptap/core';
import { Button } from '@douyinfe/semi-ui';
import { IconMark } from '@douyinfe/semi-icons';
import { Tooltip } from 'components/tooltip';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
import { ColorPicker } from '../_components/color-picker';
export const BackgroundColor: React.FC<{ editor: Editor }> = ({ editor }) => {

View File

@ -5,7 +5,7 @@ import { Tooltip } from 'components/tooltip';
import { BubbleMenu } from '../../views/bubble-menu';
import { Divider } from '../../divider';
import { Banner } from '../../extensions/banner';
import { deleteNode } from '../../services/delete-node';
import { deleteNode } from '../../utils/delete-node';
export const BannerBubbleMenu: React.FC<{ editor: Editor }> = ({ editor }) => {
return (

View File

@ -3,7 +3,7 @@ import { Editor } from '@tiptap/core';
import { Button } from '@douyinfe/semi-ui';
import { Tooltip } from 'components/tooltip';
import { IconQuote } from 'components/icons';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
export const Blockquote: React.FC<{ editor: Editor }> = ({ editor }) => {
if (!editor) {

View File

@ -3,7 +3,7 @@ import { Editor } from '@tiptap/core';
import { Button } from '@douyinfe/semi-ui';
import { IconBold } from '@douyinfe/semi-icons';
import { Tooltip } from 'components/tooltip';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
export const Bold: React.FC<{ editor: Editor }> = ({ editor }) => {
if (!editor) {

View File

@ -3,7 +3,7 @@ import { Editor } from '@tiptap/core';
import { Button } from '@douyinfe/semi-ui';
import { IconList } from 'components/icons';
import { Tooltip } from 'components/tooltip';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
export const BulletList: React.FC<{ editor: Editor }> = ({ editor }) => {
if (!editor) {

View File

@ -3,7 +3,7 @@ import { Editor } from '@tiptap/core';
import { Button } from '@douyinfe/semi-ui';
import { IconCode } from '@douyinfe/semi-icons';
import { Tooltip } from 'components/tooltip';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
export const Code: React.FC<{ editor: Editor }> = ({ editor }) => {
if (!editor) {

View File

@ -1,7 +1,7 @@
import React, { useCallback } from 'react';
import { Select } from '@douyinfe/semi-ui';
import { Editor } from '@tiptap/core';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
export const FONT_SIZES = [12, 13, 14, 15, 16, 19, 22, 24, 29, 32, 40, 48];

View File

@ -1,7 +1,7 @@
import React, { useCallback } from 'react';
import { Editor } from '@tiptap/core';
import { Select } from '@douyinfe/semi-ui';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
const getCurrentCaretTitle = (editor) => {
if (editor.isActive('heading', { level: 1 })) return 1;

View File

@ -3,7 +3,7 @@ import { Editor } from '@tiptap/core';
import { Button } from '@douyinfe/semi-ui';
import { Tooltip } from 'components/tooltip';
import { IconHorizontalRule } from 'components/icons';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
export const HorizontalRule: React.FC<{ editor: Editor }> = ({ editor }) => {
if (!editor) {

View File

@ -3,7 +3,7 @@ import { Editor } from '@tiptap/core';
import { Button } from '@douyinfe/semi-ui';
import { IconIndentLeft, IconIndentRight } from '@douyinfe/semi-icons';
import { Tooltip } from 'components/tooltip';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
export const Ident: React.FC<{ editor: Editor }> = ({ editor }) => {
if (!editor) {

View File

@ -17,7 +17,7 @@ import {
IconCountdown,
} from 'components/icons';
import { GridSelect } from 'components/grid-select';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
import { createCountdown } from '../countdown/service';
export const Insert: React.FC<{ editor: Editor }> = ({ editor }) => {

View File

@ -3,7 +3,7 @@ import { Editor } from '@tiptap/core';
import { Button } from '@douyinfe/semi-ui';
import { IconItalic } from '@douyinfe/semi-icons';
import { Tooltip } from 'components/tooltip';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
export const Italic: React.FC<{ editor: Editor }> = ({ editor }) => {
if (!editor) {

View File

@ -5,8 +5,8 @@ import { Tooltip } from 'components/tooltip';
import { Divider } from '../../divider';
import { BubbleMenu } from '../../views/bubble-menu';
import { Link } from '../../extensions/link';
import { isMarkActive } from '../../services/is-active';
import { findMarkPosition } from '../../services/find-position';
import { isMarkActive } from '../../utils/is-active';
import { findMarkPosition } from '../../utils/find-position';
import { triggerOpenLinkSettingModal } from '../_event';
export const LinkBubbleMenu = ({ editor }) => {

View File

@ -3,7 +3,7 @@ import { Editor } from '@tiptap/core';
import { Button } from '@douyinfe/semi-ui';
import { Tooltip } from 'components/tooltip';
import { IconLink } from 'components/icons';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
import { createOrToggleLink } from './service';
import { LinkBubbleMenu } from './bubble';
import { LinkSettingModal } from './modal';

View File

@ -3,7 +3,7 @@ import { Form, Modal } from '@douyinfe/semi-ui';
import { FormApi } from '@douyinfe/semi-ui/lib/es/form';
import { Editor } from '@tiptap/core';
import { useToggle } from 'hooks/use-toggle';
import { isValidURL } from '../../services/valid-url';
import { isValidURL } from '../../utils/valid-url';
import { event, OPEN_LINK_SETTING_MODAL } from '../_event';
type IProps = { editor: Editor };

View File

@ -1,5 +1,5 @@
import { Editor } from '@tiptap/core';
import { isMarkActive } from '../../services/is-active';
import { isMarkActive } from '../../utils/is-active';
import { triggerOpenLinkSettingModal } from '../_event';
/**

View File

@ -3,7 +3,7 @@ import { Editor } from '@tiptap/core';
import { Button } from '@douyinfe/semi-ui';
import { IconOrderedList } from 'components/icons';
import { Tooltip } from 'components/tooltip';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
export const OrderedList: React.FC<{ editor: Editor }> = ({ editor }) => {
if (!editor) {

View File

@ -3,7 +3,7 @@ import { Editor } from '@tiptap/core';
import { Button } from '@douyinfe/semi-ui';
import { IconStrikeThrough } from '@douyinfe/semi-icons';
import { Tooltip } from 'components/tooltip';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
export const Strike: React.FC<{ editor: Editor }> = ({ editor }) => {
if (!editor) {

View File

@ -2,7 +2,7 @@ import React from 'react';
import { Button } from '@douyinfe/semi-ui';
import { IconSub } from 'components/icons';
import { Tooltip } from 'components/tooltip';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
export const Subscript: React.FC<{ editor: any }> = ({ editor }) => {
if (!editor) {

View File

@ -2,7 +2,7 @@ import React from 'react';
import { Button } from '@douyinfe/semi-ui';
import { IconSup } from 'components/icons';
import { Tooltip } from 'components/tooltip';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
export const Superscript: React.FC<{ editor: any }> = ({ editor }) => {
if (!editor) {

View File

@ -3,7 +3,7 @@ import { Editor } from '@tiptap/core';
import { Button } from '@douyinfe/semi-ui';
import { Tooltip } from 'components/tooltip';
import { IconTask } from 'components/icons';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
export const TaskList: React.FC<{ editor: Editor }> = ({ editor }) => {
if (!editor) {

View File

@ -3,7 +3,7 @@ import { Editor } from '@tiptap/core';
import { Button } from '@douyinfe/semi-ui';
import { IconFont } from '@douyinfe/semi-icons';
import { Tooltip } from 'components/tooltip';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
import { ColorPicker } from '../_components/color-picker';
export const TextColor: React.FC<{ editor: Editor }> = ({ editor }) => {

View File

@ -3,7 +3,7 @@ import { Editor } from '@tiptap/core';
import { Button } from '@douyinfe/semi-ui';
import { IconUnderline } from '@douyinfe/semi-icons';
import { Tooltip } from 'components/tooltip';
import { isTitleActive } from '../../services/is-active';
import { isTitleActive } from '../../utils/is-active';
export const Underline: React.FC<{ editor: Editor }> = ({ editor }) => {
if (!editor) {

Some files were not shown because too many files have changed in this diff Show More