File size: 1,801 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
## `createValue`: create a `Value` object
`createValue` can be used to create a value for the editor. This is useful if you want to
populate an empty editor with a default value.
The advantage over writing a `Value` manually is that you don't need to write `id`s
and that it provides some shortcuts.
You need to pass in the language and your cellPlugins as second argument:
```ts
import { createValue } from '@react-page/editor';
const partialValue = {
rows: [
// a row with two cells:
[
{
plugin: imagePlugin.id,
data: {
src: 'http://path/to/image',
},
},
{
plugin: imagePlugin.id,
data: {
src: 'http://path/to/other-image',
},
},
],
// a row with one cell
[
// a cell with rich text
{
plugin: slatePlugin.id,
data: slatePlugin.createData((def) => ({
children: [
{
plugin: def.plugins.headings.h1,
children: ['hello'],
},
{
plugin: def.plugins.paragraphs.paragraph,
children: ['Hello world'],
},
],
})),
},
],
],
};
const value = createValue(partialValue, {
lang: 'en',
cellPlugins: yourCellPlugins,
});
```
## `getTextContents`: get raw text contents
Can be used to extract plaintext from the editors value.
You need to pass in the language and your cellPlugins as second argument:
```ts
import { getTextContents } from '@react-page/editor';
const contents = getTextContents(value, {
lang: 'en',
cellPlugins: yourCellPlugins,
});
// contents is an array of strings
```
Full example:
[extractTextContents.tsx](examples/pages/examples/extractTextContents.tsx ':include :type=code typescript')
|