From 4f992cff5cfa4af8aec96356b1178df74e102c19 Mon Sep 17 00:00:00 2001 From: Ravi Lamkoti <44892121+RavenColEvol@users.noreply.github.com> Date: Mon, 10 Mar 2025 21:50:10 +0530 Subject: [PATCH] Fix example types (#5812) * fix: types for richtext.tsx * fix: types for check-lists, code-highlighting and custom placeholder * fix: types for editable-voids, embeds, forced-layout, hovering-toolbar * fix: types for remaining examples * fix: typescript error for files in image element * fix: types for examples and some minor fixes * fix: normalize-tokens.ts type * fix: types for [example].tsx --- .../04-applying-custom-formatting.md | 8 +- package.json | 2 + site/examples/js/check-lists.jsx | 2 +- site/examples/js/code-highlighting.jsx | 34 ++--- site/examples/js/components/index.jsx | 47 +------ site/examples/js/custom-placeholder.jsx | 2 +- site/examples/js/editable-voids.jsx | 10 +- site/examples/js/forced-layout.jsx | 8 +- site/examples/js/hovering-toolbar.jsx | 14 +- site/examples/js/huge-document.jsx | 18 +-- site/examples/js/iframe.jsx | 8 +- site/examples/js/images.jsx | 39 +++--- site/examples/js/inlines.jsx | 18 +-- site/examples/js/markdown-preview.jsx | 4 +- site/examples/js/mentions.jsx | 24 ++-- site/examples/js/paste-html.jsx | 25 ++-- site/examples/js/richtext.jsx | 45 +++++-- site/examples/js/search-highlighting.jsx | 16 ++- site/examples/js/tables.jsx | 6 +- site/examples/ts/check-lists.tsx | 55 +++++--- site/examples/ts/code-highlighting.tsx | 83 +++++++----- site/examples/ts/components/index.tsx | 72 +--------- site/examples/ts/custom-placeholder.tsx | 9 +- site/examples/ts/custom-types.d.ts | 65 ++++++++- site/examples/ts/editable-voids.tsx | 34 +++-- site/examples/ts/embeds.tsx | 31 +++-- site/examples/ts/forced-layout.tsx | 33 +++-- site/examples/ts/hovering-toolbar.tsx | 46 ++++--- site/examples/ts/huge-document.tsx | 33 +++-- site/examples/ts/iframe.tsx | 60 ++++++--- site/examples/ts/images.tsx | 72 +++++----- site/examples/ts/inlines.tsx | 92 ++++++++----- site/examples/ts/markdown-preview.tsx | 30 +++-- site/examples/ts/markdown-shortcuts.tsx | 30 +++-- site/examples/ts/mentions.tsx | 77 +++++++---- site/examples/ts/paste-html.tsx | 99 +++++++++----- site/examples/ts/richtext.tsx | 123 +++++++++++++----- site/examples/ts/search-highlighting.tsx | 45 +++++-- site/examples/ts/tables.tsx | 37 ++++-- site/examples/ts/utils/normalize-tokens.ts | 4 +- site/pages/examples/[example].tsx | 49 ++++--- site/tsconfig.json | 2 +- yarn.lock | 16 +++ 43 files changed, 935 insertions(+), 592 deletions(-) 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 (
{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 (