diff --git a/docs/walkthroughs/04-applying-custom-formatting.md b/docs/walkthroughs/04-applying-custom-formatting.md index 5fea3c7c2..df89f965a 100644 --- a/docs/walkthroughs/04-applying-custom-formatting.md +++ b/docs/walkthroughs/04-applying-custom-formatting.md @@ -90,7 +90,9 @@ const App = () => { Transforms.setNodes( editor, { type: match ? 'paragraph' : 'code' }, - { match: n => Element.isElement(n) && Editor.isBlock(editor, n) } + { + match: n => Element.isElement(n) && Editor.isBlock(editor, n), + } ) break } @@ -178,7 +180,9 @@ const App = () => { Transforms.setNodes( editor, { type: match ? null : 'code' }, - { match: n => Element.isElement(n) && Editor.isBlock(editor, n) } + { + match: n => Element.isElement(n) && Editor.isBlock(editor, n), + } ) break } diff --git a/package.json b/package.json index 65ade27ec..291463871 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,8 @@ "@emotion/css": "^11.11.2", "@faker-js/faker": "^8.2.0", "@playwright/test": "^1.39.0", + "@types/is-hotkey": "^0.1.10", + "@types/is-url": "^1.2.32", "@types/jest": "29.5.6", "@types/lodash": "^4.14.200", "@types/mocha": "^10.0.3", diff --git a/site/examples/js/check-lists.jsx b/site/examples/js/check-lists.jsx index 6e56ed77d..36084fc80 100644 --- a/site/examples/js/check-lists.jsx +++ b/site/examples/js/check-lists.jsx @@ -121,9 +121,9 @@ const Element = props => { } } const CheckListItemElement = ({ attributes, children, element }) => { + const { checked } = element const editor = useSlateStatic() const readOnly = useReadOnly() - const { checked } = element return (
{ return useCallback( ([node, path]) => { if (Element.isElement(node) && node.type === CodeLineType) { - const ranges = editor.nodeToDecorations.get(node) || [] + const ranges = editor.nodeToDecorations?.get(node) || [] return ranges } return [] diff --git a/site/examples/js/components/index.jsx b/site/examples/js/components/index.jsx index 072558217..bb6c725ec 100644 --- a/site/examples/js/components/index.jsx +++ b/site/examples/js/components/index.jsx @@ -1,6 +1,6 @@ +import { css, cx } from '@emotion/css' import React from 'react' import ReactDOM from 'react-dom' -import { cx, css } from '@emotion/css' export const Button = React.forwardRef( ({ className, active, reversed, ...props }, ref) => ( @@ -23,51 +23,6 @@ export const Button = React.forwardRef( /> ) ) -export const EditorValue = React.forwardRef( - ({ className, value, ...props }, ref) => { - const textLines = value.document.nodes - .map(node => node.text) - .toArray() - .join('\n') - return ( -
-
- Slate's value as text -
-
- {textLines} -
-
- ) - } -) export const Icon = React.forwardRef(({ className, ...props }, ref) => ( { const editor = useMemo( diff --git a/site/examples/js/forced-layout.jsx b/site/examples/js/forced-layout.jsx index b6b815ffe..5186ba1c1 100644 --- a/site/examples/js/forced-layout.jsx +++ b/site/examples/js/forced-layout.jsx @@ -1,13 +1,13 @@ import React, { useCallback, useMemo } from 'react' -import { Slate, Editable, withReact } from 'slate-react' import { - Transforms, - createEditor, + Editor, Node, Element as SlateElement, - Editor, + Transforms, + createEditor, } from 'slate' import { withHistory } from 'slate-history' +import { Editable, Slate, withReact } from 'slate-react' const withLayout = editor => { const { normalizeNode } = editor diff --git a/site/examples/js/hovering-toolbar.jsx b/site/examples/js/hovering-toolbar.jsx index 002d7f4e6..9282aadc7 100644 --- a/site/examples/js/hovering-toolbar.jsx +++ b/site/examples/js/hovering-toolbar.jsx @@ -1,8 +1,8 @@ -import React, { useMemo, useRef, useEffect } from 'react' -import { Slate, Editable, withReact, useSlate, useFocused } from 'slate-react' -import { Editor, createEditor, Range } from 'slate' import { css } from '@emotion/css' +import React, { useEffect, useMemo, useRef } from 'react' +import { Editor, Range, createEditor } from 'slate' import { withHistory } from 'slate-history' +import { Editable, Slate, useFocused, useSlate, withReact } from 'slate-react' import { Button, Icon, Menu, Portal } from './components' const HoveringMenuExample = () => { @@ -23,7 +23,7 @@ const HoveringMenuExample = () => { return toggleMark(editor, 'italic') case 'formatUnderline': event.preventDefault() - return toggleMark(editor, 'underlined') + return toggleMark(editor, 'underline') } }} /> @@ -49,13 +49,13 @@ const Leaf = ({ attributes, children, leaf }) => { if (leaf.italic) { children = {children} } - if (leaf.underlined) { + if (leaf.underline) { children = {children} } return {children} } const HoveringToolbar = () => { - const ref = useRef() + const ref = useRef(null) const editor = useSlate() const inFocus = useFocused() useEffect(() => { @@ -105,7 +105,7 @@ const HoveringToolbar = () => { > - + ) diff --git a/site/examples/js/huge-document.jsx b/site/examples/js/huge-document.jsx index 789c01948..deae2380e 100644 --- a/site/examples/js/huge-document.jsx +++ b/site/examples/js/huge-document.jsx @@ -1,21 +1,23 @@ -import React, { useMemo, useCallback } from 'react' import { faker } from '@faker-js/faker' +import React, { useCallback, useMemo } from 'react' import { createEditor } from 'slate' -import { Slate, Editable, withReact } from 'slate-react' +import { Editable, Slate, withReact } from 'slate-react' const HEADINGS = 100 const PARAGRAPHS = 7 const initialValue = [] for (let h = 0; h < HEADINGS; h++) { - initialValue.push({ - type: 'heading', + const heading = { + type: 'heading-one', children: [{ text: faker.lorem.sentence() }], - }) + } + initialValue.push(heading) for (let p = 0; p < PARAGRAPHS; p++) { - initialValue.push({ + const paragraph = { type: 'paragraph', children: [{ text: faker.lorem.paragraph() }], - }) + } + initialValue.push(paragraph) } } const HugeDocumentExample = () => { @@ -29,7 +31,7 @@ const HugeDocumentExample = () => { } const Element = ({ attributes, children, element }) => { switch (element.type) { - case 'heading': + case 'heading-one': return

{children}

default: return

{children}

diff --git a/site/examples/js/iframe.jsx b/site/examples/js/iframe.jsx index 51fac9fd6..45d7877ad 100644 --- a/site/examples/js/iframe.jsx +++ b/site/examples/js/iframe.jsx @@ -1,9 +1,9 @@ +import isHotkey from 'is-hotkey' import React, { useCallback, useMemo, useState } from 'react' import { createPortal } from 'react-dom' -import isHotkey from 'is-hotkey' -import { Editable, withReact, useSlate, Slate, ReactEditor } from 'slate-react' import { Editor, createEditor } from 'slate' import { withHistory } from 'slate-history' +import { Editable, ReactEditor, Slate, useSlate, withReact } from 'slate-react' import { Button, Icon, Toolbar } from './components' const HOTKEYS = { @@ -93,7 +93,9 @@ const MarkButton = ({ format, icon }) => { const IFrame = ({ children, ...props }) => { const [iframeBody, setIframeBody] = useState(null) const handleLoad = e => { - setIframeBody(e.target.contentDocument.body) + const iframe = e.target + if (!iframe.contentDocument) return + setIframeBody(iframe.contentDocument.body) } return (