plitejs 54.0.0-beta.2 → 54.0.0-beta.3
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/dist/{internal/view/annotation-store-metrics.js → annotation-store-metrics-Ccjkef45.js} +1 -1
- package/dist/annotations/index.d.ts +1 -1
- package/dist/annotations/index.js +1 -1
- package/dist/authored/index.d.ts +596 -9
- package/dist/authored/index.js +18557 -4
- package/dist/{core/authored-veto.js → authored-veto-DSnQcHGR.js} +2 -2
- package/dist/{internal/browser-protocol.js → browser-protocol-pvt4HFF7.js} +1 -1
- package/dist/comparison-plan-CEQL0ooW.js +1338 -0
- package/dist/{diff/lib/comparison-types.d.ts → comparison-types-Dt-unJZY.d.ts} +11 -6
- package/dist/create-editor-CkHtPWXV.js +1107 -0
- package/dist/diff/index.d.ts +31 -3
- package/dist/diff/index.js +1747 -1
- package/dist/dom/index.d.ts +2 -19
- package/dist/dom/index.js +2 -16
- package/dist/dom-Cgfscvnm.js +9220 -0
- package/dist/{core/same-result.js → editor-owner-IUmkTeXz.js} +77 -2
- package/dist/{core/editor-view-lifetime.js → editor-view-lifetime-GJKa_QGh.js} +1 -1
- package/dist/history/index.d.ts +169 -3
- package/dist/history/index.js +6717 -2
- package/dist/hyperscript/index.d.ts +1 -19
- package/dist/hyperscript/index.js +1 -8
- package/dist/{hyperscript/creators.js → hyperscript-FPuoArEi.js} +134 -8
- package/dist/index-BpQx2UG4.d.ts +1093 -0
- package/dist/{yjs/core/plugin.d.ts → index-Cw-oC2ps.d.ts} +88 -5
- package/dist/{annotations/store.d.ts → index-DPWyk3lG.d.ts} +21 -6
- package/dist/index-DpltOCot.d.ts +9753 -0
- package/dist/index-HPYawTae.d.ts +119 -0
- package/dist/index-K0Za9YXc.d.ts +1246 -0
- package/dist/index.d.ts +1 -50
- package/dist/index.js +4 -34
- package/dist/internal/index.d.ts +2 -54
- package/dist/internal/index.js +156 -52
- package/dist/{internal/view/mapped-view-store.js → mapped-view-store-ld-6uxEU.js} +2 -3
- package/dist/{core/native-grouping-input.js → native-grouping-input-DMNcsIaW.js} +2 -2
- package/dist/pagination/index.d.ts +1 -7
- package/dist/pagination/index.js +1 -693
- package/dist/pagination/react.d.ts +2 -4
- package/dist/pagination/react.js +436 -30
- package/dist/pagination-D_A8iPJP.js +1021 -0
- package/dist/plugin-DWzkJbnJ.js +50999 -0
- package/dist/{react/range-geometry.d.ts → range-geometry-BLAHRE11.d.ts} +2 -2
- package/dist/{react/range-geometry.js → range-geometry-BjeLHOnl.js} +23 -18
- package/dist/react/index.d.ts +5 -97
- package/dist/react/index.js +7 -72
- package/dist/react/virtualized.d.ts +2 -4
- package/dist/react/virtualized.js +146 -7
- package/dist/react-DZ15gmz2.js +1018 -0
- package/dist/{core/change/retraction.js → retraction-BMem8Rfk.js} +16 -4
- package/dist/src-cT1OTKP_.js +1386 -0
- package/dist/{internal/view/stable-id-mapped-source.js → store-Cz2mXyDe.js} +240 -3
- package/dist/testing/index.d.ts +182 -8
- package/dist/testing/index.js +95 -8
- package/dist/use-editor-dom-scope-BbMDSCpW.js +28354 -0
- package/dist/yjs/index.d.ts +1 -4
- package/dist/yjs/index.js +1 -2
- package/dist/yjs/react/index.d.ts +25 -5
- package/dist/yjs/react/index.js +84 -3
- package/dist/yjs-DOK-m7kl.js +13413 -0
- package/package.json +1 -1
- package/dist/annotations/store.js +0 -244
- package/dist/authored/authored.d.ts +0 -116
- package/dist/authored/authored.js +0 -1271
- package/dist/authored/changes.js +0 -365
- package/dist/authored/comparison.d.ts +0 -41
- package/dist/authored/comparison.js +0 -270
- package/dist/authored/decision-window.js +0 -42
- package/dist/authored/decision.js +0 -306
- package/dist/authored/facts/admission.js +0 -388
- package/dist/authored/facts/compact.d.ts +0 -2
- package/dist/authored/facts/compact.js +0 -91
- package/dist/authored/facts/dependencies.d.ts +0 -5
- package/dist/authored/facts/dependencies.js +0 -66
- package/dist/authored/facts/editing.js +0 -12
- package/dist/authored/facts/facts.d.ts +0 -8
- package/dist/authored/facts/facts.js +0 -535
- package/dist/authored/facts/records.d.ts +0 -28
- package/dist/authored/facts/records.js +0 -226
- package/dist/authored/facts/settle.js +0 -529
- package/dist/authored/format.d.ts +0 -34
- package/dist/authored/format.js +0 -175
- package/dist/authored/ledger/book.js +0 -809
- package/dist/authored/ledger/cards.js +0 -223
- package/dist/authored/ledger/ledger.js +0 -830
- package/dist/authored/ledger/level.js +0 -1081
- package/dist/authored/ledger/links.js +0 -20
- package/dist/authored/ledger/pairs.js +0 -334
- package/dist/authored/ledger/places.js +0 -524
- package/dist/authored/ledger/preview-lens.js +0 -252
- package/dist/authored/ledger/projection.js +0 -163
- package/dist/authored/ledger/roots.js +0 -11
- package/dist/authored/ledger/runs.js +0 -480
- package/dist/authored/ledger/slots.js +0 -330
- package/dist/authored/ledger/work.js +0 -66
- package/dist/authored/refusal.d.ts +0 -33
- package/dist/authored/refusal.js +0 -188
- package/dist/authored/resolve-schema.js +0 -62
- package/dist/authored/tree/alignment.js +0 -456
- package/dist/authored/tree/carried.js +0 -205
- package/dist/authored/tree/command-values.js +0 -344
- package/dist/authored/tree/cuts.js +0 -320
- package/dist/authored/tree/grid.js +0 -49
- package/dist/authored/tree/halves.js +0 -120
- package/dist/authored/tree/holders.js +0 -345
- package/dist/authored/tree/holds.js +0 -135
- package/dist/authored/tree/layers.d.ts +0 -49
- package/dist/authored/tree/layers.js +0 -354
- package/dist/authored/tree/marks.d.ts +0 -136
- package/dist/authored/tree/marks.js +0 -263
- package/dist/authored/tree/proposed.js +0 -212
- package/dist/authored/tree/readiness.js +0 -545
- package/dist/authored/tree/record-completion.js +0 -423
- package/dist/authored/tree/record.js +0 -2908
- package/dist/authored/tree/reserves.js +0 -449
- package/dist/authored/tree/resolve.d.ts +0 -9
- package/dist/authored/tree/resolve.js +0 -1860
- package/dist/authored/tree/shown.js +0 -153
- package/dist/authored/tree/spare-lines.js +0 -119
- package/dist/authored/tree/spares.js +0 -61
- package/dist/authored/types.d.ts +0 -177
- package/dist/core/anchor-state.d.ts +0 -15
- package/dist/core/anchor-state.js +0 -792
- package/dist/core/anchor.d.ts +0 -34
- package/dist/core/anchor.js +0 -843
- package/dist/core/authored-document-capability.d.ts +0 -106
- package/dist/core/authored-document-capability.js +0 -6
- package/dist/core/authored-runtime.d.ts +0 -10
- package/dist/core/authored-runtime.js +0 -67
- package/dist/core/authored-veto.d.ts +0 -30
- package/dist/core/change/builder.d.ts +0 -546
- package/dist/core/change/builder.js +0 -1120
- package/dist/core/change/carried-projection.js +0 -1518
- package/dist/core/change/carried-run.d.ts +0 -26
- package/dist/core/change/carried-run.js +0 -251
- package/dist/core/change/carry-program.js +0 -537
- package/dist/core/change/classification.d.ts +0 -22
- package/dist/core/change/classification.js +0 -205
- package/dist/core/change/cross-rule.js +0 -238
- package/dist/core/change/cross.js +0 -577
- package/dist/core/change/document-change.d.ts +0 -137
- package/dist/core/change/document-change.js +0 -872
- package/dist/core/change/document-index.d.ts +0 -117
- package/dist/core/change/document-index.js +0 -542
- package/dist/core/change/draft-facts.js +0 -323
- package/dist/core/change/enclosure.d.ts +0 -12
- package/dist/core/change/enclosure.js +0 -272
- package/dist/core/change/join.js +0 -751
- package/dist/core/change/json.d.ts +0 -4
- package/dist/core/change/json.js +0 -26
- package/dist/core/change/lazy-root.d.ts +0 -1
- package/dist/core/change/lazy-root.js +0 -73
- package/dist/core/change/lineage.d.ts +0 -49
- package/dist/core/change/lineage.js +0 -390
- package/dist/core/change/mapping.d.ts +0 -31
- package/dist/core/change/mapping.js +0 -186
- package/dist/core/change/new-letters.d.ts +0 -14
- package/dist/core/change/new-letters.js +0 -139
- package/dist/core/change/range-association.js +0 -10
- package/dist/core/change/read-back.d.ts +0 -7
- package/dist/core/change/read-back.js +0 -7
- package/dist/core/change/record.d.ts +0 -59
- package/dist/core/change/record.js +0 -346
- package/dist/core/change/root-change.d.ts +0 -180
- package/dist/core/change/root-change.js +0 -3544
- package/dist/core/change/slice-facts.js +0 -89
- package/dist/core/change/text-splices.js +0 -98
- package/dist/core/change/tokens.d.ts +0 -97
- package/dist/core/change/tokens.js +0 -449
- package/dist/core/change/transform.d.ts +0 -36
- package/dist/core/change/transform.js +0 -97
- package/dist/core/change/wrap-fidelity.js +0 -295
- package/dist/core/change-events.js +0 -223
- package/dist/core/clone.js +0 -28
- package/dist/core/command-definition.d.ts +0 -25
- package/dist/core/command-definition.js +0 -48
- package/dist/core/command-document.d.ts +0 -4
- package/dist/core/command-document.js +0 -20
- package/dist/core/command-frame.js +0 -628
- package/dist/core/command-registry.d.ts +0 -36
- package/dist/core/command-registry.js +0 -283
- package/dist/core/commit-publication.js +0 -40
- package/dist/core/commit.d.ts +0 -26
- package/dist/core/commit.js +0 -686
- package/dist/core/composition-stamp.d.ts +0 -14
- package/dist/core/composition-stamp.js +0 -79
- package/dist/core/content-completion.d.ts +0 -4
- package/dist/core/content-completion.js +0 -343
- package/dist/core/content-landing.js +0 -124
- package/dist/core/content-slice-roots.js +0 -36
- package/dist/core/content-slice.d.ts +0 -38
- package/dist/core/content-slice.js +0 -253
- package/dist/core/content.js +0 -18
- package/dist/core/correction.js +0 -25
- package/dist/core/default-storage.js +0 -53
- package/dist/core/document-admission.d.ts +0 -4
- package/dist/core/document-admission.js +0 -64
- package/dist/core/document-change.d.ts +0 -3
- package/dist/core/document-recorder.d.ts +0 -6
- package/dist/core/document-recorder.js +0 -67
- package/dist/core/document-shape.d.ts +0 -68
- package/dist/core/document-shape.js +0 -173
- package/dist/core/document-view-read.d.ts +0 -16
- package/dist/core/document-view-read.js +0 -36
- package/dist/core/draft-track.d.ts +0 -3
- package/dist/core/draft-track.js +0 -90
- package/dist/core/editor-commands.d.ts +0 -99
- package/dist/core/editor-commands.js +0 -505
- package/dist/core/editor-lifecycle-api.d.ts +0 -8
- package/dist/core/editor-lifecycle-api.js +0 -219
- package/dist/core/editor-lifetime.js +0 -12
- package/dist/core/editor-owner.d.ts +0 -24
- package/dist/core/editor-owner.js +0 -78
- package/dist/core/editor-read-execution.d.ts +0 -6
- package/dist/core/editor-read-execution.js +0 -64
- package/dist/core/editor-read-runtime.js +0 -176
- package/dist/core/editor-reads.d.ts +0 -128
- package/dist/core/editor-reads.js +0 -63
- package/dist/core/editor-runtime.d.ts +0 -112
- package/dist/core/editor-runtime.js +0 -20
- package/dist/core/editor-schema.d.ts +0 -314
- package/dist/core/editor-schema.js +0 -2295
- package/dist/core/element-owned-root-index.d.ts +0 -4
- package/dist/core/element-owned-root-index.js +0 -353
- package/dist/core/get-content-slice.js +0 -118
- package/dist/core/get-fragment.js +0 -22
- package/dist/core/identity-owner.js +0 -697
- package/dist/core/import-content-slice.js +0 -26
- package/dist/core/initial-value.js +0 -87
- package/dist/core/insert-limit.js +0 -81
- package/dist/core/is-empty-element.js +0 -20
- package/dist/core/json-fingerprint.js +0 -16
- package/dist/core/landing.d.ts +0 -11
- package/dist/core/landing.js +0 -279
- package/dist/core/lifecycle-error.d.ts +0 -11
- package/dist/core/lifecycle-error.js +0 -68
- package/dist/core/listener-state.d.ts +0 -1
- package/dist/core/listener-state.js +0 -59
- package/dist/core/measured-sequence.d.ts +0 -43
- package/dist/core/measured-sequence.js +0 -404
- package/dist/core/missing-reference.js +0 -15
- package/dist/core/node-property-mutation.js +0 -10
- package/dist/core/node-selection.js +0 -85
- package/dist/core/node-write-veto.d.ts +0 -37
- package/dist/core/node-write-veto.js +0 -17
- package/dist/core/persisted-document.d.ts +0 -6
- package/dist/core/persisted-document.js +0 -39
- package/dist/core/persistent-map.js +0 -139
- package/dist/core/plain-text.d.ts +0 -32
- package/dist/core/plain-text.js +0 -92
- package/dist/core/plugin-dispatch.d.ts +0 -21
- package/dist/core/plugin-dispatch.js +0 -166
- package/dist/core/plugin-point.d.ts +0 -6
- package/dist/core/plugin-point.js +0 -21
- package/dist/core/plugin-registry.d.ts +0 -78
- package/dist/core/plugin-registry.js +0 -485
- package/dist/core/plugin-slot.d.ts +0 -23
- package/dist/core/plugin-slot.js +0 -30
- package/dist/core/plugin.d.ts +0 -125
- package/dist/core/plugin.js +0 -1485
- package/dist/core/prefix-occupant-join.js +0 -52
- package/dist/core/profiling.js +0 -18
- package/dist/core/property-validity.d.ts +0 -14
- package/dist/core/property-validity.js +0 -65
- package/dist/core/public-root.d.ts +0 -10
- package/dist/core/public-root.js +0 -50
- package/dist/core/public-state.d.ts +0 -191
- package/dist/core/public-state.js +0 -6772
- package/dist/core/read-definition.js +0 -22
- package/dist/core/read-registry.js +0 -127
- package/dist/core/record-store.d.ts +0 -12
- package/dist/core/record-store.js +0 -297
- package/dist/core/refusal.d.ts +0 -1
- package/dist/core/refusal.js +0 -40
- package/dist/core/representation.d.ts +0 -11
- package/dist/core/representation.js +0 -844
- package/dist/core/resolved-token-cursor.d.ts +0 -21
- package/dist/core/resolved-token-cursor.js +0 -294
- package/dist/core/root-entries.js +0 -121
- package/dist/core/root-ownership.d.ts +0 -19
- package/dist/core/root-ownership.js +0 -354
- package/dist/core/root-target.d.ts +0 -7
- package/dist/core/root-target.js +0 -281
- package/dist/core/same-result.d.ts +0 -18
- package/dist/core/schema-compiler.d.ts +0 -345
- package/dist/core/schema-compiler.js +0 -3166
- package/dist/core/schema-contribution-registry.d.ts +0 -12
- package/dist/core/schema-contribution-registry.js +0 -88
- package/dist/core/schema-definition.d.ts +0 -307
- package/dist/core/schema-definition.js +0 -628
- package/dist/core/schema-source.internal.d.ts +0 -49
- package/dist/core/schema-validation.d.ts +0 -11
- package/dist/core/schema-validation.js +0 -85
- package/dist/core/screen-reader-announcement.d.ts +0 -13
- package/dist/core/screen-reader-announcement.js +0 -17
- package/dist/core/selection-protocol.d.ts +0 -38
- package/dist/core/selection-protocol.js +0 -523
- package/dist/core/selection-state.js +0 -9
- package/dist/core/semantic-update-method.d.ts +0 -11
- package/dist/core/semantic-update-method.js +0 -26
- package/dist/core/set-root.d.ts +0 -3
- package/dist/core/set-root.js +0 -244
- package/dist/core/slice-end-matter.js +0 -77
- package/dist/core/slice-fit/compiled-slice-fitter.d.ts +0 -56
- package/dist/core/slice-fit/compiled-slice-fitter.js +0 -2087
- package/dist/core/slice-fit/fit-report.d.ts +0 -36
- package/dist/core/slice-fit/fit-report.js +0 -122
- package/dist/core/slice-fit/frontier.js +0 -98
- package/dist/core/slice-fit/origin.js +0 -57
- package/dist/core/slice-fit/provenance.d.ts +0 -30
- package/dist/core/slice-fit/provenance.js +0 -245
- package/dist/core/slice-identities.js +0 -21
- package/dist/core/slice-landing-types.d.ts +0 -61
- package/dist/core/slice-landing.js +0 -124
- package/dist/core/snapshot-index.d.ts +0 -13
- package/dist/core/snapshot-index.js +0 -860
- package/dist/core/state-field.d.ts +0 -12
- package/dist/core/state-field.js +0 -102
- package/dist/core/state-fields.js +0 -36
- package/dist/core/survival.js +0 -61
- package/dist/core/target-runtime.d.ts +0 -5
- package/dist/core/target-runtime.js +0 -42
- package/dist/core/transaction-values.d.ts +0 -47
- package/dist/core/transaction-values.js +0 -66
- package/dist/core/transfer-guard.js +0 -299
- package/dist/core/transfer-types.d.ts +0 -170
- package/dist/core/transfer.d.ts +0 -72
- package/dist/core/transfer.js +0 -655
- package/dist/core/tx-only.d.ts +0 -64
- package/dist/core/tx-only.js +0 -84
- package/dist/core/unique-values.js +0 -298
- package/dist/core/update-context.js +0 -28
- package/dist/core/update-policy.d.ts +0 -17
- package/dist/core/update-policy.js +0 -45
- package/dist/core/value-codec.d.ts +0 -35
- package/dist/core/value-codec.js +0 -240
- package/dist/core/view-carets.d.ts +0 -39
- package/dist/core/view-carets.js +0 -676
- package/dist/core/view-presentation.d.ts +0 -9
- package/dist/core/view-presentation.js +0 -70
- package/dist/core/work.d.ts +0 -192
- package/dist/core/work.js +0 -122
- package/dist/core/writable-text.js +0 -37
- package/dist/create-editor.d.ts +0 -187
- package/dist/create-editor.js +0 -281
- package/dist/diff/lib/compare.d.ts +0 -33
- package/dist/diff/lib/compare.js +0 -459
- package/dist/diff/lib/comparison-align.js +0 -324
- package/dist/diff/lib/comparison-index.js +0 -160
- package/dist/diff/lib/comparison-internal.js +0 -108
- package/dist/diff/lib/comparison-matcher.js +0 -1221
- package/dist/diff/lib/comparison-moves.js +0 -151
- package/dist/diff/lib/comparison-plan.js +0 -556
- package/dist/diff/lib/index.d.ts +0 -3
- package/dist/dom/dom-soft-line-end.d.ts +0 -3
- package/dist/dom/dom-soft-line-end.js +0 -295
- package/dist/dom/internal/index.d.ts +0 -15
- package/dist/dom/plugin/data-transfer-format.d.ts +0 -90
- package/dist/dom/plugin/data-transfer-format.js +0 -525
- package/dist/dom/plugin/dom-clipboard-runtime.d.ts +0 -50
- package/dist/dom/plugin/dom-clipboard-runtime.js +0 -482
- package/dist/dom/plugin/dom-coverage.d.ts +0 -140
- package/dist/dom/plugin/dom-coverage.js +0 -443
- package/dist/dom/plugin/dom-drag-scroll.js +0 -176
- package/dist/dom/plugin/dom-drag.d.ts +0 -54
- package/dist/dom/plugin/dom-drag.js +0 -507
- package/dist/dom/plugin/dom-editor.d.ts +0 -421
- package/dist/dom/plugin/dom-editor.js +0 -1316
- package/dist/dom/plugin/dom-event-range-targets.js +0 -39
- package/dist/dom/plugin/dom-geometry.d.ts +0 -11
- package/dist/dom/plugin/dom-geometry.js +0 -888
- package/dist/dom/plugin/dom-input-runtime.d.ts +0 -1
- package/dist/dom/plugin/dom-input-runtime.js +0 -571
- package/dist/dom/plugin/dom-integrity-observer.js +0 -436
- package/dist/dom/plugin/dom-node-path.js +0 -61
- package/dist/dom/plugin/dom-phase-scheduler.d.ts +0 -1
- package/dist/dom/plugin/dom-phase-scheduler.js +0 -284
- package/dist/dom/plugin/dom-root-runtime.d.ts +0 -10
- package/dist/dom/plugin/dom-root-runtime.js +0 -716
- package/dist/dom/plugin/dom-sync-mutation-ownership.d.ts +0 -1
- package/dist/dom/plugin/dom-sync-mutation-ownership.js +0 -120
- package/dist/dom/plugin/dom-text-flow-index.js +0 -396
- package/dist/dom/plugin/dom-text-freshness.js +0 -188
- package/dist/dom/plugin/dom-text-proofs.d.ts +0 -2
- package/dist/dom/plugin/dom-text-proofs.js +0 -350
- package/dist/dom/plugin/dom-view-caret.js +0 -28
- package/dist/dom/plugin/with-dom.d.ts +0 -53
- package/dist/dom/plugin/with-dom.js +0 -101
- package/dist/dom/utils/constants.d.ts +0 -5
- package/dist/dom/utils/constants.js +0 -5
- package/dist/dom/utils/diff-text.d.ts +0 -51
- package/dist/dom/utils/diff-text.js +0 -264
- package/dist/dom/utils/dom.d.ts +0 -104
- package/dist/dom/utils/dom.js +0 -257
- package/dist/dom/utils/drag-session.d.ts +0 -2
- package/dist/dom/utils/drag-session.js +0 -115
- package/dist/dom/utils/drop-indicator.d.ts +0 -18
- package/dist/dom/utils/drop-indicator.js +0 -36
- package/dist/dom/utils/environment.d.ts +0 -12
- package/dist/dom/utils/environment.js +0 -118
- package/dist/dom/utils/hotkey-match.d.ts +0 -36
- package/dist/dom/utils/hotkey-match.js +0 -208
- package/dist/dom/utils/hotkeys.d.ts +0 -32
- package/dist/dom/utils/hotkeys.js +0 -121
- package/dist/dom/utils/key.d.ts +0 -14
- package/dist/dom/utils/key.js +0 -18
- package/dist/dom/utils/plite-dom-markers.d.ts +0 -26
- package/dist/dom/utils/plite-dom-markers.js +0 -25
- package/dist/dom/utils/selection-writes.d.ts +0 -18
- package/dist/dom/utils/selection-writes.js +0 -63
- package/dist/dom/utils/weak-maps.d.ts +0 -2
- package/dist/dom/utils/weak-maps.js +0 -51
- package/dist/editor/above.js +0 -30
- package/dist/editor/add-mark.js +0 -79
- package/dist/editor/adjacent-character-point.js +0 -120
- package/dist/editor/after.js +0 -37
- package/dist/editor/before.js +0 -124
- package/dist/editor/block-void-break.js +0 -20
- package/dist/editor/correct-document.js +0 -225
- package/dist/editor/delete-backward.js +0 -64
- package/dist/editor/delete-forward.js +0 -11
- package/dist/editor/delete-fragment.js +0 -40
- package/dist/editor/edges.js +0 -5
- package/dist/editor/element-read-only.js +0 -35
- package/dist/editor/end.d.ts +0 -7
- package/dist/editor/end.js +0 -5
- package/dist/editor/exit-break.js +0 -51
- package/dist/editor/first.js +0 -8
- package/dist/editor/get-void.js +0 -9
- package/dist/editor/has-blocks.js +0 -6
- package/dist/editor/has-inlines.js +0 -6
- package/dist/editor/has-path.js +0 -5
- package/dist/editor/has-texts.js +0 -5
- package/dist/editor/insert-break.js +0 -77
- package/dist/editor/insert-default-child.js +0 -55
- package/dist/editor/insert-soft-break.js +0 -14
- package/dist/editor/insert-text.js +0 -83
- package/dist/editor/is-block.js +0 -5
- package/dist/editor/is-edge.js +0 -5
- package/dist/editor/is-editor.js +0 -13
- package/dist/editor/is-empty.js +0 -6
- package/dist/editor/is-end.js +0 -9
- package/dist/editor/is-start.js +0 -9
- package/dist/editor/last.js +0 -20
- package/dist/editor/leaf.js +0 -9
- package/dist/editor/levels.js +0 -21
- package/dist/editor/next.js +0 -46
- package/dist/editor/node.js +0 -9
- package/dist/editor/nodes.js +0 -106
- package/dist/editor/parent.js +0 -14
- package/dist/editor/path.js +0 -26
- package/dist/editor/point.js +0 -52
- package/dist/editor/positions.js +0 -322
- package/dist/editor/previous.js +0 -48
- package/dist/editor/project-range.js +0 -6
- package/dist/editor/range.js +0 -12
- package/dist/editor/remove-mark.js +0 -65
- package/dist/editor/should-merge-nodes-remove-prev-node.js +0 -11
- package/dist/editor/string.js +0 -35
- package/dist/editor/toggle-mark.js +0 -71
- package/dist/editor/unhang-range.js +0 -71
- package/dist/editor-runtime-view.d.ts +0 -33
- package/dist/editor-runtime-view.js +0 -788
- package/dist/history/history-carets.js +0 -127
- package/dist/history/history-character-map.js +0 -425
- package/dist/history/history-codec.js +0 -176
- package/dist/history/history-merge-policy.js +0 -164
- package/dist/history/history-plugin.d.ts +0 -71
- package/dist/history/history-plugin.js +0 -814
- package/dist/history/history-replay.js +0 -799
- package/dist/history/history-selection.js +0 -75
- package/dist/history/history-state.js +0 -1287
- package/dist/history/history.d.ts +0 -112
- package/dist/history/history.js +0 -29
- package/dist/hyperscript/creators.d.ts +0 -51
- package/dist/hyperscript/hyperscript.d.ts +0 -36
- package/dist/hyperscript/hyperscript.js +0 -66
- package/dist/hyperscript/tokens.d.ts +0 -31
- package/dist/hyperscript/tokens.js +0 -63
- package/dist/interfaces/decoration.d.ts +0 -35
- package/dist/interfaces/editor.d.ts +0 -2783
- package/dist/interfaces/editor.js +0 -348
- package/dist/interfaces/element.d.ts +0 -66
- package/dist/interfaces/element.js +0 -34
- package/dist/interfaces/index.d.ts +0 -13
- package/dist/interfaces/json.d.ts +0 -7
- package/dist/interfaces/location.d.ts +0 -50
- package/dist/interfaces/location.js +0 -26
- package/dist/interfaces/node.d.ts +0 -306
- package/dist/interfaces/node.js +0 -339
- package/dist/interfaces/path.d.ts +0 -118
- package/dist/interfaces/path.js +0 -116
- package/dist/interfaces/point.d.ts +0 -45
- package/dist/interfaces/point.js +0 -32
- package/dist/interfaces/range.d.ts +0 -80
- package/dist/interfaces/range.js +0 -85
- package/dist/interfaces/schema-validation.d.ts +0 -33
- package/dist/interfaces/schema.d.ts +0 -870
- package/dist/interfaces/selection.d.ts +0 -61
- package/dist/interfaces/selection.js +0 -106
- package/dist/interfaces/text.d.ts +0 -68
- package/dist/interfaces/text.js +0 -52
- package/dist/interfaces/transforms/node.d.ts +0 -222
- package/dist/interfaces/transforms/selection.d.ts +0 -48
- package/dist/interfaces/transforms/text.d.ts +0 -58
- package/dist/internal/browser-protocol.d.ts +0 -5
- package/dist/internal/document-range.d.ts +0 -9
- package/dist/internal/document-range.js +0 -31
- package/dist/internal/editor-options.d.ts +0 -37
- package/dist/internal/editor-options.js +0 -36
- package/dist/internal/fail-invariant.d.ts +0 -4
- package/dist/internal/fail-invariant.js +0 -6
- package/dist/internal/get-defined.js +0 -7
- package/dist/internal/law-check.js +0 -7
- package/dist/internal/range-text-marks.js +0 -31
- package/dist/internal/root-location.d.ts +0 -23
- package/dist/internal/root-location.js +0 -86
- package/dist/internal/text-run.d.ts +0 -13
- package/dist/internal/text-run.js +0 -44
- package/dist/internal/view/annotation-store-metrics.d.ts +0 -11
- package/dist/internal/view/view-source.d.ts +0 -20
- package/dist/pagination/page-composition.internal.js +0 -313
- package/dist/pagination/page-geometry.internal.js +0 -99
- package/dist/pagination/page-layout-engine-invalidation.internal.js +0 -20
- package/dist/pagination/page-mount-plan.js +0 -84
- package/dist/pagination/paged-view-lines.js +0 -163
- package/dist/range-projection.d.ts +0 -7
- package/dist/range-projection.js +0 -50
- package/dist/react/components/dom-coverage-boundary.d.ts +0 -14
- package/dist/react/components/dom-coverage-boundary.js +0 -143
- package/dist/react/components/editable-descendant-binding.js +0 -70
- package/dist/react/components/editable-dom-commit-fence.js +0 -107
- package/dist/react/components/editable-element-placement.d.ts +0 -2
- package/dist/react/components/editable-element-placement.js +0 -117
- package/dist/react/components/editable-external-text.js +0 -47
- package/dist/react/components/editable-node-equality.js +0 -25
- package/dist/react/components/editable-rendered-element.d.ts +0 -3
- package/dist/react/components/editable-rendered-element.js +0 -61
- package/dist/react/components/editable-text-blocks.d.ts +0 -192
- package/dist/react/components/editable-text-blocks.js +0 -896
- package/dist/react/components/editable-text-containers.d.ts +0 -3
- package/dist/react/components/editable-text-containers.js +0 -28
- package/dist/react/components/editable-text-flow.js +0 -1039
- package/dist/react/components/editable-text-pieces.d.ts +0 -7
- package/dist/react/components/editable-text-pieces.js +0 -193
- package/dist/react/components/editable-text.d.ts +0 -80
- package/dist/react/components/editable-text.js +0 -322
- package/dist/react/components/editable.d.ts +0 -35
- package/dist/react/components/editable.js +0 -406
- package/dist/react/components/editor-announcement-live-region.js +0 -113
- package/dist/react/components/plite-element.d.ts +0 -18
- package/dist/react/components/plite-element.js +0 -54
- package/dist/react/components/plite-leaf.d.ts +0 -18
- package/dist/react/components/plite-leaf.js +0 -21
- package/dist/react/components/plite-placeholder.d.ts +0 -19
- package/dist/react/components/plite-placeholder.js +0 -39
- package/dist/react/components/plite-spacer.js +0 -14
- package/dist/react/components/plite-text.d.ts +0 -23
- package/dist/react/components/plite-text.js +0 -32
- package/dist/react/components/plite-void-shell.js +0 -49
- package/dist/react/components/plite.d.ts +0 -45
- package/dist/react/components/plite.js +0 -297
- package/dist/react/components/text-string.js +0 -18
- package/dist/react/components/windowed-editable.internal.js +0 -51
- package/dist/react/components/zero-width-string.js +0 -26
- package/dist/react/context.js +0 -11
- package/dist/react/decoration-context.d.ts +0 -2
- package/dist/react/decoration-context.js +0 -22
- package/dist/react/decoration-source.d.ts +0 -11
- package/dist/react/decoration-source.js +0 -1030
- package/dist/react/dom-text-sync.d.ts +0 -24
- package/dist/react/dom-text-sync.js +0 -48
- package/dist/react/editable/android-composition.d.ts +0 -3
- package/dist/react/editable/android-composition.js +0 -496
- package/dist/react/editable/browser-handle.js +0 -515
- package/dist/react/editable/caret-engine.js +0 -681
- package/dist/react/editable/clipboard-input-strategy.js +0 -632
- package/dist/react/editable/composition-lease.d.ts +0 -3
- package/dist/react/editable/composition-lease.js +0 -350
- package/dist/react/editable/composition-state.js +0 -716
- package/dist/react/editable/content-root-boundaries.js +0 -79
- package/dist/react/editable/content-root-coordinate-navigation.js +0 -28
- package/dist/react/editable/content-root-navigation-actions.js +0 -190
- package/dist/react/editable/content-root-navigation.js +0 -819
- package/dist/react/editable/content-root-owner-target.js +0 -36
- package/dist/react/editable/content-root-owners.js +0 -191
- package/dist/react/editable/content-root-vertical-geometry.js +0 -60
- package/dist/react/editable/decoration-repair-bridge.js +0 -29
- package/dist/react/editable/dom-coverage-selection.js +0 -158
- package/dist/react/editable/dom-coverage-vertical-selection.js +0 -446
- package/dist/react/editable/dom-input-event.js +0 -14
- package/dist/react/editable/dom-repair-queue.d.ts +0 -7
- package/dist/react/editable/dom-repair-queue.js +0 -543
- package/dist/react/editable/dom-repair-text.js +0 -47
- package/dist/react/editable/editable-command-types.d.ts +0 -1
- package/dist/react/editable/editable-dom-runtime.d.ts +0 -66
- package/dist/react/editable/editable-dom-runtime.js +0 -1022
- package/dist/react/editable/editing-epoch-adapter.js +0 -46
- package/dist/react/editable/editing-kernel.d.ts +0 -7
- package/dist/react/editable/editing-kernel.js +0 -593
- package/dist/react/editable/external-text-binding.js +0 -43
- package/dist/react/editable/external-text-runtime.d.ts +0 -5
- package/dist/react/editable/external-text-runtime.js +0 -851
- package/dist/react/editable/history-focus.js +0 -71
- package/dist/react/editable/history-keyboard.d.ts +0 -4
- package/dist/react/editable/history-keyboard.js +0 -9
- package/dist/react/editable/input-controller.d.ts +0 -7
- package/dist/react/editable/input-controller.js +0 -175
- package/dist/react/editable/input-history.js +0 -21
- package/dist/react/editable/input-router.js +0 -742
- package/dist/react/editable/input-state.d.ts +0 -18
- package/dist/react/editable/input-state.js +0 -330
- package/dist/react/editable/input-target.js +0 -30
- package/dist/react/editable/install-browser-handle.d.ts +0 -12
- package/dist/react/editable/install-browser-handle.js +0 -18
- package/dist/react/editable/interaction-owner.js +0 -88
- package/dist/react/editable/keyboard-input-strategy.js +0 -730
- package/dist/react/editable/line-boundary.js +0 -37
- package/dist/react/editable/model-input-strategy.d.ts +0 -9
- package/dist/react/editable/model-input-strategy.js +0 -242
- package/dist/react/editable/model-selection-dom-preference.js +0 -11
- package/dist/react/editable/mutation-block-editing.js +0 -48
- package/dist/react/editable/mutation-controller.d.ts +0 -32
- package/dist/react/editable/mutation-controller.js +0 -632
- package/dist/react/editable/mutation-full-block-editing.d.ts +0 -2
- package/dist/react/editable/mutation-full-block-editing.js +0 -44
- package/dist/react/editable/mutation-history.d.ts +0 -3
- package/dist/react/editable/mutation-history.js +0 -146
- package/dist/react/editable/native-input-strategy.js +0 -86
- package/dist/react/editable/native-text-input-delta.js +0 -40
- package/dist/react/editable/placed-drag.js +0 -177
- package/dist/react/editable/plite-string-coordinate-placement.js +0 -46
- package/dist/react/editable/press-fence.d.ts +0 -2
- package/dist/react/editable/press-fence.js +0 -70
- package/dist/react/editable/projected-clipboard.js +0 -123
- package/dist/react/editable/projected-native-affordance.js +0 -30
- package/dist/react/editable/projected-selection-target.js +0 -13
- package/dist/react/editable/render-contract-monitor.d.ts +0 -3
- package/dist/react/editable/render-contract-monitor.js +0 -152
- package/dist/react/editable/root-interaction-controller.js +0 -1400
- package/dist/react/editable/root-interaction-dom-selection-replay.js +0 -40
- package/dist/react/editable/root-interaction-resolver.js +0 -116
- package/dist/react/editable/root-selector-sources.js +0 -90
- package/dist/react/editable/runtime-android-engine.js +0 -40
- package/dist/react/editable/runtime-before-input-events.js +0 -671
- package/dist/react/editable/runtime-browser-handle-events.js +0 -40
- package/dist/react/editable/runtime-clipboard-events.js +0 -169
- package/dist/react/editable/runtime-composition-events.js +0 -163
- package/dist/react/editable/runtime-drag-events.js +0 -136
- package/dist/react/editable/runtime-editor-api.d.ts +0 -20
- package/dist/react/editable/runtime-editor-api.js +0 -21
- package/dist/react/editable/runtime-event-engine.js +0 -213
- package/dist/react/editable/runtime-focus-mouse-events.js +0 -264
- package/dist/react/editable/runtime-input-events.js +0 -166
- package/dist/react/editable/runtime-kernel-trace.js +0 -185
- package/dist/react/editable/runtime-keyboard-events.js +0 -333
- package/dist/react/editable/runtime-live-state.js +0 -44
- package/dist/react/editable/runtime-mutation-state.js +0 -11
- package/dist/react/editable/runtime-repair-engine.js +0 -118
- package/dist/react/editable/runtime-root-engine.js +0 -244
- package/dist/react/editable/runtime-root-lifecycle.js +0 -118
- package/dist/react/editable/runtime-root-selection-export.js +0 -38
- package/dist/react/editable/runtime-root-selection-import.js +0 -54
- package/dist/react/editable/runtime-root-state.js +0 -62
- package/dist/react/editable/runtime-selection-engine.js +0 -260
- package/dist/react/editable/runtime-selection-state.js +0 -12
- package/dist/react/editable/runtime-target-bridge.js +0 -29
- package/dist/react/editable/schema-runtime-invalidation.js +0 -26
- package/dist/react/editable/selection-change-listener.js +0 -99
- package/dist/react/editable/selection-claim.d.ts +0 -3
- package/dist/react/editable/selection-claim.js +0 -398
- package/dist/react/editable/selection-controller.d.ts +0 -8
- package/dist/react/editable/selection-controller.js +0 -693
- package/dist/react/editable/selection-dom-range.js +0 -84
- package/dist/react/editable/selection-projected-dom.js +0 -156
- package/dist/react/editable/selection-reconciler.js +0 -630
- package/dist/react/editable/selection-runtime.js +0 -89
- package/dist/react/editable/selection-side-effect-policy.js +0 -20
- package/dist/react/editable/selection-triple-click.js +0 -48
- package/dist/react/editable/selection-void-target.js +0 -172
- package/dist/react/editable/set-root-endpoints.js +0 -75
- package/dist/react/editable/soft-line-end-delete.js +0 -106
- package/dist/react/editable/text-direction.js +0 -82
- package/dist/react/editable/typed-text.d.ts +0 -17
- package/dist/react/editable/typed-text.js +0 -89
- package/dist/react/editable/unread-press.d.ts +0 -2
- package/dist/react/editable/unread-press.js +0 -86
- package/dist/react/editable/view-caret-restore.js +0 -128
- package/dist/react/editable/view-lines.d.ts +0 -7
- package/dist/react/editable/view-lines.js +0 -166
- package/dist/react/external-text.d.ts +0 -131
- package/dist/react/history-step-views.d.ts +0 -4
- package/dist/react/history-step-views.js +0 -119
- package/dist/react/hooks/android-input-manager/android-input-manager.d.ts +0 -7
- package/dist/react/hooks/android-input-manager/android-input-manager.js +0 -716
- package/dist/react/hooks/android-input-manager/use-android-input-manager.js +0 -53
- package/dist/react/hooks/focus-plite-editable.js +0 -116
- package/dist/react/hooks/use-claim-editable-dom-commit.d.ts +0 -12
- package/dist/react/hooks/use-claim-editable-dom-commit.js +0 -31
- package/dist/react/hooks/use-drop-indicator.d.ts +0 -9
- package/dist/react/hooks/use-drop-indicator.js +0 -14
- package/dist/react/hooks/use-editable-clip.d.ts +0 -18
- package/dist/react/hooks/use-editable-clip.js +0 -31
- package/dist/react/hooks/use-editable-layout-pass.js +0 -53
- package/dist/react/hooks/use-editor-composing.d.ts +0 -7
- package/dist/react/hooks/use-editor-composing.js +0 -12
- package/dist/react/hooks/use-editor-context.d.ts +0 -10
- package/dist/react/hooks/use-editor-context.js +0 -18
- package/dist/react/hooks/use-editor-dom-scope.d.ts +0 -27
- package/dist/react/hooks/use-editor-dom-scope.js +0 -23
- package/dist/react/hooks/use-editor-focused.d.ts +0 -7
- package/dist/react/hooks/use-editor-focused.js +0 -12
- package/dist/react/hooks/use-editor-read-only.d.ts +0 -25
- package/dist/react/hooks/use-editor-read-only.js +0 -19
- package/dist/react/hooks/use-editor-runtime-state.d.ts +0 -18
- package/dist/react/hooks/use-editor-runtime-state.js +0 -38
- package/dist/react/hooks/use-editor-selection.d.ts +0 -10
- package/dist/react/hooks/use-editor-selection.js +0 -13
- package/dist/react/hooks/use-editor-selector.d.ts +0 -38
- package/dist/react/hooks/use-editor-selector.js +0 -265
- package/dist/react/hooks/use-editor-view-state.d.ts +0 -16
- package/dist/react/hooks/use-editor-view-state.js +0 -20
- package/dist/react/hooks/use-editor.d.ts +0 -26
- package/dist/react/hooks/use-editor.js +0 -27
- package/dist/react/hooks/use-element-path.d.ts +0 -7
- package/dist/react/hooks/use-element-path.js +0 -36
- package/dist/react/hooks/use-element-selected.d.ts +0 -26
- package/dist/react/hooks/use-element-selected.js +0 -91
- package/dist/react/hooks/use-element.d.ts +0 -13
- package/dist/react/hooks/use-element.js +0 -17
- package/dist/react/hooks/use-generic-selector.js +0 -91
- package/dist/react/hooks/use-hydrated.js +0 -12
- package/dist/react/hooks/use-isomorphic-layout-effect.js +0 -9
- package/dist/react/hooks/use-node-selector.d.ts +0 -40
- package/dist/react/hooks/use-node-selector.js +0 -102
- package/dist/react/hooks/use-plite-annotation-store.d.ts +0 -21
- package/dist/react/hooks/use-plite-annotation-store.js +0 -61
- package/dist/react/hooks/use-plite-annotations.d.ts +0 -9
- package/dist/react/hooks/use-plite-annotations.js +0 -16
- package/dist/react/hooks/use-plite-child-root.d.ts +0 -14
- package/dist/react/hooks/use-plite-child-root.js +0 -38
- package/dist/react/hooks/use-plite-content-root.d.ts +0 -21
- package/dist/react/hooks/use-plite-content-root.js +0 -26
- package/dist/react/hooks/use-plite-history.d.ts +0 -43
- package/dist/react/hooks/use-plite-history.js +0 -137
- package/dist/react/hooks/use-plite-node-ref.js +0 -513
- package/dist/react/hooks/use-plite-root-chrome.d.ts +0 -34
- package/dist/react/hooks/use-plite-root-chrome.js +0 -98
- package/dist/react/hooks/use-plite-runtime.d.ts +0 -86
- package/dist/react/hooks/use-plite-runtime.js +0 -433
- package/dist/react/hooks/use-runtime-focus-state.js +0 -37
- package/dist/react/hooks/use-selection-geometry.d.ts +0 -12
- package/dist/react/hooks/use-selection-geometry.js +0 -39
- package/dist/react/hooks/use-selection-view.d.ts +0 -14
- package/dist/react/hooks/use-selection-view.js +0 -14
- package/dist/react/hooks/use-state-field.d.ts +0 -26
- package/dist/react/hooks/use-state-field.js +0 -38
- package/dist/react/inactive-selection.js +0 -175
- package/dist/react/plugin/react-editor.d.ts +0 -20
- package/dist/react/plugin/react-editor.js +0 -6
- package/dist/react/plugin/with-react.d.ts +0 -108
- package/dist/react/plugin/with-react.js +0 -58
- package/dist/react/render-profiler.js +0 -20
- package/dist/react/root-key.js +0 -12
- package/dist/react/shell-runtime.js +0 -29
- package/dist/react/update-policy.d.ts +0 -10
- package/dist/react/update-policy.js +0 -15
- package/dist/react/utils/environment.js +0 -5
- package/dist/react/view-boundary-graph-core.d.ts +0 -1
- package/dist/react/view-boundary-graph-core.js +0 -208
- package/dist/react/view-boundary-graph.js +0 -105
- package/dist/react/view-selection-decoration.js +0 -97
- package/dist/react/view-selection.js +0 -184
- package/dist/react/viewport-boundary.js +0 -45
- package/dist/react/viewport-commands.d.ts +0 -1
- package/dist/react/viewport-commands.js +0 -17
- package/dist/react/viewport-plan.d.ts +0 -2
- package/dist/react/viewport-plan.js +0 -77
- package/dist/react/virtualized/use-virtualized-root-plan.js +0 -148
- package/dist/testing/createDataTransfer.d.ts +0 -4
- package/dist/testing/createDataTransfer.js +0 -13
- package/dist/testing/jsx.d.ts +0 -181
- package/dist/testing/jsx.js +0 -82
- package/dist/transforms-node/insert-nodes.js +0 -143
- package/dist/transforms-node/lift-nodes.js +0 -117
- package/dist/transforms-node/merge-nodes.js +0 -180
- package/dist/transforms-node/move-nodes.js +0 -58
- package/dist/transforms-node/remove-nodes.js +0 -86
- package/dist/transforms-node/replace-children.js +0 -117
- package/dist/transforms-node/set-nodes.js +0 -188
- package/dist/transforms-node/split-nodes.js +0 -258
- package/dist/transforms-node/unset-nodes.js +0 -10
- package/dist/transforms-node/unwrap-nodes.js +0 -182
- package/dist/transforms-node/wrap-nodes.js +0 -250
- package/dist/transforms-selection/collapse.js +0 -20
- package/dist/transforms-selection/deselect.js +0 -8
- package/dist/transforms-selection/move.js +0 -35
- package/dist/transforms-selection/select.js +0 -59
- package/dist/transforms-selection/set-point.js +0 -32
- package/dist/transforms-selection/set-selection.js +0 -52
- package/dist/transforms-text/delete-text-collapsed-path-targets.js +0 -102
- package/dist/transforms-text/delete-text-grid.js +0 -402
- package/dist/transforms-text/delete-text-inline-points.js +0 -82
- package/dist/transforms-text/delete-text-plan.js +0 -55
- package/dist/transforms-text/delete-text-removal.js +0 -153
- package/dist/transforms-text/delete-text-structural-cleanup.js +0 -130
- package/dist/transforms-text/delete-text-whole-blocks.js +0 -70
- package/dist/transforms-text/delete-text.js +0 -804
- package/dist/transforms-text/full-document-range.js +0 -12
- package/dist/transforms-text/insert-text.js +0 -314
- package/dist/types/types.d.ts +0 -13
- package/dist/utils/format-debug-value.d.ts +0 -8
- package/dist/utils/format-debug-value.js +0 -31
- package/dist/utils/get-default-insert-location.js +0 -19
- package/dist/utils/is-object.d.ts +0 -4
- package/dist/utils/is-object.js +0 -4
- package/dist/utils/match-path.js +0 -8
- package/dist/utils/node-keys.d.ts +0 -15
- package/dist/utils/node-keys.js +0 -179
- package/dist/utils/node-match.js +0 -9
- package/dist/utils/string.js +0 -283
- package/dist/yjs/core/addresses.js +0 -98
- package/dist/yjs/core/ancestor-properties.js +0 -56
- package/dist/yjs/core/attributes.js +0 -21
- package/dist/yjs/core/awareness-adapter.d.ts +0 -5
- package/dist/yjs/core/awareness-adapter.js +0 -399
- package/dist/yjs/core/awareness-relative-selection.js +0 -22
- package/dist/yjs/core/awareness.js +0 -25
- package/dist/yjs/core/binding.d.ts +0 -3
- package/dist/yjs/core/binding.js +0 -128
- package/dist/yjs/core/boundaries.js +0 -453
- package/dist/yjs/core/canonical-split.js +0 -130
- package/dist/yjs/core/change-bridge.js +0 -124
- package/dist/yjs/core/change-regions.js +0 -119
- package/dist/yjs/core/controller-registry.js +0 -70
- package/dist/yjs/core/controller.d.ts +0 -6
- package/dist/yjs/core/controller.js +0 -1282
- package/dist/yjs/core/document.js +0 -1499
- package/dist/yjs/core/editor-adapter.d.ts +0 -18
- package/dist/yjs/core/editor-adapter.js +0 -145
- package/dist/yjs/core/editor-only-roots.js +0 -53
- package/dist/yjs/core/editor-types.d.ts +0 -1
- package/dist/yjs/core/enclosures.js +0 -410
- package/dist/yjs/core/event-change-bridge.js +0 -3642
- package/dist/yjs/core/index.d.ts +0 -4
- package/dist/yjs/core/joined-lines.js +0 -81
- package/dist/yjs/core/joins.js +0 -587
- package/dist/yjs/core/json-equality.js +0 -31
- package/dist/yjs/core/keys.js +0 -29
- package/dist/yjs/core/letter-scripts.js +0 -449
- package/dist/yjs/core/new-letters.js +0 -300
- package/dist/yjs/core/path.js +0 -25
- package/dist/yjs/core/plugin.js +0 -206
- package/dist/yjs/core/record.js +0 -4
- package/dist/yjs/core/replacement.js +0 -165
- package/dist/yjs/core/retraction.js +0 -132
- package/dist/yjs/core/root-owners.js +0 -110
- package/dist/yjs/core/root-projection-index.js +0 -428
- package/dist/yjs/core/schema-metadata.js +0 -88
- package/dist/yjs/core/selection.js +0 -34
- package/dist/yjs/core/set-valued-attributes.js +0 -57
- package/dist/yjs/core/shared-effect-log.d.ts +0 -4
- package/dist/yjs/core/shared-effect-log.js +0 -674
- package/dist/yjs/core/text-runs.js +0 -1596
- package/dist/yjs/core/types.d.ts +0 -76
- package/dist/yjs/react/useYjs.d.ts +0 -25
- package/dist/yjs/react/useYjs.js +0 -85
|
@@ -1,2087 +0,0 @@
|
|
|
1
|
-
import { getDefined } from "../../internal/get-defined.js";
|
|
2
|
-
import { cloneFrozen } from "../clone.js";
|
|
3
|
-
import { assertEditorJsonValue, snapshotEditorJsonValue } from "../value-codec.js";
|
|
4
|
-
import { recordStoreFromJson, showValueRecords } from "../record-store.js";
|
|
5
|
-
import { PreparedTokenSlice, PreparedTokenSliceStructureError, commonSuffixLength, encodeNodes, getPreparedDocumentSlice } from "../change/tokens.js";
|
|
6
|
-
import { DocumentIndex, decodeNodes } from "../change/document-index.js";
|
|
7
|
-
import { profileCoreDuration } from "../profiling.js";
|
|
8
|
-
import { RootChange, reconcileChildrenStep } from "../change/root-change.js";
|
|
9
|
-
import { DocumentChange, assertNamedDocumentRootKey, createInternalDocumentChange, getInternalDocumentChangeEntries, mapInternalDocumentChangePosition } from "../change/document-change.js";
|
|
10
|
-
import { historyFollowsAllFacts } from "../change/record.js";
|
|
11
|
-
import { ChangeDraft } from "../change/builder.js";
|
|
12
|
-
import { RangeApi } from "../../interfaces/range.js";
|
|
13
|
-
import { ElementApi } from "../../interfaces/element.js";
|
|
14
|
-
import { SelectionApi } from "../../interfaces/selection.js";
|
|
15
|
-
import { getEditorDocumentShapeIssueMessage, readEditorDocument } from "../document-shape.js";
|
|
16
|
-
import { resolveCompiledSchemaProperty, resolveCompiledSchemaWrapperPlan } from "../schema-compiler.js";
|
|
17
|
-
import { toPublicRoot } from "../public-root.js";
|
|
18
|
-
import { ContentSlice, encodeContentSlice, encodeContentSliceContent, isDetachedContentSlice } from "../content-slice.js";
|
|
19
|
-
import { EditorSchemaValidationError } from "../schema-validation.js";
|
|
20
|
-
import { sliceFacts } from "../change/slice-facts.js";
|
|
21
|
-
import { getReplaceableEmptyBlock, holdsNoContent } from "../is-empty-element.js";
|
|
22
|
-
import { bindCanonicalFitPreparation, constructCanonicalDocumentChange, getProtectedInlineSpacerEntries, isLoadedDocumentCanonical, mapCanonicalRepresentationPoint, prepareCanonicalFitSlice, prepareCanonicalRootFit } from "../representation.js";
|
|
23
|
-
import { mapSelectionWithContext } from "../selection-protocol.js";
|
|
24
|
-
import { EditorSchemaFitRepairCollector, resolveRepresentationRepairs, schemaModelLocation, schemaRepair } from "./fit-report.js";
|
|
25
|
-
import { selectSliceFitCandidate } from "./frontier.js";
|
|
26
|
-
import { FitOriginLog, sliceOrigins } from "./origin.js";
|
|
27
|
-
import { createRootFitPathProvenance, getTextEdge, isLandingMove, landedRelocations, pointsEqual, visitDescendantPaths } from "./provenance.js";
|
|
28
|
-
import { NodeApi } from "../../interfaces/node.js";
|
|
29
|
-
//#region src/core/slice-fit/compiled-slice-fitter.ts
|
|
30
|
-
const withoutUnchangedTail = (document, candidate) => {
|
|
31
|
-
if (candidate.semanticChange || candidate.to === candidate.from) return candidate;
|
|
32
|
-
const limit = Math.min(candidate.to - candidate.from, candidate.insert.length);
|
|
33
|
-
const tail = commonSuffixLength(document.slice(candidate.to - limit, candidate.to).tokens, candidate.insert.tokens, limit);
|
|
34
|
-
const identical = tail === candidate.insert.length && tail === candidate.to - candidate.from;
|
|
35
|
-
return tail === 0 || identical ? candidate : Object.freeze({
|
|
36
|
-
...candidate,
|
|
37
|
-
insert: candidate.insert.slice(0, candidate.insert.length - tail),
|
|
38
|
-
to: candidate.to - tail
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* A move's raw landing, with the relocations that tie each landed text to
|
|
43
|
-
* the text it came from, so the canonical pass can judge a value it carried.
|
|
44
|
-
*/
|
|
45
|
-
const landedMove = (builder, change) => {
|
|
46
|
-
if (!builder.tracksPlaces || !isLandingMove()) return {};
|
|
47
|
-
const indexedAfter = /* @__PURE__ */ new Map();
|
|
48
|
-
const relocations = [];
|
|
49
|
-
for (const [root, rootChange] of getInternalDocumentChangeEntries(change)) {
|
|
50
|
-
const after = rootChange.apply(builder.getIndex(root));
|
|
51
|
-
indexedAfter.set(root, after);
|
|
52
|
-
relocations.push(...landedRelocations(root, after, rootChange));
|
|
53
|
-
}
|
|
54
|
-
return relocations.length > 0 ? {
|
|
55
|
-
indexedAfter,
|
|
56
|
-
relocations
|
|
57
|
-
} : {};
|
|
58
|
-
};
|
|
59
|
-
const fittedFacts = (builder, change) => historyFollowsAllFacts() ? sliceFacts(change, (root) => builder.getIndex(root)) : void 0;
|
|
60
|
-
const compileSliceFitter = (input) => {
|
|
61
|
-
const { canContain, collectPropertyRepairs, contentAllows, contentAllowsAt, createDeclarativeAndFill, editorRootLabel, elementUsesInlineContent, getCompiledElement, getDescendant, getDocumentRoot, getDocumentRootProgram, getEditor, getElementAncestors, getElementBehavior, getElementContentRoots, getElementSlicePolicy, getElementType, getRootContent, getVocabulary, indexConstructedRoot, isSetValuedProperty, nodePropertiesEqual, observeRootCanonicalization, revision, schema, schemaApi: api, structurallyEqual, validateDeclarativeChildren, validateDocument, validateSliceVocabulary, withoutGeneration } = input;
|
|
62
|
-
const getDeclarativeSchema = () => schema;
|
|
63
|
-
const contentSchema = {
|
|
64
|
-
getElementBehavior,
|
|
65
|
-
getElementContentRoots
|
|
66
|
-
};
|
|
67
|
-
const isGridCell = (element) => {
|
|
68
|
-
const structure = getCompiledElement(element)?.structure;
|
|
69
|
-
return structure?.kind === "grid" && structure.role === "cell";
|
|
70
|
-
};
|
|
71
|
-
const reportRepair = (options, repair, sources = []) => {
|
|
72
|
-
const { report } = options;
|
|
73
|
-
report?.repairs.push(schemaRepair({
|
|
74
|
-
...repair,
|
|
75
|
-
inputs: sources.flatMap((node) => report.inputsOf(node).map((path) => schemaModelLocation(options.root ?? "main", path))),
|
|
76
|
-
owner: "grammar"
|
|
77
|
-
}));
|
|
78
|
-
};
|
|
79
|
-
const allContentAllowed = (candidateSchema, content, source, from = 0, to = source.length) => {
|
|
80
|
-
const allowedByKind = /* @__PURE__ */ new Map();
|
|
81
|
-
for (let index = from; index < to; index++) {
|
|
82
|
-
const child = source[index];
|
|
83
|
-
const kind = NodeApi.isText(child) ? null : getElementType(child) ?? "";
|
|
84
|
-
let allowed = allowedByKind.get(kind);
|
|
85
|
-
if (allowed === void 0) {
|
|
86
|
-
allowed = contentAllows(candidateSchema, content, child);
|
|
87
|
-
allowedByKind.set(kind, allowed);
|
|
88
|
-
}
|
|
89
|
-
if (!allowed) return false;
|
|
90
|
-
}
|
|
91
|
-
return true;
|
|
92
|
-
};
|
|
93
|
-
const acceptsReplacement = (candidateSchema, content, children, from, to, inserted, options) => {
|
|
94
|
-
const shift = to - from - inserted.length;
|
|
95
|
-
const length = children.length - shift;
|
|
96
|
-
const prefix = content.remainder && content.prefix || [];
|
|
97
|
-
const rest = content.prefix && content.remainder || content;
|
|
98
|
-
const start = prefix.length;
|
|
99
|
-
for (const index of prefix.keys()) {
|
|
100
|
-
const child = index < from ? children[index] : index < from + inserted.length ? inserted[index - from] : children[index + shift];
|
|
101
|
-
if (!child || !contentAllowsAt(candidateSchema, content, child, index, options)) return false;
|
|
102
|
-
}
|
|
103
|
-
return length - start >= rest.min && (rest.max === null || length - start <= rest.max) && (content.max === null || length <= content.max) && allContentAllowed(candidateSchema, rest, children, start, from) && allContentAllowed(candidateSchema, rest, inserted, Math.max(start - from, 0)) && allContentAllowed(candidateSchema, rest, children, Math.max(start + shift, to));
|
|
104
|
-
};
|
|
105
|
-
const createDefaultForContent = (innerSchema, content, creating, options) => {
|
|
106
|
-
const plan = content.defaultPlan;
|
|
107
|
-
if (plan?.kind === "text") return { text: "" };
|
|
108
|
-
if (!plan || creating.has(plan.type)) return null;
|
|
109
|
-
return createDeclarativeAndFill(innerSchema, plan.type, plan.properties, creating, options);
|
|
110
|
-
};
|
|
111
|
-
const fitDirectContent = (innerSchema2, content, source, createdDefaults = [], options = {}) => {
|
|
112
|
-
if (content.prefix && content.remainder) {
|
|
113
|
-
const fitted = [];
|
|
114
|
-
let consumed = 0;
|
|
115
|
-
for (const [index, slot] of content.prefix.entries()) {
|
|
116
|
-
const candidate = source[consumed];
|
|
117
|
-
if (candidate && contentAllowsAt(innerSchema2, content, candidate, index, options)) {
|
|
118
|
-
fitted.push(candidate);
|
|
119
|
-
consumed += 1;
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
fitted.push(createDeclarativeAndFill(innerSchema2, slot.type, slot.properties, /* @__PURE__ */ new Set(), options));
|
|
123
|
-
reportRepair(options, {
|
|
124
|
-
code: "insert-required-content",
|
|
125
|
-
impact: "lossless",
|
|
126
|
-
outputs: [schemaModelLocation(options.root ?? "main", [...options.path ?? [], fitted.length - 1])]
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
const remainder = fitDirectContent(innerSchema2, content.remainder, source.slice(consumed), [], options);
|
|
130
|
-
if (!remainder || content.max !== null && fitted.length + remainder.length > content.max) return null;
|
|
131
|
-
return Object.freeze([...fitted, ...remainder]);
|
|
132
|
-
}
|
|
133
|
-
if (content.max !== null && source.length > content.max || !allContentAllowed(innerSchema2, content, source)) return null;
|
|
134
|
-
const fitted = [...source];
|
|
135
|
-
while (fitted.length < content.min) {
|
|
136
|
-
const createdDefault = createdDefaults[fitted.length];
|
|
137
|
-
const child = createdDefault && contentAllows(innerSchema2, content, createdDefault) ? createdDefault : createDefaultForContent(innerSchema2, content, /* @__PURE__ */ new Set(), options);
|
|
138
|
-
if (!child) return null;
|
|
139
|
-
fitted.push(child);
|
|
140
|
-
reportRepair(options, {
|
|
141
|
-
code: "insert-required-content",
|
|
142
|
-
impact: "lossless",
|
|
143
|
-
outputs: [schemaModelLocation(options.root ?? "main", [...options.path ?? [], fitted.length - 1])]
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
return Object.freeze(fitted);
|
|
147
|
-
};
|
|
148
|
-
const createWrappedContent = (innerSchema3, wrappers, source, options = {}) => {
|
|
149
|
-
const created = [];
|
|
150
|
-
const ancestors = [...options.ancestors ?? []];
|
|
151
|
-
for (const type of wrappers) {
|
|
152
|
-
const wrapper = createDeclarativeAndFill(innerSchema3, type, void 0, /* @__PURE__ */ new Set(), {
|
|
153
|
-
ancestors,
|
|
154
|
-
root: options.root
|
|
155
|
-
});
|
|
156
|
-
created.push(wrapper);
|
|
157
|
-
ancestors.unshift(wrapper);
|
|
158
|
-
}
|
|
159
|
-
let children = [...source];
|
|
160
|
-
for (const wrapper of created.toReversed()) {
|
|
161
|
-
const content = getCompiledElement(wrapper)?.content;
|
|
162
|
-
const fitted = content ? fitDirectContent(innerSchema3, content, children, wrapper.children, options) : children;
|
|
163
|
-
if (!fitted) return null;
|
|
164
|
-
children = [{
|
|
165
|
-
...wrapper,
|
|
166
|
-
children: [...fitted]
|
|
167
|
-
}];
|
|
168
|
-
}
|
|
169
|
-
if (wrappers.length > 0) reportRepair(options, {
|
|
170
|
-
code: "wrap-content",
|
|
171
|
-
impact: "lossless",
|
|
172
|
-
outputs: [schemaModelLocation(options.root ?? "main", options.path ?? [])]
|
|
173
|
-
}, source);
|
|
174
|
-
return children;
|
|
175
|
-
};
|
|
176
|
-
const wrapperGroupHasCapacity = (wrappers, childCount) => {
|
|
177
|
-
const innermost = wrappers.at(-1);
|
|
178
|
-
const maximum = innermost ? getDeclarativeSchema()?.elements.byType.get(innermost)?.content?.max : null;
|
|
179
|
-
return maximum === null || maximum === void 0 || childCount < maximum;
|
|
180
|
-
};
|
|
181
|
-
const findWrapping = (parent, child) => {
|
|
182
|
-
if (canContain(parent, child)) return [];
|
|
183
|
-
const innerSchema4 = getDeclarativeSchema();
|
|
184
|
-
const parentType = getElementType(parent);
|
|
185
|
-
const childType = NodeApi.isText(child) ? null : getElementType(child);
|
|
186
|
-
if (!innerSchema4 || !parentType || !NodeApi.isText(child) && !childType) return null;
|
|
187
|
-
return resolveCompiledSchemaWrapperPlan(innerSchema4, `element:${parentType}`, childType);
|
|
188
|
-
};
|
|
189
|
-
const findWrappingForContent = (innerSchema5, programId, content, child) => {
|
|
190
|
-
if (contentAllows(innerSchema5, content, child)) return [];
|
|
191
|
-
const childType = NodeApi.isText(child) ? null : getElementType(child);
|
|
192
|
-
if (!NodeApi.isText(child) && !childType) return null;
|
|
193
|
-
return resolveCompiledSchemaWrapperPlan(innerSchema5, programId, childType);
|
|
194
|
-
};
|
|
195
|
-
const fitClosedNode = (innerSchema6, node, options) => {
|
|
196
|
-
const retainOrigin = (output, subtree = false) => {
|
|
197
|
-
options.fitOrigins?.record(output, node);
|
|
198
|
-
if (subtree && ElementApi.isElement(node)) visitDescendantPaths(node.children, (descendant) => {
|
|
199
|
-
options.fitOrigins?.record(descendant, descendant);
|
|
200
|
-
});
|
|
201
|
-
return output;
|
|
202
|
-
};
|
|
203
|
-
if (NodeApi.isText(node)) return retainOrigin(node);
|
|
204
|
-
const type = getElementType(node);
|
|
205
|
-
const element = type ? innerSchema6.elements.byType.get(type) : void 0;
|
|
206
|
-
if (!element) return innerSchema6.unknown === "preserve" ? retainOrigin(node, true) : null;
|
|
207
|
-
if (!element.content) return retainOrigin(node, true);
|
|
208
|
-
const children = fitClosedContent(innerSchema6, `element:${type}`, element.content, node.children, {
|
|
209
|
-
ancestors: [node, ...options.ancestors ?? []],
|
|
210
|
-
fitOrigins: options.fitOrigins,
|
|
211
|
-
path: options.path,
|
|
212
|
-
report: options.report,
|
|
213
|
-
root: options.root
|
|
214
|
-
}, true);
|
|
215
|
-
if (!children) return null;
|
|
216
|
-
if (children.length === node.children.length && children.every((child, index) => child === node.children[index])) return retainOrigin(node, true);
|
|
217
|
-
return retainOrigin({
|
|
218
|
-
...node,
|
|
219
|
-
children: [...children]
|
|
220
|
-
});
|
|
221
|
-
};
|
|
222
|
-
const fitClosedDefaultShell = (innerSchema7, content, node, options) => {
|
|
223
|
-
const plan = content.defaultPlan;
|
|
224
|
-
if (plan?.kind !== "element") return null;
|
|
225
|
-
const shell = createDeclarativeAndFill(innerSchema7, plan.type, plan.properties, /* @__PURE__ */ new Set(), options);
|
|
226
|
-
const shellContent = innerSchema7.elements.byType.get(plan.type)?.content;
|
|
227
|
-
if (!shellContent) return null;
|
|
228
|
-
const children = fitClosedContent(innerSchema7, `element:${plan.type}`, shellContent, node.children, {
|
|
229
|
-
ancestors: [shell, ...options.ancestors ?? []],
|
|
230
|
-
fitOrigins: options.fitOrigins,
|
|
231
|
-
path: options.path,
|
|
232
|
-
report: options.report,
|
|
233
|
-
root: options.root
|
|
234
|
-
}, true);
|
|
235
|
-
if (!children) return null;
|
|
236
|
-
const fitted = {
|
|
237
|
-
...shell,
|
|
238
|
-
children: [...children]
|
|
239
|
-
};
|
|
240
|
-
options.fitOrigins?.record(fitted, node);
|
|
241
|
-
reportRepair(options, {
|
|
242
|
-
code: "replace-element-shell",
|
|
243
|
-
impact: "lossy",
|
|
244
|
-
outputs: [schemaModelLocation(options.root ?? "main", options.path ?? [])]
|
|
245
|
-
}, [node]);
|
|
246
|
-
return fitted;
|
|
247
|
-
};
|
|
248
|
-
function fitClosedContent(innerSchema7, programId, content, source, options = {}, coerceDefaultShell = false, dropMisplacedText = false) {
|
|
249
|
-
if (content.prefix) {
|
|
250
|
-
const closed = source.map((child, index) => fitClosedNode(innerSchema7, child, {
|
|
251
|
-
...options,
|
|
252
|
-
path: [...options.path ?? [], index]
|
|
253
|
-
}));
|
|
254
|
-
return closed.some((child) => child === null) ? null : fitDirectContent(innerSchema7, content, closed, [], options);
|
|
255
|
-
}
|
|
256
|
-
const groups = [];
|
|
257
|
-
for (const [sourceIndex, sourceChild] of source.entries()) {
|
|
258
|
-
const child = fitClosedNode(innerSchema7, sourceChild, {
|
|
259
|
-
...options,
|
|
260
|
-
path: [...options.path ?? [], sourceIndex]
|
|
261
|
-
});
|
|
262
|
-
if (!child) return null;
|
|
263
|
-
let wrappers = findWrappingForContent(innerSchema7, programId, content, child);
|
|
264
|
-
let fittedChild = child;
|
|
265
|
-
if (!wrappers && coerceDefaultShell && ElementApi.isElement(child)) {
|
|
266
|
-
const shell = fitClosedDefaultShell(innerSchema7, content, child, {
|
|
267
|
-
...options,
|
|
268
|
-
path: [...options.path ?? [], sourceIndex]
|
|
269
|
-
});
|
|
270
|
-
if (shell) {
|
|
271
|
-
fittedChild = shell;
|
|
272
|
-
wrappers = [];
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
if (!wrappers) {
|
|
276
|
-
if (dropMisplacedText && NodeApi.isText(child)) {
|
|
277
|
-
reportRepair(options, {
|
|
278
|
-
code: "drop-unplaceable-text",
|
|
279
|
-
impact: "lossy"
|
|
280
|
-
}, [sourceChild]);
|
|
281
|
-
continue;
|
|
282
|
-
}
|
|
283
|
-
return null;
|
|
284
|
-
}
|
|
285
|
-
const previous = groups.at(-1);
|
|
286
|
-
if (wrappers.length > 0 && previous && previous.wrappers.length === wrappers.length && wrappers.every((type, index) => type === previous.wrappers[index]) && wrapperGroupHasCapacity(wrappers, previous.children.length)) previous.children.push(fittedChild);
|
|
287
|
-
else groups.push({
|
|
288
|
-
children: [fittedChild],
|
|
289
|
-
wrappers
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
const fitted = [];
|
|
293
|
-
for (const group of groups) {
|
|
294
|
-
const children = createWrappedContent(innerSchema7, group.wrappers, group.children, {
|
|
295
|
-
...options,
|
|
296
|
-
path: [...options.path ?? [], fitted.length]
|
|
297
|
-
});
|
|
298
|
-
if (!children) return null;
|
|
299
|
-
fitted.push(...children);
|
|
300
|
-
}
|
|
301
|
-
if (content.max !== null && fitted.length > content.max) return null;
|
|
302
|
-
return fitDirectContent(innerSchema7, content, fitted, [], options);
|
|
303
|
-
}
|
|
304
|
-
const fitClosedSliceInterior = (innerSchema9, slice, root, provenance, repairs) => {
|
|
305
|
-
const stage = provenance?.stage(slice.content);
|
|
306
|
-
const report = stage && repairs ? {
|
|
307
|
-
inputsOf: stage.inputsOf,
|
|
308
|
-
repairs
|
|
309
|
-
} : void 0;
|
|
310
|
-
const visit = (children, openStart, openEnd, ancestors, parentPath) => {
|
|
311
|
-
let changed = false;
|
|
312
|
-
const fitted = [];
|
|
313
|
-
for (const [index, child] of children.entries()) {
|
|
314
|
-
const opensStart = openStart > 0 && index === 0;
|
|
315
|
-
const opensEnd = openEnd > 0 && index === children.length - 1;
|
|
316
|
-
let next = child;
|
|
317
|
-
if (!opensStart && !opensEnd) next = fitClosedNode(innerSchema9, child, {
|
|
318
|
-
ancestors,
|
|
319
|
-
fitOrigins: stage?.origins,
|
|
320
|
-
path: [...parentPath, index],
|
|
321
|
-
report,
|
|
322
|
-
root
|
|
323
|
-
});
|
|
324
|
-
else if (ElementApi.isElement(child)) {
|
|
325
|
-
const nested = visit(child.children, opensStart ? openStart - 1 : 0, opensEnd ? openEnd - 1 : 0, [child, ...ancestors], [...parentPath, index]);
|
|
326
|
-
if (!nested) return null;
|
|
327
|
-
if (nested.length !== child.children.length || nested.some((node, childIndex) => node !== child.children[childIndex])) next = {
|
|
328
|
-
...child,
|
|
329
|
-
children: [...nested]
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
if (!next) return null;
|
|
333
|
-
changed ||= next !== child;
|
|
334
|
-
fitted.push(next);
|
|
335
|
-
}
|
|
336
|
-
return changed ? Object.freeze(fitted) : children;
|
|
337
|
-
};
|
|
338
|
-
const content = visit(slice.content, slice.openStart, slice.openEnd, [], []);
|
|
339
|
-
if (!content) return null;
|
|
340
|
-
if (content !== slice.content) stage?.advance(content);
|
|
341
|
-
return content === slice.content ? slice : ContentSlice.withContent(slice, content, { open: "preserve" });
|
|
342
|
-
};
|
|
343
|
-
const getSliceEdgeOpenDepth = (content, edge, canOpenPreservedContext = () => false) => {
|
|
344
|
-
let children = content;
|
|
345
|
-
let depth = 0;
|
|
346
|
-
while (children.length > 0) {
|
|
347
|
-
const node = edge === "start" ? children[0] : children.at(-1);
|
|
348
|
-
if (!ElementApi.isElement(node)) break;
|
|
349
|
-
if (getElementBehavior(node).void || getElementSlicePolicy(node).preserveContext && !canOpenPreservedContext(node)) break;
|
|
350
|
-
depth += 1;
|
|
351
|
-
({children} = node);
|
|
352
|
-
}
|
|
353
|
-
return depth;
|
|
354
|
-
};
|
|
355
|
-
const fitContent = (slice, options) => {
|
|
356
|
-
const innerSchema10 = getDeclarativeSchema();
|
|
357
|
-
const parentType = getElementType(options.parent);
|
|
358
|
-
if (!innerSchema10 || !parentType) return null;
|
|
359
|
-
const element = innerSchema10.elements.byType.get(parentType);
|
|
360
|
-
if (!element?.content) return null;
|
|
361
|
-
const parentContent = element.content;
|
|
362
|
-
const root = options.root ?? "main";
|
|
363
|
-
const rootContext = {
|
|
364
|
-
ancestors: [],
|
|
365
|
-
root: root === "main" ? null : root,
|
|
366
|
-
type: parentType
|
|
367
|
-
};
|
|
368
|
-
let parent = snapshotEditorJsonValue({
|
|
369
|
-
...Object.fromEntries(Object.entries(options.parent).filter(([key]) => resolveCompiledSchemaProperty(innerSchema10, "element", key, rootContext) !== null)),
|
|
370
|
-
children: options.parent.children,
|
|
371
|
-
type: parentType,
|
|
372
|
-
...element.contentRoots.size > 0 && Object.hasOwn(options.parent, "childRoots") ? { childRoots: options.parent.childRoots } : {}
|
|
373
|
-
}, "Detached slice-fit parent");
|
|
374
|
-
let virtualChildren = Object.freeze([parent]);
|
|
375
|
-
let virtualDocument = DocumentIndex.fromValue(virtualChildren);
|
|
376
|
-
let parentRange = virtualDocument.nodeRange([0]);
|
|
377
|
-
let anchor = virtualDocument.pointAt(parentRange.from + 1, 1);
|
|
378
|
-
let focus = virtualDocument.pointAt(parentRange.to - 1, -1);
|
|
379
|
-
if (!anchor || !focus) {
|
|
380
|
-
parent = snapshotEditorJsonValue({
|
|
381
|
-
...parent,
|
|
382
|
-
children: [{ text: "" }]
|
|
383
|
-
}, "Detached slice-fit parent");
|
|
384
|
-
virtualChildren = Object.freeze([parent]);
|
|
385
|
-
virtualDocument = DocumentIndex.fromValue(virtualChildren);
|
|
386
|
-
parentRange = virtualDocument.nodeRange([0]);
|
|
387
|
-
anchor = virtualDocument.pointAt(parentRange.from + 1, 1);
|
|
388
|
-
focus = virtualDocument.pointAt(parentRange.to - 1, -1);
|
|
389
|
-
}
|
|
390
|
-
if (!anchor || !focus) return null;
|
|
391
|
-
const builder = new ChangeDraft(snapshotEditorJsonValue(root === "main" ? { children: [parent] } : {
|
|
392
|
-
children: [],
|
|
393
|
-
roots: { [root]: [parent] }
|
|
394
|
-
}, "Detached slice-fit document"), {
|
|
395
|
-
construct: ({ after, before, change, indexedAfter, indexedBefore }, preparation) => constructCanonicalDocumentChange(getEditor(), after, change, {
|
|
396
|
-
before,
|
|
397
|
-
fitPreparation: preparation,
|
|
398
|
-
indexedAfter,
|
|
399
|
-
indexedBefore,
|
|
400
|
-
schema: api
|
|
401
|
-
}),
|
|
402
|
-
indexConstructedRoot,
|
|
403
|
-
isSetValued: (node, key, context) => isSetValuedProperty(node, key, context),
|
|
404
|
-
validateConstructed: ({ after }) => {
|
|
405
|
-
profileCoreDuration("slice-fit-content-validation", () => {
|
|
406
|
-
const fittedParent = getDocumentRoot(after, root)[0];
|
|
407
|
-
if (!fittedParent || !ElementApi.isElement(fittedParent) || getElementType(fittedParent) !== parentType) throw new EditorSchemaValidationError("Detached slice fitting must retain its parent element.");
|
|
408
|
-
const { children } = fittedParent;
|
|
409
|
-
if (children.length < parentContent.min || parentContent.max !== null && children.length > parentContent.max || !allContentAllowed(innerSchema10, parentContent, children)) throw new EditorSchemaValidationError(`Editor element "${parentType}" has invalid fitted content.`);
|
|
410
|
-
validateDeclarativeChildren(children, innerSchema10, root, [fittedParent], []);
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
const at = {
|
|
415
|
-
anchor: {
|
|
416
|
-
offset: anchor.offset,
|
|
417
|
-
path: [...anchor.path],
|
|
418
|
-
...root === "main" ? {} : { root }
|
|
419
|
-
},
|
|
420
|
-
focus: {
|
|
421
|
-
offset: focus.offset,
|
|
422
|
-
path: [...focus.path],
|
|
423
|
-
...root === "main" ? {} : { root }
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
const innerInput = ContentSlice.fromJSON(slice);
|
|
427
|
-
const contentBounds = {
|
|
428
|
-
from: parentRange.from + 1,
|
|
429
|
-
to: parentRange.to - 1
|
|
430
|
-
};
|
|
431
|
-
if (!fit(slice, {
|
|
432
|
-
builder,
|
|
433
|
-
target: {
|
|
434
|
-
at,
|
|
435
|
-
contentBounds,
|
|
436
|
-
...innerInput.openStart === 0 && innerInput.openEnd === 0 ? { exactBounds: contentBounds } : {},
|
|
437
|
-
kind: "range"
|
|
438
|
-
}
|
|
439
|
-
})) return null;
|
|
440
|
-
try {
|
|
441
|
-
const after = builder.value;
|
|
442
|
-
const fittedParent = getDocumentRoot(after, root)[0];
|
|
443
|
-
return fittedParent && ElementApi.isElement(fittedParent) ? cloneFrozen(fittedParent.children) : null;
|
|
444
|
-
} catch (error) {
|
|
445
|
-
if (error instanceof EditorSchemaValidationError) return null;
|
|
446
|
-
throw error;
|
|
447
|
-
}
|
|
448
|
-
};
|
|
449
|
-
const getSliceVariantFamilies = (slice, at, root, rootChildren, targetRootProgram) => {
|
|
450
|
-
const contents = [{
|
|
451
|
-
content: slice.content,
|
|
452
|
-
cost: 0,
|
|
453
|
-
priority: 0
|
|
454
|
-
}];
|
|
455
|
-
const contentPrograms = /* @__PURE__ */ new Map();
|
|
456
|
-
const declarative = getDeclarativeSchema();
|
|
457
|
-
const rootProgram = targetRootProgram;
|
|
458
|
-
if (rootProgram) contentPrograms.set(rootProgram, {
|
|
459
|
-
id: root === "main" ? "root" : `root:${root}`,
|
|
460
|
-
options: { root }
|
|
461
|
-
});
|
|
462
|
-
const [start] = RangeApi.edges(at);
|
|
463
|
-
const nestedStructuralVariant = (() => {
|
|
464
|
-
if (slice.openStart !== 0 || slice.openEnd !== 0 || slice.content.length !== 1) return null;
|
|
465
|
-
const targetPath = start.path.slice(0, -1);
|
|
466
|
-
const target = getDescendant(rootChildren, targetPath);
|
|
467
|
-
const targetParent = getDescendant(rootChildren, targetPath.slice(0, -1));
|
|
468
|
-
const source = slice.content[0];
|
|
469
|
-
if (targetPath.length < 2 || !target || !ElementApi.isElement(target) || !elementUsesInlineContent(target) || !targetParent || !ElementApi.isElement(targetParent) || elementUsesInlineContent(targetParent) || !ElementApi.isElement(source)) return null;
|
|
470
|
-
const canOpenStructuralContext = (element) => {
|
|
471
|
-
const behavior = getElementBehavior(element);
|
|
472
|
-
const policy = getElementSlicePolicy(element);
|
|
473
|
-
return !behavior.inline && !behavior.isolating && !behavior.void && !policy.preserveContext && !elementUsesInlineContent(element);
|
|
474
|
-
};
|
|
475
|
-
if (!canOpenStructuralContext(source)) return null;
|
|
476
|
-
let { children } = source;
|
|
477
|
-
while (true) {
|
|
478
|
-
const first = children[0];
|
|
479
|
-
if (!first || !ElementApi.isElement(first)) return null;
|
|
480
|
-
if (elementUsesInlineContent(first)) break;
|
|
481
|
-
if (!canOpenStructuralContext(first)) return null;
|
|
482
|
-
children = [...first.children, ...children.slice(1)];
|
|
483
|
-
}
|
|
484
|
-
const first = children[0];
|
|
485
|
-
if (children.length < 2 || !first || !ElementApi.isElement(first) || !children.every((child) => ElementApi.isElement(child)) || getElementType(first) !== getElementType(target)) return null;
|
|
486
|
-
return children;
|
|
487
|
-
})();
|
|
488
|
-
if (nestedStructuralVariant) contents.push({
|
|
489
|
-
content: nestedStructuralVariant,
|
|
490
|
-
cost: 0,
|
|
491
|
-
openEnd: 0,
|
|
492
|
-
openStart: 1,
|
|
493
|
-
priority: -1
|
|
494
|
-
});
|
|
495
|
-
for (let depth = start.path.length - 1; depth > 0; depth--) {
|
|
496
|
-
const node = getDescendant(rootChildren, start.path.slice(0, depth));
|
|
497
|
-
const type = node && ElementApi.isElement(node) ? getElementType(node) : null;
|
|
498
|
-
const content = type ? declarative?.elements.byType.get(type)?.content : null;
|
|
499
|
-
if (content && node && ElementApi.isElement(node)) contentPrograms.set(content, {
|
|
500
|
-
id: `element:${type}`,
|
|
501
|
-
options: {
|
|
502
|
-
ancestors: getElementAncestors(rootChildren, start.path.slice(0, depth), { includeTarget: true }),
|
|
503
|
-
root
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
for (const [content, { id, options }] of contentPrograms) {
|
|
508
|
-
if (content.prefix) continue;
|
|
509
|
-
const fitted = declarative ? fitClosedContent(declarative, id, content, slice.content, options) : null;
|
|
510
|
-
if (fitted && (fitted.length !== slice.content.length || fitted.some((child, index) => child !== slice.content[index]))) contents.push({
|
|
511
|
-
content: fitted,
|
|
512
|
-
cost: 2,
|
|
513
|
-
priority: 0
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
return contents.map(({ content, cost: contentCost, openEnd, openStart, priority }, contentIndex) => {
|
|
517
|
-
const preparedContent = contentIndex === 0 ? slice : openStart === void 0 || openEnd === void 0 ? ContentSlice.closed(content) : ContentSlice.fromJSON({
|
|
518
|
-
content,
|
|
519
|
-
openEnd,
|
|
520
|
-
openStart
|
|
521
|
-
});
|
|
522
|
-
const baseOpenStart = preparedContent.openStart;
|
|
523
|
-
const baseOpenEnd = preparedContent.openEnd;
|
|
524
|
-
const targetTypes = new Set(start.path.slice(0, -1).map((_part, index) => getDescendant(rootChildren, start.path.slice(0, index + 1))).filter((node) => Boolean(node && ElementApi.isElement(node))).map((element) => getElementType(element)));
|
|
525
|
-
const canOpenInTargetContext = [content[0], content.at(-1)].some((edge) => ElementApi.isElement(edge) && targetTypes.has(getElementType(edge)));
|
|
526
|
-
const canOpenAtRoot = declarative ? [declarative.primaryRoot, ...declarative.roots.values()].some((compiledRoot) => allContentAllowed(declarative, compiledRoot.content, content)) : content.every((child) => ElementApi.isElement(child) && !getElementBehavior(child).inline && child.children.every((grandchild) => NodeApi.isText(grandchild) || ElementApi.isElement(grandchild) && getElementBehavior(grandchild).inline));
|
|
527
|
-
const canOpenContent = contentIndex === 0 && (slice.openStart > 0 || slice.openEnd > 0 || contents.length === 1 || canOpenInTargetContext) && (canOpenAtRoot || canOpenInTargetContext);
|
|
528
|
-
const maxOpenStart = canOpenContent ? getSliceEdgeOpenDepth(content, "start", (element) => targetTypes.has(getElementType(element))) : baseOpenStart;
|
|
529
|
-
const maxOpenEnd = canOpenContent ? getSliceEdgeOpenDepth(content, "end", (element) => targetTypes.has(getElementType(element))) : baseOpenEnd;
|
|
530
|
-
return Object.freeze({
|
|
531
|
-
baseOpenEnd,
|
|
532
|
-
baseOpenStart,
|
|
533
|
-
contentCost,
|
|
534
|
-
index: contentIndex,
|
|
535
|
-
maxOpenEnd,
|
|
536
|
-
maxOpenStart,
|
|
537
|
-
priority,
|
|
538
|
-
source: preparedContent
|
|
539
|
-
});
|
|
540
|
-
});
|
|
541
|
-
};
|
|
542
|
-
const contextsShareContent = (left, right) => {
|
|
543
|
-
if (getElementType(left) === getElementType(right)) return true;
|
|
544
|
-
const leftBehavior = getElementBehavior(left);
|
|
545
|
-
const rightBehavior = getElementBehavior(right);
|
|
546
|
-
return !leftBehavior.inline && !rightBehavior.inline && elementUsesInlineContent(left) && elementUsesInlineContent(right);
|
|
547
|
-
};
|
|
548
|
-
const getPrefixInsertionBoundary = (at, rootChildren, document, source, targetRootProgram, allowSelected = false) => {
|
|
549
|
-
const declarative = getDeclarativeSchema();
|
|
550
|
-
const [start, end] = RangeApi.edges(at);
|
|
551
|
-
const targetParent = getDescendant(rootChildren, start.path.slice(0, -1));
|
|
552
|
-
if (ElementApi.isElement(targetParent) && source.content.every((child) => ElementApi.isElement(child) && contextsShareContent(targetParent, child))) return null;
|
|
553
|
-
if (!declarative || !allowSelected && document.positionAt(start) !== document.positionAt(end) || source.openStart !== 0 || source.openEnd !== 0 || source.content.length === 0) return null;
|
|
554
|
-
for (let depth = start.path.length - 1; depth >= 0; depth--) {
|
|
555
|
-
const ownerPath = start.path.slice(0, depth);
|
|
556
|
-
const owner = ownerPath.length ? getDescendant(rootChildren, ownerPath) : null;
|
|
557
|
-
const ownerType = owner && ElementApi.isElement(owner) ? getElementType(owner) : null;
|
|
558
|
-
const content = ownerType ? declarative.elements.byType.get(ownerType)?.content : depth === 0 ? targetRootProgram : null;
|
|
559
|
-
const prefix = content?.prefix;
|
|
560
|
-
const remainder = content?.remainder;
|
|
561
|
-
const children = owner && ElementApi.isElement(owner) ? owner.children : rootChildren;
|
|
562
|
-
const options = {
|
|
563
|
-
ancestors: ownerType ? getElementAncestors(rootChildren, ownerPath, { includeTarget: true }) : [],
|
|
564
|
-
root: start.root ?? "main"
|
|
565
|
-
};
|
|
566
|
-
if (!prefix || !remainder || start.path[depth] === void 0 || start.path[depth] >= prefix.length || !source.content.every((child) => contentAllows(declarative, remainder, child)) || !prefix.every((_slot, index) => children[index] && contentAllowsAt(declarative, content, children[index], index, options))) continue;
|
|
567
|
-
return document.nodeRange([...ownerPath, prefix.length - 1]).to;
|
|
568
|
-
}
|
|
569
|
-
return null;
|
|
570
|
-
};
|
|
571
|
-
const getBoundaryCandidates = (at, rootChildren, document, source, targetRootProgram, contentBounds, exactBounds) => {
|
|
572
|
-
const [start, end] = RangeApi.edges(at);
|
|
573
|
-
const from = exactBounds?.from ?? document.positionAt(start);
|
|
574
|
-
const to = exactBounds?.to ?? document.positionAt(end);
|
|
575
|
-
const candidates = /* @__PURE__ */ new Map();
|
|
576
|
-
const add = (candidate) => {
|
|
577
|
-
if (candidate.from > candidate.to) return;
|
|
578
|
-
if (contentBounds && (candidate.from < contentBounds.from || candidate.to > contentBounds.to)) return;
|
|
579
|
-
const key = `${candidate.from}:${candidate.to}`;
|
|
580
|
-
const previous = candidates.get(key);
|
|
581
|
-
if (!previous || candidate.cost < previous.cost) candidates.set(key, candidate);
|
|
582
|
-
};
|
|
583
|
-
add({
|
|
584
|
-
cost: 0,
|
|
585
|
-
from,
|
|
586
|
-
to
|
|
587
|
-
});
|
|
588
|
-
if (exactBounds) return [...candidates.values()];
|
|
589
|
-
const collapsed = from === to;
|
|
590
|
-
const boundary = getPrefixInsertionBoundary(at, rootChildren, document, source, targetRootProgram);
|
|
591
|
-
if (boundary !== null) add({
|
|
592
|
-
cost: -1,
|
|
593
|
-
from: boundary,
|
|
594
|
-
to: boundary
|
|
595
|
-
});
|
|
596
|
-
const startBounds = [{
|
|
597
|
-
cost: 0,
|
|
598
|
-
position: from
|
|
599
|
-
}];
|
|
600
|
-
const endBounds = [{
|
|
601
|
-
cost: 0,
|
|
602
|
-
position: to
|
|
603
|
-
}];
|
|
604
|
-
const deleting = source.content.length === 0;
|
|
605
|
-
const directSourceContexts = (() => {
|
|
606
|
-
const contexts = [];
|
|
607
|
-
let { content } = source;
|
|
608
|
-
for (let depth = 0; depth <= source.openStart; depth++) {
|
|
609
|
-
const node = content[0];
|
|
610
|
-
if (!node) break;
|
|
611
|
-
contexts.push(node);
|
|
612
|
-
if (!ElementApi.isElement(node)) break;
|
|
613
|
-
if (depth < source.openStart) {
|
|
614
|
-
if (getElementBehavior(node).void || getElementSlicePolicy(node).preserveContext) return [];
|
|
615
|
-
}
|
|
616
|
-
content = node.children;
|
|
617
|
-
}
|
|
618
|
-
return contexts;
|
|
619
|
-
})();
|
|
620
|
-
const canReplaceCoveredNode = (path) => {
|
|
621
|
-
if (deleting) return true;
|
|
622
|
-
if (directSourceContexts.length === 0) return false;
|
|
623
|
-
const parentPath = path.slice(0, -1);
|
|
624
|
-
const parent = parentPath.length > 0 ? getDescendant(rootChildren, parentPath) : null;
|
|
625
|
-
if (parent) return ElementApi.isElement(parent) && directSourceContexts.some((candidate) => canContain(parent, candidate));
|
|
626
|
-
const declarative = getDeclarativeSchema();
|
|
627
|
-
const rootContent = targetRootProgram;
|
|
628
|
-
return directSourceContexts.some((candidate) => declarative && rootContent ? contentAllows(declarative, rootContent, candidate) : ElementApi.isElement(candidate) && !getElementBehavior(candidate).inline);
|
|
629
|
-
};
|
|
630
|
-
const coveredCost = (depth, distance) => {
|
|
631
|
-
if (deleting) return -distance;
|
|
632
|
-
return -2 + 1 / (depth + 1);
|
|
633
|
-
};
|
|
634
|
-
for (let depth = start.path.length - 1; depth > 0; depth--) {
|
|
635
|
-
const path = start.path.slice(0, depth);
|
|
636
|
-
const node = getDescendant(rootChildren, path);
|
|
637
|
-
if (!node || !ElementApi.isElement(node)) continue;
|
|
638
|
-
if (getElementBehavior(node).isolating) break;
|
|
639
|
-
const range = document.nodeRange(path);
|
|
640
|
-
const startEdge = getTextEdge(node, path, "start");
|
|
641
|
-
const endEdge = getTextEdge(node, path, "end");
|
|
642
|
-
const cost = start.path.length - depth + 2;
|
|
643
|
-
const { preserveContext, replaceWhenCovered } = getElementSlicePolicy(node);
|
|
644
|
-
if (startEdge && pointsEqual(start, startEdge)) {
|
|
645
|
-
if (!collapsed && replaceWhenCovered && canReplaceCoveredNode(path)) startBounds.push({
|
|
646
|
-
cost: coveredCost(depth, cost),
|
|
647
|
-
position: range.from
|
|
648
|
-
});
|
|
649
|
-
if (collapsed) add({
|
|
650
|
-
cost,
|
|
651
|
-
from: range.from,
|
|
652
|
-
to: range.from
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
if (collapsed && endEdge && pointsEqual(start, endEdge)) add({
|
|
656
|
-
cost,
|
|
657
|
-
from: range.to,
|
|
658
|
-
to: range.to
|
|
659
|
-
});
|
|
660
|
-
if (collapsed && holdsNoContent(node, contentSchema)) add({
|
|
661
|
-
cost: cost - 2,
|
|
662
|
-
from: range.from,
|
|
663
|
-
to: range.to
|
|
664
|
-
});
|
|
665
|
-
if (preserveContext) break;
|
|
666
|
-
}
|
|
667
|
-
if (!collapsed) {
|
|
668
|
-
for (let depth = end.path.length - 1; depth > 0; depth--) {
|
|
669
|
-
const path = end.path.slice(0, depth);
|
|
670
|
-
const node = getDescendant(rootChildren, path);
|
|
671
|
-
if (!node || !ElementApi.isElement(node)) continue;
|
|
672
|
-
if (getElementBehavior(node).isolating) break;
|
|
673
|
-
const range = document.nodeRange(path);
|
|
674
|
-
const endEdge = getTextEdge(node, path, "end");
|
|
675
|
-
const { preserveContext, replaceWhenCovered } = getElementSlicePolicy(node);
|
|
676
|
-
if (replaceWhenCovered && endEdge && pointsEqual(end, endEdge) && canReplaceCoveredNode(path)) endBounds.push({
|
|
677
|
-
cost: coveredCost(depth, end.path.length - depth + 2),
|
|
678
|
-
position: range.to
|
|
679
|
-
});
|
|
680
|
-
if (preserveContext) break;
|
|
681
|
-
}
|
|
682
|
-
for (const startBound of startBounds) for (const endBound of endBounds) add({
|
|
683
|
-
cost: startBound.cost + endBound.cost,
|
|
684
|
-
from: startBound.position,
|
|
685
|
-
to: endBound.position
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
return [...candidates.values()].sort((left, right) => left.cost - right.cost);
|
|
689
|
-
};
|
|
690
|
-
const getNodeToken = (node, kind) => {
|
|
691
|
-
if (kind === "close") return {
|
|
692
|
-
kind,
|
|
693
|
-
nodeKind: NodeApi.isText(node) ? "text" : "element"
|
|
694
|
-
};
|
|
695
|
-
if (NodeApi.isText(node)) {
|
|
696
|
-
const { text: _text, ...props } = node;
|
|
697
|
-
return {
|
|
698
|
-
kind,
|
|
699
|
-
nodeKind: "text",
|
|
700
|
-
props
|
|
701
|
-
};
|
|
702
|
-
}
|
|
703
|
-
const { children: _children, ...props } = node;
|
|
704
|
-
return {
|
|
705
|
-
kind,
|
|
706
|
-
nodeKind: "element",
|
|
707
|
-
props
|
|
708
|
-
};
|
|
709
|
-
};
|
|
710
|
-
const getContentEndOffset = (slice) => {
|
|
711
|
-
let offset = slice.length;
|
|
712
|
-
for (let index = slice.tokens.length - 1; index >= 0; index--) {
|
|
713
|
-
if (slice.tokens[index]?.kind !== "close") break;
|
|
714
|
-
offset -= 1;
|
|
715
|
-
}
|
|
716
|
-
return offset;
|
|
717
|
-
};
|
|
718
|
-
const endsInInlineVoid = (slice) => {
|
|
719
|
-
let node = slice.content.at(-1);
|
|
720
|
-
while (node && ElementApi.isElement(node)) {
|
|
721
|
-
const behavior = getElementBehavior(node);
|
|
722
|
-
if (behavior.inline && behavior.void) return true;
|
|
723
|
-
node = node.children.at(-1);
|
|
724
|
-
}
|
|
725
|
-
return false;
|
|
726
|
-
};
|
|
727
|
-
const restorePartiallyDeletedContext = (document, rootChildren, start, end, boundary, exactFrom, exactTo, insert) => {
|
|
728
|
-
const tokens = [];
|
|
729
|
-
if (boundary.from < exactFrom && boundary.to === exactTo) for (let depth = 1; depth <= end.path.length; depth++) {
|
|
730
|
-
const path = end.path.slice(0, depth);
|
|
731
|
-
const node = getDescendant(rootChildren, path);
|
|
732
|
-
if (!node) continue;
|
|
733
|
-
const range = document.nodeRange(path);
|
|
734
|
-
if (range.from >= boundary.from && range.from < exactTo) tokens.push(getNodeToken(node, "open"));
|
|
735
|
-
}
|
|
736
|
-
const prefix = PreparedTokenSlice.fromJSON(tokens);
|
|
737
|
-
tokens.length = 0;
|
|
738
|
-
if (boundary.from === exactFrom && boundary.to > exactTo) for (let depth = start.path.length; depth > 0; depth--) {
|
|
739
|
-
const path = start.path.slice(0, depth);
|
|
740
|
-
const node = getDescendant(rootChildren, path);
|
|
741
|
-
if (!node) continue;
|
|
742
|
-
const range = document.nodeRange(path);
|
|
743
|
-
if (range.to > exactFrom && range.to <= boundary.to) tokens.push(getNodeToken(node, "close"));
|
|
744
|
-
}
|
|
745
|
-
const suffix = PreparedTokenSlice.fromJSON(tokens);
|
|
746
|
-
const restored = prefix.length === 0 && suffix.length === 0 ? insert : PreparedTokenSlice.concat([
|
|
747
|
-
prefix,
|
|
748
|
-
insert,
|
|
749
|
-
suffix
|
|
750
|
-
]);
|
|
751
|
-
const origins = new FitOriginLog();
|
|
752
|
-
origins.add(prefix.length, "fit");
|
|
753
|
-
origins.add(insert.length, "slice");
|
|
754
|
-
origins.add(suffix.length, "fit");
|
|
755
|
-
return {
|
|
756
|
-
content: {
|
|
757
|
-
from: prefix.length,
|
|
758
|
-
to: prefix.length + insert.length
|
|
759
|
-
},
|
|
760
|
-
insert: restored,
|
|
761
|
-
origins: origins.seal(restored),
|
|
762
|
-
selectionOffset: prefix.length + getContentEndOffset(insert)
|
|
763
|
-
};
|
|
764
|
-
};
|
|
765
|
-
const prepareFittedDocument = (builder, rawChange, diffsWholeValue, fitPreparation, trustedCanonical) => {
|
|
766
|
-
const facts = diffsWholeValue ? void 0 : fittedFacts(builder, rawChange);
|
|
767
|
-
if (trustedCanonical) {
|
|
768
|
-
const indexedAfter = profileCoreDuration("slice-fit-changeset-apply", trustedCanonical.createIndexes);
|
|
769
|
-
const runtimeCandidates = new Map([...trustedCanonical.runtimeCandidatePaths].map(([root, paths]) => {
|
|
770
|
-
const index = indexedAfter.get(root);
|
|
771
|
-
if (!index) throw new Error(`Missing trusted indexed result for runtime candidates in root "${root}".`);
|
|
772
|
-
return [root, Object.freeze(paths.map((path) => Object.freeze({
|
|
773
|
-
node: index.node([...path]),
|
|
774
|
-
path
|
|
775
|
-
})))];
|
|
776
|
-
}));
|
|
777
|
-
const step = builder.applyTrustedCanonical(rawChange, {
|
|
778
|
-
facts,
|
|
779
|
-
indexedAfter,
|
|
780
|
-
origin: "slice",
|
|
781
|
-
runtimeCandidates
|
|
782
|
-
});
|
|
783
|
-
return {
|
|
784
|
-
canonicalAfter: step.after,
|
|
785
|
-
canonicalIndexes: step.indexedAfter,
|
|
786
|
-
change: rawChange,
|
|
787
|
-
constructionChange: DocumentChange.empty,
|
|
788
|
-
prepared: builder.prepare(rawChange, { classify: false }),
|
|
789
|
-
rawAfter: step.after,
|
|
790
|
-
rawIndexes: step.indexedAfter
|
|
791
|
-
};
|
|
792
|
-
}
|
|
793
|
-
const rawStep = profileCoreDuration("slice-fit-changeset-apply", () => builder.apply(rawChange, {
|
|
794
|
-
classify: false,
|
|
795
|
-
facts,
|
|
796
|
-
origin: "slice",
|
|
797
|
-
...landedMove(builder, rawChange)
|
|
798
|
-
}));
|
|
799
|
-
const constructionStep = profileCoreDuration("slice-fit-canonical-change-finalize", () => builder.finalize(fitPreparation, { classify: false }));
|
|
800
|
-
const canonicalAfter = builder.value;
|
|
801
|
-
const change = profileCoreDuration("slice-fit-canonical-change-map", () => builder.classify());
|
|
802
|
-
const constructionChange = constructionStep?.change ?? DocumentChange.empty;
|
|
803
|
-
return {
|
|
804
|
-
canonicalAfter,
|
|
805
|
-
canonicalIndexes: constructionStep?.indexedAfter ?? rawStep.indexedAfter,
|
|
806
|
-
change,
|
|
807
|
-
constructionChange,
|
|
808
|
-
prepared: builder.prepare(change),
|
|
809
|
-
rawAfter: rawStep.after,
|
|
810
|
-
rawIndexes: rawStep.indexedAfter
|
|
811
|
-
};
|
|
812
|
-
};
|
|
813
|
-
const mapFittedSelectionPoint = (rawDocument, canonicalDocument, constructionChange, root, rawPosition, selectionAssociation = -1) => {
|
|
814
|
-
const rawPoint = rawDocument.pointAt(rawPosition, selectionAssociation);
|
|
815
|
-
return rawPoint ? mapCanonicalRepresentationPoint(getEditor(), rawDocument, canonicalDocument, constructionChange, root, {
|
|
816
|
-
offset: rawPoint.offset,
|
|
817
|
-
path: [...rawPoint.path]
|
|
818
|
-
}, selectionAssociation === 1 || rawPoint.offset === 0 ? 1 : -1) : null;
|
|
819
|
-
};
|
|
820
|
-
const mapFittedLanding = (rawDocument, canonicalDocument, constructionChange, root, content) => {
|
|
821
|
-
const edge = (position, inward) => {
|
|
822
|
-
const raw = rawDocument.pointAt(position, inward) ?? rawDocument.pointAt(position, inward === 1 ? -1 : 1);
|
|
823
|
-
const point = raw && mapCanonicalRepresentationPoint(getEditor(), rawDocument, canonicalDocument, constructionChange, root, {
|
|
824
|
-
offset: raw.offset,
|
|
825
|
-
path: [...raw.path]
|
|
826
|
-
}, inward, { countInlineEdges: true });
|
|
827
|
-
return point && {
|
|
828
|
-
offset: point.offset,
|
|
829
|
-
path: [...point.path],
|
|
830
|
-
...root === "main" ? {} : { root }
|
|
831
|
-
};
|
|
832
|
-
};
|
|
833
|
-
const anchor = edge(content.from, 1);
|
|
834
|
-
const focus = edge(content.to, -1);
|
|
835
|
-
return anchor && focus ? {
|
|
836
|
-
anchor,
|
|
837
|
-
focus
|
|
838
|
-
} : null;
|
|
839
|
-
};
|
|
840
|
-
const resolveExternalDocumentPoint = (source, document, point) => {
|
|
841
|
-
const direct = getDescendant(source, point.path);
|
|
842
|
-
if (direct && NodeApi.isText(direct)) return {
|
|
843
|
-
offset: Math.min(point.offset, direct.text.length),
|
|
844
|
-
path: [...point.path],
|
|
845
|
-
...point.root === void 0 ? {} : { root: point.root }
|
|
846
|
-
};
|
|
847
|
-
if (direct && ElementApi.isElement(direct)) {
|
|
848
|
-
const [first, path] = NodeApi.first(direct, []);
|
|
849
|
-
if (NodeApi.isText(first)) return {
|
|
850
|
-
offset: Math.min(point.offset, first.text.length),
|
|
851
|
-
path: [...point.path, ...path],
|
|
852
|
-
...point.root === void 0 ? {} : { root: point.root }
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
const fallback = document.pointAt(0, 1);
|
|
856
|
-
return fallback ? {
|
|
857
|
-
offset: fallback.offset,
|
|
858
|
-
path: [...fallback.path],
|
|
859
|
-
...point.root === void 0 ? {} : { root: point.root }
|
|
860
|
-
} : null;
|
|
861
|
-
};
|
|
862
|
-
const createExternalRootMapper = (source, sourceDocument, provenance, constructionChange, root, rawDocument, canonicalDocument) => {
|
|
863
|
-
const resolveSourcePoint = (point) => resolveExternalDocumentPoint(source, sourceDocument, point);
|
|
864
|
-
const getCanonicalAssociation = (point, fallback) => {
|
|
865
|
-
const node = getDescendant(source, point.path);
|
|
866
|
-
if (!node || !NodeApi.isText(node) || node.text !== "") return fallback;
|
|
867
|
-
const index = point.path.at(-1);
|
|
868
|
-
if (index === void 0) return fallback;
|
|
869
|
-
const parent = getDescendant(source, point.path.slice(0, -1));
|
|
870
|
-
if (!parent || !ElementApi.isElement(parent)) return fallback;
|
|
871
|
-
const previous = parent.children[index - 1];
|
|
872
|
-
return previous && ElementApi.isElement(previous) && api.isInline(previous) ? 1 : fallback;
|
|
873
|
-
};
|
|
874
|
-
let textAlignedChange;
|
|
875
|
-
const getTextAlignedChange = () => {
|
|
876
|
-
if (!textAlignedChange) {
|
|
877
|
-
const aligned = constructionChange.empty ? null : RootChange.aligned(rawDocument, canonicalDocument);
|
|
878
|
-
textAlignedChange = aligned ? createInternalDocumentChange(/* @__PURE__ */ new Map([[root, aligned]])) : constructionChange;
|
|
879
|
-
}
|
|
880
|
-
return textAlignedChange;
|
|
881
|
-
};
|
|
882
|
-
const mapPoint = (point, options = {}) => {
|
|
883
|
-
const sourcePoint = resolveSourcePoint(point);
|
|
884
|
-
if (!sourcePoint) return null;
|
|
885
|
-
const association = getCanonicalAssociation(sourcePoint, options.association === "backward" ? -1 : 1);
|
|
886
|
-
const rawPoint = provenance.mapPoint(sourcePoint, sourceDocument, rawDocument, association, options.deletion);
|
|
887
|
-
if (!rawPoint) return null;
|
|
888
|
-
const mapped = constructionChange.empty ? {
|
|
889
|
-
offset: rawPoint.offset,
|
|
890
|
-
path: [...rawPoint.path]
|
|
891
|
-
} : mapCanonicalRepresentationPoint(getEditor(), rawDocument, canonicalDocument, getTextAlignedChange(), root, {
|
|
892
|
-
offset: rawPoint.offset,
|
|
893
|
-
path: [...rawPoint.path]
|
|
894
|
-
}, association);
|
|
895
|
-
return mapped ? {
|
|
896
|
-
offset: mapped.offset,
|
|
897
|
-
path: [...mapped.path],
|
|
898
|
-
...point.root === void 0 ? {} : { root }
|
|
899
|
-
} : null;
|
|
900
|
-
};
|
|
901
|
-
const mapPath = (path, options = {}) => {
|
|
902
|
-
const association = options.association === "backward" ? -1 : 1;
|
|
903
|
-
const rawPath = provenance.mapPath(path, sourceDocument, association, options.deletion);
|
|
904
|
-
const rawNode = rawPath ? rawDocument.nodeRange(rawPath) : null;
|
|
905
|
-
if (!rawNode) return null;
|
|
906
|
-
const mappedPosition = mapInternalDocumentChangePosition(getTextAlignedChange(), root, rawNode.from, association, options.deletion === "drop" ? "around" : void 0);
|
|
907
|
-
const mappedNode = mappedPosition === null ? null : canonicalDocument.nodeStartingAt(mappedPosition);
|
|
908
|
-
return mappedNode ? [...mappedNode.path] : null;
|
|
909
|
-
};
|
|
910
|
-
const mapRange = (range, options = {}) => {
|
|
911
|
-
const sourceAnchor = resolveSourcePoint(range.anchor);
|
|
912
|
-
const sourceFocus = resolveSourcePoint(range.focus);
|
|
913
|
-
if (!sourceAnchor || !sourceFocus) return null;
|
|
914
|
-
const forward = sourceDocument.positionAt(sourceAnchor) <= sourceDocument.positionAt(sourceFocus);
|
|
915
|
-
const associations = options.association === "backward" ? ["backward", "backward"] : options.association === "forward" ? ["forward", "forward"] : options.association === "outward" ? forward ? ["backward", "forward"] : ["forward", "backward"] : forward ? ["forward", "backward"] : ["backward", "forward"];
|
|
916
|
-
const anchor = mapPoint(range.anchor, {
|
|
917
|
-
association: associations[0],
|
|
918
|
-
deletion: options.deletion
|
|
919
|
-
});
|
|
920
|
-
const focus = mapPoint(range.focus, {
|
|
921
|
-
association: associations[1],
|
|
922
|
-
deletion: options.deletion
|
|
923
|
-
});
|
|
924
|
-
return anchor && focus ? {
|
|
925
|
-
anchor,
|
|
926
|
-
focus
|
|
927
|
-
} : null;
|
|
928
|
-
};
|
|
929
|
-
const context = Object.freeze({
|
|
930
|
-
mapPath,
|
|
931
|
-
mapPoint,
|
|
932
|
-
mapRange,
|
|
933
|
-
root: toPublicRoot(root)
|
|
934
|
-
});
|
|
935
|
-
return (selection, association) => mapSelectionWithContext(selection, context, { association });
|
|
936
|
-
};
|
|
937
|
-
const fit = (slice, options) => {
|
|
938
|
-
const value = options.builder.value;
|
|
939
|
-
const sourceSlice = profileCoreDuration("slice-fit-input", () => ContentSlice.fromJSON(slice));
|
|
940
|
-
const rootPathProvenance = options.target.kind === "root" ? options.target.report?.provenance ?? (options.target.selection || options.target.ranges ? createRootFitPathProvenance(sourceSlice.content) : null) : null;
|
|
941
|
-
const rangeTarget = options.target.kind === "range" ? options.target : null;
|
|
942
|
-
const root = options.target.kind === "root" ? options.target.root : RangeApi.edges(options.target.at)[0].root ?? "main";
|
|
943
|
-
const missingRoot = root !== "main" && !Object.hasOwn(value.roots ?? {}, root);
|
|
944
|
-
if (rangeTarget) {
|
|
945
|
-
const [rangeStart, rangeEnd] = RangeApi.edges(rangeTarget.at);
|
|
946
|
-
if ((rangeEnd.root ?? "main") !== (rangeStart.root ?? "main")) throw new Error("A slice replacement cannot span editor roots.");
|
|
947
|
-
}
|
|
948
|
-
if (rangeTarget && missingRoot) throw new Error(`Cannot fit content into missing editor ${editorRootLabel(root)}.`);
|
|
949
|
-
if (options.target.kind === "root" && (sourceSlice.openStart !== 0 || sourceSlice.openEnd !== 0)) return false;
|
|
950
|
-
try {
|
|
951
|
-
profileCoreDuration("slice-fit-vocabulary-validation", () => {
|
|
952
|
-
validateSliceVocabulary(sourceSlice.content);
|
|
953
|
-
});
|
|
954
|
-
} catch (error) {
|
|
955
|
-
if (error instanceof EditorSchemaValidationError) return false;
|
|
956
|
-
throw error;
|
|
957
|
-
}
|
|
958
|
-
const declarative = getDeclarativeSchema();
|
|
959
|
-
const grammarFittedInput = declarative ? fitClosedSliceInterior(declarative, sourceSlice, root, rootPathProvenance ?? void 0, options.target.kind === "root" ? options.target.report?.repairs : void 0) : sourceSlice;
|
|
960
|
-
if (!grammarFittedInput) return false;
|
|
961
|
-
const preparedInput = options.target.kind === "root" ? null : profileCoreDuration("slice-fit-canonical-preparation", () => prepareCanonicalFitSlice(getEditor(), declarative, grammarFittedInput, getDeclarativeSchema, root, api));
|
|
962
|
-
let inputSlice = preparedInput?.slice ?? grammarFittedInput;
|
|
963
|
-
const targetRootProgram = declarative ? getDocumentRootProgram(declarative, root, value) ?? null : null;
|
|
964
|
-
if (options.target.kind === "root" && declarative && targetRootProgram) {
|
|
965
|
-
const stage = rootPathProvenance?.stage(inputSlice.content);
|
|
966
|
-
const repairs = options.target.report?.repairs;
|
|
967
|
-
const report = stage && repairs ? {
|
|
968
|
-
inputsOf: stage.inputsOf,
|
|
969
|
-
repairs
|
|
970
|
-
} : void 0;
|
|
971
|
-
const fittedRoot = fitClosedContent(declarative, root === "main" ? "root" : `root:${root}`, targetRootProgram, inputSlice.content, {
|
|
972
|
-
fitOrigins: stage?.origins,
|
|
973
|
-
path: [],
|
|
974
|
-
report,
|
|
975
|
-
root
|
|
976
|
-
}, false, true);
|
|
977
|
-
if (!fittedRoot) return false;
|
|
978
|
-
if (fittedRoot.length !== inputSlice.content.length || fittedRoot.some((node, index) => node !== inputSlice.content[index])) {
|
|
979
|
-
stage?.advance(fittedRoot);
|
|
980
|
-
inputSlice = ContentSlice.closed(fittedRoot);
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
if (inputSlice.openStart > getSliceEdgeOpenDepth(inputSlice.content, "start") || inputSlice.openEnd > getSliceEdgeOpenDepth(inputSlice.content, "end")) return false;
|
|
984
|
-
const rootChildren = getDocumentRoot(value, root);
|
|
985
|
-
const document = profileCoreDuration("slice-fit-target-index", () => DocumentIndex.fromValue(rootChildren));
|
|
986
|
-
const rootPoint = {
|
|
987
|
-
offset: 0,
|
|
988
|
-
path: [],
|
|
989
|
-
...root === "main" ? {} : { root }
|
|
990
|
-
};
|
|
991
|
-
const at = options.target.kind === "root" ? {
|
|
992
|
-
anchor: rootPoint,
|
|
993
|
-
focus: rootPoint
|
|
994
|
-
} : options.target.at;
|
|
995
|
-
const [start, end] = RangeApi.edges(at);
|
|
996
|
-
const emptyCaretBlockPath = options.target.kind === "root" ? null : getReplaceableEmptyBlock(at, (path) => getDescendant(rootChildren, path), {
|
|
997
|
-
getElementBehavior,
|
|
998
|
-
getElementContentRoots,
|
|
999
|
-
getElementSlicePolicy
|
|
1000
|
-
})?.[1] ?? null;
|
|
1001
|
-
if (options.target.kind === "range" && options.target.replaceEmptyBlock && !emptyCaretBlockPath) return false;
|
|
1002
|
-
const exactBounds = options.target.kind === "root" ? {
|
|
1003
|
-
from: 0,
|
|
1004
|
-
to: document.length
|
|
1005
|
-
} : options.target.exactBounds ?? (options.target.replaceEmptyBlock && emptyCaretBlockPath ? document.nodeRange(emptyCaretBlockPath) : void 0);
|
|
1006
|
-
const prefixInsertionBoundary = options.target.kind === "root" || exactBounds ? null : getPrefixInsertionBoundary(at, rootChildren, document, inputSlice, targetRootProgram);
|
|
1007
|
-
const exactFrom = exactBounds?.from ?? document.positionAt(start);
|
|
1008
|
-
const exactTo = exactBounds?.to ?? document.positionAt(end);
|
|
1009
|
-
const collapsed = exactFrom === exactTo;
|
|
1010
|
-
const sameTextPath = start.path.length === end.path.length && start.path.every((part, index) => part === end.path[index]);
|
|
1011
|
-
const targetText = start.path.length > 0 ? document.node(start.path) : null;
|
|
1012
|
-
const targetParentPath = start.path.slice(0, -1);
|
|
1013
|
-
const targetParent = getDescendant(rootChildren, targetParentPath);
|
|
1014
|
-
const caretSplitsBlockContent = (() => {
|
|
1015
|
-
if (!collapsed || !ElementApi.isElement(targetParent) || getElementBehavior(targetParent).inline) return false;
|
|
1016
|
-
const startEdge = getTextEdge(targetParent, targetParentPath, "start");
|
|
1017
|
-
const endEdge = getTextEdge(targetParent, targetParentPath, "end");
|
|
1018
|
-
return Boolean(startEdge && endEdge && !pointsEqual(start, startEdge) && !pointsEqual(end, endEdge));
|
|
1019
|
-
})();
|
|
1020
|
-
const endText = sameTextPath ? targetText : end.path.length > 0 ? document.node(end.path) : null;
|
|
1021
|
-
const boundaries = options.target.kind === "root" ? [] : profileCoreDuration("slice-fit-boundaries", () => getBoundaryCandidates(at, rootChildren, document, inputSlice, targetRootProgram, rangeTarget?.contentBounds, exactBounds));
|
|
1022
|
-
let variantFamilies;
|
|
1023
|
-
const getTargetVariantFamilies = () => variantFamilies ??= options.target.kind === "root" ? [] : profileCoreDuration("slice-fit-variants", () => getSliceVariantFamilies(inputSlice, at, root, rootChildren, targetRootProgram));
|
|
1024
|
-
const tokenLength = (token) => token.kind === "text" ? token.text.length : 1;
|
|
1025
|
-
const openTokenNode = (token) => {
|
|
1026
|
-
if (token.sourceNode) return token.sourceNode;
|
|
1027
|
-
return token.nodeKind === "text" ? {
|
|
1028
|
-
...token.props,
|
|
1029
|
-
text: ""
|
|
1030
|
-
} : {
|
|
1031
|
-
...token.props,
|
|
1032
|
-
children: []
|
|
1033
|
-
};
|
|
1034
|
-
};
|
|
1035
|
-
const rootContainmentByKind = /* @__PURE__ */ new Map();
|
|
1036
|
-
const rootCanContain = (child) => {
|
|
1037
|
-
const kind = NodeApi.isText(child) ? "text" : `element:${getElementType(child) ?? ""}`;
|
|
1038
|
-
const cached = rootContainmentByKind.get(kind);
|
|
1039
|
-
if (cached !== void 0) return cached;
|
|
1040
|
-
const innerSchema11 = getDeclarativeSchema();
|
|
1041
|
-
const rootContent = targetRootProgram;
|
|
1042
|
-
const allowed = innerSchema11 && rootContent ? contentAllows(innerSchema11, rootContent, child) : ElementApi.isElement(child) && !getElementBehavior(child).inline;
|
|
1043
|
-
rootContainmentByKind.set(kind, allowed);
|
|
1044
|
-
return allowed;
|
|
1045
|
-
};
|
|
1046
|
-
const getOpenContext = (position) => profileCoreDuration("slice-fit-open-context", () => document.openContextAt(position).filter(({ from, to }) => from < position && position < to).map(({ path }) => {
|
|
1047
|
-
const token = encodeNodes([document.node(path)]).slice.tokens[0];
|
|
1048
|
-
if (token?.kind !== "open") throw new Error(`Missing open token at document path [${path}].`);
|
|
1049
|
-
return token;
|
|
1050
|
-
}));
|
|
1051
|
-
const openContextsMatch = (left, right) => {
|
|
1052
|
-
const leftNode = openTokenNode(left);
|
|
1053
|
-
const rightNode = openTokenNode(right);
|
|
1054
|
-
return NodeApi.isText(leftNode) && NodeApi.isText(rightNode) ? true : ElementApi.isElement(leftNode) && ElementApi.isElement(rightNode) && getElementType(leftNode) === getElementType(rightNode);
|
|
1055
|
-
};
|
|
1056
|
-
const leafBlocksShareContent = (left, right) => {
|
|
1057
|
-
const leftNode = openTokenNode(left);
|
|
1058
|
-
const rightNode = openTokenNode(right);
|
|
1059
|
-
return NodeApi.isText(leftNode) && NodeApi.isText(rightNode) || ElementApi.isElement(leftNode) && ElementApi.isElement(rightNode) && contextsShareContent(leftNode, rightNode);
|
|
1060
|
-
};
|
|
1061
|
-
let startContext;
|
|
1062
|
-
let endContext;
|
|
1063
|
-
const getStartContext = () => startContext ??= getOpenContext(exactFrom);
|
|
1064
|
-
const getEndContext = () => endContext ??= getOpenContext(exactTo);
|
|
1065
|
-
const getLocalSyncPosition = () => {
|
|
1066
|
-
let sync = exactTo;
|
|
1067
|
-
let parentPath = end.path.slice(0, -1);
|
|
1068
|
-
while (parentPath.length > 0) {
|
|
1069
|
-
const parent = getDescendant(rootChildren, parentPath);
|
|
1070
|
-
if (!parent || !ElementApi.isElement(parent)) break;
|
|
1071
|
-
const behavior = getElementBehavior(parent);
|
|
1072
|
-
if (behavior.isolating || behavior.void || getElementSlicePolicy(parent).preserveContext) break;
|
|
1073
|
-
const childIndex = end.path[parentPath.length];
|
|
1074
|
-
if (!elementUsesInlineContent(parent) && childIndex !== parent.children.length - 1) break;
|
|
1075
|
-
sync = document.nodeRange(parentPath).to;
|
|
1076
|
-
parentPath = parentPath.slice(0, -1);
|
|
1077
|
-
}
|
|
1078
|
-
return sync;
|
|
1079
|
-
};
|
|
1080
|
-
const targetHasInlineAncestor = start.path.slice(0, -1).map((_part, index) => getDescendant(rootChildren, start.path.slice(0, index + 1))).some((node) => ElementApi.isElement(node) && getElementBehavior(node).inline);
|
|
1081
|
-
const createLocalTextCandidate = (variant, cost, allowAsymmetric = false) => {
|
|
1082
|
-
if (exactBounds || !targetText || !NodeApi.isText(targetText)) return null;
|
|
1083
|
-
if (!allowAsymmetric && inputSlice.openStart === inputSlice.openEnd && variant.openStart !== variant.openEnd) return null;
|
|
1084
|
-
if (variant.openStart === inputSlice.openStart && variant.openStart > 1 && sameTextPath && start.offset === end.offset && start.offset === targetText.text.length && targetText.text.length > 0) return null;
|
|
1085
|
-
const preparedOpenBlockCandidate = (() => {
|
|
1086
|
-
if (variant.openStart !== 1 || variant.openEnd !== 1 || start.path.length !== 2 || !sameTextPath) return null;
|
|
1087
|
-
const targetPath = start.path.slice(0, -1);
|
|
1088
|
-
const targetBlock = getDescendant(rootChildren, targetPath);
|
|
1089
|
-
if (!targetBlock || !ElementApi.isElement(targetBlock) || targetBlock.children.length !== 1 || targetBlock.children[0] !== targetText) return null;
|
|
1090
|
-
const firstSourceBlock = variant.content[0];
|
|
1091
|
-
if (!firstSourceBlock || !ElementApi.isElement(firstSourceBlock) || !rootCanContain(firstSourceBlock)) return null;
|
|
1092
|
-
const sourceBlocks = variant.content;
|
|
1093
|
-
const targetType = getElementType(targetBlock);
|
|
1094
|
-
const targetElementKeys = Object.keys(targetBlock).filter((key) => key !== "children");
|
|
1095
|
-
const targetTextKeys = Object.keys(targetText).filter((key) => key !== "text");
|
|
1096
|
-
if (sourceBlocks.some((block) => {
|
|
1097
|
-
const text = ElementApi.isElement(block) ? block.children[0] : void 0;
|
|
1098
|
-
return !NodeApi.isText(text) || getElementType(block) !== targetType || block.children.length !== 1 || !nodePropertiesEqual(block, targetBlock, "children", targetElementKeys) || !nodePropertiesEqual(text, targetText, "text", targetTextKeys);
|
|
1099
|
-
})) return null;
|
|
1100
|
-
const prefix = targetText.text.slice(0, start.offset);
|
|
1101
|
-
const suffix = targetText.text.slice(end.offset);
|
|
1102
|
-
if (!isDetachedContentSlice(variant)) return null;
|
|
1103
|
-
const fullInsert = encodeContentSliceContent(variant);
|
|
1104
|
-
if (!getPreparedDocumentSlice(fullInsert)) return null;
|
|
1105
|
-
const openInsert = encodeContentSlice(variant);
|
|
1106
|
-
const semanticInsert = openInsert.slice(1, openInsert.length - 1);
|
|
1107
|
-
const targetRange = document.nodeRange(targetPath);
|
|
1108
|
-
return Object.freeze({
|
|
1109
|
-
cost,
|
|
1110
|
-
from: targetRange.from,
|
|
1111
|
-
preparedOpenBlock: Object.freeze({
|
|
1112
|
-
fullInsert,
|
|
1113
|
-
prefix,
|
|
1114
|
-
semanticInsert,
|
|
1115
|
-
sourceBlocks: Object.freeze(sourceBlocks),
|
|
1116
|
-
suffix,
|
|
1117
|
-
targetPath: Object.freeze(targetPath)
|
|
1118
|
-
}),
|
|
1119
|
-
to: targetRange.to
|
|
1120
|
-
});
|
|
1121
|
-
})();
|
|
1122
|
-
if (preparedOpenBlockCandidate) return preparedOpenBlockCandidate;
|
|
1123
|
-
let encoded = encodeContentSlice(variant);
|
|
1124
|
-
if (collapsed && variant.openStart === 0 && variant.openEnd === 0 && start.path.length === 2 && ElementApi.isElement(targetParent) && holdsNoContent(targetParent, contentSchema) && getPreparedDocumentSlice(encoded) && variant.content.every(rootCanContain)) {
|
|
1125
|
-
const targetRange = document.nodeRange(start.path.slice(0, -1));
|
|
1126
|
-
return Object.freeze({
|
|
1127
|
-
content: {
|
|
1128
|
-
from: 0,
|
|
1129
|
-
to: encoded.length
|
|
1130
|
-
},
|
|
1131
|
-
cost,
|
|
1132
|
-
from: targetRange.from,
|
|
1133
|
-
insert: encoded,
|
|
1134
|
-
origins: sliceOrigins(encoded),
|
|
1135
|
-
selectionOffset: encoded.length - getSliceEdgeOpenDepth(variant.content, "end") - 1,
|
|
1136
|
-
to: targetRange.to
|
|
1137
|
-
});
|
|
1138
|
-
}
|
|
1139
|
-
if (variant.openEnd === 0 && start.offset === 0 && start.offset === end.offset) {
|
|
1140
|
-
const terminal = variant.content.at(-1);
|
|
1141
|
-
if (targetParent && ElementApi.isElement(targetParent) && terminal && ElementApi.isElement(terminal) && getElementType(targetParent) === getElementType(terminal) && encoded.tokens.at(-1)?.kind === "close") encoded = encoded.slice(0, encoded.length - 1);
|
|
1142
|
-
}
|
|
1143
|
-
if (encoded.length === 0) return null;
|
|
1144
|
-
const output = [];
|
|
1145
|
-
const localStartContext = getStartContext();
|
|
1146
|
-
const localEndContext = getEndContext();
|
|
1147
|
-
const getProtectedDepth = (context) => context.findLastIndex((token) => {
|
|
1148
|
-
const node = openTokenNode(token);
|
|
1149
|
-
if (!ElementApi.isElement(node)) return false;
|
|
1150
|
-
const behavior = getElementBehavior(node);
|
|
1151
|
-
return behavior.isolating || behavior.void || getElementSlicePolicy(node).preserveContext;
|
|
1152
|
-
}) + 1;
|
|
1153
|
-
const protectedDepth = getProtectedDepth(localStartContext);
|
|
1154
|
-
if (protectedDepth !== getProtectedDepth(localEndContext) || start.path.slice(0, protectedDepth).some((part, index) => part !== end.path[index])) return null;
|
|
1155
|
-
const stack = [...localStartContext];
|
|
1156
|
-
const origins = new FitOriginLog();
|
|
1157
|
-
let outputPosition = 0;
|
|
1158
|
-
let selectionPosition = null;
|
|
1159
|
-
let contentStart = null;
|
|
1160
|
-
const append = (token, kind = "fit", sourceAt = 0) => {
|
|
1161
|
-
const length = tokenLength(token);
|
|
1162
|
-
output.push(token);
|
|
1163
|
-
origins.add(length, kind, sourceAt);
|
|
1164
|
-
outputPosition += length;
|
|
1165
|
-
};
|
|
1166
|
-
const closeTop = (kind = "fit", sourceAt = 0) => {
|
|
1167
|
-
if (stack.length <= protectedDepth) return false;
|
|
1168
|
-
const top = stack.pop();
|
|
1169
|
-
if (!top) return false;
|
|
1170
|
-
append({
|
|
1171
|
-
kind: "close",
|
|
1172
|
-
nodeKind: top.nodeKind
|
|
1173
|
-
}, kind, sourceAt);
|
|
1174
|
-
return true;
|
|
1175
|
-
};
|
|
1176
|
-
const canCurrentContain = (child) => {
|
|
1177
|
-
const parentToken = stack.at(-1);
|
|
1178
|
-
if (!parentToken) return rootCanContain(child);
|
|
1179
|
-
if (parentToken.nodeKind === "text") return false;
|
|
1180
|
-
const parent = openTokenNode(parentToken);
|
|
1181
|
-
if (!ElementApi.isElement(parent)) return false;
|
|
1182
|
-
const blockTypes = parent.children.filter((current) => ElementApi.isElement(current) && !getElementBehavior(current).inline).map((current) => getElementType(current));
|
|
1183
|
-
const homogeneousType = blockTypes[0];
|
|
1184
|
-
if (!getCompiledElement(parent)?.content && homogeneousType && parent.children.some((current) => ElementApi.isElement(current) && getElementType(current) === homogeneousType && elementUsesInlineContent(current)) && blockTypes.every((type) => type === homogeneousType) && ElementApi.isElement(child) && !getElementBehavior(child).inline) return getElementType(child) === homogeneousType;
|
|
1185
|
-
return canContain(parent, child);
|
|
1186
|
-
};
|
|
1187
|
-
const openFitted = (token, kind = "fit", sourceAt = 0) => {
|
|
1188
|
-
const child = openTokenNode(token);
|
|
1189
|
-
while (!canCurrentContain(child)) if (!closeTop()) return false;
|
|
1190
|
-
append(token, kind, sourceAt);
|
|
1191
|
-
stack.push(token);
|
|
1192
|
-
return true;
|
|
1193
|
-
};
|
|
1194
|
-
if (variant.openStart > 0) {
|
|
1195
|
-
let children = variant.content;
|
|
1196
|
-
let preferred = null;
|
|
1197
|
-
for (let depth = 0; depth < variant.openStart; depth++) {
|
|
1198
|
-
const node = children[0];
|
|
1199
|
-
if (!node || !ElementApi.isElement(node)) return null;
|
|
1200
|
-
preferred = node;
|
|
1201
|
-
({children} = node);
|
|
1202
|
-
}
|
|
1203
|
-
const targetDepth = start.path.slice(0, -1).map((_part, index) => getDescendant(rootChildren, start.path.slice(0, index + 1))).findLastIndex((node) => preferred && ElementApi.isElement(node) && contextsShareContent(node, preferred));
|
|
1204
|
-
if (targetDepth === -1) return null;
|
|
1205
|
-
while (stack.length > targetDepth + 1) if (!closeTop()) return null;
|
|
1206
|
-
}
|
|
1207
|
-
if (variant.openStart === 0 && variant.openEnd === 0 && targetHasInlineAncestor) while (stack.length > 0) {
|
|
1208
|
-
const top = openTokenNode(stack.at(-1));
|
|
1209
|
-
if (NodeApi.isText(top) || ElementApi.isElement(top) && getElementBehavior(top).inline) {
|
|
1210
|
-
if (!closeTop()) return null;
|
|
1211
|
-
continue;
|
|
1212
|
-
}
|
|
1213
|
-
break;
|
|
1214
|
-
}
|
|
1215
|
-
const endTextToken = localEndContext.findLast((token) => token.nodeKind === "text");
|
|
1216
|
-
const ensureTextContext = () => {
|
|
1217
|
-
if (stack.at(-1)?.nodeKind === "text") return true;
|
|
1218
|
-
if (stack.length === 0) for (const token of localEndContext) {
|
|
1219
|
-
if (!openFitted(token)) return false;
|
|
1220
|
-
if (token.nodeKind === "text") return true;
|
|
1221
|
-
}
|
|
1222
|
-
return openFitted(endTextToken ?? {
|
|
1223
|
-
kind: "open",
|
|
1224
|
-
nodeKind: "text",
|
|
1225
|
-
props: {}
|
|
1226
|
-
});
|
|
1227
|
-
};
|
|
1228
|
-
const openEndContextFor = (child) => {
|
|
1229
|
-
if (!collapsed || stack.length > 0 || !ElementApi.isElement(child) || !getElementBehavior(child).inline) return true;
|
|
1230
|
-
for (const token of localEndContext) {
|
|
1231
|
-
if (token.nodeKind === "text") return true;
|
|
1232
|
-
if (!openFitted(token)) return false;
|
|
1233
|
-
if (canCurrentContain(child)) return true;
|
|
1234
|
-
}
|
|
1235
|
-
return true;
|
|
1236
|
-
};
|
|
1237
|
-
const process = (token, kind, sourceAt = 0) => {
|
|
1238
|
-
if (token.kind === "open") return openEndContextFor(openTokenNode(token)) && openFitted(token, kind, sourceAt);
|
|
1239
|
-
if (token.kind === "close") {
|
|
1240
|
-
const top = stack.at(-1);
|
|
1241
|
-
if (!top) return true;
|
|
1242
|
-
return kind === "document" && top.nodeKind !== token.nodeKind ? closeTop() : closeTop(kind, sourceAt);
|
|
1243
|
-
}
|
|
1244
|
-
if (!ensureTextContext()) return false;
|
|
1245
|
-
append(token, kind, sourceAt);
|
|
1246
|
-
return true;
|
|
1247
|
-
};
|
|
1248
|
-
const selectionFollowsInlineVoid = endsInInlineVoid(variant);
|
|
1249
|
-
const contentEnd = selectionFollowsInlineVoid ? encoded.length : getContentEndOffset(encoded);
|
|
1250
|
-
let insertedPosition = 0;
|
|
1251
|
-
for (const token of encoded.tokens) {
|
|
1252
|
-
const appended = output.length;
|
|
1253
|
-
if (!process(token, "slice")) return null;
|
|
1254
|
-
if (output.length > appended) contentStart ??= outputPosition - tokenLength(token);
|
|
1255
|
-
insertedPosition += tokenLength(token);
|
|
1256
|
-
if (selectionPosition === null && insertedPosition >= contentEnd) selectionPosition = outputPosition - (insertedPosition - contentEnd);
|
|
1257
|
-
}
|
|
1258
|
-
selectionPosition ??= outputPosition;
|
|
1259
|
-
const content = {
|
|
1260
|
-
from: contentStart ?? outputPosition,
|
|
1261
|
-
to: outputPosition
|
|
1262
|
-
};
|
|
1263
|
-
const syncPosition = getLocalSyncPosition();
|
|
1264
|
-
const expected = syncPosition === exactTo ? localEndContext : getOpenContext(syncPosition);
|
|
1265
|
-
const sourceAlreadyAtSync = allowAsymmetric && stack.length === expected.length && stack.every((token, index) => openContextsMatch(token, expected[index]));
|
|
1266
|
-
if (!sourceAlreadyAtSync && stack.length > 0 && stack.length < localEndContext.length && stack.every((token, index) => index < stack.length - 1 ? openContextsMatch(token, localEndContext[index]) : leafBlocksShareContent(token, localEndContext[index]))) for (let index = stack.length; index < localEndContext.length; index++) {
|
|
1267
|
-
append(localEndContext[index]);
|
|
1268
|
-
stack.push(localEndContext[index]);
|
|
1269
|
-
}
|
|
1270
|
-
if (!sourceAlreadyAtSync) {
|
|
1271
|
-
let tailPosition = exactTo;
|
|
1272
|
-
for (const token of document.tokens.slice(exactTo, syncPosition).tokens) {
|
|
1273
|
-
if (!process(token, "document", tailPosition)) return null;
|
|
1274
|
-
tailPosition += tokenLength(token);
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
let shared = 0;
|
|
1278
|
-
while (shared < stack.length && shared < expected.length) {
|
|
1279
|
-
if (!openContextsMatch(stack[shared], expected[shared])) break;
|
|
1280
|
-
shared += 1;
|
|
1281
|
-
}
|
|
1282
|
-
while (stack.length > shared) if (!closeTop()) return null;
|
|
1283
|
-
for (let index = shared; index < expected.length; index++) {
|
|
1284
|
-
append(expected[index]);
|
|
1285
|
-
stack.push(expected[index]);
|
|
1286
|
-
}
|
|
1287
|
-
let candidateFrom = exactFrom;
|
|
1288
|
-
let candidateOutput = output;
|
|
1289
|
-
let removedPrefixLength = 0;
|
|
1290
|
-
for (const boundary of boundaries) {
|
|
1291
|
-
if (boundary.from >= exactFrom || boundary.to !== exactTo) continue;
|
|
1292
|
-
const opened = document.tokens.slice(boundary.from, exactFrom).tokens;
|
|
1293
|
-
if (opened.length === 0 || !opened.every((token) => token.kind === "open") || !opened.every((_token, index) => {
|
|
1294
|
-
const close = output[index];
|
|
1295
|
-
const open = opened.at(-(index + 1));
|
|
1296
|
-
return close?.kind === "close" && open?.kind === "open" && close.nodeKind === open.nodeKind;
|
|
1297
|
-
})) continue;
|
|
1298
|
-
candidateFrom = boundary.from;
|
|
1299
|
-
removedPrefixLength = opened.length;
|
|
1300
|
-
candidateOutput = output.slice(opened.length);
|
|
1301
|
-
origins.dropStart(opened.length);
|
|
1302
|
-
break;
|
|
1303
|
-
}
|
|
1304
|
-
const insert = PreparedTokenSlice.fromTokens(candidateOutput);
|
|
1305
|
-
return Object.freeze({
|
|
1306
|
-
content: {
|
|
1307
|
-
from: Math.max(0, content.from - removedPrefixLength),
|
|
1308
|
-
to: Math.max(0, content.to - removedPrefixLength)
|
|
1309
|
-
},
|
|
1310
|
-
cost,
|
|
1311
|
-
from: candidateFrom,
|
|
1312
|
-
insert,
|
|
1313
|
-
origins: origins.seal(insert),
|
|
1314
|
-
...selectionFollowsInlineVoid ? { selectionAssociation: 1 } : {},
|
|
1315
|
-
selectionOffset: selectionPosition - removedPrefixLength,
|
|
1316
|
-
to: syncPosition
|
|
1317
|
-
});
|
|
1318
|
-
};
|
|
1319
|
-
const sourceEdges = [inputSlice.content[0], inputSlice.content.at(-1)];
|
|
1320
|
-
const sourceSharesTargetContent = ElementApi.isElement(targetParent) && sourceEdges.some((edge) => ElementApi.isElement(edge) && (getElementType(edge) === getElementType(targetParent) || NodeApi.string(edge).length > 0 && contextsShareContent(targetParent, edge)));
|
|
1321
|
-
const hasContextualStructuralVariant = () => getTargetVariantFamilies().some((family) => family.priority < 0);
|
|
1322
|
-
const preserveClosedInlineBoundary = inputSlice.openStart === 0 && inputSlice.openEnd === 0 && targetHasInlineAncestor;
|
|
1323
|
-
const preserveClosedStructuralBoundary = sourceSlice.openStart === 0 && sourceSlice.openEnd === 0 && inputSlice.content.every(rootCanContain) && !sourceSharesTargetContent;
|
|
1324
|
-
const shouldGenerateLocalCandidate = () => prefixInsertionBoundary === null && !exactBounds && inputSlice.content.length > 0 && (!sameTextPath && NodeApi.isText(targetText) && NodeApi.isText(endText) && (start.offset > 0 || end.offset < endText.text.length) || hasContextualStructuralVariant() && start.path.length > 2 && Boolean(targetText && NodeApi.isText(targetText) && targetText.text) || inputSlice.openStart !== inputSlice.openEnd && start.path.length > 2 || inputSlice.openStart === 1 && inputSlice.openEnd === 1 && start.path.length === 2 || inputSlice.content.length > 1 && start.path.length > 2 || inputSlice.openStart > 0 && targetHasInlineAncestor || !collapsed && targetHasInlineAncestor || inputSlice.openStart === 0 && inputSlice.openEnd === 0 && caretSplitsBlockContent || inputSlice.openStart === 0 && inputSlice.openEnd === 0 && Boolean(targetText && NodeApi.isText(targetText) && (targetText.text ? sourceSharesTargetContent ? start.offset > 0 || end.offset < targetText.text.length : start.offset > 0 && end.offset < targetText.text.length : sourceSharesTargetContent && start.path.length > 2)));
|
|
1325
|
-
const preferOpenVariants = !preserveClosedInlineBoundary && !preserveClosedStructuralBoundary && (!collapsed || start.offset > 0 && targetText && NodeApi.isText(targetText) && start.offset < targetText.text.length || caretSplitsBlockContent || sourceSharesTargetContent);
|
|
1326
|
-
const getInsertionContent = (variant) => {
|
|
1327
|
-
if (variant.openStart !== variant.openEnd) return null;
|
|
1328
|
-
let { content } = variant;
|
|
1329
|
-
for (let depth = 0; depth < variant.openStart; depth++) {
|
|
1330
|
-
const node = content.length === 1 ? content[0] : null;
|
|
1331
|
-
if (!node || !ElementApi.isElement(node)) return null;
|
|
1332
|
-
content = node.children;
|
|
1333
|
-
}
|
|
1334
|
-
return content;
|
|
1335
|
-
};
|
|
1336
|
-
const canInsertContentAtBoundary = (boundary, content) => {
|
|
1337
|
-
if (content.length === 0) return true;
|
|
1338
|
-
if (!exactBounds && boundary.from === exactFrom && boundary.to === exactTo && sameTextPath) {
|
|
1339
|
-
const parent = getDescendant(rootChildren, start.path.slice(0, -1));
|
|
1340
|
-
return Boolean(parent && ElementApi.isElement(parent)) && content.every((child) => canContain(parent, child));
|
|
1341
|
-
}
|
|
1342
|
-
const from = document.childBoundaryAt(boundary.from);
|
|
1343
|
-
const to = document.childBoundaryAt(boundary.to);
|
|
1344
|
-
if (!from || !to || from.parentPath.length !== to.parentPath.length || from.parentPath.some((part, index) => part !== to.parentPath[index])) return false;
|
|
1345
|
-
const innerSchema12 = getDeclarativeSchema();
|
|
1346
|
-
const parent = from.parentPath.length === 0 ? null : getDescendant(rootChildren, from.parentPath);
|
|
1347
|
-
const parentChildren = parent ? ElementApi.isElement(parent) ? parent.children : null : rootChildren;
|
|
1348
|
-
if (!parentChildren) return false;
|
|
1349
|
-
if (!innerSchema12) {
|
|
1350
|
-
if (parent) {
|
|
1351
|
-
if (!ElementApi.isElement(parent)) return false;
|
|
1352
|
-
return content.every((child) => canContain(parent, child));
|
|
1353
|
-
}
|
|
1354
|
-
if (options.target.kind === "root") return true;
|
|
1355
|
-
return content.every((child) => {
|
|
1356
|
-
if (!ElementApi.isElement(child)) return false;
|
|
1357
|
-
return !getElementBehavior(child).inline;
|
|
1358
|
-
});
|
|
1359
|
-
}
|
|
1360
|
-
if (parent && !ElementApi.isElement(parent)) return false;
|
|
1361
|
-
const parentType = parent ? getElementType(parent) : null;
|
|
1362
|
-
const program = parentType ? innerSchema12.elements.byType.get(parentType)?.content : targetRootProgram;
|
|
1363
|
-
if (!program) return !parent && content.every(rootCanContain);
|
|
1364
|
-
return acceptsReplacement(innerSchema12, program, parentChildren, from.index, to.index, content, {
|
|
1365
|
-
ancestors: parent && ElementApi.isElement(parent) ? getElementAncestors(rootChildren, from.parentPath, { includeTarget: true }) : [],
|
|
1366
|
-
root
|
|
1367
|
-
});
|
|
1368
|
-
};
|
|
1369
|
-
const canApplyLocalOpenBlockCandidate = (variant) => {
|
|
1370
|
-
if (variant.openStart !== 1 || variant.openEnd !== 1 || sameTextPath) return true;
|
|
1371
|
-
const startBlockPath = start.path.slice(0, -1);
|
|
1372
|
-
const endBlockPath = end.path.slice(0, -1);
|
|
1373
|
-
const parentPath = startBlockPath.slice(0, -1);
|
|
1374
|
-
const endParentPath = endBlockPath.slice(0, -1);
|
|
1375
|
-
const targetBlock = getDescendant(rootChildren, startBlockPath);
|
|
1376
|
-
const sourceBlocks = variant.content;
|
|
1377
|
-
if (parentPath.length !== endParentPath.length || parentPath.some((part, index) => part !== endParentPath[index]) || !targetBlock || !ElementApi.isElement(targetBlock) || sourceBlocks.some((child) => !ElementApi.isElement(child))) return true;
|
|
1378
|
-
return canInsertContentAtBoundary({
|
|
1379
|
-
cost: 0,
|
|
1380
|
-
from: document.nodeRange(startBlockPath).from,
|
|
1381
|
-
to: document.nodeRange(endBlockPath).to
|
|
1382
|
-
}, [targetBlock, ...sourceBlocks.slice(1)]);
|
|
1383
|
-
};
|
|
1384
|
-
const fitOpenBlocksToPositionalSlots = (variant) => {
|
|
1385
|
-
if (variant.openStart !== 1 || variant.openEnd !== 1 || sameTextPath) return null;
|
|
1386
|
-
const targetSchema = getDeclarativeSchema();
|
|
1387
|
-
const startBlockPath = start.path.slice(0, -1);
|
|
1388
|
-
const endBlockPath = end.path.slice(0, -1);
|
|
1389
|
-
const parentPath = startBlockPath.slice(0, -1);
|
|
1390
|
-
const endParentPath = endBlockPath.slice(0, -1);
|
|
1391
|
-
const startIndex = startBlockPath.at(-1);
|
|
1392
|
-
const parent = parentPath.length ? getDescendant(rootChildren, parentPath) : null;
|
|
1393
|
-
const content = targetSchema && parent && ElementApi.isElement(parent) ? targetSchema.elements.byType.get(getElementType(parent) ?? "")?.content : targetSchema ? targetRootProgram : null;
|
|
1394
|
-
if (!targetSchema || !content?.prefix || startIndex === void 0 || parentPath.length !== endParentPath.length || parentPath.some((part, index) => part !== endParentPath[index]) || variant.content.some((child) => !ElementApi.isElement(child))) return null;
|
|
1395
|
-
const targetOptions = {
|
|
1396
|
-
ancestors: parent && ElementApi.isElement(parent) ? [parent, ...getElementAncestors(rootChildren, parentPath)] : [],
|
|
1397
|
-
root
|
|
1398
|
-
};
|
|
1399
|
-
const fitted = [];
|
|
1400
|
-
let changed = false;
|
|
1401
|
-
for (const [offset, descendant] of variant.content.entries()) {
|
|
1402
|
-
const sourceBlock = descendant;
|
|
1403
|
-
const index = startIndex + offset;
|
|
1404
|
-
if (contentAllowsAt(targetSchema, content, sourceBlock, index, targetOptions)) {
|
|
1405
|
-
fitted.push(sourceBlock);
|
|
1406
|
-
continue;
|
|
1407
|
-
}
|
|
1408
|
-
const slot = content.prefix[index];
|
|
1409
|
-
if (!slot) return null;
|
|
1410
|
-
const shell = createDeclarativeAndFill(targetSchema, slot.type, slot.properties, /* @__PURE__ */ new Set(), targetOptions);
|
|
1411
|
-
if (!contextsShareContent(shell, sourceBlock)) return null;
|
|
1412
|
-
const shellContent = targetSchema.elements.byType.get(slot.type)?.content;
|
|
1413
|
-
const children = shellContent ? fitClosedContent(targetSchema, `element:${slot.type}`, shellContent, sourceBlock.children, {
|
|
1414
|
-
ancestors: [shell, ...targetOptions.ancestors ?? []],
|
|
1415
|
-
root
|
|
1416
|
-
}, true) : sourceBlock.children;
|
|
1417
|
-
if (!children) return null;
|
|
1418
|
-
fitted.push(Object.freeze({
|
|
1419
|
-
...shell,
|
|
1420
|
-
children: Object.freeze([...children])
|
|
1421
|
-
}));
|
|
1422
|
-
changed = true;
|
|
1423
|
-
}
|
|
1424
|
-
return changed ? ContentSlice.fromJSON({
|
|
1425
|
-
content: fitted,
|
|
1426
|
-
openEnd: variant.openEnd,
|
|
1427
|
-
openStart: variant.openStart
|
|
1428
|
-
}) : null;
|
|
1429
|
-
};
|
|
1430
|
-
const materializeCandidate = (candidate) => {
|
|
1431
|
-
if ("insert" in candidate) return candidate;
|
|
1432
|
-
const { preparedOpenBlock, ...base } = candidate;
|
|
1433
|
-
const { fullInsert, prefix, semanticInsert, sourceBlocks, suffix, targetPath } = preparedOpenBlock;
|
|
1434
|
-
const mergeText = (block, text) => {
|
|
1435
|
-
const sourceText = block.children[0];
|
|
1436
|
-
if (!sourceText || !NodeApi.isText(sourceText)) throw new Error("Prepared open block fit requires one text leaf.");
|
|
1437
|
-
const children = [Object.freeze({
|
|
1438
|
-
...sourceText,
|
|
1439
|
-
text
|
|
1440
|
-
})];
|
|
1441
|
-
Object.freeze(children);
|
|
1442
|
-
return Object.freeze({
|
|
1443
|
-
...block,
|
|
1444
|
-
children
|
|
1445
|
-
});
|
|
1446
|
-
};
|
|
1447
|
-
const first = sourceBlocks[0];
|
|
1448
|
-
const last = sourceBlocks.at(-1);
|
|
1449
|
-
if (!first || !last) throw new Error("Prepared open block fit requires source blocks.");
|
|
1450
|
-
const firstText = first.children[0];
|
|
1451
|
-
const lastText = last.children[0];
|
|
1452
|
-
if (!firstText || !lastText || !NodeApi.isText(firstText) || !NodeApi.isText(lastText)) throw new Error("Prepared open block fit requires text boundaries.");
|
|
1453
|
-
const preparedContent = prefix.length === 0 && suffix.length === 0 ? sourceBlocks : sourceBlocks.length === 1 ? [mergeText(first, prefix + firstText.text + suffix)] : [
|
|
1454
|
-
mergeText(first, prefix + firstText.text),
|
|
1455
|
-
...sourceBlocks.slice(1, -1),
|
|
1456
|
-
mergeText(last, lastText.text + suffix)
|
|
1457
|
-
];
|
|
1458
|
-
Object.freeze(preparedContent);
|
|
1459
|
-
const insert = prefix.length === 0 && suffix.length === 0 ? fullInsert : PreparedTokenSlice.fromPreparedNodes(preparedContent);
|
|
1460
|
-
const targetIndex = targetPath[0];
|
|
1461
|
-
const lastIndex = targetIndex + preparedContent.length - 1;
|
|
1462
|
-
const runtimeCandidatePaths = [Object.freeze([targetIndex]), Object.freeze([targetIndex, 0])];
|
|
1463
|
-
if (lastIndex !== targetIndex) runtimeCandidatePaths.push(Object.freeze([lastIndex]), Object.freeze([lastIndex, 0]));
|
|
1464
|
-
Object.freeze(runtimeCandidatePaths);
|
|
1465
|
-
const textBlockEdge = 2;
|
|
1466
|
-
const selectionOffset = insert.length - suffix.length - textBlockEdge;
|
|
1467
|
-
const content = {
|
|
1468
|
-
from: prefix.length + textBlockEdge,
|
|
1469
|
-
to: selectionOffset
|
|
1470
|
-
};
|
|
1471
|
-
const origins = new FitOriginLog();
|
|
1472
|
-
origins.add(content.from, "document", base.from);
|
|
1473
|
-
origins.add(content.to - content.from, "slice");
|
|
1474
|
-
origins.add(insert.length - content.to, "document", exactTo);
|
|
1475
|
-
return Object.freeze({
|
|
1476
|
-
...base,
|
|
1477
|
-
content,
|
|
1478
|
-
insert,
|
|
1479
|
-
origins: origins.seal(insert),
|
|
1480
|
-
runtimeCandidatePaths,
|
|
1481
|
-
semanticChange: Object.freeze({
|
|
1482
|
-
from: exactFrom,
|
|
1483
|
-
insert: semanticInsert,
|
|
1484
|
-
to: exactTo
|
|
1485
|
-
}),
|
|
1486
|
-
selectionOffset,
|
|
1487
|
-
trustedCanonical: true
|
|
1488
|
-
});
|
|
1489
|
-
};
|
|
1490
|
-
const getStructuralContext = (position) => document.openContextAt(position).filter((entry) => entry.from < position && position < entry.to);
|
|
1491
|
-
const textCell = (() => {
|
|
1492
|
-
const context = getStructuralContext(exactFrom);
|
|
1493
|
-
for (let level = context.length - 1; level >= 0; level -= 1) {
|
|
1494
|
-
const node = getDescendant(rootChildren, context[level].path);
|
|
1495
|
-
if (ElementApi.isElement(node) && isGridCell(node) && getCompiledElement(node)?.content?.allowsText) return {
|
|
1496
|
-
depth: level + 1,
|
|
1497
|
-
...context[level]
|
|
1498
|
-
};
|
|
1499
|
-
}
|
|
1500
|
-
return null;
|
|
1501
|
-
})();
|
|
1502
|
-
const getChildCountsThrough = (context, position) => [...context.map(({ path }) => getDefined(path.at(-1)) + 1), document.childBoundaryAt(position)?.index ?? 0];
|
|
1503
|
-
const isStructurallyApplicable = (candidate) => {
|
|
1504
|
-
if (textCell && (candidate.from <= textCell.from || candidate.to >= textCell.to)) return false;
|
|
1505
|
-
if ("preparedOpenBlock" in candidate) {
|
|
1506
|
-
const from = document.childBoundaryAt(candidate.from);
|
|
1507
|
-
const to = document.childBoundaryAt(candidate.to);
|
|
1508
|
-
if (!from || !to || from.parentPath.length !== to.parentPath.length || from.parentPath.some((part, index) => part !== to.parentPath[index])) return false;
|
|
1509
|
-
return canInsertContentAtBoundary(candidate, candidate.preparedOpenBlock.sourceBlocks);
|
|
1510
|
-
}
|
|
1511
|
-
const prepared = getPreparedDocumentSlice(candidate.insert);
|
|
1512
|
-
if (prepared) {
|
|
1513
|
-
const from = document.childBoundaryAt(candidate.from);
|
|
1514
|
-
const to = document.childBoundaryAt(candidate.to);
|
|
1515
|
-
if (!from || !to || from.parentPath.length !== to.parentPath.length || from.parentPath.some((part, index) => part !== to.parentPath[index])) return false;
|
|
1516
|
-
return prepared.nodes.every(NodeApi.isDescendant) && canInsertContentAtBoundary(candidate, prepared.nodes);
|
|
1517
|
-
}
|
|
1518
|
-
const from = document.childBoundaryAt(candidate.from);
|
|
1519
|
-
const to = document.childBoundaryAt(candidate.to);
|
|
1520
|
-
if (from && to && from.parentPath.length === to.parentPath.length && from.parentPath.every((part, index) => part === to.parentPath[index])) try {
|
|
1521
|
-
const inserted = decodeNodes(candidate.insert).nodes;
|
|
1522
|
-
if (inserted.every(NodeApi.isDescendant) && !canInsertContentAtBoundary(candidate, inserted)) return false;
|
|
1523
|
-
} catch {}
|
|
1524
|
-
const fromContext = getStructuralContext(candidate.from);
|
|
1525
|
-
const stack = fromContext.map((entry) => entry.kind);
|
|
1526
|
-
const programs = [targetRootProgram, ...fromContext.map(({ path }) => {
|
|
1527
|
-
const node = getDescendant(rootChildren, path);
|
|
1528
|
-
return ElementApi.isElement(node) ? getCompiledElement(node)?.content ?? null : null;
|
|
1529
|
-
})];
|
|
1530
|
-
const counts = getChildCountsThrough(fromContext, candidate.from);
|
|
1531
|
-
const exceedsBlockMax = (program, count) => !!program && !program.allowsText && program.max !== null && count > program.max;
|
|
1532
|
-
for (const token of candidate.insert.tokens) {
|
|
1533
|
-
if (token.kind === "open") {
|
|
1534
|
-
if (stack.at(-1) === "text") return false;
|
|
1535
|
-
counts[stack.length] += 1;
|
|
1536
|
-
stack.push(token.nodeKind);
|
|
1537
|
-
programs.push(getCompiledElement(token.props)?.content ?? null);
|
|
1538
|
-
counts.push(0);
|
|
1539
|
-
continue;
|
|
1540
|
-
}
|
|
1541
|
-
if (token.kind === "text") {
|
|
1542
|
-
if (stack.at(-1) !== "text") return false;
|
|
1543
|
-
continue;
|
|
1544
|
-
}
|
|
1545
|
-
if (stack.length === textCell?.depth) return false;
|
|
1546
|
-
if (stack.pop() !== token.nodeKind) return false;
|
|
1547
|
-
if (exceedsBlockMax(programs.pop(), getDefined(counts.pop()))) return false;
|
|
1548
|
-
}
|
|
1549
|
-
const toContext = getStructuralContext(candidate.to);
|
|
1550
|
-
if (stack.length !== toContext.length || stack.some((kind, index) => kind !== toContext[index].kind)) return false;
|
|
1551
|
-
const toCounts = getChildCountsThrough(toContext, candidate.to);
|
|
1552
|
-
return counts.every((count, level) => {
|
|
1553
|
-
const parent = level === 0 ? null : getDescendant(rootChildren, toContext[level - 1].path);
|
|
1554
|
-
const childCount = level === 0 ? rootChildren.length : ElementApi.isElement(parent) ? parent.children.length : 0;
|
|
1555
|
-
return !exceedsBlockMax(programs[level], count + childCount - toCounts[level]);
|
|
1556
|
-
});
|
|
1557
|
-
};
|
|
1558
|
-
const createSeeds = () => profileCoreDuration("slice-fit-candidate-scoring", () => {
|
|
1559
|
-
const result = [];
|
|
1560
|
-
for (const family of getTargetVariantFamilies()) {
|
|
1561
|
-
if (shouldGenerateLocalCandidate()) result.push({
|
|
1562
|
-
boundary: null,
|
|
1563
|
-
boundaryIndex: -1,
|
|
1564
|
-
family,
|
|
1565
|
-
kind: "local",
|
|
1566
|
-
openEnd: preferOpenVariants ? family.maxOpenEnd : family.baseOpenEnd,
|
|
1567
|
-
openStart: preferOpenVariants ? family.maxOpenStart : family.baseOpenStart
|
|
1568
|
-
});
|
|
1569
|
-
boundaries.forEach((boundary, boundaryIndex) => {
|
|
1570
|
-
result.push({
|
|
1571
|
-
boundary,
|
|
1572
|
-
boundaryIndex,
|
|
1573
|
-
family,
|
|
1574
|
-
kind: "structural",
|
|
1575
|
-
openEnd: family.baseOpenEnd,
|
|
1576
|
-
openStart: family.baseOpenStart
|
|
1577
|
-
});
|
|
1578
|
-
});
|
|
1579
|
-
}
|
|
1580
|
-
return result;
|
|
1581
|
-
});
|
|
1582
|
-
const createStructuralCandidates = (boundary, variant, cost) => {
|
|
1583
|
-
const sourceSpine = (depth, edge) => {
|
|
1584
|
-
const result = [];
|
|
1585
|
-
let children = variant.slice.content;
|
|
1586
|
-
for (let index = 0; index < depth; index++) {
|
|
1587
|
-
const node = edge === "start" ? children[0] : children.at(-1);
|
|
1588
|
-
if (!node || !ElementApi.isElement(node)) return [];
|
|
1589
|
-
result.push(node);
|
|
1590
|
-
({children} = node);
|
|
1591
|
-
}
|
|
1592
|
-
return result;
|
|
1593
|
-
};
|
|
1594
|
-
const matchesTargetContext = (depth, edge, position) => {
|
|
1595
|
-
if (depth === 0) return true;
|
|
1596
|
-
const source = sourceSpine(depth, edge);
|
|
1597
|
-
const target = getOpenContext(position).map(openTokenNode).filter((node) => ElementApi.isElement(node));
|
|
1598
|
-
if (source.length !== depth) return false;
|
|
1599
|
-
const preferred = source.at(-1);
|
|
1600
|
-
return target.some((targetNode) => {
|
|
1601
|
-
const sameType = getElementType(targetNode) === getElementType(preferred);
|
|
1602
|
-
return contextsShareContent(targetNode, preferred) && (!getElementSlicePolicy(targetNode).preserveContext || sameType);
|
|
1603
|
-
});
|
|
1604
|
-
};
|
|
1605
|
-
if (!matchesTargetContext(variant.slice.openStart, "start", boundary.from) || !matchesTargetContext(variant.slice.openEnd, "end", boundary.to)) return [];
|
|
1606
|
-
const insertionContent = getInsertionContent(variant.slice);
|
|
1607
|
-
if (insertionContent && !canInsertContentAtBoundary(boundary, insertionContent)) return [];
|
|
1608
|
-
const encoded = encodeContentSlice(variant.slice);
|
|
1609
|
-
const contextInsert = restorePartiallyDeletedContext(document, rootChildren, start, end, boundary, exactFrom, exactTo, encoded);
|
|
1610
|
-
const inserts = contextInsert.insert === encoded ? [contextInsert] : [contextInsert, {
|
|
1611
|
-
content: {
|
|
1612
|
-
from: 0,
|
|
1613
|
-
to: encoded.length
|
|
1614
|
-
},
|
|
1615
|
-
insert: encoded,
|
|
1616
|
-
origins: sliceOrigins(encoded),
|
|
1617
|
-
selectionOffset: getContentEndOffset(encoded)
|
|
1618
|
-
}];
|
|
1619
|
-
if (boundary.from === exactFrom && boundary.to === exactTo && sameTextPath && targetText && NodeApi.isText(targetText)) {
|
|
1620
|
-
const { text: _text, ...properties } = targetText;
|
|
1621
|
-
const closeTarget = PreparedTokenSlice.fromJSON([{
|
|
1622
|
-
kind: "close",
|
|
1623
|
-
nodeKind: "text"
|
|
1624
|
-
}]);
|
|
1625
|
-
const openTarget = PreparedTokenSlice.fromJSON([{
|
|
1626
|
-
kind: "open",
|
|
1627
|
-
nodeKind: "text",
|
|
1628
|
-
props: properties
|
|
1629
|
-
}]);
|
|
1630
|
-
const insert = PreparedTokenSlice.concat([
|
|
1631
|
-
closeTarget,
|
|
1632
|
-
encoded,
|
|
1633
|
-
openTarget
|
|
1634
|
-
]);
|
|
1635
|
-
const origins = new FitOriginLog();
|
|
1636
|
-
origins.add(closeTarget.length, "fit");
|
|
1637
|
-
origins.add(encoded.length, "slice");
|
|
1638
|
-
origins.add(openTarget.length, "fit");
|
|
1639
|
-
inserts.unshift({
|
|
1640
|
-
content: {
|
|
1641
|
-
from: closeTarget.length,
|
|
1642
|
-
to: closeTarget.length + encoded.length
|
|
1643
|
-
},
|
|
1644
|
-
insert,
|
|
1645
|
-
origins: origins.seal(insert),
|
|
1646
|
-
selectionOffset: closeTarget.length + getContentEndOffset(encoded)
|
|
1647
|
-
});
|
|
1648
|
-
}
|
|
1649
|
-
return (endsInInlineVoid(variant.slice) ? inserts.map(({ content, insert, origins }) => ({
|
|
1650
|
-
content,
|
|
1651
|
-
insert,
|
|
1652
|
-
origins,
|
|
1653
|
-
selectionAssociation: 1,
|
|
1654
|
-
selectionOffset: insert.length
|
|
1655
|
-
})) : inserts).map(({ content, insert, origins, selectionOffset }) => ({
|
|
1656
|
-
content,
|
|
1657
|
-
cost,
|
|
1658
|
-
from: boundary.from,
|
|
1659
|
-
insert,
|
|
1660
|
-
origins,
|
|
1661
|
-
selectionOffset,
|
|
1662
|
-
to: boundary.to
|
|
1663
|
-
}));
|
|
1664
|
-
};
|
|
1665
|
-
const directLocalCandidate = prefixInsertionBoundary === null && inputSlice.openStart === 1 && inputSlice.openEnd === 1 ? createLocalTextCandidate(inputSlice, 0) : null;
|
|
1666
|
-
const positionalOpenSlice = fitOpenBlocksToPositionalSlots(inputSlice);
|
|
1667
|
-
const positionalOpenCandidate = positionalOpenSlice ? createLocalTextCandidate(positionalOpenSlice, -1) : null;
|
|
1668
|
-
const selectedPrefixCandidate = (() => {
|
|
1669
|
-
if (options.target.kind !== "range" || textCell || exactBounds || !sameTextPath || collapsed || !targetText || !NodeApi.isText(targetText)) return null;
|
|
1670
|
-
const boundary = getPrefixInsertionBoundary(at, rootChildren, document, inputSlice, targetRootProgram, true);
|
|
1671
|
-
if (boundary === null) return null;
|
|
1672
|
-
const retained = document.tokens.slice(exactTo, boundary);
|
|
1673
|
-
const incoming = encodeContentSlice(inputSlice);
|
|
1674
|
-
const insert = PreparedTokenSlice.concat([retained, incoming]);
|
|
1675
|
-
const origins = new FitOriginLog();
|
|
1676
|
-
origins.add(retained.length, "document", exactTo);
|
|
1677
|
-
origins.add(incoming.length, "slice");
|
|
1678
|
-
return {
|
|
1679
|
-
content: {
|
|
1680
|
-
from: retained.length,
|
|
1681
|
-
to: retained.length + incoming.length
|
|
1682
|
-
},
|
|
1683
|
-
cost: -1,
|
|
1684
|
-
from: exactFrom,
|
|
1685
|
-
insert,
|
|
1686
|
-
origins: origins.seal(insert),
|
|
1687
|
-
selectionOffset: retained.length + getContentEndOffset(incoming),
|
|
1688
|
-
to: boundary,
|
|
1689
|
-
...preparedInput ? { preparation: preparedInput.preparation } : {}
|
|
1690
|
-
};
|
|
1691
|
-
})();
|
|
1692
|
-
const closedBoundaryCandidate = (() => {
|
|
1693
|
-
if (options.target.kind !== "range" || inputSlice.openStart !== 0 || inputSlice.openEnd !== 0) return null;
|
|
1694
|
-
let boundary = exactBounds ? {
|
|
1695
|
-
cost: 0,
|
|
1696
|
-
...exactBounds
|
|
1697
|
-
} : void 0;
|
|
1698
|
-
if (!boundary) {
|
|
1699
|
-
const head = inputSlice.content[0];
|
|
1700
|
-
if (!emptyCaretBlockPath || !ElementApi.isElement(head) || !(getElementBehavior(head).object || getElementBehavior(head).void)) return null;
|
|
1701
|
-
const range = document.nodeRange(emptyCaretBlockPath);
|
|
1702
|
-
boundary = boundaries.find((item) => item.from === range.from && item.to === range.to);
|
|
1703
|
-
}
|
|
1704
|
-
if (!boundary) return null;
|
|
1705
|
-
const insert = encodeContentSlice(inputSlice);
|
|
1706
|
-
const candidate = {
|
|
1707
|
-
content: {
|
|
1708
|
-
from: 0,
|
|
1709
|
-
to: insert.length
|
|
1710
|
-
},
|
|
1711
|
-
cost: boundary.cost,
|
|
1712
|
-
from: boundary.from,
|
|
1713
|
-
insert,
|
|
1714
|
-
origins: sliceOrigins(insert),
|
|
1715
|
-
selectionOffset: getContentEndOffset(insert),
|
|
1716
|
-
to: boundary.to,
|
|
1717
|
-
...preparedInput ? { preparation: preparedInput.preparation } : {}
|
|
1718
|
-
};
|
|
1719
|
-
return isStructurallyApplicable(candidate) ? candidate : null;
|
|
1720
|
-
})();
|
|
1721
|
-
const selectedCandidate = options.target.kind === "root" ? (() => {
|
|
1722
|
-
const insert = encodeContentSlice(inputSlice);
|
|
1723
|
-
return Object.freeze({
|
|
1724
|
-
content: {
|
|
1725
|
-
from: 0,
|
|
1726
|
-
to: insert.length
|
|
1727
|
-
},
|
|
1728
|
-
cost: 0,
|
|
1729
|
-
from: 0,
|
|
1730
|
-
insert,
|
|
1731
|
-
origins: sliceOrigins(insert),
|
|
1732
|
-
selectionOffset: getContentEndOffset(insert),
|
|
1733
|
-
to: document.length
|
|
1734
|
-
});
|
|
1735
|
-
})() : closedBoundaryCandidate ?? selectedPrefixCandidate ?? (positionalOpenCandidate && isStructurallyApplicable(positionalOpenCandidate) ? positionalOpenCandidate : null) ?? (directLocalCandidate && "preparedOpenBlock" in directLocalCandidate && isStructurallyApplicable(directLocalCandidate) ? {
|
|
1736
|
-
...directLocalCandidate,
|
|
1737
|
-
...preparedInput ? { preparation: preparedInput.preparation } : {}
|
|
1738
|
-
} : selectSliceFitCandidate({
|
|
1739
|
-
candidates: ({ state, variant }) => {
|
|
1740
|
-
if (state.kind === "local") {
|
|
1741
|
-
const candidate = profileCoreDuration("slice-fit-local-candidates", () => createLocalTextCandidate(variant.slice, state.cost, state.family.priority < 0));
|
|
1742
|
-
if (candidate && canApplyLocalOpenBlockCandidate(variant.slice) && isStructurallyApplicable(candidate)) return [state.family.index === 0 ? {
|
|
1743
|
-
...candidate,
|
|
1744
|
-
...preparedInput ? { preparation: preparedInput.preparation } : {}
|
|
1745
|
-
} : candidate];
|
|
1746
|
-
return [];
|
|
1747
|
-
}
|
|
1748
|
-
const structurallyApplicable = profileCoreDuration("slice-fit-structural-candidates", () => createStructuralCandidates(state.boundary, variant, state.cost)).filter(isStructurallyApplicable);
|
|
1749
|
-
return state.family.index === 0 ? structurallyApplicable.map((candidate) => ({
|
|
1750
|
-
...candidate,
|
|
1751
|
-
...preparedInput ? { preparation: preparedInput.preparation } : {}
|
|
1752
|
-
})) : structurallyApplicable;
|
|
1753
|
-
},
|
|
1754
|
-
exactFrom,
|
|
1755
|
-
inputSlice,
|
|
1756
|
-
preferOpenVariants,
|
|
1757
|
-
seeds: createSeeds()
|
|
1758
|
-
}));
|
|
1759
|
-
if (!selectedCandidate) return false;
|
|
1760
|
-
const fittedCandidate = profileCoreDuration("slice-fit-candidate-materialize", () => materializeCandidate(selectedCandidate));
|
|
1761
|
-
const materializedCandidate = options.target.kind === "range" && !exactBounds ? withoutUnchangedTail(document, fittedCandidate) : fittedCandidate;
|
|
1762
|
-
const candidate = materializedCandidate.preparation ? Object.freeze({
|
|
1763
|
-
...materializedCandidate,
|
|
1764
|
-
preparation: bindCanonicalFitPreparation(materializedCandidate.preparation, materializedCandidate.insert)
|
|
1765
|
-
}) : materializedCandidate;
|
|
1766
|
-
const canonicalRootChange = profileCoreDuration("slice-fit-changeset-build", () => options.target.kind === "root" && candidate.from === 0 && candidate.to === document.length ? reconcileChildrenStep(document, [], 0, document.value.length, inputSlice.content).change : RootChange.create(document, {
|
|
1767
|
-
from: candidate.from,
|
|
1768
|
-
insert: candidate.insert,
|
|
1769
|
-
to: candidate.to
|
|
1770
|
-
}));
|
|
1771
|
-
const rootChange = candidate.semanticChange ? RootChange.create(document, candidate.semanticChange) : canonicalRootChange;
|
|
1772
|
-
if (options.target.kind === "range" && rootChange.empty && (inputSlice.content.length > 0 || exactFrom !== exactTo)) return false;
|
|
1773
|
-
const candidateChange = createInternalDocumentChange(rootChange.empty ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map([[root, rootChange]]), missingRoot ? { createRoots: [root] } : {});
|
|
1774
|
-
const rootInputMatchesTarget = options.target.kind === "root" && !missingRoot && structurallyEqual(rootChildren, inputSlice.content);
|
|
1775
|
-
const rawChange = rootInputMatchesTarget ? DocumentChange.empty : candidateChange;
|
|
1776
|
-
const rootFitProvenance = options.target.kind === "root" && (options.target.selection || options.target.ranges) && rootPathProvenance ? Object.freeze({
|
|
1777
|
-
paths: rootPathProvenance,
|
|
1778
|
-
rawDocument: rootInputMatchesTarget ? document : rootChange.apply(document),
|
|
1779
|
-
sourceDocument: DocumentIndex.fromValue(sourceSlice.content)
|
|
1780
|
-
}) : null;
|
|
1781
|
-
let fittedDocument;
|
|
1782
|
-
const protectedInlineSpacerPaths = options.target.kind === "root" && !options.target.omitSelectionSpacers && options.target.selection && RangeApi.isRange(options.target.selection) && rootFitProvenance ? (() => {
|
|
1783
|
-
const provenance = rootFitProvenance;
|
|
1784
|
-
const points = [options.target.selection.anchor, options.target.selection.focus].flatMap((point) => {
|
|
1785
|
-
const sourcePoint = resolveExternalDocumentPoint(sourceSlice.content, provenance.sourceDocument, point);
|
|
1786
|
-
if (!sourcePoint) return [];
|
|
1787
|
-
const mapped = provenance.paths.mapPoint(sourcePoint, provenance.sourceDocument, provenance.rawDocument, -1);
|
|
1788
|
-
return mapped ? [{
|
|
1789
|
-
offset: mapped.offset,
|
|
1790
|
-
path: [...mapped.path]
|
|
1791
|
-
}] : [];
|
|
1792
|
-
});
|
|
1793
|
-
return getProtectedInlineSpacerEntries(getEditor(), provenance.rawDocument.value, points, api).map(({ path }) => path);
|
|
1794
|
-
})() : void 0;
|
|
1795
|
-
const fitPreparation = options.target.kind === "root" ? prepareCanonicalRootFit(getDeclarativeSchema(), getDeclarativeSchema, root, protectedInlineSpacerPaths) : candidate.preparation;
|
|
1796
|
-
try {
|
|
1797
|
-
fittedDocument = profileCoreDuration("slice-fit-canonicalize", () => prepareFittedDocument(options.builder.fork(), rawChange, options.target.kind === "root", fitPreparation, candidate.trustedCanonical ? {
|
|
1798
|
-
createIndexes: () => /* @__PURE__ */ new Map([[root, canonicalRootChange.apply(document)]]),
|
|
1799
|
-
runtimeCandidatePaths: /* @__PURE__ */ new Map([[root, candidate.runtimeCandidatePaths ?? Object.freeze([])]])
|
|
1800
|
-
} : void 0));
|
|
1801
|
-
} catch (error) {
|
|
1802
|
-
if (error instanceof PreparedTokenSliceStructureError || error instanceof EditorSchemaValidationError) return false;
|
|
1803
|
-
throw error;
|
|
1804
|
-
}
|
|
1805
|
-
const { canonicalIndexes, constructionChange, prepared, rawIndexes } = fittedDocument;
|
|
1806
|
-
const rawIndex = rawIndexes.get(root) ?? rootFitProvenance?.rawDocument ?? null;
|
|
1807
|
-
const canonicalIndex = canonicalIndexes.get(root) ?? rawIndex;
|
|
1808
|
-
const point = options.target.kind === "range" ? profileCoreDuration("slice-fit-selection-map", () => {
|
|
1809
|
-
if (!rawIndex || !canonicalIndex) throw new Error("Fitted range did not retain its root indexes.");
|
|
1810
|
-
const rawSelectionPosition = candidate.from + candidate.selectionOffset;
|
|
1811
|
-
return mapFittedSelectionPoint(rawIndex, canonicalIndex, constructionChange, root, rawSelectionPosition, candidate.selectionAssociation);
|
|
1812
|
-
}) : null;
|
|
1813
|
-
if (options.target.kind === "range" && canonicalIndex) {
|
|
1814
|
-
const canonicalChildren = canonicalIndex.value;
|
|
1815
|
-
const parentPaths = [start.path.slice(0, -1)];
|
|
1816
|
-
if (point) parentPaths.push(point.path.slice(0, -1));
|
|
1817
|
-
for (const path of parentPaths) {
|
|
1818
|
-
const parent = getDescendant(canonicalChildren, path);
|
|
1819
|
-
if (!ElementApi.isElement(parent)) continue;
|
|
1820
|
-
const content = getCompiledElement(parent)?.content;
|
|
1821
|
-
if (content?.allowsText && content.max !== null && parent.children.length > content.max) return false;
|
|
1822
|
-
}
|
|
1823
|
-
}
|
|
1824
|
-
const mapExternal = options.target.kind === "root" && rootFitProvenance && rawIndex && canonicalIndex ? createExternalRootMapper(sourceSlice.content, rootFitProvenance.sourceDocument, rootFitProvenance.paths, constructionChange, root, rawIndex, canonicalIndex) : null;
|
|
1825
|
-
const externalSelection = options.target.kind === "root" && options.target.selection && mapExternal ? mapExternal(options.target.selection, "backward") : null;
|
|
1826
|
-
const externalRanges = options.target.kind === "root" ? options.target.ranges?.map((range) => {
|
|
1827
|
-
const mapped = mapExternal?.(SelectionApi.text(range), "inward");
|
|
1828
|
-
return mapped && RangeApi.isRange(mapped) ? {
|
|
1829
|
-
anchor: mapped.anchor,
|
|
1830
|
-
focus: mapped.focus
|
|
1831
|
-
} : null;
|
|
1832
|
-
}) : void 0;
|
|
1833
|
-
if (options.target.kind === "root" && options.target.selection && !externalSelection) return false;
|
|
1834
|
-
const selection = externalSelection ? externalSelection : point ? cloneFrozen(SelectionApi.text({
|
|
1835
|
-
anchor: {
|
|
1836
|
-
offset: point.offset,
|
|
1837
|
-
path: [...point.path],
|
|
1838
|
-
...root === "main" ? {} : { root }
|
|
1839
|
-
},
|
|
1840
|
-
focus: {
|
|
1841
|
-
offset: point.offset,
|
|
1842
|
-
path: [...point.path],
|
|
1843
|
-
...root === "main" ? {} : { root }
|
|
1844
|
-
}
|
|
1845
|
-
})) : void 0;
|
|
1846
|
-
const landing = options.target.kind === "range" && options.target.reportLanding && rawIndex && canonicalIndex ? mapFittedLanding(rawIndex, canonicalIndex, constructionChange, root, {
|
|
1847
|
-
from: candidate.from + candidate.content.from,
|
|
1848
|
-
to: candidate.from + candidate.content.to
|
|
1849
|
-
}) : null;
|
|
1850
|
-
const step = options.builder.adopt(prepared);
|
|
1851
|
-
if (!step) throw new Error("Prepared slice fit does not match its transaction.");
|
|
1852
|
-
options.apply?.(step, selection, landing, externalRanges);
|
|
1853
|
-
return true;
|
|
1854
|
-
};
|
|
1855
|
-
const fitKeepsSelection = (document, { root, selection }) => {
|
|
1856
|
-
if (root !== "main" && !Object.hasOwn(document.roots ?? {}, root)) return false;
|
|
1857
|
-
const children = getDocumentRoot(document, root);
|
|
1858
|
-
const namesRoot = (named, unnamed) => (named ?? unnamed) === root;
|
|
1859
|
-
if (SelectionApi.isNode(selection)) return namesRoot(selection.root, "main") && selection.paths.every((path) => getDescendant(children, path) !== null);
|
|
1860
|
-
const text = Object.hasOwn(selection, "kind") ? selection : SelectionApi.text(selection);
|
|
1861
|
-
if (!SelectionApi.isText(text)) return false;
|
|
1862
|
-
return [text.anchor, text.focus].every((point) => {
|
|
1863
|
-
const node = getDescendant(children, point.path);
|
|
1864
|
-
return namesRoot(point.root, root) && node !== null && NodeApi.isText(node) && point.offset <= node.text.length;
|
|
1865
|
-
});
|
|
1866
|
-
};
|
|
1867
|
-
const placesEachNodeOnce = (document) => {
|
|
1868
|
-
const placed = /* @__PURE__ */ new Set();
|
|
1869
|
-
const places = (children) => children.every((node) => {
|
|
1870
|
-
if (placed.has(node)) return false;
|
|
1871
|
-
placed.add(node);
|
|
1872
|
-
return !ElementApi.isElement(node) || places(node.children);
|
|
1873
|
-
});
|
|
1874
|
-
return places(document.children) && Object.values(document.roots ?? {}).every(places);
|
|
1875
|
-
};
|
|
1876
|
-
const ownDocument = (raw) => {
|
|
1877
|
-
const { records, roots, ...value } = snapshotEditorJsonValue(raw, "Editor schema document");
|
|
1878
|
-
const named = Object.entries(roots ?? {});
|
|
1879
|
-
const owned = snapshotEditorJsonValue({
|
|
1880
|
-
...value,
|
|
1881
|
-
children: [...value.children],
|
|
1882
|
-
...named.length > 0 ? { roots: Object.fromEntries(named.map(([root, children]) => [root, [...children]])) } : {}
|
|
1883
|
-
}, "Editor schema document");
|
|
1884
|
-
return records === void 0 ? owned : Object.freeze(showValueRecords({ ...owned }, recordStoreFromJson(records)));
|
|
1885
|
-
};
|
|
1886
|
-
const fullFitFailsOnRoot = (root) => root in Object.prototype;
|
|
1887
|
-
const reuseCanonicalDocument = (raw, positions) => {
|
|
1888
|
-
if (!placesEachNodeOnce(raw)) return null;
|
|
1889
|
-
try {
|
|
1890
|
-
for (const root of Object.keys(raw.roots ?? {})) {
|
|
1891
|
-
if (fullFitFailsOnRoot(root)) return null;
|
|
1892
|
-
assertNamedDocumentRootKey(root);
|
|
1893
|
-
}
|
|
1894
|
-
const document = ownDocument(raw);
|
|
1895
|
-
if (positions?.selection && !fitKeepsSelection(document, positions.selection) || positions?.ranges?.some((range) => !fitKeepsSelection(document, {
|
|
1896
|
-
root: SelectionApi.root(range) ?? "main",
|
|
1897
|
-
selection: SelectionApi.text(range)
|
|
1898
|
-
})) || !withoutGeneration(() => isLoadedDocumentCanonical(getEditor(), document, api))) return null;
|
|
1899
|
-
return Object.freeze({
|
|
1900
|
-
document,
|
|
1901
|
-
ranges: positions?.ranges,
|
|
1902
|
-
selection: positions?.selection && snapshotEditorJsonValue(positions.selection.selection, "Editor selection")
|
|
1903
|
-
});
|
|
1904
|
-
} catch {
|
|
1905
|
-
return null;
|
|
1906
|
-
}
|
|
1907
|
-
};
|
|
1908
|
-
const fitDocumentInput = (rawInput, positions, repairCollector) => {
|
|
1909
|
-
const innerInput2 = readEditorDocument(rawInput, (issue) => {
|
|
1910
|
-
if (issue.kind === "json" || issue.kind === "record") assertEditorJsonValue(rawInput, "Editor schema document");
|
|
1911
|
-
throw new EditorSchemaValidationError(getEditorDocumentShapeIssueMessage(issue));
|
|
1912
|
-
}, (record) => assertEditorJsonValue(record, "Editor schema document"));
|
|
1913
|
-
const inputRoots = innerInput2.roots ?? {};
|
|
1914
|
-
const seededRoots = {};
|
|
1915
|
-
if (schema) for (const root of getVocabulary().rootNames) {
|
|
1916
|
-
const content = getRootContent(root, innerInput2);
|
|
1917
|
-
if (!content?.min) continue;
|
|
1918
|
-
const children = fitDirectContent(schema, content, [], [], { root });
|
|
1919
|
-
if (!children) throw new Error(`Editor root "${root}" requires defaultable content.`);
|
|
1920
|
-
seededRoots[root] = children;
|
|
1921
|
-
}
|
|
1922
|
-
const reused = repairCollector ? null : reuseCanonicalDocument(innerInput2, positions);
|
|
1923
|
-
if (reused) return reused;
|
|
1924
|
-
const builder = new ChangeDraft(cloneFrozen({
|
|
1925
|
-
children: [],
|
|
1926
|
-
...innerInput2.meta !== void 0 ? { meta: innerInput2.meta } : {},
|
|
1927
|
-
...Object.keys(seededRoots).length > 0 ? { roots: seededRoots } : {}
|
|
1928
|
-
}), {
|
|
1929
|
-
construct: ({ after, before, change, indexedAfter, indexedBefore }, preparation) => constructCanonicalDocumentChange(getEditor(), after, change, {
|
|
1930
|
-
before,
|
|
1931
|
-
fitPreparation: preparation,
|
|
1932
|
-
indexedAfter,
|
|
1933
|
-
indexedBefore,
|
|
1934
|
-
schema: api
|
|
1935
|
-
}),
|
|
1936
|
-
indexConstructedRoot,
|
|
1937
|
-
isSetValued: (node, key, context) => isSetValuedProperty(node, key, context),
|
|
1938
|
-
preparationAuthority: api,
|
|
1939
|
-
preparationRevision: () => api
|
|
1940
|
-
});
|
|
1941
|
-
const roots = new Map([["main", innerInput2.children], ...Object.entries(inputRoots).sort(([left], [right]) => left.localeCompare(right))]);
|
|
1942
|
-
for (const root of getVocabulary().rootNames) if (getRootContent(root, innerInput2)?.min) roots.set(root, inputRoots[root] ?? []);
|
|
1943
|
-
const collectProjectedRoots = (children) => {
|
|
1944
|
-
for (const node of children) {
|
|
1945
|
-
if (!ElementApi.isElement(node)) continue;
|
|
1946
|
-
for (const root of Object.values(getElementContentRoots(node))) if (!roots.has(root)) roots.set(root, inputRoots[root] ?? []);
|
|
1947
|
-
collectProjectedRoots(node.children);
|
|
1948
|
-
}
|
|
1949
|
-
};
|
|
1950
|
-
collectProjectedRoots(innerInput2.children);
|
|
1951
|
-
for (const children of Object.values(inputRoots)) collectProjectedRoots(children);
|
|
1952
|
-
let mappedSelection;
|
|
1953
|
-
const mappedRanges = positions?.ranges?.map(() => null) ?? [];
|
|
1954
|
-
const fitRoot = (root, children) => {
|
|
1955
|
-
const selectionInput = positions?.selection;
|
|
1956
|
-
const mapsSelection = selectionInput?.root === root;
|
|
1957
|
-
const owned = positions?.ranges?.flatMap((range, index) => (SelectionApi.root(range) ?? "main") === root ? [{
|
|
1958
|
-
index,
|
|
1959
|
-
range
|
|
1960
|
-
}] : []) ?? [];
|
|
1961
|
-
const ranges = owned.length > 0 ? owned.map(({ range }) => range) : void 0;
|
|
1962
|
-
const repairs = [];
|
|
1963
|
-
const report = repairCollector ? {
|
|
1964
|
-
provenance: createRootFitPathProvenance(children),
|
|
1965
|
-
repairs
|
|
1966
|
-
} : void 0;
|
|
1967
|
-
const run = () => fit(ContentSlice.closed(children), {
|
|
1968
|
-
apply: mapsSelection || ranges ? (_step, selection, _landing, rangesAfter) => {
|
|
1969
|
-
if (mapsSelection) mappedSelection = selection;
|
|
1970
|
-
owned.forEach(({ index }, at) => {
|
|
1971
|
-
mappedRanges[index] = rangesAfter?.[at] ?? null;
|
|
1972
|
-
});
|
|
1973
|
-
} : void 0,
|
|
1974
|
-
builder,
|
|
1975
|
-
target: {
|
|
1976
|
-
kind: "root",
|
|
1977
|
-
...report ? { report } : {},
|
|
1978
|
-
...ranges ? { ranges } : {},
|
|
1979
|
-
root,
|
|
1980
|
-
...mapsSelection ? { selection: selectionInput.selection } : {},
|
|
1981
|
-
...positions?.omitSelectionSpacers ? { omitSelectionSpacers: true } : {}
|
|
1982
|
-
}
|
|
1983
|
-
});
|
|
1984
|
-
const observed = report ? observeRootCanonicalization(root, run) : {
|
|
1985
|
-
events: [],
|
|
1986
|
-
passes: [],
|
|
1987
|
-
value: run()
|
|
1988
|
-
};
|
|
1989
|
-
if (!observed.value) {
|
|
1990
|
-
validateDocument(innerInput2);
|
|
1991
|
-
throw new EditorSchemaValidationError(`Editor ${root === "main" ? "primary root" : `root "${root}"`} cannot fit external content.`);
|
|
1992
|
-
}
|
|
1993
|
-
if (repairCollector && report) {
|
|
1994
|
-
const [propertyPass, representationPass, ...unmapped] = observed.passes;
|
|
1995
|
-
if (unmapped.length > 0) throw new Error(`Unclassified canonical pass in editor root "${root}".`);
|
|
1996
|
-
const { inputPaths } = report.provenance;
|
|
1997
|
-
const representation = propertyPass && representationPass ? resolveRepresentationRepairs(propertyPass.output, representationPass.input, observed.events, root, inputPaths) : null;
|
|
1998
|
-
const canonicalRepairs = [
|
|
1999
|
-
...propertyPass ? collectPropertyRepairs(propertyPass.input, propertyPass.output, root, inputPaths) : [],
|
|
2000
|
-
...representationPass && representation ? collectPropertyRepairs(representationPass.input, representationPass.output, root, (path) => {
|
|
2001
|
-
const node = getDescendant(representationPass.input, path);
|
|
2002
|
-
return node ? representation.inputsOf(node) : [];
|
|
2003
|
-
}) : [],
|
|
2004
|
-
...representation?.repairs ?? []
|
|
2005
|
-
];
|
|
2006
|
-
repairCollector.replaceRoot(root, [
|
|
2007
|
-
...root !== "main" && !Object.hasOwn(inputRoots, root) ? [schemaRepair({
|
|
2008
|
-
code: "create-root",
|
|
2009
|
-
impact: "lossless",
|
|
2010
|
-
outputs: [schemaModelLocation(root, [])],
|
|
2011
|
-
owner: "document"
|
|
2012
|
-
})] : [],
|
|
2013
|
-
...repairs,
|
|
2014
|
-
...canonicalRepairs
|
|
2015
|
-
]);
|
|
2016
|
-
}
|
|
2017
|
-
};
|
|
2018
|
-
for (const [root, children] of roots) fitRoot(root, children);
|
|
2019
|
-
for (const [root, children] of roots) if (root !== "main" && !schema?.roots.has(root)) fitRoot(root, children);
|
|
2020
|
-
builder.finalize();
|
|
2021
|
-
const document = innerInput2.records === void 0 ? builder.value : Object.freeze(showValueRecords({ ...builder.value }, recordStoreFromJson(innerInput2.records)));
|
|
2022
|
-
validateDocument(document);
|
|
2023
|
-
if (positions?.selection && !mappedSelection) throw new Error("Initial selection cannot be mapped through schema fitting.");
|
|
2024
|
-
return Object.freeze({
|
|
2025
|
-
document,
|
|
2026
|
-
ranges: mappedRanges,
|
|
2027
|
-
selection: mappedSelection
|
|
2028
|
-
});
|
|
2029
|
-
};
|
|
2030
|
-
const fitDocument = (innerInput3) => fitDocumentInput(innerInput3).document;
|
|
2031
|
-
const fitDocumentWithReport = (innerInput3) => {
|
|
2032
|
-
const collector = new EditorSchemaFitRepairCollector();
|
|
2033
|
-
const { document } = fitDocumentInput(innerInput3, void 0, collector);
|
|
2034
|
-
return Object.freeze({
|
|
2035
|
-
document,
|
|
2036
|
-
repairs: collector.snapshot()
|
|
2037
|
-
});
|
|
2038
|
-
};
|
|
2039
|
-
const fitDocumentWithSelection = (innerInput4, options) => {
|
|
2040
|
-
const fitted = fitDocumentInput(innerInput4, { selection: options });
|
|
2041
|
-
return Object.freeze({
|
|
2042
|
-
document: fitted.document,
|
|
2043
|
-
selection: fitted.selection
|
|
2044
|
-
});
|
|
2045
|
-
};
|
|
2046
|
-
const fitDocumentAndMapPositions = (rawValue, options) => {
|
|
2047
|
-
const fitted = fitDocumentInput(rawValue, {
|
|
2048
|
-
...options,
|
|
2049
|
-
omitSelectionSpacers: true
|
|
2050
|
-
});
|
|
2051
|
-
return Object.freeze({
|
|
2052
|
-
document: fitted.document,
|
|
2053
|
-
ranges: fitted.ranges ?? [],
|
|
2054
|
-
...fitted.selection ? { selection: fitted.selection } : {}
|
|
2055
|
-
});
|
|
2056
|
-
};
|
|
2057
|
-
return Object.freeze({
|
|
2058
|
-
fit,
|
|
2059
|
-
fitContent,
|
|
2060
|
-
fitDocument,
|
|
2061
|
-
fitDocumentAndMapPositions,
|
|
2062
|
-
fitDocumentWithReport,
|
|
2063
|
-
fitDocumentWithSelection,
|
|
2064
|
-
findWrapping,
|
|
2065
|
-
revision,
|
|
2066
|
-
schema
|
|
2067
|
-
});
|
|
2068
|
-
};
|
|
2069
|
-
const createCompiledSliceFitterDelegate = (getDependencies) => {
|
|
2070
|
-
let compiled = null;
|
|
2071
|
-
const getCompiled = () => {
|
|
2072
|
-
const dependencies = getDependencies();
|
|
2073
|
-
if (compiled?.schema !== dependencies.schema || compiled.revision !== dependencies.revision) compiled = compileSliceFitter(dependencies);
|
|
2074
|
-
return compiled;
|
|
2075
|
-
};
|
|
2076
|
-
return Object.freeze({
|
|
2077
|
-
fit: (slice, options) => getCompiled().fit(slice, options),
|
|
2078
|
-
fitContent: (slice, options) => getCompiled().fitContent(slice, options),
|
|
2079
|
-
fitDocument: (input) => getCompiled().fitDocument(input),
|
|
2080
|
-
fitDocumentWithReport: (input) => getCompiled().fitDocumentWithReport(input),
|
|
2081
|
-
fitDocumentAndMapPositions: (input, options) => getCompiled().fitDocumentAndMapPositions(input, options),
|
|
2082
|
-
fitDocumentWithSelection: (input, options) => getCompiled().fitDocumentWithSelection(input, options),
|
|
2083
|
-
findWrapping: (parent, child) => getCompiled().findWrapping(parent, child)
|
|
2084
|
-
});
|
|
2085
|
-
};
|
|
2086
|
-
//#endregion
|
|
2087
|
-
export { compileSliceFitter, createCompiledSliceFitterDelegate };
|