-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
424dd4e
commit 5e35643
Showing
7 changed files
with
62 additions
and
1 deletion.
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
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 @@ | ||
export * from './isIndentElement'; |
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 @@ | ||
import { isDefined, isElement, TElement, Value } from '@udecode/plate-common'; | ||
|
||
export const isIndentElement = <V extends Value>(element: TElement) => { | ||
return isElement(element) && isDefined(element.listStyleType); | ||
}; |
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,48 @@ | ||
import { | ||
ELEMENT_DEFAULT, | ||
getAboveNode, | ||
getNodeString, | ||
getPreviousNode, | ||
isDefined, | ||
isElement, | ||
PlateEditor, | ||
removeNodes, | ||
select, | ||
TElement, | ||
unsetNodes, | ||
Value, | ||
} from '@udecode/plate-common'; | ||
import { outdent } from '@udecode/plate-indent'; | ||
import { Point } from 'slate'; | ||
|
||
import { isIndentElement } from '../queries'; | ||
|
||
export const deleteWhenEmpty = <V extends Value>( | ||
editor: PlateEditor<V>, | ||
pointBefore: Point | ||
) => { | ||
const aboveEntry = getAboveNode(editor, { | ||
match: (n) => isElement(n) && n.type === ELEMENT_DEFAULT, | ||
}); | ||
|
||
const prevEntry = getPreviousNode(editor, { | ||
match: (n) => n.type === ELEMENT_DEFAULT || n.type === 'blockquote', | ||
}); | ||
|
||
if (!prevEntry || !aboveEntry) return; | ||
|
||
const [prevCell] = prevEntry; | ||
const [aboveCell] = aboveEntry; | ||
|
||
if (!getNodeString(prevCell) && !isDefined(aboveCell.listStyleType)) { | ||
removeNodes(editor); | ||
select(editor, pointBefore); | ||
return true; | ||
} | ||
|
||
if (!getNodeString(aboveCell) && isIndentElement(aboveCell as TElement)) { | ||
outdent(editor); | ||
unsetNodes(editor, ['listStyleType', 'checked']); | ||
return true; | ||
} | ||
}; |
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 @@ | ||
export * from './deleteWhenEmpty'; |
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