Skip to content

Commit

Permalink
refactor(portable-text-editor): rename type > schemaType
Browse files Browse the repository at this point in the history
Keep consistent with the rest of the codebase
  • Loading branch information
skogsmaskin committed Dec 20, 2022
1 parent d25cbb5 commit b18716f
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 19 deletions.
Expand Up @@ -20,7 +20,7 @@ const Root = styled.div`
export function BlockActions(props: BlockActionsProps) {
const editor = usePortableTextEditor()
const {block, onChange, renderBlockActions} = props
const decoratorValues = useMemo(() => editor.types.decorators.map((d) => d.value), [editor])
const decoratorValues = useMemo(() => editor.schemaTypes.decorators.map((d) => d.value), [editor])

const blockActions = useMemo(() => {
if (renderBlockActions) {
Expand Down
Expand Up @@ -137,7 +137,7 @@ export function Compositor(props: Omit<InputProps, 'schemaType' | 'arrayFunction
type: blockType,
value: block,
} = blockProps
const isTextBlock = block._type === editor.types.block.name
const isTextBlock = block._type === editor.schemaTypes.block.name
if (isTextBlock) {
return (
<TextBlock
Expand Down Expand Up @@ -178,7 +178,7 @@ export function Compositor(props: Omit<InputProps, 'schemaType' | 'arrayFunction
[
_renderBlockActions,
_renderCustomMarkers,
editor.types.block.name,
editor.schemaTypes.block.name,
isFullscreen,
onChange,
onItemOpen,
Expand All @@ -196,10 +196,10 @@ export function Compositor(props: Omit<InputProps, 'schemaType' | 'arrayFunction
focused: childFocused,
path: childPath,
selected,
type: childType,
schemaType: childType,
value: child,
} = childProps
const isSpan = child._type === editor.types.span.name
const isSpan = child._type === editor.schemaTypes.span.name
if (isSpan) {
return children
}
Expand Down
Expand Up @@ -338,7 +338,7 @@ export function PortableTextInput(props: PortableTextInputProps) {
onChange={handleEditorChange}
maxBlocks={undefined} // TODO: from schema?
readOnly={readOnly}
type={schemaType} // TODO: rename to schemaType inside PortableTextEditor?
schemaType={schemaType}
value={value}
>
<Compositor
Expand Down
Expand Up @@ -15,7 +15,7 @@ export function useHotkeys(hotkeys: HotkeyOptions): HotkeyOptions {
}
return useMemo(() => {
const defaultHotkeys: {marks: Record<string, string>} = {marks: {}}
editor.types.decorators.forEach((dec) => {
editor.schemaTypes.decorators.forEach((dec) => {
switch (dec.value) {
case 'strong':
defaultHotkeys.marks['mod+b'] = dec.value
Expand Down
Expand Up @@ -7,7 +7,7 @@ export function useSpellcheck(): boolean {
// Chrome 96. has serious perf. issues with spellchecking
// https://bugs.chromium.org/p/chromium/issues/detail?id=1271918
// This issue is verified fixed in Chrome 97.
const spellCheckOption = editor.types.block.options?.spellCheck
const spellCheckOption = editor.schemaTypes.block.options?.spellCheck
const isChrome96 =
typeof navigator === 'undefined' ? false : /Chrome\/96/.test(navigator.userAgent)
return spellCheckOption === undefined && isChrome96 === true ? false : spellCheckOption
Expand Down
Expand Up @@ -24,7 +24,7 @@ export const ActionMenu = memo(function ActionMenu(props: ActionMenuProps) {
const focusBlock = useFocusBlock()
const editor = usePortableTextEditor()

const isVoidBlock = focusBlock?._type !== editor.types.block.name
const isVoidBlock = focusBlock?._type !== editor.schemaTypes.block.name
const isEmptyTextBlock =
!isVoidBlock &&
Array.isArray(focusBlock.children) &&
Expand Down
Expand Up @@ -72,7 +72,8 @@ export const BlockStyleSelect = memo(function BlockStyleSelect(
const focusBlock = useFocusBlock()
const [changed, setChanged] = useState(false)

const _disabled = disabled || (focusBlock ? editor.types.block.name !== focusBlock._type : false)
const _disabled =
disabled || (focusBlock ? editor.schemaTypes.block.name !== focusBlock._type : false)

// @todo: Explain what this does
const activeKeys = useActiveStyleKeys({items: itemsProp})
Expand Down
Expand Up @@ -22,7 +22,7 @@ export const InsertMenu = memo(function InsertMenu(props: InsertMenuProps) {
const focusBlock = useFocusBlock()
const editor = usePortableTextEditor()

const isVoidFocus = focusBlock && focusBlock._type !== editor.types.block.name
const isVoidFocus = focusBlock && focusBlock._type !== editor.schemaTypes.block.name

const handleMenuClose = useCallback(() => {
PortableTextEditor.focus(editor)
Expand Down
Expand Up @@ -226,10 +226,10 @@ export function Toolbar(props: ToolbarProps) {
disabled: true,
})

const blockStyles = useMemo(() => getBlockStyles(editor.types), [editor])
const blockStyles = useMemo(() => getBlockStyles(editor.schemaTypes), [editor])

const insertMenuItems = useMemo(
() => getInsertMenuItems(editor.types, disabled, handleInsertBlock, handleInsertInline),
() => getInsertMenuItems(editor.schemaTypes, disabled, handleInsertBlock, handleInsertInline),
[disabled, editor, handleInsertBlock, handleInsertInline]
)

Expand Down
Expand Up @@ -14,7 +14,7 @@ import {
import {
HotkeyOptions,
PortableTextEditor,
PortableTextMemberTypes,
PortableTextMemberSchemaTypes,
} from '@sanity/portable-text-editor'
import {capitalize, get} from 'lodash'
import React from 'react'
Expand All @@ -27,7 +27,7 @@ function getPTEFormatActions(
disabled: boolean,
hotkeyOpts: HotkeyOptions
): PTEToolbarAction[] {
const types = editor.types
const types = editor.schemaTypes
return types.decorators.map((decorator) => {
const shortCutKey = Object.keys(hotkeyOpts.marks || {}).find(
(key) => hotkeyOpts.marks?.[key] === decorator.value
Expand All @@ -54,7 +54,7 @@ function getPTEFormatActions(
}

function getPTEListActions(editor: PortableTextEditor, disabled: boolean): PTEToolbarAction[] {
const types = PortableTextEditor.getTypes(editor)
const types = editor.schemaTypes
return types.lists.map((listItem) => {
return {
type: 'listStyle',
Expand Down Expand Up @@ -83,7 +83,7 @@ function getPTEAnnotationActions(
disabled: boolean,
onInsert: (type: ObjectSchemaType) => void
): PTEToolbarAction[] {
const types = editor.types
const types = editor.schemaTypes
const focusChild = PortableTextEditor.focusChild(editor)
const hasText = focusChild && focusChild.text
return types.annotations.map((aType) => {
Expand Down Expand Up @@ -118,7 +118,7 @@ export function getPTEToolbarActionGroups(
]
}

export function getBlockStyles(types: PortableTextMemberTypes): BlockStyleItem[] {
export function getBlockStyles(types: PortableTextMemberSchemaTypes): BlockStyleItem[] {
return types.styles.map((style) => {
return {
key: `style-${style.value}`,
Expand All @@ -139,7 +139,7 @@ function getInsertMenuIcon(
}

export function getInsertMenuItems(
types: PortableTextMemberTypes,
types: PortableTextMemberSchemaTypes,
disabled: boolean,
onInsertBlock: (type: ObjectSchemaType) => void,
onInsertInline: (type: ObjectSchemaType) => void
Expand Down

0 comments on commit b18716f

Please sign in to comment.