@portabletext/editor 1.9.0 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -6
- package/lib/index.d.mts +302 -28
- package/lib/index.d.ts +302 -28
- package/lib/index.esm.js +84 -50
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +84 -50
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +84 -50
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/editor/PortableTextEditor.tsx +25 -15
- package/src/editor/behavior/behavior.links.ts +3 -3
- package/src/editor/behavior/behavior.markdown.ts +53 -41
- package/src/editor/components/Synchronizer.tsx +2 -2
- package/src/editor/editor-machine.ts +16 -4
- package/src/editor/use-editor.ts +3 -0
package/README.md
CHANGED
|
@@ -62,15 +62,32 @@ Use `useEditor` to create an `editor` and pass that into `PortableTextEditor`. U
|
|
|
62
62
|
|
|
63
63
|
```tsx
|
|
64
64
|
function App() {
|
|
65
|
+
const [value, setValue] = useState<Array<PortableTextBlock> | undefined>(
|
|
66
|
+
// Initial value
|
|
67
|
+
() => [
|
|
68
|
+
{
|
|
69
|
+
_type: 'block',
|
|
70
|
+
_key: keyGenerator(),
|
|
71
|
+
children: [
|
|
72
|
+
{_type: 'span', _key: keyGenerator(), text: 'Hello, '},
|
|
73
|
+
{
|
|
74
|
+
_type: 'span',
|
|
75
|
+
_key: keyGenerator(),
|
|
76
|
+
text: 'world!',
|
|
77
|
+
marks: ['strong'],
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
)
|
|
83
|
+
|
|
65
84
|
// Create an editor
|
|
66
85
|
const editor = useEditor({
|
|
67
86
|
schemaDefinition,
|
|
87
|
+
// With an optional initial value
|
|
88
|
+
initialValue: value,
|
|
68
89
|
})
|
|
69
90
|
|
|
70
|
-
const [value, setValue] = useState<Array<PortableTextBlock> | undefined>(
|
|
71
|
-
undefined,
|
|
72
|
-
)
|
|
73
|
-
|
|
74
91
|
// Subscribe to editor changes
|
|
75
92
|
useEffect(() => {
|
|
76
93
|
const subscription = editor.on('mutation', (mutation) => {
|
|
@@ -87,8 +104,6 @@ function App() {
|
|
|
87
104
|
<PortableTextEditor
|
|
88
105
|
// Pass in the `editor` you created earlier
|
|
89
106
|
editor={editor}
|
|
90
|
-
// And an optional value
|
|
91
|
-
value={value}
|
|
92
107
|
>
|
|
93
108
|
{/* Toolbar needs to be rendered inside the `PortableTextEditor` component */}
|
|
94
109
|
<Toolbar />
|