mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-26 16:44:22 +02:00
Rename <Slate>
component value
prop to initialValue
(#5421)
* Rename `slate-react` Slate component `value` prop to `initialValue` Fixes #4992 * Update documentation: `value` -> `initialValue` * Add a changeset record * Make props order consistent
This commit is contained in:
@@ -19,18 +19,18 @@ import { EDITOR_TO_ON_CHANGE } from '../utils/weak-maps'
|
||||
|
||||
export const Slate = (props: {
|
||||
editor: ReactEditor
|
||||
value: Descendant[]
|
||||
initialValue: Descendant[]
|
||||
children: React.ReactNode
|
||||
onChange?: (value: Descendant[]) => void
|
||||
}) => {
|
||||
const { editor, children, onChange, value, ...rest } = props
|
||||
const { editor, children, onChange, initialValue, ...rest } = props
|
||||
const unmountRef = useRef(false)
|
||||
|
||||
const [context, setContext] = React.useState<SlateContextValue>(() => {
|
||||
if (!Node.isNodeList(value)) {
|
||||
if (!Node.isNodeList(initialValue)) {
|
||||
throw new Error(
|
||||
`[Slate] value is invalid! Expected a list of elements but got: ${Scrubber.stringify(
|
||||
value
|
||||
`[Slate] initialValue is invalid! Expected a list of elements but got: ${Scrubber.stringify(
|
||||
initialValue
|
||||
)}`
|
||||
)
|
||||
}
|
||||
@@ -39,7 +39,7 @@ export const Slate = (props: {
|
||||
`[Slate] editor is invalid! You passed: ${Scrubber.stringify(editor)}`
|
||||
)
|
||||
}
|
||||
editor.children = value
|
||||
editor.children = initialValue
|
||||
Object.assign(editor, rest)
|
||||
return { v: 0, editor }
|
||||
})
|
||||
|
@@ -10,7 +10,9 @@ const createNodeMock = () => ({
|
||||
|
||||
class MockResizeObserver {
|
||||
observe() {}
|
||||
|
||||
unobserve() {}
|
||||
|
||||
disconnect() {}
|
||||
}
|
||||
|
||||
@@ -21,14 +23,18 @@ describe('slate-react', () => {
|
||||
describe('NODE_TO_KEY logic', () => {
|
||||
test('should not unmount the node that gets split on a split_node operation', async () => {
|
||||
const editor = withReact(createEditor())
|
||||
const value = [{ type: 'block', children: [{ text: 'test' }] }]
|
||||
const initialValue = [{ type: 'block', children: [{ text: 'test' }] }]
|
||||
const mounts = jest.fn()
|
||||
|
||||
let el: ReactTestRenderer
|
||||
|
||||
act(() => {
|
||||
el = create(
|
||||
<Slate editor={editor} value={value} onChange={() => {}}>
|
||||
<Slate
|
||||
editor={editor}
|
||||
initialValue={initialValue}
|
||||
onChange={() => {}}
|
||||
>
|
||||
<Editable
|
||||
renderElement={({ children }) => {
|
||||
useEffect(() => mounts(), [])
|
||||
@@ -52,7 +58,7 @@ describe('slate-react', () => {
|
||||
|
||||
test('should not unmount the node that gets merged into on a merge_node operation', async () => {
|
||||
const editor = withReact(createEditor())
|
||||
const value = [
|
||||
const initialValue = [
|
||||
{ type: 'block', children: [{ text: 'te' }] },
|
||||
{ type: 'block', children: [{ text: 'st' }] },
|
||||
]
|
||||
@@ -62,7 +68,11 @@ describe('slate-react', () => {
|
||||
|
||||
act(() => {
|
||||
el = create(
|
||||
<Slate editor={editor} value={value} onChange={() => {}}>
|
||||
<Slate
|
||||
editor={editor}
|
||||
initialValue={initialValue}
|
||||
onChange={() => {}}
|
||||
>
|
||||
<Editable
|
||||
renderElement={({ children }) => {
|
||||
useEffect(() => mounts(), [])
|
||||
|
Reference in New Issue
Block a user