From bb849f2a2c791961cecc72a47329556dd0cfd62b Mon Sep 17 00:00:00 2001 From: iskaktoltay Date: Tue, 22 Oct 2024 12:00:45 +0500 Subject: [PATCH] removed start attribute handling in ordered lists --- .../apps/desktop/src/editor/block-utils.ts | 1 - .../extensions/Blocks/nodes/BlockContainer.ts | 37 ++++++++++--------- .../extensions/Blocks/nodes/BlockGroup.ts | 29 ++++++++------- .../DragHandleMenu/DefaultDragHandleMenu.tsx | 30 +++++++-------- .../desktop/src/utils/blocks-to-markdown.ts | 7 ++-- 5 files changed, 53 insertions(+), 51 deletions(-) diff --git a/frontend/apps/desktop/src/editor/block-utils.ts b/frontend/apps/desktop/src/editor/block-utils.ts index b7d0f3d6..8a7cf53a 100644 --- a/frontend/apps/desktop/src/editor/block-utils.ts +++ b/frontend/apps/desktop/src/editor/block-utils.ts @@ -61,7 +61,6 @@ export function updateGroup( listType, false, undefined, - undefined, true, ) } diff --git a/frontend/apps/desktop/src/editor/blocknote/core/extensions/Blocks/nodes/BlockContainer.ts b/frontend/apps/desktop/src/editor/blocknote/core/extensions/Blocks/nodes/BlockContainer.ts index 801b3007..1b529276 100644 --- a/frontend/apps/desktop/src/editor/blocknote/core/extensions/Blocks/nodes/BlockContainer.ts +++ b/frontend/apps/desktop/src/editor/blocknote/core/extensions/Blocks/nodes/BlockContainer.ts @@ -265,7 +265,7 @@ declare module '@tiptap/core' { posInBlock: number, listType: HMBlockChildrenType, tab: boolean, - start?: string, + // start?: string, isSank?: boolean, turnInto?: boolean, ) => ReturnType @@ -626,7 +626,7 @@ export const BlockContainer = Node.create<{ .deleteSelection() .BNSplitBlock(state.selection.from, false) .sinkListItem('blockContainer') - .UpdateGroup(-1, blockInfo.node.attrs.listType, true, undefined) + .UpdateGroup(-1, blockInfo.node.attrs.listType, true) .run() }) } else { @@ -723,7 +723,7 @@ export const BlockContainer = Node.create<{ }, // Updates a block group at a given position. UpdateGroup: - (posInBlock, listType, tab, start, isSank = false, turnInto = false) => + (posInBlock, listType, tab, isSank = false, turnInto = false) => ({state, dispatch}) => { // Find block group, block container and depth it is at const { @@ -793,7 +793,7 @@ export const BlockContainer = Node.create<{ this.editor .chain() .sinkListItem('blockContainer') - .UpdateGroup(-1, listType, tab, start, true) + .UpdateGroup(-1, listType, tab, true) .run() return true @@ -814,7 +814,7 @@ export const BlockContainer = Node.create<{ this.editor .chain() .sinkListItem('blockContainer') - .UpdateGroup(-1, listType, tab, start, true) + .UpdateGroup(-1, listType, tab, true) .run() return true @@ -837,18 +837,19 @@ export const BlockContainer = Node.create<{ } } - start - ? state.tr.setNodeMarkup($pos.before(depth), null, { - ...group.attrs, - listType: listType, - listLevel: level, - start: parseInt(start), - }) - : state.tr.setNodeMarkup($pos.before(depth), null, { - ...group.attrs, - listType: listType, - listLevel: level, - }) + // start + // ? state.tr.setNodeMarkup($pos.before(depth), null, { + // ...group.attrs, + // listType: listType, + // listLevel: level, + // start: parseInt(start), + // }) + // : + state.tr.setNodeMarkup($pos.before(depth), null, { + ...group.attrs, + listType: listType, + listLevel: level, + }) if (container) { setTimeout(() => { @@ -1314,7 +1315,7 @@ export const BlockContainer = Node.create<{ this.editor .chain() .sinkListItem('blockContainer') - .UpdateGroup(-1, group.attrs.listType, true, undefined) + .UpdateGroup(-1, group.attrs.listType, true) .run() }) return true diff --git a/frontend/apps/desktop/src/editor/blocknote/core/extensions/Blocks/nodes/BlockGroup.ts b/frontend/apps/desktop/src/editor/blocknote/core/extensions/Blocks/nodes/BlockGroup.ts index 3ff36494..110eabe6 100644 --- a/frontend/apps/desktop/src/editor/blocknote/core/extensions/Blocks/nodes/BlockGroup.ts +++ b/frontend/apps/desktop/src/editor/blocknote/core/extensions/Blocks/nodes/BlockGroup.ts @@ -31,17 +31,17 @@ export const BlockGroup = Node.create<{ } }, }, - start: { - default: '1', - renderHTML: (attributes) => { - if (attributes.listType === 'Ordered' && attributes.start) { - return { - start: attributes.start, - // style: `margin-left: calc(1em + ${offset}em);`, - } - } - }, - }, + // start: { + // default: '1', + // renderHTML: (attributes) => { + // if (attributes.listType === 'Ordered' && attributes.start) { + // return { + // start: attributes.start, + // // style: `margin-left: calc(1em + ${offset}em);`, + // } + // } + // }, + // }, } }, @@ -70,7 +70,8 @@ export const BlockGroup = Node.create<{ }, }), new InputRule({ - find: new RegExp(/^\d+\.\s/), + // find: new RegExp(/^\d+\.\s/), + find: new RegExp(/^[1]+\.\s/), handler: ({state, chain, range}) => { if (state.doc.resolve(range.from).parent.type.name === 'heading') { return @@ -80,7 +81,7 @@ export const BlockGroup = Node.create<{ state.selection.from, 'Ordered', false, - this.editor.state.doc.textBetween(range.from, range.to - 1), + // this.editor.state.doc.textBetween(range.from, range.to - 1), ) // Removes the "1." characters used to set the list. .deleteRange({from: range.from, to: range.to}) @@ -114,7 +115,7 @@ export const BlockGroup = Node.create<{ return { listType: 'Ordered', - start: element.getAttribute('start'), + // start: element.getAttribute('start'), } // return false }, diff --git a/frontend/apps/desktop/src/editor/blocknote/react/SideMenu/components/DragHandleMenu/DefaultDragHandleMenu.tsx b/frontend/apps/desktop/src/editor/blocknote/react/SideMenu/components/DragHandleMenu/DefaultDragHandleMenu.tsx index 4d794107..2d76b2f8 100644 --- a/frontend/apps/desktop/src/editor/blocknote/react/SideMenu/components/DragHandleMenu/DefaultDragHandleMenu.tsx +++ b/frontend/apps/desktop/src/editor/blocknote/react/SideMenu/components/DragHandleMenu/DefaultDragHandleMenu.tsx @@ -144,21 +144,21 @@ var turnIntoItems = [ }) }, }, - { - label: 'Block Quote', - group: 'Group operations', - Icon: RiChatQuoteFill, - onClick: ({ - block, - editor, - }: { - block: Block - editor: BlockNoteEditor - }) => { - editor.focus() - updateGroup(editor, block, 'blockquote') - }, - }, + // { + // label: 'Block Quote', + // group: 'Group operations', + // Icon: RiChatQuoteFill, + // onClick: ({ + // block, + // editor, + // }: { + // block: Block + // editor: BlockNoteEditor + // }) => { + // editor.focus() + // updateGroup(editor, block, 'Blockquote') + // }, + // }, { label: 'Bullet item', group: 'Group operations', diff --git a/frontend/apps/desktop/src/utils/blocks-to-markdown.ts b/frontend/apps/desktop/src/utils/blocks-to-markdown.ts index 2fa94ef0..6c4ace92 100644 --- a/frontend/apps/desktop/src/utils/blocks-to-markdown.ts +++ b/frontend/apps/desktop/src/utils/blocks-to-markdown.ts @@ -48,9 +48,10 @@ function convertBlockToHtml(block: any, isListItem = false) { if (block.props.childrenType === 'Unordered') { childrenHtml = `
    ${childrenContent}
` } else if (block.props.childrenType === 'Ordered') { - childrenHtml = `
    ${childrenContent}
` + // childrenHtml = `
    ${childrenContent}
` + childrenHtml = `
    ${childrenContent}
` } else if (block.props.childrenType === 'Blockquote') { childrenHtml = `
${childrenContent}
` } else {