platejs 54.0.0-beta.2 → 54.0.0-beta.4
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 +1 -1
- package/THIRD_PARTY_NOTICES.md +56 -0
- package/dist/{AIChatRequestContext-BMVWhfPV.d.ts → AIChatRequestContext-DrUahdTc.d.ts} +2 -2
- package/dist/{BaseSuggestionPlugin-DBl3fqnm.d.ts → BaseSuggestionPlugin-_7Ka6nY3.d.ts} +7 -3
- package/dist/{PlateStatic-DhNv2ejp.d.ts → PlateStatic-D3Cb-QwH.d.ts} +7 -7
- package/dist/ai/index.d.ts +1 -1
- package/dist/ai/react/AIChatPlugin.js +113 -78
- package/dist/ai/react/CopilotPlugin.js +1 -1
- package/dist/ai/react/index.d.ts +23 -16
- package/dist/authored/index.d.ts +4 -4
- package/dist/code-block/codemirror/createCodeMirrorAdapter.js +12 -9
- package/dist/code-block/codemirror/index.d.ts +1 -1
- package/dist/{combobox-DkBGgyd3.d.ts → combobox-Dr0OYZIE.d.ts} +2 -2
- package/dist/{comparison-types-CYnJ35qU.d.ts → comparison-types-DdwE6mYq-BogsHoUO.d.ts} +10 -2
- package/dist/compiler/index.d.ts +2 -2
- package/dist/{core-BJG8l_mk.d.ts → core-BqR-fEDp.d.ts} +493 -116
- package/dist/diff/index.d.ts +2 -2
- package/dist/docs/ai.md +4 -3
- package/dist/docs/api/core/plate-components.md +0 -19
- package/dist/docs/api/core/plate-controller.md +5 -3
- package/dist/docs/api/core/plate-plugin.md +3 -0
- package/dist/docs/api/core/plate-store.md +3 -3
- package/dist/docs/api/core.md +45 -5
- package/dist/docs/api/dom.md +11 -4
- package/dist/docs/api/editor-transforms.md +2 -1
- package/dist/docs/api/react-hooks.md +45 -13
- package/dist/docs/authored-changes.md +9 -4
- package/dist/docs/basic-blocks.md +42 -29
- package/dist/docs/block-placeholder.md +4 -2
- package/dist/docs/blockquote.md +5 -3
- package/dist/docs/board.md +118 -10
- package/dist/docs/code-block.md +47 -0
- package/dist/docs/comment.md +2 -2
- package/dist/docs/discussion.md +1 -1
- package/dist/docs/document-model.md +15 -3
- package/dist/docs/docx.md +1 -1
- package/dist/docs/dom-coverage.md +5 -0
- package/dist/docs/editor.md +50 -4
- package/dist/docs/examples/editable-voids.md +2 -3
- package/dist/docs/external-text.md +2 -0
- package/dist/docs/field.md +370 -0
- package/dist/docs/find.md +9 -6
- package/dist/docs/form.md +2 -0
- package/dist/docs/heading.md +6 -0
- package/dist/docs/installation/manual.md +0 -4
- package/dist/docs/link.md +3 -3
- package/dist/docs/llms.txt +4 -2
- package/dist/docs/markdown.md +270 -14
- package/dist/docs/plugin-components.md +13 -10
- package/dist/docs/plugin-input-rules.md +66 -15
- package/dist/docs/prompt-editor.md +205 -0
- package/dist/docs/roots.md +8 -6
- package/dist/docs/rtl.md +6 -4
- package/dist/docs/selection.md +7 -4
- package/dist/docs/suggestion.md +1 -1
- package/dist/docs/toolbar.md +26 -30
- package/dist/docs/upload.md +106 -17
- package/dist/docx/export/index.d.ts +3 -3
- package/dist/docx/export/lib/docxStaticComponents.js +12 -2
- package/dist/docx/export/lib/exportDocx.js +46 -17
- package/dist/docx/export/lib/internal/xml-builder.js +11 -16
- package/dist/docx/export/lib/reviewPart.js +1 -1
- package/dist/docx/export/lib/reviewProjection.js +52 -10
- package/dist/docx/import/index.d.ts +4 -4
- package/dist/docx/paste/index.d.ts +4 -4
- package/dist/dom/index.d.ts +1 -6
- package/dist/dom/plite-dom.internal.js +2 -2
- package/dist/excalidraw/index.d.ts +3 -2
- package/dist/excalidraw/react/index.d.ts +3 -2
- package/dist/facade.js +2 -2
- package/dist/features/basic-nodes/lib/BaseBlockPlugins.js +13 -5
- package/dist/features/basic-nodes/lib/BaseHeadingPlugins.js +32 -10
- package/dist/features/board/index.d.ts +2 -2
- package/dist/features/board/lib/BaseBoardPlugin.js +14 -1
- package/dist/features/board/lib/boardStroke.internal.js +13 -1
- package/dist/features/board/lib/boardTypes.internal.js +16 -0
- package/dist/features/callout/index.d.ts +3 -2
- package/dist/features/code-block/lib/BaseCodeBlockPlugin.js +14 -5
- package/dist/features/combobox/index.d.ts +2 -2
- package/dist/features/comments/BaseCommentsPlugin.js +33 -17
- package/dist/features/comments/index.d.ts +1 -1
- package/dist/features/date/index.d.ts +3 -2
- package/dist/features/details/index.d.ts +3 -2
- package/dist/features/details/lib/BaseDetailsPlugin.js +25 -12
- package/dist/features/field/index.d.ts +2 -0
- package/dist/features/field/index.js +4 -0
- package/dist/features/field/lib/BaseFieldPlugin.js +360 -0
- package/dist/features/field/lib/applyFieldValues.js +188 -0
- package/dist/features/field/lib/fieldRules.internal.js +204 -0
- package/dist/features/find/index.d.ts +3 -2
- package/dist/features/footnote/index.d.ts +1 -1
- package/dist/features/ink/index.d.ts +1 -1
- package/dist/features/ink/lib/BaseInkPlugin.js +126 -103
- package/dist/features/ink/lib/inkCodec.internal.js +130 -0
- package/dist/features/ink/lib/inkGone.internal.js +229 -48
- package/dist/features/ink/lib/inkPlaces.internal.js +534 -64
- package/dist/features/layout/index.d.ts +1 -1
- package/dist/features/link/lib/BaseLinkPlugin.js +6 -4
- package/dist/features/lint/index.d.ts +3 -2
- package/dist/features/media/index.d.ts +2 -2
- package/dist/features/media/index.js +2 -2
- package/dist/features/media/lib/media/parseMediaUrl.js +11 -1
- package/dist/features/media/lib/media-embed/BaseMediaEmbedPlugin.js +206 -4
- package/dist/features/mention/index.d.ts +5 -4
- package/dist/features/suggestion/index.d.ts +1 -1
- package/dist/features/table/index.d.ts +1 -1
- package/dist/features/table/lib/BaseTablePlugin.js +64 -15
- package/dist/features/table/lib/internal/selection.js +4 -2
- package/dist/features/toc/index.d.ts +1 -1
- package/dist/features/upload/index.d.ts +2 -2
- package/dist/features/upload/lib/BaseUploadPlugin.js +464 -250
- package/dist/history/index.d.ts +2 -2
- package/dist/html/index.d.ts +3 -3
- package/dist/html/server/index.d.ts +1 -1
- package/dist/{htmlTypes-DjeFG3P8.d.ts → htmlTypes-eT2ZGDAj.d.ts} +2 -31
- package/dist/hyperscript/index.d.ts +1 -1
- package/dist/{index-DzD6BIFJ.d.ts → index-B33E1CRJ.d.ts} +295 -6
- package/dist/{index-Cl77E9yr.d.ts → index-B7moSod7.d.ts} +2 -2
- package/dist/{index-hsC_sOn2.d.ts → index-B8-5Sr7I.d.ts} +35 -5
- package/dist/{index-BiQerPJS.d.ts → index-B8QJDAmG.d.ts} +2 -2
- package/dist/{index-BBKGrsG3.d.ts → index-BTx5oK7k.d.ts} +1 -1
- package/dist/{index-iaZOhA76.d.ts → index-BWPcE4ac-Cto_IsNs.d.ts} +7 -1
- package/dist/{index-BU6k1Aev.d.ts → index-BXjLmx1n-CXk17buG.d.ts} +4781 -4584
- package/dist/{index-kLKMc-pI.d.ts → index-BXwU9QH6.d.ts} +2 -2
- package/dist/{index-DTgaSxKr.d.ts → index-BkwR-5hH.d.ts} +40 -4
- package/dist/{index-Bq3sdm3S.d.ts → index-BsV2McRr.d.ts} +5 -4
- package/dist/index-C9Fu-P4E.d.ts +773 -0
- package/dist/{index-D5W-p9bS.d.ts → index-Ca48r1ng.d.ts} +49 -4
- package/dist/{index-CcZbqPqk.d.ts → index-Cob_iBdu.d.ts} +116 -41
- package/dist/{index-Bxfvicyy.d.ts → index-CpY7Xnxw.d.ts} +4 -3
- package/dist/{index-BkR7-GLI.d.ts → index-DNQXzU-X.d.ts} +2 -2
- package/dist/{index-D1CFXA-i.d.ts → index-DPowErHa.d.ts} +471 -141
- package/dist/{index-DaM37gF6.d.ts → index-DShbzec2.d.ts} +38 -23
- package/dist/{index-DC_MNGyu.d.ts → index-DYdObeFQ.d.ts} +3 -3
- package/dist/{index-Bc2Yg_2j.d.ts → index-Dq3Jlj8O-BJ6NxZm0.d.ts} +2 -2
- package/dist/{index-CT7miqQN.d.ts → index-DwWQVwQt.d.ts} +29 -11
- package/dist/{index-xdmCBvlT.d.ts → index-JWgwL5l3.d.ts} +5 -2
- package/dist/{index-DLA2DUR2.d.ts → index-M781pyx9.d.ts} +4 -3
- package/dist/{index-DdIRduDG.d.ts → index-d7io3MzC.d.ts} +3 -2
- package/dist/index.d.ts +4 -4
- package/dist/{react/internal → internal}/penStroke.internal.js +1 -1
- package/dist/internal/plugin/OverridePlugin.js +101 -119
- package/dist/internal/plugin/collectPlateNodeMappings.js +5 -1
- package/dist/internal/plugin/pastedUploadFiles.js +4 -0
- package/dist/internal/plugin/resolvePlugin.js +1 -1
- package/dist/internal/plugin/resolvePlugins.js +3 -0
- package/dist/internal/plugin/uploadDrafts.js +6 -0
- package/dist/internal/utils/mergePlugins.js +1 -0
- package/dist/lib/plugins/element-id/ElementIdPlugin.js +14 -18
- package/dist/lib/plugins/html/HtmlPlugin.js +9 -0
- package/dist/lib/plugins/html/htmlSafety.js +1 -1
- package/dist/lib/plugins/input-rules/InputRulesPlugin.js +77 -28
- package/dist/lib/plugins/input-rules/inputRuleVeto.internal.js +16 -0
- package/dist/markdown/index.d.ts +2 -2
- package/dist/markdown/index.js +3 -1
- package/dist/markdown/lib/MarkdownPlugin.js +14 -11
- package/dist/markdown/lib/RawHtmlPlugin.js +26 -0
- package/dist/markdown/lib/deserializer/mdastToSlate.js +12 -2
- package/dist/markdown/lib/internal/markdownConversion.js +776 -74
- package/dist/markdown/lib/internal/markdownDiagnostics.js +18 -7
- package/dist/markdown/lib/internal/markdownFootnoteWriter.js +35 -0
- package/dist/markdown/lib/internal/markdownFrontmatter.js +102 -0
- package/dist/markdown/lib/internal/markdownIntrinsics.js +125 -43
- package/dist/markdown/lib/internal/markdownLine.js +5 -3
- package/dist/markdown/lib/internal/markdownMappings.js +19 -7
- package/dist/markdown/lib/internal/markdownOpenTail.js +381 -0
- package/dist/markdown/lib/internal/markdownRawHtml.js +353 -0
- package/dist/markdown/lib/internal/markdownSegments.js +57 -48
- package/dist/markdown/lib/internal/markdownTags.js +29 -9
- package/dist/markdown/lib/serializer/convertNodesSerialize.js +10 -8
- package/dist/markdown/lib/serializer/convertPhrasingSerialize.js +226 -0
- package/dist/markdown/lib/serializer/listToMdastTree.js +2 -0
- package/dist/math/index.d.ts +3 -2
- package/dist/math/react/index.d.ts +4 -3
- package/dist/migrations/index.d.ts +3 -3
- package/dist/migrations/migratePlateV54.js +4 -6
- package/dist/migrations/migratePlateV54RetiredMarks.internal.js +23 -8
- package/dist/migrations/migratePlateV54Suggestions.internal.js +2 -2
- package/dist/migrations/v53-manifest.internal.js +4 -0
- package/dist/pagination/index.d.ts +1 -1
- package/dist/pagination/react/index.d.ts +4 -4
- package/dist/react/components/EditorContentView.internal.js +42 -23
- package/dist/react/components/EditorProvider.js +5 -5
- package/dist/react/components/Plate.js +102 -128
- package/dist/react/components/PlateContainer.js +40 -32
- package/dist/react/components/PlateController.js +28 -16
- package/dist/react/components/PlateRoot.internal.js +3 -2
- package/dist/react/core.js +4 -4
- package/dist/react/features/board/BoardSurface.js +116 -87
- package/dist/react/features/board/boardClipboard.internal.js +15 -5
- package/dist/react/features/board/boardExport.internal.js +470 -0
- package/dist/react/features/board/boardGesture.internal.js +6 -3
- package/dist/react/features/board/boardIndex.internal.js +7 -18
- package/dist/react/features/board/boardPictureStyles.internal.js +415 -0
- package/dist/react/features/board/boardPictures.internal.js +19 -13
- package/dist/react/features/board/boardView.internal.js +190 -50
- package/dist/react/features/board/boardVoice.internal.js +10 -11
- package/dist/react/features/board/index.d.ts +108 -18
- package/dist/react/features/callout/index.d.ts +3 -2
- package/dist/react/features/combobox/index.d.ts +8 -8
- package/dist/react/features/comments/index.d.ts +6 -5
- package/dist/react/features/date/index.d.ts +4 -3
- package/dist/react/features/details/index.d.ts +4 -3
- package/dist/react/features/field/FieldPlugin.js +35 -0
- package/dist/react/features/field/index.d.ts +315 -0
- package/dist/react/features/field/index.js +2 -0
- package/dist/react/features/footnote/index.d.ts +7 -6
- package/dist/react/features/format-painter/index.d.ts +4 -3
- package/dist/react/features/ink/InkContent.js +313 -0
- package/dist/react/features/ink/index.d.ts +57 -33
- package/dist/react/features/ink/index.js +2 -2
- package/dist/react/features/ink/inkCapture.internal.js +39 -17
- package/dist/react/features/ink/inkInput.internal.js +1 -1
- package/dist/react/features/ink/inkLayout.internal.js +6 -3
- package/dist/react/features/ink/inkPaint.internal.js +78 -2
- package/dist/react/features/ink/inkPlacement.internal.js +332 -104
- package/dist/react/features/ink/inkWatch.internal.js +7 -5
- package/dist/react/features/layout/index.d.ts +5 -4
- package/dist/react/features/media/index.d.ts +5 -4
- package/dist/react/features/mention/index.d.ts +6 -5
- package/dist/react/features/resizable/Resizable.js +4 -6
- package/dist/react/features/resizable/index.d.ts +5 -5
- package/dist/react/features/suggestion/index.d.ts +6 -5
- package/dist/react/features/table/TablePlugin.js +4 -11
- package/dist/react/features/table/index.d.ts +10 -8
- package/dist/react/features/table/useTableResize.js +10 -1
- package/dist/react/features/toc/index.d.ts +2 -2
- package/dist/react/features/upload/index.d.ts +11 -6
- package/dist/react/index.d.ts +6 -6
- package/dist/react/index.js +4 -4
- package/dist/react/internal/plate-context.js +434 -188
- package/dist/react/plite-react.js +2 -2
- package/dist/react/plugins/navigation-feedback/NavigationFeedbackPlugin.js +12 -10
- package/dist/react/stores/plate/useEditor.js +32 -14
- package/dist/react/stores/plate/useEditorHistory.js +55 -0
- package/dist/react/stores/plate/useEditorSelector.js +79 -21
- package/dist/react/utils/BlockPlaceholderPlugin.js +5 -2
- package/dist/react/utils/pipeRenderElement.internal.js +1 -1
- package/dist/react/utils/pluginRenderElement.internal.js +1 -1
- package/dist/react/virtualized.d.ts +4 -4
- package/dist/{source-CNKy99Th.d.ts → source-BGohy8vH.d.ts} +4 -4
- package/dist/static/index.d.ts +18 -18
- package/dist/static/internal/renderStaticHtmlWithOverrides.js +2 -2
- package/dist/static/internal/staticPresentation.js +4 -4
- package/dist/static/internal/writeStaticSelectionClipboardData.js +7 -2
- package/dist/tabbable/index.d.ts +1 -1
- package/dist/tabbable/react/index.d.ts +3 -3
- package/dist/testing/index.d.ts +3 -3
- package/dist/yjs/index.d.ts +1 -1
- package/dist/yjs/react/index.d.ts +6 -6
- package/package.json +20 -2
- package/dist/markdown/lib/serializer/convertTextsSerialize.js +0 -163
- package/dist/react/components/EditorSelectionView.js +0 -40
- package/dist/react/features/ink/InkLayer.js +0 -218
- package/dist/react/internal/createPlateTargetScope.js +0 -62
package/dist/docs/markdown.md
CHANGED
|
@@ -30,8 +30,9 @@ if (result.ok) {
|
|
|
30
30
|
showDiagnostics(result.diagnostics);
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
`parse` returns one complete `EditorDocumentValue`, including roots
|
|
34
|
-
|
|
33
|
+
`parse` returns one complete `EditorDocumentValue`, including the roots that
|
|
34
|
+
mappings read and a leading [front matter](#front-matter) block in `meta`. Use
|
|
35
|
+
`parseSlice` for block insertion and
|
|
35
36
|
`parseInline` for inline insertion. Both return a closed, rootless
|
|
36
37
|
`ContentSlice`.
|
|
37
38
|
|
|
@@ -113,9 +114,12 @@ in a [table cell](#table-cells), warns under every policy.
|
|
|
113
114
|
## Syntax
|
|
114
115
|
|
|
115
116
|
Plate reads and writes CommonMark plus the tags that installed feature plugins
|
|
116
|
-
register
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
register, after a leading [front matter](#front-matter) block. GFM, math,
|
|
118
|
+
emoji, and [CJK emphasis](#cjk-emphasis) come from the
|
|
119
|
+
[remark plugins](#remark-plugins) configured on `MarkdownPlugin`. Registered
|
|
120
|
+
tags look like HTML, but only registered names are tags and nothing is
|
|
121
|
+
evaluated. Other HTML stays text, which [`RawHtmlPlugin`](#raw-html) writes
|
|
122
|
+
back as HTML when its block passes a check.
|
|
119
123
|
|
|
120
124
|
### Registered tags
|
|
121
125
|
|
|
@@ -135,6 +139,90 @@ A tag is registered only while its feature plugin is installed. Element tags
|
|
|
135
139
|
use the schema type, so an application that renames a type also renames its
|
|
136
140
|
tag.
|
|
137
141
|
|
|
142
|
+
### Raw HTML
|
|
143
|
+
|
|
144
|
+
`RawHtmlPlugin` keeps a file's raw HTML through a save. The Markdown kit
|
|
145
|
+
installs it. An editor with its own plugin list adds it beside
|
|
146
|
+
`MarkdownPlugin`:
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { BaseParagraphPlugin, createEditor } from 'platejs';
|
|
150
|
+
import { MarkdownPlugin, RawHtmlPlugin } from 'platejs/markdown';
|
|
151
|
+
|
|
152
|
+
const editor = createEditor({
|
|
153
|
+
plugins: [BaseParagraphPlugin, MarkdownPlugin, RawHtmlPlugin],
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
An app whose own plugin already declares a `rawHtml` mark keeps that plugin and
|
|
158
|
+
leaves `RawHtmlPlugin` out, because two plugins cannot own one mark.
|
|
159
|
+
|
|
160
|
+
The plugin changes the editor's schema fingerprint, so an editor with it
|
|
161
|
+
refuses a document saved under the earlier schema identity. An app that saves
|
|
162
|
+
documents under a named schema increments its `version` and adds a migration
|
|
163
|
+
step, as [Document migrations](/docs/editor#document-migrations) shows. An app
|
|
164
|
+
that saves `{ document, schema }` under the derived identity opens each saved
|
|
165
|
+
document in an editor without the plugin and passes its `read.value()` to the
|
|
166
|
+
new editor.
|
|
167
|
+
|
|
168
|
+
Import gives the `rawHtml` mark to raw HTML that no registered tag claims, such
|
|
169
|
+
as a README's centered header, and to most HTML comments on lines of their own
|
|
170
|
+
in the document, a block quote or a list item. The editor shows that text as
|
|
171
|
+
plain text, and export writes it back as HTML:
|
|
172
|
+
|
|
173
|
+
```md
|
|
174
|
+
<p align="center">
|
|
175
|
+
<img src="logo.png" width="200" />
|
|
176
|
+
</p>
|
|
177
|
+
|
|
178
|
+
<!-- markdownlint-disable -->
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
- Import marks only HTML that export can write back. Other raw HTML stays plain
|
|
182
|
+
text without the mark and saves escaped, as it does without the plugin. A
|
|
183
|
+
comment block that fails the check, such as `<!-- a <!-- b -->`, also stays
|
|
184
|
+
plain text, where an editor without the plugin drops it.
|
|
185
|
+
- Export checks each block that holds marked text: its paragraph, heading,
|
|
186
|
+
table cell or HTML block. Marked text in any other block fails the check.
|
|
187
|
+
The check accepts a fixed set of formatting, heading, list, table, media and
|
|
188
|
+
disclosure tags, such as `p`, `div`, `img`, `kbd` and `details`, and
|
|
189
|
+
attributes such as `align`, `alt`, `href`, `src`, `title` and `width`. It
|
|
190
|
+
refuses every other tag and attribute, such as `script`, `class`, `style` and
|
|
191
|
+
event handlers, and a doctype.
|
|
192
|
+
- An `href` or `src` URL passes when it is empty or Plate's URL safety rules
|
|
193
|
+
accept it, and a `cite` or `srcset` URL passes only when those rules accept
|
|
194
|
+
it. The rules refuse script-capable schemes such as `javascript:`. The check
|
|
195
|
+
does not read the Link plugin's `allowedSchemes`, so
|
|
196
|
+
`<a href="smb://server/share">x</a>` writes back as HTML, while the Link
|
|
197
|
+
plugin with its default schemes refuses `[x](smb://server/share)`.
|
|
198
|
+
- When an edit makes a marked block fail the check, export writes that block's
|
|
199
|
+
marked text escaped and reports a lossless `markdown-unsafe-content` warning.
|
|
200
|
+
In rare cases, such as a mapping that copies marked text, export writes all
|
|
201
|
+
marked text in the document escaped. Plate writes a details summary line as
|
|
202
|
+
HTML, so a CommonMark reader still reads escaped text there as HTML, while
|
|
203
|
+
Plate reads it back as the same plain text.
|
|
204
|
+
- An HTML block writes back as HTML in the document, a block quote or a list
|
|
205
|
+
item. Inside a registered block tag's body, such as `<callout>`, raw HTML
|
|
206
|
+
writes back only in pieces that fit on one line. An HTML block there stays
|
|
207
|
+
plain text and saves escaped, and one directly inside `<details>` fails the
|
|
208
|
+
parse with `markdown-schema-invalid`, unless it is a comment. A `<block>`
|
|
209
|
+
wrapper around one HTML block drops on import, and its HTML writes back. A
|
|
210
|
+
footnote definition keeps all of its raw HTML as plain text.
|
|
211
|
+
- A comment drops, as it does without the plugin, when it sits inside a line of
|
|
212
|
+
paragraph or heading text, a table cell, a registered tag's body or a
|
|
213
|
+
footnote definition, or when it is an unindented `<!---->`, the separator
|
|
214
|
+
Plate writes between two blocks.
|
|
215
|
+
- Import also leaves unmarked a comment or HTML block whose indent export
|
|
216
|
+
cannot write back. That covers one indented past its list item's text on the
|
|
217
|
+
line after an empty marker, such as ` <!-- c -->` after `-`, one indented
|
|
218
|
+
after a list, such as one space after `- a`, and one whose indent keeps a tab
|
|
219
|
+
after the indent of its quote or list item. Such a comment drops, and such
|
|
220
|
+
HTML saves escaped.
|
|
221
|
+
- HTML, DOCX and plain-text export write marked text as visible text.
|
|
222
|
+
- Naming `rawHtml` in `MarkdownPlugin`'s `plainMarks` stops import from
|
|
223
|
+
marking, so tags stay plain text and comment blocks drop. Naming it in a
|
|
224
|
+
serialize call's `plainMarks` writes marked text escaped, with no warning.
|
|
225
|
+
|
|
138
226
|
### Writer output
|
|
139
227
|
|
|
140
228
|
```md
|
|
@@ -158,12 +246,16 @@ Due <date value="2025-01-01" />, ask [Jane](mention:user_123).
|
|
|
158
246
|
`"`, a newline as ` `, and `|` as `|`.
|
|
159
247
|
- Footnote labels that CommonMark would merge, such as `A` and `a`, are written
|
|
160
248
|
as distinct labels.
|
|
249
|
+
- A file without front matter whose opening lines would read back as a block,
|
|
250
|
+
such as two `---` rules written with `rule: '-'`, opens with a line ending so
|
|
251
|
+
it reads back as written.
|
|
161
252
|
|
|
162
253
|
### Reading rules
|
|
163
254
|
|
|
164
255
|
- Every string parses. Raw HTML that no mapping accepts stays literal text and
|
|
165
256
|
reports a lossless `markdown-unsupported-node` warning under every policy.
|
|
166
|
-
-
|
|
257
|
+
- Without [`RawHtmlPlugin`](#raw-html), an HTML block that holds only closed
|
|
258
|
+
comments drops with a lossless warning.
|
|
167
259
|
- `<br>`, `<br/>`, and `<br />` become line breaks.
|
|
168
260
|
- A line holding only a registered block tag is a block, even next to paragraph
|
|
169
261
|
text. A block tag elsewhere in a paragraph or heading stays text. A table cell
|
|
@@ -239,6 +331,106 @@ reads a `<block id="…">` wrapper around one block: with `ElementIdPlugin`
|
|
|
239
331
|
installed, the block keeps that `id`; otherwise the wrapper is removed with a
|
|
240
332
|
`markdown-unsupported-node` warning. Mappings cannot claim the `block` tag.
|
|
241
333
|
|
|
334
|
+
### Front matter
|
|
335
|
+
|
|
336
|
+
`parse` reads one leading YAML or TOML block, as Obsidian, Jekyll, and Hugo
|
|
337
|
+
notes open with, into the document's metadata instead of a rule and a heading:
|
|
338
|
+
|
|
339
|
+
```md
|
|
340
|
+
---
|
|
341
|
+
title: Hello
|
|
342
|
+
tags: [a, b]
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
# Body
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
import { getMarkdownFrontmatter } from 'platejs/markdown';
|
|
350
|
+
|
|
351
|
+
const result = editor.api.markdown.parse(source);
|
|
352
|
+
|
|
353
|
+
if (result.ok) {
|
|
354
|
+
getMarkdownFrontmatter(result.document);
|
|
355
|
+
// { format: 'yaml', value: 'title: Hello\ntags: [a, b]' }
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
The block is stored at `meta['markdown.frontmatter']` as
|
|
360
|
+
`{ format: 'yaml' | 'toml', value: string }`, where `value` is the text between
|
|
361
|
+
the fences with LF line endings. `serialize` writes it first, then the body
|
|
362
|
+
right after the closing line. A note with no other content exports as the
|
|
363
|
+
block alone.
|
|
364
|
+
|
|
365
|
+
- The file opens with the fence, after at most one byte-order mark: `---` for
|
|
366
|
+
YAML or `+++` for TOML, with optional trailing spaces or tabs. A YAML block
|
|
367
|
+
closes on a `---` or `...` line, a TOML block on a `+++` line.
|
|
368
|
+
- The first line inside that is not blank or a `#` comment must be a setting,
|
|
369
|
+
such as `title: Hello` in YAML, or `title = 'Hello'` or `[params]` in TOML.
|
|
370
|
+
A note that opens with a rule and plain text keeps them.
|
|
371
|
+
- Two fence lines with nothing between are an empty block.
|
|
372
|
+
- An unclosed block, a JSON block, and a block whose text is not well-formed
|
|
373
|
+
Unicode read as CommonMark.
|
|
374
|
+
- Only `parse` reads front matter. `parseSlice`, `parseInline`, paste, and AI
|
|
375
|
+
streaming read the same lines as CommonMark.
|
|
376
|
+
|
|
377
|
+
Parse `value` with a parser for its format. Add a line ending to a non-empty
|
|
378
|
+
value first, because the last line of a YAML block scalar keeps its line break
|
|
379
|
+
only when one follows:
|
|
380
|
+
|
|
381
|
+
```ts
|
|
382
|
+
import { parse as parseToml } from 'smol-toml';
|
|
383
|
+
import { parse as parseYaml } from 'yaml';
|
|
384
|
+
|
|
385
|
+
const frontmatter = getMarkdownFrontmatter(result.document);
|
|
386
|
+
const text = frontmatter?.value ? `${frontmatter.value}\n` : '';
|
|
387
|
+
const data = frontmatter?.format === 'toml' ? parseToml(text) : parseYaml(text);
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
To change the block, change it on the copy of the document you pass to
|
|
391
|
+
`serialize`. Replacing a live editor's value with new `meta` resets its caret,
|
|
392
|
+
undo history, and local fields. Edit YAML with `yaml`'s `parseDocument` and
|
|
393
|
+
`set`, which keep the quoting the reader needs, and store the result minus
|
|
394
|
+
exactly one final line ending. Never trim it, because a `|+` block scalar keeps
|
|
395
|
+
its trailing line breaks:
|
|
396
|
+
|
|
397
|
+
```ts
|
|
398
|
+
import { getMarkdownFrontmatter } from 'platejs/markdown';
|
|
399
|
+
import { parseDocument } from 'yaml';
|
|
400
|
+
|
|
401
|
+
const document = editor.read.value();
|
|
402
|
+
const frontmatter = getMarkdownFrontmatter(document);
|
|
403
|
+
|
|
404
|
+
if (frontmatter?.format === 'yaml') {
|
|
405
|
+
const yaml = parseDocument(frontmatter.value ? `${frontmatter.value}\n` : '');
|
|
406
|
+
|
|
407
|
+
yaml.set('draft', false);
|
|
408
|
+
|
|
409
|
+
const text = yaml.toString();
|
|
410
|
+
const value = text.endsWith('\n') ? text.slice(0, -1) : text;
|
|
411
|
+
|
|
412
|
+
const result = editor.api.markdown.serialize({
|
|
413
|
+
document: {
|
|
414
|
+
...document,
|
|
415
|
+
meta: {
|
|
416
|
+
...document.meta,
|
|
417
|
+
'markdown.frontmatter': { format: 'yaml', value },
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
A document replaced with only its `children` has no `meta`, so it loses the
|
|
425
|
+
block. In a collaborative editor, Yjs does not sync `meta`, so a peer that did
|
|
426
|
+
not import the file exports the note without its front matter.
|
|
427
|
+
|
|
428
|
+
Two rules around text read as front matter when the first line between them
|
|
429
|
+
that is not blank or a comment reads as a YAML setting. That includes a line of
|
|
430
|
+
text holding `: `, such as `_Note_: read this`, and a line that opens with `{`.
|
|
431
|
+
Export writes those lines back unchanged. A block of only blank lines or
|
|
432
|
+
comments reads as CommonMark.
|
|
433
|
+
|
|
242
434
|
## Streaming previews
|
|
243
435
|
|
|
244
436
|
Parse each unfinished stream prefix with `partial: true` and the previous
|
|
@@ -269,6 +461,21 @@ nothing. A source with a link reference or footnote definition (`[id]: url`,
|
|
|
269
461
|
`[^1]: note`) always parses whole, because a definition can change blocks
|
|
270
462
|
before it.
|
|
271
463
|
|
|
464
|
+
A `partial` parse also shows bold, italic and strikethrough that have not
|
|
465
|
+
closed yet, so the preview of `Use **bold` shows `bold` in bold. It parses a
|
|
466
|
+
closed copy of the unfinished block, with the closers that block needs. The
|
|
467
|
+
copy goes through the same plugins and schema, and the preview shows it only
|
|
468
|
+
when it keeps every received character. Up to three trailing `*`, `_` or `~`
|
|
469
|
+
that could still open styling, or one trailing backslash, stay hidden until the
|
|
470
|
+
next character arrives. Markers that cannot open styling show as received, such
|
|
471
|
+
as the star in `2*3` and the underscore in `foo_bar`. The parse makes no closed
|
|
472
|
+
copy when the unfinished block holds more than 2,000 characters, or when the
|
|
473
|
+
source has a link reference or footnote definition or starts with a byte order
|
|
474
|
+
mark. Styling that opened more than 1,000 characters back gets no closer
|
|
475
|
+
either. Such a block shows its markers until they close. Code spans, links,
|
|
476
|
+
images, math and block syntax such as table rows show as received until they
|
|
477
|
+
finish, and so does styling inside link text or after an unclosed backtick.
|
|
478
|
+
|
|
272
479
|
A `partial` parse converts only the text after the kept blocks. Each kept block
|
|
273
480
|
came from a parse of its own part of the source, so a remark plugin that reads
|
|
274
481
|
the whole tree, such as one that numbers or joins blocks, can make a preview
|
|
@@ -533,7 +740,8 @@ root that no mapping reads through `contentRoot` as
|
|
|
533
740
|
## Remark plugins
|
|
534
741
|
|
|
535
742
|
Configure remark plugins once on `MarkdownPlugin`. Every parse and serialize
|
|
536
|
-
operation of that editor uses them. `MarkdownKit` enables GFM, math,
|
|
743
|
+
operation of that editor uses them. `MarkdownKit` enables GFM, math, emoji,
|
|
744
|
+
and CJK emphasis:
|
|
537
745
|
|
|
538
746
|
_Registry item `markdown`: `npx shadcn@latest add @plate/markdown`._
|
|
539
747
|
|
|
@@ -552,7 +760,53 @@ const plugins = [
|
|
|
552
760
|
Standalone functions read the configured `MarkdownPlugin` from `plugins`.
|
|
553
761
|
Remark plugins must be synchronous. An attacher or transformer that returns a
|
|
554
762
|
Promise is a configuration error and throws. The synchronous functions never
|
|
555
|
-
return `Result | Promise<Result>`.
|
|
763
|
+
return `Result | Promise<Result>`. Remark plugins must also keep no state
|
|
764
|
+
between parses, because a `partial` parse runs them on the closed copy of an
|
|
765
|
+
unfinished block as well as on the received text. See
|
|
766
|
+
[Streaming previews](#streaming-previews).
|
|
767
|
+
|
|
768
|
+
### remark-frontmatter
|
|
769
|
+
|
|
770
|
+
Files need no `remark-frontmatter` for their [front matter](#front-matter).
|
|
771
|
+
When the list still holds it, it reads every slice and every block Plate's
|
|
772
|
+
reader refuses. Unless a mapping decodes the `yaml` or `toml` node it makes,
|
|
773
|
+
that node is a lossy `markdown-unsupported-node`, which fails the parse under
|
|
774
|
+
the default policy. A [streaming preview](#streaming-previews) that continues
|
|
775
|
+
its previous result reads the whole source again while the plugin adds front
|
|
776
|
+
matter syntax, as it does with its default options, so it matches a fresh parse
|
|
777
|
+
of the same text.
|
|
778
|
+
|
|
779
|
+
### CJK emphasis
|
|
780
|
+
|
|
781
|
+
CommonMark leaves `**` literal when punctuation ends the bold text and a letter
|
|
782
|
+
follows, so `这是**重点。**然后继续` stays plain text. `remark-cjk-friendly`
|
|
783
|
+
and `remark-cjk-friendly-gfm-strikethrough` read bold, strikethrough, and `*`
|
|
784
|
+
italic that end in Chinese, Japanese, or Korean punctuation as marks. They read
|
|
785
|
+
a source without CJK characters as CommonMark does. `MarkdownKit` installs
|
|
786
|
+
both. A custom plugin list adds them after `remarkGfm`:
|
|
787
|
+
|
|
788
|
+
```ts
|
|
789
|
+
import { MarkdownPlugin } from 'platejs/markdown';
|
|
790
|
+
import remarkCjkFriendlyGfmStrikethrough from 'remark-cjk-friendly-gfm-strikethrough/bidi';
|
|
791
|
+
import remarkCjkFriendly from 'remark-cjk-friendly/bidi';
|
|
792
|
+
import remarkGfm from 'remark-gfm';
|
|
793
|
+
|
|
794
|
+
MarkdownPlugin.configure({
|
|
795
|
+
initialState: {
|
|
796
|
+
remarkPlugins: [
|
|
797
|
+
remarkGfm,
|
|
798
|
+
remarkCjkFriendly,
|
|
799
|
+
remarkCjkFriendlyGfmStrikethrough,
|
|
800
|
+
],
|
|
801
|
+
},
|
|
802
|
+
});
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
Serialize runs the same plugins, so it writes bold and strikethrough next to CJK
|
|
806
|
+
text with plain `**` and `~~`. That needs `mdast-util-to-markdown` 2.1.3 or
|
|
807
|
+
later. `_` keeps CommonMark's rule, and Plate writes italic with `_`, so it
|
|
808
|
+
writes italic next to CJK letters with character references, such as
|
|
809
|
+
`这是_斜体。_文字`.
|
|
556
810
|
|
|
557
811
|
## Results and diagnostics
|
|
558
812
|
|
|
@@ -573,14 +827,15 @@ reportWarnings(result.diagnostics);
|
|
|
573
827
|
| Code | Severity | Reports |
|
|
574
828
|
| --- | --- | --- |
|
|
575
829
|
| `markdown-unsupported-node` | Warning when `lossless` or when the content stays; other `lossy` follows `lossPolicy` | Content no mapping accepts, refused content, or nodes dropped on export (`lossy`), such as a table when no remark plugin, like `remark-gfm`, writes tables. Raw HTML kept as text, HTML comments and removed `<block>` wrappers are `lossless`. A [table cell](#table-cells)'s folded paragraph boundary or collapsed block keeps its content and warns. |
|
|
576
|
-
| `markdown-unsafe-content` | Warning when `lossless`; lossy follows `lossPolicy` | A removed link or image destination. |
|
|
830
|
+
| `markdown-unsafe-content` | Warning when `lossless`; lossy follows `lossPolicy` | A removed link or image destination, or marked raw HTML whose block fails the raw HTML check on export. |
|
|
577
831
|
| `markdown-tag-repair` | Warning | An `unclosed`, `unmatched`, or `misplaced` registered tag. |
|
|
578
832
|
| `markdown-property-omitted` | Warning | A property or mark Markdown cannot carry on export, such as a paragraph's `textAlign`, or an invalid tag attribute value on import. |
|
|
579
833
|
| `markdown-limit-exceeded` | Error | Source bytes, node count, or depth above `limits`. |
|
|
580
834
|
| `markdown-inline-blocks` | Error | `parseInline` input that produced blocks. |
|
|
581
835
|
| `markdown-schema-repair` | Warning; error when lossy under `'reject'` | A schema repair applied to the parsed document. |
|
|
582
836
|
| `markdown-schema-invalid` | Error | Parsed content the schema rejects. |
|
|
583
|
-
| `markdown-unsupported-root`, `markdown-unsupported-metadata` | Warning | A named root that no mapping read through [`contentRoot`](#content-roots), or document metadata, omitted on export. |
|
|
837
|
+
| `markdown-unsupported-root`, `markdown-unsupported-metadata` | Warning | A named root that no mapping read through [`contentRoot`](#content-roots), or document metadata other than [front matter](#front-matter), omitted on export. |
|
|
838
|
+
| `markdown-frontmatter-omitted` | Lossy: error under `'reject'`, warning under `'allow'` | Stored [front matter](#front-matter) that export cannot write back. Its `reason` is `shape` for a value that is not `{ format, value }` strings, `format` for a format other than `yaml` or `toml`, or `unreadable` for a value that holds a CR, is not well-formed Unicode, or would not read back the same. Under the default policy the export fails; `lossPolicy: 'allow'` exports the file without the block. |
|
|
584
839
|
|
|
585
840
|
Authored projection diagnostics use the same result. Configuration failures and
|
|
586
841
|
mapping contract violations throw.
|
|
@@ -600,8 +855,8 @@ parser returns because mdast does not expose a bounded construction hook.
|
|
|
600
855
|
| `editor.api.markdown.parseInline(source, options?)` | Closed, rootless inline `ContentSlice`. |
|
|
601
856
|
| `editor.api.markdown.serialize(options?)` | Current or supplied document using the installed target. |
|
|
602
857
|
|
|
603
|
-
Import `MarkdownPlugin`, the standalone functions, and their
|
|
604
|
-
diagnostic, and option types from `platejs/markdown`.
|
|
858
|
+
Import `MarkdownPlugin`, `RawHtmlPlugin`, the standalone functions, and their
|
|
859
|
+
result, diagnostic, and option types from `platejs/markdown`.
|
|
605
860
|
|
|
606
861
|
| Parse option | Use |
|
|
607
862
|
| --- | --- |
|
|
@@ -614,7 +869,7 @@ diagnostic, and option types from `platejs/markdown`.
|
|
|
614
869
|
| --- | --- |
|
|
615
870
|
| `document` | Editor method only: the document to serialize, typed as the editor's value. Defaults to the current value. |
|
|
616
871
|
| `lossPolicy` | `'reject'` (default) or `'allow'`. |
|
|
617
|
-
| `plainMarks` | Mark keys written as plain text without Markdown formatting. |
|
|
872
|
+
| `plainMarks` | Mark keys written as plain text without Markdown formatting. Defaults to `MarkdownPlugin`'s `plainMarks`. |
|
|
618
873
|
| `preserveEmptyParagraphs` | Keep empty paragraphs. Defaults to `true`. |
|
|
619
874
|
| `projection` | `'accepted'` or `'proposed'`. Required when the document has pending suggestions. |
|
|
620
875
|
| `remarkStringifyOptions` | Options passed to `remark-stringify`. |
|
|
@@ -623,4 +878,5 @@ diagnostic, and option types from `platejs/markdown`.
|
|
|
623
878
|
Standalone functions also require `plugins` and accept `schema`. Installed
|
|
624
879
|
editor methods omit both because the plugin captures them from the editor.
|
|
625
880
|
`MarkdownPlugin` state holds `remarkPlugins`, `remarkStringifyOptions`, and
|
|
626
|
-
`plainMarks`.
|
|
881
|
+
`plainMarks`. When its `plainMarks` names `rawHtml`, import gives raw HTML no
|
|
882
|
+
mark.
|
|
@@ -188,15 +188,18 @@ still selects the node. The [Excalidraw](/docs/excalidraw) element is
|
|
|
188
188
|
a complete example.
|
|
189
189
|
|
|
190
190
|
<Callout type="info" title="Keys the editor still takes">
|
|
191
|
-
Outside an IME composition,
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
when it has nothing to undo. A read-only editor only stops
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
191
|
+
Outside an IME composition, a widget gets the Undo and Redo keys first. A
|
|
192
|
+
widget that stops the key or prevents its default keeps it, and a native text
|
|
193
|
+
field applies the browser's own undo. Otherwise an editable editor runs its
|
|
194
|
+
own history, even when it has nothing to undo. A read-only editor only stops
|
|
195
|
+
the key. An independent nested editor, such as the inner editor of
|
|
196
|
+
[Editable Voids](/docs/examples/editable-voids), runs its own history. The
|
|
197
|
+
editor takes Undo and Redo before a nested editor's key handlers run only
|
|
198
|
+
when that nested editor shows another root of the same editor. The editor
|
|
199
|
+
also takes Shift+Arrow keys from a nested editor, and from any widget while
|
|
200
|
+
its own selection is in another root. While it holds a selection it draws
|
|
201
|
+
itself, such as one that spans roots, it also takes Backspace, Delete, and
|
|
202
|
+
Enter from any widget, unless Alt, Ctrl, or Meta is held.
|
|
200
203
|
</Callout>
|
|
201
204
|
|
|
202
205
|
## Styling
|
|
@@ -227,7 +230,7 @@ replace from the registry.
|
|
|
227
230
|
| `EditorLeaf` | Marked and decorated text. | Defaults to `span`; use with plugins that declare `schema.mark`. |
|
|
228
231
|
| `plugin.configure({ component: Component })` | Ordinary node component binding. | Include the component and every consumer override in the same terminal call. |
|
|
229
232
|
| `plugin.configure({ component: 'tag' })` | Default wrapper with an intrinsic tag. | Accepts an HTML tag such as `'blockquote'`, `'strong'`, or `'code'`. |
|
|
230
|
-
| `data-editor-root-chrome-ignore="true"` | A wrapper around a widget that owns its input. | Pair with `contentEditable={false}`; Undo and Redo
|
|
233
|
+
| `data-editor-root-chrome-ignore="true"` | A wrapper around a widget that owns its input. | Pair with `contentEditable={false}`; Undo and Redo reach the editor unless the widget stops them. |
|
|
231
234
|
|
|
232
235
|
For plugin method details, see [Plugin Methods](/docs/plugin-methods). For static
|
|
233
236
|
rendering components, see [Static Rendering](/docs/static).
|
|
@@ -24,7 +24,9 @@ Each rule declares a target (`insertText`, `insertBreak`, or `insertData`), an
|
|
|
24
24
|
optional `enabled` gate, a `resolve` function that looks at the current
|
|
25
25
|
selection and returns a match payload, and an `apply` function that performs the
|
|
26
26
|
transform. The first rule whose `resolve` returns a non-undefined payload gets
|
|
27
|
-
to run; if nothing matches, the default transform runs as usual.
|
|
27
|
+
to run; if nothing matches, the default transform runs as usual. An `insertData`
|
|
28
|
+
rule can declare `followUp` instead of `apply` to run after the paste lands, as
|
|
29
|
+
[Follow-up paste rules](#follow-up-paste-rules) describes.
|
|
28
30
|
|
|
29
31
|
Ownership splits cleanly into three lanes:
|
|
30
32
|
|
|
@@ -133,21 +135,13 @@ plugin's `inputRules`.
|
|
|
133
135
|
|
|
134
136
|
Basic block rules ship with `platejs`. Register them per plugin.
|
|
135
137
|
|
|
136
|
-
**Headings.** `HeadingRules.markdown()` is
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
heading to a different type, provide an app-owned rule for that type instead.
|
|
138
|
+
**Headings.** `HeadingRules.markdown()` is one rule for every heading level. It
|
|
139
|
+
counts the `#` characters typed before the space, `# ` through `###### `, and
|
|
140
|
+
gives the heading that `level`. Pass it once, on `HeadingPlugin`.
|
|
140
141
|
|
|
141
142
|
```tsx showLineNumbers
|
|
142
143
|
import { HeadingRules } from 'platejs';
|
|
143
|
-
import {
|
|
144
|
-
HeadingPlugin,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
} from 'platejs/react';
|
|
144
|
+
import { HeadingPlugin } from 'platejs/react';
|
|
151
145
|
|
|
152
146
|
export const HeadingInputRulesKit = [
|
|
153
147
|
HeadingPlugin.configure({ inputRules: [HeadingRules.markdown()] }),
|
|
@@ -687,6 +681,7 @@ rule matches, the original command runs normally.
|
|
|
687
681
|
| `enabled` | Policy gate, evaluated first |
|
|
688
682
|
| `resolve` | Computes the match payload passed to `apply` |
|
|
689
683
|
| `apply` | Mutates `tx`, then consumes, returns `next(...)`, or returns `decline()` |
|
|
684
|
+
| `followUp` | Replaces `apply` on an `insertData` rule and runs after the paste lands, as its own undo step |
|
|
690
685
|
| `priority` | Sort order for rules on the same target |
|
|
691
686
|
| `on` | Block-fence commit mode: `'match'` or `'break'` |
|
|
692
687
|
| `mimeTypes` | Narrows an `insertData` rule to specific MIME types |
|
|
@@ -699,6 +694,60 @@ callout", "only fire when this plugin is active" — belongs in `enabled`. Retur
|
|
|
699
694
|
and makes rules harder to compose.
|
|
700
695
|
</Callout>
|
|
701
696
|
|
|
697
|
+
### Follow-up paste rules
|
|
698
|
+
|
|
699
|
+
An `insertData` rule can declare `followUp` instead of `apply`. A follow-up rule
|
|
700
|
+
leaves the paste alone and runs after it, as its own undo step. One undo takes
|
|
701
|
+
back the follow-up's change and keeps the paste. A second undo takes back the
|
|
702
|
+
paste when history saved nothing between the two.
|
|
703
|
+
|
|
704
|
+
```ts
|
|
705
|
+
import { defineInputRule, NodeApi } from 'platejs';
|
|
706
|
+
|
|
707
|
+
const spaceAfterPastedLink = defineInputRule({
|
|
708
|
+
target: 'insertData',
|
|
709
|
+
resolve: ({ text }) =>
|
|
710
|
+
text && /^https?:\/\/\S+$/.test(text) ? text : undefined,
|
|
711
|
+
followUp: ({ tx }, link) => {
|
|
712
|
+
const block = tx.nodes.block();
|
|
713
|
+
|
|
714
|
+
if (!block || !NodeApi.string(block[0]).endsWith(link)) return;
|
|
715
|
+
|
|
716
|
+
tx.text.insert(' ', { at: tx.points.end(block[1]) });
|
|
717
|
+
},
|
|
718
|
+
});
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
- The runtime resolves follow-up rules against the state that `insertData`
|
|
722
|
+
starts from, apart from the rules that have `apply`. The first follow-up rule
|
|
723
|
+
whose `resolve` returns a payload runs, whichever rule took the paste.
|
|
724
|
+
- `followUp` runs only after a local paste that landed content and that undo
|
|
725
|
+
history saved, on the view that pasted. It never runs after a collaborator's
|
|
726
|
+
change, an undo, a redo or a document replacement, in an editor without
|
|
727
|
+
history, or when the view that pasted is read-only. It never runs when the
|
|
728
|
+
paste's commit changed nothing in the root the pasting view edits. It also
|
|
729
|
+
never runs after the editable's paste over a projected selection whose
|
|
730
|
+
deletion removed content, because that deletion runs before `insertData`
|
|
731
|
+
starts.
|
|
732
|
+
- `followUp` gets a transaction and the match, and no range of what the paste
|
|
733
|
+
wrote. A commit listener, a cleanup or an update that wraps the paste can
|
|
734
|
+
change the document before the follow-up runs, so a follow-up finds what it
|
|
735
|
+
acts on from its match and checks it before it writes. A match that a
|
|
736
|
+
follow-up writes at must carry a node key, or a root with its path, because a
|
|
737
|
+
bare path addresses the main root of the view that pasted.
|
|
738
|
+
- The follow-up writes at the pasting view's intent, so in Suggesting mode its
|
|
739
|
+
change is a suggestion. A rule that must not propose checks that intent
|
|
740
|
+
before it writes.
|
|
741
|
+
- `resolve` reads the clipboard data the paste started with. A rule with
|
|
742
|
+
`apply` that rewrites the data through `next(newData)` does not get the new
|
|
743
|
+
data matched again.
|
|
744
|
+
- `resolve` and `followUp` must be synchronous. A `resolve` that returns a
|
|
745
|
+
promise throws before the paste lands, a `followUp` that returns one throws,
|
|
746
|
+
and the editor reports each promise's rejection.
|
|
747
|
+
- Declare a follow-up rule through `defineInputRule`. It checks that `followUp`
|
|
748
|
+
takes what `resolve` returns, and `inputRules` refuses a follow-up rule
|
|
749
|
+
written as a plain object.
|
|
750
|
+
|
|
702
751
|
## API Reference
|
|
703
752
|
|
|
704
753
|
Low-level surface. Reach for this when the high-level factories don't cover your case. Everything below is exported from `platejs`.
|
|
@@ -739,8 +788,10 @@ const copyrightRule = defineInputRule({
|
|
|
739
788
|
```
|
|
740
789
|
|
|
741
790
|
Use it for raw `insertText`, `insertBreak`, or `insertData` rules. Match payload
|
|
742
|
-
types flow from `resolve` into `apply
|
|
743
|
-
|
|
791
|
+
types flow from `resolve` into `apply`, or into `followUp` for a
|
|
792
|
+
[follow-up paste rule](#follow-up-paste-rules), which `inputRules` accepts only
|
|
793
|
+
from `defineInputRule`. The owner-bound overload also exposes the owner's typed
|
|
794
|
+
`tx` group without explicit callback annotations.
|
|
744
795
|
|
|
745
796
|
### createMarkInputRule
|
|
746
797
|
|