1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-22 08:02:25 +01:00
slate/site/examples/huge-document.tsx
Dylan Schiemann c4c14882ed
Update dependencies to React 18, Node 20, TS 5.2, etc. (#5528)
* incremental upgrade to React 18, TS 4.9, etc.

* update yarn config

* fix build

* minor cleanup in type definitions

* incremental updates for TS 5.0

* fix build

* upgrade to typescript 5.2

* update dependencies

* fix lint issues

* update to latest Playwright version

* update changesets dep

* update emotion/css

* incremental dependency updates

* more small dependency updates

* upgrade prettier and eslint

* fix lint issues

* update dependencies rollup

* fix @types/node resolution to restore linting

* update tiny-invariant dependency

* update dependencies

* update dependencies lerna

* upgrade react-router-dom

* update @types/react and @types/node

* update babel dependencies

* udpate simple-git-hooks

* update @types/node resolution

* update lint-staged

* remove cypress from dependency list

* update @types/node to support Node 20

* update workflows to Node 20

* set resolutions for @types/react

* downgrade @types/react to 18.2.28

* update mocha

* update rimraf

* update @types/js-dom

* remove .lintstagedrc.js

* upgrade next to latest

* v0.61.4

* update lerna

* update faker and rollup

* update immer

* fix yarn clean command

* attempt to fix integration tests

* attempt to stabilize integration tests

* wip fix integration tests

* skip unstable integration test

* Add changeset

---------

Co-authored-by: Dalibor Tosic <dalibortosic00@gmail.com>
Co-authored-by: Nikola <nikolabijelic14@gmail.com>
2023-10-20 08:34:24 -07:00

44 lines
1.1 KiB
TypeScript

import React, { useMemo, useCallback } from 'react'
import { faker } from '@faker-js/faker'
import { createEditor, Descendant } from 'slate'
import { Slate, Editable, withReact } from 'slate-react'
const HEADINGS = 100
const PARAGRAPHS = 7
const initialValue: Descendant[] = []
for (let h = 0; h < HEADINGS; h++) {
initialValue.push({
type: 'heading',
children: [{ text: faker.lorem.sentence() }],
})
for (let p = 0; p < PARAGRAPHS; p++) {
initialValue.push({
type: 'paragraph',
children: [{ text: faker.lorem.paragraph() }],
})
}
}
const HugeDocumentExample = () => {
const renderElement = useCallback(props => <Element {...props} />, [])
const editor = useMemo(() => withReact(createEditor()), [])
return (
<Slate editor={editor} initialValue={initialValue}>
<Editable renderElement={renderElement} spellCheck autoFocus />
</Slate>
)
}
const Element = ({ attributes, children, element }) => {
switch (element.type) {
case 'heading':
return <h1 {...attributes}>{children}</h1>
default:
return <p {...attributes}>{children}</p>
}
}
export default HugeDocumentExample