forked from keystonejs/keystone
-
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.
Co-authored-by: Daniel Cousens <[email protected]>
- Loading branch information
Showing
10 changed files
with
35 additions
and
79 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 @@ | ||
--- | ||
'@keystone-6/fields-document': patch | ||
--- | ||
|
||
Updates slate and slate-react to ^0.81.1 |
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
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
41 changes: 3 additions & 38 deletions
41
packages/fields-document/src/DocumentEditor/soft-breaks.tsx
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,44 +1,9 @@ | ||
import { MutableRefObject, useEffect, useRef } from 'react'; | ||
import { Transforms, Editor } from 'slate'; | ||
|
||
export function withSoftBreaks( | ||
isShiftPressedRef: MutableRefObject<boolean>, | ||
editor: Editor | ||
): Editor { | ||
const { insertBreak } = editor; | ||
export function withSoftBreaks(editor: Editor): Editor { | ||
// TODO: should soft breaks only work in particular places | ||
editor.insertBreak = () => { | ||
if (isShiftPressedRef.current) { | ||
Transforms.insertText(editor, '\n'); | ||
} else { | ||
insertBreak(); | ||
} | ||
editor.insertSoftBreak = () => { | ||
Transforms.insertText(editor, '\n'); | ||
}; | ||
return editor; | ||
} | ||
|
||
export function useKeyDownRef(targetKey: string) { | ||
const ref = useRef(false); | ||
|
||
useEffect(() => { | ||
const handleKeyDown = (e: globalThis.KeyboardEvent) => { | ||
if (e.key !== targetKey) return; | ||
ref.current = true; | ||
}; | ||
|
||
const handleKeyUp = (e: globalThis.KeyboardEvent) => { | ||
if (e.key !== targetKey) return; | ||
ref.current = false; | ||
}; | ||
|
||
document.addEventListener('keydown', handleKeyDown, { passive: true }); | ||
document.addEventListener('keyup', handleKeyUp, { passive: true }); | ||
|
||
return () => { | ||
document.removeEventListener('keydown', handleKeyDown); | ||
document.removeEventListener('keyup', handleKeyUp); | ||
}; | ||
}, [targetKey]); | ||
|
||
return ref; | ||
} |
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
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