plitejs 0.0.1 → 54.0.0-beta.2
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/LICENSE +4 -1
- package/README.md +83 -0
- package/dist/annotations/index.d.ts +2 -0
- package/dist/annotations/index.js +2 -0
- package/dist/annotations/store.d.ts +50 -0
- package/dist/annotations/store.js +244 -0
- package/dist/authored/authored.d.ts +116 -0
- package/dist/authored/authored.js +1271 -0
- package/dist/authored/changes.js +365 -0
- package/dist/authored/comparison.d.ts +41 -0
- package/dist/authored/comparison.js +270 -0
- package/dist/authored/decision-window.js +42 -0
- package/dist/authored/decision.js +306 -0
- package/dist/authored/facts/admission.js +388 -0
- package/dist/authored/facts/compact.d.ts +2 -0
- package/dist/authored/facts/compact.js +91 -0
- package/dist/authored/facts/dependencies.d.ts +5 -0
- package/dist/authored/facts/dependencies.js +66 -0
- package/dist/authored/facts/editing.js +12 -0
- package/dist/authored/facts/facts.d.ts +8 -0
- package/dist/authored/facts/facts.js +535 -0
- package/dist/authored/facts/records.d.ts +28 -0
- package/dist/authored/facts/records.js +226 -0
- package/dist/authored/facts/settle.js +529 -0
- package/dist/authored/format.d.ts +34 -0
- package/dist/authored/format.js +175 -0
- package/dist/authored/index.d.ts +9 -0
- package/dist/authored/index.js +5 -0
- package/dist/authored/ledger/book.js +809 -0
- package/dist/authored/ledger/cards.js +223 -0
- package/dist/authored/ledger/ledger.js +830 -0
- package/dist/authored/ledger/level.js +1081 -0
- package/dist/authored/ledger/links.js +20 -0
- package/dist/authored/ledger/pairs.js +334 -0
- package/dist/authored/ledger/places.js +524 -0
- package/dist/authored/ledger/preview-lens.js +252 -0
- package/dist/authored/ledger/projection.js +163 -0
- package/dist/authored/ledger/roots.js +11 -0
- package/dist/authored/ledger/runs.js +480 -0
- package/dist/authored/ledger/slots.js +330 -0
- package/dist/authored/ledger/work.js +66 -0
- package/dist/authored/refusal.d.ts +33 -0
- package/dist/authored/refusal.js +188 -0
- package/dist/authored/resolve-schema.js +62 -0
- package/dist/authored/tree/alignment.js +456 -0
- package/dist/authored/tree/carried.js +205 -0
- package/dist/authored/tree/command-values.js +344 -0
- package/dist/authored/tree/cuts.js +320 -0
- package/dist/authored/tree/grid.js +49 -0
- package/dist/authored/tree/halves.js +120 -0
- package/dist/authored/tree/holders.js +345 -0
- package/dist/authored/tree/holds.js +135 -0
- package/dist/authored/tree/layers.d.ts +49 -0
- package/dist/authored/tree/layers.js +354 -0
- package/dist/authored/tree/marks.d.ts +136 -0
- package/dist/authored/tree/marks.js +263 -0
- package/dist/authored/tree/proposed.js +212 -0
- package/dist/authored/tree/readiness.js +545 -0
- package/dist/authored/tree/record-completion.js +423 -0
- package/dist/authored/tree/record.js +2908 -0
- package/dist/authored/tree/reserves.js +449 -0
- package/dist/authored/tree/resolve.d.ts +9 -0
- package/dist/authored/tree/resolve.js +1860 -0
- package/dist/authored/tree/shown.js +153 -0
- package/dist/authored/tree/spare-lines.js +119 -0
- package/dist/authored/tree/spares.js +61 -0
- package/dist/authored/types.d.ts +177 -0
- package/dist/core/anchor-state.d.ts +15 -0
- package/dist/core/anchor-state.js +792 -0
- package/dist/core/anchor.d.ts +34 -0
- package/dist/core/anchor.js +843 -0
- package/dist/core/authored-document-capability.d.ts +106 -0
- package/dist/core/authored-document-capability.js +6 -0
- package/dist/core/authored-runtime.d.ts +10 -0
- package/dist/core/authored-runtime.js +67 -0
- package/dist/core/authored-veto.d.ts +30 -0
- package/dist/core/authored-veto.js +6 -0
- package/dist/core/change/builder.d.ts +546 -0
- package/dist/core/change/builder.js +1120 -0
- package/dist/core/change/carried-projection.js +1518 -0
- package/dist/core/change/carried-run.d.ts +26 -0
- package/dist/core/change/carried-run.js +251 -0
- package/dist/core/change/carry-program.js +537 -0
- package/dist/core/change/classification.d.ts +22 -0
- package/dist/core/change/classification.js +205 -0
- package/dist/core/change/cross-rule.js +238 -0
- package/dist/core/change/cross.js +577 -0
- package/dist/core/change/document-change.d.ts +137 -0
- package/dist/core/change/document-change.js +872 -0
- package/dist/core/change/document-index.d.ts +117 -0
- package/dist/core/change/document-index.js +542 -0
- package/dist/core/change/draft-facts.js +323 -0
- package/dist/core/change/enclosure.d.ts +12 -0
- package/dist/core/change/enclosure.js +272 -0
- package/dist/core/change/join.js +751 -0
- package/dist/core/change/json.d.ts +4 -0
- package/dist/core/change/json.js +26 -0
- package/dist/core/change/lazy-root.d.ts +1 -0
- package/dist/core/change/lazy-root.js +73 -0
- package/dist/core/change/lineage.d.ts +49 -0
- package/dist/core/change/lineage.js +390 -0
- package/dist/core/change/mapping.d.ts +31 -0
- package/dist/core/change/mapping.js +186 -0
- package/dist/core/change/new-letters.d.ts +14 -0
- package/dist/core/change/new-letters.js +139 -0
- package/dist/core/change/range-association.js +10 -0
- package/dist/core/change/read-back.d.ts +7 -0
- package/dist/core/change/read-back.js +7 -0
- package/dist/core/change/record.d.ts +59 -0
- package/dist/core/change/record.js +346 -0
- package/dist/core/change/retraction.js +97 -0
- package/dist/core/change/root-change.d.ts +180 -0
- package/dist/core/change/root-change.js +3544 -0
- package/dist/core/change/slice-facts.js +89 -0
- package/dist/core/change/text-splices.js +98 -0
- package/dist/core/change/tokens.d.ts +97 -0
- package/dist/core/change/tokens.js +449 -0
- package/dist/core/change/transform.d.ts +36 -0
- package/dist/core/change/transform.js +97 -0
- package/dist/core/change/wrap-fidelity.js +295 -0
- package/dist/core/change-events.js +223 -0
- package/dist/core/clone.js +28 -0
- package/dist/core/command-definition.d.ts +25 -0
- package/dist/core/command-definition.js +48 -0
- package/dist/core/command-document.d.ts +4 -0
- package/dist/core/command-document.js +20 -0
- package/dist/core/command-frame.js +628 -0
- package/dist/core/command-registry.d.ts +36 -0
- package/dist/core/command-registry.js +283 -0
- package/dist/core/commit-publication.js +40 -0
- package/dist/core/commit.d.ts +26 -0
- package/dist/core/commit.js +686 -0
- package/dist/core/composition-stamp.d.ts +14 -0
- package/dist/core/composition-stamp.js +79 -0
- package/dist/core/content-completion.d.ts +4 -0
- package/dist/core/content-completion.js +343 -0
- package/dist/core/content-landing.js +124 -0
- package/dist/core/content-slice-roots.js +36 -0
- package/dist/core/content-slice.d.ts +38 -0
- package/dist/core/content-slice.js +253 -0
- package/dist/core/content.js +18 -0
- package/dist/core/correction.js +25 -0
- package/dist/core/default-storage.js +53 -0
- package/dist/core/document-admission.d.ts +4 -0
- package/dist/core/document-admission.js +64 -0
- package/dist/core/document-change.d.ts +3 -0
- package/dist/core/document-recorder.d.ts +6 -0
- package/dist/core/document-recorder.js +67 -0
- package/dist/core/document-shape.d.ts +68 -0
- package/dist/core/document-shape.js +173 -0
- package/dist/core/document-view-read.d.ts +16 -0
- package/dist/core/document-view-read.js +36 -0
- package/dist/core/draft-track.d.ts +3 -0
- package/dist/core/draft-track.js +90 -0
- package/dist/core/editor-commands.d.ts +99 -0
- package/dist/core/editor-commands.js +505 -0
- package/dist/core/editor-lifecycle-api.d.ts +8 -0
- package/dist/core/editor-lifecycle-api.js +219 -0
- package/dist/core/editor-lifetime.js +12 -0
- package/dist/core/editor-owner.d.ts +24 -0
- package/dist/core/editor-owner.js +78 -0
- package/dist/core/editor-read-execution.d.ts +6 -0
- package/dist/core/editor-read-execution.js +64 -0
- package/dist/core/editor-read-runtime.js +176 -0
- package/dist/core/editor-reads.d.ts +128 -0
- package/dist/core/editor-reads.js +63 -0
- package/dist/core/editor-runtime.d.ts +112 -0
- package/dist/core/editor-runtime.js +20 -0
- package/dist/core/editor-schema.d.ts +314 -0
- package/dist/core/editor-schema.js +2295 -0
- package/dist/core/editor-view-lifetime.js +23 -0
- package/dist/core/element-owned-root-index.d.ts +4 -0
- package/dist/core/element-owned-root-index.js +353 -0
- package/dist/core/get-content-slice.js +118 -0
- package/dist/core/get-fragment.js +22 -0
- package/dist/core/identity-owner.js +697 -0
- package/dist/core/import-content-slice.js +26 -0
- package/dist/core/initial-value.js +87 -0
- package/dist/core/insert-limit.js +81 -0
- package/dist/core/is-empty-element.js +20 -0
- package/dist/core/json-fingerprint.js +16 -0
- package/dist/core/landing.d.ts +11 -0
- package/dist/core/landing.js +279 -0
- package/dist/core/lifecycle-error.d.ts +11 -0
- package/dist/core/lifecycle-error.js +68 -0
- package/dist/core/listener-state.d.ts +1 -0
- package/dist/core/listener-state.js +59 -0
- package/dist/core/measured-sequence.d.ts +43 -0
- package/dist/core/measured-sequence.js +404 -0
- package/dist/core/missing-reference.js +15 -0
- package/dist/core/native-grouping-input.js +8 -0
- package/dist/core/node-property-mutation.js +10 -0
- package/dist/core/node-selection.js +85 -0
- package/dist/core/node-write-veto.d.ts +37 -0
- package/dist/core/node-write-veto.js +17 -0
- package/dist/core/persisted-document.d.ts +6 -0
- package/dist/core/persisted-document.js +39 -0
- package/dist/core/persistent-map.js +139 -0
- package/dist/core/plain-text.d.ts +32 -0
- package/dist/core/plain-text.js +92 -0
- package/dist/core/plugin-dispatch.d.ts +21 -0
- package/dist/core/plugin-dispatch.js +166 -0
- package/dist/core/plugin-point.d.ts +6 -0
- package/dist/core/plugin-point.js +21 -0
- package/dist/core/plugin-registry.d.ts +78 -0
- package/dist/core/plugin-registry.js +485 -0
- package/dist/core/plugin-slot.d.ts +23 -0
- package/dist/core/plugin-slot.js +30 -0
- package/dist/core/plugin.d.ts +125 -0
- package/dist/core/plugin.js +1485 -0
- package/dist/core/prefix-occupant-join.js +52 -0
- package/dist/core/profiling.js +18 -0
- package/dist/core/property-validity.d.ts +14 -0
- package/dist/core/property-validity.js +65 -0
- package/dist/core/public-root.d.ts +10 -0
- package/dist/core/public-root.js +50 -0
- package/dist/core/public-state.d.ts +191 -0
- package/dist/core/public-state.js +6772 -0
- package/dist/core/read-definition.js +22 -0
- package/dist/core/read-registry.js +127 -0
- package/dist/core/record-store.d.ts +12 -0
- package/dist/core/record-store.js +297 -0
- package/dist/core/refusal.d.ts +1 -0
- package/dist/core/refusal.js +40 -0
- package/dist/core/representation.d.ts +11 -0
- package/dist/core/representation.js +844 -0
- package/dist/core/resolved-token-cursor.d.ts +21 -0
- package/dist/core/resolved-token-cursor.js +294 -0
- package/dist/core/root-entries.js +121 -0
- package/dist/core/root-ownership.d.ts +19 -0
- package/dist/core/root-ownership.js +354 -0
- package/dist/core/root-target.d.ts +7 -0
- package/dist/core/root-target.js +281 -0
- package/dist/core/same-result.d.ts +18 -0
- package/dist/core/same-result.js +96 -0
- package/dist/core/schema-compiler.d.ts +345 -0
- package/dist/core/schema-compiler.js +3166 -0
- package/dist/core/schema-contribution-registry.d.ts +12 -0
- package/dist/core/schema-contribution-registry.js +88 -0
- package/dist/core/schema-definition.d.ts +307 -0
- package/dist/core/schema-definition.js +628 -0
- package/dist/core/schema-source.internal.d.ts +49 -0
- package/dist/core/schema-validation.d.ts +11 -0
- package/dist/core/schema-validation.js +85 -0
- package/dist/core/screen-reader-announcement.d.ts +13 -0
- package/dist/core/screen-reader-announcement.js +17 -0
- package/dist/core/selection-protocol.d.ts +38 -0
- package/dist/core/selection-protocol.js +523 -0
- package/dist/core/selection-state.js +9 -0
- package/dist/core/semantic-update-method.d.ts +11 -0
- package/dist/core/semantic-update-method.js +26 -0
- package/dist/core/set-root.d.ts +3 -0
- package/dist/core/set-root.js +244 -0
- package/dist/core/slice-end-matter.js +77 -0
- package/dist/core/slice-fit/compiled-slice-fitter.d.ts +56 -0
- package/dist/core/slice-fit/compiled-slice-fitter.js +2087 -0
- package/dist/core/slice-fit/fit-report.d.ts +36 -0
- package/dist/core/slice-fit/fit-report.js +122 -0
- package/dist/core/slice-fit/frontier.js +98 -0
- package/dist/core/slice-fit/origin.js +57 -0
- package/dist/core/slice-fit/provenance.d.ts +30 -0
- package/dist/core/slice-fit/provenance.js +245 -0
- package/dist/core/slice-identities.js +21 -0
- package/dist/core/slice-landing-types.d.ts +61 -0
- package/dist/core/slice-landing.js +124 -0
- package/dist/core/snapshot-index.d.ts +13 -0
- package/dist/core/snapshot-index.js +860 -0
- package/dist/core/state-field.d.ts +12 -0
- package/dist/core/state-field.js +102 -0
- package/dist/core/state-fields.js +36 -0
- package/dist/core/survival.js +61 -0
- package/dist/core/target-runtime.d.ts +5 -0
- package/dist/core/target-runtime.js +42 -0
- package/dist/core/transaction-values.d.ts +47 -0
- package/dist/core/transaction-values.js +66 -0
- package/dist/core/transfer-guard.js +299 -0
- package/dist/core/transfer-types.d.ts +170 -0
- package/dist/core/transfer.d.ts +72 -0
- package/dist/core/transfer.js +655 -0
- package/dist/core/tx-only.d.ts +64 -0
- package/dist/core/tx-only.js +84 -0
- package/dist/core/unique-values.js +298 -0
- package/dist/core/update-context.js +28 -0
- package/dist/core/update-policy.d.ts +17 -0
- package/dist/core/update-policy.js +45 -0
- package/dist/core/value-codec.d.ts +35 -0
- package/dist/core/value-codec.js +240 -0
- package/dist/core/view-carets.d.ts +39 -0
- package/dist/core/view-carets.js +676 -0
- package/dist/core/view-presentation.d.ts +9 -0
- package/dist/core/view-presentation.js +70 -0
- package/dist/core/work.d.ts +192 -0
- package/dist/core/work.js +122 -0
- package/dist/core/writable-text.js +37 -0
- package/dist/create-editor.d.ts +187 -0
- package/dist/create-editor.js +281 -0
- package/dist/diff/index.d.ts +4 -0
- package/dist/diff/index.js +2 -0
- package/dist/diff/lib/compare.d.ts +33 -0
- package/dist/diff/lib/compare.js +459 -0
- package/dist/diff/lib/comparison-align.js +324 -0
- package/dist/diff/lib/comparison-index.js +160 -0
- package/dist/diff/lib/comparison-internal.js +108 -0
- package/dist/diff/lib/comparison-matcher.js +1221 -0
- package/dist/diff/lib/comparison-moves.js +151 -0
- package/dist/diff/lib/comparison-plan.js +556 -0
- package/dist/diff/lib/comparison-types.d.ts +174 -0
- package/dist/diff/lib/index.d.ts +3 -0
- package/dist/dom/dom-soft-line-end.d.ts +3 -0
- package/dist/dom/dom-soft-line-end.js +295 -0
- package/dist/dom/index.d.ts +19 -0
- package/dist/dom/index.js +16 -0
- package/dist/dom/internal/index.d.ts +15 -0
- package/dist/dom/plugin/data-transfer-format.d.ts +90 -0
- package/dist/dom/plugin/data-transfer-format.js +525 -0
- package/dist/dom/plugin/dom-clipboard-runtime.d.ts +50 -0
- package/dist/dom/plugin/dom-clipboard-runtime.js +482 -0
- package/dist/dom/plugin/dom-coverage.d.ts +140 -0
- package/dist/dom/plugin/dom-coverage.js +443 -0
- package/dist/dom/plugin/dom-drag-scroll.js +176 -0
- package/dist/dom/plugin/dom-drag.d.ts +54 -0
- package/dist/dom/plugin/dom-drag.js +507 -0
- package/dist/dom/plugin/dom-editor.d.ts +421 -0
- package/dist/dom/plugin/dom-editor.js +1316 -0
- package/dist/dom/plugin/dom-event-range-targets.js +39 -0
- package/dist/dom/plugin/dom-geometry.d.ts +11 -0
- package/dist/dom/plugin/dom-geometry.js +888 -0
- package/dist/dom/plugin/dom-input-runtime.d.ts +1 -0
- package/dist/dom/plugin/dom-input-runtime.js +571 -0
- package/dist/dom/plugin/dom-integrity-observer.js +436 -0
- package/dist/dom/plugin/dom-node-path.js +61 -0
- package/dist/dom/plugin/dom-phase-scheduler.d.ts +1 -0
- package/dist/dom/plugin/dom-phase-scheduler.js +284 -0
- package/dist/dom/plugin/dom-root-runtime.d.ts +10 -0
- package/dist/dom/plugin/dom-root-runtime.js +716 -0
- package/dist/dom/plugin/dom-sync-mutation-ownership.d.ts +1 -0
- package/dist/dom/plugin/dom-sync-mutation-ownership.js +120 -0
- package/dist/dom/plugin/dom-text-flow-index.js +396 -0
- package/dist/dom/plugin/dom-text-freshness.js +188 -0
- package/dist/dom/plugin/dom-text-proofs.d.ts +2 -0
- package/dist/dom/plugin/dom-text-proofs.js +350 -0
- package/dist/dom/plugin/dom-view-caret.js +28 -0
- package/dist/dom/plugin/with-dom.d.ts +53 -0
- package/dist/dom/plugin/with-dom.js +101 -0
- package/dist/dom/utils/constants.d.ts +5 -0
- package/dist/dom/utils/constants.js +5 -0
- package/dist/dom/utils/diff-text.d.ts +51 -0
- package/dist/dom/utils/diff-text.js +264 -0
- package/dist/dom/utils/dom.d.ts +104 -0
- package/dist/dom/utils/dom.js +257 -0
- package/dist/dom/utils/drag-session.d.ts +2 -0
- package/dist/dom/utils/drag-session.js +115 -0
- package/dist/dom/utils/drop-indicator.d.ts +18 -0
- package/dist/dom/utils/drop-indicator.js +36 -0
- package/dist/dom/utils/environment.d.ts +12 -0
- package/dist/dom/utils/environment.js +118 -0
- package/dist/dom/utils/hotkey-match.d.ts +36 -0
- package/dist/dom/utils/hotkey-match.js +208 -0
- package/dist/dom/utils/hotkeys.d.ts +32 -0
- package/dist/dom/utils/hotkeys.js +121 -0
- package/dist/dom/utils/key.d.ts +14 -0
- package/dist/dom/utils/key.js +18 -0
- package/dist/dom/utils/plite-dom-markers.d.ts +26 -0
- package/dist/dom/utils/plite-dom-markers.js +25 -0
- package/dist/dom/utils/selection-writes.d.ts +18 -0
- package/dist/dom/utils/selection-writes.js +63 -0
- package/dist/dom/utils/weak-maps.d.ts +2 -0
- package/dist/dom/utils/weak-maps.js +51 -0
- package/dist/editor/above.js +30 -0
- package/dist/editor/add-mark.js +79 -0
- package/dist/editor/adjacent-character-point.js +120 -0
- package/dist/editor/after.js +37 -0
- package/dist/editor/before.js +124 -0
- package/dist/editor/block-void-break.js +20 -0
- package/dist/editor/correct-document.js +225 -0
- package/dist/editor/delete-backward.js +64 -0
- package/dist/editor/delete-forward.js +11 -0
- package/dist/editor/delete-fragment.js +40 -0
- package/dist/editor/edges.js +5 -0
- package/dist/editor/element-read-only.js +35 -0
- package/dist/editor/end.d.ts +7 -0
- package/dist/editor/end.js +5 -0
- package/dist/editor/exit-break.js +51 -0
- package/dist/editor/first.js +8 -0
- package/dist/editor/get-void.js +9 -0
- package/dist/editor/has-blocks.js +6 -0
- package/dist/editor/has-inlines.js +6 -0
- package/dist/editor/has-path.js +5 -0
- package/dist/editor/has-texts.js +5 -0
- package/dist/editor/insert-break.js +77 -0
- package/dist/editor/insert-default-child.js +55 -0
- package/dist/editor/insert-soft-break.js +14 -0
- package/dist/editor/insert-text.js +83 -0
- package/dist/editor/is-block.js +5 -0
- package/dist/editor/is-edge.js +5 -0
- package/dist/editor/is-editor.js +13 -0
- package/dist/editor/is-empty.js +6 -0
- package/dist/editor/is-end.js +9 -0
- package/dist/editor/is-start.js +9 -0
- package/dist/editor/last.js +20 -0
- package/dist/editor/leaf.js +9 -0
- package/dist/editor/levels.js +21 -0
- package/dist/editor/next.js +46 -0
- package/dist/editor/node.js +9 -0
- package/dist/editor/nodes.js +106 -0
- package/dist/editor/parent.js +14 -0
- package/dist/editor/path.js +26 -0
- package/dist/editor/point.js +52 -0
- package/dist/editor/positions.js +322 -0
- package/dist/editor/previous.js +48 -0
- package/dist/editor/project-range.js +6 -0
- package/dist/editor/range.js +12 -0
- package/dist/editor/remove-mark.js +65 -0
- package/dist/editor/should-merge-nodes-remove-prev-node.js +11 -0
- package/dist/editor/string.js +35 -0
- package/dist/editor/toggle-mark.js +71 -0
- package/dist/editor/unhang-range.js +71 -0
- package/dist/editor-runtime-view.d.ts +33 -0
- package/dist/editor-runtime-view.js +788 -0
- package/dist/history/history-carets.js +127 -0
- package/dist/history/history-character-map.js +425 -0
- package/dist/history/history-codec.js +176 -0
- package/dist/history/history-merge-policy.js +164 -0
- package/dist/history/history-plugin.d.ts +71 -0
- package/dist/history/history-plugin.js +814 -0
- package/dist/history/history-replay.js +799 -0
- package/dist/history/history-selection.js +75 -0
- package/dist/history/history-state.js +1287 -0
- package/dist/history/history.d.ts +112 -0
- package/dist/history/history.js +29 -0
- package/dist/history/index.d.ts +4 -0
- package/dist/history/index.js +3 -0
- package/dist/hyperscript/creators.d.ts +51 -0
- package/dist/hyperscript/creators.js +173 -0
- package/dist/hyperscript/hyperscript.d.ts +36 -0
- package/dist/hyperscript/hyperscript.js +66 -0
- package/dist/hyperscript/index.d.ts +20 -0
- package/dist/hyperscript/index.js +9 -0
- package/dist/hyperscript/tokens.d.ts +31 -0
- package/dist/hyperscript/tokens.js +63 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +35 -0
- package/dist/interfaces/decoration.d.ts +35 -0
- package/dist/interfaces/editor.d.ts +2783 -0
- package/dist/interfaces/editor.js +348 -0
- package/dist/interfaces/element.d.ts +66 -0
- package/dist/interfaces/element.js +34 -0
- package/dist/interfaces/index.d.ts +13 -0
- package/dist/interfaces/json.d.ts +7 -0
- package/dist/interfaces/location.d.ts +50 -0
- package/dist/interfaces/location.js +26 -0
- package/dist/interfaces/node.d.ts +306 -0
- package/dist/interfaces/node.js +339 -0
- package/dist/interfaces/path.d.ts +118 -0
- package/dist/interfaces/path.js +116 -0
- package/dist/interfaces/point.d.ts +45 -0
- package/dist/interfaces/point.js +32 -0
- package/dist/interfaces/range.d.ts +80 -0
- package/dist/interfaces/range.js +85 -0
- package/dist/interfaces/schema-validation.d.ts +33 -0
- package/dist/interfaces/schema.d.ts +870 -0
- package/dist/interfaces/selection.d.ts +61 -0
- package/dist/interfaces/selection.js +106 -0
- package/dist/interfaces/text.d.ts +68 -0
- package/dist/interfaces/text.js +52 -0
- package/dist/interfaces/transforms/node.d.ts +222 -0
- package/dist/interfaces/transforms/selection.d.ts +48 -0
- package/dist/interfaces/transforms/text.d.ts +58 -0
- package/dist/internal/browser-protocol.d.ts +5 -0
- package/dist/internal/browser-protocol.js +5 -0
- package/dist/internal/document-range.d.ts +9 -0
- package/dist/internal/document-range.js +31 -0
- package/dist/internal/editor-options.d.ts +37 -0
- package/dist/internal/editor-options.js +36 -0
- package/dist/internal/fail-invariant.d.ts +4 -0
- package/dist/internal/fail-invariant.js +6 -0
- package/dist/internal/get-defined.js +7 -0
- package/dist/internal/index.d.ts +54 -0
- package/dist/internal/index.js +52 -0
- package/dist/internal/law-check.js +7 -0
- package/dist/internal/range-text-marks.js +31 -0
- package/dist/internal/root-location.d.ts +23 -0
- package/dist/internal/root-location.js +86 -0
- package/dist/internal/text-run.d.ts +13 -0
- package/dist/internal/text-run.js +44 -0
- package/dist/internal/view/annotation-store-metrics.d.ts +11 -0
- package/dist/internal/view/annotation-store-metrics.js +12 -0
- package/dist/internal/view/mapped-view-store.js +121 -0
- package/dist/internal/view/stable-id-mapped-source.js +467 -0
- package/dist/internal/view/view-source.d.ts +20 -0
- package/dist/pagination/index.d.ts +175 -0
- package/dist/pagination/index.js +694 -0
- package/dist/pagination/page-composition.internal.js +313 -0
- package/dist/pagination/page-geometry.internal.js +99 -0
- package/dist/pagination/page-layout-engine-invalidation.internal.js +20 -0
- package/dist/pagination/page-mount-plan.js +84 -0
- package/dist/pagination/paged-view-lines.js +163 -0
- package/dist/pagination/react.d.ts +35 -0
- package/dist/pagination/react.js +1103 -0
- package/dist/range-projection.d.ts +7 -0
- package/dist/range-projection.js +50 -0
- package/dist/react/components/dom-coverage-boundary.d.ts +14 -0
- package/dist/react/components/dom-coverage-boundary.js +143 -0
- package/dist/react/components/editable-descendant-binding.js +70 -0
- package/dist/react/components/editable-dom-commit-fence.js +107 -0
- package/dist/react/components/editable-element-placement.d.ts +2 -0
- package/dist/react/components/editable-element-placement.js +117 -0
- package/dist/react/components/editable-external-text.js +47 -0
- package/dist/react/components/editable-node-equality.js +25 -0
- package/dist/react/components/editable-rendered-element.d.ts +3 -0
- package/dist/react/components/editable-rendered-element.js +61 -0
- package/dist/react/components/editable-text-blocks.d.ts +192 -0
- package/dist/react/components/editable-text-blocks.js +896 -0
- package/dist/react/components/editable-text-containers.d.ts +3 -0
- package/dist/react/components/editable-text-containers.js +28 -0
- package/dist/react/components/editable-text-flow.js +1039 -0
- package/dist/react/components/editable-text-pieces.d.ts +7 -0
- package/dist/react/components/editable-text-pieces.js +193 -0
- package/dist/react/components/editable-text.d.ts +80 -0
- package/dist/react/components/editable-text.js +322 -0
- package/dist/react/components/editable.d.ts +35 -0
- package/dist/react/components/editable.js +406 -0
- package/dist/react/components/editor-announcement-live-region.js +113 -0
- package/dist/react/components/plite-element.d.ts +18 -0
- package/dist/react/components/plite-element.js +54 -0
- package/dist/react/components/plite-leaf.d.ts +18 -0
- package/dist/react/components/plite-leaf.js +21 -0
- package/dist/react/components/plite-placeholder.d.ts +19 -0
- package/dist/react/components/plite-placeholder.js +39 -0
- package/dist/react/components/plite-spacer.js +14 -0
- package/dist/react/components/plite-text.d.ts +23 -0
- package/dist/react/components/plite-text.js +32 -0
- package/dist/react/components/plite-void-shell.js +49 -0
- package/dist/react/components/plite.d.ts +45 -0
- package/dist/react/components/plite.js +297 -0
- package/dist/react/components/text-string.js +18 -0
- package/dist/react/components/windowed-editable.internal.js +51 -0
- package/dist/react/components/zero-width-string.js +26 -0
- package/dist/react/context.js +11 -0
- package/dist/react/decoration-context.d.ts +2 -0
- package/dist/react/decoration-context.js +22 -0
- package/dist/react/decoration-source.d.ts +11 -0
- package/dist/react/decoration-source.js +1030 -0
- package/dist/react/dom-text-sync.d.ts +24 -0
- package/dist/react/dom-text-sync.js +48 -0
- package/dist/react/editable/android-composition.d.ts +3 -0
- package/dist/react/editable/android-composition.js +496 -0
- package/dist/react/editable/browser-handle.js +515 -0
- package/dist/react/editable/caret-engine.js +681 -0
- package/dist/react/editable/clipboard-input-strategy.js +632 -0
- package/dist/react/editable/composition-lease.d.ts +3 -0
- package/dist/react/editable/composition-lease.js +350 -0
- package/dist/react/editable/composition-state.js +716 -0
- package/dist/react/editable/content-root-boundaries.js +79 -0
- package/dist/react/editable/content-root-coordinate-navigation.js +28 -0
- package/dist/react/editable/content-root-navigation-actions.js +190 -0
- package/dist/react/editable/content-root-navigation.js +819 -0
- package/dist/react/editable/content-root-owner-target.js +36 -0
- package/dist/react/editable/content-root-owners.js +191 -0
- package/dist/react/editable/content-root-vertical-geometry.js +60 -0
- package/dist/react/editable/decoration-repair-bridge.js +29 -0
- package/dist/react/editable/dom-coverage-selection.js +158 -0
- package/dist/react/editable/dom-coverage-vertical-selection.js +446 -0
- package/dist/react/editable/dom-input-event.js +14 -0
- package/dist/react/editable/dom-repair-queue.d.ts +7 -0
- package/dist/react/editable/dom-repair-queue.js +543 -0
- package/dist/react/editable/dom-repair-text.js +47 -0
- package/dist/react/editable/editable-command-types.d.ts +1 -0
- package/dist/react/editable/editable-dom-runtime.d.ts +66 -0
- package/dist/react/editable/editable-dom-runtime.js +1022 -0
- package/dist/react/editable/editing-epoch-adapter.js +46 -0
- package/dist/react/editable/editing-kernel.d.ts +7 -0
- package/dist/react/editable/editing-kernel.js +593 -0
- package/dist/react/editable/external-text-binding.js +43 -0
- package/dist/react/editable/external-text-runtime.d.ts +5 -0
- package/dist/react/editable/external-text-runtime.js +851 -0
- package/dist/react/editable/history-focus.js +71 -0
- package/dist/react/editable/history-keyboard.d.ts +4 -0
- package/dist/react/editable/history-keyboard.js +9 -0
- package/dist/react/editable/input-controller.d.ts +7 -0
- package/dist/react/editable/input-controller.js +175 -0
- package/dist/react/editable/input-history.js +21 -0
- package/dist/react/editable/input-router.js +742 -0
- package/dist/react/editable/input-state.d.ts +18 -0
- package/dist/react/editable/input-state.js +330 -0
- package/dist/react/editable/input-target.js +30 -0
- package/dist/react/editable/install-browser-handle.d.ts +12 -0
- package/dist/react/editable/install-browser-handle.js +18 -0
- package/dist/react/editable/interaction-owner.js +88 -0
- package/dist/react/editable/keyboard-input-strategy.js +730 -0
- package/dist/react/editable/line-boundary.js +37 -0
- package/dist/react/editable/model-input-strategy.d.ts +9 -0
- package/dist/react/editable/model-input-strategy.js +242 -0
- package/dist/react/editable/model-selection-dom-preference.js +11 -0
- package/dist/react/editable/mutation-block-editing.js +48 -0
- package/dist/react/editable/mutation-controller.d.ts +32 -0
- package/dist/react/editable/mutation-controller.js +632 -0
- package/dist/react/editable/mutation-full-block-editing.d.ts +2 -0
- package/dist/react/editable/mutation-full-block-editing.js +44 -0
- package/dist/react/editable/mutation-history.d.ts +3 -0
- package/dist/react/editable/mutation-history.js +146 -0
- package/dist/react/editable/native-input-strategy.js +86 -0
- package/dist/react/editable/native-text-input-delta.js +40 -0
- package/dist/react/editable/placed-drag.js +177 -0
- package/dist/react/editable/plite-string-coordinate-placement.js +46 -0
- package/dist/react/editable/press-fence.d.ts +2 -0
- package/dist/react/editable/press-fence.js +70 -0
- package/dist/react/editable/projected-clipboard.js +123 -0
- package/dist/react/editable/projected-native-affordance.js +30 -0
- package/dist/react/editable/projected-selection-target.js +13 -0
- package/dist/react/editable/render-contract-monitor.d.ts +3 -0
- package/dist/react/editable/render-contract-monitor.js +152 -0
- package/dist/react/editable/root-interaction-controller.js +1400 -0
- package/dist/react/editable/root-interaction-dom-selection-replay.js +40 -0
- package/dist/react/editable/root-interaction-resolver.js +116 -0
- package/dist/react/editable/root-selector-sources.js +90 -0
- package/dist/react/editable/runtime-android-engine.js +40 -0
- package/dist/react/editable/runtime-before-input-events.js +671 -0
- package/dist/react/editable/runtime-browser-handle-events.js +40 -0
- package/dist/react/editable/runtime-clipboard-events.js +169 -0
- package/dist/react/editable/runtime-composition-events.js +163 -0
- package/dist/react/editable/runtime-drag-events.js +136 -0
- package/dist/react/editable/runtime-editor-api.d.ts +20 -0
- package/dist/react/editable/runtime-editor-api.js +21 -0
- package/dist/react/editable/runtime-event-engine.js +213 -0
- package/dist/react/editable/runtime-focus-mouse-events.js +264 -0
- package/dist/react/editable/runtime-input-events.js +166 -0
- package/dist/react/editable/runtime-kernel-trace.js +185 -0
- package/dist/react/editable/runtime-keyboard-events.js +333 -0
- package/dist/react/editable/runtime-live-state.js +44 -0
- package/dist/react/editable/runtime-mutation-state.js +11 -0
- package/dist/react/editable/runtime-repair-engine.js +118 -0
- package/dist/react/editable/runtime-root-engine.js +244 -0
- package/dist/react/editable/runtime-root-lifecycle.js +118 -0
- package/dist/react/editable/runtime-root-selection-export.js +38 -0
- package/dist/react/editable/runtime-root-selection-import.js +54 -0
- package/dist/react/editable/runtime-root-state.js +62 -0
- package/dist/react/editable/runtime-selection-engine.js +260 -0
- package/dist/react/editable/runtime-selection-state.js +12 -0
- package/dist/react/editable/runtime-target-bridge.js +29 -0
- package/dist/react/editable/schema-runtime-invalidation.js +26 -0
- package/dist/react/editable/selection-change-listener.js +99 -0
- package/dist/react/editable/selection-claim.d.ts +3 -0
- package/dist/react/editable/selection-claim.js +398 -0
- package/dist/react/editable/selection-controller.d.ts +8 -0
- package/dist/react/editable/selection-controller.js +693 -0
- package/dist/react/editable/selection-dom-range.js +84 -0
- package/dist/react/editable/selection-projected-dom.js +156 -0
- package/dist/react/editable/selection-reconciler.js +630 -0
- package/dist/react/editable/selection-runtime.js +89 -0
- package/dist/react/editable/selection-side-effect-policy.js +20 -0
- package/dist/react/editable/selection-triple-click.js +48 -0
- package/dist/react/editable/selection-void-target.js +172 -0
- package/dist/react/editable/set-root-endpoints.js +75 -0
- package/dist/react/editable/soft-line-end-delete.js +106 -0
- package/dist/react/editable/text-direction.js +82 -0
- package/dist/react/editable/typed-text.d.ts +17 -0
- package/dist/react/editable/typed-text.js +89 -0
- package/dist/react/editable/unread-press.d.ts +2 -0
- package/dist/react/editable/unread-press.js +86 -0
- package/dist/react/editable/view-caret-restore.js +128 -0
- package/dist/react/editable/view-lines.d.ts +7 -0
- package/dist/react/editable/view-lines.js +166 -0
- package/dist/react/external-text.d.ts +131 -0
- package/dist/react/history-step-views.d.ts +4 -0
- package/dist/react/history-step-views.js +119 -0
- package/dist/react/hooks/android-input-manager/android-input-manager.d.ts +7 -0
- package/dist/react/hooks/android-input-manager/android-input-manager.js +716 -0
- package/dist/react/hooks/android-input-manager/use-android-input-manager.js +53 -0
- package/dist/react/hooks/focus-plite-editable.js +116 -0
- package/dist/react/hooks/use-claim-editable-dom-commit.d.ts +12 -0
- package/dist/react/hooks/use-claim-editable-dom-commit.js +31 -0
- package/dist/react/hooks/use-drop-indicator.d.ts +9 -0
- package/dist/react/hooks/use-drop-indicator.js +14 -0
- package/dist/react/hooks/use-editable-clip.d.ts +18 -0
- package/dist/react/hooks/use-editable-clip.js +31 -0
- package/dist/react/hooks/use-editable-layout-pass.js +53 -0
- package/dist/react/hooks/use-editor-composing.d.ts +7 -0
- package/dist/react/hooks/use-editor-composing.js +12 -0
- package/dist/react/hooks/use-editor-context.d.ts +10 -0
- package/dist/react/hooks/use-editor-context.js +18 -0
- package/dist/react/hooks/use-editor-dom-scope.d.ts +27 -0
- package/dist/react/hooks/use-editor-dom-scope.js +23 -0
- package/dist/react/hooks/use-editor-focused.d.ts +7 -0
- package/dist/react/hooks/use-editor-focused.js +12 -0
- package/dist/react/hooks/use-editor-read-only.d.ts +25 -0
- package/dist/react/hooks/use-editor-read-only.js +19 -0
- package/dist/react/hooks/use-editor-runtime-state.d.ts +18 -0
- package/dist/react/hooks/use-editor-runtime-state.js +38 -0
- package/dist/react/hooks/use-editor-selection.d.ts +10 -0
- package/dist/react/hooks/use-editor-selection.js +13 -0
- package/dist/react/hooks/use-editor-selector.d.ts +38 -0
- package/dist/react/hooks/use-editor-selector.js +265 -0
- package/dist/react/hooks/use-editor-view-state.d.ts +16 -0
- package/dist/react/hooks/use-editor-view-state.js +20 -0
- package/dist/react/hooks/use-editor.d.ts +26 -0
- package/dist/react/hooks/use-editor.js +27 -0
- package/dist/react/hooks/use-element-path.d.ts +7 -0
- package/dist/react/hooks/use-element-path.js +36 -0
- package/dist/react/hooks/use-element-selected.d.ts +26 -0
- package/dist/react/hooks/use-element-selected.js +91 -0
- package/dist/react/hooks/use-element.d.ts +13 -0
- package/dist/react/hooks/use-element.js +17 -0
- package/dist/react/hooks/use-generic-selector.js +91 -0
- package/dist/react/hooks/use-hydrated.js +12 -0
- package/dist/react/hooks/use-isomorphic-layout-effect.js +9 -0
- package/dist/react/hooks/use-node-selector.d.ts +40 -0
- package/dist/react/hooks/use-node-selector.js +102 -0
- package/dist/react/hooks/use-plite-annotation-store.d.ts +21 -0
- package/dist/react/hooks/use-plite-annotation-store.js +61 -0
- package/dist/react/hooks/use-plite-annotations.d.ts +9 -0
- package/dist/react/hooks/use-plite-annotations.js +16 -0
- package/dist/react/hooks/use-plite-child-root.d.ts +14 -0
- package/dist/react/hooks/use-plite-child-root.js +38 -0
- package/dist/react/hooks/use-plite-content-root.d.ts +21 -0
- package/dist/react/hooks/use-plite-content-root.js +26 -0
- package/dist/react/hooks/use-plite-history.d.ts +43 -0
- package/dist/react/hooks/use-plite-history.js +137 -0
- package/dist/react/hooks/use-plite-node-ref.js +513 -0
- package/dist/react/hooks/use-plite-root-chrome.d.ts +34 -0
- package/dist/react/hooks/use-plite-root-chrome.js +98 -0
- package/dist/react/hooks/use-plite-runtime.d.ts +86 -0
- package/dist/react/hooks/use-plite-runtime.js +433 -0
- package/dist/react/hooks/use-runtime-focus-state.js +37 -0
- package/dist/react/hooks/use-selection-geometry.d.ts +12 -0
- package/dist/react/hooks/use-selection-geometry.js +39 -0
- package/dist/react/hooks/use-selection-view.d.ts +14 -0
- package/dist/react/hooks/use-selection-view.js +14 -0
- package/dist/react/hooks/use-state-field.d.ts +26 -0
- package/dist/react/hooks/use-state-field.js +38 -0
- package/dist/react/inactive-selection.js +175 -0
- package/dist/react/index.d.ts +97 -0
- package/dist/react/index.js +72 -0
- package/dist/react/plugin/react-editor.d.ts +20 -0
- package/dist/react/plugin/react-editor.js +6 -0
- package/dist/react/plugin/with-react.d.ts +108 -0
- package/dist/react/plugin/with-react.js +58 -0
- package/dist/react/range-geometry.d.ts +38 -0
- package/dist/react/range-geometry.js +481 -0
- package/dist/react/render-profiler.js +20 -0
- package/dist/react/root-key.js +12 -0
- package/dist/react/shell-runtime.js +29 -0
- package/dist/react/update-policy.d.ts +10 -0
- package/dist/react/update-policy.js +15 -0
- package/dist/react/utils/environment.js +5 -0
- package/dist/react/view-boundary-graph-core.d.ts +1 -0
- package/dist/react/view-boundary-graph-core.js +208 -0
- package/dist/react/view-boundary-graph.js +105 -0
- package/dist/react/view-selection-decoration.js +97 -0
- package/dist/react/view-selection.js +184 -0
- package/dist/react/viewport-boundary.js +45 -0
- package/dist/react/viewport-commands.d.ts +1 -0
- package/dist/react/viewport-commands.js +17 -0
- package/dist/react/viewport-plan.d.ts +2 -0
- package/dist/react/viewport-plan.js +77 -0
- package/dist/react/virtualized/use-virtualized-root-plan.js +148 -0
- package/dist/react/virtualized.d.ts +15 -0
- package/dist/react/virtualized.js +70 -0
- package/dist/testing/createDataTransfer.d.ts +4 -0
- package/dist/testing/createDataTransfer.js +13 -0
- package/dist/testing/index.d.ts +9 -0
- package/dist/testing/index.js +9 -0
- package/dist/testing/jsx.d.ts +181 -0
- package/dist/testing/jsx.js +82 -0
- package/dist/transforms-node/insert-nodes.js +143 -0
- package/dist/transforms-node/lift-nodes.js +117 -0
- package/dist/transforms-node/merge-nodes.js +180 -0
- package/dist/transforms-node/move-nodes.js +58 -0
- package/dist/transforms-node/remove-nodes.js +86 -0
- package/dist/transforms-node/replace-children.js +117 -0
- package/dist/transforms-node/set-nodes.js +188 -0
- package/dist/transforms-node/split-nodes.js +258 -0
- package/dist/transforms-node/unset-nodes.js +10 -0
- package/dist/transforms-node/unwrap-nodes.js +182 -0
- package/dist/transforms-node/wrap-nodes.js +250 -0
- package/dist/transforms-selection/collapse.js +20 -0
- package/dist/transforms-selection/deselect.js +8 -0
- package/dist/transforms-selection/move.js +35 -0
- package/dist/transforms-selection/select.js +59 -0
- package/dist/transforms-selection/set-point.js +32 -0
- package/dist/transforms-selection/set-selection.js +52 -0
- package/dist/transforms-text/delete-text-collapsed-path-targets.js +102 -0
- package/dist/transforms-text/delete-text-grid.js +402 -0
- package/dist/transforms-text/delete-text-inline-points.js +82 -0
- package/dist/transforms-text/delete-text-plan.js +55 -0
- package/dist/transforms-text/delete-text-removal.js +153 -0
- package/dist/transforms-text/delete-text-structural-cleanup.js +130 -0
- package/dist/transforms-text/delete-text-whole-blocks.js +70 -0
- package/dist/transforms-text/delete-text.js +804 -0
- package/dist/transforms-text/full-document-range.js +12 -0
- package/dist/transforms-text/insert-text.js +314 -0
- package/dist/types/types.d.ts +13 -0
- package/dist/utils/format-debug-value.d.ts +8 -0
- package/dist/utils/format-debug-value.js +31 -0
- package/dist/utils/get-default-insert-location.js +19 -0
- package/dist/utils/is-object.d.ts +4 -0
- package/dist/utils/is-object.js +4 -0
- package/dist/utils/match-path.js +8 -0
- package/dist/utils/node-keys.d.ts +15 -0
- package/dist/utils/node-keys.js +179 -0
- package/dist/utils/node-match.js +9 -0
- package/dist/utils/string.js +283 -0
- package/dist/yjs/core/addresses.js +98 -0
- package/dist/yjs/core/ancestor-properties.js +56 -0
- package/dist/yjs/core/attributes.js +21 -0
- package/dist/yjs/core/awareness-adapter.d.ts +5 -0
- package/dist/yjs/core/awareness-adapter.js +399 -0
- package/dist/yjs/core/awareness-relative-selection.js +22 -0
- package/dist/yjs/core/awareness.js +25 -0
- package/dist/yjs/core/binding.d.ts +3 -0
- package/dist/yjs/core/binding.js +128 -0
- package/dist/yjs/core/boundaries.js +453 -0
- package/dist/yjs/core/canonical-split.js +130 -0
- package/dist/yjs/core/change-bridge.js +124 -0
- package/dist/yjs/core/change-regions.js +119 -0
- package/dist/yjs/core/controller-registry.js +70 -0
- package/dist/yjs/core/controller.d.ts +6 -0
- package/dist/yjs/core/controller.js +1282 -0
- package/dist/yjs/core/document.js +1499 -0
- package/dist/yjs/core/editor-adapter.d.ts +18 -0
- package/dist/yjs/core/editor-adapter.js +145 -0
- package/dist/yjs/core/editor-only-roots.js +53 -0
- package/dist/yjs/core/editor-types.d.ts +1 -0
- package/dist/yjs/core/enclosures.js +410 -0
- package/dist/yjs/core/event-change-bridge.js +3642 -0
- package/dist/yjs/core/index.d.ts +4 -0
- package/dist/yjs/core/joined-lines.js +81 -0
- package/dist/yjs/core/joins.js +587 -0
- package/dist/yjs/core/json-equality.js +31 -0
- package/dist/yjs/core/keys.js +29 -0
- package/dist/yjs/core/letter-scripts.js +449 -0
- package/dist/yjs/core/new-letters.js +300 -0
- package/dist/yjs/core/path.js +25 -0
- package/dist/yjs/core/plugin.d.ts +107 -0
- package/dist/yjs/core/plugin.js +206 -0
- package/dist/yjs/core/record.js +4 -0
- package/dist/yjs/core/replacement.js +165 -0
- package/dist/yjs/core/retraction.js +132 -0
- package/dist/yjs/core/root-owners.js +110 -0
- package/dist/yjs/core/root-projection-index.js +428 -0
- package/dist/yjs/core/schema-metadata.js +88 -0
- package/dist/yjs/core/selection.js +34 -0
- package/dist/yjs/core/set-valued-attributes.js +57 -0
- package/dist/yjs/core/shared-effect-log.d.ts +4 -0
- package/dist/yjs/core/shared-effect-log.js +674 -0
- package/dist/yjs/core/text-runs.js +1596 -0
- package/dist/yjs/core/types.d.ts +76 -0
- package/dist/yjs/index.d.ts +5 -0
- package/dist/yjs/index.js +3 -0
- package/dist/yjs/react/index.d.ts +6 -0
- package/dist/yjs/react/index.js +4 -0
- package/dist/yjs/react/useYjs.d.ts +25 -0
- package/dist/yjs/react/useYjs.js +85 -0
- package/package.json +191 -43
|
@@ -0,0 +1,1287 @@
|
|
|
1
|
+
import { countCoreWork, readCoreWork } from "../core/work.js";
|
|
2
|
+
import { jsonEqual } from "../core/change/json.js";
|
|
3
|
+
import { invertEffect, mapEffect } from "../core/transaction-values.js";
|
|
4
|
+
import { isElementNode, nodeProps } from "../core/change/tokens.js";
|
|
5
|
+
import { DocumentChange, getInternalDocumentChangeClassificationEntries, getInternalDocumentChangeRootKeys, transformInternalDocumentChange, valueRoot, valueRootIndex } from "../core/change/document-change.js";
|
|
6
|
+
import { landCarriedRuns } from "../core/change/carried-run.js";
|
|
7
|
+
import { classifyDocumentChange } from "../core/change/builder.js";
|
|
8
|
+
import { getEditorRuntimeOwner, getEditorSchema } from "../core/editor-runtime.js";
|
|
9
|
+
import { MAIN_ROOT_KEY } from "../internal/root-location.js";
|
|
10
|
+
import { ElementApi } from "../interfaces/element.js";
|
|
11
|
+
import { SelectionApi } from "../interfaces/selection.js";
|
|
12
|
+
import { areEditorSchemaIdentitiesEqual, propertyTargetsReadParents } from "../core/schema-compiler.js";
|
|
13
|
+
import { getCompiledEditorSchema } from "../core/plugin-registry.js";
|
|
14
|
+
import { reportEditorLifecycleError } from "../core/lifecycle-error.js";
|
|
15
|
+
import { mapAnchorHistoryRecovery } from "../core/anchor-state.js";
|
|
16
|
+
import { getEditorDocumentValue } from "../core/public-state.js";
|
|
17
|
+
import { historyReplaySchemaOf, keepsUndoThrough, mapHistoryReplay, mapHistorySelection, projectedHistoryReplay, recordHistoryReplay } from "./history-replay.js";
|
|
18
|
+
import { crossRecord } from "../core/change/cross.js";
|
|
19
|
+
import { skippedRejection, stepRejection } from "../core/change/cross-rule.js";
|
|
20
|
+
import { mapHistoryCarets } from "./history-carets.js";
|
|
21
|
+
//#region src/history/history-state.ts
|
|
22
|
+
const failInvariant = (message) => {
|
|
23
|
+
throw new Error(message);
|
|
24
|
+
};
|
|
25
|
+
const HISTORY = /* @__PURE__ */ new WeakMap();
|
|
26
|
+
const HISTORY_DRAFTS = /* @__PURE__ */ new WeakMap();
|
|
27
|
+
const PUBLISHED_HISTORY_READ_DEPTH = /* @__PURE__ */ new WeakMap();
|
|
28
|
+
const KEPT_REDO_ATTEMPTS = /* @__PURE__ */ new Map();
|
|
29
|
+
const NO_DROPS = Object.freeze([]);
|
|
30
|
+
const withDrops = (store, drops) => drops.length === 0 ? store : Object.freeze({
|
|
31
|
+
...store,
|
|
32
|
+
crossingDrops: store.crossingDrops + drops.length,
|
|
33
|
+
unreportedDrops: [...store.unreportedDrops, ...drops]
|
|
34
|
+
});
|
|
35
|
+
const holdStore = (owner, store) => {
|
|
36
|
+
const { unreportedDrops } = store;
|
|
37
|
+
HISTORY.set(owner, unreportedDrops.length === 0 ? store : Object.freeze({
|
|
38
|
+
...store,
|
|
39
|
+
unreportedDrops: NO_DROPS
|
|
40
|
+
}));
|
|
41
|
+
for (const { cause, direction, editor } of unreportedDrops) reportEditorLifecycleError({
|
|
42
|
+
cause,
|
|
43
|
+
direction,
|
|
44
|
+
editor,
|
|
45
|
+
phase: "replay",
|
|
46
|
+
source: "history"
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
const getHistoryDraft = (editor) => {
|
|
50
|
+
const owner = getEditorRuntimeOwner(editor);
|
|
51
|
+
if ((PUBLISHED_HISTORY_READ_DEPTH.get(owner) ?? 0) > 0) return void 0;
|
|
52
|
+
return HISTORY_DRAFTS.get(owner)?.at(-1);
|
|
53
|
+
};
|
|
54
|
+
const withHistoryStateDraft = (editor, state, fn) => {
|
|
55
|
+
const owner = getEditorRuntimeOwner(editor);
|
|
56
|
+
const drafts = HISTORY_DRAFTS.get(owner) ?? [];
|
|
57
|
+
const draft = { state };
|
|
58
|
+
drafts.push(draft);
|
|
59
|
+
HISTORY_DRAFTS.set(owner, drafts);
|
|
60
|
+
try {
|
|
61
|
+
return {
|
|
62
|
+
result: fn(),
|
|
63
|
+
state: draft.state
|
|
64
|
+
};
|
|
65
|
+
} finally {
|
|
66
|
+
drafts.pop();
|
|
67
|
+
if (drafts.length === 0) HISTORY_DRAFTS.delete(owner);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const withPublishedHistoryState = (editor, fn) => {
|
|
71
|
+
const owner = getEditorRuntimeOwner(editor);
|
|
72
|
+
const depth = PUBLISHED_HISTORY_READ_DEPTH.get(owner) ?? 0;
|
|
73
|
+
PUBLISHED_HISTORY_READ_DEPTH.set(owner, depth + 1);
|
|
74
|
+
try {
|
|
75
|
+
return fn();
|
|
76
|
+
} finally {
|
|
77
|
+
if (depth === 0) PUBLISHED_HISTORY_READ_DEPTH.delete(owner);
|
|
78
|
+
else PUBLISHED_HISTORY_READ_DEPTH.set(owner, depth);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const captureHistoryState = (editor) => {
|
|
82
|
+
const draft = getHistoryDraft(editor);
|
|
83
|
+
return draft ? draft.state : HISTORY.get(getEditorRuntimeOwner(editor));
|
|
84
|
+
};
|
|
85
|
+
const restoreHistoryState = (editor, state) => {
|
|
86
|
+
const owner = getEditorRuntimeOwner(editor);
|
|
87
|
+
const draft = getHistoryDraft(owner);
|
|
88
|
+
if (draft) {
|
|
89
|
+
draft.state = state;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (state) holdStore(owner, state);
|
|
93
|
+
else HISTORY.delete(owner);
|
|
94
|
+
};
|
|
95
|
+
const createStore = (editor) => ({
|
|
96
|
+
crossingDrops: 0,
|
|
97
|
+
maxDepth: 100,
|
|
98
|
+
pendingReplay: null,
|
|
99
|
+
redos: null,
|
|
100
|
+
revision: 0,
|
|
101
|
+
schema: editor.read.schema.identity(),
|
|
102
|
+
snapshot: null,
|
|
103
|
+
undos: null,
|
|
104
|
+
unreportedDrops: NO_DROPS
|
|
105
|
+
});
|
|
106
|
+
const getStore = (editor) => {
|
|
107
|
+
const owner = getEditorRuntimeOwner(editor);
|
|
108
|
+
const draft = getHistoryDraft(owner);
|
|
109
|
+
let store = draft ? draft.state : HISTORY.get(owner);
|
|
110
|
+
if (!store) {
|
|
111
|
+
store = createStore(editor);
|
|
112
|
+
if (draft) draft.state = store;
|
|
113
|
+
else HISTORY.set(owner, store);
|
|
114
|
+
}
|
|
115
|
+
return store;
|
|
116
|
+
};
|
|
117
|
+
const setStore = (editor, store) => {
|
|
118
|
+
const owner = getEditorRuntimeOwner(editor);
|
|
119
|
+
const draft = getHistoryDraft(owner);
|
|
120
|
+
if (draft) {
|
|
121
|
+
draft.state = store;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
holdStore(owner, store);
|
|
125
|
+
};
|
|
126
|
+
const publish = (editor, store, patch) => {
|
|
127
|
+
const next = Object.freeze({
|
|
128
|
+
...store,
|
|
129
|
+
...patch,
|
|
130
|
+
revision: store.revision + 1,
|
|
131
|
+
snapshot: null
|
|
132
|
+
});
|
|
133
|
+
setStore(editor, next);
|
|
134
|
+
return next;
|
|
135
|
+
};
|
|
136
|
+
const cloneFrozen = (value) => {
|
|
137
|
+
const clone = structuredClone(value);
|
|
138
|
+
const pending = clone && typeof clone === "object" ? [clone] : [];
|
|
139
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
140
|
+
while (pending.length > 0) {
|
|
141
|
+
const item = pending.pop() ?? failInvariant("Expected value to be defined");
|
|
142
|
+
if (seen.has(item)) continue;
|
|
143
|
+
seen.add(item);
|
|
144
|
+
for (const nested of Object.values(item)) if (nested && typeof nested === "object") pending.push(nested);
|
|
145
|
+
Object.freeze(item);
|
|
146
|
+
}
|
|
147
|
+
return clone;
|
|
148
|
+
};
|
|
149
|
+
const omitPrimaryPointRoot = (point) => {
|
|
150
|
+
if (point.root !== "main") return point;
|
|
151
|
+
const { root: _root, ...rest } = point;
|
|
152
|
+
return rest;
|
|
153
|
+
};
|
|
154
|
+
const omitPrimarySelectionRoot = (selection) => !selection || SelectionApi.isNode(selection) ? selection : {
|
|
155
|
+
...selection,
|
|
156
|
+
anchor: omitPrimaryPointRoot(selection.anchor),
|
|
157
|
+
focus: omitPrimaryPointRoot(selection.focus)
|
|
158
|
+
};
|
|
159
|
+
const additionalRoot = (root) => root && root !== "main" ? root : void 0;
|
|
160
|
+
const STEP_IDS = /* @__PURE__ */ new WeakMap();
|
|
161
|
+
const HISTORY_STEPS = /* @__PURE__ */ new WeakMap();
|
|
162
|
+
const mintStepId = () => btoa(String.fromCodePoint(...crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16)))).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
|
|
163
|
+
const knownHistoryStepId = (step) => STEP_IDS.get(step);
|
|
164
|
+
const historyStepId = (step) => {
|
|
165
|
+
const known = STEP_IDS.get(step);
|
|
166
|
+
if (known) return known;
|
|
167
|
+
const id = mintStepId();
|
|
168
|
+
STEP_IDS.set(step, id);
|
|
169
|
+
return id;
|
|
170
|
+
};
|
|
171
|
+
const withHistoryStep = (batch, step) => {
|
|
172
|
+
HISTORY_STEPS.set(batch, step);
|
|
173
|
+
return batch;
|
|
174
|
+
};
|
|
175
|
+
const withHistoryStepId = (batch, id) => {
|
|
176
|
+
if (id === void 0) return batch;
|
|
177
|
+
const step = {};
|
|
178
|
+
STEP_IDS.set(step, id);
|
|
179
|
+
return withHistoryStep(batch, step);
|
|
180
|
+
};
|
|
181
|
+
const historyBatchStepId = (batch) => {
|
|
182
|
+
let step = HISTORY_STEPS.get(batch);
|
|
183
|
+
if (!step) {
|
|
184
|
+
step = {};
|
|
185
|
+
withHistoryStep(batch, step);
|
|
186
|
+
}
|
|
187
|
+
return historyStepId(step);
|
|
188
|
+
};
|
|
189
|
+
const HISTORY_FACTS = /* @__PURE__ */ new WeakMap();
|
|
190
|
+
const withHistoryFacts = (batch, facts) => {
|
|
191
|
+
if (facts) HISTORY_FACTS.set(batch, facts);
|
|
192
|
+
return batch;
|
|
193
|
+
};
|
|
194
|
+
const historyFactsOf = (batch) => HISTORY_FACTS.get(batch);
|
|
195
|
+
const HISTORY_PROGRAMS = /* @__PURE__ */ new WeakMap();
|
|
196
|
+
const withHistoryProgram = (batch, program) => {
|
|
197
|
+
if (program) HISTORY_PROGRAMS.set(batch, program);
|
|
198
|
+
return batch;
|
|
199
|
+
};
|
|
200
|
+
const historyProgramOf = (batch) => HISTORY_PROGRAMS.get(batch);
|
|
201
|
+
const HISTORY_FALLBACKS = /* @__PURE__ */ new WeakMap();
|
|
202
|
+
const withHistoryFallback = (batch, fallback) => {
|
|
203
|
+
HISTORY_FALLBACKS.set(batch, fallback);
|
|
204
|
+
return batch;
|
|
205
|
+
};
|
|
206
|
+
const historyFallbackOf = (batch) => {
|
|
207
|
+
const fallback = HISTORY_FALLBACKS.get(batch) ?? null;
|
|
208
|
+
if (typeof fallback !== "function") return fallback;
|
|
209
|
+
const mapped = fallback();
|
|
210
|
+
HISTORY_FALLBACKS.set(batch, mapped);
|
|
211
|
+
return mapped;
|
|
212
|
+
};
|
|
213
|
+
const outsideFallbackCount = (run) => {
|
|
214
|
+
const fallbacks = readCoreWork().carriedFallbacks;
|
|
215
|
+
const result = run();
|
|
216
|
+
countCoreWork("carriedFallbacks", fallbacks - readCoreWork().carriedFallbacks);
|
|
217
|
+
return result;
|
|
218
|
+
};
|
|
219
|
+
const freezeHistoryBatch = (batch) => {
|
|
220
|
+
const { selectionAfterRoot, selectionBeforeRoot, ...value } = batch;
|
|
221
|
+
const afterRoot = additionalRoot(selectionAfterRoot);
|
|
222
|
+
const beforeRoot = additionalRoot(selectionBeforeRoot);
|
|
223
|
+
const frozen = withHistoryProgram(Object.freeze({
|
|
224
|
+
...value,
|
|
225
|
+
...batch.carried ? { carried: Object.freeze(batch.carried.map((run) => Object.freeze({ ...run }))) } : {},
|
|
226
|
+
effects: Object.freeze(batch.effects.map((effect) => Object.freeze({ ...effect }))),
|
|
227
|
+
selectionAfter: cloneFrozen(omitPrimarySelectionRoot(batch.selectionAfter)),
|
|
228
|
+
...afterRoot ? { selectionAfterRoot: afterRoot } : {},
|
|
229
|
+
selectionBefore: cloneFrozen(omitPrimarySelectionRoot(batch.selectionBefore)),
|
|
230
|
+
...beforeRoot ? { selectionBeforeRoot: beforeRoot } : {}
|
|
231
|
+
}), HISTORY_PROGRAMS.get(batch));
|
|
232
|
+
const fallback = HISTORY_FALLBACKS.get(batch);
|
|
233
|
+
const step = HISTORY_STEPS.get(batch);
|
|
234
|
+
if (fallback !== void 0) HISTORY_FALLBACKS.set(frozen, fallback);
|
|
235
|
+
if (step) withHistoryStep(frozen, step);
|
|
236
|
+
return withHistoryFacts(frozen, HISTORY_FACTS.get(batch));
|
|
237
|
+
};
|
|
238
|
+
const freezeBatch = freezeHistoryBatch;
|
|
239
|
+
/**
|
|
240
|
+
* What a step's replay keeps beside its change: its carried runs, and the
|
|
241
|
+
* take-back and rest a two-part step replays apart.
|
|
242
|
+
*/
|
|
243
|
+
const replayedOf = (batch) => ({
|
|
244
|
+
carried: batch.carried,
|
|
245
|
+
program: HISTORY_PROGRAMS.get(batch),
|
|
246
|
+
parts: batch.rest && batch.unsettle ? {
|
|
247
|
+
rest: batch.rest,
|
|
248
|
+
unsettle: batch.unsettle
|
|
249
|
+
} : void 0
|
|
250
|
+
});
|
|
251
|
+
const branch = (batch, base, replay, next, mappings = null, group = null, recovery = null, anchorCeiling = 0, identity = {}, carets = null, kept = null) => Object.freeze({
|
|
252
|
+
anchorCeiling,
|
|
253
|
+
base,
|
|
254
|
+
batch: withHistoryStep(withHistoryFacts(withHistoryProgram(freezeBatch({
|
|
255
|
+
...batch,
|
|
256
|
+
change: replay.change
|
|
257
|
+
}), replay.program), replay.change === batch.change ? HISTORY_FACTS.get(batch) : void 0), identity),
|
|
258
|
+
carets,
|
|
259
|
+
carries: replay.carried !== void 0 || (next?.carries ?? false),
|
|
260
|
+
replay,
|
|
261
|
+
depth: (next?.depth ?? 0) + 1,
|
|
262
|
+
group,
|
|
263
|
+
identity,
|
|
264
|
+
kept,
|
|
265
|
+
mappings,
|
|
266
|
+
next,
|
|
267
|
+
recovery
|
|
268
|
+
});
|
|
269
|
+
const withKeptBranch = (kept, change) => {
|
|
270
|
+
if (!kept) return null;
|
|
271
|
+
if (kept.kind === "fallback") {
|
|
272
|
+
const plain = change(kept.plain);
|
|
273
|
+
return plain ? Object.freeze({
|
|
274
|
+
...kept,
|
|
275
|
+
plain
|
|
276
|
+
}) : null;
|
|
277
|
+
}
|
|
278
|
+
const mapped = change(kept.branch);
|
|
279
|
+
return mapped ? Object.freeze({
|
|
280
|
+
...kept,
|
|
281
|
+
branch: mapped
|
|
282
|
+
}) : null;
|
|
283
|
+
};
|
|
284
|
+
const clipBranch = (value, maxDepth) => {
|
|
285
|
+
if (!value || maxDepth === 0) return null;
|
|
286
|
+
if (value.depth <= maxDepth) return value;
|
|
287
|
+
const kept = [];
|
|
288
|
+
let current = value;
|
|
289
|
+
while (current && kept.length < maxDepth) {
|
|
290
|
+
kept.push(current);
|
|
291
|
+
current = current.next;
|
|
292
|
+
}
|
|
293
|
+
let clipped = null;
|
|
294
|
+
for (let index = kept.length - 1; index >= 0; index -= 1) {
|
|
295
|
+
const item = kept[index];
|
|
296
|
+
clipped = branch(item.batch, item.base, item.replay, clipped, item.mappings, item.group, item.recovery, item.anchorCeiling, item.identity, item.carets, withKeptBranch(item.kept, (other) => clipBranch(other, maxDepth - index)));
|
|
297
|
+
}
|
|
298
|
+
return clipped;
|
|
299
|
+
};
|
|
300
|
+
const pushBranch = (value, batchValue, base, replay, maxDepth, group = null, recovery = null, anchorCeiling = 0, identity = {}, carets = null) => branch(batchValue, base, replay, clipBranch(value, maxDepth - 1), null, group, recovery, anchorCeiling, identity, carets);
|
|
301
|
+
const addMapping = (value, entry) => {
|
|
302
|
+
if (!value) return null;
|
|
303
|
+
const previous = value.mappings;
|
|
304
|
+
const mappings = !value.carries && previous?.entry.textOnly && entry.textOnly ? Object.freeze({
|
|
305
|
+
entry: Object.freeze({
|
|
306
|
+
after: entry.after,
|
|
307
|
+
change: previous.entry.change.compose(entry.change),
|
|
308
|
+
textOnly: true
|
|
309
|
+
}),
|
|
310
|
+
previous: previous.previous
|
|
311
|
+
}) : Object.freeze({
|
|
312
|
+
entry,
|
|
313
|
+
previous
|
|
314
|
+
});
|
|
315
|
+
return Object.freeze({
|
|
316
|
+
...value,
|
|
317
|
+
kept: withKeptBranch(value.kept, (other) => addMapping(other, entry)),
|
|
318
|
+
mappings
|
|
319
|
+
});
|
|
320
|
+
};
|
|
321
|
+
const journalEntries = (journal) => {
|
|
322
|
+
const entries = [];
|
|
323
|
+
for (let item = journal; item; item = item.previous) entries.push(item.entry);
|
|
324
|
+
return entries.reverse();
|
|
325
|
+
};
|
|
326
|
+
const retainMappedCompositionGroup = (group) => {
|
|
327
|
+
if (group?.native?.composition === void 0) return null;
|
|
328
|
+
const shared = {
|
|
329
|
+
...group.closed ? { closed: group.closed } : {},
|
|
330
|
+
native: group.native,
|
|
331
|
+
...group.scope ? { scope: group.scope } : {}
|
|
332
|
+
};
|
|
333
|
+
return group.root === void 0 ? Object.freeze({
|
|
334
|
+
...shared,
|
|
335
|
+
kind: "effects",
|
|
336
|
+
root: void 0
|
|
337
|
+
}) : Object.freeze({
|
|
338
|
+
...shared,
|
|
339
|
+
kind: "document",
|
|
340
|
+
root: group.root
|
|
341
|
+
});
|
|
342
|
+
};
|
|
343
|
+
const yieldTo = (change, edit, base) => transformInternalDocumentChange(change, edit, base, { keepRecordWrites: true }).a;
|
|
344
|
+
const crossingDropCount = (editor) => captureHistoryState(editor)?.crossingDrops ?? 0;
|
|
345
|
+
const changedRootIndexes = (value, change) => new Map(getInternalDocumentChangeRootKeys(change).map((root) => [root, valueRootIndex(value, root)]));
|
|
346
|
+
const crossOrDrop = (editor, drops, replay, base, facts, mapping, crossing) => {
|
|
347
|
+
countCoreWork("crossedSteps");
|
|
348
|
+
try {
|
|
349
|
+
if (!facts) throw new Error("A crossing reached a step with no facts.");
|
|
350
|
+
const { followed, leftover } = crossRecord(base, {
|
|
351
|
+
change: replay.change,
|
|
352
|
+
facts
|
|
353
|
+
}, {
|
|
354
|
+
change: mapping.change,
|
|
355
|
+
facts: crossing
|
|
356
|
+
});
|
|
357
|
+
const after = followed.change.apply(mapping.after);
|
|
358
|
+
getEditorSchema(editor).checkDocumentChange({
|
|
359
|
+
after,
|
|
360
|
+
before: mapping.after,
|
|
361
|
+
change: followed.change,
|
|
362
|
+
indexedAfter: changedRootIndexes(after, followed.change),
|
|
363
|
+
indexedBefore: changedRootIndexes(mapping.after, followed.change)
|
|
364
|
+
});
|
|
365
|
+
const change = classifyDocumentChange(mapping.after, after, followed.change);
|
|
366
|
+
return {
|
|
367
|
+
facts: followed.facts,
|
|
368
|
+
kind: "crossed",
|
|
369
|
+
keptWrap: null,
|
|
370
|
+
projected: false,
|
|
371
|
+
readBack: false,
|
|
372
|
+
replay: recordHistoryReplay(historyReplaySchemaOf(editor), mapping.after, change, replay.direction, { after }),
|
|
373
|
+
rest: leftover.change,
|
|
374
|
+
restFacts: leftover.facts
|
|
375
|
+
};
|
|
376
|
+
} catch (error) {
|
|
377
|
+
drops.push({
|
|
378
|
+
cause: error,
|
|
379
|
+
direction: replay.direction,
|
|
380
|
+
editor
|
|
381
|
+
});
|
|
382
|
+
return { kind: "dropped" };
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
const headAfterDrop = (editor, value, target) => {
|
|
386
|
+
const { next } = value;
|
|
387
|
+
const from = next?.mappings?.entry.after ?? next?.base;
|
|
388
|
+
const correction = next && from ? DocumentChange.between(from, target, { isSetValued: historyReplaySchemaOf(editor).isSetValued }) : DocumentChange.empty;
|
|
389
|
+
return {
|
|
390
|
+
head: correction.empty ? next : addMapping(next, {
|
|
391
|
+
after: target,
|
|
392
|
+
change: correction,
|
|
393
|
+
textOnly: isTextOnlyMapping(correction)
|
|
394
|
+
}),
|
|
395
|
+
keptWrap: null,
|
|
396
|
+
projected: false,
|
|
397
|
+
projectedAfterReadBack: false,
|
|
398
|
+
readBack: false
|
|
399
|
+
};
|
|
400
|
+
};
|
|
401
|
+
const mapHead = (editor, drops, value, { anchor, readBack: reads }, count = Number.POSITIVE_INFINITY) => {
|
|
402
|
+
if (!value.mappings) return {
|
|
403
|
+
head: value,
|
|
404
|
+
keptWrap: null,
|
|
405
|
+
projected: false,
|
|
406
|
+
projectedAfterReadBack: false,
|
|
407
|
+
readBack: false
|
|
408
|
+
};
|
|
409
|
+
let keptWrap = null;
|
|
410
|
+
let readBack = false;
|
|
411
|
+
let projected = false;
|
|
412
|
+
let projectedAfterReadBack = false;
|
|
413
|
+
let batchBase = value.base;
|
|
414
|
+
let batchValue = value.batch;
|
|
415
|
+
let { replay } = value;
|
|
416
|
+
let { next } = value;
|
|
417
|
+
let { carets, recovery } = value;
|
|
418
|
+
let batchFacts = HISTORY_FACTS.get(value.batch);
|
|
419
|
+
const entries = journalEntries(value.mappings);
|
|
420
|
+
for (const mapping of entries.slice(0, count)) {
|
|
421
|
+
const nextBase = replay.record().after;
|
|
422
|
+
const crossed = mapping.crossing ? crossOrDrop(editor, drops, replay, batchBase, batchFacts, mapping, mapping.crossing) : null;
|
|
423
|
+
if (crossed?.kind === "dropped") return headAfterDrop(editor, value, (entries.at(-1) ?? mapping).after);
|
|
424
|
+
const mapped = crossed ?? mapHistoryReplay(historyReplaySchemaOf(editor), replay, batchBase, mapping, {
|
|
425
|
+
anchor: anchor && mapping.anchors === true,
|
|
426
|
+
readBack: reads
|
|
427
|
+
});
|
|
428
|
+
batchFacts = crossed?.facts;
|
|
429
|
+
keptWrap ??= mapped.keptWrap;
|
|
430
|
+
projected ||= mapped.projected;
|
|
431
|
+
projectedAfterReadBack ||= readBack && mapped.projected;
|
|
432
|
+
readBack ||= mapped.readBack;
|
|
433
|
+
const mappedBatchBase = mapping.after;
|
|
434
|
+
const mappedNextBase = mapped.replay.record().after;
|
|
435
|
+
({replay} = mapped);
|
|
436
|
+
const batchEdge = {
|
|
437
|
+
after: mappedBatchBase,
|
|
438
|
+
before: batchBase,
|
|
439
|
+
change: mapping.change,
|
|
440
|
+
facts: mapping.crossing ?? null
|
|
441
|
+
};
|
|
442
|
+
const nextEdge = {
|
|
443
|
+
after: mappedNextBase,
|
|
444
|
+
before: nextBase,
|
|
445
|
+
change: mapped.rest,
|
|
446
|
+
facts: crossed?.restFacts ?? null
|
|
447
|
+
};
|
|
448
|
+
const sides = replay.direction === "undo" ? {
|
|
449
|
+
after: batchEdge,
|
|
450
|
+
before: nextEdge
|
|
451
|
+
} : {
|
|
452
|
+
after: nextEdge,
|
|
453
|
+
before: batchEdge
|
|
454
|
+
};
|
|
455
|
+
recovery = mapAnchorHistoryRecovery(recovery, "after", sides.after);
|
|
456
|
+
recovery = mapAnchorHistoryRecovery(recovery, "before", sides.before);
|
|
457
|
+
if (carets) carets = mapHistoryCarets(editor, carets, batchValue, sides);
|
|
458
|
+
const { carried: _carried, rest: _rest, unsettle: _unmapped, ...mappedBatch } = batchValue;
|
|
459
|
+
const parts = replay.parts && {
|
|
460
|
+
rest: replay.parts.rest.change,
|
|
461
|
+
unsettle: replay.parts.unsettle.change
|
|
462
|
+
};
|
|
463
|
+
const unsettle = parts?.unsettle ?? (batchValue.unsettle && yieldTo(batchValue.unsettle, mapping.change, batchBase));
|
|
464
|
+
batchValue = freezeBatch({
|
|
465
|
+
...mappedBatch,
|
|
466
|
+
...parts ?? (unsettle && !unsettle.empty ? { unsettle } : {}),
|
|
467
|
+
...replay.carried ? { carried: replay.carried } : {},
|
|
468
|
+
change: replay.change,
|
|
469
|
+
effects: batchValue.effects.flatMap((effect) => {
|
|
470
|
+
const mappedEffect = mapEffect(effect, mapping.change);
|
|
471
|
+
return mappedEffect ? [mappedEffect] : [];
|
|
472
|
+
}),
|
|
473
|
+
selectionAfter: mapHistorySelection(editor, batchValue.selectionAfter, sides.after.change, sides.after.before, sides.after.after, batchValue.selectionAfterRoot ?? "main"),
|
|
474
|
+
selectionBefore: mapHistorySelection(editor, batchValue.selectionBefore, sides.before.change, sides.before.before, sides.before.after, batchValue.selectionBeforeRoot ?? "main")
|
|
475
|
+
});
|
|
476
|
+
if (!mapped.rest.empty) next = addMapping(next, {
|
|
477
|
+
after: mappedNextBase,
|
|
478
|
+
change: mapped.rest,
|
|
479
|
+
textOnly: false,
|
|
480
|
+
...crossed ? { crossing: crossed.restFacts } : {}
|
|
481
|
+
});
|
|
482
|
+
batchBase = mappedBatchBase;
|
|
483
|
+
}
|
|
484
|
+
const later = entries.slice(count);
|
|
485
|
+
const empty = batchValue.change.empty && batchValue.effects.length === 0;
|
|
486
|
+
if (empty) for (const mapping of later) next = addMapping(next, mapping);
|
|
487
|
+
return {
|
|
488
|
+
head: empty ? next : branch(withHistoryFacts(batchValue, batchFacts), batchBase, replay, next, later.reduce((previous, entry) => Object.freeze({
|
|
489
|
+
entry,
|
|
490
|
+
previous
|
|
491
|
+
}), null), retainMappedCompositionGroup(value.group), recovery, value.anchorCeiling, value.identity, carets),
|
|
492
|
+
keptWrap,
|
|
493
|
+
projected,
|
|
494
|
+
projectedAfterReadBack,
|
|
495
|
+
readBack
|
|
496
|
+
};
|
|
497
|
+
};
|
|
498
|
+
const mapAnchored = (editor, value, readBack) => {
|
|
499
|
+
const drops = [];
|
|
500
|
+
try {
|
|
501
|
+
return {
|
|
502
|
+
...mapHead(editor, drops, value, {
|
|
503
|
+
anchor: true,
|
|
504
|
+
readBack
|
|
505
|
+
}),
|
|
506
|
+
drops
|
|
507
|
+
};
|
|
508
|
+
} catch {
|
|
509
|
+
return null;
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
const resolveProgramHead = (editor, drops, value, readBack) => {
|
|
513
|
+
const attemptDrops = [];
|
|
514
|
+
const mapped = mapHead(editor, attemptDrops, value, {
|
|
515
|
+
anchor: false,
|
|
516
|
+
readBack
|
|
517
|
+
});
|
|
518
|
+
const { head: attempt } = mapped;
|
|
519
|
+
const fallbackReplay = projectedHistoryReplay(historyReplaySchemaOf(editor), value.replay, value.base);
|
|
520
|
+
if (!attempt?.replay.program || attempt.identity !== value.identity || !fallbackReplay) {
|
|
521
|
+
drops.push(...attemptDrops);
|
|
522
|
+
return mapped;
|
|
523
|
+
}
|
|
524
|
+
const fallbackDrops = [];
|
|
525
|
+
const { head: fallback } = mapHead(editor, fallbackDrops, branch(value.batch, value.base, fallbackReplay, value.next, value.mappings, value.group, value.recovery, value.anchorCeiling, value.identity, value.carets), {
|
|
526
|
+
anchor: false,
|
|
527
|
+
readBack: false
|
|
528
|
+
});
|
|
529
|
+
if (fallback?.identity !== value.identity) {
|
|
530
|
+
drops.push(...attemptDrops);
|
|
531
|
+
return mapped;
|
|
532
|
+
}
|
|
533
|
+
drops.push(...fallbackDrops);
|
|
534
|
+
return {
|
|
535
|
+
head: Object.freeze({
|
|
536
|
+
...fallback,
|
|
537
|
+
kept: Object.freeze({
|
|
538
|
+
branch: attempt,
|
|
539
|
+
kind: "program"
|
|
540
|
+
})
|
|
541
|
+
}),
|
|
542
|
+
projected: mapped.projected,
|
|
543
|
+
projectedAfterReadBack: mapped.projectedAfterReadBack,
|
|
544
|
+
readBack: mapped.readBack
|
|
545
|
+
};
|
|
546
|
+
};
|
|
547
|
+
const crossFirstMapping = (editor, drops, value) => mapHead(editor, drops, value, {
|
|
548
|
+
anchor: false,
|
|
549
|
+
readBack: false
|
|
550
|
+
}, 1).head;
|
|
551
|
+
const resolveHead = (editor, drops, value) => {
|
|
552
|
+
if (!value.mappings) return value;
|
|
553
|
+
if (journalEntries(value.mappings)[0]?.crossing) return crossFirstMapping(editor, drops, value);
|
|
554
|
+
const earlier = value.kept?.kind === "fallback" ? value.kept.plain : null;
|
|
555
|
+
const current = earlier ? Object.freeze({
|
|
556
|
+
...value,
|
|
557
|
+
kept: null
|
|
558
|
+
}) : value;
|
|
559
|
+
const bestDrops = [];
|
|
560
|
+
const { head: best, projected, projectedAfterReadBack, readBack: shaped } = resolveByRules(editor, bestDrops, current, true);
|
|
561
|
+
if (projectedAfterReadBack || earlier && projected) return resolveByRules(editor, drops, earlier ?? current, false).head;
|
|
562
|
+
if (current.replay.direction !== "redo" || !best || best.kept || best.identity !== value.identity || !earlier && !shaped) {
|
|
563
|
+
drops.push(...bestDrops);
|
|
564
|
+
return best;
|
|
565
|
+
}
|
|
566
|
+
const fallback = earlier ?? plainOf(editor, current);
|
|
567
|
+
if (shaped) try {
|
|
568
|
+
editor.read.schema.assertDocument(best.replay.change.apply(best.base));
|
|
569
|
+
} catch {
|
|
570
|
+
return resolveByRules(editor, drops, fallback, false).head;
|
|
571
|
+
}
|
|
572
|
+
drops.push(...bestDrops);
|
|
573
|
+
return Object.freeze({
|
|
574
|
+
...best,
|
|
575
|
+
kept: Object.freeze({
|
|
576
|
+
kind: "fallback",
|
|
577
|
+
plain: fallback
|
|
578
|
+
})
|
|
579
|
+
});
|
|
580
|
+
};
|
|
581
|
+
const plainOf = (editor, value) => {
|
|
582
|
+
const { head } = outsideFallbackCount(() => resolveByRules(editor, [], value, false));
|
|
583
|
+
return head?.identity === value.identity ? head : value;
|
|
584
|
+
};
|
|
585
|
+
const plainFallback = (editor, drops, shown) => {
|
|
586
|
+
if (shown.kept?.kind !== "fallback") return null;
|
|
587
|
+
const { head: plain } = resolveByRules(editor, drops, shown.kept.plain, false);
|
|
588
|
+
return plain && plain.identity === shown.identity && !jsonEqual(plain.replay.change.toJSON(), shown.replay.change.toJSON()) ? plain : null;
|
|
589
|
+
};
|
|
590
|
+
const resolveByRules = (editor, drops, value, readBack) => {
|
|
591
|
+
if (!value.mappings) return {
|
|
592
|
+
head: value,
|
|
593
|
+
projected: false,
|
|
594
|
+
projectedAfterReadBack: false,
|
|
595
|
+
readBack: false
|
|
596
|
+
};
|
|
597
|
+
if (value.replay.program && value.replay.direction === "redo" && !value.kept) return resolveProgramHead(editor, drops, value, readBack);
|
|
598
|
+
const anchorable = !value.kept && value.replay.direction === "redo" && journalEntries(value.mappings).some(({ anchors }) => anchors);
|
|
599
|
+
const anchored = value.kept ? mapAnchored(editor, value.kept.kind === "fallback" ? value.kept.plain : value.kept.branch, readBack) : anchorable ? mapAnchored(editor, value, readBack) : null;
|
|
600
|
+
if (anchorable && anchored && !anchored.keptWrap) {
|
|
601
|
+
drops.push(...anchored.drops);
|
|
602
|
+
return anchored;
|
|
603
|
+
}
|
|
604
|
+
const wrap = value.kept ? value.kept.kind === "wrap" ? value.kept.wrap : null : anchored?.keptWrap;
|
|
605
|
+
const attempt = anchored?.head?.identity === value.identity ? anchored.head : null;
|
|
606
|
+
const kept = attempt && wrap ? Object.freeze({
|
|
607
|
+
branch: attempt,
|
|
608
|
+
kind: "wrap",
|
|
609
|
+
wrap
|
|
610
|
+
}) : attempt?.replay.program ? Object.freeze({
|
|
611
|
+
branch: attempt,
|
|
612
|
+
kind: "program"
|
|
613
|
+
}) : null;
|
|
614
|
+
const mapped = mapHead(editor, drops, value, {
|
|
615
|
+
anchor: false,
|
|
616
|
+
readBack: readBack && !kept
|
|
617
|
+
});
|
|
618
|
+
const { head } = mapped;
|
|
619
|
+
return kept && head?.identity === value.identity ? {
|
|
620
|
+
...mapped,
|
|
621
|
+
head: Object.freeze({
|
|
622
|
+
...head,
|
|
623
|
+
kept
|
|
624
|
+
})
|
|
625
|
+
} : mapped;
|
|
626
|
+
};
|
|
627
|
+
const resolveTop = (editor, drops, value) => {
|
|
628
|
+
let current = value;
|
|
629
|
+
while (current?.mappings) current = resolveHead(editor, drops, current);
|
|
630
|
+
return current;
|
|
631
|
+
};
|
|
632
|
+
const resolveCanonicalTop = (editor, drops, value) => {
|
|
633
|
+
const head = resolveTop(editor, drops, value);
|
|
634
|
+
if (!head) return null;
|
|
635
|
+
const schema = historyReplaySchemaOf(editor);
|
|
636
|
+
const target = head.replay.change.apply(head.base);
|
|
637
|
+
const repair = schema.repairCanonical(head.base, head.replay.change, target);
|
|
638
|
+
if (repair.empty) return head;
|
|
639
|
+
const repaired = repair.apply(target);
|
|
640
|
+
const change = head.replay.change.compose(repair);
|
|
641
|
+
const rest = head.batch.rest?.compose(repair);
|
|
642
|
+
const { carried: _carried, ...repairedBatch } = head.batch;
|
|
643
|
+
const carried = head.batch.carried && landCarriedRuns(head.batch.carried, [{
|
|
644
|
+
after: repaired,
|
|
645
|
+
before: target,
|
|
646
|
+
change: repair
|
|
647
|
+
}]);
|
|
648
|
+
const undo = head.replay.direction === "undo";
|
|
649
|
+
const unmoved = {
|
|
650
|
+
after: head.base,
|
|
651
|
+
before: head.base,
|
|
652
|
+
change: DocumentChange.between(head.base, head.base)
|
|
653
|
+
};
|
|
654
|
+
const moved = {
|
|
655
|
+
after: repaired,
|
|
656
|
+
before: target,
|
|
657
|
+
change: repair
|
|
658
|
+
};
|
|
659
|
+
const restored = (selection, root) => mapHistorySelection(editor, selection, repair, target, repaired, root ?? "main");
|
|
660
|
+
return branch(freezeBatch(undo ? {
|
|
661
|
+
...repairedBatch,
|
|
662
|
+
change,
|
|
663
|
+
...rest ? { rest } : {},
|
|
664
|
+
...carried ? { carried } : {},
|
|
665
|
+
selectionBefore: restored(head.batch.selectionBefore, head.batch.selectionBeforeRoot)
|
|
666
|
+
} : {
|
|
667
|
+
...repairedBatch,
|
|
668
|
+
change,
|
|
669
|
+
...carried ? { carried } : {},
|
|
670
|
+
selectionAfter: restored(head.batch.selectionAfter, head.batch.selectionAfterRoot)
|
|
671
|
+
}), head.base, recordHistoryReplay(schema, head.base, change, head.replay.direction, {
|
|
672
|
+
carried,
|
|
673
|
+
program: head.replay.program,
|
|
674
|
+
parts: rest && head.batch.unsettle ? {
|
|
675
|
+
rest,
|
|
676
|
+
unsettle: head.batch.unsettle
|
|
677
|
+
} : void 0
|
|
678
|
+
}), addMapping(head.next, {
|
|
679
|
+
after: repaired,
|
|
680
|
+
change: repair,
|
|
681
|
+
textOnly: isTextOnlyMapping(repair)
|
|
682
|
+
}), null, head.group, mapAnchorHistoryRecovery(head.recovery, undo ? "before" : "after", {
|
|
683
|
+
after: repaired,
|
|
684
|
+
before: target,
|
|
685
|
+
change: repair,
|
|
686
|
+
facts: null
|
|
687
|
+
}), head.anchorCeiling, head.identity, head.carets && mapHistoryCarets(editor, head.carets, head.batch, undo ? {
|
|
688
|
+
after: unmoved,
|
|
689
|
+
before: moved
|
|
690
|
+
} : {
|
|
691
|
+
after: moved,
|
|
692
|
+
before: unmoved
|
|
693
|
+
}));
|
|
694
|
+
};
|
|
695
|
+
const shownBatches = (editor, drops, value) => {
|
|
696
|
+
const batches = [];
|
|
697
|
+
let current = resolveTop(editor, drops, value);
|
|
698
|
+
while (current) {
|
|
699
|
+
const shown = current.kept?.kind === "program" ? current.kept.branch : current;
|
|
700
|
+
if (shown !== current && !jsonEqual(current.replay.change.toJSON(), shown.replay.change.toJSON())) HISTORY_FALLBACKS.set(shown.batch, current.batch);
|
|
701
|
+
if (shown.kept?.kind === "fallback") {
|
|
702
|
+
const withFallback = shown;
|
|
703
|
+
HISTORY_FALLBACKS.set(shown.batch, () => outsideFallbackCount(() => plainFallback(editor, [], withFallback))?.batch ?? null);
|
|
704
|
+
}
|
|
705
|
+
batches.push(shown.batch);
|
|
706
|
+
current = resolveTop(editor, drops, shown.next);
|
|
707
|
+
}
|
|
708
|
+
return Object.freeze(batches.toReversed());
|
|
709
|
+
};
|
|
710
|
+
const resolvedEntryOf = (current) => ({
|
|
711
|
+
anchorCeiling: current.anchorCeiling,
|
|
712
|
+
base: current.base,
|
|
713
|
+
batch: current.batch,
|
|
714
|
+
carets: current.carets,
|
|
715
|
+
group: current.group,
|
|
716
|
+
identity: current.identity,
|
|
717
|
+
kept: current.kept,
|
|
718
|
+
recovery: current.recovery,
|
|
719
|
+
replay: current.replay
|
|
720
|
+
});
|
|
721
|
+
const resolveAll = (editor, drops, value) => {
|
|
722
|
+
const newest = [];
|
|
723
|
+
let current = value;
|
|
724
|
+
while (current) {
|
|
725
|
+
current = resolveTop(editor, drops, current);
|
|
726
|
+
if (!current) break;
|
|
727
|
+
newest.push(resolvedEntryOf(current));
|
|
728
|
+
current = current.next;
|
|
729
|
+
}
|
|
730
|
+
let resolved = null;
|
|
731
|
+
for (let index = newest.length - 1; index >= 0; index--) {
|
|
732
|
+
const entry = newest[index];
|
|
733
|
+
resolved = branch(entry.batch, entry.base, entry.replay, resolved, null, entry.group, entry.recovery, entry.anchorCeiling, entry.identity, entry.carets, entry.kept);
|
|
734
|
+
}
|
|
735
|
+
return {
|
|
736
|
+
batches: shownBatches(editor, drops, resolved),
|
|
737
|
+
branch: resolved,
|
|
738
|
+
entries: Object.freeze(newest)
|
|
739
|
+
};
|
|
740
|
+
};
|
|
741
|
+
const rebuildBranch = (entries, maxDepth, tail = null) => {
|
|
742
|
+
let value = tail;
|
|
743
|
+
for (let index = Math.min(entries.length, maxDepth) - 1; index >= 0; index -= 1) {
|
|
744
|
+
const entry = entries[index];
|
|
745
|
+
value = branch(entry.batch, entry.base, entry.replay, value, null, entry.group, entry.recovery, entry.anchorCeiling, entry.identity, entry.carets, withKeptBranch(entry.kept, (other) => clipBranch(other, maxDepth - index)));
|
|
746
|
+
}
|
|
747
|
+
return value;
|
|
748
|
+
};
|
|
749
|
+
const replacePendingReplay = (editor, store, pendingReplay, patch = {}) => {
|
|
750
|
+
setStore(editor, Object.freeze({
|
|
751
|
+
...store,
|
|
752
|
+
...patch,
|
|
753
|
+
pendingReplay
|
|
754
|
+
}));
|
|
755
|
+
};
|
|
756
|
+
const beginHistoryReplay = (editor, input) => {
|
|
757
|
+
const store = getStore(editor);
|
|
758
|
+
if (store.pendingReplay) throw new Error("History replay is already pending.");
|
|
759
|
+
replacePendingReplay(editor, store, Object.freeze({
|
|
760
|
+
...input,
|
|
761
|
+
edited: false,
|
|
762
|
+
entry: null,
|
|
763
|
+
phase: "attached",
|
|
764
|
+
replayMappings: null
|
|
765
|
+
}));
|
|
766
|
+
};
|
|
767
|
+
const readPendingHistoryReplay = (editor) => getStore(editor).pendingReplay;
|
|
768
|
+
const dropPendingHistoryReplayEntry = (editor) => {
|
|
769
|
+
const store = getStore(editor);
|
|
770
|
+
const pending = store.pendingReplay;
|
|
771
|
+
if (!pending || pending.phase === "dropped") return;
|
|
772
|
+
replacePendingReplay(editor, store, Object.freeze({
|
|
773
|
+
...pending,
|
|
774
|
+
entry: null,
|
|
775
|
+
phase: "dropped"
|
|
776
|
+
}));
|
|
777
|
+
};
|
|
778
|
+
const queuePendingHistoryReplayMapping = (editor, change, after) => {
|
|
779
|
+
if (change.empty) return;
|
|
780
|
+
const store = getStore(editor);
|
|
781
|
+
const pending = store.pendingReplay;
|
|
782
|
+
if (!pending || pending.phase !== "attached") return;
|
|
783
|
+
replacePendingReplay(editor, store, Object.freeze({
|
|
784
|
+
...pending,
|
|
785
|
+
replayMappings: Object.freeze({
|
|
786
|
+
entry: Object.freeze({
|
|
787
|
+
after,
|
|
788
|
+
change,
|
|
789
|
+
textOnly: isTextOnlyMapping(change)
|
|
790
|
+
}),
|
|
791
|
+
previous: pending.replayMappings
|
|
792
|
+
})
|
|
793
|
+
}));
|
|
794
|
+
};
|
|
795
|
+
const markPendingHistoryReplayEdited = (editor) => {
|
|
796
|
+
const store = getStore(editor);
|
|
797
|
+
const pending = store.pendingReplay;
|
|
798
|
+
if (!pending) return false;
|
|
799
|
+
if (pending.edited) return true;
|
|
800
|
+
if (pending.direction !== "redo" || pending.phase !== "attached") {
|
|
801
|
+
replacePendingReplay(editor, store, Object.freeze({
|
|
802
|
+
...pending,
|
|
803
|
+
edited: true
|
|
804
|
+
}));
|
|
805
|
+
return true;
|
|
806
|
+
}
|
|
807
|
+
const drops = [];
|
|
808
|
+
const redos = resolveAll(editor, drops, store.redos);
|
|
809
|
+
const entry = redos.entries.find((candidate) => candidate.identity === pending.identity) ?? null;
|
|
810
|
+
replacePendingReplay(editor, withDrops(store, drops), Object.freeze({
|
|
811
|
+
...pending,
|
|
812
|
+
edited: true,
|
|
813
|
+
entry,
|
|
814
|
+
phase: entry ? "detached" : "dropped"
|
|
815
|
+
}), { redos: redos.branch });
|
|
816
|
+
return true;
|
|
817
|
+
};
|
|
818
|
+
const settlePendingHistoryReplay = (editor, input) => {
|
|
819
|
+
const store = getStore(editor);
|
|
820
|
+
const pending = store.pendingReplay;
|
|
821
|
+
if (!pending || pending.request !== input.request) throw new Error("History replay settlement has no matching claim.");
|
|
822
|
+
if (input.status === "blocked") {
|
|
823
|
+
replacePendingReplay(editor, store, null);
|
|
824
|
+
return null;
|
|
825
|
+
}
|
|
826
|
+
if (!input.change || !input.effects) throw new Error("Applied history replay settlement requires a batch.");
|
|
827
|
+
const drops = [];
|
|
828
|
+
const undos = resolveAll(editor, drops, store.undos);
|
|
829
|
+
const redos = resolveAll(editor, drops, store.redos);
|
|
830
|
+
const attached = (pending.direction === "undo" ? undos.entries : redos.entries).find((candidate) => candidate.identity === pending.identity);
|
|
831
|
+
const claimed = pending.phase === "detached" ? pending.entry : attached ?? null;
|
|
832
|
+
if (!claimed) {
|
|
833
|
+
replacePendingReplay(editor, withDrops(store, drops), null, {
|
|
834
|
+
redos: redos.branch,
|
|
835
|
+
undos: undos.branch
|
|
836
|
+
});
|
|
837
|
+
return null;
|
|
838
|
+
}
|
|
839
|
+
let nextUndos = [...undos.entries];
|
|
840
|
+
let nextRedos = [...redos.entries];
|
|
841
|
+
let insertionIndex = null;
|
|
842
|
+
let replayBase = claimed.base;
|
|
843
|
+
let replayEffects = pending.replayMappings ? journalEntries(pending.replayMappings).reduce((mapped, mapping) => mapped.flatMap((effect) => {
|
|
844
|
+
const next = mapEffect(effect, mapping.change);
|
|
845
|
+
return next ? [next] : [];
|
|
846
|
+
}), [...input.effects]) : [...input.effects];
|
|
847
|
+
if (pending.direction === "undo") nextUndos = nextUndos.filter((candidate) => candidate.identity !== pending.identity);
|
|
848
|
+
else {
|
|
849
|
+
nextRedos = nextRedos.filter((candidate) => candidate.identity !== pending.identity);
|
|
850
|
+
if (pending.edited) {
|
|
851
|
+
insertionIndex = pending.undoAnchor ? nextUndos.findIndex((candidate) => candidate.identity === pending.undoAnchor) : nextUndos.length;
|
|
852
|
+
if (insertionIndex >= 0 && insertionIndex < store.maxDepth) {
|
|
853
|
+
const latestUndo = nextUndos.at(-1);
|
|
854
|
+
replayBase = nextUndos[insertionIndex]?.base ?? (latestUndo ? latestUndo.batch.change.apply(latestUndo.base) : claimed.base);
|
|
855
|
+
const correction = DocumentChange.between(claimed.base, replayBase);
|
|
856
|
+
if (!correction.empty) replayEffects = replayEffects.flatMap((effect) => {
|
|
857
|
+
const mapped = mapEffect(effect, correction);
|
|
858
|
+
return mapped ? [mapped] : [];
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
const { carried: _carried, rest: _rest, unsettle: _unsettle, ...claimedBatch } = claimed.batch;
|
|
864
|
+
const replayed = Object.freeze({
|
|
865
|
+
...claimed,
|
|
866
|
+
base: replayBase,
|
|
867
|
+
kept: null,
|
|
868
|
+
replay: recordHistoryReplay(historyReplaySchemaOf(editor), replayBase, input.change, pending.direction === "undo" ? "redo" : "undo"),
|
|
869
|
+
batch: Object.freeze({
|
|
870
|
+
...claimedBatch,
|
|
871
|
+
change: input.change,
|
|
872
|
+
effects: replayEffects.toReversed().map(invertEffect)
|
|
873
|
+
})
|
|
874
|
+
});
|
|
875
|
+
if (pending.direction === "undo") {
|
|
876
|
+
if (!pending.edited) nextRedos.unshift(replayed);
|
|
877
|
+
} else if (!pending.edited) nextUndos.unshift(replayed);
|
|
878
|
+
else if (insertionIndex !== null && insertionIndex >= 0 && insertionIndex < store.maxDepth) nextUndos.splice(insertionIndex, 0, replayed);
|
|
879
|
+
publish(editor, withDrops(store, drops), {
|
|
880
|
+
pendingReplay: null,
|
|
881
|
+
redos: rebuildBranch(nextRedos, store.maxDepth),
|
|
882
|
+
undos: rebuildBranch(nextUndos, store.maxDepth)
|
|
883
|
+
});
|
|
884
|
+
return claimed.identity;
|
|
885
|
+
};
|
|
886
|
+
const fromBatches = (editor, direction, batches, base, maxDepth) => {
|
|
887
|
+
const entries = [];
|
|
888
|
+
let currentBase = base;
|
|
889
|
+
for (const batchValue of batches.slice(-maxDepth).toReversed()) {
|
|
890
|
+
entries.push({
|
|
891
|
+
base: currentBase,
|
|
892
|
+
batch: batchValue
|
|
893
|
+
});
|
|
894
|
+
currentBase = batchValue.change.apply(currentBase);
|
|
895
|
+
}
|
|
896
|
+
let value = null;
|
|
897
|
+
const replayOf = (batchValue, from) => recordHistoryReplay(historyReplaySchemaOf(editor), from, batchValue.change, direction, replayedOf(batchValue));
|
|
898
|
+
for (const entry of entries.toReversed()) {
|
|
899
|
+
const fallback = direction === "redo" ? historyFallbackOf(entry.batch) : null;
|
|
900
|
+
const identity = HISTORY_STEPS.get(entry.batch) ?? {};
|
|
901
|
+
value = branch(entry.batch, entry.base, replayOf(entry.batch, entry.base), value, null, null, null, 0, identity, null, fallback ? Object.freeze({
|
|
902
|
+
kind: "fallback",
|
|
903
|
+
plain: branch(fallback, entry.base, replayOf(fallback, entry.base), value, null, null, null, 0, identity)
|
|
904
|
+
}) : null);
|
|
905
|
+
}
|
|
906
|
+
return value;
|
|
907
|
+
};
|
|
908
|
+
/** Publish activation options and the live schema as one history revision. */
|
|
909
|
+
const configureHistoryState = (editor, maxDepth, schema = editor.read.schema.identity()) => {
|
|
910
|
+
const store = getStore(editor);
|
|
911
|
+
const schemaChanged = !areEditorSchemaIdentitiesEqual(store.schema, schema);
|
|
912
|
+
if (store.maxDepth === maxDepth && !schemaChanged) return false;
|
|
913
|
+
publish(editor, store, {
|
|
914
|
+
maxDepth,
|
|
915
|
+
redos: schemaChanged ? null : clipBranch(store.redos, maxDepth),
|
|
916
|
+
schema,
|
|
917
|
+
undos: schemaChanged ? null : clipBranch(store.undos, maxDepth)
|
|
918
|
+
});
|
|
919
|
+
return schemaChanged;
|
|
920
|
+
};
|
|
921
|
+
const getWorkingHistory = (editor) => {
|
|
922
|
+
const store = getStore(editor);
|
|
923
|
+
if (store.snapshot) return store.snapshot;
|
|
924
|
+
const drops = [];
|
|
925
|
+
const redos = resolveAll(editor, drops, store.redos);
|
|
926
|
+
const undos = resolveAll(editor, drops, store.undos);
|
|
927
|
+
const snapshot = Object.freeze({
|
|
928
|
+
redos: redos.batches,
|
|
929
|
+
revision: store.revision,
|
|
930
|
+
schema: store.schema,
|
|
931
|
+
undos: undos.batches
|
|
932
|
+
});
|
|
933
|
+
setStore(editor, withDrops(Object.freeze({
|
|
934
|
+
...store,
|
|
935
|
+
redos: redos.branch,
|
|
936
|
+
snapshot,
|
|
937
|
+
undos: undos.branch
|
|
938
|
+
}), drops));
|
|
939
|
+
return snapshot;
|
|
940
|
+
};
|
|
941
|
+
const getHistory = (editor) => withPublishedHistoryState(editor, () => getWorkingHistory(editor));
|
|
942
|
+
const keptAttempt = (stack, request) => stack === "redos" && request !== void 0 ? KEPT_REDO_ATTEMPTS.get(request) : void 0;
|
|
943
|
+
const peekResolvedEntry = (editor, stack, resolve, request) => {
|
|
944
|
+
const store = getStore(editor);
|
|
945
|
+
const kept = keptAttempt(stack, request);
|
|
946
|
+
const head = kept ? kept.attempt : store[stack];
|
|
947
|
+
const drops = [];
|
|
948
|
+
const resolved = resolve(editor, drops, head);
|
|
949
|
+
if (kept) {
|
|
950
|
+
if (resolved && (resolved !== head || drops.length > 0) && request !== void 0) KEPT_REDO_ATTEMPTS.set(request, {
|
|
951
|
+
attempt: resolved,
|
|
952
|
+
drops: [...kept.drops, ...drops]
|
|
953
|
+
});
|
|
954
|
+
} else if (resolved !== head || drops.length > 0) setStore(editor, withDrops(Object.freeze({
|
|
955
|
+
...store,
|
|
956
|
+
[stack]: resolved,
|
|
957
|
+
snapshot: null
|
|
958
|
+
}), drops));
|
|
959
|
+
return resolved ? Object.freeze({
|
|
960
|
+
anchorCeiling: resolved.anchorCeiling,
|
|
961
|
+
base: resolved.base,
|
|
962
|
+
batch: resolved.batch,
|
|
963
|
+
carets: resolved.carets,
|
|
964
|
+
group: resolved.group,
|
|
965
|
+
identity: resolved.identity,
|
|
966
|
+
recovery: resolved.recovery,
|
|
967
|
+
restores: resolved.replay.after
|
|
968
|
+
}) : void 0;
|
|
969
|
+
};
|
|
970
|
+
const peekHistoryEntry = (editor, stack, request) => peekResolvedEntry(editor, stack, resolveTop, request);
|
|
971
|
+
const topJoinsNothingOnceMapped = (editor) => {
|
|
972
|
+
const head = getStore(editor).undos;
|
|
973
|
+
const mapping = head?.mappings;
|
|
974
|
+
return !!head && !!mapping && !mapping.previous && !mapping.entry.crossing && !head.kept && !retainMappedCompositionGroup(head.group) && keepsUndoThrough(historyReplaySchemaOf(editor), head.replay, head.base, mapping.entry);
|
|
975
|
+
};
|
|
976
|
+
const peekJoinableUndoEntry = (editor) => {
|
|
977
|
+
if (topJoinsNothingOnceMapped(editor)) return void 0;
|
|
978
|
+
const drops = crossingDropCount(editor);
|
|
979
|
+
const entry = peekResolvedEntry(editor, "undos", resolveSurvivingTop);
|
|
980
|
+
return crossingDropCount(editor) === drops ? entry : void 0;
|
|
981
|
+
};
|
|
982
|
+
const peekHistoryReplayEntry = (editor, stack, request) => peekResolvedEntry(editor, stack, resolveCanonicalTop, request);
|
|
983
|
+
const unwrapsTo = (after, before, props) => {
|
|
984
|
+
if (!jsonEqual(after.records, before.records)) return false;
|
|
985
|
+
const changed = [.../* @__PURE__ */ new Set([
|
|
986
|
+
MAIN_ROOT_KEY,
|
|
987
|
+
...Object.keys(after.roots ?? {}),
|
|
988
|
+
...Object.keys(before.roots ?? {})
|
|
989
|
+
])].filter((root) => !jsonEqual(valueRoot(after, root), valueRoot(before, root)));
|
|
990
|
+
if (changed.length !== 1) return false;
|
|
991
|
+
const [root] = changed;
|
|
992
|
+
const equalFrom = (left, right, from, shift) => left.length - from === right.length - from - shift && left.slice(from).every((node, index) => jsonEqual(node, right[from + shift + index]));
|
|
993
|
+
let left = valueRoot(after, root);
|
|
994
|
+
let right = valueRoot(before, root);
|
|
995
|
+
while (true) {
|
|
996
|
+
let at = 0;
|
|
997
|
+
while (at < left.length && jsonEqual(left[at], right[at])) at += 1;
|
|
998
|
+
const element = left[at];
|
|
999
|
+
const other = right[at];
|
|
1000
|
+
if (!element || !isElementNode(element)) return false;
|
|
1001
|
+
const held = element.children.length;
|
|
1002
|
+
if (jsonEqual(nodeProps(element), props) && element.children.every((child, index) => jsonEqual(child, right[at + index])) && equalFrom(left, right, at + 1, held - 1)) return true;
|
|
1003
|
+
if (!other || !isElementNode(other) || !jsonEqual(nodeProps(element), nodeProps(other)) || !equalFrom(left, right, at + 1, 0)) return false;
|
|
1004
|
+
left = element.children;
|
|
1005
|
+
right = other.children;
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
const keepsOnlyWrap = (current, head, kept) => {
|
|
1009
|
+
try {
|
|
1010
|
+
return unwrapsTo(kept.branch.replay.change.apply(current), head.replay.change.apply(current), kept.wrap.props);
|
|
1011
|
+
} catch {
|
|
1012
|
+
return false;
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
1015
|
+
const attachKeptHistoryRedo = (editor, request) => {
|
|
1016
|
+
const state = getStore(editor);
|
|
1017
|
+
const head = state.redos;
|
|
1018
|
+
const kept = head?.kept;
|
|
1019
|
+
if (!head || !kept) return null;
|
|
1020
|
+
if (kept.kind === "wrap" && (head.next || !keepsOnlyWrap(getEditorDocumentValue(editor), head, kept))) {
|
|
1021
|
+
setStore(editor, Object.freeze({
|
|
1022
|
+
...state,
|
|
1023
|
+
redos: Object.freeze({
|
|
1024
|
+
...head,
|
|
1025
|
+
kept: null
|
|
1026
|
+
})
|
|
1027
|
+
}));
|
|
1028
|
+
return null;
|
|
1029
|
+
}
|
|
1030
|
+
const causes = DROPPED_HISTORY_CAUSES.get(editor)?.length ?? 0;
|
|
1031
|
+
KEPT_REDO_ATTEMPTS.set(request, {
|
|
1032
|
+
attempt: kept.kind === "fallback" ? Object.freeze({
|
|
1033
|
+
...head,
|
|
1034
|
+
kept: null
|
|
1035
|
+
}) : kept.branch,
|
|
1036
|
+
drops: NO_DROPS
|
|
1037
|
+
});
|
|
1038
|
+
return {
|
|
1039
|
+
detach: () => {
|
|
1040
|
+
KEPT_REDO_ATTEMPTS.delete(request);
|
|
1041
|
+
},
|
|
1042
|
+
fallBack: () => {
|
|
1043
|
+
DROPPED_HISTORY_CAUSES.get(editor)?.splice(causes);
|
|
1044
|
+
const waiting = getStore(editor).redos;
|
|
1045
|
+
const drops = [];
|
|
1046
|
+
const plain = waiting?.identity === head.identity && plainFallback(editor, drops, waiting);
|
|
1047
|
+
if (plain) KEPT_REDO_ATTEMPTS.set(request, {
|
|
1048
|
+
attempt: plain,
|
|
1049
|
+
drops
|
|
1050
|
+
});
|
|
1051
|
+
return () => {
|
|
1052
|
+
KEPT_REDO_ATTEMPTS.delete(request);
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
};
|
|
1057
|
+
const writeHistory = (editor, stack, batchValue, current, options = {}) => {
|
|
1058
|
+
const store = getStore(editor);
|
|
1059
|
+
const identity = {};
|
|
1060
|
+
publish(editor, store, {
|
|
1061
|
+
[stack]: pushBranch(store[stack], batchValue, current, recordHistoryReplay(historyReplaySchemaOf(editor), current, batchValue.change, stack === "undos" ? "undo" : "redo", {
|
|
1062
|
+
...replayedOf(batchValue),
|
|
1063
|
+
after: options.restores
|
|
1064
|
+
}), store.maxDepth, options.group ?? null, options.recovery ?? null, options.anchorCeiling ?? 0, identity, options.carets ?? null),
|
|
1065
|
+
...options.clearRedos ? { redos: null } : {}
|
|
1066
|
+
});
|
|
1067
|
+
return identity;
|
|
1068
|
+
};
|
|
1069
|
+
const replaceHistoryHead = (editor, stack, batchValue, current, options = {}) => {
|
|
1070
|
+
const store = getStore(editor);
|
|
1071
|
+
const drops = [];
|
|
1072
|
+
const resolved = resolveTop(editor, drops, store[stack]);
|
|
1073
|
+
if (!resolved) throw new Error(`Missing ${stack} history batch.`);
|
|
1074
|
+
publish(editor, withDrops(store, drops), {
|
|
1075
|
+
[stack]: branch(batchValue, current, recordHistoryReplay(historyReplaySchemaOf(editor), current, batchValue.change, stack === "undos" ? "undo" : "redo", {
|
|
1076
|
+
...replayedOf(batchValue),
|
|
1077
|
+
after: options.restores
|
|
1078
|
+
}), resolved.next, null, options.group ?? null, options.recovery ?? null, options.anchorCeiling ?? resolved.anchorCeiling, resolved.identity, options.carets ?? null),
|
|
1079
|
+
...options.clearRedos ? { redos: null } : {}
|
|
1080
|
+
});
|
|
1081
|
+
};
|
|
1082
|
+
const resolveDownTo = (editor, drops, value, id) => {
|
|
1083
|
+
const above = [];
|
|
1084
|
+
const causes = [];
|
|
1085
|
+
let onto = null;
|
|
1086
|
+
for (let entry = value; entry;) {
|
|
1087
|
+
const attemptDrops = [];
|
|
1088
|
+
let current = null;
|
|
1089
|
+
try {
|
|
1090
|
+
const top = resolveTop(editor, attemptDrops, entry);
|
|
1091
|
+
current = top && onto ? resolveTop(editor, attemptDrops, mappedOnto(editor, top, top.base, onto)) : top;
|
|
1092
|
+
} catch (error) {
|
|
1093
|
+
causes.push(error);
|
|
1094
|
+
onto = above.at(-1)?.replay.record().after ?? getEditorDocumentValue(editor);
|
|
1095
|
+
entry = entry.next;
|
|
1096
|
+
continue;
|
|
1097
|
+
}
|
|
1098
|
+
if (!current) break;
|
|
1099
|
+
drops.push(...attemptDrops);
|
|
1100
|
+
onto = null;
|
|
1101
|
+
if (STEP_IDS.get(current.identity) === id) return {
|
|
1102
|
+
above,
|
|
1103
|
+
causes,
|
|
1104
|
+
entry: resolvedEntryOf(current),
|
|
1105
|
+
tail: current.next
|
|
1106
|
+
};
|
|
1107
|
+
above.push(resolvedEntryOf(current));
|
|
1108
|
+
entry = current.next;
|
|
1109
|
+
}
|
|
1110
|
+
return null;
|
|
1111
|
+
};
|
|
1112
|
+
const replaceUndoStep = (editor, id, change, matches) => {
|
|
1113
|
+
const store = getStore(editor);
|
|
1114
|
+
if (store.pendingReplay) return false;
|
|
1115
|
+
const drops = [];
|
|
1116
|
+
const found = resolveDownTo(editor, drops, store.undos, id);
|
|
1117
|
+
if (!found || !matches(found.entry.base)) return false;
|
|
1118
|
+
const { above, entry, tail } = found;
|
|
1119
|
+
const { carried: _carried, rest: _rest, unsettle: _unsettle, ...plain } = entry.batch;
|
|
1120
|
+
const replay = recordHistoryReplay(historyReplaySchemaOf(editor), entry.base, change, "undo");
|
|
1121
|
+
publish(editor, withDrops(store, drops), { undos: rebuildBranch([...above, {
|
|
1122
|
+
...entry,
|
|
1123
|
+
batch: {
|
|
1124
|
+
...plain,
|
|
1125
|
+
change
|
|
1126
|
+
},
|
|
1127
|
+
kept: null,
|
|
1128
|
+
replay
|
|
1129
|
+
}], store.maxDepth, mappedOnto(editor, tail, entry.replay.record().after, replay.record().after)) });
|
|
1130
|
+
for (const cause of found.causes) recordDroppedCause(editor, cause);
|
|
1131
|
+
return true;
|
|
1132
|
+
};
|
|
1133
|
+
const forgetHistoryStep = (editor, id) => {
|
|
1134
|
+
const store = getStore(editor);
|
|
1135
|
+
if (store.pendingReplay) return false;
|
|
1136
|
+
for (const stack of ["undos", "redos"]) {
|
|
1137
|
+
const drops = [];
|
|
1138
|
+
const found = resolveDownTo(editor, drops, store[stack], id);
|
|
1139
|
+
if (!found) continue;
|
|
1140
|
+
const { above, entry, tail } = found;
|
|
1141
|
+
const below = above.length === 0 ? tail : mappedOnto(editor, tail, entry.replay.record().after, entry.base);
|
|
1142
|
+
const remaining = rebaseOnto(editor, drops, rebuildBranch(above, store.maxDepth, below), getEditorDocumentValue(editor));
|
|
1143
|
+
publish(editor, withDrops(store, drops), { [stack]: remaining });
|
|
1144
|
+
for (const cause of found.causes) recordDroppedCause(editor, cause);
|
|
1145
|
+
return true;
|
|
1146
|
+
}
|
|
1147
|
+
return false;
|
|
1148
|
+
};
|
|
1149
|
+
const DROPPED_HISTORY_CAUSES = /* @__PURE__ */ new WeakMap();
|
|
1150
|
+
const recordDroppedCause = (editor, cause) => {
|
|
1151
|
+
const causes = DROPPED_HISTORY_CAUSES.get(editor) ?? [];
|
|
1152
|
+
causes.push(cause);
|
|
1153
|
+
DROPPED_HISTORY_CAUSES.set(editor, causes);
|
|
1154
|
+
countCoreWork("carriedFallbacks");
|
|
1155
|
+
};
|
|
1156
|
+
const takeDroppedHistoryCauses = (editor) => {
|
|
1157
|
+
const causes = DROPPED_HISTORY_CAUSES.get(editor) ?? [];
|
|
1158
|
+
DROPPED_HISTORY_CAUSES.delete(editor);
|
|
1159
|
+
return causes;
|
|
1160
|
+
};
|
|
1161
|
+
const resolveSurvivingTop = (editor, drops, value) => {
|
|
1162
|
+
for (let entry = value; entry; entry = entry.next) {
|
|
1163
|
+
const attemptDrops = [];
|
|
1164
|
+
try {
|
|
1165
|
+
const head = resolveTop(editor, attemptDrops, entry);
|
|
1166
|
+
drops.push(...attemptDrops);
|
|
1167
|
+
return head;
|
|
1168
|
+
} catch (error) {
|
|
1169
|
+
recordDroppedCause(editor, error);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
return null;
|
|
1173
|
+
};
|
|
1174
|
+
const mappedOnto = (editor, value, from, to) => {
|
|
1175
|
+
if (!value) return null;
|
|
1176
|
+
const change = DocumentChange.between(from, to, { isSetValued: historyReplaySchemaOf(editor).isSetValued });
|
|
1177
|
+
return change.empty ? value : addMapping(value, {
|
|
1178
|
+
after: to,
|
|
1179
|
+
change,
|
|
1180
|
+
textOnly: isTextOnlyMapping(change)
|
|
1181
|
+
});
|
|
1182
|
+
};
|
|
1183
|
+
const rebaseOnto = (editor, drops, value, current) => {
|
|
1184
|
+
const head = resolveSurvivingTop(editor, drops, value);
|
|
1185
|
+
return head && mappedOnto(editor, head, head.base, current);
|
|
1186
|
+
};
|
|
1187
|
+
const dropHistoryHead = (editor, stack, current) => {
|
|
1188
|
+
const store = getStore(editor);
|
|
1189
|
+
const value = store[stack];
|
|
1190
|
+
if (!value) return;
|
|
1191
|
+
const drops = [];
|
|
1192
|
+
const result = rebaseOnto(editor, drops, value.next, current);
|
|
1193
|
+
publish(editor, withDrops(store, drops), { [stack]: result });
|
|
1194
|
+
};
|
|
1195
|
+
const completeHistoryAction = (editor, source, destination, batchValue, current, olderStepsMapping, request) => {
|
|
1196
|
+
const store = getStore(editor);
|
|
1197
|
+
const kept = keptAttempt(source, request);
|
|
1198
|
+
const drops = [...kept?.drops ?? []];
|
|
1199
|
+
const resolved = resolveTop(editor, drops, kept ? kept.attempt : store[source]);
|
|
1200
|
+
KEPT_REDO_ATTEMPTS.delete(request);
|
|
1201
|
+
if (!resolved) throw new Error(`Missing ${source} history batch.`);
|
|
1202
|
+
const nextSource = rebaseOnto(editor, drops, resolved.next, current);
|
|
1203
|
+
const older = olderStepsMapping ? addMapping(store[destination], {
|
|
1204
|
+
...olderStepsMapping,
|
|
1205
|
+
textOnly: false
|
|
1206
|
+
}) : store[destination];
|
|
1207
|
+
publish(editor, withDrops(store, drops), {
|
|
1208
|
+
[destination]: batchValue.change.empty && batchValue.effects.length === 0 ? older : pushBranch(older, batchValue, current, recordHistoryReplay(historyReplaySchemaOf(editor), current, batchValue.change, destination === "undos" ? "undo" : "redo", replayedOf(batchValue)), store.maxDepth, resolved.group, resolved.recovery, resolved.anchorCeiling, resolved.identity, resolved.carets),
|
|
1209
|
+
[source]: nextSource
|
|
1210
|
+
});
|
|
1211
|
+
};
|
|
1212
|
+
const isTextOnlyMapping = (change) => {
|
|
1213
|
+
const classifications = [...getInternalDocumentChangeClassificationEntries(change)];
|
|
1214
|
+
return change.createRoots.size === 0 && change.deleteRoots.size === 0 && getInternalDocumentChangeRootKeys(change).length > 0 && classifications.length > 0 && classifications.every(([, classification]) => classification.text && !classification.properties && !classification.structure);
|
|
1215
|
+
};
|
|
1216
|
+
const ELEMENT_SCHEMAS = /* @__PURE__ */ new WeakMap();
|
|
1217
|
+
const historyElementSchemaOf = (editor) => {
|
|
1218
|
+
const read = getEditorSchema(editor);
|
|
1219
|
+
const known = ELEMENT_SCHEMAS.get(read);
|
|
1220
|
+
if (known) return known;
|
|
1221
|
+
const owner = getEditorRuntimeOwner(editor);
|
|
1222
|
+
const contentOf = (element) => typeof element.type === "string" ? read.getElementContent(element.type) : null;
|
|
1223
|
+
const schema = {
|
|
1224
|
+
content: (element) => contentOf(element) ?? "unknown",
|
|
1225
|
+
isInline: (element) => ElementApi.isElement(element) && read.isInline(element),
|
|
1226
|
+
ownsContentRoot: (element) => typeof element.type === "string" && (getCompiledEditorSchema(owner).elements.byType.get(element.type)?.contentRoots.size ?? 0) > 0,
|
|
1227
|
+
propertiesReadParents: () => propertyTargetsReadParents(getCompiledEditorSchema(owner)),
|
|
1228
|
+
rootContent: (document, root) => read.getRootContent(root, document) ?? "unknown"
|
|
1229
|
+
};
|
|
1230
|
+
ELEMENT_SCHEMAS.set(read, schema);
|
|
1231
|
+
return schema;
|
|
1232
|
+
};
|
|
1233
|
+
const holdsCarry = (facts) => facts.kind === "recorded" && [...facts.roots.values()].some(({ carries }) => carries.length > 0);
|
|
1234
|
+
const waitsOnNothing = ({ batch, kept, mappings, replay }) => !mappings && !kept && !replay.program && !replay.carried && !replay.parts && !replay.exact && !batch.unsettle;
|
|
1235
|
+
const crossesEveryStep = (value, schema) => {
|
|
1236
|
+
for (let entry = value; entry; entry = entry.next) {
|
|
1237
|
+
const facts = HISTORY_FACTS.get(entry.batch);
|
|
1238
|
+
if (!facts || !waitsOnNothing(entry) || stepRejection(entry.base, {
|
|
1239
|
+
change: entry.replay.change,
|
|
1240
|
+
facts
|
|
1241
|
+
}, schema) !== null) return false;
|
|
1242
|
+
}
|
|
1243
|
+
return true;
|
|
1244
|
+
};
|
|
1245
|
+
const admits = (editor, store, skipped, before) => {
|
|
1246
|
+
if (!holdsCarry(skipped.facts) || store.pendingReplay) return false;
|
|
1247
|
+
const schema = historyElementSchemaOf(editor);
|
|
1248
|
+
return skippedRejection(before, skipped, schema) === null && crossesEveryStep(store.undos, schema) && crossesEveryStep(store.redos, schema);
|
|
1249
|
+
};
|
|
1250
|
+
const queueHistoryMapping = (editor, change, after, skipped) => {
|
|
1251
|
+
if (change.empty) return;
|
|
1252
|
+
const store = getStore(editor);
|
|
1253
|
+
const crosses = admits(editor, store, {
|
|
1254
|
+
change,
|
|
1255
|
+
facts: skipped.facts
|
|
1256
|
+
}, skipped.before);
|
|
1257
|
+
if (crosses) countCoreWork("admittedChanges");
|
|
1258
|
+
const mapping = Object.freeze({
|
|
1259
|
+
after,
|
|
1260
|
+
anchors: true,
|
|
1261
|
+
change,
|
|
1262
|
+
textOnly: isTextOnlyMapping(change),
|
|
1263
|
+
...crosses ? { crossing: skipped.facts } : {}
|
|
1264
|
+
});
|
|
1265
|
+
publish(editor, store, {
|
|
1266
|
+
redos: addMapping(store.redos, mapping),
|
|
1267
|
+
undos: addMapping(store.undos, mapping)
|
|
1268
|
+
});
|
|
1269
|
+
};
|
|
1270
|
+
const clearHistoryState = (editor) => {
|
|
1271
|
+
HISTORY.delete(getEditorRuntimeOwner(editor));
|
|
1272
|
+
};
|
|
1273
|
+
const replaceHistoryState = (editor, value, current = editor.read.value()) => {
|
|
1274
|
+
const store = getStore(editor);
|
|
1275
|
+
const next = Object.freeze({
|
|
1276
|
+
...store,
|
|
1277
|
+
redos: fromBatches(editor, "redo", value.redos, current, store.maxDepth),
|
|
1278
|
+
revision: store.revision + 1,
|
|
1279
|
+
schema: value.schema,
|
|
1280
|
+
snapshot: null,
|
|
1281
|
+
undos: fromBatches(editor, "undo", value.undos, current, store.maxDepth)
|
|
1282
|
+
});
|
|
1283
|
+
setStore(editor, next);
|
|
1284
|
+
return getWorkingHistory(editor);
|
|
1285
|
+
};
|
|
1286
|
+
//#endregion
|
|
1287
|
+
export { attachKeptHistoryRedo, beginHistoryReplay, captureHistoryState, clearHistoryState, completeHistoryAction, configureHistoryState, crossingDropCount, dropHistoryHead, dropPendingHistoryReplayEntry, forgetHistoryStep, freezeHistoryBatch, getHistory, getWorkingHistory, historyBatchStepId, historyElementSchemaOf, historyFactsOf, historyFallbackOf, historyProgramOf, historyStepId, knownHistoryStepId, markPendingHistoryReplayEdited, peekHistoryEntry, peekHistoryReplayEntry, peekJoinableUndoEntry, queueHistoryMapping, queuePendingHistoryReplayMapping, readPendingHistoryReplay, replaceHistoryHead, replaceHistoryState, replaceUndoStep, restoreHistoryState, settlePendingHistoryReplay, takeDroppedHistoryCauses, withHistoryFacts, withHistoryFallback, withHistoryProgram, withHistoryStateDraft, withHistoryStepId, withPublishedHistoryState, writeHistory };
|