forked from remirror/remirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(extension-list): improve list item node view performance (remirro…
- Loading branch information
Showing
5 changed files
with
70 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@remirror/extension-list': patch | ||
--- | ||
|
||
Improve the performance of large task lists and collapsible bullet lists. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 21 additions & 29 deletions
50
packages/remirror__extension-list/src/list-item-node-view.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,44 @@ | ||
import type { EditorView, NodeView } from '@remirror/pm/view'; | ||
import { ProsemirrorNode } from '@remirror/pm'; | ||
import type { NodeView } from '@remirror/pm/view'; | ||
import { ExtensionListTheme } from '@remirror/theme'; | ||
|
||
type UpdateElement = (node: ProsemirrorNode, dom: HTMLElement) => void; | ||
|
||
export function createCustomMarkListItemNodeView({ | ||
node, | ||
mark, | ||
extraAttrs, | ||
extraClasses, | ||
view, | ||
updateDOM, | ||
updateMark, | ||
}: { | ||
node: ProsemirrorNode; | ||
mark: HTMLElement; | ||
extraAttrs?: Record<string, string>; | ||
extraClasses?: string[]; | ||
view: EditorView; | ||
updateDOM: UpdateElement; | ||
updateMark: UpdateElement; | ||
}): NodeView { | ||
const dom = document.createElement('li'); | ||
dom.classList.add(ExtensionListTheme.LIST_ITEM_WITH_CUSTOM_MARKER); | ||
|
||
if (extraClasses) { | ||
extraClasses.forEach((className) => dom.classList.add(className)); | ||
} | ||
|
||
const markContainer = document.createElement('span'); | ||
markContainer.contentEditable = 'false'; | ||
markContainer.classList.add(ExtensionListTheme.LIST_ITEM_MARKER_CONTAINER); | ||
markContainer.append(mark); | ||
|
||
const contentDOM = document.createElement('div'); | ||
|
||
markContainer.append(mark); | ||
const dom = document.createElement('li'); | ||
dom.classList.add(ExtensionListTheme.LIST_ITEM_WITH_CUSTOM_MARKER); | ||
dom.append(markContainer); | ||
dom.append(contentDOM); | ||
|
||
// When a list item node's `content` updates, it's necessary to re-run the | ||
// nodeView function so that the list item node's `disabled` class can be | ||
// updated. | ||
// | ||
// However, when users are using IME, never re-create the nodeView. See also #1017. | ||
const update = (): boolean => { | ||
if (view?.composing) { | ||
return true; | ||
const update = (newNode: ProsemirrorNode): boolean => { | ||
if (newNode.type !== node.type) { | ||
return false; | ||
} | ||
|
||
return false; | ||
node = newNode; | ||
updateDOM(node, dom); | ||
updateMark(node, mark); | ||
return true; | ||
}; | ||
|
||
if (extraAttrs) { | ||
for (const [key, value] of Object.entries(extraAttrs)) { | ||
dom.setAttribute(key, value); | ||
} | ||
} | ||
update(node); | ||
|
||
return { dom, contentDOM, update }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters