@mdsvex/parse 1.0.0-next.0 → 1.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +213 -0
- package/WIRE_FORMAT.md +5 -1
- package/dist/buf-utils.js +23 -23
- package/dist/buf_utils.d.ts +1 -1
- package/dist/cursor.d.ts +17 -13
- package/dist/cursor.js +118 -31
- package/dist/main.d.ts +362 -26
- package/dist/main.js +5841 -3420
- package/dist/node_view-bvM0i0-p.js +407 -0
- package/dist/node_view.d.ts +11 -12
- package/dist/opcodes.d.ts +23 -6
- package/dist/plugin_dispatch.d.ts +22 -8
- package/dist/tree-builder.js +185 -66
- package/dist/tree_builder.d.ts +42 -11
- package/dist/undo_log.d.ts +11 -1
- package/dist/utils.d.ts +77 -51
- package/dist/utils.js +687 -209
- package/dist/wire-tree-builder.js +69 -71
- package/dist/wire_tree_builder.d.ts +4 -7
- package/package.json +1 -1
- package/src/buf_utils.ts +10 -14
- package/src/cursor.ts +74 -57
- package/src/main.ts +9898 -5593
- package/src/node_view.ts +159 -140
- package/src/opcodes.ts +39 -7
- package/src/plugin_dispatch.ts +328 -219
- package/src/tree_builder.ts +278 -98
- package/src/undo_log.ts +58 -24
- package/src/utils.spec.ts +86 -9
- package/src/utils.ts +769 -392
- package/src/wire_emitter.ts +6 -0
- package/src/wire_tree_builder.ts +39 -52
- package/test/block_quotes.spec.ts +78 -7
- package/test/code_spans.spec.ts +158 -6
- package/test/crlf.spec.ts +49 -1
- package/test/directives.spec.ts +530 -1
- package/test/emphasis.spec.ts +10 -4
- package/test/fixtures/pfm/block_quotes/pfm_fence_close.md +4 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_compact.md +4 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_end_quote.md +5 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_info.md +5 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_longer.md +4 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_nested.md +3 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_twice.md +6 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_info_eof.md +1 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_unclosed.md +2 -0
- package/test/fixtures/pfm/code_spans/pfm_328_5.md +1 -0
- package/test/fixtures/pfm/code_spans/pfm_328_6.md +1 -0
- package/test/fixtures/pfm/code_spans/pfm_328_7.md +1 -0
- package/test/fixtures/pfm/code_spans/pfm_328_8.md +1 -0
- package/test/fixtures/pfm/code_spans/pfm_328_9.md +2 -0
- package/test/fixtures/pfm/fenced_code_blocks/pfm_info_eof.md +1 -0
- package/test/fixtures/pfm/fenced_code_blocks/pfm_info_eof_no_lf.md +1 -0
- package/test/fixtures/pfm/generic_directives/106.md +1 -0
- package/test/fixtures/pfm/generic_directives/107.md +3 -0
- package/test/fixtures/pfm/generic_directives/108.md +1 -0
- package/test/fixtures/pfm/generic_directives/109.md +1 -0
- package/test/fixtures/pfm/generic_directives/110.md +1 -0
- package/test/fixtures/pfm/generic_directives/111.md +1 -0
- package/test/fixtures/pfm/generic_directives/112.md +1 -0
- package/test/fixtures/pfm/generic_directives/113.md +1 -0
- package/test/fixtures/pfm/generic_directives/114.md +2 -0
- package/test/fixtures/pfm/generic_directives/115.md +1 -0
- package/test/fixtures/pfm/generic_directives/116.md +6 -0
- package/test/fixtures/pfm/generic_directives/117.md +3 -0
- package/test/fixtures/pfm/generic_directives/118.md +6 -0
- package/test/fixtures/pfm/generic_directives/119.md +3 -0
- package/test/fixtures/pfm/generic_directives/120.md +5 -0
- package/test/fixtures/pfm/generic_directives/121.md +3 -0
- package/test/fixtures/pfm/generic_directives/122.md +4 -0
- package/test/fixtures/pfm/generic_directives/123.md +2 -0
- package/test/html.spec.ts +44 -1
- package/test/html_block_containers.spec.ts +445 -0
- package/test/incremental.spec.ts +271 -0
- package/test/lists.spec.ts +107 -1
- package/test/parser_reuse.spec.ts +40 -0
- package/test/plugins.spec.ts +196 -226
- package/test/print.ts +2 -3
- package/test/run_bytecode.spec.ts +36 -0
- package/test/snapshots/hybrid/component-children.snap.ast +9 -16
- package/test/snapshots/hybrid/component-simple-00.snap.ast +1 -2
- package/test/snapshots/hybrid/component-simple-01.snap.ast +1 -2
- package/test/snapshots/hybrid/component-simple-03.snap.ast +13 -13
- package/test/snapshots/hybrid/component-simple-04.snap.ast +1 -2
- package/test/snapshots/hybrid/error.snap.ast +1 -2
- package/test/snapshots/markdown/blockquote-nested-markdown.snap.ast +2 -1
- package/test/snapshots/markdown/emphasis.snap.ast +2 -2
- package/test/snapshots/markdown/encodeHTMLCodeTags.snap.ast +1 -2
- package/test/snapshots/markdown/github-style-codeblock-inside-quote.snap.ast +8 -1
- package/test/snapshots/markdown/html-comments.snap.ast +11 -13
- package/test/snapshots/markdown/html5-strutural-tags.snap.ast +16 -31
- package/test/snapshots/markdown/line-starts-with-html.snap.ast +5 -6
- package/test/snapshots/markdown/literal-html-tags.snap.ast +11 -14
- package/test/snapshots/markdown/nested-blockquote.snap.ast +3 -3
- package/test/snapshots/markdown/pre-code-tags.snap.ast +5 -8
- package/test/snapshots/pfm/block_quotes/237.snap.ast +1 -2
- package/test/snapshots/pfm/block_quotes/251.snap.ast +5 -5
- package/test/snapshots/pfm/block_quotes/pfm_fence_close.snap.ast +6 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_compact.snap.ast +6 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_end_quote.snap.ast +8 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_info.snap.ast +4 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_longer.snap.ast +6 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_nested.snap.ast +5 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_twice.snap.ast +5 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_info_eof.snap.ast +3 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_unclosed.snap.ast +3 -0
- package/test/snapshots/pfm/code_spans/344.snap.ast +1 -1
- package/test/snapshots/pfm/code_spans/347.snap.ast +1 -2
- package/test/snapshots/pfm/code_spans/pfm_328_5.snap.ast +6 -0
- package/test/snapshots/pfm/code_spans/pfm_328_6.snap.ast +6 -0
- package/test/snapshots/pfm/code_spans/pfm_328_7.snap.ast +6 -0
- package/test/snapshots/pfm/code_spans/pfm_328_8.snap.ast +8 -0
- package/test/snapshots/pfm/code_spans/pfm_328_9.snap.ast +10 -0
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/417.snap.ast +2 -2
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/438.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/441.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/444.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/445.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/450.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/453.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/456.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/457.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/473.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/475.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/476.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/477.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/478.snap.ast +3 -4
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/479.snap.ast +3 -4
- package/test/snapshots/pfm/fenced_code_blocks/126.snap.ast +1 -2
- package/test/snapshots/pfm/fenced_code_blocks/pfm_info_eof.snap.ast +2 -0
- package/test/snapshots/pfm/fenced_code_blocks/pfm_info_eof_no_lf.snap.ast +2 -0
- package/test/snapshots/pfm/generic_directives/011.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/015.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/016.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/017.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/019.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/020.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/030.snap.ast +4 -6
- package/test/snapshots/pfm/generic_directives/034.snap.ast +6 -2
- package/test/snapshots/pfm/generic_directives/036.snap.ast +5 -1
- package/test/snapshots/pfm/generic_directives/038.snap.ast +6 -2
- package/test/snapshots/pfm/generic_directives/039.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/040.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/044.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/046.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/089.snap.ast +1 -1
- package/test/snapshots/pfm/generic_directives/103.snap.ast +6 -2
- package/test/snapshots/pfm/generic_directives/106.snap.ast +9 -0
- package/test/snapshots/pfm/generic_directives/107.snap.ast +9 -0
- package/test/snapshots/pfm/generic_directives/108.snap.ast +5 -0
- package/test/snapshots/pfm/generic_directives/109.snap.ast +4 -0
- package/test/snapshots/pfm/generic_directives/110.snap.ast +10 -0
- package/test/snapshots/pfm/generic_directives/111.snap.ast +7 -0
- package/test/snapshots/pfm/generic_directives/112.snap.ast +18 -0
- package/test/snapshots/pfm/generic_directives/113.snap.ast +7 -0
- package/test/snapshots/pfm/generic_directives/114.snap.ast +12 -0
- package/test/snapshots/pfm/generic_directives/115.snap.ast +10 -0
- package/test/snapshots/pfm/generic_directives/116.snap.ast +13 -0
- package/test/snapshots/pfm/generic_directives/117.snap.ast +9 -0
- package/test/snapshots/pfm/generic_directives/118.snap.ast +10 -0
- package/test/snapshots/pfm/generic_directives/119.snap.ast +9 -0
- package/test/snapshots/pfm/generic_directives/120.snap.ast +12 -0
- package/test/snapshots/pfm/generic_directives/121.snap.ast +3 -0
- package/test/snapshots/pfm/generic_directives/122.snap.ast +3 -0
- package/test/snapshots/pfm/generic_directives/123.snap.ast +3 -0
- package/test/snapshots/pfm/hard_line_breaks/642.snap.ast +1 -1
- package/test/snapshots/pfm/hard_line_breaks/643.snap.ast +1 -1
- package/test/snapshots/pfm/html/148.snap.ast +1 -1
- package/test/snapshots/pfm/html/150.snap.ast +1 -1
- package/test/snapshots/pfm/html/159.snap.ast +2 -3
- package/test/snapshots/pfm/html/162.snap.ast +3 -4
- package/test/snapshots/pfm/html/163.snap.ast +1 -1
- package/test/snapshots/pfm/html/164.snap.ast +3 -4
- package/test/snapshots/pfm/html/166.snap.ast +1 -1
- package/test/snapshots/pfm/html/168.snap.ast +2 -3
- package/test/snapshots/pfm/html/169.snap.ast +5 -7
- package/test/snapshots/pfm/html/174.snap.ast +3 -3
- package/test/snapshots/pfm/html/182.snap.ast +1 -1
- package/test/snapshots/pfm/html/613.snap.ast +2 -2
- package/test/snapshots/pfm/html/615.snap.ast +2 -2
- package/test/snapshots/pfm/images/585.snap.ast +1 -1
- package/test/snapshots/pfm/images/589.snap.ast +1 -1
- package/test/snapshots/pfm/link_reference_definitions/201.snap.ast +1 -1
- package/test/snapshots/pfm/link_reference_definitions/208.snap.ast +1 -1
- package/test/snapshots/pfm/links/491.snap.ast +1 -1
- package/test/snapshots/pfm/links/494.snap.ast +2 -2
- package/test/snapshots/pfm/links/516.snap.ast +8 -9
- package/test/snapshots/pfm/links/521.snap.ast +1 -1
- package/test/snapshots/pfm/links/530.snap.ast +8 -12
- package/test/snapshots/pfm/links/534.snap.ast +1 -1
- package/test/snapshots/pfm/links/552.snap.ast +2 -2
- package/test/snapshots/pfm/links/559.snap.ast +1 -1
- package/test/snapshots/pfm/links/564.snap.ast +1 -1
- package/test/snapshots/pfm/list_items/260.snap.ast +3 -4
- package/test/snapshots/pfm/list_items/293.snap.ast +2 -2
- package/test/snapshots/pfm/tabs/16.snap.ast +2 -3
- package/test/snapshots/pfm/tabs/4.snap.ast +6 -5
- package/test/snapshots/svelte/00-introduction/00-hello-world/App.snap.ast +3 -4
- package/test/snapshots/svelte/00-introduction/02-styling/App.snap.ast +2 -3
- package/test/snapshots/svelte/00-introduction/03-nested-components/App.snap.ast +2 -3
- package/test/snapshots/svelte/00-introduction/03-nested-components/Nested.snap.ast +1 -2
- package/test/snapshots/svelte/00-introduction/04-html-tags/App.snap.ast +1 -2
- package/test/snapshots/svelte/01-reactivity/00-reactive-assignments/App.snap.ast +5 -6
- package/test/snapshots/svelte/01-reactivity/01-reactive-declarations/App.snap.ast +11 -14
- package/test/snapshots/svelte/01-reactivity/02-reactive-statements/App.snap.ast +5 -6
- package/test/snapshots/svelte/02-props/00-declaring-props/Nested.snap.ast +2 -3
- package/test/snapshots/svelte/02-props/01-default-values/App.snap.ast +1 -1
- package/test/snapshots/svelte/02-props/01-default-values/Nested.snap.ast +2 -3
- package/test/snapshots/svelte/02-props/02-spread-props/Info.snap.ast +16 -17
- package/test/snapshots/svelte/03-logic/00-if-blocks/App.snap.ast +4 -8
- package/test/snapshots/svelte/03-logic/01-else-blocks/App.snap.ast +4 -8
- package/test/snapshots/svelte/03-logic/02-else-if-blocks/App.snap.ast +6 -9
- package/test/snapshots/svelte/03-logic/03-each-blocks/App.snap.ast +5 -8
- package/test/snapshots/svelte/03-logic/04-keyed-each-blocks/App.snap.ast +4 -7
- package/test/snapshots/svelte/03-logic/04-keyed-each-blocks/Thing.snap.ast +4 -5
- package/test/snapshots/svelte/04-events/02-event-modifiers/App.snap.ast +2 -3
- package/test/snapshots/svelte/04-events/03-component-events/Inner.snap.ast +2 -3
- package/test/snapshots/svelte/04-events/04-event-forwarding/Inner.snap.ast +2 -3
- package/test/snapshots/svelte/04-events/05-dom-event-forwarding/FancyButton.snap.ast +2 -3
- package/test/snapshots/svelte/05-bindings/00-text-inputs/App.snap.ast +3 -4
- package/test/snapshots/svelte/05-bindings/01-numeric-inputs/App.snap.ast +9 -8
- package/test/snapshots/svelte/05-bindings/02-checkbox-inputs/App.snap.ast +7 -11
- package/test/snapshots/svelte/05-bindings/03-group-inputs/App.snap.ast +21 -30
- package/test/snapshots/svelte/05-bindings/04-textarea-inputs/App.snap.ast +1 -2
- package/test/snapshots/svelte/05-bindings/05-select-bindings/App.snap.ast +5 -9
- package/test/snapshots/svelte/05-bindings/06-multiple-select-bindings/App.snap.ast +18 -26
- package/test/snapshots/svelte/05-bindings/07-each-block-bindings/App.snap.ast +7 -11
- package/test/snapshots/svelte/05-bindings/08-media-elements/App.snap.ast +15 -19
- package/test/snapshots/svelte/05-bindings/09-dimensions/App.snap.ast +7 -9
- package/test/snapshots/svelte/05-bindings/11-component-bindings/App.snap.ast +1 -2
- package/test/snapshots/svelte/05-bindings/11-component-bindings/Keypad.snap.ast +32 -34
- package/test/snapshots/svelte/06-lifecycle/00-onmount/App.snap.ast +3 -6
- package/test/snapshots/svelte/06-lifecycle/01-ondestroy/App.snap.ast +6 -7
- package/test/snapshots/svelte/06-lifecycle/02-update/App.snap.ast +2 -4
- package/test/snapshots/svelte/07-stores/00-writable-stores/App.snap.ast +4 -5
- package/test/snapshots/svelte/07-stores/00-writable-stores/Decrementer.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/00-writable-stores/Incrementer.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/00-writable-stores/Resetter.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/01-auto-subscriptions/App.snap.ast +4 -5
- package/test/snapshots/svelte/07-stores/01-auto-subscriptions/Decrementer.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/01-auto-subscriptions/Incrementer.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/01-auto-subscriptions/Resetter.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/02-readable-stores/App.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/03-derived-stores/App.snap.ast +8 -10
- package/test/snapshots/svelte/07-stores/04-custom-stores/App.snap.ast +7 -11
- package/test/snapshots/svelte/08-motion/00-tweened/App.snap.ast +10 -15
- package/test/snapshots/svelte/08-motion/01-spring/App.snap.ast +10 -10
- package/test/snapshots/svelte/09-transitions/00-transition/App.snap.ast +3 -5
- package/test/snapshots/svelte/09-transitions/01-adding-parameters-to-transitions/App.snap.ast +3 -5
- package/test/snapshots/svelte/09-transitions/02-in-and-out/App.snap.ast +3 -5
- package/test/snapshots/svelte/09-transitions/03-custom-css-transitions/App.snap.ast +4 -6
- package/test/snapshots/svelte/09-transitions/04-custom-js-transitions/App.snap.ast +3 -5
- package/test/snapshots/svelte/09-transitions/05-transition-events/App.snap.ast +5 -8
- package/test/snapshots/svelte/10-animations/00-animate/App.snap.ast +16 -20
- package/test/snapshots/svelte/11-easing/00-easing/App.snap.ast +16 -11
- package/test/snapshots/svelte/11-easing/00-easing/Controls.snap.ast +11 -16
- package/test/snapshots/svelte/11-easing/00-easing/Grid.snap.ast +2 -2
- package/test/snapshots/svelte/12-svg/01-clock/App.snap.ast +2 -1
- package/test/snapshots/svelte/12-svg/02-bar-chart/App.snap.ast +7 -9
- package/test/snapshots/svelte/12-svg/03-area-chart/App.snap.ast +14 -15
- package/test/snapshots/svelte/12-svg/04-scatterplot/App.snap.ast +7 -5
- package/test/snapshots/svelte/12-svg/04-scatterplot/Scatterplot.snap.ast +6 -6
- package/test/snapshots/svelte/12-svg/05-svg-transitions/App.snap.ast +5 -6
- package/test/snapshots/svelte/13-actions/01-adding-parameters-to-actions/App.snap.ast +2 -3
- package/test/snapshots/svelte/14-classes/00-classes/App.snap.ast +3 -6
- package/test/snapshots/svelte/14-classes/01-class-shorthand/App.snap.ast +2 -3
- package/test/snapshots/svelte/15-composition/00-slots/App.snap.ast +3 -5
- package/test/snapshots/svelte/15-composition/01-slot-fallbacks/App.snap.ast +3 -5
- package/test/snapshots/svelte/15-composition/01-slot-fallbacks/Box.snap.ast +1 -2
- package/test/snapshots/svelte/15-composition/02-named-slots/App.snap.ast +7 -11
- package/test/snapshots/svelte/15-composition/02-named-slots/ContactCard.snap.ast +3 -6
- package/test/snapshots/svelte/15-composition/03-slot-props/App.snap.ast +9 -15
- package/test/snapshots/svelte/15-composition/04-modal/App.snap.ast +17 -26
- package/test/snapshots/svelte/15-composition/04-modal/Modal.snap.ast +3 -3
- package/test/snapshots/svelte/16-context/00-context-api/App.snap.ast +10 -5
- package/test/snapshots/svelte/17-special-elements/00-svelte-self/File.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/00-svelte-self/Folder.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/01-svelte-component/App.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/01-svelte-component/BlueThing.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/01-svelte-component/GreenThing.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/01-svelte-component/RedThing.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/02-svelte-window/App.snap.ast +3 -6
- package/test/snapshots/svelte/17-special-elements/03-svelte-window-bindings/App.snap.ast +2 -4
- package/test/snapshots/svelte/17-special-elements/05-svelte-head/App.snap.ast +6 -12
- package/test/snapshots/svelte/18-module-context/01-module-exports/App.snap.ast +2 -3
- package/test/snapshots/svelte/18-module-context/01-module-exports/AudioPlayer.snap.ast +4 -7
- package/test/snapshots/svelte/19-debugging/00-debug/App.snap.ast +5 -7
- package/test/snapshots/svelte/19-debugging/00-debug/Test.snap.ast +7 -11
- package/test/snapshots/svelte/20-7guis/01-7guis-counter/App.snap.ast +2 -3
- package/test/snapshots/svelte/20-7guis/02-7guis-temperature/App.snap.ast +2 -2
- package/test/snapshots/svelte/20-7guis/03-7guis-flight-booker/App.snap.ast +4 -7
- package/test/snapshots/svelte/20-7guis/04-7guis-timer/App.snap.ast +13 -17
- package/test/snapshots/svelte/20-7guis/05-7guis-crud/App.snap.ast +11 -13
- package/test/snapshots/svelte/20-7guis/06-7guis-circles/App.snap.ast +10 -11
- package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/Comment.snap.ast +4 -6
- package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/Item.snap.ast +9 -13
- package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/List.snap.ast +3 -5
- package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/Summary.snap.ast +7 -11
- package/test/snapshots/svelte/21-miscellaneous/02-immutable-data/App.snap.ast +2 -4
- package/test/snapshots/svelte/99-embeds/20181225-blog-svelte-css-in-js/App.snap.ast +6 -7
- package/test/snapshots/svelte/99-embeds/20181225-blog-svelte-css-in-js/Hero.snap.ast +3 -5
- package/test/snapshots/svelte/99-embeds/20190420-blog-write-less-code/App.snap.ast +6 -7
- package/test/svelte_expressions.spec.ts +93 -4
- package/test/svelte_tags.spec.ts +27 -12
- package/test/tables.spec.ts +347 -0
- package/test/tree_builder.spec.ts +286 -1
- package/test/unclosed_delimiters.spec.ts +529 -0
- package/tsc/buf_utils.d.ts +1 -1
- package/tsc/buf_utils.js +9 -9
- package/tsc/cursor.d.ts +17 -13
- package/tsc/cursor.js +60 -43
- package/tsc/main.d.ts +362 -26
- package/tsc/main.js +8955 -4891
- package/tsc/node_view.d.ts +11 -12
- package/tsc/node_view.js +134 -102
- package/tsc/opcodes.d.ts +23 -6
- package/tsc/plugin_dispatch.d.ts +22 -8
- package/tsc/plugin_dispatch.js +292 -170
- package/tsc/tree_builder.d.ts +42 -11
- package/tsc/tree_builder.js +237 -82
- package/tsc/undo_log.d.ts +11 -1
- package/tsc/undo_log.js +54 -19
- package/tsc/utils.d.ts +77 -51
- package/tsc/utils.js +687 -344
- package/tsc/utils.spec.js +83 -9
- package/tsc/wire_emitter.js +6 -0
- package/tsc/wire_tree_builder.d.ts +4 -7
- package/tsc/wire_tree_builder.js +34 -37
- package/dist/node_view-BEh2-H86.js +0 -373
package/tsc/tree_builder.d.ts
CHANGED
|
@@ -1,31 +1,62 @@
|
|
|
1
|
-
import type { Emitter } from
|
|
2
|
-
import { NodeBuffer, NodeKind } from
|
|
3
|
-
import type { PluginDispatcher } from
|
|
1
|
+
import type { Emitter } from './opcodes';
|
|
2
|
+
import { NodeBuffer, NodeKind } from './utils';
|
|
3
|
+
import type { PluginDispatcher } from './plugin_dispatch';
|
|
4
4
|
/**
|
|
5
5
|
* consumes opcodes from PFMParser and builds a NodeBuffer.
|
|
6
6
|
* this is the backward-compatibility layer: the opcode stream is the
|
|
7
7
|
* primary output, but existing tests and consumers expect a NodeBuffer.
|
|
8
|
+
*
|
|
9
|
+
* ids are dense so each id is its own buffer index, an id that misses the next
|
|
10
|
+
* free slot, as after a revoke pushes a repair node, switches to an id map for
|
|
11
|
+
* the rest of the document, plugins always use the map since they push
|
|
12
|
+
* synthetic nodes
|
|
8
13
|
*/
|
|
9
14
|
export declare class TreeBuilder implements Emitter {
|
|
10
15
|
private nodes;
|
|
11
|
-
/**
|
|
16
|
+
/** null while ids equal buffer indices */
|
|
12
17
|
private id_to_index;
|
|
13
|
-
/**
|
|
14
|
-
|
|
18
|
+
/**
|
|
19
|
+
* buffer index and kind at open of each node a revoke rewrote, read only
|
|
20
|
+
* for a close or text that does not pass the kind
|
|
21
|
+
*/
|
|
22
|
+
private revoked;
|
|
23
|
+
/** kind at open by index, built from revoked on the first read */
|
|
24
|
+
private revoked_map;
|
|
25
|
+
/** entries of revoked already copied into revoked_map */
|
|
26
|
+
private revoked_mapped;
|
|
15
27
|
/** optional plugin dispatcher. null when no plugins registered. */
|
|
16
28
|
private dispatcher;
|
|
17
|
-
|
|
18
|
-
private register_id;
|
|
29
|
+
private wants;
|
|
19
30
|
constructor(capacity: number, dispatcher?: PluginDispatcher);
|
|
31
|
+
/**
|
|
32
|
+
* Reset a no-plugin builder for another complete document.
|
|
33
|
+
*
|
|
34
|
+
* A plugin dispatcher owns a source-specific TextSource, so those builders
|
|
35
|
+
* cannot be safely reused for a different document.
|
|
36
|
+
*/
|
|
37
|
+
reset(): void;
|
|
38
|
+
private index_of;
|
|
39
|
+
private start_id_map;
|
|
40
|
+
/** for callers that do not pass the kind, a revoke may have rewritten it */
|
|
41
|
+
private opened_kind;
|
|
20
42
|
open(id: number, kind: NodeKind, start: number, parent: number, extra: number, pending: boolean): void;
|
|
21
|
-
|
|
22
|
-
|
|
43
|
+
private open_slow;
|
|
44
|
+
/** an open once a plugin pushed nodes without ids or ids skipped a slot */
|
|
45
|
+
private open_mapped;
|
|
46
|
+
close(id: number, end: number, kind?: NodeKind): void;
|
|
47
|
+
private close_rest;
|
|
48
|
+
/** a no op when finalize_list_pending_paras already revoked the paragraphs */
|
|
49
|
+
private unwrap_tight_list;
|
|
50
|
+
text(parent: number, start: number, end: number, parent_kind?: NodeKind): void;
|
|
51
|
+
leaf(id: number, kind: NodeKind, start: number, parent: number, value_start: number, value_end: number, end: number): void;
|
|
23
52
|
attr(id: number, key: string, value: any): void;
|
|
24
53
|
set_value_start(id: number, pos: number): void;
|
|
25
54
|
set_value_end(id: number, pos: number): void;
|
|
26
|
-
revoke(id: number, source_text?: string): void;
|
|
55
|
+
revoke(id: number, source_text?: string, text_start?: number): void;
|
|
27
56
|
commit(id: number): void;
|
|
28
57
|
cursor(_pos: number): void;
|
|
58
|
+
/** an incremental document is complete, give its unused slab tail back */
|
|
59
|
+
end(): void;
|
|
29
60
|
/** extract the built NodeBuffer. */
|
|
30
61
|
get_buffer(): NodeBuffer;
|
|
31
62
|
}
|
package/tsc/tree_builder.js
CHANGED
|
@@ -1,99 +1,223 @@
|
|
|
1
|
-
import { NodeBuffer } from
|
|
1
|
+
import { NodeBuffer, make_meta, merge_meta, } from './utils';
|
|
2
|
+
const NONE = 0xffffffff;
|
|
3
|
+
/** open_wants of a builder without plugins, never written */
|
|
4
|
+
const NO_WANTS = new Uint8Array(64);
|
|
2
5
|
/**
|
|
3
6
|
* consumes opcodes from PFMParser and builds a NodeBuffer.
|
|
4
7
|
* this is the backward-compatibility layer: the opcode stream is the
|
|
5
8
|
* primary output, but existing tests and consumers expect a NodeBuffer.
|
|
9
|
+
*
|
|
10
|
+
* ids are dense so each id is its own buffer index, an id that misses the next
|
|
11
|
+
* free slot, as after a revoke pushes a repair node, switches to an id map for
|
|
12
|
+
* the rest of the document, plugins always use the map since they push
|
|
13
|
+
* synthetic nodes
|
|
6
14
|
*/
|
|
7
15
|
export class TreeBuilder {
|
|
8
16
|
constructor(capacity, dispatcher) {
|
|
9
|
-
/**
|
|
10
|
-
this.id_to_index =
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
/** null while ids equal buffer indices */
|
|
18
|
+
this.id_to_index = null;
|
|
19
|
+
/**
|
|
20
|
+
* buffer index and kind at open of each node a revoke rewrote, read only
|
|
21
|
+
* for a close or text that does not pass the kind
|
|
22
|
+
*/
|
|
23
|
+
this.revoked = null;
|
|
24
|
+
/** kind at open by index, built from revoked on the first read */
|
|
25
|
+
this.revoked_map = null;
|
|
26
|
+
/** entries of revoked already copied into revoked_map */
|
|
27
|
+
this.revoked_mapped = 0;
|
|
17
28
|
this.nodes = new NodeBuffer(capacity);
|
|
18
|
-
// NodeBuffer constructor auto-creates root at index 0
|
|
19
|
-
this.id_to_index[0] = 0;
|
|
20
|
-
this.id_to_kind[0] = 0 /* NodeKind.root */;
|
|
21
29
|
this.dispatcher = dispatcher ?? null;
|
|
30
|
+
this.wants = dispatcher !== undefined ? dispatcher.open_wants : NO_WANTS;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Reset a no-plugin builder for another complete document.
|
|
34
|
+
*
|
|
35
|
+
* A plugin dispatcher owns a source-specific TextSource, so those builders
|
|
36
|
+
* cannot be safely reused for a different document.
|
|
37
|
+
*/
|
|
38
|
+
reset() {
|
|
39
|
+
if (this.dispatcher !== null) {
|
|
40
|
+
throw new Error('TreeBuilder with plugins cannot be reset');
|
|
41
|
+
}
|
|
42
|
+
this.nodes.reset();
|
|
43
|
+
this.nodes.push(0 /* NodeKind.root */, 0);
|
|
44
|
+
this.id_to_index = null;
|
|
45
|
+
if (this.revoked !== null) {
|
|
46
|
+
this.revoked = null;
|
|
47
|
+
this.revoked_map = null;
|
|
48
|
+
this.revoked_mapped = 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
index_of(id) {
|
|
52
|
+
const map = this.id_to_index;
|
|
53
|
+
return map === null ? id : map[id];
|
|
54
|
+
}
|
|
55
|
+
start_id_map() {
|
|
56
|
+
const size = this.nodes._size;
|
|
57
|
+
const map = [];
|
|
58
|
+
for (let i = 0; i < size; i++)
|
|
59
|
+
map.push(i);
|
|
60
|
+
this.id_to_index = map;
|
|
61
|
+
return map;
|
|
62
|
+
}
|
|
63
|
+
/** for callers that do not pass the kind, a revoke may have rewritten it */
|
|
64
|
+
opened_kind(idx) {
|
|
65
|
+
// plugins rewrite kinds too, the dispatcher logs every rewrite
|
|
66
|
+
const revoked = this.dispatcher !== null ? this.dispatcher.kind_log() : this.revoked;
|
|
67
|
+
if (revoked !== null) {
|
|
68
|
+
let map = this.revoked_map;
|
|
69
|
+
if (map === null)
|
|
70
|
+
map = this.revoked_map = new Map();
|
|
71
|
+
// the first revoke of an index holds the kind at open
|
|
72
|
+
for (let i = this.revoked_mapped; i < revoked.length; i += 2) {
|
|
73
|
+
if (!map.has(revoked[i]))
|
|
74
|
+
map.set(revoked[i], revoked[i + 1]);
|
|
75
|
+
}
|
|
76
|
+
this.revoked_mapped = revoked.length;
|
|
77
|
+
const kind = map.get(idx);
|
|
78
|
+
if (kind !== undefined)
|
|
79
|
+
return kind;
|
|
80
|
+
}
|
|
81
|
+
return this.nodes._n[idx * 12 /* NodeField.stride */] & 0xff;
|
|
22
82
|
}
|
|
23
83
|
open(id, kind, start, parent, extra, pending) {
|
|
24
|
-
|
|
25
|
-
|
|
84
|
+
const nodes = this.nodes;
|
|
85
|
+
// parents are opened ids below this one so they are indices too, id 0
|
|
86
|
+
// never matches as the buffer makes the root, the rare rest stays out of line
|
|
87
|
+
if (this.id_to_index === null && id === nodes._size && !this.wants[kind]) {
|
|
88
|
+
// >>> 0 turns the -1 of no parent into NONE
|
|
89
|
+
nodes.push_node(kind, start, parent >>> 0, extra, pending);
|
|
26
90
|
return;
|
|
27
|
-
|
|
91
|
+
}
|
|
92
|
+
if (id !== 0)
|
|
93
|
+
this.open_slow(id, kind, start, parent, extra, pending);
|
|
94
|
+
}
|
|
95
|
+
open_slow(id, kind, start, parent, extra, pending) {
|
|
96
|
+
const nodes = this.nodes;
|
|
97
|
+
const dispatcher = this.dispatcher;
|
|
98
|
+
if (dispatcher !== null &&
|
|
99
|
+
this.id_to_index === null &&
|
|
100
|
+
id === nodes._size) {
|
|
101
|
+
let parent_idx = parent === -1 ? NONE : parent;
|
|
102
|
+
if (!dispatcher.wants_open(kind)) {
|
|
103
|
+
nodes.push_node(kind, start, parent_idx, extra, pending);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
// children of a wrap_inner parent go to its wrapper
|
|
107
|
+
if (parent_idx !== NONE) {
|
|
108
|
+
const redirect = dispatcher.get_redirect(parent_idx);
|
|
109
|
+
if (redirect !== undefined)
|
|
110
|
+
parent_idx = redirect;
|
|
111
|
+
}
|
|
112
|
+
const idx = nodes.push_node(kind, start, parent_idx, extra, pending);
|
|
113
|
+
if (dispatcher.has_handlers(kind)) {
|
|
114
|
+
dispatcher.dispatch_open(idx, kind, nodes);
|
|
115
|
+
this.wants = dispatcher.open_wants;
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this.open_mapped(id, kind, start, parent, extra, pending);
|
|
120
|
+
}
|
|
121
|
+
/** an open once a plugin pushed nodes without ids or ids skipped a slot */
|
|
122
|
+
open_mapped(id, kind, start, parent, extra, pending) {
|
|
123
|
+
const nodes = this.nodes;
|
|
124
|
+
const dispatcher = this.dispatcher;
|
|
125
|
+
const map = this.id_to_index ?? this.start_id_map();
|
|
126
|
+
let parent_idx = parent === -1 ? NONE : (map[parent] ?? NONE);
|
|
28
127
|
// plugin redirect: if parent has a wrap_inner wrapper, children go there
|
|
29
|
-
if (
|
|
30
|
-
const redirect =
|
|
128
|
+
if (dispatcher !== null && parent_idx !== NONE) {
|
|
129
|
+
const redirect = dispatcher.get_redirect(parent_idx);
|
|
31
130
|
if (redirect !== undefined)
|
|
32
131
|
parent_idx = redirect;
|
|
33
132
|
}
|
|
34
|
-
const idx = pending
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// plugin dispatch
|
|
40
|
-
if (this.dispatcher && this.dispatcher.has_handlers(kind)) {
|
|
41
|
-
this.dispatcher.dispatch_open(idx, kind, this.nodes, this.register_id);
|
|
133
|
+
const idx = nodes.push_node(kind, start, parent_idx, extra, pending);
|
|
134
|
+
map[id] = idx;
|
|
135
|
+
if (dispatcher !== null && dispatcher.has_handlers(kind)) {
|
|
136
|
+
dispatcher.dispatch_open(idx, kind, nodes);
|
|
137
|
+
this.wants = dispatcher.open_wants;
|
|
42
138
|
}
|
|
43
139
|
}
|
|
44
|
-
close(id, end) {
|
|
45
|
-
const idx = this.
|
|
140
|
+
close(id, end, kind) {
|
|
141
|
+
const idx = this.index_of(id);
|
|
46
142
|
if (idx === undefined)
|
|
47
143
|
return;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
//
|
|
52
|
-
if (this.dispatcher
|
|
53
|
-
|
|
144
|
+
const b = idx * 12 /* NodeField.stride */;
|
|
145
|
+
const n = this.nodes._n;
|
|
146
|
+
n[b + 2 /* NodeField.end */] = end;
|
|
147
|
+
// the rare closes go to a call so close inlines cheaply at every emit site
|
|
148
|
+
if (this.dispatcher === null &&
|
|
149
|
+
kind !== undefined &&
|
|
150
|
+
kind !== 15 /* NodeKind.list */ &&
|
|
151
|
+
(kind !== 7 /* NodeKind.paragraph */ || n[b + 10 /* NodeField.pending */] === 0)) {
|
|
152
|
+
n[b + 10 /* NodeField.pending */] = 0;
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
this.close_rest(idx, b, kind);
|
|
156
|
+
}
|
|
157
|
+
close_rest(idx, b, kind) {
|
|
158
|
+
const nodes = this.nodes;
|
|
159
|
+
// fire close callbacks before committing, a quiet dispatcher has none
|
|
160
|
+
const dispatcher = this.dispatcher;
|
|
161
|
+
if (dispatcher !== null && !dispatcher.quiet()) {
|
|
162
|
+
dispatcher.dispatch_close(idx, nodes);
|
|
54
163
|
}
|
|
55
164
|
// pending paragraphs inside list_items are tight-list speculation
|
|
56
165
|
// wrappers, they stay pending after close until the list closes
|
|
57
166
|
// and the parser either revokes (tight) or commits (loose) them.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
167
|
+
// dispatch_close already committed the undo log of a node not pending
|
|
168
|
+
if (kind === undefined)
|
|
169
|
+
kind = this.opened_kind(idx);
|
|
170
|
+
const n = nodes._n;
|
|
171
|
+
if (kind === 7 /* NodeKind.paragraph */ &&
|
|
172
|
+
n[b + 10 /* NodeField.pending */] === 1 &&
|
|
173
|
+
(n[n[b + 5 /* NodeField.parent */] * 12 /* NodeField.stride */] & 0xff) ===
|
|
174
|
+
16 /* NodeKind.list_item */) {
|
|
175
|
+
return;
|
|
67
176
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
177
|
+
n[b + 10 /* NodeField.pending */] = 0;
|
|
178
|
+
if (kind === 15 /* NodeKind.list */)
|
|
179
|
+
this.unwrap_tight_list(idx);
|
|
180
|
+
}
|
|
181
|
+
/** a no op when finalize_list_pending_paras already revoked the paragraphs */
|
|
182
|
+
unwrap_tight_list(idx) {
|
|
183
|
+
const nodes = this.nodes;
|
|
184
|
+
const meta = nodes.metadata_at(idx);
|
|
185
|
+
if (!meta || !meta.tight)
|
|
186
|
+
return;
|
|
187
|
+
// next is read before the unwrap, so children it splices in are skipped
|
|
188
|
+
let item = nodes.first_child_at(idx);
|
|
189
|
+
let more_items = item !== NONE && nodes.parent_at(item) === idx;
|
|
190
|
+
while (more_items) {
|
|
191
|
+
const next_item = nodes.next_at(item);
|
|
192
|
+
more_items = next_item !== NONE && nodes.parent_at(next_item) === idx;
|
|
193
|
+
let child = nodes.first_child_at(item);
|
|
194
|
+
let more = child !== NONE && nodes.parent_at(child) === item;
|
|
195
|
+
while (more) {
|
|
196
|
+
const next = nodes.next_at(child);
|
|
197
|
+
more = next !== NONE && nodes.parent_at(next) === item;
|
|
198
|
+
if (nodes.kind_at(child) === 7 /* NodeKind.paragraph */) {
|
|
199
|
+
nodes.unwrap_node(child);
|
|
82
200
|
}
|
|
201
|
+
child = next;
|
|
83
202
|
}
|
|
203
|
+
item = next_item;
|
|
84
204
|
}
|
|
85
205
|
}
|
|
86
|
-
text(parent, start, end) {
|
|
87
|
-
let parent_idx = this.
|
|
206
|
+
text(parent, start, end, parent_kind) {
|
|
207
|
+
let parent_idx = this.index_of(parent);
|
|
88
208
|
if (parent_idx === undefined)
|
|
89
209
|
return;
|
|
90
|
-
|
|
91
|
-
|
|
210
|
+
if (this.dispatcher !== null) {
|
|
211
|
+
if (parent_kind === undefined)
|
|
212
|
+
parent_kind = this.opened_kind(parent_idx);
|
|
213
|
+
// plugin redirect: text targeting a wrapped parent goes to the wrapper
|
|
92
214
|
const redirect = this.dispatcher.get_redirect(parent_idx);
|
|
93
215
|
if (redirect !== undefined)
|
|
94
216
|
parent_idx = redirect;
|
|
95
217
|
}
|
|
96
|
-
|
|
218
|
+
else if (parent_kind === undefined) {
|
|
219
|
+
parent_kind = this.opened_kind(parent_idx);
|
|
220
|
+
}
|
|
97
221
|
// nodes that store content as a value range (no child text node)
|
|
98
222
|
if (parent_kind === 3 /* NodeKind.heading */ ||
|
|
99
223
|
parent_kind === 5 /* NodeKind.code_fence */ ||
|
|
@@ -102,62 +226,89 @@ export class TreeBuilder {
|
|
|
102
226
|
this.nodes.set_value(parent_idx, start, end);
|
|
103
227
|
}
|
|
104
228
|
else {
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
229
|
+
// fills the slot of the id the parser reserved for this text node
|
|
230
|
+
this.nodes.push_text(start, end, parent_idx);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
leaf(id, kind, start, parent, value_start, value_end, end) {
|
|
234
|
+
const nodes = this.nodes;
|
|
235
|
+
const dispatcher = this.dispatcher;
|
|
236
|
+
if (this.id_to_index === null &&
|
|
237
|
+
id === nodes._size &&
|
|
238
|
+
(dispatcher === null || (!this.wants[kind] && dispatcher.quiet()))) {
|
|
239
|
+
nodes.push_leaf(kind, start, value_start, value_end, end, parent);
|
|
240
|
+
return;
|
|
109
241
|
}
|
|
242
|
+
this.open(id, kind, start, parent, 0, false);
|
|
243
|
+
this.set_value_start(id, value_start);
|
|
244
|
+
this.set_value_end(id, value_end);
|
|
245
|
+
this.close(id, end, kind);
|
|
110
246
|
}
|
|
111
247
|
attr(id, key, value) {
|
|
112
|
-
const idx = this.
|
|
248
|
+
const idx = this.index_of(id);
|
|
113
249
|
if (idx === undefined)
|
|
114
250
|
return;
|
|
115
251
|
switch (key) {
|
|
116
|
-
case
|
|
252
|
+
case 'value':
|
|
117
253
|
this.nodes.set_value(idx, value[0], value[1]);
|
|
118
254
|
break;
|
|
119
|
-
case
|
|
255
|
+
case 'value_start':
|
|
120
256
|
this.nodes.set_value_start(idx, value);
|
|
121
257
|
break;
|
|
122
|
-
case
|
|
258
|
+
case 'value_end':
|
|
123
259
|
this.nodes.set_value_end(idx, value);
|
|
124
260
|
break;
|
|
125
261
|
default: {
|
|
126
|
-
//
|
|
127
|
-
const
|
|
262
|
+
// mutated in place, so no set_metadata call is needed
|
|
263
|
+
const nodes = this.nodes;
|
|
264
|
+
const existing = nodes.metadata_at(idx);
|
|
128
265
|
if (existing) {
|
|
129
|
-
existing
|
|
130
|
-
this.nodes.set_metadata(idx, existing);
|
|
266
|
+
merge_meta(existing, key, value);
|
|
131
267
|
}
|
|
132
268
|
else {
|
|
133
|
-
|
|
269
|
+
nodes.set_metadata(idx, make_meta(key, value));
|
|
134
270
|
}
|
|
135
271
|
break;
|
|
136
272
|
}
|
|
137
273
|
}
|
|
138
274
|
}
|
|
139
275
|
set_value_start(id, pos) {
|
|
140
|
-
const idx = this.
|
|
276
|
+
const idx = this.index_of(id);
|
|
141
277
|
if (idx !== undefined)
|
|
142
278
|
this.nodes.set_value_start(idx, pos);
|
|
143
279
|
}
|
|
144
280
|
set_value_end(id, pos) {
|
|
145
|
-
const idx = this.
|
|
281
|
+
const idx = this.index_of(id);
|
|
146
282
|
if (idx !== undefined)
|
|
147
283
|
this.nodes.set_value_end(idx, pos);
|
|
148
284
|
}
|
|
149
|
-
revoke(id, source_text) {
|
|
150
|
-
const idx = this.
|
|
285
|
+
revoke(id, source_text, text_start) {
|
|
286
|
+
const idx = this.index_of(id);
|
|
151
287
|
if (idx === undefined)
|
|
152
288
|
return;
|
|
289
|
+
const nodes = this.nodes;
|
|
153
290
|
// plugin revoke: undo mutations before handle_repair
|
|
154
|
-
if (this.dispatcher) {
|
|
155
|
-
this.dispatcher.dispatch_revoke(idx,
|
|
291
|
+
if (this.dispatcher !== null) {
|
|
292
|
+
this.dispatcher.dispatch_revoke(idx, nodes);
|
|
293
|
+
const kind = nodes.kind_at(idx);
|
|
294
|
+
nodes.handle_repair(idx, source_text, text_start);
|
|
295
|
+
if (nodes.kind_at(idx) !== kind)
|
|
296
|
+
this.dispatcher.log_kind(idx, kind);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const kind = nodes.kind_at(idx);
|
|
300
|
+
nodes.handle_repair(idx, source_text, text_start);
|
|
301
|
+
// close and text act on the kind at open, callers that omit it read it here
|
|
302
|
+
if (nodes.kind_at(idx) !== kind) {
|
|
303
|
+
const revoked = this.revoked;
|
|
304
|
+
if (revoked === null)
|
|
305
|
+
this.revoked = [idx, kind];
|
|
306
|
+
else
|
|
307
|
+
revoked.push(idx, kind);
|
|
156
308
|
}
|
|
157
|
-
this.nodes.handle_repair(idx, source_text);
|
|
158
309
|
}
|
|
159
310
|
commit(id) {
|
|
160
|
-
const idx = this.
|
|
311
|
+
const idx = this.index_of(id);
|
|
161
312
|
if (idx === undefined)
|
|
162
313
|
return;
|
|
163
314
|
this.nodes.commit_node(idx);
|
|
@@ -166,6 +317,10 @@ export class TreeBuilder {
|
|
|
166
317
|
}
|
|
167
318
|
}
|
|
168
319
|
cursor(_pos) { }
|
|
320
|
+
/** an incremental document is complete, give its unused slab tail back */
|
|
321
|
+
end() {
|
|
322
|
+
this.nodes.trim();
|
|
323
|
+
}
|
|
169
324
|
/** extract the built NodeBuffer. */
|
|
170
325
|
get_buffer() {
|
|
171
326
|
return this.nodes;
|
package/tsc/undo_log.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NodeBuffer } from
|
|
1
|
+
import type { NodeBuffer } from './utils';
|
|
2
2
|
/** sentinel: the attribute key did not exist before this write. */
|
|
3
3
|
export declare const ATTR_DID_NOT_EXIST: unique symbol;
|
|
4
4
|
export declare const enum UndoEntryKind {
|
|
@@ -74,10 +74,18 @@ export declare class UndoLog {
|
|
|
74
74
|
* attribute their entries to this node.
|
|
75
75
|
*/
|
|
76
76
|
private active_node;
|
|
77
|
+
/**
|
|
78
|
+
* buffer index and prior kind of every kind rewrite, recorded or not, in
|
|
79
|
+
* order, so the first entry of an index holds its kind at open
|
|
80
|
+
*/
|
|
81
|
+
kind_changes: number[] | null;
|
|
82
|
+
log_kind(target: number, prior_kind: number): void;
|
|
77
83
|
/** called by dispatcher before invoking plugin handlers for a node. */
|
|
78
84
|
set_active_node(index: number): void;
|
|
79
85
|
/** called by dispatcher after handlers complete. */
|
|
80
86
|
clear_active_node(): void;
|
|
87
|
+
/** false while nothing would keep an entry */
|
|
88
|
+
get recording(): boolean;
|
|
81
89
|
record_attr_set(target: number, key: string, prior_value: any): void;
|
|
82
90
|
record_attr_delete(target: number, key: string, prior_value: any): void;
|
|
83
91
|
record_type_change(target: number, prior_kind: number): void;
|
|
@@ -94,6 +102,8 @@ export declare class UndoLog {
|
|
|
94
102
|
* commit a node, discard its undo log, making mutations permanent.
|
|
95
103
|
*/
|
|
96
104
|
commit(handler_node: number): void;
|
|
105
|
+
/** true when no node holds a mutation that a revoke would undo */
|
|
106
|
+
get empty(): boolean;
|
|
97
107
|
/** check whether a node has any recorded mutations. */
|
|
98
108
|
has(handler_node: number): boolean;
|
|
99
109
|
/** get undo entries for a node (for redirect detection). */
|