reactive-md 0.8.0 → 0.9.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/CHANGELOG-ch.md +54 -4
- package/CHANGELOG.md +55 -4
- package/CONTRIBUTING-ch.md +13 -2
- package/CONTRIBUTING.md +13 -2
- package/README-ch.md +132 -23
- package/README-en.md +130 -21
- package/README.md +128 -21
- package/SECURITY-ch.md +3 -3
- package/SECURITY.md +3 -3
- package/THIRD_PARTY_NOTICES.md +111 -1
- package/cli/args.mjs +51 -1
- package/cli/assets.mjs +6 -1
- package/cli/build.mjs +125 -9
- package/cli/fs-utils.mjs +3 -3
- package/cli/help.mjs +12 -5
- package/cli/init.mjs +1 -1
- package/cli/package.mjs +1 -0
- package/dist-library/LocalDocumentView-sthUP0ct.js +109 -0
- package/dist-library/LocalDocumentViewCore-GiWV3bey.js +9829 -0
- package/dist-library/LocalReactiveDocumentCore-ZjQSGyHE.js +275 -0
- package/dist-library/{authoring-BsfSwQRm.js → authoring-Dsune4Hy.js} +240 -218
- package/dist-library/compile-wUv8KEge.js +1249 -0
- package/dist-library/{compiler-core-kPiH-gOV.js → compiler-core-As_m-MNm.js} +5372 -5559
- package/dist-library/compiler-eOfcinZs.js +62 -0
- package/dist-library/component-state-BoLCGee4.js +801 -0
- package/dist-library/{component-state-D_cw_EHe.js → component-state-C52ZFJGl.js} +2 -2
- package/dist-library/{registry-B9Jc3FVe.js → config-BadfhjdP.js} +374 -457
- package/dist-library/{config-validation-DXTynAw7.js → config-validation-F47AcE6o.js} +549 -751
- package/dist-library/controls-CcT6n7k_.js +6740 -0
- package/dist-library/coordinate-CWS9p5q_.js +293 -0
- package/dist-library/data-table-Bgccxd7h.js +296 -0
- package/dist-library/{default-components-Z_YMio5P.js → default-components-BwQf0oP-.js} +344 -334
- package/dist-library/{math-display-BJz4gbFc.js → display-B-VhqVND.js} +1299 -1299
- package/dist-library/export-BqVmTXm8.js +369 -0
- package/dist-library/gallery-CY6mTx8i.js +360 -0
- package/dist-library/html-CNT4KD-2.js +757 -0
- package/dist-library/{math-sample-BGEW49zY.js → incremental-Dv0FSp_U.js} +476 -394
- package/dist-library/latex-1w7aQgD5.js +928 -0
- package/dist-library/layout-C0YlEPGr.js +562 -0
- package/dist-library/mount-preset-KxvtKgJb.js +13 -0
- package/dist-library/options-1aDLK7JY.js +121 -0
- package/dist-library/{react-ByOHunUW.js → package-core-WFK1RhAZ.js} +49 -55
- package/dist-library/{parser-standard-DlCk7sLo.js → parser-standard-Yuf3A_VI.js} +6605 -7097
- package/dist-library/plugin-packs-B1XPWcFs.js +18 -0
- package/dist-library/{identity-MYJXKSkB.js → preset-core-CKc5YXSM.js} +31 -31
- package/dist-library/{props-DGlBk0e5.js → props-sJ8vk0cr.js} +1 -1
- package/dist-library/react-BbyAgeXc.js +6070 -0
- package/dist-library/react-D5iGiUdL.js +7 -0
- package/dist-library/reactive-md-authoring.js +222 -223
- package/dist-library/reactive-md-build.js +126 -72
- package/dist-library/reactive-md-compiler-standard.js +12 -10
- package/dist-library/reactive-md-compiler.js +3 -3
- package/dist-library/reactive-md-default-packs.js +2 -2
- package/dist-library/reactive-md-default-preset.js +4 -4
- package/dist-library/reactive-md-export-assets.js +57 -0
- package/dist-library/reactive-md-export.js +5 -111
- package/dist-library/reactive-md-minimal-preset.js +24 -0
- package/dist-library/reactive-md-minimal-react-preset.js +26 -0
- package/dist-library/reactive-md-minimal-styles.js +80 -0
- package/dist-library/reactive-md-minimal.css +2 -0
- package/dist-library/reactive-md-pdf.js +7582 -0
- package/dist-library/reactive-md-plugin-chart.js +13 -0
- package/dist-library/reactive-md-plugin-data.js +17 -0
- package/dist-library/reactive-md-plugin-diagram.js +18 -0
- package/dist-library/reactive-md-plugin-forms.js +18 -0
- package/dist-library/reactive-md-plugin-gallery.js +12 -0
- package/dist-library/reactive-md-plugin-navigation.js +15 -0
- package/dist-library/reactive-md-plugin-network.js +222 -0
- package/dist-library/reactive-md-plugin-plot.js +24 -0
- package/dist-library/reactive-md-print.css +5 -0
- package/dist-library/reactive-md-react-minimal.js +28 -0
- package/dist-library/reactive-md-react-server.js +34 -32
- package/dist-library/reactive-md-react-unstyled.js +14 -9
- package/dist-library/reactive-md-react.js +14 -9
- package/dist-library/reactive-md-runtime-browser.js +847 -15
- package/dist-library/reactive-md-runtime.js +3 -3
- package/dist-library/reactive-md-sdk.js +8 -6
- package/dist-library/reactive-md-standalone-configured.js +16 -0
- package/dist-library/reactive-md-standalone-host.js +9 -438
- package/dist-library/reactive-md-testing-browser.js +5 -4
- package/dist-library/reactive-md-testing-react.js +46 -44
- package/dist-library/reactive-md-testing.js +45 -44
- package/dist-library/reactive-md-vite.js +135 -37
- package/dist-library/reactive-md.css +1 -1
- package/dist-library/reactive-md.js +590 -498
- package/dist-library/registry-B9NGct4d.js +20 -0
- package/dist-library/registry-core-Bbad9Bm2.js +479 -0
- package/dist-library/{resources-BGt8mpDA.js → resources-D2GDQS0p.js} +45 -45
- package/dist-library/{runtime-Dkq7ldyg.js → runtime-B2fxeveq.js} +1 -1
- package/dist-library/runtime-kcA7bG7G.js +1282 -0
- package/dist-library/sample-bP4zHB3L.js +289 -0
- package/dist-library/{schema-ZFufO8V0.js → schema-BufhKUSM.js} +12 -11
- package/dist-library/sdk-core-BoJT1SIt.js +1166 -0
- package/dist-library/session-core-nmJHuR9c.js +452 -0
- package/dist-library/{shareable-DDVL4Fi9.js → shareable-DpbE-59H.js} +250 -283
- package/dist-library/tooltip-layer-HDLrSWs0.js +28 -0
- package/dist-library/types/authoring/catalog.d.ts +2 -3
- package/dist-library/types/authoring/editor-i18n.d.ts +1 -1
- package/dist-library/types/authoring/index.d.ts +1 -1
- package/dist-library/types/authoring/insert.d.ts +1 -1
- package/dist-library/types/authoring/templates.d.ts +2 -2
- package/dist-library/types/build/diagnostics.d.ts +1 -1
- package/dist-library/types/build/host.d.ts +1 -1
- package/dist-library/types/build/index.d.ts +1 -1
- package/dist-library/types/build/notices.d.ts +1 -1
- package/dist-library/types/build/resources.d.ts +1 -1
- package/dist-library/types/build/vite.d.ts +1 -1
- package/dist-library/types/compiler/index.d.ts +2 -2
- package/dist-library/types/compiler/result.d.ts +1 -1
- package/dist-library/types/compiler/standard.d.ts +2 -2
- package/dist-library/types/compiler/types.d.ts +1 -1
- package/dist-library/types/components/{controls.d.ts → controls/controls.d.ts} +2 -3
- package/dist-library/types/components/{numeric-sliders.d.ts → controls/numeric-sliders.d.ts} +1 -1
- package/dist-library/types/components/{gallery.d.ts → gallery/gallery.d.ts} +1 -1
- package/dist-library/types/components/{layout.d.ts → layout/layout.d.ts} +1 -1
- package/dist-library/types/components/minimal-preset.d.ts +2 -0
- package/dist-library/types/components/mount-preset.d.ts +4 -0
- package/dist-library/types/components/network/submit-button.d.ts +10 -0
- package/dist-library/types/components/plot/coordinate.d.ts +2 -0
- package/dist-library/types/components/plugins/chart.d.ts +2 -0
- package/dist-library/types/components/plugins/data.d.ts +2 -0
- package/dist-library/types/components/plugins/diagram.d.ts +2 -0
- package/dist-library/types/components/plugins/forms.d.ts +2 -0
- package/dist-library/types/components/plugins/gallery.d.ts +2 -0
- package/dist-library/types/components/plugins/navigation.d.ts +2 -0
- package/dist-library/types/components/plugins/network.d.ts +2 -0
- package/dist-library/types/components/plugins/plot.d.ts +2 -0
- package/dist-library/types/components/shared/visual-frame.d.ts +12 -0
- package/dist-library/types/components/{visuals.d.ts → shared/visuals.d.ts} +1 -7
- package/dist-library/types/components/{data-table.d.ts → table/data-table.d.ts} +2 -2
- package/dist-library/types/export/component-state.d.ts +1 -1
- package/dist-library/types/export/index.d.ts +2 -1
- package/dist-library/types/export/print-document.d.ts +18 -0
- package/dist-library/types/export/render-markup.d.ts +23 -0
- package/dist-library/types/export/requirements.d.ts +1 -1
- package/dist-library/types/export/resources.d.ts +1 -1
- package/dist-library/types/export/restoration.d.ts +1 -1
- package/dist-library/types/export-assets/index.d.ts +25 -0
- package/dist-library/types/local/compilation/compiler-attributes.d.ts +8 -0
- package/dist-library/types/local/compilation/compiler-bindings.d.ts +19 -0
- package/dist-library/types/local/compilation/compiler-capabilities.d.ts +3 -0
- package/dist-library/types/local/compilation/compiler-core.d.ts +11 -3
- package/dist-library/types/local/compilation/compiler-declarations.d.ts +32 -0
- package/dist-library/types/local/compilation/compiler-expressions.d.ts +32 -0
- package/dist-library/types/local/compilation/compiler-services.d.ts +62 -16
- package/dist-library/types/local/compilation/compiler-structure.d.ts +38 -3
- package/dist-library/types/local/compilation/compiler-tables.d.ts +30 -0
- package/dist-library/types/local/compilation/compiler-validation.d.ts +15 -0
- package/dist-library/types/local/compilation/compiler-values.d.ts +39 -1
- package/dist-library/types/local/compilation/compiler.d.ts +7 -14
- package/dist-library/types/local/compilation/dependencies.d.ts +1 -1
- package/dist-library/types/local/compilation/session/incremental.d.ts +75 -0
- package/dist-library/types/local/{session → compilation/session}/row-reuse.d.ts +1 -1
- package/dist-library/types/local/{session/compiler-cache.d.ts → compilation/session/semantic-cache.d.ts} +5 -19
- package/dist-library/types/local/compilation/streaming.d.ts +27 -0
- package/dist-library/types/local/configuration/capability-policy.d.ts +3 -0
- package/dist-library/types/local/{compilation → configuration}/component-kernel.d.ts +3 -79
- package/dist-library/types/local/configuration/diagnostic-messages.d.ts +1104 -1056
- package/dist-library/types/local/configuration/diagnostic-runtime-messages.d.ts +731 -0
- package/dist-library/types/local/configuration/diagnostics.d.ts +1 -1
- package/dist-library/types/local/configuration/kernel-value-rules.d.ts +66 -0
- package/dist-library/types/local/configuration/official-leaf-syntax.d.ts +24 -0
- package/dist-library/types/local/configuration/options-core.d.ts +5 -4
- package/dist-library/types/local/configuration/options.d.ts +2 -1
- package/dist-library/types/local/configuration/portable-options.d.ts +1 -1
- package/dist-library/types/local/configuration/schema-core.d.ts +1 -1
- package/dist-library/types/local/configuration/schema.d.ts +1 -1
- package/dist-library/types/local/css/author-css.d.ts +66 -0
- package/dist-library/types/local/evaluation/computations.d.ts +2 -2
- package/dist-library/types/local/evaluation/expression/compile.d.ts +30 -0
- package/dist-library/types/local/evaluation/expression/evaluation.d.ts +3 -0
- package/dist-library/types/local/evaluation/expression/inference.d.ts +4 -0
- package/dist-library/types/local/evaluation/expression/syntax.d.ts +72 -0
- package/dist-library/types/local/evaluation/expression/values.d.ts +56 -0
- package/dist-library/types/local/evaluation/{math-display.d.ts → math/display.d.ts} +2 -2
- package/dist-library/types/local/evaluation/math/evaluation.d.ts +10 -0
- package/dist-library/types/local/evaluation/{math.d.ts → math/latex.d.ts} +58 -17
- package/dist-library/types/local/evaluation/{math-sample.d.ts → math/sample.d.ts} +4 -2
- package/dist-library/types/local/evaluation/math/syntax.d.ts +72 -0
- package/dist-library/types/local/evaluation/validation.d.ts +1 -1
- package/dist-library/types/local/html/extended-fragment.d.ts +41 -0
- package/dist-library/types/local/html/html-details.d.ts +1 -1
- package/dist-library/types/local/html/html-entities.d.ts +11 -2
- package/dist-library/types/local/html/html-recovery.d.ts +1 -1
- package/dist-library/types/local/html/html-table.d.ts +1 -1
- package/dist-library/types/local/html/html.d.ts +40 -4
- package/dist-library/types/local/index.d.ts +14 -13
- package/dist-library/types/local/parsing/author-markdown.d.ts +11 -0
- package/dist-library/types/local/{markdown → parsing}/fast-markdown.d.ts +1 -1
- package/dist-library/types/local/{markdown → parsing}/footnotes.d.ts +1 -1
- package/dist-library/types/local/{markdown → parsing}/heading-anchors.d.ts +1 -1
- package/dist-library/types/local/parsing/html-attributes.d.ts +14 -0
- package/dist-library/types/local/parsing/parse-budget.d.ts +1 -1
- package/dist-library/types/local/{session → parsing}/parse-session.d.ts +5 -5
- package/dist-library/types/local/parsing/parser-capabilities.d.ts +7 -2
- package/dist-library/types/local/parsing/parser-convert.d.ts +26 -0
- package/dist-library/types/local/parsing/parser-core.d.ts +10 -4
- package/dist-library/types/local/parsing/parser-internals.d.ts +54 -0
- package/dist-library/types/local/parsing/parser-region.d.ts +46 -0
- package/dist-library/types/local/parsing/parser-standard.d.ts +3 -0
- package/dist-library/types/local/parsing/parser-tags.d.ts +108 -0
- package/dist-library/types/local/parsing/parser.d.ts +3 -3
- package/dist-library/types/local/{markdown → parsing}/plain-paragraphs.d.ts +1 -1
- package/dist-library/types/local/parsing/rmd-recovery.d.ts +1 -1
- package/dist-library/types/local/parsing/theme-declaration.d.ts +22 -0
- package/dist-library/types/local/rendering/document/ExtendedHtmlFragment.d.ts +14 -0
- package/dist-library/types/local/rendering/document/LocalDocumentView.d.ts +5 -0
- package/dist-library/types/local/rendering/{LocalDocumentView.d.ts → document/LocalDocumentViewCore.d.ts} +48 -9
- package/dist-library/types/local/rendering/document/LocalReactiveDocumentCore.d.ts +6 -0
- package/dist-library/types/local/rendering/document/render-nodes.d.ts +24 -0
- package/dist-library/types/local/rendering/document/use-author-script.d.ts +3 -0
- package/dist-library/types/local/rendering/document/use-color-scheme.d.ts +10 -0
- package/dist-library/types/local/rendering/document/validation-state.d.ts +31 -0
- package/dist-library/types/local/rendering/document/view-render-context.d.ts +146 -0
- package/dist-library/types/local/rendering/{view-revision.d.ts → document/view-revision.d.ts} +31 -4
- package/dist-library/types/local/rendering/render-types.d.ts +1 -1
- package/dist-library/types/local/{widgets/table-surface.d.ts → rendering/table/data-table.d.ts} +3 -0
- package/dist-library/types/local/rendering/table/table-numeric-columns.d.ts +7 -0
- package/dist-library/types/local/runtime/author-script-protocol.d.ts +59 -0
- package/dist-library/types/local/runtime/retention.d.ts +1 -1
- package/dist-library/types/local/runtime/runtime-document.d.ts +71 -0
- package/dist-library/types/local/runtime/runtime-migration.d.ts +19 -0
- package/dist-library/types/local/runtime/runtime-values.d.ts +39 -0
- package/dist-library/types/local/runtime/runtime.d.ts +4 -2
- package/dist-library/types/local/runtime/state.d.ts +1 -1
- package/dist-library/types/local/source/authoring-syntax.d.ts +48 -0
- package/dist-library/types/local/source/authoring.d.ts +1 -1
- package/dist-library/types/local/source/source-context.d.ts +23 -0
- package/dist-library/types/local/source/source-migration.d.ts +2 -2
- package/dist-library/types/local/transport/compile-patch.d.ts +1 -1
- package/dist-library/types/local/transport/flat-compiled-data.d.ts +1 -1
- package/dist-library/types/local/transport/shared-data.d.ts +1 -1
- package/dist-library/types/local/transport/worker-handler.d.ts +30 -0
- package/dist-library/types/local/transport/worker-job.d.ts +28 -0
- package/dist-library/types/local/transport/worker.d.ts +32 -46
- package/dist-library/types/local/{contracts/types.d.ts → types.d.ts} +78 -21
- package/dist-library/types/pdf.d.ts +22 -0
- package/dist-library/types/presets/identity.d.ts +1 -0
- package/dist-library/types/presets/minimal.d.ts +2 -0
- package/dist-library/types/presets/plugin-packs.d.ts +1 -0
- package/dist-library/types/react/component-api.d.ts +20 -4
- package/dist-library/types/react/component-primitives.d.ts +10 -10
- package/dist-library/types/react/component-utils.d.ts +9 -1
- package/dist-library/types/react/index.d.ts +6 -5
- package/dist-library/types/{local/theme/i18n.d.ts → react/localization.d.ts} +2 -2
- package/dist-library/types/react/minimal.d.ts +13 -0
- package/dist-library/types/react/package-core.d.ts +67 -0
- package/dist-library/types/react/package.d.ts +3 -67
- package/dist-library/types/react/runtime/common.d.ts +1 -1
- package/dist-library/types/react/sdk-core.d.ts +115 -0
- package/dist-library/types/react/sdk.d.ts +4 -110
- package/dist-library/types/react/server.d.ts +2 -2
- package/dist-library/types/react/use-draft-field.d.ts +5 -1
- package/dist-library/types/runtime-services/browser/duplex.d.ts +163 -0
- package/dist-library/types/runtime-services/browser/http-sse.d.ts +117 -0
- package/dist-library/types/runtime-services/browser/index.d.ts +2 -1
- package/dist-library/types/runtime-services/component-state.d.ts +1 -1
- package/dist-library/types/runtime-services/index.d.ts +2 -0
- package/dist-library/types/runtime-services/network.d.ts +86 -0
- package/dist-library/types/runtime-services/runtime.d.ts +1 -1
- package/dist-library/types/sdk/config.d.ts +1 -1
- package/dist-library/types/sdk/index.d.ts +1 -0
- package/dist-library/types/sdk/props.d.ts +1 -1
- package/dist-library/types/sdk/registry-core.d.ts +1 -1
- package/dist-library/types/sdk/theme.d.ts +5 -4
- package/dist-library/types/sdk/types.d.ts +2 -2
- package/dist-library/types/shareable.d.ts +6 -5
- package/dist-library/types/standalone/diagnostics.d.ts +1 -1
- package/dist-library/types/standalone/host.d.ts +5 -0
- package/dist-library/types/standalone/payload.d.ts +1 -1
- package/dist-library/types/standalone/prepare.d.ts +2 -2
- package/dist-library/types/standalone/session-core.d.ts +68 -0
- package/dist-library/types/standalone/session.d.ts +6 -68
- package/dist-library/types/themes/contract.d.ts +7 -0
- package/dist-library/types/{local/theme/theme.d.ts → themes/document-theme.d.ts} +4 -3
- package/dist-library/types/vite/client.d.ts +19 -0
- package/dist-library/types/vite/index.d.ts +18 -3
- package/dist-library/types/vite/registration.d.ts +2 -2
- package/dist-library/{types-BFCrMrg0.js → types-BeNtPqdY.js} +1 -1
- package/dist-library/validation-BEBA_HvS.js +1121 -0
- package/dist-library/visual-frame-CyV1FXzs.js +48 -0
- package/dist-library/visuals-B5KSafVk.js +3 -0
- package/dist-library/visuals-BZbZYA7w.js +72572 -0
- package/dist-standalone/reactive-md-standalone.css +1 -1
- package/dist-standalone/reactive-md-standalone.js +146 -137
- package/docs/README-ch.md +16 -11
- package/docs/README.md +16 -11
- package/docs/compatibility/compatibility-ch.md +8 -8
- package/docs/compatibility/compatibility-en.md +8 -8
- package/docs/compatibility/source-versioning-ch.md +1 -1
- package/docs/compatibility/source-versioning-en.md +1 -1
- package/docs/development/component-development-ch.md +2 -2
- package/docs/development/component-development-en.md +2 -2
- package/docs/development/component-development-reference-ch.md +4 -4
- package/docs/development/component-development-reference-en.md +4 -4
- package/docs/development/component-protocol-ch.md +14 -14
- package/docs/development/component-protocol-en.md +14 -14
- package/docs/development/extension-tutorial-ch.md +308 -0
- package/docs/development/extension-tutorial-en.md +308 -0
- package/docs/development/local-module-layout-ch.md +10 -50
- package/docs/development/local-module-layout-en.md +9 -49
- package/docs/development/performance-overview-ch.md +174 -154
- package/docs/development/performance-overview-en.md +174 -154
- package/docs/guides/local-guide-ch.md +2 -2
- package/docs/guides/local-guide-en.md +2 -2
- package/docs/integration/author-tools-ch.md +2 -2
- package/docs/integration/author-tools-en.md +2 -2
- package/docs/integration/compiler-ch.md +4 -2
- package/docs/integration/compiler-en.md +4 -2
- package/docs/integration/directory-discovery-ch.md +5 -1
- package/docs/integration/directory-discovery-en.md +5 -1
- package/docs/integration/editor-ch.md +35 -5
- package/docs/integration/editor-en.md +42 -4
- package/docs/integration/extension-sdk-ch.md +6 -4
- package/docs/integration/extension-sdk-en.md +6 -4
- package/docs/integration/local-integration-ch.md +201 -19
- package/docs/integration/local-integration-en.md +194 -18
- package/docs/integration/network-host-ch.md +75 -0
- package/docs/integration/network-host-en.md +75 -0
- package/docs/integration/shareable-export-ch.md +58 -16
- package/docs/integration/shareable-export-en.md +57 -15
- package/docs/reference/html-compatibility-ch.md +20 -67
- package/docs/reference/html-compatibility-en.md +19 -64
- package/docs/reference/local-interaction-syntax-ch.md +199 -26
- package/docs/reference/local-interaction-syntax-en.md +194 -27
- package/docs/reference/public-api-ch.md +416 -0
- package/docs/reference/public-api-en.md +416 -0
- package/docs/reference/theme-protocol-ch.md +27 -8
- package/docs/reference/theme-protocol-en.md +46 -8
- package/docs/releases/release-0.4.0-ch.md +2 -2
- package/docs/releases/release-0.4.0-en.md +2 -2
- package/docs/releases/release-0.8.0-ch.md +19 -3
- package/docs/releases/release-0.8.0-en.md +19 -3
- package/docs/releases/release-0.9.0-ch.md +44 -0
- package/docs/releases/release-0.9.0-en.md +44 -0
- package/docs/releases/release-0.9.1-ch.md +29 -0
- package/docs/releases/release-0.9.1-en.md +29 -0
- package/examples/component-package/README-ch.md +1 -1
- package/examples/component-package/README.md +1 -1
- package/examples/conformance/README-ch.md +3 -3
- package/examples/conformance/README.md +3 -3
- package/examples/game-2048-package/README-ch.md +3 -9
- package/examples/game-2048-package/README.md +8 -12
- package/examples/integration/README-ch.md +21 -2
- package/examples/integration/README.md +21 -2
- package/examples/integration/extension-sdk/README-ch.md +1 -1
- package/examples/integration/extension-sdk/README.md +1 -1
- package/examples/integration/streaming/index.html +48 -0
- package/examples/integration/streaming/main.js +175 -0
- package/examples/integration/streaming/package.json +13 -0
- package/examples/integration/streaming/worker.js +3 -0
- package/examples/local/README-ch.md +3 -3
- package/examples/local/README.md +2 -2
- package/examples/local/minimal-budget.reactive.md +48 -0
- package/examples/minimal-extension/README-ch.md +78 -0
- package/examples/minimal-extension/README.md +78 -0
- package/examples/minimal-extension/index.html +15 -0
- package/examples/minimal-extension/package.json +26 -0
- package/examples/minimal-extension/sample/document.reactive.md +10 -0
- package/examples/minimal-extension/scripts/build.mjs +32 -0
- package/examples/minimal-extension/scripts/export.mjs +72 -0
- package/examples/minimal-extension/scripts/test-node.mjs +75 -0
- package/examples/minimal-extension/src/extension.tsx +90 -0
- package/examples/minimal-extension/src/preview.tsx +12 -0
- package/examples/minimal-extension/src/source.ts +4 -0
- package/examples/minimal-extension/tsconfig.json +14 -0
- package/examples/network-survey/README.md +200 -0
- package/examples/network-survey/index.html +49 -0
- package/examples/network-survey/package.json +26 -0
- package/examples/network-survey/sample/document.reactive.md +51 -0
- package/examples/network-survey/src/components.tsx +325 -0
- package/examples/network-survey/src/host.ts +316 -0
- package/examples/network-survey/src/main.tsx +91 -0
- package/examples/network-survey/src/source.ts +1 -0
- package/examples/network-survey/tsconfig.json +26 -0
- package/examples/network-survey/vite.config.ts +227 -0
- package/examples/sci-fi-theme/README-ch.md +4 -2
- package/examples/sci-fi-theme/README.md +4 -2
- package/examples/sci-fi-theme/demo/acceptance.reactive.md +454 -0
- package/examples/sci-fi-theme/demo/demo.css +129 -23
- package/examples/sci-fi-theme/demo/document.reactive.md +27 -6
- package/examples/sci-fi-theme/demo/main.tsx +45 -10
- package/examples/sci-fi-theme/docs/design-system-ch.md +6 -6
- package/examples/sci-fi-theme/package.json +2 -1
- package/examples/sci-fi-theme/src/components.css +1064 -154
- package/examples/sci-fi-theme/src/notch.css +142 -0
- package/examples/sci-fi-theme/src/sci-fi.css +3 -1
- package/examples/sci-fi-theme/src/theme.ts +2 -0
- package/examples/sci-fi-theme/src/tokens.css +512 -408
- package/examples/tetris-package/README-ch.md +4 -4
- package/examples/tetris-package/README.md +4 -4
- package/package.json +70 -3
- package/dist-library/LocalDocumentView-6trX7xJc.js +0 -97920
- package/dist-library/compiler--ea2CKQF.js +0 -61
- package/dist-library/component-state-Cq2K5gkS.js +0 -490
- package/dist-library/options-CX5m5n-J.js +0 -115
- package/dist-library/runtime-C-sbfpOX.js +0 -1157
- package/dist-library/types/local/contracts/locale.d.ts +0 -1
- package/dist-library/types/local/contracts/version.d.ts +0 -2
- package/dist-library/types/local/evaluation/dates.d.ts +0 -2
- package/dist-library/types/local/evaluation/expression.d.ts +0 -47
- package/dist-library/types/local/markdown/markdown-structure.d.ts +0 -3
- package/dist-library/types/local/rendering/legacy-component-adapter.d.ts +0 -36
- package/dist-library/types/local/session/incremental.d.ts +0 -48
- package/dist-library/types/local/source/node-walk.d.ts +0 -3
- package/dist-library/types/local/source/text-length.d.ts +0 -13
- package/dist-library/types/local/theme/theme-name.d.ts +0 -3
- package/dist-library/types/local/widgets/visuals.d.ts +0 -25
- package/dist-library/types/react/default-theme.d.ts +0 -6
- package/dist-library/validation-W-bmny-x.js +0 -2253
- package/docs/development/releasing-ch.md +0 -12
- package/docs/development/releasing-en.md +0 -12
- package/docs/integration/codemirror-ch.md +0 -52
- package/docs/integration/codemirror-en.md +0 -29
- package/docs/integration/repository-split-ch.md +0 -40
- package/docs/integration/repository-split-en.md +0 -23
- package/docs/reference/computations-formatting-ch.md +0 -89
- package/docs/reference/computations-formatting-en.md +0 -89
- package/docs/reference/constraints-collections-ch.md +0 -104
- package/docs/reference/constraints-collections-en.md +0 -104
- package/docs/reference/local-components-v2-ch.md +0 -140
- package/docs/reference/local-components-v2-en.md +0 -106
- package/docs/reference/tolerance-ch.md +0 -64
- package/docs/reference/tolerance-en.md +0 -57
- /package/dist-library/types/components/{chart-motion.d.ts → chart/chart-motion.d.ts} +0 -0
- /package/dist-library/types/components/{default-chart-types.d.ts → chart/default-chart-types.d.ts} +0 -0
- /package/dist-library/types/components/{default-chart.d.ts → chart/default-chart.d.ts} +0 -0
- /package/dist-library/types/components/{diagram-inspector.d.ts → diagram/diagram-inspector.d.ts} +0 -0
- /package/dist-library/types/{local/widgets/diagram-layout.d.ts → components/diagram/layout.d.ts} +0 -0
- /package/dist-library/types/components/{mafs-plot-grid.d.ts → plot/mafs-plot-grid.d.ts} +0 -0
- /package/dist-library/types/components/{mafs-visuals.d.ts → plot/mafs-visuals.d.ts} +0 -0
- /package/dist-library/types/components/{use-hydrated.d.ts → shared/use-hydrated.d.ts} +0 -0
- /package/dist-library/types/local/{theme/colors.d.ts → configuration/color-values.d.ts} +0 -0
- /package/dist-library/types/local/evaluation/{collection-functions.d.ts → expression/collection-functions.d.ts} +0 -0
- /package/dist-library/types/local/evaluation/{data-functions.d.ts → expression/data-functions.d.ts} +0 -0
- /package/dist-library/types/local/evaluation/{formatting.d.ts → expression/formatting.d.ts} +0 -0
- /package/dist-library/types/local/{markdown → parsing}/markdown-blocks.d.ts +0 -0
- /package/dist-library/types/local/{widgets → rendering/code}/code-block.d.ts +0 -0
- /package/dist-library/types/local/{widgets → rendering/code}/code-languages.d.ts +0 -0
- /package/dist-library/types/local/{widgets → rendering/image}/image-view.d.ts +0 -0
- /package/dist-library/types/local/{widgets → rendering}/math-view.d.ts +0 -0
|
@@ -6,7 +6,7 @@ Local interaction mode uses HTML-style tags, in-place parameters and `{{ express
|
|
|
6
6
|
|
|
7
7
|
## Runtime and entries
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
ReactiveMD mixes P0 HTML with Markdown and components. Hosts grant author styles, scripts and extended HTML fragments independently. See [HTML compatibility](../reference/html-compatibility-en.md).
|
|
10
10
|
|
|
11
11
|
| Entry | Contents | Dependency |
|
|
12
12
|
| --- | --- | --- |
|
|
@@ -45,7 +45,9 @@ export function Article() {
|
|
|
45
45
|
|
|
46
46
|
| Prop | Type | Component | Notes |
|
|
47
47
|
| --- | --- | --- | --- |
|
|
48
|
-
| `source` | `string` | `LocalReactiveDocument` | Recompiles and
|
|
48
|
+
| `source` | `string` | `LocalReactiveDocument` | Recompiles on source changes and adopts the new document in the existing runtime, migrating parameter values that still satisfy their contracts. Host option changes that affect compilation semantics or a document the runtime cannot adopt create a new runtime and drop the old instance state. See [Keeping values when source changes](#keeping-values-when-source-changes) |
|
|
49
|
+
| `sourcePhase` | `'streaming' \| 'final'` | `LocalReactiveDocument` | Marks whether the source is still being generated; defaults to `final`. While `streaming`, the document renders read-only in static mode and defers side effects; independent of `strict`. A host may also set `compileOptions.sourcePhase`; the prop wins. See [Streaming source compilation](#streaming-source-compilation) |
|
|
50
|
+
| `onTransientDiagnostics` | `(diagnostics: Diagnostic[]) => void` | `LocalReactiveDocument` | Receives fixable issues from streaming snapshots; they never enter `onDiagnostics`. When generation finishes, hosts that received them get one final empty array. Omit to ignore provisional issues |
|
|
49
51
|
| `compileOptions` | `LocalCompileOptions` | `LocalReactiveDocument` | Per-compilation limits, HTML capability flags and host component schemas; omitted options use the default ReactiveMD path |
|
|
50
52
|
| `document` | `LocalDocument` | `LocalDocumentView` | Compiled document; compiled once by the host |
|
|
51
53
|
| `runtime` | `LocalRuntime` | `LocalDocumentView` | Created by the host, which is responsible for disposal |
|
|
@@ -57,7 +59,7 @@ export function Article() {
|
|
|
57
59
|
| `hostData` | `Readonly<Record<string, unknown>>` | Both | JSON-safe host data keyed `${kind}:${ref}` for `hostComponent` nodes; never enters the worker |
|
|
58
60
|
| `hostRenderer` | `LocalHostRenderer` | Both | Client-only renderer for `hostComponent` nodes; a missing renderer or data renders a visible placeholder |
|
|
59
61
|
| `externalValues` | `Readonly<Record<string, LocalValue>>` | `LocalReactiveDocument` | Values for `<external>` declarations; updates never recompile or reset parameters. `LocalDocumentView` also accepts it for host-managed runtimes |
|
|
60
|
-
| `initialParameters` | `Readonly<Record<string, LocalValue>>` | `LocalReactiveDocument` | Public parameter values applied once after each new runtime is created, before interaction;
|
|
62
|
+
| `initialParameters` | `Readonly<Record<string, LocalValue>>` | `LocalReactiveDocument` | Public parameter values applied once after each new runtime is created, before interaction; ordinary source updates reuse the runtime and do not reapply them. An invalid set is rejected atomically and reported through `onDiagnostics` |
|
|
61
63
|
| `onParametersChange` | `(parameters, snapshot) => void` | `LocalReactiveDocument` | Called once per commit when the public writable parameter set actually changes; initialization, rejected writes, unchanged values and external-only updates do not call it |
|
|
62
64
|
| `onSourceNavigate` | `(target: LocalSourceTarget) => void` | Both | Reports a preview node's source range; enabling it adds source metadata attributes, omitting it leaves the DOM unchanged |
|
|
63
65
|
|
|
@@ -74,7 +76,7 @@ Neither component has `className`, `style` or slot props. `LocalReactiveDocument
|
|
|
74
76
|
/>
|
|
75
77
|
```
|
|
76
78
|
|
|
77
|
-
Each component instance manages in-memory state independently. Changing the source recompiles and
|
|
79
|
+
Each component instance manages in-memory state independently. Changing the source recompiles and adopts the new document in the existing runtime: parameters keep their values when their bindings, types and initial definitions still match, and incompatible values fall back to the new initial values. Disposing an instance clears subscriptions and timers. To migrate values explicitly when creating a new runtime or managing the runtime yourself, use the retention helpers; see [Keeping values when source changes](#keeping-values-when-source-changes). A panel reset in the document restores its internal parameters, input drafts and component state, and displays of same-name parameters outside the panel update as well.
|
|
78
80
|
|
|
79
81
|
When a host React root shares a page with the standalone IIFE, give the host root a distinct `identifierPrefix`, for example `createRoot(container, { identifierPrefix: 'host-' })`. The bundles own separate React instances, so their default `useId` counters can overlap. Independent server-rendered roots need matching unique prefixes on the server and client too.
|
|
80
82
|
|
|
@@ -102,13 +104,13 @@ console.log(session.stats); // mode: 'incremental', compiledBlocks: 1, reusedBlo
|
|
|
102
104
|
session.dispose(); // when closing the document
|
|
103
105
|
```
|
|
104
106
|
|
|
105
|
-
`compile(source, options?)` returns `LocalCompileResult
|
|
107
|
+
`compile(source, options?, phase?)` returns `LocalCompileResult`; see [Streaming source compilation](#streaming-source-compilation) for phases. `compileShared` exposes the compiler-owned read-only result graph used by the Worker and preview; callers must not mutate it, and `compile` publishes an independent plain-data snapshot instead. `clear()` releases reusable state; `dispose()` releases it and ends the session. Compiling after disposal throws. Each result is an independent, serializable plain-data snapshot, so mutating an earlier result cannot corrupt cached blocks. Unchanged blocks may retain node IDs across edits. Their numbering can differ from a separate `compileLocal()` call; resolve metadata IDs within the same result.
|
|
106
108
|
|
|
107
109
|
With an unchanged declaration and binding context, only affected Markdown blocks are recompiled. Changes to declarations, component contents, options, permissions or host schemas trigger full compilation. Reference definitions, footnotes, navigation anchors, HTML, BOMs, code-delimiter changes and uncertain boundaries also use full compilation. Inputs producing diagnostics return the full compiler's diagnostics. Whole-document source and cumulative node budgets still apply, and only the current version is retained.
|
|
108
110
|
|
|
109
111
|
During consecutive component or declaration edits, the session retains the latest successful full result and defers building its block index. The next independent prose edit builds the index once and reuses the other blocks. Identical source can return an independent cached snapshot. Option changes, errors, `clear()` and `dispose()` discard deferred state.
|
|
110
112
|
|
|
111
|
-
`stats` reports the latest mode (`full`, `incremental`, or `
|
|
113
|
+
`stats` reports the latest mode (`full`, `incremental`, `cached`, or `streaming`), block counts, reuse counts, compiled characters and an optional invalidation reason. `cacheBuilds` counts block-index construction attempts during the call, including deferred recovery. Changed blocks compile under the unchanged declaration prefix; that work is included in `compiledCharacters`. Source comparison, range relocation and complete result snapshot assembly still scale with document size.
|
|
112
114
|
|
|
113
115
|
A document consisting of one flat list or table can also establish an incremental snapshot. Simple inline plans survive row edits; unchanged rows retain node IDs after semantic validation. Rows at unchanged offsets can share objects; shifted rows are cloned with updated UTF-16 ranges. Dynamic interpolation still uses the general parser. The cumulative `stats.parse.reusedRows` / `reusedItems` counters track inline plans, while `reusedRowNodes` / `reusedItemNodes` track final row subtrees separately.
|
|
114
116
|
|
|
@@ -116,6 +118,179 @@ When a result patch costs too much, the Worker can return a complete successful
|
|
|
116
118
|
|
|
117
119
|
`startLocalCompileWorker()`, the default `LocalCompileScheduler` fallback, and `LocalReactiveDocument` manage their own sessions. A custom `fallbackCompile` remains host-owned. `compileLocal()` remains the one-shot full compiler. See the [implementation and measurements](../development/performance-overview-en.md).
|
|
118
120
|
|
|
121
|
+
## Streaming source compilation
|
|
122
|
+
|
|
123
|
+
When a model, a collaborative replay or another producer grows a document in chunks, the host can submit the growing source to a compile session, scheduler, Worker or `LocalReactiveDocument` without waiting for the complete text. The engine accepts complete source snapshots and a phase marker only; token accumulation, model connections, conversation history, retries and cancellation stay with the host.
|
|
124
|
+
|
|
125
|
+
### Snapshots and phases
|
|
126
|
+
|
|
127
|
+
Every submission is the complete source so far. The host appends tokens to its own buffer and submits that buffer at a throttling window or structural boundary; reconnecting or replacing a damaged fragment also submits complete text. The phase is:
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
type LocalSourcePhase = 'streaming' | 'final';
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`streaming` means the current generation is unfinished; `final` means the source is complete. The phase may be supplied as `LocalCompileOptions.sourcePhase` or as an explicit session or scheduler argument. When both are omitted, compilation keeps the existing final semantics. Only these two values are accepted at runtime; sessions and `LocalCompileScheduler` return the same `local.options.invalid` failure for any other value instead of falling back to `final`. `sourcePhase` is not part of compile identity: it does not enter `localCompileOptionsKey` and does not change `strict`:
|
|
134
|
+
|
|
135
|
+
- `strict` still controls structural recovery of the final source only. `strict: false` is not a streaming mode; it recovers structures that remain damaged in the final source as literal text and reports warnings.
|
|
136
|
+
- `sourcePhase` reports whether the source is still being generated. A streaming snapshot degrades regions that cannot be interpreted safely to literal text while keeping node identity and source ranges for the completed prefix; an unfinished tail does not fail the whole preview. `strict: false` recovery records and warnings keep their existing rules and are not marked transient. `final` compiles the complete source under the selected strict mode.
|
|
137
|
+
- Unclosed tags, attribute quotes, component bodies, interpolations and formulas that are temporarily visible during streaming should not be rewritten into syntax repairs by the host; submit the completed source and compile it normally.
|
|
138
|
+
|
|
139
|
+
### Status and transient diagnostics
|
|
140
|
+
|
|
141
|
+
Results for calls that supply an explicit phase add `status`; streaming results may also carry `transientDiagnostics`. Calls that omit the phase keep the existing result shape without either field. `diagnostics` always contains non-transient diagnostics only:
|
|
142
|
+
|
|
143
|
+
| Source phase | `status` | Result meaning |
|
|
144
|
+
| --- | --- | --- |
|
|
145
|
+
| `streaming` | `partial` | `ok: true`; returns the document that can be shown safely. Issues that later source can repair go to `transientDiagnostics`, and regions that cannot be interpreted safely stay literal. |
|
|
146
|
+
| `streaming` + deterministic error | `failed` | `ok: false`; only deterministic errors remain in `diagnostics`: options, source type or length, syntax version, budgets, native-HTML/security policy, configuration, registry and capability failures, plus internal parse failures (`local.parse.*`). |
|
|
147
|
+
| `final` | `valid` | Complete compilation succeeded without structural recovery. |
|
|
148
|
+
| `final` + `strict: false` recovery | `recovered` | Returns the document, `recoveries` and one warning per recovery. |
|
|
149
|
+
| `final` | `failed` | Keeps the final compilation error rules; errors are not marked transient. |
|
|
150
|
+
|
|
151
|
+
Transient diagnostics keep their original `code`, `message` and source range and appear only in `transientDiagnostics`; loose-mode recovery warnings keep their final diagnostic rules and are never copied into the transient list. Consumers should use `status` and the explicit fields instead of inferring the phase from diagnostic text. A streaming success may temporarily contain unclosed structures or unevaluated expressions; on `final`, clear the host's transient state and use the final `diagnostics`. Deterministic errors still fail immediately and are not repairable placeholders.
|
|
152
|
+
|
|
153
|
+
### Sessions, schedulers and Workers
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
import { LocalCompileScheduler, createLocalCompileSession } from 'reactive-md';
|
|
157
|
+
|
|
158
|
+
const session = createLocalCompileSession();
|
|
159
|
+
const partial = session.compile(snapshot, options, 'streaming');
|
|
160
|
+
if (partial.status === 'partial') {
|
|
161
|
+
render(partial.document);
|
|
162
|
+
showTransient(partial.transientDiagnostics ?? []);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const final = session.compile(completedSource, options, 'final');
|
|
166
|
+
if (final.status === 'valid' || final.status === 'recovered') {
|
|
167
|
+
clearTransient();
|
|
168
|
+
render(final.document);
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
The explicit `phase` of `compile(source, options?, phase?)` and `compileShared(source, options?, phase?)` wins over `options.sourcePhase`. An explicit `final` uses the same final compilation path as an omitted phase and only adds `status`.
|
|
173
|
+
|
|
174
|
+
`LocalCompileScheduler.schedule(source, options?, hint?, phase?)` follows the same phases:
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
const scheduler = new LocalCompileScheduler({
|
|
178
|
+
createWorker: () => new Worker(new URL('./compile.worker.ts', import.meta.url), { type: 'module' }),
|
|
179
|
+
onResult: ({ result, sourcePhase }) => applySnapshot(result, sourcePhase),
|
|
180
|
+
delay: 150,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
scheduler.schedule(snapshot, options, undefined, 'streaming');
|
|
184
|
+
scheduler.schedule(completedSource, options, undefined, 'final');
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
- Streaming snapshots share the scheduler's throttle window (`LOCAL_COMPILE_DELAY_MS`, 150 ms by default) and only the latest queued snapshot is kept; no compilation runs per token.
|
|
188
|
+
- `final` bypasses the debounce and queues immediately. It may wait for an in-flight compile, but the older result cannot be delivered because the phase is part of job identity; monotonic revisions keep later responses from overwriting earlier accepted state.
|
|
189
|
+
- Revisions increase monotonically, and a stale Worker response cannot update the current preview. Streaming jobs never join the `patch-v1` baseline; scheduling a streaming snapshot invalidates the existing baseline, and only a final result can establish a patch baseline.
|
|
190
|
+
- Worker full requests and responses echo `sourcePhase` whenever a phase was declared; phase-less legacy jobs keep the historical wire shape and omit it. A phase on the options object is honored the same way. `LocalCompileOutcome.sourcePhase` reports the result phase. Main-thread fallback uses the same semantics; a custom `fallbackCompile` receives the phase as its third argument.
|
|
191
|
+
- Worker patch retries use `retryFull` with the codes `stale-base`, `options-mismatch`, `invalid-edit` or `phase-mismatch`; the scheduler falls back to one complete request instead of trusting a misaligned patch.
|
|
192
|
+
|
|
193
|
+
Streaming snapshots never read or populate the final block, deferred-index or shared-result caches; a final compile always starts from the existing incremental or full path. Lower-level parser caches keyed by exact source text may still serve both phases, because they are pure functions of that text and options. Streaming jobs may reuse the last result for an identical snapshot, but do not depend on block-level reuse across snapshots.
|
|
194
|
+
|
|
195
|
+
### React hosts
|
|
196
|
+
|
|
197
|
+
```tsx
|
|
198
|
+
import { useState } from 'react';
|
|
199
|
+
import type { Diagnostic, LocalSourcePhase } from 'reactive-md';
|
|
200
|
+
import { LocalReactiveDocument } from 'reactive-md/react';
|
|
201
|
+
|
|
202
|
+
export function StreamedArticle({ source, phase }: {
|
|
203
|
+
source: string;
|
|
204
|
+
phase: LocalSourcePhase;
|
|
205
|
+
}) {
|
|
206
|
+
const [transient, setTransient] = useState<Diagnostic[]>([]);
|
|
207
|
+
const [diagnostics, setDiagnostics] = useState<Diagnostic[]>([]);
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<>
|
|
211
|
+
<LocalReactiveDocument
|
|
212
|
+
source={source}
|
|
213
|
+
sourcePhase={phase}
|
|
214
|
+
onTransientDiagnostics={setTransient}
|
|
215
|
+
onDiagnostics={setDiagnostics}
|
|
216
|
+
/>
|
|
217
|
+
{transient.length > 0 && <p>{transient.length} provisional issues</p>}
|
|
218
|
+
{phase === 'final' && diagnostics.length > 0 && <p>Compilation failed; see diagnostics.</p>}
|
|
219
|
+
</>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
While streaming, `LocalReactiveDocument` renders with `mode="static"`: controls are read-only, network sessions are not established, and submissions, resets and other component side effects do not start. It still reuses the same compile session and runtime, and ordinary source updates retain compatible reader values and input drafts through the existing migration rules; a phase change does not rebuild the runtime or reset state. `final` restores the host's `mode`, `staticFirst` and full interaction. `onDiagnostics` carries non-transient diagnostics for the current snapshot; provisional issues never enter that channel. `onTransientDiagnostics` reports provisional issues only; if the host received any, finalization calls it once more with an empty array, and a later streaming snapshot without provisional issues retracts the same way. Deterministic failures still show the existing error notice.
|
|
225
|
+
|
|
226
|
+
The host must write each new snapshot to `source` and switch `sourcePhase` back to `final` when generation ends. On cancellation, document switches or unmount, stop submitting and discard old results; the engine validates revisions and phases only and does not manage generation rounds.
|
|
227
|
+
|
|
228
|
+
### Security boundaries
|
|
229
|
+
|
|
230
|
+
Streaming compilation does not change the document security model:
|
|
231
|
+
|
|
232
|
+
- The host owns model transport, credentials, retries and cancellation. ReactiveMD receives text snapshots only; it does not connect to model services or add network requests or code execution for streaming.
|
|
233
|
+
- `streaming` does not enable author HTML, scripts, CSS or other language capabilities; the host still grants them through explicit compile options. Deterministic security, configuration, version and budget errors remain final failures.
|
|
234
|
+
- During streaming, side-effecting components are deferred by static mode so incomplete content cannot submit, subscribe or perform other external actions; full interaction returns on `final`. Hosts still enforce their own permissions, CSP and untrusted-content policies.
|
|
235
|
+
|
|
236
|
+
### Performance expectations
|
|
237
|
+
|
|
238
|
+
Every accepted streaming snapshot compiles the complete source. Regions that cannot be interpreted safely are degraded to literal text through up to six stabilization passes, followed by one whole-source literal compile when damage persists; this path does not promise block-level incremental cost. The scheduler throttles and coalesces snapshots, and `final` queues immediately. Source still respects the 1,000,000-character limit and compile budgets; longer snapshots cost more per compile. Measure input-to-preview latency and compile volume on long documents, then tune the host's submission window accordingly; do not call a compile entry per token. The repository benchmark `npm run bench:streaming` reports, for a 15.5 KB / 227-block document in 64-character chunks, p50 ≈ 15–23 ms and p95 ≈ 33–53 ms per streaming snapshot across runs, exact final equality with one-shot compilation, and about 31 coalesced submissions under a 150 ms window. Treat these numbers as a baseline, not a cross-machine SLO.
|
|
239
|
+
|
|
240
|
+
## Strict parsing and local recovery
|
|
241
|
+
|
|
242
|
+
The `strict` option controls structural recovery in compiler factories, `compileLocal`, editing sessions and Workers. It defaults to `true`; omission and explicit `undefined` use the same default. Other non-boolean values are configuration errors.
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
import { createStandardCompiler } from 'reactive-md/compiler/standard';
|
|
246
|
+
|
|
247
|
+
const compiler = createStandardCompiler({ strict: false });
|
|
248
|
+
const result = compiler.compile(`<alert>
|
|
249
|
+
Unfinished content {{ missing }}.
|
|
250
|
+
|
|
251
|
+
## Next section
|
|
252
|
+
|
|
253
|
+
This **Markdown** still renders.
|
|
254
|
+
`);
|
|
255
|
+
|
|
256
|
+
if (result.status === 'recovered') {
|
|
257
|
+
console.log(result.diagnostics, result.recoveries, result.program.nodes);
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Loose mode keeps the damaged region as original source text. Components, expressions and declarations inside it stay inert. Compilation resumes at the next reliable boundary without rewriting the source.
|
|
262
|
+
|
|
263
|
+
Complete pairs take priority, including components whose bodies cross headings. A stray closing tag becomes literal text by itself. An outer closing tag can terminate an intact outer container while its unclosed inner fragment becomes text. An unmatched, lexically complete opener can recover before an ATX heading with a preceding blank line in the same Markdown container. Code, comments, raw HTML text and unfinished attribute quotes do not supply heading boundaries. Ordinary paragraphs, blank lines and sibling components are not synchronization points; without a reliable heading, recovery extends to the outer boundary or end of file.
|
|
264
|
+
|
|
265
|
+
Each recovery records `code`, `causeRange`, `affectedRange`, `action` and `boundary`. Ranges are half-open UTF-16 offsets into the original source. Records are sorted and deduplicated.
|
|
266
|
+
|
|
267
|
+
Each finalized recovery also produces at most one warning at `causeRange` with the same stable code: `local.recovery.unclosed`, `local.recovery.mismatch`, `local.recovery.stray-close`, `local.html.repair` or `local.html.literal`. The message states what was repaired or kept as literal text, so recovery is never silent. Line and column use the raw UTF-16 source. Warnings are not emitted per token. The diagnostics budget applies: when it is full, a warning may be omitted while the recovery record remains in `recoveries`. Recovery inserts no error block in the document body.
|
|
268
|
+
|
|
269
|
+
Binding errors, computation cycles, invalid initial values, required component attributes and component shape errors remain errors and fail compilation; recovery does not downgrade them. Configuration, version and budget errors also remain fatal. References outside a literal region to declarations removed inside it remain unknown bindings. A failed result can retain recoveries completed before the failure, their warnings and the separate error that caused failure.
|
|
270
|
+
|
|
271
|
+
### HTML and details
|
|
272
|
+
|
|
273
|
+
Loose mode repairs omitted or mismatched HTML tags within an isolated fragment using parse5. The existing element, attribute and URL policies still apply; loose mode grants no script, CSS or extended HTML capability. A repaired fragment yields one `local.html.repair` warning. A mixed RMD fragment becomes literal text with one `local.html.literal` warning when ownership and source ranges cannot be preserved. Synthetic nodes carry `synthetic` and `syntheticBoundary` metadata.
|
|
274
|
+
|
|
275
|
+
Both modes support a details element without blank lines:
|
|
276
|
+
|
|
277
|
+
```html
|
|
278
|
+
<details>
|
|
279
|
+
<summary>1145</summary>
|
|
280
|
+
1145
|
|
281
|
+
</details>
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
It renders as a single disclosure in an accordion with no group title. The trigger is `1145`, the panel contains `1145`, and it starts collapsed; click, Enter and Space toggle it. Boolean `open` starts it expanded, and static output exposes the body. Rich summaries and nested details retain their content.
|
|
285
|
+
|
|
286
|
+
### Results and hosts
|
|
287
|
+
|
|
288
|
+
Factory success results include `status: 'valid' | 'recovered'`, a deeply frozen `program`, diagnostics, recoveries and optional-check coverage in `checks`. A `valid` success has no recovery warning. A `recovered` success includes the program and one warning per recovery. Failures use `status: 'failed'` and contain no program; they may retain recoveries completed before the failure and their warnings. Unrecoverable semantic, type, binding, options, version and budget errors remain errors. The `ok` and `document` aliases remain available; `document` is a separate plain-data copy.
|
|
289
|
+
|
|
290
|
+
`compileLocal` keeps its existing result type and adds `recoveries` only when present. Strict results keep their existing field shape. Export options preserve the selected mode so standalone replay compiles the same source with that mode.
|
|
291
|
+
|
|
292
|
+
Loose editing sessions use the full reference path to avoid reusing blocks across recovery boundaries. Strict mode keeps its existing optimizations. Configuration identity includes strict mode and recovery strategy version 2. Demo and editor defaults remain strict.
|
|
293
|
+
|
|
119
294
|
## Core API
|
|
120
295
|
|
|
121
296
|
```ts
|
|
@@ -254,13 +429,13 @@ Migration changes only the metadata directive, preserves body bytes, BOM and CRL
|
|
|
254
429
|
|
|
255
430
|
### `createLocalRuntime(document: LocalDocument, options?: LocalRuntimeOptions)`
|
|
256
431
|
|
|
257
|
-
Named read-only values are described by `LocalComputation` in the optional `document.computations` record. `bindings` and `initialState` remain writable controls; `snapshot().state` also includes successful calculated values for its revision. Read a named value with `evaluate(name)` to preserve expression errors; failed values are absent from snapshots. See [calculation and error semantics](../reference/
|
|
432
|
+
Named read-only values are described by `LocalComputation` in the optional `document.computations` record. `bindings` and `initialState` remain writable controls; `snapshot().state` also includes successful calculated values for its revision. Read a named value with `evaluate(name)` to preserve expression errors; failed values are absent from snapshots. See [calculation and error semantics](../reference/local-interaction-syntax-en.md).
|
|
258
433
|
|
|
259
434
|
`options.externalValues` seeds declared `<external>` values; invalid entries are treated as unavailable and can be corrected through `setExternalValues`. The runtime creates an independent in-memory instance. Throws if `document` is not a local mode document, if initial values exceed budgets, or if the structure is invalid. Each instance has independent state; the runtime never stores or transmits state by itself.
|
|
260
435
|
|
|
261
436
|
### `LocalRuntime`
|
|
262
437
|
|
|
263
|
-
`validate(): Diagnostic[]` reads advisory cross-field failures for the current revision. Dynamic `min`/`max`/`required` failures are enforced on writes and displayed on the control; `validate()` keeps its existing meaning. It preserves editability and returns copies of cached diagnostics. `document.validations?: LocalValidation[]` holds the serializable rule declarations. Numeric collections add `number[]` to `LocalValue` and `number-array` to `LocalValueKind`; existing writable selection controls keep string arrays. See [constraints and collections](../reference/
|
|
438
|
+
`validate(): Diagnostic[]` reads advisory cross-field failures for the current revision. Dynamic `min`/`max`/`required` failures are enforced on writes and displayed on the control; `validate()` keeps its existing meaning. It preserves editability and returns copies of cached diagnostics. `document.validations?: LocalValidation[]` holds the serializable rule declarations. Numeric collections add `number[]` to `LocalValue` and `number-array` to `LocalValueKind`; existing writable selection controls keep string arrays. See [constraints and collections](../reference/local-interaction-syntax-en.md).
|
|
264
439
|
|
|
265
440
|
| Member | Parameters | Returns | Behavior |
|
|
266
441
|
| --- | --- | --- | --- |
|
|
@@ -323,7 +498,7 @@ The lower-level `createLocalStateFile`, `parseLocalState`, `resolveLocalState`,
|
|
|
323
498
|
|
|
324
499
|
### Keeping values when source changes
|
|
325
500
|
|
|
326
|
-
`LocalReactiveDocument`
|
|
501
|
+
`LocalReactiveDocument` reuses its runtime and migrates compatible values on ordinary source updates. Hosts that manage the runtime themselves or switch between independent documents can plan the migration explicitly:
|
|
327
502
|
|
|
328
503
|
```ts
|
|
329
504
|
import {
|
|
@@ -382,9 +557,9 @@ const scheduler = new LocalCompileScheduler({
|
|
|
382
557
|
scheduler.schedule(source);
|
|
383
558
|
```
|
|
384
559
|
|
|
385
|
-
`LocalCompileScheduler` coalesces edits for `LOCAL_COMPILE_DELAY_MS` (150 ms; override with `delay`), keeps one compile in flight plus only the latest queued source, and discards results that a newer edit has superseded. When no worker is available, or after a worker error, it compiles on the main thread with `fallbackCompile
|
|
560
|
+
`LocalCompileScheduler` coalesces edits for `LOCAL_COMPILE_DELAY_MS` (150 ms; override with `delay`), keeps one compile in flight plus only the latest queued source, and discards results that a newer edit has superseded. When no worker is available, or after a worker error, it compiles on the main thread with `fallbackCompile`; the default is an internal session-backed compile with the same results as `compileLocal`, without cross-call reuse. A worker failure switches permanently to this fallback and reports it through `onModeChange`. Failures thrown by the worker or during fallback compilation use the `local.worker.compile` diagnostic code. Use `schedule(source, options?, hint?, phase?)` for streaming snapshots; `final` bypasses the debounce. See [Streaming source compilation](#streaming-source-compilation).
|
|
386
561
|
|
|
387
|
-
`onResult` receives `LocalCompileOutcome` (`source`, `result`, `duration`, `mode`), `onPendingChange` reports whether work is queued or in flight, and `dispose()` stops the timer, terminates the worker and suppresses later callbacks.
|
|
562
|
+
`onResult` receives `LocalCompileOutcome` (`source`, `result`, `duration`, `mode`, `sourcePhase`), `onPendingChange` reports whether work is queued or in flight, and `dispose()` stops the timer, terminates the worker and suppresses later callbacks.
|
|
388
563
|
|
|
389
564
|
### Other core exports
|
|
390
565
|
|
|
@@ -397,7 +572,8 @@ scheduler.schedule(source);
|
|
|
397
572
|
- Source revisions: `inspectLocalSourceVersion`, `checkLocalUpgrade` and `migrateLocalSource`; `LocalUpgradeOptions` configures the source revision and semantic-change allowance.
|
|
398
573
|
- Retention: `planLocalStateRetention` and `applyLocalStateRetention`.
|
|
399
574
|
- Background compilation: `LocalCompileScheduler`, `LOCAL_COMPILE_DELAY_MS` and `startLocalCompileWorker`.
|
|
400
|
-
-
|
|
575
|
+
- Streaming phases: `LocalSourcePhase`, `LocalCompileStatus`; the `status` and `transientDiagnostics` fields on explicit-phase results.
|
|
576
|
+
- Type exports: `Diagnostic`, `SourceRange`, `LocalValue`, `LocalValueKind`, `LocalNode`, `LocalBinding`, `LocalComputation`, `LocalValidation`, `LocalDocument`, `LocalCompileLimits`, `LocalCompileOptions`, `LocalCompileResult`, `LocalSourcePhase`, `LocalCompileStatus`, `LocalHostPropKind`, `LocalHostPropSchema`, `LocalHostComponentForm`, `LocalHostBindingSchema`, `LocalHostComponentSchema`, `LocalExternal`, `LocalDynamicConstraint`, `LocalDynamicConstraints`, `LocalRuntimeOptions`, `LocalUpgradeOptions`, `LocalRuntime`, `LocalSnapshot`, `LocalStateFile`, `LocalStateGenerator`, `LocalStateParseResult`, `LocalStateResolution`, `LocalRetainedState`, `LocalStateRetentionReason`, `LocalStateRetentionDrop`, `LocalStateRetentionInput`, `LocalStateRetentionResult`, `LocalCompileWorker`, `LocalCompileWorkerScope`, `LocalCompileRequest`, `LocalCompileResponse`, `LocalCompileOutcome`, `LocalCompileMode`, `LocalCompileSchedulerOptions`.
|
|
401
577
|
|
|
402
578
|
`compileExpression`, `compileLatex` and `samplePlot` are lower-level utilities with the same stability level as the core API; usually only `compileLocal` and `createLocalRuntime` are needed.
|
|
403
579
|
|
|
@@ -409,11 +585,11 @@ The fields and stability levels of `Diagnostic` are described in the diagnostics
|
|
|
409
585
|
|
|
410
586
|
## State, instances and cleanup
|
|
411
587
|
|
|
412
|
-
- `LocalReactiveDocument` recompiles and
|
|
588
|
+
- `LocalReactiveDocument` recompiles on `source` changes and adopts the new document in its existing runtime, migrating compatible values; host option changes that affect compilation semantics or an incompatible document create a new runtime. React StrictMode is supported.
|
|
413
589
|
- When managing the lifecycle yourself, render with `<LocalDocumentView document={result.document} runtime={runtime} />` and call `runtime.dispose()` on unmount.
|
|
414
590
|
- `subscribe()` returns an unsubscribe function. `dispose()` clears remaining subscriptions; calling other runtime methods afterwards throws.
|
|
415
591
|
- `snapshot()` returns the same object until state changes, which is useful for external store subscriptions. `reset(panelNode)` commits once for the panel subtree, and subscribers receive one notification; hidden controls inside the panel are also within reset scope.
|
|
416
|
-
- Document state lives only in memory; the runtime never writes storage, cookies or the network. Refreshing
|
|
592
|
+
- Document state lives only in memory; the runtime never writes storage, cookies or the network. Refreshing or remounting starts from initial values; a source change reuses the runtime and migrates values that still satisfy the new document's contracts. Persistence is an explicit host action through `exportLocalState` and `importLocalState`; the [retention helpers](#keeping-values-when-source-changes) serve hosts that manage the runtime themselves or switch between independent documents.
|
|
417
593
|
- Hidden regions keep parameters, tab selection and checklist state; timers in hidden regions pause and stay paused when shown again until the reader starts them. Disposing an instance releases timers and subscriptions.
|
|
418
594
|
|
|
419
595
|
## Image and link policy
|
|
@@ -463,7 +639,7 @@ A single string is limited to 100,000 characters, an array to 10,000 items, and
|
|
|
463
639
|
|
|
464
640
|
A single document source is limited to 1,000,000 characters. There are at most 100 diagnostics, and a single message is at most 2,000 characters.
|
|
465
641
|
|
|
466
|
-
Each plot component has at most 16 curves; the whole document requests at most 20,000 curve sample points, including hidden regions. Plotting computation is also limited by a shared execution budget of 2,000,000 steps. A document has at most 100 validation rules. Generated `data-table` rows, columns and text have per-table and whole-document budgets described in [
|
|
642
|
+
Each plot component has at most 16 curves; the whole document requests at most 20,000 curve sample points, including hidden regions. Plotting computation is also limited by a shared execution budget of 2,000,000 steps. A document has at most 100 validation rules. Generated `data-table` rows, columns and text have per-table and whole-document budgets described in the [syntax specification](../reference/local-interaction-syntax-en.md). Documents over a limit receive diagnostics; expression and math rendering also have their own depth and token budgets.
|
|
467
643
|
|
|
468
644
|
These limits bound the work for a single document; they do not replace host control over request size, concurrency and execution time. See the [security policy](../../SECURITY.md) for the full threat boundary.
|
|
469
645
|
|
|
@@ -476,11 +652,11 @@ These limits bound the work for a single document; they do not replace host cont
|
|
|
476
652
|
|
|
477
653
|
## Features not provided
|
|
478
654
|
|
|
479
|
-
|
|
655
|
+
ReactiveMD supports P0 HTML and independent author capabilities. See [HTML compatibility](../reference/html-compatibility-en.md). Automatic state persistence, unrestricted network/storage calls, Vue, React 18 and CommonJS remain outside the current API. Hosts declare read-only values and invoke state export/import explicitly.
|
|
480
656
|
|
|
481
|
-
The source [extension SDK](extension-sdk-en.md) provides custom component and theme package registration
|
|
657
|
+
The source [extension SDK](extension-sdk-en.md) provides custom component and theme package registration since `reactive-md@0.8.0`; follow the [component plugin development guide](../development/component-development-en.md). On ordinary source edits, `LocalReactiveDocument` tries to adopt the new document and retain compatible bindings. Use a new React `key` for independent documents, or manage documents and runtimes in the host.
|
|
482
658
|
|
|
483
659
|
|
|
484
|
-
See [
|
|
660
|
+
See the [syntax specification](../reference/local-interaction-syntax-en.md) for the component tags, color options and slot state.
|
|
485
661
|
|
|
486
662
|
0.5.3 adds compile-option-aware authoring and explicit screen/print styles. See [0.5.3 host integration](../releases/release-0.5.3-en.md). 0.6.0 makes `compileLocal` return plain data that can cross a React Server Components boundary; see the [0.6.0 release notes](../releases/release-0.6.0-en.md).
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# 宿主网络通道
|
|
2
|
+
|
|
3
|
+
[English](network-host-en.md) · **中文**
|
|
4
|
+
|
|
5
|
+
ReactiveMD 文档按名称使用通道。宿主决定开放哪些通道,并配置端点、凭据、校验和传输方式。
|
|
6
|
+
|
|
7
|
+
## 开放通道
|
|
8
|
+
|
|
9
|
+
将 `NetworkConfig` 传给 `LocalReactiveDocument`。如果文档使用 `<submit-button>`,还需在 React 配置中安装可选的网络组件包。
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { createReactHost, LocalReactiveDocument } from 'reactive-md/react/minimal';
|
|
13
|
+
import { minimalReactPresetPackage } from 'reactive-md/presets/minimal/react';
|
|
14
|
+
import networkPreset from 'reactive-md/plugins/network';
|
|
15
|
+
import type { Json, NetworkConfig } from 'reactive-md/runtime';
|
|
16
|
+
import { httpSubmit, sseStream } from 'reactive-md/runtime/browser';
|
|
17
|
+
|
|
18
|
+
const host = createReactHost({ presets: [minimalReactPresetPackage, networkPreset] });
|
|
19
|
+
const reactConfig = host.reactConfig;
|
|
20
|
+
const source = `
|
|
21
|
+
<external name="yesCount" type="number">
|
|
22
|
+
<select bind="choice" label="Choice" initial="yes">
|
|
23
|
+
<option value="yes">Yes</option>
|
|
24
|
+
<option value="no">No</option>
|
|
25
|
+
|
|
26
|
+
<submit-button channel="answers" fields="choice" label="提交答案">
|
|
27
|
+
|
|
28
|
+
当前赞成票:{{ yesCount }}
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
function isCountSnapshot(value: Json): value is { readonly yes: number; readonly no: number } {
|
|
32
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
33
|
+
&& 'yes' in value && typeof value.yes === 'number'
|
|
34
|
+
&& 'no' in value && typeof value.no === 'number';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const network: NetworkConfig = {
|
|
38
|
+
channels: {
|
|
39
|
+
answers: {
|
|
40
|
+
submit: httpSubmit({
|
|
41
|
+
endpoint: '/api/answers',
|
|
42
|
+
validate: payload => typeof payload.choice === 'string'
|
|
43
|
+
|| '提交前请选择答案。',
|
|
44
|
+
}),
|
|
45
|
+
},
|
|
46
|
+
results: {
|
|
47
|
+
subscribe: sseStream({
|
|
48
|
+
endpoint: '/api/results/events',
|
|
49
|
+
validate: isCountSnapshot,
|
|
50
|
+
}),
|
|
51
|
+
mapExternalValues: value => isCountSnapshot(value)
|
|
52
|
+
? { yesCount: value.yes }
|
|
53
|
+
: undefined,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
function Survey() {
|
|
59
|
+
return <LocalReactiveDocument source={source} network={network} reactConfig={reactConfig} />;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
宿主的 `reactConfig` 已包含 `<submit-button>` 所需的网络预设。自定义组件也可以从 `context.services.network` 获取同一服务,并对已知通道调用 `supports`、`submit` 或 `subscribe`。
|
|
64
|
+
|
|
65
|
+
`<submit-button>` 在激活时读取所列绑定的快照,并发送一次。默认 HTTP 适配器会把操作幂等键放入 `Idempotency-Key` 请求头。需要避免重试重复写入时,接收服务应执行幂等校验。
|
|
66
|
+
|
|
67
|
+
## 订阅与外部变量
|
|
68
|
+
|
|
69
|
+
同一通道的文档监听器共享一条宿主连接。隐藏或卸载监听器会退订。最后一个监听器离开时,传输连接关闭。通道的 `mapExternalValues` 回调可以把经过校验的订阅数据映射为已声明的 `<external>` 值。运行时会校验并一次性写入每次映射结果。加载文档时由宿主提供外部变量,独立于文档状态文件。
|
|
70
|
+
|
|
71
|
+
核心网络契约接受普通 JSON,校验输入和输出,默认编码负载上限为 64 KiB。需要更紧的 schema 预算时,可为通道设置较小的 `maxBytes`。提交与订阅适配器会收到操作和通道生命周期的 abort signal。监听器抛出的异常会被隔离,也可以通过 `onListenerError` 上报。
|
|
72
|
+
|
|
73
|
+
`reactive-md/runtime/browser` 提供 `httpSubmit`、`sseStream`、`webSocketChannel` 和 `webRtcChannel`。宿主也可以为其他传输自行实现 `SubmitAdapter` 与 `SubscribeAdapter`。认证、授权、端点选择和服务端校验应由宿主或后端负责。
|
|
74
|
+
|
|
75
|
+
静态渲染和静态导出使用不可用的网络服务。只在可信的实时宿主中传入 `NetworkConfig`。[网络问卷示例](../../examples/network-survey/README.md)展示内存与 HTTP/SSE 适配器、生命周期共享、响应校验、幂等重试、WebSocket 和 WebRTC。
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Host network channels
|
|
2
|
+
|
|
3
|
+
**English** · [中文](network-host-ch.md)
|
|
4
|
+
|
|
5
|
+
ReactiveMD documents request named channels. The host chooses which channels to open and configures their endpoints, credentials, validation and transport.
|
|
6
|
+
|
|
7
|
+
## Enable a channel
|
|
8
|
+
|
|
9
|
+
Pass a `NetworkConfig` to `LocalReactiveDocument`. Install the optional network component package in the React configuration when the document uses `<submit-button>`.
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { createReactHost, LocalReactiveDocument } from 'reactive-md/react/minimal';
|
|
13
|
+
import { minimalReactPresetPackage } from 'reactive-md/presets/minimal/react';
|
|
14
|
+
import networkPreset from 'reactive-md/plugins/network';
|
|
15
|
+
import type { Json, NetworkConfig } from 'reactive-md/runtime';
|
|
16
|
+
import { httpSubmit, sseStream } from 'reactive-md/runtime/browser';
|
|
17
|
+
|
|
18
|
+
const host = createReactHost({ presets: [minimalReactPresetPackage, networkPreset] });
|
|
19
|
+
const reactConfig = host.reactConfig;
|
|
20
|
+
const source = `
|
|
21
|
+
<external name="yesCount" type="number">
|
|
22
|
+
<select bind="choice" label="Choice" initial="yes">
|
|
23
|
+
<option value="yes">Yes</option>
|
|
24
|
+
<option value="no">No</option>
|
|
25
|
+
|
|
26
|
+
<submit-button channel="answers" fields="choice" label="Send answer">
|
|
27
|
+
|
|
28
|
+
Current yes votes: {{ yesCount }}
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
function isCountSnapshot(value: Json): value is { readonly yes: number; readonly no: number } {
|
|
32
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
33
|
+
&& 'yes' in value && typeof value.yes === 'number'
|
|
34
|
+
&& 'no' in value && typeof value.no === 'number';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const network: NetworkConfig = {
|
|
38
|
+
channels: {
|
|
39
|
+
answers: {
|
|
40
|
+
submit: httpSubmit({
|
|
41
|
+
endpoint: '/api/answers',
|
|
42
|
+
validate: payload => typeof payload.choice === 'string'
|
|
43
|
+
|| 'Choose an answer before submitting.',
|
|
44
|
+
}),
|
|
45
|
+
},
|
|
46
|
+
results: {
|
|
47
|
+
subscribe: sseStream({
|
|
48
|
+
endpoint: '/api/results/events',
|
|
49
|
+
validate: isCountSnapshot,
|
|
50
|
+
}),
|
|
51
|
+
mapExternalValues: value => isCountSnapshot(value)
|
|
52
|
+
? { yesCount: value.yes }
|
|
53
|
+
: undefined,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
function Survey() {
|
|
59
|
+
return <LocalReactiveDocument source={source} network={network} reactConfig={reactConfig} />;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The host's `reactConfig` includes the network preset required by `<submit-button>`. A custom component can access the same service at `context.services.network` and call `supports`, `submit` or `subscribe` for a known channel.
|
|
64
|
+
|
|
65
|
+
`<submit-button>` snapshots the listed bindings at activation and sends that snapshot once. The default HTTP adapter includes the operation's idempotency key in the `Idempotency-Key` header. The host should enforce idempotency on the receiving service when retries must not repeat a write.
|
|
66
|
+
|
|
67
|
+
## Subscriptions and external values
|
|
68
|
+
|
|
69
|
+
Document listeners on the same channel share a host connection. Hiding or unmounting a listener removes its subscription. The transport closes when the last listener leaves. A channel's `mapExternalValues` callback maps validated data to declared `<external>` values. The runtime validates and applies each mapped update as one write. The host supplies external values on load, independently of document state files.
|
|
70
|
+
|
|
71
|
+
The core network contract accepts plain JSON, validates input and output, and defaults to a 64 KiB encoded payload budget. Configure a smaller `maxBytes` for a channel when its schema allows it. Submit and subscribe adapters receive abort signals for operation and channel lifetimes. Listener exceptions are isolated and can be reported through `onListenerError`.
|
|
72
|
+
|
|
73
|
+
`reactive-md/runtime/browser` provides `httpSubmit`, `sseStream`, `webSocketChannel` and `webRtcChannel`. Hosts can also implement `SubmitAdapter` and `SubscribeAdapter` for another transport. Keep authentication, authorization, endpoint selection and server-side validation in the host/backend.
|
|
74
|
+
|
|
75
|
+
Static rendering and static exports use an unavailable network service. Supply a `NetworkConfig` only in a trusted live host. The [network survey example](../../examples/network-survey/README.md) demonstrates in-memory and HTTP/SSE adapters, lifecycle sharing, response validation, idempotent retries, WebSocket and WebRTC.
|