Skip to content

Commit

Permalink
removed start attribute handling in ordered lists
Browse files Browse the repository at this point in the history
  • Loading branch information
iskaktoltay committed Oct 22, 2024
1 parent 7fbe521 commit bb849f2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 51 deletions.
1 change: 0 additions & 1 deletion frontend/apps/desktop/src/editor/block-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export function updateGroup(
listType,
false,
undefined,
undefined,
true,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ declare module '@tiptap/core' {
posInBlock: number,
listType: HMBlockChildrenType,
tab: boolean,
start?: string,
// start?: string,
isSank?: boolean,
turnInto?: boolean,
) => ReturnType
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(() => {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);`,
// }
// }
// },
// },
}
},

Expand Down Expand Up @@ -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
Expand All @@ -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})
Expand Down Expand Up @@ -114,7 +115,7 @@ export const BlockGroup = Node.create<{

return {
listType: 'Ordered',
start: element.getAttribute('start'),
// start: element.getAttribute('start'),
}
// return false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,21 @@ var turnIntoItems = [
})
},
},
{
label: 'Block Quote',
group: 'Group operations',
Icon: RiChatQuoteFill,
onClick: ({
block,
editor,
}: {
block: Block<HMBlockSchema>
editor: BlockNoteEditor<HMBlockSchema>
}) => {
editor.focus()
updateGroup(editor, block, 'blockquote')
},
},
// {
// label: 'Block Quote',
// group: 'Group operations',
// Icon: RiChatQuoteFill,
// onClick: ({
// block,
// editor,
// }: {
// block: Block<HMBlockSchema>
// editor: BlockNoteEditor<HMBlockSchema>
// }) => {
// editor.focus()
// updateGroup(editor, block, 'Blockquote')
// },
// },
{
label: 'Bullet item',
group: 'Group operations',
Expand Down
7 changes: 4 additions & 3 deletions frontend/apps/desktop/src/utils/blocks-to-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ function convertBlockToHtml(block: any, isListItem = false) {
if (block.props.childrenType === 'Unordered') {
childrenHtml = `<ul>${childrenContent}</ul>`
} else if (block.props.childrenType === 'Ordered') {
childrenHtml = `<ol start="${
block.props.start || 1
}">${childrenContent}</ol>`
// childrenHtml = `<ol start="${
// block.props.start || 1
// }">${childrenContent}</ol>`
childrenHtml = `<ol>${childrenContent}</ol>`
} else if (block.props.childrenType === 'Blockquote') {
childrenHtml = `<blockquote>${childrenContent}</blockquote>`
} else {
Expand Down

0 comments on commit bb849f2

Please sign in to comment.